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: <d5dc56c34e06e00aadbf12a3f518cd250357d18c.1608746691.git.me@pmachata.org>
Date:   Wed, 23 Dec 2020 19:25:41 +0100
From:   Petr Machata <me@...chata.org>
To:     netdev@...r.kernel.org, dsahern@...il.com,
        stephen@...workplumber.org
Cc:     Petr Machata <me@...chata.org>
Subject: [PATCH iproute2-next 3/9] lib: rt_names: Add rtnl_dsfield_get_name()

For formatting DSCP (not full dsfield), it would be handy to be able to
just get the name from the name table, and not get any of the remaining
cruft related to formatting. Add a new entry point to just fetch the
name table string uninterpreted. Use it from rtnl_dsfield_n2a().

Signed-off-by: Petr Machata <me@...chata.org>
---
 include/rt_names.h |  1 +
 lib/rt_names.c     | 20 ++++++++++++++++----
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/include/rt_names.h b/include/rt_names.h
index 990ed7f22e69..1835f3be2bed 100644
--- a/include/rt_names.h
+++ b/include/rt_names.h
@@ -9,6 +9,7 @@ const char *rtnl_rtscope_n2a(int id, char *buf, int len);
 const char *rtnl_rttable_n2a(__u32 id, char *buf, int len);
 const char *rtnl_rtrealm_n2a(int id, char *buf, int len);
 const char *rtnl_dsfield_n2a(int id, char *buf, int len);
+const char *rtnl_dsfield_get_name(int id);
 const char *rtnl_group_n2a(int id, char *buf, int len);
 
 int rtnl_rtprot_a2n(__u32 *id, const char *arg);
diff --git a/lib/rt_names.c b/lib/rt_names.c
index ca0680a12150..b976471d7979 100644
--- a/lib/rt_names.c
+++ b/lib/rt_names.c
@@ -479,18 +479,30 @@ static void rtnl_rtdsfield_initialize(void)
 
 const char *rtnl_dsfield_n2a(int id, char *buf, int len)
 {
+	const char *name;
+
 	if (id < 0 || id >= 256) {
 		snprintf(buf, len, "%d", id);
 		return buf;
 	}
+	if (!numeric) {
+		name = rtnl_dsfield_get_name(id);
+		if (name != NULL)
+			return name;
+	}
+	snprintf(buf, len, "0x%02x", id);
+	return buf;
+}
+
+const char *rtnl_dsfield_get_name(int id)
+{
+	if (id < 0 || id >= 256)
+		return NULL;
 	if (!rtnl_rtdsfield_tab[id]) {
 		if (!rtnl_rtdsfield_init)
 			rtnl_rtdsfield_initialize();
 	}
-	if (!numeric && rtnl_rtdsfield_tab[id])
-		return rtnl_rtdsfield_tab[id];
-	snprintf(buf, len, "0x%02x", id);
-	return buf;
+	return rtnl_rtdsfield_tab[id];
 }
 
 
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ