aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorNicolas Dichtel <nicolas.dichtel@6wind.com>2015-01-15 09:11:15 -0500
committerDavid S. Miller <davem@davemloft.net>2015-01-19 14:21:18 -0500
commit0c7aecd4bde4b7302cd41986d3a29e4f0b0ed218 (patch)
tree2c4ba6eda5392449a2c9019aafd061324e242dbc /include
parent4de8b413700e78560388eb14c4bbc67aff62da6d (diff)
netns: add rtnl cmd to add and get peer netns ids
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>
Diffstat (limited to 'include')
-rw-r--r--include/net/net_namespace.h4
-rw-r--r--include/uapi/linux/Kbuild1
-rw-r--r--include/uapi/linux/net_namespace.h23
-rw-r--r--include/uapi/linux/rtnetlink.h5
4 files changed, 33 insertions, 0 deletions
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
index 2e8756b8c775..36faf4990c4b 100644
--- a/include/net/net_namespace.h
+++ b/include/net/net_namespace.h
@@ -60,6 +60,7 @@ struct net {
60 struct list_head exit_list; /* Use only net_mutex */ 60 struct list_head exit_list; /* Use only net_mutex */
61 61
62 struct user_namespace *user_ns; /* Owning user namespace */ 62 struct user_namespace *user_ns; /* Owning user namespace */
63 struct idr netns_ids;
63 64
64 struct ns_common ns; 65 struct ns_common ns;
65 66
@@ -290,6 +291,9 @@ static inline struct net *read_pnet(struct net * const *pnet)
290#define __net_initconst __initconst 291#define __net_initconst __initconst
291#endif 292#endif
292 293
294int peernet2id(struct net *net, struct net *peer);
295struct net *get_net_ns_by_id(struct net *net, int id);
296
293struct pernet_operations { 297struct pernet_operations {
294 struct list_head list; 298 struct list_head list;
295 int (*init)(struct net *net); 299 int (*init)(struct net *net);
diff --git a/include/uapi/linux/Kbuild b/include/uapi/linux/Kbuild
index 00b100023c47..14b7b6e44c77 100644
--- a/include/uapi/linux/Kbuild
+++ b/include/uapi/linux/Kbuild
@@ -283,6 +283,7 @@ header-y += net.h
283header-y += netlink_diag.h 283header-y += netlink_diag.h
284header-y += netlink.h 284header-y += netlink.h
285header-y += netrom.h 285header-y += netrom.h
286header-y += net_namespace.h
286header-y += net_tstamp.h 287header-y += net_tstamp.h
287header-y += nfc.h 288header-y += nfc.h
288header-y += nfs2.h 289header-y += nfs2.h
diff --git a/include/uapi/linux/net_namespace.h b/include/uapi/linux/net_namespace.h
new file mode 100644
index 000000000000..778cd2c3ebf4
--- /dev/null
+++ b/include/uapi/linux/net_namespace.h
@@ -0,0 +1,23 @@
1/* Copyright (c) 2015 6WIND S.A.
2 * Author: Nicolas Dichtel <nicolas.dichtel@6wind.com>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 */
8#ifndef _UAPI_LINUX_NET_NAMESPACE_H_
9#define _UAPI_LINUX_NET_NAMESPACE_H_
10
11/* Attributes of RTM_NEWNSID/RTM_GETNSID messages */
12enum {
13 NETNSA_NONE,
14#define NETNSA_NSID_NOT_ASSIGNED -1
15 NETNSA_NSID,
16 NETNSA_PID,
17 NETNSA_FD,
18 __NETNSA_MAX,
19};
20
21#define NETNSA_MAX (__NETNSA_MAX - 1)
22
23#endif /* _UAPI_LINUX_NET_NAMESPACE_H_ */
diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
index a1d18593f41e..5cc5d66bf519 100644
--- a/include/uapi/linux/rtnetlink.h
+++ b/include/uapi/linux/rtnetlink.h
@@ -132,6 +132,11 @@ enum {
132 RTM_GETMDB = 86, 132 RTM_GETMDB = 86,
133#define RTM_GETMDB RTM_GETMDB 133#define RTM_GETMDB RTM_GETMDB
134 134
135 RTM_NEWNSID = 88,
136#define RTM_NEWNSID RTM_NEWNSID
137 RTM_GETNSID = 90,
138#define RTM_GETNSID RTM_GETNSID
139
135 __RTM_MAX, 140 __RTM_MAX,
136#define RTM_MAX (((__RTM_MAX + 3) & ~3) - 1) 141#define RTM_MAX (((__RTM_MAX + 3) & ~3) - 1)
137}; 142};