Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
5f256bec EB |
2 | /* |
3 | * Operations on the network namespace | |
4 | */ | |
5 | #ifndef __NET_NET_NAMESPACE_H | |
6 | #define __NET_NET_NAMESPACE_H | |
7 | ||
60063497 | 8 | #include <linux/atomic.h> |
c122e14d | 9 | #include <linux/refcount.h> |
5f256bec EB |
10 | #include <linux/workqueue.h> |
11 | #include <linux/list.h> | |
bee95250 | 12 | #include <linux/sysctl.h> |
fbdeaed4 | 13 | #include <linux/uidgid.h> |
5f256bec | 14 | |
6a662719 | 15 | #include <net/flow.h> |
8efa6e93 | 16 | #include <net/netns/core.h> |
852566f5 | 17 | #include <net/netns/mib.h> |
a0a53c8b | 18 | #include <net/netns/unix.h> |
2aaef4e4 | 19 | #include <net/netns/packet.h> |
8afd351c | 20 | #include <net/netns/ipv4.h> |
b0f159db | 21 | #include <net/netns/ipv6.h> |
ab84be7e | 22 | #include <net/netns/nexthop.h> |
633fc86f | 23 | #include <net/netns/ieee802154_6lowpan.h> |
4db67e80 | 24 | #include <net/netns/sctp.h> |
f3c1a44a | 25 | #include <net/netns/netfilter.h> |
dfdb8d79 AD |
26 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) |
27 | #include <net/netns/conntrack.h> | |
28 | #endif | |
b0381776 VB |
29 | #if IS_ENABLED(CONFIG_NF_FLOW_TABLE) |
30 | #include <net/netns/flow_table.h> | |
31 | #endif | |
99633ab2 | 32 | #include <net/netns/nftables.h> |
d62ddc21 | 33 | #include <net/netns/xfrm.h> |
0189197f | 34 | #include <net/netns/mpls.h> |
8e8cda6d | 35 | #include <net/netns/can.h> |
1d0dc069 | 36 | #include <net/netns/xdp.h> |
194730a9 | 37 | #include <net/netns/smc.h> |
a3fd7cee | 38 | #include <net/netns/bpf.h> |
889b7da2 | 39 | #include <net/netns/mctp.h> |
9ba74e6c | 40 | #include <net/net_trackers.h> |
435d5f4b | 41 | #include <linux/ns_common.h> |
04c52dec PNA |
42 | #include <linux/idr.h> |
43 | #include <linux/skbuff.h> | |
a30c7b42 | 44 | #include <linux/notifier.h> |
759ab1ed | 45 | #include <linux/xarray.h> |
a0a53c8b | 46 | |
038e7332 | 47 | struct user_namespace; |
457c4cbc | 48 | struct proc_dir_entry; |
2774c7ab | 49 | struct net_device; |
97c53cac | 50 | struct sock; |
1597fbc0 | 51 | struct ctl_table_header; |
dec827d1 | 52 | struct net_generic; |
94e5e308 | 53 | struct uevent_sock; |
2553d064 | 54 | struct netns_ipvs; |
d58e468b | 55 | struct bpf_prog; |
1597fbc0 | 56 | |
7c28bd0b ED |
57 | |
58 | #define NETDEV_HASHBITS 8 | |
59 | #define NETDEV_HASHENTRIES (1 << NETDEV_HASHBITS) | |
60 | ||
5f256bec | 61 | struct net { |
2a06b898 ED |
62 | /* First cache line can be often dirtied. |
63 | * Do not place here read-mostly fields. | |
64 | */ | |
aad12c23 | 65 | refcount_t passive; /* To decide when the network |
a685e089 AV |
66 | * namespace should be freed. |
67 | */ | |
8e602ce2 ED |
68 | spinlock_t rules_mod_lock; |
69 | ||
2a06b898 | 70 | unsigned int dev_base_seq; /* protected by rtnl_mutex */ |
759ab1ed | 71 | u32 ifindex; |
2a06b898 ED |
72 | |
73 | spinlock_t nsid_lock; | |
74 | atomic_t fnhe_genid; | |
33cf7c90 | 75 | |
5f256bec | 76 | struct list_head list; /* list of network namespaces */ |
19efbd93 | 77 | struct list_head exit_list; /* To linked to call pernet exit |
4420bf21 KT |
78 | * methods on dead net ( |
79 | * pernet_ops_rwsem read locked), | |
80 | * or to unregister pernet ops | |
81 | * (pernet_ops_rwsem write locked). | |
19efbd93 | 82 | */ |
65b7b5b9 KT |
83 | struct llist_node cleanup_list; /* namespaces on death row */ |
84 | ||
9b242610 DH |
85 | #ifdef CONFIG_KEYS |
86 | struct key_tag *key_domain; /* Key domain of operation tag */ | |
87 | #endif | |
038e7332 | 88 | struct user_namespace *user_ns; /* Owning user namespace */ |
70328660 | 89 | struct ucounts *ucounts; |
0c7aecd4 | 90 | struct idr netns_ids; |
038e7332 | 91 | |
435d5f4b | 92 | struct ns_common ns; |
9ba74e6c | 93 | struct ref_tracker_dir refcnt_tracker; |
0cafd77d ED |
94 | struct ref_tracker_dir notrefcnt_tracker; /* tracker for objects not |
95 | * refcounted against netns | |
96 | */ | |
2a06b898 | 97 | struct list_head dev_base_head; |
457c4cbc EB |
98 | struct proc_dir_entry *proc_net; |
99 | struct proc_dir_entry *proc_net_stat; | |
881d966b | 100 | |
73455092 AV |
101 | #ifdef CONFIG_SYSCTL |
102 | struct ctl_table_set sysctls; | |
103 | #endif | |
95bdfccb | 104 | |
8e602ce2 ED |
105 | struct sock *rtnl; /* rtnetlink socket */ |
106 | struct sock *genl_sock; | |
2774c7ab | 107 | |
94e5e308 CB |
108 | struct uevent_sock *uevent_sock; /* uevent socket */ |
109 | ||
881d966b EB |
110 | struct hlist_head *dev_name_head; |
111 | struct hlist_head *dev_index_head; | |
759ab1ed | 112 | struct xarray dev_by_index; |
a30c7b42 JP |
113 | struct raw_notifier_head netdev_chain; |
114 | ||
2a06b898 ED |
115 | /* Note that @hash_mix can be read millions times per second, |
116 | * it is critical that it is on a read_mostly cache line. | |
117 | */ | |
118 | u32 hash_mix; | |
119 | ||
120 | struct net_device *loopback_dev; /* The loopback */ | |
97c53cac | 121 | |
5fd30ee7 DL |
122 | /* core fib_rules */ |
123 | struct list_head rules_ops; | |
5fd30ee7 | 124 | |
8efa6e93 | 125 | struct netns_core core; |
852566f5 | 126 | struct netns_mib mib; |
2aaef4e4 | 127 | struct netns_packet packet; |
b6e81138 | 128 | #if IS_ENABLED(CONFIG_UNIX) |
a0a53c8b | 129 | struct netns_unix unx; |
b6e81138 | 130 | #endif |
ab84be7e | 131 | struct netns_nexthop nexthop; |
8afd351c | 132 | struct netns_ipv4 ipv4; |
dfd56b8b | 133 | #if IS_ENABLED(CONFIG_IPV6) |
b0f159db DL |
134 | struct netns_ipv6 ipv6; |
135 | #endif | |
633fc86f AA |
136 | #if IS_ENABLED(CONFIG_IEEE802154_6LOWPAN) |
137 | struct netns_ieee802154_lowpan ieee802154_lowpan; | |
138 | #endif | |
4db67e80 EB |
139 | #if defined(CONFIG_IP_SCTP) || defined(CONFIG_IP_SCTP_MODULE) |
140 | struct netns_sctp sctp; | |
141 | #endif | |
8d870052 | 142 | #ifdef CONFIG_NETFILTER |
f3c1a44a | 143 | struct netns_nf nf; |
dfdb8d79 AD |
144 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) |
145 | struct netns_ct ct; | |
c038a767 | 146 | #endif |
99633ab2 PNA |
147 | #if defined(CONFIG_NF_TABLES) || defined(CONFIG_NF_TABLES_MODULE) |
148 | struct netns_nftables nft; | |
149 | #endif | |
b0381776 VB |
150 | #if IS_ENABLED(CONFIG_NF_FLOW_TABLE) |
151 | struct netns_ft ft; | |
152 | #endif | |
d62ddc21 | 153 | #endif |
3d23e349 | 154 | #ifdef CONFIG_WEXT_CORE |
b333b3d2 | 155 | struct sk_buff_head wext_nlevents; |
8d870052 | 156 | #endif |
1c87733d | 157 | struct net_generic __rcu *gen; |
8e602ce2 | 158 | |
a3fd7cee JS |
159 | /* Used to store attached BPF programs */ |
160 | struct netns_bpf bpf; | |
d58e468b | 161 | |
8e602ce2 ED |
162 | /* Note : following structs are cache line aligned */ |
163 | #ifdef CONFIG_XFRM | |
164 | struct netns_xfrm xfrm; | |
165 | #endif | |
f318903c | 166 | |
3d368ab8 | 167 | u64 net_cookie; /* written once */ |
f318903c | 168 | |
8b4d14d8 | 169 | #if IS_ENABLED(CONFIG_IP_VS) |
61b1ab45 | 170 | struct netns_ipvs *ipvs; |
0189197f EB |
171 | #endif |
172 | #if IS_ENABLED(CONFIG_MPLS) | |
173 | struct netns_mpls mpls; | |
8e8cda6d MK |
174 | #endif |
175 | #if IS_ENABLED(CONFIG_CAN) | |
176 | struct netns_can can; | |
1d0dc069 BT |
177 | #endif |
178 | #ifdef CONFIG_XDP_SOCKETS | |
179 | struct netns_xdp xdp; | |
91b05a7e | 180 | #endif |
889b7da2 JK |
181 | #if IS_ENABLED(CONFIG_MCTP) |
182 | struct netns_mctp mctp; | |
183 | #endif | |
91b05a7e OM |
184 | #if IS_ENABLED(CONFIG_CRYPTO_USER) |
185 | struct sock *crypto_nlsk; | |
8b4d14d8 | 186 | #endif |
51d7cccf | 187 | struct sock *diag_nlsk; |
194730a9 GG |
188 | #if IS_ENABLED(CONFIG_SMC) |
189 | struct netns_smc smc; | |
190 | #endif | |
3859a271 | 191 | } __randomize_layout; |
5f256bec | 192 | |
c0f39322 DL |
193 | #include <linux/seq_file_net.h> |
194 | ||
4fabcd71 | 195 | /* Init's network namespace */ |
5f256bec | 196 | extern struct net init_net; |
a4aa834a | 197 | |
d727abcb | 198 | #ifdef CONFIG_NET_NS |
e67e16ea JP |
199 | struct net *copy_net_ns(unsigned long flags, struct user_namespace *user_ns, |
200 | struct net *old_net); | |
225c0a01 | 201 | |
fbdeaed4 TH |
202 | void net_ns_get_ownership(const struct net *net, kuid_t *uid, kgid_t *gid); |
203 | ||
7866cc57 | 204 | void net_ns_barrier(void); |
ea6932d7 CD |
205 | |
206 | struct ns_common *get_net_ns(struct ns_common *ns); | |
e34492de | 207 | struct net *get_net_ns_by_fd(int fd); |
d727abcb EB |
208 | #else /* CONFIG_NET_NS */ |
209 | #include <linux/sched.h> | |
210 | #include <linux/nsproxy.h> | |
038e7332 EB |
211 | static inline struct net *copy_net_ns(unsigned long flags, |
212 | struct user_namespace *user_ns, struct net *old_net) | |
9dd776b6 | 213 | { |
d727abcb EB |
214 | if (flags & CLONE_NEWNET) |
215 | return ERR_PTR(-EINVAL); | |
216 | return old_net; | |
9dd776b6 | 217 | } |
7866cc57 | 218 | |
fbdeaed4 TH |
219 | static inline void net_ns_get_ownership(const struct net *net, |
220 | kuid_t *uid, kgid_t *gid) | |
221 | { | |
222 | *uid = GLOBAL_ROOT_UID; | |
223 | *gid = GLOBAL_ROOT_GID; | |
224 | } | |
225 | ||
7866cc57 | 226 | static inline void net_ns_barrier(void) {} |
ea6932d7 CD |
227 | |
228 | static inline struct ns_common *get_net_ns(struct ns_common *ns) | |
229 | { | |
230 | return ERR_PTR(-EINVAL); | |
231 | } | |
e34492de CD |
232 | |
233 | static inline struct net *get_net_ns_by_fd(int fd) | |
234 | { | |
235 | return ERR_PTR(-EINVAL); | |
236 | } | |
d727abcb | 237 | #endif /* CONFIG_NET_NS */ |
225c0a01 DL |
238 | |
239 | ||
240 | extern struct list_head net_namespace_list; | |
9dd776b6 | 241 | |
e67e16ea | 242 | struct net *get_net_ns_by_pid(pid_t pid); |
30ffee84 | 243 | |
535d3ae9 RK |
244 | #ifdef CONFIG_SYSCTL |
245 | void ipx_register_sysctl(void); | |
246 | void ipx_unregister_sysctl(void); | |
247 | #else | |
248 | #define ipx_register_sysctl() | |
249 | #define ipx_unregister_sysctl() | |
250 | #endif | |
251 | ||
d4655795 | 252 | #ifdef CONFIG_NET_NS |
e67e16ea | 253 | void __put_net(struct net *net); |
5f256bec | 254 | |
9ba74e6c | 255 | /* Try using get_net_track() instead */ |
5f256bec EB |
256 | static inline struct net *get_net(struct net *net) |
257 | { | |
8b8f3e66 | 258 | refcount_inc(&net->ns.count); |
5f256bec EB |
259 | return net; |
260 | } | |
261 | ||
077130c0 EB |
262 | static inline struct net *maybe_get_net(struct net *net) |
263 | { | |
264 | /* Used when we know struct net exists but we | |
265 | * aren't guaranteed a previous reference count | |
266 | * exists. If the reference count is zero this | |
267 | * function fails and returns NULL. | |
268 | */ | |
8b8f3e66 | 269 | if (!refcount_inc_not_zero(&net->ns.count)) |
077130c0 EB |
270 | net = NULL; |
271 | return net; | |
272 | } | |
273 | ||
9ba74e6c | 274 | /* Try using put_net_track() instead */ |
5f256bec EB |
275 | static inline void put_net(struct net *net) |
276 | { | |
8b8f3e66 | 277 | if (refcount_dec_and_test(&net->ns.count)) |
5f256bec EB |
278 | __put_net(net); |
279 | } | |
280 | ||
878628fb YH |
281 | static inline |
282 | int net_eq(const struct net *net1, const struct net *net2) | |
283 | { | |
284 | return net1 == net2; | |
285 | } | |
a685e089 | 286 | |
4ee806d5 DS |
287 | static inline int check_net(const struct net *net) |
288 | { | |
8b8f3e66 | 289 | return refcount_read(&net->ns.count) != 0; |
4ee806d5 DS |
290 | } |
291 | ||
e67e16ea | 292 | void net_drop_ns(void *); |
a685e089 | 293 | |
d4655795 | 294 | #else |
b9f75f45 | 295 | |
d4655795 PE |
296 | static inline struct net *get_net(struct net *net) |
297 | { | |
298 | return net; | |
299 | } | |
300 | ||
301 | static inline void put_net(struct net *net) | |
302 | { | |
303 | } | |
304 | ||
5d1e4468 DL |
305 | static inline struct net *maybe_get_net(struct net *net) |
306 | { | |
307 | return net; | |
308 | } | |
309 | ||
310 | static inline | |
311 | int net_eq(const struct net *net1, const struct net *net2) | |
312 | { | |
313 | return 1; | |
314 | } | |
a685e089 | 315 | |
4ee806d5 DS |
316 | static inline int check_net(const struct net *net) |
317 | { | |
318 | return 1; | |
319 | } | |
320 | ||
a685e089 | 321 | #define net_drop_ns NULL |
5d1e4468 DL |
322 | #endif |
323 | ||
324 | ||
0cafd77d ED |
325 | static inline void __netns_tracker_alloc(struct net *net, |
326 | netns_tracker *tracker, | |
327 | bool refcounted, | |
328 | gfp_t gfp) | |
9ba74e6c ED |
329 | { |
330 | #ifdef CONFIG_NET_NS_REFCNT_TRACKER | |
0cafd77d ED |
331 | ref_tracker_alloc(refcounted ? &net->refcnt_tracker : |
332 | &net->notrefcnt_tracker, | |
333 | tracker, gfp); | |
9ba74e6c ED |
334 | #endif |
335 | } | |
336 | ||
0cafd77d ED |
337 | static inline void netns_tracker_alloc(struct net *net, netns_tracker *tracker, |
338 | gfp_t gfp) | |
339 | { | |
340 | __netns_tracker_alloc(net, tracker, true, gfp); | |
341 | } | |
342 | ||
343 | static inline void __netns_tracker_free(struct net *net, | |
344 | netns_tracker *tracker, | |
345 | bool refcounted) | |
9ba74e6c ED |
346 | { |
347 | #ifdef CONFIG_NET_NS_REFCNT_TRACKER | |
0cafd77d ED |
348 | ref_tracker_free(refcounted ? &net->refcnt_tracker : |
349 | &net->notrefcnt_tracker, tracker); | |
9ba74e6c ED |
350 | #endif |
351 | } | |
352 | ||
353 | static inline struct net *get_net_track(struct net *net, | |
354 | netns_tracker *tracker, gfp_t gfp) | |
355 | { | |
356 | get_net(net); | |
357 | netns_tracker_alloc(net, tracker, gfp); | |
358 | return net; | |
359 | } | |
360 | ||
361 | static inline void put_net_track(struct net *net, netns_tracker *tracker) | |
362 | { | |
0cafd77d | 363 | __netns_tracker_free(net, tracker, true); |
9ba74e6c ED |
364 | put_net(net); |
365 | } | |
366 | ||
0c5c9fb5 | 367 | typedef struct { |
8f424b5f | 368 | #ifdef CONFIG_NET_NS |
2034d90a | 369 | struct net __rcu *net; |
0c5c9fb5 EB |
370 | #endif |
371 | } possible_net_t; | |
8f424b5f | 372 | |
0c5c9fb5 | 373 | static inline void write_pnet(possible_net_t *pnet, struct net *net) |
8f424b5f | 374 | { |
0c5c9fb5 | 375 | #ifdef CONFIG_NET_NS |
2034d90a | 376 | rcu_assign_pointer(pnet->net, net); |
0c5c9fb5 | 377 | #endif |
8f424b5f ED |
378 | } |
379 | ||
0c5c9fb5 | 380 | static inline struct net *read_pnet(const possible_net_t *pnet) |
8f424b5f | 381 | { |
0c5c9fb5 | 382 | #ifdef CONFIG_NET_NS |
2034d90a JP |
383 | return rcu_dereference_protected(pnet->net, true); |
384 | #else | |
385 | return &init_net; | |
386 | #endif | |
387 | } | |
388 | ||
389 | static inline struct net *read_pnet_rcu(possible_net_t *pnet) | |
390 | { | |
391 | #ifdef CONFIG_NET_NS | |
392 | return rcu_dereference(pnet->net); | |
8f424b5f | 393 | #else |
0c5c9fb5 | 394 | return &init_net; |
8f424b5f | 395 | #endif |
0c5c9fb5 | 396 | } |
5d1e4468 | 397 | |
f0b07bb1 | 398 | /* Protected by net_rwsem */ |
5f256bec EB |
399 | #define for_each_net(VAR) \ |
400 | list_for_each_entry(VAR, &net_namespace_list, list) | |
afa0df59 JP |
401 | #define for_each_net_continue_reverse(VAR) \ |
402 | list_for_each_entry_continue_reverse(VAR, &net_namespace_list, list) | |
11a28d37 JB |
403 | #define for_each_net_rcu(VAR) \ |
404 | list_for_each_entry_rcu(VAR, &net_namespace_list, list) | |
405 | ||
4665079c PE |
406 | #ifdef CONFIG_NET_NS |
407 | #define __net_init | |
408 | #define __net_exit | |
022cbae6 | 409 | #define __net_initdata |
04a6f82c | 410 | #define __net_initconst |
4665079c PE |
411 | #else |
412 | #define __net_init __init | |
bd721ea7 | 413 | #define __net_exit __ref |
022cbae6 | 414 | #define __net_initdata __initdata |
04a6f82c | 415 | #define __net_initconst __initconst |
4665079c | 416 | #endif |
5f256bec | 417 | |
d4e4fdf9 | 418 | int peernet2id_alloc(struct net *net, struct net *peer, gfp_t gfp); |
56f200c7 GN |
419 | int peernet2id(const struct net *net, struct net *peer); |
420 | bool peernet_has_id(const struct net *net, struct net *peer); | |
421 | struct net *get_net_ns_by_id(const struct net *net, int id); | |
0c7aecd4 | 422 | |
5f256bec EB |
423 | struct pernet_operations { |
424 | struct list_head list; | |
6056415d KT |
425 | /* |
426 | * Below methods are called without any exclusive locks. | |
427 | * More than one net may be constructed and destructed | |
428 | * in parallel on several cpus. Every pernet_operations | |
429 | * have to keep in mind all other pernet_operations and | |
430 | * to introduce a locking, if they share common resources. | |
431 | * | |
8518e9bb KT |
432 | * The only time they are called with exclusive lock is |
433 | * from register_pernet_subsys(), unregister_pernet_subsys() | |
434 | * register_pernet_device() and unregister_pernet_device(). | |
435 | * | |
6056415d KT |
436 | * Exit methods using blocking RCU primitives, such as |
437 | * synchronize_rcu(), should be implemented via exit_batch. | |
438 | * Then, destruction of a group of net requires single | |
439 | * synchronize_rcu() related to these pernet_operations, | |
440 | * instead of separate synchronize_rcu() for every net. | |
441 | * Please, avoid synchronize_rcu() at all, where it's possible. | |
d7d99872 ED |
442 | * |
443 | * Note that a combination of pre_exit() and exit() can | |
444 | * be used, since a synchronize_rcu() is guaranteed between | |
445 | * the calls. | |
6056415d | 446 | */ |
5f256bec | 447 | int (*init)(struct net *net); |
d7d99872 | 448 | void (*pre_exit)(struct net *net); |
5f256bec | 449 | void (*exit)(struct net *net); |
72ad937a | 450 | void (*exit_batch)(struct list_head *net_exit_list); |
fd4f101e ED |
451 | /* Following method is called with RTNL held. */ |
452 | void (*exit_batch_rtnl)(struct list_head *net_exit_list, | |
453 | struct list_head *dev_kill_list); | |
768e4bb6 KI |
454 | unsigned int * const id; |
455 | const size_t size; | |
5f256bec EB |
456 | }; |
457 | ||
17edde52 EB |
458 | /* |
459 | * Use these carefully. If you implement a network device and it | |
460 | * needs per network namespace operations use device pernet operations, | |
461 | * otherwise use pernet subsys operations. | |
462 | * | |
4edf547b JB |
463 | * Network interfaces need to be removed from a dying netns _before_ |
464 | * subsys notifiers can be called, as most of the network code cleanup | |
465 | * (which is done from subsys notifiers) runs with the assumption that | |
466 | * dev_remove_pack has been called so no new packets will arrive during | |
467 | * and after the cleanup functions have been called. dev_remove_pack | |
468 | * is not per namespace so instead the guarantee of no more packets | |
469 | * arriving in a network namespace is provided by ensuring that all | |
470 | * network devices and all sockets have left the network namespace | |
471 | * before the cleanup methods are called. | |
17edde52 EB |
472 | * |
473 | * For the longest time the ipv4 icmp code was registered as a pernet | |
474 | * device which caused kernel oops, and panics during network | |
475 | * namespace cleanup. So please don't get this wrong. | |
476 | */ | |
e67e16ea JP |
477 | int register_pernet_subsys(struct pernet_operations *); |
478 | void unregister_pernet_subsys(struct pernet_operations *); | |
479 | int register_pernet_device(struct pernet_operations *); | |
480 | void unregister_pernet_device(struct pernet_operations *); | |
f875bae0 | 481 | |
95bdfccb | 482 | struct ctl_table; |
d62c612e | 483 | |
95d49778 | 484 | #define register_net_sysctl(net, path, table) \ |
e1b41e4f | 485 | register_net_sysctl_sz(net, path, table, ARRAY_SIZE(table)) |
2ca794e5 | 486 | #ifdef CONFIG_SYSCTL |
e67e16ea | 487 | int net_sysctl_init(void); |
95d49778 JG |
488 | struct ctl_table_header *register_net_sysctl_sz(struct net *net, const char *path, |
489 | struct ctl_table *table, size_t table_size); | |
e67e16ea | 490 | void unregister_net_sysctl_table(struct ctl_table_header *header); |
48c74958 EB |
491 | #else |
492 | static inline int net_sysctl_init(void) { return 0; } | |
95d49778 JG |
493 | static inline struct ctl_table_header *register_net_sysctl_sz(struct net *net, |
494 | const char *path, struct ctl_table *table, size_t table_size) | |
48c74958 EB |
495 | { |
496 | return NULL; | |
497 | } | |
498 | static inline void unregister_net_sysctl_table(struct ctl_table_header *header) | |
499 | { | |
500 | } | |
501 | #endif | |
502 | ||
56f200c7 | 503 | static inline int rt_genid_ipv4(const struct net *net) |
b42664f8 | 504 | { |
ca4c3fc2 | 505 | return atomic_read(&net->ipv4.rt_genid); |
b42664f8 ND |
506 | } |
507 | ||
8f34e53b DA |
508 | #if IS_ENABLED(CONFIG_IPV6) |
509 | static inline int rt_genid_ipv6(const struct net *net) | |
510 | { | |
511 | return atomic_read(&net->ipv6.fib6_sernum); | |
512 | } | |
513 | #endif | |
514 | ||
ca4c3fc2 | 515 | static inline void rt_genid_bump_ipv4(struct net *net) |
b42664f8 | 516 | { |
ca4c3fc2 | 517 | atomic_inc(&net->ipv4.rt_genid); |
518 | } | |
519 | ||
705f1c86 | 520 | extern void (*__fib6_flush_trees)(struct net *net); |
ca4c3fc2 | 521 | static inline void rt_genid_bump_ipv6(struct net *net) |
522 | { | |
705f1c86 HFS |
523 | if (__fib6_flush_trees) |
524 | __fib6_flush_trees(net); | |
ca4c3fc2 | 525 | } |
ca4c3fc2 | 526 | |
599018a7 LR |
527 | #if IS_ENABLED(CONFIG_IEEE802154_6LOWPAN) |
528 | static inline struct netns_ieee802154_lowpan * | |
529 | net_ieee802154_lowpan(struct net *net) | |
530 | { | |
531 | return &net->ieee802154_lowpan; | |
532 | } | |
599018a7 LR |
533 | #endif |
534 | ||
ca4c3fc2 | 535 | /* For callers who don't really care about whether it's IPv4 or IPv6 */ |
536 | static inline void rt_genid_bump_all(struct net *net) | |
537 | { | |
538 | rt_genid_bump_ipv4(net); | |
539 | rt_genid_bump_ipv6(net); | |
b42664f8 | 540 | } |
95bdfccb | 541 | |
56f200c7 | 542 | static inline int fnhe_genid(const struct net *net) |
5aad1de5 TT |
543 | { |
544 | return atomic_read(&net->fnhe_genid); | |
545 | } | |
546 | ||
547 | static inline void fnhe_genid_bump(struct net *net) | |
548 | { | |
549 | atomic_inc(&net->fnhe_genid); | |
550 | } | |
551 | ||
9c1be193 ED |
552 | #ifdef CONFIG_NET |
553 | void net_ns_init(void); | |
554 | #else | |
555 | static inline void net_ns_init(void) {} | |
556 | #endif | |
557 | ||
5f256bec | 558 | #endif /* __NET_NET_NAMESPACE_H */ |