]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ip netns: Delete all netns
authorVadim Kochan <vadim4j@gmail.com>
Sun, 18 Jan 2015 14:10:19 +0000 (16:10 +0200)
committerStephen Hemminger <shemming@brocade.com>
Thu, 5 Feb 2015 18:28:19 +0000 (10:28 -0800)
Allow delete all namespace names by:

    $ ip -all netns del

Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
ip/ipnetns.c
man/man8/ip-netns.8

index 59a9321374dc249e5296ffb9f2336a1a342c8ead..e4038ea72d7161d205b041344a5c0e405dcf79e2 100644 (file)
@@ -23,7 +23,7 @@ static int usage(void)
 {
        fprintf(stderr, "Usage: ip netns list\n");
        fprintf(stderr, "       ip netns add NAME\n");
-       fprintf(stderr, "       ip netns delete NAME\n");
+       fprintf(stderr, "       ip [-all] netns delete [NAME]\n");
        fprintf(stderr, "       ip netns identify [PID]\n");
        fprintf(stderr, "       ip netns pids NAME\n");
        fprintf(stderr, "       ip [-all] netns exec [NAME] cmd ...\n");
@@ -259,18 +259,11 @@ static int netns_identify(int argc, char **argv)
 
 }
 
-static int netns_delete(int argc, char **argv)
+static int on_netns_del(char *nsname, void *arg)
 {
-       const char *name;
        char netns_path[MAXPATHLEN];
 
-       if (argc < 1) {
-               fprintf(stderr, "No netns name specified\n");
-               return -1;
-       }
-
-       name = argv[0];
-       snprintf(netns_path, sizeof(netns_path), "%s/%s", NETNS_RUN_DIR, name);
+       snprintf(netns_path, sizeof(netns_path), "%s/%s", NETNS_RUN_DIR, nsname);
        umount2(netns_path, MNT_DETACH);
        if (unlink(netns_path) < 0) {
                fprintf(stderr, "Cannot remove namespace file \"%s\": %s\n",
@@ -280,6 +273,19 @@ static int netns_delete(int argc, char **argv)
        return 0;
 }
 
+static int netns_delete(int argc, char **argv)
+{
+       if (argc < 1 && !do_all) {
+               fprintf(stderr, "No netns name specified\n");
+               return -1;
+       }
+
+       if (do_all)
+               return netns_foreach(on_netns_del, NULL);
+
+       return on_netns_del(argv[0], NULL);
+}
+
 static int create_netns_dir(void)
 {
        /* Create the base netns directory if it doesn't exist */
index 7b9571ea0637137db4afb5744695e1a00ff40450..8e6999c0abcb72b9bb56e771a9498f59eee42de3 100644 (file)
@@ -16,9 +16,13 @@ ip-netns \- process network namespace management
 .BR "ip netns" " { " list " } "
 
 .ti -8
-.BR "ip netns" " { " add " | " delete " } "
+.B ip netns add
 .I NETNSNAME
 
+.ti -8
+.B ip [-all] netns del
+.RI "[ " NETNSNAME " ]"
+
 .ti -8
 .BR "ip netns identify"
 .RI "[ " PID " ]"
@@ -76,7 +80,7 @@ If NAME is available in /var/run/netns/ this command creates a new
 network namespace and assigns NAME.
 
 .TP
-.B ip netns delete NAME - delete the name of a network namespace
+.B ip [-all] netns delete [ NAME ] - delete the name of a network namespace(s)
 .sp
 If NAME is present in /var/run/netns it is umounted and the mount
 point is removed.  If this is the last user of the network namespace the
@@ -84,6 +88,10 @@ network namespace will be freed, otherwise the network namespace
 persists until it has no more users.  ip netns delete may fail if
 the mount point is in use in another mount namespace.
 
+If
+.B -all
+option was specified then all the network namespace names will be removed.
+
 .TP
 .B ip netns identify [PID] - Report network namespaces names for process
 .sp