]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - include/net/ip_vs.h
Merge branch 'merge' of git://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc
[mirror_ubuntu-focal-kernel.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 */
da413908 10#include <linux/types.h> /* For __beXX types in userland */
1da177e4
LT
11
12#define IP_VS_VERSION_CODE 0x010201
13#define NVERSION(version) \
14 (version >> 16) & 0xFF, \
15 (version >> 8) & 0xFF, \
16 version & 0xFF
17
18/*
19 * Virtual Service Flags
20 */
21#define IP_VS_SVC_F_PERSISTENT 0x0001 /* persistent port */
22#define IP_VS_SVC_F_HASHED 0x0002 /* hashed entry */
23
24/*
25 * Destination Server Flags
26 */
27#define IP_VS_DEST_F_AVAILABLE 0x0001 /* server is available */
28#define IP_VS_DEST_F_OVERLOAD 0x0002 /* server is overloaded */
29
30/*
31 * IPVS sync daemon states
32 */
33#define IP_VS_STATE_NONE 0x0000 /* daemon is stopped */
34#define IP_VS_STATE_MASTER 0x0001 /* started as master */
35#define IP_VS_STATE_BACKUP 0x0002 /* started as backup */
36
37/*
38 * IPVS socket options
39 */
40#define IP_VS_BASE_CTL (64+1024+64) /* base */
41
42#define IP_VS_SO_SET_NONE IP_VS_BASE_CTL /* just peek */
43#define IP_VS_SO_SET_INSERT (IP_VS_BASE_CTL+1)
44#define IP_VS_SO_SET_ADD (IP_VS_BASE_CTL+2)
45#define IP_VS_SO_SET_EDIT (IP_VS_BASE_CTL+3)
46#define IP_VS_SO_SET_DEL (IP_VS_BASE_CTL+4)
47#define IP_VS_SO_SET_FLUSH (IP_VS_BASE_CTL+5)
48#define IP_VS_SO_SET_LIST (IP_VS_BASE_CTL+6)
49#define IP_VS_SO_SET_ADDDEST (IP_VS_BASE_CTL+7)
50#define IP_VS_SO_SET_DELDEST (IP_VS_BASE_CTL+8)
51#define IP_VS_SO_SET_EDITDEST (IP_VS_BASE_CTL+9)
52#define IP_VS_SO_SET_TIMEOUT (IP_VS_BASE_CTL+10)
53#define IP_VS_SO_SET_STARTDAEMON (IP_VS_BASE_CTL+11)
54#define IP_VS_SO_SET_STOPDAEMON (IP_VS_BASE_CTL+12)
55#define IP_VS_SO_SET_RESTORE (IP_VS_BASE_CTL+13)
56#define IP_VS_SO_SET_SAVE (IP_VS_BASE_CTL+14)
57#define IP_VS_SO_SET_ZERO (IP_VS_BASE_CTL+15)
58#define IP_VS_SO_SET_MAX IP_VS_SO_SET_ZERO
59
60#define IP_VS_SO_GET_VERSION IP_VS_BASE_CTL
61#define IP_VS_SO_GET_INFO (IP_VS_BASE_CTL+1)
62#define IP_VS_SO_GET_SERVICES (IP_VS_BASE_CTL+2)
63#define IP_VS_SO_GET_SERVICE (IP_VS_BASE_CTL+3)
64#define IP_VS_SO_GET_DESTS (IP_VS_BASE_CTL+4)
65#define IP_VS_SO_GET_DEST (IP_VS_BASE_CTL+5) /* not used now */
66#define IP_VS_SO_GET_TIMEOUT (IP_VS_BASE_CTL+6)
67#define IP_VS_SO_GET_DAEMON (IP_VS_BASE_CTL+7)
68#define IP_VS_SO_GET_MAX IP_VS_SO_GET_DAEMON
69
70
71/*
72 * IPVS Connection Flags
73 */
74#define IP_VS_CONN_F_FWD_MASK 0x0007 /* mask for the fwd methods */
75#define IP_VS_CONN_F_MASQ 0x0000 /* masquerading/NAT */
76#define IP_VS_CONN_F_LOCALNODE 0x0001 /* local node */
77#define IP_VS_CONN_F_TUNNEL 0x0002 /* tunneling */
78#define IP_VS_CONN_F_DROUTE 0x0003 /* direct routing */
79#define IP_VS_CONN_F_BYPASS 0x0004 /* cache bypass */
80#define IP_VS_CONN_F_SYNC 0x0020 /* entry created by sync */
81#define IP_VS_CONN_F_HASHED 0x0040 /* hashed entry */
82#define IP_VS_CONN_F_NOOUTPUT 0x0080 /* no output packets */
83#define IP_VS_CONN_F_INACTIVE 0x0100 /* not established */
84#define IP_VS_CONN_F_OUT_SEQ 0x0200 /* must do output seq adjust */
85#define IP_VS_CONN_F_IN_SEQ 0x0400 /* must do input seq adjust */
86#define IP_VS_CONN_F_SEQ_MASK 0x0600 /* in/out sequence mask */
87#define IP_VS_CONN_F_NO_CPORT 0x0800 /* no client port set yet */
87375ab4 88#define IP_VS_CONN_F_TEMPLATE 0x1000 /* template, not connection */
1da177e4
LT
89
90/* Move it to better place one day, for now keep it unique */
91#define NFC_IPVS_PROPERTY 0x10000
92
93#define IP_VS_SCHEDNAME_MAXLEN 16
94#define IP_VS_IFNAME_MAXLEN 16
95
96
97/*
98 * The struct ip_vs_service_user and struct ip_vs_dest_user are
99 * used to set IPVS rules through setsockopt.
100 */
101struct ip_vs_service_user {
102 /* virtual service addresses */
103 u_int16_t protocol;
014d730d
AV
104 __be32 addr; /* virtual ip address */
105 __be16 port;
1da177e4
LT
106 u_int32_t fwmark; /* firwall mark of service */
107
108 /* virtual service options */
109 char sched_name[IP_VS_SCHEDNAME_MAXLEN];
110 unsigned flags; /* virtual service flags */
111 unsigned timeout; /* persistent timeout in sec */
014d730d 112 __be32 netmask; /* persistent netmask */
1da177e4
LT
113};
114
115
116struct ip_vs_dest_user {
117 /* destination server address */
014d730d
AV
118 __be32 addr;
119 __be16 port;
1da177e4
LT
120
121 /* real server options */
122 unsigned conn_flags; /* connection flags */
123 int weight; /* destination weight */
124
125 /* thresholds for active connections */
126 u_int32_t u_threshold; /* upper threshold */
127 u_int32_t l_threshold; /* lower threshold */
128};
129
130
131/*
132 * IPVS statistics object (for user space)
133 */
134struct ip_vs_stats_user
135{
136 __u32 conns; /* connections scheduled */
137 __u32 inpkts; /* incoming packets */
138 __u32 outpkts; /* outgoing packets */
139 __u64 inbytes; /* incoming bytes */
140 __u64 outbytes; /* outgoing bytes */
141
142 __u32 cps; /* current connection rate */
143 __u32 inpps; /* current in packet rate */
144 __u32 outpps; /* current out packet rate */
145 __u32 inbps; /* current in byte rate */
146 __u32 outbps; /* current out byte rate */
147};
148
149
150/* The argument to IP_VS_SO_GET_INFO */
151struct ip_vs_getinfo {
152 /* version number */
153 unsigned int version;
154
155 /* size of connection hash table */
156 unsigned int size;
157
158 /* number of virtual services */
159 unsigned int num_services;
160};
161
162
163/* The argument to IP_VS_SO_GET_SERVICE */
164struct ip_vs_service_entry {
165 /* which service: user fills in these */
166 u_int16_t protocol;
014d730d
AV
167 __be32 addr; /* virtual address */
168 __be16 port;
1da177e4
LT
169 u_int32_t fwmark; /* firwall mark of service */
170
171 /* service options */
172 char sched_name[IP_VS_SCHEDNAME_MAXLEN];
173 unsigned flags; /* virtual service flags */
174 unsigned timeout; /* persistent timeout */
014d730d 175 __be32 netmask; /* persistent netmask */
1da177e4
LT
176
177 /* number of real servers */
178 unsigned int num_dests;
179
180 /* statistics */
181 struct ip_vs_stats_user stats;
182};
183
184
185struct ip_vs_dest_entry {
014d730d
AV
186 __be32 addr; /* destination address */
187 __be16 port;
1da177e4
LT
188 unsigned conn_flags; /* connection flags */
189 int weight; /* destination weight */
190
191 u_int32_t u_threshold; /* upper threshold */
192 u_int32_t l_threshold; /* lower threshold */
193
194 u_int32_t activeconns; /* active connections */
195 u_int32_t inactconns; /* inactive connections */
196 u_int32_t persistconns; /* persistent connections */
197
198 /* statistics */
199 struct ip_vs_stats_user stats;
200};
201
202
203/* The argument to IP_VS_SO_GET_DESTS */
204struct ip_vs_get_dests {
205 /* which service: user fills in these */
206 u_int16_t protocol;
014d730d
AV
207 __be32 addr; /* virtual address */
208 __be16 port;
1da177e4
LT
209 u_int32_t fwmark; /* firwall mark of service */
210
211 /* number of real servers */
212 unsigned int num_dests;
213
214 /* the real servers */
215 struct ip_vs_dest_entry entrytable[0];
216};
217
218
219/* The argument to IP_VS_SO_GET_SERVICES */
220struct ip_vs_get_services {
221 /* number of virtual services */
222 unsigned int num_services;
223
224 /* service table */
225 struct ip_vs_service_entry entrytable[0];
226};
227
228
229/* The argument to IP_VS_SO_GET_TIMEOUT */
230struct ip_vs_timeout_user {
231 int tcp_timeout;
232 int tcp_fin_timeout;
233 int udp_timeout;
234};
235
236
237/* The argument to IP_VS_SO_GET_DAEMON */
238struct ip_vs_daemon_user {
239 /* sync daemon state (master/backup) */
240 int state;
241
242 /* multicast interface name */
243 char mcast_ifn[IP_VS_IFNAME_MAXLEN];
244
245 /* SyncID we belong to */
246 int syncid;
247};
248
249
250#ifdef __KERNEL__
251
1da177e4
LT
252#include <linux/list.h> /* for struct list_head */
253#include <linux/spinlock.h> /* for struct rwlock_t */
1da177e4 254#include <asm/atomic.h> /* for struct atomic_t */
1da177e4 255#include <linux/compiler.h>
14c85021 256#include <linux/timer.h>
1da177e4 257
14c85021 258#include <net/checksum.h>
1da177e4
LT
259
260#ifdef CONFIG_IP_VS_DEBUG
14c85021
ACM
261#include <linux/net.h>
262
1da177e4
LT
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
14c85021
ACM
431struct dst_entry;
432struct iphdr;
1da177e4
LT
433struct ip_vs_conn;
434struct ip_vs_app;
14c85021 435struct sk_buff;
1da177e4
LT
436
437struct 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 */
444
445 void (*init)(struct ip_vs_protocol *pp);
446
447 void (*exit)(struct ip_vs_protocol *pp);
448
449 int (*conn_schedule)(struct sk_buff *skb,
450 struct ip_vs_protocol *pp,
451 int *verdict, struct ip_vs_conn **cpp);
452
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);
459
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);
466
3db05fea 467 int (*snat_handler)(struct sk_buff *skb,
1da177e4
LT
468 struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
469
3db05fea 470 int (*dnat_handler)(struct sk_buff *skb,
1da177e4
LT
471 struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
472
473 int (*csum_check)(struct sk_buff *skb, struct ip_vs_protocol *pp);
474
475 const char *(*state_name)(int state);
476
477 int (*state_transition)(struct ip_vs_conn *cp, int direction,
478 const struct sk_buff *skb,
479 struct ip_vs_protocol *pp);
480
481 int (*register_app)(struct ip_vs_app *inc);
482
483 void (*unregister_app)(struct ip_vs_app *inc);
484
485 int (*app_conn_bind)(struct ip_vs_conn *cp);
486
487 void (*debug_packet)(struct ip_vs_protocol *pp,
488 const struct sk_buff *skb,
489 int offset,
490 const char *msg);
491
492 void (*timeout_change)(struct ip_vs_protocol *pp, int flags);
493
494 int (*set_state_timeout)(struct ip_vs_protocol *pp, char *sname, int to);
495};
496
497extern struct ip_vs_protocol * ip_vs_proto_get(unsigned short proto);
498
499/*
500 * IP_VS structure allocated for each dynamically scheduled connection
501 */
502struct ip_vs_conn {
503 struct list_head c_list; /* hashed list heads */
504
505 /* Protocol, addresses and port numbers */
014d730d
AV
506 __be32 caddr; /* client address */
507 __be32 vaddr; /* virtual address */
508 __be32 daddr; /* destination address */
509 __be16 cport;
510 __be16 vport;
511 __be16 dport;
1da177e4
LT
512 __u16 protocol; /* Which protocol (TCP/UDP) */
513
514 /* counter and timer */
515 atomic_t refcnt; /* reference count */
516 struct timer_list timer; /* Expiration timer */
517 volatile unsigned long timeout; /* timeout */
518
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 */
efac5276
RB
523 volatile __u16 old_state; /* old state, to be used for
524 * state transition triggerd
525 * synchronization
526 */
1da177e4
LT
527
528 /* Control members */
529 struct ip_vs_conn *control; /* Master control connection */
530 atomic_t n_control; /* Number of controlled ones */
531 struct ip_vs_dest *dest; /* real server */
532 atomic_t in_pkts; /* incoming packet counter */
533
534 /* packet transmitter for different forwarding methods. If it
535 mangles the packet, it must return NF_DROP or better NF_STOLEN,
536 otherwise this must be changed to a sk_buff **.
537 */
538 int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp,
539 struct ip_vs_protocol *pp);
540
541 /* Note: we can group the following members into a structure,
542 in order to save more space, and the following members are
543 only used in VS/NAT anyway */
544 struct ip_vs_app *app; /* bound ip_vs_app object */
545 void *app_data; /* Application private data */
546 struct ip_vs_seq in_seq; /* incoming seq. struct */
547 struct ip_vs_seq out_seq; /* outgoing seq. struct */
548};
549
550
551/*
552 * The information about the virtual service offered to the net
553 * and the forwarding entries
554 */
555struct ip_vs_service {
556 struct list_head s_list; /* for normal service table */
557 struct list_head f_list; /* for fwmark-based service table */
558 atomic_t refcnt; /* reference counter */
559 atomic_t usecnt; /* use counter */
560
561 __u16 protocol; /* which protocol (TCP/UDP) */
014d730d
AV
562 __be32 addr; /* IP address for virtual service */
563 __be16 port; /* port number for the service */
1da177e4
LT
564 __u32 fwmark; /* firewall mark of the service */
565 unsigned flags; /* service status flags */
566 unsigned timeout; /* persistent timeout in ticks */
014d730d 567 __be32 netmask; /* grouping granularity */
1da177e4
LT
568
569 struct list_head destinations; /* real server d-linked list */
570 __u32 num_dests; /* number of servers */
571 struct ip_vs_stats stats; /* statistics for the service */
572 struct ip_vs_app *inc; /* bind conns to this app inc */
573
574 /* for scheduling */
575 struct ip_vs_scheduler *scheduler; /* bound scheduler object */
576 rwlock_t sched_lock; /* lock sched_data */
577 void *sched_data; /* scheduler application data */
578};
579
580
581/*
582 * The real server destination forwarding entry
583 * with ip address, port number, and so on.
584 */
585struct ip_vs_dest {
586 struct list_head n_list; /* for the dests in the service */
587 struct list_head d_list; /* for table with all the dests */
588
014d730d
AV
589 __be32 addr; /* IP address of the server */
590 __be16 port; /* port number of the server */
1da177e4
LT
591 volatile unsigned flags; /* dest status flags */
592 atomic_t conn_flags; /* flags to copy to conn */
593 atomic_t weight; /* server weight */
594
595 atomic_t refcnt; /* reference counter */
596 struct ip_vs_stats stats; /* statistics */
597
598 /* connection counters and thresholds */
599 atomic_t activeconns; /* active connections */
600 atomic_t inactconns; /* inactive connections */
601 atomic_t persistconns; /* persistent connections */
602 __u32 u_threshold; /* upper threshold */
603 __u32 l_threshold; /* lower threshold */
604
605 /* for destination cache */
606 spinlock_t dst_lock; /* lock of dst_cache */
607 struct dst_entry *dst_cache; /* destination cache entry */
608 u32 dst_rtos; /* RT_TOS(tos) for dst */
609
610 /* for virtual service */
611 struct ip_vs_service *svc; /* service it belongs to */
612 __u16 protocol; /* which protocol (TCP/UDP) */
014d730d
AV
613 __be32 vaddr; /* virtual IP address */
614 __be16 vport; /* virtual port number */
1da177e4
LT
615 __u32 vfwmark; /* firewall mark of service */
616};
617
618
619/*
620 * The scheduler object
621 */
622struct ip_vs_scheduler {
623 struct list_head n_list; /* d-linked list head */
624 char *name; /* scheduler name */
625 atomic_t refcnt; /* reference counter */
626 struct module *module; /* THIS_MODULE/NULL */
627
628 /* scheduler initializing service */
629 int (*init_service)(struct ip_vs_service *svc);
630 /* scheduling service finish */
631 int (*done_service)(struct ip_vs_service *svc);
632 /* scheduler updating service */
633 int (*update_service)(struct ip_vs_service *svc);
634
635 /* selecting a server from the given service */
636 struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc,
637 const struct sk_buff *skb);
638};
639
640
641/*
642 * The application module object (a.k.a. app incarnation)
643 */
644struct ip_vs_app
645{
646 struct list_head a_list; /* member in app list */
647 int type; /* IP_VS_APP_TYPE_xxx */
648 char *name; /* application module name */
649 __u16 protocol;
650 struct module *module; /* THIS_MODULE/NULL */
651 struct list_head incs_list; /* list of incarnations */
652
653 /* members for application incarnations */
654 struct list_head p_list; /* member in proto app list */
655 struct ip_vs_app *app; /* its real application */
014d730d 656 __be16 port; /* port number in net order */
1da177e4
LT
657 atomic_t usecnt; /* usage counter */
658
659 /* output hook: return false if can't linearize. diff set for TCP. */
660 int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *,
3db05fea 661 struct sk_buff *, int *diff);
1da177e4
LT
662
663 /* input hook: return false if can't linearize. diff set for TCP. */
664 int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *,
3db05fea 665 struct sk_buff *, int *diff);
1da177e4
LT
666
667 /* ip_vs_app initializer */
668 int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *);
669
670 /* ip_vs_app finish */
671 int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *);
672
673
674 /* not used now */
675 int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *,
676 struct ip_vs_protocol *);
677
678 void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *);
679
680 int * timeout_table;
681 int * timeouts;
682 int timeouts_size;
683
684 int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app,
685 int *verdict, struct ip_vs_conn **cpp);
686
687 struct ip_vs_conn *
688 (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app,
689 const struct iphdr *iph, unsigned int proto_off,
690 int inverse);
691
692 struct ip_vs_conn *
693 (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app,
694 const struct iphdr *iph, unsigned int proto_off,
695 int inverse);
696
697 int (*state_transition)(struct ip_vs_conn *cp, int direction,
698 const struct sk_buff *skb,
699 struct ip_vs_app *app);
700
701 void (*timeout_change)(struct ip_vs_app *app, int flags);
702};
703
704
705/*
706 * IPVS core functions
707 * (from ip_vs_core.c)
708 */
709extern const char *ip_vs_proto_name(unsigned proto);
710extern void ip_vs_init_hash_table(struct list_head *table, int rows);
711#define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table(t, sizeof(t)/sizeof(t[0]))
712
713#define IP_VS_APP_TYPE_UNSPEC 0
714#define IP_VS_APP_TYPE_FTP 1
715
716/*
717 * ip_vs_conn handling functions
718 * (from ip_vs_conn.c)
719 */
720
721/*
722 * IPVS connection entry hash table
723 */
724#ifndef CONFIG_IP_VS_TAB_BITS
725#define CONFIG_IP_VS_TAB_BITS 12
726#endif
727/* make sure that IP_VS_CONN_TAB_BITS is located in [8, 20] */
728#if CONFIG_IP_VS_TAB_BITS < 8
729#define IP_VS_CONN_TAB_BITS 8
730#endif
731#if CONFIG_IP_VS_TAB_BITS > 20
732#define IP_VS_CONN_TAB_BITS 20
733#endif
734#if 8 <= CONFIG_IP_VS_TAB_BITS && CONFIG_IP_VS_TAB_BITS <= 20
735#define IP_VS_CONN_TAB_BITS CONFIG_IP_VS_TAB_BITS
736#endif
737#define IP_VS_CONN_TAB_SIZE (1 << IP_VS_CONN_TAB_BITS)
738#define IP_VS_CONN_TAB_MASK (IP_VS_CONN_TAB_SIZE - 1)
739
740enum {
741 IP_VS_DIR_INPUT = 0,
742 IP_VS_DIR_OUTPUT,
743 IP_VS_DIR_INPUT_ONLY,
744 IP_VS_DIR_LAST,
745};
746
747extern struct ip_vs_conn *ip_vs_conn_in_get
014d730d 748(int protocol, __be32 s_addr, __be16 s_port, __be32 d_addr, __be16 d_port);
87375ab4 749extern struct ip_vs_conn *ip_vs_ct_in_get
014d730d 750(int protocol, __be32 s_addr, __be16 s_port, __be32 d_addr, __be16 d_port);
1da177e4 751extern struct ip_vs_conn *ip_vs_conn_out_get
014d730d 752(int protocol, __be32 s_addr, __be16 s_port, __be32 d_addr, __be16 d_port);
1da177e4
LT
753
754/* put back the conn without restarting its timer */
755static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
756{
757 atomic_dec(&cp->refcnt);
758}
759extern void ip_vs_conn_put(struct ip_vs_conn *cp);
014d730d 760extern void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport);
1da177e4
LT
761
762extern struct ip_vs_conn *
014d730d
AV
763ip_vs_conn_new(int proto, __be32 caddr, __be16 cport, __be32 vaddr, __be16 vport,
764 __be32 daddr, __be16 dport, unsigned flags,
1da177e4
LT
765 struct ip_vs_dest *dest);
766extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
767
768extern const char * ip_vs_state_name(__u16 proto, int state);
769
770extern void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp);
771extern int ip_vs_check_template(struct ip_vs_conn *ct);
772extern void ip_vs_secure_tcp_set(int on);
773extern void ip_vs_random_dropentry(void);
774extern int ip_vs_conn_init(void);
775extern void ip_vs_conn_cleanup(void);
776
777static inline void ip_vs_control_del(struct ip_vs_conn *cp)
778{
779 struct ip_vs_conn *ctl_cp = cp->control;
780 if (!ctl_cp) {
781 IP_VS_ERR("request control DEL for uncontrolled: "
782 "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
783 NIPQUAD(cp->caddr),ntohs(cp->cport),
784 NIPQUAD(cp->vaddr),ntohs(cp->vport));
785 return;
786 }
787
788 IP_VS_DBG(7, "DELeting control for: "
789 "cp.dst=%d.%d.%d.%d:%d ctl_cp.dst=%d.%d.%d.%d:%d\n",
790 NIPQUAD(cp->caddr),ntohs(cp->cport),
791 NIPQUAD(ctl_cp->caddr),ntohs(ctl_cp->cport));
792
793 cp->control = NULL;
794 if (atomic_read(&ctl_cp->n_control) == 0) {
795 IP_VS_ERR("BUG control DEL with n=0 : "
796 "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
797 NIPQUAD(cp->caddr),ntohs(cp->cport),
798 NIPQUAD(cp->vaddr),ntohs(cp->vport));
799 return;
800 }
801 atomic_dec(&ctl_cp->n_control);
802}
803
804static inline void
805ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)
806{
807 if (cp->control) {
808 IP_VS_ERR("request control ADD for already controlled: "
809 "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
810 NIPQUAD(cp->caddr),ntohs(cp->cport),
811 NIPQUAD(cp->vaddr),ntohs(cp->vport));
812 ip_vs_control_del(cp);
813 }
814
815 IP_VS_DBG(7, "ADDing control for: "
816 "cp.dst=%d.%d.%d.%d:%d ctl_cp.dst=%d.%d.%d.%d:%d\n",
817 NIPQUAD(cp->caddr),ntohs(cp->cport),
818 NIPQUAD(ctl_cp->caddr),ntohs(ctl_cp->cport));
819
820 cp->control = ctl_cp;
821 atomic_inc(&ctl_cp->n_control);
822}
823
824
825/*
826 * IPVS application functions
827 * (from ip_vs_app.c)
828 */
829#define IP_VS_APP_MAX_PORTS 8
830extern int register_ip_vs_app(struct ip_vs_app *app);
831extern void unregister_ip_vs_app(struct ip_vs_app *app);
832extern int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
833extern void ip_vs_unbind_app(struct ip_vs_conn *cp);
834extern int
835register_ip_vs_app_inc(struct ip_vs_app *app, __u16 proto, __u16 port);
836extern int ip_vs_app_inc_get(struct ip_vs_app *inc);
837extern void ip_vs_app_inc_put(struct ip_vs_app *inc);
838
3db05fea
HX
839extern int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb);
840extern int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb);
dd0fc66f 841extern int ip_vs_skb_replace(struct sk_buff *skb, gfp_t pri,
1da177e4
LT
842 char *o_buf, int o_len, char *n_buf, int n_len);
843extern int ip_vs_app_init(void);
844extern void ip_vs_app_cleanup(void);
845
846
847/*
848 * IPVS protocol functions (from ip_vs_proto.c)
849 */
850extern int ip_vs_protocol_init(void);
851extern void ip_vs_protocol_cleanup(void);
852extern void ip_vs_protocol_timeout_change(int flags);
853extern int *ip_vs_create_timeout_table(int *table, int size);
854extern int
855ip_vs_set_state_timeout(int *table, int num, char **names, char *name, int to);
856extern void
857ip_vs_tcpudp_debug_packet(struct ip_vs_protocol *pp, const struct sk_buff *skb,
858 int offset, const char *msg);
859
860extern struct ip_vs_protocol ip_vs_protocol_tcp;
861extern struct ip_vs_protocol ip_vs_protocol_udp;
862extern struct ip_vs_protocol ip_vs_protocol_icmp;
863extern struct ip_vs_protocol ip_vs_protocol_esp;
864extern struct ip_vs_protocol ip_vs_protocol_ah;
865
866
867/*
868 * Registering/unregistering scheduler functions
869 * (from ip_vs_sched.c)
870 */
871extern int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
872extern int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
873extern int ip_vs_bind_scheduler(struct ip_vs_service *svc,
874 struct ip_vs_scheduler *scheduler);
875extern int ip_vs_unbind_scheduler(struct ip_vs_service *svc);
876extern struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name);
877extern void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler);
878extern struct ip_vs_conn *
879ip_vs_schedule(struct ip_vs_service *svc, const struct sk_buff *skb);
880extern int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
881 struct ip_vs_protocol *pp);
882
883
884/*
885 * IPVS control data and functions (from ip_vs_ctl.c)
886 */
887extern int sysctl_ip_vs_cache_bypass;
888extern int sysctl_ip_vs_expire_nodest_conn;
889extern int sysctl_ip_vs_expire_quiescent_template;
890extern int sysctl_ip_vs_sync_threshold[2];
891extern int sysctl_ip_vs_nat_icmp_send;
892extern struct ip_vs_stats ip_vs_stats;
893
894extern struct ip_vs_service *
014d730d 895ip_vs_service_get(__u32 fwmark, __u16 protocol, __be32 vaddr, __be16 vport);
1da177e4
LT
896
897static inline void ip_vs_service_put(struct ip_vs_service *svc)
898{
899 atomic_dec(&svc->usecnt);
900}
901
902extern struct ip_vs_dest *
014d730d 903ip_vs_lookup_real_service(__u16 protocol, __be32 daddr, __be16 dport);
1da177e4
LT
904extern int ip_vs_use_count_inc(void);
905extern void ip_vs_use_count_dec(void);
906extern int ip_vs_control_init(void);
907extern void ip_vs_control_cleanup(void);
1e356f9c
RB
908extern struct ip_vs_dest *
909ip_vs_find_dest(__be32 daddr, __be16 dport,
910 __be32 vaddr, __be16 vport, __u16 protocol);
911extern struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp);
1da177e4
LT
912
913
914/*
915 * IPVS sync daemon data and function prototypes
916 * (from ip_vs_sync.c)
917 */
918extern volatile int ip_vs_sync_state;
919extern volatile int ip_vs_master_syncid;
920extern volatile int ip_vs_backup_syncid;
921extern char ip_vs_master_mcast_ifn[IP_VS_IFNAME_MAXLEN];
922extern char ip_vs_backup_mcast_ifn[IP_VS_IFNAME_MAXLEN];
923extern int start_sync_thread(int state, char *mcast_ifn, __u8 syncid);
924extern int stop_sync_thread(int state);
925extern void ip_vs_sync_conn(struct ip_vs_conn *cp);
926
927
928/*
929 * IPVS rate estimator prototypes (from ip_vs_est.c)
930 */
931extern int ip_vs_new_estimator(struct ip_vs_stats *stats);
932extern void ip_vs_kill_estimator(struct ip_vs_stats *stats);
933extern void ip_vs_zero_estimator(struct ip_vs_stats *stats);
934
935/*
936 * Various IPVS packet transmitters (from ip_vs_xmit.c)
937 */
938extern int ip_vs_null_xmit
939(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
940extern int ip_vs_bypass_xmit
941(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
942extern int ip_vs_nat_xmit
943(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
944extern int ip_vs_tunnel_xmit
945(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
946extern int ip_vs_dr_xmit
947(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
948extern int ip_vs_icmp_xmit
949(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, int offset);
950extern void ip_vs_dst_reset(struct ip_vs_dest *dest);
951
952
953/*
954 * This is a simple mechanism to ignore packets when
955 * we are loaded. Just set ip_vs_drop_rate to 'n' and
956 * we start to drop 1/rate of the packets
957 */
958extern int ip_vs_drop_rate;
959extern int ip_vs_drop_counter;
960
961static __inline__ int ip_vs_todrop(void)
962{
963 if (!ip_vs_drop_rate) return 0;
964 if (--ip_vs_drop_counter > 0) return 0;
965 ip_vs_drop_counter = ip_vs_drop_rate;
966 return 1;
967}
968
969/*
970 * ip_vs_fwd_tag returns the forwarding tag of the connection
971 */
972#define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK)
973
732db659 974static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp)
1da177e4
LT
975{
976 char fwd;
977
978 switch (IP_VS_FWD_METHOD(cp)) {
979 case IP_VS_CONN_F_MASQ:
980 fwd = 'M'; break;
981 case IP_VS_CONN_F_LOCALNODE:
982 fwd = 'L'; break;
983 case IP_VS_CONN_F_TUNNEL:
984 fwd = 'T'; break;
985 case IP_VS_CONN_F_DROUTE:
986 fwd = 'R'; break;
987 case IP_VS_CONN_F_BYPASS:
988 fwd = 'B'; break;
989 default:
990 fwd = '?'; break;
991 }
992 return fwd;
993}
994
1da177e4
LT
995extern void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,
996 struct ip_vs_conn *cp, int dir);
997
b1550f22 998extern __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset);
1da177e4 999
f9214b26 1000static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum)
1da177e4 1001{
f9214b26 1002 __be32 diff[2] = { ~old, new };
1da177e4 1003
f9214b26
AV
1004 return csum_partial((char *) diff, sizeof(diff), oldsum);
1005}
1006
1007static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum)
1008{
1009 __be16 diff[2] = { ~old, new };
1010
1011 return csum_partial((char *) diff, sizeof(diff), oldsum);
1da177e4
LT
1012}
1013
1014#endif /* __KERNEL__ */
1015
1016#endif /* _IP_VS_H */