]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
xdp: Introduce xdp_convert_frame_to_buff utility routine
authorLorenzo Bianconi <lorenzo@kernel.org>
Thu, 28 May 2020 20:47:28 +0000 (22:47 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 1 Jun 2020 22:02:53 +0000 (15:02 -0700)
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 <brouer@redhat.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>
Link: https://lore.kernel.org/bpf/87acf133073c4b2d4cbb8097e8c2480c0a0fac32.1590698295.git.lorenzo@kernel.org
drivers/net/veth.c
include/net/xdp.h

index b586d2fa555151a31473d405616ac6aea1af759c..fb5c17361f6439c48e13beced9327bd1d621cb77 100644 (file)
@@ -575,11 +575,7 @@ static struct sk_buff *veth_xdp_rcv_one(struct veth_rq *rq,
                struct xdp_buff xdp;
                u32 act;
 
-               xdp.data_hard_start = hard_start;
-               xdp.data = frame->data;
-               xdp.data_end = frame->data + frame->len;
-               xdp.data_meta = frame->data - frame->metasize;
-               xdp.frame_sz = frame->frame_sz;
+               xdp_convert_frame_to_buff(frame, &xdp);
                xdp.rxq = &rq->xdp_rxq;
 
                act = bpf_prog_run_xdp(xdp_prog, &xdp);
index d540229594910294e8e8a539659e2d6089ca8bfe..db5c2c687f48fdecd1b948be2ac4e09ecf9c3337 100644 (file)
@@ -111,6 +111,16 @@ void xdp_warn(const char *msg, const char *func, const int line);
 
 struct xdp_frame *xdp_convert_zc_to_xdp_frame(struct xdp_buff *xdp);
 
+static inline
+void xdp_convert_frame_to_buff(struct xdp_frame *frame, struct xdp_buff *xdp)
+{
+       xdp->data_hard_start = frame->data - frame->headroom - sizeof(*frame);
+       xdp->data = frame->data;
+       xdp->data_end = frame->data + frame->len;
+       xdp->data_meta = frame->data - frame->metasize;
+       xdp->frame_sz = frame->frame_sz;
+}
+
 /* Convert xdp_buff to xdp_frame */
 static inline
 struct xdp_frame *convert_to_xdp_frame(struct xdp_buff *xdp)