blob: 7312c3dd309f2cc705a678f29be79a972780f2ec [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * IP Virtual Server
3 * data structure and functionality definitions
4 */
5
Julius Volzbc4768e2008-07-31 20:45:24 -07006#ifndef _NET_IP_VS_H
7#define _NET_IP_VS_H
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
Julius Volzbc4768e2008-07-31 20:45:24 -07009#include <linux/ip_vs.h> /* definitions shared with userland */
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
Julius Volzbc4768e2008-07-31 20:45:24 -070011/* old ipvsadm versions still include this file directly */
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#ifdef __KERNEL__
13
Julius Volzbc4768e2008-07-31 20:45:24 -070014#include <asm/types.h> /* for __uXX types */
15
16#include <linux/sysctl.h> /* for ctl_path */
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/list.h> /* for struct list_head */
18#include <linux/spinlock.h> /* for struct rwlock_t */
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/atomic.h> /* for struct atomic_t */
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/compiler.h>
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020021#include <linux/timer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020023#include <net/checksum.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25#ifdef CONFIG_IP_VS_DEBUG
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020026#include <linux/net.h>
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028extern int ip_vs_get_debug_level(void);
29#define IP_VS_DBG(level, msg...) \
30 do { \
31 if (level <= ip_vs_get_debug_level()) \
32 printk(KERN_DEBUG "IPVS: " msg); \
33 } while (0)
34#define IP_VS_DBG_RL(msg...) \
35 do { \
36 if (net_ratelimit()) \
37 printk(KERN_DEBUG "IPVS: " msg); \
38 } while (0)
39#define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) \
40 do { \
41 if (level <= ip_vs_get_debug_level()) \
42 pp->debug_packet(pp, skb, ofs, msg); \
43 } while (0)
44#define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) \
45 do { \
46 if (level <= ip_vs_get_debug_level() && \
47 net_ratelimit()) \
48 pp->debug_packet(pp, skb, ofs, msg); \
49 } while (0)
50#else /* NO DEBUGGING at ALL */
51#define IP_VS_DBG(level, msg...) do {} while (0)
52#define IP_VS_DBG_RL(msg...) do {} while (0)
53#define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) do {} while (0)
54#define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) do {} while (0)
55#endif
56
57#define IP_VS_BUG() BUG()
58#define IP_VS_ERR(msg...) printk(KERN_ERR "IPVS: " msg)
59#define IP_VS_INFO(msg...) printk(KERN_INFO "IPVS: " msg)
60#define IP_VS_WARNING(msg...) \
61 printk(KERN_WARNING "IPVS: " msg)
62#define IP_VS_ERR_RL(msg...) \
63 do { \
64 if (net_ratelimit()) \
65 printk(KERN_ERR "IPVS: " msg); \
66 } while (0)
67
68#ifdef CONFIG_IP_VS_DEBUG
69#define EnterFunction(level) \
70 do { \
71 if (level <= ip_vs_get_debug_level()) \
72 printk(KERN_DEBUG "Enter: %s, %s line %i\n", \
73 __FUNCTION__, __FILE__, __LINE__); \
74 } while (0)
75#define LeaveFunction(level) \
76 do { \
77 if (level <= ip_vs_get_debug_level()) \
78 printk(KERN_DEBUG "Leave: %s, %s line %i\n", \
79 __FUNCTION__, __FILE__, __LINE__); \
80 } while (0)
81#else
82#define EnterFunction(level) do {} while (0)
83#define LeaveFunction(level) do {} while (0)
84#endif
85
86#define IP_VS_WAIT_WHILE(expr) while (expr) { cpu_relax(); }
87
88
89/*
90 * The port number of FTP service (in network order).
91 */
92#define FTPPORT __constant_htons(21)
93#define FTPDATA __constant_htons(20)
94
95/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 * TCP State Values
97 */
98enum {
99 IP_VS_TCP_S_NONE = 0,
100 IP_VS_TCP_S_ESTABLISHED,
101 IP_VS_TCP_S_SYN_SENT,
102 IP_VS_TCP_S_SYN_RECV,
103 IP_VS_TCP_S_FIN_WAIT,
104 IP_VS_TCP_S_TIME_WAIT,
105 IP_VS_TCP_S_CLOSE,
106 IP_VS_TCP_S_CLOSE_WAIT,
107 IP_VS_TCP_S_LAST_ACK,
108 IP_VS_TCP_S_LISTEN,
109 IP_VS_TCP_S_SYNACK,
110 IP_VS_TCP_S_LAST
111};
112
113/*
114 * UDP State Values
115 */
116enum {
117 IP_VS_UDP_S_NORMAL,
118 IP_VS_UDP_S_LAST,
119};
120
121/*
122 * ICMP State Values
123 */
124enum {
125 IP_VS_ICMP_S_NORMAL,
126 IP_VS_ICMP_S_LAST,
127};
128
129/*
130 * Delta sequence info structure
131 * Each ip_vs_conn has 2 (output AND input seq. changes).
132 * Only used in the VS/NAT.
133 */
134struct ip_vs_seq {
135 __u32 init_seq; /* Add delta from this seq */
136 __u32 delta; /* Delta in sequence numbers */
137 __u32 previous_delta; /* Delta in sequence numbers
138 before last resized pkt */
139};
140
141
142/*
Sven Wegener3a14a312008-08-10 18:24:41 +0000143 * IPVS statistics objects
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 */
Sven Wegener3a14a312008-08-10 18:24:41 +0000145struct ip_vs_estimator {
146 struct list_head list;
147
148 u64 last_inbytes;
149 u64 last_outbytes;
150 u32 last_conns;
151 u32 last_inpkts;
152 u32 last_outpkts;
153
154 u32 cps;
155 u32 inpps;
156 u32 outpps;
157 u32 inbps;
158 u32 outbps;
159};
160
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161struct ip_vs_stats
162{
163 __u32 conns; /* connections scheduled */
164 __u32 inpkts; /* incoming packets */
165 __u32 outpkts; /* outgoing packets */
166 __u64 inbytes; /* incoming bytes */
167 __u64 outbytes; /* outgoing bytes */
168
169 __u32 cps; /* current connection rate */
170 __u32 inpps; /* current in packet rate */
171 __u32 outpps; /* current out packet rate */
172 __u32 inbps; /* current in byte rate */
173 __u32 outbps; /* current out byte rate */
174
Sven Wegener3a14a312008-08-10 18:24:41 +0000175 /*
176 * Don't add anything before the lock, because we use memcpy() to copy
177 * the members before the lock to struct ip_vs_stats_user in
178 * ip_vs_ctl.c.
179 */
180
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 spinlock_t lock; /* spin lock */
Sven Wegener3a14a312008-08-10 18:24:41 +0000182
183 struct ip_vs_estimator est; /* estimator */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184};
185
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -0200186struct dst_entry;
187struct iphdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188struct ip_vs_conn;
189struct ip_vs_app;
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -0200190struct sk_buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192struct ip_vs_protocol {
193 struct ip_vs_protocol *next;
194 char *name;
Julian Anastasov2ad17de2008-04-29 03:21:23 -0700195 u16 protocol;
196 u16 num_states;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 int dont_defrag;
198 atomic_t appcnt; /* counter of proto app incs */
199 int *timeout_table; /* protocol timeout table */
200
201 void (*init)(struct ip_vs_protocol *pp);
202
203 void (*exit)(struct ip_vs_protocol *pp);
204
205 int (*conn_schedule)(struct sk_buff *skb,
206 struct ip_vs_protocol *pp,
207 int *verdict, struct ip_vs_conn **cpp);
208
209 struct ip_vs_conn *
210 (*conn_in_get)(const struct sk_buff *skb,
211 struct ip_vs_protocol *pp,
212 const struct iphdr *iph,
213 unsigned int proto_off,
214 int inverse);
215
216 struct ip_vs_conn *
217 (*conn_out_get)(const struct sk_buff *skb,
218 struct ip_vs_protocol *pp,
219 const struct iphdr *iph,
220 unsigned int proto_off,
221 int inverse);
222
Herbert Xu3db05fe2007-10-15 00:53:15 -0700223 int (*snat_handler)(struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
225
Herbert Xu3db05fe2007-10-15 00:53:15 -0700226 int (*dnat_handler)(struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
228
229 int (*csum_check)(struct sk_buff *skb, struct ip_vs_protocol *pp);
230
231 const char *(*state_name)(int state);
232
233 int (*state_transition)(struct ip_vs_conn *cp, int direction,
234 const struct sk_buff *skb,
235 struct ip_vs_protocol *pp);
236
237 int (*register_app)(struct ip_vs_app *inc);
238
239 void (*unregister_app)(struct ip_vs_app *inc);
240
241 int (*app_conn_bind)(struct ip_vs_conn *cp);
242
243 void (*debug_packet)(struct ip_vs_protocol *pp,
244 const struct sk_buff *skb,
245 int offset,
246 const char *msg);
247
248 void (*timeout_change)(struct ip_vs_protocol *pp, int flags);
249
250 int (*set_state_timeout)(struct ip_vs_protocol *pp, char *sname, int to);
251};
252
253extern struct ip_vs_protocol * ip_vs_proto_get(unsigned short proto);
254
255/*
256 * IP_VS structure allocated for each dynamically scheduled connection
257 */
258struct ip_vs_conn {
259 struct list_head c_list; /* hashed list heads */
260
261 /* Protocol, addresses and port numbers */
Al Viro014d7302006-09-28 14:29:52 -0700262 __be32 caddr; /* client address */
263 __be32 vaddr; /* virtual address */
264 __be32 daddr; /* destination address */
265 __be16 cport;
266 __be16 vport;
267 __be16 dport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 __u16 protocol; /* Which protocol (TCP/UDP) */
269
270 /* counter and timer */
271 atomic_t refcnt; /* reference count */
272 struct timer_list timer; /* Expiration timer */
273 volatile unsigned long timeout; /* timeout */
274
275 /* Flags and state transition */
276 spinlock_t lock; /* lock for state transition */
277 volatile __u16 flags; /* status flags */
278 volatile __u16 state; /* state info */
Rumen G. Bogdanovskiefac5272007-11-07 02:36:55 -0800279 volatile __u16 old_state; /* old state, to be used for
280 * state transition triggerd
281 * synchronization
282 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284 /* Control members */
285 struct ip_vs_conn *control; /* Master control connection */
286 atomic_t n_control; /* Number of controlled ones */
287 struct ip_vs_dest *dest; /* real server */
288 atomic_t in_pkts; /* incoming packet counter */
289
290 /* packet transmitter for different forwarding methods. If it
291 mangles the packet, it must return NF_DROP or better NF_STOLEN,
292 otherwise this must be changed to a sk_buff **.
293 */
294 int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp,
295 struct ip_vs_protocol *pp);
296
297 /* Note: we can group the following members into a structure,
298 in order to save more space, and the following members are
299 only used in VS/NAT anyway */
300 struct ip_vs_app *app; /* bound ip_vs_app object */
301 void *app_data; /* Application private data */
302 struct ip_vs_seq in_seq; /* incoming seq. struct */
303 struct ip_vs_seq out_seq; /* outgoing seq. struct */
304};
305
306
307/*
308 * The information about the virtual service offered to the net
309 * and the forwarding entries
310 */
311struct ip_vs_service {
312 struct list_head s_list; /* for normal service table */
313 struct list_head f_list; /* for fwmark-based service table */
314 atomic_t refcnt; /* reference counter */
315 atomic_t usecnt; /* use counter */
316
317 __u16 protocol; /* which protocol (TCP/UDP) */
Al Viro014d7302006-09-28 14:29:52 -0700318 __be32 addr; /* IP address for virtual service */
319 __be16 port; /* port number for the service */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 __u32 fwmark; /* firewall mark of the service */
321 unsigned flags; /* service status flags */
322 unsigned timeout; /* persistent timeout in ticks */
Al Viro014d7302006-09-28 14:29:52 -0700323 __be32 netmask; /* grouping granularity */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
325 struct list_head destinations; /* real server d-linked list */
326 __u32 num_dests; /* number of servers */
327 struct ip_vs_stats stats; /* statistics for the service */
328 struct ip_vs_app *inc; /* bind conns to this app inc */
329
330 /* for scheduling */
331 struct ip_vs_scheduler *scheduler; /* bound scheduler object */
332 rwlock_t sched_lock; /* lock sched_data */
333 void *sched_data; /* scheduler application data */
334};
335
336
337/*
338 * The real server destination forwarding entry
339 * with ip address, port number, and so on.
340 */
341struct ip_vs_dest {
342 struct list_head n_list; /* for the dests in the service */
343 struct list_head d_list; /* for table with all the dests */
344
Al Viro014d7302006-09-28 14:29:52 -0700345 __be32 addr; /* IP address of the server */
346 __be16 port; /* port number of the server */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 volatile unsigned flags; /* dest status flags */
348 atomic_t conn_flags; /* flags to copy to conn */
349 atomic_t weight; /* server weight */
350
351 atomic_t refcnt; /* reference counter */
352 struct ip_vs_stats stats; /* statistics */
353
354 /* connection counters and thresholds */
355 atomic_t activeconns; /* active connections */
356 atomic_t inactconns; /* inactive connections */
357 atomic_t persistconns; /* persistent connections */
358 __u32 u_threshold; /* upper threshold */
359 __u32 l_threshold; /* lower threshold */
360
361 /* for destination cache */
362 spinlock_t dst_lock; /* lock of dst_cache */
363 struct dst_entry *dst_cache; /* destination cache entry */
364 u32 dst_rtos; /* RT_TOS(tos) for dst */
365
366 /* for virtual service */
367 struct ip_vs_service *svc; /* service it belongs to */
368 __u16 protocol; /* which protocol (TCP/UDP) */
Al Viro014d7302006-09-28 14:29:52 -0700369 __be32 vaddr; /* virtual IP address */
370 __be16 vport; /* virtual port number */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 __u32 vfwmark; /* firewall mark of service */
372};
373
374
375/*
376 * The scheduler object
377 */
378struct ip_vs_scheduler {
379 struct list_head n_list; /* d-linked list head */
380 char *name; /* scheduler name */
381 atomic_t refcnt; /* reference counter */
382 struct module *module; /* THIS_MODULE/NULL */
383
384 /* scheduler initializing service */
385 int (*init_service)(struct ip_vs_service *svc);
386 /* scheduling service finish */
387 int (*done_service)(struct ip_vs_service *svc);
388 /* scheduler updating service */
389 int (*update_service)(struct ip_vs_service *svc);
390
391 /* selecting a server from the given service */
392 struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc,
393 const struct sk_buff *skb);
394};
395
396
397/*
398 * The application module object (a.k.a. app incarnation)
399 */
400struct ip_vs_app
401{
402 struct list_head a_list; /* member in app list */
403 int type; /* IP_VS_APP_TYPE_xxx */
404 char *name; /* application module name */
405 __u16 protocol;
406 struct module *module; /* THIS_MODULE/NULL */
407 struct list_head incs_list; /* list of incarnations */
408
409 /* members for application incarnations */
410 struct list_head p_list; /* member in proto app list */
411 struct ip_vs_app *app; /* its real application */
Al Viro014d7302006-09-28 14:29:52 -0700412 __be16 port; /* port number in net order */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 atomic_t usecnt; /* usage counter */
414
415 /* output hook: return false if can't linearize. diff set for TCP. */
416 int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *,
Herbert Xu3db05fe2007-10-15 00:53:15 -0700417 struct sk_buff *, int *diff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
419 /* input hook: return false if can't linearize. diff set for TCP. */
420 int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *,
Herbert Xu3db05fe2007-10-15 00:53:15 -0700421 struct sk_buff *, int *diff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
423 /* ip_vs_app initializer */
424 int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *);
425
426 /* ip_vs_app finish */
427 int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *);
428
429
430 /* not used now */
431 int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *,
432 struct ip_vs_protocol *);
433
434 void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *);
435
436 int * timeout_table;
437 int * timeouts;
438 int timeouts_size;
439
440 int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app,
441 int *verdict, struct ip_vs_conn **cpp);
442
443 struct ip_vs_conn *
444 (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app,
445 const struct iphdr *iph, unsigned int proto_off,
446 int inverse);
447
448 struct ip_vs_conn *
449 (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app,
450 const struct iphdr *iph, unsigned int proto_off,
451 int inverse);
452
453 int (*state_transition)(struct ip_vs_conn *cp, int direction,
454 const struct sk_buff *skb,
455 struct ip_vs_app *app);
456
457 void (*timeout_change)(struct ip_vs_app *app, int flags);
458};
459
460
461/*
462 * IPVS core functions
463 * (from ip_vs_core.c)
464 */
465extern const char *ip_vs_proto_name(unsigned proto);
466extern void ip_vs_init_hash_table(struct list_head *table, int rows);
Sven Wegenerafdd6142008-08-10 09:18:01 +0000467#define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469#define IP_VS_APP_TYPE_FTP 1
470
471/*
472 * ip_vs_conn handling functions
473 * (from ip_vs_conn.c)
474 */
475
476/*
477 * IPVS connection entry hash table
478 */
479#ifndef CONFIG_IP_VS_TAB_BITS
480#define CONFIG_IP_VS_TAB_BITS 12
481#endif
482/* make sure that IP_VS_CONN_TAB_BITS is located in [8, 20] */
483#if CONFIG_IP_VS_TAB_BITS < 8
484#define IP_VS_CONN_TAB_BITS 8
485#endif
486#if CONFIG_IP_VS_TAB_BITS > 20
487#define IP_VS_CONN_TAB_BITS 20
488#endif
489#if 8 <= CONFIG_IP_VS_TAB_BITS && CONFIG_IP_VS_TAB_BITS <= 20
490#define IP_VS_CONN_TAB_BITS CONFIG_IP_VS_TAB_BITS
491#endif
492#define IP_VS_CONN_TAB_SIZE (1 << IP_VS_CONN_TAB_BITS)
493#define IP_VS_CONN_TAB_MASK (IP_VS_CONN_TAB_SIZE - 1)
494
495enum {
496 IP_VS_DIR_INPUT = 0,
497 IP_VS_DIR_OUTPUT,
498 IP_VS_DIR_INPUT_ONLY,
499 IP_VS_DIR_LAST,
500};
501
502extern struct ip_vs_conn *ip_vs_conn_in_get
Al Viro014d7302006-09-28 14:29:52 -0700503(int protocol, __be32 s_addr, __be16 s_port, __be32 d_addr, __be16 d_port);
Julian Anastasov87375ab2005-09-14 21:08:51 -0700504extern struct ip_vs_conn *ip_vs_ct_in_get
Al Viro014d7302006-09-28 14:29:52 -0700505(int protocol, __be32 s_addr, __be16 s_port, __be32 d_addr, __be16 d_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506extern struct ip_vs_conn *ip_vs_conn_out_get
Al Viro014d7302006-09-28 14:29:52 -0700507(int protocol, __be32 s_addr, __be16 s_port, __be32 d_addr, __be16 d_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
509/* put back the conn without restarting its timer */
510static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
511{
512 atomic_dec(&cp->refcnt);
513}
514extern void ip_vs_conn_put(struct ip_vs_conn *cp);
Al Viro014d7302006-09-28 14:29:52 -0700515extern void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
517extern struct ip_vs_conn *
Al Viro014d7302006-09-28 14:29:52 -0700518ip_vs_conn_new(int proto, __be32 caddr, __be16 cport, __be32 vaddr, __be16 vport,
519 __be32 daddr, __be16 dport, unsigned flags,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 struct ip_vs_dest *dest);
521extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
522
523extern const char * ip_vs_state_name(__u16 proto, int state);
524
525extern void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp);
526extern int ip_vs_check_template(struct ip_vs_conn *ct);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527extern void ip_vs_random_dropentry(void);
528extern int ip_vs_conn_init(void);
529extern void ip_vs_conn_cleanup(void);
530
531static inline void ip_vs_control_del(struct ip_vs_conn *cp)
532{
533 struct ip_vs_conn *ctl_cp = cp->control;
534 if (!ctl_cp) {
535 IP_VS_ERR("request control DEL for uncontrolled: "
536 "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
537 NIPQUAD(cp->caddr),ntohs(cp->cport),
538 NIPQUAD(cp->vaddr),ntohs(cp->vport));
539 return;
540 }
541
542 IP_VS_DBG(7, "DELeting control for: "
543 "cp.dst=%d.%d.%d.%d:%d ctl_cp.dst=%d.%d.%d.%d:%d\n",
544 NIPQUAD(cp->caddr),ntohs(cp->cport),
545 NIPQUAD(ctl_cp->caddr),ntohs(ctl_cp->cport));
546
547 cp->control = NULL;
548 if (atomic_read(&ctl_cp->n_control) == 0) {
549 IP_VS_ERR("BUG control DEL with n=0 : "
550 "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
551 NIPQUAD(cp->caddr),ntohs(cp->cport),
552 NIPQUAD(cp->vaddr),ntohs(cp->vport));
553 return;
554 }
555 atomic_dec(&ctl_cp->n_control);
556}
557
558static inline void
559ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)
560{
561 if (cp->control) {
562 IP_VS_ERR("request control ADD for already controlled: "
563 "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
564 NIPQUAD(cp->caddr),ntohs(cp->cport),
565 NIPQUAD(cp->vaddr),ntohs(cp->vport));
566 ip_vs_control_del(cp);
567 }
568
569 IP_VS_DBG(7, "ADDing control for: "
570 "cp.dst=%d.%d.%d.%d:%d ctl_cp.dst=%d.%d.%d.%d:%d\n",
571 NIPQUAD(cp->caddr),ntohs(cp->cport),
572 NIPQUAD(ctl_cp->caddr),ntohs(ctl_cp->cport));
573
574 cp->control = ctl_cp;
575 atomic_inc(&ctl_cp->n_control);
576}
577
578
579/*
580 * IPVS application functions
581 * (from ip_vs_app.c)
582 */
583#define IP_VS_APP_MAX_PORTS 8
584extern int register_ip_vs_app(struct ip_vs_app *app);
585extern void unregister_ip_vs_app(struct ip_vs_app *app);
586extern int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
587extern void ip_vs_unbind_app(struct ip_vs_conn *cp);
588extern int
589register_ip_vs_app_inc(struct ip_vs_app *app, __u16 proto, __u16 port);
590extern int ip_vs_app_inc_get(struct ip_vs_app *inc);
591extern void ip_vs_app_inc_put(struct ip_vs_app *inc);
592
Herbert Xu3db05fe2007-10-15 00:53:15 -0700593extern int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb);
594extern int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb);
Al Virodd0fc662005-10-07 07:46:04 +0100595extern int ip_vs_skb_replace(struct sk_buff *skb, gfp_t pri,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 char *o_buf, int o_len, char *n_buf, int n_len);
597extern int ip_vs_app_init(void);
598extern void ip_vs_app_cleanup(void);
599
600
601/*
602 * IPVS protocol functions (from ip_vs_proto.c)
603 */
604extern int ip_vs_protocol_init(void);
605extern void ip_vs_protocol_cleanup(void);
606extern void ip_vs_protocol_timeout_change(int flags);
607extern int *ip_vs_create_timeout_table(int *table, int size);
608extern int
609ip_vs_set_state_timeout(int *table, int num, char **names, char *name, int to);
610extern void
611ip_vs_tcpudp_debug_packet(struct ip_vs_protocol *pp, const struct sk_buff *skb,
612 int offset, const char *msg);
613
614extern struct ip_vs_protocol ip_vs_protocol_tcp;
615extern struct ip_vs_protocol ip_vs_protocol_udp;
616extern struct ip_vs_protocol ip_vs_protocol_icmp;
617extern struct ip_vs_protocol ip_vs_protocol_esp;
618extern struct ip_vs_protocol ip_vs_protocol_ah;
619
620
621/*
622 * Registering/unregistering scheduler functions
623 * (from ip_vs_sched.c)
624 */
625extern int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
626extern int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
627extern int ip_vs_bind_scheduler(struct ip_vs_service *svc,
628 struct ip_vs_scheduler *scheduler);
629extern int ip_vs_unbind_scheduler(struct ip_vs_service *svc);
630extern struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name);
631extern void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler);
632extern struct ip_vs_conn *
633ip_vs_schedule(struct ip_vs_service *svc, const struct sk_buff *skb);
634extern int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
635 struct ip_vs_protocol *pp);
636
637
638/*
639 * IPVS control data and functions (from ip_vs_ctl.c)
640 */
641extern int sysctl_ip_vs_cache_bypass;
642extern int sysctl_ip_vs_expire_nodest_conn;
643extern int sysctl_ip_vs_expire_quiescent_template;
644extern int sysctl_ip_vs_sync_threshold[2];
645extern int sysctl_ip_vs_nat_icmp_send;
646extern struct ip_vs_stats ip_vs_stats;
Sven Wegener5587da52008-08-10 18:24:40 +0000647extern const struct ctl_path net_vs_ctl_path[];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
649extern struct ip_vs_service *
Al Viro014d7302006-09-28 14:29:52 -0700650ip_vs_service_get(__u32 fwmark, __u16 protocol, __be32 vaddr, __be16 vport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
652static inline void ip_vs_service_put(struct ip_vs_service *svc)
653{
654 atomic_dec(&svc->usecnt);
655}
656
657extern struct ip_vs_dest *
Al Viro014d7302006-09-28 14:29:52 -0700658ip_vs_lookup_real_service(__u16 protocol, __be32 daddr, __be16 dport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659extern int ip_vs_use_count_inc(void);
660extern void ip_vs_use_count_dec(void);
661extern int ip_vs_control_init(void);
662extern void ip_vs_control_cleanup(void);
Rumen G. Bogdanovski1e356f92007-11-07 02:35:54 -0800663extern struct ip_vs_dest *
664ip_vs_find_dest(__be32 daddr, __be16 dport,
665 __be32 vaddr, __be16 vport, __u16 protocol);
666extern struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
668
669/*
670 * IPVS sync daemon data and function prototypes
671 * (from ip_vs_sync.c)
672 */
673extern volatile int ip_vs_sync_state;
674extern volatile int ip_vs_master_syncid;
675extern volatile int ip_vs_backup_syncid;
676extern char ip_vs_master_mcast_ifn[IP_VS_IFNAME_MAXLEN];
677extern char ip_vs_backup_mcast_ifn[IP_VS_IFNAME_MAXLEN];
678extern int start_sync_thread(int state, char *mcast_ifn, __u8 syncid);
679extern int stop_sync_thread(int state);
680extern void ip_vs_sync_conn(struct ip_vs_conn *cp);
681
682
683/*
684 * IPVS rate estimator prototypes (from ip_vs_est.c)
685 */
Sven Wegener3a14a312008-08-10 18:24:41 +0000686extern void ip_vs_new_estimator(struct ip_vs_stats *stats);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687extern void ip_vs_kill_estimator(struct ip_vs_stats *stats);
688extern void ip_vs_zero_estimator(struct ip_vs_stats *stats);
689
690/*
691 * Various IPVS packet transmitters (from ip_vs_xmit.c)
692 */
693extern int ip_vs_null_xmit
694(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
695extern int ip_vs_bypass_xmit
696(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
697extern int ip_vs_nat_xmit
698(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
699extern int ip_vs_tunnel_xmit
700(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
701extern int ip_vs_dr_xmit
702(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
703extern int ip_vs_icmp_xmit
704(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, int offset);
705extern void ip_vs_dst_reset(struct ip_vs_dest *dest);
706
707
708/*
709 * This is a simple mechanism to ignore packets when
710 * we are loaded. Just set ip_vs_drop_rate to 'n' and
711 * we start to drop 1/rate of the packets
712 */
713extern int ip_vs_drop_rate;
714extern int ip_vs_drop_counter;
715
716static __inline__ int ip_vs_todrop(void)
717{
718 if (!ip_vs_drop_rate) return 0;
719 if (--ip_vs_drop_counter > 0) return 0;
720 ip_vs_drop_counter = ip_vs_drop_rate;
721 return 1;
722}
723
724/*
725 * ip_vs_fwd_tag returns the forwarding tag of the connection
726 */
727#define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK)
728
Adrian Bunk732db652005-09-01 17:40:26 -0700729static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730{
731 char fwd;
732
733 switch (IP_VS_FWD_METHOD(cp)) {
734 case IP_VS_CONN_F_MASQ:
735 fwd = 'M'; break;
736 case IP_VS_CONN_F_LOCALNODE:
737 fwd = 'L'; break;
738 case IP_VS_CONN_F_TUNNEL:
739 fwd = 'T'; break;
740 case IP_VS_CONN_F_DROUTE:
741 fwd = 'R'; break;
742 case IP_VS_CONN_F_BYPASS:
743 fwd = 'B'; break;
744 default:
745 fwd = '?'; break;
746 }
747 return fwd;
748}
749
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750extern void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,
751 struct ip_vs_conn *cp, int dir);
752
Al Virob1550f22006-11-14 21:37:50 -0800753extern __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
Al Virof9214b22006-11-16 02:41:18 -0800755static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756{
Al Virof9214b22006-11-16 02:41:18 -0800757 __be32 diff[2] = { ~old, new };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
Al Virof9214b22006-11-16 02:41:18 -0800759 return csum_partial((char *) diff, sizeof(diff), oldsum);
760}
761
762static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum)
763{
764 __be16 diff[2] = { ~old, new };
765
766 return csum_partial((char *) diff, sizeof(diff), oldsum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767}
768
769#endif /* __KERNEL__ */
770
Julius Volzbc4768e2008-07-31 20:45:24 -0700771#endif /* _NET_IP_VS_H */