creating a socket with netns destination
Subsystems (4)
cover creating a socket with netns destination
This patchset (not tested) shows how it is possible to create a socket specifying the network namespace destination. That should allow a single process to handle several network namespaces.
RFC PATCH 1/2 add socketat syscall
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.
--- 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(-)
arch/x86/include/asm/unistd_32.h +1 -0
@@ -338,6 +338,7 @@#define __NR_dup3 330#define __NR_pipe2 331#define __NR_inotify_init1 332 +#define __NR_socketat 333#ifdef __KERNEL__
arch/x86/include/asm/unistd_64.h +2 -1
@@ -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
arch/x86/kernel/syscall_table_32.S +1 -0
@@ -332,3 +332,4 @@ ENTRY(sys_call_table) .long sys_dup3 /* 330 */ .long sys_pipe2 .long sys_inotify_init1 + .long sys_socketat
net/socket.c +45 -0
51 lines not on this page · raw message
include/linux/syscalls.h +1 -0
@@ -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 );
kernel/sys_ni.c +1 -0
@@ -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);
A message that is not in the archive (sent off-list or not yet received): 20081031215900.810348746-NmTC/[email protected]
Re: [patch 1/2][RFC] add socketat syscall
Quoted 4 lines · Daniel Lezcano
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.
Looks good and very simple.
I have a small update to my proposal for an ABI, that should be easier to deploy if the ABI gods can't find fault with it.
#define SOCK_FDNS 0x100000 /* Some good non-conflicting number */
And then reuse extend socket to read one more argument when it is passed.
So.
asmlinkage long sys_socket(int domain, int type, int protocol); becomes:
asmlinkage long sys_socket(int domain, int type, int protocol, int fd); when SOCK_FDNS is set in type.
I believe the calling conventions in the kernel already pass 4 arguments so we just need to read and act on the forth. That should be easier than allocating an extra syscall number on every architecture.
Eric
Re: [patch 1/2][RFC] add socketat syscall
In reply to a message not in the archiveHi Daniel,
Please CC linux-api on API/ABI changes.
See Documentation/SubmitChecklist and
http://thread.gmane.org/gmane.linux.ltp/5658.
Thanks,
Michael
Quoted 137 lines · Daniel Lezcano
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/[email protected]>--- 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
===================================================================arch/x86/include/asm/unistd_32.h +1
-0@@ -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
===================================================================arch/x86/include/asm/unistd_64.h +2
-1@@ -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_READDIRIndex:
net-next-2.6/arch/x86/kernel/syscall_table_32.S
===================================================================arch/x86/kernel/syscall_table_32.S +1
-0@@ -332,3 +332,4 @@ ENTRY(sys_call_table) .long sys_dup3 /* 330 */ .long sys_pipe2 .long sys_inotify_init1 + .long sys_socketatIndex:
net-next-2.6/net/socket.c
===================================================================net/socket.c +45
-0@@ -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
===================================================================include/linux/syscalls.h +1
-0@@ -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
===================================================================kernel/sys_ni.c +1
-1@@ -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); --_______________________________________________
Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers
Signature · 7 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Found a documentation bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html -- To unsubscribe from this list: send the line "unsubscribe linux-api" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 517f3f820811060522i7b3518aen47907a34b38adee9-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Re: [patch 1/2][RFC] add socketat syscall
Quoted 6 lines · Michael Kerrisk
Hi Daniel,
Please CC linux-api on API/ABI changes.
See
Documentation/SubmitChecklistand
http://thread.gmane.org/gmane.linux.ltp/5658.
Will do, thanks.
-- Daniel
Re: [patch 1/2][RFC] add socketat syscall
In reply to a message not in the archiveQuoted 6 lines · Michael Kerrisk
Hi Daniel,
Please CC linux-api on API/ABI changes.
See
Documentation/SubmitChecklistand
http://thread.gmane.org/gmane.linux.ltp/5658.
Will do, thanks.
-- Daniel
--
To unsubscribe from this list: send the line "unsubscribe linux-api" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [patch 1/2][RFC] add socketat syscall
In reply to a message not in the archiveQuoted 5 lines · Daniel Lezcano
Quoted 4 lines
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.
Daniel,
Is there any documentation for this system call, and/or test programs?
Cheers,
Michael
Quoted 144 lines
Quoted 127 lines
Signed-off-by Daniel Lezcano <dlezcano-NmTC/[email protected]>--- 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
===================================================================arch/x86/include/asm/unistd_32.h +1
-0@@ -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
===================================================================arch/x86/include/asm/unistd_64.h +2
-1@@ -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_READDIRIndex:
net-next-2.6/arch/x86/kernel/syscall_table_32.S
===================================================================arch/x86/kernel/syscall_table_32.S +1
-0@@ -332,3 +332,4 @@ ENTRY(sys_call_table) .long sys_dup3 /* 330 */ .long sys_pipe2 .long sys_inotify_init1 + .long sys_socketatIndex:
net-next-2.6/net/socket.c
===================================================================net/socket.c +45
-0@@ -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
===================================================================include/linux/syscalls.h +1
-0@@ -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
===================================================================kernel/sys_ni.c +1
-1@@ -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); --Quoted 5 lines
_______________________________________________
Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers--
Michael Kerrisk Linux man-pages maintainer;
http://www.kernel.org/doc/man-pages/ Found a documentation bug?
http://www.kernel.org/doc/man-pages/reporting_bugs.html
--
To unsubscribe from this list: send the line "unsubscribe linux-api" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 9 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ git://git.kernel.org/pub/scm/docs/man-pages/man-pages.git man-pages online: http://www.kernel.org/doc/man-pages/online_pages.html Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html -- To unsubscribe from this list: send the line "unsubscribe linux-api" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): cfd18e0f0811060746l77fbe6fel83402ba543fccb38-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Re: [patch 1/2][RFC] add socketat syscall
Quoted 9 lines · Michael Kerrisk
Quoted 5 lines · Daniel Lezcano
Quoted 4 lines
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.
Daniel,
Is there any documentation for this system call, and/or test programs?
Not yet.
This small patch is a proposition to Andreas and Vivien to have a single process being able to manage several network namespaces.
When a process unshares the network, it creates a socket which is used as a socket control (it belongs to the network namespace). Each time a network namespace is created, a socket control is created.
When the process has to create a socket for a specific network namespace, it can use the socket control to specify it. This is the purpose of the socketat syscall.
One example for a program in userspace:
int main(int argc, char *argv[])
{
const int maxunshare = 128;
int scs[maxunshare];
int i, fd;
for (i = 0; i < maxunshare; i++) {
scs[i] = socket(PF_INET, SOCK_DGRAM, 0);
unshare(CLONE_NEWNET);
}
....
/* I want to create a socket inside the network namespace #10 */
fd = socketat(scs[10], PF_INET, SOCKET_STREAM, 0);
....
bind, listen, etc ...
}Quoted 146 lines
Quoted 143 lines
Quoted 127 lines
Signed-off-by Daniel Lezcano <dlezcano-NmTC/[email protected]>--- 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
===================================================================arch/x86/include/asm/unistd_32.h +1
-0@@ -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
===================================================================arch/x86/include/asm/unistd_64.h +2
-1@@ -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_READDIRIndex:
net-next-2.6/arch/x86/kernel/syscall_table_32.S
===================================================================arch/x86/kernel/syscall_table_32.S +1
-0@@ -332,3 +332,4 @@ ENTRY(sys_call_table) .long sys_dup3 /* 330 */ .long sys_pipe2 .long sys_inotify_init1 + .long sys_socketatIndex:
net-next-2.6/net/socket.c
===================================================================net/socket.c +45
-0@@ -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
===================================================================include/linux/syscalls.h +1
-0@@ -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
===================================================================kernel/sys_ni.c +1
-1@@ -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); --Quoted 5 lines
_______________________________________________
Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers--
Michael Kerrisk Linux man-pages maintainer;
http://www.kernel.org/doc/man-pages/ Found a documentation bug?
http://www.kernel.org/doc/man-pages/reporting_bugs.html
--
To unsubscribe from this list: send the line "unsubscribe linux-api" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 12 lines
Sauf indication contraire ci-dessus: Compagnie IBM France Siège Social : Tour Descartes, 2, avenue Gambetta, La Défense 5, 92400 Courbevoie RCS Nanterre 552 118 465 Forme Sociale : S.A.S. Capital Social : 542.737.118 ? SIREN/SIRET : 552 118 465 02430 -- To unsubscribe from this list: send the line "unsubscribe linux-api" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 491318DC.4000300-NmTC/[email protected]
Re: [patch 1/2][RFC] add socketat syscall
Thanks Daniel/Michael,
Adding Veerendra, Sudhir & Gowri as they are handling NS tests now and they may include it in their Plan.
Regards--
Subrata
Quoted 196 lines · Daniel Lezcano
Quoted 9 lines · Michael Kerrisk
Quoted 5 lines · Daniel Lezcano
Quoted 4 lines
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.
Daniel,
Is there any documentation for this system call, and/or test programs?
Not yet.
This small patch is a proposition to Andreas and Vivien to have a single process being able to manage several network namespaces.
When a process unshares the network, it creates a socket which is used as a socket control (it belongs to the network namespace). Each time a network namespace is created, a socket control is created.
When the process has to create a socket for a specific network namespace, it can use the socket control to specify it. This is the purpose of the socketat syscall.
One example for a program in userspace:
int
main(int argc, char *argv[]){ const int maxunshare = 128; int scs[maxunshare]; int i, fd; for (i = 0; i < maxunshare; i++) { scs[i] = socket(PF_INET, SOCK_DGRAM, 0); unshare(CLONE_NEWNET); } .... /* I want to create a socket inside the network namespace #10 */ fd = socketat(scs[10], PF_INET, SOCKET_STREAM, 0); .... bind, listen, etc ... }Quoted 146 lines
Quoted 143 lines
Quoted 127 lines
Signed-off-by Daniel Lezcano <dlezcano-NmTC/[email protected]>--- 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
===================================================================arch/x86/include/asm/unistd_32.h +1
-0@@ -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
===================================================================arch/x86/include/asm/unistd_64.h +2
-1@@ -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_READDIRIndex:
net-next-2.6/arch/x86/kernel/syscall_table_32.S
===================================================================arch/x86/kernel/syscall_table_32.S +1
-0@@ -332,3 +332,4 @@ ENTRY(sys_call_table) .long sys_dup3 /* 330 */ .long sys_pipe2 .long sys_inotify_init1 + .long sys_socketatIndex:
net-next-2.6/net/socket.c
===================================================================net/socket.c +45
-0@@ -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
===================================================================include/linux/syscalls.h +1
-0@@ -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
===================================================================kernel/sys_ni.c +1
-1@@ -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); --Quoted 5 lines
_______________________________________________
Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers--
Michael Kerrisk Linux man-pages maintainer;
http://www.kernel.org/doc/man-pages/ Found a documentation bug?
http://www.kernel.org/doc/man-pages/reporting_bugs.html
--
To unsubscribe from this list: send the line "unsubscribe linux-api" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [patch 1/2][RFC] add socketat syscall
In reply to a message not in the archiveThanks Daniel/Michael,
Adding Veerendra, Sudhir & Gowri as they are handling NS tests now and they may include it in their Plan.
Regards--
Subrata
Quoted 39 lines · Daniel Lezcano
Quoted 9 lines · Michael Kerrisk
Quoted 5 lines · Daniel Lezcano
Quoted 4 lines
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.
Daniel,
Is there any documentation for this system call, and/or test programs?
Not yet.
This small patch is a proposition to Andreas and Vivien to have a single process being able to manage several network namespaces.
When a process unshares the network, it creates a socket which is used as a socket control (it belongs to the network namespace). Each time a network namespace is created, a socket control is created.
When the process has to create a socket for a specific network namespace, it can use the socket control to specify it. This is the purpose of the socketat syscall.
One example for a program in userspace:
int
main(int argc, char *argv[]){ const int maxunshare = 128; int scs[maxunshare]; int i, fd; for (i = 0; i < maxunshare; i++) { scs[i] = socket(PF_INET, SOCK_DGRAM, 0); unshare(CLONE_NEWNET); } ....
Quoted 157 lines
/* I want to create a socket inside the network namespace #10 */ fd = socketat(scs[10], PF_INET, SOCKET_STREAM, 0); .... bind, listen, etc ... }Quoted 146 lines
Quoted 143 lines
Quoted 127 lines
Signed-off-by Daniel Lezcano <dlezcano-NmTC/[email protected]>--- 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
===================================================================arch/x86/include/asm/unistd_32.h +1
-0@@ -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
===================================================================arch/x86/include/asm/unistd_64.h +2
-1@@ -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_READDIRIndex:
net-next-2.6/arch/x86/kernel/syscall_table_32.S
===================================================================arch/x86/kernel/syscall_table_32.S +1
-0@@ -332,3 +332,4 @@ ENTRY(sys_call_table) .long sys_dup3 /* 330 */ .long sys_pipe2 .long sys_inotify_init1 + .long sys_socketatIndex:
net-next-2.6/net/socket.c
===================================================================net/socket.c +45
-0@@ -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
===================================================================include/linux/syscalls.h +1
-0@@ -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
===================================================================kernel/sys_ni.c +1
-1@@ -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); --Quoted 5 lines
_______________________________________________
Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers--
Michael Kerrisk Linux man-pages maintainer;
http://www.kernel.org/doc/man-pages/ Found a documentation bug?
http://www.kernel.org/doc/man-pages/reporting_bugs.html
--
To unsubscribe from this list: send the line "unsubscribe linux-api" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-api" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [patch 1/2][RFC] add socketat syscall
In reply to a message not in the archiveQuoted 15 lines · Daniel Lezcano
Quoted 8 lines · Michael Kerrisk
Quoted 5 lines · Daniel Lezcano
Quoted 4 lines
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.
Daniel,
Is there any documentation for this system call, and/or test programs?
Not yet.
This small patch is a proposition to Andreas and Vivien to have a single process being able to manage several network namespaces.
Quoted 7 lines
When a process unshares the network, it creates a socket which is used as a socket control (it belongs to the network namespace). Each time a network namespace is created, a socket control is created.
When the process has to create a socket for a specific network namespace, it can use the socket control to specify it. This is the purpose of the socketat syscall.
what about eric's proposal of adding an fd argument to sys_socket() ? was it dropped ?
C.
--
To unsubscribe from this list: send the line "unsubscribe linux-api" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 49143263.1040604-NmTC/[email protected]
Re: [patch 1/2][RFC] add socketat syscall
Quoted 12 lines · Cedric Le Goater
Quoted 11 lines · Daniel Lezcano
Quoted 8 lines · Michael Kerrisk
Quoted 5 lines · Daniel Lezcano
Quoted 4 lines
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.
Daniel,
Is there any documentation for this system call, and/or test programs?
Not yet.
Quoted 7 lines
Quoted 5 lines
This small patch is a proposition to Andreas and Vivien to have a single process being able to manage several network namespaces.
When a process unshares the network, it creates a socket which is used as a socket control (it belongs to the network namespace). Each time a network namespace is created, a socket control is created.
When the process has to create a socket for a specific network namespace, it can use the socket control to specify it. This is the purpose of the socketat syscall.
what about eric's proposal of adding an fd argument to
sys_socket()? was it dropped ?
AFAIU, the Eric's proposal in case a new syscall was not accepted. IMHO a new syscall, with the man pages is better than adding an extra obscure argument to a well known API. But if there is a reason to not add a new syscall, we can consider Eric's approach as a good alternative I think.
But before sending anything, I am still waiting for Vivien and Andreas answer about this approach. If it helps them to migrate their project to the network namespace, I will send something more formal. --
To unsubscribe from this list: send the line "unsubscribe linux-api" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 49143594.8030109-NmTC/[email protected]
Re: [patch 1/2][RFC] add socketat syscall
Quoted 8 lines · Daniel Lezcano
AFAIU, the Eric's proposal in case a new syscall was not accepted. IMHO a new syscall, with the man pages is better than adding an extra obscure argument to a well known API. But if there is a reason to not add a new syscall, we can consider Eric's approach as a good alternative I think.
But before sending anything, I am still waiting for Vivien and Andreas answer about this approach. If it helps them to migrate their project to the network namespace, I will send something more formal.
In my queue I have some preliminary patches. For both the syscall thing and a filesystem that will pin the namespace. I trying to get my pile down so I can actually test it.
Ultimately to get the full functionality of the current linux-vrf project we need:
socketat (or some variant thereof) so we can get unprivileged creation of new sockets in another network namespace.
A fs to pin the network namespace and give it a name.
And ultimately a privileged operation sys_enter(int type, int fd); To allow the default network namespace to be changed allowing unprivileged applications to be run in the network namespace.
Eric
Re: [patch 1/2][RFC] add socketat syscall
In reply to a message not in the archiveQuoted 8 lines · Daniel Lezcano
AFAIU, the Eric's proposal in case a new syscall was not accepted. IMHO a new syscall, with the man pages is better than adding an extra obscure argument to a well known API. But if there is a reason to not add a new syscall, we can consider Eric's approach as a good alternative I think.
But before sending anything, I am still waiting for Vivien and Andreas answer about this approach. If it helps them to migrate their project to the network namespace, I will send something more formal.
In my queue I have some preliminary patches. For both the syscall thing and a filesystem that will pin the namespace. I trying to get my pile down so I can actually test it.
Ultimately to get the full functionality of the current linux-vrf project we need:
socketat (or some variant thereof) so we can get unprivileged creation of new sockets in another network namespace.
A fs to pin the network namespace and give it a name.
And ultimately a privileged operation sys_enter(int type, int fd); To allow the default network namespace to be changed allowing unprivileged applications to be run in the network namespace.
Eric
--
To unsubscribe from this list: send the line "unsubscribe linux-api" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [patch 1/2][RFC] add socketat syscall
In reply to a message not in the archiveHi,
The socketat() option is fine but only solves half of the problem. I
also need to be able to change the default namespace of a process to join an existing network namespace.
My use case is the following (embedded router): I have two separate
networks, one with internet access running standard applications and routing LAN traffic, one with access to the operator network only and running dedicated applications such as software upgrade or telephony software. These two networks have to be totally separate and I need the ability to run applications and open sockets in any of these networks or even both. With the current proposal, I could have init or some additional daemon create the two namespaces and ask it to fork and exec the applications I want to run so that it can give the open socket to its child. However this solution is not very practical nor elegant compared to the chvrf approach.
The fs solution proposed by Eric to name, create, and remove network
namespaces is fine. IMHO using the filesystem to create sockets would be a bad option as the filename would need to be parsed for every protocol etc.. So combining the filesystem idea with the socketat() syscall is a good way of solving both issues. In this case, each namespace would be represented with a single file and we could also give the fd obtained by opening this file as the socketat() argument. I also prefer extending socket() as was suggested previously rather than adding a new syscall, but this is up to the syscall API maintainers to decide.
regards,
Vivien.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [patch 1/2][RFC] add socketat syscall
Quoted 5 lines · Vivien Chappelier
Hi,
The
socketat()option is fine but only solves half of the problem. I also need
to be able to change the default namespace of a process to join an existing network namespace.
I'm trying to get a feel. What kind of applications do you have for which you are changing the default network namespace aka chvrf?
Eric
--
To unsubscribe from this list: send the line "unsubscribe linux-api" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [patch 1/2][RFC] add socketat syscall
Hi,
Quoted 3 lines
I'm trying to get a feel. What kind of applications do you have for which you are changing the default network namespace aka chvrf?
No problem to detail a bit more. We are working on products for
telephony operators that generally need both a classical 'user' access to the internet and a priviledged 'services' access to the operator network.
My first example is a cable modem (CM), IP phone (eMTA) and router.
The DOCSIS and PacketCable standards require this product to have separate networks for each of these features, bridged together at the MAC level, so that it behaves exactly as three separate boxes from the operator's network point of view. So we have:
- default network namespace '0' for the router and standard Linux applications that need internet access.
- network namespace '1' for the CM
- network namespace '2' for the eMTA
- a bridge connecting the CM interface, eMTA interface and router WAN-side interface together
Basically, the CM application is run in a chvrf context and performs
its DHCP and TFTP requests on the operator network using the CM MAC address. The same way, the eMTA application is run in its own network for its DHCP, TFTP and all the VOIP related traffic (MGCP signaling and RTP voice traffic) using the eMTA MAC address. The CM network is also used for firmware upgrade.
A second example is a product mixing an internet browser and a set
top box-like access to the operator's TV network. In this case, the operator's network for internet and TV use separate VLANs and DHCP requests on each network may provide IP addresses in the same subnet. So in this case, one DHCP client and the TV player are run in chvrf context.
I hope it clarifies our use case a bit more and why we need and use
the VRF feature.
regards,
Vivien.
Re: [patch 1/2][RFC] add socketat syscall
In reply to a message not in the archiveHi,
Quoted 3 lines
I'm trying to get a feel. What kind of applications do you have for which you are changing the default network namespace aka chvrf?
No problem to detail a bit more. We are working on products for
telephony operators that generally need both a classical 'user' access to the internet and a priviledged 'services' access to the operator network.
My first example is a cable modem (CM), IP phone (eMTA) and router.
The DOCSIS and PacketCable standards require this product to have separate networks for each of these features, bridged together at the MAC level, so that it behaves exactly as three separate boxes from the operator's network point of view. So we have:
- default network namespace '0' for the router and standard Linux applications that need internet access.
- network namespace '1' for the CM
- network namespace '2' for the eMTA
- a bridge connecting the CM interface, eMTA interface and router WAN-side interface together
Basically, the CM application is run in a chvrf context and performs
its DHCP and TFTP requests on the operator network using the CM MAC address. The same way, the eMTA application is run in its own network for its DHCP, TFTP and all the VOIP related traffic (MGCP signaling and RTP voice traffic) using the eMTA MAC address. The CM network is also used for firmware upgrade.
A second example is a product mixing an internet browser and a set
top box-like access to the operator's TV network. In this case, the operator's network for internet and TV use separate VLANs and DHCP requests on each network may provide IP addresses in the same subnet. So in this case, one DHCP client and the TV player are run in chvrf context.
I hope it clarifies our use case a bit more and why we need and use
the VRF feature.
regards,
Vivien.
--
To unsubscribe from this list: send the line "unsubscribe linux-api" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [patch 1/2][RFC] add socketat syscall
In reply to a message not in the archiveQuoted 5 lines · Vivien Chappelier
Hi,
The
socketat()option is fine but only solves half of the problem. I also need
to be able to change the default namespace of a process to join an existing network namespace.
I'm trying to get a feel. What kind of applications do you have for which you are changing the default network namespace aka chvrf?
Eric
Re: [patch 1/2][RFC] add socketat syscall
In reply to a message not in the archiveQuoted 19 lines · Cedric Le Goater
Quoted 18 lines · Daniel Lezcano
Quoted 8 lines · Michael Kerrisk
Quoted 5 lines · Daniel Lezcano
Quoted 4 lines
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.
Daniel,
Is there any documentation for this system call, and/or test programs?
Not yet.
This small patch is a proposition to Andreas and Vivien to have a single process being able to manage several network namespaces.
When a process unshares the network, it creates a socket which is used as a socket control (it belongs to the network namespace). Each time a network namespace is created, a socket control is created.
Quoted 6 lines
Quoted 3 lines
When the process has to create a socket for a specific network namespace, it can use the socket control to specify it. This is the purpose of the socketat syscall.
what about eric's proposal of adding an fd argument to
sys_socket()? was it dropped ?
AFAIU, the Eric's proposal in case a new syscall was not accepted. IMHO a new syscall, with the man pages is better than adding an extra obscure argument to a well known API. But if there is a reason to not add a new syscall, we can consider Eric's approach as a good alternative I think.
But before sending anything, I am still waiting for Vivien and Andreas answer about this approach. If it helps them to migrate their project to the network namespace, I will send something more formal.
Re: [patch 1/2][RFC] add socketat syscall
In reply to a message not in the archiveQuoted 15 lines · Daniel Lezcano
Quoted 8 lines · Michael Kerrisk
Quoted 5 lines · Daniel Lezcano
Quoted 4 lines
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.
Daniel,
Is there any documentation for this system call, and/or test programs?
Not yet.
This small patch is a proposition to Andreas and Vivien to have a single process being able to manage several network namespaces.
Quoted 7 lines
When a process unshares the network, it creates a socket which is used as a socket control (it belongs to the network namespace). Each time a network namespace is created, a socket control is created.
When the process has to create a socket for a specific network namespace, it can use the socket control to specify it. This is the purpose of the socketat syscall.
what about eric's proposal of adding an fd argument to sys_socket() ? was it dropped ?
C.
Re: [patch 1/2][RFC] add socketat syscall
In reply to a message not in the archiveQuoted 9 lines · Michael Kerrisk
Quoted 5 lines · Daniel Lezcano
Quoted 4 lines
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.
Daniel,
Is there any documentation for this system call, and/or test programs?
Not yet.
This small patch is a proposition to Andreas and Vivien to have a single process being able to manage several network namespaces.
When a process unshares the network, it creates a socket which is used as a socket control (it belongs to the network namespace). Each time a network namespace is created, a socket control is created.
When the process has to create a socket for a specific network namespace, it can use the socket control to specify it. This is the purpose of the socketat syscall.
One example for a program in userspace:
int main(int argc, char *argv[])
{
const int maxunshare = 128;
int scs[maxunshare];
int i, fd;
for (i = 0; i < maxunshare; i++) {
scs[i] = socket(PF_INET, SOCK_DGRAM, 0);
unshare(CLONE_NEWNET);
}
....
/* I want to create a socket inside the network namespace #10 */
fd = socketat(scs[10], PF_INET, SOCKET_STREAM, 0);
....
bind, listen, etc ...
}Quoted 146 lines
Quoted 143 lines
Quoted 127 lines
Signed-off-by Daniel Lezcano <dlezcano-NmTC/[email protected]>--- 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
===================================================================arch/x86/include/asm/unistd_32.h +1
-0@@ -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
===================================================================arch/x86/include/asm/unistd_64.h +2
-1@@ -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_READDIRIndex:
net-next-2.6/arch/x86/kernel/syscall_table_32.S
===================================================================arch/x86/kernel/syscall_table_32.S +1
-0@@ -332,3 +332,4 @@ ENTRY(sys_call_table) .long sys_dup3 /* 330 */ .long sys_pipe2 .long sys_inotify_init1 + .long sys_socketatIndex:
net-next-2.6/net/socket.c
===================================================================net/socket.c +45
-0@@ -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
===================================================================include/linux/syscalls.h +1
-0@@ -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
===================================================================kernel/sys_ni.c +1
-1@@ -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); --Quoted 5 lines
_______________________________________________
Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers--
Michael Kerrisk Linux man-pages maintainer;
http://www.kernel.org/doc/man-pages/ Found a documentation bug?
http://www.kernel.org/doc/man-pages/reporting_bugs.html
--
To unsubscribe from this list: send the line "unsubscribe linux-api" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 8 lines
Sauf indication contraire ci-dessus: Compagnie IBM France Siège Social : Tour Descartes, 2, avenue Gambetta, La Défense 5, 92400 Courbevoie RCS Nanterre 552 118 465 Forme Sociale : S.A.S. Capital Social : 542.737.118 ? SIREN/SIRET : 552 118 465 02430
Re: [patch 1/2][RFC] add socketat syscall
In reply to a message not in the archiveQuoted 5 lines · Daniel Lezcano
Quoted 4 lines
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.
Daniel,
Is there any documentation for this system call, and/or test programs?
Cheers,
Michael
Quoted 144 lines
Quoted 127 lines
Signed-off-by Daniel Lezcano <dlezcano-NmTC/[email protected]>--- 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
===================================================================arch/x86/include/asm/unistd_32.h +1
-0@@ -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
===================================================================arch/x86/include/asm/unistd_64.h +2
-1@@ -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_READDIRIndex:
net-next-2.6/arch/x86/kernel/syscall_table_32.S
===================================================================arch/x86/kernel/syscall_table_32.S +1
-0@@ -332,3 +332,4 @@ ENTRY(sys_call_table) .long sys_dup3 /* 330 */ .long sys_pipe2 .long sys_inotify_init1 + .long sys_socketatIndex:
net-next-2.6/net/socket.c
===================================================================net/socket.c +45
-0@@ -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
===================================================================include/linux/syscalls.h +1
-0@@ -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
===================================================================kernel/sys_ni.c +1
-1@@ -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); --Quoted 5 lines
_______________________________________________
Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers--
Michael Kerrisk Linux man-pages maintainer;
http://www.kernel.org/doc/man-pages/ Found a documentation bug?
http://www.kernel.org/doc/man-pages/reporting_bugs.html
--
To unsubscribe from this list: send the line "unsubscribe linux-api" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 5 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ git://git.kernel.org/pub/scm/docs/man-pages/man-pages.git man-pages online: http://www.kernel.org/doc/man-pages/online_pages.html Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html
Re: [patch 1/2][RFC] add socketat syscall
In reply to a message not in the archiveHi Daniel,
Please CC linux-api on API/ABI changes.
See Documentation/SubmitChecklist and
http://thread.gmane.org/gmane.linux.ltp/5658.
Thanks,
Michael
Quoted 137 lines · Daniel Lezcano
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/[email protected]>--- 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
===================================================================arch/x86/include/asm/unistd_32.h +1
-0@@ -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
===================================================================arch/x86/include/asm/unistd_64.h +2
-1@@ -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_READDIRIndex:
net-next-2.6/arch/x86/kernel/syscall_table_32.S
===================================================================arch/x86/kernel/syscall_table_32.S +1
-0@@ -332,3 +332,4 @@ ENTRY(sys_call_table) .long sys_dup3 /* 330 */ .long sys_pipe2 .long sys_inotify_init1 + .long sys_socketatIndex:
net-next-2.6/net/socket.c
===================================================================net/socket.c +45
-0@@ -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
===================================================================include/linux/syscalls.h +1
-0@@ -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
===================================================================kernel/sys_ni.c +1
-1@@ -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); --_______________________________________________
Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Found a documentation bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html
RFC PATCH 2/2 Factor sys_socket and sys_socketat
In reply to Daniel LezcanoThe common code between sys_socket and sys_socketat has been grouped into the socket_create function. The both functions make use of it.
--- net/socket.c | 41 ++++++++--------------------------------- 1 file changed, 8 insertions(+), 33 deletions(-)
net/socket.c +8 -33
@@ -1216,7 +1216,7 @@ int sock_create_kern(int family, int typreturn __sock_create (&init_net, family, type, protocol, res,1 ); } -asmlinkage long sys_socket (int family,int type,int protocol) +static int socket_create (struct net *net,int family,int type,int protocol) {int retval;struct socket *sock;
@@ -1236,7 +1236,7 @@ asmlinkage long sys_socket(int family, iif (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;
@@ -1253,49 +1253,24 @@ out_release:return retval; } +asmlinkage long sys_socket (int family,int type,int protocol) +{ +return socket_create (current->nsproxy->net_ns, family, type, protocol); +} +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: + retval =socket_create (sock_net (sock->sk), family, type, protocol);fput_light (sock->file, fput_needed); out:return retval; - -out_release: -sock_release (sockat); - goto out; }/*
A message that is not in the archive (sent off-list or not yet received): 20081031215602.655672481-NmTC/[email protected]
Quoted 3 lines · Daniel Lezcano
This patchset (not tested) shows how it is possible to create a socket specifying the network namespace destination. That should allow a single process to handle several network namespaces.
Vivien, Andreas,
does this patch fit your needs ? If so, I can ask for mainstream inclusion.