Skip to content

Commit 7c49747

Browse files
jasowangdavem330
authored andcommitted
net: export some generic xdp helpers
This patch tries to export some generic xdp helpers to drivers. This can let driver to do XDP for a specific skb. This is useful for the case when the packet is hard to be processed at page level directly (e.g jumbo/GSO frame). With this patch, there's no need for driver to forbid the XDP set when configuration is not suitable. Instead, it can defer the XDP for packets that is hard to be processed directly after skb is created. Signed-off-by: Jason Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 66ccbc9 commit 7c49747

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

include/linux/netdevice.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3243,6 +3243,8 @@ static inline void dev_consume_skb_any(struct sk_buff *skb)
32433243
__dev_kfree_skb_any(skb, SKB_REASON_CONSUMED);
32443244
}
32453245

3246+
void generic_xdp_tx(struct sk_buff *skb, struct bpf_prog *xdp_prog);
3247+
int do_xdp_generic(struct bpf_prog *xdp_prog, struct sk_buff *skb);
32463248
int netif_rx(struct sk_buff *skb);
32473249
int netif_rx_ni(struct sk_buff *skb);
32483250
int netif_receive_skb(struct sk_buff *skb);

net/core/dev.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3919,7 +3919,7 @@ static u32 netif_receive_generic_xdp(struct sk_buff *skb,
39193919
/* When doing generic XDP we have to bypass the qdisc layer and the
39203920
* network taps in order to match in-driver-XDP behavior.
39213921
*/
3922-
static void generic_xdp_tx(struct sk_buff *skb, struct bpf_prog *xdp_prog)
3922+
void generic_xdp_tx(struct sk_buff *skb, struct bpf_prog *xdp_prog)
39233923
{
39243924
struct net_device *dev = skb->dev;
39253925
struct netdev_queue *txq;
@@ -3940,13 +3940,12 @@ static void generic_xdp_tx(struct sk_buff *skb, struct bpf_prog *xdp_prog)
39403940
kfree_skb(skb);
39413941
}
39423942
}
3943+
EXPORT_SYMBOL_GPL(generic_xdp_tx);
39433944

39443945
static struct static_key generic_xdp_needed __read_mostly;
39453946

3946-
static int do_xdp_generic(struct sk_buff *skb)
3947+
int do_xdp_generic(struct bpf_prog *xdp_prog, struct sk_buff *skb)
39473948
{
3948-
struct bpf_prog *xdp_prog = rcu_dereference(skb->dev->xdp_prog);
3949-
39503949
if (xdp_prog) {
39513950
u32 act = netif_receive_generic_xdp(skb, xdp_prog);
39523951
int err;
@@ -3971,6 +3970,7 @@ static int do_xdp_generic(struct sk_buff *skb)
39713970
kfree_skb(skb);
39723971
return XDP_DROP;
39733972
}
3973+
EXPORT_SYMBOL_GPL(do_xdp_generic);
39743974

39753975
static int netif_rx_internal(struct sk_buff *skb)
39763976
{
@@ -3981,7 +3981,8 @@ static int netif_rx_internal(struct sk_buff *skb)
39813981
trace_netif_rx(skb);
39823982

39833983
if (static_key_false(&generic_xdp_needed)) {
3984-
int ret = do_xdp_generic(skb);
3984+
int ret = do_xdp_generic(rcu_dereference(skb->dev->xdp_prog),
3985+
skb);
39853986

39863987
/* Consider XDP consuming the packet a success from
39873988
* the netdev point of view we do not want to count
@@ -4502,7 +4503,8 @@ static int netif_receive_skb_internal(struct sk_buff *skb)
45024503
rcu_read_lock();
45034504

45044505
if (static_key_false(&generic_xdp_needed)) {
4505-
int ret = do_xdp_generic(skb);
4506+
int ret = do_xdp_generic(rcu_dereference(skb->dev->xdp_prog),
4507+
skb);
45064508

45074509
if (ret != XDP_PASS) {
45084510
rcu_read_unlock();

0 commit comments

Comments
 (0)