[TCP]: Move the tcp sock states to net/tcp_states.h
[deliverable/linux.git] / include / net / ip_vs.h
CommitLineData
1da177e4
LT
1/*
2 * IP Virtual Server
3 * data structure and functionality definitions
4 */
5
6#ifndef _IP_VS_H
7#define _IP_VS_H
8
9#include <asm/types.h> /* For __uXX types */
10
11#define IP_VS_VERSION_CODE 0x010201
12#define NVERSION(version) \
13 (version >> 16) & 0xFF, \
14 (version >> 8) & 0xFF, \
15 version & 0xFF
16
17/*
18 * Virtual Service Flags
19 */
20#define IP_VS_SVC_F_PERSISTENT 0x0001 /* persistent port */
21#define IP_VS_SVC_F_HASHED 0x0002 /* hashed entry */
22
23/*
24 * Destination Server Flags
25 */
26#define IP_VS_DEST_F_AVAILABLE 0x0001 /* server is available */
27#define IP_VS_DEST_F_OVERLOAD 0x0002 /* server is overloaded */
28
29/*
30 * IPVS sync daemon states
31 */
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 */
35
36/*
37 * IPVS socket options
38 */
39#define IP_VS_BASE_CTL (64+1024+64) /* base */
40
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
58
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
68
69
70/*
71 * IPVS Connection Flags
72 */
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
88/* Move it to better place one day, for now keep it unique */
89#define NFC_IPVS_PROPERTY 0x10000
90
91#define IP_VS_SCHEDNAME_MAXLEN 16
92#define IP_VS_IFNAME_MAXLEN 16
93
94
95/*
96 * The struct ip_vs_service_user and struct ip_vs_dest_user are
97 * used to set IPVS rules through setsockopt.
98 */
99struct 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 */
105
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 */
111};
112
113
114struct ip_vs_dest_user {
115 /* destination server address */
116 u_int32_t addr;
117 u_int16_t port;
118
119 /* real server options */
120 unsigned conn_flags; /* connection flags */
121 int weight; /* destination weight */
122
123 /* thresholds for active connections */
124 u_int32_t u_threshold; /* upper threshold */
125 u_int32_t l_threshold; /* lower threshold */
126};
127
128
129/*
130 * IPVS statistics object (for user space)
131 */
132struct ip_vs_stats_user
133{
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 */
139
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 */
145};
146
147
148/* The argument to IP_VS_SO_GET_INFO */
149struct ip_vs_getinfo {
150 /* version number */
151 unsigned int version;
152
153 /* size of connection hash table */
154 unsigned int size;
155
156 /* number of virtual services */
157 unsigned int num_services;
158};
159
160
161/* The argument to IP_VS_SO_GET_SERVICE */
162struct 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 */
168
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 */
174
175 /* number of real servers */
176 unsigned int num_dests;
177
178 /* statistics */
179 struct ip_vs_stats_user stats;
180};
181
182
183struct 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 */
188
189 u_int32_t u_threshold; /* upper threshold */
190 u_int32_t l_threshold; /* lower threshold */
191
192 u_int32_t activeconns; /* active connections */
193 u_int32_t inactconns; /* inactive connections */
194 u_int32_t persistconns; /* persistent connections */
195
196 /* statistics */
197 struct ip_vs_stats_user stats;
198};
199
200
201/* The argument to IP_VS_SO_GET_DESTS */
202struct 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 */
208
209 /* number of real servers */
210 unsigned int num_dests;
211
212 /* the real servers */
213 struct ip_vs_dest_entry entrytable[0];
214};
215
216
217/* The argument to IP_VS_SO_GET_SERVICES */
218struct ip_vs_get_services {
219 /* number of virtual services */
220 unsigned int num_services;
221
222 /* service table */
223 struct ip_vs_service_entry entrytable[0];
224};
225
226
227/* The argument to IP_VS_SO_GET_TIMEOUT */
228struct ip_vs_timeout_user {
229 int tcp_timeout;
230 int tcp_fin_timeout;
231 int udp_timeout;
232};
233
234
235/* The argument to IP_VS_SO_GET_DAEMON */
236struct ip_vs_daemon_user {
237 /* sync daemon state (master/backup) */
238 int state;
239
240 /* multicast interface name */
241 char mcast_ifn[IP_VS_IFNAME_MAXLEN];
242
243 /* SyncID we belong to */
244 int syncid;
245};
246
247
248#ifdef __KERNEL__
249
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 */
1da177e4
LT
258#include <net/udp.h>
259#include <linux/compiler.h>
260
261
262#ifdef CONFIG_IP_VS_DEBUG
263extern 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
291
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)
302
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
320
321#define IP_VS_WAIT_WHILE(expr) while (expr) { cpu_relax(); }
322
323
324/*
325 * The port number of FTP service (in network order).
326 */
327#define FTPPORT __constant_htons(21)
328#define FTPDATA __constant_htons(20)
329
330/*
331 * IPVS sysctl variables under the /proc/sys/net/ipv4/vs/
332 */
333#define NET_IPV4_VS 21
334
335enum {
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
362};
363
364/*
365 * TCP State Values
366 */
367enum {
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
380};
381
382/*
383 * UDP State Values
384 */
385enum {
386 IP_VS_UDP_S_NORMAL,
387 IP_VS_UDP_S_LAST,
388};
389
390/*
391 * ICMP State Values
392 */
393enum {
394 IP_VS_ICMP_S_NORMAL,
395 IP_VS_ICMP_S_LAST,
396};
397
398/*
399 * Delta sequence info structure
400 * Each ip_vs_conn has 2 (output AND input seq. changes).
401 * Only used in the VS/NAT.
402 */
403struct 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 */
408};
409
410
411/*
412 * IPVS statistics object
413 */
414struct ip_vs_stats
415{
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 */
421
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 */
427
428 spinlock_t lock; /* spin lock */
429};
430
431struct ip_vs_conn;
432struct ip_vs_app;
433
434struct ip_vs_protocol {
435 struct ip_vs_protocol *next;
436 char *name;
437 __u16 protocol;
438 int dont_defrag;
439 atomic_t appcnt; /* counter of proto app incs */
440 int *timeout_table; /* protocol timeout table */
441
442 void (*init)(struct ip_vs_protocol *pp);
443
444 void (*exit)(struct ip_vs_protocol *pp);
445
446 int (*conn_schedule)(struct sk_buff *skb,
447 struct ip_vs_protocol *pp,
448 int *verdict, struct ip_vs_conn **cpp);
449
450 struct ip_vs_conn *
451 (*conn_in_get)(const struct sk_buff *skb,
452 struct ip_vs_protocol *pp,
453 const struct iphdr *iph,
454 unsigned int proto_off,
455 int inverse);
456
457 struct ip_vs_conn *
458 (*conn_out_get)(const struct sk_buff *skb,
459 struct ip_vs_protocol *pp,
460 const struct iphdr *iph,
461 unsigned int proto_off,
462 int inverse);
463
464 int (*snat_handler)(struct sk_buff **pskb,
465 struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
466
467 int (*dnat_handler)(struct sk_buff **pskb,
468 struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
469
470 int (*csum_check)(struct sk_buff *skb, struct ip_vs_protocol *pp);
471
472 const char *(*state_name)(int state);
473
474 int (*state_transition)(struct ip_vs_conn *cp, int direction,
475 const struct sk_buff *skb,
476 struct ip_vs_protocol *pp);
477
478 int (*register_app)(struct ip_vs_app *inc);
479
480 void (*unregister_app)(struct ip_vs_app *inc);
481
482 int (*app_conn_bind)(struct ip_vs_conn *cp);
483
484 void (*debug_packet)(struct ip_vs_protocol *pp,
485 const struct sk_buff *skb,
486 int offset,
487 const char *msg);
488
489 void (*timeout_change)(struct ip_vs_protocol *pp, int flags);
490
491 int (*set_state_timeout)(struct ip_vs_protocol *pp, char *sname, int to);
492};
493
494extern struct ip_vs_protocol * ip_vs_proto_get(unsigned short proto);
495
496/*
497 * IP_VS structure allocated for each dynamically scheduled connection
498 */
499struct ip_vs_conn {
500 struct list_head c_list; /* hashed list heads */
501
502 /* Protocol, addresses and port numbers */
503 __u32 caddr; /* client address */
504 __u32 vaddr; /* virtual address */
505 __u32 daddr; /* destination address */
506 __u16 cport;
507 __u16 vport;
508 __u16 dport;
509 __u16 protocol; /* Which protocol (TCP/UDP) */
510
511 /* counter and timer */
512 atomic_t refcnt; /* reference count */
513 struct timer_list timer; /* Expiration timer */
514 volatile unsigned long timeout; /* timeout */
515
516 /* Flags and state transition */
517 spinlock_t lock; /* lock for state transition */
518 volatile __u16 flags; /* status flags */
519 volatile __u16 state; /* state info */
520
521 /* Control members */
522 struct ip_vs_conn *control; /* Master control connection */
523 atomic_t n_control; /* Number of controlled ones */
524 struct ip_vs_dest *dest; /* real server */
525 atomic_t in_pkts; /* incoming packet counter */
526
527 /* packet transmitter for different forwarding methods. If it
528 mangles the packet, it must return NF_DROP or better NF_STOLEN,
529 otherwise this must be changed to a sk_buff **.
530 */
531 int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp,
532 struct ip_vs_protocol *pp);
533
534 /* Note: we can group the following members into a structure,
535 in order to save more space, and the following members are
536 only used in VS/NAT anyway */
537 struct ip_vs_app *app; /* bound ip_vs_app object */
538 void *app_data; /* Application private data */
539 struct ip_vs_seq in_seq; /* incoming seq. struct */
540 struct ip_vs_seq out_seq; /* outgoing seq. struct */
541};
542
543
544/*
545 * The information about the virtual service offered to the net
546 * and the forwarding entries
547 */
548struct ip_vs_service {
549 struct list_head s_list; /* for normal service table */
550 struct list_head f_list; /* for fwmark-based service table */
551 atomic_t refcnt; /* reference counter */
552 atomic_t usecnt; /* use counter */
553
554 __u16 protocol; /* which protocol (TCP/UDP) */
555 __u32 addr; /* IP address for virtual service */
556 __u16 port; /* port number for the service */
557 __u32 fwmark; /* firewall mark of the service */
558 unsigned flags; /* service status flags */
559 unsigned timeout; /* persistent timeout in ticks */
560 __u32 netmask; /* grouping granularity */
561
562 struct list_head destinations; /* real server d-linked list */
563 __u32 num_dests; /* number of servers */
564 struct ip_vs_stats stats; /* statistics for the service */
565 struct ip_vs_app *inc; /* bind conns to this app inc */
566
567 /* for scheduling */
568 struct ip_vs_scheduler *scheduler; /* bound scheduler object */
569 rwlock_t sched_lock; /* lock sched_data */
570 void *sched_data; /* scheduler application data */
571};
572
573
574/*
575 * The real server destination forwarding entry
576 * with ip address, port number, and so on.
577 */
578struct ip_vs_dest {
579 struct list_head n_list; /* for the dests in the service */
580 struct list_head d_list; /* for table with all the dests */
581
582 __u32 addr; /* IP address of the server */
583 __u16 port; /* port number of the server */
584 volatile unsigned flags; /* dest status flags */
585 atomic_t conn_flags; /* flags to copy to conn */
586 atomic_t weight; /* server weight */
587
588 atomic_t refcnt; /* reference counter */
589 struct ip_vs_stats stats; /* statistics */
590
591 /* connection counters and thresholds */
592 atomic_t activeconns; /* active connections */
593 atomic_t inactconns; /* inactive connections */
594 atomic_t persistconns; /* persistent connections */
595 __u32 u_threshold; /* upper threshold */
596 __u32 l_threshold; /* lower threshold */
597
598 /* for destination cache */
599 spinlock_t dst_lock; /* lock of dst_cache */
600 struct dst_entry *dst_cache; /* destination cache entry */
601 u32 dst_rtos; /* RT_TOS(tos) for dst */
602
603 /* for virtual service */
604 struct ip_vs_service *svc; /* service it belongs to */
605 __u16 protocol; /* which protocol (TCP/UDP) */
606 __u32 vaddr; /* virtual IP address */
607 __u16 vport; /* virtual port number */
608 __u32 vfwmark; /* firewall mark of service */
609};
610
611
612/*
613 * The scheduler object
614 */
615struct ip_vs_scheduler {
616 struct list_head n_list; /* d-linked list head */
617 char *name; /* scheduler name */
618 atomic_t refcnt; /* reference counter */
619 struct module *module; /* THIS_MODULE/NULL */
620
621 /* scheduler initializing service */
622 int (*init_service)(struct ip_vs_service *svc);
623 /* scheduling service finish */
624 int (*done_service)(struct ip_vs_service *svc);
625 /* scheduler updating service */
626 int (*update_service)(struct ip_vs_service *svc);
627
628 /* selecting a server from the given service */
629 struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc,
630 const struct sk_buff *skb);
631};
632
633
634/*
635 * The application module object (a.k.a. app incarnation)
636 */
637struct ip_vs_app
638{
639 struct list_head a_list; /* member in app list */
640 int type; /* IP_VS_APP_TYPE_xxx */
641 char *name; /* application module name */
642 __u16 protocol;
643 struct module *module; /* THIS_MODULE/NULL */
644 struct list_head incs_list; /* list of incarnations */
645
646 /* members for application incarnations */
647 struct list_head p_list; /* member in proto app list */
648 struct ip_vs_app *app; /* its real application */
649 __u16 port; /* port number in net order */
650 atomic_t usecnt; /* usage counter */
651
652 /* output hook: return false if can't linearize. diff set for TCP. */
653 int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *,
654 struct sk_buff **, int *diff);
655
656 /* input hook: return false if can't linearize. diff set for TCP. */
657 int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *,
658 struct sk_buff **, int *diff);
659
660 /* ip_vs_app initializer */
661 int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *);
662
663 /* ip_vs_app finish */
664 int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *);
665
666
667 /* not used now */
668 int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *,
669 struct ip_vs_protocol *);
670
671 void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *);
672
673 int * timeout_table;
674 int * timeouts;
675 int timeouts_size;
676
677 int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app,
678 int *verdict, struct ip_vs_conn **cpp);
679
680 struct ip_vs_conn *
681 (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app,
682 const struct iphdr *iph, unsigned int proto_off,
683 int inverse);
684
685 struct ip_vs_conn *
686 (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app,
687 const struct iphdr *iph, unsigned int proto_off,
688 int inverse);
689
690 int (*state_transition)(struct ip_vs_conn *cp, int direction,
691 const struct sk_buff *skb,
692 struct ip_vs_app *app);
693
694 void (*timeout_change)(struct ip_vs_app *app, int flags);
695};
696
697
698/*
699 * IPVS core functions
700 * (from ip_vs_core.c)
701 */
702extern const char *ip_vs_proto_name(unsigned proto);
703extern void ip_vs_init_hash_table(struct list_head *table, int rows);
704#define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table(t, sizeof(t)/sizeof(t[0]))
705
706#define IP_VS_APP_TYPE_UNSPEC 0
707#define IP_VS_APP_TYPE_FTP 1
708
709/*
710 * ip_vs_conn handling functions
711 * (from ip_vs_conn.c)
712 */
713
714/*
715 * IPVS connection entry hash table
716 */
717#ifndef CONFIG_IP_VS_TAB_BITS
718#define CONFIG_IP_VS_TAB_BITS 12
719#endif
720/* make sure that IP_VS_CONN_TAB_BITS is located in [8, 20] */
721#if CONFIG_IP_VS_TAB_BITS < 8
722#define IP_VS_CONN_TAB_BITS 8
723#endif
724#if CONFIG_IP_VS_TAB_BITS > 20
725#define IP_VS_CONN_TAB_BITS 20
726#endif
727#if 8 <= CONFIG_IP_VS_TAB_BITS && CONFIG_IP_VS_TAB_BITS <= 20
728#define IP_VS_CONN_TAB_BITS CONFIG_IP_VS_TAB_BITS
729#endif
730#define IP_VS_CONN_TAB_SIZE (1 << IP_VS_CONN_TAB_BITS)
731#define IP_VS_CONN_TAB_MASK (IP_VS_CONN_TAB_SIZE - 1)
732
733enum {
734 IP_VS_DIR_INPUT = 0,
735 IP_VS_DIR_OUTPUT,
736 IP_VS_DIR_INPUT_ONLY,
737 IP_VS_DIR_LAST,
738};
739
740extern struct ip_vs_conn *ip_vs_conn_in_get
741(int protocol, __u32 s_addr, __u16 s_port, __u32 d_addr, __u16 d_port);
742extern struct ip_vs_conn *ip_vs_conn_out_get
743(int protocol, __u32 s_addr, __u16 s_port, __u32 d_addr, __u16 d_port);
744
745/* put back the conn without restarting its timer */
746static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
747{
748 atomic_dec(&cp->refcnt);
749}
750extern void ip_vs_conn_put(struct ip_vs_conn *cp);
751extern void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __u16 cport);
752
753extern struct ip_vs_conn *
754ip_vs_conn_new(int proto, __u32 caddr, __u16 cport, __u32 vaddr, __u16 vport,
755 __u32 daddr, __u16 dport, unsigned flags,
756 struct ip_vs_dest *dest);
757extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
758
759extern const char * ip_vs_state_name(__u16 proto, int state);
760
761extern void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp);
762extern int ip_vs_check_template(struct ip_vs_conn *ct);
763extern void ip_vs_secure_tcp_set(int on);
764extern void ip_vs_random_dropentry(void);
765extern int ip_vs_conn_init(void);
766extern void ip_vs_conn_cleanup(void);
767
768static inline void ip_vs_control_del(struct ip_vs_conn *cp)
769{
770 struct ip_vs_conn *ctl_cp = cp->control;
771 if (!ctl_cp) {
772 IP_VS_ERR("request control DEL for uncontrolled: "
773 "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
774 NIPQUAD(cp->caddr),ntohs(cp->cport),
775 NIPQUAD(cp->vaddr),ntohs(cp->vport));
776 return;
777 }
778
779 IP_VS_DBG(7, "DELeting control for: "
780 "cp.dst=%d.%d.%d.%d:%d ctl_cp.dst=%d.%d.%d.%d:%d\n",
781 NIPQUAD(cp->caddr),ntohs(cp->cport),
782 NIPQUAD(ctl_cp->caddr),ntohs(ctl_cp->cport));
783
784 cp->control = NULL;
785 if (atomic_read(&ctl_cp->n_control) == 0) {
786 IP_VS_ERR("BUG control DEL with n=0 : "
787 "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
788 NIPQUAD(cp->caddr),ntohs(cp->cport),
789 NIPQUAD(cp->vaddr),ntohs(cp->vport));
790 return;
791 }
792 atomic_dec(&ctl_cp->n_control);
793}
794
795static inline void
796ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)
797{
798 if (cp->control) {
799 IP_VS_ERR("request control ADD for already controlled: "
800 "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
801 NIPQUAD(cp->caddr),ntohs(cp->cport),
802 NIPQUAD(cp->vaddr),ntohs(cp->vport));
803 ip_vs_control_del(cp);
804 }
805
806 IP_VS_DBG(7, "ADDing control for: "
807 "cp.dst=%d.%d.%d.%d:%d ctl_cp.dst=%d.%d.%d.%d:%d\n",
808 NIPQUAD(cp->caddr),ntohs(cp->cport),
809 NIPQUAD(ctl_cp->caddr),ntohs(ctl_cp->cport));
810
811 cp->control = ctl_cp;
812 atomic_inc(&ctl_cp->n_control);
813}
814
815
816/*
817 * IPVS application functions
818 * (from ip_vs_app.c)
819 */
820#define IP_VS_APP_MAX_PORTS 8
821extern int register_ip_vs_app(struct ip_vs_app *app);
822extern void unregister_ip_vs_app(struct ip_vs_app *app);
823extern int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
824extern void ip_vs_unbind_app(struct ip_vs_conn *cp);
825extern int
826register_ip_vs_app_inc(struct ip_vs_app *app, __u16 proto, __u16 port);
827extern int ip_vs_app_inc_get(struct ip_vs_app *inc);
828extern void ip_vs_app_inc_put(struct ip_vs_app *inc);
829
830extern int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff **pskb);
831extern int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff **pskb);
832extern int ip_vs_skb_replace(struct sk_buff *skb, int pri,
833 char *o_buf, int o_len, char *n_buf, int n_len);
834extern int ip_vs_app_init(void);
835extern void ip_vs_app_cleanup(void);
836
837
838/*
839 * IPVS protocol functions (from ip_vs_proto.c)
840 */
841extern int ip_vs_protocol_init(void);
842extern void ip_vs_protocol_cleanup(void);
843extern void ip_vs_protocol_timeout_change(int flags);
844extern int *ip_vs_create_timeout_table(int *table, int size);
845extern int
846ip_vs_set_state_timeout(int *table, int num, char **names, char *name, int to);
847extern void
848ip_vs_tcpudp_debug_packet(struct ip_vs_protocol *pp, const struct sk_buff *skb,
849 int offset, const char *msg);
850
851extern struct ip_vs_protocol ip_vs_protocol_tcp;
852extern struct ip_vs_protocol ip_vs_protocol_udp;
853extern struct ip_vs_protocol ip_vs_protocol_icmp;
854extern struct ip_vs_protocol ip_vs_protocol_esp;
855extern struct ip_vs_protocol ip_vs_protocol_ah;
856
857
858/*
859 * Registering/unregistering scheduler functions
860 * (from ip_vs_sched.c)
861 */
862extern int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
863extern int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
864extern int ip_vs_bind_scheduler(struct ip_vs_service *svc,
865 struct ip_vs_scheduler *scheduler);
866extern int ip_vs_unbind_scheduler(struct ip_vs_service *svc);
867extern struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name);
868extern void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler);
869extern struct ip_vs_conn *
870ip_vs_schedule(struct ip_vs_service *svc, const struct sk_buff *skb);
871extern int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
872 struct ip_vs_protocol *pp);
873
874
875/*
876 * IPVS control data and functions (from ip_vs_ctl.c)
877 */
878extern int sysctl_ip_vs_cache_bypass;
879extern int sysctl_ip_vs_expire_nodest_conn;
880extern int sysctl_ip_vs_expire_quiescent_template;
881extern int sysctl_ip_vs_sync_threshold[2];
882extern int sysctl_ip_vs_nat_icmp_send;
883extern struct ip_vs_stats ip_vs_stats;
884
885extern struct ip_vs_service *
886ip_vs_service_get(__u32 fwmark, __u16 protocol, __u32 vaddr, __u16 vport);
887
888static inline void ip_vs_service_put(struct ip_vs_service *svc)
889{
890 atomic_dec(&svc->usecnt);
891}
892
893extern struct ip_vs_dest *
894ip_vs_lookup_real_service(__u16 protocol, __u32 daddr, __u16 dport);
895extern int ip_vs_use_count_inc(void);
896extern void ip_vs_use_count_dec(void);
897extern int ip_vs_control_init(void);
898extern void ip_vs_control_cleanup(void);
899
900
901/*
902 * IPVS sync daemon data and function prototypes
903 * (from ip_vs_sync.c)
904 */
905extern volatile int ip_vs_sync_state;
906extern volatile int ip_vs_master_syncid;
907extern volatile int ip_vs_backup_syncid;
908extern char ip_vs_master_mcast_ifn[IP_VS_IFNAME_MAXLEN];
909extern char ip_vs_backup_mcast_ifn[IP_VS_IFNAME_MAXLEN];
910extern int start_sync_thread(int state, char *mcast_ifn, __u8 syncid);
911extern int stop_sync_thread(int state);
912extern void ip_vs_sync_conn(struct ip_vs_conn *cp);
913
914
915/*
916 * IPVS rate estimator prototypes (from ip_vs_est.c)
917 */
918extern int ip_vs_new_estimator(struct ip_vs_stats *stats);
919extern void ip_vs_kill_estimator(struct ip_vs_stats *stats);
920extern void ip_vs_zero_estimator(struct ip_vs_stats *stats);
921
922/*
923 * Various IPVS packet transmitters (from ip_vs_xmit.c)
924 */
925extern int ip_vs_null_xmit
926(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
927extern int ip_vs_bypass_xmit
928(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
929extern int ip_vs_nat_xmit
930(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
931extern int ip_vs_tunnel_xmit
932(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
933extern int ip_vs_dr_xmit
934(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
935extern int ip_vs_icmp_xmit
936(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, int offset);
937extern void ip_vs_dst_reset(struct ip_vs_dest *dest);
938
939
940/*
941 * This is a simple mechanism to ignore packets when
942 * we are loaded. Just set ip_vs_drop_rate to 'n' and
943 * we start to drop 1/rate of the packets
944 */
945extern int ip_vs_drop_rate;
946extern int ip_vs_drop_counter;
947
948static __inline__ int ip_vs_todrop(void)
949{
950 if (!ip_vs_drop_rate) return 0;
951 if (--ip_vs_drop_counter > 0) return 0;
952 ip_vs_drop_counter = ip_vs_drop_rate;
953 return 1;
954}
955
956/*
957 * ip_vs_fwd_tag returns the forwarding tag of the connection
958 */
959#define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK)
960
961extern __inline__ char ip_vs_fwd_tag(struct ip_vs_conn *cp)
962{
963 char fwd;
964
965 switch (IP_VS_FWD_METHOD(cp)) {
966 case IP_VS_CONN_F_MASQ:
967 fwd = 'M'; break;
968 case IP_VS_CONN_F_LOCALNODE:
969 fwd = 'L'; break;
970 case IP_VS_CONN_F_TUNNEL:
971 fwd = 'T'; break;
972 case IP_VS_CONN_F_DROUTE:
973 fwd = 'R'; break;
974 case IP_VS_CONN_F_BYPASS:
975 fwd = 'B'; break;
976 default:
977 fwd = '?'; break;
978 }
979 return fwd;
980}
981
982extern int ip_vs_make_skb_writable(struct sk_buff **pskb, int len);
983extern void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,
984 struct ip_vs_conn *cp, int dir);
985
986extern u16 ip_vs_checksum_complete(struct sk_buff *skb, int offset);
987
988static inline u16 ip_vs_check_diff(u32 old, u32 new, u16 oldsum)
989{
990 u32 diff[2] = { old, new };
991
992 return csum_fold(csum_partial((char *) diff, sizeof(diff),
993 oldsum ^ 0xFFFF));
994}
995
996#endif /* __KERNEL__ */
997
998#endif /* _IP_VS_H */
This page took 0.115919 seconds and 5 git commands to generate.