Skip to contentSkip to conversation

Fix the upper MTU limit in ipv6 GRE tunnel

PATCH In review Oussama Ghorbel 3 participants 14 messages Oct 4, 2013 – Oct 7, 2013

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

PATCH 1/1 Fix the upper MTU limit in ipv6 GRE tunnel

Unlike ipv4, the struct member hlen holds the length of the GRE and ipv6 headers. This length is also counted in dev->hard_header_len. Perhaps, it's more clean to modify the hlen to count only the GRE header without ipv6 header as the variable name suggest, but the simple way to fix this without regression risk is simply modify the calculation of the limit in ip6gre_tunnel_change_mtu function.
Verified in kernel version v3.11.

---
 net/ipv6/ip6_gre.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/ipv6/ip6_gre.c +1 -2
index 90747f1..41487ab 100644
@@ -1175,9 +1175,8 @@ done:
 
 static int ip6gre_tunnel_change_mtu(struct net_device *dev, int new_mtu)
 {
-	struct ip6_tnl *tunnel = netdev_priv(dev);
 	if (new_mtu < 68 ||
-	    new_mtu > 0xFFF8 - dev->hard_header_len - tunnel->hlen)
+	    new_mtu > 0xFFF8 - dev->hard_header_len)
 		return -EINVAL;
 	dev->mtu = new_mtu;
 	return 0;
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 18 lines · Oussama Ghorbel

Unlike ipv4, the struct member hlen holds the length of the GRE and ipv6 headers. This length is also counted in dev->hard_header_len. Perhaps, it's more clean to modify the hlen to count only the GRE header without ipv6 header as the variable name suggest, but the simple way to fix this without regression risk is simply modify the calculation of the limit in ip6gre_tunnel_change_mtu function.
Verified in kernel version v3.11.

---
 net/ipv6/ip6_gre.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/ipv6/ip6_gre.c +0 -0
index 90747f1..41487ab 100644

net/ipv6/ip6_gre.c done: · line 1182

Quoted 10 lines
net/ipv6/ip6_gre.c +1 -2
@@ -1175,9 +1175,8 @@ done:
 
 static int ip6gre_tunnel_change_mtu(struct net_device *dev, int new_mtu)
 {
-	struct ip6_tnl *tunnel = netdev_priv(dev);
 	if (new_mtu < 68 ||
-	    new_mtu > 0xFFF8 - dev->hard_header_len - tunnel->hlen)
+	    new_mtu > 0xFFF8 - dev->hard_header_len)
 		return -EINVAL;
 	dev->mtu = new_mtu;
 	return 0;

Hmmm...

dev->hard_header_len is initialized to LL_MAX_HEADER + sizeof(struct ipv6hdr)
+ 4 but won't include the additional head space needed for GRE_SEQ, GRE_KEY etc. if at time of tunnel creation the routing table did not had a good guess for the outgoing device.

To make this correct we would have to refactor the usage of the variables a bit as is done in ipv4/ip_tunnel.c. The safest thing would be to leave this check as-is currently although we exclude some allowed mtus.

Perhaps you want to take a look how to achieve that? ;)

Greetings,

Hannes

#2 lore raw
Quoted 32 lines · Hannes Frederic Sowa
Quoted 18 lines · Oussama Ghorbel

Unlike ipv4, the struct member hlen holds the length of the GRE and ipv6 headers. This length is also counted in dev->hard_header_len. Perhaps, it's more clean to modify the hlen to count only the GRE header without ipv6 header as the variable name suggest, but the simple way to fix this without regression risk is simply modify the calculation of the limit in ip6gre_tunnel_change_mtu function.
Verified in kernel version v3.11.

---
 net/ipv6/ip6_gre.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/ipv6/ip6_gre.c +0 -0
index 90747f1..41487ab 100644

net/ipv6/ip6_gre.c done: · line 1182

Quoted 10 lines
net/ipv6/ip6_gre.c +1 -2
@@ -1175,9 +1175,8 @@ done:
 
 static int ip6gre_tunnel_change_mtu(struct net_device *dev, int new_mtu)
 {
-     struct ip6_tnl *tunnel = netdev_priv(dev);
      if (new_mtu < 68 ||
-         new_mtu > 0xFFF8 - dev->hard_header_len - tunnel->hlen)
+         new_mtu > 0xFFF8 - dev->hard_header_len)
              return -EINVAL;
      dev->mtu = new_mtu;
      return 0;

Hmmm...

Quoted 5 lines

dev->hard_header_len is initialized to LL_MAX_HEADER + sizeof(struct ipv6hdr)
+ 4 but won't include the additional head space needed for GRE_SEQ, GRE_KEY etc. if at time of tunnel creation the routing table did not had a good guess for the outgoing device.

This hard_header_len initialization that you have shown above is taken from ip6gre_tunnel_setup, however this same variable seems to be reinitialized in ip6gre_tnl_link_config() which are called from ip6gre_newlink()
The initialization in ip6gre_tnl_link_config is done as the following:
static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu) {
...
int addend = sizeof(struct ipv6hdr) + 4;
...
/* 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;
}
...
dev->hard_header_len = rt->dst.dev->hard_header_len + addend;
...
t->hlen = addend;
..
}

Unless they are other reasons, the hard_header_len is taken into account the GRE_KEY, GRE_SEQ ..

Quoted 6 lines

To make this correct we would have to refactor the usage of the variables a bit as is done in ipv4/ip_tunnel.c. The safest thing would be to leave this check as-is currently although we exclude some allowed mtus.

Perhaps you want to take a look how to achieve that? ;)

Why not, consistency is good ...

Quoted 4 lines

Greetings,

Hannes

Thanks,
Oussama

#3 lore raw
Quoted 22 lines · Oussama Ghorbel

The initialization in ip6gre_tnl_link_config is done as the following:
static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu) {
...
int addend = sizeof(struct ipv6hdr) + 4;
...
/* 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;
}
...
dev->hard_header_len = rt->dst.dev->hard_header_len + addend;
...
t->hlen = addend;
..
}

Quoted 2 lines

Unless they are other reasons, the hard_header_len is taken into account the GRE_KEY, GRE_SEQ ..

But only if a new route is found. The hard_header_len reinitialization is guarded by a (rt == NULL). We may have not found one on boot up.

Quoted 7 lines
Quoted 6 lines

To make this correct we would have to refactor the usage of the variables a bit as is done in ipv4/ip_tunnel.c. The safest thing would be to leave this check as-is currently although we exclude some allowed mtus.

Perhaps you want to take a look how to achieve that? ;)

Why not, consistency is good ...

Thanks,

Hannes

#4 lore raw
Quoted 23 lines · Hannes Frederic Sowa
Quoted 22 lines · Oussama Ghorbel

The initialization in ip6gre_tnl_link_config is done as the following:
static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu) {
...
int addend = sizeof(struct ipv6hdr) + 4;
...
/* 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;
}
...
dev->hard_header_len = rt->dst.dev->hard_header_len + addend;
...
t->hlen = addend;
..
}

Quoted 6 lines
Quoted 2 lines

Unless they are other reasons, the hard_header_len is taken into account the GRE_KEY, GRE_SEQ ..

But only if a new route is found. The hard_header_len reinitialization is guarded by a (rt == NULL). We may have not found one on boot up.

In that case the function will make a return and hlen will be zero. Subtracting hlen in ip6gre_tunnel_change_mtu has no effect ...

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

To make this correct we would have to refactor the usage of the variables a bit as is done in ipv4/ip_tunnel.c. The safest thing would be to leave this check as-is currently although we exclude some allowed mtus.

Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

Perhaps you want to take a look how to achieve that? ;)

Why not, consistency is good ...

Thanks,

Hannes

Thanks,
Oussama

#5 lore raw
Quoted 25 lines · Oussama Ghorbel
Quoted 23 lines · Hannes Frederic Sowa
Quoted 22 lines · Oussama Ghorbel

The initialization in ip6gre_tnl_link_config is done as the following:
static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu) {
...
int addend = sizeof(struct ipv6hdr) + 4;
...
/* 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;
}
...
dev->hard_header_len = rt->dst.dev->hard_header_len + addend;
...
t->hlen = addend;
..
}

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Unless they are other reasons, the hard_header_len is taken into account the GRE_KEY, GRE_SEQ ..

But only if a new route is found. The hard_header_len reinitialization is guarded by a (rt == NULL). We may have not found one on boot up.

In that case the function will make a return and hlen will be zero. Subtracting hlen in ip6gre_tunnel_change_mtu has no effect ...

Oh yes, somehow I missed that.

We depend on t->hlen when pushing the gre header onto the skb. t->hlen == 0 should never be the case because we assume t->hlen > sizeof(struct ipv6_hdr).

#6 lore raw

Yes, to summarize, the idea of this patch was to fix the incoherence in the condition of ip6gre_tunnel_change_mtu function

if (new_mtu < 68 ||
new_mtu > 0xFFF8 - dev->hard_header_len - tunnel->hlen)

Quoted 1 line

From the ip6gre_tnl_link_config function we can see that:

The variable addend is equal the ipv6 header + gre header (including the gre options)
On the other hand hard_header_len equal to the header of the lower layer + addend.
So the quantity - (dev->hard_header_len + tunnel->hlen) equals - (eth header + ipv6 header + gre header + ipv6 header + gre header) which by no means this would represent anything! (I've just taken ipv6 over ethernet as example)

As we have seen there is another approach to fix this issue is to re-factor the hlen to hold only the length of gre as it's done for ipv4 gre, however the solution provided in the patch seems to be regression risk-less.
Although the value hold by hlen is not coherent with the variable name nor with ipv4, I think there is an advantage of the current approach of ipv6 hlen over ipv4 hlen, because we save the calculation of ipv6 header each time. Ex:
In ipv4 gre and in the function ipgre_header:
iph = (struct iphdr *)skb_push(skb, t->hlen + sizeof(*iph)); In ipv6 and in the function ip6gre_header
ipv6h = (struct ipv6hdr *)skb_push(skb, t->hlen);

Thanks,
Oussama

Quoted 40 lines · Hannes Frederic Sowa
Quoted 25 lines · Oussama Ghorbel
Quoted 23 lines · Hannes Frederic Sowa
Quoted 22 lines · Oussama Ghorbel

The initialization in ip6gre_tnl_link_config is done as the following:
static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu) {
...
int addend = sizeof(struct ipv6hdr) + 4;
...
/* 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;
}
...
dev->hard_header_len = rt->dst.dev->hard_header_len + addend;
...
t->hlen = addend;
..
}

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Unless they are other reasons, the hard_header_len is taken into account the GRE_KEY, GRE_SEQ ..

But only if a new route is found. The hard_header_len reinitialization is guarded by a (rt == NULL). We may have not found one on boot up.

In that case the function will make a return and hlen will be zero. Subtracting hlen in ip6gre_tunnel_change_mtu has no effect ...

Oh yes, somehow I missed that.

We depend on t->hlen when pushing the gre header onto the skb. t->hlen == 0 should never be the case because we assume t->hlen > sizeof(struct ipv6_hdr).

#7 lore raw
Quoted 16 lines · Oussama Ghorbel

Yes, to summarize, the idea of this patch was to fix the incoherence in the condition of ip6gre_tunnel_change_mtu function

if (new_mtu < 68 ||
new_mtu > 0xFFF8 - dev->hard_header_len - tunnel->hlen)

From the ip6gre_tnl_link_config function we can see that:
The variable addend is equal the ipv6 header + gre header (including the gre options)
On the other hand hard_header_len equal to the header of the lower layer + addend.
So the quantity - (dev->hard_header_len + tunnel->hlen) equals - (eth header + ipv6 header + gre header + ipv6 header + gre header) which by no means this would represent anything! (I've just taken ipv6 over ethernet as example)

Quoted 4 lines

As we have seen there is another approach to fix this issue is to re-factor the hlen to hold only the length of gre as it's done for ipv4 gre, however the solution provided in the patch seems to be regression risk-less.

I agree, it actually does not worsen the situation:

Quoted 8 lines

Although the value hold by hlen is not coherent with the variable name nor with ipv4, I think there is an advantage of the current approach of ipv6 hlen over ipv4 hlen, because we save the calculation of ipv6 header each time. Ex:
In ipv4 gre and in the function ipgre_header:
iph = (struct iphdr *)skb_push(skb, t->hlen + sizeof(*iph)); In ipv6 and in the function ip6gre_header
ipv6h = (struct ipv6hdr *)skb_push(skb, t->hlen);

I see your point. But we should take care that t->hlen is always initialized, regardless if we got a route and outgoing device or not.

Greetings,

Hannes

#8 lore raw
Quoted 35 lines · Hannes Frederic Sowa
Quoted 16 lines · Oussama Ghorbel

Yes, to summarize, the idea of this patch was to fix the incoherence in the condition of ip6gre_tunnel_change_mtu function

if (new_mtu < 68 ||
new_mtu > 0xFFF8 - dev->hard_header_len - tunnel->hlen)

From the ip6gre_tnl_link_config function we can see that:
The variable addend is equal the ipv6 header + gre header (including the gre options)
On the other hand hard_header_len equal to the header of the lower layer + addend.
So the quantity - (dev->hard_header_len + tunnel->hlen) equals - (eth header + ipv6 header + gre header + ipv6 header + gre header) which by no means this would represent anything! (I've just taken ipv6 over ethernet as example)

Quoted 4 lines

As we have seen there is another approach to fix this issue is to re-factor the hlen to hold only the length of gre as it's done for ipv4 gre, however the solution provided in the patch seems to be regression risk-less.

I agree, it actually does not worsen the situation:

Quoted 8 lines

Although the value hold by hlen is not coherent with the variable name nor with ipv4, I think there is an advantage of the current approach of ipv6 hlen over ipv4 hlen, because we save the calculation of ipv6 header each time. Ex:
In ipv4 gre and in the function ipgre_header:
iph = (struct iphdr *)skb_push(skb, t->hlen + sizeof(*iph)); In ipv6 and in the function ip6gre_header
ipv6h = (struct ipv6hdr *)skb_push(skb, t->hlen);

Quoted 3 lines

I see your point. But we should take care that t->hlen is always initialized, regardless if we got a route and outgoing device or not.

OK, I'll investigate on this and I'll open a dedicated thread mail/send patch...

Quoted 4 lines

Greetings,

Hannes

Thanks,
Oussama

maintainer
#9 lore raw
In reply to Oussama Ghorbel

From: Oussama Ghorbel <[email protected]>
Date: Fri, 4 Oct 2013 10:52:13 +0100

Quoted 9 lines

Unlike ipv4, the struct member hlen holds the length of the GRE and ipv6 headers. This length is also counted in dev->hard_header_len. Perhaps, it's more clean to modify the hlen to count only the GRE header without ipv6 header as the variable name suggest, but the simple way to fix this without regression risk is simply modify the calculation of the limit in ip6gre_tunnel_change_mtu function.
Verified in kernel version v3.11.

Please resubmit this with a proper Subject line.

It should be "[PATCH] " then a legitimate subsystem prefix. In this case "ipv6: " would be appropriate. And then the "ipv6" in your existing Subject text is redundant so can be removed.

Thanks.

#10 lore raw

OK, I've resubmitted the patch with the proper Subject line.
The new mail subject is: [PATCH] ipv6: Fix the upper MTU limit in GRE tunnel

Thanks,
Oussama

Quoted 21 lines · David Miller

From: Oussama Ghorbel <[email protected]>
Date: Fri, 4 Oct 2013 10:52:13 +0100

Quoted 9 lines

Unlike ipv4, the struct member hlen holds the length of the GRE and ipv6 headers. This length is also counted in dev->hard_header_len. Perhaps, it's more clean to modify the hlen to count only the GRE header without ipv6 header as the variable name suggest, but the simple way to fix this without regression risk is simply modify the calculation of the limit in ip6gre_tunnel_change_mtu function.
Verified in kernel version v3.11.

Please resubmit this with a proper Subject line.

It should be "[PATCH] " then a legitimate subsystem prefix. In this case "ipv6: " would be appropriate. And then the "ipv6" in your existing Subject text is redundant so can be removed.

Thanks.

maintainer
#11 lore raw

From: Oussama Ghorbel <[email protected]>
Date: Mon, 7 Oct 2013 18:34:53 +0100

Quoted 2 lines

OK, I've resubmitted the patch with the proper Subject line.
The new mail subject is: [PATCH] ipv6: Fix the upper MTU limit in GRE tunnel

You forgot to propagate the "Acked-by: " tag that was given by reviewers of your patch.

#12 lore raw

Sorry for that. I've added it and I have resubmitted the patch.

Thanks

Quoted 8 lines · David Miller

From: Oussama Ghorbel <[email protected]>
Date: Mon, 7 Oct 2013 18:34:53 +0100

Quoted 2 lines

OK, I've resubmitted the patch with the proper Subject line.
The new mail subject is: [PATCH] ipv6: Fix the upper MTU limit in GRE tunnel

You forgot to propagate the "Acked-by: " tag that was given by reviewers of your patch.

maintainer
#13 lore raw

From: Oussama Ghorbel <[email protected]>
Date: Mon, 7 Oct 2013 18:52:15 +0100

Quoted 1 line

Sorry for that. I've added it and I have resubmitted the patch.

Thank you.