OCT 1. 修正双层QinQ时包长度计算错误问题

This commit is contained in:
黄昕 2023-05-16 14:49:50 +08:00
parent 41029b43fe
commit 8304f4eef6
1 changed files with 15 additions and 16 deletions

View File

@ -24,10 +24,6 @@
#define MAXIMUM_SNAPLEN (262144)
#define IP_HDR_OFFSET (sizeof(struct ethhdr))
#define UDP_HDR_OFFSET (sizeof(struct ethhdr) + sizeof(struct iphdr))
#define DHCP_OFFSET (sizeof(struct ethhdr) + sizeof(struct iphdr) + sizeof(struct udphdr))
/*
TORs (Top of Rack switch) at Facebook run DHCP relayers, these relayers are
responsible for relaying broadcast DHCP traffic (DISCOVERY and SOLICIT
@ -329,6 +325,7 @@ static int dhcp_prepare_tx(U8 *pRsp, U32 optSize) {
struct udphdr *pUdp = NULL;
U16 csum;
U32 tolSize;
U8 vlanSize = 0;
switch (get_package_vlan_type(pRsp)) {
default:
@ -342,19 +339,21 @@ static int dhcp_prepare_tx(U8 *pRsp, U32 optSize) {
pUdp = (struct udphdr *)(pRsp + UDP_HDR_OFFSET + sizeof(VLAN_HDR));
// 计算包总长度
tolSize = optSize + sizeof(DHCP_PROTO) + DHCP_OFFSET + sizeof(VLAN_HDR);
vlanSize = sizeof(VLAN_HDR);
break;
case VLAN_LEVEL2:
pIp = (struct iphdr *)(pRsp + IP_HDR_OFFSET + sizeof(VLAN_HDR2));
pUdp = (struct udphdr *)(pRsp + UDP_HDR_OFFSET + sizeof(VLAN_HDR2));
// 计算包总长度
tolSize = optSize + sizeof(DHCP_PROTO) + DHCP_OFFSET + sizeof(VLAN_HDR2);
vlanSize = sizeof(VLAN_HDR2);
break;
}
// 计算 IP 数据长度
pIp->tot_len = htons(tolSize - sizeof(struct ethhdr) - sizeof(struct vlan_hdr));
pIp->tot_len = htons(tolSize - sizeof(struct ethhdr) - vlanSize);
// 计算 UDP 数据长度
pUdp->len = htons(tolSize - sizeof(struct ethhdr) - sizeof(struct vlan_hdr) - sizeof(struct iphdr));
pUdp->len = htons(tolSize - sizeof(struct ethhdr) - vlanSize - sizeof(struct iphdr));
// 计算 IP 校验和
csum = htons(ip_checksum((unsigned char *)pIp));
@ -495,7 +494,7 @@ static int dhcp_resp_offer(void *pReq, PPOOL_CTX pIpInfo, U32 ip) {
return dhcp_prepare_tx(pRsp, (int)((pOpt - pDhcp->options) + 1));
}
static PDHCP_PROTO get_dhcp_date(void *pBuf, U32 *pOptSize, U32 bufSize) {
PDHCP_PROTO get_dhcp_date(void *pBuf, U32 *pOptSize, U32 bufSize) {
U8 *p = (U8 *)pBuf;
U32 hdrCom = sizeof(struct ethhdr) + sizeof(struct iphdr) + sizeof(struct udphdr);
@ -719,8 +718,8 @@ static void on_sock_recv(uv_work_t *req) {
//dhcp_option_prase(optMsg, pkg->options, pWork->nSize - sizeof(DHCP_PACKAGE));
LOG_MSG_HEX(trace, pkg, pWork->nSize);
//LOG_MSG(info, "vni: %d, xid: 0x%08X\n", VLAN_VNI_ID(pkg->hdr.vlan.id), DHCP_XID(pkg->xid));
//LOG_MSG_HEX(trace, pkg, pWork->nSize);
//LOG_MSG(info, "Recv, xid: 0x%08X\n", DHCP_XID(pkg->xid));
#if 0
LOG_MOD(info, ZM_DHCP_NET, "vlan = %u\n", VXLAN_VIN_ID_PACK(pkg->hdr.vlan.id));