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