system-linux: Don't set gre tunnel ttl by default to 64 (#FS312)
authorHans Dedecker <dedeckeh@gmail.com>
Fri, 23 Dec 2016 14:52:32 +0000 (15:52 +0100)
committerFelix Fietkau <nbd@nbd.name>
Sat, 24 Dec 2016 09:51:58 +0000 (10:51 +0100)
As the ttl of a gre tunnel was set by default to 64 the gre tunnel
failed to get active if don't fragment was disabled as setting
nopmtudisc and ttl is incompatible.
Fix this by setting the default ttl value after don't fragment
and ttl config values have been parsed.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
system-linux.c

index 67fa2b1..52a1c17 100644 (file)
@@ -2127,7 +2127,7 @@ static int system_add_gre_tunnel(const char *name, const char *kind,
        uint32_t ikey = 0, okey = 0, flags = 0, flowinfo = 0;
        uint16_t iflags = 0, oflags = 0;
        uint8_t tos = 0;
        uint32_t ikey = 0, okey = 0, flags = 0, flowinfo = 0;
        uint16_t iflags = 0, oflags = 0;
        uint8_t tos = 0;
-       int ret = 0, ttl = 64;
+       int ret = 0, ttl = 0;
 
        nlm = nlmsg_alloc_simple(RTM_NEWLINK, NLM_F_REQUEST | NLM_F_REPLACE | NLM_F_CREATE);
        if (!nlm)
 
        nlm = nlmsg_alloc_simple(RTM_NEWLINK, NLM_F_REQUEST | NLM_F_REPLACE | NLM_F_CREATE);
        if (!nlm)
@@ -2155,8 +2155,6 @@ static int system_add_gre_tunnel(const char *name, const char *kind,
        if ((cur = tb[TUNNEL_ATTR_TTL]))
                ttl = blobmsg_get_u32(cur);
 
        if ((cur = tb[TUNNEL_ATTR_TTL]))
                ttl = blobmsg_get_u32(cur);
 
-       nla_put_u8(nlm, IFLA_GRE_TTL, ttl);
-
        if ((cur = tb[TUNNEL_ATTR_TOS])) {
                char *str = blobmsg_get_string(cur);
                if (strcmp(str, "inherit")) {
        if ((cur = tb[TUNNEL_ATTR_TOS])) {
                char *str = blobmsg_get_string(cur);
                if (strcmp(str, "inherit")) {
@@ -2230,6 +2228,9 @@ static int system_add_gre_tunnel(const char *name, const char *kind,
 
                if (flags)
                        nla_put_u32(nlm, IFLA_GRE_FLAGS, flags);
 
                if (flags)
                        nla_put_u32(nlm, IFLA_GRE_FLAGS, flags);
+
+               if (!ttl)
+                       ttl = 64;
        } else {
                struct in_addr inbuf;
                bool set_df = true;
        } else {
                struct in_addr inbuf;
                bool set_df = true;
@@ -2265,17 +2266,23 @@ static int system_add_gre_tunnel(const char *name, const char *kind,
                if ((cur = tb[TUNNEL_ATTR_DF]))
                        set_df = blobmsg_get_bool(cur);
 
                if ((cur = tb[TUNNEL_ATTR_DF]))
                        set_df = blobmsg_get_bool(cur);
 
-               /* ttl !=0 and nopmtudisc are incompatible */
-               if (ttl && !set_df) {
-                       ret = -EINVAL;
-                       goto failure;
-               }
+               if (!set_df) {
+                       /* ttl != 0 and nopmtudisc are incompatible */
+                       if (ttl) {
+                               ret = -EINVAL;
+                               goto failure;
+                       }
+               } else if (!ttl)
+                       ttl = 64;
 
                nla_put_u8(nlm, IFLA_GRE_PMTUDISC, set_df ? 1 : 0);
 
                nla_put_u8(nlm, IFLA_GRE_TOS, tos);
        }
 
 
                nla_put_u8(nlm, IFLA_GRE_PMTUDISC, set_df ? 1 : 0);
 
                nla_put_u8(nlm, IFLA_GRE_TOS, tos);
        }
 
+       if (ttl)
+               nla_put_u8(nlm, IFLA_GRE_TTL, ttl);
+
        if (oflags)
                nla_put_u16(nlm, IFLA_GRE_OFLAGS, oflags);
 
        if (oflags)
                nla_put_u16(nlm, IFLA_GRE_OFLAGS, oflags);