[PATCH 8/8] net: Implement socketat.

Subsystems: networking [general], networking [sockets], the rest

STALE5791d

4 messages, 3 authors, 2010-09-23 · open the first message on its own page

[PATCH 8/8] net: Implement socketat.

From: Eric W. Biederman <hidden>
Date: 2010-09-23 08:51:59

Add a system call for creating sockets in a specified network namespace.

Signed-off-by: Eric W. Biederman <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
---
 net/socket.c |   26 ++++++++++++++++++++++++--
 1 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/net/socket.c b/net/socket.c
index 2270b94..1116f3c 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -1269,7 +1269,7 @@ int sock_create_kern(int family, int type, int protocol, struct socket **res)
 }
 EXPORT_SYMBOL(sock_create_kern);
 
-SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
+static int do_socket(struct net *net, int family, int type, int protocol)
 {
 	int retval;
 	struct socket *sock;
@@ -1289,7 +1289,7 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
 	if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
 		flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
 
-	retval = sock_create(family, type, protocol, &sock);
+	retval = __sock_create(net, family, type, protocol, &sock, 0);
 	if (retval < 0)
 		goto out;
 
@@ -1306,6 +1306,28 @@ out_release:
 	return retval;
 }
 
+SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
+{
+	return do_socket(current->nsproxy->net_ns, family, type, protocol);
+}
+
+SYSCALL_DEFINE4(socketat, int, fd, int, family, int, type, int, protocol)
+{
+	struct net *net;
+	int retval;
+
+	if (fd == -1) {
+		net = get_net(current->nsproxy->net_ns);
+	} else {
+		net = get_net_ns_by_fd(fd);
+		if (IS_ERR(net))
+			return  PTR_ERR(net);
+	}
+	retval = do_socket(net, family, type, protocol);
+	put_net(net);
+	return retval;
+}
+
 /*
  *	Create a pair of connected sockets.
  */
-- 
1.6.5.2.143.g8cc62

Re: [PATCH 8/8] net: Implement socketat.

From: Pavel Emelyanov <hidden>
Date: 2010-09-23 08:56:14

On 09/23/2010 12:51 PM, Eric W. Biederman wrote:
Add a system call for creating sockets in a specified network namespace.
What for?

Re: [PATCH 8/8] net: Implement socketat.

From: jamal <hidden>
Date: 2010-09-23 11:20:04

On Thu, 2010-09-23 at 12:56 +0400, Pavel Emelyanov wrote:
On 09/23/2010 12:51 PM, Eric W. Biederman wrote:
quoted
Add a system call for creating sockets in a specified network namespace.
What for?
I can see many uses if my understanding is correct..
ex, from mother namespace:
fdx = open socket at namespace blah
from mother namespace, read/write/poll fdx 
(eg add route with netlink socket)

cheers,
jamal

Re: [PATCH 8/8] net: Implement socketat.

From: Pavel Emelyanov <hidden>
Date: 2010-09-23 11:33:26

On 09/23/2010 03:19 PM, jamal wrote:
On Thu, 2010-09-23 at 12:56 +0400, Pavel Emelyanov wrote:
quoted
On 09/23/2010 12:51 PM, Eric W. Biederman wrote:
quoted
Add a system call for creating sockets in a specified network namespace.
What for?
I can see many uses if my understanding is correct..
ex, from mother namespace:
fdx = open socket at namespace blah
from mother namespace, read/write/poll fdx 
(eg add route with netlink socket)
This particular usecase is unneeded once you have the "enter" ability.
cheers,
jamal

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help