Skip to content

Commit fc37987

Browse files
LorenzoBianconiAlexei Starovoitov
authored andcommitted
xdp: Introduce xdp_convert_frame_to_buff utility routine
Introduce xdp_convert_frame_to_buff utility routine to initialize xdp_buff fields from xdp_frames ones. Rely on xdp_convert_frame_to_buff in veth xdp code. Suggested-by: Jesper Dangaard Brouer <[email protected]> Signed-off-by: Lorenzo Bianconi <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Jesper Dangaard Brouer <[email protected]> Link: https://lore.kernel.org/bpf/87acf133073c4b2d4cbb8097e8c2480c0a0fac32.1590698295.git.lorenzo@kernel.org
1 parent c48a24f commit fc37987

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

drivers/net/veth.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -575,11 +575,7 @@ static struct sk_buff *veth_xdp_rcv_one(struct veth_rq *rq,
575575
struct xdp_buff xdp;
576576
u32 act;
577577

578-
xdp.data_hard_start = hard_start;
579-
xdp.data = frame->data;
580-
xdp.data_end = frame->data + frame->len;
581-
xdp.data_meta = frame->data - frame->metasize;
582-
xdp.frame_sz = frame->frame_sz;
578+
xdp_convert_frame_to_buff(frame, &xdp);
583579
xdp.rxq = &rq->xdp_rxq;
584580

585581
act = bpf_prog_run_xdp(xdp_prog, &xdp);

include/net/xdp.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ void xdp_warn(const char *msg, const char *func, const int line);
111111

112112
struct xdp_frame *xdp_convert_zc_to_xdp_frame(struct xdp_buff *xdp);
113113

114+
static inline
115+
void xdp_convert_frame_to_buff(struct xdp_frame *frame, struct xdp_buff *xdp)
116+
{
117+
xdp->data_hard_start = frame->data - frame->headroom - sizeof(*frame);
118+
xdp->data = frame->data;
119+
xdp->data_end = frame->data + frame->len;
120+
xdp->data_meta = frame->data - frame->metasize;
121+
xdp->frame_sz = frame->frame_sz;
122+
}
123+
114124
/* Convert xdp_buff to xdp_frame */
115125
static inline
116126
struct xdp_frame *convert_to_xdp_frame(struct xdp_buff *xdp)

0 commit comments

Comments
 (0)