]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ipnetns: treat NETNSA_NSID and NETNSA_CURRENT_NSID as signed
authorGuillaume Nault <gnault@redhat.com>
Fri, 8 Nov 2019 17:00:12 +0000 (18:00 +0100)
committerDavid Ahern <dsahern@gmail.com>
Sat, 9 Nov 2019 01:33:00 +0000 (01:33 +0000)
These attributes are signed (with -1 meaning NETNSA_NSID_NOT_ASSIGNED).
So let's use rta_getattr_s32() and print_int() instead of their
unsigned counterpart to avoid confusion.

Signed-off-by: Guillaume Nault <gnault@redhat.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
ip/ipnetns.c

index fc58a04b57de2a54d260bc2b76f8bd11ef718722..06a773e43b7dffc3843c7595b60d52c74694dc3c 100644 (file)
@@ -137,7 +137,7 @@ int get_netnsid_from_name(const char *name)
        parse_rtattr(tb, NETNSA_MAX, NETNS_RTA(rthdr), len);
 
        if (tb[NETNSA_NSID]) {
-               ret = rta_getattr_u32(tb[NETNSA_NSID]);
+               ret = rta_getattr_s32(tb[NETNSA_NSID]);
        }
 
 out:
@@ -317,20 +317,20 @@ int print_nsid(struct nlmsghdr *n, void *arg)
        if (n->nlmsg_type == RTM_DELNSID)
                print_bool(PRINT_ANY, "deleted", "Deleted ", true);
 
-       nsid = rta_getattr_u32(tb[NETNSA_NSID]);
+       nsid = rta_getattr_s32(tb[NETNSA_NSID]);
        if (nsid < 0)
                print_string(PRINT_ANY, "nsid", "nsid %s ", "not-assigned");
        else
-               print_uint(PRINT_ANY, "nsid", "nsid %u ", nsid);
+               print_int(PRINT_ANY, "nsid", "nsid %d ", nsid);
 
        if (tb[NETNSA_CURRENT_NSID]) {
-               current = rta_getattr_u32(tb[NETNSA_CURRENT_NSID]);
+               current = rta_getattr_s32(tb[NETNSA_CURRENT_NSID]);
                if (current < 0)
                        print_string(PRINT_ANY, "current-nsid",
                                     "current-nsid %s ", "not-assigned");
                else
-                       print_uint(PRINT_ANY, "current-nsid",
-                                  "current-nsid %u ", current);
+                       print_int(PRINT_ANY, "current-nsid",
+                                 "current-nsid %d ", current);
        }
 
        c = netns_map_get_by_nsid(tb[NETNSA_CURRENT_NSID] ? current : nsid);
@@ -491,8 +491,7 @@ static int netns_list(int argc, char **argv)
                if (ipnetns_have_nsid()) {
                        id = get_netnsid_from_name(entry->d_name);
                        if (id >= 0)
-                               print_uint(PRINT_ANY, "id",
-                                          " (id: %d)", id);
+                               print_int(PRINT_ANY, "id", " (id: %d)", id);
                }
                print_string(PRINT_FP, NULL, "\n", NULL);
                close_json_object();