]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
ip: display netns name instead of nsid
authorNicolas Dichtel <nicolas.dichtel@6wind.com>
Tue, 5 Jun 2018 13:08:30 +0000 (15:08 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Fri, 8 Jun 2018 17:06:21 +0000 (10:06 -0700)
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>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
ip/ip_common.h
ip/ipaddress.c
ip/ipnetns.c

index 49eb7d7bed401120d8f765d881d4589e0c73f555..794478c546cd33901c25363a942528575e953c6a 100644 (file)
@@ -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);
index c7c7e7df4e813104c47a7d0b5b07414742080fb1..e4a1b985e4e9d50f6722429e301a0402943c67ca 100644 (file)
@@ -955,10 +955,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 +972,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]);
index e06100f4ad2d2896705c76ff43167965d8c09975..30af9319f39e8e3468d9fd5d3eed5c71b6bc86f2 100644 (file)
@@ -169,6 +169,20 @@ 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_nsid_socket_init();
+       netns_map_init();
+
+       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;