Linux Container Development
 help / color / mirror / Atom feed
From: Daniel Lezcano <dlezcano-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
To: ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org,
	vivien.chappelier-L+G57L1VLRbR7s880joybQ@public.gmane.org,
	andreas.aaen-546VmZ+UeKYX2WXlbB3fKg@public.gmane.org
Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
Subject: [patch 1/2][RFC] add socketat syscall
Date: Fri, 31 Oct 2008 22:56:03 +0100	[thread overview]
Message-ID: <20081031215900.810348746@fr.ibm.com> (raw)
In-Reply-To: 20081031215602.655672481@fr.ibm.com

[-- Attachment #1: add-socketat-syscall.patch --]
[-- Type: text/plain, Size: 4468 bytes --]

This patch adds the socketat syscall which allows to specify in
which network namespace we want to create a socket. The network
namespace destination is referred by a socket fd previously opened
in the destination network namespace.

Signed-off-by: Daniel Lezcano <dlezcano-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
---
 arch/x86/include/asm/unistd_32.h   |    1 
 arch/x86/include/asm/unistd_64.h   |    3 +-
 arch/x86/kernel/syscall_table_32.S |    1 
 include/linux/syscalls.h           |    1 
 kernel/sys_ni.c                    |    1 
 net/socket.c                       |   45 +++++++++++++++++++++++++++++++++++++
 6 files changed, 51 insertions(+), 1 deletion(-)

Index: net-next-2.6/arch/x86/include/asm/unistd_32.h
===================================================================
--- net-next-2.6.orig/arch/x86/include/asm/unistd_32.h
+++ net-next-2.6/arch/x86/include/asm/unistd_32.h
@@ -338,6 +338,7 @@
 #define __NR_dup3		330
 #define __NR_pipe2		331
 #define __NR_inotify_init1	332
+#define __NR_socketat           333
 
 #ifdef __KERNEL__
 
Index: net-next-2.6/arch/x86/include/asm/unistd_64.h
===================================================================
--- net-next-2.6.orig/arch/x86/include/asm/unistd_64.h
+++ net-next-2.6/arch/x86/include/asm/unistd_64.h
@@ -653,7 +653,8 @@ __SYSCALL(__NR_dup3, sys_dup3)
 __SYSCALL(__NR_pipe2, sys_pipe2)
 #define __NR_inotify_init1			294
 __SYSCALL(__NR_inotify_init1, sys_inotify_init1)
-
+#define __NR_socketat                           295
+__SYSCALL(__NR_socketat, sys_socketat)
 
 #ifndef __NO_STUBS
 #define __ARCH_WANT_OLD_READDIR
Index: net-next-2.6/arch/x86/kernel/syscall_table_32.S
===================================================================
--- net-next-2.6.orig/arch/x86/kernel/syscall_table_32.S
+++ net-next-2.6/arch/x86/kernel/syscall_table_32.S
@@ -332,3 +332,4 @@ ENTRY(sys_call_table)
 	.long sys_dup3			/* 330 */
 	.long sys_pipe2
 	.long sys_inotify_init1
+	.long sys_socketat
Index: net-next-2.6/net/socket.c
===================================================================
--- net-next-2.6.orig/net/socket.c
+++ net-next-2.6/net/socket.c
@@ -1253,6 +1253,51 @@ out_release:
 	return retval;
 }
 
+asmlinkage long sys_socketat(int fd, int family, int type, int protocol)
+{
+	int retval, fput_needed;
+	struct socket *sock;
+	struct socket *sockat;
+	struct net *net;
+	int flags;
+
+	/* Check the SOCK_* constants for consistency.  */
+	BUILD_BUG_ON(SOCK_CLOEXEC != O_CLOEXEC);
+	BUILD_BUG_ON((SOCK_MAX | SOCK_TYPE_MASK) != SOCK_TYPE_MASK);
+	BUILD_BUG_ON(SOCK_CLOEXEC & SOCK_TYPE_MASK);
+	BUILD_BUG_ON(SOCK_NONBLOCK & SOCK_TYPE_MASK);
+
+	flags = type & ~SOCK_TYPE_MASK;
+	if (flags & ~(SOCK_CLOEXEC | SOCK_NONBLOCK))
+		return -EINVAL;
+	type &= SOCK_TYPE_MASK;
+
+	if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
+		flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
+
+	sock = sockfd_lookup_light(fd, &retval, &fput_needed);
+	if (!sock)
+		goto out;
+
+	net = sock_net(sock->sk);
+
+	retval = __sock_create(net, family, type, protocol, &sockat, 0);
+	if (retval)
+		goto out_fput;
+
+	retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
+	if (retval < 0)
+		goto out_release;
+out_fput:
+	fput_light(sock->file, fput_needed);
+out:
+	return retval;
+
+out_release:
+	sock_release(sockat);
+	goto out;
+}
+
 /*
  *	Create a pair of connected sockets.
  */
Index: net-next-2.6/include/linux/syscalls.h
===================================================================
--- net-next-2.6.orig/include/linux/syscalls.h
+++ net-next-2.6/include/linux/syscalls.h
@@ -423,6 +423,7 @@ asmlinkage long sys_recvfrom(int, void _
 				struct sockaddr __user *, int __user *);
 asmlinkage long sys_recvmsg(int fd, struct msghdr __user *msg, unsigned flags);
 asmlinkage long sys_socket(int, int, int);
+asmlinkage long sys_socketat(int, int, int, int);
 asmlinkage long sys_socketpair(int, int, int, int __user *);
 asmlinkage long sys_socketcall(int call, unsigned long __user *args);
 asmlinkage long sys_listen(int, int);
Index: net-next-2.6/kernel/sys_ni.c
===================================================================
--- net-next-2.6.orig/kernel/sys_ni.c
+++ net-next-2.6/kernel/sys_ni.c
@@ -40,6 +40,7 @@ cond_syscall(sys_send);
 cond_syscall(sys_recvfrom);
 cond_syscall(sys_recv);
 cond_syscall(sys_socket);
+cond_syscall(sys_socketat);
 cond_syscall(sys_setsockopt);
 cond_syscall(compat_sys_setsockopt);
 cond_syscall(sys_getsockopt);

-- 

  reply	other threads:[~2008-10-31 21:56 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-31 21:56 [patch 0/2][RFC] creating a socket with netns destination Daniel Lezcano
2008-10-31 21:56 ` Daniel Lezcano [this message]
     [not found]   ` <20081031215900.810348746-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2008-11-01  1:30     ` [patch 1/2][RFC] add socketat syscall Eric W. Biederman
2008-11-06 13:22     ` Michael Kerrisk
     [not found]   ` <517f3f820811060522i7b3518aen47907a34b38adee9@mail.gmail.com>
     [not found]     ` <517f3f820811060522i7b3518aen47907a34b38adee9-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-11-06 13:27       ` Daniel Lezcano
2008-11-06 15:46       ` Michael Kerrisk
     [not found]     ` <cfd18e0f0811060746l77fbe6fel83402ba543fccb38@mail.gmail.com>
     [not found]       ` <cfd18e0f0811060746l77fbe6fel83402ba543fccb38-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-11-06 16:18         ` Daniel Lezcano
     [not found]       ` <491318DC.4000300@fr.ibm.com>
     [not found]         ` <491318DC.4000300-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2008-11-07  9:45           ` Subrata Modak
2008-11-07 12:19           ` Cedric Le Goater
     [not found]         ` <49143263.1040604@fr.ibm.com>
     [not found]           ` <49143263.1040604-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2008-11-07 12:33             ` Daniel Lezcano
     [not found]           ` <49143594.8030109@fr.ibm.com>
     [not found]             ` <49143594.8030109-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2008-11-07 16:09               ` Eric W. Biederman
2008-11-12 10:33               ` Vivien Chappelier
     [not found]                 ` <491AB112.1030806-L+G57L1VLRbR7s880joybQ@public.gmane.org>
2008-11-12 15:24                   ` Eric W. Biederman
     [not found]                 ` <m1vdutotky.fsf@frodo.ebiederm.org>
     [not found]                   ` <m1vdutotky.fsf-B27657KtZYmhTnVgQlOflh2eb7JE58TQ@public.gmane.org>
2008-11-12 15:59                     ` Vivien Chappelier
2008-10-31 21:56 ` [patch 2/2][RFC] Factor sys_socket and sys_socketat Daniel Lezcano
     [not found] ` <20081031215602.655672481-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2008-11-05 19:47   ` [patch 0/2][RFC] creating a socket with netns destination Daniel Lezcano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081031215900.810348746@fr.ibm.com \
    --to=dlezcano-nmtc/0zbporqt0dzr+alfa@public.gmane.org \
    --cc=andreas.aaen-546VmZ+UeKYX2WXlbB3fKg@public.gmane.org \
    --cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org \
    --cc=vivien.chappelier-L+G57L1VLRbR7s880joybQ@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox