]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/net/ip_vs.h
smsc95xx: remove EEPROM loaded check
[mirror_ubuntu-bionic-kernel.git] / include / net / ip_vs.h
CommitLineData
1da177e4
LT
1/*
2 * IP Virtual Server
3 * data structure and functionality definitions
4 */
5
bc4768eb
JV
6#ifndef _NET_IP_VS_H
7#define _NET_IP_VS_H
1da177e4 8
bc4768eb 9#include <linux/ip_vs.h> /* definitions shared with userland */
1da177e4 10
bc4768eb 11/* old ipvsadm versions still include this file directly */
1da177e4
LT
12#ifdef __KERNEL__
13
bc4768eb
JV
14#include <asm/types.h> /* for __uXX types */
15
16#include <linux/sysctl.h> /* for ctl_path */
1da177e4
LT
17#include <linux/list.h> /* for struct list_head */
18#include <linux/spinlock.h> /* for struct rwlock_t */
1da177e4 19#include <asm/atomic.h> /* for struct atomic_t */
1da177e4 20#include <linux/compiler.h>
14c85021 21#include <linux/timer.h>
1da177e4 22
14c85021 23#include <net/checksum.h>
e7ade46a 24#include <linux/netfilter.h> /* for union nf_inet_addr */
1668e010 25#include <linux/ip.h>
e7ade46a
JV
26#include <linux/ipv6.h> /* for struct ipv6hdr */
27#include <net/ipv6.h> /* for ipv6_addr_copy */
1da177e4 28
64aae3cb
JV
29struct ip_vs_iphdr {
30 int len;
31 __u8 protocol;
32 union nf_inet_addr saddr;
33 union nf_inet_addr daddr;
34};
35
36static inline void
37ip_vs_fill_iphdr(int af, const void *nh, struct ip_vs_iphdr *iphdr)
38{
39#ifdef CONFIG_IP_VS_IPV6
40 if (af == AF_INET6) {
41 const struct ipv6hdr *iph = nh;
42 iphdr->len = sizeof(struct ipv6hdr);
43 iphdr->protocol = iph->nexthdr;
44 ipv6_addr_copy(&iphdr->saddr.in6, &iph->saddr);
45 ipv6_addr_copy(&iphdr->daddr.in6, &iph->daddr);
46 } else
47#endif
48 {
49 const struct iphdr *iph = nh;
50 iphdr->len = iph->ihl * 4;
51 iphdr->protocol = iph->protocol;
52 iphdr->saddr.ip = iph->saddr;
53 iphdr->daddr.ip = iph->daddr;
54 }
55}
56
57static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst,
58 const union nf_inet_addr *src)
59{
60#ifdef CONFIG_IP_VS_IPV6
61 if (af == AF_INET6)
62 ipv6_addr_copy(&dst->in6, &src->in6);
63 else
64#endif
65 dst->ip = src->ip;
66}
67
68static inline int ip_vs_addr_equal(int af, const union nf_inet_addr *a,
69 const union nf_inet_addr *b)
70{
71#ifdef CONFIG_IP_VS_IPV6
72 if (af == AF_INET6)
73 return ipv6_addr_equal(&a->in6, &b->in6);
74#endif
75 return a->ip == b->ip;
76}
77
1da177e4 78#ifdef CONFIG_IP_VS_DEBUG
14c85021
ACM
79#include <linux/net.h>
80
1da177e4 81extern int ip_vs_get_debug_level(void);
c842a3ad
JV
82
83static inline const char *ip_vs_dbg_addr(int af, char *buf, size_t buf_len,
84 const union nf_inet_addr *addr,
85 int *idx)
86{
87 int len;
88#ifdef CONFIG_IP_VS_IPV6
89 if (af == AF_INET6)
5b095d98 90 len = snprintf(&buf[*idx], buf_len - *idx, "[%pI6]",
0c6ce78a 91 &addr->in6) + 1;
c842a3ad
JV
92 else
93#endif
3685f25d
HH
94 len = snprintf(&buf[*idx], buf_len - *idx, "%pI4",
95 &addr->ip) + 1;
c842a3ad
JV
96
97 *idx += len;
98 BUG_ON(*idx > buf_len + 1);
99 return &buf[*idx - len];
100}
101
9aada7ac
HE
102#define IP_VS_DBG_BUF(level, msg, ...) \
103 do { \
104 char ip_vs_dbg_buf[160]; \
105 int ip_vs_dbg_idx = 0; \
106 if (level <= ip_vs_get_debug_level()) \
107 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
108 } while (0)
109#define IP_VS_ERR_BUF(msg...) \
110 do { \
111 char ip_vs_dbg_buf[160]; \
112 int ip_vs_dbg_idx = 0; \
113 pr_err(msg); \
114 } while (0)
c842a3ad
JV
115
116/* Only use from within IP_VS_DBG_BUF() or IP_VS_ERR_BUF macros */
9aada7ac
HE
117#define IP_VS_DBG_ADDR(af, addr) \
118 ip_vs_dbg_addr(af, ip_vs_dbg_buf, \
119 sizeof(ip_vs_dbg_buf), addr, \
120 &ip_vs_dbg_idx)
121
122#define IP_VS_DBG(level, msg, ...) \
123 do { \
124 if (level <= ip_vs_get_debug_level()) \
125 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
126 } while (0)
127#define IP_VS_DBG_RL(msg, ...) \
128 do { \
129 if (net_ratelimit()) \
130 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
131 } while (0)
132#define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) \
133 do { \
134 if (level <= ip_vs_get_debug_level()) \
135 pp->debug_packet(pp, skb, ofs, msg); \
136 } while (0)
137#define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) \
138 do { \
139 if (level <= ip_vs_get_debug_level() && \
140 net_ratelimit()) \
141 pp->debug_packet(pp, skb, ofs, msg); \
142 } while (0)
1da177e4 143#else /* NO DEBUGGING at ALL */
c842a3ad
JV
144#define IP_VS_DBG_BUF(level, msg...) do {} while (0)
145#define IP_VS_ERR_BUF(msg...) do {} while (0)
1da177e4
LT
146#define IP_VS_DBG(level, msg...) do {} while (0)
147#define IP_VS_DBG_RL(msg...) do {} while (0)
148#define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) do {} while (0)
149#define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) do {} while (0)
150#endif
151
152#define IP_VS_BUG() BUG()
9aada7ac
HE
153#define IP_VS_ERR(msg...) pr_err(msg)
154#define IP_VS_INFO(msg...) pr_info(msg)
155#define IP_VS_WARNING(msg...) pr_warning(msg)
156#define IP_VS_ERR_RL(msg...) \
157 do { \
158 if (net_ratelimit()) \
159 pr_err(msg); \
160 } while (0)
1da177e4
LT
161
162#ifdef CONFIG_IP_VS_DEBUG
163#define EnterFunction(level) \
9aada7ac
HE
164 do { \
165 if (level <= ip_vs_get_debug_level()) \
166 printk(KERN_DEBUG \
167 pr_fmt("Enter: %s, %s line %i\n"), \
168 __func__, __FILE__, __LINE__); \
169 } while (0)
170#define LeaveFunction(level) \
171 do { \
172 if (level <= ip_vs_get_debug_level()) \
173 printk(KERN_DEBUG \
174 pr_fmt("Leave: %s, %s line %i\n"), \
175 __func__, __FILE__, __LINE__); \
176 } while (0)
1da177e4
LT
177#else
178#define EnterFunction(level) do {} while (0)
179#define LeaveFunction(level) do {} while (0)
180#endif
181
182#define IP_VS_WAIT_WHILE(expr) while (expr) { cpu_relax(); }
183
184
185/*
186 * The port number of FTP service (in network order).
187 */
f3a7c66b
HH
188#define FTPPORT cpu_to_be16(21)
189#define FTPDATA cpu_to_be16(20)
1da177e4 190
1da177e4
LT
191/*
192 * TCP State Values
193 */
194enum {
195 IP_VS_TCP_S_NONE = 0,
196 IP_VS_TCP_S_ESTABLISHED,
197 IP_VS_TCP_S_SYN_SENT,
198 IP_VS_TCP_S_SYN_RECV,
199 IP_VS_TCP_S_FIN_WAIT,
200 IP_VS_TCP_S_TIME_WAIT,
201 IP_VS_TCP_S_CLOSE,
202 IP_VS_TCP_S_CLOSE_WAIT,
203 IP_VS_TCP_S_LAST_ACK,
204 IP_VS_TCP_S_LISTEN,
205 IP_VS_TCP_S_SYNACK,
206 IP_VS_TCP_S_LAST
207};
208
209/*
210 * UDP State Values
211 */
212enum {
213 IP_VS_UDP_S_NORMAL,
214 IP_VS_UDP_S_LAST,
215};
216
217/*
218 * ICMP State Values
219 */
220enum {
221 IP_VS_ICMP_S_NORMAL,
222 IP_VS_ICMP_S_LAST,
223};
224
225/*
226 * Delta sequence info structure
227 * Each ip_vs_conn has 2 (output AND input seq. changes).
228 * Only used in the VS/NAT.
229 */
230struct ip_vs_seq {
231 __u32 init_seq; /* Add delta from this seq */
232 __u32 delta; /* Delta in sequence numbers */
233 __u32 previous_delta; /* Delta in sequence numbers
234 before last resized pkt */
235};
236
237
238/*
3a14a313 239 * IPVS statistics objects
1da177e4 240 */
3a14a313
SW
241struct ip_vs_estimator {
242 struct list_head list;
243
244 u64 last_inbytes;
245 u64 last_outbytes;
246 u32 last_conns;
247 u32 last_inpkts;
248 u32 last_outpkts;
249
250 u32 cps;
251 u32 inpps;
252 u32 outpps;
253 u32 inbps;
254 u32 outbps;
255};
256
1da177e4
LT
257struct ip_vs_stats
258{
e9c0ce23
SW
259 struct ip_vs_stats_user ustats; /* statistics */
260 struct ip_vs_estimator est; /* estimator */
3a14a313 261
1da177e4
LT
262 spinlock_t lock; /* spin lock */
263};
264
14c85021
ACM
265struct dst_entry;
266struct iphdr;
1da177e4
LT
267struct ip_vs_conn;
268struct ip_vs_app;
14c85021 269struct sk_buff;
1da177e4
LT
270
271struct ip_vs_protocol {
272 struct ip_vs_protocol *next;
273 char *name;
2ad17def
JA
274 u16 protocol;
275 u16 num_states;
1da177e4
LT
276 int dont_defrag;
277 atomic_t appcnt; /* counter of proto app incs */
278 int *timeout_table; /* protocol timeout table */
279
280 void (*init)(struct ip_vs_protocol *pp);
281
282 void (*exit)(struct ip_vs_protocol *pp);
283
51ef348b 284 int (*conn_schedule)(int af, struct sk_buff *skb,
1da177e4
LT
285 struct ip_vs_protocol *pp,
286 int *verdict, struct ip_vs_conn **cpp);
287
288 struct ip_vs_conn *
51ef348b
JV
289 (*conn_in_get)(int af,
290 const struct sk_buff *skb,
1da177e4 291 struct ip_vs_protocol *pp,
51ef348b 292 const struct ip_vs_iphdr *iph,
1da177e4
LT
293 unsigned int proto_off,
294 int inverse);
295
296 struct ip_vs_conn *
51ef348b
JV
297 (*conn_out_get)(int af,
298 const struct sk_buff *skb,
1da177e4 299 struct ip_vs_protocol *pp,
51ef348b 300 const struct ip_vs_iphdr *iph,
1da177e4
LT
301 unsigned int proto_off,
302 int inverse);
303
3db05fea 304 int (*snat_handler)(struct sk_buff *skb,
1da177e4
LT
305 struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
306
3db05fea 307 int (*dnat_handler)(struct sk_buff *skb,
1da177e4
LT
308 struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
309
51ef348b
JV
310 int (*csum_check)(int af, struct sk_buff *skb,
311 struct ip_vs_protocol *pp);
1da177e4
LT
312
313 const char *(*state_name)(int state);
314
315 int (*state_transition)(struct ip_vs_conn *cp, int direction,
316 const struct sk_buff *skb,
317 struct ip_vs_protocol *pp);
318
319 int (*register_app)(struct ip_vs_app *inc);
320
321 void (*unregister_app)(struct ip_vs_app *inc);
322
323 int (*app_conn_bind)(struct ip_vs_conn *cp);
324
325 void (*debug_packet)(struct ip_vs_protocol *pp,
326 const struct sk_buff *skb,
327 int offset,
328 const char *msg);
329
330 void (*timeout_change)(struct ip_vs_protocol *pp, int flags);
331
332 int (*set_state_timeout)(struct ip_vs_protocol *pp, char *sname, int to);
333};
334
335extern struct ip_vs_protocol * ip_vs_proto_get(unsigned short proto);
336
337/*
338 * IP_VS structure allocated for each dynamically scheduled connection
339 */
340struct ip_vs_conn {
341 struct list_head c_list; /* hashed list heads */
342
343 /* Protocol, addresses and port numbers */
e7ade46a
JV
344 u16 af; /* address family */
345 union nf_inet_addr caddr; /* client address */
346 union nf_inet_addr vaddr; /* virtual address */
347 union nf_inet_addr daddr; /* destination address */
014d730d
AV
348 __be16 cport;
349 __be16 vport;
350 __be16 dport;
1da177e4
LT
351 __u16 protocol; /* Which protocol (TCP/UDP) */
352
353 /* counter and timer */
354 atomic_t refcnt; /* reference count */
355 struct timer_list timer; /* Expiration timer */
356 volatile unsigned long timeout; /* timeout */
357
358 /* Flags and state transition */
359 spinlock_t lock; /* lock for state transition */
360 volatile __u16 flags; /* status flags */
361 volatile __u16 state; /* state info */
efac5276
RB
362 volatile __u16 old_state; /* old state, to be used for
363 * state transition triggerd
364 * synchronization
365 */
1da177e4
LT
366
367 /* Control members */
368 struct ip_vs_conn *control; /* Master control connection */
369 atomic_t n_control; /* Number of controlled ones */
370 struct ip_vs_dest *dest; /* real server */
371 atomic_t in_pkts; /* incoming packet counter */
372
373 /* packet transmitter for different forwarding methods. If it
374 mangles the packet, it must return NF_DROP or better NF_STOLEN,
375 otherwise this must be changed to a sk_buff **.
376 */
377 int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp,
378 struct ip_vs_protocol *pp);
379
380 /* Note: we can group the following members into a structure,
381 in order to save more space, and the following members are
382 only used in VS/NAT anyway */
383 struct ip_vs_app *app; /* bound ip_vs_app object */
384 void *app_data; /* Application private data */
385 struct ip_vs_seq in_seq; /* incoming seq. struct */
386 struct ip_vs_seq out_seq; /* outgoing seq. struct */
387};
388
389
c860c6b1
JV
390/*
391 * Extended internal versions of struct ip_vs_service_user and
392 * ip_vs_dest_user for IPv6 support.
393 *
394 * We need these to conveniently pass around service and destination
395 * options, but unfortunately, we also need to keep the old definitions to
396 * maintain userspace backwards compatibility for the setsockopt interface.
397 */
398struct ip_vs_service_user_kern {
399 /* virtual service addresses */
400 u16 af;
401 u16 protocol;
402 union nf_inet_addr addr; /* virtual ip address */
403 u16 port;
404 u32 fwmark; /* firwall mark of service */
405
406 /* virtual service options */
407 char *sched_name;
408 unsigned flags; /* virtual service flags */
409 unsigned timeout; /* persistent timeout in sec */
410 u32 netmask; /* persistent netmask */
411};
412
413
414struct ip_vs_dest_user_kern {
415 /* destination server address */
416 union nf_inet_addr addr;
417 u16 port;
418
419 /* real server options */
420 unsigned conn_flags; /* connection flags */
421 int weight; /* destination weight */
422
423 /* thresholds for active connections */
424 u32 u_threshold; /* upper threshold */
425 u32 l_threshold; /* lower threshold */
426};
427
428
1da177e4
LT
429/*
430 * The information about the virtual service offered to the net
431 * and the forwarding entries
432 */
433struct ip_vs_service {
434 struct list_head s_list; /* for normal service table */
435 struct list_head f_list; /* for fwmark-based service table */
436 atomic_t refcnt; /* reference counter */
437 atomic_t usecnt; /* use counter */
438
e7ade46a 439 u16 af; /* address family */
1da177e4 440 __u16 protocol; /* which protocol (TCP/UDP) */
e7ade46a 441 union nf_inet_addr addr; /* IP address for virtual service */
014d730d 442 __be16 port; /* port number for the service */
1da177e4
LT
443 __u32 fwmark; /* firewall mark of the service */
444 unsigned flags; /* service status flags */
445 unsigned timeout; /* persistent timeout in ticks */
014d730d 446 __be32 netmask; /* grouping granularity */
1da177e4
LT
447
448 struct list_head destinations; /* real server d-linked list */
449 __u32 num_dests; /* number of servers */
450 struct ip_vs_stats stats; /* statistics for the service */
451 struct ip_vs_app *inc; /* bind conns to this app inc */
452
453 /* for scheduling */
454 struct ip_vs_scheduler *scheduler; /* bound scheduler object */
455 rwlock_t sched_lock; /* lock sched_data */
456 void *sched_data; /* scheduler application data */
457};
458
459
460/*
461 * The real server destination forwarding entry
462 * with ip address, port number, and so on.
463 */
464struct ip_vs_dest {
465 struct list_head n_list; /* for the dests in the service */
466 struct list_head d_list; /* for table with all the dests */
467
e7ade46a
JV
468 u16 af; /* address family */
469 union nf_inet_addr addr; /* IP address of the server */
014d730d 470 __be16 port; /* port number of the server */
1da177e4
LT
471 volatile unsigned flags; /* dest status flags */
472 atomic_t conn_flags; /* flags to copy to conn */
473 atomic_t weight; /* server weight */
474
475 atomic_t refcnt; /* reference counter */
476 struct ip_vs_stats stats; /* statistics */
477
478 /* connection counters and thresholds */
479 atomic_t activeconns; /* active connections */
480 atomic_t inactconns; /* inactive connections */
481 atomic_t persistconns; /* persistent connections */
482 __u32 u_threshold; /* upper threshold */
483 __u32 l_threshold; /* lower threshold */
484
485 /* for destination cache */
486 spinlock_t dst_lock; /* lock of dst_cache */
487 struct dst_entry *dst_cache; /* destination cache entry */
488 u32 dst_rtos; /* RT_TOS(tos) for dst */
489
490 /* for virtual service */
491 struct ip_vs_service *svc; /* service it belongs to */
492 __u16 protocol; /* which protocol (TCP/UDP) */
e7ade46a 493 union nf_inet_addr vaddr; /* virtual IP address */
014d730d 494 __be16 vport; /* virtual port number */
1da177e4
LT
495 __u32 vfwmark; /* firewall mark of service */
496};
497
498
499/*
500 * The scheduler object
501 */
502struct ip_vs_scheduler {
503 struct list_head n_list; /* d-linked list head */
504 char *name; /* scheduler name */
505 atomic_t refcnt; /* reference counter */
506 struct module *module; /* THIS_MODULE/NULL */
507
508 /* scheduler initializing service */
509 int (*init_service)(struct ip_vs_service *svc);
510 /* scheduling service finish */
511 int (*done_service)(struct ip_vs_service *svc);
512 /* scheduler updating service */
513 int (*update_service)(struct ip_vs_service *svc);
514
515 /* selecting a server from the given service */
516 struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc,
517 const struct sk_buff *skb);
518};
519
520
521/*
522 * The application module object (a.k.a. app incarnation)
523 */
524struct ip_vs_app
525{
526 struct list_head a_list; /* member in app list */
527 int type; /* IP_VS_APP_TYPE_xxx */
528 char *name; /* application module name */
529 __u16 protocol;
530 struct module *module; /* THIS_MODULE/NULL */
531 struct list_head incs_list; /* list of incarnations */
532
533 /* members for application incarnations */
534 struct list_head p_list; /* member in proto app list */
535 struct ip_vs_app *app; /* its real application */
014d730d 536 __be16 port; /* port number in net order */
1da177e4
LT
537 atomic_t usecnt; /* usage counter */
538
539 /* output hook: return false if can't linearize. diff set for TCP. */
540 int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *,
3db05fea 541 struct sk_buff *, int *diff);
1da177e4
LT
542
543 /* input hook: return false if can't linearize. diff set for TCP. */
544 int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *,
3db05fea 545 struct sk_buff *, int *diff);
1da177e4
LT
546
547 /* ip_vs_app initializer */
548 int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *);
549
550 /* ip_vs_app finish */
551 int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *);
552
553
554 /* not used now */
555 int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *,
556 struct ip_vs_protocol *);
557
558 void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *);
559
560 int * timeout_table;
561 int * timeouts;
562 int timeouts_size;
563
564 int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app,
565 int *verdict, struct ip_vs_conn **cpp);
566
567 struct ip_vs_conn *
568 (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app,
569 const struct iphdr *iph, unsigned int proto_off,
570 int inverse);
571
572 struct ip_vs_conn *
573 (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app,
574 const struct iphdr *iph, unsigned int proto_off,
575 int inverse);
576
577 int (*state_transition)(struct ip_vs_conn *cp, int direction,
578 const struct sk_buff *skb,
579 struct ip_vs_app *app);
580
581 void (*timeout_change)(struct ip_vs_app *app, int flags);
582};
583
584
585/*
586 * IPVS core functions
587 * (from ip_vs_core.c)
588 */
589extern const char *ip_vs_proto_name(unsigned proto);
590extern void ip_vs_init_hash_table(struct list_head *table, int rows);
afdd6140 591#define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t)))
1da177e4 592
1da177e4
LT
593#define IP_VS_APP_TYPE_FTP 1
594
595/*
596 * ip_vs_conn handling functions
597 * (from ip_vs_conn.c)
598 */
599
600/*
601 * IPVS connection entry hash table
602 */
603#ifndef CONFIG_IP_VS_TAB_BITS
604#define CONFIG_IP_VS_TAB_BITS 12
605#endif
2206a3f5 606
1da177e4 607#define IP_VS_CONN_TAB_BITS CONFIG_IP_VS_TAB_BITS
1da177e4
LT
608#define IP_VS_CONN_TAB_SIZE (1 << IP_VS_CONN_TAB_BITS)
609#define IP_VS_CONN_TAB_MASK (IP_VS_CONN_TAB_SIZE - 1)
610
611enum {
612 IP_VS_DIR_INPUT = 0,
613 IP_VS_DIR_OUTPUT,
614 IP_VS_DIR_INPUT_ONLY,
615 IP_VS_DIR_LAST,
616};
617
618extern struct ip_vs_conn *ip_vs_conn_in_get
28364a59
JV
619(int af, int protocol, const union nf_inet_addr *s_addr, __be16 s_port,
620 const union nf_inet_addr *d_addr, __be16 d_port);
621
87375ab4 622extern struct ip_vs_conn *ip_vs_ct_in_get
28364a59
JV
623(int af, int protocol, const union nf_inet_addr *s_addr, __be16 s_port,
624 const union nf_inet_addr *d_addr, __be16 d_port);
625
1da177e4 626extern struct ip_vs_conn *ip_vs_conn_out_get
28364a59
JV
627(int af, int protocol, const union nf_inet_addr *s_addr, __be16 s_port,
628 const union nf_inet_addr *d_addr, __be16 d_port);
1da177e4
LT
629
630/* put back the conn without restarting its timer */
631static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
632{
633 atomic_dec(&cp->refcnt);
634}
635extern void ip_vs_conn_put(struct ip_vs_conn *cp);
014d730d 636extern void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport);
1da177e4
LT
637
638extern struct ip_vs_conn *
28364a59
JV
639ip_vs_conn_new(int af, int proto, const union nf_inet_addr *caddr, __be16 cport,
640 const union nf_inet_addr *vaddr, __be16 vport,
641 const union nf_inet_addr *daddr, __be16 dport, unsigned flags,
1da177e4
LT
642 struct ip_vs_dest *dest);
643extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
644
645extern const char * ip_vs_state_name(__u16 proto, int state);
646
647extern void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp);
648extern int ip_vs_check_template(struct ip_vs_conn *ct);
1da177e4
LT
649extern void ip_vs_random_dropentry(void);
650extern int ip_vs_conn_init(void);
651extern void ip_vs_conn_cleanup(void);
652
653static inline void ip_vs_control_del(struct ip_vs_conn *cp)
654{
655 struct ip_vs_conn *ctl_cp = cp->control;
656 if (!ctl_cp) {
cfc78c5a
JV
657 IP_VS_ERR_BUF("request control DEL for uncontrolled: "
658 "%s:%d to %s:%d\n",
659 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
660 ntohs(cp->cport),
661 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
662 ntohs(cp->vport));
663
1da177e4
LT
664 return;
665 }
666
cfc78c5a
JV
667 IP_VS_DBG_BUF(7, "DELeting control for: "
668 "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
669 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
670 ntohs(cp->cport),
671 IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
672 ntohs(ctl_cp->cport));
1da177e4
LT
673
674 cp->control = NULL;
675 if (atomic_read(&ctl_cp->n_control) == 0) {
cfc78c5a
JV
676 IP_VS_ERR_BUF("BUG control DEL with n=0 : "
677 "%s:%d to %s:%d\n",
678 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
679 ntohs(cp->cport),
680 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
681 ntohs(cp->vport));
682
1da177e4
LT
683 return;
684 }
685 atomic_dec(&ctl_cp->n_control);
686}
687
688static inline void
689ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)
690{
691 if (cp->control) {
cfc78c5a
JV
692 IP_VS_ERR_BUF("request control ADD for already controlled: "
693 "%s:%d to %s:%d\n",
694 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
695 ntohs(cp->cport),
696 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
697 ntohs(cp->vport));
698
1da177e4
LT
699 ip_vs_control_del(cp);
700 }
701
cfc78c5a
JV
702 IP_VS_DBG_BUF(7, "ADDing control for: "
703 "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
704 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
705 ntohs(cp->cport),
706 IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
707 ntohs(ctl_cp->cport));
1da177e4
LT
708
709 cp->control = ctl_cp;
710 atomic_inc(&ctl_cp->n_control);
711}
712
713
714/*
715 * IPVS application functions
716 * (from ip_vs_app.c)
717 */
718#define IP_VS_APP_MAX_PORTS 8
719extern int register_ip_vs_app(struct ip_vs_app *app);
720extern void unregister_ip_vs_app(struct ip_vs_app *app);
721extern int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
722extern void ip_vs_unbind_app(struct ip_vs_conn *cp);
723extern int
724register_ip_vs_app_inc(struct ip_vs_app *app, __u16 proto, __u16 port);
725extern int ip_vs_app_inc_get(struct ip_vs_app *inc);
726extern void ip_vs_app_inc_put(struct ip_vs_app *inc);
727
3db05fea
HX
728extern int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb);
729extern int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb);
dd0fc66f 730extern int ip_vs_skb_replace(struct sk_buff *skb, gfp_t pri,
1da177e4
LT
731 char *o_buf, int o_len, char *n_buf, int n_len);
732extern int ip_vs_app_init(void);
733extern void ip_vs_app_cleanup(void);
734
735
736/*
737 * IPVS protocol functions (from ip_vs_proto.c)
738 */
739extern int ip_vs_protocol_init(void);
740extern void ip_vs_protocol_cleanup(void);
741extern void ip_vs_protocol_timeout_change(int flags);
742extern int *ip_vs_create_timeout_table(int *table, int size);
743extern int
744ip_vs_set_state_timeout(int *table, int num, char **names, char *name, int to);
745extern void
746ip_vs_tcpudp_debug_packet(struct ip_vs_protocol *pp, const struct sk_buff *skb,
747 int offset, const char *msg);
748
749extern struct ip_vs_protocol ip_vs_protocol_tcp;
750extern struct ip_vs_protocol ip_vs_protocol_udp;
751extern struct ip_vs_protocol ip_vs_protocol_icmp;
752extern struct ip_vs_protocol ip_vs_protocol_esp;
753extern struct ip_vs_protocol ip_vs_protocol_ah;
754
755
756/*
757 * Registering/unregistering scheduler functions
758 * (from ip_vs_sched.c)
759 */
760extern int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
761extern int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
762extern int ip_vs_bind_scheduler(struct ip_vs_service *svc,
763 struct ip_vs_scheduler *scheduler);
764extern int ip_vs_unbind_scheduler(struct ip_vs_service *svc);
765extern struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name);
766extern void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler);
767extern struct ip_vs_conn *
768ip_vs_schedule(struct ip_vs_service *svc, const struct sk_buff *skb);
769extern int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
770 struct ip_vs_protocol *pp);
771
772
773/*
774 * IPVS control data and functions (from ip_vs_ctl.c)
775 */
776extern int sysctl_ip_vs_cache_bypass;
777extern int sysctl_ip_vs_expire_nodest_conn;
778extern int sysctl_ip_vs_expire_quiescent_template;
779extern int sysctl_ip_vs_sync_threshold[2];
780extern int sysctl_ip_vs_nat_icmp_send;
781extern struct ip_vs_stats ip_vs_stats;
5587da55 782extern const struct ctl_path net_vs_ctl_path[];
1da177e4
LT
783
784extern struct ip_vs_service *
3c2e0505
JV
785ip_vs_service_get(int af, __u32 fwmark, __u16 protocol,
786 const union nf_inet_addr *vaddr, __be16 vport);
1da177e4
LT
787
788static inline void ip_vs_service_put(struct ip_vs_service *svc)
789{
790 atomic_dec(&svc->usecnt);
791}
792
793extern struct ip_vs_dest *
7937df15
JV
794ip_vs_lookup_real_service(int af, __u16 protocol,
795 const union nf_inet_addr *daddr, __be16 dport);
796
1da177e4
LT
797extern int ip_vs_use_count_inc(void);
798extern void ip_vs_use_count_dec(void);
799extern int ip_vs_control_init(void);
800extern void ip_vs_control_cleanup(void);
1e356f9c 801extern struct ip_vs_dest *
7937df15
JV
802ip_vs_find_dest(int af, const union nf_inet_addr *daddr, __be16 dport,
803 const union nf_inet_addr *vaddr, __be16 vport, __u16 protocol);
1e356f9c 804extern struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp);
1da177e4
LT
805
806
807/*
808 * IPVS sync daemon data and function prototypes
809 * (from ip_vs_sync.c)
810 */
811extern volatile int ip_vs_sync_state;
812extern volatile int ip_vs_master_syncid;
813extern volatile int ip_vs_backup_syncid;
814extern char ip_vs_master_mcast_ifn[IP_VS_IFNAME_MAXLEN];
815extern char ip_vs_backup_mcast_ifn[IP_VS_IFNAME_MAXLEN];
816extern int start_sync_thread(int state, char *mcast_ifn, __u8 syncid);
817extern int stop_sync_thread(int state);
818extern void ip_vs_sync_conn(struct ip_vs_conn *cp);
819
820
821/*
822 * IPVS rate estimator prototypes (from ip_vs_est.c)
823 */
a919cf4b
SW
824extern int ip_vs_estimator_init(void);
825extern void ip_vs_estimator_cleanup(void);
3a14a313 826extern void ip_vs_new_estimator(struct ip_vs_stats *stats);
1da177e4
LT
827extern void ip_vs_kill_estimator(struct ip_vs_stats *stats);
828extern void ip_vs_zero_estimator(struct ip_vs_stats *stats);
829
830/*
831 * Various IPVS packet transmitters (from ip_vs_xmit.c)
832 */
833extern int ip_vs_null_xmit
834(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
835extern int ip_vs_bypass_xmit
836(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
837extern int ip_vs_nat_xmit
838(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
839extern int ip_vs_tunnel_xmit
840(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
841extern int ip_vs_dr_xmit
842(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
843extern int ip_vs_icmp_xmit
844(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, int offset);
845extern void ip_vs_dst_reset(struct ip_vs_dest *dest);
846
b3cdd2a7
JV
847#ifdef CONFIG_IP_VS_IPV6
848extern int ip_vs_bypass_xmit_v6
849(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
850extern int ip_vs_nat_xmit_v6
851(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
852extern int ip_vs_tunnel_xmit_v6
853(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
854extern int ip_vs_dr_xmit_v6
855(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
856extern int ip_vs_icmp_xmit_v6
857(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp,
858 int offset);
859#endif
1da177e4
LT
860
861/*
862 * This is a simple mechanism to ignore packets when
863 * we are loaded. Just set ip_vs_drop_rate to 'n' and
864 * we start to drop 1/rate of the packets
865 */
866extern int ip_vs_drop_rate;
867extern int ip_vs_drop_counter;
868
869static __inline__ int ip_vs_todrop(void)
870{
871 if (!ip_vs_drop_rate) return 0;
872 if (--ip_vs_drop_counter > 0) return 0;
873 ip_vs_drop_counter = ip_vs_drop_rate;
874 return 1;
875}
876
877/*
878 * ip_vs_fwd_tag returns the forwarding tag of the connection
879 */
880#define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK)
881
732db659 882static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp)
1da177e4
LT
883{
884 char fwd;
885
886 switch (IP_VS_FWD_METHOD(cp)) {
887 case IP_VS_CONN_F_MASQ:
888 fwd = 'M'; break;
889 case IP_VS_CONN_F_LOCALNODE:
890 fwd = 'L'; break;
891 case IP_VS_CONN_F_TUNNEL:
892 fwd = 'T'; break;
893 case IP_VS_CONN_F_DROUTE:
894 fwd = 'R'; break;
895 case IP_VS_CONN_F_BYPASS:
896 fwd = 'B'; break;
897 default:
898 fwd = '?'; break;
899 }
900 return fwd;
901}
902
1da177e4 903extern void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,
b3cdd2a7
JV
904 struct ip_vs_conn *cp, int dir);
905
906#ifdef CONFIG_IP_VS_IPV6
907extern void ip_vs_nat_icmp_v6(struct sk_buff *skb, struct ip_vs_protocol *pp,
908 struct ip_vs_conn *cp, int dir);
909#endif
1da177e4 910
b1550f22 911extern __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset);
1da177e4 912
f9214b26 913static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum)
1da177e4 914{
f9214b26 915 __be32 diff[2] = { ~old, new };
1da177e4 916
07f0757a 917 return csum_partial(diff, sizeof(diff), oldsum);
f9214b26
AV
918}
919
0bbdd42b
JV
920#ifdef CONFIG_IP_VS_IPV6
921static inline __wsum ip_vs_check_diff16(const __be32 *old, const __be32 *new,
922 __wsum oldsum)
923{
924 __be32 diff[8] = { ~old[3], ~old[2], ~old[1], ~old[0],
925 new[3], new[2], new[1], new[0] };
926
07f0757a 927 return csum_partial(diff, sizeof(diff), oldsum);
0bbdd42b
JV
928}
929#endif
930
f9214b26
AV
931static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum)
932{
933 __be16 diff[2] = { ~old, new };
934
07f0757a 935 return csum_partial(diff, sizeof(diff), oldsum);
1da177e4
LT
936}
937
938#endif /* __KERNEL__ */
939
bc4768eb 940#endif /* _NET_IP_VS_H */