Skip to content

Commit db2ec95

Browse files
tomratbertdavem330
authored andcommitted
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. Signed-off-by: Tom Herbert <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent bfca2eb commit db2ec95

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

net/ipv6/ip6_gre.c

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu)
700700
struct net_device *dev = t->dev;
701701
struct __ip6_tnl_parm *p = &t->parms;
702702
struct flowi6 *fl6 = &t->fl.u.ip6;
703-
int addend = sizeof(struct ipv6hdr) + 4;
703+
int t_hlen;
704704

705705
if (dev->type != ARPHRD_ETHER) {
706706
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)
727727
else
728728
dev->flags &= ~IFF_POINTOPOINT;
729729

730-
/* Precalculate GRE options length */
731-
if (t->parms.o_flags&(GRE_CSUM|GRE_KEY|GRE_SEQ)) {
732-
if (t->parms.o_flags&GRE_CSUM)
733-
addend += 4;
734-
if (t->parms.o_flags&GRE_KEY)
735-
addend += 4;
736-
if (t->parms.o_flags&GRE_SEQ)
737-
addend += 4;
738-
}
739-
t->hlen = addend;
730+
t->tun_hlen = gre_calc_hlen(t->parms.o_flags);
731+
732+
t->hlen = t->tun_hlen;
733+
734+
t_hlen = t->hlen + sizeof(struct ipv6hdr);
740735

741736
if (p->flags & IP6_TNL_F_CAP_XMIT) {
742737
int strict = (ipv6_addr_type(&p->raddr) &
@@ -750,10 +745,11 @@ static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu)
750745
return;
751746

752747
if (rt->dst.dev) {
753-
dev->hard_header_len = rt->dst.dev->hard_header_len + addend;
748+
dev->hard_header_len = rt->dst.dev->hard_header_len +
749+
t_hlen;
754750

755751
if (set_mtu) {
756-
dev->mtu = rt->dst.dev->mtu - addend;
752+
dev->mtu = rt->dst.dev->mtu - t_hlen;
757753
if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
758754
dev->mtu -= 8;
759755
if (dev->type == ARPHRD_ETHER)
@@ -1027,11 +1023,12 @@ static int ip6gre_tunnel_init_common(struct net_device *dev)
10271023

10281024
tunnel->tun_hlen = gre_calc_hlen(tunnel->parms.o_flags);
10291025

1030-
t_hlen = tunnel->hlen + sizeof(struct ipv6hdr);
1026+
tunnel->hlen = tunnel->tun_hlen;
10311027

1032-
dev->needed_headroom = LL_MAX_HEADER + t_hlen + 4;
1033-
dev->mtu = ETH_DATA_LEN - t_hlen - 4;
1028+
t_hlen = tunnel->hlen + sizeof(struct ipv6hdr);
10341029

1030+
dev->hard_header_len = LL_MAX_HEADER + t_hlen;
1031+
dev->mtu = ETH_DATA_LEN - t_hlen;
10351032
if (!(tunnel->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
10361033
dev->mtu -= 8;
10371034

0 commit comments

Comments
 (0)