]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
iproute: Add support for MPLS LWT ttl attribute
authorRobert Shearman <rshearma@brocade.com>
Tue, 11 Apr 2017 08:37:21 +0000 (09:37 +0100)
committerStephen Hemminger <stephen@networkplumber.org>
Wed, 12 Apr 2017 17:02:15 +0000 (10:02 -0700)
Add support for setting and displaying the ttl attribute
for MPLS IP lighweight tunnels.

Signed-off-by: Robert Shearman <rshearma@brocade.com>
Acked-by: David Ahern <dsa@cumulusnetworks.com>
ip/iproute_lwtunnel.c
man/man8/ip-route.8.in

index 0fa1cab0a790fa4adc9d4a0dbe75002d427645ca..845a115e9e41611d075bb409bc8f1ad0bd308281 100644 (file)
@@ -84,6 +84,9 @@ static void print_encap_mpls(FILE *fp, struct rtattr *encap)
        if (tb[MPLS_IPTUNNEL_DST])
                fprintf(fp, " %s ",
                        format_host_rta(AF_MPLS, tb[MPLS_IPTUNNEL_DST]));
+       if (tb[MPLS_IPTUNNEL_TTL])
+               fprintf(fp, "ttl %u ",
+                       rta_getattr_u8(tb[MPLS_IPTUNNEL_TTL]));
 }
 
 static void print_encap_ip(FILE *fp, struct rtattr *encap)
@@ -247,6 +250,7 @@ static int parse_encap_mpls(struct rtattr *rta, size_t len,
        inet_prefix addr;
        int argc = *argcp;
        char **argv = *argvp;
+       int ttl_ok = 0;
 
        if (get_addr(&addr, *argv, AF_MPLS)) {
                fprintf(stderr,
@@ -258,8 +262,31 @@ static int parse_encap_mpls(struct rtattr *rta, size_t len,
        rta_addattr_l(rta, len, MPLS_IPTUNNEL_DST, &addr.data,
                      addr.bytelen);
 
-       *argcp = argc;
-       *argvp = argv;
+       argc--;
+       argv++;
+
+       while (argc > 0) {
+               if (strcmp(*argv, "ttl") == 0) {
+                       __u8 ttl;
+
+                       NEXT_ARG();
+                       if (ttl_ok++)
+                               duparg2("ttl", *argv);
+                       if (get_u8(&ttl, *argv, 0))
+                               invarg("\"ttl\" value is invalid\n", *argv);
+                       rta_addattr8(rta, len, MPLS_IPTUNNEL_TTL, ttl);
+               } else {
+                       break;
+               }
+               argc--; argv++;
+       }
+
+       /* argv is currently the first unparsed argument,
+        * but the lwt_parse_encap() caller will move to the next,
+        * so step back
+        */
+       *argcp = argc + 1;
+       *argvp = argv - 1;
 
        return 0;
 }
index fbe2711a4301034bdc23b18da2bb46142907a164..d2a44acf27937bc829a87a9acea8108573429ae5 100644 (file)
@@ -181,7 +181,9 @@ throw " | " unreachable " | " prohibit " | " blackhole " | " nat " ]"
 .ti -8
 .IR ENCAP_MPLS " := "
 .BR mpls " [ "
-.IR LABEL " ]"
+.IR LABEL " ] ["
+.B  ttl
+.IR TTL " ]"
 
 .ti -8
 .IR ENCAP_IP " := "
@@ -666,6 +668,11 @@ is a set of encapsulation attributes specific to the
 .I MPLSLABEL
 - mpls label stack with labels separated by
 .I "/"
+.sp
+
+.B ttl
+.I TTL
+- TTL to use for MPLS header or 0 to inherit from IP header
 .in -2
 .sp