Skip to content

Commit dd9ee34

Browse files
suyj-fnstklassert
authored andcommitted
vti4: Fix a ipip packet processing bug in 'IPCOMP' virtual tunnel
Recently we run a network test over ipcomp virtual tunnel.We find that if a ipv4 packet needs fragment, then the peer can't receive it. We deep into the code and find that when packet need fragment the smaller fragment will be encapsulated by ipip not ipcomp. So when the ipip packet goes into xfrm, it's skb->dev is not properly set. The ipv4 reassembly code always set skb'dev to the last fragment's dev. After ipv4 defrag processing, when the kernel rp_filter parameter is set, the skb will be drop by -EXDEV error. This patch adds compatible support for the ipip process in ipcomp virtual tunnel. Signed-off-by: Su Yanjun <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent 12750ab commit dd9ee34

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

net/ipv4/ip_vti.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,33 @@ static int vti_input(struct sk_buff *skb, int nexthdr, __be32 spi,
7474
return 0;
7575
}
7676

77+
static int vti_input_ipip(struct sk_buff *skb, int nexthdr, __be32 spi,
78+
int encap_type)
79+
{
80+
struct ip_tunnel *tunnel;
81+
const struct iphdr *iph = ip_hdr(skb);
82+
struct net *net = dev_net(skb->dev);
83+
struct ip_tunnel_net *itn = net_generic(net, vti_net_id);
84+
85+
tunnel = ip_tunnel_lookup(itn, skb->dev->ifindex, TUNNEL_NO_KEY,
86+
iph->saddr, iph->daddr, 0);
87+
if (tunnel) {
88+
if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb))
89+
goto drop;
90+
91+
XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip4 = tunnel;
92+
93+
skb->dev = tunnel->dev;
94+
95+
return xfrm_input(skb, nexthdr, spi, encap_type);
96+
}
97+
98+
return -EINVAL;
99+
drop:
100+
kfree_skb(skb);
101+
return 0;
102+
}
103+
77104
static int vti_rcv(struct sk_buff *skb)
78105
{
79106
XFRM_SPI_SKB_CB(skb)->family = AF_INET;
@@ -82,6 +109,14 @@ static int vti_rcv(struct sk_buff *skb)
82109
return vti_input(skb, ip_hdr(skb)->protocol, 0, 0);
83110
}
84111

112+
static int vti_rcv_ipip(struct sk_buff *skb)
113+
{
114+
XFRM_SPI_SKB_CB(skb)->family = AF_INET;
115+
XFRM_SPI_SKB_CB(skb)->daddroff = offsetof(struct iphdr, daddr);
116+
117+
return vti_input_ipip(skb, ip_hdr(skb)->protocol, ip_hdr(skb)->saddr, 0);
118+
}
119+
85120
static int vti_rcv_cb(struct sk_buff *skb, int err)
86121
{
87122
unsigned short family;
@@ -435,6 +470,12 @@ static struct xfrm4_protocol vti_ipcomp4_protocol __read_mostly = {
435470
.priority = 100,
436471
};
437472

473+
static struct xfrm_tunnel ipip_handler __read_mostly = {
474+
.handler = vti_rcv_ipip,
475+
.err_handler = vti4_err,
476+
.priority = 0,
477+
};
478+
438479
static int __net_init vti_init_net(struct net *net)
439480
{
440481
int err;
@@ -603,6 +644,13 @@ static int __init vti_init(void)
603644
if (err < 0)
604645
goto xfrm_proto_comp_failed;
605646

647+
msg = "ipip tunnel";
648+
err = xfrm4_tunnel_register(&ipip_handler, AF_INET);
649+
if (err < 0) {
650+
pr_info("%s: cant't register tunnel\n",__func__);
651+
goto xfrm_tunnel_failed;
652+
}
653+
606654
msg = "netlink interface";
607655
err = rtnl_link_register(&vti_link_ops);
608656
if (err < 0)
@@ -612,6 +660,8 @@ static int __init vti_init(void)
612660

613661
rtnl_link_failed:
614662
xfrm4_protocol_deregister(&vti_ipcomp4_protocol, IPPROTO_COMP);
663+
xfrm_tunnel_failed:
664+
xfrm4_tunnel_deregister(&ipip_handler, AF_INET);
615665
xfrm_proto_comp_failed:
616666
xfrm4_protocol_deregister(&vti_ah4_protocol, IPPROTO_AH);
617667
xfrm_proto_ah_failed:

0 commit comments

Comments
 (0)