]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
ip/geneve: fix ttl inherit behavior
authorHangbin Liu <liuhangbin@gmail.com>
Mon, 22 Oct 2018 07:46:18 +0000 (15:46 +0800)
committerDavid Ahern <dsahern@gmail.com>
Tue, 23 Oct 2018 17:53:16 +0000 (10:53 -0700)
Currently when we add geneve with "ttl inherit", we only set ttl to 0, which
is actually use whatever default value instead of inherit the inner protocol's
ttl value.

To make a difference with ttl inherit and ttl == 0, we add an attribute
IFLA_GENEVE_TTL_INHERIT in kernel commit 52d0d404d39dd ("geneve: add ttl
inherit support"). Now let's use "ttl inherit" to inherit the inner
protocol's ttl, and use "ttl auto" to means "use whatever default value",
the same behavior with ttl == 0.

v2:
1) remove IFLA_GENEVE_TTL_INHERIT defination in if_link.h as it's already
   updated.
2) Still use addattr8() so we can enable/disable ttl inherit, as Michal
   suggested.

v3: Update man page

Reported-by: Jianlin Shi <jishi@redhat.com>
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
ip/iplink_geneve.c
man/man8/ip-link.8.in

index 26e70ff4db42de8802befa72d0fda41db98d29be..c417842b2a5b58f63b1147fd02283c03d451829a 100644 (file)
@@ -34,7 +34,7 @@ static void print_explain(FILE *f)
                "Where: VNI   := 0-16777215\n"
                "       ADDR  := IP_ADDRESS\n"
                "       TOS   := { NUMBER | inherit }\n"
-               "       TTL   := { 1..255 | inherit }\n"
+               "       TTL   := { 1..255 | auto | inherit }\n"
                "       LABEL := 0-1048575\n"
        );
 }
@@ -94,7 +94,9 @@ static int geneve_parse_opt(struct link_util *lu, int argc, char **argv,
 
                        NEXT_ARG();
                        check_duparg(&attrs, IFLA_GENEVE_TTL, "ttl", *argv);
-                       if (strcmp(*argv, "inherit") != 0) {
+                       if (strcmp(*argv, "inherit") == 0) {
+                               addattr8(n, 1024, IFLA_GENEVE_TTL_INHERIT, 1);
+                       } else if (strcmp(*argv, "auto") != 0) {
                                if (get_unsigned(&uval, *argv, 0))
                                        invarg("invalid TTL", *argv);
                                if (uval > 255)
@@ -265,12 +267,16 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
                }
        }
 
-       if (tb[IFLA_GENEVE_TTL])
-               ttl = rta_getattr_u8(tb[IFLA_GENEVE_TTL]);
-       if (is_json_context() || ttl)
-               print_uint(PRINT_ANY, "ttl", "ttl %u ", ttl);
-       else
+       if (tb[IFLA_GENEVE_TTL_INHERIT] &&
+           rta_getattr_u8(tb[IFLA_GENEVE_TTL_INHERIT])) {
                print_string(PRINT_FP, NULL, "ttl %s ", "inherit");
+       } else if (tb[IFLA_GENEVE_TTL]) {
+               ttl = rta_getattr_u8(tb[IFLA_GENEVE_TTL]);
+               if (is_json_context() || ttl)
+                       print_uint(PRINT_ANY, "ttl", "ttl %u ", ttl);
+               else
+                       print_string(PRINT_FP, NULL, "ttl %s ", "auto");
+       }
 
        if (tb[IFLA_GENEVE_TOS])
                tos = rta_getattr_u8(tb[IFLA_GENEVE_TOS]);
index ecbbd4f499e7ce2911fcb82f9d9a772f9d6c5679..4489162b4331f87166b356769ed0e5158cd8b2ba 100644 (file)
@@ -1190,7 +1190,9 @@ the following additional arguments are supported:
 
 .sp
 .BI ttl " TTL"
-- specifies the TTL value to use in outgoing packets.
+- specifies the TTL value to use in outgoing packets. "0" or "auto" means
+use whatever default value, "inherit" means inherit the inner protocol's
+ttl. Default option is "0".
 
 .sp
 .BI tos " TOS"