Commit | Line | Data |
---|---|---|
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 | ||
457c4cbc | 11 | struct proc_dir_entry; |
2774c7ab | 12 | struct net_device; |
97c53cac | 13 | struct sock; |
5f256bec EB |
14 | struct net { |
15 | atomic_t count; /* To decided when the network | |
16 | * namespace should be freed. | |
17 | */ | |
18 | atomic_t use_count; /* To track references we | |
19 | * destroy on demand | |
20 | */ | |
21 | struct list_head list; /* list of network namespaces */ | |
22 | struct work_struct work; /* work struct for freeing */ | |
457c4cbc EB |
23 | |
24 | struct proc_dir_entry *proc_net; | |
25 | struct proc_dir_entry *proc_net_stat; | |
26 | struct proc_dir_entry *proc_net_root; | |
881d966b | 27 | |
2774c7ab EB |
28 | struct net_device *loopback_dev; /* The loopback */ |
29 | ||
881d966b EB |
30 | struct list_head dev_base_head; |
31 | struct hlist_head *dev_name_head; | |
32 | struct hlist_head *dev_index_head; | |
97c53cac DL |
33 | |
34 | struct sock *rtnl; /* rtnetlink socket */ | |
5f256bec EB |
35 | }; |
36 | ||
4fabcd71 DL |
37 | #ifdef CONFIG_NET |
38 | /* Init's network namespace */ | |
5f256bec | 39 | extern struct net init_net; |
4fabcd71 DL |
40 | #define INIT_NET_NS(net_ns) .net_ns = &init_net, |
41 | #else | |
42 | #define INIT_NET_NS(net_ns) | |
43 | #endif | |
44 | ||
5f256bec EB |
45 | extern struct list_head net_namespace_list; |
46 | ||
9dd776b6 EB |
47 | #ifdef CONFIG_NET |
48 | extern struct net *copy_net_ns(unsigned long flags, struct net *net_ns); | |
49 | #else | |
50 | static inline struct net *copy_net_ns(unsigned long flags, struct net *net_ns) | |
51 | { | |
52 | /* There is nothing to copy so this is a noop */ | |
53 | return net_ns; | |
54 | } | |
55 | #endif | |
56 | ||
d4655795 | 57 | #ifdef CONFIG_NET_NS |
5f256bec EB |
58 | extern void __put_net(struct net *net); |
59 | ||
60 | static inline struct net *get_net(struct net *net) | |
61 | { | |
62 | atomic_inc(&net->count); | |
63 | return net; | |
64 | } | |
65 | ||
077130c0 EB |
66 | static inline struct net *maybe_get_net(struct net *net) |
67 | { | |
68 | /* Used when we know struct net exists but we | |
69 | * aren't guaranteed a previous reference count | |
70 | * exists. If the reference count is zero this | |
71 | * function fails and returns NULL. | |
72 | */ | |
73 | if (!atomic_inc_not_zero(&net->count)) | |
74 | net = NULL; | |
75 | return net; | |
76 | } | |
77 | ||
5f256bec EB |
78 | static inline void put_net(struct net *net) |
79 | { | |
80 | if (atomic_dec_and_test(&net->count)) | |
81 | __put_net(net); | |
82 | } | |
83 | ||
84 | static inline struct net *hold_net(struct net *net) | |
85 | { | |
86 | atomic_inc(&net->use_count); | |
87 | return net; | |
88 | } | |
89 | ||
90 | static inline void release_net(struct net *net) | |
91 | { | |
92 | atomic_dec(&net->use_count); | |
93 | } | |
d4655795 PE |
94 | #else |
95 | static inline struct net *get_net(struct net *net) | |
96 | { | |
97 | return net; | |
98 | } | |
99 | ||
100 | static inline void put_net(struct net *net) | |
101 | { | |
102 | } | |
103 | ||
104 | static inline struct net *hold_net(struct net *net) | |
105 | { | |
106 | return net; | |
107 | } | |
108 | ||
109 | static inline void release_net(struct net *net) | |
110 | { | |
111 | } | |
112 | ||
113 | static inline struct net *maybe_get_net(struct net *net) | |
114 | { | |
115 | return net; | |
116 | } | |
117 | #endif | |
5f256bec | 118 | |
5f256bec EB |
119 | #define for_each_net(VAR) \ |
120 | list_for_each_entry(VAR, &net_namespace_list, list) | |
121 | ||
4665079c PE |
122 | #ifdef CONFIG_NET_NS |
123 | #define __net_init | |
124 | #define __net_exit | |
022cbae6 | 125 | #define __net_initdata |
4665079c PE |
126 | #else |
127 | #define __net_init __init | |
128 | #define __net_exit __exit_refok | |
022cbae6 | 129 | #define __net_initdata __initdata |
4665079c | 130 | #endif |
5f256bec EB |
131 | |
132 | struct pernet_operations { | |
133 | struct list_head list; | |
134 | int (*init)(struct net *net); | |
135 | void (*exit)(struct net *net); | |
136 | }; | |
137 | ||
138 | extern int register_pernet_subsys(struct pernet_operations *); | |
139 | extern void unregister_pernet_subsys(struct pernet_operations *); | |
140 | extern int register_pernet_device(struct pernet_operations *); | |
141 | extern void unregister_pernet_device(struct pernet_operations *); | |
142 | ||
143 | #endif /* __NET_NET_NAMESPACE_H */ |