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