我正在生成 GTP 隧道数据包,格式如下:
“外部 IP”->“外部 UDP”->“GTP”->“内部 IP”->“内部 UDP”
我使用的 UDP 校验和算法实际上来自 DHCPd
**********************code snippet start **********************
udp_header->check = wrapsum(in_cksum((unsigned char *)udp_header, sizeof(struct udp_header),
in_cksum((unsigned char *)&buffer[i], send_len-i,
in_cksum((unsigned char *)&ip_header->saddr,
2*sizeof(ip_header->saddr),
IPPROTO_UDP + ntohs(udp_header->len)))));
/* ******************************************* */
/*
* Checksum routine for Internet Protocol family headers (C Version)
*
* Borrowed from DHCPd
*/
static u_int32_t in_cksum(unsigned char *buf,
unsigned nbytes, u_int32_t sum) {
uint i;
/* Checksum all the pairs of bytes first... */
for (i = 0; i < (nbytes & ~1U); i += 2) {
sum += (u_int16_t) ntohs(*((u_int16_t *)(buf + i)));
/* Add carry. */
if(sum > 0xFFFF)
sum -= 0xFFFF;
}
/* If there's a single byte left over, checksum it, too. Network
byte order is big-endian, so the remaining byte is the high byte. */
if(i < nbytes) {
#ifdef DEBUG_CHECKSUM_VERBOSE
debug ("sum = %x", sum);
#endif
sum += buf [i] << 8;
/* Add carry. */
if(sum > 0xFFFF)
sum -= 0xFFFF;
}
return sum;
}
/* ******************************************* */
static u_int32_t wrapsum (u_int32_t sum) {
sum = ~sum & 0xFFFF;
return htons(sum);
}
**********************code snippet end**********************
外部 UDP 和内部 UDP 调用都使用相同的校验和功能。但是,我的内部 UDP 很好,但我的外部 UDP 未通过wireshark 的校验和检查。有人对这个问题有什么建议吗?