Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at b4e0f9eb8aeceb22c48fee005378bd19e25216fc 234 lines 5.3 kB view raw
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#include <net/netns/core.h> 12#include <net/netns/mib.h> 13#include <net/netns/unix.h> 14#include <net/netns/packet.h> 15#include <net/netns/ipv4.h> 16#include <net/netns/ipv6.h> 17#include <net/netns/dccp.h> 18#include <net/netns/x_tables.h> 19#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) 20#include <net/netns/conntrack.h> 21#endif 22 23struct proc_dir_entry; 24struct net_device; 25struct sock; 26struct ctl_table_header; 27struct net_generic; 28 29struct net { 30 atomic_t count; /* To decided when the network 31 * namespace should be freed. 32 */ 33#ifdef NETNS_REFCNT_DEBUG 34 atomic_t use_count; /* To track references we 35 * destroy on demand 36 */ 37#endif 38 struct list_head list; /* list of network namespaces */ 39 struct work_struct work; /* work struct for freeing */ 40 41 struct proc_dir_entry *proc_net; 42 struct proc_dir_entry *proc_net_stat; 43 44#ifdef CONFIG_SYSCTL 45 struct ctl_table_set sysctls; 46#endif 47 48 struct net_device *loopback_dev; /* The loopback */ 49 50 struct list_head dev_base_head; 51 struct hlist_head *dev_name_head; 52 struct hlist_head *dev_index_head; 53 54 /* core fib_rules */ 55 struct list_head rules_ops; 56 spinlock_t rules_mod_lock; 57 58 struct sock *rtnl; /* rtnetlink socket */ 59 60 struct netns_core core; 61 struct netns_mib mib; 62 struct netns_packet packet; 63 struct netns_unix unx; 64 struct netns_ipv4 ipv4; 65#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 66 struct netns_ipv6 ipv6; 67#endif 68#if defined(CONFIG_IP_DCCP) || defined(CONFIG_IP_DCCP_MODULE) 69 struct netns_dccp dccp; 70#endif 71#ifdef CONFIG_NETFILTER 72 struct netns_xt xt; 73#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) 74 struct netns_ct ct; 75#endif 76#endif 77 struct net_generic *gen; 78}; 79 80 81#include <linux/seq_file_net.h> 82 83/* Init's network namespace */ 84extern struct net init_net; 85 86#ifdef CONFIG_NET 87#define INIT_NET_NS(net_ns) .net_ns = &init_net, 88 89extern struct net *copy_net_ns(unsigned long flags, struct net *net_ns); 90 91#else /* CONFIG_NET */ 92 93#define INIT_NET_NS(net_ns) 94 95static inline struct net *copy_net_ns(unsigned long flags, struct net *net_ns) 96{ 97 /* There is nothing to copy so this is a noop */ 98 return net_ns; 99} 100#endif /* CONFIG_NET */ 101 102 103extern struct list_head net_namespace_list; 104 105#ifdef CONFIG_NET_NS 106extern void __put_net(struct net *net); 107 108static inline int net_alive(struct net *net) 109{ 110 return net && atomic_read(&net->count); 111} 112 113static inline struct net *get_net(struct net *net) 114{ 115 atomic_inc(&net->count); 116 return net; 117} 118 119static inline struct net *maybe_get_net(struct net *net) 120{ 121 /* Used when we know struct net exists but we 122 * aren't guaranteed a previous reference count 123 * exists. If the reference count is zero this 124 * function fails and returns NULL. 125 */ 126 if (!atomic_inc_not_zero(&net->count)) 127 net = NULL; 128 return net; 129} 130 131static inline void put_net(struct net *net) 132{ 133 if (atomic_dec_and_test(&net->count)) 134 __put_net(net); 135} 136 137static inline 138int net_eq(const struct net *net1, const struct net *net2) 139{ 140 return net1 == net2; 141} 142#else 143 144static inline int net_alive(struct net *net) 145{ 146 return 1; 147} 148 149static inline struct net *get_net(struct net *net) 150{ 151 return net; 152} 153 154static inline void put_net(struct net *net) 155{ 156} 157 158static inline struct net *maybe_get_net(struct net *net) 159{ 160 return net; 161} 162 163static inline 164int net_eq(const struct net *net1, const struct net *net2) 165{ 166 return 1; 167} 168#endif 169 170 171#ifdef NETNS_REFCNT_DEBUG 172static inline struct net *hold_net(struct net *net) 173{ 174 if (net) 175 atomic_inc(&net->use_count); 176 return net; 177} 178 179static inline void release_net(struct net *net) 180{ 181 if (net) 182 atomic_dec(&net->use_count); 183} 184#else 185static inline struct net *hold_net(struct net *net) 186{ 187 return net; 188} 189 190static inline void release_net(struct net *net) 191{ 192} 193#endif 194 195 196#define for_each_net(VAR) \ 197 list_for_each_entry(VAR, &net_namespace_list, list) 198 199#ifdef CONFIG_NET_NS 200#define __net_init 201#define __net_exit 202#define __net_initdata 203#else 204#define __net_init __init 205#define __net_exit __exit_refok 206#define __net_initdata __initdata 207#endif 208 209struct pernet_operations { 210 struct list_head list; 211 int (*init)(struct net *net); 212 void (*exit)(struct net *net); 213}; 214 215extern int register_pernet_subsys(struct pernet_operations *); 216extern void unregister_pernet_subsys(struct pernet_operations *); 217extern int register_pernet_gen_subsys(int *id, struct pernet_operations *); 218extern void unregister_pernet_gen_subsys(int id, struct pernet_operations *); 219extern int register_pernet_device(struct pernet_operations *); 220extern void unregister_pernet_device(struct pernet_operations *); 221extern int register_pernet_gen_device(int *id, struct pernet_operations *); 222extern void unregister_pernet_gen_device(int id, struct pernet_operations *); 223 224struct ctl_path; 225struct ctl_table; 226struct ctl_table_header; 227 228extern struct ctl_table_header *register_net_sysctl_table(struct net *net, 229 const struct ctl_path *path, struct ctl_table *table); 230extern struct ctl_table_header *register_net_sysctl_rotable( 231 const struct ctl_path *path, struct ctl_table *table); 232extern void unregister_net_sysctl_table(struct ctl_table_header *header); 233 234#endif /* __NET_NET_NAMESPACE_H */