From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Dichtel Subject: [PATCH iproute2] ipnetns: parse nsid as a signed integer Date: Wed, 21 Nov 2018 10:44:27 +0100 Message-ID: <20181121094427.19007-1-nicolas.dichtel@6wind.com> References: <3df598c0-d90a-c794-e19b-22e0f61d4f49@gmail.com> Cc: netdev@vger.kernel.org, dsahern@gmail.com, joe@wand.net.nz, daniel@iogearbox.net, Nicolas Dichtel To: stephen@networkplumber.org Return-path: Received: from host.76.145.23.62.rev.coltfrance.com ([62.23.145.76]:54736 "EHLO proxy.6wind.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726705AbeKUUSs (ORCPT ); Wed, 21 Nov 2018 15:18:48 -0500 In-Reply-To: <3df598c0-d90a-c794-e19b-22e0f61d4f49@gmail.com> Sender: netdev-owner@vger.kernel.org List-ID: Don't confuse the user, nsid is a signed integer, this kind of command should return an error: 'ip netns set foo 0xffffffff'. Also, a valid value is a positive value. To let the kernel chooses a value, the keyword 'auto' must be used. Signed-off-by: Nicolas Dichtel --- ip/ipnetns.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ip/ipnetns.c b/ip/ipnetns.c index 0eac18cf2682..03879b496343 100644 --- a/ip/ipnetns.c +++ b/ip/ipnetns.c @@ -35,6 +35,7 @@ static int usage(void) fprintf(stderr, " ip [-all] netns exec [NAME] cmd ...\n"); fprintf(stderr, " ip netns monitor\n"); fprintf(stderr, " ip netns list-id\n"); + fprintf(stderr, "NETNSID := auto | POSITIVE-INT\n"); exit(-1); } @@ -739,8 +740,7 @@ static int netns_set(int argc, char **argv) { char netns_path[PATH_MAX]; const char *name; - unsigned int nsid; - int netns; + int netns, nsid; if (argc < 1) { fprintf(stderr, "No netns name specified\n"); @@ -754,8 +754,10 @@ static int netns_set(int argc, char **argv) /* If a negative nsid is specified the kernel will select the nsid. */ if (strcmp(argv[1], "auto") == 0) nsid = -1; - else if (get_unsigned(&nsid, argv[1], 0)) + else if (get_integer(&nsid, argv[1], 0)) invarg("Invalid \"netnsid\" value\n", argv[1]); + else if (nsid < 0) + invarg("\"netnsid\" value should be >= 0\n", argv[1]); snprintf(netns_path, sizeof(netns_path), "%s/%s", NETNS_RUN_DIR, name); netns = open(netns_path, O_RDONLY | O_CLOEXEC); -- 2.18.0