netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: netdev@vger.kernel.org
Cc: Stephen Hemminger <stephen@networkplumber.org>, petrm@nvidia.com
Subject: [PATCH iproute2] ipaddress: accept symbolic names
Date: Fri,  2 Jun 2023 08:54:19 -0700	[thread overview]
Message-ID: <20230602155419.8958-1-stephen@networkplumber.org> (raw)

The function rtnl_addproto_a2n() was defined but never used.
Use it to allow for symbolic names, and fix the function signatures
so protocol value is consistently __u8.

Fixes: bdb8d8549ed9 ("ip: Support IP address protocol")
Cc: petrm@nvidia.com
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 include/rt_names.h |  4 ++--
 ip/ipaddress.c     |  2 +-
 lib/rt_names.c     | 18 +++++-------------
 3 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/include/rt_names.h b/include/rt_names.h
index e96d80f30554..0275030704c1 100644
--- a/include/rt_names.h
+++ b/include/rt_names.h
@@ -5,7 +5,7 @@
 #include <asm/types.h>
 
 const char *rtnl_rtprot_n2a(int id, char *buf, int len);
-const char *rtnl_addrprot_n2a(int id, char *buf, int len);
+const char *rtnl_addrprot_n2a(__u8 id, char *buf, int len);
 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);
@@ -14,7 +14,7 @@ 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);
-int rtnl_addrprot_a2n(__u32 *id, const char *arg);
+int rtnl_addrprot_a2n(__u8 *id, const char *arg);
 int rtnl_rtscope_a2n(__u32 *id, const char *arg);
 int rtnl_rttable_a2n(__u32 *id, const char *arg);
 int rtnl_rtrealm_a2n(__u32 *id, const char *arg);
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index c428dd3d5413..7accbf7d7822 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -2547,7 +2547,7 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv)
 			__u8 proto;
 
 			NEXT_ARG();
-			if (get_u8(&proto, *argv, 0))
+			if (rtnl_addrprot_a2n(&proto, *argv))
 				invarg("\"proto\" value is invalid\n", *argv);
 			addattr8(&req.n, sizeof(req), IFA_PROTO, proto);
 		} else {
diff --git a/lib/rt_names.c b/lib/rt_names.c
index 51d11fd056b1..b441e98f8078 100644
--- a/lib/rt_names.c
+++ b/lib/rt_names.c
@@ -242,9 +242,9 @@ static void rtnl_addrprot_initialize(void)
 	rtnl_addrprot_tab_initialized = true;
 }
 
-const char *rtnl_addrprot_n2a(int id, char *buf, int len)
+const char *rtnl_addrprot_n2a(__u8 id, char *buf, int len)
 {
-	if (id < 0 || id >= 256 || numeric)
+	if (numeric)
 		goto numeric;
 	if (!rtnl_addrprot_tab_initialized)
 		rtnl_addrprot_initialize();
@@ -255,27 +255,19 @@ numeric:
 	return buf;
 }
 
-int rtnl_addrprot_a2n(__u32 *id, const char *arg)
+int rtnl_addrprot_a2n(__u8 *id, const char *arg)
 {
-	static char *cache;
-	static unsigned long res;
+	unsigned long res;
 	char *end;
 	int i;
 
-	if (cache && strcmp(cache, arg) == 0) {
-		*id = res;
-		return 0;
-	}
-
 	if (!rtnl_addrprot_tab_initialized)
 		rtnl_addrprot_initialize();
 
 	for (i = 0; i < 256; i++) {
 		if (rtnl_addrprot_tab[i] &&
 		    strcmp(rtnl_addrprot_tab[i], arg) == 0) {
-			cache = rtnl_addrprot_tab[i];
-			res = i;
-			*id = res;
+			*id = i;
 			return 0;
 		}
 	}
-- 
2.39.2


             reply	other threads:[~2023-06-02 15:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-02 15:54 Stephen Hemminger [this message]
2023-06-02 21:30 ` [PATCH iproute2] ipaddress: accept symbolic names patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230602155419.8958-1-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=netdev@vger.kernel.org \
    --cc=petrm@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).