diff --git a/include/linux/socket.h b/include/linux/socket.h index 2b06d8ccbd1687738b25717f2d1258e5a86c719f..c37812d9771caba61c3c3b17d762f9f5c2f67b5f 100644 --- a/include/linux/socket.h +++ b/include/linux/socket.h @@ -409,6 +409,4 @@ extern int __sys_getpeername(int fd, struct sockaddr __user *usockaddr, extern int __sys_socketpair(int family, int type, int protocol, int __user *usockvec); extern int __sys_shutdown(int fd, int how); - -extern struct ns_common *get_net_ns(struct ns_common *ns); #endif /* _LINUX_SOCKET_H */ diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h index 5007eaba207d53840101cda281df759181918692..bc88ac6c2e1d76dfca088de5da9d2189992abdbb 100644 --- a/include/net/net_namespace.h +++ b/include/net/net_namespace.h @@ -175,6 +175,8 @@ struct net *copy_net_ns(unsigned long flags, struct user_namespace *user_ns, void net_ns_get_ownership(const struct net *net, kuid_t *uid, kgid_t *gid); void net_ns_barrier(void); + +struct ns_common *get_net_ns(struct ns_common *ns); #else /* CONFIG_NET_NS */ #include #include @@ -194,6 +196,11 @@ static inline void net_ns_get_ownership(const struct net *net, } static inline void net_ns_barrier(void) {} + +static inline struct ns_common *get_net_ns(struct ns_common *ns) +{ + return ERR_PTR(-EINVAL); +} #endif /* CONFIG_NET_NS */ diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index c60123dff803912c398cb6fa9e25a08f326fd879..939d8a31eb82a36ab47da5376c5a449482f507a2 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c @@ -598,6 +598,18 @@ void __put_net(struct net *net) } EXPORT_SYMBOL_GPL(__put_net); +/** + * get_net_ns - increment the refcount of the network namespace + * @ns: common namespace (net) + * + * Returns the net's common namespace. + */ +struct ns_common *get_net_ns(struct ns_common *ns) +{ + return &get_net(container_of(ns, struct net, ns))->ns; +} +EXPORT_SYMBOL_GPL(get_net_ns); + struct net *get_net_ns_by_fd(int fd) { struct file *file; diff --git a/net/socket.c b/net/socket.c index bf943e6d47fe8372c89de1200c205f89dcc69eda..9e4ef5342dd8126905821b0d1b0ef630005ee326 100644 --- a/net/socket.c +++ b/net/socket.c @@ -1048,19 +1048,6 @@ static long sock_do_ioctl(struct net *net, struct socket *sock, * what to do with it - that's up to the protocol still. */ -/** - * get_net_ns - increment the refcount of the network namespace - * @ns: common namespace (net) - * - * Returns the net's common namespace. - */ - -struct ns_common *get_net_ns(struct ns_common *ns) -{ - return &get_net(container_of(ns, struct net, ns))->ns; -} -EXPORT_SYMBOL_GPL(get_net_ns); - static long sock_ioctl(struct file *file, unsigned cmd, unsigned long arg) { struct socket *sock;