Skip to content

Commit 02dd329

Browse files
netoptimizerAlexei Starovoitov
authored andcommitted
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 Signed-off-by: Jesper Dangaard Brouer <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Acked-by: John Fastabend <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent e817f85 commit 02dd329

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

include/uapi/linux/bpf.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,9 @@ struct xdp_md {
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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4304,6 +4304,25 @@ static u32 xdp_convert_ctx_access(enum bpf_access_type type,
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;

0 commit comments

Comments
 (0)