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
Unified · Split
| @@ -899,6 +899,9 @@ struct xdp_md { · 898 unmodified lines | |||
| 899 | __u32 data; | 899 | __u32 data; |
| 900 | __u32 data_end; | 900 | __u32 data_end; |
| 901 | __u32 data_meta; | 901 | __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 */ | ||
| 902 | }; | 905 | }; |
| 903 | 906 | ||
| 904 | enum sk_action { | 907 | enum sk_action { |
| @@ -4304,6 +4304,25 @@ static u32 xdp_convert_ctx_access(enum bpf_access_type type, · 4303 unmodified lines | |||
| 4304 | si->dst_reg, si->src_reg, | 4304 | si->dst_reg, si->src_reg, |
| 4305 | offsetof(struct xdp_buff, data_end)); | 4305 | offsetof(struct xdp_buff, data_end)); |
| 4306 | break; | 4306 | 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; | ||
| 4307 | } | 4326 | } |
| 4308 | 4327 | ||
| 4309 | return insn - insn_buf; | 4328 | return insn - insn_buf; |