1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 25f256becSEric W. Biederman /* 35f256becSEric W. Biederman * Operations on the network namespace 45f256becSEric W. Biederman */ 55f256becSEric W. Biederman #ifndef __NET_NET_NAMESPACE_H 65f256becSEric W. Biederman #define __NET_NET_NAMESPACE_H 75f256becSEric W. Biederman 860063497SArun Sharma #include <linux/atomic.h> 9c122e14dSReshetova, Elena #include <linux/refcount.h> 105f256becSEric W. Biederman #include <linux/workqueue.h> 115f256becSEric W. Biederman #include <linux/list.h> 12bee95250SDavid S. Miller #include <linux/sysctl.h> 13fbdeaed4STyler Hicks #include <linux/uidgid.h> 145f256becSEric W. Biederman 156a662719SCong Wang #include <net/flow.h> 168efa6e93SPavel Emelyanov #include <net/netns/core.h> 17852566f5SPavel Emelyanov #include <net/netns/mib.h> 18a0a53c8bSDenis V. Lunev #include <net/netns/unix.h> 192aaef4e4SDenis V. Lunev #include <net/netns/packet.h> 208afd351cSPavel Emelyanov #include <net/netns/ipv4.h> 21b0f159dbSDaniel Lezcano #include <net/netns/ipv6.h> 22ab84be7eSDavid Ahern #include <net/netns/nexthop.h> 23633fc86fSAlexander Aring #include <net/netns/ieee802154_6lowpan.h> 244db67e80SEric W. Biederman #include <net/netns/sctp.h> 2567019cc9SPavel Emelyanov #include <net/netns/dccp.h> 26f3c1a44aSGao feng #include <net/netns/netfilter.h> 278d870052SAlexey Dobriyan #include <net/netns/x_tables.h> 28dfdb8d79SAlexey Dobriyan #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) 29dfdb8d79SAlexey Dobriyan #include <net/netns/conntrack.h> 30dfdb8d79SAlexey Dobriyan #endif 3199633ab2SPablo Neira Ayuso #include <net/netns/nftables.h> 32d62ddc21SAlexey Dobriyan #include <net/netns/xfrm.h> 330189197fSEric W. Biederman #include <net/netns/mpls.h> 348e8cda6dSMario Kicherer #include <net/netns/can.h> 351d0dc069SBjörn Töpel #include <net/netns/xdp.h> 36435d5f4bSAl Viro #include <linux/ns_common.h> 3704c52decSPablo Neira Ayuso #include <linux/idr.h> 3804c52decSPablo Neira Ayuso #include <linux/skbuff.h> 39a0a53c8bSDenis V. Lunev 40038e7332SEric W. Biederman struct user_namespace; 41457c4cbcSEric W. Biederman struct proc_dir_entry; 422774c7abSEric W. Biederman struct net_device; 4397c53cacSDenis V. Lunev struct sock; 441597fbc0SPavel Emelyanov struct ctl_table_header; 45dec827d1SPavel Emelyanov struct net_generic; 4694e5e308SChristian Brauner struct uevent_sock; 472553d064SJulian Anastasov struct netns_ipvs; 48d58e468bSPetar Penkov struct bpf_prog; 491597fbc0SPavel Emelyanov 507c28bd0bSEric Dumazet 517c28bd0bSEric Dumazet #define NETDEV_HASHBITS 8 527c28bd0bSEric Dumazet #define NETDEV_HASHENTRIES (1 << NETDEV_HASHBITS) 537c28bd0bSEric Dumazet 545f256becSEric W. Biederman struct net { 55aad12c23SMike Rapoport refcount_t passive; /* To decide when the network 565f256becSEric W. Biederman * namespace should be freed. 575f256becSEric W. Biederman */ 58273c28bcSKirill Tkhai refcount_t count; /* To decided when the network 59a685e089SAl Viro * namespace should be shut down. 60a685e089SAl Viro */ 618e602ce2SEric Dumazet spinlock_t rules_mod_lock; 628e602ce2SEric Dumazet 63355b9855SEric Dumazet u32 hash_mix; 6433cf7c90SEric Dumazet 655f256becSEric W. Biederman struct list_head list; /* list of network namespaces */ 6619efbd93SKirill Tkhai struct list_head exit_list; /* To linked to call pernet exit 674420bf21SKirill Tkhai * methods on dead net ( 684420bf21SKirill Tkhai * pernet_ops_rwsem read locked), 694420bf21SKirill Tkhai * or to unregister pernet ops 704420bf21SKirill Tkhai * (pernet_ops_rwsem write locked). 7119efbd93SKirill Tkhai */ 7265b7b5b9SKirill Tkhai struct llist_node cleanup_list; /* namespaces on death row */ 7365b7b5b9SKirill Tkhai 749b242610SDavid Howells #ifdef CONFIG_KEYS 759b242610SDavid Howells struct key_tag *key_domain; /* Key domain of operation tag */ 769b242610SDavid Howells #endif 77038e7332SEric W. Biederman struct user_namespace *user_ns; /* Owning user namespace */ 7870328660SEric W. Biederman struct ucounts *ucounts; 79de133464SWANG Cong spinlock_t nsid_lock; 800c7aecd4SNicolas Dichtel struct idr netns_ids; 81038e7332SEric W. Biederman 82435d5f4bSAl Viro struct ns_common ns; 8398f842e6SEric W. Biederman 84457c4cbcSEric W. Biederman struct proc_dir_entry *proc_net; 85457c4cbcSEric W. Biederman struct proc_dir_entry *proc_net_stat; 86881d966bSEric W. Biederman 8773455092SAl Viro #ifdef CONFIG_SYSCTL 8873455092SAl Viro struct ctl_table_set sysctls; 8973455092SAl Viro #endif 9095bdfccbSEric W. Biederman 918e602ce2SEric Dumazet struct sock *rtnl; /* rtnetlink socket */ 928e602ce2SEric Dumazet struct sock *genl_sock; 932774c7abSEric W. Biederman 9494e5e308SChristian Brauner struct uevent_sock *uevent_sock; /* uevent socket */ 9594e5e308SChristian Brauner 96881d966bSEric W. Biederman struct list_head dev_base_head; 97881d966bSEric W. Biederman struct hlist_head *dev_name_head; 98881d966bSEric W. Biederman struct hlist_head *dev_index_head; 994e985adaSThomas Graf unsigned int dev_base_seq; /* protected by rtnl_mutex */ 100aa79e66eSPavel Emelyanov int ifindex; 10150624c93SEric W. Biederman unsigned int dev_unreg_count; 10297c53cacSDenis V. Lunev 1035fd30ee7SDenis V. Lunev /* core fib_rules */ 1045fd30ee7SDenis V. Lunev struct list_head rules_ops; 1055fd30ee7SDenis V. Lunev 1068e602ce2SEric Dumazet struct net_device *loopback_dev; /* The loopback */ 1078efa6e93SPavel Emelyanov struct netns_core core; 108852566f5SPavel Emelyanov struct netns_mib mib; 1092aaef4e4SDenis V. Lunev struct netns_packet packet; 110a0a53c8bSDenis V. Lunev struct netns_unix unx; 111ab84be7eSDavid Ahern struct netns_nexthop nexthop; 1128afd351cSPavel Emelyanov struct netns_ipv4 ipv4; 113dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6) 114b0f159dbSDaniel Lezcano struct netns_ipv6 ipv6; 115b0f159dbSDaniel Lezcano #endif 116633fc86fSAlexander Aring #if IS_ENABLED(CONFIG_IEEE802154_6LOWPAN) 117633fc86fSAlexander Aring struct netns_ieee802154_lowpan ieee802154_lowpan; 118633fc86fSAlexander Aring #endif 1194db67e80SEric W. Biederman #if defined(CONFIG_IP_SCTP) || defined(CONFIG_IP_SCTP_MODULE) 1204db67e80SEric W. Biederman struct netns_sctp sctp; 1214db67e80SEric W. Biederman #endif 12267019cc9SPavel Emelyanov #if defined(CONFIG_IP_DCCP) || defined(CONFIG_IP_DCCP_MODULE) 12367019cc9SPavel Emelyanov struct netns_dccp dccp; 12467019cc9SPavel Emelyanov #endif 1258d870052SAlexey Dobriyan #ifdef CONFIG_NETFILTER 126f3c1a44aSGao feng struct netns_nf nf; 1278d870052SAlexey Dobriyan struct netns_xt xt; 128dfdb8d79SAlexey Dobriyan #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) 129dfdb8d79SAlexey Dobriyan struct netns_ct ct; 130dfdb8d79SAlexey Dobriyan #endif 13199633ab2SPablo Neira Ayuso #if defined(CONFIG_NF_TABLES) || defined(CONFIG_NF_TABLES_MODULE) 13299633ab2SPablo Neira Ayuso struct netns_nftables nft; 13399633ab2SPablo Neira Ayuso #endif 134c038a767SAmerigo Wang #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6) 135c038a767SAmerigo Wang struct netns_nf_frag nf_frag; 1369ce7bc03SEric Dumazet struct ctl_table_header *nf_frag_frags_hdr; 137c038a767SAmerigo Wang #endif 138cd8c20b6SAlexey Dobriyan struct sock *nfnl; 139cd8c20b6SAlexey Dobriyan struct sock *nfnl_stash; 1403499abb2SAndreas Schultz #if IS_ENABLED(CONFIG_NETFILTER_NETLINK_ACCT) 1413499abb2SAndreas Schultz struct list_head nfnl_acct_list; 1423499abb2SAndreas Schultz #endif 14319576c94SPablo Neira #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) 14419576c94SPablo Neira struct list_head nfct_timeout_list; 14519576c94SPablo Neira #endif 1468d870052SAlexey Dobriyan #endif 1473d23e349SJohannes Berg #ifdef CONFIG_WEXT_CORE 148b333b3d2SJohannes Berg struct sk_buff_head wext_nlevents; 149b333b3d2SJohannes Berg #endif 1501c87733dSEric Dumazet struct net_generic __rcu *gen; 1518e602ce2SEric Dumazet 152d58e468bSPetar Penkov struct bpf_prog __rcu *flow_dissector_prog; 153d58e468bSPetar Penkov 1548e602ce2SEric Dumazet /* Note : following structs are cache line aligned */ 1558e602ce2SEric Dumazet #ifdef CONFIG_XFRM 1568e602ce2SEric Dumazet struct netns_xfrm xfrm; 1578e602ce2SEric Dumazet #endif 1588b4d14d8SJunweiZhang #if IS_ENABLED(CONFIG_IP_VS) 15961b1ab45SHans Schillstrom struct netns_ipvs *ipvs; 1608b4d14d8SJunweiZhang #endif 1610189197fSEric W. Biederman #if IS_ENABLED(CONFIG_MPLS) 1620189197fSEric W. Biederman struct netns_mpls mpls; 1630189197fSEric W. Biederman #endif 1648e8cda6dSMario Kicherer #if IS_ENABLED(CONFIG_CAN) 1658e8cda6dSMario Kicherer struct netns_can can; 1668e8cda6dSMario Kicherer #endif 1671d0dc069SBjörn Töpel #ifdef CONFIG_XDP_SOCKETS 1681d0dc069SBjörn Töpel struct netns_xdp xdp; 1691d0dc069SBjörn Töpel #endif 17091b05a7eSOndrej Mosnacek #if IS_ENABLED(CONFIG_CRYPTO_USER) 17191b05a7eSOndrej Mosnacek struct sock *crypto_nlsk; 17291b05a7eSOndrej Mosnacek #endif 17351d7cccfSAndrey Vagin struct sock *diag_nlsk; 1745aad1de5STimo Teräs atomic_t fnhe_genid; 1753859a271SKees Cook } __randomize_layout; 1765f256becSEric W. Biederman 177c0f39322SDenis V. Lunev #include <linux/seq_file_net.h> 178c0f39322SDenis V. Lunev 1794fabcd71SDaniel Lezcano /* Init's network namespace */ 1805f256becSEric W. Biederman extern struct net init_net; 181a4aa834aSDenis V. Lunev 182d727abcbSEric W. Biederman #ifdef CONFIG_NET_NS 183e67e16eaSJoe Perches struct net *copy_net_ns(unsigned long flags, struct user_namespace *user_ns, 184e67e16eaSJoe Perches struct net *old_net); 185225c0a01SDenis V. Lunev 186fbdeaed4STyler Hicks void net_ns_get_ownership(const struct net *net, kuid_t *uid, kgid_t *gid); 187fbdeaed4STyler Hicks 1887866cc57SFlorian Westphal void net_ns_barrier(void); 189d727abcbSEric W. Biederman #else /* CONFIG_NET_NS */ 190d727abcbSEric W. Biederman #include <linux/sched.h> 191d727abcbSEric W. Biederman #include <linux/nsproxy.h> 192038e7332SEric W. Biederman static inline struct net *copy_net_ns(unsigned long flags, 193038e7332SEric W. Biederman struct user_namespace *user_ns, struct net *old_net) 1949dd776b6SEric W. Biederman { 195d727abcbSEric W. Biederman if (flags & CLONE_NEWNET) 196d727abcbSEric W. Biederman return ERR_PTR(-EINVAL); 197d727abcbSEric W. Biederman return old_net; 1989dd776b6SEric W. Biederman } 1997866cc57SFlorian Westphal 200fbdeaed4STyler Hicks static inline void net_ns_get_ownership(const struct net *net, 201fbdeaed4STyler Hicks kuid_t *uid, kgid_t *gid) 202fbdeaed4STyler Hicks { 203fbdeaed4STyler Hicks *uid = GLOBAL_ROOT_UID; 204fbdeaed4STyler Hicks *gid = GLOBAL_ROOT_GID; 205fbdeaed4STyler Hicks } 206fbdeaed4STyler Hicks 2077866cc57SFlorian Westphal static inline void net_ns_barrier(void) {} 208d727abcbSEric W. Biederman #endif /* CONFIG_NET_NS */ 209225c0a01SDenis V. Lunev 210225c0a01SDenis V. Lunev 211225c0a01SDenis V. Lunev extern struct list_head net_namespace_list; 2129dd776b6SEric W. Biederman 213e67e16eaSJoe Perches struct net *get_net_ns_by_pid(pid_t pid); 2140f5258cdSStefan Hajnoczi struct net *get_net_ns_by_fd(int fd); 21530ffee84SJohannes Berg 216535d3ae9SRashika Kheria #ifdef CONFIG_SYSCTL 217535d3ae9SRashika Kheria void ipx_register_sysctl(void); 218535d3ae9SRashika Kheria void ipx_unregister_sysctl(void); 219535d3ae9SRashika Kheria #else 220535d3ae9SRashika Kheria #define ipx_register_sysctl() 221535d3ae9SRashika Kheria #define ipx_unregister_sysctl() 222535d3ae9SRashika Kheria #endif 223535d3ae9SRashika Kheria 224d4655795SPavel Emelyanov #ifdef CONFIG_NET_NS 225e67e16eaSJoe Perches void __put_net(struct net *net); 2265f256becSEric W. Biederman 2275f256becSEric W. Biederman static inline struct net *get_net(struct net *net) 2285f256becSEric W. Biederman { 229273c28bcSKirill Tkhai refcount_inc(&net->count); 2305f256becSEric W. Biederman return net; 2315f256becSEric W. Biederman } 2325f256becSEric W. Biederman 233077130c0SEric W. Biederman static inline struct net *maybe_get_net(struct net *net) 234077130c0SEric W. Biederman { 235077130c0SEric W. Biederman /* Used when we know struct net exists but we 236077130c0SEric W. Biederman * aren't guaranteed a previous reference count 237077130c0SEric W. Biederman * exists. If the reference count is zero this 238077130c0SEric W. Biederman * function fails and returns NULL. 239077130c0SEric W. Biederman */ 240273c28bcSKirill Tkhai if (!refcount_inc_not_zero(&net->count)) 241077130c0SEric W. Biederman net = NULL; 242077130c0SEric W. Biederman return net; 243077130c0SEric W. Biederman } 244077130c0SEric W. Biederman 2455f256becSEric W. Biederman static inline void put_net(struct net *net) 2465f256becSEric W. Biederman { 247273c28bcSKirill Tkhai if (refcount_dec_and_test(&net->count)) 2485f256becSEric W. Biederman __put_net(net); 2495f256becSEric W. Biederman } 2505f256becSEric W. Biederman 251878628fbSYOSHIFUJI Hideaki static inline 252878628fbSYOSHIFUJI Hideaki int net_eq(const struct net *net1, const struct net *net2) 253878628fbSYOSHIFUJI Hideaki { 254878628fbSYOSHIFUJI Hideaki return net1 == net2; 255878628fbSYOSHIFUJI Hideaki } 256a685e089SAl Viro 2574ee806d5SDan Streetman static inline int check_net(const struct net *net) 2584ee806d5SDan Streetman { 2593e3ab9ccSDavid S. Miller return refcount_read(&net->count) != 0; 2604ee806d5SDan Streetman } 2614ee806d5SDan Streetman 262e67e16eaSJoe Perches void net_drop_ns(void *); 263a685e089SAl Viro 264d4655795SPavel Emelyanov #else 265b9f75f45SEric W. Biederman 266d4655795SPavel Emelyanov static inline struct net *get_net(struct net *net) 267d4655795SPavel Emelyanov { 268d4655795SPavel Emelyanov return net; 269d4655795SPavel Emelyanov } 270d4655795SPavel Emelyanov 271d4655795SPavel Emelyanov static inline void put_net(struct net *net) 272d4655795SPavel Emelyanov { 273d4655795SPavel Emelyanov } 274d4655795SPavel Emelyanov 275d4655795SPavel Emelyanov static inline struct net *maybe_get_net(struct net *net) 276d4655795SPavel Emelyanov { 277d4655795SPavel Emelyanov return net; 278d4655795SPavel Emelyanov } 279878628fbSYOSHIFUJI Hideaki 280878628fbSYOSHIFUJI Hideaki static inline 281878628fbSYOSHIFUJI Hideaki int net_eq(const struct net *net1, const struct net *net2) 282878628fbSYOSHIFUJI Hideaki { 283878628fbSYOSHIFUJI Hideaki return 1; 284878628fbSYOSHIFUJI Hideaki } 285a685e089SAl Viro 2864ee806d5SDan Streetman static inline int check_net(const struct net *net) 2874ee806d5SDan Streetman { 2884ee806d5SDan Streetman return 1; 2894ee806d5SDan Streetman } 2904ee806d5SDan Streetman 291a685e089SAl Viro #define net_drop_ns NULL 292d4655795SPavel Emelyanov #endif 2935f256becSEric W. Biederman 2945d1e4468SDenis V. Lunev 2950c5c9fb5SEric W. Biederman typedef struct { 2968f424b5fSEric Dumazet #ifdef CONFIG_NET_NS 2970c5c9fb5SEric W. Biederman struct net *net; 2988f424b5fSEric Dumazet #endif 2990c5c9fb5SEric W. Biederman } possible_net_t; 3000c5c9fb5SEric W. Biederman 3010c5c9fb5SEric W. Biederman static inline void write_pnet(possible_net_t *pnet, struct net *net) 3020c5c9fb5SEric W. Biederman { 3030c5c9fb5SEric W. Biederman #ifdef CONFIG_NET_NS 3040c5c9fb5SEric W. Biederman pnet->net = net; 3050c5c9fb5SEric W. Biederman #endif 3060c5c9fb5SEric W. Biederman } 3070c5c9fb5SEric W. Biederman 3080c5c9fb5SEric W. Biederman static inline struct net *read_pnet(const possible_net_t *pnet) 3090c5c9fb5SEric W. Biederman { 3100c5c9fb5SEric W. Biederman #ifdef CONFIG_NET_NS 3110c5c9fb5SEric W. Biederman return pnet->net; 3120c5c9fb5SEric W. Biederman #else 3130c5c9fb5SEric W. Biederman return &init_net; 3140c5c9fb5SEric W. Biederman #endif 3150c5c9fb5SEric W. Biederman } 3165d1e4468SDenis V. Lunev 317f0b07bb1SKirill Tkhai /* Protected by net_rwsem */ 3185f256becSEric W. Biederman #define for_each_net(VAR) \ 3195f256becSEric W. Biederman list_for_each_entry(VAR, &net_namespace_list, list) 320afa0df59SJiri Pirko #define for_each_net_continue_reverse(VAR) \ 321afa0df59SJiri Pirko list_for_each_entry_continue_reverse(VAR, &net_namespace_list, list) 32211a28d37SJohannes Berg #define for_each_net_rcu(VAR) \ 32311a28d37SJohannes Berg list_for_each_entry_rcu(VAR, &net_namespace_list, list) 32411a28d37SJohannes Berg 3254665079cSPavel Emelyanov #ifdef CONFIG_NET_NS 3264665079cSPavel Emelyanov #define __net_init 3274665079cSPavel Emelyanov #define __net_exit 328022cbae6SDenis V. Lunev #define __net_initdata 32904a6f82cSAndi Kleen #define __net_initconst 3304665079cSPavel Emelyanov #else 3314665079cSPavel Emelyanov #define __net_init __init 332bd721ea7SFabian Frederick #define __net_exit __ref 333022cbae6SDenis V. Lunev #define __net_initdata __initdata 33404a6f82cSAndi Kleen #define __net_initconst __initconst 3354665079cSPavel Emelyanov #endif 3365f256becSEric W. Biederman 3377a0877d4SNicolas Dichtel int peernet2id_alloc(struct net *net, struct net *peer); 33859324cf3SNicolas Dichtel int peernet2id(struct net *net, struct net *peer); 33959324cf3SNicolas Dichtel bool peernet_has_id(struct net *net, struct net *peer); 3400c7aecd4SNicolas Dichtel struct net *get_net_ns_by_id(struct net *net, int id); 3410c7aecd4SNicolas Dichtel 3425f256becSEric W. Biederman struct pernet_operations { 3435f256becSEric W. Biederman struct list_head list; 3446056415dSKirill Tkhai /* 3456056415dSKirill Tkhai * Below methods are called without any exclusive locks. 3466056415dSKirill Tkhai * More than one net may be constructed and destructed 3476056415dSKirill Tkhai * in parallel on several cpus. Every pernet_operations 3486056415dSKirill Tkhai * have to keep in mind all other pernet_operations and 3496056415dSKirill Tkhai * to introduce a locking, if they share common resources. 3506056415dSKirill Tkhai * 3518518e9bbSKirill Tkhai * The only time they are called with exclusive lock is 3528518e9bbSKirill Tkhai * from register_pernet_subsys(), unregister_pernet_subsys() 3538518e9bbSKirill Tkhai * register_pernet_device() and unregister_pernet_device(). 3548518e9bbSKirill Tkhai * 3556056415dSKirill Tkhai * Exit methods using blocking RCU primitives, such as 3566056415dSKirill Tkhai * synchronize_rcu(), should be implemented via exit_batch. 3576056415dSKirill Tkhai * Then, destruction of a group of net requires single 3586056415dSKirill Tkhai * synchronize_rcu() related to these pernet_operations, 3596056415dSKirill Tkhai * instead of separate synchronize_rcu() for every net. 3606056415dSKirill Tkhai * Please, avoid synchronize_rcu() at all, where it's possible. 361d7d99872SEric Dumazet * 362d7d99872SEric Dumazet * Note that a combination of pre_exit() and exit() can 363d7d99872SEric Dumazet * be used, since a synchronize_rcu() is guaranteed between 364d7d99872SEric Dumazet * the calls. 3656056415dSKirill Tkhai */ 3665f256becSEric W. Biederman int (*init)(struct net *net); 367d7d99872SEric Dumazet void (*pre_exit)(struct net *net); 3685f256becSEric W. Biederman void (*exit)(struct net *net); 36972ad937aSEric W. Biederman void (*exit_batch)(struct list_head *net_exit_list); 370c7d03a00SAlexey Dobriyan unsigned int *id; 371f875bae0SEric W. Biederman size_t size; 3725f256becSEric W. Biederman }; 3735f256becSEric W. Biederman 37417edde52SEric W. Biederman /* 37517edde52SEric W. Biederman * Use these carefully. If you implement a network device and it 37617edde52SEric W. Biederman * needs per network namespace operations use device pernet operations, 37717edde52SEric W. Biederman * otherwise use pernet subsys operations. 37817edde52SEric W. Biederman * 3794edf547bSJohannes Berg * Network interfaces need to be removed from a dying netns _before_ 3804edf547bSJohannes Berg * subsys notifiers can be called, as most of the network code cleanup 3814edf547bSJohannes Berg * (which is done from subsys notifiers) runs with the assumption that 3824edf547bSJohannes Berg * dev_remove_pack has been called so no new packets will arrive during 3834edf547bSJohannes Berg * and after the cleanup functions have been called. dev_remove_pack 3844edf547bSJohannes Berg * is not per namespace so instead the guarantee of no more packets 3854edf547bSJohannes Berg * arriving in a network namespace is provided by ensuring that all 3864edf547bSJohannes Berg * network devices and all sockets have left the network namespace 3874edf547bSJohannes Berg * before the cleanup methods are called. 38817edde52SEric W. Biederman * 38917edde52SEric W. Biederman * For the longest time the ipv4 icmp code was registered as a pernet 39017edde52SEric W. Biederman * device which caused kernel oops, and panics during network 39117edde52SEric W. Biederman * namespace cleanup. So please don't get this wrong. 39217edde52SEric W. Biederman */ 393e67e16eaSJoe Perches int register_pernet_subsys(struct pernet_operations *); 394e67e16eaSJoe Perches void unregister_pernet_subsys(struct pernet_operations *); 395e67e16eaSJoe Perches int register_pernet_device(struct pernet_operations *); 396e67e16eaSJoe Perches void unregister_pernet_device(struct pernet_operations *); 397f875bae0SEric W. Biederman 39895bdfccbSEric W. Biederman struct ctl_table; 39995bdfccbSEric W. Biederman struct ctl_table_header; 400d62c612eSPavel Emelyanov 4012ca794e5SEric W. Biederman #ifdef CONFIG_SYSCTL 402e67e16eaSJoe Perches int net_sysctl_init(void); 403e67e16eaSJoe Perches struct ctl_table_header *register_net_sysctl(struct net *net, const char *path, 404e67e16eaSJoe Perches struct ctl_table *table); 405e67e16eaSJoe Perches void unregister_net_sysctl_table(struct ctl_table_header *header); 40648c74958SEric W. Biederman #else 40748c74958SEric W. Biederman static inline int net_sysctl_init(void) { return 0; } 40848c74958SEric W. Biederman static inline struct ctl_table_header *register_net_sysctl(struct net *net, 40948c74958SEric W. Biederman const char *path, struct ctl_table *table) 41048c74958SEric W. Biederman { 41148c74958SEric W. Biederman return NULL; 41248c74958SEric W. Biederman } 41348c74958SEric W. Biederman static inline void unregister_net_sysctl_table(struct ctl_table_header *header) 41448c74958SEric W. Biederman { 41548c74958SEric W. Biederman } 41648c74958SEric W. Biederman #endif 41748c74958SEric W. Biederman 418ca4c3fc2Sfan.du static inline int rt_genid_ipv4(struct net *net) 419b42664f8SNicolas Dichtel { 420ca4c3fc2Sfan.du return atomic_read(&net->ipv4.rt_genid); 421b42664f8SNicolas Dichtel } 422b42664f8SNicolas Dichtel 423ca4c3fc2Sfan.du static inline void rt_genid_bump_ipv4(struct net *net) 424b42664f8SNicolas Dichtel { 425ca4c3fc2Sfan.du atomic_inc(&net->ipv4.rt_genid); 426ca4c3fc2Sfan.du } 427ca4c3fc2Sfan.du 428705f1c86SHannes Frederic Sowa extern void (*__fib6_flush_trees)(struct net *net); 429ca4c3fc2Sfan.du static inline void rt_genid_bump_ipv6(struct net *net) 430ca4c3fc2Sfan.du { 431705f1c86SHannes Frederic Sowa if (__fib6_flush_trees) 432705f1c86SHannes Frederic Sowa __fib6_flush_trees(net); 433ca4c3fc2Sfan.du } 434ca4c3fc2Sfan.du 435599018a7SLuis R. Rodriguez #if IS_ENABLED(CONFIG_IEEE802154_6LOWPAN) 436599018a7SLuis R. Rodriguez static inline struct netns_ieee802154_lowpan * 437599018a7SLuis R. Rodriguez net_ieee802154_lowpan(struct net *net) 438599018a7SLuis R. Rodriguez { 439599018a7SLuis R. Rodriguez return &net->ieee802154_lowpan; 440599018a7SLuis R. Rodriguez } 441599018a7SLuis R. Rodriguez #endif 442599018a7SLuis R. Rodriguez 443ca4c3fc2Sfan.du /* For callers who don't really care about whether it's IPv4 or IPv6 */ 444ca4c3fc2Sfan.du static inline void rt_genid_bump_all(struct net *net) 445ca4c3fc2Sfan.du { 446ca4c3fc2Sfan.du rt_genid_bump_ipv4(net); 447ca4c3fc2Sfan.du rt_genid_bump_ipv6(net); 448b42664f8SNicolas Dichtel } 44995bdfccbSEric W. Biederman 4505aad1de5STimo Teräs static inline int fnhe_genid(struct net *net) 4515aad1de5STimo Teräs { 4525aad1de5STimo Teräs return atomic_read(&net->fnhe_genid); 4535aad1de5STimo Teräs } 4545aad1de5STimo Teräs 4555aad1de5STimo Teräs static inline void fnhe_genid_bump(struct net *net) 4565aad1de5STimo Teräs { 4575aad1de5STimo Teräs atomic_inc(&net->fnhe_genid); 4585aad1de5STimo Teräs } 4595aad1de5STimo Teräs 4605f256becSEric W. Biederman #endif /* __NET_NET_NAMESPACE_H */ 461