All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2 0/3] ip netns: Run over all netns
@ 2015-01-07 11:04 Vadim Kochan
  2015-01-07 11:04 ` [PATCH iproute2 1/3] lib: Exec func on each netns Vadim Kochan
                   ` (4 more replies)
  0 siblings, 5 replies; 19+ messages in thread
From: Vadim Kochan @ 2015-01-07 11:04 UTC (permalink / raw)
  To: netdev; +Cc: Vadim Kochan

From: Vadim Kochan <vadim4j@gmail.com>

Allow 'ip netns del' and 'ip netns exec' run over each network namespace names.

'ip netns exec' executes command forcely on eacn nsname.

Vadim Kochan (3):
  lib: Exec func on each netns
  ip netns: Allow exec on each netns
  ip netns: Delete all netns

 include/namespace.h |  6 ++++
 include/utils.h     |  5 +++
 ip/ipnetns.c        | 96 ++++++++++++++++++++++++++++++++---------------------
 lib/namespace.c     | 22 ++++++++++++
 lib/utils.c         | 28 ++++++++++++++++
 man/man8/ip-netns.8 | 26 ++++++++++++---
 6 files changed, 141 insertions(+), 42 deletions(-)

-- 
2.1.3

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH iproute2 1/3] lib: Exec func on each netns
  2015-01-07 11:04 [PATCH iproute2 0/3] ip netns: Run over all netns Vadim Kochan
@ 2015-01-07 11:04 ` Vadim Kochan
  2015-01-07 11:04 ` [PATCH iproute2 2/3] ip netns: Allow exec " Vadim Kochan
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 19+ messages in thread
From: Vadim Kochan @ 2015-01-07 11:04 UTC (permalink / raw)
  To: netdev; +Cc: Vadim Kochan

From: Vadim Kochan <vadim4j@gmail.com>

Added possibility to run some func on each netns.

Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
---
 include/namespace.h |  6 ++++++
 include/utils.h     |  5 +++++
 lib/namespace.c     | 22 ++++++++++++++++++++++
 lib/utils.c         | 28 ++++++++++++++++++++++++++++
 4 files changed, 61 insertions(+)

diff --git a/include/namespace.h b/include/namespace.h
index 2f13e65..1a7e066 100644
--- a/include/namespace.h
+++ b/include/namespace.h
@@ -42,5 +42,11 @@ static int setns(int fd, int nstype)
 #endif /* HAVE_SETNS */
 
 extern int netns_switch(char *netns);
+extern int netns_foreach(int (*func)(char *nsname, void *arg), void *arg);
+
+struct netns_func {
+	int (*func)(char *nsname, void *arg);
+	void *arg;
+};
 
 #endif /* __NAMESPACE_H__ */
diff --git a/include/utils.h b/include/utils.h
index eecbc39..3196561 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -5,6 +5,7 @@
 #include <asm/types.h>
 #include <resolv.h>
 #include <stdlib.h>
+#include <stdbool.h>
 
 #include "libnetlink.h"
 #include "ll_map.h"
@@ -160,4 +161,8 @@ struct iplink_req;
 int iplink_parse(int argc, char **argv, struct iplink_req *req,
 		char **name, char **type, char **link, char **dev,
 		int *group, int *index);
+
+extern int do_each_netns(int (*func)(char *nsname, void *arg), void *arg,
+		bool show_label);
+
 #endif /* __UTILS_H__ */
diff --git a/lib/namespace.c b/lib/namespace.c
index 1554ce0..a0f7c6d 100644
--- a/lib/namespace.c
+++ b/lib/namespace.c
@@ -84,3 +84,25 @@ int netns_switch(char *name)
 	bind_etc(name);
 	return 0;
 }
+
+int netns_foreach(int (*func)(char *nsname, void *arg), void *arg)
+{
+	DIR *dir;
+	struct dirent *entry;
+
+	dir = opendir(NETNS_RUN_DIR);
+	if (!dir)
+		return -1;
+
+	while ((entry = readdir(dir)) != NULL) {
+		if (strcmp(entry->d_name, ".") == 0)
+			continue;
+		if (strcmp(entry->d_name, "..") == 0)
+			continue;
+		if (func(entry->d_name, arg))
+			break;
+	}
+
+	closedir(dir);
+	return 0;
+}
diff --git a/lib/utils.c b/lib/utils.c
index 64915f3..e3ca11b 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -31,6 +31,7 @@
 
 
 #include "utils.h"
+#include "namespace.h"
 
 int timestamp_short = 0;
 
@@ -868,3 +869,30 @@ int inet_get_addr(const char *src, __u32 *dst, struct in6_addr *dst6)
 	else
 		return inet_pton(AF_INET, src, dst);
 }
+
+static int on_netns(char *nsname, void *arg)
+{
+	struct netns_func *f = arg;
+
+	if (netns_switch(nsname))
+		return -1;
+
+	return f->func(nsname, f->arg);
+}
+
+static int on_netns_label(char *nsname, void *arg)
+{
+	printf("\nnetns: %s\n", nsname);
+	return on_netns(nsname, arg);
+}
+
+int do_each_netns(int (*func)(char *nsname, void *arg), void *arg,
+		bool show_label)
+{
+	struct netns_func nsf = { .func = func, .arg = arg };
+
+	if (show_label)
+		return netns_foreach(on_netns_label, &nsf);
+
+	return netns_foreach(on_netns, &nsf);
+}
-- 
2.1.3

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH iproute2 2/3] ip netns: Allow exec on each netns
  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 ` Vadim Kochan
  2015-01-07 11:04 ` [PATCH iproute2 3/3] ip netns: Delete all netns Vadim Kochan
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 19+ messages in thread
From: Vadim Kochan @ 2015-01-07 11:04 UTC (permalink / raw)
  To: netdev; +Cc: Vadim Kochan

From: Vadim Kochan <vadim4j@gmail.com>

This change allows to exec some cmd on each
netns (except default) by specifying 'all' as netns name:

    # ip netns exec all ip link

Each command executes synchronously.

Exit status is not considered, so there might be a case
that some CMD can fail on some netns but success on the other.

EXAMPLES:

1) Show link info on all netns:

$ ip netns exec all ip link

netns: test_net
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
4: tap0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 500
    link/ether 1a:19:6f:25:eb:85 brd ff:ff:ff:ff:ff:ff

netns: home0
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
4: tap0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 500
    link/ether ea:1a:59:40:d3:29 brd ff:ff:ff:ff:ff:ff

netns: lan0
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
4: tap0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 500
    link/ether ce:49:d5:46:81:ea brd ff:ff:ff:ff:ff:ff

2) Set UP tap0 device for the all netns:

$ ip netns exec all ip link set dev tap0 up

netns: test_net

netns: home0

netns: lan0

Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
---
 ip/ipnetns.c        | 72 ++++++++++++++++++++++++++++++++---------------------
 man/man8/ip-netns.8 | 14 +++++++++--
 2 files changed, 55 insertions(+), 31 deletions(-)

diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index 519d518..b5a6f57 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -26,7 +26,7 @@ static int usage(void)
 	fprintf(stderr, "       ip netns delete NAME\n");
 	fprintf(stderr, "       ip netns identify [PID]\n");
 	fprintf(stderr, "       ip netns pids NAME\n");
-	fprintf(stderr, "       ip netns exec NAME cmd ...\n");
+	fprintf(stderr, "       ip netns exec { NAME | all } cmd ...\n");
 	fprintf(stderr, "       ip netns monitor\n");
 	exit(-1);
 }
@@ -66,29 +66,10 @@ static int netns_list(int argc, char **argv)
 	return 0;
 }
 
-static int netns_exec(int argc, char **argv)
+static int cmd_exec(const char *cmd, char **argv, bool do_fork)
 {
-	/* Setup the proper environment for apps that are not netns
-	 * aware, and execute a program in that environment.
-	 */
-	const char *cmd;
-
-	if (argc < 1) {
-		fprintf(stderr, "No netns name specified\n");
-		return -1;
-	}
-	if (argc < 2) {
-		fprintf(stderr, "No command specified\n");
-		return -1;
-	}
-	cmd = argv[1];
-
-	if (netns_switch(argv[0]))
-		return -1;
-
 	fflush(stdout);
-
-	if (batch_mode) {
+	if (do_fork) {
 		int status;
 		pid_t pid;
 
@@ -106,23 +87,56 @@ static int netns_exec(int argc, char **argv)
 			}
 
 			if (WIFEXITED(status)) {
-				/* ip must return the status of the child,
-				 * but do_cmd() will add a minus to this,
-				 * so let's add another one here to cancel it.
-				 */
-				return -WEXITSTATUS(status);
+				return WEXITSTATUS(status);
 			}
 
 			exit(1);
 		}
 	}
 
-	if (execvp(cmd, argv + 1)  < 0)
+	if (execvp(cmd, argv)  < 0)
 		fprintf(stderr, "exec of \"%s\" failed: %s\n",
-			cmd, strerror(errno));
+				cmd, strerror(errno));
 	_exit(1);
 }
 
+static int on_netns_exec(char *nsname, void *arg)
+{
+	char **argv = arg;
+	cmd_exec(argv[1], argv + 1, 1);
+	return 0;
+}
+
+static int netns_exec(int argc, char **argv)
+{
+	/* Setup the proper environment for apps that are not netns
+	 * aware, and execute a program in that environment.
+	 */
+	const char *cmd;
+
+	if (argc < 1) {
+		fprintf(stderr, "No netns name specified\n");
+		return -1;
+	}
+	if (argc < 2) {
+		fprintf(stderr, "No command specified\n");
+		return -1;
+	}
+	cmd = argv[1];
+
+	if (strcmp(argv[0], "all") == 0)
+		return do_each_netns(on_netns_exec, argv, 1);
+
+	if (netns_switch(argv[0]))
+		return -1;
+
+	/* ip must return the status of the child,
+	 * but do_cmd() will add a minus to this,
+	 * so let's add another one here to cancel it.
+	 */
+	return -cmd_exec(cmd, argv + 1, batch_mode);
+}
+
 static int is_pid(const char *str)
 {
 	int ch;
diff --git a/man/man8/ip-netns.8 b/man/man8/ip-netns.8
index 74343ed..70ea4f0 100644
--- a/man/man8/ip-netns.8
+++ b/man/man8/ip-netns.8
@@ -29,7 +29,7 @@ ip-netns \- process network namespace management
 
 .ti -8
 .BR "ip netns exec "
-.I NETNSNAME command ...
+.RI "{ " NETNSNAME " | " all " } " command ...
 
 .ti -8
 .BR "ip netns monitor"
@@ -98,7 +98,7 @@ This command walks through proc and finds all of the process who have
 the named network namespace as their primary network namespace.
 
 .TP
-.B ip netns exec NAME cmd ... - Run cmd in the named network namespace
+.B ip netns exec { NAME | all } cmd ... - Run cmd in the named network namespace
 .sp
 This command allows applications that are network namespace unaware
 to be run in something other than the default network namespace with
@@ -107,6 +107,16 @@ in the customary global locations.  A network namespace and bind mounts
 are used to move files from their network namespace specific location
 to their default locations without affecting other processes.
 
+If
+.B all
+was specified then
+.B cmd
+will be executed synchronously on the each named network namespace even if
+.B cmd
+fails on some of them. Network namespace name is printed on each
+.B cmd
+executing.
+
 .TP
 .B ip netns monitor - Report as network namespace names are added and deleted
 .sp
-- 
2.1.3

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH iproute2 3/3] ip netns: Delete all netns
  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
  2015-01-07 15:44   ` Brian Haley
  2015-01-08  0:04 ` [PATCH iproute2 0/3] ip netns: Run over " Cong Wang
  2015-01-14  1:28 ` Stephen Hemminger
  4 siblings, 1 reply; 19+ messages in thread
From: Vadim Kochan @ 2015-01-07 11:04 UTC (permalink / raw)
  To: netdev; +Cc: Vadim Kochan

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

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH iproute2 3/3] ip netns: Delete all netns
  2015-01-07 11:04 ` [PATCH iproute2 3/3] ip netns: Delete all netns Vadim Kochan
@ 2015-01-07 15:44   ` Brian Haley
  2015-01-07 17:36     ` Vadim Kochan
  0 siblings, 1 reply; 19+ messages in thread
From: Brian Haley @ 2015-01-07 15:44 UTC (permalink / raw)
  To: Vadim Kochan, netdev

On 01/07/2015 06:04 AM, Vadim Kochan wrote:
> From: Vadim Kochan <vadim4j@gmail.com>
> 
> Allow delete all namespace names by:
> 
>     $ ip netns del all

So I can still create a namespace called 'all', but can't exec in it or delete
it independently with this change.  Perhaps you need to block that as well?
Unless there's some other patch I'm missing?

-Brian

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH iproute2 3/3] ip netns: Delete all netns
  2015-01-07 15:44   ` Brian Haley
@ 2015-01-07 17:36     ` Vadim Kochan
  2015-01-07 18:11       ` Vadim Kochan
  0 siblings, 1 reply; 19+ messages in thread
From: Vadim Kochan @ 2015-01-07 17:36 UTC (permalink / raw)
  To: Brian Haley; +Cc: Vadim Kochan, netdev

On Wed, Jan 07, 2015 at 10:44:24AM -0500, Brian Haley wrote:
> On 01/07/2015 06:04 AM, Vadim Kochan wrote:
> > From: Vadim Kochan <vadim4j@gmail.com>
> > 
> > Allow delete all namespace names by:
> > 
> >     $ ip netns del all
> 
> So I can still create a namespace called 'all', but can't exec in it or delete
> it independently with this change.  Perhaps you need to block that as well?
> Unless there's some other patch I'm missing?
> 
> -Brian
Hm, I did not take it into account ...
I will look if I can find another way ...

Thanks,

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH iproute2 3/3] ip netns: Delete all netns
  2015-01-07 17:36     ` Vadim Kochan
@ 2015-01-07 18:11       ` Vadim Kochan
  2015-01-07 19:40         ` Brian Haley
  0 siblings, 1 reply; 19+ messages in thread
From: Vadim Kochan @ 2015-01-07 18:11 UTC (permalink / raw)
  To: Brian Haley; +Cc: Vadim Kochan, netdev

On Wed, Jan 07, 2015 at 07:36:40PM +0200, Vadim Kochan wrote:
> On Wed, Jan 07, 2015 at 10:44:24AM -0500, Brian Haley wrote:
> > On 01/07/2015 06:04 AM, Vadim Kochan wrote:
> > > From: Vadim Kochan <vadim4j@gmail.com>
> > > 
> > > Allow delete all namespace names by:
> > > 
> > >     $ ip netns del all
> > 
> > So I can still create a namespace called 'all', but can't exec in it or delete
> > it independently with this change.  Perhaps you need to block that as well?
> > Unless there's some other patch I'm missing?
> > 
> > -Brian
> Hm, I did not take it into account ...
> I will look if I can find another way ...
> 
> Thanks,

what about this ?

    $ ip netns exec / ip link
    $ ip netns del /

so it make a sense to be as root directory of bound ns names in /var/run/netns/ ?
what do you think ?

Regards,

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH iproute2 3/3] ip netns: Delete all netns
  2015-01-07 18:11       ` Vadim Kochan
@ 2015-01-07 19:40         ` Brian Haley
  2015-01-07 19:55           ` Vadim Kochan
  0 siblings, 1 reply; 19+ messages in thread
From: Brian Haley @ 2015-01-07 19:40 UTC (permalink / raw)
  To: Vadim Kochan; +Cc: netdev

On 01/07/2015 01:11 PM, Vadim Kochan wrote:
> On Wed, Jan 07, 2015 at 07:36:40PM +0200, Vadim Kochan wrote:
>> On Wed, Jan 07, 2015 at 10:44:24AM -0500, Brian Haley wrote:
>>> On 01/07/2015 06:04 AM, Vadim Kochan wrote:
>>>> From: Vadim Kochan <vadim4j@gmail.com>
>>>>
>>>> Allow delete all namespace names by:
>>>>
>>>>     $ ip netns del all
>>>
>>> So I can still create a namespace called 'all', but can't exec in it or delete
>>> it independently with this change.  Perhaps you need to block that as well?
>>> Unless there's some other patch I'm missing?
>>>
>>> -Brian
>> Hm, I did not take it into account ...
>> I will look if I can find another way ...
>>
>> Thanks,
> 
> what about this ?
> 
>     $ ip netns exec / ip link
>     $ ip netns del /
> 
> so it make a sense to be as root directory of bound ns names in /var/run/netns/ ?
> what do you think ?

I think using / is confusing.  And something like -a[ll] as an option doesn't
seem right either.

Or you just trap the name "all" in the add case and don't allow it.

Just my opinion.

-Brian

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH iproute2 3/3] ip netns: Delete all netns
  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
  0 siblings, 2 replies; 19+ messages in thread
From: Vadim Kochan @ 2015-01-07 19:55 UTC (permalink / raw)
  To: Brian Haley; +Cc: Vadim Kochan, netdev

On Wed, Jan 07, 2015 at 02:40:51PM -0500, Brian Haley wrote:
> On 01/07/2015 01:11 PM, Vadim Kochan wrote:
> > On Wed, Jan 07, 2015 at 07:36:40PM +0200, Vadim Kochan wrote:
> >> On Wed, Jan 07, 2015 at 10:44:24AM -0500, Brian Haley wrote:
> >>> On 01/07/2015 06:04 AM, Vadim Kochan wrote:
> >>>> From: Vadim Kochan <vadim4j@gmail.com>
> >>>>
> >>>> Allow delete all namespace names by:
> >>>>
> >>>>     $ ip netns del all
> >>>
> >>> So I can still create a namespace called 'all', but can't exec in it or delete
> >>> it independently with this change.  Perhaps you need to block that as well?
> >>> Unless there's some other patch I'm missing?
> >>>
> >>> -Brian
> >> Hm, I did not take it into account ...
> >> I will look if I can find another way ...
> >>
> >> Thanks,
> > 
> > what about this ?
> > 
> >     $ ip netns exec / ip link
> >     $ ip netns del /
> > 
> > so it make a sense to be as root directory of bound ns names in /var/run/netns/ ?
> > what do you think ?
> 
> I think using / is confusing.  And something like -a[ll] as an option doesn't
> seem right either.
> 
> Or you just trap the name "all" in the add case and don't allow it.
> 
> Just my opinion.
> 
> -Brian

So I think that do not allow to add netns "all" can be a solution, I'd
like to hear from other people if it might be OK.

Thanks,

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH iproute2 3/3] ip netns: Delete all netns
  2015-01-07 19:55           ` Vadim Kochan
@ 2015-01-08  0:00             ` Cong Wang
  2015-01-09  8:43             ` Jiri Benc
  1 sibling, 0 replies; 19+ messages in thread
From: Cong Wang @ 2015-01-08  0:00 UTC (permalink / raw)
  To: Vadim Kochan; +Cc: Brian Haley, netdev

On Wed, Jan 7, 2015 at 11:55 AM, Vadim Kochan <vadim4j@gmail.com> wrote:
> So I think that do not allow to add netns "all" can be a solution, I'd
> like to hear from other people if it might be OK.
>

Nope, that would break existing scripts using "all" as a netns.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH iproute2 0/3] ip netns: Run over all netns
  2015-01-07 11:04 [PATCH iproute2 0/3] ip netns: Run over all netns Vadim Kochan
                   ` (2 preceding siblings ...)
  2015-01-07 11:04 ` [PATCH iproute2 3/3] ip netns: Delete all netns Vadim Kochan
@ 2015-01-08  0:04 ` Cong Wang
  2015-01-08  0:52   ` Vadim Kochan
  2015-01-14  1:28 ` Stephen Hemminger
  4 siblings, 1 reply; 19+ messages in thread
From: Cong Wang @ 2015-01-08  0:04 UTC (permalink / raw)
  To: Vadim Kochan; +Cc: netdev

On Wed, Jan 7, 2015 at 3:04 AM, Vadim Kochan <vadim4j@gmail.com> wrote:
> From: Vadim Kochan <vadim4j@gmail.com>
>
> Allow 'ip netns del' and 'ip netns exec' run over each network namespace names.
>
> 'ip netns exec' executes command forcely on eacn nsname.
>

Why this has to be done in iproute command?
That is, why not just offloading this to a shell script like below?

for ns in `ip netns show`;
do
     ip netns exec $ns ip link show.....
done

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH iproute2 0/3] ip netns: Run over all netns
  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
  0 siblings, 1 reply; 19+ messages in thread
From: Vadim Kochan @ 2015-01-08  0:52 UTC (permalink / raw)
  To: Cong Wang; +Cc: Vadim Kochan, netdev

On Wed, Jan 07, 2015 at 04:04:14PM -0800, Cong Wang wrote:
> On Wed, Jan 7, 2015 at 3:04 AM, Vadim Kochan <vadim4j@gmail.com> wrote:
> > From: Vadim Kochan <vadim4j@gmail.com>
> >
> > Allow 'ip netns del' and 'ip netns exec' run over each network namespace names.
> >
> > 'ip netns exec' executes command forcely on eacn nsname.
> >
> 
> Why this has to be done in iproute command?
> That is, why not just offloading this to a shell script like below?
> 
> for ns in `ip netns show`;
> do
>      ip netns exec $ns ip link show.....
> done

Hm, but would not it better to have it in iproute instead of collect
scripts ? Scripts allows to do a lot of things, but in this case it seems like a
feature which related to iproute.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH iproute2 3/3] ip netns: Delete all netns
  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
  1 sibling, 1 reply; 19+ messages in thread
From: Jiri Benc @ 2015-01-09  8:43 UTC (permalink / raw)
  To: Vadim Kochan; +Cc: Brian Haley, netdev

On Wed, 7 Jan 2015 21:55:17 +0200, Vadim Kochan wrote:
> On Wed, Jan 07, 2015 at 02:40:51PM -0500, Brian Haley wrote:
> > Or you just trap the name "all" in the add case and don't allow it.
> 
> So I think that do not allow to add netns "all" can be a solution, I'd
> like to hear from other people if it might be OK.

You can still add the name manually (there is software out there that
adds symlinks to /ver/run/netns), so nope, that's not a solution.

Generally, the only special names that could be used would be those
containing a letter not allowed in file name, i.e. \0 or '/'. Neither
of those sounds thrilling. I'm afraid the only working solution is a
new option.

 Jiri

-- 
Jiri Benc

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH iproute2 3/3] ip netns: Delete all netns
  2015-01-09  8:43             ` Jiri Benc
@ 2015-01-09  9:54               ` Vadim Kochan
  2015-01-09 14:24                 ` Nicolas Dichtel
  0 siblings, 1 reply; 19+ messages in thread
From: Vadim Kochan @ 2015-01-09  9:54 UTC (permalink / raw)
  To: Jiri Benc; +Cc: Brian Haley, netdev, vadim kochan

Ok,

If I will re-work to use new option, would it be useful ? So it will look:

    $ ip -all netns del
    $ ip -all netns exec ip link
    $ ip -all netns exec ip route add ...

Seems not so weird to me ?

Thanks,

On Fri, Jan 9, 2015 at 10:43 AM, Jiri Benc <jbenc@redhat.com> wrote:
> On Wed, 7 Jan 2015 21:55:17 +0200, Vadim Kochan wrote:
>> On Wed, Jan 07, 2015 at 02:40:51PM -0500, Brian Haley wrote:
>> > Or you just trap the name "all" in the add case and don't allow it.
>>
>> So I think that do not allow to add netns "all" can be a solution, I'd
>> like to hear from other people if it might be OK.
>
> You can still add the name manually (there is software out there that
> adds symlinks to /ver/run/netns), so nope, that's not a solution.
>
> Generally, the only special names that could be used would be those
> containing a letter not allowed in file name, i.e. \0 or '/'. Neither
> of those sounds thrilling. I'm afraid the only working solution is a
> new option.
>
>  Jiri
>
> --
> Jiri Benc

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH iproute2 3/3] ip netns: Delete all netns
  2015-01-09  9:54               ` Vadim Kochan
@ 2015-01-09 14:24                 ` Nicolas Dichtel
  0 siblings, 0 replies; 19+ messages in thread
From: Nicolas Dichtel @ 2015-01-09 14:24 UTC (permalink / raw)
  To: Vadim Kochan, Jiri Benc; +Cc: Brian Haley, netdev

Le 09/01/2015 10:54, Vadim Kochan a écrit :
> Ok,
>
> If I will re-work to use new option, would it be useful ? So it will look:
>
>      $ ip -all netns del
>      $ ip -all netns exec ip link
>      $ ip -all netns exec ip route add ...
>
> Seems not so weird to me ?
What about making this new option only for the 'netns' subsystem?
Something like: 'ip netns -all exec'?


Regards,
Nicolas

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH iproute2 0/3] ip netns: Run over all netns
  2015-01-08  0:52   ` Vadim Kochan
@ 2015-01-09 18:49     ` Cong Wang
  2015-01-09 19:17       ` Vadim Kochan
  0 siblings, 1 reply; 19+ messages in thread
From: Cong Wang @ 2015-01-09 18:49 UTC (permalink / raw)
  To: Vadim Kochan; +Cc: netdev

On Wed, Jan 7, 2015 at 4:52 PM, Vadim Kochan <vadim4j@gmail.com> wrote:
> On Wed, Jan 07, 2015 at 04:04:14PM -0800, Cong Wang wrote:
>> On Wed, Jan 7, 2015 at 3:04 AM, Vadim Kochan <vadim4j@gmail.com> wrote:
>> > From: Vadim Kochan <vadim4j@gmail.com>
>> >
>> > Allow 'ip netns del' and 'ip netns exec' run over each network namespace names.
>> >
>> > 'ip netns exec' executes command forcely on eacn nsname.
>> >
>>
>> Why this has to be done in iproute command?
>> That is, why not just offloading this to a shell script like below?
>>
>> for ns in `ip netns show`;
>> do
>>      ip netns exec $ns ip link show.....
>> done
>
> Hm, but would not it better to have it in iproute instead of collect
> scripts ? Scripts allows to do a lot of things, but in this case it seems like a
> feature which related to iproute.

iproute2 should keep a minimum set of features especially when
a one-liner shell script can do that.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH iproute2 0/3] ip netns: Run over all netns
  2015-01-09 18:49     ` Cong Wang
@ 2015-01-09 19:17       ` Vadim Kochan
  0 siblings, 0 replies; 19+ messages in thread
From: Vadim Kochan @ 2015-01-09 19:17 UTC (permalink / raw)
  To: Cong Wang; +Cc: Vadim Kochan, netdev

On Fri, Jan 09, 2015 at 10:49:50AM -0800, Cong Wang wrote:
> On Wed, Jan 7, 2015 at 4:52 PM, Vadim Kochan <vadim4j@gmail.com> wrote:
> > On Wed, Jan 07, 2015 at 04:04:14PM -0800, Cong Wang wrote:
> >> On Wed, Jan 7, 2015 at 3:04 AM, Vadim Kochan <vadim4j@gmail.com> wrote:
> >> > From: Vadim Kochan <vadim4j@gmail.com>
> >> >
> >> > Allow 'ip netns del' and 'ip netns exec' run over each network namespace names.
> >> >
> >> > 'ip netns exec' executes command forcely on eacn nsname.
> >> >
> >>
> >> Why this has to be done in iproute command?
> >> That is, why not just offloading this to a shell script like below?
> >>
> >> for ns in `ip netns show`;
> >> do
> >>      ip netns exec $ns ip link show.....
> >> done
> >
> > Hm, but would not it better to have it in iproute instead of collect
> > scripts ? Scripts allows to do a lot of things, but in this case it seems like a
> > feature which related to iproute.
> 
> iproute2 should keep a minimum set of features especially when
> a one-liner shell script can do that.

BTW, this script should have additional output of netns name
before the 'ip netns exec $ns ...' invocation.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH iproute2 0/3] ip netns: Run over all netns
  2015-01-07 11:04 [PATCH iproute2 0/3] ip netns: Run over all netns Vadim Kochan
                   ` (3 preceding siblings ...)
  2015-01-08  0:04 ` [PATCH iproute2 0/3] ip netns: Run over " Cong Wang
@ 2015-01-14  1:28 ` Stephen Hemminger
  2015-01-14 16:13   ` Vadim Kochan
  4 siblings, 1 reply; 19+ messages in thread
From: Stephen Hemminger @ 2015-01-14  1:28 UTC (permalink / raw)
  To: Vadim Kochan; +Cc: netdev

On Wed,  7 Jan 2015 13:04:19 +0200
Vadim Kochan <vadim4j@gmail.com> wrote:

> From: Vadim Kochan <vadim4j@gmail.com>
> 
> Allow 'ip netns del' and 'ip netns exec' run over each network namespace names.
> 
> 'ip netns exec' executes command forcely on eacn nsname.
> 
> Vadim Kochan (3):
>   lib: Exec func on each netns
>   ip netns: Allow exec on each netns
>   ip netns: Delete all netns
> 
>  include/namespace.h |  6 ++++
>  include/utils.h     |  5 +++
>  ip/ipnetns.c        | 96 ++++++++++++++++++++++++++++++++---------------------
>  lib/namespace.c     | 22 ++++++++++++
>  lib/utils.c         | 28 ++++++++++++++++
>  man/man8/ip-netns.8 | 26 ++++++++++++---
>  6 files changed, 141 insertions(+), 42 deletions(-)
> 

It is a useful concept but as others have pointed out the idea of reserving
a keyword 'all' at this point is likely to cause somebody to break.
So sorry.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH iproute2 0/3] ip netns: Run over all netns
  2015-01-14  1:28 ` Stephen Hemminger
@ 2015-01-14 16:13   ` Vadim Kochan
  0 siblings, 0 replies; 19+ messages in thread
From: Vadim Kochan @ 2015-01-14 16:13 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Vadim Kochan, netdev

On Tue, Jan 13, 2015 at 05:28:37PM -0800, Stephen Hemminger wrote:
> On Wed,  7 Jan 2015 13:04:19 +0200
> Vadim Kochan <vadim4j@gmail.com> wrote:
> 
> > From: Vadim Kochan <vadim4j@gmail.com>
> > 
> > Allow 'ip netns del' and 'ip netns exec' run over each network namespace names.
> > 
> > 'ip netns exec' executes command forcely on eacn nsname.
> > 
> > Vadim Kochan (3):
> >   lib: Exec func on each netns
> >   ip netns: Allow exec on each netns
> >   ip netns: Delete all netns
> > 
> >  include/namespace.h |  6 ++++
> >  include/utils.h     |  5 +++
> >  ip/ipnetns.c        | 96 ++++++++++++++++++++++++++++++++---------------------
> >  lib/namespace.c     | 22 ++++++++++++
> >  lib/utils.c         | 28 ++++++++++++++++
> >  man/man8/ip-netns.8 | 26 ++++++++++++---
> >  6 files changed, 141 insertions(+), 42 deletions(-)
> > 
> 
> It is a useful concept but as others have pointed out the idea of reserving
> a keyword 'all' at this point is likely to cause somebody to break.
> So sorry.
OK, then what about additional option like:

    $ ip -all netns exec ...

?

Thanks,

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2015-01-14 16:23 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH iproute2 3/3] ip netns: Delete all netns Vadim Kochan
2015-01-07 15:44   ` 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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.