Skip to content

Commit f6e2711

Browse files
committed
net: Add a xfrm validate function to validate_xmit_skb
When we do IPsec offloading, we need a fallback for packets that were targeted to be IPsec offloaded but rerouted to a device that does not support IPsec offload. For that we add a function that checks the offloading features of the sending device and and flags the requirement of a fallback before it calls the IPsec output function. The IPsec output function adds the IPsec trailer and does encryption if needed. Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
1 parent b3859c8 commit f6e2711

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

‎include/net/xfrm.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,6 +1862,7 @@ static inline struct xfrm_offload *xfrm_offload(struct sk_buff *skb)
18621862

18631863
#ifdef CONFIG_XFRM_OFFLOAD
18641864
void __net_init xfrm_dev_init(void);
1865+
int validate_xmit_xfrm(struct sk_buff *skb, netdev_features_t features);
18651866
int xfrm_dev_state_add(struct net *net, struct xfrm_state *x,
18661867
struct xfrm_user_offload *xuo);
18671868
bool xfrm_dev_offload_ok(struct sk_buff *skb, struct xfrm_state *x);
@@ -1890,6 +1891,11 @@ static inline void __net_init xfrm_dev_init(void)
18901891
{
18911892
}
18921893

1894+
static inline int validate_xmit_xfrm(struct sk_buff *skb, netdev_features_t features)
1895+
{
1896+
return 0;
1897+
}
1898+
18931899
static inline int xfrm_dev_state_add(struct net *net, struct xfrm_state *x, struct xfrm_user_offload *xuo)
18941900
{
18951901
return 0;

‎net/core/dev.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2972,6 +2972,9 @@ static struct sk_buff *validate_xmit_skb(struct sk_buff *skb, struct net_device
29722972
__skb_linearize(skb))
29732973
goto out_kfree_skb;
29742974

2975+
if (validate_xmit_xfrm(skb, features))
2976+
goto out_kfree_skb;
2977+
29752978
/* If packet is not checksummed and device does not
29762979
* support checksumming for this protocol, complete
29772980
* checksumming here.

‎net/xfrm/xfrm_device.c‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,35 @@
2222
#include <net/xfrm.h>
2323
#include <linux/notifier.h>
2424

25+
int validate_xmit_xfrm(struct sk_buff *skb, netdev_features_t features)
26+
{
27+
int err;
28+
struct xfrm_state *x;
29+
struct xfrm_offload *xo = xfrm_offload(skb);
30+
31+
if (skb_is_gso(skb))
32+
return 0;
33+
34+
if (xo) {
35+
x = skb->sp->xvec[skb->sp->len - 1];
36+
if (xo->flags & XFRM_GRO || x->xso.flags & XFRM_OFFLOAD_INBOUND)
37+
return 0;
38+
39+
x->outer_mode->xmit(x, skb);
40+
41+
err = x->type_offload->xmit(x, skb, features);
42+
if (err) {
43+
XFRM_INC_STATS(xs_net(x), LINUX_MIB_XFRMOUTSTATEPROTOERROR);
44+
return err;
45+
}
46+
47+
skb_push(skb, skb->data - skb_mac_header(skb));
48+
}
49+
50+
return 0;
51+
}
52+
EXPORT_SYMBOL_GPL(validate_xmit_xfrm);
53+
2554
int xfrm_dev_state_add(struct net *net, struct xfrm_state *x,
2655
struct xfrm_user_offload *xuo)
2756
{

0 commit comments

Comments
 (0)