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