我更改了这个小NAT实现的数据包源端口和IP地址(数据包在struct rte_mbuf *m
中):
eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
ipv4_hdr->dst_addr = f->int_src_ip;
这是修改包裹的正确方法吗?如果是,我该如何更新校验和?
答案 0 :(得分:1)
是的,这是通常的方式。您可以使用checksum API of DPDK修改校验和。
示例:
ipv4_hdr = (struct ipv4_hdr *)(eth_hdr + 1);
udp_hdr = (struct udp_hdr *)((char *)ipv4_hdr + sizeof(struct ipv4_hdr));
udp_hdr->src_port = 42;
ipv4_hdr->hdr_checksum = 0;
udp_hdr->dgram_cksum = 0;
udp_hdr->dgram_cksum = rte_ipv4_udptcp_cksum(ipv4_hdr, udp_hdr);
ipv4_hdr>hdr_checksum = rte_ipv4_cksum(ipv4_hdr);