Skip to content

Commit 5eddd76

Browse files
Alexandre Cassenklassert
authored andcommitted
xfrm: fix tunnel mode TX datapath in packet offload mode
Packets that match the output xfrm policy are delivered to the netstack. In IPsec packet mode for tunnel mode, the HW is responsible for building the hard header and outer IP header. In such a situation, the inner header may refer to a network that is not directly reachable by the host, resulting in a failed neighbor resolution. The packet is then dropped. xfrm policy defines the netdevice to use for xmit so we can send packets directly to it. Makes direct xmit exclusive to tunnel mode, since some rules may apply in transport mode. Fixes: f8a70af ("xfrm: add TX datapath support for IPsec packet offload mode") Signed-off-by: Alexandre Cassen <acassen@corp.free.fr> Signed-off-by: Leon Romanovsky <leonro@nvidia.com> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
1 parent a130069 commit 5eddd76

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

net/xfrm/xfrm_output.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,40 @@ int xfrm_output_resume(struct sock *sk, struct sk_buff *skb, int err)
612612
}
613613
EXPORT_SYMBOL_GPL(xfrm_output_resume);
614614

615+
static int xfrm_dev_direct_output(struct sock *sk, struct xfrm_state *x,
616+
struct sk_buff *skb)
617+
{
618+
struct dst_entry *dst = skb_dst(skb);
619+
struct net *net = xs_net(x);
620+
int err;
621+
622+
dst = skb_dst_pop(skb);
623+
if (!dst) {
624+
XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR);
625+
kfree_skb(skb);
626+
return -EHOSTUNREACH;
627+
}
628+
skb_dst_set(skb, dst);
629+
nf_reset_ct(skb);
630+
631+
err = skb_dst(skb)->ops->local_out(net, sk, skb);
632+
if (unlikely(err != 1)) {
633+
kfree_skb(skb);
634+
return err;
635+
}
636+
637+
/* In transport mode, network destination is
638+
* directly reachable, while in tunnel mode,
639+
* inner packet network may not be. In packet
640+
* offload type, HW is responsible for hard
641+
* header packet mangling so directly xmit skb
642+
* to netdevice.
643+
*/
644+
skb->dev = x->xso.dev;
645+
__skb_push(skb, skb->dev->hard_header_len);
646+
return dev_queue_xmit(skb);
647+
}
648+
615649
static int xfrm_output2(struct net *net, struct sock *sk, struct sk_buff *skb)
616650
{
617651
return xfrm_output_resume(sk, skb, 1);
@@ -735,6 +769,13 @@ int xfrm_output(struct sock *sk, struct sk_buff *skb)
735769
return -EHOSTUNREACH;
736770
}
737771

772+
/* Exclusive direct xmit for tunnel mode, as
773+
* some filtering or matching rules may apply
774+
* in transport mode.
775+
*/
776+
if (x->props.mode == XFRM_MODE_TUNNEL)
777+
return xfrm_dev_direct_output(sk, x, skb);
778+
738779
return xfrm_output_resume(sk, skb, 0);
739780
}
740781

0 commit comments

Comments
 (0)