Commit | Line | Data |
---|---|---|
5f256bec EB |
1 | /* |
2 | * Operations on the network namespace | |
3 | */ | |
4 | #ifndef __NET_NET_NAMESPACE_H | |
5 | #define __NET_NET_NAMESPACE_H | |
6 | ||
7 | #include <asm/atomic.h> | |
8 | #include <linux/workqueue.h> | |
9 | #include <linux/list.h> | |
10 | ||
a0a53c8b | 11 | #include <net/netns/unix.h> |
2aaef4e4 | 12 | #include <net/netns/packet.h> |
8afd351c | 13 | #include <net/netns/ipv4.h> |
b0f159db | 14 | #include <net/netns/ipv6.h> |
a0a53c8b | 15 | |
457c4cbc | 16 | struct proc_dir_entry; |
2774c7ab | 17 | struct net_device; |
97c53cac | 18 | struct sock; |
1597fbc0 PE |
19 | struct ctl_table_header; |
20 | ||
5f256bec EB |
21 | struct net { |
22 | atomic_t count; /* To decided when the network | |
23 | * namespace should be freed. | |
24 | */ | |
25 | atomic_t use_count; /* To track references we | |
26 | * destroy on demand | |
27 | */ | |
28 | struct list_head list; /* list of network namespaces */ | |
29 | struct work_struct work; /* work struct for freeing */ | |
457c4cbc EB |
30 | |
31 | struct proc_dir_entry *proc_net; | |
32 | struct proc_dir_entry *proc_net_stat; | |
33 | struct proc_dir_entry *proc_net_root; | |
881d966b | 34 | |
95bdfccb EB |
35 | struct list_head sysctl_table_headers; |
36 | ||
2774c7ab EB |
37 | struct net_device *loopback_dev; /* The loopback */ |
38 | ||
881d966b EB |
39 | struct list_head dev_base_head; |
40 | struct hlist_head *dev_name_head; | |
41 | struct hlist_head *dev_index_head; | |
97c53cac DL |
42 | |
43 | struct sock *rtnl; /* rtnetlink socket */ | |
d12d01d6 | 44 | |
024626e3 PE |
45 | /* core sysctls */ |
46 | struct ctl_table_header *sysctl_core_hdr; | |
b8e1f9b5 | 47 | int sysctl_somaxconn; |
024626e3 | 48 | |
2aaef4e4 | 49 | struct netns_packet packet; |
a0a53c8b | 50 | struct netns_unix unx; |
8afd351c | 51 | struct netns_ipv4 ipv4; |
b0f159db DL |
52 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) |
53 | struct netns_ipv6 ipv6; | |
54 | #endif | |
5f256bec EB |
55 | }; |
56 | ||
4fabcd71 DL |
57 | #ifdef CONFIG_NET |
58 | /* Init's network namespace */ | |
5f256bec | 59 | extern struct net init_net; |
4fabcd71 DL |
60 | #define INIT_NET_NS(net_ns) .net_ns = &init_net, |
61 | #else | |
62 | #define INIT_NET_NS(net_ns) | |
63 | #endif | |
64 | ||
5f256bec EB |
65 | extern struct list_head net_namespace_list; |
66 | ||
9dd776b6 EB |
67 | #ifdef CONFIG_NET |
68 | extern struct net *copy_net_ns(unsigned long flags, struct net *net_ns); | |
69 | #else | |
70 | static inline struct net *copy_net_ns(unsigned long flags, struct net *net_ns) | |
71 | { | |
72 | /* There is nothing to copy so this is a noop */ | |
73 | return net_ns; | |
74 | } | |
75 | #endif | |
76 | ||
d4655795 | 77 | #ifdef CONFIG_NET_NS |
5f256bec EB |
78 | extern void __put_net(struct net *net); |
79 | ||
80 | static inline struct net *get_net(struct net *net) | |
81 | { | |
82 | atomic_inc(&net->count); | |
83 | return net; | |
84 | } | |
85 | ||
077130c0 EB |
86 | static inline struct net *maybe_get_net(struct net *net) |
87 | { | |
88 | /* Used when we know struct net exists but we | |
89 | * aren't guaranteed a previous reference count | |
90 | * exists. If the reference count is zero this | |
91 | * function fails and returns NULL. | |
92 | */ | |
93 | if (!atomic_inc_not_zero(&net->count)) | |
94 | net = NULL; | |
95 | return net; | |
96 | } | |
97 | ||
5f256bec EB |
98 | static inline void put_net(struct net *net) |
99 | { | |
100 | if (atomic_dec_and_test(&net->count)) | |
101 | __put_net(net); | |
102 | } | |
103 | ||
104 | static inline struct net *hold_net(struct net *net) | |
105 | { | |
106 | atomic_inc(&net->use_count); | |
107 | return net; | |
108 | } | |
109 | ||
110 | static inline void release_net(struct net *net) | |
111 | { | |
112 | atomic_dec(&net->use_count); | |
113 | } | |
d4655795 PE |
114 | #else |
115 | static inline struct net *get_net(struct net *net) | |
116 | { | |
117 | return net; | |
118 | } | |
119 | ||
120 | static inline void put_net(struct net *net) | |
121 | { | |
122 | } | |
123 | ||
124 | static inline struct net *hold_net(struct net *net) | |
125 | { | |
126 | return net; | |
127 | } | |
128 | ||
129 | static inline void release_net(struct net *net) | |
130 | { | |
131 | } | |
132 | ||
133 | static inline struct net *maybe_get_net(struct net *net) | |
134 | { | |
135 | return net; | |
136 | } | |
137 | #endif | |
5f256bec | 138 | |
5f256bec EB |
139 | #define for_each_net(VAR) \ |
140 | list_for_each_entry(VAR, &net_namespace_list, list) | |
141 | ||
4665079c PE |
142 | #ifdef CONFIG_NET_NS |
143 | #define __net_init | |
144 | #define __net_exit | |
022cbae6 | 145 | #define __net_initdata |
4665079c PE |
146 | #else |
147 | #define __net_init __init | |
148 | #define __net_exit __exit_refok | |
022cbae6 | 149 | #define __net_initdata __initdata |
4665079c | 150 | #endif |
5f256bec EB |
151 | |
152 | struct pernet_operations { | |
153 | struct list_head list; | |
154 | int (*init)(struct net *net); | |
155 | void (*exit)(struct net *net); | |
156 | }; | |
157 | ||
158 | extern int register_pernet_subsys(struct pernet_operations *); | |
159 | extern void unregister_pernet_subsys(struct pernet_operations *); | |
160 | extern int register_pernet_device(struct pernet_operations *); | |
161 | extern void unregister_pernet_device(struct pernet_operations *); | |
162 | ||
95bdfccb EB |
163 | struct ctl_path; |
164 | struct ctl_table; | |
165 | struct ctl_table_header; | |
166 | extern struct ctl_table_header *register_net_sysctl_table(struct net *net, | |
167 | const struct ctl_path *path, struct ctl_table *table); | |
168 | extern void unregister_net_sysctl_table(struct ctl_table_header *header); | |
169 | ||
5f256bec | 170 | #endif /* __NET_NET_NAMESPACE_H */ |