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 */ | |
d12d01d6 DL |
35 | |
36 | /* List of all packet sockets. */ | |
37 | rwlock_t packet_sklist_lock; | |
38 | struct hlist_head packet_sklist; | |
5f256bec EB |
39 | }; |
40 | ||
4fabcd71 DL |
41 | #ifdef CONFIG_NET |
42 | /* Init's network namespace */ | |
5f256bec | 43 | extern struct net init_net; |
4fabcd71 DL |
44 | #define INIT_NET_NS(net_ns) .net_ns = &init_net, |
45 | #else | |
46 | #define INIT_NET_NS(net_ns) | |
47 | #endif | |
48 | ||
5f256bec EB |
49 | extern struct list_head net_namespace_list; |
50 | ||
9dd776b6 EB |
51 | #ifdef CONFIG_NET |
52 | extern struct net *copy_net_ns(unsigned long flags, struct net *net_ns); | |
53 | #else | |
54 | static inline struct net *copy_net_ns(unsigned long flags, struct net *net_ns) | |
55 | { | |
56 | /* There is nothing to copy so this is a noop */ | |
57 | return net_ns; | |
58 | } | |
59 | #endif | |
60 | ||
d4655795 | 61 | #ifdef CONFIG_NET_NS |
5f256bec EB |
62 | extern void __put_net(struct net *net); |
63 | ||
64 | static inline struct net *get_net(struct net *net) | |
65 | { | |
66 | atomic_inc(&net->count); | |
67 | return net; | |
68 | } | |
69 | ||
077130c0 EB |
70 | static inline struct net *maybe_get_net(struct net *net) |
71 | { | |
72 | /* Used when we know struct net exists but we | |
73 | * aren't guaranteed a previous reference count | |
74 | * exists. If the reference count is zero this | |
75 | * function fails and returns NULL. | |
76 | */ | |
77 | if (!atomic_inc_not_zero(&net->count)) | |
78 | net = NULL; | |
79 | return net; | |
80 | } | |
81 | ||
5f256bec EB |
82 | static inline void put_net(struct net *net) |
83 | { | |
84 | if (atomic_dec_and_test(&net->count)) | |
85 | __put_net(net); | |
86 | } | |
87 | ||
88 | static inline struct net *hold_net(struct net *net) | |
89 | { | |
90 | atomic_inc(&net->use_count); | |
91 | return net; | |
92 | } | |
93 | ||
94 | static inline void release_net(struct net *net) | |
95 | { | |
96 | atomic_dec(&net->use_count); | |
97 | } | |
d4655795 PE |
98 | #else |
99 | static inline struct net *get_net(struct net *net) | |
100 | { | |
101 | return net; | |
102 | } | |
103 | ||
104 | static inline void put_net(struct net *net) | |
105 | { | |
106 | } | |
107 | ||
108 | static inline struct net *hold_net(struct net *net) | |
109 | { | |
110 | return net; | |
111 | } | |
112 | ||
113 | static inline void release_net(struct net *net) | |
114 | { | |
115 | } | |
116 | ||
117 | static inline struct net *maybe_get_net(struct net *net) | |
118 | { | |
119 | return net; | |
120 | } | |
121 | #endif | |
5f256bec | 122 | |
5f256bec EB |
123 | #define for_each_net(VAR) \ |
124 | list_for_each_entry(VAR, &net_namespace_list, list) | |
125 | ||
4665079c PE |
126 | #ifdef CONFIG_NET_NS |
127 | #define __net_init | |
128 | #define __net_exit | |
022cbae6 | 129 | #define __net_initdata |
4665079c PE |
130 | #else |
131 | #define __net_init __init | |
132 | #define __net_exit __exit_refok | |
022cbae6 | 133 | #define __net_initdata __initdata |
4665079c | 134 | #endif |
5f256bec EB |
135 | |
136 | struct pernet_operations { | |
137 | struct list_head list; | |
138 | int (*init)(struct net *net); | |
139 | void (*exit)(struct net *net); | |
140 | }; | |
141 | ||
142 | extern int register_pernet_subsys(struct pernet_operations *); | |
143 | extern void unregister_pernet_subsys(struct pernet_operations *); | |
144 | extern int register_pernet_device(struct pernet_operations *); | |
145 | extern void unregister_pernet_device(struct pernet_operations *); | |
146 | ||
147 | #endif /* __NET_NET_NAMESPACE_H */ |