如何访问通过DPDK接收到的数据包中的各个层?

问题描述

我在dpdk-stable-18.11.9上运行Ubuntu 18.04。我使用rte_eth_rx_burst(port_id,queue_id,pkts_burst,MAX_PKT_BURST)函数来接收数据包。

我想访问数据包的各种标头,即eth_hdr+Ip_hdr+udp_hdr+udp_payload获取有效的pkts_burst[0]

例如,在Wireshark中,我可以通过pkts_burst [0]向您展示我的需求。

enter image description here

在1512 BYTE ARRAY上的所有1512 BYTE象红色部分插入:

enter image description here

我该怎么做?

解决方法

使用How do we can Access to Payload of Received Packets in DPDK 18.11.9作为参考代码,直到IPv4标头访问有效负载。然后通过

访问UDP层
#include <rte_udp.h>

内部过程功能

struct udp_hdr *udp = (struct udp_hdr *)((unsigned char *)ipv4_hdr +                                      
 sizeof(struct ipv4_hdr));
unsigned char *paylaod = (unsigned char *) (udp + 1);

注意:UDP标头和UDP有效负载就在IP标头之后。

P.S。已经花了单独的Skype电话来解释和确保信息共享。