]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
bridge: Deduplicate print_range()
authorBenjamin Poirier <bpoirier@nvidia.com>
Mon, 11 Dec 2023 14:07:29 +0000 (09:07 -0500)
committerStephen Hemminger <stephen@networkplumber.org>
Fri, 22 Dec 2023 17:57:54 +0000 (09:57 -0800)
The two implementations are now identical so keep only one instance and
move it to json_print.c where there are already a few other specialized
printing functions.

The string that's formatted in the "end" buffer is only needed when
outputting a range so move the snprintf() call within the condition.

The second argument's purpose is better conveyed by calling it "end" rather
than "id" so rename it.

Reviewed-by: Petr Machata <petrm@nvidia.com>
Tested-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: Benjamin Poirier <bpoirier@nvidia.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
bridge/vlan.c
bridge/vni.c
include/json_print.h
lib/json_print.c

index 7a175b047b9226ababdc08eb3c79c314dd39c127..05e6a6206d8d20175ac26e9211b1eb7bcc15de68 100644 (file)
@@ -590,20 +590,6 @@ static void close_vlan_port(void)
        close_json_object();
 }
 
-static unsigned int print_range(const char *name, __u32 start, __u32 id)
-{
-       char end[64];
-       int width;
-
-       snprintf(end, sizeof(end), "%sEnd", name);
-
-       width = print_uint(PRINT_ANY, name, "%u", start);
-       if (start != id)
-               width += print_uint(PRINT_ANY, end, "-%u", id);
-
-       return width;
-}
-
 static void print_vlan_tunnel_info(struct rtattr *tb, int ifindex)
 {
        struct rtattr *i, *list = tb;
index 2c6d506a72de5f09822f851622c3430b7d98739f..ffc3e18879617d43540f0cb633d9edf0180cd412 100644 (file)
@@ -163,20 +163,6 @@ static void close_vni_port(void)
        close_json_object();
 }
 
-static unsigned int print_range(const char *name, __u32 start, __u32 id)
-{
-       char end[64];
-       int width;
-
-       snprintf(end, sizeof(end), "%sEnd", name);
-
-       width = print_uint(PRINT_ANY, name, "%u", start);
-       if (start != id)
-               width += print_uint(PRINT_ANY, end, "-%u", id);
-
-       return width;
-}
-
 static void print_vnifilter_entry_stats(struct rtattr *stats_attr)
 {
        struct rtattr *stb[VNIFILTER_ENTRY_STATS_MAX+1];
index 0b1d84f787498373ca793360e3cb2d63e83d3f0e..daebcf5d25f5967346806518159bf1c4866863d4 100644 (file)
@@ -97,6 +97,8 @@ static inline int print_rate(bool use_iec, enum output_type t,
        return print_color_rate(use_iec, t, COLOR_NONE, key, fmt, rate);
 }
 
+unsigned int print_range(const char *name, __u32 start, __u32 end);
+
 int print_color_bool_opt(enum output_type type, enum color_attr color,
                         const char *key, bool value, bool show);
 
index 602de027ca27b8867d3b6795aa26e4ffb0a171a6..7b3b6c3fafba97ef94a1748125647a4031c3f224 100644 (file)
@@ -374,3 +374,18 @@ int print_color_rate(bool use_iec, enum output_type type, enum color_attr color,
        free(buf);
        return rc;
 }
+
+unsigned int print_range(const char *name, __u32 start, __u32 end)
+{
+       int width;
+
+       width = print_uint(PRINT_ANY, name, "%u", start);
+       if (start != end) {
+               char buf[64];
+
+               snprintf(buf, sizeof(buf), "%sEnd", name);
+               width += print_uint(PRINT_ANY, buf, "-%u", end);
+       }
+
+       return width;
+}