52 const UDPHdr *udph = PacketSetUDP(p, pkt);
70 p->
proto = IPPROTO_UDP;
76 const uint8_t *pkt, uint16_t
len)
85 SCLogDebug(
"UDP sp: %u -> dp: %u - HLEN: %" PRIu32
" LEN: %" PRIu32
"", p->
sp, p->
dp,
120 static int UDPV4CalculateValidChecksumtest01(
void)
124 uint8_t raw_ipshdr[] = {
125 0xd0, 0x43, 0xdc, 0xdc, 0xc0, 0xa8, 0x01, 0x3};
127 uint8_t raw_udp[] = {
128 0x00, 0x35, 0xcf, 0x34, 0x00, 0x55, 0x6c, 0xe0,
129 0x83, 0xfc, 0x81, 0x80, 0x00, 0x01, 0x00, 0x01,
130 0x00, 0x00, 0x00, 0x00, 0x07, 0x70, 0x61, 0x67,
131 0x65, 0x61, 0x64, 0x32, 0x11, 0x67, 0x6f, 0x6f,
132 0x67, 0x6c, 0x65, 0x73, 0x79, 0x6e, 0x64, 0x69,
133 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x03, 0x63,
134 0x6f, 0x6d, 0x00, 0x00, 0x1c, 0x00, 0x01, 0xc0,
135 0x0c, 0x00, 0x05, 0x00, 0x01, 0x00, 0x01, 0x4b,
136 0x50, 0x00, 0x12, 0x06, 0x70, 0x61, 0x67, 0x65,
137 0x61, 0x64, 0x01, 0x6c, 0x06, 0x67, 0x6f, 0x6f,
138 0x67, 0x6c, 0x65, 0xc0, 0x26};
140 csum = *( ((uint16_t *)raw_udp) + 3);
142 FAIL_IF(UDPV4Checksum((uint16_t *) raw_ipshdr,
143 (uint16_t *)raw_udp,
sizeof(raw_udp), csum) != 0);
147 static int UDPV4CalculateInvalidChecksumtest02(
void)
151 uint8_t raw_ipshdr[] = {
152 0xd0, 0x43, 0xdc, 0xdc, 0xc0, 0xa8, 0x01, 0x3};
154 uint8_t raw_udp[] = {
155 0x00, 0x35, 0xcf, 0x34, 0x00, 0x55, 0x6c, 0xe0,
156 0x83, 0xfc, 0x81, 0x80, 0x00, 0x01, 0x00, 0x01,
157 0x00, 0x00, 0x00, 0x00, 0x07, 0x70, 0x61, 0x67,
158 0x65, 0x61, 0x64, 0x32, 0x11, 0x67, 0x6f, 0x6f,
159 0x67, 0x6c, 0x65, 0x73, 0x79, 0x6e, 0x64, 0x69,
160 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x03, 0x63,
161 0x6f, 0x6d, 0x00, 0x00, 0x1c, 0x00, 0x01, 0xc0,
162 0x0c, 0x00, 0x05, 0x00, 0x01, 0x00, 0x01, 0x4b,
163 0x50, 0x00, 0x12, 0x06, 0x70, 0x61, 0x67, 0x65,
164 0x61, 0x64, 0x01, 0x6c, 0x06, 0x67, 0x6f, 0x6f,
165 0x67, 0x6c, 0x65, 0xc0, 0x27};
167 csum = *( ((uint16_t *)raw_udp) + 3);
169 FAIL_IF(UDPV4Checksum((uint16_t *) raw_ipshdr,
170 (uint16_t *)raw_udp,
sizeof(raw_udp), csum) == 0);
174 static int UDPV6CalculateValidChecksumtest03(
void)
178 static uint8_t raw_ipv6[] = {
179 0x00, 0x60, 0x97, 0x07, 0x69, 0xea, 0x00, 0x00,
180 0x86, 0x05, 0x80, 0xda, 0x86, 0xdd, 0x60, 0x00,
181 0x00, 0x00, 0x00, 0x14, 0x11, 0x02, 0x3f, 0xfe,
182 0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00,
183 0x86, 0xff, 0xfe, 0x05, 0x80, 0xda, 0x3f, 0xfe,
184 0x05, 0x01, 0x04, 0x10, 0x00, 0x00, 0x02, 0xc0,
185 0xdf, 0xff, 0xfe, 0x47, 0x03, 0x3e, 0xa0, 0x75,
186 0x82, 0xa0, 0x00, 0x14, 0x1a, 0xc3, 0x06, 0x02,
187 0x00, 0x00, 0xf9, 0xc8, 0xe7, 0x36, 0x57, 0xb0,
190 csum = *( ((uint16_t *)(raw_ipv6 + 60)));
192 FAIL_IF(UDPV6Checksum((uint16_t *)(raw_ipv6 + 14 + 8),
193 (uint16_t *)(raw_ipv6 + 54), 20, csum) != 0);
197 static int UDPV6CalculateInvalidChecksumtest04(
void)
201 static uint8_t raw_ipv6[] = {
202 0x00, 0x60, 0x97, 0x07, 0x69, 0xea, 0x00, 0x00,
203 0x86, 0x05, 0x80, 0xda, 0x86, 0xdd, 0x60, 0x00,
204 0x00, 0x00, 0x00, 0x14, 0x11, 0x02, 0x3f, 0xfe,
205 0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00,
206 0x86, 0xff, 0xfe, 0x05, 0x80, 0xda, 0x3f, 0xfe,
207 0x05, 0x01, 0x04, 0x10, 0x00, 0x00, 0x02, 0xc0,
208 0xdf, 0xff, 0xfe, 0x47, 0x03, 0x3e, 0xa0, 0x75,
209 0x82, 0xa0, 0x00, 0x14, 0x1a, 0xc3, 0x06, 0x02,
210 0x00, 0x00, 0xf9, 0xc8, 0xe7, 0x36, 0x57, 0xb0,
213 csum = *( ((uint16_t *)(raw_ipv6 + 60)));
215 FAIL_IF(UDPV6Checksum((uint16_t *)(raw_ipv6 + 14 + 8),
216 (uint16_t *)(raw_ipv6 + 54), 20, csum) == 0);
225 UDPV4CalculateValidChecksumtest01);
227 UDPV4CalculateInvalidChecksumtest02);
229 UDPV6CalculateValidChecksumtest03);
231 UDPV6CalculateInvalidChecksumtest04);