From: Vadim Kochan <redacted>
Added new '-ns' option to simplify executing following cmd:
ip netns exec NETNS ip OPTIONS COMMAND OBJECT
to
ip -ns NETNS OPTIONS COMMAND OBJECT
e.g.:
ip -ns vnet0 link add br0 type bridge
Signed-off-by: Vadim Kochan <redacted>
---
May be new option should have better name than '-ns' ?
ip/ip.c | 6 ++++++
ip/ip_common.h | 1 +
ip/ipnetns.c | 2 +-
man/man8/ip.8 | 21 +++++++++++++++++++++
4 files changed, 29 insertions(+), 1 deletion(-)
@@ -129,7 +129,7 @@ static void bind_etc(const char *name)closedir(dir);}-staticintnetns_exec(intargc,char**argv)+intnetns_exec(intargc,char**argv){/* Setup the proper environment for apps that are not netns*aware,andexecuteaprograminthatenvironment.
From: Nicolas Dichtel <hidden> Date: 2014-12-11 10:58:25
Le 10/12/2014 23:56, Vadim Kochan a écrit :
From: Vadim Kochan <redacted>
Added new '-ns' option to simplify executing following cmd:
ip netns exec NETNS ip OPTIONS COMMAND OBJECT
to
ip -ns NETNS OPTIONS COMMAND OBJECT
e.g.:
ip -ns vnet0 link add br0 type bridge
Signed-off-by: Vadim Kochan <redacted>
---
May be new option should have better name than '-ns' ?
What about 'ip -netns' to be explicit like other options?
user may still use 'ip -n' at the end.
Regards,
Nicolas
On Thu, Dec 11, 2014 at 11:58:21AM +0100, Nicolas Dichtel wrote:
Le 10/12/2014 23:56, Vadim Kochan a écrit :
quoted
From: Vadim Kochan <redacted>
Added new '-ns' option to simplify executing following cmd:
ip netns exec NETNS ip OPTIONS COMMAND OBJECT
to
ip -ns NETNS OPTIONS COMMAND OBJECT
e.g.:
ip -ns vnet0 link add br0 type bridge
Signed-off-by: Vadim Kochan <redacted>
---
May be new option should have better name than '-ns' ?
What about 'ip -netns' to be explicit like other options?
user may still use 'ip -n' at the end.
Regards,
Nicolas
May be left '-n' for some other future option, but use the following
options: -net[ns] and -ns ? What do you think ?
Thanks,
From: Nicolas Dichtel <hidden> Date: 2014-12-11 12:50:20
Le 11/12/2014 11:57, vadim4j@gmail.com a écrit :
On Thu, Dec 11, 2014 at 11:58:21AM +0100, Nicolas Dichtel wrote:
quoted
Le 10/12/2014 23:56, Vadim Kochan a écrit :
quoted
From: Vadim Kochan <redacted>
Added new '-ns' option to simplify executing following cmd:
ip netns exec NETNS ip OPTIONS COMMAND OBJECT
to
ip -ns NETNS OPTIONS COMMAND OBJECT
e.g.:
ip -ns vnet0 link add br0 type bridge
Signed-off-by: Vadim Kochan <redacted>
---
May be new option should have better name than '-ns' ?
What about 'ip -netns' to be explicit like other options?
user may still use 'ip -n' at the end.
Regards,
Nicolas
May be left '-n' for some other future option, but use the following
Options parsing in iproute2 will match -netns when typing -n because there
is no other options that begin with a 'n' (I've done a quick look, maybe I've
missed one).
Like -d which matches -details, etc.
options: -net[ns] and -ns ? What do you think ?
One option is enough. '-netns' is an explicit reference to 'ip netns'.
Regards,
Nicolas
On Thu, Dec 11, 2014 at 01:50:17PM +0100, Nicolas Dichtel wrote:
Le 11/12/2014 11:57, vadim4j@gmail.com a écrit :
quoted
On Thu, Dec 11, 2014 at 11:58:21AM +0100, Nicolas Dichtel wrote:
quoted
Le 10/12/2014 23:56, Vadim Kochan a écrit :
quoted
From: Vadim Kochan <redacted>
Added new '-ns' option to simplify executing following cmd:
ip netns exec NETNS ip OPTIONS COMMAND OBJECT
to
ip -ns NETNS OPTIONS COMMAND OBJECT
e.g.:
ip -ns vnet0 link add br0 type bridge
Signed-off-by: Vadim Kochan <redacted>
---
May be new option should have better name than '-ns' ?
What about 'ip -netns' to be explicit like other options?
user may still use 'ip -n' at the end.
Regards,
Nicolas
May be left '-n' for some other future option, but use the following
Options parsing in iproute2 will match -netns when typing -n because there
is no other options that begin with a 'n' (I've done a quick look, maybe I've
missed one).
Like -d which matches -details, etc.
quoted
options: -net[ns] and -ns ? What do you think ?
One option is enough. '-netns' is an explicit reference to 'ip netns'.
Regards,
Nicolas
OK, I agree.
I will re-work and resend v2.
Thanks,
On Thu, 11 Dec 2014 00:56:35 +0200, Vadim Kochan wrote:
From: Vadim Kochan <redacted>
Added new '-ns' option to simplify executing following cmd:
ip netns exec NETNS ip OPTIONS COMMAND OBJECT
to
ip -ns NETNS OPTIONS COMMAND OBJECT
e.g.:
ip -ns vnet0 link add br0 type bridge
This is great! It's a thing that has been bothering me for long time
but never got high enough on my todo list. Thanks for working on this.
However,
quoted hunk
--- a/ip/ip.c+++ b/ip/ip.c
@@ -262,6 +262,12 @@ int main(int argc, char **argv)rcvbuf=size;}elseif(matches(opt,"-help")==0){usage();+}elseif(matches(opt,"-ns")==0){+argc--;+argv++;+argv[0]=argv[1];+argv[1]=basename;+returnnetns_exec(argc,argv);
I very much dislike this. There's no reason to exec another ip binary.
The main reason I wanted the -n (or whatever) option was to speed up
execution of test scripts in environments with hundreds of interfaces
in different net namespaces.
Please just change to the specified netns and continue with interpreting
of the rest of the command line, there's absolutely no reason for doing
the exec.
Thanks,
Jiri
--
Jiri Benc
On Thu, Dec 11, 2014 at 05:09:28PM +0100, Jiri Benc wrote:
On Thu, 11 Dec 2014 00:56:35 +0200, Vadim Kochan wrote:
quoted
From: Vadim Kochan <redacted>
Added new '-ns' option to simplify executing following cmd:
ip netns exec NETNS ip OPTIONS COMMAND OBJECT
to
ip -ns NETNS OPTIONS COMMAND OBJECT
e.g.:
ip -ns vnet0 link add br0 type bridge
This is great! It's a thing that has been bothering me for long time
but never got high enough on my todo list. Thanks for working on this.
However,
quoted
--- a/ip/ip.c+++ b/ip/ip.c
@@ -262,6 +262,12 @@ int main(int argc, char **argv)rcvbuf=size;}elseif(matches(opt,"-help")==0){usage();+}elseif(matches(opt,"-ns")==0){+argc--;+argv++;+argv[0]=argv[1];+argv[1]=basename;+returnnetns_exec(argc,argv);
I very much dislike this. There's no reason to exec another ip binary.
The main reason I wanted the -n (or whatever) option was to speed up
execution of test scripts in environments with hundreds of interfaces
in different net namespaces.
Please just change to the specified netns and continue with interpreting
of the rest of the command line, there's absolutely no reason for doing
the exec.
On Thu, Dec 11, 2014 at 05:09:28PM +0100, Jiri Benc wrote:
quoted
On Thu, 11 Dec 2014 00:56:35 +0200, Vadim Kochan wrote:
quoted
From: Vadim Kochan <redacted>
Added new '-ns' option to simplify executing following cmd:
ip netns exec NETNS ip OPTIONS COMMAND OBJECT
to
ip -ns NETNS OPTIONS COMMAND OBJECT
e.g.:
ip -ns vnet0 link add br0 type bridge
This is great! It's a thing that has been bothering me for long time
but never got high enough on my todo list. Thanks for working on this.
However,
quoted
--- a/ip/ip.c+++ b/ip/ip.c
@@ -262,6 +262,12 @@ int main(int argc, char **argv)rcvbuf=size;}elseif(matches(opt,"-help")==0){usage();+}elseif(matches(opt,"-ns")==0){+argc--;+argv++;+argv[0]=argv[1];+argv[1]=basename;+returnnetns_exec(argc,argv);
I very much dislike this. There's no reason to exec another ip binary.
The main reason I wanted the -n (or whatever) option was to speed up
execution of test scripts in environments with hundreds of interfaces
in different net namespaces.
Please just change to the specified netns and continue with interpreting
of the rest of the command line, there's absolutely no reason for doing
the exec.
Yes, I will follow that way.
In that case, it would be interesting to also accelerate the original use
case, no? So all usages we currently have will benefit from this speed up
without a change.
if (command to be executed == myself)
switch namespace, continue without fork/exec..
I'm not sure if this is feasible, though. Just sharing the idea, didn't even
open the code..
Marcelo
On Thu, 11 Dec 2014 15:33:34 -0200, Marcelo Ricardo Leitner wrote:
In that case, it would be interesting to also accelerate the original use
case, no? So all usages we currently have will benefit from this speed up
without a change.
if (command to be executed == myself)
switch namespace, continue without fork/exec..
It's never good idea to do such tricks behind the user's back. This
particular case could easily break for users wanting to execute a
different ip binary (for whatever reason).
All programs should do what they are told to do, not try to outsmart
the user.
Jiri
--
Jiri Benc
On Thu, 11 Dec 2014 15:33:34 -0200, Marcelo Ricardo Leitner wrote:
quoted
In that case, it would be interesting to also accelerate the original use
case, no? So all usages we currently have will benefit from this speed up
without a change.
if (command to be executed == myself)
switch namespace, continue without fork/exec..
It's never good idea to do such tricks behind the user's back. This
particular case could easily break for users wanting to execute a
different ip binary (for whatever reason).
Then the if() above wouldn't match. That if means to check
/proc/self/exe against the result of the path expansion. If that fails,
continue with the normal path. If it matches, it is the same binary, and
no need to re-exec itself.
All programs should do what they are told to do, not try to outsmart
the user.
It's not outsmarting, it's just not being dumb and doing it the proper
way. Bash itself does this twist a lot. If you just type 'echo hi', it
won't execute /bin/echo but use a built-in version. But if you write
"/bin/echo hi", it will use /bin/echo..
We could use the same idea. "ip netns exec ip" -> ellipse it and avoid
the fork/exec. But if it's cmd != "ip", execute it..
Now consider other applications that are user of this command. They will
have to implement something like:
if (this ip command has --netns argument) {
cmd="ip --netns ..."
} else {
cmd="ip netns exec ..."
}
which is ugly and inconvenient.
Marcelo