[PATCH 8/8] net: Implement socketat.
[Posted September 29, 2010 by jake]
| From: |
| ebiederm-aS9lmoZGLiVWk0Htik3J/w-AT-public.gmane.org (Eric W. Biederman) |
| To: |
| <linux-kernel-u79uwXL29TY76Z2rM5mHXA-AT-public.gmane.org> |
| Subject: |
| [PATCH 8/8] net: Implement socketat. |
| Date: |
| Thu, 23 Sep 2010 01:51:59 -0700 |
| Message-ID: |
| <m1bp7oq1u8.fsf@fess.ebiederm.org> |
| Cc: |
| Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8-AT-public.gmane.org>,
Pavel Emelyanov <xemul-GEFAQzZX7r8dnm+yROfE0A-AT-public.gmane.org>,
Pavel Emelyanov <xemul-bzQdu9zFT3WakBO8gow8eQ-AT-public.gmane.org>,
Ulrich Drepper <drepper-Re5JQEeQqe8AvxtiuMwx3w-AT-public.gmane.org>, netdev-u79uwXL29TY76Z2rM5mHXA-AT-public.gmane.org,
Jonathan Corbet <corbet-T1hC0tSOHrs-AT-public.gmane.org>, Jan Engelhardt <jengelh-nopoi9nDyk+ELgA04lAiVw-AT-public.gmane.org>,
linux-fsdevel-u79uwXL29TY76Z2rM5mHXA-AT-public.gmane.org, netfilter-devel-u79uwXL29TY76Z2rM5mHXA-AT-public.gmane.org,
Michael Kerrisk <mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w-AT-public.gmane.org>,
Linux Containers <containers-qjLDD68F18O7TbgM5vRIOg-AT-public.gmane.org>,
Ben Greear <greearb-my8/4N5VtI7c+919tysfdA-AT-public.gmane.org>,
Linus Torvalds <torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b-AT-public.gmane.org>,
David Miller <davem-fT/PcQaiUtIeIZ0/mPfg9Q-AT-public.gmane.org>, Al Viro <viro-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn-AT-public.gmane.org> |
| Archive‑link: | |
Article |
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