[CPUFREQ] Fix the p4-clockmod N60 errata workaround.
[linux-2.6/mini2440.git] / include / net / ip_vs.h
blob7d2674fde19a87020a225ada56b64a97c118ff44
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 */
87 #define IP_VS_CONN_F_TEMPLATE 0x1000 /* template, not connection */
89 /* Move it to better place one day, for now keep it unique */
90 #define NFC_IPVS_PROPERTY 0x10000
92 #define IP_VS_SCHEDNAME_MAXLEN 16
93 #define IP_VS_IFNAME_MAXLEN 16
97 * The struct ip_vs_service_user and struct ip_vs_dest_user are
98 * used to set IPVS rules through setsockopt.
100 struct ip_vs_service_user {
101 /* virtual service addresses */
102 u_int16_t protocol;
103 u_int32_t addr; /* virtual ip address */
104 u_int16_t port;
105 u_int32_t fwmark; /* firwall mark of service */
107 /* virtual service options */
108 char sched_name[IP_VS_SCHEDNAME_MAXLEN];
109 unsigned flags; /* virtual service flags */
110 unsigned timeout; /* persistent timeout in sec */
111 u_int32_t netmask; /* persistent netmask */
115 struct ip_vs_dest_user {
116 /* destination server address */
117 u_int32_t addr;
118 u_int16_t port;
120 /* real server options */
121 unsigned conn_flags; /* connection flags */
122 int weight; /* destination weight */
124 /* thresholds for active connections */
125 u_int32_t u_threshold; /* upper threshold */
126 u_int32_t l_threshold; /* lower threshold */
131 * IPVS statistics object (for user space)
133 struct ip_vs_stats_user
135 __u32 conns; /* connections scheduled */
136 __u32 inpkts; /* incoming packets */
137 __u32 outpkts; /* outgoing packets */
138 __u64 inbytes; /* incoming bytes */
139 __u64 outbytes; /* outgoing bytes */
141 __u32 cps; /* current connection rate */
142 __u32 inpps; /* current in packet rate */
143 __u32 outpps; /* current out packet rate */
144 __u32 inbps; /* current in byte rate */
145 __u32 outbps; /* current out byte rate */
149 /* The argument to IP_VS_SO_GET_INFO */
150 struct ip_vs_getinfo {
151 /* version number */
152 unsigned int version;
154 /* size of connection hash table */
155 unsigned int size;
157 /* number of virtual services */
158 unsigned int num_services;
162 /* The argument to IP_VS_SO_GET_SERVICE */
163 struct ip_vs_service_entry {
164 /* which service: user fills in these */
165 u_int16_t protocol;
166 u_int32_t addr; /* virtual address */
167 u_int16_t port;
168 u_int32_t fwmark; /* firwall mark of service */
170 /* service options */
171 char sched_name[IP_VS_SCHEDNAME_MAXLEN];
172 unsigned flags; /* virtual service flags */
173 unsigned timeout; /* persistent timeout */
174 u_int32_t netmask; /* persistent netmask */
176 /* number of real servers */
177 unsigned int num_dests;
179 /* statistics */
180 struct ip_vs_stats_user stats;
184 struct ip_vs_dest_entry {
185 u_int32_t addr; /* destination address */
186 u_int16_t port;
187 unsigned conn_flags; /* connection flags */
188 int weight; /* destination weight */
190 u_int32_t u_threshold; /* upper threshold */
191 u_int32_t l_threshold; /* lower threshold */
193 u_int32_t activeconns; /* active connections */
194 u_int32_t inactconns; /* inactive connections */
195 u_int32_t persistconns; /* persistent connections */
197 /* statistics */
198 struct ip_vs_stats_user stats;
202 /* The argument to IP_VS_SO_GET_DESTS */
203 struct ip_vs_get_dests {
204 /* which service: user fills in these */
205 u_int16_t protocol;
206 u_int32_t addr; /* virtual address */
207 u_int16_t port;
208 u_int32_t fwmark; /* firwall mark of service */
210 /* number of real servers */
211 unsigned int num_dests;
213 /* the real servers */
214 struct ip_vs_dest_entry entrytable[0];
218 /* The argument to IP_VS_SO_GET_SERVICES */
219 struct ip_vs_get_services {
220 /* number of virtual services */
221 unsigned int num_services;
223 /* service table */
224 struct ip_vs_service_entry entrytable[0];
228 /* The argument to IP_VS_SO_GET_TIMEOUT */
229 struct ip_vs_timeout_user {
230 int tcp_timeout;
231 int tcp_fin_timeout;
232 int udp_timeout;
236 /* The argument to IP_VS_SO_GET_DAEMON */
237 struct ip_vs_daemon_user {
238 /* sync daemon state (master/backup) */
239 int state;
241 /* multicast interface name */
242 char mcast_ifn[IP_VS_IFNAME_MAXLEN];
244 /* SyncID we belong to */
245 int syncid;
249 #ifdef __KERNEL__
251 #include <linux/config.h>
252 #include <linux/list.h> /* for struct list_head */
253 #include <linux/spinlock.h> /* for struct rwlock_t */
254 #include <asm/atomic.h> /* for struct atomic_t */
255 #include <linux/compiler.h>
256 #include <linux/timer.h>
258 #include <net/checksum.h>
260 #ifdef CONFIG_IP_VS_DEBUG
261 #include <linux/net.h>
263 extern int ip_vs_get_debug_level(void);
264 #define IP_VS_DBG(level, msg...) \
265 do { \
266 if (level <= ip_vs_get_debug_level()) \
267 printk(KERN_DEBUG "IPVS: " msg); \
268 } while (0)
269 #define IP_VS_DBG_RL(msg...) \
270 do { \
271 if (net_ratelimit()) \
272 printk(KERN_DEBUG "IPVS: " msg); \
273 } while (0)
274 #define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) \
275 do { \
276 if (level <= ip_vs_get_debug_level()) \
277 pp->debug_packet(pp, skb, ofs, msg); \
278 } while (0)
279 #define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) \
280 do { \
281 if (level <= ip_vs_get_debug_level() && \
282 net_ratelimit()) \
283 pp->debug_packet(pp, skb, ofs, msg); \
284 } while (0)
285 #else /* NO DEBUGGING at ALL */
286 #define IP_VS_DBG(level, msg...) do {} while (0)
287 #define IP_VS_DBG_RL(msg...) do {} while (0)
288 #define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) do {} while (0)
289 #define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) do {} while (0)
290 #endif
292 #define IP_VS_BUG() BUG()
293 #define IP_VS_ERR(msg...) printk(KERN_ERR "IPVS: " msg)
294 #define IP_VS_INFO(msg...) printk(KERN_INFO "IPVS: " msg)
295 #define IP_VS_WARNING(msg...) \
296 printk(KERN_WARNING "IPVS: " msg)
297 #define IP_VS_ERR_RL(msg...) \
298 do { \
299 if (net_ratelimit()) \
300 printk(KERN_ERR "IPVS: " msg); \
301 } while (0)
303 #ifdef CONFIG_IP_VS_DEBUG
304 #define EnterFunction(level) \
305 do { \
306 if (level <= ip_vs_get_debug_level()) \
307 printk(KERN_DEBUG "Enter: %s, %s line %i\n", \
308 __FUNCTION__, __FILE__, __LINE__); \
309 } while (0)
310 #define LeaveFunction(level) \
311 do { \
312 if (level <= ip_vs_get_debug_level()) \
313 printk(KERN_DEBUG "Leave: %s, %s line %i\n", \
314 __FUNCTION__, __FILE__, __LINE__); \
315 } while (0)
316 #else
317 #define EnterFunction(level) do {} while (0)
318 #define LeaveFunction(level) do {} while (0)
319 #endif
321 #define IP_VS_WAIT_WHILE(expr) while (expr) { cpu_relax(); }
325 * The port number of FTP service (in network order).
327 #define FTPPORT __constant_htons(21)
328 #define FTPDATA __constant_htons(20)
331 * IPVS sysctl variables under the /proc/sys/net/ipv4/vs/
333 #define NET_IPV4_VS 21
335 enum {
336 NET_IPV4_VS_DEBUG_LEVEL=1,
337 NET_IPV4_VS_AMEMTHRESH=2,
338 NET_IPV4_VS_AMDROPRATE=3,
339 NET_IPV4_VS_DROP_ENTRY=4,
340 NET_IPV4_VS_DROP_PACKET=5,
341 NET_IPV4_VS_SECURE_TCP=6,
342 NET_IPV4_VS_TO_ES=7,
343 NET_IPV4_VS_TO_SS=8,
344 NET_IPV4_VS_TO_SR=9,
345 NET_IPV4_VS_TO_FW=10,
346 NET_IPV4_VS_TO_TW=11,
347 NET_IPV4_VS_TO_CL=12,
348 NET_IPV4_VS_TO_CW=13,
349 NET_IPV4_VS_TO_LA=14,
350 NET_IPV4_VS_TO_LI=15,
351 NET_IPV4_VS_TO_SA=16,
352 NET_IPV4_VS_TO_UDP=17,
353 NET_IPV4_VS_TO_ICMP=18,
354 NET_IPV4_VS_LBLC_EXPIRE=19,
355 NET_IPV4_VS_LBLCR_EXPIRE=20,
356 NET_IPV4_VS_CACHE_BYPASS=22,
357 NET_IPV4_VS_EXPIRE_NODEST_CONN=23,
358 NET_IPV4_VS_SYNC_THRESHOLD=24,
359 NET_IPV4_VS_NAT_ICMP_SEND=25,
360 NET_IPV4_VS_EXPIRE_QUIESCENT_TEMPLATE=26,
361 NET_IPV4_VS_LAST
365 * TCP State Values
367 enum {
368 IP_VS_TCP_S_NONE = 0,
369 IP_VS_TCP_S_ESTABLISHED,
370 IP_VS_TCP_S_SYN_SENT,
371 IP_VS_TCP_S_SYN_RECV,
372 IP_VS_TCP_S_FIN_WAIT,
373 IP_VS_TCP_S_TIME_WAIT,
374 IP_VS_TCP_S_CLOSE,
375 IP_VS_TCP_S_CLOSE_WAIT,
376 IP_VS_TCP_S_LAST_ACK,
377 IP_VS_TCP_S_LISTEN,
378 IP_VS_TCP_S_SYNACK,
379 IP_VS_TCP_S_LAST
383 * UDP State Values
385 enum {
386 IP_VS_UDP_S_NORMAL,
387 IP_VS_UDP_S_LAST,
391 * ICMP State Values
393 enum {
394 IP_VS_ICMP_S_NORMAL,
395 IP_VS_ICMP_S_LAST,
399 * Delta sequence info structure
400 * Each ip_vs_conn has 2 (output AND input seq. changes).
401 * Only used in the VS/NAT.
403 struct ip_vs_seq {
404 __u32 init_seq; /* Add delta from this seq */
405 __u32 delta; /* Delta in sequence numbers */
406 __u32 previous_delta; /* Delta in sequence numbers
407 before last resized pkt */
412 * IPVS statistics object
414 struct ip_vs_stats
416 __u32 conns; /* connections scheduled */
417 __u32 inpkts; /* incoming packets */
418 __u32 outpkts; /* outgoing packets */
419 __u64 inbytes; /* incoming bytes */
420 __u64 outbytes; /* outgoing bytes */
422 __u32 cps; /* current connection rate */
423 __u32 inpps; /* current in packet rate */
424 __u32 outpps; /* current out packet rate */
425 __u32 inbps; /* current in byte rate */
426 __u32 outbps; /* current out byte rate */
428 spinlock_t lock; /* spin lock */
431 struct dst_entry;
432 struct iphdr;
433 struct ip_vs_conn;
434 struct ip_vs_app;
435 struct sk_buff;
437 struct ip_vs_protocol {
438 struct ip_vs_protocol *next;
439 char *name;
440 __u16 protocol;
441 int dont_defrag;
442 atomic_t appcnt; /* counter of proto app incs */
443 int *timeout_table; /* protocol timeout table */
445 void (*init)(struct ip_vs_protocol *pp);
447 void (*exit)(struct ip_vs_protocol *pp);
449 int (*conn_schedule)(struct sk_buff *skb,
450 struct ip_vs_protocol *pp,
451 int *verdict, struct ip_vs_conn **cpp);
453 struct ip_vs_conn *
454 (*conn_in_get)(const struct sk_buff *skb,
455 struct ip_vs_protocol *pp,
456 const struct iphdr *iph,
457 unsigned int proto_off,
458 int inverse);
460 struct ip_vs_conn *
461 (*conn_out_get)(const struct sk_buff *skb,
462 struct ip_vs_protocol *pp,
463 const struct iphdr *iph,
464 unsigned int proto_off,
465 int inverse);
467 int (*snat_handler)(struct sk_buff **pskb,
468 struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
470 int (*dnat_handler)(struct sk_buff **pskb,
471 struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
473 int (*csum_check)(struct sk_buff *skb, struct ip_vs_protocol *pp);
475 const char *(*state_name)(int state);
477 int (*state_transition)(struct ip_vs_conn *cp, int direction,
478 const struct sk_buff *skb,
479 struct ip_vs_protocol *pp);
481 int (*register_app)(struct ip_vs_app *inc);
483 void (*unregister_app)(struct ip_vs_app *inc);
485 int (*app_conn_bind)(struct ip_vs_conn *cp);
487 void (*debug_packet)(struct ip_vs_protocol *pp,
488 const struct sk_buff *skb,
489 int offset,
490 const char *msg);
492 void (*timeout_change)(struct ip_vs_protocol *pp, int flags);
494 int (*set_state_timeout)(struct ip_vs_protocol *pp, char *sname, int to);
497 extern struct ip_vs_protocol * ip_vs_proto_get(unsigned short proto);
500 * IP_VS structure allocated for each dynamically scheduled connection
502 struct ip_vs_conn {
503 struct list_head c_list; /* hashed list heads */
505 /* Protocol, addresses and port numbers */
506 __u32 caddr; /* client address */
507 __u32 vaddr; /* virtual address */
508 __u32 daddr; /* destination address */
509 __u16 cport;
510 __u16 vport;
511 __u16 dport;
512 __u16 protocol; /* Which protocol (TCP/UDP) */
514 /* counter and timer */
515 atomic_t refcnt; /* reference count */
516 struct timer_list timer; /* Expiration timer */
517 volatile unsigned long timeout; /* timeout */
519 /* Flags and state transition */
520 spinlock_t lock; /* lock for state transition */
521 volatile __u16 flags; /* status flags */
522 volatile __u16 state; /* state info */
524 /* Control members */
525 struct ip_vs_conn *control; /* Master control connection */
526 atomic_t n_control; /* Number of controlled ones */
527 struct ip_vs_dest *dest; /* real server */
528 atomic_t in_pkts; /* incoming packet counter */
530 /* packet transmitter for different forwarding methods. If it
531 mangles the packet, it must return NF_DROP or better NF_STOLEN,
532 otherwise this must be changed to a sk_buff **.
534 int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp,
535 struct ip_vs_protocol *pp);
537 /* Note: we can group the following members into a structure,
538 in order to save more space, and the following members are
539 only used in VS/NAT anyway */
540 struct ip_vs_app *app; /* bound ip_vs_app object */
541 void *app_data; /* Application private data */
542 struct ip_vs_seq in_seq; /* incoming seq. struct */
543 struct ip_vs_seq out_seq; /* outgoing seq. struct */
548 * The information about the virtual service offered to the net
549 * and the forwarding entries
551 struct ip_vs_service {
552 struct list_head s_list; /* for normal service table */
553 struct list_head f_list; /* for fwmark-based service table */
554 atomic_t refcnt; /* reference counter */
555 atomic_t usecnt; /* use counter */
557 __u16 protocol; /* which protocol (TCP/UDP) */
558 __u32 addr; /* IP address for virtual service */
559 __u16 port; /* port number for the service */
560 __u32 fwmark; /* firewall mark of the service */
561 unsigned flags; /* service status flags */
562 unsigned timeout; /* persistent timeout in ticks */
563 __u32 netmask; /* grouping granularity */
565 struct list_head destinations; /* real server d-linked list */
566 __u32 num_dests; /* number of servers */
567 struct ip_vs_stats stats; /* statistics for the service */
568 struct ip_vs_app *inc; /* bind conns to this app inc */
570 /* for scheduling */
571 struct ip_vs_scheduler *scheduler; /* bound scheduler object */
572 rwlock_t sched_lock; /* lock sched_data */
573 void *sched_data; /* scheduler application data */
578 * The real server destination forwarding entry
579 * with ip address, port number, and so on.
581 struct ip_vs_dest {
582 struct list_head n_list; /* for the dests in the service */
583 struct list_head d_list; /* for table with all the dests */
585 __u32 addr; /* IP address of the server */
586 __u16 port; /* port number of the server */
587 volatile unsigned flags; /* dest status flags */
588 atomic_t conn_flags; /* flags to copy to conn */
589 atomic_t weight; /* server weight */
591 atomic_t refcnt; /* reference counter */
592 struct ip_vs_stats stats; /* statistics */
594 /* connection counters and thresholds */
595 atomic_t activeconns; /* active connections */
596 atomic_t inactconns; /* inactive connections */
597 atomic_t persistconns; /* persistent connections */
598 __u32 u_threshold; /* upper threshold */
599 __u32 l_threshold; /* lower threshold */
601 /* for destination cache */
602 spinlock_t dst_lock; /* lock of dst_cache */
603 struct dst_entry *dst_cache; /* destination cache entry */
604 u32 dst_rtos; /* RT_TOS(tos) for dst */
606 /* for virtual service */
607 struct ip_vs_service *svc; /* service it belongs to */
608 __u16 protocol; /* which protocol (TCP/UDP) */
609 __u32 vaddr; /* virtual IP address */
610 __u16 vport; /* virtual port number */
611 __u32 vfwmark; /* firewall mark of service */
616 * The scheduler object
618 struct ip_vs_scheduler {
619 struct list_head n_list; /* d-linked list head */
620 char *name; /* scheduler name */
621 atomic_t refcnt; /* reference counter */
622 struct module *module; /* THIS_MODULE/NULL */
624 /* scheduler initializing service */
625 int (*init_service)(struct ip_vs_service *svc);
626 /* scheduling service finish */
627 int (*done_service)(struct ip_vs_service *svc);
628 /* scheduler updating service */
629 int (*update_service)(struct ip_vs_service *svc);
631 /* selecting a server from the given service */
632 struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc,
633 const struct sk_buff *skb);
638 * The application module object (a.k.a. app incarnation)
640 struct ip_vs_app
642 struct list_head a_list; /* member in app list */
643 int type; /* IP_VS_APP_TYPE_xxx */
644 char *name; /* application module name */
645 __u16 protocol;
646 struct module *module; /* THIS_MODULE/NULL */
647 struct list_head incs_list; /* list of incarnations */
649 /* members for application incarnations */
650 struct list_head p_list; /* member in proto app list */
651 struct ip_vs_app *app; /* its real application */
652 __u16 port; /* port number in net order */
653 atomic_t usecnt; /* usage counter */
655 /* output hook: return false if can't linearize. diff set for TCP. */
656 int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *,
657 struct sk_buff **, int *diff);
659 /* input hook: return false if can't linearize. diff set for TCP. */
660 int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *,
661 struct sk_buff **, int *diff);
663 /* ip_vs_app initializer */
664 int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *);
666 /* ip_vs_app finish */
667 int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *);
670 /* not used now */
671 int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *,
672 struct ip_vs_protocol *);
674 void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *);
676 int * timeout_table;
677 int * timeouts;
678 int timeouts_size;
680 int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app,
681 int *verdict, struct ip_vs_conn **cpp);
683 struct ip_vs_conn *
684 (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app,
685 const struct iphdr *iph, unsigned int proto_off,
686 int inverse);
688 struct ip_vs_conn *
689 (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app,
690 const struct iphdr *iph, unsigned int proto_off,
691 int inverse);
693 int (*state_transition)(struct ip_vs_conn *cp, int direction,
694 const struct sk_buff *skb,
695 struct ip_vs_app *app);
697 void (*timeout_change)(struct ip_vs_app *app, int flags);
702 * IPVS core functions
703 * (from ip_vs_core.c)
705 extern const char *ip_vs_proto_name(unsigned proto);
706 extern void ip_vs_init_hash_table(struct list_head *table, int rows);
707 #define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table(t, sizeof(t)/sizeof(t[0]))
709 #define IP_VS_APP_TYPE_UNSPEC 0
710 #define IP_VS_APP_TYPE_FTP 1
713 * ip_vs_conn handling functions
714 * (from ip_vs_conn.c)
718 * IPVS connection entry hash table
720 #ifndef CONFIG_IP_VS_TAB_BITS
721 #define CONFIG_IP_VS_TAB_BITS 12
722 #endif
723 /* make sure that IP_VS_CONN_TAB_BITS is located in [8, 20] */
724 #if CONFIG_IP_VS_TAB_BITS < 8
725 #define IP_VS_CONN_TAB_BITS 8
726 #endif
727 #if CONFIG_IP_VS_TAB_BITS > 20
728 #define IP_VS_CONN_TAB_BITS 20
729 #endif
730 #if 8 <= CONFIG_IP_VS_TAB_BITS && CONFIG_IP_VS_TAB_BITS <= 20
731 #define IP_VS_CONN_TAB_BITS CONFIG_IP_VS_TAB_BITS
732 #endif
733 #define IP_VS_CONN_TAB_SIZE (1 << IP_VS_CONN_TAB_BITS)
734 #define IP_VS_CONN_TAB_MASK (IP_VS_CONN_TAB_SIZE - 1)
736 enum {
737 IP_VS_DIR_INPUT = 0,
738 IP_VS_DIR_OUTPUT,
739 IP_VS_DIR_INPUT_ONLY,
740 IP_VS_DIR_LAST,
743 extern struct ip_vs_conn *ip_vs_conn_in_get
744 (int protocol, __u32 s_addr, __u16 s_port, __u32 d_addr, __u16 d_port);
745 extern struct ip_vs_conn *ip_vs_ct_in_get
746 (int protocol, __u32 s_addr, __u16 s_port, __u32 d_addr, __u16 d_port);
747 extern struct ip_vs_conn *ip_vs_conn_out_get
748 (int protocol, __u32 s_addr, __u16 s_port, __u32 d_addr, __u16 d_port);
750 /* put back the conn without restarting its timer */
751 static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
753 atomic_dec(&cp->refcnt);
755 extern void ip_vs_conn_put(struct ip_vs_conn *cp);
756 extern void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __u16 cport);
758 extern struct ip_vs_conn *
759 ip_vs_conn_new(int proto, __u32 caddr, __u16 cport, __u32 vaddr, __u16 vport,
760 __u32 daddr, __u16 dport, unsigned flags,
761 struct ip_vs_dest *dest);
762 extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
764 extern const char * ip_vs_state_name(__u16 proto, int state);
766 extern void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp);
767 extern int ip_vs_check_template(struct ip_vs_conn *ct);
768 extern void ip_vs_secure_tcp_set(int on);
769 extern void ip_vs_random_dropentry(void);
770 extern int ip_vs_conn_init(void);
771 extern void ip_vs_conn_cleanup(void);
773 static inline void ip_vs_control_del(struct ip_vs_conn *cp)
775 struct ip_vs_conn *ctl_cp = cp->control;
776 if (!ctl_cp) {
777 IP_VS_ERR("request control DEL for uncontrolled: "
778 "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
779 NIPQUAD(cp->caddr),ntohs(cp->cport),
780 NIPQUAD(cp->vaddr),ntohs(cp->vport));
781 return;
784 IP_VS_DBG(7, "DELeting control for: "
785 "cp.dst=%d.%d.%d.%d:%d ctl_cp.dst=%d.%d.%d.%d:%d\n",
786 NIPQUAD(cp->caddr),ntohs(cp->cport),
787 NIPQUAD(ctl_cp->caddr),ntohs(ctl_cp->cport));
789 cp->control = NULL;
790 if (atomic_read(&ctl_cp->n_control) == 0) {
791 IP_VS_ERR("BUG control DEL with n=0 : "
792 "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
793 NIPQUAD(cp->caddr),ntohs(cp->cport),
794 NIPQUAD(cp->vaddr),ntohs(cp->vport));
795 return;
797 atomic_dec(&ctl_cp->n_control);
800 static inline void
801 ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)
803 if (cp->control) {
804 IP_VS_ERR("request control ADD for already controlled: "
805 "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
806 NIPQUAD(cp->caddr),ntohs(cp->cport),
807 NIPQUAD(cp->vaddr),ntohs(cp->vport));
808 ip_vs_control_del(cp);
811 IP_VS_DBG(7, "ADDing control for: "
812 "cp.dst=%d.%d.%d.%d:%d ctl_cp.dst=%d.%d.%d.%d:%d\n",
813 NIPQUAD(cp->caddr),ntohs(cp->cport),
814 NIPQUAD(ctl_cp->caddr),ntohs(ctl_cp->cport));
816 cp->control = ctl_cp;
817 atomic_inc(&ctl_cp->n_control);
822 * IPVS application functions
823 * (from ip_vs_app.c)
825 #define IP_VS_APP_MAX_PORTS 8
826 extern int register_ip_vs_app(struct ip_vs_app *app);
827 extern void unregister_ip_vs_app(struct ip_vs_app *app);
828 extern int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
829 extern void ip_vs_unbind_app(struct ip_vs_conn *cp);
830 extern int
831 register_ip_vs_app_inc(struct ip_vs_app *app, __u16 proto, __u16 port);
832 extern int ip_vs_app_inc_get(struct ip_vs_app *inc);
833 extern void ip_vs_app_inc_put(struct ip_vs_app *inc);
835 extern int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff **pskb);
836 extern int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff **pskb);
837 extern int ip_vs_skb_replace(struct sk_buff *skb, gfp_t pri,
838 char *o_buf, int o_len, char *n_buf, int n_len);
839 extern int ip_vs_app_init(void);
840 extern void ip_vs_app_cleanup(void);
844 * IPVS protocol functions (from ip_vs_proto.c)
846 extern int ip_vs_protocol_init(void);
847 extern void ip_vs_protocol_cleanup(void);
848 extern void ip_vs_protocol_timeout_change(int flags);
849 extern int *ip_vs_create_timeout_table(int *table, int size);
850 extern int
851 ip_vs_set_state_timeout(int *table, int num, char **names, char *name, int to);
852 extern void
853 ip_vs_tcpudp_debug_packet(struct ip_vs_protocol *pp, const struct sk_buff *skb,
854 int offset, const char *msg);
856 extern struct ip_vs_protocol ip_vs_protocol_tcp;
857 extern struct ip_vs_protocol ip_vs_protocol_udp;
858 extern struct ip_vs_protocol ip_vs_protocol_icmp;
859 extern struct ip_vs_protocol ip_vs_protocol_esp;
860 extern struct ip_vs_protocol ip_vs_protocol_ah;
864 * Registering/unregistering scheduler functions
865 * (from ip_vs_sched.c)
867 extern int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
868 extern int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
869 extern int ip_vs_bind_scheduler(struct ip_vs_service *svc,
870 struct ip_vs_scheduler *scheduler);
871 extern int ip_vs_unbind_scheduler(struct ip_vs_service *svc);
872 extern struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name);
873 extern void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler);
874 extern struct ip_vs_conn *
875 ip_vs_schedule(struct ip_vs_service *svc, const struct sk_buff *skb);
876 extern int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
877 struct ip_vs_protocol *pp);
881 * IPVS control data and functions (from ip_vs_ctl.c)
883 extern int sysctl_ip_vs_cache_bypass;
884 extern int sysctl_ip_vs_expire_nodest_conn;
885 extern int sysctl_ip_vs_expire_quiescent_template;
886 extern int sysctl_ip_vs_sync_threshold[2];
887 extern int sysctl_ip_vs_nat_icmp_send;
888 extern struct ip_vs_stats ip_vs_stats;
890 extern struct ip_vs_service *
891 ip_vs_service_get(__u32 fwmark, __u16 protocol, __u32 vaddr, __u16 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(__u16 protocol, __u32 daddr, __u16 dport);
900 extern int ip_vs_use_count_inc(void);
901 extern void ip_vs_use_count_dec(void);
902 extern int ip_vs_control_init(void);
903 extern void ip_vs_control_cleanup(void);
907 * IPVS sync daemon data and function prototypes
908 * (from ip_vs_sync.c)
910 extern volatile int ip_vs_sync_state;
911 extern volatile int ip_vs_master_syncid;
912 extern volatile int ip_vs_backup_syncid;
913 extern char ip_vs_master_mcast_ifn[IP_VS_IFNAME_MAXLEN];
914 extern char ip_vs_backup_mcast_ifn[IP_VS_IFNAME_MAXLEN];
915 extern int start_sync_thread(int state, char *mcast_ifn, __u8 syncid);
916 extern int stop_sync_thread(int state);
917 extern void ip_vs_sync_conn(struct ip_vs_conn *cp);
921 * IPVS rate estimator prototypes (from ip_vs_est.c)
923 extern int ip_vs_new_estimator(struct ip_vs_stats *stats);
924 extern void ip_vs_kill_estimator(struct ip_vs_stats *stats);
925 extern void ip_vs_zero_estimator(struct ip_vs_stats *stats);
928 * Various IPVS packet transmitters (from ip_vs_xmit.c)
930 extern int ip_vs_null_xmit
931 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
932 extern int ip_vs_bypass_xmit
933 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
934 extern int ip_vs_nat_xmit
935 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
936 extern int ip_vs_tunnel_xmit
937 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
938 extern int ip_vs_dr_xmit
939 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
940 extern int ip_vs_icmp_xmit
941 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, int offset);
942 extern void ip_vs_dst_reset(struct ip_vs_dest *dest);
946 * This is a simple mechanism to ignore packets when
947 * we are loaded. Just set ip_vs_drop_rate to 'n' and
948 * we start to drop 1/rate of the packets
950 extern int ip_vs_drop_rate;
951 extern int ip_vs_drop_counter;
953 static __inline__ int ip_vs_todrop(void)
955 if (!ip_vs_drop_rate) return 0;
956 if (--ip_vs_drop_counter > 0) return 0;
957 ip_vs_drop_counter = ip_vs_drop_rate;
958 return 1;
962 * ip_vs_fwd_tag returns the forwarding tag of the connection
964 #define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK)
966 static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp)
968 char fwd;
970 switch (IP_VS_FWD_METHOD(cp)) {
971 case IP_VS_CONN_F_MASQ:
972 fwd = 'M'; break;
973 case IP_VS_CONN_F_LOCALNODE:
974 fwd = 'L'; break;
975 case IP_VS_CONN_F_TUNNEL:
976 fwd = 'T'; break;
977 case IP_VS_CONN_F_DROUTE:
978 fwd = 'R'; break;
979 case IP_VS_CONN_F_BYPASS:
980 fwd = 'B'; break;
981 default:
982 fwd = '?'; break;
984 return fwd;
987 extern int ip_vs_make_skb_writable(struct sk_buff **pskb, int len);
988 extern void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,
989 struct ip_vs_conn *cp, int dir);
991 extern u16 ip_vs_checksum_complete(struct sk_buff *skb, int offset);
993 static inline u16 ip_vs_check_diff(u32 old, u32 new, u16 oldsum)
995 u32 diff[2] = { old, new };
997 return csum_fold(csum_partial((char *) diff, sizeof(diff),
998 oldsum ^ 0xFFFF));
1001 #endif /* __KERNEL__ */
1003 #endif /* _IP_VS_H */