diff --git a/srcs/service/dhcpd/dhcpd_network.c b/srcs/service/dhcpd/dhcpd_network.c index b19238f..4ea2412 100644 --- a/srcs/service/dhcpd/dhcpd_network.c +++ b/srcs/service/dhcpd/dhcpd_network.c @@ -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: @@ -338,23 +335,25 @@ static int dhcp_prepare_tx(U8 *pRsp, U32 optSize) { tolSize = optSize + sizeof(DHCP_PROTO) + DHCP_OFFSET; break; case VLAN_LEVEL1: - pIp = (struct iphdr *)(pRsp + IP_HDR_OFFSET + sizeof(VLAN_HDR)); - pUdp = (struct udphdr *)(pRsp + UDP_HDR_OFFSET + sizeof(VLAN_HDR)); + pIp = (struct iphdr *)(pRsp + IP_HDR_OFFSET + sizeof(VLAN_HDR)); + pUdp = (struct udphdr *)(pRsp + UDP_HDR_OFFSET + sizeof(VLAN_HDR)); // 计算包总长度 - tolSize = optSize + sizeof(DHCP_PROTO) + DHCP_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)); + 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); + 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); @@ -717,10 +716,10 @@ static void on_sock_recv(uv_work_t *req) { break; } - //dhcp_option_prase(optMsg, pkg->options, pWork->nSize - sizeof(DHCP_PACKAGE)); + //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));