Skip to content

Commit 4ff2980

Browse files
pigfavorklassert
authored andcommitted
xfrm: fix tunnel model fragmentation behavior
in tunnel mode, if outer interface(ipv4) is less, it is easily to let inner IPV6 mtu be less than 1280. If so, a Packet Too Big ICMPV6 message is received. When send again, packets are fragmentized with 1280, they are still rejected with ICMPV6(Packet Too Big) by xfrmi_xmit2(). According to RFC4213 Section3.2.2: if (IPv4 path MTU - 20) is less than 1280 if packet is larger than 1280 bytes Send ICMPv6 "packet too big" with MTU=1280 Drop packet else Encapsulate but do not set the Don't Fragment flag in the IPv4 header. The resulting IPv4 packet might be fragmented by the IPv4 layer on the encapsulator or by some router along the IPv4 path. endif else if packet is larger than (IPv4 path MTU - 20) Send ICMPv6 "packet too big" with MTU = (IPv4 path MTU - 20). Drop packet. else Encapsulate and set the Don't Fragment flag in the IPv4 header. endif endif Packets should be fragmentized with ipv4 outer interface, so change it. After it is fragemtized with ipv4, there will be double fragmenation. No.48 & No.51 are ipv6 fragment packets, No.48 is double fragmentized, then tunneled with IPv4(No.49& No.50), which obey spec. And received peer cannot decrypt it rightly. 48 2002::10 2002::11 1296(length) IPv6 fragment (off=0 more=y ident=0xa20da5bc nxt=50) 49 0x0000 (0) 2002::10 2002::11 1304 IPv6 fragment (off=0 more=y ident=0x7448042c nxt=44) 50 0x0000 (0) 2002::10 2002::11 200 ESP (SPI=0x00035000) 51 2002::10 2002::11 180 Echo (ping) request 52 0x56dc 2002::10 2002::11 248 IPv6 fragment (off=1232 more=n ident=0xa20da5bc nxt=50) xfrm6_noneed_fragment has fixed above issues. Finally, it acted like below: 1 0x6206 192.168.1.138 192.168.1.1 1316 Fragmented IP protocol (proto=Encap Security Payload 50, off=0, ID=6206) [Reassembled in #2] 2 0x6206 2002::10 2002::11 88 IPv6 fragment (off=0 more=y ident=0x1f440778 nxt=50) 3 0x0000 2002::10 2002::11 248 ICMPv6 Echo (ping) request Signed-off-by: Lina Wang <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent 519ca6f commit 4ff2980

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

net/ipv6/xfrm6_output.c

+16
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ static int __xfrm6_output_finish(struct net *net, struct sock *sk, struct sk_buf
4545
return xfrm_output(sk, skb);
4646
}
4747

48+
static int xfrm6_noneed_fragment(struct sk_buff *skb)
49+
{
50+
struct frag_hdr *fh;
51+
u8 prevhdr = ipv6_hdr(skb)->nexthdr;
52+
53+
if (prevhdr != NEXTHDR_FRAGMENT)
54+
return 0;
55+
fh = (struct frag_hdr *)(skb->data + sizeof(struct ipv6hdr));
56+
if (fh->nexthdr == NEXTHDR_ESP || fh->nexthdr == NEXTHDR_AUTH)
57+
return 1;
58+
return 0;
59+
}
60+
4861
static int __xfrm6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
4962
{
5063
struct dst_entry *dst = skb_dst(skb);
@@ -73,6 +86,9 @@ static int __xfrm6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
7386
xfrm6_local_rxpmtu(skb, mtu);
7487
kfree_skb(skb);
7588
return -EMSGSIZE;
89+
} else if (toobig && xfrm6_noneed_fragment(skb)) {
90+
skb->ignore_df = 1;
91+
goto skip_frag;
7692
} else if (!skb->ignore_df && toobig && skb->sk) {
7793
xfrm_local_error(skb, mtu);
7894
kfree_skb(skb);

net/xfrm/xfrm_interface.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,10 @@ xfrmi_xmit2(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)
304304
if (mtu < IPV6_MIN_MTU)
305305
mtu = IPV6_MIN_MTU;
306306

307-
icmpv6_ndo_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
307+
if (skb->len > 1280)
308+
icmpv6_ndo_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
309+
else
310+
goto xmit;
308311
} else {
309312
if (!(ip_hdr(skb)->frag_off & htons(IP_DF)))
310313
goto xmit;

0 commit comments

Comments
 (0)