英文:
Can't print IP-address in DPDK
问题
我正在使用DPDK示例skeleton进行测试,但无法正确打印IP地址。
在rte_eth_rx_burst()
之后,我尝试了以下两种打印方法:
第一种方式,打印结果如下:
SrcIP: 162.38.192.168
DstIP: 250.250.0.0
struct rte_ipv4_hdr *ipv4_hdr = rte_pktmbuf_mtod_offset(bufs[0],
struct rte_ipv4_hdr *, sizeof(struct rte_ether_hdr));
struct in_addr ip_addr = {0};
ip_addr.s_addr = ipv4_hdr->src_addr;
printf("SrcIP: %s\n", inet_ntoa(ip_addr));
ip_addr.s_addr = ipv4_hdr->dst_addr;
printf("DstIP: %s\n", inet_ntoa(ip_addr));
第二种方式,打印结果如下:
Source IP: 168.192.38.162
Dest IP: 0.0.250.250
printf("Source IP: %u.%u.%u.%u\n", (ipv4_hdr->src_addr >> 24) & 0xff,
(ipv4_hdr->src_addr >> 16) & 0xff,
(ipv4_hdr->src_addr >> 8) & 0xff,
ipv4_hdr->src_addr & 0xff);
printf("Dest IP: %u.%u.%u.%u\n", (ipv4_hdr->dst_addr >> 24) & 0xff,
(ipv4_hdr->dst_addr >> 16) & 0xff,
(ipv4_hdr->dst_addr >> 8) & 0xff,
ipv4_hdr->dst_addr & 0xff);
但我从192.168.250.250(源IP)发送ICMP数据包到192.168.250.1(目标IP)。似乎偏移量有问题,但我无法理解如何修复它?但似乎我正在正确地获取指向IP头部的指针。
英文:
I'm playing with DPDK example skeleton, but can't print the right IP addresses
Right after rte_eth_rx_burst()
I tried the following ways of printing:
struct rte_ipv4_hdr *ipv4_hdr = rte_pktmbuf_mtod_offset(bufs[0],
struct rte_ipv4_hdr *, sizeof(struct rte_ether_hdr));
/* 1st way, prints:
SrcIP: 162.38.192.168
DstIP: 250.250.0.0
*/
struct in_addr ip_addr = {0};
ip_addr.s_addr = ipv4_hdr->src_addr;
printf("SrcIP: %s\n", inet_ntoa(ip_addr));
ip_addr.s_addr = ipv4_hdr->dst_addr;
printf("DstIP: %s\n", inet_ntoa(ip_addr));
/* 2nd way, prints:
Source IP: 168.192.38.162
Dest IP: 0.0.250.250
*/
printf("Source IP: %u.%u.%u.%u\n", (ipv4_hdr->src_addr >> 24) & 0xff,
(ipv4_hdr->src_addr >> 16) & 0xff,
(ipv4_hdr->src_addr >> 8) & 0xff,
ipv4_hdr->src_addr & 0xff);
printf("Dest IP: %u.%u.%u.%u\n", (ipv4_hdr->dst_addr >> 24) & 0xff,
(ipv4_hdr->dst_addr >> 16) & 0xff,
(ipv4_hdr->dst_addr >> 8) & 0xff,
ipv4_hdr->dst_addr & 0xff);
But I send ICMP packets from 192.168.250.250 (src IP) to 192.168.250.1 (dst IP). Seems that something wrong with offset, but I can't understand how to fix it? But also seems like I'm using the right way to get a pointer to IP header
答案1
得分: 2
DPDK的示例中没有ARP响应支持*,似乎您的ping主机无法建立L2连接(邻居关系)。因此,您只是尝试从ARP头而不是IPv4头中打印IP地址。由于头部中协议字段的位置恰好相符,一些IP地址部分最终出现在printf输出中。
*- 在DPDK中,必须自己处理所有重要的协议逻辑
P.S. 对于接收到的数据包,您应该分类它们是IPv4、IPv6、ARP还是其他类型,然后进行适当的协议处理。因此,在确保收到了使用IPv4协议的数据包之后,您需要打印IPv4地址。
英文:
The DPDK's skeleton example has no ARP-response support*, and seems that your pinging host couldn't setup L2-connectivity (neighboring). So you just trying to print IP-addresses not from IPv4 header, but from ARP header. And by a happy accident of the location of the protocol fields in headers, some of the IP addresses parst end up in the printf output.
*- in DPDK it's necessary to take care of the implementation of all the vital protocol logic yourself
P.S. also for received packets you should classify if it's IPv4, IPv6, ARP or whatever, then do an appropriate protocol handling. Thus, you need to print IPv4 addresses after making sure that a packet with the IPv4 protocol has arrived
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论