]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/net/net_namespace.h
[NETNS]: struct net content re-work (v3)
[mirror_ubuntu-jammy-kernel.git] / include / net / net_namespace.h
CommitLineData
5f256bec
EB
1/*
2 * Operations on the network namespace
3 */
4#ifndef __NET_NET_NAMESPACE_H
5#define __NET_NET_NAMESPACE_H
6
7#include <asm/atomic.h>
8#include <linux/workqueue.h>
9#include <linux/list.h>
10
a0a53c8b
DL
11#include <net/netns/unix.h>
12
457c4cbc 13struct proc_dir_entry;
2774c7ab 14struct net_device;
97c53cac 15struct sock;
1597fbc0
PE
16struct ctl_table_header;
17
5f256bec
EB
18struct net {
19 atomic_t count; /* To decided when the network
20 * namespace should be freed.
21 */
22 atomic_t use_count; /* To track references we
23 * destroy on demand
24 */
25 struct list_head list; /* list of network namespaces */
26 struct work_struct work; /* work struct for freeing */
457c4cbc
EB
27
28 struct proc_dir_entry *proc_net;
29 struct proc_dir_entry *proc_net_stat;
30 struct proc_dir_entry *proc_net_root;
881d966b 31
95bdfccb
EB
32 struct list_head sysctl_table_headers;
33
2774c7ab
EB
34 struct net_device *loopback_dev; /* The loopback */
35
881d966b
EB
36 struct list_head dev_base_head;
37 struct hlist_head *dev_name_head;
38 struct hlist_head *dev_index_head;
97c53cac
DL
39
40 struct sock *rtnl; /* rtnetlink socket */
d12d01d6 41
024626e3
PE
42 /* core sysctls */
43 struct ctl_table_header *sysctl_core_hdr;
b8e1f9b5 44 int sysctl_somaxconn;
024626e3 45
d12d01d6
DL
46 /* List of all packet sockets. */
47 rwlock_t packet_sklist_lock;
48 struct hlist_head packet_sklist;
d392e497 49
a0a53c8b 50 struct netns_unix unx;
5f256bec
EB
51};
52
4fabcd71
DL
53#ifdef CONFIG_NET
54/* Init's network namespace */
5f256bec 55extern struct net init_net;
4fabcd71
DL
56#define INIT_NET_NS(net_ns) .net_ns = &init_net,
57#else
58#define INIT_NET_NS(net_ns)
59#endif
60
5f256bec
EB
61extern struct list_head net_namespace_list;
62
9dd776b6
EB
63#ifdef CONFIG_NET
64extern struct net *copy_net_ns(unsigned long flags, struct net *net_ns);
65#else
66static inline struct net *copy_net_ns(unsigned long flags, struct net *net_ns)
67{
68 /* There is nothing to copy so this is a noop */
69 return net_ns;
70}
71#endif
72
d4655795 73#ifdef CONFIG_NET_NS
5f256bec
EB
74extern void __put_net(struct net *net);
75
76static inline struct net *get_net(struct net *net)
77{
78 atomic_inc(&net->count);
79 return net;
80}
81
077130c0
EB
82static inline struct net *maybe_get_net(struct net *net)
83{
84 /* Used when we know struct net exists but we
85 * aren't guaranteed a previous reference count
86 * exists. If the reference count is zero this
87 * function fails and returns NULL.
88 */
89 if (!atomic_inc_not_zero(&net->count))
90 net = NULL;
91 return net;
92}
93
5f256bec
EB
94static inline void put_net(struct net *net)
95{
96 if (atomic_dec_and_test(&net->count))
97 __put_net(net);
98}
99
100static inline struct net *hold_net(struct net *net)
101{
102 atomic_inc(&net->use_count);
103 return net;
104}
105
106static inline void release_net(struct net *net)
107{
108 atomic_dec(&net->use_count);
109}
d4655795
PE
110#else
111static inline struct net *get_net(struct net *net)
112{
113 return net;
114}
115
116static inline void put_net(struct net *net)
117{
118}
119
120static inline struct net *hold_net(struct net *net)
121{
122 return net;
123}
124
125static inline void release_net(struct net *net)
126{
127}
128
129static inline struct net *maybe_get_net(struct net *net)
130{
131 return net;
132}
133#endif
5f256bec 134
5f256bec
EB
135#define for_each_net(VAR) \
136 list_for_each_entry(VAR, &net_namespace_list, list)
137
4665079c
PE
138#ifdef CONFIG_NET_NS
139#define __net_init
140#define __net_exit
022cbae6 141#define __net_initdata
4665079c
PE
142#else
143#define __net_init __init
144#define __net_exit __exit_refok
022cbae6 145#define __net_initdata __initdata
4665079c 146#endif
5f256bec
EB
147
148struct pernet_operations {
149 struct list_head list;
150 int (*init)(struct net *net);
151 void (*exit)(struct net *net);
152};
153
154extern int register_pernet_subsys(struct pernet_operations *);
155extern void unregister_pernet_subsys(struct pernet_operations *);
156extern int register_pernet_device(struct pernet_operations *);
157extern void unregister_pernet_device(struct pernet_operations *);
158
95bdfccb
EB
159struct ctl_path;
160struct ctl_table;
161struct ctl_table_header;
162extern struct ctl_table_header *register_net_sysctl_table(struct net *net,
163 const struct ctl_path *path, struct ctl_table *table);
164extern void unregister_net_sysctl_table(struct ctl_table_header *header);
165
5f256bec 166#endif /* __NET_NET_NAMESPACE_H */