blob: 29265bf4153e16510f0178dd85971220ca717fd3 [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#include <asm/types.h> /* for __uXX types */
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/list.h> /* for struct list_head */
14#include <linux/spinlock.h> /* for struct rwlock_t */
Arun Sharma600634972011-07-26 16:09:06 -070015#include <linux/atomic.h> /* for struct atomic_t */
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/compiler.h>
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020017#include <linux/timer.h>
Paul Gortmaker187f1882011-11-23 20:12:59 -050018#include <linux/bug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020020#include <net/checksum.h>
Julius Volze7ade462008-09-02 15:55:33 +020021#include <linux/netfilter.h> /* for union nf_inet_addr */
KOVACS Krisztian1668e012008-10-01 07:33:10 -070022#include <linux/ip.h>
Julius Volze7ade462008-09-02 15:55:33 +020023#include <linux/ipv6.h> /* for struct ipv6hdr */
Alexey Dobriyan4e3fd7a2011-11-21 03:39:03 +000024#include <net/ipv6.h>
Jesper Dangaard Brouer63dca2c2012-09-26 14:06:41 +020025#if IS_ENABLED(CONFIG_IPV6)
26#include <linux/netfilter_ipv6/ip6_tables.h>
27#endif
Jesper Dangaard Brouera638e512012-09-26 14:06:20 +020028#if IS_ENABLED(CONFIG_NF_CONNTRACK)
Julian Anastasovf4bc17c2010-09-21 17:35:41 +020029#include <net/netfilter/nf_conntrack.h>
30#endif
Hans Schillstrom61b1ab42011-01-03 14:44:42 +010031#include <net/net_namespace.h> /* Netw namespace */
32
33/*
34 * Generic access of ipvs struct
35 */
36static inline struct netns_ipvs *net_ipvs(struct net* net)
37{
38 return net->ipvs;
39}
Hans Schillstromfc723252011-01-03 14:44:43 +010040/*
41 * Get net ptr from skb in traffic cases
42 * use skb_sknet when call is from userland (ioctl or netlink)
43 */
Hans Schillstroma0840e22011-01-03 14:44:58 +010044static inline struct net *skb_net(const struct sk_buff *skb)
Hans Schillstromfc723252011-01-03 14:44:43 +010045{
46#ifdef CONFIG_NET_NS
47#ifdef CONFIG_IP_VS_DEBUG
48 /*
49 * This is used for debug only.
50 * Start with the most likely hit
51 * End with BUG
52 */
53 if (likely(skb->dev && skb->dev->nd_net))
54 return dev_net(skb->dev);
Hans Schillstroma09d1972011-04-04 15:25:18 +020055 if (skb_dst(skb) && skb_dst(skb)->dev)
Hans Schillstromfc723252011-01-03 14:44:43 +010056 return dev_net(skb_dst(skb)->dev);
57 WARN(skb->sk, "Maybe skb_sknet should be used in %s() at line:%d\n",
58 __func__, __LINE__);
59 if (likely(skb->sk && skb->sk->sk_net))
60 return sock_net(skb->sk);
61 pr_err("There is no net ptr to find in the skb in %s() line:%d\n",
62 __func__, __LINE__);
63 BUG();
64#else
65 return dev_net(skb->dev ? : skb_dst(skb)->dev);
66#endif
67#else
68 return &init_net;
69#endif
70}
71
Hans Schillstroma0840e22011-01-03 14:44:58 +010072static inline struct net *skb_sknet(const struct sk_buff *skb)
Hans Schillstromfc723252011-01-03 14:44:43 +010073{
74#ifdef CONFIG_NET_NS
75#ifdef CONFIG_IP_VS_DEBUG
76 /* Start with the most likely hit */
77 if (likely(skb->sk && skb->sk->sk_net))
78 return sock_net(skb->sk);
79 WARN(skb->dev, "Maybe skb_net should be used instead in %s() line:%d\n",
80 __func__, __LINE__);
81 if (likely(skb->dev && skb->dev->nd_net))
82 return dev_net(skb->dev);
83 pr_err("There is no net ptr to find in the skb in %s() line:%d\n",
84 __func__, __LINE__);
85 BUG();
86#else
87 return sock_net(skb->sk);
88#endif
89#else
90 return &init_net;
91#endif
92}
Hans Schillstromb17fc992011-01-03 14:44:56 +010093/*
94 * This one needed for single_open_net since net is stored directly in
Lucas De Marchi25985ed2011-03-30 22:57:33 -030095 * private not as a struct i.e. seq_file_net can't be used.
Hans Schillstromb17fc992011-01-03 14:44:56 +010096 */
97static inline struct net *seq_file_single_net(struct seq_file *seq)
98{
99#ifdef CONFIG_NET_NS
100 return (struct net *)seq->private;
101#else
102 return &init_net;
103#endif
104}
Catalin(ux) M. BOIE6f7edb42010-01-05 05:50:24 +0100105
106/* Connections' size value needed by ip_vs_ctl.c */
107extern int ip_vs_conn_tab_size;
108
Julius Volz64aae3c2008-09-02 15:55:34 +0200109struct ip_vs_iphdr {
Jesper Dangaard Brouer63dca2c2012-09-26 14:06:41 +0200110 __u32 len; /* IPv4 simply where L4 starts
111 IPv6 where L4 Transport Header starts */
112 __u16 fragoffs; /* IPv6 fragment offset, 0 if first frag (or not frag)*/
113 __s16 protocol;
114 __s32 flags;
Julius Volz64aae3c2008-09-02 15:55:34 +0200115 union nf_inet_addr saddr;
116 union nf_inet_addr daddr;
117};
118
119static inline void
Jesper Dangaard Brouer63dca2c2012-09-26 14:06:41 +0200120ip_vs_fill_ip4hdr(const void *nh, struct ip_vs_iphdr *iphdr)
121{
122 const struct iphdr *iph = nh;
123
124 iphdr->len = iph->ihl * 4;
125 iphdr->fragoffs = 0;
126 iphdr->protocol = iph->protocol;
127 iphdr->saddr.ip = iph->saddr;
128 iphdr->daddr.ip = iph->daddr;
129}
130
131/* This function handles filling *ip_vs_iphdr, both for IPv4 and IPv6.
132 * IPv6 requires some extra work, as finding proper header position,
133 * depend on the IPv6 extension headers.
134 */
135static inline void
136ip_vs_fill_iph_skb(int af, const struct sk_buff *skb, struct ip_vs_iphdr *iphdr)
Julius Volz64aae3c2008-09-02 15:55:34 +0200137{
138#ifdef CONFIG_IP_VS_IPV6
139 if (af == AF_INET6) {
Jesper Dangaard Brouer63dca2c2012-09-26 14:06:41 +0200140 const struct ipv6hdr *iph =
141 (struct ipv6hdr *)skb_network_header(skb);
Alexey Dobriyan4e3fd7a2011-11-21 03:39:03 +0000142 iphdr->saddr.in6 = iph->saddr;
143 iphdr->daddr.in6 = iph->daddr;
Jesper Dangaard Brouer63dca2c2012-09-26 14:06:41 +0200144 /* ipv6_find_hdr() updates len, flags */
145 iphdr->len = 0;
146 iphdr->flags = 0;
147 iphdr->protocol = ipv6_find_hdr(skb, &iphdr->len, -1,
148 &iphdr->fragoffs,
149 &iphdr->flags);
Julius Volz64aae3c2008-09-02 15:55:34 +0200150 } else
151#endif
152 {
Jesper Dangaard Brouer63dca2c2012-09-26 14:06:41 +0200153 const struct iphdr *iph =
154 (struct iphdr *)skb_network_header(skb);
155 iphdr->len = iph->ihl * 4;
156 iphdr->fragoffs = 0;
157 iphdr->protocol = iph->protocol;
158 iphdr->saddr.ip = iph->saddr;
159 iphdr->daddr.ip = iph->daddr;
160 }
161}
162
163/* This function is a faster version of ip_vs_fill_iph_skb().
164 * Where we only populate {s,d}addr (and avoid calling ipv6_find_hdr()).
165 * This is used by the some of the ip_vs_*_schedule() functions.
166 * (Mostly done to avoid ABI breakage of external schedulers)
167 */
168static inline void
169ip_vs_fill_iph_addr_only(int af, const struct sk_buff *skb,
170 struct ip_vs_iphdr *iphdr)
171{
172#ifdef CONFIG_IP_VS_IPV6
173 if (af == AF_INET6) {
174 const struct ipv6hdr *iph =
175 (struct ipv6hdr *)skb_network_header(skb);
176 iphdr->saddr.in6 = iph->saddr;
177 iphdr->daddr.in6 = iph->daddr;
178 } else {
179#endif
180 const struct iphdr *iph =
181 (struct iphdr *)skb_network_header(skb);
Julius Volz64aae3c2008-09-02 15:55:34 +0200182 iphdr->saddr.ip = iph->saddr;
183 iphdr->daddr.ip = iph->daddr;
184 }
185}
186
187static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst,
188 const union nf_inet_addr *src)
189{
190#ifdef CONFIG_IP_VS_IPV6
191 if (af == AF_INET6)
Alexey Dobriyan4e3fd7a2011-11-21 03:39:03 +0000192 dst->in6 = src->in6;
Julius Volz64aae3c2008-09-02 15:55:34 +0200193 else
194#endif
195 dst->ip = src->ip;
196}
197
198static inline int ip_vs_addr_equal(int af, const union nf_inet_addr *a,
199 const union nf_inet_addr *b)
200{
201#ifdef CONFIG_IP_VS_IPV6
202 if (af == AF_INET6)
203 return ipv6_addr_equal(&a->in6, &b->in6);
204#endif
205 return a->ip == b->ip;
206}
207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208#ifdef CONFIG_IP_VS_DEBUG
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -0200209#include <linux/net.h>
210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211extern int ip_vs_get_debug_level(void);
Julius Volzc842a3a2008-09-02 15:55:35 +0200212
213static inline const char *ip_vs_dbg_addr(int af, char *buf, size_t buf_len,
214 const union nf_inet_addr *addr,
215 int *idx)
216{
217 int len;
218#ifdef CONFIG_IP_VS_IPV6
219 if (af == AF_INET6)
Jesper Dangaard Brouer120b9c12012-09-26 14:05:53 +0200220 len = snprintf(&buf[*idx], buf_len - *idx, "[%pI6c]",
Harvey Harrison0c6ce782008-10-28 16:09:23 -0700221 &addr->in6) + 1;
Julius Volzc842a3a2008-09-02 15:55:35 +0200222 else
223#endif
Harvey Harrison3685f25d2008-10-31 00:56:49 -0700224 len = snprintf(&buf[*idx], buf_len - *idx, "%pI4",
225 &addr->ip) + 1;
Julius Volzc842a3a2008-09-02 15:55:35 +0200226
227 *idx += len;
228 BUG_ON(*idx > buf_len + 1);
229 return &buf[*idx - len];
230}
231
Hannes Eder9aada7a2009-07-30 14:29:44 -0700232#define IP_VS_DBG_BUF(level, msg, ...) \
233 do { \
234 char ip_vs_dbg_buf[160]; \
235 int ip_vs_dbg_idx = 0; \
236 if (level <= ip_vs_get_debug_level()) \
237 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
238 } while (0)
239#define IP_VS_ERR_BUF(msg...) \
240 do { \
241 char ip_vs_dbg_buf[160]; \
242 int ip_vs_dbg_idx = 0; \
243 pr_err(msg); \
244 } while (0)
Julius Volzc842a3a2008-09-02 15:55:35 +0200245
246/* Only use from within IP_VS_DBG_BUF() or IP_VS_ERR_BUF macros */
Hannes Eder9aada7a2009-07-30 14:29:44 -0700247#define IP_VS_DBG_ADDR(af, addr) \
248 ip_vs_dbg_addr(af, ip_vs_dbg_buf, \
249 sizeof(ip_vs_dbg_buf), addr, \
250 &ip_vs_dbg_idx)
Julius Volzc842a3a2008-09-02 15:55:35 +0200251
Hannes Eder9aada7a2009-07-30 14:29:44 -0700252#define IP_VS_DBG(level, msg, ...) \
253 do { \
254 if (level <= ip_vs_get_debug_level()) \
255 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
256 } while (0)
257#define IP_VS_DBG_RL(msg, ...) \
258 do { \
259 if (net_ratelimit()) \
260 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
261 } while (0)
Julian Anastasov0d796412010-10-17 16:46:17 +0300262#define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) \
Hannes Eder9aada7a2009-07-30 14:29:44 -0700263 do { \
264 if (level <= ip_vs_get_debug_level()) \
Julian Anastasov0d796412010-10-17 16:46:17 +0300265 pp->debug_packet(af, pp, skb, ofs, msg); \
Hannes Eder9aada7a2009-07-30 14:29:44 -0700266 } while (0)
Julian Anastasov0d796412010-10-17 16:46:17 +0300267#define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) \
Hannes Eder9aada7a2009-07-30 14:29:44 -0700268 do { \
269 if (level <= ip_vs_get_debug_level() && \
270 net_ratelimit()) \
Julian Anastasov0d796412010-10-17 16:46:17 +0300271 pp->debug_packet(af, pp, skb, ofs, msg); \
Hannes Eder9aada7a2009-07-30 14:29:44 -0700272 } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273#else /* NO DEBUGGING at ALL */
Julius Volzc842a3a2008-09-02 15:55:35 +0200274#define IP_VS_DBG_BUF(level, msg...) do {} while (0)
275#define IP_VS_ERR_BUF(msg...) do {} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276#define IP_VS_DBG(level, msg...) do {} while (0)
277#define IP_VS_DBG_RL(msg...) do {} while (0)
Julian Anastasov0d796412010-10-17 16:46:17 +0300278#define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) do {} while (0)
279#define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) do {} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280#endif
281
282#define IP_VS_BUG() BUG()
Hannes Eder1e3e2382009-08-02 11:05:41 +0000283#define IP_VS_ERR_RL(msg, ...) \
Hannes Eder9aada7a2009-07-30 14:29:44 -0700284 do { \
285 if (net_ratelimit()) \
Hannes Eder1e3e2382009-08-02 11:05:41 +0000286 pr_err(msg, ##__VA_ARGS__); \
Hannes Eder9aada7a2009-07-30 14:29:44 -0700287 } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
289#ifdef CONFIG_IP_VS_DEBUG
290#define EnterFunction(level) \
Hannes Eder9aada7a2009-07-30 14:29:44 -0700291 do { \
292 if (level <= ip_vs_get_debug_level()) \
293 printk(KERN_DEBUG \
294 pr_fmt("Enter: %s, %s line %i\n"), \
295 __func__, __FILE__, __LINE__); \
296 } while (0)
297#define LeaveFunction(level) \
298 do { \
299 if (level <= ip_vs_get_debug_level()) \
300 printk(KERN_DEBUG \
301 pr_fmt("Leave: %s, %s line %i\n"), \
302 __func__, __FILE__, __LINE__); \
303 } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304#else
305#define EnterFunction(level) do {} while (0)
306#define LeaveFunction(level) do {} while (0)
307#endif
308
309#define IP_VS_WAIT_WHILE(expr) while (expr) { cpu_relax(); }
310
311
312/*
313 * The port number of FTP service (in network order).
314 */
Harvey Harrisonf3a7c662009-02-14 22:58:35 -0800315#define FTPPORT cpu_to_be16(21)
316#define FTPDATA cpu_to_be16(20)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
318/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 * TCP State Values
320 */
321enum {
322 IP_VS_TCP_S_NONE = 0,
323 IP_VS_TCP_S_ESTABLISHED,
324 IP_VS_TCP_S_SYN_SENT,
325 IP_VS_TCP_S_SYN_RECV,
326 IP_VS_TCP_S_FIN_WAIT,
327 IP_VS_TCP_S_TIME_WAIT,
328 IP_VS_TCP_S_CLOSE,
329 IP_VS_TCP_S_CLOSE_WAIT,
330 IP_VS_TCP_S_LAST_ACK,
331 IP_VS_TCP_S_LISTEN,
332 IP_VS_TCP_S_SYNACK,
333 IP_VS_TCP_S_LAST
334};
335
336/*
337 * UDP State Values
338 */
339enum {
340 IP_VS_UDP_S_NORMAL,
341 IP_VS_UDP_S_LAST,
342};
343
344/*
345 * ICMP State Values
346 */
347enum {
348 IP_VS_ICMP_S_NORMAL,
349 IP_VS_ICMP_S_LAST,
350};
351
352/*
Venkata Mohan Reddy2906f662010-02-18 12:31:05 +0100353 * SCTP State Values
354 */
355enum ip_vs_sctp_states {
356 IP_VS_SCTP_S_NONE,
357 IP_VS_SCTP_S_INIT_CLI,
358 IP_VS_SCTP_S_INIT_SER,
359 IP_VS_SCTP_S_INIT_ACK_CLI,
360 IP_VS_SCTP_S_INIT_ACK_SER,
361 IP_VS_SCTP_S_ECHO_CLI,
362 IP_VS_SCTP_S_ECHO_SER,
363 IP_VS_SCTP_S_ESTABLISHED,
364 IP_VS_SCTP_S_SHUT_CLI,
365 IP_VS_SCTP_S_SHUT_SER,
366 IP_VS_SCTP_S_SHUT_ACK_CLI,
367 IP_VS_SCTP_S_SHUT_ACK_SER,
368 IP_VS_SCTP_S_CLOSED,
369 IP_VS_SCTP_S_LAST
370};
371
372/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 * Delta sequence info structure
374 * Each ip_vs_conn has 2 (output AND input seq. changes).
375 * Only used in the VS/NAT.
376 */
377struct ip_vs_seq {
378 __u32 init_seq; /* Add delta from this seq */
379 __u32 delta; /* Delta in sequence numbers */
380 __u32 previous_delta; /* Delta in sequence numbers
381 before last resized pkt */
382};
383
Hans Schillstromb17fc992011-01-03 14:44:56 +0100384/*
385 * counters per cpu
386 */
387struct ip_vs_counters {
388 __u32 conns; /* connections scheduled */
389 __u32 inpkts; /* incoming packets */
390 __u32 outpkts; /* outgoing packets */
391 __u64 inbytes; /* incoming bytes */
392 __u64 outbytes; /* outgoing bytes */
393};
394/*
395 * Stats per cpu
396 */
397struct ip_vs_cpu_stats {
398 struct ip_vs_counters ustats;
399 struct u64_stats_sync syncp;
400};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
402/*
Sven Wegener3a14a3132008-08-10 18:24:41 +0000403 * IPVS statistics objects
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 */
Sven Wegener3a14a3132008-08-10 18:24:41 +0000405struct ip_vs_estimator {
406 struct list_head list;
407
408 u64 last_inbytes;
409 u64 last_outbytes;
410 u32 last_conns;
411 u32 last_inpkts;
412 u32 last_outpkts;
413
414 u32 cps;
415 u32 inpps;
416 u32 outpps;
417 u32 inbps;
418 u32 outbps;
419};
420
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +0000421struct ip_vs_stats {
Hans Schillstromb17fc992011-01-03 14:44:56 +0100422 struct ip_vs_stats_user ustats; /* statistics */
Sven Wegenere9c0ce22008-09-08 13:39:04 +0200423 struct ip_vs_estimator est; /* estimator */
Hans Schillstromb17fc992011-01-03 14:44:56 +0100424 struct ip_vs_cpu_stats *cpustats; /* per cpu counters */
425 spinlock_t lock; /* spin lock */
Julian Anastasov55a3d4e2011-03-14 01:37:49 +0200426 struct ip_vs_stats_user ustats0; /* reset values */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427};
428
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -0200429struct dst_entry;
430struct iphdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431struct ip_vs_conn;
432struct ip_vs_app;
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -0200433struct sk_buff;
Hans Schillstrom252c6412011-01-03 14:44:46 +0100434struct ip_vs_proto_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
436struct ip_vs_protocol {
437 struct ip_vs_protocol *next;
438 char *name;
Julian Anastasov2ad17de2008-04-29 03:21:23 -0700439 u16 protocol;
440 u16 num_states;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 int dont_defrag;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
443 void (*init)(struct ip_vs_protocol *pp);
444
445 void (*exit)(struct ip_vs_protocol *pp);
446
Hans Schillstrom582b8e32012-04-26 09:45:35 +0200447 int (*init_netns)(struct net *net, struct ip_vs_proto_data *pd);
Hans Schillstrom252c6412011-01-03 14:44:46 +0100448
449 void (*exit_netns)(struct net *net, struct ip_vs_proto_data *pd);
450
Julius Volz51ef3482008-09-02 15:55:40 +0200451 int (*conn_schedule)(int af, struct sk_buff *skb,
Hans Schillstrom93304192011-01-03 14:44:51 +0100452 struct ip_vs_proto_data *pd,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 int *verdict, struct ip_vs_conn **cpp);
454
455 struct ip_vs_conn *
Julius Volz51ef3482008-09-02 15:55:40 +0200456 (*conn_in_get)(int af,
457 const struct sk_buff *skb,
Julius Volz51ef3482008-09-02 15:55:40 +0200458 const struct ip_vs_iphdr *iph,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 unsigned int proto_off,
460 int inverse);
461
462 struct ip_vs_conn *
Julius Volz51ef3482008-09-02 15:55:40 +0200463 (*conn_out_get)(int af,
464 const struct sk_buff *skb,
Julius Volz51ef3482008-09-02 15:55:40 +0200465 const struct ip_vs_iphdr *iph,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 unsigned int proto_off,
467 int inverse);
468
Herbert Xu3db05fe2007-10-15 00:53:15 -0700469 int (*snat_handler)(struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
471
Herbert Xu3db05fe2007-10-15 00:53:15 -0700472 int (*dnat_handler)(struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
474
Julius Volz51ef3482008-09-02 15:55:40 +0200475 int (*csum_check)(int af, struct sk_buff *skb,
476 struct ip_vs_protocol *pp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
478 const char *(*state_name)(int state);
479
Simon Horman4a516f12011-09-16 14:11:49 +0900480 void (*state_transition)(struct ip_vs_conn *cp, int direction,
481 const struct sk_buff *skb,
482 struct ip_vs_proto_data *pd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
Hans Schillstromab8a5e82011-01-03 14:44:53 +0100484 int (*register_app)(struct net *net, struct ip_vs_app *inc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Hans Schillstromab8a5e82011-01-03 14:44:53 +0100486 void (*unregister_app)(struct net *net, struct ip_vs_app *inc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
488 int (*app_conn_bind)(struct ip_vs_conn *cp);
489
Julian Anastasov0d796412010-10-17 16:46:17 +0300490 void (*debug_packet)(int af, struct ip_vs_protocol *pp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 const struct sk_buff *skb,
492 int offset,
493 const char *msg);
494
Hans Schillstrom93304192011-01-03 14:44:51 +0100495 void (*timeout_change)(struct ip_vs_proto_data *pd, int flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496};
497
Hans Schillstrom252c6412011-01-03 14:44:46 +0100498/*
499 * protocol data per netns
500 */
501struct ip_vs_proto_data {
502 struct ip_vs_proto_data *next;
503 struct ip_vs_protocol *pp;
504 int *timeout_table; /* protocol timeout table */
505 atomic_t appcnt; /* counter of proto app incs. */
506 struct tcp_states_t *tcp_state_table;
507};
508
509extern struct ip_vs_protocol *ip_vs_proto_get(unsigned short proto);
510extern struct ip_vs_proto_data *ip_vs_proto_data_get(struct net *net,
511 unsigned short proto);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
Simon Hormanf11017e2010-08-22 21:37:52 +0900513struct ip_vs_conn_param {
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100514 struct net *net;
Simon Hormanf11017e2010-08-22 21:37:52 +0900515 const union nf_inet_addr *caddr;
516 const union nf_inet_addr *vaddr;
517 __be16 cport;
518 __be16 vport;
519 __u16 protocol;
520 u16 af;
Simon Horman85999282010-08-22 21:37:53 +0900521
522 const struct ip_vs_pe *pe;
523 char *pe_data;
524 __u8 pe_data_len;
Simon Hormanf11017e2010-08-22 21:37:52 +0900525};
526
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527/*
528 * IP_VS structure allocated for each dynamically scheduled connection
529 */
530struct ip_vs_conn {
Changli Gao731109e2011-02-19 18:05:08 +0800531 struct hlist_node c_list; /* hashed list heads */
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100532#ifdef CONFIG_NET_NS
533 struct net *net; /* Name space */
534#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 /* Protocol, addresses and port numbers */
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100536 u16 af; /* address family */
537 __be16 cport;
538 __be16 vport;
539 __be16 dport;
540 __u32 fwmark; /* Fire wall mark from skb */
541 union nf_inet_addr caddr; /* client address */
542 union nf_inet_addr vaddr; /* virtual address */
543 union nf_inet_addr daddr; /* destination address */
544 volatile __u32 flags; /* status flags */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 __u16 protocol; /* Which protocol (TCP/UDP) */
546
547 /* counter and timer */
548 atomic_t refcnt; /* reference count */
549 struct timer_list timer; /* Expiration timer */
550 volatile unsigned long timeout; /* timeout */
551
552 /* Flags and state transition */
553 spinlock_t lock; /* lock for state transition */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 volatile __u16 state; /* state info */
Rumen G. Bogdanovskiefac5272007-11-07 02:36:55 -0800555 volatile __u16 old_state; /* old state, to be used for
556 * state transition triggerd
557 * synchronization
558 */
Julian Anastasov749c42b2012-04-24 23:46:40 +0300559 unsigned long sync_endtime; /* jiffies + sent_retries */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
561 /* Control members */
562 struct ip_vs_conn *control; /* Master control connection */
563 atomic_t n_control; /* Number of controlled ones */
564 struct ip_vs_dest *dest; /* real server */
565 atomic_t in_pkts; /* incoming packet counter */
566
567 /* packet transmitter for different forwarding methods. If it
568 mangles the packet, it must return NF_DROP or better NF_STOLEN,
569 otherwise this must be changed to a sk_buff **.
Julian Anastasovfc604762010-10-17 16:38:15 +0300570 NF_ACCEPT can be returned when destination is local.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 */
572 int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp,
573 struct ip_vs_protocol *pp);
574
575 /* Note: we can group the following members into a structure,
576 in order to save more space, and the following members are
577 only used in VS/NAT anyway */
578 struct ip_vs_app *app; /* bound ip_vs_app object */
579 void *app_data; /* Application private data */
580 struct ip_vs_seq in_seq; /* incoming seq. struct */
581 struct ip_vs_seq out_seq; /* outgoing seq. struct */
Simon Horman85999282010-08-22 21:37:53 +0900582
Simon Hormane9e5eee2010-11-08 20:05:57 +0900583 const struct ip_vs_pe *pe;
Simon Horman85999282010-08-22 21:37:53 +0900584 char *pe_data;
585 __u8 pe_data_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586};
587
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100588/*
589 * To save some memory in conn table when name space is disabled.
590 */
591static inline struct net *ip_vs_conn_net(const struct ip_vs_conn *cp)
592{
593#ifdef CONFIG_NET_NS
594 return cp->net;
595#else
596 return &init_net;
597#endif
598}
599static inline void ip_vs_conn_net_set(struct ip_vs_conn *cp, struct net *net)
600{
601#ifdef CONFIG_NET_NS
602 cp->net = net;
603#endif
604}
605
606static inline int ip_vs_conn_net_eq(const struct ip_vs_conn *cp,
607 struct net *net)
608{
609#ifdef CONFIG_NET_NS
610 return cp->net == net;
611#else
612 return 1;
613#endif
614}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
616/*
Julius Volzc860c6b2008-09-02 15:55:36 +0200617 * Extended internal versions of struct ip_vs_service_user and
618 * ip_vs_dest_user for IPv6 support.
619 *
620 * We need these to conveniently pass around service and destination
621 * options, but unfortunately, we also need to keep the old definitions to
622 * maintain userspace backwards compatibility for the setsockopt interface.
623 */
624struct ip_vs_service_user_kern {
625 /* virtual service addresses */
626 u16 af;
627 u16 protocol;
628 union nf_inet_addr addr; /* virtual ip address */
629 u16 port;
630 u32 fwmark; /* firwall mark of service */
631
632 /* virtual service options */
633 char *sched_name;
Simon Horman0d1e71b2010-08-22 21:37:54 +0900634 char *pe_name;
Eric Dumazet95c96172012-04-15 05:58:06 +0000635 unsigned int flags; /* virtual service flags */
636 unsigned int timeout; /* persistent timeout in sec */
Julius Volzc860c6b2008-09-02 15:55:36 +0200637 u32 netmask; /* persistent netmask */
638};
639
640
641struct ip_vs_dest_user_kern {
642 /* destination server address */
643 union nf_inet_addr addr;
644 u16 port;
645
646 /* real server options */
Eric Dumazet95c96172012-04-15 05:58:06 +0000647 unsigned int conn_flags; /* connection flags */
Julius Volzc860c6b2008-09-02 15:55:36 +0200648 int weight; /* destination weight */
649
650 /* thresholds for active connections */
651 u32 u_threshold; /* upper threshold */
652 u32 l_threshold; /* lower threshold */
653};
654
655
656/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 * The information about the virtual service offered to the net
658 * and the forwarding entries
659 */
660struct ip_vs_service {
661 struct list_head s_list; /* for normal service table */
662 struct list_head f_list; /* for fwmark-based service table */
663 atomic_t refcnt; /* reference counter */
664 atomic_t usecnt; /* use counter */
665
Julius Volze7ade462008-09-02 15:55:33 +0200666 u16 af; /* address family */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 __u16 protocol; /* which protocol (TCP/UDP) */
Julius Volze7ade462008-09-02 15:55:33 +0200668 union nf_inet_addr addr; /* IP address for virtual service */
Al Viro014d7302006-09-28 14:29:52 -0700669 __be16 port; /* port number for the service */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 __u32 fwmark; /* firewall mark of the service */
Eric Dumazet95c96172012-04-15 05:58:06 +0000671 unsigned int flags; /* service status flags */
672 unsigned int timeout; /* persistent timeout in ticks */
Al Viro014d7302006-09-28 14:29:52 -0700673 __be32 netmask; /* grouping granularity */
Hans Schillstromfc723252011-01-03 14:44:43 +0100674 struct net *net;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
676 struct list_head destinations; /* real server d-linked list */
677 __u32 num_dests; /* number of servers */
678 struct ip_vs_stats stats; /* statistics for the service */
679 struct ip_vs_app *inc; /* bind conns to this app inc */
680
681 /* for scheduling */
682 struct ip_vs_scheduler *scheduler; /* bound scheduler object */
683 rwlock_t sched_lock; /* lock sched_data */
684 void *sched_data; /* scheduler application data */
Simon Horman85999282010-08-22 21:37:53 +0900685
686 /* alternate persistence engine */
687 struct ip_vs_pe *pe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688};
689
690
691/*
692 * The real server destination forwarding entry
693 * with ip address, port number, and so on.
694 */
695struct ip_vs_dest {
696 struct list_head n_list; /* for the dests in the service */
697 struct list_head d_list; /* for table with all the dests */
698
Julius Volze7ade462008-09-02 15:55:33 +0200699 u16 af; /* address family */
Al Viro014d7302006-09-28 14:29:52 -0700700 __be16 port; /* port number of the server */
Hans Schillstromf2431e62011-01-03 14:45:00 +0100701 union nf_inet_addr addr; /* IP address of the server */
Eric Dumazet95c96172012-04-15 05:58:06 +0000702 volatile unsigned int flags; /* dest status flags */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 atomic_t conn_flags; /* flags to copy to conn */
704 atomic_t weight; /* server weight */
705
706 atomic_t refcnt; /* reference counter */
707 struct ip_vs_stats stats; /* statistics */
708
709 /* connection counters and thresholds */
710 atomic_t activeconns; /* active connections */
711 atomic_t inactconns; /* inactive connections */
712 atomic_t persistconns; /* persistent connections */
713 __u32 u_threshold; /* upper threshold */
714 __u32 l_threshold; /* lower threshold */
715
716 /* for destination cache */
717 spinlock_t dst_lock; /* lock of dst_cache */
718 struct dst_entry *dst_cache; /* destination cache entry */
719 u32 dst_rtos; /* RT_TOS(tos) for dst */
Hans Schillstrom714f0952010-10-19 10:38:48 +0200720 u32 dst_cookie;
Julian Anastasovc92f5ca2011-05-10 12:46:05 +0000721 union nf_inet_addr dst_saddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
723 /* for virtual service */
724 struct ip_vs_service *svc; /* service it belongs to */
725 __u16 protocol; /* which protocol (TCP/UDP) */
Al Viro014d7302006-09-28 14:29:52 -0700726 __be16 vport; /* virtual port number */
Hans Schillstromf2431e62011-01-03 14:45:00 +0100727 union nf_inet_addr vaddr; /* virtual IP address */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 __u32 vfwmark; /* firewall mark of service */
729};
730
731
732/*
733 * The scheduler object
734 */
735struct ip_vs_scheduler {
736 struct list_head n_list; /* d-linked list head */
737 char *name; /* scheduler name */
738 atomic_t refcnt; /* reference counter */
739 struct module *module; /* THIS_MODULE/NULL */
740
741 /* scheduler initializing service */
742 int (*init_service)(struct ip_vs_service *svc);
743 /* scheduling service finish */
744 int (*done_service)(struct ip_vs_service *svc);
745 /* scheduler updating service */
746 int (*update_service)(struct ip_vs_service *svc);
747
748 /* selecting a server from the given service */
749 struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc,
750 const struct sk_buff *skb);
751};
752
Simon Horman85999282010-08-22 21:37:53 +0900753/* The persistence engine object */
754struct ip_vs_pe {
755 struct list_head n_list; /* d-linked list head */
756 char *name; /* scheduler name */
757 atomic_t refcnt; /* reference counter */
758 struct module *module; /* THIS_MODULE/NULL */
759
760 /* get the connection template, if any */
761 int (*fill_param)(struct ip_vs_conn_param *p, struct sk_buff *skb);
762 bool (*ct_match)(const struct ip_vs_conn_param *p,
763 struct ip_vs_conn *ct);
764 u32 (*hashkey_raw)(const struct ip_vs_conn_param *p, u32 initval,
765 bool inverse);
Simon Hormana3c918a2010-08-22 21:37:53 +0900766 int (*show_pe_data)(const struct ip_vs_conn *cp, char *buf);
Simon Horman85999282010-08-22 21:37:53 +0900767};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
769/*
770 * The application module object (a.k.a. app incarnation)
771 */
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +0000772struct ip_vs_app {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 struct list_head a_list; /* member in app list */
774 int type; /* IP_VS_APP_TYPE_xxx */
775 char *name; /* application module name */
776 __u16 protocol;
777 struct module *module; /* THIS_MODULE/NULL */
778 struct list_head incs_list; /* list of incarnations */
779
780 /* members for application incarnations */
781 struct list_head p_list; /* member in proto app list */
782 struct ip_vs_app *app; /* its real application */
Al Viro014d7302006-09-28 14:29:52 -0700783 __be16 port; /* port number in net order */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 atomic_t usecnt; /* usage counter */
785
Julian Anastasov8b27b102010-10-17 16:17:20 +0300786 /*
787 * output hook: Process packet in inout direction, diff set for TCP.
788 * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
789 * 2=Mangled but checksum was not updated
790 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *,
Herbert Xu3db05fe2007-10-15 00:53:15 -0700792 struct sk_buff *, int *diff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
Julian Anastasov8b27b102010-10-17 16:17:20 +0300794 /*
795 * input hook: Process packet in outin direction, diff set for TCP.
796 * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
797 * 2=Mangled but checksum was not updated
798 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *,
Herbert Xu3db05fe2007-10-15 00:53:15 -0700800 struct sk_buff *, int *diff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
802 /* ip_vs_app initializer */
803 int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *);
804
805 /* ip_vs_app finish */
806 int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *);
807
808
809 /* not used now */
810 int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *,
811 struct ip_vs_protocol *);
812
813 void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *);
814
815 int * timeout_table;
816 int * timeouts;
817 int timeouts_size;
818
819 int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app,
820 int *verdict, struct ip_vs_conn **cpp);
821
822 struct ip_vs_conn *
823 (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app,
824 const struct iphdr *iph, unsigned int proto_off,
825 int inverse);
826
827 struct ip_vs_conn *
828 (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app,
829 const struct iphdr *iph, unsigned int proto_off,
830 int inverse);
831
832 int (*state_transition)(struct ip_vs_conn *cp, int direction,
833 const struct sk_buff *skb,
834 struct ip_vs_app *app);
835
836 void (*timeout_change)(struct ip_vs_app *app, int flags);
837};
838
Pablo Neira Ayusof73181c2012-05-08 19:40:30 +0200839struct ipvs_master_sync_state {
840 struct list_head sync_queue;
841 struct ip_vs_sync_buff *sync_buff;
842 int sync_queue_len;
843 unsigned int sync_queue_delay;
844 struct task_struct *master_thread;
845 struct delayed_work master_wakeup_work;
846 struct netns_ipvs *ipvs;
847};
848
Julian Anastasov2553d062011-03-04 12:18:07 +0200849/* IPVS in network namespace */
850struct netns_ipvs {
851 int gen; /* Generation */
Hans Schillstrom7a4f0762011-05-03 22:09:31 +0200852 int enable; /* enable like nf_hooks do */
Julian Anastasov2553d062011-03-04 12:18:07 +0200853 /*
854 * Hash table: for real service lookups
855 */
856 #define IP_VS_RTAB_BITS 4
857 #define IP_VS_RTAB_SIZE (1 << IP_VS_RTAB_BITS)
858 #define IP_VS_RTAB_MASK (IP_VS_RTAB_SIZE - 1)
859
860 struct list_head rs_table[IP_VS_RTAB_SIZE];
861 /* ip_vs_app */
862 struct list_head app_list;
Julian Anastasov2553d062011-03-04 12:18:07 +0200863 /* ip_vs_proto */
864 #define IP_VS_PROTO_TAB_SIZE 32 /* must be power of 2 */
865 struct ip_vs_proto_data *proto_data_table[IP_VS_PROTO_TAB_SIZE];
866 /* ip_vs_proto_tcp */
867#ifdef CONFIG_IP_VS_PROTO_TCP
868 #define TCP_APP_TAB_BITS 4
869 #define TCP_APP_TAB_SIZE (1 << TCP_APP_TAB_BITS)
870 #define TCP_APP_TAB_MASK (TCP_APP_TAB_SIZE - 1)
871 struct list_head tcp_apps[TCP_APP_TAB_SIZE];
872 spinlock_t tcp_app_lock;
873#endif
874 /* ip_vs_proto_udp */
875#ifdef CONFIG_IP_VS_PROTO_UDP
876 #define UDP_APP_TAB_BITS 4
877 #define UDP_APP_TAB_SIZE (1 << UDP_APP_TAB_BITS)
878 #define UDP_APP_TAB_MASK (UDP_APP_TAB_SIZE - 1)
879 struct list_head udp_apps[UDP_APP_TAB_SIZE];
880 spinlock_t udp_app_lock;
881#endif
882 /* ip_vs_proto_sctp */
883#ifdef CONFIG_IP_VS_PROTO_SCTP
884 #define SCTP_APP_TAB_BITS 4
885 #define SCTP_APP_TAB_SIZE (1 << SCTP_APP_TAB_BITS)
886 #define SCTP_APP_TAB_MASK (SCTP_APP_TAB_SIZE - 1)
887 /* Hash table for SCTP application incarnations */
888 struct list_head sctp_apps[SCTP_APP_TAB_SIZE];
889 spinlock_t sctp_app_lock;
890#endif
891 /* ip_vs_conn */
892 atomic_t conn_count; /* connection counter */
893
894 /* ip_vs_ctl */
Julian Anastasov2a0751a2011-03-04 12:20:35 +0200895 struct ip_vs_stats tot_stats; /* Statistics & est. */
Julian Anastasov2553d062011-03-04 12:18:07 +0200896
897 int num_services; /* no of virtual services */
Simon Hormanf2247fb2011-02-04 18:33:02 +0900898
Julian Anastasov2553d062011-03-04 12:18:07 +0200899 rwlock_t rs_lock; /* real services table */
Julian Anastasov2553d062011-03-04 12:18:07 +0200900 /* Trash for destinations */
901 struct list_head dest_trash;
902 /* Service counters */
903 atomic_t ftpsvc_counter;
904 atomic_t nullsvc_counter;
905
Simon Hormanf2247fb2011-02-04 18:33:02 +0900906#ifdef CONFIG_SYSCTL
907 /* 1/rate drop and drop-entry variables */
908 struct delayed_work defense_work; /* Work handler */
909 int drop_rate;
910 int drop_counter;
911 atomic_t dropentry;
912 /* locks in ctl.c */
913 spinlock_t dropentry_lock; /* drop entry handling */
914 spinlock_t droppacket_lock; /* drop packet handling */
915 spinlock_t securetcp_lock; /* state and timeout tables */
916
Julian Anastasov2553d062011-03-04 12:18:07 +0200917 /* sys-ctl struct */
918 struct ctl_table_header *sysctl_hdr;
919 struct ctl_table *sysctl_tbl;
Simon Hormanf2247fb2011-02-04 18:33:02 +0900920#endif
921
Julian Anastasov2553d062011-03-04 12:18:07 +0200922 /* sysctl variables */
923 int sysctl_amemthresh;
924 int sysctl_am_droprate;
925 int sysctl_drop_entry;
926 int sysctl_drop_packet;
927 int sysctl_secure_tcp;
928#ifdef CONFIG_IP_VS_NFCT
929 int sysctl_conntrack;
930#endif
931 int sysctl_snat_reroute;
932 int sysctl_sync_ver;
Pablo Neira Ayusof73181c2012-05-08 19:40:30 +0200933 int sysctl_sync_ports;
Pablo Neira Ayuso1c003b12012-05-08 19:39:49 +0200934 int sysctl_sync_qlen_max;
935 int sysctl_sync_sock_size;
Julian Anastasov2553d062011-03-04 12:18:07 +0200936 int sysctl_cache_bypass;
937 int sysctl_expire_nodest_conn;
938 int sysctl_expire_quiescent_template;
939 int sysctl_sync_threshold[2];
Julian Anastasov749c42b2012-04-24 23:46:40 +0300940 unsigned int sysctl_sync_refresh_period;
941 int sysctl_sync_retries;
Julian Anastasov2553d062011-03-04 12:18:07 +0200942 int sysctl_nat_icmp_send;
Julian Anastasov3654e612012-07-20 11:59:53 +0300943 int sysctl_pmtu_disc;
Julian Anastasov2553d062011-03-04 12:18:07 +0200944
945 /* ip_vs_lblc */
946 int sysctl_lblc_expiration;
947 struct ctl_table_header *lblc_ctl_header;
948 struct ctl_table *lblc_ctl_table;
949 /* ip_vs_lblcr */
950 int sysctl_lblcr_expiration;
951 struct ctl_table_header *lblcr_ctl_header;
952 struct ctl_table *lblcr_ctl_table;
953 /* ip_vs_est */
954 struct list_head est_list; /* estimator list */
955 spinlock_t est_lock;
956 struct timer_list est_timer; /* Estimation timer */
957 /* ip_vs_sync */
Julian Anastasov2553d062011-03-04 12:18:07 +0200958 spinlock_t sync_lock;
Pablo Neira Ayusof73181c2012-05-08 19:40:30 +0200959 struct ipvs_master_sync_state *ms;
Julian Anastasov2553d062011-03-04 12:18:07 +0200960 spinlock_t sync_buff_lock;
Pablo Neira Ayusof73181c2012-05-08 19:40:30 +0200961 struct task_struct **backup_threads;
962 int threads_mask;
Julian Anastasov2553d062011-03-04 12:18:07 +0200963 int send_mesg_maxlen;
964 int recv_mesg_maxlen;
965 volatile int sync_state;
966 volatile int master_syncid;
967 volatile int backup_syncid;
Hans Schillstromae1d48b2011-10-11 10:54:35 +0900968 struct mutex sync_mutex;
Julian Anastasov2553d062011-03-04 12:18:07 +0200969 /* multicast interface name */
970 char master_mcast_ifn[IP_VS_IFNAME_MAXLEN];
971 char backup_mcast_ifn[IP_VS_IFNAME_MAXLEN];
972 /* net name space ptr */
973 struct net *net; /* Needed by timer routines */
974};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975
Simon Horman59e03502011-02-04 18:33:01 +0900976#define DEFAULT_SYNC_THRESHOLD 3
977#define DEFAULT_SYNC_PERIOD 50
Simon Horman7532e8d2011-02-04 18:33:01 +0900978#define DEFAULT_SYNC_VER 1
Julian Anastasov749c42b2012-04-24 23:46:40 +0300979#define DEFAULT_SYNC_REFRESH_PERIOD (0U * HZ)
980#define DEFAULT_SYNC_RETRIES 0
Pablo Neira Ayuso1c003b12012-05-08 19:39:49 +0200981#define IPVS_SYNC_WAKEUP_RATE 8
982#define IPVS_SYNC_QLEN_MAX (IPVS_SYNC_WAKEUP_RATE * 4)
983#define IPVS_SYNC_SEND_DELAY (HZ / 50)
984#define IPVS_SYNC_CHECK_PERIOD HZ
Julian Anastasov749c42b2012-04-24 23:46:40 +0300985#define IPVS_SYNC_FLUSH_TIME (HZ * 2)
Pablo Neira Ayusof73181c2012-05-08 19:40:30 +0200986#define IPVS_SYNC_PORTS_MAX (1 << 6)
Simon Horman59e03502011-02-04 18:33:01 +0900987
988#ifdef CONFIG_SYSCTL
989
990static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs)
991{
992 return ipvs->sysctl_sync_threshold[0];
993}
994
995static inline int sysctl_sync_period(struct netns_ipvs *ipvs)
996{
Julian Anastasov749c42b2012-04-24 23:46:40 +0300997 return ACCESS_ONCE(ipvs->sysctl_sync_threshold[1]);
998}
999
1000static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs *ipvs)
1001{
1002 return ACCESS_ONCE(ipvs->sysctl_sync_refresh_period);
1003}
1004
1005static inline int sysctl_sync_retries(struct netns_ipvs *ipvs)
1006{
1007 return ipvs->sysctl_sync_retries;
Simon Horman59e03502011-02-04 18:33:01 +09001008}
1009
Simon Horman7532e8d2011-02-04 18:33:01 +09001010static inline int sysctl_sync_ver(struct netns_ipvs *ipvs)
1011{
1012 return ipvs->sysctl_sync_ver;
1013}
1014
Pablo Neira Ayusof73181c2012-05-08 19:40:30 +02001015static inline int sysctl_sync_ports(struct netns_ipvs *ipvs)
1016{
1017 return ACCESS_ONCE(ipvs->sysctl_sync_ports);
1018}
1019
Pablo Neira Ayuso1c003b12012-05-08 19:39:49 +02001020static inline int sysctl_sync_qlen_max(struct netns_ipvs *ipvs)
1021{
1022 return ipvs->sysctl_sync_qlen_max;
1023}
1024
1025static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs)
1026{
1027 return ipvs->sysctl_sync_sock_size;
1028}
1029
Julian Anastasov3654e612012-07-20 11:59:53 +03001030static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs)
1031{
1032 return ipvs->sysctl_pmtu_disc;
1033}
1034
Simon Horman59e03502011-02-04 18:33:01 +09001035#else
1036
1037static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs)
1038{
1039 return DEFAULT_SYNC_THRESHOLD;
1040}
1041
1042static inline int sysctl_sync_period(struct netns_ipvs *ipvs)
1043{
1044 return DEFAULT_SYNC_PERIOD;
1045}
1046
Julian Anastasov749c42b2012-04-24 23:46:40 +03001047static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs *ipvs)
1048{
1049 return DEFAULT_SYNC_REFRESH_PERIOD;
1050}
1051
1052static inline int sysctl_sync_retries(struct netns_ipvs *ipvs)
1053{
1054 return DEFAULT_SYNC_RETRIES & 3;
1055}
1056
Simon Horman7532e8d2011-02-04 18:33:01 +09001057static inline int sysctl_sync_ver(struct netns_ipvs *ipvs)
1058{
1059 return DEFAULT_SYNC_VER;
1060}
1061
Pablo Neira Ayusof73181c2012-05-08 19:40:30 +02001062static inline int sysctl_sync_ports(struct netns_ipvs *ipvs)
1063{
1064 return 1;
1065}
1066
Pablo Neira Ayuso1c003b12012-05-08 19:39:49 +02001067static inline int sysctl_sync_qlen_max(struct netns_ipvs *ipvs)
1068{
1069 return IPVS_SYNC_QLEN_MAX;
1070}
1071
1072static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs)
1073{
1074 return 0;
1075}
1076
Julian Anastasov3654e612012-07-20 11:59:53 +03001077static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs)
1078{
1079 return 1;
1080}
1081
Simon Horman59e03502011-02-04 18:33:01 +09001082#endif
1083
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084/*
1085 * IPVS core functions
1086 * (from ip_vs_core.c)
1087 */
Eric Dumazet95c96172012-04-15 05:58:06 +00001088extern const char *ip_vs_proto_name(unsigned int proto);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089extern void ip_vs_init_hash_table(struct list_head *table, int rows);
Sven Wegenerafdd6142008-08-10 09:18:01 +00001090#define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092#define IP_VS_APP_TYPE_FTP 1
1093
1094/*
1095 * ip_vs_conn handling functions
1096 * (from ip_vs_conn.c)
1097 */
1098
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099enum {
1100 IP_VS_DIR_INPUT = 0,
1101 IP_VS_DIR_OUTPUT,
1102 IP_VS_DIR_INPUT_ONLY,
1103 IP_VS_DIR_LAST,
1104};
1105
Hans Schillstrom6e67e582011-01-03 14:44:57 +01001106static inline void ip_vs_conn_fill_param(struct net *net, int af, int protocol,
Simon Hormanf11017e2010-08-22 21:37:52 +09001107 const union nf_inet_addr *caddr,
1108 __be16 cport,
1109 const union nf_inet_addr *vaddr,
1110 __be16 vport,
1111 struct ip_vs_conn_param *p)
1112{
Hans Schillstrom6e67e582011-01-03 14:44:57 +01001113 p->net = net;
Simon Hormanf11017e2010-08-22 21:37:52 +09001114 p->af = af;
1115 p->protocol = protocol;
1116 p->caddr = caddr;
1117 p->cport = cport;
1118 p->vaddr = vaddr;
1119 p->vport = vport;
Simon Horman85999282010-08-22 21:37:53 +09001120 p->pe = NULL;
1121 p->pe_data = NULL;
Simon Hormanf11017e2010-08-22 21:37:52 +09001122}
Julius Volz28364a52008-09-02 15:55:43 +02001123
Simon Hormanf11017e2010-08-22 21:37:52 +09001124struct ip_vs_conn *ip_vs_conn_in_get(const struct ip_vs_conn_param *p);
1125struct ip_vs_conn *ip_vs_ct_in_get(const struct ip_vs_conn_param *p);
Julius Volz28364a52008-09-02 15:55:43 +02001126
Simon Horman5c0d2372010-08-02 17:12:44 +02001127struct ip_vs_conn * ip_vs_conn_in_get_proto(int af, const struct sk_buff *skb,
Simon Horman5c0d2372010-08-02 17:12:44 +02001128 const struct ip_vs_iphdr *iph,
1129 unsigned int proto_off,
1130 int inverse);
1131
Simon Hormanf11017e2010-08-22 21:37:52 +09001132struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
Simon Horman5c0d2372010-08-02 17:12:44 +02001134struct ip_vs_conn * ip_vs_conn_out_get_proto(int af, const struct sk_buff *skb,
Simon Horman5c0d2372010-08-02 17:12:44 +02001135 const struct ip_vs_iphdr *iph,
1136 unsigned int proto_off,
1137 int inverse);
1138
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139/* put back the conn without restarting its timer */
1140static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
1141{
1142 atomic_dec(&cp->refcnt);
1143}
1144extern void ip_vs_conn_put(struct ip_vs_conn *cp);
Al Viro014d7302006-09-28 14:29:52 -07001145extern void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146
Simon Hormanf11017e2010-08-22 21:37:52 +09001147struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p,
1148 const union nf_inet_addr *daddr,
Eric Dumazet95c96172012-04-15 05:58:06 +00001149 __be16 dport, unsigned int flags,
Hans Schillstrom0e051e62010-11-19 14:25:07 +01001150 struct ip_vs_dest *dest, __u32 fwmark);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
1152
1153extern const char * ip_vs_state_name(__u16 proto, int state);
1154
Hans Schillstrom4a85b962011-01-03 14:44:47 +01001155extern void ip_vs_tcp_conn_listen(struct net *net, struct ip_vs_conn *cp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156extern int ip_vs_check_template(struct ip_vs_conn *ct);
Hans Schillstromf6340ee2011-01-03 14:44:59 +01001157extern void ip_vs_random_dropentry(struct net *net);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158extern int ip_vs_conn_init(void);
1159extern void ip_vs_conn_cleanup(void);
1160
1161static inline void ip_vs_control_del(struct ip_vs_conn *cp)
1162{
1163 struct ip_vs_conn *ctl_cp = cp->control;
1164 if (!ctl_cp) {
Julius Volzcfc78c52008-09-02 15:55:53 +02001165 IP_VS_ERR_BUF("request control DEL for uncontrolled: "
1166 "%s:%d to %s:%d\n",
1167 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
1168 ntohs(cp->cport),
1169 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
1170 ntohs(cp->vport));
1171
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 return;
1173 }
1174
Julius Volzcfc78c52008-09-02 15:55:53 +02001175 IP_VS_DBG_BUF(7, "DELeting control for: "
1176 "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
1177 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
1178 ntohs(cp->cport),
1179 IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
1180 ntohs(ctl_cp->cport));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181
1182 cp->control = NULL;
1183 if (atomic_read(&ctl_cp->n_control) == 0) {
Julius Volzcfc78c52008-09-02 15:55:53 +02001184 IP_VS_ERR_BUF("BUG control DEL with n=0 : "
1185 "%s:%d to %s:%d\n",
1186 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
1187 ntohs(cp->cport),
1188 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
1189 ntohs(cp->vport));
1190
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 return;
1192 }
1193 atomic_dec(&ctl_cp->n_control);
1194}
1195
1196static inline void
1197ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)
1198{
1199 if (cp->control) {
Julius Volzcfc78c52008-09-02 15:55:53 +02001200 IP_VS_ERR_BUF("request control ADD for already controlled: "
1201 "%s:%d to %s:%d\n",
1202 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
1203 ntohs(cp->cport),
1204 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
1205 ntohs(cp->vport));
1206
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 ip_vs_control_del(cp);
1208 }
1209
Julius Volzcfc78c52008-09-02 15:55:53 +02001210 IP_VS_DBG_BUF(7, "ADDing control for: "
1211 "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
1212 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
1213 ntohs(cp->cport),
1214 IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
1215 ntohs(ctl_cp->cport));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216
1217 cp->control = ctl_cp;
1218 atomic_inc(&ctl_cp->n_control);
1219}
1220
Hans Schillstrom7a4f0762011-05-03 22:09:31 +02001221/*
1222 * IPVS netns init & cleanup functions
1223 */
Hans Schillstrom503cf152011-05-01 18:50:16 +02001224extern int ip_vs_estimator_net_init(struct net *net);
1225extern int ip_vs_control_net_init(struct net *net);
1226extern int ip_vs_protocol_net_init(struct net *net);
1227extern int ip_vs_app_net_init(struct net *net);
1228extern int ip_vs_conn_net_init(struct net *net);
1229extern int ip_vs_sync_net_init(struct net *net);
1230extern void ip_vs_conn_net_cleanup(struct net *net);
1231extern void ip_vs_app_net_cleanup(struct net *net);
1232extern void ip_vs_protocol_net_cleanup(struct net *net);
1233extern void ip_vs_control_net_cleanup(struct net *net);
1234extern void ip_vs_estimator_net_cleanup(struct net *net);
1235extern void ip_vs_sync_net_cleanup(struct net *net);
1236extern void ip_vs_service_net_cleanup(struct net *net);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237
1238/*
1239 * IPVS application functions
1240 * (from ip_vs_app.c)
1241 */
1242#define IP_VS_APP_MAX_PORTS 8
Julian Anastasovbe97fdb2012-07-12 23:06:20 +03001243extern struct ip_vs_app *register_ip_vs_app(struct net *net,
1244 struct ip_vs_app *app);
Hans Schillstromab8a5e82011-01-03 14:44:53 +01001245extern void unregister_ip_vs_app(struct net *net, struct ip_vs_app *app);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246extern int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
1247extern void ip_vs_unbind_app(struct ip_vs_conn *cp);
Hans Schillstromab8a5e82011-01-03 14:44:53 +01001248extern int register_ip_vs_app_inc(struct net *net, struct ip_vs_app *app,
1249 __u16 proto, __u16 port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250extern int ip_vs_app_inc_get(struct ip_vs_app *inc);
1251extern void ip_vs_app_inc_put(struct ip_vs_app *inc);
1252
Herbert Xu3db05fe2007-10-15 00:53:15 -07001253extern int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb);
1254extern int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255
Simon Horman8be67a62010-08-22 21:37:54 +09001256void ip_vs_bind_pe(struct ip_vs_service *svc, struct ip_vs_pe *pe);
1257void ip_vs_unbind_pe(struct ip_vs_service *svc);
1258int register_ip_vs_pe(struct ip_vs_pe *pe);
1259int unregister_ip_vs_pe(struct ip_vs_pe *pe);
Simon Hormane9e5eee2010-11-08 20:05:57 +09001260struct ip_vs_pe *ip_vs_pe_getbyname(const char *name);
Hans Schillstromfe5e7a12010-11-19 14:25:12 +01001261struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name);
Simon Hormane9e5eee2010-11-08 20:05:57 +09001262
Paul Gortmaker69e7dae2011-08-29 12:40:15 -04001263/*
1264 * Use a #define to avoid all of module.h just for these trivial ops
1265 */
1266#define ip_vs_pe_get(pe) \
1267 if (pe && pe->module) \
Simon Hormane9e5eee2010-11-08 20:05:57 +09001268 __module_get(pe->module);
Simon Hormane9e5eee2010-11-08 20:05:57 +09001269
Paul Gortmaker69e7dae2011-08-29 12:40:15 -04001270#define ip_vs_pe_put(pe) \
1271 if (pe && pe->module) \
Simon Hormane9e5eee2010-11-08 20:05:57 +09001272 module_put(pe->module);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273
1274/*
1275 * IPVS protocol functions (from ip_vs_proto.c)
1276 */
1277extern int ip_vs_protocol_init(void);
1278extern void ip_vs_protocol_cleanup(void);
Hans Schillstrom93304192011-01-03 14:44:51 +01001279extern void ip_vs_protocol_timeout_change(struct netns_ipvs *ipvs, int flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280extern int *ip_vs_create_timeout_table(int *table, int size);
1281extern int
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -07001282ip_vs_set_state_timeout(int *table, int num, const char *const *names,
1283 const char *name, int to);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284extern void
Julian Anastasov0d796412010-10-17 16:46:17 +03001285ip_vs_tcpudp_debug_packet(int af, struct ip_vs_protocol *pp,
1286 const struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 int offset, const char *msg);
1288
1289extern struct ip_vs_protocol ip_vs_protocol_tcp;
1290extern struct ip_vs_protocol ip_vs_protocol_udp;
1291extern struct ip_vs_protocol ip_vs_protocol_icmp;
1292extern struct ip_vs_protocol ip_vs_protocol_esp;
1293extern struct ip_vs_protocol ip_vs_protocol_ah;
Venkata Mohan Reddy2906f662010-02-18 12:31:05 +01001294extern struct ip_vs_protocol ip_vs_protocol_sctp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
1296/*
1297 * Registering/unregistering scheduler functions
1298 * (from ip_vs_sched.c)
1299 */
1300extern int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
1301extern int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
1302extern int ip_vs_bind_scheduler(struct ip_vs_service *svc,
1303 struct ip_vs_scheduler *scheduler);
1304extern int ip_vs_unbind_scheduler(struct ip_vs_service *svc);
1305extern struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name);
1306extern void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler);
1307extern struct ip_vs_conn *
Julian Anastasov190ecd22010-10-17 16:24:37 +03001308ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,
Hans Schillstrom93304192011-01-03 14:44:51 +01001309 struct ip_vs_proto_data *pd, int *ignored);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310extern int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
Hans Schillstrom93304192011-01-03 14:44:51 +01001311 struct ip_vs_proto_data *pd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312
Patrick Schaaf41ac51e2011-02-11 14:01:12 +01001313extern void ip_vs_scheduler_err(struct ip_vs_service *svc, const char *msg);
1314
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315
1316/*
1317 * IPVS control data and functions (from ip_vs_ctl.c)
1318 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319extern struct ip_vs_stats ip_vs_stats;
Hans Schillstromb880c1f2010-11-19 14:25:14 +01001320extern int sysctl_ip_vs_sync_ver;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321
1322extern struct ip_vs_service *
Hans Schillstromfc723252011-01-03 14:44:43 +01001323ip_vs_service_get(struct net *net, int af, __u32 fwmark, __u16 protocol,
Julius Volz3c2e0502008-09-02 15:55:38 +02001324 const union nf_inet_addr *vaddr, __be16 vport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325
1326static inline void ip_vs_service_put(struct ip_vs_service *svc)
1327{
1328 atomic_dec(&svc->usecnt);
1329}
1330
1331extern struct ip_vs_dest *
Hans Schillstromfc723252011-01-03 14:44:43 +01001332ip_vs_lookup_real_service(struct net *net, int af, __u16 protocol,
Julius Volz7937df12008-09-02 15:55:48 +02001333 const union nf_inet_addr *daddr, __be16 dport);
1334
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335extern int ip_vs_use_count_inc(void);
1336extern void ip_vs_use_count_dec(void);
Hans Schillstrom8537de82012-04-26 07:47:44 +02001337extern int ip_vs_register_nl_ioctl(void);
1338extern void ip_vs_unregister_nl_ioctl(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339extern int ip_vs_control_init(void);
1340extern void ip_vs_control_cleanup(void);
Rumen G. Bogdanovski1e356f92007-11-07 02:35:54 -08001341extern struct ip_vs_dest *
Hans Schillstromfc723252011-01-03 14:44:43 +01001342ip_vs_find_dest(struct net *net, int af, const union nf_inet_addr *daddr,
1343 __be16 dport, const union nf_inet_addr *vaddr, __be16 vport,
Julian Anastasov52793db2011-12-30 14:19:02 +09001344 __u16 protocol, __u32 fwmark, __u32 flags);
Rumen G. Bogdanovski1e356f92007-11-07 02:35:54 -08001345extern struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346
1347
1348/*
1349 * IPVS sync daemon data and function prototypes
1350 * (from ip_vs_sync.c)
1351 */
Hans Schillstromf1313152011-01-03 14:44:55 +01001352extern int start_sync_thread(struct net *net, int state, char *mcast_ifn,
1353 __u8 syncid);
1354extern int stop_sync_thread(struct net *net, int state);
Julian Anastasov749c42b2012-04-24 23:46:40 +03001355extern void ip_vs_sync_conn(struct net *net, struct ip_vs_conn *cp, int pkts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356
1357
1358/*
1359 * IPVS rate estimator prototypes (from ip_vs_est.c)
1360 */
Julian Anastasov6ef757f2011-03-14 01:44:28 +02001361extern void ip_vs_start_estimator(struct net *net, struct ip_vs_stats *stats);
1362extern void ip_vs_stop_estimator(struct net *net, struct ip_vs_stats *stats);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363extern void ip_vs_zero_estimator(struct ip_vs_stats *stats);
Julian Anastasovea9f22c2011-03-14 01:41:54 +02001364extern void ip_vs_read_estimator(struct ip_vs_stats_user *dst,
1365 struct ip_vs_stats *stats);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366
1367/*
1368 * Various IPVS packet transmitters (from ip_vs_xmit.c)
1369 */
1370extern int ip_vs_null_xmit
1371(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
1372extern int ip_vs_bypass_xmit
1373(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
1374extern int ip_vs_nat_xmit
1375(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
1376extern int ip_vs_tunnel_xmit
1377(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
1378extern int ip_vs_dr_xmit
1379(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
1380extern int ip_vs_icmp_xmit
Julian Anastasovc92f5ca2011-05-10 12:46:05 +00001381(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp,
1382 int offset, unsigned int hooknum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383extern void ip_vs_dst_reset(struct ip_vs_dest *dest);
1384
Julius Volzb3cdd2a72008-09-02 15:55:45 +02001385#ifdef CONFIG_IP_VS_IPV6
1386extern int ip_vs_bypass_xmit_v6
1387(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
1388extern int ip_vs_nat_xmit_v6
1389(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
1390extern int ip_vs_tunnel_xmit_v6
1391(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
1392extern int ip_vs_dr_xmit_v6
1393(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
1394extern int ip_vs_icmp_xmit_v6
1395(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp,
Julian Anastasovc92f5ca2011-05-10 12:46:05 +00001396 int offset, unsigned int hooknum);
Julius Volzb3cdd2a72008-09-02 15:55:45 +02001397#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398
Simon Horman3a1bbf12011-02-04 18:33:02 +09001399#ifdef CONFIG_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400/*
1401 * This is a simple mechanism to ignore packets when
1402 * we are loaded. Just set ip_vs_drop_rate to 'n' and
1403 * we start to drop 1/rate of the packets
1404 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405
Hans Schillstroma0840e22011-01-03 14:44:58 +01001406static inline int ip_vs_todrop(struct netns_ipvs *ipvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407{
Hans Schillstroma0840e22011-01-03 14:44:58 +01001408 if (!ipvs->drop_rate)
1409 return 0;
1410 if (--ipvs->drop_counter > 0)
1411 return 0;
1412 ipvs->drop_counter = ipvs->drop_rate;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 return 1;
1414}
Simon Horman3a1bbf12011-02-04 18:33:02 +09001415#else
1416static inline int ip_vs_todrop(struct netns_ipvs *ipvs) { return 0; }
1417#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
1419/*
1420 * ip_vs_fwd_tag returns the forwarding tag of the connection
1421 */
1422#define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK)
1423
Adrian Bunk732db652005-09-01 17:40:26 -07001424static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425{
1426 char fwd;
1427
1428 switch (IP_VS_FWD_METHOD(cp)) {
1429 case IP_VS_CONN_F_MASQ:
1430 fwd = 'M'; break;
1431 case IP_VS_CONN_F_LOCALNODE:
1432 fwd = 'L'; break;
1433 case IP_VS_CONN_F_TUNNEL:
1434 fwd = 'T'; break;
1435 case IP_VS_CONN_F_DROUTE:
1436 fwd = 'R'; break;
1437 case IP_VS_CONN_F_BYPASS:
1438 fwd = 'B'; break;
1439 default:
1440 fwd = '?'; break;
1441 }
1442 return fwd;
1443}
1444
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445extern void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,
Julius Volzb3cdd2a72008-09-02 15:55:45 +02001446 struct ip_vs_conn *cp, int dir);
1447
1448#ifdef CONFIG_IP_VS_IPV6
1449extern void ip_vs_nat_icmp_v6(struct sk_buff *skb, struct ip_vs_protocol *pp,
1450 struct ip_vs_conn *cp, int dir);
1451#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
Al Virob1550f22006-11-14 21:37:50 -08001453extern __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454
Al Virof9214b22006-11-16 02:41:18 -08001455static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456{
Al Virof9214b22006-11-16 02:41:18 -08001457 __be32 diff[2] = { ~old, new };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458
Joe Perches07f07572008-11-19 15:44:53 -08001459 return csum_partial(diff, sizeof(diff), oldsum);
Al Virof9214b22006-11-16 02:41:18 -08001460}
1461
Julius Volz0bbdd422008-09-02 15:55:42 +02001462#ifdef CONFIG_IP_VS_IPV6
1463static inline __wsum ip_vs_check_diff16(const __be32 *old, const __be32 *new,
1464 __wsum oldsum)
1465{
1466 __be32 diff[8] = { ~old[3], ~old[2], ~old[1], ~old[0],
1467 new[3], new[2], new[1], new[0] };
1468
Joe Perches07f07572008-11-19 15:44:53 -08001469 return csum_partial(diff, sizeof(diff), oldsum);
Julius Volz0bbdd422008-09-02 15:55:42 +02001470}
1471#endif
1472
Al Virof9214b22006-11-16 02:41:18 -08001473static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum)
1474{
1475 __be16 diff[2] = { ~old, new };
1476
Joe Perches07f07572008-11-19 15:44:53 -08001477 return csum_partial(diff, sizeof(diff), oldsum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478}
1479
Julian Anastasovcf356d62010-10-17 16:21:07 +03001480/*
1481 * Forget current conntrack (unconfirmed) and attach notrack entry
1482 */
1483static inline void ip_vs_notrack(struct sk_buff *skb)
1484{
1485#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1486 enum ip_conntrack_info ctinfo;
Jesper Juhl06b69392011-03-09 22:55:05 +01001487 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
Julian Anastasovcf356d62010-10-17 16:21:07 +03001488
1489 if (!ct || !nf_ct_is_untracked(ct)) {
Lin Ming9e33ce42012-07-07 18:26:10 +08001490 nf_conntrack_put(skb->nfct);
Julian Anastasovcf356d62010-10-17 16:21:07 +03001491 skb->nfct = &nf_ct_untracked_get()->ct_general;
1492 skb->nfctinfo = IP_CT_NEW;
1493 nf_conntrack_get(skb->nfct);
1494 }
1495#endif
1496}
1497
Julian Anastasovf4bc17c2010-09-21 17:35:41 +02001498#ifdef CONFIG_IP_VS_NFCT
1499/*
1500 * Netfilter connection tracking
1501 * (from ip_vs_nfct.c)
1502 */
Hans Schillstroma0840e22011-01-03 14:44:58 +01001503static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs)
Julian Anastasovf4bc17c2010-09-21 17:35:41 +02001504{
Simon Hormana4e2f5a2011-02-04 18:33:02 +09001505#ifdef CONFIG_SYSCTL
Hans Schillstroma0840e22011-01-03 14:44:58 +01001506 return ipvs->sysctl_conntrack;
Simon Hormana4e2f5a2011-02-04 18:33:02 +09001507#else
1508 return 0;
1509#endif
Julian Anastasovf4bc17c2010-09-21 17:35:41 +02001510}
1511
Julian Anastasov6523ce12010-09-05 18:02:29 +00001512extern void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp,
1513 int outin);
Simon Horman3c2de2a2011-09-16 14:02:19 +09001514extern int ip_vs_confirm_conntrack(struct sk_buff *skb);
Julian Anastasovf4bc17c2010-09-21 17:35:41 +02001515extern void ip_vs_nfct_expect_related(struct sk_buff *skb, struct nf_conn *ct,
1516 struct ip_vs_conn *cp, u_int8_t proto,
1517 const __be16 port, int from_rs);
1518extern void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp);
1519
1520#else
1521
Hans Schillstroma0840e22011-01-03 14:44:58 +01001522static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs)
Julian Anastasovf4bc17c2010-09-21 17:35:41 +02001523{
1524 return 0;
1525}
1526
1527static inline void ip_vs_update_conntrack(struct sk_buff *skb,
1528 struct ip_vs_conn *cp, int outin)
1529{
1530}
1531
Krzysztof Wilczynskie23ebf02011-10-20 13:18:04 +01001532static inline int ip_vs_confirm_conntrack(struct sk_buff *skb)
Julian Anastasovf4bc17c2010-09-21 17:35:41 +02001533{
1534 return NF_ACCEPT;
1535}
1536
1537static inline void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp)
1538{
1539}
1540/* CONFIG_IP_VS_NFCT */
1541#endif
Julian Anastasov6523ce12010-09-05 18:02:29 +00001542
Changli Gaob552f7e2011-02-19 17:32:28 +08001543static inline unsigned int
1544ip_vs_dest_conn_overhead(struct ip_vs_dest *dest)
1545{
1546 /*
1547 * We think the overhead of processing active connections is 256
1548 * times higher than that of inactive connections in average. (This
1549 * 256 times might not be accurate, we will change it later) We
1550 * use the following formula to estimate the overhead now:
1551 * dest->activeconns*256 + dest->inactconns
1552 */
1553 return (atomic_read(&dest->activeconns) << 8) +
1554 atomic_read(&dest->inactconns);
1555}
1556
Julius Volzbc4768e2008-07-31 20:45:24 -07001557#endif /* _NET_IP_VS_H */