]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
ip/tunnel: Use print_0xhex() instead of print_string()
authorSerhey Popovych <serhe.popovych@gmail.com>
Thu, 18 Jan 2018 14:04:31 +0000 (16:04 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Fri, 19 Jan 2018 00:34:40 +0000 (16:34 -0800)
No need for custom SPRINT_BUF() and snprintf() 0x%x
value to this buffer: we can use print_0xhex() instead
of print_string().

In link_iptnl.c use s2 instead of s1 buffer and remove
s1.

While there adjust fwmark option print order in iptnl
and ip6tnl to get it match each other.

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

index 490d7db8d62e47a62934d9e6581f57ef0c96f857..2462828e8e2d3cecd60d7941a653d0855401ea47 100644 (file)
@@ -443,9 +443,8 @@ static void gre_print_direct_opt(FILE *f, struct rtattr *tb[])
                __u32 fwmark = rta_getattr_u32(tb[IFLA_GRE_FWMARK]);
 
                if (fwmark) {
-                       snprintf(s2, sizeof(s2), "0x%x", fwmark);
-
-                       print_string(PRINT_ANY, "fwmark", "fwmark %s ", s2);
+                       print_0xhex(PRINT_ANY,
+                                   "fwmark", "fwmark 0x%x ", fwmark);
                }
        }
 }
index 37bc5444daf61fc66ce22490b9ea4d7081e3756f..7dcd70de9240c3fb78ec9d1b21a590265f9d27bf 100644 (file)
@@ -497,18 +497,17 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
        if (oflags & GRE_CSUM)
                print_bool(PRINT_ANY, "ocsum", "ocsum ", true);
 
-       if (flags & IP6_TNL_F_USE_ORIG_FWMARK)
+       if (flags & IP6_TNL_F_USE_ORIG_FWMARK) {
                print_bool(PRINT_ANY,
                           "ip6_tnl_f_use_orig_fwmark",
                           "fwmark inherit ",
                           true);
-       else if (tb[IFLA_GRE_FWMARK]) {
+       else if (tb[IFLA_GRE_FWMARK]) {
                __u32 fwmark = rta_getattr_u32(tb[IFLA_GRE_FWMARK]);
 
                if (fwmark) {
-                       snprintf(s2, sizeof(s2), "0x%x", fwmark);
-
-                       print_string(PRINT_ANY, "fwmark", "fwmark %s ", s2);
+                       print_0xhex(PRINT_ANY,
+                                   "fwmark", "fwmark 0x%x ", fwmark);
                }
        }
 
index 605bc614d4b93633702d49246829b25dad5c2a31..00bf00a3ffb9ded84a8fc2c527d0c1ca0e80b531 100644 (file)
@@ -438,6 +438,12 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb
        if (flags & IP6_TNL_F_MIP6_DEV)
                print_bool(PRINT_ANY, "ip6_tnl_f_mip6_dev", "mip6 ", true);
 
+       if (flags & IP6_TNL_F_ALLOW_LOCAL_REMOTE)
+               print_bool(PRINT_ANY,
+                          "ip6_tnl_f_allow_local_remote",
+                          "allow-localremote ",
+                          true);
+
        if (flags & IP6_TNL_F_USE_ORIG_FWMARK) {
                print_bool(PRINT_ANY,
                           "ip6_tnl_f_use_orig_fwmark",
@@ -447,19 +453,11 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb
                __u32 fwmark = rta_getattr_u32(tb[IFLA_IPTUN_FWMARK]);
 
                if (fwmark) {
-                       SPRINT_BUF(b1);
-
-                       snprintf(b1, sizeof(b1), "0x%x", fwmark);
-                       print_string(PRINT_ANY, "fwmark", "fwmark %s ", b1);
+                       print_0xhex(PRINT_ANY,
+                                   "fwmark", "fwmark 0x%x ", fwmark);
                }
        }
 
-       if (flags & IP6_TNL_F_ALLOW_LOCAL_REMOTE)
-               print_bool(PRINT_ANY,
-                          "ip6_tnl_f_allow_local_remote",
-                          "allow-localremote ",
-                          true);
-
        if (tb[IFLA_IPTUN_ENCAP_TYPE] &&
            rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_TYPE]) != TUNNEL_ENCAP_NONE) {
                __u16 type = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_TYPE]);
index 7fda580f15236ebf4e4f933776dbdd5b9cfa3af5..00a8366cda935a0fa4474663939c9e2ea633fd0e 100644 (file)
@@ -360,7 +360,6 @@ get_failed:
 
 static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 {
-       char s1[1024];
        char s2[64];
        const char *local = "any";
        const char *remote = "any";
@@ -455,7 +454,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
 
                const char *prefix = inet_ntop(AF_INET6,
                                               RTA_DATA(tb[IFLA_IPTUN_6RD_PREFIX]),
-                                              s1, sizeof(s1));
+                                              s2, sizeof(s2));
 
                if (is_json_context()) {
                        print_string(PRINT_JSON, "prefix", NULL, prefix);
@@ -482,6 +481,15 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
                }
        }
 
+       if (tb[IFLA_IPTUN_FWMARK]) {
+               __u32 fwmark = rta_getattr_u32(tb[IFLA_IPTUN_FWMARK]);
+
+               if (fwmark) {
+                       print_0xhex(PRINT_ANY,
+                                   "fwmark", "fwmark 0x%x ", fwmark);
+               }
+       }
+
        if (tb[IFLA_IPTUN_ENCAP_TYPE] &&
            (type = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_TYPE])) != TUNNEL_ENCAP_NONE) {
                __u16 flags = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_FLAGS]);
@@ -545,16 +553,6 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
                                fputs("noencap-remcsum ", f);
                }
        }
-
-       if (tb[IFLA_IPTUN_FWMARK]) {
-               __u32 fwmark = rta_getattr_u32(tb[IFLA_IPTUN_FWMARK]);
-
-               if (fwmark) {
-                       snprintf(s2, sizeof(s2), "0x%x", fwmark);
-
-                       print_string(PRINT_ANY, "fwmark", "fwmark %s ", s2);
-               }
-       }
 }
 
 static void iptunnel_print_help(struct link_util *lu, int argc, char **argv,
index 554cfcc43466913e292f1398ec50378d768463b9..baaaf2f2ab5e7a13301d08fb8d72060637c36abd 100644 (file)
@@ -213,10 +213,8 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
                __u32 fwmark = rta_getattr_u32(tb[IFLA_VTI_FWMARK]);
 
                if (fwmark) {
-                       SPRINT_BUF(b1);
-
-                       snprintf(b1, sizeof(b1), "0x%x", fwmark);
-                       print_string(PRINT_ANY, "fwmark", "fwmark %s ", s2);
+                       print_0xhex(PRINT_ANY,
+                                   "fwmark", "fwmark 0x%x ", fwmark);
                }
        }
 }
index a63f49fa8d0203898f105c9dc8cce6b67c11c72b..952dbb08aa1143a03598cb77e43f6839ce4bbcfd 100644 (file)
@@ -212,9 +212,8 @@ static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
                __u32 fwmark = rta_getattr_u32(tb[IFLA_VTI_FWMARK]);
 
                if (fwmark) {
-                       snprintf(s2, sizeof(s2), "0x%x", fwmark);
-
-                       print_string(PRINT_ANY, "fwmark", "fwmark %s ", s2);
+                       print_0xhex(PRINT_ANY,
+                                   "fwmark", "fwmark 0x%x ", fwmark);
                }
        }
 }