]> git.ipfire.org Git - thirdparty/iproute2.git/commit
netns: allow negative nsid
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 6 Feb 2018 18:39:31 +0000 (19:39 +0100)
committerStephen Hemminger <stephen@networkplumber.org>
Thu, 8 Feb 2018 15:57:34 +0000 (07:57 -0800)
commit375d51caaaa7a381dbeab8fb622d3c6ff9597be7
tree51bc4f5bde4f4684297911d58c4311807448e5c3
parent5f8265536f6f511ec62d3a0ee7e1324a8720f7e3
netns: allow negative nsid

If the kernel receives a negative nsid it will automatically assign
the next available nsid. In this case alloc_netid() will set min and
max to 0 for ird_alloc(). And when max == 0 idr_alloc() will interpret
this as the maximum range, i.e. specific to nsids it will try to find
an id in the range [0,INT_MAX). This is intentionally supported in the
kernel for nsids.

Commit acbe9118ce80 ("ip netns: use strtol() instead of atoi()")
regressed ip netns in that respect although previously the use-case
was either accidentally supported or opaquely supported such that it
triggered the original commit. From what I can gather it went as
follows before: atoi() was called with a string indicating a negative
value which caused it to return -1 which was passed to the
kernel. Let's make it less opaque by introducing the keyword "auto":

ip netns set <netns-name> auto

will cause nsid to be set to -1 and the kernel will select an available
nsid.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
ip/ipnetns.c
man/man8/ip-netns.8