netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nicolas Dichtel <nicolas.dichtel@6wind.com>
To: stephen@networkplumber.org
Cc: netdev@vger.kernel.org, Nicolas Dichtel <nicolas.dichtel@6wind.com>
Subject: [PATCH iproute2 1/2] ip: display netns name instead of nsid
Date: Mon,  4 Jun 2018 14:12:52 +0200	[thread overview]
Message-ID: <20180604121253.2140-2-nicolas.dichtel@6wind.com> (raw)
In-Reply-To: <20180604121253.2140-1-nicolas.dichtel@6wind.com>

When iproute2 has a name for the nsid, let's display it. It's more
user friendly than a number.

Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
 ip/ip_common.h |  1 +
 ip/ipaddress.c | 23 ++++++++++++++++++-----
 ip/ipnetns.c   | 10 ++++++++++
 3 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/ip/ip_common.h b/ip/ip_common.h
index 49eb7d7bed40..794478c546cd 100644
--- a/ip/ip_common.h
+++ b/ip/ip_common.h
@@ -60,6 +60,7 @@ void netns_map_init(void);
 void netns_nsid_socket_init(void);
 int print_nsid(const struct sockaddr_nl *who,
 	       struct nlmsghdr *n, void *arg);
+char *get_name_from_nsid(int nsid);
 int do_ipaddr(int argc, char **argv);
 int do_ipaddrlabel(int argc, char **argv);
 int do_iproute(int argc, char **argv);
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index c7c7e7df4e81..aee09c7ff6df 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -819,6 +819,9 @@ int print_linkinfo(const struct sockaddr_nl *who,
 	unsigned int m_flag = 0;
 	SPRINT_BUF(b1);
 
+	netns_nsid_socket_init();
+	netns_map_init();
+
 	if (n->nlmsg_type != RTM_NEWLINK && n->nlmsg_type != RTM_DELLINK)
 		return 0;
 
@@ -955,10 +958,16 @@ int print_linkinfo(const struct sockaddr_nl *who,
 		if (is_json_context()) {
 			print_int(PRINT_JSON, "link_netnsid", NULL, id);
 		} else {
-			if (id >= 0)
-				print_int(PRINT_FP, NULL,
-					  " link-netnsid %d", id);
-			else
+			if (id >= 0) {
+				char *name = get_name_from_nsid(id);
+
+				if (name)
+					print_string(PRINT_FP, NULL,
+						     " link-netns %s", name);
+				else
+					print_int(PRINT_FP, NULL,
+						  " link-netnsid %d", id);
+			} else
 				print_string(PRINT_FP, NULL,
 					     " link-netnsid %s", "unknown");
 		}
@@ -966,8 +975,12 @@ int print_linkinfo(const struct sockaddr_nl *who,
 
 	if (tb[IFLA_NEW_NETNSID]) {
 		int id = rta_getattr_u32(tb[IFLA_NEW_NETNSID]);
+		char *name = get_name_from_nsid(id);
 
-		print_int(PRINT_FP, NULL, " new-nsid %d", id);
+		if (name)
+			print_string(PRINT_FP, NULL, " new-netns %s", name);
+		else
+			print_int(PRINT_FP, NULL, " new-netnsid %d", id);
 	}
 	if (tb[IFLA_NEW_IFINDEX]) {
 		int id = rta_getattr_u32(tb[IFLA_NEW_IFINDEX]);
diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index e06100f4ad2d..a4f5b02427e7 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -169,6 +169,16 @@ static struct nsid_cache *netns_map_get_by_nsid(int nsid)
 	return NULL;
 }
 
+char *get_name_from_nsid(int nsid)
+{
+	struct nsid_cache *c = netns_map_get_by_nsid(nsid);
+
+	if (c)
+		return c->name;
+
+	return NULL;
+}
+
 static int netns_map_add(int nsid, const char *name)
 {
 	struct nsid_cache *c;
-- 
2.15.1

  reply	other threads:[~2018-06-04 12:13 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-31 14:28 [PATCH iproute2] ip: IFLA_NEW_NETNSID/IFLA_NEW_IFINDEX support Nicolas Dichtel
2018-05-31 14:31 ` Nicolas Dichtel
2018-05-31 15:46 ` Stephen Hemminger
2018-05-31 15:51   ` Nicolas Dichtel
2018-06-01 15:02     ` Nicolas Dichtel
2018-06-01 20:02       ` Stephen Hemminger
2018-06-04 12:12   ` [PATCH iproute2 0/2] display netns name instead of nsid Nicolas Dichtel
2018-06-04 12:12     ` Nicolas Dichtel [this message]
2018-06-04 21:12       ` [PATCH iproute2 1/2] ip: " Stephen Hemminger
2018-06-05 13:08         ` [PATCH iproute2 v2 0/2] " Nicolas Dichtel
2018-06-05 13:08           ` [PATCH iproute2 v2 1/2] ip: " Nicolas Dichtel
2018-06-05 16:52             ` Stephen Hemminger
2018-06-06  7:11               ` Nicolas Dichtel
2018-06-05 13:08           ` [PATCH iproute2 v2 2/2] iplink: enable to specify a name for the link-netns Nicolas Dichtel
2018-06-08 17:08           ` [PATCH iproute2 v2 0/2] display netns name instead of nsid Stephen Hemminger
2018-06-04 12:12     ` [PATCH iproute2 2/2] iplink: enable to specify a name for the link-netns Nicolas Dichtel

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=20180604121253.2140-2-nicolas.dichtel@6wind.com \
    --to=nicolas.dichtel@6wind.com \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    /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).