diff --git a/ip/ipnetns.c b/ip/ipnetns.c index 059a4220..631794b8 100644 --- a/ip/ipnetns.c +++ b/ip/ipnetns.c @@ -718,7 +718,10 @@ static int netns_set(int argc, char **argv) return -1; } name = argv[0]; - if (get_unsigned(&nsid, argv[1], 0)) + /* 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)) invarg("Invalid \"netnsid\" value\n", argv[1]); snprintf(netns_path, sizeof(netns_path), "%s/%s", NETNS_RUN_DIR, name); diff --git a/man/man8/ip-netns.8 b/man/man8/ip-netns.8 index c5310e24..d539f18b 100644 --- a/man/man8/ip-netns.8 +++ b/man/man8/ip-netns.8 @@ -137,6 +137,7 @@ $ ip netns del net0 .sp This command assigns a id to a peer network namespace. This id is valid only in the current network namespace. +If the keyword "auto" is specified an available nsid will be chosen. This id will be used by the kernel in some netlink messages. If no id is assigned when the kernel needs it, it will be automatically assigned by the kernel.