blob: c1c2ece3ed946a450461fa2b5b41e21c022617e1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * IP Virtual Server
3 * data structure and functionality definitions
4 */
5
Julius Volzbc4768e2008-07-31 20:45:24 -07006#ifndef _NET_IP_VS_H
7#define _NET_IP_VS_H
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
Julius Volzbc4768e2008-07-31 20:45:24 -07009#include <linux/ip_vs.h> /* definitions shared with userland */
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
Julius Volzbc4768e2008-07-31 20:45:24 -070011/* old ipvsadm versions still include this file directly */
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#ifdef __KERNEL__
13
Julius Volzbc4768e2008-07-31 20:45:24 -070014#include <asm/types.h> /* for __uXX types */
15
16#include <linux/sysctl.h> /* for ctl_path */
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/list.h> /* for struct list_head */
18#include <linux/spinlock.h> /* for struct rwlock_t */
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/atomic.h> /* for struct atomic_t */
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/compiler.h>
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020021#include <linux/timer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020023#include <net/checksum.h>
Julius Volze7ade462008-09-02 15:55:33 +020024#include <linux/netfilter.h> /* for union nf_inet_addr */
KOVACS Krisztian1668e012008-10-01 07:33:10 -070025#include <linux/ip.h>
Julius Volze7ade462008-09-02 15:55:33 +020026#include <linux/ipv6.h> /* for struct ipv6hdr */
27#include <net/ipv6.h> /* for ipv6_addr_copy */
Julian Anastasovcf356d62010-10-17 16:21:07 +030028#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
Julian Anastasovf4bc17c2010-09-21 17:35:41 +020029#include <net/netfilter/nf_conntrack.h>
30#endif
Hans Schillstrom61b1ab42011-01-03 14:44:42 +010031#include <net/net_namespace.h> /* Netw namespace */
32
33/*
34 * Generic access of ipvs struct
35 */
36static inline struct netns_ipvs *net_ipvs(struct net* net)
37{
38 return net->ipvs;
39}
Catalin(ux) M. BOIE6f7edb42010-01-05 05:50:24 +010040
41/* Connections' size value needed by ip_vs_ctl.c */
42extern int ip_vs_conn_tab_size;
43
44
Julius Volz64aae3c2008-09-02 15:55:34 +020045struct ip_vs_iphdr {
46 int len;
47 __u8 protocol;
48 union nf_inet_addr saddr;
49 union nf_inet_addr daddr;
50};
51
52static inline void
53ip_vs_fill_iphdr(int af, const void *nh, struct ip_vs_iphdr *iphdr)
54{
55#ifdef CONFIG_IP_VS_IPV6
56 if (af == AF_INET6) {
57 const struct ipv6hdr *iph = nh;
58 iphdr->len = sizeof(struct ipv6hdr);
59 iphdr->protocol = iph->nexthdr;
60 ipv6_addr_copy(&iphdr->saddr.in6, &iph->saddr);
61 ipv6_addr_copy(&iphdr->daddr.in6, &iph->daddr);
62 } else
63#endif
64 {
65 const struct iphdr *iph = nh;
66 iphdr->len = iph->ihl * 4;
67 iphdr->protocol = iph->protocol;
68 iphdr->saddr.ip = iph->saddr;
69 iphdr->daddr.ip = iph->daddr;
70 }
71}
72
73static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst,
74 const union nf_inet_addr *src)
75{
76#ifdef CONFIG_IP_VS_IPV6
77 if (af == AF_INET6)
78 ipv6_addr_copy(&dst->in6, &src->in6);
79 else
80#endif
81 dst->ip = src->ip;
82}
83
84static inline int ip_vs_addr_equal(int af, const union nf_inet_addr *a,
85 const union nf_inet_addr *b)
86{
87#ifdef CONFIG_IP_VS_IPV6
88 if (af == AF_INET6)
89 return ipv6_addr_equal(&a->in6, &b->in6);
90#endif
91 return a->ip == b->ip;
92}
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094#ifdef CONFIG_IP_VS_DEBUG
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020095#include <linux/net.h>
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097extern int ip_vs_get_debug_level(void);
Julius Volzc842a3a2008-09-02 15:55:35 +020098
99static inline const char *ip_vs_dbg_addr(int af, char *buf, size_t buf_len,
100 const union nf_inet_addr *addr,
101 int *idx)
102{
103 int len;
104#ifdef CONFIG_IP_VS_IPV6
105 if (af == AF_INET6)
Harvey Harrison5b095d9892008-10-29 12:52:50 -0700106 len = snprintf(&buf[*idx], buf_len - *idx, "[%pI6]",
Harvey Harrison0c6ce782008-10-28 16:09:23 -0700107 &addr->in6) + 1;
Julius Volzc842a3a2008-09-02 15:55:35 +0200108 else
109#endif
Harvey Harrison3685f25d2008-10-31 00:56:49 -0700110 len = snprintf(&buf[*idx], buf_len - *idx, "%pI4",
111 &addr->ip) + 1;
Julius Volzc842a3a2008-09-02 15:55:35 +0200112
113 *idx += len;
114 BUG_ON(*idx > buf_len + 1);
115 return &buf[*idx - len];
116}
117
Hannes Eder9aada7a2009-07-30 14:29:44 -0700118#define IP_VS_DBG_BUF(level, msg, ...) \
119 do { \
120 char ip_vs_dbg_buf[160]; \
121 int ip_vs_dbg_idx = 0; \
122 if (level <= ip_vs_get_debug_level()) \
123 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
124 } while (0)
125#define IP_VS_ERR_BUF(msg...) \
126 do { \
127 char ip_vs_dbg_buf[160]; \
128 int ip_vs_dbg_idx = 0; \
129 pr_err(msg); \
130 } while (0)
Julius Volzc842a3a2008-09-02 15:55:35 +0200131
132/* Only use from within IP_VS_DBG_BUF() or IP_VS_ERR_BUF macros */
Hannes Eder9aada7a2009-07-30 14:29:44 -0700133#define IP_VS_DBG_ADDR(af, addr) \
134 ip_vs_dbg_addr(af, ip_vs_dbg_buf, \
135 sizeof(ip_vs_dbg_buf), addr, \
136 &ip_vs_dbg_idx)
Julius Volzc842a3a2008-09-02 15:55:35 +0200137
Hannes Eder9aada7a2009-07-30 14:29:44 -0700138#define IP_VS_DBG(level, msg, ...) \
139 do { \
140 if (level <= ip_vs_get_debug_level()) \
141 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
142 } while (0)
143#define IP_VS_DBG_RL(msg, ...) \
144 do { \
145 if (net_ratelimit()) \
146 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
147 } while (0)
Julian Anastasov0d796412010-10-17 16:46:17 +0300148#define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) \
Hannes Eder9aada7a2009-07-30 14:29:44 -0700149 do { \
150 if (level <= ip_vs_get_debug_level()) \
Julian Anastasov0d796412010-10-17 16:46:17 +0300151 pp->debug_packet(af, pp, skb, ofs, msg); \
Hannes Eder9aada7a2009-07-30 14:29:44 -0700152 } while (0)
Julian Anastasov0d796412010-10-17 16:46:17 +0300153#define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) \
Hannes Eder9aada7a2009-07-30 14:29:44 -0700154 do { \
155 if (level <= ip_vs_get_debug_level() && \
156 net_ratelimit()) \
Julian Anastasov0d796412010-10-17 16:46:17 +0300157 pp->debug_packet(af, pp, skb, ofs, msg); \
Hannes Eder9aada7a2009-07-30 14:29:44 -0700158 } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159#else /* NO DEBUGGING at ALL */
Julius Volzc842a3a2008-09-02 15:55:35 +0200160#define IP_VS_DBG_BUF(level, msg...) do {} while (0)
161#define IP_VS_ERR_BUF(msg...) do {} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162#define IP_VS_DBG(level, msg...) do {} while (0)
163#define IP_VS_DBG_RL(msg...) do {} while (0)
Julian Anastasov0d796412010-10-17 16:46:17 +0300164#define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) do {} while (0)
165#define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) do {} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166#endif
167
168#define IP_VS_BUG() BUG()
Hannes Eder1e3e2382009-08-02 11:05:41 +0000169#define IP_VS_ERR_RL(msg, ...) \
Hannes Eder9aada7a2009-07-30 14:29:44 -0700170 do { \
171 if (net_ratelimit()) \
Hannes Eder1e3e2382009-08-02 11:05:41 +0000172 pr_err(msg, ##__VA_ARGS__); \
Hannes Eder9aada7a2009-07-30 14:29:44 -0700173 } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175#ifdef CONFIG_IP_VS_DEBUG
176#define EnterFunction(level) \
Hannes Eder9aada7a2009-07-30 14:29:44 -0700177 do { \
178 if (level <= ip_vs_get_debug_level()) \
179 printk(KERN_DEBUG \
180 pr_fmt("Enter: %s, %s line %i\n"), \
181 __func__, __FILE__, __LINE__); \
182 } while (0)
183#define LeaveFunction(level) \
184 do { \
185 if (level <= ip_vs_get_debug_level()) \
186 printk(KERN_DEBUG \
187 pr_fmt("Leave: %s, %s line %i\n"), \
188 __func__, __FILE__, __LINE__); \
189 } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190#else
191#define EnterFunction(level) do {} while (0)
192#define LeaveFunction(level) do {} while (0)
193#endif
194
195#define IP_VS_WAIT_WHILE(expr) while (expr) { cpu_relax(); }
196
197
198/*
199 * The port number of FTP service (in network order).
200 */
Harvey Harrisonf3a7c662009-02-14 22:58:35 -0800201#define FTPPORT cpu_to_be16(21)
202#define FTPDATA cpu_to_be16(20)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
204/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 * TCP State Values
206 */
207enum {
208 IP_VS_TCP_S_NONE = 0,
209 IP_VS_TCP_S_ESTABLISHED,
210 IP_VS_TCP_S_SYN_SENT,
211 IP_VS_TCP_S_SYN_RECV,
212 IP_VS_TCP_S_FIN_WAIT,
213 IP_VS_TCP_S_TIME_WAIT,
214 IP_VS_TCP_S_CLOSE,
215 IP_VS_TCP_S_CLOSE_WAIT,
216 IP_VS_TCP_S_LAST_ACK,
217 IP_VS_TCP_S_LISTEN,
218 IP_VS_TCP_S_SYNACK,
219 IP_VS_TCP_S_LAST
220};
221
222/*
223 * UDP State Values
224 */
225enum {
226 IP_VS_UDP_S_NORMAL,
227 IP_VS_UDP_S_LAST,
228};
229
230/*
231 * ICMP State Values
232 */
233enum {
234 IP_VS_ICMP_S_NORMAL,
235 IP_VS_ICMP_S_LAST,
236};
237
238/*
Venkata Mohan Reddy2906f662010-02-18 12:31:05 +0100239 * SCTP State Values
240 */
241enum ip_vs_sctp_states {
242 IP_VS_SCTP_S_NONE,
243 IP_VS_SCTP_S_INIT_CLI,
244 IP_VS_SCTP_S_INIT_SER,
245 IP_VS_SCTP_S_INIT_ACK_CLI,
246 IP_VS_SCTP_S_INIT_ACK_SER,
247 IP_VS_SCTP_S_ECHO_CLI,
248 IP_VS_SCTP_S_ECHO_SER,
249 IP_VS_SCTP_S_ESTABLISHED,
250 IP_VS_SCTP_S_SHUT_CLI,
251 IP_VS_SCTP_S_SHUT_SER,
252 IP_VS_SCTP_S_SHUT_ACK_CLI,
253 IP_VS_SCTP_S_SHUT_ACK_SER,
254 IP_VS_SCTP_S_CLOSED,
255 IP_VS_SCTP_S_LAST
256};
257
258/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 * Delta sequence info structure
260 * Each ip_vs_conn has 2 (output AND input seq. changes).
261 * Only used in the VS/NAT.
262 */
263struct ip_vs_seq {
264 __u32 init_seq; /* Add delta from this seq */
265 __u32 delta; /* Delta in sequence numbers */
266 __u32 previous_delta; /* Delta in sequence numbers
267 before last resized pkt */
268};
269
270
271/*
Sven Wegener3a14a312008-08-10 18:24:41 +0000272 * IPVS statistics objects
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 */
Sven Wegener3a14a312008-08-10 18:24:41 +0000274struct ip_vs_estimator {
275 struct list_head list;
276
277 u64 last_inbytes;
278 u64 last_outbytes;
279 u32 last_conns;
280 u32 last_inpkts;
281 u32 last_outpkts;
282
283 u32 cps;
284 u32 inpps;
285 u32 outpps;
286 u32 inbps;
287 u32 outbps;
288};
289
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +0000290struct ip_vs_stats {
Sven Wegenere9c0ce22008-09-08 13:39:04 +0200291 struct ip_vs_stats_user ustats; /* statistics */
292 struct ip_vs_estimator est; /* estimator */
Sven Wegener3a14a312008-08-10 18:24:41 +0000293
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 spinlock_t lock; /* spin lock */
295};
296
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -0200297struct dst_entry;
298struct iphdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299struct ip_vs_conn;
300struct ip_vs_app;
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -0200301struct sk_buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
303struct ip_vs_protocol {
304 struct ip_vs_protocol *next;
305 char *name;
Julian Anastasov2ad17de2008-04-29 03:21:23 -0700306 u16 protocol;
307 u16 num_states;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 int dont_defrag;
309 atomic_t appcnt; /* counter of proto app incs */
310 int *timeout_table; /* protocol timeout table */
311
312 void (*init)(struct ip_vs_protocol *pp);
313
314 void (*exit)(struct ip_vs_protocol *pp);
315
Julius Volz51ef3482008-09-02 15:55:40 +0200316 int (*conn_schedule)(int af, struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 struct ip_vs_protocol *pp,
318 int *verdict, struct ip_vs_conn **cpp);
319
320 struct ip_vs_conn *
Julius Volz51ef3482008-09-02 15:55:40 +0200321 (*conn_in_get)(int af,
322 const struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 struct ip_vs_protocol *pp,
Julius Volz51ef3482008-09-02 15:55:40 +0200324 const struct ip_vs_iphdr *iph,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 unsigned int proto_off,
326 int inverse);
327
328 struct ip_vs_conn *
Julius Volz51ef3482008-09-02 15:55:40 +0200329 (*conn_out_get)(int af,
330 const struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 struct ip_vs_protocol *pp,
Julius Volz51ef3482008-09-02 15:55:40 +0200332 const struct ip_vs_iphdr *iph,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 unsigned int proto_off,
334 int inverse);
335
Herbert Xu3db05fe2007-10-15 00:53:15 -0700336 int (*snat_handler)(struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
338
Herbert Xu3db05fe2007-10-15 00:53:15 -0700339 int (*dnat_handler)(struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
341
Julius Volz51ef3482008-09-02 15:55:40 +0200342 int (*csum_check)(int af, struct sk_buff *skb,
343 struct ip_vs_protocol *pp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
345 const char *(*state_name)(int state);
346
347 int (*state_transition)(struct ip_vs_conn *cp, int direction,
348 const struct sk_buff *skb,
349 struct ip_vs_protocol *pp);
350
351 int (*register_app)(struct ip_vs_app *inc);
352
353 void (*unregister_app)(struct ip_vs_app *inc);
354
355 int (*app_conn_bind)(struct ip_vs_conn *cp);
356
Julian Anastasov0d796412010-10-17 16:46:17 +0300357 void (*debug_packet)(int af, struct ip_vs_protocol *pp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 const struct sk_buff *skb,
359 int offset,
360 const char *msg);
361
362 void (*timeout_change)(struct ip_vs_protocol *pp, int flags);
363
364 int (*set_state_timeout)(struct ip_vs_protocol *pp, char *sname, int to);
365};
366
367extern struct ip_vs_protocol * ip_vs_proto_get(unsigned short proto);
368
Simon Hormanf11017e2010-08-22 21:37:52 +0900369struct ip_vs_conn_param {
370 const union nf_inet_addr *caddr;
371 const union nf_inet_addr *vaddr;
372 __be16 cport;
373 __be16 vport;
374 __u16 protocol;
375 u16 af;
Simon Horman85999282010-08-22 21:37:53 +0900376
377 const struct ip_vs_pe *pe;
378 char *pe_data;
379 __u8 pe_data_len;
Simon Hormanf11017e2010-08-22 21:37:52 +0900380};
381
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382/*
383 * IP_VS structure allocated for each dynamically scheduled connection
384 */
385struct ip_vs_conn {
386 struct list_head c_list; /* hashed list heads */
387
388 /* Protocol, addresses and port numbers */
Julius Volze7ade462008-09-02 15:55:33 +0200389 u16 af; /* address family */
390 union nf_inet_addr caddr; /* client address */
391 union nf_inet_addr vaddr; /* virtual address */
392 union nf_inet_addr daddr; /* destination address */
Julian Anastasov35757922010-09-17 14:18:16 +0200393 volatile __u32 flags; /* status flags */
Hans Schillstrom0e051e62010-11-19 14:25:07 +0100394 __u32 fwmark; /* Fire wall mark from skb */
Al Viro014d7302006-09-28 14:29:52 -0700395 __be16 cport;
396 __be16 vport;
397 __be16 dport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 __u16 protocol; /* Which protocol (TCP/UDP) */
399
400 /* counter and timer */
401 atomic_t refcnt; /* reference count */
402 struct timer_list timer; /* Expiration timer */
403 volatile unsigned long timeout; /* timeout */
404
405 /* Flags and state transition */
406 spinlock_t lock; /* lock for state transition */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 volatile __u16 state; /* state info */
Rumen G. Bogdanovskiefac5272007-11-07 02:36:55 -0800408 volatile __u16 old_state; /* old state, to be used for
409 * state transition triggerd
410 * synchronization
411 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
413 /* Control members */
414 struct ip_vs_conn *control; /* Master control connection */
415 atomic_t n_control; /* Number of controlled ones */
416 struct ip_vs_dest *dest; /* real server */
417 atomic_t in_pkts; /* incoming packet counter */
418
419 /* packet transmitter for different forwarding methods. If it
420 mangles the packet, it must return NF_DROP or better NF_STOLEN,
421 otherwise this must be changed to a sk_buff **.
Julian Anastasovfc604762010-10-17 16:38:15 +0300422 NF_ACCEPT can be returned when destination is local.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 */
424 int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp,
425 struct ip_vs_protocol *pp);
426
427 /* Note: we can group the following members into a structure,
428 in order to save more space, and the following members are
429 only used in VS/NAT anyway */
430 struct ip_vs_app *app; /* bound ip_vs_app object */
431 void *app_data; /* Application private data */
432 struct ip_vs_seq in_seq; /* incoming seq. struct */
433 struct ip_vs_seq out_seq; /* outgoing seq. struct */
Simon Horman85999282010-08-22 21:37:53 +0900434
Simon Hormane9e5eee2010-11-08 20:05:57 +0900435 const struct ip_vs_pe *pe;
Simon Horman85999282010-08-22 21:37:53 +0900436 char *pe_data;
437 __u8 pe_data_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438};
439
440
441/*
Julius Volzc860c6b2008-09-02 15:55:36 +0200442 * Extended internal versions of struct ip_vs_service_user and
443 * ip_vs_dest_user for IPv6 support.
444 *
445 * We need these to conveniently pass around service and destination
446 * options, but unfortunately, we also need to keep the old definitions to
447 * maintain userspace backwards compatibility for the setsockopt interface.
448 */
449struct ip_vs_service_user_kern {
450 /* virtual service addresses */
451 u16 af;
452 u16 protocol;
453 union nf_inet_addr addr; /* virtual ip address */
454 u16 port;
455 u32 fwmark; /* firwall mark of service */
456
457 /* virtual service options */
458 char *sched_name;
Simon Horman0d1e71b2010-08-22 21:37:54 +0900459 char *pe_name;
Julius Volzc860c6b2008-09-02 15:55:36 +0200460 unsigned flags; /* virtual service flags */
461 unsigned timeout; /* persistent timeout in sec */
462 u32 netmask; /* persistent netmask */
463};
464
465
466struct ip_vs_dest_user_kern {
467 /* destination server address */
468 union nf_inet_addr addr;
469 u16 port;
470
471 /* real server options */
472 unsigned conn_flags; /* connection flags */
473 int weight; /* destination weight */
474
475 /* thresholds for active connections */
476 u32 u_threshold; /* upper threshold */
477 u32 l_threshold; /* lower threshold */
478};
479
480
481/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 * The information about the virtual service offered to the net
483 * and the forwarding entries
484 */
485struct ip_vs_service {
486 struct list_head s_list; /* for normal service table */
487 struct list_head f_list; /* for fwmark-based service table */
488 atomic_t refcnt; /* reference counter */
489 atomic_t usecnt; /* use counter */
490
Julius Volze7ade462008-09-02 15:55:33 +0200491 u16 af; /* address family */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 __u16 protocol; /* which protocol (TCP/UDP) */
Julius Volze7ade462008-09-02 15:55:33 +0200493 union nf_inet_addr addr; /* IP address for virtual service */
Al Viro014d7302006-09-28 14:29:52 -0700494 __be16 port; /* port number for the service */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 __u32 fwmark; /* firewall mark of the service */
496 unsigned flags; /* service status flags */
497 unsigned timeout; /* persistent timeout in ticks */
Al Viro014d7302006-09-28 14:29:52 -0700498 __be32 netmask; /* grouping granularity */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
500 struct list_head destinations; /* real server d-linked list */
501 __u32 num_dests; /* number of servers */
502 struct ip_vs_stats stats; /* statistics for the service */
503 struct ip_vs_app *inc; /* bind conns to this app inc */
504
505 /* for scheduling */
506 struct ip_vs_scheduler *scheduler; /* bound scheduler object */
507 rwlock_t sched_lock; /* lock sched_data */
508 void *sched_data; /* scheduler application data */
Simon Horman85999282010-08-22 21:37:53 +0900509
510 /* alternate persistence engine */
511 struct ip_vs_pe *pe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512};
513
514
515/*
516 * The real server destination forwarding entry
517 * with ip address, port number, and so on.
518 */
519struct ip_vs_dest {
520 struct list_head n_list; /* for the dests in the service */
521 struct list_head d_list; /* for table with all the dests */
522
Julius Volze7ade462008-09-02 15:55:33 +0200523 u16 af; /* address family */
524 union nf_inet_addr addr; /* IP address of the server */
Al Viro014d7302006-09-28 14:29:52 -0700525 __be16 port; /* port number of the server */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 volatile unsigned flags; /* dest status flags */
527 atomic_t conn_flags; /* flags to copy to conn */
528 atomic_t weight; /* server weight */
529
530 atomic_t refcnt; /* reference counter */
531 struct ip_vs_stats stats; /* statistics */
532
533 /* connection counters and thresholds */
534 atomic_t activeconns; /* active connections */
535 atomic_t inactconns; /* inactive connections */
536 atomic_t persistconns; /* persistent connections */
537 __u32 u_threshold; /* upper threshold */
538 __u32 l_threshold; /* lower threshold */
539
540 /* for destination cache */
541 spinlock_t dst_lock; /* lock of dst_cache */
542 struct dst_entry *dst_cache; /* destination cache entry */
543 u32 dst_rtos; /* RT_TOS(tos) for dst */
Hans Schillstrom714f0952010-10-19 10:38:48 +0200544 u32 dst_cookie;
545#ifdef CONFIG_IP_VS_IPV6
546 struct in6_addr dst_saddr;
547#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
549 /* for virtual service */
550 struct ip_vs_service *svc; /* service it belongs to */
551 __u16 protocol; /* which protocol (TCP/UDP) */
Julius Volze7ade462008-09-02 15:55:33 +0200552 union nf_inet_addr vaddr; /* virtual IP address */
Al Viro014d7302006-09-28 14:29:52 -0700553 __be16 vport; /* virtual port number */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 __u32 vfwmark; /* firewall mark of service */
555};
556
557
558/*
559 * The scheduler object
560 */
561struct ip_vs_scheduler {
562 struct list_head n_list; /* d-linked list head */
563 char *name; /* scheduler name */
564 atomic_t refcnt; /* reference counter */
565 struct module *module; /* THIS_MODULE/NULL */
566
567 /* scheduler initializing service */
568 int (*init_service)(struct ip_vs_service *svc);
569 /* scheduling service finish */
570 int (*done_service)(struct ip_vs_service *svc);
571 /* scheduler updating service */
572 int (*update_service)(struct ip_vs_service *svc);
573
574 /* selecting a server from the given service */
575 struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc,
576 const struct sk_buff *skb);
577};
578
Simon Horman85999282010-08-22 21:37:53 +0900579/* The persistence engine object */
580struct ip_vs_pe {
581 struct list_head n_list; /* d-linked list head */
582 char *name; /* scheduler name */
583 atomic_t refcnt; /* reference counter */
584 struct module *module; /* THIS_MODULE/NULL */
585
586 /* get the connection template, if any */
587 int (*fill_param)(struct ip_vs_conn_param *p, struct sk_buff *skb);
588 bool (*ct_match)(const struct ip_vs_conn_param *p,
589 struct ip_vs_conn *ct);
590 u32 (*hashkey_raw)(const struct ip_vs_conn_param *p, u32 initval,
591 bool inverse);
Simon Hormana3c918a2010-08-22 21:37:53 +0900592 int (*show_pe_data)(const struct ip_vs_conn *cp, char *buf);
Simon Horman85999282010-08-22 21:37:53 +0900593};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
595/*
596 * The application module object (a.k.a. app incarnation)
597 */
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +0000598struct ip_vs_app {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 struct list_head a_list; /* member in app list */
600 int type; /* IP_VS_APP_TYPE_xxx */
601 char *name; /* application module name */
602 __u16 protocol;
603 struct module *module; /* THIS_MODULE/NULL */
604 struct list_head incs_list; /* list of incarnations */
605
606 /* members for application incarnations */
607 struct list_head p_list; /* member in proto app list */
608 struct ip_vs_app *app; /* its real application */
Al Viro014d7302006-09-28 14:29:52 -0700609 __be16 port; /* port number in net order */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 atomic_t usecnt; /* usage counter */
611
Julian Anastasov8b27b102010-10-17 16:17:20 +0300612 /*
613 * output hook: Process packet in inout direction, diff set for TCP.
614 * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
615 * 2=Mangled but checksum was not updated
616 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *,
Herbert Xu3db05fe2007-10-15 00:53:15 -0700618 struct sk_buff *, int *diff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
Julian Anastasov8b27b102010-10-17 16:17:20 +0300620 /*
621 * input hook: Process packet in outin direction, diff set for TCP.
622 * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
623 * 2=Mangled but checksum was not updated
624 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *,
Herbert Xu3db05fe2007-10-15 00:53:15 -0700626 struct sk_buff *, int *diff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
628 /* ip_vs_app initializer */
629 int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *);
630
631 /* ip_vs_app finish */
632 int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *);
633
634
635 /* not used now */
636 int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *,
637 struct ip_vs_protocol *);
638
639 void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *);
640
641 int * timeout_table;
642 int * timeouts;
643 int timeouts_size;
644
645 int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app,
646 int *verdict, struct ip_vs_conn **cpp);
647
648 struct ip_vs_conn *
649 (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app,
650 const struct iphdr *iph, unsigned int proto_off,
651 int inverse);
652
653 struct ip_vs_conn *
654 (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app,
655 const struct iphdr *iph, unsigned int proto_off,
656 int inverse);
657
658 int (*state_transition)(struct ip_vs_conn *cp, int direction,
659 const struct sk_buff *skb,
660 struct ip_vs_app *app);
661
662 void (*timeout_change)(struct ip_vs_app *app, int flags);
663};
664
665
666/*
667 * IPVS core functions
668 * (from ip_vs_core.c)
669 */
670extern const char *ip_vs_proto_name(unsigned proto);
671extern void ip_vs_init_hash_table(struct list_head *table, int rows);
Sven Wegenerafdd6142008-08-10 09:18:01 +0000672#define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674#define IP_VS_APP_TYPE_FTP 1
675
676/*
677 * ip_vs_conn handling functions
678 * (from ip_vs_conn.c)
679 */
680
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681enum {
682 IP_VS_DIR_INPUT = 0,
683 IP_VS_DIR_OUTPUT,
684 IP_VS_DIR_INPUT_ONLY,
685 IP_VS_DIR_LAST,
686};
687
Simon Hormanf11017e2010-08-22 21:37:52 +0900688static inline void ip_vs_conn_fill_param(int af, int protocol,
689 const union nf_inet_addr *caddr,
690 __be16 cport,
691 const union nf_inet_addr *vaddr,
692 __be16 vport,
693 struct ip_vs_conn_param *p)
694{
695 p->af = af;
696 p->protocol = protocol;
697 p->caddr = caddr;
698 p->cport = cport;
699 p->vaddr = vaddr;
700 p->vport = vport;
Simon Horman85999282010-08-22 21:37:53 +0900701 p->pe = NULL;
702 p->pe_data = NULL;
Simon Hormanf11017e2010-08-22 21:37:52 +0900703}
Julius Volz28364a52008-09-02 15:55:43 +0200704
Simon Hormanf11017e2010-08-22 21:37:52 +0900705struct ip_vs_conn *ip_vs_conn_in_get(const struct ip_vs_conn_param *p);
706struct ip_vs_conn *ip_vs_ct_in_get(const struct ip_vs_conn_param *p);
Julius Volz28364a52008-09-02 15:55:43 +0200707
Simon Horman5c0d2372010-08-02 17:12:44 +0200708struct ip_vs_conn * ip_vs_conn_in_get_proto(int af, const struct sk_buff *skb,
709 struct ip_vs_protocol *pp,
710 const struct ip_vs_iphdr *iph,
711 unsigned int proto_off,
712 int inverse);
713
Simon Hormanf11017e2010-08-22 21:37:52 +0900714struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
Simon Horman5c0d2372010-08-02 17:12:44 +0200716struct ip_vs_conn * ip_vs_conn_out_get_proto(int af, const struct sk_buff *skb,
717 struct ip_vs_protocol *pp,
718 const struct ip_vs_iphdr *iph,
719 unsigned int proto_off,
720 int inverse);
721
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722/* put back the conn without restarting its timer */
723static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
724{
725 atomic_dec(&cp->refcnt);
726}
727extern void ip_vs_conn_put(struct ip_vs_conn *cp);
Al Viro014d7302006-09-28 14:29:52 -0700728extern void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
Simon Hormanf11017e2010-08-22 21:37:52 +0900730struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p,
731 const union nf_inet_addr *daddr,
732 __be16 dport, unsigned flags,
Hans Schillstrom0e051e62010-11-19 14:25:07 +0100733 struct ip_vs_dest *dest, __u32 fwmark);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
735
736extern const char * ip_vs_state_name(__u16 proto, int state);
737
738extern void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp);
739extern int ip_vs_check_template(struct ip_vs_conn *ct);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740extern void ip_vs_random_dropentry(void);
741extern int ip_vs_conn_init(void);
742extern void ip_vs_conn_cleanup(void);
743
744static inline void ip_vs_control_del(struct ip_vs_conn *cp)
745{
746 struct ip_vs_conn *ctl_cp = cp->control;
747 if (!ctl_cp) {
Julius Volzcfc78c52008-09-02 15:55:53 +0200748 IP_VS_ERR_BUF("request control DEL for uncontrolled: "
749 "%s:%d to %s:%d\n",
750 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
751 ntohs(cp->cport),
752 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
753 ntohs(cp->vport));
754
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 return;
756 }
757
Julius Volzcfc78c52008-09-02 15:55:53 +0200758 IP_VS_DBG_BUF(7, "DELeting control for: "
759 "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
760 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
761 ntohs(cp->cport),
762 IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
763 ntohs(ctl_cp->cport));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
765 cp->control = NULL;
766 if (atomic_read(&ctl_cp->n_control) == 0) {
Julius Volzcfc78c52008-09-02 15:55:53 +0200767 IP_VS_ERR_BUF("BUG control DEL with n=0 : "
768 "%s:%d to %s:%d\n",
769 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
770 ntohs(cp->cport),
771 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
772 ntohs(cp->vport));
773
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 return;
775 }
776 atomic_dec(&ctl_cp->n_control);
777}
778
779static inline void
780ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)
781{
782 if (cp->control) {
Julius Volzcfc78c52008-09-02 15:55:53 +0200783 IP_VS_ERR_BUF("request control ADD for already controlled: "
784 "%s:%d to %s:%d\n",
785 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
786 ntohs(cp->cport),
787 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
788 ntohs(cp->vport));
789
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 ip_vs_control_del(cp);
791 }
792
Julius Volzcfc78c52008-09-02 15:55:53 +0200793 IP_VS_DBG_BUF(7, "ADDing control for: "
794 "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
795 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
796 ntohs(cp->cport),
797 IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
798 ntohs(ctl_cp->cport));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
800 cp->control = ctl_cp;
801 atomic_inc(&ctl_cp->n_control);
802}
803
804
805/*
806 * IPVS application functions
807 * (from ip_vs_app.c)
808 */
809#define IP_VS_APP_MAX_PORTS 8
810extern int register_ip_vs_app(struct ip_vs_app *app);
811extern void unregister_ip_vs_app(struct ip_vs_app *app);
812extern int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
813extern void ip_vs_unbind_app(struct ip_vs_conn *cp);
814extern int
815register_ip_vs_app_inc(struct ip_vs_app *app, __u16 proto, __u16 port);
816extern int ip_vs_app_inc_get(struct ip_vs_app *inc);
817extern void ip_vs_app_inc_put(struct ip_vs_app *inc);
818
Herbert Xu3db05fe2007-10-15 00:53:15 -0700819extern int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb);
820extern int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821extern int ip_vs_app_init(void);
822extern void ip_vs_app_cleanup(void);
823
Simon Horman8be67a62010-08-22 21:37:54 +0900824void ip_vs_bind_pe(struct ip_vs_service *svc, struct ip_vs_pe *pe);
825void ip_vs_unbind_pe(struct ip_vs_service *svc);
826int register_ip_vs_pe(struct ip_vs_pe *pe);
827int unregister_ip_vs_pe(struct ip_vs_pe *pe);
Simon Hormane9e5eee2010-11-08 20:05:57 +0900828struct ip_vs_pe *ip_vs_pe_getbyname(const char *name);
Hans Schillstromfe5e7a12010-11-19 14:25:12 +0100829struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name);
Simon Hormane9e5eee2010-11-08 20:05:57 +0900830
831static inline void ip_vs_pe_get(const struct ip_vs_pe *pe)
832{
833 if (pe && pe->module)
834 __module_get(pe->module);
835}
836
837static inline void ip_vs_pe_put(const struct ip_vs_pe *pe)
838{
839 if (pe && pe->module)
840 module_put(pe->module);
841}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
843/*
844 * IPVS protocol functions (from ip_vs_proto.c)
845 */
846extern int ip_vs_protocol_init(void);
847extern void ip_vs_protocol_cleanup(void);
848extern void ip_vs_protocol_timeout_change(int flags);
849extern int *ip_vs_create_timeout_table(int *table, int size);
850extern int
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -0700851ip_vs_set_state_timeout(int *table, int num, const char *const *names,
852 const char *name, int to);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853extern void
Julian Anastasov0d796412010-10-17 16:46:17 +0300854ip_vs_tcpudp_debug_packet(int af, struct ip_vs_protocol *pp,
855 const struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 int offset, const char *msg);
857
858extern struct ip_vs_protocol ip_vs_protocol_tcp;
859extern struct ip_vs_protocol ip_vs_protocol_udp;
860extern struct ip_vs_protocol ip_vs_protocol_icmp;
861extern struct ip_vs_protocol ip_vs_protocol_esp;
862extern struct ip_vs_protocol ip_vs_protocol_ah;
Venkata Mohan Reddy2906f662010-02-18 12:31:05 +0100863extern struct ip_vs_protocol ip_vs_protocol_sctp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
865/*
866 * Registering/unregistering scheduler functions
867 * (from ip_vs_sched.c)
868 */
869extern int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
870extern int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
871extern int ip_vs_bind_scheduler(struct ip_vs_service *svc,
872 struct ip_vs_scheduler *scheduler);
873extern int ip_vs_unbind_scheduler(struct ip_vs_service *svc);
874extern struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name);
875extern void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler);
876extern struct ip_vs_conn *
Julian Anastasov190ecd22010-10-17 16:24:37 +0300877ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,
878 struct ip_vs_protocol *pp, int *ignored);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879extern int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
880 struct ip_vs_protocol *pp);
881
882
883/*
884 * IPVS control data and functions (from ip_vs_ctl.c)
885 */
886extern int sysctl_ip_vs_cache_bypass;
887extern int sysctl_ip_vs_expire_nodest_conn;
888extern int sysctl_ip_vs_expire_quiescent_template;
889extern int sysctl_ip_vs_sync_threshold[2];
890extern int sysctl_ip_vs_nat_icmp_send;
Julian Anastasovf4bc17c2010-09-21 17:35:41 +0200891extern int sysctl_ip_vs_conntrack;
Julian Anastasov8a803042010-09-21 17:38:57 +0200892extern int sysctl_ip_vs_snat_reroute;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893extern struct ip_vs_stats ip_vs_stats;
Sven Wegener5587da52008-08-10 18:24:40 +0000894extern const struct ctl_path net_vs_ctl_path[];
Hans Schillstromb880c1f2010-11-19 14:25:14 +0100895extern int sysctl_ip_vs_sync_ver;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
Hans Schillstromb880c1f2010-11-19 14:25:14 +0100897extern void ip_vs_sync_switch_mode(int mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898extern struct ip_vs_service *
Julius Volz3c2e0502008-09-02 15:55:38 +0200899ip_vs_service_get(int af, __u32 fwmark, __u16 protocol,
900 const union nf_inet_addr *vaddr, __be16 vport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
902static inline void ip_vs_service_put(struct ip_vs_service *svc)
903{
904 atomic_dec(&svc->usecnt);
905}
906
907extern struct ip_vs_dest *
Julius Volz7937df12008-09-02 15:55:48 +0200908ip_vs_lookup_real_service(int af, __u16 protocol,
909 const union nf_inet_addr *daddr, __be16 dport);
910
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911extern int ip_vs_use_count_inc(void);
912extern void ip_vs_use_count_dec(void);
913extern int ip_vs_control_init(void);
914extern void ip_vs_control_cleanup(void);
Rumen G. Bogdanovski1e356f92007-11-07 02:35:54 -0800915extern struct ip_vs_dest *
Julius Volz7937df12008-09-02 15:55:48 +0200916ip_vs_find_dest(int af, const union nf_inet_addr *daddr, __be16 dport,
Hans Schillstrom0e051e62010-11-19 14:25:07 +0100917 const union nf_inet_addr *vaddr, __be16 vport, __u16 protocol,
918 __u32 fwmark);
Rumen G. Bogdanovski1e356f92007-11-07 02:35:54 -0800919extern struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920
921
922/*
923 * IPVS sync daemon data and function prototypes
924 * (from ip_vs_sync.c)
925 */
926extern volatile int ip_vs_sync_state;
927extern volatile int ip_vs_master_syncid;
928extern volatile int ip_vs_backup_syncid;
929extern char ip_vs_master_mcast_ifn[IP_VS_IFNAME_MAXLEN];
930extern char ip_vs_backup_mcast_ifn[IP_VS_IFNAME_MAXLEN];
931extern int start_sync_thread(int state, char *mcast_ifn, __u8 syncid);
932extern int stop_sync_thread(int state);
Hans Schillstrom986a0752010-11-19 14:25:13 +0100933extern void ip_vs_sync_conn(struct ip_vs_conn *cp);
Hans Schillstrom61b1ab42011-01-03 14:44:42 +0100934extern int ip_vs_sync_init(void);
935extern void ip_vs_sync_cleanup(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936
937
938/*
939 * IPVS rate estimator prototypes (from ip_vs_est.c)
940 */
Sven Wegenera919cf42008-08-14 00:47:16 +0200941extern int ip_vs_estimator_init(void);
942extern void ip_vs_estimator_cleanup(void);
Sven Wegener3a14a312008-08-10 18:24:41 +0000943extern void ip_vs_new_estimator(struct ip_vs_stats *stats);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944extern void ip_vs_kill_estimator(struct ip_vs_stats *stats);
945extern void ip_vs_zero_estimator(struct ip_vs_stats *stats);
946
947/*
948 * Various IPVS packet transmitters (from ip_vs_xmit.c)
949 */
950extern int ip_vs_null_xmit
951(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
952extern int ip_vs_bypass_xmit
953(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
954extern int ip_vs_nat_xmit
955(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
956extern int ip_vs_tunnel_xmit
957(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
958extern int ip_vs_dr_xmit
959(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
960extern int ip_vs_icmp_xmit
961(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, int offset);
962extern void ip_vs_dst_reset(struct ip_vs_dest *dest);
963
Julius Volzb3cdd2a2008-09-02 15:55:45 +0200964#ifdef CONFIG_IP_VS_IPV6
965extern int ip_vs_bypass_xmit_v6
966(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
967extern int ip_vs_nat_xmit_v6
968(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
969extern int ip_vs_tunnel_xmit_v6
970(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
971extern int ip_vs_dr_xmit_v6
972(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
973extern int ip_vs_icmp_xmit_v6
974(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp,
975 int offset);
976#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
978/*
979 * This is a simple mechanism to ignore packets when
980 * we are loaded. Just set ip_vs_drop_rate to 'n' and
981 * we start to drop 1/rate of the packets
982 */
983extern int ip_vs_drop_rate;
984extern int ip_vs_drop_counter;
985
986static __inline__ int ip_vs_todrop(void)
987{
988 if (!ip_vs_drop_rate) return 0;
989 if (--ip_vs_drop_counter > 0) return 0;
990 ip_vs_drop_counter = ip_vs_drop_rate;
991 return 1;
992}
993
994/*
995 * ip_vs_fwd_tag returns the forwarding tag of the connection
996 */
997#define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK)
998
Adrian Bunk732db652005-09-01 17:40:26 -0700999static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000{
1001 char fwd;
1002
1003 switch (IP_VS_FWD_METHOD(cp)) {
1004 case IP_VS_CONN_F_MASQ:
1005 fwd = 'M'; break;
1006 case IP_VS_CONN_F_LOCALNODE:
1007 fwd = 'L'; break;
1008 case IP_VS_CONN_F_TUNNEL:
1009 fwd = 'T'; break;
1010 case IP_VS_CONN_F_DROUTE:
1011 fwd = 'R'; break;
1012 case IP_VS_CONN_F_BYPASS:
1013 fwd = 'B'; break;
1014 default:
1015 fwd = '?'; break;
1016 }
1017 return fwd;
1018}
1019
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020extern void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,
Julius Volzb3cdd2a2008-09-02 15:55:45 +02001021 struct ip_vs_conn *cp, int dir);
1022
1023#ifdef CONFIG_IP_VS_IPV6
1024extern void ip_vs_nat_icmp_v6(struct sk_buff *skb, struct ip_vs_protocol *pp,
1025 struct ip_vs_conn *cp, int dir);
1026#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
Al Virob1550f22006-11-14 21:37:50 -08001028extern __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
Al Virof9214b22006-11-16 02:41:18 -08001030static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031{
Al Virof9214b22006-11-16 02:41:18 -08001032 __be32 diff[2] = { ~old, new };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033
Joe Perches07f07572008-11-19 15:44:53 -08001034 return csum_partial(diff, sizeof(diff), oldsum);
Al Virof9214b22006-11-16 02:41:18 -08001035}
1036
Julius Volz0bbdd422008-09-02 15:55:42 +02001037#ifdef CONFIG_IP_VS_IPV6
1038static inline __wsum ip_vs_check_diff16(const __be32 *old, const __be32 *new,
1039 __wsum oldsum)
1040{
1041 __be32 diff[8] = { ~old[3], ~old[2], ~old[1], ~old[0],
1042 new[3], new[2], new[1], new[0] };
1043
Joe Perches07f07572008-11-19 15:44:53 -08001044 return csum_partial(diff, sizeof(diff), oldsum);
Julius Volz0bbdd422008-09-02 15:55:42 +02001045}
1046#endif
1047
Al Virof9214b22006-11-16 02:41:18 -08001048static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum)
1049{
1050 __be16 diff[2] = { ~old, new };
1051
Joe Perches07f07572008-11-19 15:44:53 -08001052 return csum_partial(diff, sizeof(diff), oldsum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053}
1054
Julian Anastasovcf356d62010-10-17 16:21:07 +03001055/*
1056 * Forget current conntrack (unconfirmed) and attach notrack entry
1057 */
1058static inline void ip_vs_notrack(struct sk_buff *skb)
1059{
1060#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1061 enum ip_conntrack_info ctinfo;
1062 struct nf_conn *ct = ct = nf_ct_get(skb, &ctinfo);
1063
1064 if (!ct || !nf_ct_is_untracked(ct)) {
1065 nf_reset(skb);
1066 skb->nfct = &nf_ct_untracked_get()->ct_general;
1067 skb->nfctinfo = IP_CT_NEW;
1068 nf_conntrack_get(skb->nfct);
1069 }
1070#endif
1071}
1072
Julian Anastasovf4bc17c2010-09-21 17:35:41 +02001073#ifdef CONFIG_IP_VS_NFCT
1074/*
1075 * Netfilter connection tracking
1076 * (from ip_vs_nfct.c)
1077 */
1078static inline int ip_vs_conntrack_enabled(void)
1079{
1080 return sysctl_ip_vs_conntrack;
1081}
1082
Julian Anastasov6523ce12010-09-05 18:02:29 +00001083extern void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp,
1084 int outin);
Julian Anastasovf4bc17c2010-09-21 17:35:41 +02001085extern int ip_vs_confirm_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp);
1086extern void ip_vs_nfct_expect_related(struct sk_buff *skb, struct nf_conn *ct,
1087 struct ip_vs_conn *cp, u_int8_t proto,
1088 const __be16 port, int from_rs);
1089extern void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp);
1090
1091#else
1092
1093static inline int ip_vs_conntrack_enabled(void)
1094{
1095 return 0;
1096}
1097
1098static inline void ip_vs_update_conntrack(struct sk_buff *skb,
1099 struct ip_vs_conn *cp, int outin)
1100{
1101}
1102
1103static inline int ip_vs_confirm_conntrack(struct sk_buff *skb,
1104 struct ip_vs_conn *cp)
1105{
1106 return NF_ACCEPT;
1107}
1108
1109static inline void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp)
1110{
1111}
1112/* CONFIG_IP_VS_NFCT */
1113#endif
Julian Anastasov6523ce12010-09-05 18:02:29 +00001114
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115#endif /* __KERNEL__ */
1116
Julius Volzbc4768e2008-07-31 20:45:24 -07001117#endif /* _NET_IP_VS_H */