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