From: Vadim Kochan <vadim4j@gmail.com>
To: netdev@vger.kernel.org
Cc: Vadim Kochan <vadim4j@gmail.com>
Subject: [PATCH iproute2 3/3] ip netns: Delete all netns
Date: Wed, 7 Jan 2015 13:04:22 +0200 [thread overview]
Message-ID: <1420628662-9930-4-git-send-email-vadim4j@gmail.com> (raw)
In-Reply-To: <1420628662-9930-1-git-send-email-vadim4j@gmail.com>
From: Vadim Kochan <vadim4j@gmail.com>
Allow delete all namespace names by:
$ ip netns del all
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
---
ip/ipnetns.c | 24 +++++++++++++++---------
man/man8/ip-netns.8 | 12 ++++++++++--
2 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index b5a6f57..20707b8 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -274,18 +274,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",
@@ -295,6 +288,19 @@ static int netns_delete(int argc, char **argv)
return 0;
}
+static int netns_delete(int argc, char **argv)
+{
+ if (argc < 1) {
+ fprintf(stderr, "No netns name specified\n");
+ return -1;
+ }
+
+ if (strcmp(argv[0], "all") == 0)
+ 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 */
diff --git a/man/man8/ip-netns.8 b/man/man8/ip-netns.8
index 70ea4f0..e56068e 100644
--- a/man/man8/ip-netns.8
+++ b/man/man8/ip-netns.8
@@ -16,10 +16,14 @@ 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 netns del
+.RI "{ " NETNSNAME " | " all " }"
+
+.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 netns delete { NAME | all } - 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
+was specified then all the network namespace names will be removed.
+
.TP
.B ip netns identify [PID] - Report network namespaces names for process
.sp
--
2.1.3
next prev parent reply other threads:[~2015-01-07 11:14 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-07 11:04 [PATCH iproute2 0/3] ip netns: Run over all netns Vadim Kochan
2015-01-07 11:04 ` [PATCH iproute2 1/3] lib: Exec func on each netns Vadim Kochan
2015-01-07 11:04 ` [PATCH iproute2 2/3] ip netns: Allow exec " Vadim Kochan
2015-01-07 11:04 ` Vadim Kochan [this message]
2015-01-07 15:44 ` [PATCH iproute2 3/3] ip netns: Delete all netns Brian Haley
2015-01-07 17:36 ` Vadim Kochan
2015-01-07 18:11 ` Vadim Kochan
2015-01-07 19:40 ` Brian Haley
2015-01-07 19:55 ` Vadim Kochan
2015-01-08 0:00 ` Cong Wang
2015-01-09 8:43 ` Jiri Benc
2015-01-09 9:54 ` Vadim Kochan
2015-01-09 14:24 ` Nicolas Dichtel
2015-01-08 0:04 ` [PATCH iproute2 0/3] ip netns: Run over " Cong Wang
2015-01-08 0:52 ` Vadim Kochan
2015-01-09 18:49 ` Cong Wang
2015-01-09 19:17 ` Vadim Kochan
2015-01-14 1:28 ` Stephen Hemminger
2015-01-14 16:13 ` Vadim Kochan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1420628662-9930-4-git-send-email-vadim4j@gmail.com \
--to=vadim4j@gmail.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).