History

bpf: finally expose xdp_rxq_info to XDP bpf-programs

Now all XDP driver have been updated to setup xdp_rxq_info and assign this to xdp_buff->rxq. Thus, it is now safe to enable access to some of the xdp_rxq_info struct members. This patch extend xdp_md and expose UAPI to userspace for ingress_ifindex and rx_queue_index. Access happens via bpf instruction rewrite, that load data directly from struct xdp_rxq_info. * ingress_ifindex map to xdp_rxq_info->dev->ifindex * rx_queue_index map to xdp_rxq_info->queue_index

Jesper Dangaard Brouer committed 8 years ago

Commit 02dd3291 parent e817f852 files · +22 −0Browse files

Unified · Split

2 files
  1. include/uapi/linux/bpf.h +3 −0
  2. net/core/filter.c +19 −0
include/uapi/linux/bpf.h+3−0
@@ -899,6 +899,9 @@ struct xdp_md { · 898 unmodified lines
899899 __u32 data;
900900 __u32 data_end;
901901 __u32 data_meta;
902+ /* Below access go though struct xdp_rxq_info */
903+ __u32 ingress_ifindex; /* rxq->dev->ifindex */
904+ __u32 rx_queue_index; /* rxq->queue_index */
902905 };
903906
904907 enum sk_action {
net/core/filter.c+19−0
@@ -4304,6 +4304,25 @@ static u32 xdp_convert_ctx_access(enum bpf_access_type type, · 4303 unmodified lines
43044304 si->dst_reg, si->src_reg,
43054305 offsetof(struct xdp_buff, data_end));
43064306 break;
4307+ case offsetof(struct xdp_md, ingress_ifindex):
4308+ *insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct xdp_buff, rxq),
4309+ si->dst_reg, si->src_reg,
4310+ offsetof(struct xdp_buff, rxq));
4311+ *insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct xdp_rxq_info, dev),
4312+ si->dst_reg, si->dst_reg,
4313+ offsetof(struct xdp_rxq_info, dev));
4314+ *insn++ = BPF_LDX_MEM(BPF_W, si->dst_reg, si->dst_reg,
4315+ bpf_target_off(struct net_device,
4316+ ifindex, 4, target_size));
4317+ break;
4318+ case offsetof(struct xdp_md, rx_queue_index):
4319+ *insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct xdp_buff, rxq),
4320+ si->dst_reg, si->src_reg,
4321+ offsetof(struct xdp_buff, rxq));
4322+ *insn++ = BPF_LDX_MEM(BPF_W, si->dst_reg, si->dst_reg,
4323+ bpf_target_off(struct xdp_rxq_info,
4324+ queue_index, 4, target_size));
4325+ break;
43074326 }
43084327
43094328 return insn - insn_buf;