Skip to content

Commit a2c2998

Browse files
LorenzoBianconiborkmann
authored andcommitted
net, xdp: Introduce xdp_build_skb_from_frame utility routine
Introduce xdp_build_skb_from_frame utility routine to build the skb from xdp_frame. Respect to __xdp_build_skb_from_frame, xdp_build_skb_from_frame will allocate the skb object. Rely on xdp_build_skb_from_frame in veth driver. Introduce missing xdp metadata support in veth_xdp_rcv_one routine. Add missing metadata support in veth_xdp_rcv_one(). Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Reviewed-by: Toshiaki Makita <toshiaki.makita1@gmail.com> Acked-by: Jesper Dangaard Brouer <brouer@redhat.com> Link: https://lore.kernel.org/bpf/94ade9e853162ae1947941965193190da97457bc.1610475660.git.lorenzo@kernel.org
1 parent e753e92 commit a2c2998

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

drivers/net/veth.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -567,16 +567,10 @@ static struct sk_buff *veth_xdp_rcv_one(struct veth_rq *rq,
567567
struct veth_xdp_tx_bq *bq,
568568
struct veth_stats *stats)
569569
{
570-
void *hard_start = frame->data - frame->headroom;
571-
int len = frame->len, delta = 0;
572570
struct xdp_frame orig_frame;
573571
struct bpf_prog *xdp_prog;
574-
unsigned int headroom;
575572
struct sk_buff *skb;
576573

577-
/* bpf_xdp_adjust_head() assures BPF cannot access xdp_frame area */
578-
hard_start -= sizeof(struct xdp_frame);
579-
580574
rcu_read_lock();
581575
xdp_prog = rcu_dereference(rq->xdp_prog);
582576
if (likely(xdp_prog)) {
@@ -590,8 +584,8 @@ static struct sk_buff *veth_xdp_rcv_one(struct veth_rq *rq,
590584

591585
switch (act) {
592586
case XDP_PASS:
593-
delta = frame->data - xdp.data;
594-
len = xdp.data_end - xdp.data;
587+
if (xdp_update_frame_from_buff(&xdp, frame))
588+
goto err_xdp;
595589
break;
596590
case XDP_TX:
597591
orig_frame = *frame;
@@ -629,18 +623,12 @@ static struct sk_buff *veth_xdp_rcv_one(struct veth_rq *rq,
629623
}
630624
rcu_read_unlock();
631625

632-
headroom = sizeof(struct xdp_frame) + frame->headroom - delta;
633-
skb = veth_build_skb(hard_start, headroom, len, frame->frame_sz);
626+
skb = xdp_build_skb_from_frame(frame, rq->dev);
634627
if (!skb) {
635628
xdp_return_frame(frame);
636629
stats->rx_drops++;
637-
goto err;
638630
}
639631

640-
xdp_release_frame(frame);
641-
xdp_scrub_frame(frame);
642-
skb->protocol = eth_type_trans(skb, rq->dev);
643-
err:
644632
return skb;
645633
err_xdp:
646634
rcu_read_unlock();

include/net/xdp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ struct xdp_frame *xdp_convert_zc_to_xdp_frame(struct xdp_buff *xdp);
167167
struct sk_buff *__xdp_build_skb_from_frame(struct xdp_frame *xdpf,
168168
struct sk_buff *skb,
169169
struct net_device *dev);
170+
struct sk_buff *xdp_build_skb_from_frame(struct xdp_frame *xdpf,
171+
struct net_device *dev);
170172

171173
static inline
172174
void xdp_convert_frame_to_buff(struct xdp_frame *frame, struct xdp_buff *xdp)

net/core/xdp.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,3 +557,18 @@ struct sk_buff *__xdp_build_skb_from_frame(struct xdp_frame *xdpf,
557557
return skb;
558558
}
559559
EXPORT_SYMBOL_GPL(__xdp_build_skb_from_frame);
560+
561+
struct sk_buff *xdp_build_skb_from_frame(struct xdp_frame *xdpf,
562+
struct net_device *dev)
563+
{
564+
struct sk_buff *skb;
565+
566+
skb = kmem_cache_alloc(skbuff_head_cache, GFP_ATOMIC);
567+
if (unlikely(!skb))
568+
return NULL;
569+
570+
memset(skb, 0, offsetof(struct sk_buff, tail));
571+
572+
return __xdp_build_skb_from_frame(xdpf, skb, dev);
573+
}
574+
EXPORT_SYMBOL_GPL(xdp_build_skb_from_frame);

0 commit comments

Comments
 (0)