[PATCH] hvc_console: Register ops when setting up hvc_console
[linux-2.6/mini2440.git] / include / net / ip_vs.h
blob52da5d26617a2989f4c0c7a0c017b22388582b77
1 /*
2 * IP Virtual Server
3 * data structure and functionality definitions
4 */
6 #ifndef _IP_VS_H
7 #define _IP_VS_H
9 #include <asm/types.h> /* For __uXX types */
11 #define IP_VS_VERSION_CODE 0x010201
12 #define NVERSION(version) \
13 (version >> 16) & 0xFF, \
14 (version >> 8) & 0xFF, \
15 version & 0xFF
18 * Virtual Service Flags
20 #define IP_VS_SVC_F_PERSISTENT 0x0001 /* persistent port */
21 #define IP_VS_SVC_F_HASHED 0x0002 /* hashed entry */
24 * Destination Server Flags
26 #define IP_VS_DEST_F_AVAILABLE 0x0001 /* server is available */
27 #define IP_VS_DEST_F_OVERLOAD 0x0002 /* server is overloaded */
30 * IPVS sync daemon states
32 #define IP_VS_STATE_NONE 0x0000 /* daemon is stopped */
33 #define IP_VS_STATE_MASTER 0x0001 /* started as master */
34 #define IP_VS_STATE_BACKUP 0x0002 /* started as backup */
37 * IPVS socket options
39 #define IP_VS_BASE_CTL (64+1024+64) /* base */
41 #define IP_VS_SO_SET_NONE IP_VS_BASE_CTL /* just peek */
42 #define IP_VS_SO_SET_INSERT (IP_VS_BASE_CTL+1)
43 #define IP_VS_SO_SET_ADD (IP_VS_BASE_CTL+2)
44 #define IP_VS_SO_SET_EDIT (IP_VS_BASE_CTL+3)
45 #define IP_VS_SO_SET_DEL (IP_VS_BASE_CTL+4)
46 #define IP_VS_SO_SET_FLUSH (IP_VS_BASE_CTL+5)
47 #define IP_VS_SO_SET_LIST (IP_VS_BASE_CTL+6)
48 #define IP_VS_SO_SET_ADDDEST (IP_VS_BASE_CTL+7)
49 #define IP_VS_SO_SET_DELDEST (IP_VS_BASE_CTL+8)
50 #define IP_VS_SO_SET_EDITDEST (IP_VS_BASE_CTL+9)
51 #define IP_VS_SO_SET_TIMEOUT (IP_VS_BASE_CTL+10)
52 #define IP_VS_SO_SET_STARTDAEMON (IP_VS_BASE_CTL+11)
53 #define IP_VS_SO_SET_STOPDAEMON (IP_VS_BASE_CTL+12)
54 #define IP_VS_SO_SET_RESTORE (IP_VS_BASE_CTL+13)
55 #define IP_VS_SO_SET_SAVE (IP_VS_BASE_CTL+14)
56 #define IP_VS_SO_SET_ZERO (IP_VS_BASE_CTL+15)
57 #define IP_VS_SO_SET_MAX IP_VS_SO_SET_ZERO
59 #define IP_VS_SO_GET_VERSION IP_VS_BASE_CTL
60 #define IP_VS_SO_GET_INFO (IP_VS_BASE_CTL+1)
61 #define IP_VS_SO_GET_SERVICES (IP_VS_BASE_CTL+2)
62 #define IP_VS_SO_GET_SERVICE (IP_VS_BASE_CTL+3)
63 #define IP_VS_SO_GET_DESTS (IP_VS_BASE_CTL+4)
64 #define IP_VS_SO_GET_DEST (IP_VS_BASE_CTL+5) /* not used now */
65 #define IP_VS_SO_GET_TIMEOUT (IP_VS_BASE_CTL+6)
66 #define IP_VS_SO_GET_DAEMON (IP_VS_BASE_CTL+7)
67 #define IP_VS_SO_GET_MAX IP_VS_SO_GET_DAEMON
71 * IPVS Connection Flags
73 #define IP_VS_CONN_F_FWD_MASK 0x0007 /* mask for the fwd methods */
74 #define IP_VS_CONN_F_MASQ 0x0000 /* masquerading/NAT */
75 #define IP_VS_CONN_F_LOCALNODE 0x0001 /* local node */
76 #define IP_VS_CONN_F_TUNNEL 0x0002 /* tunneling */
77 #define IP_VS_CONN_F_DROUTE 0x0003 /* direct routing */
78 #define IP_VS_CONN_F_BYPASS 0x0004 /* cache bypass */
79 #define IP_VS_CONN_F_SYNC 0x0020 /* entry created by sync */
80 #define IP_VS_CONN_F_HASHED 0x0040 /* hashed entry */
81 #define IP_VS_CONN_F_NOOUTPUT 0x0080 /* no output packets */
82 #define IP_VS_CONN_F_INACTIVE 0x0100 /* not established */
83 #define IP_VS_CONN_F_OUT_SEQ 0x0200 /* must do output seq adjust */
84 #define IP_VS_CONN_F_IN_SEQ 0x0400 /* must do input seq adjust */
85 #define IP_VS_CONN_F_SEQ_MASK 0x0600 /* in/out sequence mask */
86 #define IP_VS_CONN_F_NO_CPORT 0x0800 /* no client port set yet */
88 /* Move it to better place one day, for now keep it unique */
89 #define NFC_IPVS_PROPERTY 0x10000
91 #define IP_VS_SCHEDNAME_MAXLEN 16
92 #define IP_VS_IFNAME_MAXLEN 16
96 * The struct ip_vs_service_user and struct ip_vs_dest_user are
97 * used to set IPVS rules through setsockopt.
99 struct ip_vs_service_user {
100 /* virtual service addresses */
101 u_int16_t protocol;
102 u_int32_t addr; /* virtual ip address */
103 u_int16_t port;
104 u_int32_t fwmark; /* firwall mark of service */
106 /* virtual service options */
107 char sched_name[IP_VS_SCHEDNAME_MAXLEN];
108 unsigned flags; /* virtual service flags */
109 unsigned timeout; /* persistent timeout in sec */
110 u_int32_t netmask; /* persistent netmask */
114 struct ip_vs_dest_user {
115 /* destination server address */
116 u_int32_t addr;
117 u_int16_t port;
119 /* real server options */
120 unsigned conn_flags; /* connection flags */
121 int weight; /* destination weight */
123 /* thresholds for active connections */
124 u_int32_t u_threshold; /* upper threshold */
125 u_int32_t l_threshold; /* lower threshold */
130 * IPVS statistics object (for user space)
132 struct ip_vs_stats_user
134 __u32 conns; /* connections scheduled */
135 __u32 inpkts; /* incoming packets */
136 __u32 outpkts; /* outgoing packets */
137 __u64 inbytes; /* incoming bytes */
138 __u64 outbytes; /* outgoing bytes */
140 __u32 cps; /* current connection rate */
141 __u32 inpps; /* current in packet rate */
142 __u32 outpps; /* current out packet rate */
143 __u32 inbps; /* current in byte rate */
144 __u32 outbps; /* current out byte rate */
148 /* The argument to IP_VS_SO_GET_INFO */
149 struct ip_vs_getinfo {
150 /* version number */
151 unsigned int version;
153 /* size of connection hash table */
154 unsigned int size;
156 /* number of virtual services */
157 unsigned int num_services;
161 /* The argument to IP_VS_SO_GET_SERVICE */
162 struct ip_vs_service_entry {
163 /* which service: user fills in these */
164 u_int16_t protocol;
165 u_int32_t addr; /* virtual address */
166 u_int16_t port;
167 u_int32_t fwmark; /* firwall mark of service */
169 /* service options */
170 char sched_name[IP_VS_SCHEDNAME_MAXLEN];
171 unsigned flags; /* virtual service flags */
172 unsigned timeout; /* persistent timeout */
173 u_int32_t netmask; /* persistent netmask */
175 /* number of real servers */
176 unsigned int num_dests;
178 /* statistics */
179 struct ip_vs_stats_user stats;
183 struct ip_vs_dest_entry {
184 u_int32_t addr; /* destination address */
185 u_int16_t port;
186 unsigned conn_flags; /* connection flags */
187 int weight; /* destination weight */
189 u_int32_t u_threshold; /* upper threshold */
190 u_int32_t l_threshold; /* lower threshold */
192 u_int32_t activeconns; /* active connections */
193 u_int32_t inactconns; /* inactive connections */
194 u_int32_t persistconns; /* persistent connections */
196 /* statistics */
197 struct ip_vs_stats_user stats;
201 /* The argument to IP_VS_SO_GET_DESTS */
202 struct ip_vs_get_dests {
203 /* which service: user fills in these */
204 u_int16_t protocol;
205 u_int32_t addr; /* virtual address */
206 u_int16_t port;
207 u_int32_t fwmark; /* firwall mark of service */
209 /* number of real servers */
210 unsigned int num_dests;
212 /* the real servers */
213 struct ip_vs_dest_entry entrytable[0];
217 /* The argument to IP_VS_SO_GET_SERVICES */
218 struct ip_vs_get_services {
219 /* number of virtual services */
220 unsigned int num_services;
222 /* service table */
223 struct ip_vs_service_entry entrytable[0];
227 /* The argument to IP_VS_SO_GET_TIMEOUT */
228 struct ip_vs_timeout_user {
229 int tcp_timeout;
230 int tcp_fin_timeout;
231 int udp_timeout;
235 /* The argument to IP_VS_SO_GET_DAEMON */
236 struct ip_vs_daemon_user {
237 /* sync daemon state (master/backup) */
238 int state;
240 /* multicast interface name */
241 char mcast_ifn[IP_VS_IFNAME_MAXLEN];
243 /* SyncID we belong to */
244 int syncid;
248 #ifdef __KERNEL__
250 #include <linux/config.h>
251 #include <linux/list.h> /* for struct list_head */
252 #include <linux/spinlock.h> /* for struct rwlock_t */
253 #include <linux/skbuff.h> /* for struct sk_buff */
254 #include <linux/ip.h> /* for struct iphdr */
255 #include <asm/atomic.h> /* for struct atomic_t */
256 #include <linux/netdevice.h> /* for struct neighbour */
257 #include <net/dst.h> /* for struct dst_entry */
258 #include <net/tcp.h>
259 #include <net/udp.h>
260 #include <linux/compiler.h>
263 #ifdef CONFIG_IP_VS_DEBUG
264 extern int ip_vs_get_debug_level(void);
265 #define IP_VS_DBG(level, msg...) \
266 do { \
267 if (level <= ip_vs_get_debug_level()) \
268 printk(KERN_DEBUG "IPVS: " msg); \
269 } while (0)
270 #define IP_VS_DBG_RL(msg...) \
271 do { \
272 if (net_ratelimit()) \
273 printk(KERN_DEBUG "IPVS: " msg); \
274 } while (0)
275 #define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) \
276 do { \
277 if (level <= ip_vs_get_debug_level()) \
278 pp->debug_packet(pp, skb, ofs, msg); \
279 } while (0)
280 #define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) \
281 do { \
282 if (level <= ip_vs_get_debug_level() && \
283 net_ratelimit()) \
284 pp->debug_packet(pp, skb, ofs, msg); \
285 } while (0)
286 #else /* NO DEBUGGING at ALL */
287 #define IP_VS_DBG(level, msg...) do {} while (0)
288 #define IP_VS_DBG_RL(msg...) do {} while (0)
289 #define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) do {} while (0)
290 #define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) do {} while (0)
291 #endif
293 #define IP_VS_BUG() BUG()
294 #define IP_VS_ERR(msg...) printk(KERN_ERR "IPVS: " msg)
295 #define IP_VS_INFO(msg...) printk(KERN_INFO "IPVS: " msg)
296 #define IP_VS_WARNING(msg...) \
297 printk(KERN_WARNING "IPVS: " msg)
298 #define IP_VS_ERR_RL(msg...) \
299 do { \
300 if (net_ratelimit()) \
301 printk(KERN_ERR "IPVS: " msg); \
302 } while (0)
304 #ifdef CONFIG_IP_VS_DEBUG
305 #define EnterFunction(level) \
306 do { \
307 if (level <= ip_vs_get_debug_level()) \
308 printk(KERN_DEBUG "Enter: %s, %s line %i\n", \
309 __FUNCTION__, __FILE__, __LINE__); \
310 } while (0)
311 #define LeaveFunction(level) \
312 do { \
313 if (level <= ip_vs_get_debug_level()) \
314 printk(KERN_DEBUG "Leave: %s, %s line %i\n", \
315 __FUNCTION__, __FILE__, __LINE__); \
316 } while (0)
317 #else
318 #define EnterFunction(level) do {} while (0)
319 #define LeaveFunction(level) do {} while (0)
320 #endif
322 #define IP_VS_WAIT_WHILE(expr) while (expr) { cpu_relax(); }
326 * The port number of FTP service (in network order).
328 #define FTPPORT __constant_htons(21)
329 #define FTPDATA __constant_htons(20)
332 * IPVS sysctl variables under the /proc/sys/net/ipv4/vs/
334 #define NET_IPV4_VS 21
336 enum {
337 NET_IPV4_VS_DEBUG_LEVEL=1,
338 NET_IPV4_VS_AMEMTHRESH=2,
339 NET_IPV4_VS_AMDROPRATE=3,
340 NET_IPV4_VS_DROP_ENTRY=4,
341 NET_IPV4_VS_DROP_PACKET=5,
342 NET_IPV4_VS_SECURE_TCP=6,
343 NET_IPV4_VS_TO_ES=7,
344 NET_IPV4_VS_TO_SS=8,
345 NET_IPV4_VS_TO_SR=9,
346 NET_IPV4_VS_TO_FW=10,
347 NET_IPV4_VS_TO_TW=11,
348 NET_IPV4_VS_TO_CL=12,
349 NET_IPV4_VS_TO_CW=13,
350 NET_IPV4_VS_TO_LA=14,
351 NET_IPV4_VS_TO_LI=15,
352 NET_IPV4_VS_TO_SA=16,
353 NET_IPV4_VS_TO_UDP=17,
354 NET_IPV4_VS_TO_ICMP=18,
355 NET_IPV4_VS_LBLC_EXPIRE=19,
356 NET_IPV4_VS_LBLCR_EXPIRE=20,
357 NET_IPV4_VS_CACHE_BYPASS=22,
358 NET_IPV4_VS_EXPIRE_NODEST_CONN=23,
359 NET_IPV4_VS_SYNC_THRESHOLD=24,
360 NET_IPV4_VS_NAT_ICMP_SEND=25,
361 NET_IPV4_VS_EXPIRE_QUIESCENT_TEMPLATE=26,
362 NET_IPV4_VS_LAST
366 * TCP State Values
368 enum {
369 IP_VS_TCP_S_NONE = 0,
370 IP_VS_TCP_S_ESTABLISHED,
371 IP_VS_TCP_S_SYN_SENT,
372 IP_VS_TCP_S_SYN_RECV,
373 IP_VS_TCP_S_FIN_WAIT,
374 IP_VS_TCP_S_TIME_WAIT,
375 IP_VS_TCP_S_CLOSE,
376 IP_VS_TCP_S_CLOSE_WAIT,
377 IP_VS_TCP_S_LAST_ACK,
378 IP_VS_TCP_S_LISTEN,
379 IP_VS_TCP_S_SYNACK,
380 IP_VS_TCP_S_LAST
384 * UDP State Values
386 enum {
387 IP_VS_UDP_S_NORMAL,
388 IP_VS_UDP_S_LAST,
392 * ICMP State Values
394 enum {
395 IP_VS_ICMP_S_NORMAL,
396 IP_VS_ICMP_S_LAST,
400 * Delta sequence info structure
401 * Each ip_vs_conn has 2 (output AND input seq. changes).
402 * Only used in the VS/NAT.
404 struct ip_vs_seq {
405 __u32 init_seq; /* Add delta from this seq */
406 __u32 delta; /* Delta in sequence numbers */
407 __u32 previous_delta; /* Delta in sequence numbers
408 before last resized pkt */
413 * IPVS statistics object
415 struct ip_vs_stats
417 __u32 conns; /* connections scheduled */
418 __u32 inpkts; /* incoming packets */
419 __u32 outpkts; /* outgoing packets */
420 __u64 inbytes; /* incoming bytes */
421 __u64 outbytes; /* outgoing bytes */
423 __u32 cps; /* current connection rate */
424 __u32 inpps; /* current in packet rate */
425 __u32 outpps; /* current out packet rate */
426 __u32 inbps; /* current in byte rate */
427 __u32 outbps; /* current out byte rate */
429 spinlock_t lock; /* spin lock */
432 struct ip_vs_conn;
433 struct ip_vs_app;
435 struct ip_vs_protocol {
436 struct ip_vs_protocol *next;
437 char *name;
438 __u16 protocol;
439 int dont_defrag;
440 atomic_t appcnt; /* counter of proto app incs */
441 int *timeout_table; /* protocol timeout table */
443 void (*init)(struct ip_vs_protocol *pp);
445 void (*exit)(struct ip_vs_protocol *pp);
447 int (*conn_schedule)(struct sk_buff *skb,
448 struct ip_vs_protocol *pp,
449 int *verdict, struct ip_vs_conn **cpp);
451 struct ip_vs_conn *
452 (*conn_in_get)(const struct sk_buff *skb,
453 struct ip_vs_protocol *pp,
454 const struct iphdr *iph,
455 unsigned int proto_off,
456 int inverse);
458 struct ip_vs_conn *
459 (*conn_out_get)(const struct sk_buff *skb,
460 struct ip_vs_protocol *pp,
461 const struct iphdr *iph,
462 unsigned int proto_off,
463 int inverse);
465 int (*snat_handler)(struct sk_buff **pskb,
466 struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
468 int (*dnat_handler)(struct sk_buff **pskb,
469 struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
471 int (*csum_check)(struct sk_buff *skb, struct ip_vs_protocol *pp);
473 const char *(*state_name)(int state);
475 int (*state_transition)(struct ip_vs_conn *cp, int direction,
476 const struct sk_buff *skb,
477 struct ip_vs_protocol *pp);
479 int (*register_app)(struct ip_vs_app *inc);
481 void (*unregister_app)(struct ip_vs_app *inc);
483 int (*app_conn_bind)(struct ip_vs_conn *cp);
485 void (*debug_packet)(struct ip_vs_protocol *pp,
486 const struct sk_buff *skb,
487 int offset,
488 const char *msg);
490 void (*timeout_change)(struct ip_vs_protocol *pp, int flags);
492 int (*set_state_timeout)(struct ip_vs_protocol *pp, char *sname, int to);
495 extern struct ip_vs_protocol * ip_vs_proto_get(unsigned short proto);
498 * IP_VS structure allocated for each dynamically scheduled connection
500 struct ip_vs_conn {
501 struct list_head c_list; /* hashed list heads */
503 /* Protocol, addresses and port numbers */
504 __u32 caddr; /* client address */
505 __u32 vaddr; /* virtual address */
506 __u32 daddr; /* destination address */
507 __u16 cport;
508 __u16 vport;
509 __u16 dport;
510 __u16 protocol; /* Which protocol (TCP/UDP) */
512 /* counter and timer */
513 atomic_t refcnt; /* reference count */
514 struct timer_list timer; /* Expiration timer */
515 volatile unsigned long timeout; /* timeout */
517 /* Flags and state transition */
518 spinlock_t lock; /* lock for state transition */
519 volatile __u16 flags; /* status flags */
520 volatile __u16 state; /* state info */
522 /* Control members */
523 struct ip_vs_conn *control; /* Master control connection */
524 atomic_t n_control; /* Number of controlled ones */
525 struct ip_vs_dest *dest; /* real server */
526 atomic_t in_pkts; /* incoming packet counter */
528 /* packet transmitter for different forwarding methods. If it
529 mangles the packet, it must return NF_DROP or better NF_STOLEN,
530 otherwise this must be changed to a sk_buff **.
532 int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp,
533 struct ip_vs_protocol *pp);
535 /* Note: we can group the following members into a structure,
536 in order to save more space, and the following members are
537 only used in VS/NAT anyway */
538 struct ip_vs_app *app; /* bound ip_vs_app object */
539 void *app_data; /* Application private data */
540 struct ip_vs_seq in_seq; /* incoming seq. struct */
541 struct ip_vs_seq out_seq; /* outgoing seq. struct */
546 * The information about the virtual service offered to the net
547 * and the forwarding entries
549 struct ip_vs_service {
550 struct list_head s_list; /* for normal service table */
551 struct list_head f_list; /* for fwmark-based service table */
552 atomic_t refcnt; /* reference counter */
553 atomic_t usecnt; /* use counter */
555 __u16 protocol; /* which protocol (TCP/UDP) */
556 __u32 addr; /* IP address for virtual service */
557 __u16 port; /* port number for the service */
558 __u32 fwmark; /* firewall mark of the service */
559 unsigned flags; /* service status flags */
560 unsigned timeout; /* persistent timeout in ticks */
561 __u32 netmask; /* grouping granularity */
563 struct list_head destinations; /* real server d-linked list */
564 __u32 num_dests; /* number of servers */
565 struct ip_vs_stats stats; /* statistics for the service */
566 struct ip_vs_app *inc; /* bind conns to this app inc */
568 /* for scheduling */
569 struct ip_vs_scheduler *scheduler; /* bound scheduler object */
570 rwlock_t sched_lock; /* lock sched_data */
571 void *sched_data; /* scheduler application data */
576 * The real server destination forwarding entry
577 * with ip address, port number, and so on.
579 struct ip_vs_dest {
580 struct list_head n_list; /* for the dests in the service */
581 struct list_head d_list; /* for table with all the dests */
583 __u32 addr; /* IP address of the server */
584 __u16 port; /* port number of the server */
585 volatile unsigned flags; /* dest status flags */
586 atomic_t conn_flags; /* flags to copy to conn */
587 atomic_t weight; /* server weight */
589 atomic_t refcnt; /* reference counter */
590 struct ip_vs_stats stats; /* statistics */
592 /* connection counters and thresholds */
593 atomic_t activeconns; /* active connections */
594 atomic_t inactconns; /* inactive connections */
595 atomic_t persistconns; /* persistent connections */
596 __u32 u_threshold; /* upper threshold */
597 __u32 l_threshold; /* lower threshold */
599 /* for destination cache */
600 spinlock_t dst_lock; /* lock of dst_cache */
601 struct dst_entry *dst_cache; /* destination cache entry */
602 u32 dst_rtos; /* RT_TOS(tos) for dst */
604 /* for virtual service */
605 struct ip_vs_service *svc; /* service it belongs to */
606 __u16 protocol; /* which protocol (TCP/UDP) */
607 __u32 vaddr; /* virtual IP address */
608 __u16 vport; /* virtual port number */
609 __u32 vfwmark; /* firewall mark of service */
614 * The scheduler object
616 struct ip_vs_scheduler {
617 struct list_head n_list; /* d-linked list head */
618 char *name; /* scheduler name */
619 atomic_t refcnt; /* reference counter */
620 struct module *module; /* THIS_MODULE/NULL */
622 /* scheduler initializing service */
623 int (*init_service)(struct ip_vs_service *svc);
624 /* scheduling service finish */
625 int (*done_service)(struct ip_vs_service *svc);
626 /* scheduler updating service */
627 int (*update_service)(struct ip_vs_service *svc);
629 /* selecting a server from the given service */
630 struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc,
631 const struct sk_buff *skb);
636 * The application module object (a.k.a. app incarnation)
638 struct ip_vs_app
640 struct list_head a_list; /* member in app list */
641 int type; /* IP_VS_APP_TYPE_xxx */
642 char *name; /* application module name */
643 __u16 protocol;
644 struct module *module; /* THIS_MODULE/NULL */
645 struct list_head incs_list; /* list of incarnations */
647 /* members for application incarnations */
648 struct list_head p_list; /* member in proto app list */
649 struct ip_vs_app *app; /* its real application */
650 __u16 port; /* port number in net order */
651 atomic_t usecnt; /* usage counter */
653 /* output hook: return false if can't linearize. diff set for TCP. */
654 int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *,
655 struct sk_buff **, int *diff);
657 /* input hook: return false if can't linearize. diff set for TCP. */
658 int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *,
659 struct sk_buff **, int *diff);
661 /* ip_vs_app initializer */
662 int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *);
664 /* ip_vs_app finish */
665 int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *);
668 /* not used now */
669 int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *,
670 struct ip_vs_protocol *);
672 void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *);
674 int * timeout_table;
675 int * timeouts;
676 int timeouts_size;
678 int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app,
679 int *verdict, struct ip_vs_conn **cpp);
681 struct ip_vs_conn *
682 (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app,
683 const struct iphdr *iph, unsigned int proto_off,
684 int inverse);
686 struct ip_vs_conn *
687 (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app,
688 const struct iphdr *iph, unsigned int proto_off,
689 int inverse);
691 int (*state_transition)(struct ip_vs_conn *cp, int direction,
692 const struct sk_buff *skb,
693 struct ip_vs_app *app);
695 void (*timeout_change)(struct ip_vs_app *app, int flags);
700 * IPVS core functions
701 * (from ip_vs_core.c)
703 extern const char *ip_vs_proto_name(unsigned proto);
704 extern void ip_vs_init_hash_table(struct list_head *table, int rows);
705 #define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table(t, sizeof(t)/sizeof(t[0]))
707 #define IP_VS_APP_TYPE_UNSPEC 0
708 #define IP_VS_APP_TYPE_FTP 1
711 * ip_vs_conn handling functions
712 * (from ip_vs_conn.c)
716 * IPVS connection entry hash table
718 #ifndef CONFIG_IP_VS_TAB_BITS
719 #define CONFIG_IP_VS_TAB_BITS 12
720 #endif
721 /* make sure that IP_VS_CONN_TAB_BITS is located in [8, 20] */
722 #if CONFIG_IP_VS_TAB_BITS < 8
723 #define IP_VS_CONN_TAB_BITS 8
724 #endif
725 #if CONFIG_IP_VS_TAB_BITS > 20
726 #define IP_VS_CONN_TAB_BITS 20
727 #endif
728 #if 8 <= CONFIG_IP_VS_TAB_BITS && CONFIG_IP_VS_TAB_BITS <= 20
729 #define IP_VS_CONN_TAB_BITS CONFIG_IP_VS_TAB_BITS
730 #endif
731 #define IP_VS_CONN_TAB_SIZE (1 << IP_VS_CONN_TAB_BITS)
732 #define IP_VS_CONN_TAB_MASK (IP_VS_CONN_TAB_SIZE - 1)
734 enum {
735 IP_VS_DIR_INPUT = 0,
736 IP_VS_DIR_OUTPUT,
737 IP_VS_DIR_INPUT_ONLY,
738 IP_VS_DIR_LAST,
741 extern struct ip_vs_conn *ip_vs_conn_in_get
742 (int protocol, __u32 s_addr, __u16 s_port, __u32 d_addr, __u16 d_port);
743 extern struct ip_vs_conn *ip_vs_conn_out_get
744 (int protocol, __u32 s_addr, __u16 s_port, __u32 d_addr, __u16 d_port);
746 /* put back the conn without restarting its timer */
747 static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
749 atomic_dec(&cp->refcnt);
751 extern void ip_vs_conn_put(struct ip_vs_conn *cp);
752 extern void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __u16 cport);
754 extern struct ip_vs_conn *
755 ip_vs_conn_new(int proto, __u32 caddr, __u16 cport, __u32 vaddr, __u16 vport,
756 __u32 daddr, __u16 dport, unsigned flags,
757 struct ip_vs_dest *dest);
758 extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
760 extern const char * ip_vs_state_name(__u16 proto, int state);
762 extern void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp);
763 extern int ip_vs_check_template(struct ip_vs_conn *ct);
764 extern void ip_vs_secure_tcp_set(int on);
765 extern void ip_vs_random_dropentry(void);
766 extern int ip_vs_conn_init(void);
767 extern void ip_vs_conn_cleanup(void);
769 static inline void ip_vs_control_del(struct ip_vs_conn *cp)
771 struct ip_vs_conn *ctl_cp = cp->control;
772 if (!ctl_cp) {
773 IP_VS_ERR("request control DEL for uncontrolled: "
774 "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
775 NIPQUAD(cp->caddr),ntohs(cp->cport),
776 NIPQUAD(cp->vaddr),ntohs(cp->vport));
777 return;
780 IP_VS_DBG(7, "DELeting control for: "
781 "cp.dst=%d.%d.%d.%d:%d ctl_cp.dst=%d.%d.%d.%d:%d\n",
782 NIPQUAD(cp->caddr),ntohs(cp->cport),
783 NIPQUAD(ctl_cp->caddr),ntohs(ctl_cp->cport));
785 cp->control = NULL;
786 if (atomic_read(&ctl_cp->n_control) == 0) {
787 IP_VS_ERR("BUG control DEL with n=0 : "
788 "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
789 NIPQUAD(cp->caddr),ntohs(cp->cport),
790 NIPQUAD(cp->vaddr),ntohs(cp->vport));
791 return;
793 atomic_dec(&ctl_cp->n_control);
796 static inline void
797 ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)
799 if (cp->control) {
800 IP_VS_ERR("request control ADD for already controlled: "
801 "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
802 NIPQUAD(cp->caddr),ntohs(cp->cport),
803 NIPQUAD(cp->vaddr),ntohs(cp->vport));
804 ip_vs_control_del(cp);
807 IP_VS_DBG(7, "ADDing control for: "
808 "cp.dst=%d.%d.%d.%d:%d ctl_cp.dst=%d.%d.%d.%d:%d\n",
809 NIPQUAD(cp->caddr),ntohs(cp->cport),
810 NIPQUAD(ctl_cp->caddr),ntohs(ctl_cp->cport));
812 cp->control = ctl_cp;
813 atomic_inc(&ctl_cp->n_control);
818 * IPVS application functions
819 * (from ip_vs_app.c)
821 #define IP_VS_APP_MAX_PORTS 8
822 extern int register_ip_vs_app(struct ip_vs_app *app);
823 extern void unregister_ip_vs_app(struct ip_vs_app *app);
824 extern int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
825 extern void ip_vs_unbind_app(struct ip_vs_conn *cp);
826 extern int
827 register_ip_vs_app_inc(struct ip_vs_app *app, __u16 proto, __u16 port);
828 extern int ip_vs_app_inc_get(struct ip_vs_app *inc);
829 extern void ip_vs_app_inc_put(struct ip_vs_app *inc);
831 extern int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff **pskb);
832 extern int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff **pskb);
833 extern int ip_vs_skb_replace(struct sk_buff *skb, int pri,
834 char *o_buf, int o_len, char *n_buf, int n_len);
835 extern int ip_vs_app_init(void);
836 extern void ip_vs_app_cleanup(void);
840 * IPVS protocol functions (from ip_vs_proto.c)
842 extern int ip_vs_protocol_init(void);
843 extern void ip_vs_protocol_cleanup(void);
844 extern void ip_vs_protocol_timeout_change(int flags);
845 extern int *ip_vs_create_timeout_table(int *table, int size);
846 extern int
847 ip_vs_set_state_timeout(int *table, int num, char **names, char *name, int to);
848 extern void
849 ip_vs_tcpudp_debug_packet(struct ip_vs_protocol *pp, const struct sk_buff *skb,
850 int offset, const char *msg);
852 extern struct ip_vs_protocol ip_vs_protocol_tcp;
853 extern struct ip_vs_protocol ip_vs_protocol_udp;
854 extern struct ip_vs_protocol ip_vs_protocol_icmp;
855 extern struct ip_vs_protocol ip_vs_protocol_esp;
856 extern struct ip_vs_protocol ip_vs_protocol_ah;
860 * Registering/unregistering scheduler functions
861 * (from ip_vs_sched.c)
863 extern int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
864 extern int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
865 extern int ip_vs_bind_scheduler(struct ip_vs_service *svc,
866 struct ip_vs_scheduler *scheduler);
867 extern int ip_vs_unbind_scheduler(struct ip_vs_service *svc);
868 extern struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name);
869 extern void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler);
870 extern struct ip_vs_conn *
871 ip_vs_schedule(struct ip_vs_service *svc, const struct sk_buff *skb);
872 extern int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
873 struct ip_vs_protocol *pp);
877 * IPVS control data and functions (from ip_vs_ctl.c)
879 extern int sysctl_ip_vs_cache_bypass;
880 extern int sysctl_ip_vs_expire_nodest_conn;
881 extern int sysctl_ip_vs_expire_quiescent_template;
882 extern int sysctl_ip_vs_sync_threshold[2];
883 extern int sysctl_ip_vs_nat_icmp_send;
884 extern struct ip_vs_stats ip_vs_stats;
886 extern struct ip_vs_service *
887 ip_vs_service_get(__u32 fwmark, __u16 protocol, __u32 vaddr, __u16 vport);
889 static inline void ip_vs_service_put(struct ip_vs_service *svc)
891 atomic_dec(&svc->usecnt);
894 extern struct ip_vs_dest *
895 ip_vs_lookup_real_service(__u16 protocol, __u32 daddr, __u16 dport);
896 extern int ip_vs_use_count_inc(void);
897 extern void ip_vs_use_count_dec(void);
898 extern int ip_vs_control_init(void);
899 extern void ip_vs_control_cleanup(void);
903 * IPVS sync daemon data and function prototypes
904 * (from ip_vs_sync.c)
906 extern volatile int ip_vs_sync_state;
907 extern volatile int ip_vs_master_syncid;
908 extern volatile int ip_vs_backup_syncid;
909 extern char ip_vs_master_mcast_ifn[IP_VS_IFNAME_MAXLEN];
910 extern char ip_vs_backup_mcast_ifn[IP_VS_IFNAME_MAXLEN];
911 extern int start_sync_thread(int state, char *mcast_ifn, __u8 syncid);
912 extern int stop_sync_thread(int state);
913 extern void ip_vs_sync_conn(struct ip_vs_conn *cp);
917 * IPVS rate estimator prototypes (from ip_vs_est.c)
919 extern int ip_vs_new_estimator(struct ip_vs_stats *stats);
920 extern void ip_vs_kill_estimator(struct ip_vs_stats *stats);
921 extern void ip_vs_zero_estimator(struct ip_vs_stats *stats);
924 * Various IPVS packet transmitters (from ip_vs_xmit.c)
926 extern int ip_vs_null_xmit
927 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
928 extern int ip_vs_bypass_xmit
929 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
930 extern int ip_vs_nat_xmit
931 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
932 extern int ip_vs_tunnel_xmit
933 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
934 extern int ip_vs_dr_xmit
935 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
936 extern int ip_vs_icmp_xmit
937 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, int offset);
938 extern void ip_vs_dst_reset(struct ip_vs_dest *dest);
942 * This is a simple mechanism to ignore packets when
943 * we are loaded. Just set ip_vs_drop_rate to 'n' and
944 * we start to drop 1/rate of the packets
946 extern int ip_vs_drop_rate;
947 extern int ip_vs_drop_counter;
949 static __inline__ int ip_vs_todrop(void)
951 if (!ip_vs_drop_rate) return 0;
952 if (--ip_vs_drop_counter > 0) return 0;
953 ip_vs_drop_counter = ip_vs_drop_rate;
954 return 1;
958 * ip_vs_fwd_tag returns the forwarding tag of the connection
960 #define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK)
962 extern __inline__ char ip_vs_fwd_tag(struct ip_vs_conn *cp)
964 char fwd;
966 switch (IP_VS_FWD_METHOD(cp)) {
967 case IP_VS_CONN_F_MASQ:
968 fwd = 'M'; break;
969 case IP_VS_CONN_F_LOCALNODE:
970 fwd = 'L'; break;
971 case IP_VS_CONN_F_TUNNEL:
972 fwd = 'T'; break;
973 case IP_VS_CONN_F_DROUTE:
974 fwd = 'R'; break;
975 case IP_VS_CONN_F_BYPASS:
976 fwd = 'B'; break;
977 default:
978 fwd = '?'; break;
980 return fwd;
983 extern int ip_vs_make_skb_writable(struct sk_buff **pskb, int len);
984 extern void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,
985 struct ip_vs_conn *cp, int dir);
987 extern u16 ip_vs_checksum_complete(struct sk_buff *skb, int offset);
989 static inline u16 ip_vs_check_diff(u32 old, u32 new, u16 oldsum)
991 u32 diff[2] = { old, new };
993 return csum_fold(csum_partial((char *) diff, sizeof(diff),
994 oldsum ^ 0xFFFF));
997 #endif /* __KERNEL__ */
999 #endif /* _IP_VS_H */