]> git.openpandora.org Git - pandora-kernel.git/commitdiff
netns: add rtnl cmd to add and get peer netns ids
authorNicolas Dichtel <nicolas.dichtel@6wind.com>
Thu, 15 Jan 2015 14:11:15 +0000 (15:11 +0100)
committerDavid S. Miller <davem@davemloft.net>
Mon, 19 Jan 2015 19:21:18 +0000 (14:21 -0500)
With this patch, a user can define an id for a peer netns by providing a FD or a
PID. These ids are local to the netns where it is added (ie valid only into this
netns).

The main function (ie the one exported to other module), peernet2id(), allows to
get the id of a peer netns. If no id has been assigned by the user, this
function allocates one.

These ids will be used in netlink messages to point to a peer netns, for example
in case of a x-netns interface.

Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
MAINTAINERS
include/net/net_namespace.h
include/uapi/linux/Kbuild
include/uapi/linux/net_namespace.h [new file with mode: 0644]
include/uapi/linux/rtnetlink.h
net/core/net_namespace.c

index 9de900572633bdccd6a7afa39943d36e391b1a86..9b91d9f0257e370d61a32095fdcb8914a5882873 100644 (file)
@@ -6578,6 +6578,7 @@ F:        include/linux/netdevice.h
 F:     include/uapi/linux/in.h
 F:     include/uapi/linux/net.h
 F:     include/uapi/linux/netdevice.h
+F:     include/uapi/linux/net_namespace.h
 F:     tools/net/
 F:     tools/testing/selftests/net/
 F:     lib/random32.c
index 2e8756b8c77543391b1c3381fa442c2a2a1c582e..36faf4990c4b6f2604fd2b00178c941d75f540a8 100644 (file)
@@ -60,6 +60,7 @@ struct net {
        struct list_head        exit_list;      /* Use only net_mutex */
 
        struct user_namespace   *user_ns;       /* Owning user namespace */
+       struct idr              netns_ids;
 
        struct ns_common        ns;
 
@@ -290,6 +291,9 @@ static inline struct net *read_pnet(struct net * const *pnet)
 #define __net_initconst        __initconst
 #endif
 
+int peernet2id(struct net *net, struct net *peer);
+struct net *get_net_ns_by_id(struct net *net, int id);
+
 struct pernet_operations {
        struct list_head list;
        int (*init)(struct net *net);
index 00b100023c477bf80de661c386ceb27461f4bbd6..14b7b6e44c77ce279960d852936e9fbf37b231da 100644 (file)
@@ -283,6 +283,7 @@ header-y += net.h
 header-y += netlink_diag.h
 header-y += netlink.h
 header-y += netrom.h
+header-y += net_namespace.h
 header-y += net_tstamp.h
 header-y += nfc.h
 header-y += nfs2.h
diff --git a/include/uapi/linux/net_namespace.h b/include/uapi/linux/net_namespace.h
new file mode 100644 (file)
index 0000000..778cd2c
--- /dev/null
@@ -0,0 +1,23 @@
+/* Copyright (c) 2015 6WIND S.A.
+ * Author: Nicolas Dichtel <nicolas.dichtel@6wind.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ */
+#ifndef _UAPI_LINUX_NET_NAMESPACE_H_
+#define _UAPI_LINUX_NET_NAMESPACE_H_
+
+/* Attributes of RTM_NEWNSID/RTM_GETNSID messages */
+enum {
+       NETNSA_NONE,
+#define NETNSA_NSID_NOT_ASSIGNED -1
+       NETNSA_NSID,
+       NETNSA_PID,
+       NETNSA_FD,
+       __NETNSA_MAX,
+};
+
+#define NETNSA_MAX             (__NETNSA_MAX - 1)
+
+#endif /* _UAPI_LINUX_NET_NAMESPACE_H_ */
Simple merge
Simple merge