device create: isdn: convert device_create to device_create_drvdata
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / net / ip_vs.h
blob9a51ebad3f1fc21e054cedd03b344d8a851c28bd
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 */
10 #include <linux/types.h> /* For __beXX types in userland */
12 #include <linux/sysctl.h> /* For ctl_path */
14 #define IP_VS_VERSION_CODE 0x010201
15 #define NVERSION(version) \
16 (version >> 16) & 0xFF, \
17 (version >> 8) & 0xFF, \
18 version & 0xFF
21 * Virtual Service Flags
23 #define IP_VS_SVC_F_PERSISTENT 0x0001 /* persistent port */
24 #define IP_VS_SVC_F_HASHED 0x0002 /* hashed entry */
27 * Destination Server Flags
29 #define IP_VS_DEST_F_AVAILABLE 0x0001 /* server is available */
30 #define IP_VS_DEST_F_OVERLOAD 0x0002 /* server is overloaded */
33 * IPVS sync daemon states
35 #define IP_VS_STATE_NONE 0x0000 /* daemon is stopped */
36 #define IP_VS_STATE_MASTER 0x0001 /* started as master */
37 #define IP_VS_STATE_BACKUP 0x0002 /* started as backup */
40 * IPVS socket options
42 #define IP_VS_BASE_CTL (64+1024+64) /* base */
44 #define IP_VS_SO_SET_NONE IP_VS_BASE_CTL /* just peek */
45 #define IP_VS_SO_SET_INSERT (IP_VS_BASE_CTL+1)
46 #define IP_VS_SO_SET_ADD (IP_VS_BASE_CTL+2)
47 #define IP_VS_SO_SET_EDIT (IP_VS_BASE_CTL+3)
48 #define IP_VS_SO_SET_DEL (IP_VS_BASE_CTL+4)
49 #define IP_VS_SO_SET_FLUSH (IP_VS_BASE_CTL+5)
50 #define IP_VS_SO_SET_LIST (IP_VS_BASE_CTL+6)
51 #define IP_VS_SO_SET_ADDDEST (IP_VS_BASE_CTL+7)
52 #define IP_VS_SO_SET_DELDEST (IP_VS_BASE_CTL+8)
53 #define IP_VS_SO_SET_EDITDEST (IP_VS_BASE_CTL+9)
54 #define IP_VS_SO_SET_TIMEOUT (IP_VS_BASE_CTL+10)
55 #define IP_VS_SO_SET_STARTDAEMON (IP_VS_BASE_CTL+11)
56 #define IP_VS_SO_SET_STOPDAEMON (IP_VS_BASE_CTL+12)
57 #define IP_VS_SO_SET_RESTORE (IP_VS_BASE_CTL+13)
58 #define IP_VS_SO_SET_SAVE (IP_VS_BASE_CTL+14)
59 #define IP_VS_SO_SET_ZERO (IP_VS_BASE_CTL+15)
60 #define IP_VS_SO_SET_MAX IP_VS_SO_SET_ZERO
62 #define IP_VS_SO_GET_VERSION IP_VS_BASE_CTL
63 #define IP_VS_SO_GET_INFO (IP_VS_BASE_CTL+1)
64 #define IP_VS_SO_GET_SERVICES (IP_VS_BASE_CTL+2)
65 #define IP_VS_SO_GET_SERVICE (IP_VS_BASE_CTL+3)
66 #define IP_VS_SO_GET_DESTS (IP_VS_BASE_CTL+4)
67 #define IP_VS_SO_GET_DEST (IP_VS_BASE_CTL+5) /* not used now */
68 #define IP_VS_SO_GET_TIMEOUT (IP_VS_BASE_CTL+6)
69 #define IP_VS_SO_GET_DAEMON (IP_VS_BASE_CTL+7)
70 #define IP_VS_SO_GET_MAX IP_VS_SO_GET_DAEMON
74 * IPVS Connection Flags
76 #define IP_VS_CONN_F_FWD_MASK 0x0007 /* mask for the fwd methods */
77 #define IP_VS_CONN_F_MASQ 0x0000 /* masquerading/NAT */
78 #define IP_VS_CONN_F_LOCALNODE 0x0001 /* local node */
79 #define IP_VS_CONN_F_TUNNEL 0x0002 /* tunneling */
80 #define IP_VS_CONN_F_DROUTE 0x0003 /* direct routing */
81 #define IP_VS_CONN_F_BYPASS 0x0004 /* cache bypass */
82 #define IP_VS_CONN_F_SYNC 0x0020 /* entry created by sync */
83 #define IP_VS_CONN_F_HASHED 0x0040 /* hashed entry */
84 #define IP_VS_CONN_F_NOOUTPUT 0x0080 /* no output packets */
85 #define IP_VS_CONN_F_INACTIVE 0x0100 /* not established */
86 #define IP_VS_CONN_F_OUT_SEQ 0x0200 /* must do output seq adjust */
87 #define IP_VS_CONN_F_IN_SEQ 0x0400 /* must do input seq adjust */
88 #define IP_VS_CONN_F_SEQ_MASK 0x0600 /* in/out sequence mask */
89 #define IP_VS_CONN_F_NO_CPORT 0x0800 /* no client port set yet */
90 #define IP_VS_CONN_F_TEMPLATE 0x1000 /* template, not connection */
92 /* Move it to better place one day, for now keep it unique */
93 #define NFC_IPVS_PROPERTY 0x10000
95 #define IP_VS_SCHEDNAME_MAXLEN 16
96 #define IP_VS_IFNAME_MAXLEN 16
100 * The struct ip_vs_service_user and struct ip_vs_dest_user are
101 * used to set IPVS rules through setsockopt.
103 struct ip_vs_service_user {
104 /* virtual service addresses */
105 u_int16_t protocol;
106 __be32 addr; /* virtual ip address */
107 __be16 port;
108 u_int32_t fwmark; /* firwall mark of service */
110 /* virtual service options */
111 char sched_name[IP_VS_SCHEDNAME_MAXLEN];
112 unsigned flags; /* virtual service flags */
113 unsigned timeout; /* persistent timeout in sec */
114 __be32 netmask; /* persistent netmask */
118 struct ip_vs_dest_user {
119 /* destination server address */
120 __be32 addr;
121 __be16 port;
123 /* real server options */
124 unsigned conn_flags; /* connection flags */
125 int weight; /* destination weight */
127 /* thresholds for active connections */
128 u_int32_t u_threshold; /* upper threshold */
129 u_int32_t l_threshold; /* lower threshold */
134 * IPVS statistics object (for user space)
136 struct ip_vs_stats_user
138 __u32 conns; /* connections scheduled */
139 __u32 inpkts; /* incoming packets */
140 __u32 outpkts; /* outgoing packets */
141 __u64 inbytes; /* incoming bytes */
142 __u64 outbytes; /* outgoing bytes */
144 __u32 cps; /* current connection rate */
145 __u32 inpps; /* current in packet rate */
146 __u32 outpps; /* current out packet rate */
147 __u32 inbps; /* current in byte rate */
148 __u32 outbps; /* current out byte rate */
152 /* The argument to IP_VS_SO_GET_INFO */
153 struct ip_vs_getinfo {
154 /* version number */
155 unsigned int version;
157 /* size of connection hash table */
158 unsigned int size;
160 /* number of virtual services */
161 unsigned int num_services;
165 /* The argument to IP_VS_SO_GET_SERVICE */
166 struct ip_vs_service_entry {
167 /* which service: user fills in these */
168 u_int16_t protocol;
169 __be32 addr; /* virtual address */
170 __be16 port;
171 u_int32_t fwmark; /* firwall mark of service */
173 /* service options */
174 char sched_name[IP_VS_SCHEDNAME_MAXLEN];
175 unsigned flags; /* virtual service flags */
176 unsigned timeout; /* persistent timeout */
177 __be32 netmask; /* persistent netmask */
179 /* number of real servers */
180 unsigned int num_dests;
182 /* statistics */
183 struct ip_vs_stats_user stats;
187 struct ip_vs_dest_entry {
188 __be32 addr; /* destination address */
189 __be16 port;
190 unsigned conn_flags; /* connection flags */
191 int weight; /* destination weight */
193 u_int32_t u_threshold; /* upper threshold */
194 u_int32_t l_threshold; /* lower threshold */
196 u_int32_t activeconns; /* active connections */
197 u_int32_t inactconns; /* inactive connections */
198 u_int32_t persistconns; /* persistent connections */
200 /* statistics */
201 struct ip_vs_stats_user stats;
205 /* The argument to IP_VS_SO_GET_DESTS */
206 struct ip_vs_get_dests {
207 /* which service: user fills in these */
208 u_int16_t protocol;
209 __be32 addr; /* virtual address */
210 __be16 port;
211 u_int32_t fwmark; /* firwall mark of service */
213 /* number of real servers */
214 unsigned int num_dests;
216 /* the real servers */
217 struct ip_vs_dest_entry entrytable[0];
221 /* The argument to IP_VS_SO_GET_SERVICES */
222 struct ip_vs_get_services {
223 /* number of virtual services */
224 unsigned int num_services;
226 /* service table */
227 struct ip_vs_service_entry entrytable[0];
231 /* The argument to IP_VS_SO_GET_TIMEOUT */
232 struct ip_vs_timeout_user {
233 int tcp_timeout;
234 int tcp_fin_timeout;
235 int udp_timeout;
239 /* The argument to IP_VS_SO_GET_DAEMON */
240 struct ip_vs_daemon_user {
241 /* sync daemon state (master/backup) */
242 int state;
244 /* multicast interface name */
245 char mcast_ifn[IP_VS_IFNAME_MAXLEN];
247 /* SyncID we belong to */
248 int syncid;
252 #ifdef __KERNEL__
254 #include <linux/list.h> /* for struct list_head */
255 #include <linux/spinlock.h> /* for struct rwlock_t */
256 #include <asm/atomic.h> /* for struct atomic_t */
257 #include <linux/compiler.h>
258 #include <linux/timer.h>
260 #include <net/checksum.h>
262 #ifdef CONFIG_IP_VS_DEBUG
263 #include <linux/net.h>
265 extern int ip_vs_get_debug_level(void);
266 #define IP_VS_DBG(level, msg...) \
267 do { \
268 if (level <= ip_vs_get_debug_level()) \
269 printk(KERN_DEBUG "IPVS: " msg); \
270 } while (0)
271 #define IP_VS_DBG_RL(msg...) \
272 do { \
273 if (net_ratelimit()) \
274 printk(KERN_DEBUG "IPVS: " msg); \
275 } while (0)
276 #define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) \
277 do { \
278 if (level <= ip_vs_get_debug_level()) \
279 pp->debug_packet(pp, skb, ofs, msg); \
280 } while (0)
281 #define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) \
282 do { \
283 if (level <= ip_vs_get_debug_level() && \
284 net_ratelimit()) \
285 pp->debug_packet(pp, skb, ofs, msg); \
286 } while (0)
287 #else /* NO DEBUGGING at ALL */
288 #define IP_VS_DBG(level, msg...) do {} while (0)
289 #define IP_VS_DBG_RL(msg...) do {} while (0)
290 #define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) do {} while (0)
291 #define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) do {} while (0)
292 #endif
294 #define IP_VS_BUG() BUG()
295 #define IP_VS_ERR(msg...) printk(KERN_ERR "IPVS: " msg)
296 #define IP_VS_INFO(msg...) printk(KERN_INFO "IPVS: " msg)
297 #define IP_VS_WARNING(msg...) \
298 printk(KERN_WARNING "IPVS: " msg)
299 #define IP_VS_ERR_RL(msg...) \
300 do { \
301 if (net_ratelimit()) \
302 printk(KERN_ERR "IPVS: " msg); \
303 } while (0)
305 #ifdef CONFIG_IP_VS_DEBUG
306 #define EnterFunction(level) \
307 do { \
308 if (level <= ip_vs_get_debug_level()) \
309 printk(KERN_DEBUG "Enter: %s, %s line %i\n", \
310 __FUNCTION__, __FILE__, __LINE__); \
311 } while (0)
312 #define LeaveFunction(level) \
313 do { \
314 if (level <= ip_vs_get_debug_level()) \
315 printk(KERN_DEBUG "Leave: %s, %s line %i\n", \
316 __FUNCTION__, __FILE__, __LINE__); \
317 } while (0)
318 #else
319 #define EnterFunction(level) do {} while (0)
320 #define LeaveFunction(level) do {} while (0)
321 #endif
323 #define IP_VS_WAIT_WHILE(expr) while (expr) { cpu_relax(); }
327 * The port number of FTP service (in network order).
329 #define FTPPORT __constant_htons(21)
330 #define FTPDATA __constant_htons(20)
333 * TCP State Values
335 enum {
336 IP_VS_TCP_S_NONE = 0,
337 IP_VS_TCP_S_ESTABLISHED,
338 IP_VS_TCP_S_SYN_SENT,
339 IP_VS_TCP_S_SYN_RECV,
340 IP_VS_TCP_S_FIN_WAIT,
341 IP_VS_TCP_S_TIME_WAIT,
342 IP_VS_TCP_S_CLOSE,
343 IP_VS_TCP_S_CLOSE_WAIT,
344 IP_VS_TCP_S_LAST_ACK,
345 IP_VS_TCP_S_LISTEN,
346 IP_VS_TCP_S_SYNACK,
347 IP_VS_TCP_S_LAST
351 * UDP State Values
353 enum {
354 IP_VS_UDP_S_NORMAL,
355 IP_VS_UDP_S_LAST,
359 * ICMP State Values
361 enum {
362 IP_VS_ICMP_S_NORMAL,
363 IP_VS_ICMP_S_LAST,
367 * Delta sequence info structure
368 * Each ip_vs_conn has 2 (output AND input seq. changes).
369 * Only used in the VS/NAT.
371 struct ip_vs_seq {
372 __u32 init_seq; /* Add delta from this seq */
373 __u32 delta; /* Delta in sequence numbers */
374 __u32 previous_delta; /* Delta in sequence numbers
375 before last resized pkt */
380 * IPVS statistics object
382 struct ip_vs_stats
384 __u32 conns; /* connections scheduled */
385 __u32 inpkts; /* incoming packets */
386 __u32 outpkts; /* outgoing packets */
387 __u64 inbytes; /* incoming bytes */
388 __u64 outbytes; /* outgoing bytes */
390 __u32 cps; /* current connection rate */
391 __u32 inpps; /* current in packet rate */
392 __u32 outpps; /* current out packet rate */
393 __u32 inbps; /* current in byte rate */
394 __u32 outbps; /* current out byte rate */
396 spinlock_t lock; /* spin lock */
399 struct dst_entry;
400 struct iphdr;
401 struct ip_vs_conn;
402 struct ip_vs_app;
403 struct sk_buff;
405 struct ip_vs_protocol {
406 struct ip_vs_protocol *next;
407 char *name;
408 u16 protocol;
409 u16 num_states;
410 int dont_defrag;
411 atomic_t appcnt; /* counter of proto app incs */
412 int *timeout_table; /* protocol timeout table */
414 void (*init)(struct ip_vs_protocol *pp);
416 void (*exit)(struct ip_vs_protocol *pp);
418 int (*conn_schedule)(struct sk_buff *skb,
419 struct ip_vs_protocol *pp,
420 int *verdict, struct ip_vs_conn **cpp);
422 struct ip_vs_conn *
423 (*conn_in_get)(const struct sk_buff *skb,
424 struct ip_vs_protocol *pp,
425 const struct iphdr *iph,
426 unsigned int proto_off,
427 int inverse);
429 struct ip_vs_conn *
430 (*conn_out_get)(const struct sk_buff *skb,
431 struct ip_vs_protocol *pp,
432 const struct iphdr *iph,
433 unsigned int proto_off,
434 int inverse);
436 int (*snat_handler)(struct sk_buff *skb,
437 struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
439 int (*dnat_handler)(struct sk_buff *skb,
440 struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
442 int (*csum_check)(struct sk_buff *skb, struct ip_vs_protocol *pp);
444 const char *(*state_name)(int state);
446 int (*state_transition)(struct ip_vs_conn *cp, int direction,
447 const struct sk_buff *skb,
448 struct ip_vs_protocol *pp);
450 int (*register_app)(struct ip_vs_app *inc);
452 void (*unregister_app)(struct ip_vs_app *inc);
454 int (*app_conn_bind)(struct ip_vs_conn *cp);
456 void (*debug_packet)(struct ip_vs_protocol *pp,
457 const struct sk_buff *skb,
458 int offset,
459 const char *msg);
461 void (*timeout_change)(struct ip_vs_protocol *pp, int flags);
463 int (*set_state_timeout)(struct ip_vs_protocol *pp, char *sname, int to);
466 extern struct ip_vs_protocol * ip_vs_proto_get(unsigned short proto);
469 * IP_VS structure allocated for each dynamically scheduled connection
471 struct ip_vs_conn {
472 struct list_head c_list; /* hashed list heads */
474 /* Protocol, addresses and port numbers */
475 __be32 caddr; /* client address */
476 __be32 vaddr; /* virtual address */
477 __be32 daddr; /* destination address */
478 __be16 cport;
479 __be16 vport;
480 __be16 dport;
481 __u16 protocol; /* Which protocol (TCP/UDP) */
483 /* counter and timer */
484 atomic_t refcnt; /* reference count */
485 struct timer_list timer; /* Expiration timer */
486 volatile unsigned long timeout; /* timeout */
488 /* Flags and state transition */
489 spinlock_t lock; /* lock for state transition */
490 volatile __u16 flags; /* status flags */
491 volatile __u16 state; /* state info */
492 volatile __u16 old_state; /* old state, to be used for
493 * state transition triggerd
494 * synchronization
497 /* Control members */
498 struct ip_vs_conn *control; /* Master control connection */
499 atomic_t n_control; /* Number of controlled ones */
500 struct ip_vs_dest *dest; /* real server */
501 atomic_t in_pkts; /* incoming packet counter */
503 /* packet transmitter for different forwarding methods. If it
504 mangles the packet, it must return NF_DROP or better NF_STOLEN,
505 otherwise this must be changed to a sk_buff **.
507 int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp,
508 struct ip_vs_protocol *pp);
510 /* Note: we can group the following members into a structure,
511 in order to save more space, and the following members are
512 only used in VS/NAT anyway */
513 struct ip_vs_app *app; /* bound ip_vs_app object */
514 void *app_data; /* Application private data */
515 struct ip_vs_seq in_seq; /* incoming seq. struct */
516 struct ip_vs_seq out_seq; /* outgoing seq. struct */
521 * The information about the virtual service offered to the net
522 * and the forwarding entries
524 struct ip_vs_service {
525 struct list_head s_list; /* for normal service table */
526 struct list_head f_list; /* for fwmark-based service table */
527 atomic_t refcnt; /* reference counter */
528 atomic_t usecnt; /* use counter */
530 __u16 protocol; /* which protocol (TCP/UDP) */
531 __be32 addr; /* IP address for virtual service */
532 __be16 port; /* port number for the service */
533 __u32 fwmark; /* firewall mark of the service */
534 unsigned flags; /* service status flags */
535 unsigned timeout; /* persistent timeout in ticks */
536 __be32 netmask; /* grouping granularity */
538 struct list_head destinations; /* real server d-linked list */
539 __u32 num_dests; /* number of servers */
540 struct ip_vs_stats stats; /* statistics for the service */
541 struct ip_vs_app *inc; /* bind conns to this app inc */
543 /* for scheduling */
544 struct ip_vs_scheduler *scheduler; /* bound scheduler object */
545 rwlock_t sched_lock; /* lock sched_data */
546 void *sched_data; /* scheduler application data */
551 * The real server destination forwarding entry
552 * with ip address, port number, and so on.
554 struct ip_vs_dest {
555 struct list_head n_list; /* for the dests in the service */
556 struct list_head d_list; /* for table with all the dests */
558 __be32 addr; /* IP address of the server */
559 __be16 port; /* port number of the server */
560 volatile unsigned flags; /* dest status flags */
561 atomic_t conn_flags; /* flags to copy to conn */
562 atomic_t weight; /* server weight */
564 atomic_t refcnt; /* reference counter */
565 struct ip_vs_stats stats; /* statistics */
567 /* connection counters and thresholds */
568 atomic_t activeconns; /* active connections */
569 atomic_t inactconns; /* inactive connections */
570 atomic_t persistconns; /* persistent connections */
571 __u32 u_threshold; /* upper threshold */
572 __u32 l_threshold; /* lower threshold */
574 /* for destination cache */
575 spinlock_t dst_lock; /* lock of dst_cache */
576 struct dst_entry *dst_cache; /* destination cache entry */
577 u32 dst_rtos; /* RT_TOS(tos) for dst */
579 /* for virtual service */
580 struct ip_vs_service *svc; /* service it belongs to */
581 __u16 protocol; /* which protocol (TCP/UDP) */
582 __be32 vaddr; /* virtual IP address */
583 __be16 vport; /* virtual port number */
584 __u32 vfwmark; /* firewall mark of service */
589 * The scheduler object
591 struct ip_vs_scheduler {
592 struct list_head n_list; /* d-linked list head */
593 char *name; /* scheduler name */
594 atomic_t refcnt; /* reference counter */
595 struct module *module; /* THIS_MODULE/NULL */
597 /* scheduler initializing service */
598 int (*init_service)(struct ip_vs_service *svc);
599 /* scheduling service finish */
600 int (*done_service)(struct ip_vs_service *svc);
601 /* scheduler updating service */
602 int (*update_service)(struct ip_vs_service *svc);
604 /* selecting a server from the given service */
605 struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc,
606 const struct sk_buff *skb);
611 * The application module object (a.k.a. app incarnation)
613 struct ip_vs_app
615 struct list_head a_list; /* member in app list */
616 int type; /* IP_VS_APP_TYPE_xxx */
617 char *name; /* application module name */
618 __u16 protocol;
619 struct module *module; /* THIS_MODULE/NULL */
620 struct list_head incs_list; /* list of incarnations */
622 /* members for application incarnations */
623 struct list_head p_list; /* member in proto app list */
624 struct ip_vs_app *app; /* its real application */
625 __be16 port; /* port number in net order */
626 atomic_t usecnt; /* usage counter */
628 /* output hook: return false if can't linearize. diff set for TCP. */
629 int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *,
630 struct sk_buff *, int *diff);
632 /* input hook: return false if can't linearize. diff set for TCP. */
633 int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *,
634 struct sk_buff *, int *diff);
636 /* ip_vs_app initializer */
637 int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *);
639 /* ip_vs_app finish */
640 int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *);
643 /* not used now */
644 int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *,
645 struct ip_vs_protocol *);
647 void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *);
649 int * timeout_table;
650 int * timeouts;
651 int timeouts_size;
653 int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app,
654 int *verdict, struct ip_vs_conn **cpp);
656 struct ip_vs_conn *
657 (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app,
658 const struct iphdr *iph, unsigned int proto_off,
659 int inverse);
661 struct ip_vs_conn *
662 (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app,
663 const struct iphdr *iph, unsigned int proto_off,
664 int inverse);
666 int (*state_transition)(struct ip_vs_conn *cp, int direction,
667 const struct sk_buff *skb,
668 struct ip_vs_app *app);
670 void (*timeout_change)(struct ip_vs_app *app, int flags);
675 * IPVS core functions
676 * (from ip_vs_core.c)
678 extern const char *ip_vs_proto_name(unsigned proto);
679 extern void ip_vs_init_hash_table(struct list_head *table, int rows);
680 #define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table(t, sizeof(t)/sizeof(t[0]))
682 #define IP_VS_APP_TYPE_FTP 1
685 * ip_vs_conn handling functions
686 * (from ip_vs_conn.c)
690 * IPVS connection entry hash table
692 #ifndef CONFIG_IP_VS_TAB_BITS
693 #define CONFIG_IP_VS_TAB_BITS 12
694 #endif
695 /* make sure that IP_VS_CONN_TAB_BITS is located in [8, 20] */
696 #if CONFIG_IP_VS_TAB_BITS < 8
697 #define IP_VS_CONN_TAB_BITS 8
698 #endif
699 #if CONFIG_IP_VS_TAB_BITS > 20
700 #define IP_VS_CONN_TAB_BITS 20
701 #endif
702 #if 8 <= CONFIG_IP_VS_TAB_BITS && CONFIG_IP_VS_TAB_BITS <= 20
703 #define IP_VS_CONN_TAB_BITS CONFIG_IP_VS_TAB_BITS
704 #endif
705 #define IP_VS_CONN_TAB_SIZE (1 << IP_VS_CONN_TAB_BITS)
706 #define IP_VS_CONN_TAB_MASK (IP_VS_CONN_TAB_SIZE - 1)
708 enum {
709 IP_VS_DIR_INPUT = 0,
710 IP_VS_DIR_OUTPUT,
711 IP_VS_DIR_INPUT_ONLY,
712 IP_VS_DIR_LAST,
715 extern struct ip_vs_conn *ip_vs_conn_in_get
716 (int protocol, __be32 s_addr, __be16 s_port, __be32 d_addr, __be16 d_port);
717 extern struct ip_vs_conn *ip_vs_ct_in_get
718 (int protocol, __be32 s_addr, __be16 s_port, __be32 d_addr, __be16 d_port);
719 extern struct ip_vs_conn *ip_vs_conn_out_get
720 (int protocol, __be32 s_addr, __be16 s_port, __be32 d_addr, __be16 d_port);
722 /* put back the conn without restarting its timer */
723 static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
725 atomic_dec(&cp->refcnt);
727 extern void ip_vs_conn_put(struct ip_vs_conn *cp);
728 extern void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport);
730 extern struct ip_vs_conn *
731 ip_vs_conn_new(int proto, __be32 caddr, __be16 cport, __be32 vaddr, __be16 vport,
732 __be32 daddr, __be16 dport, unsigned flags,
733 struct ip_vs_dest *dest);
734 extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
736 extern const char * ip_vs_state_name(__u16 proto, int state);
738 extern void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp);
739 extern int ip_vs_check_template(struct ip_vs_conn *ct);
740 extern void ip_vs_random_dropentry(void);
741 extern int ip_vs_conn_init(void);
742 extern void ip_vs_conn_cleanup(void);
744 static inline void ip_vs_control_del(struct ip_vs_conn *cp)
746 struct ip_vs_conn *ctl_cp = cp->control;
747 if (!ctl_cp) {
748 IP_VS_ERR("request control DEL for uncontrolled: "
749 "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
750 NIPQUAD(cp->caddr),ntohs(cp->cport),
751 NIPQUAD(cp->vaddr),ntohs(cp->vport));
752 return;
755 IP_VS_DBG(7, "DELeting control for: "
756 "cp.dst=%d.%d.%d.%d:%d ctl_cp.dst=%d.%d.%d.%d:%d\n",
757 NIPQUAD(cp->caddr),ntohs(cp->cport),
758 NIPQUAD(ctl_cp->caddr),ntohs(ctl_cp->cport));
760 cp->control = NULL;
761 if (atomic_read(&ctl_cp->n_control) == 0) {
762 IP_VS_ERR("BUG control DEL with n=0 : "
763 "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
764 NIPQUAD(cp->caddr),ntohs(cp->cport),
765 NIPQUAD(cp->vaddr),ntohs(cp->vport));
766 return;
768 atomic_dec(&ctl_cp->n_control);
771 static inline void
772 ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)
774 if (cp->control) {
775 IP_VS_ERR("request control ADD for already controlled: "
776 "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
777 NIPQUAD(cp->caddr),ntohs(cp->cport),
778 NIPQUAD(cp->vaddr),ntohs(cp->vport));
779 ip_vs_control_del(cp);
782 IP_VS_DBG(7, "ADDing control for: "
783 "cp.dst=%d.%d.%d.%d:%d ctl_cp.dst=%d.%d.%d.%d:%d\n",
784 NIPQUAD(cp->caddr),ntohs(cp->cport),
785 NIPQUAD(ctl_cp->caddr),ntohs(ctl_cp->cport));
787 cp->control = ctl_cp;
788 atomic_inc(&ctl_cp->n_control);
793 * IPVS application functions
794 * (from ip_vs_app.c)
796 #define IP_VS_APP_MAX_PORTS 8
797 extern int register_ip_vs_app(struct ip_vs_app *app);
798 extern void unregister_ip_vs_app(struct ip_vs_app *app);
799 extern int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
800 extern void ip_vs_unbind_app(struct ip_vs_conn *cp);
801 extern int
802 register_ip_vs_app_inc(struct ip_vs_app *app, __u16 proto, __u16 port);
803 extern int ip_vs_app_inc_get(struct ip_vs_app *inc);
804 extern void ip_vs_app_inc_put(struct ip_vs_app *inc);
806 extern int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb);
807 extern int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb);
808 extern int ip_vs_skb_replace(struct sk_buff *skb, gfp_t pri,
809 char *o_buf, int o_len, char *n_buf, int n_len);
810 extern int ip_vs_app_init(void);
811 extern void ip_vs_app_cleanup(void);
815 * IPVS protocol functions (from ip_vs_proto.c)
817 extern int ip_vs_protocol_init(void);
818 extern void ip_vs_protocol_cleanup(void);
819 extern void ip_vs_protocol_timeout_change(int flags);
820 extern int *ip_vs_create_timeout_table(int *table, int size);
821 extern int
822 ip_vs_set_state_timeout(int *table, int num, char **names, char *name, int to);
823 extern void
824 ip_vs_tcpudp_debug_packet(struct ip_vs_protocol *pp, const struct sk_buff *skb,
825 int offset, const char *msg);
827 extern struct ip_vs_protocol ip_vs_protocol_tcp;
828 extern struct ip_vs_protocol ip_vs_protocol_udp;
829 extern struct ip_vs_protocol ip_vs_protocol_icmp;
830 extern struct ip_vs_protocol ip_vs_protocol_esp;
831 extern struct ip_vs_protocol ip_vs_protocol_ah;
835 * Registering/unregistering scheduler functions
836 * (from ip_vs_sched.c)
838 extern int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
839 extern int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
840 extern int ip_vs_bind_scheduler(struct ip_vs_service *svc,
841 struct ip_vs_scheduler *scheduler);
842 extern int ip_vs_unbind_scheduler(struct ip_vs_service *svc);
843 extern struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name);
844 extern void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler);
845 extern struct ip_vs_conn *
846 ip_vs_schedule(struct ip_vs_service *svc, const struct sk_buff *skb);
847 extern int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
848 struct ip_vs_protocol *pp);
852 * IPVS control data and functions (from ip_vs_ctl.c)
854 extern int sysctl_ip_vs_cache_bypass;
855 extern int sysctl_ip_vs_expire_nodest_conn;
856 extern int sysctl_ip_vs_expire_quiescent_template;
857 extern int sysctl_ip_vs_sync_threshold[2];
858 extern int sysctl_ip_vs_nat_icmp_send;
859 extern struct ip_vs_stats ip_vs_stats;
860 extern struct ctl_path net_vs_ctl_path[];
862 extern struct ip_vs_service *
863 ip_vs_service_get(__u32 fwmark, __u16 protocol, __be32 vaddr, __be16 vport);
865 static inline void ip_vs_service_put(struct ip_vs_service *svc)
867 atomic_dec(&svc->usecnt);
870 extern struct ip_vs_dest *
871 ip_vs_lookup_real_service(__u16 protocol, __be32 daddr, __be16 dport);
872 extern int ip_vs_use_count_inc(void);
873 extern void ip_vs_use_count_dec(void);
874 extern int ip_vs_control_init(void);
875 extern void ip_vs_control_cleanup(void);
876 extern struct ip_vs_dest *
877 ip_vs_find_dest(__be32 daddr, __be16 dport,
878 __be32 vaddr, __be16 vport, __u16 protocol);
879 extern struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp);
883 * IPVS sync daemon data and function prototypes
884 * (from ip_vs_sync.c)
886 extern volatile int ip_vs_sync_state;
887 extern volatile int ip_vs_master_syncid;
888 extern volatile int ip_vs_backup_syncid;
889 extern char ip_vs_master_mcast_ifn[IP_VS_IFNAME_MAXLEN];
890 extern char ip_vs_backup_mcast_ifn[IP_VS_IFNAME_MAXLEN];
891 extern int start_sync_thread(int state, char *mcast_ifn, __u8 syncid);
892 extern int stop_sync_thread(int state);
893 extern void ip_vs_sync_conn(struct ip_vs_conn *cp);
897 * IPVS rate estimator prototypes (from ip_vs_est.c)
899 extern int ip_vs_new_estimator(struct ip_vs_stats *stats);
900 extern void ip_vs_kill_estimator(struct ip_vs_stats *stats);
901 extern void ip_vs_zero_estimator(struct ip_vs_stats *stats);
904 * Various IPVS packet transmitters (from ip_vs_xmit.c)
906 extern int ip_vs_null_xmit
907 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
908 extern int ip_vs_bypass_xmit
909 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
910 extern int ip_vs_nat_xmit
911 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
912 extern int ip_vs_tunnel_xmit
913 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
914 extern int ip_vs_dr_xmit
915 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
916 extern int ip_vs_icmp_xmit
917 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, int offset);
918 extern void ip_vs_dst_reset(struct ip_vs_dest *dest);
922 * This is a simple mechanism to ignore packets when
923 * we are loaded. Just set ip_vs_drop_rate to 'n' and
924 * we start to drop 1/rate of the packets
926 extern int ip_vs_drop_rate;
927 extern int ip_vs_drop_counter;
929 static __inline__ int ip_vs_todrop(void)
931 if (!ip_vs_drop_rate) return 0;
932 if (--ip_vs_drop_counter > 0) return 0;
933 ip_vs_drop_counter = ip_vs_drop_rate;
934 return 1;
938 * ip_vs_fwd_tag returns the forwarding tag of the connection
940 #define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK)
942 static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp)
944 char fwd;
946 switch (IP_VS_FWD_METHOD(cp)) {
947 case IP_VS_CONN_F_MASQ:
948 fwd = 'M'; break;
949 case IP_VS_CONN_F_LOCALNODE:
950 fwd = 'L'; break;
951 case IP_VS_CONN_F_TUNNEL:
952 fwd = 'T'; break;
953 case IP_VS_CONN_F_DROUTE:
954 fwd = 'R'; break;
955 case IP_VS_CONN_F_BYPASS:
956 fwd = 'B'; break;
957 default:
958 fwd = '?'; break;
960 return fwd;
963 extern void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,
964 struct ip_vs_conn *cp, int dir);
966 extern __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset);
968 static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum)
970 __be32 diff[2] = { ~old, new };
972 return csum_partial((char *) diff, sizeof(diff), oldsum);
975 static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum)
977 __be16 diff[2] = { ~old, new };
979 return csum_partial((char *) diff, sizeof(diff), oldsum);
982 #endif /* __KERNEL__ */
984 #endif /* _IP_VS_H */