hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/include/net/net_namespace.h
....@@ -19,6 +19,7 @@
1919 #include <net/netns/packet.h>
2020 #include <net/netns/ipv4.h>
2121 #include <net/netns/ipv6.h>
22
+#include <net/netns/nexthop.h>
2223 #include <net/netns/ieee802154_6lowpan.h>
2324 #include <net/netns/sctp.h>
2425 #include <net/netns/dccp.h>
....@@ -31,9 +32,12 @@
3132 #include <net/netns/xfrm.h>
3233 #include <net/netns/mpls.h>
3334 #include <net/netns/can.h>
35
+#include <net/netns/xdp.h>
36
+#include <net/netns/bpf.h>
3437 #include <linux/ns_common.h>
3538 #include <linux/idr.h>
3639 #include <linux/skbuff.h>
40
+#include <linux/notifier.h>
3741
3842 struct user_namespace;
3943 struct proc_dir_entry;
....@@ -43,13 +47,17 @@
4347 struct net_generic;
4448 struct uevent_sock;
4549 struct netns_ipvs;
50
+struct bpf_prog;
4651
4752
4853 #define NETDEV_HASHBITS 8
4954 #define NETDEV_HASHENTRIES (1 << NETDEV_HASHBITS)
5055
5156 struct net {
52
- refcount_t passive; /* To decided when the network
57
+ /* First cache line can be often dirtied.
58
+ * Do not place here read-mostly fields.
59
+ */
60
+ refcount_t passive; /* To decide when the network
5361 * namespace should be freed.
5462 */
5563 refcount_t count; /* To decided when the network
....@@ -57,8 +65,13 @@
5765 */
5866 spinlock_t rules_mod_lock;
5967
60
- u32 hash_mix;
61
- atomic64_t cookie_gen;
68
+ unsigned int dev_unreg_count;
69
+
70
+ unsigned int dev_base_seq; /* protected by rtnl_mutex */
71
+ int ifindex;
72
+
73
+ spinlock_t nsid_lock;
74
+ atomic_t fnhe_genid;
6275
6376 struct list_head list; /* list of network namespaces */
6477 struct list_head exit_list; /* To linked to call pernet exit
....@@ -69,13 +82,16 @@
6982 */
7083 struct llist_node cleanup_list; /* namespaces on death row */
7184
85
+#ifdef CONFIG_KEYS
86
+ struct key_tag *key_domain; /* Key domain of operation tag */
87
+#endif
7288 struct user_namespace *user_ns; /* Owning user namespace */
7389 struct ucounts *ucounts;
74
- spinlock_t nsid_lock;
7590 struct idr netns_ids;
7691
7792 struct ns_common ns;
7893
94
+ struct list_head dev_base_head;
7995 struct proc_dir_entry *proc_net;
8096 struct proc_dir_entry *proc_net_stat;
8197
....@@ -88,24 +104,25 @@
88104
89105 struct uevent_sock *uevent_sock; /* uevent socket */
90106
91
- struct list_head dev_base_head;
92107 struct hlist_head *dev_name_head;
93108 struct hlist_head *dev_index_head;
94
- unsigned int dev_base_seq; /* protected by rtnl_mutex */
95
- int ifindex;
96
- unsigned int dev_unreg_count;
109
+ struct raw_notifier_head netdev_chain;
110
+
111
+ /* Note that @hash_mix can be read millions times per second,
112
+ * it is critical that it is on a read_mostly cache line.
113
+ */
114
+ u32 hash_mix;
115
+
116
+ struct net_device *loopback_dev; /* The loopback */
97117
98118 /* core fib_rules */
99119 struct list_head rules_ops;
100120
101
- struct list_head fib_notifier_ops; /* Populated by
102
- * register_pernet_subsys()
103
- */
104
- struct net_device *loopback_dev; /* The loopback */
105121 struct netns_core core;
106122 struct netns_mib mib;
107123 struct netns_packet packet;
108124 struct netns_unix unx;
125
+ struct netns_nexthop nexthop;
109126 struct netns_ipv4 ipv4;
110127 #if IS_ENABLED(CONFIG_IPV6)
111128 struct netns_ipv6 ipv6;
....@@ -113,7 +130,9 @@
113130 #if IS_ENABLED(CONFIG_IEEE802154_6LOWPAN)
114131 struct netns_ieee802154_lowpan ieee802154_lowpan;
115132 #endif
133
+#if defined(CONFIG_IP_SCTP) || defined(CONFIG_IP_SCTP_MODULE)
116134 struct netns_sctp sctp;
135
+#endif
117136 #if defined(CONFIG_IP_DCCP) || defined(CONFIG_IP_DCCP_MODULE)
118137 struct netns_dccp dccp;
119138 #endif
....@@ -144,10 +163,16 @@
144163 #endif
145164 struct net_generic __rcu *gen;
146165
166
+ /* Used to store attached BPF programs */
167
+ struct netns_bpf bpf;
168
+
147169 /* Note : following structs are cache line aligned */
148170 #ifdef CONFIG_XFRM
149171 struct netns_xfrm xfrm;
150172 #endif
173
+
174
+ atomic64_t net_cookie; /* written once */
175
+
151176 #if IS_ENABLED(CONFIG_IP_VS)
152177 struct netns_ipvs *ipvs;
153178 #endif
....@@ -157,8 +182,13 @@
157182 #if IS_ENABLED(CONFIG_CAN)
158183 struct netns_can can;
159184 #endif
185
+#ifdef CONFIG_XDP_SOCKETS
186
+ struct netns_xdp xdp;
187
+#endif
188
+#if IS_ENABLED(CONFIG_CRYPTO_USER)
189
+ struct sock *crypto_nlsk;
190
+#endif
160191 struct sock *diag_nlsk;
161
- atomic_t fnhe_genid;
162192 } __randomize_layout;
163193
164194 #include <linux/seq_file_net.h>
....@@ -311,7 +341,8 @@
311341 /* Protected by net_rwsem */
312342 #define for_each_net(VAR) \
313343 list_for_each_entry(VAR, &net_namespace_list, list)
314
-
344
+#define for_each_net_continue_reverse(VAR) \
345
+ list_for_each_entry_continue_reverse(VAR, &net_namespace_list, list)
315346 #define for_each_net_rcu(VAR) \
316347 list_for_each_entry_rcu(VAR, &net_namespace_list, list)
317348
....@@ -328,9 +359,9 @@
328359 #endif
329360
330361 int peernet2id_alloc(struct net *net, struct net *peer, gfp_t gfp);
331
-int peernet2id(struct net *net, struct net *peer);
332
-bool peernet_has_id(struct net *net, struct net *peer);
333
-struct net *get_net_ns_by_id(struct net *net, int id);
362
+int peernet2id(const struct net *net, struct net *peer);
363
+bool peernet_has_id(const struct net *net, struct net *peer);
364
+struct net *get_net_ns_by_id(const struct net *net, int id);
334365
335366 struct pernet_operations {
336367 struct list_head list;
....@@ -351,8 +382,13 @@
351382 * synchronize_rcu() related to these pernet_operations,
352383 * instead of separate synchronize_rcu() for every net.
353384 * Please, avoid synchronize_rcu() at all, where it's possible.
385
+ *
386
+ * Note that a combination of pre_exit() and exit() can
387
+ * be used, since a synchronize_rcu() is guaranteed between
388
+ * the calls.
354389 */
355390 int (*init)(struct net *net);
391
+ void (*pre_exit)(struct net *net);
356392 void (*exit)(struct net *net);
357393 void (*exit_batch)(struct list_head *net_exit_list);
358394 unsigned int *id;
....@@ -403,10 +439,17 @@
403439 }
404440 #endif
405441
406
-static inline int rt_genid_ipv4(struct net *net)
442
+static inline int rt_genid_ipv4(const struct net *net)
407443 {
408444 return atomic_read(&net->ipv4.rt_genid);
409445 }
446
+
447
+#if IS_ENABLED(CONFIG_IPV6)
448
+static inline int rt_genid_ipv6(const struct net *net)
449
+{
450
+ return atomic_read(&net->ipv6.fib6_sernum);
451
+}
452
+#endif
410453
411454 static inline void rt_genid_bump_ipv4(struct net *net)
412455 {
....@@ -435,7 +478,7 @@
435478 rt_genid_bump_ipv6(net);
436479 }
437480
438
-static inline int fnhe_genid(struct net *net)
481
+static inline int fnhe_genid(const struct net *net)
439482 {
440483 return atomic_read(&net->fnhe_genid);
441484 }