Skip to content

Commit daaf24c

Browse files
netoptimizerborkmann
authored andcommitted
bpf: simplify xdp_convert_ctx_access for xdp_rxq_info
As pointed out by Daniel Borkmann, using bpf_target_off() is not necessary for xdp_rxq_info when extracting queue_index and ifindex, as these members are u32 like BPF_W. Also fix trivial spelling mistake introduced in same commit. Fixes: 02dd329 ("bpf: finally expose xdp_rxq_info to XDP bpf-programs") Reported-by: Daniel Borkmann <[email protected]> Signed-off-by: Jesper Dangaard Brouer <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent 6bd39bc commit daaf24c

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

include/uapi/linux/bpf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ struct xdp_md {
899899
__u32 data;
900900
__u32 data_end;
901901
__u32 data_meta;
902-
/* Below access go though struct xdp_rxq_info */
902+
/* Below access go through struct xdp_rxq_info */
903903
__u32 ingress_ifindex; /* rxq->dev->ifindex */
904904
__u32 rx_queue_index; /* rxq->queue_index */
905905
};

net/core/filter.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4310,16 +4310,15 @@ static u32 xdp_convert_ctx_access(enum bpf_access_type type,
43104310
si->dst_reg, si->dst_reg,
43114311
offsetof(struct xdp_rxq_info, dev));
43124312
*insn++ = BPF_LDX_MEM(BPF_W, si->dst_reg, si->dst_reg,
4313-
bpf_target_off(struct net_device,
4314-
ifindex, 4, target_size));
4313+
offsetof(struct net_device, ifindex));
43154314
break;
43164315
case offsetof(struct xdp_md, rx_queue_index):
43174316
*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct xdp_buff, rxq),
43184317
si->dst_reg, si->src_reg,
43194318
offsetof(struct xdp_buff, rxq));
43204319
*insn++ = BPF_LDX_MEM(BPF_W, si->dst_reg, si->dst_reg,
4321-
bpf_target_off(struct xdp_rxq_info,
4322-
queue_index, 4, target_size));
4320+
offsetof(struct xdp_rxq_info,
4321+
queue_index));
43234322
break;
43244323
}
43254324

0 commit comments

Comments
 (0)