Skip to contentSkip to conversation

ip6_gre: Fix MTU setting

PATCH In review Tom Herbert 2 participants 6 messages May 9, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ip6_gre: Fix MTU setting

In ip6gre_tnl_link_config set t->tun_len and t->hlen correctly for the configuration. For hard_header_len and mtu calculation include IPv6 header and encapsulation overhead.

In ip6gre_tunnel_init_common set t->tun_len and t->hlen correctly for the configuration. Revert to setting hard_header_len instead of needed_headroom.

Tested:

./ip link add name tun8 type ip6gretap remote \
2401:db00:20:911a:face:0:27:0 local \
2401:db00:20:911a:face:0:25:0 ttl 225

Gives MTU of 1434. That is equal to 1500 - 40 - 14 - 4 - 8.

./ip link add name tun8 type ip6gretap remote \
2401:db00:20:911a:face:0:27:0 local \
2401:db00:20:911a:face:0:25:0 ttl 225 okey 123

Gives MTU of 1430. That is equal to 1500 - 40 - 14 - 4 - 8 - 4.

---
 net/ipv6/ip6_gre.c | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)
net/ipv6/ip6_gre.c +13 -16
index 47b671a..6d0aa94 100644
@@ -700,7 +700,7 @@ static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu)
 	struct net_device *dev = t->dev;
 	struct __ip6_tnl_parm *p = &t->parms;
 	struct flowi6 *fl6 = &t->fl.u.ip6;
-	int addend = sizeof(struct ipv6hdr) + 4;
+	int t_hlen;
 
 	if (dev->type != ARPHRD_ETHER) {
 		memcpy(dev->dev_addr, &p->laddr, sizeof(struct in6_addr));
@@ -727,16 +727,11 @@ static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu)
 	else
 		dev->flags &= ~IFF_POINTOPOINT;
 
-	/* Precalculate GRE options length */
-	if (t->parms.o_flags&(GRE_CSUM|GRE_KEY|GRE_SEQ)) {
-		if (t->parms.o_flags&GRE_CSUM)
-			addend += 4;
-		if (t->parms.o_flags&GRE_KEY)
-			addend += 4;
-		if (t->parms.o_flags&GRE_SEQ)
-			addend += 4;
-	}
-	t->hlen = addend;
+	t->tun_hlen = gre_calc_hlen(t->parms.o_flags);
+
+	t->hlen = t->tun_hlen;
+
+	t_hlen = t->hlen + sizeof(struct ipv6hdr);
 
 	if (p->flags & IP6_TNL_F_CAP_XMIT) {
 		int strict = (ipv6_addr_type(&p->raddr) &
@@ -750,10 +745,11 @@ static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu)
 			return;
 
 		if (rt->dst.dev) {
-			dev->hard_header_len = rt->dst.dev->hard_header_len + addend;
+			dev->hard_header_len = rt->dst.dev->hard_header_len +
+					       t_hlen;
 
 			if (set_mtu) {
-				dev->mtu = rt->dst.dev->mtu - addend;
+				dev->mtu = rt->dst.dev->mtu - t_hlen;
 				if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
 					dev->mtu -= 8;
 				if (dev->type == ARPHRD_ETHER)
@@ -1027,11 +1023,12 @@ static int ip6gre_tunnel_init_common(struct net_device *dev)
 
 	tunnel->tun_hlen = gre_calc_hlen(tunnel->parms.o_flags);
 
-	t_hlen = tunnel->hlen + sizeof(struct ipv6hdr);
+	tunnel->hlen = tunnel->tun_hlen;
 
-	dev->needed_headroom	= LL_MAX_HEADER + t_hlen + 4;
-	dev->mtu		= ETH_DATA_LEN - t_hlen - 4;
+	t_hlen = tunnel->hlen + sizeof(struct ipv6hdr);
 
+	dev->hard_header_len = LL_MAX_HEADER + t_hlen;
+	dev->mtu = ETH_DATA_LEN - t_hlen;
 	if (!(tunnel->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
 		dev->mtu -= 8;
 
Signature · 1 line
2.8.0.rc2
Tested-by on v1 1/1
#1 lore raw
Quoted 16 lines · Tom Herbert

In ip6gre_tnl_link_config set t->tun_len and t->hlen correctly for the configuration. For hard_header_len and mtu calculation include IPv6 header and encapsulation overhead.

In ip6gre_tunnel_init_common set t->tun_len and t->hlen correctly for the configuration. Revert to setting hard_header_len instead of needed_headroom.

Tested:

./ip link add name tun8 type ip6gretap remote \
2401:db00:20:911a:face:0:27:0 local \
2401:db00:20:911a:face:0:25:0 ttl 225

Gives MTU of 1434. That is equal to 1500 - 40 - 14 - 4 - 8.

Quoted 7 lines

./ip link add name tun8 type ip6gretap remote \
2401:db00:20:911a:face:0:27:0 local \
2401:db00:20:911a:face:0:25:0 ttl 225 okey 123

Gives MTU of 1430. That is equal to 1500 - 40 - 14 - 4 - 8 - 4.

So this gives me the correct result now. However we still need patch 3 / 11 from the set you submitted next week in order to be able to even transmit because the flags are otherwise mangled.

#2 lore raw
Quoted 23 lines · Alexander Duyck
Quoted 22 lines · Tom Herbert

In ip6gre_tnl_link_config set t->tun_len and t->hlen correctly for the configuration. For hard_header_len and mtu calculation include IPv6 header and encapsulation overhead.

In ip6gre_tunnel_init_common set t->tun_len and t->hlen correctly for the configuration. Revert to setting hard_header_len instead of needed_headroom.

Tested:

./ip link add name tun8 type ip6gretap remote \
2401:db00:20:911a:face:0:27:0 local \
2401:db00:20:911a:face:0:25:0 ttl 225

Gives MTU of 1434. That is equal to 1500 - 40 - 14 - 4 - 8.

./ip link add name tun8 type ip6gretap remote \
2401:db00:20:911a:face:0:27:0 local \
2401:db00:20:911a:face:0:25:0 ttl 225 okey 123

Gives MTU of 1430. That is equal to 1500 - 40 - 14 - 4 - 8 - 4.

Quoted 7 lines
Quoted 1 line

So this gives me the correct result now. However we still need patch 3 / 11 from the set you submitted next week in order to be able to even transmit because the flags are otherwise mangled.

Okay, I'll repost the flags patch as a standalone. Do you have any other issues then in this path?

Tom

#3 lore raw
Quoted 27 lines · Tom Herbert
Quoted 25 lines · Alexander Duyck
Quoted 23 lines · Tom Herbert

In ip6gre_tnl_link_config set t->tun_len and t->hlen correctly for the configuration. For hard_header_len and mtu calculation include IPv6 header and encapsulation overhead.

In ip6gre_tunnel_init_common set t->tun_len and t->hlen correctly for the configuration. Revert to setting hard_header_len instead of needed_headroom.

Tested:

./ip link add name tun8 type ip6gretap remote \
2401:db00:20:911a:face:0:27:0 local \
2401:db00:20:911a:face:0:25:0 ttl 225

Gives MTU of 1434. That is equal to 1500 - 40 - 14 - 4 - 8.

./ip link add name tun8 type ip6gretap remote \
2401:db00:20:911a:face:0:27:0 local \
2401:db00:20:911a:face:0:25:0 ttl 225 okey 123

Gives MTU of 1430. That is equal to 1500 - 40 - 14 - 4 - 8 - 4.

Quoted 8 lines
Quoted 5 lines

So this gives me the correct result now. However we still need patch 3 / 11 from the set you submitted next week in order to be able to even transmit because the flags are otherwise mangled.

Okay, I'll repost the flags patch as a standalone. Do you have any other issues then in this path?

This piece no.

Like I said in the other email I did find two other issues. First in __gre6_xmit I think you want to set the inner protocol to "protocol", not "proto". Second is the issue with ip6_tnl_xmit stomping on skb->transport_header. The second one is the big one that is blocking things badly right now. That is the one that keeps me from doing anything with any sort of offload as the headers are jumping around out of order with the outer transport header having an offset that is further in than the inner mac header.

I'd be fine with you submitting the whole set as one piece with the other 11 patches you had just as long as we get those core pieces fixed in the patch set.

- Alex

#4 lore raw
Quoted 32 lines · Alexander Duyck
Quoted 31 lines · Tom Herbert
Quoted 29 lines · Alexander Duyck
Quoted 16 lines · Tom Herbert

In ip6gre_tnl_link_config set t->tun_len and t->hlen correctly for the configuration. For hard_header_len and mtu calculation include IPv6 header and encapsulation overhead.

In ip6gre_tunnel_init_common set t->tun_len and t->hlen correctly for the configuration. Revert to setting hard_header_len instead of needed_headroom.

Tested:

./ip link add name tun8 type ip6gretap remote \
2401:db00:20:911a:face:0:27:0 local \
2401:db00:20:911a:face:0:25:0 ttl 225

Gives MTU of 1434. That is equal to 1500 - 40 - 14 - 4 - 8.

Quoted 7 lines

./ip link add name tun8 type ip6gretap remote \
2401:db00:20:911a:face:0:27:0 local \
2401:db00:20:911a:face:0:25:0 ttl 225 okey 123

Gives MTU of 1430. That is equal to 1500 - 40 - 14 - 4 - 8 - 4.

So this gives me the correct result now. However we still need patch 3 / 11 from the set you submitted next week in order to be able to even transmit because the flags are otherwise mangled.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Okay, I'll repost the flags patch as a standalone. Do you have any other issues then in this path?

This piece no.

Actually I just realized there are two other bits that need to be updated.

I just copied/pasted the below out of a text console so I am sure the white-space formatting is wrong. These two spots should be fixed as well as they are using the wrong flag type.

net/ipv6/ip6_gre.c +1 -1
index ec209f4d3312..ee62ec469ab3 100644
@@ -343,7 +343,7 @@ static struct ip6_tnl *ip6gre_tunnel_locate(struct net *net,
                goto failed_free;
 
        /* Can use a lockless transmit, unless we generate output sequences */
-       if (!(nt->parms.o_flags & GRE_SEQ))
+       if (!(nt->parms.o_flags & TUNNEL_SEQ))
                dev->features |= NETIF_F_LLTX;
 
        dev_hold(dev);
@@ -1314,7 +1314,7 @@ static int ip6gre_newlink(struct net *src_net,

struct net_device *dev,

        dev->features           |= GRE6_FEATURES;
        dev->hw_features        |= GRE6_FEATURES;

- if (!(nt->parms.o_flags & GRE_SEQ)) {

+       if (!(nt->parms.o_flags & TUNNEL_SEQ)) {
                /* TCP segmentation offload is not supported when we
                 * generate output sequences.
                 */
#5 lore raw
In reply to Alexander Duyck
Quoted 39 lines · Alexander Duyck
Quoted 27 lines · Tom Herbert
Quoted 25 lines · Alexander Duyck
Quoted 23 lines · Tom Herbert

In ip6gre_tnl_link_config set t->tun_len and t->hlen correctly for the configuration. For hard_header_len and mtu calculation include IPv6 header and encapsulation overhead.

In ip6gre_tunnel_init_common set t->tun_len and t->hlen correctly for the configuration. Revert to setting hard_header_len instead of needed_headroom.

Tested:

./ip link add name tun8 type ip6gretap remote \
2401:db00:20:911a:face:0:27:0 local \
2401:db00:20:911a:face:0:25:0 ttl 225

Gives MTU of 1434. That is equal to 1500 - 40 - 14 - 4 - 8.

./ip link add name tun8 type ip6gretap remote \
2401:db00:20:911a:face:0:27:0 local \
2401:db00:20:911a:face:0:25:0 ttl 225 okey 123

Gives MTU of 1430. That is equal to 1500 - 40 - 14 - 4 - 8 - 4.

Quoted 8 lines
Quoted 5 lines

So this gives me the correct result now. However we still need patch 3 / 11 from the set you submitted next week in order to be able to even transmit because the flags are otherwise mangled.

Okay, I'll repost the flags patch as a standalone. Do you have any other issues then in this path?

This piece no.

Quoted 9 lines

Like I said in the other email I did find two other issues. First in __gre6_xmit I think you want to set the inner protocol to "protocol", not "proto". Second is the issue with ip6_tnl_xmit stomping on skb->transport_header. The second one is the big one that is blocking things badly right now. That is the one that keeps me from doing anything with any sort of offload as the headers are jumping around out of order with the outer transport header having an offset that is further in than the inner mac header.

You mean "skb->transport_header = skb->network_header;"? It doesn't look right to me either, but that line has been around a while....

Quoted 4 lines

I'd be fine with you submitting the whole set as one piece with the other 11 patches you had just as long as we get those core pieces fixed in the patch set.

Probably just as easy to break it up.

Quoted 1 line

- Alex