blob: d4da774eca75d84d102ce6762f756502c60fd552 [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 Anastasovf4bc17c2010-09-21 17:35:41 +020028#ifdef CONFIG_IP_VS_NFCT
29#include <net/netfilter/nf_conntrack.h>
30#endif
Catalin(ux) M. BOIE6f7edb42010-01-05 05:50:24 +010031
32/* Connections' size value needed by ip_vs_ctl.c */
33extern int ip_vs_conn_tab_size;
34
35
Julius Volz64aae3c2008-09-02 15:55:34 +020036struct ip_vs_iphdr {
37 int len;
38 __u8 protocol;
39 union nf_inet_addr saddr;
40 union nf_inet_addr daddr;
41};
42
43static inline void
44ip_vs_fill_iphdr(int af, const void *nh, struct ip_vs_iphdr *iphdr)
45{
46#ifdef CONFIG_IP_VS_IPV6
47 if (af == AF_INET6) {
48 const struct ipv6hdr *iph = nh;
49 iphdr->len = sizeof(struct ipv6hdr);
50 iphdr->protocol = iph->nexthdr;
51 ipv6_addr_copy(&iphdr->saddr.in6, &iph->saddr);
52 ipv6_addr_copy(&iphdr->daddr.in6, &iph->daddr);
53 } else
54#endif
55 {
56 const struct iphdr *iph = nh;
57 iphdr->len = iph->ihl * 4;
58 iphdr->protocol = iph->protocol;
59 iphdr->saddr.ip = iph->saddr;
60 iphdr->daddr.ip = iph->daddr;
61 }
62}
63
64static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst,
65 const union nf_inet_addr *src)
66{
67#ifdef CONFIG_IP_VS_IPV6
68 if (af == AF_INET6)
69 ipv6_addr_copy(&dst->in6, &src->in6);
70 else
71#endif
72 dst->ip = src->ip;
73}
74
75static inline int ip_vs_addr_equal(int af, const union nf_inet_addr *a,
76 const union nf_inet_addr *b)
77{
78#ifdef CONFIG_IP_VS_IPV6
79 if (af == AF_INET6)
80 return ipv6_addr_equal(&a->in6, &b->in6);
81#endif
82 return a->ip == b->ip;
83}
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#ifdef CONFIG_IP_VS_DEBUG
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020086#include <linux/net.h>
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088extern int ip_vs_get_debug_level(void);
Julius Volzc842a3a2008-09-02 15:55:35 +020089
90static inline const char *ip_vs_dbg_addr(int af, char *buf, size_t buf_len,
91 const union nf_inet_addr *addr,
92 int *idx)
93{
94 int len;
95#ifdef CONFIG_IP_VS_IPV6
96 if (af == AF_INET6)
Harvey Harrison5b095d9892008-10-29 12:52:50 -070097 len = snprintf(&buf[*idx], buf_len - *idx, "[%pI6]",
Harvey Harrison0c6ce782008-10-28 16:09:23 -070098 &addr->in6) + 1;
Julius Volzc842a3a2008-09-02 15:55:35 +020099 else
100#endif
Harvey Harrison3685f25d2008-10-31 00:56:49 -0700101 len = snprintf(&buf[*idx], buf_len - *idx, "%pI4",
102 &addr->ip) + 1;
Julius Volzc842a3a2008-09-02 15:55:35 +0200103
104 *idx += len;
105 BUG_ON(*idx > buf_len + 1);
106 return &buf[*idx - len];
107}
108
Hannes Eder9aada7a2009-07-30 14:29:44 -0700109#define IP_VS_DBG_BUF(level, msg, ...) \
110 do { \
111 char ip_vs_dbg_buf[160]; \
112 int ip_vs_dbg_idx = 0; \
113 if (level <= ip_vs_get_debug_level()) \
114 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
115 } while (0)
116#define IP_VS_ERR_BUF(msg...) \
117 do { \
118 char ip_vs_dbg_buf[160]; \
119 int ip_vs_dbg_idx = 0; \
120 pr_err(msg); \
121 } while (0)
Julius Volzc842a3a2008-09-02 15:55:35 +0200122
123/* Only use from within IP_VS_DBG_BUF() or IP_VS_ERR_BUF macros */
Hannes Eder9aada7a2009-07-30 14:29:44 -0700124#define IP_VS_DBG_ADDR(af, addr) \
125 ip_vs_dbg_addr(af, ip_vs_dbg_buf, \
126 sizeof(ip_vs_dbg_buf), addr, \
127 &ip_vs_dbg_idx)
Julius Volzc842a3a2008-09-02 15:55:35 +0200128
Hannes Eder9aada7a2009-07-30 14:29:44 -0700129#define IP_VS_DBG(level, msg, ...) \
130 do { \
131 if (level <= ip_vs_get_debug_level()) \
132 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
133 } while (0)
134#define IP_VS_DBG_RL(msg, ...) \
135 do { \
136 if (net_ratelimit()) \
137 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
138 } while (0)
139#define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) \
140 do { \
141 if (level <= ip_vs_get_debug_level()) \
142 pp->debug_packet(pp, skb, ofs, msg); \
143 } while (0)
144#define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) \
145 do { \
146 if (level <= ip_vs_get_debug_level() && \
147 net_ratelimit()) \
148 pp->debug_packet(pp, skb, ofs, msg); \
149 } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150#else /* NO DEBUGGING at ALL */
Julius Volzc842a3a2008-09-02 15:55:35 +0200151#define IP_VS_DBG_BUF(level, msg...) do {} while (0)
152#define IP_VS_ERR_BUF(msg...) do {} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153#define IP_VS_DBG(level, msg...) do {} while (0)
154#define IP_VS_DBG_RL(msg...) do {} while (0)
155#define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) do {} while (0)
156#define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) do {} while (0)
157#endif
158
159#define IP_VS_BUG() BUG()
Hannes Eder1e3e2382009-08-02 11:05:41 +0000160#define IP_VS_ERR_RL(msg, ...) \
Hannes Eder9aada7a2009-07-30 14:29:44 -0700161 do { \
162 if (net_ratelimit()) \
Hannes Eder1e3e2382009-08-02 11:05:41 +0000163 pr_err(msg, ##__VA_ARGS__); \
Hannes Eder9aada7a2009-07-30 14:29:44 -0700164 } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166#ifdef CONFIG_IP_VS_DEBUG
167#define EnterFunction(level) \
Hannes Eder9aada7a2009-07-30 14:29:44 -0700168 do { \
169 if (level <= ip_vs_get_debug_level()) \
170 printk(KERN_DEBUG \
171 pr_fmt("Enter: %s, %s line %i\n"), \
172 __func__, __FILE__, __LINE__); \
173 } while (0)
174#define LeaveFunction(level) \
175 do { \
176 if (level <= ip_vs_get_debug_level()) \
177 printk(KERN_DEBUG \
178 pr_fmt("Leave: %s, %s line %i\n"), \
179 __func__, __FILE__, __LINE__); \
180 } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181#else
182#define EnterFunction(level) do {} while (0)
183#define LeaveFunction(level) do {} while (0)
184#endif
185
186#define IP_VS_WAIT_WHILE(expr) while (expr) { cpu_relax(); }
187
188
189/*
190 * The port number of FTP service (in network order).
191 */
Harvey Harrisonf3a7c662009-02-14 22:58:35 -0800192#define FTPPORT cpu_to_be16(21)
193#define FTPDATA cpu_to_be16(20)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
195/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 * TCP State Values
197 */
198enum {
199 IP_VS_TCP_S_NONE = 0,
200 IP_VS_TCP_S_ESTABLISHED,
201 IP_VS_TCP_S_SYN_SENT,
202 IP_VS_TCP_S_SYN_RECV,
203 IP_VS_TCP_S_FIN_WAIT,
204 IP_VS_TCP_S_TIME_WAIT,
205 IP_VS_TCP_S_CLOSE,
206 IP_VS_TCP_S_CLOSE_WAIT,
207 IP_VS_TCP_S_LAST_ACK,
208 IP_VS_TCP_S_LISTEN,
209 IP_VS_TCP_S_SYNACK,
210 IP_VS_TCP_S_LAST
211};
212
213/*
214 * UDP State Values
215 */
216enum {
217 IP_VS_UDP_S_NORMAL,
218 IP_VS_UDP_S_LAST,
219};
220
221/*
222 * ICMP State Values
223 */
224enum {
225 IP_VS_ICMP_S_NORMAL,
226 IP_VS_ICMP_S_LAST,
227};
228
229/*
Venkata Mohan Reddy2906f662010-02-18 12:31:05 +0100230 * SCTP State Values
231 */
232enum ip_vs_sctp_states {
233 IP_VS_SCTP_S_NONE,
234 IP_VS_SCTP_S_INIT_CLI,
235 IP_VS_SCTP_S_INIT_SER,
236 IP_VS_SCTP_S_INIT_ACK_CLI,
237 IP_VS_SCTP_S_INIT_ACK_SER,
238 IP_VS_SCTP_S_ECHO_CLI,
239 IP_VS_SCTP_S_ECHO_SER,
240 IP_VS_SCTP_S_ESTABLISHED,
241 IP_VS_SCTP_S_SHUT_CLI,
242 IP_VS_SCTP_S_SHUT_SER,
243 IP_VS_SCTP_S_SHUT_ACK_CLI,
244 IP_VS_SCTP_S_SHUT_ACK_SER,
245 IP_VS_SCTP_S_CLOSED,
246 IP_VS_SCTP_S_LAST
247};
248
249/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 * Delta sequence info structure
251 * Each ip_vs_conn has 2 (output AND input seq. changes).
252 * Only used in the VS/NAT.
253 */
254struct ip_vs_seq {
255 __u32 init_seq; /* Add delta from this seq */
256 __u32 delta; /* Delta in sequence numbers */
257 __u32 previous_delta; /* Delta in sequence numbers
258 before last resized pkt */
259};
260
261
262/*
Sven Wegener3a14a3132008-08-10 18:24:41 +0000263 * IPVS statistics objects
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 */
Sven Wegener3a14a3132008-08-10 18:24:41 +0000265struct ip_vs_estimator {
266 struct list_head list;
267
268 u64 last_inbytes;
269 u64 last_outbytes;
270 u32 last_conns;
271 u32 last_inpkts;
272 u32 last_outpkts;
273
274 u32 cps;
275 u32 inpps;
276 u32 outpps;
277 u32 inbps;
278 u32 outbps;
279};
280
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +0000281struct ip_vs_stats {
Sven Wegenere9c0ce22008-09-08 13:39:04 +0200282 struct ip_vs_stats_user ustats; /* statistics */
283 struct ip_vs_estimator est; /* estimator */
Sven Wegener3a14a3132008-08-10 18:24:41 +0000284
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 spinlock_t lock; /* spin lock */
286};
287
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -0200288struct dst_entry;
289struct iphdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290struct ip_vs_conn;
291struct ip_vs_app;
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -0200292struct sk_buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
294struct ip_vs_protocol {
295 struct ip_vs_protocol *next;
296 char *name;
Julian Anastasov2ad17de2008-04-29 03:21:23 -0700297 u16 protocol;
298 u16 num_states;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 int dont_defrag;
300 atomic_t appcnt; /* counter of proto app incs */
301 int *timeout_table; /* protocol timeout table */
302
303 void (*init)(struct ip_vs_protocol *pp);
304
305 void (*exit)(struct ip_vs_protocol *pp);
306
Julius Volz51ef3482008-09-02 15:55:40 +0200307 int (*conn_schedule)(int af, struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 struct ip_vs_protocol *pp,
309 int *verdict, struct ip_vs_conn **cpp);
310
311 struct ip_vs_conn *
Julius Volz51ef3482008-09-02 15:55:40 +0200312 (*conn_in_get)(int af,
313 const struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 struct ip_vs_protocol *pp,
Julius Volz51ef3482008-09-02 15:55:40 +0200315 const struct ip_vs_iphdr *iph,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 unsigned int proto_off,
317 int inverse);
318
319 struct ip_vs_conn *
Julius Volz51ef3482008-09-02 15:55:40 +0200320 (*conn_out_get)(int af,
321 const struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 struct ip_vs_protocol *pp,
Julius Volz51ef3482008-09-02 15:55:40 +0200323 const struct ip_vs_iphdr *iph,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 unsigned int proto_off,
325 int inverse);
326
Herbert Xu3db05fe2007-10-15 00:53:15 -0700327 int (*snat_handler)(struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
329
Herbert Xu3db05fe2007-10-15 00:53:15 -0700330 int (*dnat_handler)(struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
332
Julius Volz51ef3482008-09-02 15:55:40 +0200333 int (*csum_check)(int af, struct sk_buff *skb,
334 struct ip_vs_protocol *pp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
336 const char *(*state_name)(int state);
337
338 int (*state_transition)(struct ip_vs_conn *cp, int direction,
339 const struct sk_buff *skb,
340 struct ip_vs_protocol *pp);
341
342 int (*register_app)(struct ip_vs_app *inc);
343
344 void (*unregister_app)(struct ip_vs_app *inc);
345
346 int (*app_conn_bind)(struct ip_vs_conn *cp);
347
348 void (*debug_packet)(struct ip_vs_protocol *pp,
349 const struct sk_buff *skb,
350 int offset,
351 const char *msg);
352
353 void (*timeout_change)(struct ip_vs_protocol *pp, int flags);
354
355 int (*set_state_timeout)(struct ip_vs_protocol *pp, char *sname, int to);
356};
357
358extern struct ip_vs_protocol * ip_vs_proto_get(unsigned short proto);
359
Simon Hormanf11017e2010-08-22 21:37:52 +0900360struct ip_vs_conn_param {
361 const union nf_inet_addr *caddr;
362 const union nf_inet_addr *vaddr;
363 __be16 cport;
364 __be16 vport;
365 __u16 protocol;
366 u16 af;
367};
368
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369/*
370 * IP_VS structure allocated for each dynamically scheduled connection
371 */
372struct ip_vs_conn {
373 struct list_head c_list; /* hashed list heads */
374
375 /* Protocol, addresses and port numbers */
Julius Volze7ade462008-09-02 15:55:33 +0200376 u16 af; /* address family */
377 union nf_inet_addr caddr; /* client address */
378 union nf_inet_addr vaddr; /* virtual address */
379 union nf_inet_addr daddr; /* destination address */
Julian Anastasov35757922010-09-17 14:18:16 +0200380 volatile __u32 flags; /* status flags */
Al Viro014d7302006-09-28 14:29:52 -0700381 __be16 cport;
382 __be16 vport;
383 __be16 dport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 __u16 protocol; /* Which protocol (TCP/UDP) */
385
386 /* counter and timer */
387 atomic_t refcnt; /* reference count */
388 struct timer_list timer; /* Expiration timer */
389 volatile unsigned long timeout; /* timeout */
390
391 /* Flags and state transition */
392 spinlock_t lock; /* lock for state transition */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 volatile __u16 state; /* state info */
Rumen G. Bogdanovskiefac5272007-11-07 02:36:55 -0800394 volatile __u16 old_state; /* old state, to be used for
395 * state transition triggerd
396 * synchronization
397 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
399 /* Control members */
400 struct ip_vs_conn *control; /* Master control connection */
401 atomic_t n_control; /* Number of controlled ones */
402 struct ip_vs_dest *dest; /* real server */
403 atomic_t in_pkts; /* incoming packet counter */
404
405 /* packet transmitter for different forwarding methods. If it
406 mangles the packet, it must return NF_DROP or better NF_STOLEN,
407 otherwise this must be changed to a sk_buff **.
408 */
409 int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp,
410 struct ip_vs_protocol *pp);
411
412 /* Note: we can group the following members into a structure,
413 in order to save more space, and the following members are
414 only used in VS/NAT anyway */
415 struct ip_vs_app *app; /* bound ip_vs_app object */
416 void *app_data; /* Application private data */
417 struct ip_vs_seq in_seq; /* incoming seq. struct */
418 struct ip_vs_seq out_seq; /* outgoing seq. struct */
419};
420
421
422/*
Julius Volzc860c6b2008-09-02 15:55:36 +0200423 * Extended internal versions of struct ip_vs_service_user and
424 * ip_vs_dest_user for IPv6 support.
425 *
426 * We need these to conveniently pass around service and destination
427 * options, but unfortunately, we also need to keep the old definitions to
428 * maintain userspace backwards compatibility for the setsockopt interface.
429 */
430struct ip_vs_service_user_kern {
431 /* virtual service addresses */
432 u16 af;
433 u16 protocol;
434 union nf_inet_addr addr; /* virtual ip address */
435 u16 port;
436 u32 fwmark; /* firwall mark of service */
437
438 /* virtual service options */
439 char *sched_name;
440 unsigned flags; /* virtual service flags */
441 unsigned timeout; /* persistent timeout in sec */
442 u32 netmask; /* persistent netmask */
443};
444
445
446struct ip_vs_dest_user_kern {
447 /* destination server address */
448 union nf_inet_addr addr;
449 u16 port;
450
451 /* real server options */
452 unsigned conn_flags; /* connection flags */
453 int weight; /* destination weight */
454
455 /* thresholds for active connections */
456 u32 u_threshold; /* upper threshold */
457 u32 l_threshold; /* lower threshold */
458};
459
460
461/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 * The information about the virtual service offered to the net
463 * and the forwarding entries
464 */
465struct ip_vs_service {
466 struct list_head s_list; /* for normal service table */
467 struct list_head f_list; /* for fwmark-based service table */
468 atomic_t refcnt; /* reference counter */
469 atomic_t usecnt; /* use counter */
470
Julius Volze7ade462008-09-02 15:55:33 +0200471 u16 af; /* address family */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 __u16 protocol; /* which protocol (TCP/UDP) */
Julius Volze7ade462008-09-02 15:55:33 +0200473 union nf_inet_addr addr; /* IP address for virtual service */
Al Viro014d7302006-09-28 14:29:52 -0700474 __be16 port; /* port number for the service */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 __u32 fwmark; /* firewall mark of the service */
476 unsigned flags; /* service status flags */
477 unsigned timeout; /* persistent timeout in ticks */
Al Viro014d7302006-09-28 14:29:52 -0700478 __be32 netmask; /* grouping granularity */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
480 struct list_head destinations; /* real server d-linked list */
481 __u32 num_dests; /* number of servers */
482 struct ip_vs_stats stats; /* statistics for the service */
483 struct ip_vs_app *inc; /* bind conns to this app inc */
484
485 /* for scheduling */
486 struct ip_vs_scheduler *scheduler; /* bound scheduler object */
487 rwlock_t sched_lock; /* lock sched_data */
488 void *sched_data; /* scheduler application data */
489};
490
491
492/*
493 * The real server destination forwarding entry
494 * with ip address, port number, and so on.
495 */
496struct ip_vs_dest {
497 struct list_head n_list; /* for the dests in the service */
498 struct list_head d_list; /* for table with all the dests */
499
Julius Volze7ade462008-09-02 15:55:33 +0200500 u16 af; /* address family */
501 union nf_inet_addr addr; /* IP address of the server */
Al Viro014d7302006-09-28 14:29:52 -0700502 __be16 port; /* port number of the server */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 volatile unsigned flags; /* dest status flags */
504 atomic_t conn_flags; /* flags to copy to conn */
505 atomic_t weight; /* server weight */
506
507 atomic_t refcnt; /* reference counter */
508 struct ip_vs_stats stats; /* statistics */
509
510 /* connection counters and thresholds */
511 atomic_t activeconns; /* active connections */
512 atomic_t inactconns; /* inactive connections */
513 atomic_t persistconns; /* persistent connections */
514 __u32 u_threshold; /* upper threshold */
515 __u32 l_threshold; /* lower threshold */
516
517 /* for destination cache */
518 spinlock_t dst_lock; /* lock of dst_cache */
519 struct dst_entry *dst_cache; /* destination cache entry */
520 u32 dst_rtos; /* RT_TOS(tos) for dst */
521
522 /* for virtual service */
523 struct ip_vs_service *svc; /* service it belongs to */
524 __u16 protocol; /* which protocol (TCP/UDP) */
Julius Volze7ade462008-09-02 15:55:33 +0200525 union nf_inet_addr vaddr; /* virtual IP address */
Al Viro014d7302006-09-28 14:29:52 -0700526 __be16 vport; /* virtual port number */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 __u32 vfwmark; /* firewall mark of service */
528};
529
530
531/*
532 * The scheduler object
533 */
534struct ip_vs_scheduler {
535 struct list_head n_list; /* d-linked list head */
536 char *name; /* scheduler name */
537 atomic_t refcnt; /* reference counter */
538 struct module *module; /* THIS_MODULE/NULL */
539
540 /* scheduler initializing service */
541 int (*init_service)(struct ip_vs_service *svc);
542 /* scheduling service finish */
543 int (*done_service)(struct ip_vs_service *svc);
544 /* scheduler updating service */
545 int (*update_service)(struct ip_vs_service *svc);
546
547 /* selecting a server from the given service */
548 struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc,
549 const struct sk_buff *skb);
550};
551
552
553/*
554 * The application module object (a.k.a. app incarnation)
555 */
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +0000556struct ip_vs_app {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 struct list_head a_list; /* member in app list */
558 int type; /* IP_VS_APP_TYPE_xxx */
559 char *name; /* application module name */
560 __u16 protocol;
561 struct module *module; /* THIS_MODULE/NULL */
562 struct list_head incs_list; /* list of incarnations */
563
564 /* members for application incarnations */
565 struct list_head p_list; /* member in proto app list */
566 struct ip_vs_app *app; /* its real application */
Al Viro014d7302006-09-28 14:29:52 -0700567 __be16 port; /* port number in net order */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 atomic_t usecnt; /* usage counter */
569
570 /* output hook: return false if can't linearize. diff set for TCP. */
571 int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *,
Herbert Xu3db05fe2007-10-15 00:53:15 -0700572 struct sk_buff *, int *diff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
574 /* input hook: return false if can't linearize. diff set for TCP. */
575 int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *,
Herbert Xu3db05fe2007-10-15 00:53:15 -0700576 struct sk_buff *, int *diff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
578 /* ip_vs_app initializer */
579 int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *);
580
581 /* ip_vs_app finish */
582 int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *);
583
584
585 /* not used now */
586 int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *,
587 struct ip_vs_protocol *);
588
589 void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *);
590
591 int * timeout_table;
592 int * timeouts;
593 int timeouts_size;
594
595 int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app,
596 int *verdict, struct ip_vs_conn **cpp);
597
598 struct ip_vs_conn *
599 (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app,
600 const struct iphdr *iph, unsigned int proto_off,
601 int inverse);
602
603 struct ip_vs_conn *
604 (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app,
605 const struct iphdr *iph, unsigned int proto_off,
606 int inverse);
607
608 int (*state_transition)(struct ip_vs_conn *cp, int direction,
609 const struct sk_buff *skb,
610 struct ip_vs_app *app);
611
612 void (*timeout_change)(struct ip_vs_app *app, int flags);
613};
614
615
616/*
617 * IPVS core functions
618 * (from ip_vs_core.c)
619 */
620extern const char *ip_vs_proto_name(unsigned proto);
621extern void ip_vs_init_hash_table(struct list_head *table, int rows);
Sven Wegenerafdd6142008-08-10 09:18:01 +0000622#define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624#define IP_VS_APP_TYPE_FTP 1
625
626/*
627 * ip_vs_conn handling functions
628 * (from ip_vs_conn.c)
629 */
630
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631enum {
632 IP_VS_DIR_INPUT = 0,
633 IP_VS_DIR_OUTPUT,
634 IP_VS_DIR_INPUT_ONLY,
635 IP_VS_DIR_LAST,
636};
637
Simon Hormanf11017e2010-08-22 21:37:52 +0900638static inline void ip_vs_conn_fill_param(int af, int protocol,
639 const union nf_inet_addr *caddr,
640 __be16 cport,
641 const union nf_inet_addr *vaddr,
642 __be16 vport,
643 struct ip_vs_conn_param *p)
644{
645 p->af = af;
646 p->protocol = protocol;
647 p->caddr = caddr;
648 p->cport = cport;
649 p->vaddr = vaddr;
650 p->vport = vport;
651}
Julius Volz28364a52008-09-02 15:55:43 +0200652
Simon Hormanf11017e2010-08-22 21:37:52 +0900653struct ip_vs_conn *ip_vs_conn_in_get(const struct ip_vs_conn_param *p);
654struct ip_vs_conn *ip_vs_ct_in_get(const struct ip_vs_conn_param *p);
Julius Volz28364a52008-09-02 15:55:43 +0200655
Simon Horman5c0d2372010-08-02 17:12:44 +0200656struct ip_vs_conn * ip_vs_conn_in_get_proto(int af, const struct sk_buff *skb,
657 struct ip_vs_protocol *pp,
658 const struct ip_vs_iphdr *iph,
659 unsigned int proto_off,
660 int inverse);
661
Simon Hormanf11017e2010-08-22 21:37:52 +0900662struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
Simon Horman5c0d2372010-08-02 17:12:44 +0200664struct ip_vs_conn * ip_vs_conn_out_get_proto(int af, const struct sk_buff *skb,
665 struct ip_vs_protocol *pp,
666 const struct ip_vs_iphdr *iph,
667 unsigned int proto_off,
668 int inverse);
669
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670/* put back the conn without restarting its timer */
671static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
672{
673 atomic_dec(&cp->refcnt);
674}
675extern void ip_vs_conn_put(struct ip_vs_conn *cp);
Al Viro014d7302006-09-28 14:29:52 -0700676extern void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
Simon Hormanf11017e2010-08-22 21:37:52 +0900678struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p,
679 const union nf_inet_addr *daddr,
680 __be16 dport, unsigned flags,
681 struct ip_vs_dest *dest);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
683
684extern const char * ip_vs_state_name(__u16 proto, int state);
685
686extern void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp);
687extern int ip_vs_check_template(struct ip_vs_conn *ct);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688extern void ip_vs_random_dropentry(void);
689extern int ip_vs_conn_init(void);
690extern void ip_vs_conn_cleanup(void);
691
692static inline void ip_vs_control_del(struct ip_vs_conn *cp)
693{
694 struct ip_vs_conn *ctl_cp = cp->control;
695 if (!ctl_cp) {
Julius Volzcfc78c52008-09-02 15:55:53 +0200696 IP_VS_ERR_BUF("request control DEL for uncontrolled: "
697 "%s:%d to %s:%d\n",
698 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
699 ntohs(cp->cport),
700 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
701 ntohs(cp->vport));
702
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 return;
704 }
705
Julius Volzcfc78c52008-09-02 15:55:53 +0200706 IP_VS_DBG_BUF(7, "DELeting control for: "
707 "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
708 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
709 ntohs(cp->cport),
710 IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
711 ntohs(ctl_cp->cport));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712
713 cp->control = NULL;
714 if (atomic_read(&ctl_cp->n_control) == 0) {
Julius Volzcfc78c52008-09-02 15:55:53 +0200715 IP_VS_ERR_BUF("BUG control DEL with n=0 : "
716 "%s:%d to %s:%d\n",
717 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
718 ntohs(cp->cport),
719 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
720 ntohs(cp->vport));
721
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 return;
723 }
724 atomic_dec(&ctl_cp->n_control);
725}
726
727static inline void
728ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)
729{
730 if (cp->control) {
Julius Volzcfc78c52008-09-02 15:55:53 +0200731 IP_VS_ERR_BUF("request control ADD for already controlled: "
732 "%s:%d to %s:%d\n",
733 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
734 ntohs(cp->cport),
735 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
736 ntohs(cp->vport));
737
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 ip_vs_control_del(cp);
739 }
740
Julius Volzcfc78c52008-09-02 15:55:53 +0200741 IP_VS_DBG_BUF(7, "ADDing control for: "
742 "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
743 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
744 ntohs(cp->cport),
745 IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
746 ntohs(ctl_cp->cport));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
748 cp->control = ctl_cp;
749 atomic_inc(&ctl_cp->n_control);
750}
751
752
753/*
754 * IPVS application functions
755 * (from ip_vs_app.c)
756 */
757#define IP_VS_APP_MAX_PORTS 8
758extern int register_ip_vs_app(struct ip_vs_app *app);
759extern void unregister_ip_vs_app(struct ip_vs_app *app);
760extern int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
761extern void ip_vs_unbind_app(struct ip_vs_conn *cp);
762extern int
763register_ip_vs_app_inc(struct ip_vs_app *app, __u16 proto, __u16 port);
764extern int ip_vs_app_inc_get(struct ip_vs_app *inc);
765extern void ip_vs_app_inc_put(struct ip_vs_app *inc);
766
Herbert Xu3db05fe2007-10-15 00:53:15 -0700767extern int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb);
768extern int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769extern int ip_vs_app_init(void);
770extern void ip_vs_app_cleanup(void);
771
772
773/*
774 * IPVS protocol functions (from ip_vs_proto.c)
775 */
776extern int ip_vs_protocol_init(void);
777extern void ip_vs_protocol_cleanup(void);
778extern void ip_vs_protocol_timeout_change(int flags);
779extern int *ip_vs_create_timeout_table(int *table, int size);
780extern int
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -0700781ip_vs_set_state_timeout(int *table, int num, const char *const *names,
782 const char *name, int to);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783extern void
784ip_vs_tcpudp_debug_packet(struct ip_vs_protocol *pp, const struct sk_buff *skb,
785 int offset, const char *msg);
786
787extern struct ip_vs_protocol ip_vs_protocol_tcp;
788extern struct ip_vs_protocol ip_vs_protocol_udp;
789extern struct ip_vs_protocol ip_vs_protocol_icmp;
790extern struct ip_vs_protocol ip_vs_protocol_esp;
791extern struct ip_vs_protocol ip_vs_protocol_ah;
Venkata Mohan Reddy2906f662010-02-18 12:31:05 +0100792extern struct ip_vs_protocol ip_vs_protocol_sctp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
794/*
795 * Registering/unregistering scheduler functions
796 * (from ip_vs_sched.c)
797 */
798extern int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
799extern int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
800extern int ip_vs_bind_scheduler(struct ip_vs_service *svc,
801 struct ip_vs_scheduler *scheduler);
802extern int ip_vs_unbind_scheduler(struct ip_vs_service *svc);
803extern struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name);
804extern void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler);
805extern struct ip_vs_conn *
806ip_vs_schedule(struct ip_vs_service *svc, const struct sk_buff *skb);
807extern int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
808 struct ip_vs_protocol *pp);
809
810
811/*
812 * IPVS control data and functions (from ip_vs_ctl.c)
813 */
814extern int sysctl_ip_vs_cache_bypass;
815extern int sysctl_ip_vs_expire_nodest_conn;
816extern int sysctl_ip_vs_expire_quiescent_template;
817extern int sysctl_ip_vs_sync_threshold[2];
818extern int sysctl_ip_vs_nat_icmp_send;
Julian Anastasovf4bc17c2010-09-21 17:35:41 +0200819extern int sysctl_ip_vs_conntrack;
Julian Anastasov8a803042010-09-21 17:38:57 +0200820extern int sysctl_ip_vs_snat_reroute;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821extern struct ip_vs_stats ip_vs_stats;
Sven Wegener5587da52008-08-10 18:24:40 +0000822extern const struct ctl_path net_vs_ctl_path[];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
824extern struct ip_vs_service *
Julius Volz3c2e0502008-09-02 15:55:38 +0200825ip_vs_service_get(int af, __u32 fwmark, __u16 protocol,
826 const union nf_inet_addr *vaddr, __be16 vport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
828static inline void ip_vs_service_put(struct ip_vs_service *svc)
829{
830 atomic_dec(&svc->usecnt);
831}
832
833extern struct ip_vs_dest *
Julius Volz7937df12008-09-02 15:55:48 +0200834ip_vs_lookup_real_service(int af, __u16 protocol,
835 const union nf_inet_addr *daddr, __be16 dport);
836
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837extern int ip_vs_use_count_inc(void);
838extern void ip_vs_use_count_dec(void);
839extern int ip_vs_control_init(void);
840extern void ip_vs_control_cleanup(void);
Rumen G. Bogdanovski1e356f92007-11-07 02:35:54 -0800841extern struct ip_vs_dest *
Julius Volz7937df12008-09-02 15:55:48 +0200842ip_vs_find_dest(int af, const union nf_inet_addr *daddr, __be16 dport,
843 const union nf_inet_addr *vaddr, __be16 vport, __u16 protocol);
Rumen G. Bogdanovski1e356f92007-11-07 02:35:54 -0800844extern struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
846
847/*
848 * IPVS sync daemon data and function prototypes
849 * (from ip_vs_sync.c)
850 */
851extern volatile int ip_vs_sync_state;
852extern volatile int ip_vs_master_syncid;
853extern volatile int ip_vs_backup_syncid;
854extern char ip_vs_master_mcast_ifn[IP_VS_IFNAME_MAXLEN];
855extern char ip_vs_backup_mcast_ifn[IP_VS_IFNAME_MAXLEN];
856extern int start_sync_thread(int state, char *mcast_ifn, __u8 syncid);
857extern int stop_sync_thread(int state);
858extern void ip_vs_sync_conn(struct ip_vs_conn *cp);
859
860
861/*
862 * IPVS rate estimator prototypes (from ip_vs_est.c)
863 */
Sven Wegenera919cf42008-08-14 00:47:16 +0200864extern int ip_vs_estimator_init(void);
865extern void ip_vs_estimator_cleanup(void);
Sven Wegener3a14a3132008-08-10 18:24:41 +0000866extern void ip_vs_new_estimator(struct ip_vs_stats *stats);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867extern void ip_vs_kill_estimator(struct ip_vs_stats *stats);
868extern void ip_vs_zero_estimator(struct ip_vs_stats *stats);
869
870/*
871 * Various IPVS packet transmitters (from ip_vs_xmit.c)
872 */
873extern int ip_vs_null_xmit
874(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
875extern int ip_vs_bypass_xmit
876(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
877extern int ip_vs_nat_xmit
878(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
879extern int ip_vs_tunnel_xmit
880(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
881extern int ip_vs_dr_xmit
882(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
883extern int ip_vs_icmp_xmit
884(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, int offset);
885extern void ip_vs_dst_reset(struct ip_vs_dest *dest);
886
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200887#ifdef CONFIG_IP_VS_IPV6
888extern int ip_vs_bypass_xmit_v6
889(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
890extern int ip_vs_nat_xmit_v6
891(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
892extern int ip_vs_tunnel_xmit_v6
893(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
894extern int ip_vs_dr_xmit_v6
895(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
896extern int ip_vs_icmp_xmit_v6
897(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp,
898 int offset);
899#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900
901/*
902 * This is a simple mechanism to ignore packets when
903 * we are loaded. Just set ip_vs_drop_rate to 'n' and
904 * we start to drop 1/rate of the packets
905 */
906extern int ip_vs_drop_rate;
907extern int ip_vs_drop_counter;
908
909static __inline__ int ip_vs_todrop(void)
910{
911 if (!ip_vs_drop_rate) return 0;
912 if (--ip_vs_drop_counter > 0) return 0;
913 ip_vs_drop_counter = ip_vs_drop_rate;
914 return 1;
915}
916
917/*
918 * ip_vs_fwd_tag returns the forwarding tag of the connection
919 */
920#define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK)
921
Adrian Bunk732db652005-09-01 17:40:26 -0700922static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923{
924 char fwd;
925
926 switch (IP_VS_FWD_METHOD(cp)) {
927 case IP_VS_CONN_F_MASQ:
928 fwd = 'M'; break;
929 case IP_VS_CONN_F_LOCALNODE:
930 fwd = 'L'; break;
931 case IP_VS_CONN_F_TUNNEL:
932 fwd = 'T'; break;
933 case IP_VS_CONN_F_DROUTE:
934 fwd = 'R'; break;
935 case IP_VS_CONN_F_BYPASS:
936 fwd = 'B'; break;
937 default:
938 fwd = '?'; break;
939 }
940 return fwd;
941}
942
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943extern void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200944 struct ip_vs_conn *cp, int dir);
945
946#ifdef CONFIG_IP_VS_IPV6
947extern void ip_vs_nat_icmp_v6(struct sk_buff *skb, struct ip_vs_protocol *pp,
948 struct ip_vs_conn *cp, int dir);
949#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
Al Virob1550f22006-11-14 21:37:50 -0800951extern __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
Al Virof9214b22006-11-16 02:41:18 -0800953static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954{
Al Virof9214b22006-11-16 02:41:18 -0800955 __be32 diff[2] = { ~old, new };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
Joe Perches07f07572008-11-19 15:44:53 -0800957 return csum_partial(diff, sizeof(diff), oldsum);
Al Virof9214b22006-11-16 02:41:18 -0800958}
959
Julius Volz0bbdd422008-09-02 15:55:42 +0200960#ifdef CONFIG_IP_VS_IPV6
961static inline __wsum ip_vs_check_diff16(const __be32 *old, const __be32 *new,
962 __wsum oldsum)
963{
964 __be32 diff[8] = { ~old[3], ~old[2], ~old[1], ~old[0],
965 new[3], new[2], new[1], new[0] };
966
Joe Perches07f07572008-11-19 15:44:53 -0800967 return csum_partial(diff, sizeof(diff), oldsum);
Julius Volz0bbdd422008-09-02 15:55:42 +0200968}
969#endif
970
Al Virof9214b22006-11-16 02:41:18 -0800971static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum)
972{
973 __be16 diff[2] = { ~old, new };
974
Joe Perches07f07572008-11-19 15:44:53 -0800975 return csum_partial(diff, sizeof(diff), oldsum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976}
977
Julian Anastasovf4bc17c2010-09-21 17:35:41 +0200978#ifdef CONFIG_IP_VS_NFCT
979/*
980 * Netfilter connection tracking
981 * (from ip_vs_nfct.c)
982 */
983static inline int ip_vs_conntrack_enabled(void)
984{
985 return sysctl_ip_vs_conntrack;
986}
987
Julian Anastasov6523ce12010-09-05 18:02:29 +0000988extern void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp,
989 int outin);
Julian Anastasovf4bc17c2010-09-21 17:35:41 +0200990extern int ip_vs_confirm_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp);
991extern void ip_vs_nfct_expect_related(struct sk_buff *skb, struct nf_conn *ct,
992 struct ip_vs_conn *cp, u_int8_t proto,
993 const __be16 port, int from_rs);
994extern void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp);
995
996#else
997
998static inline int ip_vs_conntrack_enabled(void)
999{
1000 return 0;
1001}
1002
1003static inline void ip_vs_update_conntrack(struct sk_buff *skb,
1004 struct ip_vs_conn *cp, int outin)
1005{
1006}
1007
1008static inline int ip_vs_confirm_conntrack(struct sk_buff *skb,
1009 struct ip_vs_conn *cp)
1010{
1011 return NF_ACCEPT;
1012}
1013
1014static inline void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp)
1015{
1016}
1017/* CONFIG_IP_VS_NFCT */
1018#endif
Julian Anastasov6523ce12010-09-05 18:02:29 +00001019
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020#endif /* __KERNEL__ */
1021
Julius Volzbc4768e2008-07-31 20:45:24 -07001022#endif /* _NET_IP_VS_H */