How to access the pointer to beginning of Layer 3 header. I was trying to get access to pointer to L3 as shown in following code segment.
for (i = 0; i < nb_rx; i++) {
m = bufs[i];
pkt_len=rte_pktmbuf_pkt_len(bufs[i]);
if (RTE_ETH_IS_IPV4_HDR(m->packet_type))
{
struct rte_ipv4_hdr *ip_hdr;
ip_hdr = rte_pktmbuf_mtod(m, struct rte_ipv4_hdr *);
if(Func1(P1,(unsigned char*)ip_hdr,
pkt_len-sizeof(struct ethhdr),T1)) {
//DO Something
}
}
}
But Func1 is returning false Previously the same code implemented with raw socket is working.
unsigned char *buffer;
if Fun1(P1,(buffer+sizeof(struct ethhdr)),pkt_size-sizeof(struct ethhdr),T1) {
}
@ima, Accessing L2|L3|L4 are easily covered in DPDK examples. For your particular requirement DPDK example, l3fwd
easily covers the scenario. Hence my humble recommendation is to refer to such an application first.
The answer to your query is the way in which you are trying to access the L3 headers is incorrect. To properly access the L3 header you will need to changes from
if (RTE_ETH_IS_IPV4_HDR(m->packet_type))
{
struct rte_ipv4_hdr *ip_hdr;
ip_hdr = rte_pktmbuf_mtod(m, struct rte_ipv4_hdr *);
change to
if (RTE_ETH_IS_IPV4_HDR(m->packet_type))
{
struct rte_ipv4_hdr *ip_hdr;
ip_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *, sizeof(struct rte_ether_hdr));
Note: this is with the assumption there ethertype is IPV4 and does not have VLAN or MPLS in front of it.