So I have this code in my ebpf program and so on my system struct xdp_md
does exists.
struct xdp_md {
__u32 data;
__u32 data_end;
__u32 data_meta;
/* Below access go through struct xdp_rxq_info */
__u32 ingress_ifindex; /* rxq->dev->ifindex */
__u32 rx_queue_index; /* rxq->queue_index */
__u32 egress_ifindex; /* txq->dev->ifindex */
};
the above struct is inside /usr/include/linux/bpf.h file
So u can see egree_ifindex does exists. But when I do compile it says
-O2 -emit-llvm -c -g -o af_xdp_kern.ll af_xdp_kern.c
af_xdp_kern.c:49:22: error: no member named 'egress_ifindex' in 'struct xdp_md'; did you mean 'ingress_ifindex'?
int index = ctx->egress_ifindex;
^~~~~~~~~~~~~~
ingress_ifindex
../headers/linux/bpf.h:2861:8: note: 'ingress_ifindex' declared here
__u32 ingress_ifindex; /* rxq->dev->ifindex */
^
1 error generated.
following is the my code in ebpf program
SEC("xdp_devmap_xmit")
int xdp_sock_prog(struct xdp_md *ctx)
{
int index = ctx->egress_ifindex
__u32 *pkt_count;
void *data = (void *)(long)ctx->data;
void *data_end = (void *)(long)ctx->data_end;
struct ethhdr *eth = data;
struct share_me me;
if ((void *)eth + sizeof(*eth) <= data_end)
{
struct iphdr *ip = data + sizeof(*eth);
//me.dest_ip=ip;
if(((void *)ip+sizeof(*ip))<=data_end)
{
struct iphdr ip_temp=(struct iphdr)*ip;
memcpy(&me.dest_ip,&ip_temp,sizeof(ip_temp));
bpf_map_lookup_elem(&ip_map, &index);
bpf_map_update_elem(&ip_map,&index,&me,0);
if ((void *)ip + sizeof(*ip) <= data_end)
{
if (ip->protocol == IPPROTO_UDP)
{
struct udphdr *udp = (void *)ip + sizeof(*ip);
if ((void *)udp + sizeof(*udp) <= data_end)
{
//u64 value = htons(udp->dest);
//counter.increment(value);
}
}
}
}
}
pkt_count = bpf_map_lookup_elem(&xdp_stats_map, &index);
if (pkt_count) {
/* We pass every other packet */
if ((*pkt_count)++ & 1)
return XDP_DROP;
}
/* A set entry here means that the correspnding queue_id
* has an active AF_XDP socket bound to it. */
if (bpf_map_lookup_elem(&xsks_map, &index))
return bpf_redirect_map(&xsks_map, index, 0);
return XDP_PASS;
}
Can anyone guide me what exactly I need to to get iphdr (for egress packets) .is it possible?