blob: 88d4e40b538a9f274f08a8908232e20993834f3e [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}
Hans Schillstromfc723252011-01-03 14:44:43 +010040/*
41 * Get net ptr from skb in traffic cases
42 * use skb_sknet when call is from userland (ioctl or netlink)
43 */
44static inline struct net *skb_net(struct sk_buff *skb)
45{
46#ifdef CONFIG_NET_NS
47#ifdef CONFIG_IP_VS_DEBUG
48 /*
49 * This is used for debug only.
50 * Start with the most likely hit
51 * End with BUG
52 */
53 if (likely(skb->dev && skb->dev->nd_net))
54 return dev_net(skb->dev);
55 if (skb_dst(skb)->dev)
56 return dev_net(skb_dst(skb)->dev);
57 WARN(skb->sk, "Maybe skb_sknet should be used in %s() at line:%d\n",
58 __func__, __LINE__);
59 if (likely(skb->sk && skb->sk->sk_net))
60 return sock_net(skb->sk);
61 pr_err("There is no net ptr to find in the skb in %s() line:%d\n",
62 __func__, __LINE__);
63 BUG();
64#else
65 return dev_net(skb->dev ? : skb_dst(skb)->dev);
66#endif
67#else
68 return &init_net;
69#endif
70}
71
72static inline struct net *skb_sknet(struct sk_buff *skb)
73{
74#ifdef CONFIG_NET_NS
75#ifdef CONFIG_IP_VS_DEBUG
76 /* Start with the most likely hit */
77 if (likely(skb->sk && skb->sk->sk_net))
78 return sock_net(skb->sk);
79 WARN(skb->dev, "Maybe skb_net should be used instead in %s() line:%d\n",
80 __func__, __LINE__);
81 if (likely(skb->dev && skb->dev->nd_net))
82 return dev_net(skb->dev);
83 pr_err("There is no net ptr to find in the skb in %s() line:%d\n",
84 __func__, __LINE__);
85 BUG();
86#else
87 return sock_net(skb->sk);
88#endif
89#else
90 return &init_net;
91#endif
92}
Catalin(ux) M. BOIE6f7edb42010-01-05 05:50:24 +010093
94/* Connections' size value needed by ip_vs_ctl.c */
95extern int ip_vs_conn_tab_size;
96
97
Julius Volz64aae3c2008-09-02 15:55:34 +020098struct ip_vs_iphdr {
99 int len;
100 __u8 protocol;
101 union nf_inet_addr saddr;
102 union nf_inet_addr daddr;
103};
104
105static inline void
106ip_vs_fill_iphdr(int af, const void *nh, struct ip_vs_iphdr *iphdr)
107{
108#ifdef CONFIG_IP_VS_IPV6
109 if (af == AF_INET6) {
110 const struct ipv6hdr *iph = nh;
111 iphdr->len = sizeof(struct ipv6hdr);
112 iphdr->protocol = iph->nexthdr;
113 ipv6_addr_copy(&iphdr->saddr.in6, &iph->saddr);
114 ipv6_addr_copy(&iphdr->daddr.in6, &iph->daddr);
115 } else
116#endif
117 {
118 const struct iphdr *iph = nh;
119 iphdr->len = iph->ihl * 4;
120 iphdr->protocol = iph->protocol;
121 iphdr->saddr.ip = iph->saddr;
122 iphdr->daddr.ip = iph->daddr;
123 }
124}
125
126static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst,
127 const union nf_inet_addr *src)
128{
129#ifdef CONFIG_IP_VS_IPV6
130 if (af == AF_INET6)
131 ipv6_addr_copy(&dst->in6, &src->in6);
132 else
133#endif
134 dst->ip = src->ip;
135}
136
137static inline int ip_vs_addr_equal(int af, const union nf_inet_addr *a,
138 const union nf_inet_addr *b)
139{
140#ifdef CONFIG_IP_VS_IPV6
141 if (af == AF_INET6)
142 return ipv6_addr_equal(&a->in6, &b->in6);
143#endif
144 return a->ip == b->ip;
145}
146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147#ifdef CONFIG_IP_VS_DEBUG
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -0200148#include <linux/net.h>
149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150extern int ip_vs_get_debug_level(void);
Julius Volzc842a3a2008-09-02 15:55:35 +0200151
152static inline const char *ip_vs_dbg_addr(int af, char *buf, size_t buf_len,
153 const union nf_inet_addr *addr,
154 int *idx)
155{
156 int len;
157#ifdef CONFIG_IP_VS_IPV6
158 if (af == AF_INET6)
Harvey Harrison5b095d9892008-10-29 12:52:50 -0700159 len = snprintf(&buf[*idx], buf_len - *idx, "[%pI6]",
Harvey Harrison0c6ce782008-10-28 16:09:23 -0700160 &addr->in6) + 1;
Julius Volzc842a3a2008-09-02 15:55:35 +0200161 else
162#endif
Harvey Harrison3685f25d2008-10-31 00:56:49 -0700163 len = snprintf(&buf[*idx], buf_len - *idx, "%pI4",
164 &addr->ip) + 1;
Julius Volzc842a3a2008-09-02 15:55:35 +0200165
166 *idx += len;
167 BUG_ON(*idx > buf_len + 1);
168 return &buf[*idx - len];
169}
170
Hannes Eder9aada7a2009-07-30 14:29:44 -0700171#define IP_VS_DBG_BUF(level, msg, ...) \
172 do { \
173 char ip_vs_dbg_buf[160]; \
174 int ip_vs_dbg_idx = 0; \
175 if (level <= ip_vs_get_debug_level()) \
176 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
177 } while (0)
178#define IP_VS_ERR_BUF(msg...) \
179 do { \
180 char ip_vs_dbg_buf[160]; \
181 int ip_vs_dbg_idx = 0; \
182 pr_err(msg); \
183 } while (0)
Julius Volzc842a3a2008-09-02 15:55:35 +0200184
185/* Only use from within IP_VS_DBG_BUF() or IP_VS_ERR_BUF macros */
Hannes Eder9aada7a2009-07-30 14:29:44 -0700186#define IP_VS_DBG_ADDR(af, addr) \
187 ip_vs_dbg_addr(af, ip_vs_dbg_buf, \
188 sizeof(ip_vs_dbg_buf), addr, \
189 &ip_vs_dbg_idx)
Julius Volzc842a3a2008-09-02 15:55:35 +0200190
Hannes Eder9aada7a2009-07-30 14:29:44 -0700191#define IP_VS_DBG(level, msg, ...) \
192 do { \
193 if (level <= ip_vs_get_debug_level()) \
194 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
195 } while (0)
196#define IP_VS_DBG_RL(msg, ...) \
197 do { \
198 if (net_ratelimit()) \
199 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
200 } while (0)
Julian Anastasov0d796412010-10-17 16:46:17 +0300201#define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) \
Hannes Eder9aada7a2009-07-30 14:29:44 -0700202 do { \
203 if (level <= ip_vs_get_debug_level()) \
Julian Anastasov0d796412010-10-17 16:46:17 +0300204 pp->debug_packet(af, pp, skb, ofs, msg); \
Hannes Eder9aada7a2009-07-30 14:29:44 -0700205 } while (0)
Julian Anastasov0d796412010-10-17 16:46:17 +0300206#define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) \
Hannes Eder9aada7a2009-07-30 14:29:44 -0700207 do { \
208 if (level <= ip_vs_get_debug_level() && \
209 net_ratelimit()) \
Julian Anastasov0d796412010-10-17 16:46:17 +0300210 pp->debug_packet(af, pp, skb, ofs, msg); \
Hannes Eder9aada7a2009-07-30 14:29:44 -0700211 } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212#else /* NO DEBUGGING at ALL */
Julius Volzc842a3a2008-09-02 15:55:35 +0200213#define IP_VS_DBG_BUF(level, msg...) do {} while (0)
214#define IP_VS_ERR_BUF(msg...) do {} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215#define IP_VS_DBG(level, msg...) do {} while (0)
216#define IP_VS_DBG_RL(msg...) do {} while (0)
Julian Anastasov0d796412010-10-17 16:46:17 +0300217#define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) do {} while (0)
218#define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) do {} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219#endif
220
221#define IP_VS_BUG() BUG()
Hannes Eder1e3e2382009-08-02 11:05:41 +0000222#define IP_VS_ERR_RL(msg, ...) \
Hannes Eder9aada7a2009-07-30 14:29:44 -0700223 do { \
224 if (net_ratelimit()) \
Hannes Eder1e3e2382009-08-02 11:05:41 +0000225 pr_err(msg, ##__VA_ARGS__); \
Hannes Eder9aada7a2009-07-30 14:29:44 -0700226 } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
228#ifdef CONFIG_IP_VS_DEBUG
229#define EnterFunction(level) \
Hannes Eder9aada7a2009-07-30 14:29:44 -0700230 do { \
231 if (level <= ip_vs_get_debug_level()) \
232 printk(KERN_DEBUG \
233 pr_fmt("Enter: %s, %s line %i\n"), \
234 __func__, __FILE__, __LINE__); \
235 } while (0)
236#define LeaveFunction(level) \
237 do { \
238 if (level <= ip_vs_get_debug_level()) \
239 printk(KERN_DEBUG \
240 pr_fmt("Leave: %s, %s line %i\n"), \
241 __func__, __FILE__, __LINE__); \
242 } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243#else
244#define EnterFunction(level) do {} while (0)
245#define LeaveFunction(level) do {} while (0)
246#endif
247
248#define IP_VS_WAIT_WHILE(expr) while (expr) { cpu_relax(); }
249
250
251/*
252 * The port number of FTP service (in network order).
253 */
Harvey Harrisonf3a7c662009-02-14 22:58:35 -0800254#define FTPPORT cpu_to_be16(21)
255#define FTPDATA cpu_to_be16(20)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
257/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 * TCP State Values
259 */
260enum {
261 IP_VS_TCP_S_NONE = 0,
262 IP_VS_TCP_S_ESTABLISHED,
263 IP_VS_TCP_S_SYN_SENT,
264 IP_VS_TCP_S_SYN_RECV,
265 IP_VS_TCP_S_FIN_WAIT,
266 IP_VS_TCP_S_TIME_WAIT,
267 IP_VS_TCP_S_CLOSE,
268 IP_VS_TCP_S_CLOSE_WAIT,
269 IP_VS_TCP_S_LAST_ACK,
270 IP_VS_TCP_S_LISTEN,
271 IP_VS_TCP_S_SYNACK,
272 IP_VS_TCP_S_LAST
273};
274
275/*
276 * UDP State Values
277 */
278enum {
279 IP_VS_UDP_S_NORMAL,
280 IP_VS_UDP_S_LAST,
281};
282
283/*
284 * ICMP State Values
285 */
286enum {
287 IP_VS_ICMP_S_NORMAL,
288 IP_VS_ICMP_S_LAST,
289};
290
291/*
Venkata Mohan Reddy2906f662010-02-18 12:31:05 +0100292 * SCTP State Values
293 */
294enum ip_vs_sctp_states {
295 IP_VS_SCTP_S_NONE,
296 IP_VS_SCTP_S_INIT_CLI,
297 IP_VS_SCTP_S_INIT_SER,
298 IP_VS_SCTP_S_INIT_ACK_CLI,
299 IP_VS_SCTP_S_INIT_ACK_SER,
300 IP_VS_SCTP_S_ECHO_CLI,
301 IP_VS_SCTP_S_ECHO_SER,
302 IP_VS_SCTP_S_ESTABLISHED,
303 IP_VS_SCTP_S_SHUT_CLI,
304 IP_VS_SCTP_S_SHUT_SER,
305 IP_VS_SCTP_S_SHUT_ACK_CLI,
306 IP_VS_SCTP_S_SHUT_ACK_SER,
307 IP_VS_SCTP_S_CLOSED,
308 IP_VS_SCTP_S_LAST
309};
310
311/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 * Delta sequence info structure
313 * Each ip_vs_conn has 2 (output AND input seq. changes).
314 * Only used in the VS/NAT.
315 */
316struct ip_vs_seq {
317 __u32 init_seq; /* Add delta from this seq */
318 __u32 delta; /* Delta in sequence numbers */
319 __u32 previous_delta; /* Delta in sequence numbers
320 before last resized pkt */
321};
322
323
324/*
Sven Wegener3a14a3132008-08-10 18:24:41 +0000325 * IPVS statistics objects
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 */
Sven Wegener3a14a3132008-08-10 18:24:41 +0000327struct ip_vs_estimator {
328 struct list_head list;
329
330 u64 last_inbytes;
331 u64 last_outbytes;
332 u32 last_conns;
333 u32 last_inpkts;
334 u32 last_outpkts;
335
336 u32 cps;
337 u32 inpps;
338 u32 outpps;
339 u32 inbps;
340 u32 outbps;
341};
342
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +0000343struct ip_vs_stats {
Sven Wegenere9c0ce22008-09-08 13:39:04 +0200344 struct ip_vs_stats_user ustats; /* statistics */
345 struct ip_vs_estimator est; /* estimator */
Sven Wegener3a14a3132008-08-10 18:24:41 +0000346
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 spinlock_t lock; /* spin lock */
348};
349
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -0200350struct dst_entry;
351struct iphdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352struct ip_vs_conn;
353struct ip_vs_app;
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -0200354struct sk_buff;
Hans Schillstrom252c6412011-01-03 14:44:46 +0100355struct ip_vs_proto_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
357struct ip_vs_protocol {
358 struct ip_vs_protocol *next;
359 char *name;
Julian Anastasov2ad17de2008-04-29 03:21:23 -0700360 u16 protocol;
361 u16 num_states;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 int dont_defrag;
363 atomic_t appcnt; /* counter of proto app incs */
364 int *timeout_table; /* protocol timeout table */
365
366 void (*init)(struct ip_vs_protocol *pp);
367
368 void (*exit)(struct ip_vs_protocol *pp);
369
Hans Schillstrom252c6412011-01-03 14:44:46 +0100370 void (*init_netns)(struct net *net, struct ip_vs_proto_data *pd);
371
372 void (*exit_netns)(struct net *net, struct ip_vs_proto_data *pd);
373
Julius Volz51ef3482008-09-02 15:55:40 +0200374 int (*conn_schedule)(int af, struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 struct ip_vs_protocol *pp,
376 int *verdict, struct ip_vs_conn **cpp);
377
378 struct ip_vs_conn *
Julius Volz51ef3482008-09-02 15:55:40 +0200379 (*conn_in_get)(int af,
380 const struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 struct ip_vs_protocol *pp,
Julius Volz51ef3482008-09-02 15:55:40 +0200382 const struct ip_vs_iphdr *iph,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 unsigned int proto_off,
384 int inverse);
385
386 struct ip_vs_conn *
Julius Volz51ef3482008-09-02 15:55:40 +0200387 (*conn_out_get)(int af,
388 const struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 struct ip_vs_protocol *pp,
Julius Volz51ef3482008-09-02 15:55:40 +0200390 const struct ip_vs_iphdr *iph,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 unsigned int proto_off,
392 int inverse);
393
Herbert Xu3db05fe2007-10-15 00:53:15 -0700394 int (*snat_handler)(struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
396
Herbert Xu3db05fe2007-10-15 00:53:15 -0700397 int (*dnat_handler)(struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
399
Julius Volz51ef3482008-09-02 15:55:40 +0200400 int (*csum_check)(int af, struct sk_buff *skb,
401 struct ip_vs_protocol *pp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
403 const char *(*state_name)(int state);
404
405 int (*state_transition)(struct ip_vs_conn *cp, int direction,
406 const struct sk_buff *skb,
407 struct ip_vs_protocol *pp);
408
409 int (*register_app)(struct ip_vs_app *inc);
410
411 void (*unregister_app)(struct ip_vs_app *inc);
412
413 int (*app_conn_bind)(struct ip_vs_conn *cp);
414
Julian Anastasov0d796412010-10-17 16:46:17 +0300415 void (*debug_packet)(int af, struct ip_vs_protocol *pp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 const struct sk_buff *skb,
417 int offset,
418 const char *msg);
419
420 void (*timeout_change)(struct ip_vs_protocol *pp, int flags);
421
422 int (*set_state_timeout)(struct ip_vs_protocol *pp, char *sname, int to);
423};
424
Hans Schillstrom252c6412011-01-03 14:44:46 +0100425/*
426 * protocol data per netns
427 */
428struct ip_vs_proto_data {
429 struct ip_vs_proto_data *next;
430 struct ip_vs_protocol *pp;
431 int *timeout_table; /* protocol timeout table */
432 atomic_t appcnt; /* counter of proto app incs. */
433 struct tcp_states_t *tcp_state_table;
434};
435
436extern struct ip_vs_protocol *ip_vs_proto_get(unsigned short proto);
437extern struct ip_vs_proto_data *ip_vs_proto_data_get(struct net *net,
438 unsigned short proto);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
Simon Hormanf11017e2010-08-22 21:37:52 +0900440struct ip_vs_conn_param {
441 const union nf_inet_addr *caddr;
442 const union nf_inet_addr *vaddr;
443 __be16 cport;
444 __be16 vport;
445 __u16 protocol;
446 u16 af;
Simon Horman85999282010-08-22 21:37:53 +0900447
448 const struct ip_vs_pe *pe;
449 char *pe_data;
450 __u8 pe_data_len;
Simon Hormanf11017e2010-08-22 21:37:52 +0900451};
452
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453/*
454 * IP_VS structure allocated for each dynamically scheduled connection
455 */
456struct ip_vs_conn {
457 struct list_head c_list; /* hashed list heads */
458
459 /* Protocol, addresses and port numbers */
Julius Volze7ade462008-09-02 15:55:33 +0200460 u16 af; /* address family */
461 union nf_inet_addr caddr; /* client address */
462 union nf_inet_addr vaddr; /* virtual address */
463 union nf_inet_addr daddr; /* destination address */
Julian Anastasov35757922010-09-17 14:18:16 +0200464 volatile __u32 flags; /* status flags */
Hans Schillstrom0e051e62010-11-19 14:25:07 +0100465 __u32 fwmark; /* Fire wall mark from skb */
Al Viro014d7302006-09-28 14:29:52 -0700466 __be16 cport;
467 __be16 vport;
468 __be16 dport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 __u16 protocol; /* Which protocol (TCP/UDP) */
470
471 /* counter and timer */
472 atomic_t refcnt; /* reference count */
473 struct timer_list timer; /* Expiration timer */
474 volatile unsigned long timeout; /* timeout */
475
476 /* Flags and state transition */
477 spinlock_t lock; /* lock for state transition */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 volatile __u16 state; /* state info */
Rumen G. Bogdanovskiefac5272007-11-07 02:36:55 -0800479 volatile __u16 old_state; /* old state, to be used for
480 * state transition triggerd
481 * synchronization
482 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
484 /* Control members */
485 struct ip_vs_conn *control; /* Master control connection */
486 atomic_t n_control; /* Number of controlled ones */
487 struct ip_vs_dest *dest; /* real server */
488 atomic_t in_pkts; /* incoming packet counter */
489
490 /* packet transmitter for different forwarding methods. If it
491 mangles the packet, it must return NF_DROP or better NF_STOLEN,
492 otherwise this must be changed to a sk_buff **.
Julian Anastasovfc604762010-10-17 16:38:15 +0300493 NF_ACCEPT can be returned when destination is local.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 */
495 int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp,
496 struct ip_vs_protocol *pp);
497
498 /* Note: we can group the following members into a structure,
499 in order to save more space, and the following members are
500 only used in VS/NAT anyway */
501 struct ip_vs_app *app; /* bound ip_vs_app object */
502 void *app_data; /* Application private data */
503 struct ip_vs_seq in_seq; /* incoming seq. struct */
504 struct ip_vs_seq out_seq; /* outgoing seq. struct */
Simon Horman85999282010-08-22 21:37:53 +0900505
Simon Hormane9e5eee2010-11-08 20:05:57 +0900506 const struct ip_vs_pe *pe;
Simon Horman85999282010-08-22 21:37:53 +0900507 char *pe_data;
508 __u8 pe_data_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509};
510
511
512/*
Julius Volzc860c6b2008-09-02 15:55:36 +0200513 * Extended internal versions of struct ip_vs_service_user and
514 * ip_vs_dest_user for IPv6 support.
515 *
516 * We need these to conveniently pass around service and destination
517 * options, but unfortunately, we also need to keep the old definitions to
518 * maintain userspace backwards compatibility for the setsockopt interface.
519 */
520struct ip_vs_service_user_kern {
521 /* virtual service addresses */
522 u16 af;
523 u16 protocol;
524 union nf_inet_addr addr; /* virtual ip address */
525 u16 port;
526 u32 fwmark; /* firwall mark of service */
527
528 /* virtual service options */
529 char *sched_name;
Simon Horman0d1e71b2010-08-22 21:37:54 +0900530 char *pe_name;
Julius Volzc860c6b2008-09-02 15:55:36 +0200531 unsigned flags; /* virtual service flags */
532 unsigned timeout; /* persistent timeout in sec */
533 u32 netmask; /* persistent netmask */
534};
535
536
537struct ip_vs_dest_user_kern {
538 /* destination server address */
539 union nf_inet_addr addr;
540 u16 port;
541
542 /* real server options */
543 unsigned conn_flags; /* connection flags */
544 int weight; /* destination weight */
545
546 /* thresholds for active connections */
547 u32 u_threshold; /* upper threshold */
548 u32 l_threshold; /* lower threshold */
549};
550
551
552/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 * The information about the virtual service offered to the net
554 * and the forwarding entries
555 */
556struct ip_vs_service {
557 struct list_head s_list; /* for normal service table */
558 struct list_head f_list; /* for fwmark-based service table */
559 atomic_t refcnt; /* reference counter */
560 atomic_t usecnt; /* use counter */
561
Julius Volze7ade462008-09-02 15:55:33 +0200562 u16 af; /* address family */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 __u16 protocol; /* which protocol (TCP/UDP) */
Julius Volze7ade462008-09-02 15:55:33 +0200564 union nf_inet_addr addr; /* IP address for virtual service */
Al Viro014d7302006-09-28 14:29:52 -0700565 __be16 port; /* port number for the service */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 __u32 fwmark; /* firewall mark of the service */
567 unsigned flags; /* service status flags */
568 unsigned timeout; /* persistent timeout in ticks */
Al Viro014d7302006-09-28 14:29:52 -0700569 __be32 netmask; /* grouping granularity */
Hans Schillstromfc723252011-01-03 14:44:43 +0100570 struct net *net;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
572 struct list_head destinations; /* real server d-linked list */
573 __u32 num_dests; /* number of servers */
574 struct ip_vs_stats stats; /* statistics for the service */
575 struct ip_vs_app *inc; /* bind conns to this app inc */
576
577 /* for scheduling */
578 struct ip_vs_scheduler *scheduler; /* bound scheduler object */
579 rwlock_t sched_lock; /* lock sched_data */
580 void *sched_data; /* scheduler application data */
Simon Horman85999282010-08-22 21:37:53 +0900581
582 /* alternate persistence engine */
583 struct ip_vs_pe *pe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584};
585
586
587/*
588 * The real server destination forwarding entry
589 * with ip address, port number, and so on.
590 */
591struct ip_vs_dest {
592 struct list_head n_list; /* for the dests in the service */
593 struct list_head d_list; /* for table with all the dests */
594
Julius Volze7ade462008-09-02 15:55:33 +0200595 u16 af; /* address family */
596 union nf_inet_addr addr; /* IP address of the server */
Al Viro014d7302006-09-28 14:29:52 -0700597 __be16 port; /* port number of the server */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 volatile unsigned flags; /* dest status flags */
599 atomic_t conn_flags; /* flags to copy to conn */
600 atomic_t weight; /* server weight */
601
602 atomic_t refcnt; /* reference counter */
603 struct ip_vs_stats stats; /* statistics */
604
605 /* connection counters and thresholds */
606 atomic_t activeconns; /* active connections */
607 atomic_t inactconns; /* inactive connections */
608 atomic_t persistconns; /* persistent connections */
609 __u32 u_threshold; /* upper threshold */
610 __u32 l_threshold; /* lower threshold */
611
612 /* for destination cache */
613 spinlock_t dst_lock; /* lock of dst_cache */
614 struct dst_entry *dst_cache; /* destination cache entry */
615 u32 dst_rtos; /* RT_TOS(tos) for dst */
Hans Schillstrom714f0952010-10-19 10:38:48 +0200616 u32 dst_cookie;
617#ifdef CONFIG_IP_VS_IPV6
618 struct in6_addr dst_saddr;
619#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620
621 /* for virtual service */
622 struct ip_vs_service *svc; /* service it belongs to */
623 __u16 protocol; /* which protocol (TCP/UDP) */
Julius Volze7ade462008-09-02 15:55:33 +0200624 union nf_inet_addr vaddr; /* virtual IP address */
Al Viro014d7302006-09-28 14:29:52 -0700625 __be16 vport; /* virtual port number */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 __u32 vfwmark; /* firewall mark of service */
627};
628
629
630/*
631 * The scheduler object
632 */
633struct ip_vs_scheduler {
634 struct list_head n_list; /* d-linked list head */
635 char *name; /* scheduler name */
636 atomic_t refcnt; /* reference counter */
637 struct module *module; /* THIS_MODULE/NULL */
638
639 /* scheduler initializing service */
640 int (*init_service)(struct ip_vs_service *svc);
641 /* scheduling service finish */
642 int (*done_service)(struct ip_vs_service *svc);
643 /* scheduler updating service */
644 int (*update_service)(struct ip_vs_service *svc);
645
646 /* selecting a server from the given service */
647 struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc,
648 const struct sk_buff *skb);
649};
650
Simon Horman85999282010-08-22 21:37:53 +0900651/* The persistence engine object */
652struct ip_vs_pe {
653 struct list_head n_list; /* d-linked list head */
654 char *name; /* scheduler name */
655 atomic_t refcnt; /* reference counter */
656 struct module *module; /* THIS_MODULE/NULL */
657
658 /* get the connection template, if any */
659 int (*fill_param)(struct ip_vs_conn_param *p, struct sk_buff *skb);
660 bool (*ct_match)(const struct ip_vs_conn_param *p,
661 struct ip_vs_conn *ct);
662 u32 (*hashkey_raw)(const struct ip_vs_conn_param *p, u32 initval,
663 bool inverse);
Simon Hormana3c918a2010-08-22 21:37:53 +0900664 int (*show_pe_data)(const struct ip_vs_conn *cp, char *buf);
Simon Horman85999282010-08-22 21:37:53 +0900665};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666
667/*
668 * The application module object (a.k.a. app incarnation)
669 */
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +0000670struct ip_vs_app {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 struct list_head a_list; /* member in app list */
672 int type; /* IP_VS_APP_TYPE_xxx */
673 char *name; /* application module name */
674 __u16 protocol;
675 struct module *module; /* THIS_MODULE/NULL */
676 struct list_head incs_list; /* list of incarnations */
677
678 /* members for application incarnations */
679 struct list_head p_list; /* member in proto app list */
680 struct ip_vs_app *app; /* its real application */
Al Viro014d7302006-09-28 14:29:52 -0700681 __be16 port; /* port number in net order */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 atomic_t usecnt; /* usage counter */
683
Julian Anastasov8b27b102010-10-17 16:17:20 +0300684 /*
685 * output hook: Process packet in inout direction, diff set for TCP.
686 * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
687 * 2=Mangled but checksum was not updated
688 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *,
Herbert Xu3db05fe2007-10-15 00:53:15 -0700690 struct sk_buff *, int *diff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
Julian Anastasov8b27b102010-10-17 16:17:20 +0300692 /*
693 * input hook: Process packet in outin direction, diff set for TCP.
694 * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
695 * 2=Mangled but checksum was not updated
696 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *,
Herbert Xu3db05fe2007-10-15 00:53:15 -0700698 struct sk_buff *, int *diff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
700 /* ip_vs_app initializer */
701 int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *);
702
703 /* ip_vs_app finish */
704 int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *);
705
706
707 /* not used now */
708 int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *,
709 struct ip_vs_protocol *);
710
711 void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *);
712
713 int * timeout_table;
714 int * timeouts;
715 int timeouts_size;
716
717 int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app,
718 int *verdict, struct ip_vs_conn **cpp);
719
720 struct ip_vs_conn *
721 (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app,
722 const struct iphdr *iph, unsigned int proto_off,
723 int inverse);
724
725 struct ip_vs_conn *
726 (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app,
727 const struct iphdr *iph, unsigned int proto_off,
728 int inverse);
729
730 int (*state_transition)(struct ip_vs_conn *cp, int direction,
731 const struct sk_buff *skb,
732 struct ip_vs_app *app);
733
734 void (*timeout_change)(struct ip_vs_app *app, int flags);
735};
736
737
738/*
739 * IPVS core functions
740 * (from ip_vs_core.c)
741 */
742extern const char *ip_vs_proto_name(unsigned proto);
743extern void ip_vs_init_hash_table(struct list_head *table, int rows);
Sven Wegenerafdd6142008-08-10 09:18:01 +0000744#define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746#define IP_VS_APP_TYPE_FTP 1
747
748/*
749 * ip_vs_conn handling functions
750 * (from ip_vs_conn.c)
751 */
752
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753enum {
754 IP_VS_DIR_INPUT = 0,
755 IP_VS_DIR_OUTPUT,
756 IP_VS_DIR_INPUT_ONLY,
757 IP_VS_DIR_LAST,
758};
759
Simon Hormanf11017e2010-08-22 21:37:52 +0900760static inline void ip_vs_conn_fill_param(int af, int protocol,
761 const union nf_inet_addr *caddr,
762 __be16 cport,
763 const union nf_inet_addr *vaddr,
764 __be16 vport,
765 struct ip_vs_conn_param *p)
766{
767 p->af = af;
768 p->protocol = protocol;
769 p->caddr = caddr;
770 p->cport = cport;
771 p->vaddr = vaddr;
772 p->vport = vport;
Simon Horman85999282010-08-22 21:37:53 +0900773 p->pe = NULL;
774 p->pe_data = NULL;
Simon Hormanf11017e2010-08-22 21:37:52 +0900775}
Julius Volz28364a52008-09-02 15:55:43 +0200776
Simon Hormanf11017e2010-08-22 21:37:52 +0900777struct ip_vs_conn *ip_vs_conn_in_get(const struct ip_vs_conn_param *p);
778struct ip_vs_conn *ip_vs_ct_in_get(const struct ip_vs_conn_param *p);
Julius Volz28364a52008-09-02 15:55:43 +0200779
Simon Horman5c0d2372010-08-02 17:12:44 +0200780struct ip_vs_conn * ip_vs_conn_in_get_proto(int af, const struct sk_buff *skb,
781 struct ip_vs_protocol *pp,
782 const struct ip_vs_iphdr *iph,
783 unsigned int proto_off,
784 int inverse);
785
Simon Hormanf11017e2010-08-22 21:37:52 +0900786struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
Simon Horman5c0d2372010-08-02 17:12:44 +0200788struct ip_vs_conn * ip_vs_conn_out_get_proto(int af, const struct sk_buff *skb,
789 struct ip_vs_protocol *pp,
790 const struct ip_vs_iphdr *iph,
791 unsigned int proto_off,
792 int inverse);
793
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794/* put back the conn without restarting its timer */
795static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
796{
797 atomic_dec(&cp->refcnt);
798}
799extern void ip_vs_conn_put(struct ip_vs_conn *cp);
Al Viro014d7302006-09-28 14:29:52 -0700800extern void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
Simon Hormanf11017e2010-08-22 21:37:52 +0900802struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p,
803 const union nf_inet_addr *daddr,
804 __be16 dport, unsigned flags,
Hans Schillstrom0e051e62010-11-19 14:25:07 +0100805 struct ip_vs_dest *dest, __u32 fwmark);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
807
808extern const char * ip_vs_state_name(__u16 proto, int state);
809
810extern void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp);
811extern int ip_vs_check_template(struct ip_vs_conn *ct);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812extern void ip_vs_random_dropentry(void);
813extern int ip_vs_conn_init(void);
814extern void ip_vs_conn_cleanup(void);
815
816static inline void ip_vs_control_del(struct ip_vs_conn *cp)
817{
818 struct ip_vs_conn *ctl_cp = cp->control;
819 if (!ctl_cp) {
Julius Volzcfc78c52008-09-02 15:55:53 +0200820 IP_VS_ERR_BUF("request control DEL for uncontrolled: "
821 "%s:%d to %s:%d\n",
822 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
823 ntohs(cp->cport),
824 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
825 ntohs(cp->vport));
826
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 return;
828 }
829
Julius Volzcfc78c52008-09-02 15:55:53 +0200830 IP_VS_DBG_BUF(7, "DELeting control for: "
831 "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
832 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
833 ntohs(cp->cport),
834 IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
835 ntohs(ctl_cp->cport));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
837 cp->control = NULL;
838 if (atomic_read(&ctl_cp->n_control) == 0) {
Julius Volzcfc78c52008-09-02 15:55:53 +0200839 IP_VS_ERR_BUF("BUG control DEL with n=0 : "
840 "%s:%d to %s:%d\n",
841 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
842 ntohs(cp->cport),
843 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
844 ntohs(cp->vport));
845
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 return;
847 }
848 atomic_dec(&ctl_cp->n_control);
849}
850
851static inline void
852ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)
853{
854 if (cp->control) {
Julius Volzcfc78c52008-09-02 15:55:53 +0200855 IP_VS_ERR_BUF("request control ADD for already controlled: "
856 "%s:%d to %s:%d\n",
857 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
858 ntohs(cp->cport),
859 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
860 ntohs(cp->vport));
861
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 ip_vs_control_del(cp);
863 }
864
Julius Volzcfc78c52008-09-02 15:55:53 +0200865 IP_VS_DBG_BUF(7, "ADDing control for: "
866 "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
867 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
868 ntohs(cp->cport),
869 IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
870 ntohs(ctl_cp->cport));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
872 cp->control = ctl_cp;
873 atomic_inc(&ctl_cp->n_control);
874}
875
876
877/*
878 * IPVS application functions
879 * (from ip_vs_app.c)
880 */
881#define IP_VS_APP_MAX_PORTS 8
882extern int register_ip_vs_app(struct ip_vs_app *app);
883extern void unregister_ip_vs_app(struct ip_vs_app *app);
884extern int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
885extern void ip_vs_unbind_app(struct ip_vs_conn *cp);
886extern int
887register_ip_vs_app_inc(struct ip_vs_app *app, __u16 proto, __u16 port);
888extern int ip_vs_app_inc_get(struct ip_vs_app *inc);
889extern void ip_vs_app_inc_put(struct ip_vs_app *inc);
890
Herbert Xu3db05fe2007-10-15 00:53:15 -0700891extern int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb);
892extern int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893extern int ip_vs_app_init(void);
894extern void ip_vs_app_cleanup(void);
895
Simon Horman8be67a62010-08-22 21:37:54 +0900896void ip_vs_bind_pe(struct ip_vs_service *svc, struct ip_vs_pe *pe);
897void ip_vs_unbind_pe(struct ip_vs_service *svc);
898int register_ip_vs_pe(struct ip_vs_pe *pe);
899int unregister_ip_vs_pe(struct ip_vs_pe *pe);
Simon Hormane9e5eee2010-11-08 20:05:57 +0900900struct ip_vs_pe *ip_vs_pe_getbyname(const char *name);
Hans Schillstromfe5e7a12010-11-19 14:25:12 +0100901struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name);
Simon Hormane9e5eee2010-11-08 20:05:57 +0900902
903static inline void ip_vs_pe_get(const struct ip_vs_pe *pe)
904{
905 if (pe && pe->module)
906 __module_get(pe->module);
907}
908
909static inline void ip_vs_pe_put(const struct ip_vs_pe *pe)
910{
911 if (pe && pe->module)
912 module_put(pe->module);
913}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
915/*
916 * IPVS protocol functions (from ip_vs_proto.c)
917 */
918extern int ip_vs_protocol_init(void);
919extern void ip_vs_protocol_cleanup(void);
920extern void ip_vs_protocol_timeout_change(int flags);
921extern int *ip_vs_create_timeout_table(int *table, int size);
922extern int
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -0700923ip_vs_set_state_timeout(int *table, int num, const char *const *names,
924 const char *name, int to);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925extern void
Julian Anastasov0d796412010-10-17 16:46:17 +0300926ip_vs_tcpudp_debug_packet(int af, struct ip_vs_protocol *pp,
927 const struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 int offset, const char *msg);
929
930extern struct ip_vs_protocol ip_vs_protocol_tcp;
931extern struct ip_vs_protocol ip_vs_protocol_udp;
932extern struct ip_vs_protocol ip_vs_protocol_icmp;
933extern struct ip_vs_protocol ip_vs_protocol_esp;
934extern struct ip_vs_protocol ip_vs_protocol_ah;
Venkata Mohan Reddy2906f662010-02-18 12:31:05 +0100935extern struct ip_vs_protocol ip_vs_protocol_sctp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936
937/*
938 * Registering/unregistering scheduler functions
939 * (from ip_vs_sched.c)
940 */
941extern int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
942extern int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
943extern int ip_vs_bind_scheduler(struct ip_vs_service *svc,
944 struct ip_vs_scheduler *scheduler);
945extern int ip_vs_unbind_scheduler(struct ip_vs_service *svc);
946extern struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name);
947extern void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler);
948extern struct ip_vs_conn *
Julian Anastasov190ecd22010-10-17 16:24:37 +0300949ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,
950 struct ip_vs_protocol *pp, int *ignored);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951extern int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
952 struct ip_vs_protocol *pp);
953
954
955/*
956 * IPVS control data and functions (from ip_vs_ctl.c)
957 */
958extern int sysctl_ip_vs_cache_bypass;
959extern int sysctl_ip_vs_expire_nodest_conn;
960extern int sysctl_ip_vs_expire_quiescent_template;
961extern int sysctl_ip_vs_sync_threshold[2];
962extern int sysctl_ip_vs_nat_icmp_send;
Julian Anastasovf4bc17c2010-09-21 17:35:41 +0200963extern int sysctl_ip_vs_conntrack;
Julian Anastasov8a803042010-09-21 17:38:57 +0200964extern int sysctl_ip_vs_snat_reroute;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965extern struct ip_vs_stats ip_vs_stats;
Sven Wegener5587da52008-08-10 18:24:40 +0000966extern const struct ctl_path net_vs_ctl_path[];
Hans Schillstromb880c1f2010-11-19 14:25:14 +0100967extern int sysctl_ip_vs_sync_ver;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968
Hans Schillstromb880c1f2010-11-19 14:25:14 +0100969extern void ip_vs_sync_switch_mode(int mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970extern struct ip_vs_service *
Hans Schillstromfc723252011-01-03 14:44:43 +0100971ip_vs_service_get(struct net *net, int af, __u32 fwmark, __u16 protocol,
Julius Volz3c2e0502008-09-02 15:55:38 +0200972 const union nf_inet_addr *vaddr, __be16 vport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973
974static inline void ip_vs_service_put(struct ip_vs_service *svc)
975{
976 atomic_dec(&svc->usecnt);
977}
978
979extern struct ip_vs_dest *
Hans Schillstromfc723252011-01-03 14:44:43 +0100980ip_vs_lookup_real_service(struct net *net, int af, __u16 protocol,
Julius Volz7937df12008-09-02 15:55:48 +0200981 const union nf_inet_addr *daddr, __be16 dport);
982
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983extern int ip_vs_use_count_inc(void);
984extern void ip_vs_use_count_dec(void);
985extern int ip_vs_control_init(void);
986extern void ip_vs_control_cleanup(void);
Rumen G. Bogdanovski1e356f92007-11-07 02:35:54 -0800987extern struct ip_vs_dest *
Hans Schillstromfc723252011-01-03 14:44:43 +0100988ip_vs_find_dest(struct net *net, int af, const union nf_inet_addr *daddr,
989 __be16 dport, const union nf_inet_addr *vaddr, __be16 vport,
990 __u16 protocol, __u32 fwmark);
Rumen G. Bogdanovski1e356f92007-11-07 02:35:54 -0800991extern struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992
993
994/*
995 * IPVS sync daemon data and function prototypes
996 * (from ip_vs_sync.c)
997 */
998extern volatile int ip_vs_sync_state;
999extern volatile int ip_vs_master_syncid;
1000extern volatile int ip_vs_backup_syncid;
1001extern char ip_vs_master_mcast_ifn[IP_VS_IFNAME_MAXLEN];
1002extern char ip_vs_backup_mcast_ifn[IP_VS_IFNAME_MAXLEN];
1003extern int start_sync_thread(int state, char *mcast_ifn, __u8 syncid);
1004extern int stop_sync_thread(int state);
Hans Schillstrom986a0752010-11-19 14:25:13 +01001005extern void ip_vs_sync_conn(struct ip_vs_conn *cp);
Hans Schillstrom61b1ab42011-01-03 14:44:42 +01001006extern int ip_vs_sync_init(void);
1007extern void ip_vs_sync_cleanup(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
1009
1010/*
1011 * IPVS rate estimator prototypes (from ip_vs_est.c)
1012 */
Sven Wegenera919cf42008-08-14 00:47:16 +02001013extern int ip_vs_estimator_init(void);
1014extern void ip_vs_estimator_cleanup(void);
Sven Wegener3a14a3132008-08-10 18:24:41 +00001015extern void ip_vs_new_estimator(struct ip_vs_stats *stats);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016extern void ip_vs_kill_estimator(struct ip_vs_stats *stats);
1017extern void ip_vs_zero_estimator(struct ip_vs_stats *stats);
1018
1019/*
1020 * Various IPVS packet transmitters (from ip_vs_xmit.c)
1021 */
1022extern int ip_vs_null_xmit
1023(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
1024extern int ip_vs_bypass_xmit
1025(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
1026extern int ip_vs_nat_xmit
1027(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
1028extern int ip_vs_tunnel_xmit
1029(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
1030extern int ip_vs_dr_xmit
1031(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
1032extern int ip_vs_icmp_xmit
1033(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, int offset);
1034extern void ip_vs_dst_reset(struct ip_vs_dest *dest);
1035
Julius Volzb3cdd2a72008-09-02 15:55:45 +02001036#ifdef CONFIG_IP_VS_IPV6
1037extern int ip_vs_bypass_xmit_v6
1038(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
1039extern int ip_vs_nat_xmit_v6
1040(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
1041extern int ip_vs_tunnel_xmit_v6
1042(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
1043extern int ip_vs_dr_xmit_v6
1044(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
1045extern int ip_vs_icmp_xmit_v6
1046(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp,
1047 int offset);
1048#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049
1050/*
1051 * This is a simple mechanism to ignore packets when
1052 * we are loaded. Just set ip_vs_drop_rate to 'n' and
1053 * we start to drop 1/rate of the packets
1054 */
1055extern int ip_vs_drop_rate;
1056extern int ip_vs_drop_counter;
1057
1058static __inline__ int ip_vs_todrop(void)
1059{
1060 if (!ip_vs_drop_rate) return 0;
1061 if (--ip_vs_drop_counter > 0) return 0;
1062 ip_vs_drop_counter = ip_vs_drop_rate;
1063 return 1;
1064}
1065
1066/*
1067 * ip_vs_fwd_tag returns the forwarding tag of the connection
1068 */
1069#define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK)
1070
Adrian Bunk732db652005-09-01 17:40:26 -07001071static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072{
1073 char fwd;
1074
1075 switch (IP_VS_FWD_METHOD(cp)) {
1076 case IP_VS_CONN_F_MASQ:
1077 fwd = 'M'; break;
1078 case IP_VS_CONN_F_LOCALNODE:
1079 fwd = 'L'; break;
1080 case IP_VS_CONN_F_TUNNEL:
1081 fwd = 'T'; break;
1082 case IP_VS_CONN_F_DROUTE:
1083 fwd = 'R'; break;
1084 case IP_VS_CONN_F_BYPASS:
1085 fwd = 'B'; break;
1086 default:
1087 fwd = '?'; break;
1088 }
1089 return fwd;
1090}
1091
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092extern void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,
Julius Volzb3cdd2a72008-09-02 15:55:45 +02001093 struct ip_vs_conn *cp, int dir);
1094
1095#ifdef CONFIG_IP_VS_IPV6
1096extern void ip_vs_nat_icmp_v6(struct sk_buff *skb, struct ip_vs_protocol *pp,
1097 struct ip_vs_conn *cp, int dir);
1098#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099
Al Virob1550f22006-11-14 21:37:50 -08001100extern __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
Al Virof9214b22006-11-16 02:41:18 -08001102static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103{
Al Virof9214b22006-11-16 02:41:18 -08001104 __be32 diff[2] = { ~old, new };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105
Joe Perches07f07572008-11-19 15:44:53 -08001106 return csum_partial(diff, sizeof(diff), oldsum);
Al Virof9214b22006-11-16 02:41:18 -08001107}
1108
Julius Volz0bbdd422008-09-02 15:55:42 +02001109#ifdef CONFIG_IP_VS_IPV6
1110static inline __wsum ip_vs_check_diff16(const __be32 *old, const __be32 *new,
1111 __wsum oldsum)
1112{
1113 __be32 diff[8] = { ~old[3], ~old[2], ~old[1], ~old[0],
1114 new[3], new[2], new[1], new[0] };
1115
Joe Perches07f07572008-11-19 15:44:53 -08001116 return csum_partial(diff, sizeof(diff), oldsum);
Julius Volz0bbdd422008-09-02 15:55:42 +02001117}
1118#endif
1119
Al Virof9214b22006-11-16 02:41:18 -08001120static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum)
1121{
1122 __be16 diff[2] = { ~old, new };
1123
Joe Perches07f07572008-11-19 15:44:53 -08001124 return csum_partial(diff, sizeof(diff), oldsum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125}
1126
Julian Anastasovcf356d62010-10-17 16:21:07 +03001127/*
1128 * Forget current conntrack (unconfirmed) and attach notrack entry
1129 */
1130static inline void ip_vs_notrack(struct sk_buff *skb)
1131{
1132#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1133 enum ip_conntrack_info ctinfo;
1134 struct nf_conn *ct = ct = nf_ct_get(skb, &ctinfo);
1135
1136 if (!ct || !nf_ct_is_untracked(ct)) {
1137 nf_reset(skb);
1138 skb->nfct = &nf_ct_untracked_get()->ct_general;
1139 skb->nfctinfo = IP_CT_NEW;
1140 nf_conntrack_get(skb->nfct);
1141 }
1142#endif
1143}
1144
Julian Anastasovf4bc17c2010-09-21 17:35:41 +02001145#ifdef CONFIG_IP_VS_NFCT
1146/*
1147 * Netfilter connection tracking
1148 * (from ip_vs_nfct.c)
1149 */
1150static inline int ip_vs_conntrack_enabled(void)
1151{
1152 return sysctl_ip_vs_conntrack;
1153}
1154
Julian Anastasov6523ce12010-09-05 18:02:29 +00001155extern void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp,
1156 int outin);
Julian Anastasovf4bc17c2010-09-21 17:35:41 +02001157extern int ip_vs_confirm_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp);
1158extern void ip_vs_nfct_expect_related(struct sk_buff *skb, struct nf_conn *ct,
1159 struct ip_vs_conn *cp, u_int8_t proto,
1160 const __be16 port, int from_rs);
1161extern void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp);
1162
1163#else
1164
1165static inline int ip_vs_conntrack_enabled(void)
1166{
1167 return 0;
1168}
1169
1170static inline void ip_vs_update_conntrack(struct sk_buff *skb,
1171 struct ip_vs_conn *cp, int outin)
1172{
1173}
1174
1175static inline int ip_vs_confirm_conntrack(struct sk_buff *skb,
1176 struct ip_vs_conn *cp)
1177{
1178 return NF_ACCEPT;
1179}
1180
1181static inline void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp)
1182{
1183}
1184/* CONFIG_IP_VS_NFCT */
1185#endif
Julian Anastasov6523ce12010-09-05 18:02:29 +00001186
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187#endif /* __KERNEL__ */
1188
Julius Volzbc4768e2008-07-31 20:45:24 -07001189#endif /* _NET_IP_VS_H */