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