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 */
28 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
29 #include <net/netfilter/nf_conntrack.h>
32 /* Connections' size value needed by ip_vs_ctl.c */
33 extern int ip_vs_conn_tab_size;
39 union nf_inet_addr saddr;
40 union nf_inet_addr daddr;
44 ip_vs_fill_iphdr(int af, const void *nh, struct ip_vs_iphdr *iphdr)
46 #ifdef CONFIG_IP_VS_IPV6
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);
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;
64 static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst,
65 const union nf_inet_addr *src)
67 #ifdef CONFIG_IP_VS_IPV6
69 ipv6_addr_copy(&dst->in6, &src->in6);
75 static inline int ip_vs_addr_equal(int af, const union nf_inet_addr *a,
76 const union nf_inet_addr *b)
78 #ifdef CONFIG_IP_VS_IPV6
80 return ipv6_addr_equal(&a->in6, &b->in6);
82 return a->ip == b->ip;
85 #ifdef CONFIG_IP_VS_DEBUG
86 #include <linux/net.h>
88 extern int ip_vs_get_debug_level(void);
90 static inline const char *ip_vs_dbg_addr(int af, char *buf, size_t buf_len,
91 const union nf_inet_addr *addr,
95 #ifdef CONFIG_IP_VS_IPV6
97 len = snprintf(&buf[*idx], buf_len - *idx, "[%pI6]",
101 len = snprintf(&buf[*idx], buf_len - *idx, "%pI4",
105 BUG_ON(*idx > buf_len + 1);
106 return &buf[*idx - len];
109 #define IP_VS_DBG_BUF(level, msg, ...) \
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__); \
116 #define IP_VS_ERR_BUF(msg...) \
118 char ip_vs_dbg_buf[160]; \
119 int ip_vs_dbg_idx = 0; \
123 /* Only use from within IP_VS_DBG_BUF() or IP_VS_ERR_BUF macros */
124 #define IP_VS_DBG_ADDR(af, addr) \
125 ip_vs_dbg_addr(af, ip_vs_dbg_buf, \
126 sizeof(ip_vs_dbg_buf), addr, \
129 #define IP_VS_DBG(level, msg, ...) \
131 if (level <= ip_vs_get_debug_level()) \
132 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
134 #define IP_VS_DBG_RL(msg, ...) \
136 if (net_ratelimit()) \
137 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
139 #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) \
141 if (level <= ip_vs_get_debug_level()) \
142 pp->debug_packet(af, pp, skb, ofs, msg); \
144 #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) \
146 if (level <= ip_vs_get_debug_level() && \
148 pp->debug_packet(af, pp, skb, ofs, msg); \
150 #else /* NO DEBUGGING at ALL */
151 #define IP_VS_DBG_BUF(level, msg...) do {} while (0)
152 #define IP_VS_ERR_BUF(msg...) do {} while (0)
153 #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, af, pp, skb, ofs, msg) do {} while (0)
156 #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) do {} while (0)
159 #define IP_VS_BUG() BUG()
160 #define IP_VS_ERR_RL(msg, ...) \
162 if (net_ratelimit()) \
163 pr_err(msg, ##__VA_ARGS__); \
166 #ifdef CONFIG_IP_VS_DEBUG
167 #define EnterFunction(level) \
169 if (level <= ip_vs_get_debug_level()) \
171 pr_fmt("Enter: %s, %s line %i\n"), \
172 __func__, __FILE__, __LINE__); \
174 #define LeaveFunction(level) \
176 if (level <= ip_vs_get_debug_level()) \
178 pr_fmt("Leave: %s, %s line %i\n"), \
179 __func__, __FILE__, __LINE__); \
182 #define EnterFunction(level) do {} while (0)
183 #define LeaveFunction(level) do {} while (0)
186 #define IP_VS_WAIT_WHILE(expr) while (expr) { cpu_relax(); }
190 * The port number of FTP service (in network order).
192 #define FTPPORT cpu_to_be16(21)
193 #define FTPDATA cpu_to_be16(20)
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,
206 IP_VS_TCP_S_CLOSE_WAIT,
207 IP_VS_TCP_S_LAST_ACK,
232 enum ip_vs_sctp_states {
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,
250 * Delta sequence info structure
251 * Each ip_vs_conn has 2 (output AND input seq. changes).
252 * Only used in the VS/NAT.
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 */
263 * IPVS statistics objects
265 struct ip_vs_estimator {
266 struct list_head list;
282 struct ip_vs_stats_user ustats; /* statistics */
283 struct ip_vs_estimator est; /* estimator */
285 spinlock_t lock; /* spin lock */
294 struct ip_vs_protocol {
295 struct ip_vs_protocol *next;
300 atomic_t appcnt; /* counter of proto app incs */
301 int *timeout_table; /* protocol timeout table */
303 void (*init)(struct ip_vs_protocol *pp);
305 void (*exit)(struct ip_vs_protocol *pp);
307 int (*conn_schedule)(int af, struct sk_buff *skb,
308 struct ip_vs_protocol *pp,
309 int *verdict, struct ip_vs_conn **cpp);
312 (*conn_in_get)(int af,
313 const struct sk_buff *skb,
314 struct ip_vs_protocol *pp,
315 const struct ip_vs_iphdr *iph,
316 unsigned int proto_off,
320 (*conn_out_get)(int af,
321 const struct sk_buff *skb,
322 struct ip_vs_protocol *pp,
323 const struct ip_vs_iphdr *iph,
324 unsigned int proto_off,
327 int (*snat_handler)(struct sk_buff *skb,
328 struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
330 int (*dnat_handler)(struct sk_buff *skb,
331 struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
333 int (*csum_check)(int af, struct sk_buff *skb,
334 struct ip_vs_protocol *pp);
336 const char *(*state_name)(int state);
338 int (*state_transition)(struct ip_vs_conn *cp, int direction,
339 const struct sk_buff *skb,
340 struct ip_vs_protocol *pp);
342 int (*register_app)(struct ip_vs_app *inc);
344 void (*unregister_app)(struct ip_vs_app *inc);
346 int (*app_conn_bind)(struct ip_vs_conn *cp);
348 void (*debug_packet)(int af, struct ip_vs_protocol *pp,
349 const struct sk_buff *skb,
353 void (*timeout_change)(struct ip_vs_protocol *pp, int flags);
355 int (*set_state_timeout)(struct ip_vs_protocol *pp, char *sname, int to);
358 extern struct ip_vs_protocol * ip_vs_proto_get(unsigned short proto);
360 struct ip_vs_conn_param {
361 const union nf_inet_addr *caddr;
362 const union nf_inet_addr *vaddr;
368 const struct ip_vs_pe *pe;
374 * IP_VS structure allocated for each dynamically scheduled connection
377 struct list_head c_list; /* hashed list heads */
379 /* Protocol, addresses and port numbers */
380 u16 af; /* address family */
381 union nf_inet_addr caddr; /* client address */
382 union nf_inet_addr vaddr; /* virtual address */
383 union nf_inet_addr daddr; /* destination address */
384 volatile __u32 flags; /* status flags */
385 __u32 fwmark; /* Fire wall mark from skb */
389 __u16 protocol; /* Which protocol (TCP/UDP) */
391 /* counter and timer */
392 atomic_t refcnt; /* reference count */
393 struct timer_list timer; /* Expiration timer */
394 volatile unsigned long timeout; /* timeout */
396 /* Flags and state transition */
397 spinlock_t lock; /* lock for state transition */
398 volatile __u16 state; /* state info */
399 volatile __u16 old_state; /* old state, to be used for
400 * state transition triggerd
404 /* Control members */
405 struct ip_vs_conn *control; /* Master control connection */
406 atomic_t n_control; /* Number of controlled ones */
407 struct ip_vs_dest *dest; /* real server */
408 atomic_t in_pkts; /* incoming packet counter */
410 /* packet transmitter for different forwarding methods. If it
411 mangles the packet, it must return NF_DROP or better NF_STOLEN,
412 otherwise this must be changed to a sk_buff **.
413 NF_ACCEPT can be returned when destination is local.
415 int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp,
416 struct ip_vs_protocol *pp);
418 /* Note: we can group the following members into a structure,
419 in order to save more space, and the following members are
420 only used in VS/NAT anyway */
421 struct ip_vs_app *app; /* bound ip_vs_app object */
422 void *app_data; /* Application private data */
423 struct ip_vs_seq in_seq; /* incoming seq. struct */
424 struct ip_vs_seq out_seq; /* outgoing seq. struct */
426 const struct ip_vs_pe *pe;
433 * Extended internal versions of struct ip_vs_service_user and
434 * ip_vs_dest_user for IPv6 support.
436 * We need these to conveniently pass around service and destination
437 * options, but unfortunately, we also need to keep the old definitions to
438 * maintain userspace backwards compatibility for the setsockopt interface.
440 struct ip_vs_service_user_kern {
441 /* virtual service addresses */
444 union nf_inet_addr addr; /* virtual ip address */
446 u32 fwmark; /* firwall mark of service */
448 /* virtual service options */
451 unsigned flags; /* virtual service flags */
452 unsigned timeout; /* persistent timeout in sec */
453 u32 netmask; /* persistent netmask */
457 struct ip_vs_dest_user_kern {
458 /* destination server address */
459 union nf_inet_addr addr;
462 /* real server options */
463 unsigned conn_flags; /* connection flags */
464 int weight; /* destination weight */
466 /* thresholds for active connections */
467 u32 u_threshold; /* upper threshold */
468 u32 l_threshold; /* lower threshold */
473 * The information about the virtual service offered to the net
474 * and the forwarding entries
476 struct ip_vs_service {
477 struct list_head s_list; /* for normal service table */
478 struct list_head f_list; /* for fwmark-based service table */
479 atomic_t refcnt; /* reference counter */
480 atomic_t usecnt; /* use counter */
482 u16 af; /* address family */
483 __u16 protocol; /* which protocol (TCP/UDP) */
484 union nf_inet_addr addr; /* IP address for virtual service */
485 __be16 port; /* port number for the service */
486 __u32 fwmark; /* firewall mark of the service */
487 unsigned flags; /* service status flags */
488 unsigned timeout; /* persistent timeout in ticks */
489 __be32 netmask; /* grouping granularity */
491 struct list_head destinations; /* real server d-linked list */
492 __u32 num_dests; /* number of servers */
493 struct ip_vs_stats stats; /* statistics for the service */
494 struct ip_vs_app *inc; /* bind conns to this app inc */
497 struct ip_vs_scheduler *scheduler; /* bound scheduler object */
498 rwlock_t sched_lock; /* lock sched_data */
499 void *sched_data; /* scheduler application data */
501 /* alternate persistence engine */
507 * The real server destination forwarding entry
508 * with ip address, port number, and so on.
511 struct list_head n_list; /* for the dests in the service */
512 struct list_head d_list; /* for table with all the dests */
514 u16 af; /* address family */
515 union nf_inet_addr addr; /* IP address of the server */
516 __be16 port; /* port number of the server */
517 volatile unsigned flags; /* dest status flags */
518 atomic_t conn_flags; /* flags to copy to conn */
519 atomic_t weight; /* server weight */
521 atomic_t refcnt; /* reference counter */
522 struct ip_vs_stats stats; /* statistics */
524 /* connection counters and thresholds */
525 atomic_t activeconns; /* active connections */
526 atomic_t inactconns; /* inactive connections */
527 atomic_t persistconns; /* persistent connections */
528 __u32 u_threshold; /* upper threshold */
529 __u32 l_threshold; /* lower threshold */
531 /* for destination cache */
532 spinlock_t dst_lock; /* lock of dst_cache */
533 struct dst_entry *dst_cache; /* destination cache entry */
534 u32 dst_rtos; /* RT_TOS(tos) for dst */
536 #ifdef CONFIG_IP_VS_IPV6
537 struct in6_addr dst_saddr;
540 /* for virtual service */
541 struct ip_vs_service *svc; /* service it belongs to */
542 __u16 protocol; /* which protocol (TCP/UDP) */
543 union nf_inet_addr vaddr; /* virtual IP address */
544 __be16 vport; /* virtual port number */
545 __u32 vfwmark; /* firewall mark of service */
550 * The scheduler object
552 struct ip_vs_scheduler {
553 struct list_head n_list; /* d-linked list head */
554 char *name; /* scheduler name */
555 atomic_t refcnt; /* reference counter */
556 struct module *module; /* THIS_MODULE/NULL */
558 /* scheduler initializing service */
559 int (*init_service)(struct ip_vs_service *svc);
560 /* scheduling service finish */
561 int (*done_service)(struct ip_vs_service *svc);
562 /* scheduler updating service */
563 int (*update_service)(struct ip_vs_service *svc);
565 /* selecting a server from the given service */
566 struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc,
567 const struct sk_buff *skb);
570 /* The persistence engine object */
572 struct list_head n_list; /* d-linked list head */
573 char *name; /* scheduler name */
574 atomic_t refcnt; /* reference counter */
575 struct module *module; /* THIS_MODULE/NULL */
577 /* get the connection template, if any */
578 int (*fill_param)(struct ip_vs_conn_param *p, struct sk_buff *skb);
579 bool (*ct_match)(const struct ip_vs_conn_param *p,
580 struct ip_vs_conn *ct);
581 u32 (*hashkey_raw)(const struct ip_vs_conn_param *p, u32 initval,
583 int (*show_pe_data)(const struct ip_vs_conn *cp, char *buf);
587 * The application module object (a.k.a. app incarnation)
590 struct list_head a_list; /* member in app list */
591 int type; /* IP_VS_APP_TYPE_xxx */
592 char *name; /* application module name */
594 struct module *module; /* THIS_MODULE/NULL */
595 struct list_head incs_list; /* list of incarnations */
597 /* members for application incarnations */
598 struct list_head p_list; /* member in proto app list */
599 struct ip_vs_app *app; /* its real application */
600 __be16 port; /* port number in net order */
601 atomic_t usecnt; /* usage counter */
604 * output hook: Process packet in inout direction, diff set for TCP.
605 * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
606 * 2=Mangled but checksum was not updated
608 int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *,
609 struct sk_buff *, int *diff);
612 * input hook: Process packet in outin direction, diff set for TCP.
613 * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
614 * 2=Mangled but checksum was not updated
616 int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *,
617 struct sk_buff *, int *diff);
619 /* ip_vs_app initializer */
620 int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *);
622 /* ip_vs_app finish */
623 int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *);
627 int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *,
628 struct ip_vs_protocol *);
630 void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *);
636 int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app,
637 int *verdict, struct ip_vs_conn **cpp);
640 (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app,
641 const struct iphdr *iph, unsigned int proto_off,
645 (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app,
646 const struct iphdr *iph, unsigned int proto_off,
649 int (*state_transition)(struct ip_vs_conn *cp, int direction,
650 const struct sk_buff *skb,
651 struct ip_vs_app *app);
653 void (*timeout_change)(struct ip_vs_app *app, int flags);
658 * IPVS core functions
659 * (from ip_vs_core.c)
661 extern const char *ip_vs_proto_name(unsigned proto);
662 extern void ip_vs_init_hash_table(struct list_head *table, int rows);
663 #define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t)))
665 #define IP_VS_APP_TYPE_FTP 1
668 * ip_vs_conn handling functions
669 * (from ip_vs_conn.c)
675 IP_VS_DIR_INPUT_ONLY,
679 static inline void ip_vs_conn_fill_param(int af, int protocol,
680 const union nf_inet_addr *caddr,
682 const union nf_inet_addr *vaddr,
684 struct ip_vs_conn_param *p)
687 p->protocol = protocol;
696 struct ip_vs_conn *ip_vs_conn_in_get(const struct ip_vs_conn_param *p);
697 struct ip_vs_conn *ip_vs_ct_in_get(const struct ip_vs_conn_param *p);
699 struct ip_vs_conn * ip_vs_conn_in_get_proto(int af, const struct sk_buff *skb,
700 struct ip_vs_protocol *pp,
701 const struct ip_vs_iphdr *iph,
702 unsigned int proto_off,
705 struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p);
707 struct ip_vs_conn * ip_vs_conn_out_get_proto(int af, const struct sk_buff *skb,
708 struct ip_vs_protocol *pp,
709 const struct ip_vs_iphdr *iph,
710 unsigned int proto_off,
713 /* put back the conn without restarting its timer */
714 static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
716 atomic_dec(&cp->refcnt);
718 extern void ip_vs_conn_put(struct ip_vs_conn *cp);
719 extern void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport);
721 struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p,
722 const union nf_inet_addr *daddr,
723 __be16 dport, unsigned flags,
724 struct ip_vs_dest *dest, __u32 fwmark);
725 extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
727 extern const char * ip_vs_state_name(__u16 proto, int state);
729 extern void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp);
730 extern int ip_vs_check_template(struct ip_vs_conn *ct);
731 extern void ip_vs_random_dropentry(void);
732 extern int ip_vs_conn_init(void);
733 extern void ip_vs_conn_cleanup(void);
735 static inline void ip_vs_control_del(struct ip_vs_conn *cp)
737 struct ip_vs_conn *ctl_cp = cp->control;
739 IP_VS_ERR_BUF("request control DEL for uncontrolled: "
741 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
743 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
749 IP_VS_DBG_BUF(7, "DELeting control for: "
750 "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
751 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
753 IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
754 ntohs(ctl_cp->cport));
757 if (atomic_read(&ctl_cp->n_control) == 0) {
758 IP_VS_ERR_BUF("BUG control DEL with n=0 : "
760 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
762 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
767 atomic_dec(&ctl_cp->n_control);
771 ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)
774 IP_VS_ERR_BUF("request control ADD for already controlled: "
776 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
778 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
781 ip_vs_control_del(cp);
784 IP_VS_DBG_BUF(7, "ADDing control for: "
785 "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
786 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
788 IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
789 ntohs(ctl_cp->cport));
791 cp->control = ctl_cp;
792 atomic_inc(&ctl_cp->n_control);
797 * IPVS application functions
800 #define IP_VS_APP_MAX_PORTS 8
801 extern int register_ip_vs_app(struct ip_vs_app *app);
802 extern void unregister_ip_vs_app(struct ip_vs_app *app);
803 extern int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
804 extern void ip_vs_unbind_app(struct ip_vs_conn *cp);
806 register_ip_vs_app_inc(struct ip_vs_app *app, __u16 proto, __u16 port);
807 extern int ip_vs_app_inc_get(struct ip_vs_app *inc);
808 extern void ip_vs_app_inc_put(struct ip_vs_app *inc);
810 extern int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb);
811 extern int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb);
812 extern int ip_vs_app_init(void);
813 extern void ip_vs_app_cleanup(void);
815 void ip_vs_bind_pe(struct ip_vs_service *svc, struct ip_vs_pe *pe);
816 void ip_vs_unbind_pe(struct ip_vs_service *svc);
817 int register_ip_vs_pe(struct ip_vs_pe *pe);
818 int unregister_ip_vs_pe(struct ip_vs_pe *pe);
819 struct ip_vs_pe *ip_vs_pe_getbyname(const char *name);
820 struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name);
822 static inline void ip_vs_pe_get(const struct ip_vs_pe *pe)
824 if (pe && pe->module)
825 __module_get(pe->module);
828 static inline void ip_vs_pe_put(const struct ip_vs_pe *pe)
830 if (pe && pe->module)
831 module_put(pe->module);
835 * IPVS protocol functions (from ip_vs_proto.c)
837 extern int ip_vs_protocol_init(void);
838 extern void ip_vs_protocol_cleanup(void);
839 extern void ip_vs_protocol_timeout_change(int flags);
840 extern int *ip_vs_create_timeout_table(int *table, int size);
842 ip_vs_set_state_timeout(int *table, int num, const char *const *names,
843 const char *name, int to);
845 ip_vs_tcpudp_debug_packet(int af, struct ip_vs_protocol *pp,
846 const struct sk_buff *skb,
847 int offset, const char *msg);
849 extern struct ip_vs_protocol ip_vs_protocol_tcp;
850 extern struct ip_vs_protocol ip_vs_protocol_udp;
851 extern struct ip_vs_protocol ip_vs_protocol_icmp;
852 extern struct ip_vs_protocol ip_vs_protocol_esp;
853 extern struct ip_vs_protocol ip_vs_protocol_ah;
854 extern struct ip_vs_protocol ip_vs_protocol_sctp;
857 * Registering/unregistering scheduler functions
858 * (from ip_vs_sched.c)
860 extern int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
861 extern int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
862 extern int ip_vs_bind_scheduler(struct ip_vs_service *svc,
863 struct ip_vs_scheduler *scheduler);
864 extern int ip_vs_unbind_scheduler(struct ip_vs_service *svc);
865 extern struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name);
866 extern void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler);
867 extern struct ip_vs_conn *
868 ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,
869 struct ip_vs_protocol *pp, int *ignored);
870 extern int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
871 struct ip_vs_protocol *pp);
875 * IPVS control data and functions (from ip_vs_ctl.c)
877 extern int sysctl_ip_vs_cache_bypass;
878 extern int sysctl_ip_vs_expire_nodest_conn;
879 extern int sysctl_ip_vs_expire_quiescent_template;
880 extern int sysctl_ip_vs_sync_threshold[2];
881 extern int sysctl_ip_vs_nat_icmp_send;
882 extern int sysctl_ip_vs_conntrack;
883 extern int sysctl_ip_vs_snat_reroute;
884 extern struct ip_vs_stats ip_vs_stats;
885 extern const struct ctl_path net_vs_ctl_path[];
886 extern int sysctl_ip_vs_sync_ver;
888 extern void ip_vs_sync_switch_mode(int mode);
889 extern struct ip_vs_service *
890 ip_vs_service_get(int af, __u32 fwmark, __u16 protocol,
891 const union nf_inet_addr *vaddr, __be16 vport);
893 static inline void ip_vs_service_put(struct ip_vs_service *svc)
895 atomic_dec(&svc->usecnt);
898 extern struct ip_vs_dest *
899 ip_vs_lookup_real_service(int af, __u16 protocol,
900 const union nf_inet_addr *daddr, __be16 dport);
902 extern int ip_vs_use_count_inc(void);
903 extern void ip_vs_use_count_dec(void);
904 extern int ip_vs_control_init(void);
905 extern void ip_vs_control_cleanup(void);
906 extern struct ip_vs_dest *
907 ip_vs_find_dest(int af, const union nf_inet_addr *daddr, __be16 dport,
908 const union nf_inet_addr *vaddr, __be16 vport, __u16 protocol,
910 extern struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp);
914 * IPVS sync daemon data and function prototypes
915 * (from ip_vs_sync.c)
917 extern volatile int ip_vs_sync_state;
918 extern volatile int ip_vs_master_syncid;
919 extern volatile int ip_vs_backup_syncid;
920 extern char ip_vs_master_mcast_ifn[IP_VS_IFNAME_MAXLEN];
921 extern char ip_vs_backup_mcast_ifn[IP_VS_IFNAME_MAXLEN];
922 extern int start_sync_thread(int state, char *mcast_ifn, __u8 syncid);
923 extern int stop_sync_thread(int state);
924 extern void ip_vs_sync_conn(struct ip_vs_conn *cp);
928 * IPVS rate estimator prototypes (from ip_vs_est.c)
930 extern int ip_vs_estimator_init(void);
931 extern void ip_vs_estimator_cleanup(void);
932 extern void ip_vs_new_estimator(struct ip_vs_stats *stats);
933 extern void ip_vs_kill_estimator(struct ip_vs_stats *stats);
934 extern void ip_vs_zero_estimator(struct ip_vs_stats *stats);
937 * Various IPVS packet transmitters (from ip_vs_xmit.c)
939 extern int ip_vs_null_xmit
940 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
941 extern int ip_vs_bypass_xmit
942 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
943 extern int ip_vs_nat_xmit
944 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
945 extern int ip_vs_tunnel_xmit
946 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
947 extern int ip_vs_dr_xmit
948 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
949 extern int ip_vs_icmp_xmit
950 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, int offset);
951 extern void ip_vs_dst_reset(struct ip_vs_dest *dest);
953 #ifdef CONFIG_IP_VS_IPV6
954 extern int ip_vs_bypass_xmit_v6
955 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
956 extern int ip_vs_nat_xmit_v6
957 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
958 extern int ip_vs_tunnel_xmit_v6
959 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
960 extern int ip_vs_dr_xmit_v6
961 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
962 extern int ip_vs_icmp_xmit_v6
963 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp,
968 * This is a simple mechanism to ignore packets when
969 * we are loaded. Just set ip_vs_drop_rate to 'n' and
970 * we start to drop 1/rate of the packets
972 extern int ip_vs_drop_rate;
973 extern int ip_vs_drop_counter;
975 static __inline__ int ip_vs_todrop(void)
977 if (!ip_vs_drop_rate) return 0;
978 if (--ip_vs_drop_counter > 0) return 0;
979 ip_vs_drop_counter = ip_vs_drop_rate;
984 * ip_vs_fwd_tag returns the forwarding tag of the connection
986 #define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK)
988 static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp)
992 switch (IP_VS_FWD_METHOD(cp)) {
993 case IP_VS_CONN_F_MASQ:
995 case IP_VS_CONN_F_LOCALNODE:
997 case IP_VS_CONN_F_TUNNEL:
999 case IP_VS_CONN_F_DROUTE:
1001 case IP_VS_CONN_F_BYPASS:
1009 extern void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,
1010 struct ip_vs_conn *cp, int dir);
1012 #ifdef CONFIG_IP_VS_IPV6
1013 extern void ip_vs_nat_icmp_v6(struct sk_buff *skb, struct ip_vs_protocol *pp,
1014 struct ip_vs_conn *cp, int dir);
1017 extern __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset);
1019 static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum)
1021 __be32 diff[2] = { ~old, new };
1023 return csum_partial(diff, sizeof(diff), oldsum);
1026 #ifdef CONFIG_IP_VS_IPV6
1027 static inline __wsum ip_vs_check_diff16(const __be32 *old, const __be32 *new,
1030 __be32 diff[8] = { ~old[3], ~old[2], ~old[1], ~old[0],
1031 new[3], new[2], new[1], new[0] };
1033 return csum_partial(diff, sizeof(diff), oldsum);
1037 static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum)
1039 __be16 diff[2] = { ~old, new };
1041 return csum_partial(diff, sizeof(diff), oldsum);
1045 * Forget current conntrack (unconfirmed) and attach notrack entry
1047 static inline void ip_vs_notrack(struct sk_buff *skb)
1049 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1050 enum ip_conntrack_info ctinfo;
1051 struct nf_conn *ct = ct = nf_ct_get(skb, &ctinfo);
1053 if (!ct || !nf_ct_is_untracked(ct)) {
1055 skb->nfct = &nf_ct_untracked_get()->ct_general;
1056 skb->nfctinfo = IP_CT_NEW;
1057 nf_conntrack_get(skb->nfct);
1062 #ifdef CONFIG_IP_VS_NFCT
1064 * Netfilter connection tracking
1065 * (from ip_vs_nfct.c)
1067 static inline int ip_vs_conntrack_enabled(void)
1069 return sysctl_ip_vs_conntrack;
1072 extern void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp,
1074 extern int ip_vs_confirm_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp);
1075 extern void ip_vs_nfct_expect_related(struct sk_buff *skb, struct nf_conn *ct,
1076 struct ip_vs_conn *cp, u_int8_t proto,
1077 const __be16 port, int from_rs);
1078 extern void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp);
1082 static inline int ip_vs_conntrack_enabled(void)
1087 static inline void ip_vs_update_conntrack(struct sk_buff *skb,
1088 struct ip_vs_conn *cp, int outin)
1092 static inline int ip_vs_confirm_conntrack(struct sk_buff *skb,
1093 struct ip_vs_conn *cp)
1098 static inline void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp)
1101 /* CONFIG_IP_VS_NFCT */
1104 #endif /* __KERNEL__ */
1106 #endif /* _NET_IP_VS_H */