50 p->
udph = (UDPHdr *)pkt;
68 p->
proto = IPPROTO_UDP;
77 if (
unlikely(DecodeUDPPacket(tv, p,pkt,len) < 0)) {
82 SCLogDebug(
"UDP sp: %" PRIu32
" -> dp: %" PRIu32
" - HLEN: %" PRIu32
" LEN: %" PRIu32
"",
98 static int UDPV4CalculateValidChecksumtest01(
void)
102 uint8_t raw_ipshdr[] = {
103 0xd0, 0x43, 0xdc, 0xdc, 0xc0, 0xa8, 0x01, 0x3};
105 uint8_t raw_udp[] = {
106 0x00, 0x35, 0xcf, 0x34, 0x00, 0x55, 0x6c, 0xe0,
107 0x83, 0xfc, 0x81, 0x80, 0x00, 0x01, 0x00, 0x01,
108 0x00, 0x00, 0x00, 0x00, 0x07, 0x70, 0x61, 0x67,
109 0x65, 0x61, 0x64, 0x32, 0x11, 0x67, 0x6f, 0x6f,
110 0x67, 0x6c, 0x65, 0x73, 0x79, 0x6e, 0x64, 0x69,
111 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x03, 0x63,
112 0x6f, 0x6d, 0x00, 0x00, 0x1c, 0x00, 0x01, 0xc0,
113 0x0c, 0x00, 0x05, 0x00, 0x01, 0x00, 0x01, 0x4b,
114 0x50, 0x00, 0x12, 0x06, 0x70, 0x61, 0x67, 0x65,
115 0x61, 0x64, 0x01, 0x6c, 0x06, 0x67, 0x6f, 0x6f,
116 0x67, 0x6c, 0x65, 0xc0, 0x26};
118 csum = *( ((uint16_t *)raw_udp) + 3);
120 FAIL_IF(UDPV4Checksum((uint16_t *) raw_ipshdr,
121 (uint16_t *)raw_udp,
sizeof(raw_udp), csum) != 0);
125 static int UDPV4CalculateInvalidChecksumtest02(
void)
129 uint8_t raw_ipshdr[] = {
130 0xd0, 0x43, 0xdc, 0xdc, 0xc0, 0xa8, 0x01, 0x3};
132 uint8_t raw_udp[] = {
133 0x00, 0x35, 0xcf, 0x34, 0x00, 0x55, 0x6c, 0xe0,
134 0x83, 0xfc, 0x81, 0x80, 0x00, 0x01, 0x00, 0x01,
135 0x00, 0x00, 0x00, 0x00, 0x07, 0x70, 0x61, 0x67,
136 0x65, 0x61, 0x64, 0x32, 0x11, 0x67, 0x6f, 0x6f,
137 0x67, 0x6c, 0x65, 0x73, 0x79, 0x6e, 0x64, 0x69,
138 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x03, 0x63,
139 0x6f, 0x6d, 0x00, 0x00, 0x1c, 0x00, 0x01, 0xc0,
140 0x0c, 0x00, 0x05, 0x00, 0x01, 0x00, 0x01, 0x4b,
141 0x50, 0x00, 0x12, 0x06, 0x70, 0x61, 0x67, 0x65,
142 0x61, 0x64, 0x01, 0x6c, 0x06, 0x67, 0x6f, 0x6f,
143 0x67, 0x6c, 0x65, 0xc0, 0x27};
145 csum = *( ((uint16_t *)raw_udp) + 3);
147 FAIL_IF(UDPV4Checksum((uint16_t *) raw_ipshdr,
148 (uint16_t *)raw_udp,
sizeof(raw_udp), csum) == 0);
152 static int UDPV6CalculateValidChecksumtest03(
void)
156 static uint8_t raw_ipv6[] = {
157 0x00, 0x60, 0x97, 0x07, 0x69, 0xea, 0x00, 0x00,
158 0x86, 0x05, 0x80, 0xda, 0x86, 0xdd, 0x60, 0x00,
159 0x00, 0x00, 0x00, 0x14, 0x11, 0x02, 0x3f, 0xfe,
160 0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00,
161 0x86, 0xff, 0xfe, 0x05, 0x80, 0xda, 0x3f, 0xfe,
162 0x05, 0x01, 0x04, 0x10, 0x00, 0x00, 0x02, 0xc0,
163 0xdf, 0xff, 0xfe, 0x47, 0x03, 0x3e, 0xa0, 0x75,
164 0x82, 0xa0, 0x00, 0x14, 0x1a, 0xc3, 0x06, 0x02,
165 0x00, 0x00, 0xf9, 0xc8, 0xe7, 0x36, 0x57, 0xb0,
168 csum = *( ((uint16_t *)(raw_ipv6 + 60)));
170 FAIL_IF(UDPV6Checksum((uint16_t *)(raw_ipv6 + 14 + 8),
171 (uint16_t *)(raw_ipv6 + 54), 20, csum) != 0);
175 static int UDPV6CalculateInvalidChecksumtest04(
void)
179 static uint8_t raw_ipv6[] = {
180 0x00, 0x60, 0x97, 0x07, 0x69, 0xea, 0x00, 0x00,
181 0x86, 0x05, 0x80, 0xda, 0x86, 0xdd, 0x60, 0x00,
182 0x00, 0x00, 0x00, 0x14, 0x11, 0x02, 0x3f, 0xfe,
183 0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00,
184 0x86, 0xff, 0xfe, 0x05, 0x80, 0xda, 0x3f, 0xfe,
185 0x05, 0x01, 0x04, 0x10, 0x00, 0x00, 0x02, 0xc0,
186 0xdf, 0xff, 0xfe, 0x47, 0x03, 0x3e, 0xa0, 0x75,
187 0x82, 0xa0, 0x00, 0x14, 0x1a, 0xc3, 0x06, 0x02,
188 0x00, 0x00, 0xf9, 0xc8, 0xe7, 0x36, 0x57, 0xb0,
191 csum = *( ((uint16_t *)(raw_ipv6 + 60)));
193 FAIL_IF(UDPV6Checksum((uint16_t *)(raw_ipv6 + 14 + 8),
194 (uint16_t *)(raw_ipv6 + 54), 20, csum) == 0);
203 UDPV4CalculateValidChecksumtest01);
205 UDPV4CalculateInvalidChecksumtest02);
207 UDPV6CalculateValidChecksumtest03);
209 UDPV6CalculateInvalidChecksumtest04);
void FlowSetupPacket(Packet *p)
prepare packet for a life with flow Set PKT_WANTS_FLOW flag to incidate workers should do a flow look...
#define PASS
Pass the test.
void DecodeUDPV4RegisterTests(void)
#define UDP_GET_SRC_PORT(p)
int DecodeUDP(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, uint16_t len, PacketQueue *pq)
#define FAIL_IF(expr)
Fail a test if expression evaluates to false.
int DecodeTeredo(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, uint16_t len, PacketQueue *pq)
Function to decode Teredo packets.
#define SET_UDP_DST_PORT(pkt, prt)
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Structure to hold thread specific data for all decode modules.
#define SET_UDP_SRC_PORT(pkt, prt)
void StatsIncr(ThreadVars *tv, uint16_t id)
Increments the local counter.
#define UDP_GET_DST_PORT(p)
Per thread variable structure.
#define ENGINE_SET_INVALID_EVENT(p, e)