Eric W. Biederman | 5f256be | 2007-09-12 11:50:50 +0200 | [diff] [blame] | 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 | |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 11 | struct proc_dir_entry; |
Eric W. Biederman | 2774c7a | 2007-09-26 22:10:56 -0700 | [diff] [blame] | 12 | struct net_device; |
Denis V. Lunev | 97c53ca | 2007-11-19 22:26:51 -0800 | [diff] [blame] | 13 | struct sock; |
Pavel Emelyanov | 1597fbc | 2007-12-01 23:51:01 +1100 | [diff] [blame] | 14 | struct ctl_table_header; |
| 15 | |
Eric W. Biederman | 5f256be | 2007-09-12 11:50:50 +0200 | [diff] [blame] | 16 | struct net { |
| 17 | atomic_t count; /* To decided when the network |
| 18 | * namespace should be freed. |
| 19 | */ |
| 20 | atomic_t use_count; /* To track references we |
| 21 | * destroy on demand |
| 22 | */ |
| 23 | struct list_head list; /* list of network namespaces */ |
| 24 | struct work_struct work; /* work struct for freeing */ |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 25 | |
| 26 | struct proc_dir_entry *proc_net; |
| 27 | struct proc_dir_entry *proc_net_stat; |
| 28 | struct proc_dir_entry *proc_net_root; |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 29 | |
Eric W. Biederman | 95bdfcc | 2007-11-30 23:55:42 +1100 | [diff] [blame] | 30 | struct list_head sysctl_table_headers; |
| 31 | |
Eric W. Biederman | 2774c7a | 2007-09-26 22:10:56 -0700 | [diff] [blame] | 32 | struct net_device *loopback_dev; /* The loopback */ |
| 33 | |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 34 | struct list_head dev_base_head; |
| 35 | struct hlist_head *dev_name_head; |
| 36 | struct hlist_head *dev_index_head; |
Denis V. Lunev | 97c53ca | 2007-11-19 22:26:51 -0800 | [diff] [blame] | 37 | |
| 38 | struct sock *rtnl; /* rtnetlink socket */ |
Denis V. Lunev | d12d01d | 2007-11-19 22:28:35 -0800 | [diff] [blame] | 39 | |
Pavel Emelyanov | 024626e | 2007-12-08 00:09:24 -0800 | [diff] [blame] | 40 | /* core sysctls */ |
| 41 | struct ctl_table_header *sysctl_core_hdr; |
| 42 | |
Denis V. Lunev | d12d01d | 2007-11-19 22:28:35 -0800 | [diff] [blame] | 43 | /* List of all packet sockets. */ |
| 44 | rwlock_t packet_sklist_lock; |
| 45 | struct hlist_head packet_sklist; |
Pavel Emelyanov | d392e49 | 2007-12-01 23:44:15 +1100 | [diff] [blame] | 46 | |
| 47 | /* unix sockets */ |
| 48 | int sysctl_unix_max_dgram_qlen; |
Pavel Emelyanov | 1597fbc | 2007-12-01 23:51:01 +1100 | [diff] [blame] | 49 | struct ctl_table_header *unix_ctl; |
Eric W. Biederman | 5f256be | 2007-09-12 11:50:50 +0200 | [diff] [blame] | 50 | }; |
| 51 | |
Daniel Lezcano | 4fabcd7 | 2007-09-13 09:16:29 +0200 | [diff] [blame] | 52 | #ifdef CONFIG_NET |
| 53 | /* Init's network namespace */ |
Eric W. Biederman | 5f256be | 2007-09-12 11:50:50 +0200 | [diff] [blame] | 54 | extern struct net init_net; |
Daniel Lezcano | 4fabcd7 | 2007-09-13 09:16:29 +0200 | [diff] [blame] | 55 | #define INIT_NET_NS(net_ns) .net_ns = &init_net, |
| 56 | #else |
| 57 | #define INIT_NET_NS(net_ns) |
| 58 | #endif |
| 59 | |
Eric W. Biederman | 5f256be | 2007-09-12 11:50:50 +0200 | [diff] [blame] | 60 | extern struct list_head net_namespace_list; |
| 61 | |
Eric W. Biederman | 9dd776b | 2007-09-26 22:04:26 -0700 | [diff] [blame] | 62 | #ifdef CONFIG_NET |
| 63 | extern struct net *copy_net_ns(unsigned long flags, struct net *net_ns); |
| 64 | #else |
| 65 | static inline struct net *copy_net_ns(unsigned long flags, struct net *net_ns) |
| 66 | { |
| 67 | /* There is nothing to copy so this is a noop */ |
| 68 | return net_ns; |
| 69 | } |
| 70 | #endif |
| 71 | |
Pavel Emelyanov | d465579 | 2007-11-01 00:43:49 -0700 | [diff] [blame] | 72 | #ifdef CONFIG_NET_NS |
Eric W. Biederman | 5f256be | 2007-09-12 11:50:50 +0200 | [diff] [blame] | 73 | extern void __put_net(struct net *net); |
| 74 | |
| 75 | static inline struct net *get_net(struct net *net) |
| 76 | { |
| 77 | atomic_inc(&net->count); |
| 78 | return net; |
| 79 | } |
| 80 | |
Eric W. Biederman | 077130c | 2007-09-13 09:18:57 +0200 | [diff] [blame] | 81 | static inline struct net *maybe_get_net(struct net *net) |
| 82 | { |
| 83 | /* Used when we know struct net exists but we |
| 84 | * aren't guaranteed a previous reference count |
| 85 | * exists. If the reference count is zero this |
| 86 | * function fails and returns NULL. |
| 87 | */ |
| 88 | if (!atomic_inc_not_zero(&net->count)) |
| 89 | net = NULL; |
| 90 | return net; |
| 91 | } |
| 92 | |
Eric W. Biederman | 5f256be | 2007-09-12 11:50:50 +0200 | [diff] [blame] | 93 | static inline void put_net(struct net *net) |
| 94 | { |
| 95 | if (atomic_dec_and_test(&net->count)) |
| 96 | __put_net(net); |
| 97 | } |
| 98 | |
| 99 | static inline struct net *hold_net(struct net *net) |
| 100 | { |
| 101 | atomic_inc(&net->use_count); |
| 102 | return net; |
| 103 | } |
| 104 | |
| 105 | static inline void release_net(struct net *net) |
| 106 | { |
| 107 | atomic_dec(&net->use_count); |
Eric W. Biederman | 5f256be | 2007-09-12 11:50:50 +0200 | [diff] [blame] | 108 | } |
Pavel Emelyanov | d465579 | 2007-11-01 00:43:49 -0700 | [diff] [blame] | 109 | #else |
| 110 | static inline struct net *get_net(struct net *net) |
| 111 | { |
| 112 | return net; |
| 113 | } |
| 114 | |
| 115 | static inline void put_net(struct net *net) |
| 116 | { |
| 117 | } |
| 118 | |
| 119 | static inline struct net *hold_net(struct net *net) |
| 120 | { |
| 121 | return net; |
| 122 | } |
| 123 | |
| 124 | static inline void release_net(struct net *net) |
| 125 | { |
| 126 | } |
| 127 | |
| 128 | static inline struct net *maybe_get_net(struct net *net) |
| 129 | { |
| 130 | return net; |
| 131 | } |
| 132 | #endif |
Eric W. Biederman | 5f256be | 2007-09-12 11:50:50 +0200 | [diff] [blame] | 133 | |
Eric W. Biederman | 5f256be | 2007-09-12 11:50:50 +0200 | [diff] [blame] | 134 | #define for_each_net(VAR) \ |
| 135 | list_for_each_entry(VAR, &net_namespace_list, list) |
| 136 | |
Pavel Emelyanov | 4665079 | 2007-10-08 20:38:39 -0700 | [diff] [blame] | 137 | #ifdef CONFIG_NET_NS |
| 138 | #define __net_init |
| 139 | #define __net_exit |
Denis V. Lunev | 022cbae | 2007-11-13 03:23:50 -0800 | [diff] [blame] | 140 | #define __net_initdata |
Pavel Emelyanov | 4665079 | 2007-10-08 20:38:39 -0700 | [diff] [blame] | 141 | #else |
| 142 | #define __net_init __init |
| 143 | #define __net_exit __exit_refok |
Denis V. Lunev | 022cbae | 2007-11-13 03:23:50 -0800 | [diff] [blame] | 144 | #define __net_initdata __initdata |
Pavel Emelyanov | 4665079 | 2007-10-08 20:38:39 -0700 | [diff] [blame] | 145 | #endif |
Eric W. Biederman | 5f256be | 2007-09-12 11:50:50 +0200 | [diff] [blame] | 146 | |
| 147 | struct pernet_operations { |
| 148 | struct list_head list; |
| 149 | int (*init)(struct net *net); |
| 150 | void (*exit)(struct net *net); |
| 151 | }; |
| 152 | |
| 153 | extern int register_pernet_subsys(struct pernet_operations *); |
| 154 | extern void unregister_pernet_subsys(struct pernet_operations *); |
| 155 | extern int register_pernet_device(struct pernet_operations *); |
| 156 | extern void unregister_pernet_device(struct pernet_operations *); |
| 157 | |
Eric W. Biederman | 95bdfcc | 2007-11-30 23:55:42 +1100 | [diff] [blame] | 158 | struct ctl_path; |
| 159 | struct ctl_table; |
| 160 | struct ctl_table_header; |
| 161 | extern struct ctl_table_header *register_net_sysctl_table(struct net *net, |
| 162 | const struct ctl_path *path, struct ctl_table *table); |
| 163 | extern void unregister_net_sysctl_table(struct ctl_table_header *header); |
| 164 | |
Eric W. Biederman | 5f256be | 2007-09-12 11:50:50 +0200 | [diff] [blame] | 165 | #endif /* __NET_NET_NAMESPACE_H */ |