1 /* SPDX-License-Identifier: GPL-2.0 */ 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 2 /* 3 * Operations on the network namespace 3 * Operations on the network namespace 4 */ 4 */ 5 #ifndef __NET_NET_NAMESPACE_H 5 #ifndef __NET_NET_NAMESPACE_H 6 #define __NET_NET_NAMESPACE_H 6 #define __NET_NET_NAMESPACE_H 7 7 8 #include <linux/atomic.h> 8 #include <linux/atomic.h> 9 #include <linux/refcount.h> 9 #include <linux/refcount.h> 10 #include <linux/workqueue.h> 10 #include <linux/workqueue.h> 11 #include <linux/list.h> 11 #include <linux/list.h> 12 #include <linux/sysctl.h> 12 #include <linux/sysctl.h> 13 #include <linux/uidgid.h> << 14 13 15 #include <net/flow.h> 14 #include <net/flow.h> 16 #include <net/netns/core.h> 15 #include <net/netns/core.h> 17 #include <net/netns/mib.h> 16 #include <net/netns/mib.h> 18 #include <net/netns/unix.h> 17 #include <net/netns/unix.h> 19 #include <net/netns/packet.h> 18 #include <net/netns/packet.h> 20 #include <net/netns/ipv4.h> 19 #include <net/netns/ipv4.h> 21 #include <net/netns/ipv6.h> 20 #include <net/netns/ipv6.h> 22 #include <net/netns/nexthop.h> << 23 #include <net/netns/ieee802154_6lowpan.h> 21 #include <net/netns/ieee802154_6lowpan.h> 24 #include <net/netns/sctp.h> 22 #include <net/netns/sctp.h> >> 23 #include <net/netns/dccp.h> 25 #include <net/netns/netfilter.h> 24 #include <net/netns/netfilter.h> >> 25 #include <net/netns/x_tables.h> 26 #if defined(CONFIG_NF_CONNTRACK) || defined(CO 26 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) 27 #include <net/netns/conntrack.h> 27 #include <net/netns/conntrack.h> 28 #endif 28 #endif 29 #if IS_ENABLED(CONFIG_NF_FLOW_TABLE) << 30 #include <net/netns/flow_table.h> << 31 #endif << 32 #include <net/netns/nftables.h> 29 #include <net/netns/nftables.h> 33 #include <net/netns/xfrm.h> 30 #include <net/netns/xfrm.h> 34 #include <net/netns/mpls.h> 31 #include <net/netns/mpls.h> 35 #include <net/netns/can.h> 32 #include <net/netns/can.h> 36 #include <net/netns/xdp.h> << 37 #include <net/netns/smc.h> << 38 #include <net/netns/bpf.h> << 39 #include <net/netns/mctp.h> << 40 #include <net/net_trackers.h> << 41 #include <linux/ns_common.h> 33 #include <linux/ns_common.h> 42 #include <linux/idr.h> 34 #include <linux/idr.h> 43 #include <linux/skbuff.h> 35 #include <linux/skbuff.h> 44 #include <linux/notifier.h> << 45 #include <linux/xarray.h> << 46 36 47 struct user_namespace; 37 struct user_namespace; 48 struct proc_dir_entry; 38 struct proc_dir_entry; 49 struct net_device; 39 struct net_device; 50 struct sock; 40 struct sock; 51 struct ctl_table_header; 41 struct ctl_table_header; 52 struct net_generic; 42 struct net_generic; 53 struct uevent_sock; !! 43 struct sock; 54 struct netns_ipvs; 44 struct netns_ipvs; 55 struct bpf_prog; << 56 45 57 46 58 #define NETDEV_HASHBITS 8 47 #define NETDEV_HASHBITS 8 59 #define NETDEV_HASHENTRIES (1 << NETDEV_HASHBI 48 #define NETDEV_HASHENTRIES (1 << NETDEV_HASHBITS) 60 49 61 struct net { 50 struct net { 62 /* First cache line can be often dirti !! 51 refcount_t passive; /* To decided when the network 63 * Do not place here read-mostly field << 64 */ << 65 refcount_t passive; << 66 52 * namespace should be freed. 67 53 */ >> 54 atomic_t count; /* To decided when the network >> 55 * namespace should be shut down. >> 56 */ 68 spinlock_t rules_mod_lock 57 spinlock_t rules_mod_lock; 69 58 70 unsigned int dev_base_seq; !! 59 u32 hash_mix; 71 u32 ifindex; !! 60 atomic64_t cookie_gen; 72 << 73 spinlock_t nsid_lock; << 74 atomic_t fnhe_genid; << 75 61 76 struct list_head list; 62 struct list_head list; /* list of network namespaces */ 77 struct list_head exit_list; !! 63 struct list_head cleanup_list; /* namespaces on death row */ 78 !! 64 struct list_head exit_list; /* Use only net_mutex */ 79 << 80 << 81 << 82 << 83 struct llist_node cleanup_list; << 84 65 85 #ifdef CONFIG_KEYS << 86 struct key_tag *key_domain; << 87 #endif << 88 struct user_namespace *user_ns; 66 struct user_namespace *user_ns; /* Owning user namespace */ 89 struct ucounts *ucounts; 67 struct ucounts *ucounts; >> 68 spinlock_t nsid_lock; 90 struct idr netns_ids; 69 struct idr netns_ids; 91 70 92 struct ns_common ns; 71 struct ns_common ns; 93 struct ref_tracker_dir refcnt_tracker !! 72 94 struct ref_tracker_dir notrefcnt_trac << 95 << 96 << 97 struct list_head dev_base_head; << 98 struct proc_dir_entry *proc_net; 73 struct proc_dir_entry *proc_net; 99 struct proc_dir_entry *proc_net_stat 74 struct proc_dir_entry *proc_net_stat; 100 75 101 #ifdef CONFIG_SYSCTL 76 #ifdef CONFIG_SYSCTL 102 struct ctl_table_set sysctls; 77 struct ctl_table_set sysctls; 103 #endif 78 #endif 104 79 105 struct sock *rtnl; 80 struct sock *rtnl; /* rtnetlink socket */ 106 struct sock *genl_sock; 81 struct sock *genl_sock; 107 82 108 struct uevent_sock *uevent_sock; !! 83 struct list_head dev_base_head; 109 << 110 struct hlist_head *dev_name_head 84 struct hlist_head *dev_name_head; 111 struct hlist_head *dev_index_hea 85 struct hlist_head *dev_index_head; 112 struct xarray dev_by_index; !! 86 unsigned int dev_base_seq; /* protected by rtnl_mutex */ 113 struct raw_notifier_head netdev !! 87 int ifindex; 114 !! 88 unsigned int dev_unreg_count; 115 /* Note that @hash_mix can be read mil << 116 * it is critical that it is on a read << 117 */ << 118 u32 hash_mix; << 119 << 120 struct net_device *loopback_dev; << 121 89 122 /* core fib_rules */ 90 /* core fib_rules */ 123 struct list_head rules_ops; 91 struct list_head rules_ops; 124 92 >> 93 struct list_head fib_notifier_ops; /* protected by net_mutex */ >> 94 >> 95 struct net_device *loopback_dev; /* The loopback */ 125 struct netns_core core; 96 struct netns_core core; 126 struct netns_mib mib; 97 struct netns_mib mib; 127 struct netns_packet packet; 98 struct netns_packet packet; 128 #if IS_ENABLED(CONFIG_UNIX) << 129 struct netns_unix unx; 99 struct netns_unix unx; 130 #endif << 131 struct netns_nexthop nexthop; << 132 struct netns_ipv4 ipv4; 100 struct netns_ipv4 ipv4; 133 #if IS_ENABLED(CONFIG_IPV6) 101 #if IS_ENABLED(CONFIG_IPV6) 134 struct netns_ipv6 ipv6; 102 struct netns_ipv6 ipv6; 135 #endif 103 #endif 136 #if IS_ENABLED(CONFIG_IEEE802154_6LOWPAN) 104 #if IS_ENABLED(CONFIG_IEEE802154_6LOWPAN) 137 struct netns_ieee802154_lowpan ieee80 105 struct netns_ieee802154_lowpan ieee802154_lowpan; 138 #endif 106 #endif 139 #if defined(CONFIG_IP_SCTP) || defined(CONFIG_ 107 #if defined(CONFIG_IP_SCTP) || defined(CONFIG_IP_SCTP_MODULE) 140 struct netns_sctp sctp; 108 struct netns_sctp sctp; 141 #endif 109 #endif >> 110 #if defined(CONFIG_IP_DCCP) || defined(CONFIG_IP_DCCP_MODULE) >> 111 struct netns_dccp dccp; >> 112 #endif 142 #ifdef CONFIG_NETFILTER 113 #ifdef CONFIG_NETFILTER 143 struct netns_nf nf; 114 struct netns_nf nf; >> 115 struct netns_xt xt; 144 #if defined(CONFIG_NF_CONNTRACK) || defined(CO 116 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) 145 struct netns_ct ct; 117 struct netns_ct ct; 146 #endif 118 #endif 147 #if defined(CONFIG_NF_TABLES) || defined(CONFI 119 #if defined(CONFIG_NF_TABLES) || defined(CONFIG_NF_TABLES_MODULE) 148 struct netns_nftables nft; 120 struct netns_nftables nft; 149 #endif 121 #endif 150 #if IS_ENABLED(CONFIG_NF_FLOW_TABLE) !! 122 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6) 151 struct netns_ft ft; !! 123 struct netns_nf_frag nf_frag; >> 124 struct ctl_table_header *nf_frag_frags_hdr; >> 125 #endif >> 126 struct sock *nfnl; >> 127 struct sock *nfnl_stash; >> 128 #if IS_ENABLED(CONFIG_NETFILTER_NETLINK_ACCT) >> 129 struct list_head nfnl_acct_list; >> 130 #endif >> 131 #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) >> 132 struct list_head nfct_timeout_list; 152 #endif 133 #endif 153 #endif 134 #endif 154 #ifdef CONFIG_WEXT_CORE 135 #ifdef CONFIG_WEXT_CORE 155 struct sk_buff_head wext_nlevents; 136 struct sk_buff_head wext_nlevents; 156 #endif 137 #endif 157 struct net_generic __rcu *gen; 138 struct net_generic __rcu *gen; 158 139 159 /* Used to store attached BPF programs << 160 struct netns_bpf bpf; << 161 << 162 /* Note : following structs are cache 140 /* Note : following structs are cache line aligned */ 163 #ifdef CONFIG_XFRM 141 #ifdef CONFIG_XFRM 164 struct netns_xfrm xfrm; 142 struct netns_xfrm xfrm; 165 #endif 143 #endif 166 << 167 u64 net_cookie; /* << 168 << 169 #if IS_ENABLED(CONFIG_IP_VS) 144 #if IS_ENABLED(CONFIG_IP_VS) 170 struct netns_ipvs *ipvs; 145 struct netns_ipvs *ipvs; 171 #endif 146 #endif 172 #if IS_ENABLED(CONFIG_MPLS) 147 #if IS_ENABLED(CONFIG_MPLS) 173 struct netns_mpls mpls; 148 struct netns_mpls mpls; 174 #endif 149 #endif 175 #if IS_ENABLED(CONFIG_CAN) 150 #if IS_ENABLED(CONFIG_CAN) 176 struct netns_can can; 151 struct netns_can can; 177 #endif 152 #endif 178 #ifdef CONFIG_XDP_SOCKETS << 179 struct netns_xdp xdp; << 180 #endif << 181 #if IS_ENABLED(CONFIG_MCTP) << 182 struct netns_mctp mctp; << 183 #endif << 184 #if IS_ENABLED(CONFIG_CRYPTO_USER) << 185 struct sock *crypto_nlsk; << 186 #endif << 187 struct sock *diag_nlsk; 153 struct sock *diag_nlsk; 188 #if IS_ENABLED(CONFIG_SMC) !! 154 atomic_t fnhe_genid; 189 struct netns_smc smc; << 190 #endif << 191 } __randomize_layout; 155 } __randomize_layout; 192 156 193 #include <linux/seq_file_net.h> 157 #include <linux/seq_file_net.h> 194 158 195 /* Init's network namespace */ 159 /* Init's network namespace */ 196 extern struct net init_net; 160 extern struct net init_net; 197 161 198 #ifdef CONFIG_NET_NS 162 #ifdef CONFIG_NET_NS 199 struct net *copy_net_ns(unsigned long flags, s 163 struct net *copy_net_ns(unsigned long flags, struct user_namespace *user_ns, 200 struct net *old_net); 164 struct net *old_net); 201 165 202 void net_ns_get_ownership(const struct net *ne << 203 << 204 void net_ns_barrier(void); 166 void net_ns_barrier(void); 205 << 206 struct ns_common *get_net_ns(struct ns_common << 207 struct net *get_net_ns_by_fd(int fd); << 208 #else /* CONFIG_NET_NS */ 167 #else /* CONFIG_NET_NS */ 209 #include <linux/sched.h> 168 #include <linux/sched.h> 210 #include <linux/nsproxy.h> 169 #include <linux/nsproxy.h> 211 static inline struct net *copy_net_ns(unsigned 170 static inline struct net *copy_net_ns(unsigned long flags, 212 struct user_namespace *user_ns, struct 171 struct user_namespace *user_ns, struct net *old_net) 213 { 172 { 214 if (flags & CLONE_NEWNET) 173 if (flags & CLONE_NEWNET) 215 return ERR_PTR(-EINVAL); 174 return ERR_PTR(-EINVAL); 216 return old_net; 175 return old_net; 217 } 176 } 218 177 219 static inline void net_ns_get_ownership(const << 220 kuid_t << 221 { << 222 *uid = GLOBAL_ROOT_UID; << 223 *gid = GLOBAL_ROOT_GID; << 224 } << 225 << 226 static inline void net_ns_barrier(void) {} 178 static inline void net_ns_barrier(void) {} 227 << 228 static inline struct ns_common *get_net_ns(str << 229 { << 230 return ERR_PTR(-EINVAL); << 231 } << 232 << 233 static inline struct net *get_net_ns_by_fd(int << 234 { << 235 return ERR_PTR(-EINVAL); << 236 } << 237 #endif /* CONFIG_NET_NS */ 179 #endif /* CONFIG_NET_NS */ 238 180 239 181 240 extern struct list_head net_namespace_list; 182 extern struct list_head net_namespace_list; 241 183 242 struct net *get_net_ns_by_pid(pid_t pid); 184 struct net *get_net_ns_by_pid(pid_t pid); >> 185 struct net *get_net_ns_by_fd(int fd); 243 186 244 #ifdef CONFIG_SYSCTL 187 #ifdef CONFIG_SYSCTL 245 void ipx_register_sysctl(void); 188 void ipx_register_sysctl(void); 246 void ipx_unregister_sysctl(void); 189 void ipx_unregister_sysctl(void); 247 #else 190 #else 248 #define ipx_register_sysctl() 191 #define ipx_register_sysctl() 249 #define ipx_unregister_sysctl() 192 #define ipx_unregister_sysctl() 250 #endif 193 #endif 251 194 252 #ifdef CONFIG_NET_NS 195 #ifdef CONFIG_NET_NS 253 void __put_net(struct net *net); 196 void __put_net(struct net *net); 254 197 255 /* Try using get_net_track() instead */ << 256 static inline struct net *get_net(struct net * 198 static inline struct net *get_net(struct net *net) 257 { 199 { 258 refcount_inc(&net->ns.count); !! 200 atomic_inc(&net->count); 259 return net; 201 return net; 260 } 202 } 261 203 262 static inline struct net *maybe_get_net(struct 204 static inline struct net *maybe_get_net(struct net *net) 263 { 205 { 264 /* Used when we know struct net exists 206 /* Used when we know struct net exists but we 265 * aren't guaranteed a previous refere 207 * aren't guaranteed a previous reference count 266 * exists. If the reference count is 208 * exists. If the reference count is zero this 267 * function fails and returns NULL. 209 * function fails and returns NULL. 268 */ 210 */ 269 if (!refcount_inc_not_zero(&net->ns.co !! 211 if (!atomic_inc_not_zero(&net->count)) 270 net = NULL; 212 net = NULL; 271 return net; 213 return net; 272 } 214 } 273 215 274 /* Try using put_net_track() instead */ << 275 static inline void put_net(struct net *net) 216 static inline void put_net(struct net *net) 276 { 217 { 277 if (refcount_dec_and_test(&net->ns.cou !! 218 if (atomic_dec_and_test(&net->count)) 278 __put_net(net); 219 __put_net(net); 279 } 220 } 280 221 281 static inline 222 static inline 282 int net_eq(const struct net *net1, const struc 223 int net_eq(const struct net *net1, const struct net *net2) 283 { 224 { 284 return net1 == net2; 225 return net1 == net2; 285 } 226 } 286 227 287 static inline int check_net(const struct net * 228 static inline int check_net(const struct net *net) 288 { 229 { 289 return refcount_read(&net->ns.count) ! !! 230 return atomic_read(&net->count) != 0; 290 } 231 } 291 232 292 void net_drop_ns(void *); 233 void net_drop_ns(void *); 293 234 294 #else 235 #else 295 236 296 static inline struct net *get_net(struct net * 237 static inline struct net *get_net(struct net *net) 297 { 238 { 298 return net; 239 return net; 299 } 240 } 300 241 301 static inline void put_net(struct net *net) 242 static inline void put_net(struct net *net) 302 { 243 { 303 } 244 } 304 245 305 static inline struct net *maybe_get_net(struct 246 static inline struct net *maybe_get_net(struct net *net) 306 { 247 { 307 return net; 248 return net; 308 } 249 } 309 250 310 static inline 251 static inline 311 int net_eq(const struct net *net1, const struc 252 int net_eq(const struct net *net1, const struct net *net2) 312 { 253 { 313 return 1; 254 return 1; 314 } 255 } 315 256 316 static inline int check_net(const struct net * 257 static inline int check_net(const struct net *net) 317 { 258 { 318 return 1; 259 return 1; 319 } 260 } 320 261 321 #define net_drop_ns NULL 262 #define net_drop_ns NULL 322 #endif 263 #endif 323 264 324 265 325 static inline void __netns_tracker_alloc(struc << 326 netns << 327 bool << 328 gfp_t << 329 { << 330 #ifdef CONFIG_NET_NS_REFCNT_TRACKER << 331 ref_tracker_alloc(refcounted ? &net->r << 332 &net->n << 333 tracker, gfp); << 334 #endif << 335 } << 336 << 337 static inline void netns_tracker_alloc(struct << 338 gfp_t g << 339 { << 340 __netns_tracker_alloc(net, tracker, tr << 341 } << 342 << 343 static inline void __netns_tracker_free(struct << 344 netns_ << 345 bool r << 346 { << 347 #ifdef CONFIG_NET_NS_REFCNT_TRACKER << 348 ref_tracker_free(refcounted ? &net->ref << 349 &net->not << 350 #endif << 351 } << 352 << 353 static inline struct net *get_net_track(struct << 354 netns_ << 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 *n << 362 { << 363 __netns_tracker_free(net, tracker, tru << 364 put_net(net); << 365 } << 366 << 367 typedef struct { 266 typedef struct { 368 #ifdef CONFIG_NET_NS 267 #ifdef CONFIG_NET_NS 369 struct net __rcu *net; !! 268 struct net *net; 370 #endif 269 #endif 371 } possible_net_t; 270 } possible_net_t; 372 271 373 static inline void write_pnet(possible_net_t * 272 static inline void write_pnet(possible_net_t *pnet, struct net *net) 374 { 273 { 375 #ifdef CONFIG_NET_NS 274 #ifdef CONFIG_NET_NS 376 rcu_assign_pointer(pnet->net, net); !! 275 pnet->net = net; 377 #endif 276 #endif 378 } 277 } 379 278 380 static inline struct net *read_pnet(const poss 279 static inline struct net *read_pnet(const possible_net_t *pnet) 381 { 280 { 382 #ifdef CONFIG_NET_NS 281 #ifdef CONFIG_NET_NS 383 return rcu_dereference_protected(pnet- !! 282 return pnet->net; 384 #else 283 #else 385 return &init_net; 284 return &init_net; 386 #endif 285 #endif 387 } 286 } 388 287 389 static inline struct net *read_pnet_rcu(possib << 390 { << 391 #ifdef CONFIG_NET_NS << 392 return rcu_dereference(pnet->net); << 393 #else << 394 return &init_net; << 395 #endif << 396 } << 397 << 398 /* Protected by net_rwsem */ << 399 #define for_each_net(VAR) 288 #define for_each_net(VAR) \ 400 list_for_each_entry(VAR, &net_namespac 289 list_for_each_entry(VAR, &net_namespace_list, list) 401 #define for_each_net_continue_reverse(VAR) !! 290 402 list_for_each_entry_continue_reverse(V << 403 #define for_each_net_rcu(VAR) 291 #define for_each_net_rcu(VAR) \ 404 list_for_each_entry_rcu(VAR, &net_name 292 list_for_each_entry_rcu(VAR, &net_namespace_list, list) 405 293 406 #ifdef CONFIG_NET_NS 294 #ifdef CONFIG_NET_NS 407 #define __net_init 295 #define __net_init 408 #define __net_exit 296 #define __net_exit 409 #define __net_initdata 297 #define __net_initdata 410 #define __net_initconst 298 #define __net_initconst 411 #else 299 #else 412 #define __net_init __init 300 #define __net_init __init 413 #define __net_exit __ref 301 #define __net_exit __ref 414 #define __net_initdata __initdata 302 #define __net_initdata __initdata 415 #define __net_initconst __initconst 303 #define __net_initconst __initconst 416 #endif 304 #endif 417 305 418 int peernet2id_alloc(struct net *net, struct n !! 306 int peernet2id_alloc(struct net *net, struct net *peer); 419 int peernet2id(const struct net *net, struct n !! 307 int peernet2id(struct net *net, struct net *peer); 420 bool peernet_has_id(const struct net *net, str !! 308 bool peernet_has_id(struct net *net, struct net *peer); 421 struct net *get_net_ns_by_id(const struct net !! 309 struct net *get_net_ns_by_id(struct net *net, int id); 422 310 423 struct pernet_operations { 311 struct pernet_operations { 424 struct list_head list; 312 struct list_head list; 425 /* << 426 * Below methods are called without an << 427 * More than one net may be constructe << 428 * in parallel on several cpus. Every << 429 * have to keep in mind all other pern << 430 * to introduce a locking, if they sha << 431 * << 432 * The only time they are called with << 433 * from register_pernet_subsys(), unre << 434 * register_pernet_device() and unregi << 435 * << 436 * Exit methods using blocking RCU pri << 437 * synchronize_rcu(), should be implem << 438 * Then, destruction of a group of net << 439 * synchronize_rcu() related to these << 440 * instead of separate synchronize_rcu << 441 * Please, avoid synchronize_rcu() at << 442 * << 443 * Note that a combination of pre_exit << 444 * be used, since a synchronize_rcu() << 445 * the calls. << 446 */ << 447 int (*init)(struct net *net); 313 int (*init)(struct net *net); 448 void (*pre_exit)(struct net *net); << 449 void (*exit)(struct net *net); 314 void (*exit)(struct net *net); 450 void (*exit_batch)(struct list_head *n 315 void (*exit_batch)(struct list_head *net_exit_list); 451 /* Following method is called with RTN !! 316 unsigned int *id; 452 void (*exit_batch_rtnl)(struct list_he !! 317 size_t size; 453 struct list_he << 454 unsigned int * const id; << 455 const size_t size; << 456 }; 318 }; 457 319 458 /* 320 /* 459 * Use these carefully. If you implement a ne 321 * Use these carefully. If you implement a network device and it 460 * needs per network namespace operations use 322 * needs per network namespace operations use device pernet operations, 461 * otherwise use pernet subsys operations. 323 * otherwise use pernet subsys operations. 462 * 324 * 463 * Network interfaces need to be removed from 325 * Network interfaces need to be removed from a dying netns _before_ 464 * subsys notifiers can be called, as most of 326 * subsys notifiers can be called, as most of the network code cleanup 465 * (which is done from subsys notifiers) runs 327 * (which is done from subsys notifiers) runs with the assumption that 466 * dev_remove_pack has been called so no new p 328 * dev_remove_pack has been called so no new packets will arrive during 467 * and after the cleanup functions have been c 329 * and after the cleanup functions have been called. dev_remove_pack 468 * is not per namespace so instead the guarant 330 * is not per namespace so instead the guarantee of no more packets 469 * arriving in a network namespace is provided 331 * arriving in a network namespace is provided by ensuring that all 470 * network devices and all sockets have left t 332 * network devices and all sockets have left the network namespace 471 * before the cleanup methods are called. 333 * before the cleanup methods are called. 472 * 334 * 473 * For the longest time the ipv4 icmp code was 335 * For the longest time the ipv4 icmp code was registered as a pernet 474 * device which caused kernel oops, and panics 336 * device which caused kernel oops, and panics during network 475 * namespace cleanup. So please don't get th 337 * namespace cleanup. So please don't get this wrong. 476 */ 338 */ 477 int register_pernet_subsys(struct pernet_opera 339 int register_pernet_subsys(struct pernet_operations *); 478 void unregister_pernet_subsys(struct pernet_op 340 void unregister_pernet_subsys(struct pernet_operations *); 479 int register_pernet_device(struct pernet_opera 341 int register_pernet_device(struct pernet_operations *); 480 void unregister_pernet_device(struct pernet_op 342 void unregister_pernet_device(struct pernet_operations *); 481 343 482 struct ctl_table; 344 struct ctl_table; >> 345 struct ctl_table_header; 483 346 484 #define register_net_sysctl(net, path, table) << 485 register_net_sysctl_sz(net, path, tabl << 486 #ifdef CONFIG_SYSCTL 347 #ifdef CONFIG_SYSCTL 487 int net_sysctl_init(void); 348 int net_sysctl_init(void); 488 struct ctl_table_header *register_net_sysctl_s !! 349 struct ctl_table_header *register_net_sysctl(struct net *net, const char *path, 489 s !! 350 struct ctl_table *table); 490 void unregister_net_sysctl_table(struct ctl_ta 351 void unregister_net_sysctl_table(struct ctl_table_header *header); 491 #else 352 #else 492 static inline int net_sysctl_init(void) { retu 353 static inline int net_sysctl_init(void) { return 0; } 493 static inline struct ctl_table_header *registe !! 354 static inline struct ctl_table_header *register_net_sysctl(struct net *net, 494 const char *path, struct ctl_table *ta !! 355 const char *path, struct ctl_table *table) 495 { 356 { 496 return NULL; 357 return NULL; 497 } 358 } 498 static inline void unregister_net_sysctl_table 359 static inline void unregister_net_sysctl_table(struct ctl_table_header *header) 499 { 360 { 500 } 361 } 501 #endif 362 #endif 502 363 503 static inline int rt_genid_ipv4(const struct n !! 364 static inline int rt_genid_ipv4(struct net *net) 504 { 365 { 505 return atomic_read(&net->ipv4.rt_genid 366 return atomic_read(&net->ipv4.rt_genid); 506 } 367 } 507 368 508 #if IS_ENABLED(CONFIG_IPV6) << 509 static inline int rt_genid_ipv6(const struct n << 510 { << 511 return atomic_read(&net->ipv6.fib6_ser << 512 } << 513 #endif << 514 << 515 static inline void rt_genid_bump_ipv4(struct n 369 static inline void rt_genid_bump_ipv4(struct net *net) 516 { 370 { 517 atomic_inc(&net->ipv4.rt_genid); 371 atomic_inc(&net->ipv4.rt_genid); 518 } 372 } 519 373 520 extern void (*__fib6_flush_trees)(struct net * 374 extern void (*__fib6_flush_trees)(struct net *net); 521 static inline void rt_genid_bump_ipv6(struct n 375 static inline void rt_genid_bump_ipv6(struct net *net) 522 { 376 { 523 if (__fib6_flush_trees) 377 if (__fib6_flush_trees) 524 __fib6_flush_trees(net); 378 __fib6_flush_trees(net); 525 } 379 } 526 380 527 #if IS_ENABLED(CONFIG_IEEE802154_6LOWPAN) 381 #if IS_ENABLED(CONFIG_IEEE802154_6LOWPAN) 528 static inline struct netns_ieee802154_lowpan * 382 static inline struct netns_ieee802154_lowpan * 529 net_ieee802154_lowpan(struct net *net) 383 net_ieee802154_lowpan(struct net *net) 530 { 384 { 531 return &net->ieee802154_lowpan; 385 return &net->ieee802154_lowpan; 532 } 386 } 533 #endif 387 #endif 534 388 535 /* For callers who don't really care about whe 389 /* For callers who don't really care about whether it's IPv4 or IPv6 */ 536 static inline void rt_genid_bump_all(struct ne 390 static inline void rt_genid_bump_all(struct net *net) 537 { 391 { 538 rt_genid_bump_ipv4(net); 392 rt_genid_bump_ipv4(net); 539 rt_genid_bump_ipv6(net); 393 rt_genid_bump_ipv6(net); 540 } 394 } 541 395 542 static inline int fnhe_genid(const struct net !! 396 static inline int fnhe_genid(struct net *net) 543 { 397 { 544 return atomic_read(&net->fnhe_genid); 398 return atomic_read(&net->fnhe_genid); 545 } 399 } 546 400 547 static inline void fnhe_genid_bump(struct net 401 static inline void fnhe_genid_bump(struct net *net) 548 { 402 { 549 atomic_inc(&net->fnhe_genid); 403 atomic_inc(&net->fnhe_genid); 550 } 404 } 551 << 552 #ifdef CONFIG_NET << 553 void net_ns_init(void); << 554 #else << 555 static inline void net_ns_init(void) {} << 556 #endif << 557 405 558 #endif /* __NET_NET_NAMESPACE_H */ 406 #endif /* __NET_NET_NAMESPACE_H */ 559 407
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.