24 #ifndef __DECODE_UDP_H__
25 #define __DECODE_UDP_H__
27 #define UDP_HEADER_LEN 8
30 #define UDP_GET_RAW_LEN(udph) SCNtohs((udph)->uh_len)
31 #define UDP_GET_RAW_SRC_PORT(udph) SCNtohs((udph)->uh_sport)
32 #define UDP_GET_RAW_DST_PORT(udph) SCNtohs((udph)->uh_dport)
33 #define UDP_GET_RAW_SUM(udph) SCNtohs((udph)->uh_sum)
35 #define UDP_GET_LEN(p) UDP_GET_RAW_LEN(p->udph)
36 #define UDP_GET_SRC_PORT(p) UDP_GET_RAW_SRC_PORT(p->udph)
37 #define UDP_GET_DST_PORT(p) UDP_GET_RAW_DST_PORT(p->udph)
38 #define UDP_GET_SUM(p) UDP_GET_RAW_SUM(p->udph)
49 #define CLEAR_UDP_PACKET(p) do { \
50 (p)->level4_comp_csum = -1; \
71 static inline uint16_t UDPV4Checksum(
72 const uint16_t *shdr,
const uint16_t *pkt, uint16_t tlen, uint16_t init)
77 csum += shdr[0] + shdr[1] + shdr[2] + shdr[3] + htons(17) + htons(tlen);
79 csum += pkt[0] + pkt[1] + pkt[2];
85 csum += pkt[0] + pkt[1] + pkt[2] + pkt[3] + pkt[4] + pkt[5] + pkt[6] +
86 pkt[7] + pkt[8] + pkt[9] + pkt[10] + pkt[11] + pkt[12] + pkt[13] +
93 csum += pkt[0] + pkt[1] + pkt[2] + pkt[3];
99 csum += pkt[0] + pkt[1];
111 *(uint8_t *)(&
pad) = (*(uint8_t *)pkt);
115 csum = (csum >> 16) + (csum & 0x0000FFFF);
116 csum += (csum >> 16);
118 uint16_t csum_u16 = (uint16_t)~csum;
119 if (init == 0 && csum_u16 == 0)
138 static inline uint16_t UDPV6Checksum(
139 const uint16_t *shdr,
const uint16_t *pkt, uint16_t tlen, uint16_t init)
142 uint32_t csum = init;
144 csum += shdr[0] + shdr[1] + shdr[2] + shdr[3] + shdr[4] + shdr[5] + shdr[6] +
145 shdr[7] + shdr[8] + shdr[9] + shdr[10] + shdr[11] + shdr[12] +
146 shdr[13] + shdr[14] + shdr[15] + htons(17) + htons(tlen);
148 csum += pkt[0] + pkt[1] + pkt[2];
154 csum += pkt[0] + pkt[1] + pkt[2] + pkt[3] + pkt[4] + pkt[5] + pkt[6] +
155 pkt[7] + pkt[8] + pkt[9] + pkt[10] + pkt[11] + pkt[12] + pkt[13] +
162 csum += pkt[0] + pkt[1] + pkt[2] + pkt[3];
168 csum += pkt[0] + pkt[1];
180 *(uint8_t *)(&
pad) = (*(uint8_t *)pkt);
184 csum = (csum >> 16) + (csum & 0x0000FFFF);
185 csum += (csum >> 16);
187 uint16_t csum_u16 = (uint16_t)~csum;
188 if (init == 0 && csum_u16 == 0)