blob: fac42db7f6d0772b8d2fbd3c93bb075a5b7f2577 [file] [log] [blame]
Eric W. Biederman5f256be2007-09-12 11:50:50 +02001/*
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
Eric W. Biederman457c4cb2007-09-12 12:01:34 +020011struct proc_dir_entry;
Eric W. Biederman5f256be2007-09-12 11:50:50 +020012struct net {
13 atomic_t count; /* To decided when the network
14 * namespace should be freed.
15 */
16 atomic_t use_count; /* To track references we
17 * destroy on demand
18 */
19 struct list_head list; /* list of network namespaces */
20 struct work_struct work; /* work struct for freeing */
Eric W. Biederman457c4cb2007-09-12 12:01:34 +020021
22 struct proc_dir_entry *proc_net;
23 struct proc_dir_entry *proc_net_stat;
24 struct proc_dir_entry *proc_net_root;
Eric W. Biederman881d9662007-09-17 11:56:21 -070025
26 struct list_head dev_base_head;
27 struct hlist_head *dev_name_head;
28 struct hlist_head *dev_index_head;
Eric W. Biederman5f256be2007-09-12 11:50:50 +020029};
30
31extern struct net init_net;
32extern struct list_head net_namespace_list;
33
34extern void __put_net(struct net *net);
35
36static inline struct net *get_net(struct net *net)
37{
38 atomic_inc(&net->count);
39 return net;
40}
41
42static inline void put_net(struct net *net)
43{
44 if (atomic_dec_and_test(&net->count))
45 __put_net(net);
46}
47
48static inline struct net *hold_net(struct net *net)
49{
50 atomic_inc(&net->use_count);
51 return net;
52}
53
54static inline void release_net(struct net *net)
55{
56 atomic_dec(&net->use_count);
57}
58
59extern void net_lock(void);
60extern void net_unlock(void);
61
62#define for_each_net(VAR) \
63 list_for_each_entry(VAR, &net_namespace_list, list)
64
65
66struct pernet_operations {
67 struct list_head list;
68 int (*init)(struct net *net);
69 void (*exit)(struct net *net);
70};
71
72extern int register_pernet_subsys(struct pernet_operations *);
73extern void unregister_pernet_subsys(struct pernet_operations *);
74extern int register_pernet_device(struct pernet_operations *);
75extern void unregister_pernet_device(struct pernet_operations *);
76
77#endif /* __NET_NET_NAMESPACE_H */