netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ipnetns: fix exec for netns not in NETNS_RUN_DIR
@ 2014-12-25 22:15 Shahar Lev
  0 siblings, 0 replies; 4+ messages in thread
From: Shahar Lev @ 2014-12-25 22:15 UTC (permalink / raw)
  To: netdev; +Cc: Shahar Lev

Enabling "ip netns exec" to be run with a net namespace
specified by a file path rather than a filename under /var/run/nets.

Signed-off-by: Shahar Lev <shahar@stratoscale.com>
---
 ip/ipnetns.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index 1c8aa02..5310d0c 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -66,7 +66,7 @@ static int usage(void)
 	exit(-1);
 }
 
-int get_netns_fd(const char *name)
+static int get_netns_fd_flags(const char *name, int flags)
 {
 	char pathbuf[MAXPATHLEN];
 	const char *path, *ptr;
@@ -78,7 +78,12 @@ int get_netns_fd(const char *name)
 			NETNS_RUN_DIR, name );
 		path = pathbuf;
 	}
-	return open(path, O_RDONLY);
+	return open(path, flags);
+}
+
+int get_netns_fd(const char *name)
+{
+	return get_netns_fd_flags(name, O_RDONLY);
 }
 
 static int netns_list(int argc, char **argv)
@@ -135,7 +140,6 @@ static int netns_exec(int argc, char **argv)
 	 * aware, and execute a program in that environment.
 	 */
 	const char *name, *cmd;
-	char net_path[MAXPATHLEN];
 	int netns;
 
 	if (argc < 1) {
@@ -149,8 +153,7 @@ static int netns_exec(int argc, char **argv)
 
 	name = argv[0];
 	cmd = argv[1];
-	snprintf(net_path, sizeof(net_path), "%s/%s", NETNS_RUN_DIR, name);
-	netns = open(net_path, O_RDONLY | O_CLOEXEC);
+	netns = get_netns_fd_flags(name, O_RDONLY | O_CLOEXEC);
 	if (netns < 0) {
 		fprintf(stderr, "Cannot open network namespace \"%s\": %s\n",
 			name, strerror(errno));
-- 
1.8.3.1

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

* [PATCH] ipnetns: fix exec for netns not in NETNS_RUN_DIR
@ 2014-12-26 16:27 Shahar Lev
  2014-12-27 18:05 ` Stephen Hemminger
  0 siblings, 1 reply; 4+ messages in thread
From: Shahar Lev @ 2014-12-26 16:27 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev, Shahar Lev

Enabling "ip netns exec" to be run with a net namespace
specified by a file path rather than a filename under /var/run/nets.

Signed-off-by: Shahar Lev <shahar@stratoscale.com>
---
 ip/ipnetns.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index 1c8aa02..5310d0c 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -66,7 +66,7 @@ static int usage(void)
 	exit(-1);
 }
 
-int get_netns_fd(const char *name)
+static int get_netns_fd_flags(const char *name, int flags)
 {
 	char pathbuf[MAXPATHLEN];
 	const char *path, *ptr;
@@ -78,7 +78,12 @@ int get_netns_fd(const char *name)
 			NETNS_RUN_DIR, name );
 		path = pathbuf;
 	}
-	return open(path, O_RDONLY);
+	return open(path, flags);
+}
+
+int get_netns_fd(const char *name)
+{
+	return get_netns_fd_flags(name, O_RDONLY);
 }
 
 static int netns_list(int argc, char **argv)
@@ -135,7 +140,6 @@ static int netns_exec(int argc, char **argv)
 	 * aware, and execute a program in that environment.
 	 */
 	const char *name, *cmd;
-	char net_path[MAXPATHLEN];
 	int netns;
 
 	if (argc < 1) {
@@ -149,8 +153,7 @@ static int netns_exec(int argc, char **argv)
 
 	name = argv[0];
 	cmd = argv[1];
-	snprintf(net_path, sizeof(net_path), "%s/%s", NETNS_RUN_DIR, name);
-	netns = open(net_path, O_RDONLY | O_CLOEXEC);
+	netns = get_netns_fd_flags(name, O_RDONLY | O_CLOEXEC);
 	if (netns < 0) {
 		fprintf(stderr, "Cannot open network namespace \"%s\": %s\n",
 			name, strerror(errno));
-- 
1.8.3.1

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

* Re: [PATCH] ipnetns: fix exec for netns not in NETNS_RUN_DIR
  2014-12-26 16:27 [PATCH] ipnetns: fix exec for netns not in NETNS_RUN_DIR Shahar Lev
@ 2014-12-27 18:05 ` Stephen Hemminger
  2014-12-29  9:25   ` Shahar Lev
  0 siblings, 1 reply; 4+ messages in thread
From: Stephen Hemminger @ 2014-12-27 18:05 UTC (permalink / raw)
  To: Shahar Lev; +Cc: netdev

On Fri, 26 Dec 2014 18:27:12 +0200
Shahar Lev <shahar@stratoscale.com> wrote:

> Enabling "ip netns exec" to be run with a net namespace
> specified by a file path rather than a filename under /var/run/nets.
> 

This breaks existing users since you now require full pathname.

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

* Re: [PATCH] ipnetns: fix exec for netns not in NETNS_RUN_DIR
  2014-12-27 18:05 ` Stephen Hemminger
@ 2014-12-29  9:25   ` Shahar Lev
  0 siblings, 0 replies; 4+ messages in thread
From: Shahar Lev @ 2014-12-29  9:25 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev

>
> This breaks existing users since you now require full pathname.
>

Providing a full path is not a requirement.
If there's no dash ('/') in the parameter provided it defaults to
opening relative to NETNS_RUN_DIR (the existing behavior).
So this is just an extension.

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

end of thread, other threads:[~2014-12-29  9:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-26 16:27 [PATCH] ipnetns: fix exec for netns not in NETNS_RUN_DIR Shahar Lev
2014-12-27 18:05 ` Stephen Hemminger
2014-12-29  9:25   ` Shahar Lev
  -- strict thread matches above, loose matches on Subject: below --
2014-12-25 22:15 Shahar Lev

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).