无法在DPDK中打印IP地址。

huangapple go评论110阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年4月17日 06:13:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76030586.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定