hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
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>
....@@ -206,6 +236,8 @@
206236
207237 struct net *get_net_ns_by_pid(pid_t pid);
208238 struct net *get_net_ns_by_fd(int fd);
239
+
240
+u64 __net_gen_cookie(struct net *net);
209241
210242 #ifdef CONFIG_SYSCTL
211243 void ipx_register_sysctl(void);
....@@ -311,7 +343,8 @@
311343 /* Protected by net_rwsem */
312344 #define for_each_net(VAR) \
313345 list_for_each_entry(VAR, &net_namespace_list, list)
314
-
346
+#define for_each_net_continue_reverse(VAR) \
347
+ list_for_each_entry_continue_reverse(VAR, &net_namespace_list, list)
315348 #define for_each_net_rcu(VAR) \
316349 list_for_each_entry_rcu(VAR, &net_namespace_list, list)
317350
....@@ -328,9 +361,9 @@
328361 #endif
329362
330363 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);
364
+int peernet2id(const struct net *net, struct net *peer);
365
+bool peernet_has_id(const struct net *net, struct net *peer);
366
+struct net *get_net_ns_by_id(const struct net *net, int id);
334367
335368 struct pernet_operations {
336369 struct list_head list;
....@@ -351,8 +384,13 @@
351384 * synchronize_rcu() related to these pernet_operations,
352385 * instead of separate synchronize_rcu() for every net.
353386 * Please, avoid synchronize_rcu() at all, where it's possible.
387
+ *
388
+ * Note that a combination of pre_exit() and exit() can
389
+ * be used, since a synchronize_rcu() is guaranteed between
390
+ * the calls.
354391 */
355392 int (*init)(struct net *net);
393
+ void (*pre_exit)(struct net *net);
356394 void (*exit)(struct net *net);
357395 void (*exit_batch)(struct list_head *net_exit_list);
358396 unsigned int *id;
....@@ -403,10 +441,17 @@
403441 }
404442 #endif
405443
406
-static inline int rt_genid_ipv4(struct net *net)
444
+static inline int rt_genid_ipv4(const struct net *net)
407445 {
408446 return atomic_read(&net->ipv4.rt_genid);
409447 }
448
+
449
+#if IS_ENABLED(CONFIG_IPV6)
450
+static inline int rt_genid_ipv6(const struct net *net)
451
+{
452
+ return atomic_read(&net->ipv6.fib6_sernum);
453
+}
454
+#endif
410455
411456 static inline void rt_genid_bump_ipv4(struct net *net)
412457 {
....@@ -435,7 +480,7 @@
435480 rt_genid_bump_ipv6(net);
436481 }
437482
438
-static inline int fnhe_genid(struct net *net)
483
+static inline int fnhe_genid(const struct net *net)
439484 {
440485 return atomic_read(&net->fnhe_genid);
441486 }