* updated kmbox (21.12.1 -> 21.12.2), untested
[t2-trunk.git] / package / network / ipvsadm / inject_2.4.29_ip_vs.h.patch
blob5eadee81cc156e628afbfc2964981554eb1e2358
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
3 #
4 # T2 SDE: package/.../ipvsadm/inject_2.4.29_ip_vs.h.patch
5 # Copyright (C) 2004 - 2005 The T2 SDE Project
6 #
7 # More information can be found in the files COPYING and README.
8 #
9 # This patch file is dual-licensed. It is available under the license the
10 # patched project is licensed under, as long as it is an OpenSource license
11 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
12 # of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
15 # --- T2-COPYRIGHT-NOTE-END ---
16 --- ./Makefile.orig 2005-02-03 19:09:08.000000000 -0300
17 +++ ./Makefile 2005-02-03 19:09:23.000000000 -0300
18 @@ -59,7 +59,7 @@
19 echo "rpm"; \
20 fi )
22 -IP_VS_H_DEFINE = $(shell if [ ! -f ../ip_vs.h ]; then \
23 +IP_VS_H_DEFINE = $(shell if [ ! -f ip_vs.h ]; then \
24 echo "-DHAVE_NET_IP_VS_H"; fi;)
26 ifeq (,$(FORCE_GETOPT))
27 --- /dev/null 2004-11-09 23:14:49.000000000 -0300
28 +++ ./ip_vs.h 2005-02-03 19:04:00.000000000 -0300
29 @@ -0,0 +1,937 @@
30 +/*
31 + * IP Virtual Server
32 + * data structure and functionality definitions
33 + */
35 +#ifndef _IP_VS_H
36 +#define _IP_VS_H
38 +#include <asm/types.h> /* For __uXX types */
40 +#define IP_VS_VERSION_CODE 0x01000C
41 +#define NVERSION(version) \
42 + (version >> 16) & 0xFF, \
43 + (version >> 8) & 0xFF, \
44 + version & 0xFF
46 +/*
47 + * Virtual Service Flags
48 + */
49 +#define IP_VS_SVC_F_PERSISTENT 0x0001 /* persistent port */
50 +#define IP_VS_SVC_F_HASHED 0x0002 /* hashed entry */
52 +/*
53 + * Destination Server Flags
54 + */
55 +#define IP_VS_DEST_F_AVAILABLE 0x0001 /* Available tag */
57 +/*
58 + * IPVS sync daemon states
59 + */
60 +#define IP_VS_STATE_NONE 0 /* daemon is stopped */
61 +#define IP_VS_STATE_MASTER 1 /* started as master */
62 +#define IP_VS_STATE_BACKUP 2 /* started as backup */
64 +/*
65 + * IPVS socket options
66 + */
67 +#define IP_VS_BASE_CTL (64+1024+64) /* base */
69 +#define IP_VS_SO_SET_NONE IP_VS_BASE_CTL /* just peek */
70 +#define IP_VS_SO_SET_INSERT (IP_VS_BASE_CTL+1)
71 +#define IP_VS_SO_SET_ADD (IP_VS_BASE_CTL+2)
72 +#define IP_VS_SO_SET_EDIT (IP_VS_BASE_CTL+3)
73 +#define IP_VS_SO_SET_DEL (IP_VS_BASE_CTL+4)
74 +#define IP_VS_SO_SET_FLUSH (IP_VS_BASE_CTL+5)
75 +#define IP_VS_SO_SET_LIST (IP_VS_BASE_CTL+6)
76 +#define IP_VS_SO_SET_ADDDEST (IP_VS_BASE_CTL+7)
77 +#define IP_VS_SO_SET_DELDEST (IP_VS_BASE_CTL+8)
78 +#define IP_VS_SO_SET_EDITDEST (IP_VS_BASE_CTL+9)
79 +#define IP_VS_SO_SET_TIMEOUTS (IP_VS_BASE_CTL+10)
80 +#define IP_VS_SO_SET_STARTDAEMON (IP_VS_BASE_CTL+11)
81 +#define IP_VS_SO_SET_STOPDAEMON (IP_VS_BASE_CTL+12)
82 +#define IP_VS_SO_SET_RESTORE (IP_VS_BASE_CTL+13)
83 +#define IP_VS_SO_SET_SAVE (IP_VS_BASE_CTL+14)
84 +#define IP_VS_SO_SET_ZERO (IP_VS_BASE_CTL+15)
85 +#define IP_VS_SO_SET_MAX IP_VS_SO_SET_ZERO
87 +#define IP_VS_SO_GET_VERSION IP_VS_BASE_CTL
88 +#define IP_VS_SO_GET_INFO (IP_VS_BASE_CTL+1)
89 +#define IP_VS_SO_GET_SERVICES (IP_VS_BASE_CTL+2)
90 +#define IP_VS_SO_GET_SERVICE (IP_VS_BASE_CTL+3)
91 +#define IP_VS_SO_GET_DESTS (IP_VS_BASE_CTL+4)
92 +#define IP_VS_SO_GET_DEST (IP_VS_BASE_CTL+5) /* not used now */
93 +#define IP_VS_SO_GET_TIMEOUTS (IP_VS_BASE_CTL+6)
94 +#define IP_VS_SO_GET_DAEMON (IP_VS_BASE_CTL+7)
95 +#define IP_VS_SO_GET_MAX IP_VS_SO_GET_DAEMON
98 +/*
99 + * IPVS Connection Flags
100 + */
101 +#define IP_VS_CONN_F_FWD_MASK 0x0007 /* mask for the fwd methods */
102 +#define IP_VS_CONN_F_MASQ 0x0000 /* masquerading */
103 +#define IP_VS_CONN_F_LOCALNODE 0x0001 /* local node */
104 +#define IP_VS_CONN_F_TUNNEL 0x0002 /* tunneling */
105 +#define IP_VS_CONN_F_DROUTE 0x0003 /* direct routing */
106 +#define IP_VS_CONN_F_BYPASS 0x0004 /* cache bypass */
107 +#define IP_VS_CONN_F_HASHED 0x0040 /* hashed entry */
108 +#define IP_VS_CONN_F_NOOUTPUT 0x0080 /* no output packets */
109 +#define IP_VS_CONN_F_INACTIVE 0x0100 /* not established */
110 +#define IP_VS_CONN_F_OUT_SEQ 0x0200 /* must do output seq adjust */
111 +#define IP_VS_CONN_F_IN_SEQ 0x0400 /* must do input seq adjust */
112 +#define IP_VS_CONN_F_SEQ_MASK 0x0600 /* in/out sequence mask */
113 +#define IP_VS_CONN_F_NO_CPORT 0x0800 /* no client port set yet */
115 +/* Move it to better place one day, for now keep it unique */
116 +#define NFC_IPVS_PROPERTY 0x10000
118 +#define IP_VS_SCHEDNAME_MAXLEN 16
119 +#define IP_VS_IFNAME_MAXLEN 16
121 +struct ip_vs_rule_user {
122 + /* global options */
123 + int tcp_timeout; /* timeout values */
124 + int tcp_fin_timeout;
125 + int udp_timeout;
126 + int state; /* sync daemon state */
127 + char mcast_ifn[IP_VS_IFNAME_MAXLEN];
128 + /* multicast interface name */
129 + int syncid;
131 + /* virtual service options */
132 + u_int16_t protocol;
133 + u_int32_t vaddr; /* virtual address */
134 + u_int16_t vport;
135 + u_int32_t vfwmark; /* firwall mark of virtual service*/
136 + char sched_name[IP_VS_SCHEDNAME_MAXLEN];
137 + unsigned vs_flags; /* virtual service flags */
138 + unsigned timeout; /* persistent timeout in ticks */
139 + u_int32_t netmask; /* persistent netmask */
141 + /* destination specific options */
142 + u_int32_t daddr; /* destination address */
143 + u_int16_t dport;
144 + unsigned conn_flags; /* destination flags */
145 + int weight; /* destination weight */
150 + * IPVS statistics object (for user space)
151 + */
152 +struct ip_vs_stats_user
154 + __u32 conns; /* connections scheduled */
155 + __u32 inpkts; /* incoming packets */
156 + __u32 outpkts; /* outgoing packets */
157 + __u64 inbytes; /* incoming bytes */
158 + __u64 outbytes; /* outgoing bytes */
160 + __u32 cps; /* current connection rate */
161 + __u32 inpps; /* current in packet rate */
162 + __u32 outpps; /* current out packet rate */
163 + __u32 inbps; /* current in byte rate */
164 + __u32 outbps; /* current out byte rate */
168 +/* The argument to IP_VS_SO_GET_INFO */
169 +struct ip_vs_getinfo {
170 + /* version number */
171 + unsigned int version;
173 + /* size of connection hash table */
174 + unsigned int size;
176 + /* number of virtual services */
177 + unsigned int num_services;
180 +/* The argument to IP_VS_SO_GET_SERVICE */
181 +struct ip_vs_service_user {
182 + /* which service: user fills this in */
183 + u_int16_t protocol;
184 + u_int32_t addr; /* virtual address */
185 + u_int16_t port;
186 + u_int32_t fwmark; /* firwall mark of virtual service */
188 + /* service options */
189 + char sched_name[IP_VS_SCHEDNAME_MAXLEN];
190 + unsigned flags; /* virtual service flags */
191 + unsigned timeout; /* persistent timeout in ticks */
192 + u_int32_t netmask; /* persistent netmask */
194 + /* number of real servers */
195 + unsigned int num_dests;
197 + /* statistics */
198 + struct ip_vs_stats_user stats;
201 +struct ip_vs_dest_user {
202 + u_int32_t addr; /* destination address */
203 + u_int16_t port;
204 + unsigned flags; /* destination flags */
205 + int weight; /* destination weight */
206 + u_int32_t activeconns; /* active connections */
207 + u_int32_t inactconns; /* inactive connections */
209 + /* statistics */
210 + struct ip_vs_stats_user stats;
213 +/* The argument to IP_VS_SO_GET_DESTS */
214 +struct ip_vs_get_dests {
215 + /* which service: user fills this in */
216 + u_int16_t protocol;
217 + u_int32_t addr; /* virtual address */
218 + u_int16_t port;
219 + u_int32_t fwmark; /* firwall mark of virtual service */
221 + /* number of real servers */
222 + unsigned int num_dests;
224 + /* the real servers */
225 + struct ip_vs_dest_user entrytable[0];
228 +/* The argument to IP_VS_SO_GET_SERVICES */
229 +struct ip_vs_get_services {
230 + /* number of virtual services */
231 + unsigned int num_services;
233 + /* service table */
234 + struct ip_vs_service_user entrytable[0];
237 +/* The argument to IP_VS_SO_GET_TIMEOUTS */
238 +struct ip_vs_timeout_user {
239 + int tcp_timeout;
240 + int tcp_fin_timeout;
241 + int udp_timeout;
244 +/* The argument to IP_VS_SO_GET_DAEMON */
245 +struct ip_vs_daemon_user {
246 + int state; /* sync daemon state */
247 + char mcast_master_ifn[IP_VS_IFNAME_MAXLEN]; /* mcast master interface name */
248 + char mcast_backup_ifn[IP_VS_IFNAME_MAXLEN]; /* mcast backup interface name */
252 +#ifdef __KERNEL__
254 +#include <linux/config.h>
255 +#include <linux/list.h> /* for struct list_head */
256 +#include <linux/spinlock.h> /* for struct rwlock_t */
257 +#include <linux/skbuff.h> /* for struct sk_buff */
258 +#include <linux/ip.h> /* for struct iphdr */
259 +#include <asm/atomic.h> /* for struct atomic_t */
260 +#include <linux/netdevice.h> /* for struct neighbour; */
261 +#include <net/dst.h> /* for struct dst_entry */
262 +#include <net/route.h> /* for ip_route_output */
263 +#include <net/tcp.h>
264 +#include <net/udp.h>
267 +#ifdef CONFIG_IP_VS_DEBUG
268 +extern int ip_vs_get_debug_level(void);
269 +#define IP_VS_DBG(level, msg...) \
270 + do { \
271 + if (level <= ip_vs_get_debug_level()) \
272 + printk(KERN_DEBUG "IPVS: " msg); \
273 + } while (0)
274 +#define IP_VS_DBG_RL(msg...) \
275 + do { \
276 + if (net_ratelimit()) \
277 + printk(KERN_DEBUG "IPVS: " msg); \
278 + } while (0)
279 +#else /* NO DEBUGGING at ALL */
280 +#define IP_VS_DBG(level, msg...) do {} while (0)
281 +#define IP_VS_DBG_RL(msg...) do {} while (0)
282 +#endif
284 +#define IP_VS_BUG() BUG()
285 +#define IP_VS_ERR(msg...) printk(KERN_ERR "IPVS: " msg)
286 +#define IP_VS_INFO(msg...) printk(KERN_INFO "IPVS: " msg)
287 +#define IP_VS_WARNING(msg...) \
288 + printk(KERN_WARNING "IPVS: " msg)
289 +#define IP_VS_ERR_RL(msg...) \
290 + do { \
291 + if (net_ratelimit()) \
292 + printk(KERN_ERR "IPVS: " msg); \
293 + } while (0)
295 +#ifdef CONFIG_IP_VS_DEBUG
296 +#define EnterFunction(level) \
297 + do { \
298 + if (level <= ip_vs_get_debug_level()) \
299 + printk(KERN_DEBUG "Enter: %s, %s line %i\n", \
300 + __FUNCTION__, __FILE__, __LINE__); \
301 + } while (0)
302 +#define LeaveFunction(level) \
303 + do { \
304 + if (level <= ip_vs_get_debug_level()) \
305 + printk(KERN_DEBUG "Leave: %s, %s line %i\n", \
306 + __FUNCTION__, __FILE__, __LINE__); \
307 + } while (0)
308 +#else
309 +#define EnterFunction(level) do {} while (0)
310 +#define LeaveFunction(level) do {} while (0)
311 +#endif
315 + * The port number of FTP service (in network order).
316 + */
317 +#define FTPPORT __constant_htons(21)
318 +#define FTPDATA __constant_htons(20)
322 + * IPVS sysctl variables under the /proc/sys/net/ipv4/vs/
323 + */
324 +#define NET_IPV4_VS 21
326 +enum {
327 + NET_IPV4_VS_DEBUG_LEVEL=1,
328 + NET_IPV4_VS_AMEMTHRESH=2,
329 + NET_IPV4_VS_AMDROPRATE=3,
330 + NET_IPV4_VS_DROP_ENTRY=4,
331 + NET_IPV4_VS_DROP_PACKET=5,
332 + NET_IPV4_VS_SECURE_TCP=6,
333 + NET_IPV4_VS_TO_ES=7,
334 + NET_IPV4_VS_TO_SS=8,
335 + NET_IPV4_VS_TO_SR=9,
336 + NET_IPV4_VS_TO_FW=10,
337 + NET_IPV4_VS_TO_TW=11,
338 + NET_IPV4_VS_TO_CL=12,
339 + NET_IPV4_VS_TO_CW=13,
340 + NET_IPV4_VS_TO_LA=14,
341 + NET_IPV4_VS_TO_LI=15,
342 + NET_IPV4_VS_TO_SA=16,
343 + NET_IPV4_VS_TO_UDP=17,
344 + NET_IPV4_VS_TO_ICMP=18,
345 + NET_IPV4_VS_LBLC_EXPIRE=19,
346 + NET_IPV4_VS_LBLCR_EXPIRE=20,
347 + NET_IPV4_VS_CACHE_BYPASS=22,
348 + NET_IPV4_VS_EXPIRE_NODEST_CONN=23,
349 + NET_IPV4_VS_SYNC_THRESHOLD=24,
350 + NET_IPV4_VS_NAT_ICMP_SEND=25,
351 + NET_IPV4_VS_EXPIRE_QUIESCENT_TEMPLATE=26,
352 + NET_IPV4_VS_LAST
357 + * IPVS State Values
358 + */
359 +enum {
360 + IP_VS_S_NONE = 0,
361 + IP_VS_S_ESTABLISHED,
362 + IP_VS_S_SYN_SENT,
363 + IP_VS_S_SYN_RECV,
364 + IP_VS_S_FIN_WAIT,
365 + IP_VS_S_TIME_WAIT,
366 + IP_VS_S_CLOSE,
367 + IP_VS_S_CLOSE_WAIT,
368 + IP_VS_S_LAST_ACK,
369 + IP_VS_S_LISTEN,
370 + IP_VS_S_SYNACK,
371 + IP_VS_S_UDP,
372 + IP_VS_S_ICMP,
373 + IP_VS_S_LAST
377 +struct ip_vs_timeout_table {
378 + atomic_t refcnt;
379 + int scale;
380 + int timeout[IP_VS_S_LAST+1];
385 + * Transport protocol header
386 + */
387 +union ip_vs_tphdr {
388 + unsigned char *raw;
389 + struct udphdr *uh;
390 + struct tcphdr *th;
391 + struct icmphdr *icmph;
392 + __u16 *portp;
397 + * Delta sequence info structure
398 + * Each ip_vs_conn has 2 (output AND input seq. changes).
399 + * Only used in the VS/NAT.
400 + */
401 +struct ip_vs_seq {
402 + __u32 init_seq; /* Add delta from this seq */
403 + __u32 delta; /* Delta in sequence numbers */
404 + __u32 previous_delta; /* Delta in sequence numbers
405 + before last resized pkt */
410 + * IPVS statistics object
411 + */
412 +struct ip_vs_stats
414 + __u32 conns; /* connections scheduled */
415 + __u32 inpkts; /* incoming packets */
416 + __u32 outpkts; /* outgoing packets */
417 + __u64 inbytes; /* incoming bytes */
418 + __u64 outbytes; /* outgoing bytes */
420 + __u32 cps; /* current connection rate */
421 + __u32 inpps; /* current in packet rate */
422 + __u32 outpps; /* current out packet rate */
423 + __u32 inbps; /* current in byte rate */
424 + __u32 outbps; /* current out byte rate */
426 + spinlock_t lock; /* spin lock */
431 + * IP_VS structure allocated for each dynamically scheduled connection
432 + */
433 +struct ip_vs_conn {
434 + struct list_head c_list; /* hashed list heads */
436 + /* Protocol, addresses and port numbers */
437 + __u32 caddr; /* client address */
438 + __u32 vaddr; /* virtual address */
439 + __u32 daddr; /* destination address */
440 + __u16 cport;
441 + __u16 vport;
442 + __u16 dport;
443 + __u16 protocol; /* Which protocol (TCP/UDP) */
445 + /* counter and timer */
446 + atomic_t refcnt; /* reference count */
447 + struct timer_list timer; /* Expiration timer */
448 + volatile unsigned long timeout; /* timeout */
449 + struct ip_vs_timeout_table *timeout_table;
451 + /* Flags and state transition */
452 + spinlock_t lock; /* lock for state transition */
453 + volatile __u16 flags; /* status flags */
454 + volatile __u16 state; /* state info */
456 + /* Control members */
457 + struct ip_vs_conn *control; /* Master control connection */
458 + atomic_t n_control; /* Number of controlled ones */
459 + struct ip_vs_dest *dest; /* real server */
460 + atomic_t in_pkts; /* incoming packet counter */
462 + /* packet transmitter for different forwarding methods */
463 + int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp);
465 + /* Note: we can group the following members into a structure,
466 + in order to save more space, and the following members are
467 + only used in VS/NAT anyway */
468 + struct ip_vs_app *app; /* bound ip_vs_app object */
469 + void *app_data; /* Application private data */
470 + struct ip_vs_seq in_seq; /* incoming seq. struct */
471 + struct ip_vs_seq out_seq; /* outgoing seq. struct */
476 + * The information about the virtual service offered to the net
477 + * and the forwarding entries
478 + */
479 +struct ip_vs_service {
480 + struct list_head s_list; /* for normal service table */
481 + struct list_head f_list; /* for fwmark-based service table */
482 + atomic_t refcnt; /* reference counter */
483 + atomic_t usecnt; /* use counter */
485 + __u16 protocol; /* which protocol (TCP/UDP) */
486 + __u32 addr; /* IP address for virtual service */
487 + __u16 port; /* port number for the service */
488 + __u32 fwmark; /* firewall mark of the service */
489 + unsigned flags; /* service status flags */
490 + unsigned timeout; /* persistent timeout in ticks */
491 + __u32 netmask; /* grouping granularity */
493 + struct list_head destinations; /* real server d-linked list */
494 + __u32 num_dests; /* number of servers */
495 + struct ip_vs_stats stats; /* statistics for the service */
497 + /* for scheduling */
498 + struct ip_vs_scheduler *scheduler; /* bound scheduler object */
499 + rwlock_t sched_lock; /* lock sched_data */
500 + void *sched_data; /* scheduler application data */
505 + * The real server destination forwarding entry
506 + * with ip address, port number, and so on.
507 + */
508 +struct ip_vs_dest {
509 + struct list_head n_list; /* for the dests in the service */
510 + struct list_head d_list; /* for table with all the dests */
512 + __u32 addr; /* IP address of real server */
513 + __u16 port; /* port number of the service */
514 + unsigned flags; /* dest status flags */
515 + atomic_t weight; /* server weight */
516 + atomic_t conn_flags; /* flags to copy to conn */
517 + atomic_t activeconns; /* active connections */
518 + atomic_t inactconns; /* inactive connections */
519 + atomic_t refcnt; /* reference counter */
520 + struct ip_vs_stats stats; /* statistics */
522 + /* for destination cache */
523 + spinlock_t dst_lock; /* lock dst_cache */
524 + struct dst_entry *dst_cache; /* destination cache entry */
525 + u32 dst_rtos; /* RT_TOS(tos) for dst */
527 + /* for virtual service */
528 + struct ip_vs_service *svc; /* service that it belongs to */
529 + __u16 protocol; /* which protocol (TCP/UDP) */
530 + __u32 vaddr; /* IP address for virtual service */
531 + __u16 vport; /* port number for the service */
532 + __u32 vfwmark; /* firewall mark of the service */
537 + * The scheduler object
538 + */
539 +struct ip_vs_scheduler {
540 + struct list_head n_list; /* d-linked list head */
541 + char *name; /* scheduler name */
542 + atomic_t refcnt; /* reference counter */
543 + struct module *module; /* THIS_MODULE/NULL */
545 + /* scheduler initializing service */
546 + int (*init_service)(struct ip_vs_service *svc);
547 + /* scheduling service finish */
548 + int (*done_service)(struct ip_vs_service *svc);
549 + /* scheduler updating service */
550 + int (*update_service)(struct ip_vs_service *svc);
552 + /* selecting a server from the given service */
553 + struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc,
554 + struct iphdr *iph);
559 + * The application module object
560 + */
561 +struct ip_vs_app
563 + struct list_head n_list; /* d-linked list head */
564 + char *name; /* name of application module */
565 + unsigned type; /* type = proto<<16 | port
566 + (host byte order)*/
567 + struct module *module; /* THIS_MODULE/NULL */
569 + /* ip_vs_app initializer */
570 + int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *);
571 + /* ip_vs_app finish */
572 + int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *);
573 + /* output hook */
574 + int (*pkt_out)(struct ip_vs_app *,
575 + struct ip_vs_conn *, struct sk_buff *);
576 + /* input hook */
577 + int (*pkt_in)(struct ip_vs_app *,
578 + struct ip_vs_conn *, struct sk_buff *);
583 + * IPVS core functions
584 + * (from ip_vs_core.c)
585 + */
586 +extern const char *ip_vs_proto_name(unsigned proto);
587 +extern unsigned int check_for_ip_vs_out(struct sk_buff **skb_p,
588 + int (*okfn)(struct sk_buff *));
592 + * ip_vs_conn handling functions
593 + * (from ip_vs_conn.c)
594 + */
597 + * IPVS connection entry hash table
598 + */
599 +#ifndef CONFIG_IP_VS_TAB_BITS
600 +#define CONFIG_IP_VS_TAB_BITS 12
601 +#endif
602 +/* make sure that IP_VS_CONN_TAB_BITS is located in [8, 20] */
603 +#if CONFIG_IP_VS_TAB_BITS < 8
604 +#define IP_VS_CONN_TAB_BITS 8
605 +#endif
606 +#if CONFIG_IP_VS_TAB_BITS > 20
607 +#define IP_VS_CONN_TAB_BITS 20
608 +#endif
609 +#if 8 <= CONFIG_IP_VS_TAB_BITS && CONFIG_IP_VS_TAB_BITS <= 20
610 +#define IP_VS_CONN_TAB_BITS CONFIG_IP_VS_TAB_BITS
611 +#endif
612 +#define IP_VS_CONN_TAB_SIZE (1 << IP_VS_CONN_TAB_BITS)
613 +#define IP_VS_CONN_TAB_MASK (IP_VS_CONN_TAB_SIZE - 1)
615 +#define VS_STATE_INPUT 0
616 +#define VS_STATE_OUTPUT 4
617 +#define VS_STATE_INPUT_ONLY 8
619 +extern struct ip_vs_timeout_table vs_timeout_table;
620 +extern struct ip_vs_timeout_table vs_timeout_table_dos;
622 +extern struct ip_vs_conn *ip_vs_conn_in_get
623 +(int protocol, __u32 s_addr, __u16 s_port, __u32 d_addr, __u16 d_port);
624 +extern struct ip_vs_conn *ip_vs_conn_out_get
625 +(int protocol, __u32 s_addr, __u16 s_port, __u32 d_addr, __u16 d_port);
627 +/* put back the conn without restarting its timer */
628 +static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
630 + atomic_dec(&cp->refcnt);
632 +extern void ip_vs_conn_put(struct ip_vs_conn *cp);
634 +extern struct ip_vs_conn *
635 +ip_vs_conn_new(int proto, __u32 caddr, __u16 cport, __u32 vaddr, __u16 vport,
636 + __u32 daddr, __u16 dport, unsigned flags,
637 + struct ip_vs_dest *dest);
638 +extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
640 +extern const char * ip_vs_state_name(int state);
641 +extern int ip_vs_set_state(struct ip_vs_conn *cp, int state_off,
642 + struct iphdr *iph, void *tp);
643 +extern int ip_vs_conn_listen(struct ip_vs_conn *cp);
644 +extern int ip_vs_check_template(struct ip_vs_conn *ct);
645 +extern void ip_vs_secure_tcp_set(int on);
646 +extern void ip_vs_random_dropentry(void);
647 +extern int ip_vs_conn_init(void);
648 +extern void ip_vs_conn_cleanup(void);
650 +static inline void ip_vs_control_del(struct ip_vs_conn *cp)
652 + struct ip_vs_conn *ctl_cp = cp->control;
653 + if (!ctl_cp) {
654 + IP_VS_ERR("request control DEL for uncontrolled: "
655 + "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
656 + NIPQUAD(cp->caddr),ntohs(cp->cport),
657 + NIPQUAD(cp->vaddr),ntohs(cp->vport));
658 + return;
661 + IP_VS_DBG(7, "DELeting control for: "
662 + "cp.dst=%d.%d.%d.%d:%d ctl_cp.dst=%d.%d.%d.%d:%d\n",
663 + NIPQUAD(cp->caddr),ntohs(cp->cport),
664 + NIPQUAD(ctl_cp->caddr),ntohs(ctl_cp->cport));
666 + cp->control = NULL;
667 + if (atomic_read(&ctl_cp->n_control) == 0) {
668 + IP_VS_ERR("BUG control DEL with n=0 : "
669 + "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
670 + NIPQUAD(cp->caddr),ntohs(cp->cport),
671 + NIPQUAD(cp->vaddr),ntohs(cp->vport));
672 + return;
674 + atomic_dec(&ctl_cp->n_control);
677 +static inline void
678 +ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)
680 + if (cp->control) {
681 + IP_VS_ERR("request control ADD for already controlled: "
682 + "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
683 + NIPQUAD(cp->caddr),ntohs(cp->cport),
684 + NIPQUAD(cp->vaddr),ntohs(cp->vport));
685 + ip_vs_control_del(cp);
688 + IP_VS_DBG(7, "ADDing control for: "
689 + "cp.dst=%d.%d.%d.%d:%d ctl_cp.dst=%d.%d.%d.%d:%d\n",
690 + NIPQUAD(cp->caddr),ntohs(cp->cport),
691 + NIPQUAD(ctl_cp->caddr),ntohs(ctl_cp->cport));
693 + cp->control = ctl_cp;
694 + atomic_inc(&ctl_cp->n_control);
699 + * IPVS application functions
700 + * (from ip_vs_app.c)
701 + */
702 +#define IP_VS_APP_MAX_PORTS 8
703 +extern int register_ip_vs_app(struct ip_vs_app *mapp,
704 + unsigned short proto, __u16 port);
705 +extern int unregister_ip_vs_app(struct ip_vs_app *mapp);
706 +extern struct ip_vs_app * ip_vs_bind_app(struct ip_vs_conn *cp);
707 +extern int ip_vs_unbind_app(struct ip_vs_conn *cp);
708 +extern int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb);
709 +extern int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb);
710 +extern int ip_vs_skb_replace(struct sk_buff *skb, int pri,
711 + char *o_buf, int o_len, char *n_buf, int n_len);
712 +extern int ip_vs_app_init(void);
713 +extern void ip_vs_app_cleanup(void);
717 + * Registering/unregistering scheduler functions
718 + * (from ip_vs_sched.c)
719 + */
720 +extern int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
721 +extern int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
722 +extern int ip_vs_bind_scheduler(struct ip_vs_service *svc,
723 + struct ip_vs_scheduler *scheduler);
724 +extern int ip_vs_unbind_scheduler(struct ip_vs_service *svc);
725 +extern struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name);
726 +extern void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler);
730 + * IPVS control data and functions
731 + * (from ip_vs_ctl.c)
732 + */
733 +extern int sysctl_ip_vs_cache_bypass;
734 +extern int sysctl_ip_vs_expire_nodest_conn;
735 +extern int sysctl_ip_vs_expire_quiescent_template;
736 +extern int sysctl_ip_vs_sync_threshold;
737 +extern int sysctl_ip_vs_nat_icmp_send;
738 +extern struct ip_vs_stats ip_vs_stats;
740 +extern struct ip_vs_service *ip_vs_service_get(__u32 fwmark,
741 + __u16 protocol,
742 + __u32 vaddr, __u16 vport);
743 +static inline void ip_vs_service_put(struct ip_vs_service *svc)
745 + atomic_dec(&svc->usecnt);
748 +extern struct ip_vs_dest *
749 +ip_vs_lookup_real_service(__u16 protocol, __u32 daddr, __u16 dport);
750 +extern void ip_vs_random_dropentry(void);
751 +extern int ip_vs_control_init(void);
752 +extern void ip_vs_control_cleanup(void);
756 + * IPVS sync daemon data and function prototypes
757 + * (from ip_vs_sync.c)
758 + */
759 +extern volatile int ip_vs_sync_state;
760 +extern char ip_vs_mcast_master_ifn[IP_VS_IFNAME_MAXLEN];
761 +extern char ip_vs_mcast_backup_ifn[IP_VS_IFNAME_MAXLEN];
762 +extern int start_sync_thread(int state, char *mcast_ifn, __u8 syncid);
763 +extern int stop_sync_thread(int state);
764 +extern void ip_vs_sync_conn(struct ip_vs_conn *cp);
768 + * IPVS rate estimator prototypes (from ip_vs_est.c)
769 + */
770 +extern int ip_vs_new_estimator(struct ip_vs_stats *stats);
771 +extern void ip_vs_kill_estimator(struct ip_vs_stats *stats);
772 +extern void ip_vs_zero_estimator(struct ip_vs_stats *stats);
776 + * This is a simple mechanism to ignore packets when
777 + * we are loaded. Just set ip_vs_drop_rate to 'n' and
778 + * we start to drop 1/rate of the packets
779 + */
780 +extern int ip_vs_drop_rate;
781 +extern int ip_vs_drop_counter;
783 +static __inline__ int ip_vs_todrop(void)
785 + if (!ip_vs_drop_rate) return 0;
786 + if (--ip_vs_drop_counter > 0) return 0;
787 + ip_vs_drop_counter = ip_vs_drop_rate;
788 + return 1;
793 + * ip_vs_fwd_tag returns the forwarding tag of the connection
794 + */
795 +#define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK)
797 +extern __inline__ char ip_vs_fwd_tag(struct ip_vs_conn *cp)
799 + char fwd;
801 + switch (IP_VS_FWD_METHOD(cp)) {
802 + case IP_VS_CONN_F_MASQ:
803 + fwd = 'M'; break;
804 + case IP_VS_CONN_F_LOCALNODE:
805 + fwd = 'L'; break;
806 + case IP_VS_CONN_F_TUNNEL:
807 + fwd = 'T'; break;
808 + case IP_VS_CONN_F_DROUTE:
809 + fwd = 'R'; break;
810 + case IP_VS_CONN_F_BYPASS:
811 + fwd = 'B'; break;
812 + default:
813 + fwd = '?'; break;
815 + return fwd;
820 + * transport layer header checking
821 + */
822 +extern inline int ip_vs_header_check(struct sk_buff *skb, int proto, int ihl)
824 + int len;
826 + switch (proto) {
827 + case IPPROTO_TCP:
828 + len = ihl + sizeof(struct tcphdr);
829 + /* we don't care about TCP options */
830 + break;
831 + case IPPROTO_UDP:
832 + len = ihl + sizeof(struct udphdr);
833 + break;
834 + default:
835 + len = 0;
838 + /* guarantee protocol header available in skb data area */
839 + if (!pskb_may_pull(skb, len))
840 + return -1;
841 + else
842 + return 0;
847 + * Destination cache
848 + */
849 +static inline void
850 +__ip_vs_dst_set(struct ip_vs_dest *dest, u32 rtos, struct dst_entry *dst)
852 + struct dst_entry *old_dst;
854 + old_dst = dest->dst_cache;
855 + dest->dst_cache = dst;
856 + dest->dst_rtos = rtos;
857 + dst_release(old_dst);
860 +static inline void
861 +__ip_vs_dst_reset(struct ip_vs_dest *dest)
863 + struct dst_entry *old_dst;
865 + old_dst = dest->dst_cache;
866 + dest->dst_cache = NULL;
867 + dst_release(old_dst);
870 +static inline struct dst_entry *
871 +__ip_vs_dst_check(struct ip_vs_dest *dest, u32 rtos, u32 cookie)
873 + struct dst_entry *dst = dest->dst_cache;
875 + if (!dst)
876 + return NULL;
877 + if ((dst->obsolete || rtos != dest->dst_rtos) &&
878 + dst->ops->check(dst, cookie) == NULL) {
879 + dest->dst_cache = 0;
880 + return NULL;
882 + dst_hold(dst);
883 + return dst;
886 +static inline struct rtable *
887 +__ip_vs_get_out_rt(struct ip_vs_conn *cp, u32 rtos)
889 + struct rtable *rt; /* Route to the other host */
890 + struct ip_vs_dest *dest = cp->dest;
892 + if (dest) {
893 + spin_lock(&dest->dst_lock);
894 + if (!(rt = (struct rtable *)
895 + __ip_vs_dst_check(dest, rtos, 0))) {
896 + if (ip_route_output(&rt, dest->addr, 0, rtos, 0)) {
897 + spin_unlock(&dest->dst_lock);
898 + IP_VS_DBG_RL("ip_route_output error, "
899 + "dest: %u.%u.%u.%u\n",
900 + NIPQUAD(dest->addr));
901 + return NULL;
903 + __ip_vs_dst_set(dest, rtos, dst_clone(&rt->u.dst));
904 + IP_VS_DBG(10, "new dst %u.%u.%u.%u, refcnt=%d, rtos=%X\n",
905 + NIPQUAD(dest->addr),
906 + atomic_read(&rt->u.dst.__refcnt), rtos);
908 + spin_unlock(&dest->dst_lock);
909 + } else {
910 + if (ip_route_output(&rt, cp->daddr, 0, rtos, 0)) {
911 + IP_VS_DBG_RL("ip_route_output error, dest: "
912 + "%u.%u.%u.%u\n", NIPQUAD(cp->daddr));
913 + return NULL;
917 + return rt;
920 +static inline u16 ip_vs_check_diff(u32 old, u32 new, u16 oldsum)
922 + u32 diff[2] = { old, new };
924 + return csum_fold(csum_partial((char *) diff, sizeof(diff),
925 + oldsum ^ 0xFFFF));
928 +static inline void ip_vs_fast_check_update(union ip_vs_tphdr *h,
929 + u32 oldip, u32 newip, u16 oldport, u16 newport, u8 protocol)
931 + u16 *checkp;
933 + if (protocol == IPPROTO_TCP)
934 + checkp = &h->th->check;
935 + else
936 + checkp = &h->uh->check;
937 + *checkp = ip_vs_check_diff(~oldip, newip,
938 + ip_vs_check_diff(oldport ^ 0xFFFF,
939 + newport, *checkp));
940 + if (!*checkp && protocol == IPPROTO_UDP)
941 + *checkp = 0xFFFF;
944 +static inline int
945 +ip_vs_skb_cow(struct sk_buff *skb, unsigned int headroom,
946 + struct iphdr **iph_p, unsigned char **t_p)
948 + int delta = (headroom > 16 ? headroom : 16) - skb_headroom(skb);
950 + if (delta < 0)
951 + delta = 0;
953 + if (delta || skb_cloned(skb)) {
954 + if (pskb_expand_head(skb, (delta+15)&~15, 0, GFP_ATOMIC))
955 + return -ENOMEM;
957 + /* skb data changed, update pointers */
958 + *iph_p = skb->nh.iph;
959 + *t_p = (char*) (*iph_p) + (*iph_p)->ihl * 4;
961 + return 0;
964 +#endif /* __KERNEL__ */
966 +#endif /* _IP_VS_H */