[NET]: Implement the per network namespace sysctl infrastructure
[pandora-kernel.git] / include / net / net_namespace.h
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
11 struct proc_dir_entry;
12 struct net_device;
13 struct sock;
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 */
23
24         struct proc_dir_entry   *proc_net;
25         struct proc_dir_entry   *proc_net_stat;
26         struct proc_dir_entry   *proc_net_root;
27
28         struct list_head        sysctl_table_headers;
29
30         struct net_device       *loopback_dev;          /* The loopback */
31
32         struct list_head        dev_base_head;
33         struct hlist_head       *dev_name_head;
34         struct hlist_head       *dev_index_head;
35
36         struct sock             *rtnl;                  /* rtnetlink socket */
37
38         /* List of all packet sockets. */
39         rwlock_t                packet_sklist_lock;
40         struct hlist_head       packet_sklist;
41 };
42
43 #ifdef CONFIG_NET
44 /* Init's network namespace */
45 extern struct net init_net;
46 #define INIT_NET_NS(net_ns) .net_ns = &init_net,
47 #else
48 #define INIT_NET_NS(net_ns)
49 #endif
50
51 extern struct list_head net_namespace_list;
52
53 #ifdef CONFIG_NET
54 extern struct net *copy_net_ns(unsigned long flags, struct net *net_ns);
55 #else
56 static inline struct net *copy_net_ns(unsigned long flags, struct net *net_ns)
57 {
58         /* There is nothing to copy so this is a noop */
59         return net_ns;
60 }
61 #endif
62
63 #ifdef CONFIG_NET_NS
64 extern void __put_net(struct net *net);
65
66 static inline struct net *get_net(struct net *net)
67 {
68         atomic_inc(&net->count);
69         return net;
70 }
71
72 static inline struct net *maybe_get_net(struct net *net)
73 {
74         /* Used when we know struct net exists but we
75          * aren't guaranteed a previous reference count
76          * exists.  If the reference count is zero this
77          * function fails and returns NULL.
78          */
79         if (!atomic_inc_not_zero(&net->count))
80                 net = NULL;
81         return net;
82 }
83
84 static inline void put_net(struct net *net)
85 {
86         if (atomic_dec_and_test(&net->count))
87                 __put_net(net);
88 }
89
90 static inline struct net *hold_net(struct net *net)
91 {
92         atomic_inc(&net->use_count);
93         return net;
94 }
95
96 static inline void release_net(struct net *net)
97 {
98         atomic_dec(&net->use_count);
99 }
100 #else
101 static inline struct net *get_net(struct net *net)
102 {
103         return net;
104 }
105
106 static inline void put_net(struct net *net)
107 {
108 }
109
110 static inline struct net *hold_net(struct net *net)
111 {
112         return net;
113 }
114
115 static inline void release_net(struct net *net)
116 {
117 }
118
119 static inline struct net *maybe_get_net(struct net *net)
120 {
121         return net;
122 }
123 #endif
124
125 #define for_each_net(VAR)                               \
126         list_for_each_entry(VAR, &net_namespace_list, list)
127
128 #ifdef CONFIG_NET_NS
129 #define __net_init
130 #define __net_exit
131 #define __net_initdata
132 #else
133 #define __net_init      __init
134 #define __net_exit      __exit_refok
135 #define __net_initdata  __initdata
136 #endif
137
138 struct pernet_operations {
139         struct list_head list;
140         int (*init)(struct net *net);
141         void (*exit)(struct net *net);
142 };
143
144 extern int register_pernet_subsys(struct pernet_operations *);
145 extern void unregister_pernet_subsys(struct pernet_operations *);
146 extern int register_pernet_device(struct pernet_operations *);
147 extern void unregister_pernet_device(struct pernet_operations *);
148
149 struct ctl_path;
150 struct ctl_table;
151 struct ctl_table_header;
152 extern struct ctl_table_header *register_net_sysctl_table(struct net *net,
153         const struct ctl_path *path, struct ctl_table *table);
154 extern void unregister_net_sysctl_table(struct ctl_table_header *header);
155
156 #endif /* __NET_NET_NAMESPACE_H */