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