lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20231211140732.11475-18-bpoirier@nvidia.com>
Date: Mon, 11 Dec 2023 09:07:29 -0500
From: Benjamin Poirier <bpoirier@...dia.com>
To: netdev@...r.kernel.org
Cc: Petr Machata <petrm@...dia.com>,
	Roopa Prabhu <roopa@...dia.com>
Subject: [PATCH iproute2-next 17/20] bridge: Deduplicate print_range()

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.

Reviewed-by: Petr Machata <petrm@...dia.com>
Tested-by: Petr Machata <petrm@...dia.com>
Signed-off-by: Benjamin Poirier <bpoirier@...dia.com>
---
 bridge/vlan.c        | 14 --------------
 bridge/vni.c         | 14 --------------
 include/json_print.h |  2 ++
 lib/json_print.c     | 14 ++++++++++++++
 4 files changed, 16 insertions(+), 28 deletions(-)

diff --git a/bridge/vlan.c b/bridge/vlan.c
index 7a175b04..05e6a620 100644
--- a/bridge/vlan.c
+++ b/bridge/vlan.c
@@ -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;
diff --git a/bridge/vni.c b/bridge/vni.c
index 2c6d506a..ffc3e188 100644
--- a/bridge/vni.c
+++ b/bridge/vni.c
@@ -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];
diff --git a/include/json_print.h b/include/json_print.h
index 0b1d84f7..86dc5f16 100644
--- a/include/json_print.h
+++ b/include/json_print.h
@@ -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 id);
+
 int print_color_bool_opt(enum output_type type, enum color_attr color,
 			 const char *key, bool value, bool show);
 
diff --git a/lib/json_print.c b/lib/json_print.c
index 602de027..072105c0 100644
--- a/lib/json_print.c
+++ b/lib/json_print.c
@@ -374,3 +374,17 @@ 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 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;
+}
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ