Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * IP Virtual Server |
| 3 | * data structure and functionality definitions |
| 4 | */ |
| 5 | |
Julius Volz | bc4768e | 2008-07-31 20:45:24 -0700 | [diff] [blame] | 6 | #ifndef _NET_IP_VS_H |
| 7 | #define _NET_IP_VS_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
Julius Volz | bc4768e | 2008-07-31 20:45:24 -0700 | [diff] [blame] | 9 | #include <linux/ip_vs.h> /* definitions shared with userland */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | |
Julius Volz | bc4768e | 2008-07-31 20:45:24 -0700 | [diff] [blame] | 11 | /* old ipvsadm versions still include this file directly */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #ifdef __KERNEL__ |
| 13 | |
Julius Volz | bc4768e | 2008-07-31 20:45:24 -0700 | [diff] [blame] | 14 | #include <asm/types.h> /* for __uXX types */ |
| 15 | |
| 16 | #include <linux/sysctl.h> /* for ctl_path */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/list.h> /* for struct list_head */ |
| 18 | #include <linux/spinlock.h> /* for struct rwlock_t */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <asm/atomic.h> /* for struct atomic_t */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/compiler.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 21 | #include <linux/timer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 23 | #include <net/checksum.h> |
Julius Volz | e7ade46 | 2008-09-02 15:55:33 +0200 | [diff] [blame] | 24 | #include <linux/netfilter.h> /* for union nf_inet_addr */ |
KOVACS Krisztian | 1668e01 | 2008-10-01 07:33:10 -0700 | [diff] [blame] | 25 | #include <linux/ip.h> |
Julius Volz | e7ade46 | 2008-09-02 15:55:33 +0200 | [diff] [blame] | 26 | #include <linux/ipv6.h> /* for struct ipv6hdr */ |
| 27 | #include <net/ipv6.h> /* for ipv6_addr_copy */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
Catalin(ux) M. BOIE | 6f7edb4 | 2010-01-05 05:50:24 +0100 | [diff] [blame^] | 29 | |
| 30 | /* Connections' size value needed by ip_vs_ctl.c */ |
| 31 | extern int ip_vs_conn_tab_size; |
| 32 | |
| 33 | |
Julius Volz | 64aae3c | 2008-09-02 15:55:34 +0200 | [diff] [blame] | 34 | struct ip_vs_iphdr { |
| 35 | int len; |
| 36 | __u8 protocol; |
| 37 | union nf_inet_addr saddr; |
| 38 | union nf_inet_addr daddr; |
| 39 | }; |
| 40 | |
| 41 | static inline void |
| 42 | ip_vs_fill_iphdr(int af, const void *nh, struct ip_vs_iphdr *iphdr) |
| 43 | { |
| 44 | #ifdef CONFIG_IP_VS_IPV6 |
| 45 | if (af == AF_INET6) { |
| 46 | const struct ipv6hdr *iph = nh; |
| 47 | iphdr->len = sizeof(struct ipv6hdr); |
| 48 | iphdr->protocol = iph->nexthdr; |
| 49 | ipv6_addr_copy(&iphdr->saddr.in6, &iph->saddr); |
| 50 | ipv6_addr_copy(&iphdr->daddr.in6, &iph->daddr); |
| 51 | } else |
| 52 | #endif |
| 53 | { |
| 54 | const struct iphdr *iph = nh; |
| 55 | iphdr->len = iph->ihl * 4; |
| 56 | iphdr->protocol = iph->protocol; |
| 57 | iphdr->saddr.ip = iph->saddr; |
| 58 | iphdr->daddr.ip = iph->daddr; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst, |
| 63 | const union nf_inet_addr *src) |
| 64 | { |
| 65 | #ifdef CONFIG_IP_VS_IPV6 |
| 66 | if (af == AF_INET6) |
| 67 | ipv6_addr_copy(&dst->in6, &src->in6); |
| 68 | else |
| 69 | #endif |
| 70 | dst->ip = src->ip; |
| 71 | } |
| 72 | |
| 73 | static inline int ip_vs_addr_equal(int af, const union nf_inet_addr *a, |
| 74 | const union nf_inet_addr *b) |
| 75 | { |
| 76 | #ifdef CONFIG_IP_VS_IPV6 |
| 77 | if (af == AF_INET6) |
| 78 | return ipv6_addr_equal(&a->in6, &b->in6); |
| 79 | #endif |
| 80 | return a->ip == b->ip; |
| 81 | } |
| 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | #ifdef CONFIG_IP_VS_DEBUG |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 84 | #include <linux/net.h> |
| 85 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | extern int ip_vs_get_debug_level(void); |
Julius Volz | c842a3a | 2008-09-02 15:55:35 +0200 | [diff] [blame] | 87 | |
| 88 | static inline const char *ip_vs_dbg_addr(int af, char *buf, size_t buf_len, |
| 89 | const union nf_inet_addr *addr, |
| 90 | int *idx) |
| 91 | { |
| 92 | int len; |
| 93 | #ifdef CONFIG_IP_VS_IPV6 |
| 94 | if (af == AF_INET6) |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 95 | len = snprintf(&buf[*idx], buf_len - *idx, "[%pI6]", |
Harvey Harrison | 0c6ce78 | 2008-10-28 16:09:23 -0700 | [diff] [blame] | 96 | &addr->in6) + 1; |
Julius Volz | c842a3a | 2008-09-02 15:55:35 +0200 | [diff] [blame] | 97 | else |
| 98 | #endif |
Harvey Harrison | 3685f25d | 2008-10-31 00:56:49 -0700 | [diff] [blame] | 99 | len = snprintf(&buf[*idx], buf_len - *idx, "%pI4", |
| 100 | &addr->ip) + 1; |
Julius Volz | c842a3a | 2008-09-02 15:55:35 +0200 | [diff] [blame] | 101 | |
| 102 | *idx += len; |
| 103 | BUG_ON(*idx > buf_len + 1); |
| 104 | return &buf[*idx - len]; |
| 105 | } |
| 106 | |
Hannes Eder | 9aada7a | 2009-07-30 14:29:44 -0700 | [diff] [blame] | 107 | #define IP_VS_DBG_BUF(level, msg, ...) \ |
| 108 | do { \ |
| 109 | char ip_vs_dbg_buf[160]; \ |
| 110 | int ip_vs_dbg_idx = 0; \ |
| 111 | if (level <= ip_vs_get_debug_level()) \ |
| 112 | printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \ |
| 113 | } while (0) |
| 114 | #define IP_VS_ERR_BUF(msg...) \ |
| 115 | do { \ |
| 116 | char ip_vs_dbg_buf[160]; \ |
| 117 | int ip_vs_dbg_idx = 0; \ |
| 118 | pr_err(msg); \ |
| 119 | } while (0) |
Julius Volz | c842a3a | 2008-09-02 15:55:35 +0200 | [diff] [blame] | 120 | |
| 121 | /* Only use from within IP_VS_DBG_BUF() or IP_VS_ERR_BUF macros */ |
Hannes Eder | 9aada7a | 2009-07-30 14:29:44 -0700 | [diff] [blame] | 122 | #define IP_VS_DBG_ADDR(af, addr) \ |
| 123 | ip_vs_dbg_addr(af, ip_vs_dbg_buf, \ |
| 124 | sizeof(ip_vs_dbg_buf), addr, \ |
| 125 | &ip_vs_dbg_idx) |
Julius Volz | c842a3a | 2008-09-02 15:55:35 +0200 | [diff] [blame] | 126 | |
Hannes Eder | 9aada7a | 2009-07-30 14:29:44 -0700 | [diff] [blame] | 127 | #define IP_VS_DBG(level, msg, ...) \ |
| 128 | do { \ |
| 129 | if (level <= ip_vs_get_debug_level()) \ |
| 130 | printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \ |
| 131 | } while (0) |
| 132 | #define IP_VS_DBG_RL(msg, ...) \ |
| 133 | do { \ |
| 134 | if (net_ratelimit()) \ |
| 135 | printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \ |
| 136 | } while (0) |
| 137 | #define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) \ |
| 138 | do { \ |
| 139 | if (level <= ip_vs_get_debug_level()) \ |
| 140 | pp->debug_packet(pp, skb, ofs, msg); \ |
| 141 | } while (0) |
| 142 | #define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) \ |
| 143 | do { \ |
| 144 | if (level <= ip_vs_get_debug_level() && \ |
| 145 | net_ratelimit()) \ |
| 146 | pp->debug_packet(pp, skb, ofs, msg); \ |
| 147 | } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | #else /* NO DEBUGGING at ALL */ |
Julius Volz | c842a3a | 2008-09-02 15:55:35 +0200 | [diff] [blame] | 149 | #define IP_VS_DBG_BUF(level, msg...) do {} while (0) |
| 150 | #define IP_VS_ERR_BUF(msg...) do {} while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | #define IP_VS_DBG(level, msg...) do {} while (0) |
| 152 | #define IP_VS_DBG_RL(msg...) do {} while (0) |
| 153 | #define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) do {} while (0) |
| 154 | #define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) do {} while (0) |
| 155 | #endif |
| 156 | |
| 157 | #define IP_VS_BUG() BUG() |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 158 | #define IP_VS_ERR_RL(msg, ...) \ |
Hannes Eder | 9aada7a | 2009-07-30 14:29:44 -0700 | [diff] [blame] | 159 | do { \ |
| 160 | if (net_ratelimit()) \ |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 161 | pr_err(msg, ##__VA_ARGS__); \ |
Hannes Eder | 9aada7a | 2009-07-30 14:29:44 -0700 | [diff] [blame] | 162 | } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | |
| 164 | #ifdef CONFIG_IP_VS_DEBUG |
| 165 | #define EnterFunction(level) \ |
Hannes Eder | 9aada7a | 2009-07-30 14:29:44 -0700 | [diff] [blame] | 166 | do { \ |
| 167 | if (level <= ip_vs_get_debug_level()) \ |
| 168 | printk(KERN_DEBUG \ |
| 169 | pr_fmt("Enter: %s, %s line %i\n"), \ |
| 170 | __func__, __FILE__, __LINE__); \ |
| 171 | } while (0) |
| 172 | #define LeaveFunction(level) \ |
| 173 | do { \ |
| 174 | if (level <= ip_vs_get_debug_level()) \ |
| 175 | printk(KERN_DEBUG \ |
| 176 | pr_fmt("Leave: %s, %s line %i\n"), \ |
| 177 | __func__, __FILE__, __LINE__); \ |
| 178 | } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | #else |
| 180 | #define EnterFunction(level) do {} while (0) |
| 181 | #define LeaveFunction(level) do {} while (0) |
| 182 | #endif |
| 183 | |
| 184 | #define IP_VS_WAIT_WHILE(expr) while (expr) { cpu_relax(); } |
| 185 | |
| 186 | |
| 187 | /* |
| 188 | * The port number of FTP service (in network order). |
| 189 | */ |
Harvey Harrison | f3a7c66 | 2009-02-14 22:58:35 -0800 | [diff] [blame] | 190 | #define FTPPORT cpu_to_be16(21) |
| 191 | #define FTPDATA cpu_to_be16(20) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
| 193 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | * TCP State Values |
| 195 | */ |
| 196 | enum { |
| 197 | IP_VS_TCP_S_NONE = 0, |
| 198 | IP_VS_TCP_S_ESTABLISHED, |
| 199 | IP_VS_TCP_S_SYN_SENT, |
| 200 | IP_VS_TCP_S_SYN_RECV, |
| 201 | IP_VS_TCP_S_FIN_WAIT, |
| 202 | IP_VS_TCP_S_TIME_WAIT, |
| 203 | IP_VS_TCP_S_CLOSE, |
| 204 | IP_VS_TCP_S_CLOSE_WAIT, |
| 205 | IP_VS_TCP_S_LAST_ACK, |
| 206 | IP_VS_TCP_S_LISTEN, |
| 207 | IP_VS_TCP_S_SYNACK, |
| 208 | IP_VS_TCP_S_LAST |
| 209 | }; |
| 210 | |
| 211 | /* |
| 212 | * UDP State Values |
| 213 | */ |
| 214 | enum { |
| 215 | IP_VS_UDP_S_NORMAL, |
| 216 | IP_VS_UDP_S_LAST, |
| 217 | }; |
| 218 | |
| 219 | /* |
| 220 | * ICMP State Values |
| 221 | */ |
| 222 | enum { |
| 223 | IP_VS_ICMP_S_NORMAL, |
| 224 | IP_VS_ICMP_S_LAST, |
| 225 | }; |
| 226 | |
| 227 | /* |
| 228 | * Delta sequence info structure |
| 229 | * Each ip_vs_conn has 2 (output AND input seq. changes). |
| 230 | * Only used in the VS/NAT. |
| 231 | */ |
| 232 | struct ip_vs_seq { |
| 233 | __u32 init_seq; /* Add delta from this seq */ |
| 234 | __u32 delta; /* Delta in sequence numbers */ |
| 235 | __u32 previous_delta; /* Delta in sequence numbers |
| 236 | before last resized pkt */ |
| 237 | }; |
| 238 | |
| 239 | |
| 240 | /* |
Sven Wegener | 3a14a313 | 2008-08-10 18:24:41 +0000 | [diff] [blame] | 241 | * IPVS statistics objects |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | */ |
Sven Wegener | 3a14a313 | 2008-08-10 18:24:41 +0000 | [diff] [blame] | 243 | struct ip_vs_estimator { |
| 244 | struct list_head list; |
| 245 | |
| 246 | u64 last_inbytes; |
| 247 | u64 last_outbytes; |
| 248 | u32 last_conns; |
| 249 | u32 last_inpkts; |
| 250 | u32 last_outpkts; |
| 251 | |
| 252 | u32 cps; |
| 253 | u32 inpps; |
| 254 | u32 outpps; |
| 255 | u32 inbps; |
| 256 | u32 outbps; |
| 257 | }; |
| 258 | |
Eric Dumazet | fd2c3ef | 2009-11-03 03:26:03 +0000 | [diff] [blame] | 259 | struct ip_vs_stats { |
Sven Wegener | e9c0ce2 | 2008-09-08 13:39:04 +0200 | [diff] [blame] | 260 | struct ip_vs_stats_user ustats; /* statistics */ |
| 261 | struct ip_vs_estimator est; /* estimator */ |
Sven Wegener | 3a14a313 | 2008-08-10 18:24:41 +0000 | [diff] [blame] | 262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | spinlock_t lock; /* spin lock */ |
| 264 | }; |
| 265 | |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 266 | struct dst_entry; |
| 267 | struct iphdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | struct ip_vs_conn; |
| 269 | struct ip_vs_app; |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 270 | struct sk_buff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
| 272 | struct ip_vs_protocol { |
| 273 | struct ip_vs_protocol *next; |
| 274 | char *name; |
Julian Anastasov | 2ad17de | 2008-04-29 03:21:23 -0700 | [diff] [blame] | 275 | u16 protocol; |
| 276 | u16 num_states; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | int dont_defrag; |
| 278 | atomic_t appcnt; /* counter of proto app incs */ |
| 279 | int *timeout_table; /* protocol timeout table */ |
| 280 | |
| 281 | void (*init)(struct ip_vs_protocol *pp); |
| 282 | |
| 283 | void (*exit)(struct ip_vs_protocol *pp); |
| 284 | |
Julius Volz | 51ef348 | 2008-09-02 15:55:40 +0200 | [diff] [blame] | 285 | int (*conn_schedule)(int af, struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | struct ip_vs_protocol *pp, |
| 287 | int *verdict, struct ip_vs_conn **cpp); |
| 288 | |
| 289 | struct ip_vs_conn * |
Julius Volz | 51ef348 | 2008-09-02 15:55:40 +0200 | [diff] [blame] | 290 | (*conn_in_get)(int af, |
| 291 | const struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | struct ip_vs_protocol *pp, |
Julius Volz | 51ef348 | 2008-09-02 15:55:40 +0200 | [diff] [blame] | 293 | const struct ip_vs_iphdr *iph, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | unsigned int proto_off, |
| 295 | int inverse); |
| 296 | |
| 297 | struct ip_vs_conn * |
Julius Volz | 51ef348 | 2008-09-02 15:55:40 +0200 | [diff] [blame] | 298 | (*conn_out_get)(int af, |
| 299 | const struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | struct ip_vs_protocol *pp, |
Julius Volz | 51ef348 | 2008-09-02 15:55:40 +0200 | [diff] [blame] | 301 | const struct ip_vs_iphdr *iph, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | unsigned int proto_off, |
| 303 | int inverse); |
| 304 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 305 | int (*snat_handler)(struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | struct ip_vs_protocol *pp, struct ip_vs_conn *cp); |
| 307 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 308 | int (*dnat_handler)(struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | struct ip_vs_protocol *pp, struct ip_vs_conn *cp); |
| 310 | |
Julius Volz | 51ef348 | 2008-09-02 15:55:40 +0200 | [diff] [blame] | 311 | int (*csum_check)(int af, struct sk_buff *skb, |
| 312 | struct ip_vs_protocol *pp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
| 314 | const char *(*state_name)(int state); |
| 315 | |
| 316 | int (*state_transition)(struct ip_vs_conn *cp, int direction, |
| 317 | const struct sk_buff *skb, |
| 318 | struct ip_vs_protocol *pp); |
| 319 | |
| 320 | int (*register_app)(struct ip_vs_app *inc); |
| 321 | |
| 322 | void (*unregister_app)(struct ip_vs_app *inc); |
| 323 | |
| 324 | int (*app_conn_bind)(struct ip_vs_conn *cp); |
| 325 | |
| 326 | void (*debug_packet)(struct ip_vs_protocol *pp, |
| 327 | const struct sk_buff *skb, |
| 328 | int offset, |
| 329 | const char *msg); |
| 330 | |
| 331 | void (*timeout_change)(struct ip_vs_protocol *pp, int flags); |
| 332 | |
| 333 | int (*set_state_timeout)(struct ip_vs_protocol *pp, char *sname, int to); |
| 334 | }; |
| 335 | |
| 336 | extern struct ip_vs_protocol * ip_vs_proto_get(unsigned short proto); |
| 337 | |
| 338 | /* |
| 339 | * IP_VS structure allocated for each dynamically scheduled connection |
| 340 | */ |
| 341 | struct ip_vs_conn { |
| 342 | struct list_head c_list; /* hashed list heads */ |
| 343 | |
| 344 | /* Protocol, addresses and port numbers */ |
Julius Volz | e7ade46 | 2008-09-02 15:55:33 +0200 | [diff] [blame] | 345 | u16 af; /* address family */ |
| 346 | union nf_inet_addr caddr; /* client address */ |
| 347 | union nf_inet_addr vaddr; /* virtual address */ |
| 348 | union nf_inet_addr daddr; /* destination address */ |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 349 | __be16 cport; |
| 350 | __be16 vport; |
| 351 | __be16 dport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | __u16 protocol; /* Which protocol (TCP/UDP) */ |
| 353 | |
| 354 | /* counter and timer */ |
| 355 | atomic_t refcnt; /* reference count */ |
| 356 | struct timer_list timer; /* Expiration timer */ |
| 357 | volatile unsigned long timeout; /* timeout */ |
| 358 | |
| 359 | /* Flags and state transition */ |
| 360 | spinlock_t lock; /* lock for state transition */ |
| 361 | volatile __u16 flags; /* status flags */ |
| 362 | volatile __u16 state; /* state info */ |
Rumen G. Bogdanovski | efac527 | 2007-11-07 02:36:55 -0800 | [diff] [blame] | 363 | volatile __u16 old_state; /* old state, to be used for |
| 364 | * state transition triggerd |
| 365 | * synchronization |
| 366 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | |
| 368 | /* Control members */ |
| 369 | struct ip_vs_conn *control; /* Master control connection */ |
| 370 | atomic_t n_control; /* Number of controlled ones */ |
| 371 | struct ip_vs_dest *dest; /* real server */ |
| 372 | atomic_t in_pkts; /* incoming packet counter */ |
| 373 | |
| 374 | /* packet transmitter for different forwarding methods. If it |
| 375 | mangles the packet, it must return NF_DROP or better NF_STOLEN, |
| 376 | otherwise this must be changed to a sk_buff **. |
| 377 | */ |
| 378 | int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp, |
| 379 | struct ip_vs_protocol *pp); |
| 380 | |
| 381 | /* Note: we can group the following members into a structure, |
| 382 | in order to save more space, and the following members are |
| 383 | only used in VS/NAT anyway */ |
| 384 | struct ip_vs_app *app; /* bound ip_vs_app object */ |
| 385 | void *app_data; /* Application private data */ |
| 386 | struct ip_vs_seq in_seq; /* incoming seq. struct */ |
| 387 | struct ip_vs_seq out_seq; /* outgoing seq. struct */ |
| 388 | }; |
| 389 | |
| 390 | |
| 391 | /* |
Julius Volz | c860c6b | 2008-09-02 15:55:36 +0200 | [diff] [blame] | 392 | * Extended internal versions of struct ip_vs_service_user and |
| 393 | * ip_vs_dest_user for IPv6 support. |
| 394 | * |
| 395 | * We need these to conveniently pass around service and destination |
| 396 | * options, but unfortunately, we also need to keep the old definitions to |
| 397 | * maintain userspace backwards compatibility for the setsockopt interface. |
| 398 | */ |
| 399 | struct ip_vs_service_user_kern { |
| 400 | /* virtual service addresses */ |
| 401 | u16 af; |
| 402 | u16 protocol; |
| 403 | union nf_inet_addr addr; /* virtual ip address */ |
| 404 | u16 port; |
| 405 | u32 fwmark; /* firwall mark of service */ |
| 406 | |
| 407 | /* virtual service options */ |
| 408 | char *sched_name; |
| 409 | unsigned flags; /* virtual service flags */ |
| 410 | unsigned timeout; /* persistent timeout in sec */ |
| 411 | u32 netmask; /* persistent netmask */ |
| 412 | }; |
| 413 | |
| 414 | |
| 415 | struct ip_vs_dest_user_kern { |
| 416 | /* destination server address */ |
| 417 | union nf_inet_addr addr; |
| 418 | u16 port; |
| 419 | |
| 420 | /* real server options */ |
| 421 | unsigned conn_flags; /* connection flags */ |
| 422 | int weight; /* destination weight */ |
| 423 | |
| 424 | /* thresholds for active connections */ |
| 425 | u32 u_threshold; /* upper threshold */ |
| 426 | u32 l_threshold; /* lower threshold */ |
| 427 | }; |
| 428 | |
| 429 | |
| 430 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | * The information about the virtual service offered to the net |
| 432 | * and the forwarding entries |
| 433 | */ |
| 434 | struct ip_vs_service { |
| 435 | struct list_head s_list; /* for normal service table */ |
| 436 | struct list_head f_list; /* for fwmark-based service table */ |
| 437 | atomic_t refcnt; /* reference counter */ |
| 438 | atomic_t usecnt; /* use counter */ |
| 439 | |
Julius Volz | e7ade46 | 2008-09-02 15:55:33 +0200 | [diff] [blame] | 440 | u16 af; /* address family */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | __u16 protocol; /* which protocol (TCP/UDP) */ |
Julius Volz | e7ade46 | 2008-09-02 15:55:33 +0200 | [diff] [blame] | 442 | union nf_inet_addr addr; /* IP address for virtual service */ |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 443 | __be16 port; /* port number for the service */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | __u32 fwmark; /* firewall mark of the service */ |
| 445 | unsigned flags; /* service status flags */ |
| 446 | unsigned timeout; /* persistent timeout in ticks */ |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 447 | __be32 netmask; /* grouping granularity */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
| 449 | struct list_head destinations; /* real server d-linked list */ |
| 450 | __u32 num_dests; /* number of servers */ |
| 451 | struct ip_vs_stats stats; /* statistics for the service */ |
| 452 | struct ip_vs_app *inc; /* bind conns to this app inc */ |
| 453 | |
| 454 | /* for scheduling */ |
| 455 | struct ip_vs_scheduler *scheduler; /* bound scheduler object */ |
| 456 | rwlock_t sched_lock; /* lock sched_data */ |
| 457 | void *sched_data; /* scheduler application data */ |
| 458 | }; |
| 459 | |
| 460 | |
| 461 | /* |
| 462 | * The real server destination forwarding entry |
| 463 | * with ip address, port number, and so on. |
| 464 | */ |
| 465 | struct ip_vs_dest { |
| 466 | struct list_head n_list; /* for the dests in the service */ |
| 467 | struct list_head d_list; /* for table with all the dests */ |
| 468 | |
Julius Volz | e7ade46 | 2008-09-02 15:55:33 +0200 | [diff] [blame] | 469 | u16 af; /* address family */ |
| 470 | union nf_inet_addr addr; /* IP address of the server */ |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 471 | __be16 port; /* port number of the server */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | volatile unsigned flags; /* dest status flags */ |
| 473 | atomic_t conn_flags; /* flags to copy to conn */ |
| 474 | atomic_t weight; /* server weight */ |
| 475 | |
| 476 | atomic_t refcnt; /* reference counter */ |
| 477 | struct ip_vs_stats stats; /* statistics */ |
| 478 | |
| 479 | /* connection counters and thresholds */ |
| 480 | atomic_t activeconns; /* active connections */ |
| 481 | atomic_t inactconns; /* inactive connections */ |
| 482 | atomic_t persistconns; /* persistent connections */ |
| 483 | __u32 u_threshold; /* upper threshold */ |
| 484 | __u32 l_threshold; /* lower threshold */ |
| 485 | |
| 486 | /* for destination cache */ |
| 487 | spinlock_t dst_lock; /* lock of dst_cache */ |
| 488 | struct dst_entry *dst_cache; /* destination cache entry */ |
| 489 | u32 dst_rtos; /* RT_TOS(tos) for dst */ |
| 490 | |
| 491 | /* for virtual service */ |
| 492 | struct ip_vs_service *svc; /* service it belongs to */ |
| 493 | __u16 protocol; /* which protocol (TCP/UDP) */ |
Julius Volz | e7ade46 | 2008-09-02 15:55:33 +0200 | [diff] [blame] | 494 | union nf_inet_addr vaddr; /* virtual IP address */ |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 495 | __be16 vport; /* virtual port number */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | __u32 vfwmark; /* firewall mark of service */ |
| 497 | }; |
| 498 | |
| 499 | |
| 500 | /* |
| 501 | * The scheduler object |
| 502 | */ |
| 503 | struct ip_vs_scheduler { |
| 504 | struct list_head n_list; /* d-linked list head */ |
| 505 | char *name; /* scheduler name */ |
| 506 | atomic_t refcnt; /* reference counter */ |
| 507 | struct module *module; /* THIS_MODULE/NULL */ |
| 508 | |
| 509 | /* scheduler initializing service */ |
| 510 | int (*init_service)(struct ip_vs_service *svc); |
| 511 | /* scheduling service finish */ |
| 512 | int (*done_service)(struct ip_vs_service *svc); |
| 513 | /* scheduler updating service */ |
| 514 | int (*update_service)(struct ip_vs_service *svc); |
| 515 | |
| 516 | /* selecting a server from the given service */ |
| 517 | struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc, |
| 518 | const struct sk_buff *skb); |
| 519 | }; |
| 520 | |
| 521 | |
| 522 | /* |
| 523 | * The application module object (a.k.a. app incarnation) |
| 524 | */ |
Eric Dumazet | fd2c3ef | 2009-11-03 03:26:03 +0000 | [diff] [blame] | 525 | struct ip_vs_app { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | struct list_head a_list; /* member in app list */ |
| 527 | int type; /* IP_VS_APP_TYPE_xxx */ |
| 528 | char *name; /* application module name */ |
| 529 | __u16 protocol; |
| 530 | struct module *module; /* THIS_MODULE/NULL */ |
| 531 | struct list_head incs_list; /* list of incarnations */ |
| 532 | |
| 533 | /* members for application incarnations */ |
| 534 | struct list_head p_list; /* member in proto app list */ |
| 535 | struct ip_vs_app *app; /* its real application */ |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 536 | __be16 port; /* port number in net order */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | atomic_t usecnt; /* usage counter */ |
| 538 | |
| 539 | /* output hook: return false if can't linearize. diff set for TCP. */ |
| 540 | int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *, |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 541 | struct sk_buff *, int *diff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | |
| 543 | /* input hook: return false if can't linearize. diff set for TCP. */ |
| 544 | int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *, |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 545 | struct sk_buff *, int *diff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
| 547 | /* ip_vs_app initializer */ |
| 548 | int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *); |
| 549 | |
| 550 | /* ip_vs_app finish */ |
| 551 | int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *); |
| 552 | |
| 553 | |
| 554 | /* not used now */ |
| 555 | int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *, |
| 556 | struct ip_vs_protocol *); |
| 557 | |
| 558 | void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *); |
| 559 | |
| 560 | int * timeout_table; |
| 561 | int * timeouts; |
| 562 | int timeouts_size; |
| 563 | |
| 564 | int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app, |
| 565 | int *verdict, struct ip_vs_conn **cpp); |
| 566 | |
| 567 | struct ip_vs_conn * |
| 568 | (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app, |
| 569 | const struct iphdr *iph, unsigned int proto_off, |
| 570 | int inverse); |
| 571 | |
| 572 | struct ip_vs_conn * |
| 573 | (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app, |
| 574 | const struct iphdr *iph, unsigned int proto_off, |
| 575 | int inverse); |
| 576 | |
| 577 | int (*state_transition)(struct ip_vs_conn *cp, int direction, |
| 578 | const struct sk_buff *skb, |
| 579 | struct ip_vs_app *app); |
| 580 | |
| 581 | void (*timeout_change)(struct ip_vs_app *app, int flags); |
| 582 | }; |
| 583 | |
| 584 | |
| 585 | /* |
| 586 | * IPVS core functions |
| 587 | * (from ip_vs_core.c) |
| 588 | */ |
| 589 | extern const char *ip_vs_proto_name(unsigned proto); |
| 590 | extern void ip_vs_init_hash_table(struct list_head *table, int rows); |
Sven Wegener | afdd614 | 2008-08-10 09:18:01 +0000 | [diff] [blame] | 591 | #define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | #define IP_VS_APP_TYPE_FTP 1 |
| 594 | |
| 595 | /* |
| 596 | * ip_vs_conn handling functions |
| 597 | * (from ip_vs_conn.c) |
| 598 | */ |
| 599 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | enum { |
| 601 | IP_VS_DIR_INPUT = 0, |
| 602 | IP_VS_DIR_OUTPUT, |
| 603 | IP_VS_DIR_INPUT_ONLY, |
| 604 | IP_VS_DIR_LAST, |
| 605 | }; |
| 606 | |
| 607 | extern struct ip_vs_conn *ip_vs_conn_in_get |
Julius Volz | 28364a5 | 2008-09-02 15:55:43 +0200 | [diff] [blame] | 608 | (int af, int protocol, const union nf_inet_addr *s_addr, __be16 s_port, |
| 609 | const union nf_inet_addr *d_addr, __be16 d_port); |
| 610 | |
Julian Anastasov | 87375ab | 2005-09-14 21:08:51 -0700 | [diff] [blame] | 611 | extern struct ip_vs_conn *ip_vs_ct_in_get |
Julius Volz | 28364a5 | 2008-09-02 15:55:43 +0200 | [diff] [blame] | 612 | (int af, int protocol, const union nf_inet_addr *s_addr, __be16 s_port, |
| 613 | const union nf_inet_addr *d_addr, __be16 d_port); |
| 614 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | extern struct ip_vs_conn *ip_vs_conn_out_get |
Julius Volz | 28364a5 | 2008-09-02 15:55:43 +0200 | [diff] [blame] | 616 | (int af, int protocol, const union nf_inet_addr *s_addr, __be16 s_port, |
| 617 | const union nf_inet_addr *d_addr, __be16 d_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
| 619 | /* put back the conn without restarting its timer */ |
| 620 | static inline void __ip_vs_conn_put(struct ip_vs_conn *cp) |
| 621 | { |
| 622 | atomic_dec(&cp->refcnt); |
| 623 | } |
| 624 | extern void ip_vs_conn_put(struct ip_vs_conn *cp); |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 625 | extern void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | |
| 627 | extern struct ip_vs_conn * |
Julius Volz | 28364a5 | 2008-09-02 15:55:43 +0200 | [diff] [blame] | 628 | ip_vs_conn_new(int af, int proto, const union nf_inet_addr *caddr, __be16 cport, |
| 629 | const union nf_inet_addr *vaddr, __be16 vport, |
| 630 | const union nf_inet_addr *daddr, __be16 dport, unsigned flags, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | struct ip_vs_dest *dest); |
| 632 | extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp); |
| 633 | |
| 634 | extern const char * ip_vs_state_name(__u16 proto, int state); |
| 635 | |
| 636 | extern void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp); |
| 637 | extern int ip_vs_check_template(struct ip_vs_conn *ct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | extern void ip_vs_random_dropentry(void); |
| 639 | extern int ip_vs_conn_init(void); |
| 640 | extern void ip_vs_conn_cleanup(void); |
| 641 | |
| 642 | static inline void ip_vs_control_del(struct ip_vs_conn *cp) |
| 643 | { |
| 644 | struct ip_vs_conn *ctl_cp = cp->control; |
| 645 | if (!ctl_cp) { |
Julius Volz | cfc78c5 | 2008-09-02 15:55:53 +0200 | [diff] [blame] | 646 | IP_VS_ERR_BUF("request control DEL for uncontrolled: " |
| 647 | "%s:%d to %s:%d\n", |
| 648 | IP_VS_DBG_ADDR(cp->af, &cp->caddr), |
| 649 | ntohs(cp->cport), |
| 650 | IP_VS_DBG_ADDR(cp->af, &cp->vaddr), |
| 651 | ntohs(cp->vport)); |
| 652 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | return; |
| 654 | } |
| 655 | |
Julius Volz | cfc78c5 | 2008-09-02 15:55:53 +0200 | [diff] [blame] | 656 | IP_VS_DBG_BUF(7, "DELeting control for: " |
| 657 | "cp.dst=%s:%d ctl_cp.dst=%s:%d\n", |
| 658 | IP_VS_DBG_ADDR(cp->af, &cp->caddr), |
| 659 | ntohs(cp->cport), |
| 660 | IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr), |
| 661 | ntohs(ctl_cp->cport)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | |
| 663 | cp->control = NULL; |
| 664 | if (atomic_read(&ctl_cp->n_control) == 0) { |
Julius Volz | cfc78c5 | 2008-09-02 15:55:53 +0200 | [diff] [blame] | 665 | IP_VS_ERR_BUF("BUG control DEL with n=0 : " |
| 666 | "%s:%d to %s:%d\n", |
| 667 | IP_VS_DBG_ADDR(cp->af, &cp->caddr), |
| 668 | ntohs(cp->cport), |
| 669 | IP_VS_DBG_ADDR(cp->af, &cp->vaddr), |
| 670 | ntohs(cp->vport)); |
| 671 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | return; |
| 673 | } |
| 674 | atomic_dec(&ctl_cp->n_control); |
| 675 | } |
| 676 | |
| 677 | static inline void |
| 678 | ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp) |
| 679 | { |
| 680 | if (cp->control) { |
Julius Volz | cfc78c5 | 2008-09-02 15:55:53 +0200 | [diff] [blame] | 681 | IP_VS_ERR_BUF("request control ADD for already controlled: " |
| 682 | "%s:%d to %s:%d\n", |
| 683 | IP_VS_DBG_ADDR(cp->af, &cp->caddr), |
| 684 | ntohs(cp->cport), |
| 685 | IP_VS_DBG_ADDR(cp->af, &cp->vaddr), |
| 686 | ntohs(cp->vport)); |
| 687 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | ip_vs_control_del(cp); |
| 689 | } |
| 690 | |
Julius Volz | cfc78c5 | 2008-09-02 15:55:53 +0200 | [diff] [blame] | 691 | IP_VS_DBG_BUF(7, "ADDing control for: " |
| 692 | "cp.dst=%s:%d ctl_cp.dst=%s:%d\n", |
| 693 | IP_VS_DBG_ADDR(cp->af, &cp->caddr), |
| 694 | ntohs(cp->cport), |
| 695 | IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr), |
| 696 | ntohs(ctl_cp->cport)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | |
| 698 | cp->control = ctl_cp; |
| 699 | atomic_inc(&ctl_cp->n_control); |
| 700 | } |
| 701 | |
| 702 | |
| 703 | /* |
| 704 | * IPVS application functions |
| 705 | * (from ip_vs_app.c) |
| 706 | */ |
| 707 | #define IP_VS_APP_MAX_PORTS 8 |
| 708 | extern int register_ip_vs_app(struct ip_vs_app *app); |
| 709 | extern void unregister_ip_vs_app(struct ip_vs_app *app); |
| 710 | extern int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
| 711 | extern void ip_vs_unbind_app(struct ip_vs_conn *cp); |
| 712 | extern int |
| 713 | register_ip_vs_app_inc(struct ip_vs_app *app, __u16 proto, __u16 port); |
| 714 | extern int ip_vs_app_inc_get(struct ip_vs_app *inc); |
| 715 | extern void ip_vs_app_inc_put(struct ip_vs_app *inc); |
| 716 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 717 | extern int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb); |
| 718 | extern int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb); |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 719 | extern int ip_vs_skb_replace(struct sk_buff *skb, gfp_t pri, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | char *o_buf, int o_len, char *n_buf, int n_len); |
| 721 | extern int ip_vs_app_init(void); |
| 722 | extern void ip_vs_app_cleanup(void); |
| 723 | |
| 724 | |
| 725 | /* |
| 726 | * IPVS protocol functions (from ip_vs_proto.c) |
| 727 | */ |
| 728 | extern int ip_vs_protocol_init(void); |
| 729 | extern void ip_vs_protocol_cleanup(void); |
| 730 | extern void ip_vs_protocol_timeout_change(int flags); |
| 731 | extern int *ip_vs_create_timeout_table(int *table, int size); |
| 732 | extern int |
Jan Engelhardt | 36cbd3d | 2009-08-05 10:42:58 -0700 | [diff] [blame] | 733 | ip_vs_set_state_timeout(int *table, int num, const char *const *names, |
| 734 | const char *name, int to); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | extern void |
| 736 | ip_vs_tcpudp_debug_packet(struct ip_vs_protocol *pp, const struct sk_buff *skb, |
| 737 | int offset, const char *msg); |
| 738 | |
| 739 | extern struct ip_vs_protocol ip_vs_protocol_tcp; |
| 740 | extern struct ip_vs_protocol ip_vs_protocol_udp; |
| 741 | extern struct ip_vs_protocol ip_vs_protocol_icmp; |
| 742 | extern struct ip_vs_protocol ip_vs_protocol_esp; |
| 743 | extern struct ip_vs_protocol ip_vs_protocol_ah; |
| 744 | |
| 745 | |
| 746 | /* |
| 747 | * Registering/unregistering scheduler functions |
| 748 | * (from ip_vs_sched.c) |
| 749 | */ |
| 750 | extern int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler); |
| 751 | extern int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler); |
| 752 | extern int ip_vs_bind_scheduler(struct ip_vs_service *svc, |
| 753 | struct ip_vs_scheduler *scheduler); |
| 754 | extern int ip_vs_unbind_scheduler(struct ip_vs_service *svc); |
| 755 | extern struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name); |
| 756 | extern void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler); |
| 757 | extern struct ip_vs_conn * |
| 758 | ip_vs_schedule(struct ip_vs_service *svc, const struct sk_buff *skb); |
| 759 | extern int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb, |
| 760 | struct ip_vs_protocol *pp); |
| 761 | |
| 762 | |
| 763 | /* |
| 764 | * IPVS control data and functions (from ip_vs_ctl.c) |
| 765 | */ |
| 766 | extern int sysctl_ip_vs_cache_bypass; |
| 767 | extern int sysctl_ip_vs_expire_nodest_conn; |
| 768 | extern int sysctl_ip_vs_expire_quiescent_template; |
| 769 | extern int sysctl_ip_vs_sync_threshold[2]; |
| 770 | extern int sysctl_ip_vs_nat_icmp_send; |
| 771 | extern struct ip_vs_stats ip_vs_stats; |
Sven Wegener | 5587da5 | 2008-08-10 18:24:40 +0000 | [diff] [blame] | 772 | extern const struct ctl_path net_vs_ctl_path[]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | |
| 774 | extern struct ip_vs_service * |
Julius Volz | 3c2e050 | 2008-09-02 15:55:38 +0200 | [diff] [blame] | 775 | ip_vs_service_get(int af, __u32 fwmark, __u16 protocol, |
| 776 | const union nf_inet_addr *vaddr, __be16 vport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | |
| 778 | static inline void ip_vs_service_put(struct ip_vs_service *svc) |
| 779 | { |
| 780 | atomic_dec(&svc->usecnt); |
| 781 | } |
| 782 | |
| 783 | extern struct ip_vs_dest * |
Julius Volz | 7937df1 | 2008-09-02 15:55:48 +0200 | [diff] [blame] | 784 | ip_vs_lookup_real_service(int af, __u16 protocol, |
| 785 | const union nf_inet_addr *daddr, __be16 dport); |
| 786 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | extern int ip_vs_use_count_inc(void); |
| 788 | extern void ip_vs_use_count_dec(void); |
| 789 | extern int ip_vs_control_init(void); |
| 790 | extern void ip_vs_control_cleanup(void); |
Rumen G. Bogdanovski | 1e356f9 | 2007-11-07 02:35:54 -0800 | [diff] [blame] | 791 | extern struct ip_vs_dest * |
Julius Volz | 7937df1 | 2008-09-02 15:55:48 +0200 | [diff] [blame] | 792 | ip_vs_find_dest(int af, const union nf_inet_addr *daddr, __be16 dport, |
| 793 | const union nf_inet_addr *vaddr, __be16 vport, __u16 protocol); |
Rumen G. Bogdanovski | 1e356f9 | 2007-11-07 02:35:54 -0800 | [diff] [blame] | 794 | extern struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | |
| 796 | |
| 797 | /* |
| 798 | * IPVS sync daemon data and function prototypes |
| 799 | * (from ip_vs_sync.c) |
| 800 | */ |
| 801 | extern volatile int ip_vs_sync_state; |
| 802 | extern volatile int ip_vs_master_syncid; |
| 803 | extern volatile int ip_vs_backup_syncid; |
| 804 | extern char ip_vs_master_mcast_ifn[IP_VS_IFNAME_MAXLEN]; |
| 805 | extern char ip_vs_backup_mcast_ifn[IP_VS_IFNAME_MAXLEN]; |
| 806 | extern int start_sync_thread(int state, char *mcast_ifn, __u8 syncid); |
| 807 | extern int stop_sync_thread(int state); |
| 808 | extern void ip_vs_sync_conn(struct ip_vs_conn *cp); |
| 809 | |
| 810 | |
| 811 | /* |
| 812 | * IPVS rate estimator prototypes (from ip_vs_est.c) |
| 813 | */ |
Sven Wegener | a919cf4 | 2008-08-14 00:47:16 +0200 | [diff] [blame] | 814 | extern int ip_vs_estimator_init(void); |
| 815 | extern void ip_vs_estimator_cleanup(void); |
Sven Wegener | 3a14a313 | 2008-08-10 18:24:41 +0000 | [diff] [blame] | 816 | extern void ip_vs_new_estimator(struct ip_vs_stats *stats); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | extern void ip_vs_kill_estimator(struct ip_vs_stats *stats); |
| 818 | extern void ip_vs_zero_estimator(struct ip_vs_stats *stats); |
| 819 | |
| 820 | /* |
| 821 | * Various IPVS packet transmitters (from ip_vs_xmit.c) |
| 822 | */ |
| 823 | extern int ip_vs_null_xmit |
| 824 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
| 825 | extern int ip_vs_bypass_xmit |
| 826 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
| 827 | extern int ip_vs_nat_xmit |
| 828 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
| 829 | extern int ip_vs_tunnel_xmit |
| 830 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
| 831 | extern int ip_vs_dr_xmit |
| 832 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
| 833 | extern int ip_vs_icmp_xmit |
| 834 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, int offset); |
| 835 | extern void ip_vs_dst_reset(struct ip_vs_dest *dest); |
| 836 | |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 837 | #ifdef CONFIG_IP_VS_IPV6 |
| 838 | extern int ip_vs_bypass_xmit_v6 |
| 839 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
| 840 | extern int ip_vs_nat_xmit_v6 |
| 841 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
| 842 | extern int ip_vs_tunnel_xmit_v6 |
| 843 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
| 844 | extern int ip_vs_dr_xmit_v6 |
| 845 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
| 846 | extern int ip_vs_icmp_xmit_v6 |
| 847 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, |
| 848 | int offset); |
| 849 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | |
| 851 | /* |
| 852 | * This is a simple mechanism to ignore packets when |
| 853 | * we are loaded. Just set ip_vs_drop_rate to 'n' and |
| 854 | * we start to drop 1/rate of the packets |
| 855 | */ |
| 856 | extern int ip_vs_drop_rate; |
| 857 | extern int ip_vs_drop_counter; |
| 858 | |
| 859 | static __inline__ int ip_vs_todrop(void) |
| 860 | { |
| 861 | if (!ip_vs_drop_rate) return 0; |
| 862 | if (--ip_vs_drop_counter > 0) return 0; |
| 863 | ip_vs_drop_counter = ip_vs_drop_rate; |
| 864 | return 1; |
| 865 | } |
| 866 | |
| 867 | /* |
| 868 | * ip_vs_fwd_tag returns the forwarding tag of the connection |
| 869 | */ |
| 870 | #define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK) |
| 871 | |
Adrian Bunk | 732db65 | 2005-09-01 17:40:26 -0700 | [diff] [blame] | 872 | static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | { |
| 874 | char fwd; |
| 875 | |
| 876 | switch (IP_VS_FWD_METHOD(cp)) { |
| 877 | case IP_VS_CONN_F_MASQ: |
| 878 | fwd = 'M'; break; |
| 879 | case IP_VS_CONN_F_LOCALNODE: |
| 880 | fwd = 'L'; break; |
| 881 | case IP_VS_CONN_F_TUNNEL: |
| 882 | fwd = 'T'; break; |
| 883 | case IP_VS_CONN_F_DROUTE: |
| 884 | fwd = 'R'; break; |
| 885 | case IP_VS_CONN_F_BYPASS: |
| 886 | fwd = 'B'; break; |
| 887 | default: |
| 888 | fwd = '?'; break; |
| 889 | } |
| 890 | return fwd; |
| 891 | } |
| 892 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | extern void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp, |
Julius Volz | b3cdd2a7 | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 894 | struct ip_vs_conn *cp, int dir); |
| 895 | |
| 896 | #ifdef CONFIG_IP_VS_IPV6 |
| 897 | extern void ip_vs_nat_icmp_v6(struct sk_buff *skb, struct ip_vs_protocol *pp, |
| 898 | struct ip_vs_conn *cp, int dir); |
| 899 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | |
Al Viro | b1550f2 | 2006-11-14 21:37:50 -0800 | [diff] [blame] | 901 | extern __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | |
Al Viro | f9214b2 | 2006-11-16 02:41:18 -0800 | [diff] [blame] | 903 | static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | { |
Al Viro | f9214b2 | 2006-11-16 02:41:18 -0800 | [diff] [blame] | 905 | __be32 diff[2] = { ~old, new }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | |
Joe Perches | 07f0757 | 2008-11-19 15:44:53 -0800 | [diff] [blame] | 907 | return csum_partial(diff, sizeof(diff), oldsum); |
Al Viro | f9214b2 | 2006-11-16 02:41:18 -0800 | [diff] [blame] | 908 | } |
| 909 | |
Julius Volz | 0bbdd42 | 2008-09-02 15:55:42 +0200 | [diff] [blame] | 910 | #ifdef CONFIG_IP_VS_IPV6 |
| 911 | static inline __wsum ip_vs_check_diff16(const __be32 *old, const __be32 *new, |
| 912 | __wsum oldsum) |
| 913 | { |
| 914 | __be32 diff[8] = { ~old[3], ~old[2], ~old[1], ~old[0], |
| 915 | new[3], new[2], new[1], new[0] }; |
| 916 | |
Joe Perches | 07f0757 | 2008-11-19 15:44:53 -0800 | [diff] [blame] | 917 | return csum_partial(diff, sizeof(diff), oldsum); |
Julius Volz | 0bbdd42 | 2008-09-02 15:55:42 +0200 | [diff] [blame] | 918 | } |
| 919 | #endif |
| 920 | |
Al Viro | f9214b2 | 2006-11-16 02:41:18 -0800 | [diff] [blame] | 921 | static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum) |
| 922 | { |
| 923 | __be16 diff[2] = { ~old, new }; |
| 924 | |
Joe Perches | 07f0757 | 2008-11-19 15:44:53 -0800 | [diff] [blame] | 925 | return csum_partial(diff, sizeof(diff), oldsum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | #endif /* __KERNEL__ */ |
| 929 | |
Julius Volz | bc4768e | 2008-07-31 20:45:24 -0700 | [diff] [blame] | 930 | #endif /* _NET_IP_VS_H */ |