@@ -77,6 +77,8 @@
/* Instruct lower device to use last 4-bytes of skb data as FCS */
#define SO_NOFCS 43
+#define SO_NETNS 44
+
#ifdef __KERNEL__
/* O_NONBLOCK clashes with the bits used for socket types. Therefore we
* have to define SOCK_NONBLOCK to a different value here.
@@ -70,4 +70,6 @@
/* Instruct lower device to use last 4-bytes of skb data as FCS */
#define SO_NOFCS 43
+#define SO_NETNS 44
+
#endif /* __ASM_AVR32_SOCKET_H */
@@ -70,5 +70,7 @@
/* Instruct lower device to use last 4-bytes of skb data as FCS */
#define SO_NOFCS 43
+#define SO_NETNS 44
+
#endif /* _ASM_SOCKET_H */
@@ -70,4 +70,6 @@
/* Instruct lower device to use last 4-bytes of skb data as FCS */
#define SO_NOFCS 43
+#define SO_NETNS 44
+
#endif /* _ASM_SOCKET_H */
@@ -79,4 +79,6 @@
/* Instruct lower device to use last 4-bytes of skb data as FCS */
#define SO_NOFCS 43
+#define SO_NETNS 44
+
#endif /* _ASM_IA64_SOCKET_H */
@@ -70,4 +70,6 @@
/* Instruct lower device to use last 4-bytes of skb data as FCS */
#define SO_NOFCS 43
+#define SO_NETNS 44
+
#endif /* _ASM_M32R_SOCKET_H */
@@ -70,4 +70,6 @@
/* Instruct lower device to use last 4-bytes of skb data as FCS */
#define SO_NOFCS 43
+#define SO_NETNS 44
+
#endif /* _ASM_SOCKET_H */
@@ -90,5 +90,7 @@ To add: #define SO_REUSEPORT 0x0200 /* Allow local address and port reuse. */
/* Instruct lower device to use last 4-bytes of skb data as FCS */
#define SO_NOFCS 43
+#define SO_NETNS 44
+
#endif /* _UAPI_ASM_SOCKET_H */
@@ -70,4 +70,6 @@
/* Instruct lower device to use last 4-bytes of skb data as FCS */
#define SO_NOFCS 43
+#define SO_NETNS 44
+
#endif /* _ASM_SOCKET_H */
@@ -69,6 +69,8 @@
/* Instruct lower device to use last 4-bytes of skb data as FCS */
#define SO_NOFCS 0x4024
+#define SO_NETNS 0x4025
+
/* O_NONBLOCK clashes with the bits used for socket types. Therefore we
* have to define SOCK_NONBLOCK to a different value here.
@@ -77,4 +77,6 @@
/* Instruct lower device to use last 4-bytes of skb data as FCS */
#define SO_NOFCS 43
+#define SO_NETNS 44
+
#endif /* _ASM_POWERPC_SOCKET_H */
@@ -76,4 +76,6 @@
/* Instruct lower device to use last 4-bytes of skb data as FCS */
#define SO_NOFCS 43
+#define SO_NETNS 44
+
#endif /* _ASM_SOCKET_H */
@@ -66,6 +66,8 @@
/* Instruct lower device to use last 4-bytes of skb data as FCS */
#define SO_NOFCS 0x0027
+#define SO_NETNS 0x0028
+
/* Security levels - as per NRL IPv6 - don't actually do anything */
#define SO_SECURITY_AUTHENTICATION 0x5001
@@ -81,4 +81,6 @@
/* Instruct lower device to use last 4-bytes of skb data as FCS */
#define SO_NOFCS 43
+#define SO_NETNS 44
+
#endif /* _XTENSA_SOCKET_H */
@@ -73,4 +73,6 @@
/* Instruct lower device to use last 4-bytes of skb data as FCS */
#define SO_NOFCS 43
+#define SO_NETNS 44
+
#endif /* __ASM_GENERIC_SOCKET_H */
@@ -895,6 +895,30 @@ set_rcvbuf:
sock_valbool_flag(sk, SOCK_NOFCS, valbool);
break;
+ case SO_NETNS:
+#ifdef CONFIG_NET_NS
+ if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
+ ret = -EPERM;
+ else if (sk->sk_state != TCP_CLOSE)
+ ret = -EBUSY; /* Too late to change netns */
+ else {
+ struct net *net = get_net_ns_by_nsindex(val);
+
+ if (net) {
+ /* We can not use sk_change_net() because sk
+ * will not be released with
+ * sk_release_kernel(). Let do it manually.
+ */
+ put_net(sock_net(sk));
+ sock_net_set(sk, net);
+ } else
+ ret = -EINVAL;
+ }
+#else
+ ret = -EOPNOTSUPP;
+#endif
+ break;
+
default:
ret = -ENOPROTOOPT;
break;
@@ -1140,6 +1164,10 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
goto lenout;
+ case SO_NETNS:
+ v.val = sock_net(sk)->nsindex;
+ break;
+
default:
return -ENOPROTOOPT;
}
This new setsockopt() option allows user to change netns of a socket. It should be done enough early, before any bind(), etc. Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com> --- arch/alpha/include/asm/socket.h | 2 ++ arch/avr32/include/uapi/asm/socket.h | 2 ++ arch/frv/include/uapi/asm/socket.h | 2 ++ arch/h8300/include/asm/socket.h | 2 ++ arch/ia64/include/uapi/asm/socket.h | 2 ++ arch/m32r/include/asm/socket.h | 2 ++ arch/m68k/include/uapi/asm/socket.h | 2 ++ arch/mips/include/uapi/asm/socket.h | 2 ++ arch/mn10300/include/uapi/asm/socket.h | 2 ++ arch/parisc/include/uapi/asm/socket.h | 2 ++ arch/powerpc/include/uapi/asm/socket.h | 2 ++ arch/s390/include/uapi/asm/socket.h | 2 ++ arch/sparc/include/uapi/asm/socket.h | 2 ++ arch/xtensa/include/uapi/asm/socket.h | 2 ++ include/uapi/asm-generic/socket.h | 2 ++ net/core/sock.c | 28 ++++++++++++++++++++++++++++ 16 files changed, 58 insertions(+)