]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
ip6/tunnel: Unify flowlabel printing
authorSerhey Popovych <serhe.popovych@gmail.com>
Wed, 10 Jan 2018 15:53:12 +0000 (17:53 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Wed, 10 Jan 2018 16:06:12 +0000 (08:06 -0800)
Use @s2 buffer to store string representation of
flowlabel and get rid of extra SPRINT_BUF(): no
need to preserve @s2 contents for later.

Use print_string(PRINT_ANY, ...) with prepared by
snprintf() string for both PRINT_JSON and PRINT_FP
cases.

Omit flowlabel from output if no flowinfo attribute
is given and IP6_TNL_F_USE_ORIG_FLOWLABEL isn't set.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
ip/link_gre6.c
ip/link_ip6tnl.c

index a02dd4a4322a1da3f562bae04fd8baec8090b9b4..1205946f137ecf91d970451dfe7110979c4728dd 100644 (file)
@@ -452,18 +452,11 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
                           "ip6_tnl_f_use_orig_flowlabel",
                           "flowlabel inherit ",
                           true);
-       } else {
-               if (is_json_context()) {
-                       SPRINT_BUF(b1);
-
-                       snprintf(b1, sizeof(b1), "0x%05x",
-                                ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL));
-                       print_string(PRINT_JSON, "flowlabel", NULL, b1);
+       } else if (tb[IFLA_GRE_FLOWINFO]) {
+               __u32 val = ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL);
 
-               } else {
-                       fprintf(f, "flowlabel 0x%05x ",
-                               ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL));
-               }
+               snprintf(s2, sizeof(s2), "0x%05x", val);
+               print_string(PRINT_ANY, "flowlabel", "flowlabel %s ", s2);
        }
 
        if (flags & IP6_TNL_F_USE_ORIG_TCLASS) {
index 05322fdf46eadbcb2dbd35afd5acd89f29343690..7000056b6e2e41bbdd9709360562c2590219f031 100644 (file)
@@ -421,17 +421,11 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb
                           "ip6_tnl_f_use_orig_flowlabel",
                           "flowlabel inherit ",
                           true);
-       } else {
-               if (is_json_context()) {
-                       SPRINT_BUF(b1);
+       } else if (tb[IFLA_IPTUN_FLOWINFO]) {
+               __u32 val = ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL);
 
-                       snprintf(b1, sizeof(b1), "0x%05x",
-                                ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL));
-                       print_string(PRINT_JSON, "flowlabel", NULL, b1);
-               } else {
-                       printf("flowlabel 0x%05x ",
-                              ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL));
-               }
+               snprintf(s2, sizeof(s2), "0x%05x", val);
+               print_string(PRINT_ANY, "flowlabel", "flowlabel %s ", s2);
        }
 
        if (flags & IP6_TNL_F_RCV_DSCP_COPY)