blob: 6344b77f81a2ece81da79190d2f0cef86dcda7f0 [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
11struct net {
12 atomic_t count; /* To decided when the network
13 * namespace should be freed.
14 */
15 atomic_t use_count; /* To track references we
16 * destroy on demand
17 */
18 struct list_head list; /* list of network namespaces */
19 struct work_struct work; /* work struct for freeing */
20};
21
22extern struct net init_net;
23extern struct list_head net_namespace_list;
24
25extern void __put_net(struct net *net);
26
27static inline struct net *get_net(struct net *net)
28{
29 atomic_inc(&net->count);
30 return net;
31}
32
33static inline void put_net(struct net *net)
34{
35 if (atomic_dec_and_test(&net->count))
36 __put_net(net);
37}
38
39static inline struct net *hold_net(struct net *net)
40{
41 atomic_inc(&net->use_count);
42 return net;
43}
44
45static inline void release_net(struct net *net)
46{
47 atomic_dec(&net->use_count);
48}
49
50extern void net_lock(void);
51extern void net_unlock(void);
52
53#define for_each_net(VAR) \
54 list_for_each_entry(VAR, &net_namespace_list, list)
55
56
57struct pernet_operations {
58 struct list_head list;
59 int (*init)(struct net *net);
60 void (*exit)(struct net *net);
61};
62
63extern int register_pernet_subsys(struct pernet_operations *);
64extern void unregister_pernet_subsys(struct pernet_operations *);
65extern int register_pernet_device(struct pernet_operations *);
66extern void unregister_pernet_device(struct pernet_operations *);
67
68#endif /* __NET_NET_NAMESPACE_H */