3 * data structure and functionality definitions
9 #include <linux/ip_vs.h> /* definitions shared with userland */
11 /* old ipvsadm versions still include this file directly */
14 #include <asm/types.h> /* for __uXX types */
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>
23 #include <net/checksum.h>
24 #include <linux/netfilter.h> /* for union nf_inet_addr */
26 #include <linux/ipv6.h> /* for struct ipv6hdr */
27 #include <net/ipv6.h> /* for ipv6_addr_copy */
32 union nf_inet_addr saddr;
33 union nf_inet_addr daddr;
37 ip_vs_fill_iphdr(int af, const void *nh, struct ip_vs_iphdr *iphdr)
39 #ifdef CONFIG_IP_VS_IPV6
41 const struct ipv6hdr *iph = nh;
42 iphdr->len = sizeof(struct ipv6hdr);
43 iphdr->protocol = iph->nexthdr;
44 ipv6_addr_copy(&iphdr->saddr.in6, &iph->saddr);
45 ipv6_addr_copy(&iphdr->daddr.in6, &iph->daddr);
49 const struct iphdr *iph = nh;
50 iphdr->len = iph->ihl * 4;
51 iphdr->protocol = iph->protocol;
52 iphdr->saddr.ip = iph->saddr;
53 iphdr->daddr.ip = iph->daddr;
57 static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst,
58 const union nf_inet_addr *src)
60 #ifdef CONFIG_IP_VS_IPV6
62 ipv6_addr_copy(&dst->in6, &src->in6);
68 static inline int ip_vs_addr_equal(int af, const union nf_inet_addr *a,
69 const union nf_inet_addr *b)
71 #ifdef CONFIG_IP_VS_IPV6
73 return ipv6_addr_equal(&a->in6, &b->in6);
75 return a->ip == b->ip;
78 #ifdef CONFIG_IP_VS_DEBUG
79 #include <linux/net.h>
81 extern int ip_vs_get_debug_level(void);
83 static inline const char *ip_vs_dbg_addr(int af, char *buf, size_t buf_len,
84 const union nf_inet_addr *addr,
88 #ifdef CONFIG_IP_VS_IPV6
90 len = snprintf(&buf[*idx], buf_len - *idx, "[%pI6]",
94 len = snprintf(&buf[*idx], buf_len - *idx, "%pI4",
98 BUG_ON(*idx > buf_len + 1);
99 return &buf[*idx - len];
102 #define IP_VS_DBG_BUF(level, msg, ...) \
104 char ip_vs_dbg_buf[160]; \
105 int ip_vs_dbg_idx = 0; \
106 if (level <= ip_vs_get_debug_level()) \
107 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
109 #define IP_VS_ERR_BUF(msg...) \
111 char ip_vs_dbg_buf[160]; \
112 int ip_vs_dbg_idx = 0; \
116 /* Only use from within IP_VS_DBG_BUF() or IP_VS_ERR_BUF macros */
117 #define IP_VS_DBG_ADDR(af, addr) \
118 ip_vs_dbg_addr(af, ip_vs_dbg_buf, \
119 sizeof(ip_vs_dbg_buf), addr, \
122 #define IP_VS_DBG(level, msg, ...) \
124 if (level <= ip_vs_get_debug_level()) \
125 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
127 #define IP_VS_DBG_RL(msg, ...) \
129 if (net_ratelimit()) \
130 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
132 #define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) \
134 if (level <= ip_vs_get_debug_level()) \
135 pp->debug_packet(pp, skb, ofs, msg); \
137 #define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) \
139 if (level <= ip_vs_get_debug_level() && \
141 pp->debug_packet(pp, skb, ofs, msg); \
143 #else /* NO DEBUGGING at ALL */
144 #define IP_VS_DBG_BUF(level, msg...) do {} while (0)
145 #define IP_VS_ERR_BUF(msg...) do {} while (0)
146 #define IP_VS_DBG(level, msg...) do {} while (0)
147 #define IP_VS_DBG_RL(msg...) do {} while (0)
148 #define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) do {} while (0)
149 #define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) do {} while (0)
152 #define IP_VS_BUG() BUG()
153 #define IP_VS_ERR(msg...) pr_err(msg)
154 #define IP_VS_INFO(msg...) pr_info(msg)
155 #define IP_VS_WARNING(msg...) pr_warning(msg)
156 #define IP_VS_ERR_RL(msg...) \
158 if (net_ratelimit()) \
162 #ifdef CONFIG_IP_VS_DEBUG
163 #define EnterFunction(level) \
165 if (level <= ip_vs_get_debug_level()) \
167 pr_fmt("Enter: %s, %s line %i\n"), \
168 __func__, __FILE__, __LINE__); \
170 #define LeaveFunction(level) \
172 if (level <= ip_vs_get_debug_level()) \
174 pr_fmt("Leave: %s, %s line %i\n"), \
175 __func__, __FILE__, __LINE__); \
178 #define EnterFunction(level) do {} while (0)
179 #define LeaveFunction(level) do {} while (0)
182 #define IP_VS_WAIT_WHILE(expr) while (expr) { cpu_relax(); }
186 * The port number of FTP service (in network order).
188 #define FTPPORT cpu_to_be16(21)
189 #define FTPDATA cpu_to_be16(20)
195 IP_VS_TCP_S_NONE = 0,
196 IP_VS_TCP_S_ESTABLISHED,
197 IP_VS_TCP_S_SYN_SENT,
198 IP_VS_TCP_S_SYN_RECV,
199 IP_VS_TCP_S_FIN_WAIT,
200 IP_VS_TCP_S_TIME_WAIT,
202 IP_VS_TCP_S_CLOSE_WAIT,
203 IP_VS_TCP_S_LAST_ACK,
226 * Delta sequence info structure
227 * Each ip_vs_conn has 2 (output AND input seq. changes).
228 * Only used in the VS/NAT.
231 __u32 init_seq; /* Add delta from this seq */
232 __u32 delta; /* Delta in sequence numbers */
233 __u32 previous_delta; /* Delta in sequence numbers
234 before last resized pkt */
239 * IPVS statistics objects
241 struct ip_vs_estimator {
242 struct list_head list;
259 struct ip_vs_stats_user ustats; /* statistics */
260 struct ip_vs_estimator est; /* estimator */
262 spinlock_t lock; /* spin lock */
271 struct ip_vs_protocol {
272 struct ip_vs_protocol *next;
277 atomic_t appcnt; /* counter of proto app incs */
278 int *timeout_table; /* protocol timeout table */
280 void (*init)(struct ip_vs_protocol *pp);
282 void (*exit)(struct ip_vs_protocol *pp);
284 int (*conn_schedule)(int af, struct sk_buff *skb,
285 struct ip_vs_protocol *pp,
286 int *verdict, struct ip_vs_conn **cpp);
289 (*conn_in_get)(int af,
290 const struct sk_buff *skb,
291 struct ip_vs_protocol *pp,
292 const struct ip_vs_iphdr *iph,
293 unsigned int proto_off,
297 (*conn_out_get)(int af,
298 const struct sk_buff *skb,
299 struct ip_vs_protocol *pp,
300 const struct ip_vs_iphdr *iph,
301 unsigned int proto_off,
304 int (*snat_handler)(struct sk_buff *skb,
305 struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
307 int (*dnat_handler)(struct sk_buff *skb,
308 struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
310 int (*csum_check)(int af, struct sk_buff *skb,
311 struct ip_vs_protocol *pp);
313 const char *(*state_name)(int state);
315 int (*state_transition)(struct ip_vs_conn *cp, int direction,
316 const struct sk_buff *skb,
317 struct ip_vs_protocol *pp);
319 int (*register_app)(struct ip_vs_app *inc);
321 void (*unregister_app)(struct ip_vs_app *inc);
323 int (*app_conn_bind)(struct ip_vs_conn *cp);
325 void (*debug_packet)(struct ip_vs_protocol *pp,
326 const struct sk_buff *skb,
330 void (*timeout_change)(struct ip_vs_protocol *pp, int flags);
332 int (*set_state_timeout)(struct ip_vs_protocol *pp, char *sname, int to);
335 extern struct ip_vs_protocol * ip_vs_proto_get(unsigned short proto);
338 * IP_VS structure allocated for each dynamically scheduled connection
341 struct list_head c_list; /* hashed list heads */
343 /* Protocol, addresses and port numbers */
344 u16 af; /* address family */
345 union nf_inet_addr caddr; /* client address */
346 union nf_inet_addr vaddr; /* virtual address */
347 union nf_inet_addr daddr; /* destination address */
351 __u16 protocol; /* Which protocol (TCP/UDP) */
353 /* counter and timer */
354 atomic_t refcnt; /* reference count */
355 struct timer_list timer; /* Expiration timer */
356 volatile unsigned long timeout; /* timeout */
358 /* Flags and state transition */
359 spinlock_t lock; /* lock for state transition */
360 volatile __u16 flags; /* status flags */
361 volatile __u16 state; /* state info */
362 volatile __u16 old_state; /* old state, to be used for
363 * state transition triggerd
367 /* Control members */
368 struct ip_vs_conn *control; /* Master control connection */
369 atomic_t n_control; /* Number of controlled ones */
370 struct ip_vs_dest *dest; /* real server */
371 atomic_t in_pkts; /* incoming packet counter */
373 /* packet transmitter for different forwarding methods. If it
374 mangles the packet, it must return NF_DROP or better NF_STOLEN,
375 otherwise this must be changed to a sk_buff **.
377 int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp,
378 struct ip_vs_protocol *pp);
380 /* Note: we can group the following members into a structure,
381 in order to save more space, and the following members are
382 only used in VS/NAT anyway */
383 struct ip_vs_app *app; /* bound ip_vs_app object */
384 void *app_data; /* Application private data */
385 struct ip_vs_seq in_seq; /* incoming seq. struct */
386 struct ip_vs_seq out_seq; /* outgoing seq. struct */
391 * Extended internal versions of struct ip_vs_service_user and
392 * ip_vs_dest_user for IPv6 support.
394 * We need these to conveniently pass around service and destination
395 * options, but unfortunately, we also need to keep the old definitions to
396 * maintain userspace backwards compatibility for the setsockopt interface.
398 struct ip_vs_service_user_kern {
399 /* virtual service addresses */
402 union nf_inet_addr addr; /* virtual ip address */
404 u32 fwmark; /* firwall mark of service */
406 /* virtual service options */
408 unsigned flags; /* virtual service flags */
409 unsigned timeout; /* persistent timeout in sec */
410 u32 netmask; /* persistent netmask */
414 struct ip_vs_dest_user_kern {
415 /* destination server address */
416 union nf_inet_addr addr;
419 /* real server options */
420 unsigned conn_flags; /* connection flags */
421 int weight; /* destination weight */
423 /* thresholds for active connections */
424 u32 u_threshold; /* upper threshold */
425 u32 l_threshold; /* lower threshold */
430 * The information about the virtual service offered to the net
431 * and the forwarding entries
433 struct ip_vs_service {
434 struct list_head s_list; /* for normal service table */
435 struct list_head f_list; /* for fwmark-based service table */
436 atomic_t refcnt; /* reference counter */
437 atomic_t usecnt; /* use counter */
439 u16 af; /* address family */
440 __u16 protocol; /* which protocol (TCP/UDP) */
441 union nf_inet_addr addr; /* IP address for virtual service */
442 __be16 port; /* port number for the service */
443 __u32 fwmark; /* firewall mark of the service */
444 unsigned flags; /* service status flags */
445 unsigned timeout; /* persistent timeout in ticks */
446 __be32 netmask; /* grouping granularity */
448 struct list_head destinations; /* real server d-linked list */
449 __u32 num_dests; /* number of servers */
450 struct ip_vs_stats stats; /* statistics for the service */
451 struct ip_vs_app *inc; /* bind conns to this app inc */
454 struct ip_vs_scheduler *scheduler; /* bound scheduler object */
455 rwlock_t sched_lock; /* lock sched_data */
456 void *sched_data; /* scheduler application data */
461 * The real server destination forwarding entry
462 * with ip address, port number, and so on.
465 struct list_head n_list; /* for the dests in the service */
466 struct list_head d_list; /* for table with all the dests */
468 u16 af; /* address family */
469 union nf_inet_addr addr; /* IP address of the server */
470 __be16 port; /* port number of the server */
471 volatile unsigned flags; /* dest status flags */
472 atomic_t conn_flags; /* flags to copy to conn */
473 atomic_t weight; /* server weight */
475 atomic_t refcnt; /* reference counter */
476 struct ip_vs_stats stats; /* statistics */
478 /* connection counters and thresholds */
479 atomic_t activeconns; /* active connections */
480 atomic_t inactconns; /* inactive connections */
481 atomic_t persistconns; /* persistent connections */
482 __u32 u_threshold; /* upper threshold */
483 __u32 l_threshold; /* lower threshold */
485 /* for destination cache */
486 spinlock_t dst_lock; /* lock of dst_cache */
487 struct dst_entry *dst_cache; /* destination cache entry */
488 u32 dst_rtos; /* RT_TOS(tos) for dst */
490 /* for virtual service */
491 struct ip_vs_service *svc; /* service it belongs to */
492 __u16 protocol; /* which protocol (TCP/UDP) */
493 union nf_inet_addr vaddr; /* virtual IP address */
494 __be16 vport; /* virtual port number */
495 __u32 vfwmark; /* firewall mark of service */
500 * The scheduler object
502 struct ip_vs_scheduler {
503 struct list_head n_list; /* d-linked list head */
504 char *name; /* scheduler name */
505 atomic_t refcnt; /* reference counter */
506 struct module *module; /* THIS_MODULE/NULL */
508 /* scheduler initializing service */
509 int (*init_service)(struct ip_vs_service *svc);
510 /* scheduling service finish */
511 int (*done_service)(struct ip_vs_service *svc);
512 /* scheduler updating service */
513 int (*update_service)(struct ip_vs_service *svc);
515 /* selecting a server from the given service */
516 struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc,
517 const struct sk_buff *skb);
522 * The application module object (a.k.a. app incarnation)
526 struct list_head a_list; /* member in app list */
527 int type; /* IP_VS_APP_TYPE_xxx */
528 char *name; /* application module name */
530 struct module *module; /* THIS_MODULE/NULL */
531 struct list_head incs_list; /* list of incarnations */
533 /* members for application incarnations */
534 struct list_head p_list; /* member in proto app list */
535 struct ip_vs_app *app; /* its real application */
536 __be16 port; /* port number in net order */
537 atomic_t usecnt; /* usage counter */
539 /* output hook: return false if can't linearize. diff set for TCP. */
540 int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *,
541 struct sk_buff *, int *diff);
543 /* input hook: return false if can't linearize. diff set for TCP. */
544 int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *,
545 struct sk_buff *, int *diff);
547 /* ip_vs_app initializer */
548 int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *);
550 /* ip_vs_app finish */
551 int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *);
555 int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *,
556 struct ip_vs_protocol *);
558 void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *);
564 int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app,
565 int *verdict, struct ip_vs_conn **cpp);
568 (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app,
569 const struct iphdr *iph, unsigned int proto_off,
573 (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app,
574 const struct iphdr *iph, unsigned int proto_off,
577 int (*state_transition)(struct ip_vs_conn *cp, int direction,
578 const struct sk_buff *skb,
579 struct ip_vs_app *app);
581 void (*timeout_change)(struct ip_vs_app *app, int flags);
586 * IPVS core functions
587 * (from ip_vs_core.c)
589 extern const char *ip_vs_proto_name(unsigned proto);
590 extern void ip_vs_init_hash_table(struct list_head *table, int rows);
591 #define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t)))
593 #define IP_VS_APP_TYPE_FTP 1
596 * ip_vs_conn handling functions
597 * (from ip_vs_conn.c)
601 * IPVS connection entry hash table
603 #ifndef CONFIG_IP_VS_TAB_BITS
604 #define CONFIG_IP_VS_TAB_BITS 12
607 #define IP_VS_CONN_TAB_BITS CONFIG_IP_VS_TAB_BITS
608 #define IP_VS_CONN_TAB_SIZE (1 << IP_VS_CONN_TAB_BITS)
609 #define IP_VS_CONN_TAB_MASK (IP_VS_CONN_TAB_SIZE - 1)
614 IP_VS_DIR_INPUT_ONLY,
618 extern struct ip_vs_conn *ip_vs_conn_in_get
619 (int af, int protocol, const union nf_inet_addr *s_addr, __be16 s_port,
620 const union nf_inet_addr *d_addr, __be16 d_port);
622 extern struct ip_vs_conn *ip_vs_ct_in_get
623 (int af, int protocol, const union nf_inet_addr *s_addr, __be16 s_port,
624 const union nf_inet_addr *d_addr, __be16 d_port);
626 extern struct ip_vs_conn *ip_vs_conn_out_get
627 (int af, int protocol, const union nf_inet_addr *s_addr, __be16 s_port,
628 const union nf_inet_addr *d_addr, __be16 d_port);
630 /* put back the conn without restarting its timer */
631 static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
633 atomic_dec(&cp->refcnt);
635 extern void ip_vs_conn_put(struct ip_vs_conn *cp);
636 extern void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport);
638 extern struct ip_vs_conn *
639 ip_vs_conn_new(int af, int proto, const union nf_inet_addr *caddr, __be16 cport,
640 const union nf_inet_addr *vaddr, __be16 vport,
641 const union nf_inet_addr *daddr, __be16 dport, unsigned flags,
642 struct ip_vs_dest *dest);
643 extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
645 extern const char * ip_vs_state_name(__u16 proto, int state);
647 extern void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp);
648 extern int ip_vs_check_template(struct ip_vs_conn *ct);
649 extern void ip_vs_random_dropentry(void);
650 extern int ip_vs_conn_init(void);
651 extern void ip_vs_conn_cleanup(void);
653 static inline void ip_vs_control_del(struct ip_vs_conn *cp)
655 struct ip_vs_conn *ctl_cp = cp->control;
657 IP_VS_ERR_BUF("request control DEL for uncontrolled: "
659 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
661 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
667 IP_VS_DBG_BUF(7, "DELeting control for: "
668 "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
669 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
671 IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
672 ntohs(ctl_cp->cport));
675 if (atomic_read(&ctl_cp->n_control) == 0) {
676 IP_VS_ERR_BUF("BUG control DEL with n=0 : "
678 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
680 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
685 atomic_dec(&ctl_cp->n_control);
689 ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)
692 IP_VS_ERR_BUF("request control ADD for already controlled: "
694 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
696 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
699 ip_vs_control_del(cp);
702 IP_VS_DBG_BUF(7, "ADDing control for: "
703 "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
704 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
706 IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
707 ntohs(ctl_cp->cport));
709 cp->control = ctl_cp;
710 atomic_inc(&ctl_cp->n_control);
715 * IPVS application functions
718 #define IP_VS_APP_MAX_PORTS 8
719 extern int register_ip_vs_app(struct ip_vs_app *app);
720 extern void unregister_ip_vs_app(struct ip_vs_app *app);
721 extern int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
722 extern void ip_vs_unbind_app(struct ip_vs_conn *cp);
724 register_ip_vs_app_inc(struct ip_vs_app *app, __u16 proto, __u16 port);
725 extern int ip_vs_app_inc_get(struct ip_vs_app *inc);
726 extern void ip_vs_app_inc_put(struct ip_vs_app *inc);
728 extern int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb);
729 extern int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb);
730 extern int ip_vs_skb_replace(struct sk_buff *skb, gfp_t pri,
731 char *o_buf, int o_len, char *n_buf, int n_len);
732 extern int ip_vs_app_init(void);
733 extern void ip_vs_app_cleanup(void);
737 * IPVS protocol functions (from ip_vs_proto.c)
739 extern int ip_vs_protocol_init(void);
740 extern void ip_vs_protocol_cleanup(void);
741 extern void ip_vs_protocol_timeout_change(int flags);
742 extern int *ip_vs_create_timeout_table(int *table, int size);
744 ip_vs_set_state_timeout(int *table, int num, char **names, char *name, int to);
746 ip_vs_tcpudp_debug_packet(struct ip_vs_protocol *pp, const struct sk_buff *skb,
747 int offset, const char *msg);
749 extern struct ip_vs_protocol ip_vs_protocol_tcp;
750 extern struct ip_vs_protocol ip_vs_protocol_udp;
751 extern struct ip_vs_protocol ip_vs_protocol_icmp;
752 extern struct ip_vs_protocol ip_vs_protocol_esp;
753 extern struct ip_vs_protocol ip_vs_protocol_ah;
757 * Registering/unregistering scheduler functions
758 * (from ip_vs_sched.c)
760 extern int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
761 extern int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
762 extern int ip_vs_bind_scheduler(struct ip_vs_service *svc,
763 struct ip_vs_scheduler *scheduler);
764 extern int ip_vs_unbind_scheduler(struct ip_vs_service *svc);
765 extern struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name);
766 extern void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler);
767 extern struct ip_vs_conn *
768 ip_vs_schedule(struct ip_vs_service *svc, const struct sk_buff *skb);
769 extern int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
770 struct ip_vs_protocol *pp);
774 * IPVS control data and functions (from ip_vs_ctl.c)
776 extern int sysctl_ip_vs_cache_bypass;
777 extern int sysctl_ip_vs_expire_nodest_conn;
778 extern int sysctl_ip_vs_expire_quiescent_template;
779 extern int sysctl_ip_vs_sync_threshold[2];
780 extern int sysctl_ip_vs_nat_icmp_send;
781 extern struct ip_vs_stats ip_vs_stats;
782 extern const struct ctl_path net_vs_ctl_path[];
784 extern struct ip_vs_service *
785 ip_vs_service_get(int af, __u32 fwmark, __u16 protocol,
786 const union nf_inet_addr *vaddr, __be16 vport);
788 static inline void ip_vs_service_put(struct ip_vs_service *svc)
790 atomic_dec(&svc->usecnt);
793 extern struct ip_vs_dest *
794 ip_vs_lookup_real_service(int af, __u16 protocol,
795 const union nf_inet_addr *daddr, __be16 dport);
797 extern int ip_vs_use_count_inc(void);
798 extern void ip_vs_use_count_dec(void);
799 extern int ip_vs_control_init(void);
800 extern void ip_vs_control_cleanup(void);
801 extern struct ip_vs_dest *
802 ip_vs_find_dest(int af, const union nf_inet_addr *daddr, __be16 dport,
803 const union nf_inet_addr *vaddr, __be16 vport, __u16 protocol);
804 extern struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp);
808 * IPVS sync daemon data and function prototypes
809 * (from ip_vs_sync.c)
811 extern volatile int ip_vs_sync_state;
812 extern volatile int ip_vs_master_syncid;
813 extern volatile int ip_vs_backup_syncid;
814 extern char ip_vs_master_mcast_ifn[IP_VS_IFNAME_MAXLEN];
815 extern char ip_vs_backup_mcast_ifn[IP_VS_IFNAME_MAXLEN];
816 extern int start_sync_thread(int state, char *mcast_ifn, __u8 syncid);
817 extern int stop_sync_thread(int state);
818 extern void ip_vs_sync_conn(struct ip_vs_conn *cp);
822 * IPVS rate estimator prototypes (from ip_vs_est.c)
824 extern int ip_vs_estimator_init(void);
825 extern void ip_vs_estimator_cleanup(void);
826 extern void ip_vs_new_estimator(struct ip_vs_stats *stats);
827 extern void ip_vs_kill_estimator(struct ip_vs_stats *stats);
828 extern void ip_vs_zero_estimator(struct ip_vs_stats *stats);
831 * Various IPVS packet transmitters (from ip_vs_xmit.c)
833 extern int ip_vs_null_xmit
834 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
835 extern int ip_vs_bypass_xmit
836 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
837 extern int ip_vs_nat_xmit
838 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
839 extern int ip_vs_tunnel_xmit
840 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
841 extern int ip_vs_dr_xmit
842 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
843 extern int ip_vs_icmp_xmit
844 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, int offset);
845 extern void ip_vs_dst_reset(struct ip_vs_dest *dest);
847 #ifdef CONFIG_IP_VS_IPV6
848 extern int ip_vs_bypass_xmit_v6
849 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
850 extern int ip_vs_nat_xmit_v6
851 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
852 extern int ip_vs_tunnel_xmit_v6
853 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
854 extern int ip_vs_dr_xmit_v6
855 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
856 extern int ip_vs_icmp_xmit_v6
857 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp,
862 * This is a simple mechanism to ignore packets when
863 * we are loaded. Just set ip_vs_drop_rate to 'n' and
864 * we start to drop 1/rate of the packets
866 extern int ip_vs_drop_rate;
867 extern int ip_vs_drop_counter;
869 static __inline__ int ip_vs_todrop(void)
871 if (!ip_vs_drop_rate) return 0;
872 if (--ip_vs_drop_counter > 0) return 0;
873 ip_vs_drop_counter = ip_vs_drop_rate;
878 * ip_vs_fwd_tag returns the forwarding tag of the connection
880 #define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK)
882 static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp)
886 switch (IP_VS_FWD_METHOD(cp)) {
887 case IP_VS_CONN_F_MASQ:
889 case IP_VS_CONN_F_LOCALNODE:
891 case IP_VS_CONN_F_TUNNEL:
893 case IP_VS_CONN_F_DROUTE:
895 case IP_VS_CONN_F_BYPASS:
903 extern void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,
904 struct ip_vs_conn *cp, int dir);
906 #ifdef CONFIG_IP_VS_IPV6
907 extern void ip_vs_nat_icmp_v6(struct sk_buff *skb, struct ip_vs_protocol *pp,
908 struct ip_vs_conn *cp, int dir);
911 extern __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset);
913 static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum)
915 __be32 diff[2] = { ~old, new };
917 return csum_partial(diff, sizeof(diff), oldsum);
920 #ifdef CONFIG_IP_VS_IPV6
921 static inline __wsum ip_vs_check_diff16(const __be32 *old, const __be32 *new,
924 __be32 diff[8] = { ~old[3], ~old[2], ~old[1], ~old[0],
925 new[3], new[2], new[1], new[0] };
927 return csum_partial(diff, sizeof(diff), oldsum);
931 static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum)
933 __be16 diff[2] = { ~old, new };
935 return csum_partial(diff, sizeof(diff), oldsum);
938 #endif /* __KERNEL__ */
940 #endif /* _NET_IP_VS_H */