mirror of https://github.com/OISF/suricata
udp decoding added icmp unreachables added to reject
parent
3f7195454b
commit
7006085195
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,48 @@
|
||||
/* Copyright (c) 2008 Victor Julien <victor@inliniac.net> */
|
||||
|
||||
#include "decode.h"
|
||||
#include "decode-udp.h"
|
||||
#include "decode-events.h"
|
||||
|
||||
static int DecodeUDPPacket(ThreadVars *t, Packet *p, u_int8_t *pkt, u_int16_t len)
|
||||
{
|
||||
p->udph = (UDPHdr *)pkt;
|
||||
|
||||
if (len < UDP_GET_LEN(p)) {
|
||||
DECODER_SET_EVENT(p, UDP_PKT_TOO_SMALL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (len < UDP_HEADER_LEN) {
|
||||
DECODER_SET_EVENT(p, UDP_HLEN_TOO_SMALL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (len != UDP_GET_LEN(p)) {
|
||||
DECODER_SET_EVENT(p, UDP_HLEN_INVALID);
|
||||
return -1;
|
||||
}
|
||||
|
||||
SET_UDP_SRC_PORT(p,&p->sp);
|
||||
SET_UDP_DST_PORT(p,&p->dp);
|
||||
|
||||
p->tcp_payload = pkt + UDP_HEADER_LEN;
|
||||
p->tcp_payload_len = len - UDP_HEADER_LEN;
|
||||
|
||||
p->proto = IPPROTO_UDP;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DecodeUDP(ThreadVars *t, Packet *p, u_int8_t *pkt, u_int16_t len)
|
||||
{
|
||||
if (DecodeUDPPacket(t, p,pkt,len) < 0)
|
||||
return;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("UDP sp: %u -> dp: %u - HLEN: %u LEN: %u TEST: %u\n",
|
||||
UDP_GET_SRC_PORT(p), UDP_GET_DST_PORT(p), UDP_HEADER_LEN, p->tcp_payload_len);
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/* Copyright (c) 2008 Victor Julien <victor@inliniac.net> */
|
||||
|
||||
#ifndef __DECODE_UDP_H__
|
||||
#define __DECODE_UDP_H__
|
||||
|
||||
#define UDP_HEADER_LEN 8
|
||||
|
||||
#define UDP_GET_RAW_LEN(udph) ntohs((udph)->uh_len)
|
||||
#define UDP_GET_RAW_SRC_PORT(udph) ntohs((udph)->uh_sport)
|
||||
#define UDP_GET_RAW_DST_PORT(udph) ntohs((udph)->uh_dport)
|
||||
|
||||
#define UDP_GET_LEN(p) UDP_GET_RAW_LEN(p->udph)
|
||||
#define UDP_GET_SRC_PORT(p) UDP_GET_RAW_SRC_PORT(p->udph)
|
||||
#define UDP_GET_DST_PORT(p) UDP_GET_RAW_DST_PORT(p->udph)
|
||||
|
||||
/* UDP header structure */
|
||||
typedef struct _UDPHdr
|
||||
{
|
||||
u_int16_t uh_sport; /* source port */
|
||||
u_int16_t uh_dport; /* destination port */
|
||||
u_int16_t uh_len; /* length */
|
||||
u_int16_t uh_sum; /* checksum */
|
||||
} UDPHdr;
|
||||
|
||||
typedef struct _UDPVars
|
||||
{
|
||||
u_int8_t hlen;
|
||||
}
|
||||
UDPVars;
|
||||
|
||||
#endif /* __DECODE_UDP_H__ */
|
Loading…
Reference in New Issue