Blame view

include/net/ip_vs.h 46.8 KB
07dcc686f   Simon Horman   ipvs: Clean up co...
1
2
  /* IP Virtual Server
   * data structure and functionality definitions
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3
   */
bc4768eb0   Julius Volz   ipvs: Move usersp...
4
5
  #ifndef _NET_IP_VS_H
  #define _NET_IP_VS_H
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
6

bc4768eb0   Julius Volz   ipvs: Move usersp...
7
  #include <linux/ip_vs.h>                /* definitions shared with userland */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
8

bc4768eb0   Julius Volz   ipvs: Move usersp...
9
  #include <asm/types.h>                  /* for __uXX types */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
10
11
  #include <linux/list.h>                 /* for struct list_head */
  #include <linux/spinlock.h>             /* for struct rwlock_t */
07dcc686f   Simon Horman   ipvs: Clean up co...
12
  #include <linux/atomic.h>               /* for struct atomic_t */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
  #include <linux/compiler.h>
14c850212   Arnaldo Carvalho de Melo   [INET_SOCK]: Move...
14
  #include <linux/timer.h>
187f1882b   Paul Gortmaker   BUG: headers with...
15
  #include <linux/bug.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
16

14c850212   Arnaldo Carvalho de Melo   [INET_SOCK]: Move...
17
  #include <net/checksum.h>
e7ade46a5   Julius Volz   IPVS: Change IPVS...
18
  #include <linux/netfilter.h>		/* for union nf_inet_addr */
1668e010c   KOVACS Krisztian   ipv4: Make inet_s...
19
  #include <linux/ip.h>
e7ade46a5   Julius Volz   IPVS: Change IPVS...
20
  #include <linux/ipv6.h>			/* for struct ipv6hdr */
4e3fd7a06   Alexey Dobriyan   net: remove ipv6_...
21
  #include <net/ipv6.h>
54d83efa4   Jesper Dangaard Brouer   ipvs: fix build e...
22
  #if IS_ENABLED(CONFIG_IP_VS_IPV6)
63dca2c0b   Jesper Dangaard Brouer   ipvs: Fix faulty ...
23
24
  #include <linux/netfilter_ipv6/ip6_tables.h>
  #endif
a638e5143   Jesper Dangaard Brouer   ipvs: Use config ...
25
  #if IS_ENABLED(CONFIG_NF_CONNTRACK)
f4bc17cdd   Julian Anastasov   ipvs: netfilter c...
26
27
  #include <net/netfilter/nf_conntrack.h>
  #endif
61b1ab458   Hans Schillstrom   IPVS: netns, add ...
28
  #include <net/net_namespace.h>		/* Netw namespace */
4fd9beef3   Alex Gartrell   ipvs: Add hdr_fla...
29
30
  #define IP_VS_HDR_INVERSE	1
  #define IP_VS_HDR_ICMP		2
07dcc686f   Simon Horman   ipvs: Clean up co...
31
  /* Generic access of ipvs struct */
61b1ab458   Hans Schillstrom   IPVS: netns, add ...
32
33
34
35
  static inline struct netns_ipvs *net_ipvs(struct net* net)
  {
  	return net->ipvs;
  }
07dcc686f   Simon Horman   ipvs: Clean up co...
36

07dcc686f   Simon Horman   ipvs: Clean up co...
37
  /* This one needed for single_open_net since net is stored directly in
25985edce   Lucas De Marchi   Fix common misspe...
38
   * private not as a struct i.e. seq_file_net can't be used.
b17fc9963   Hans Schillstrom   IPVS: netns, ip_v...
39
40
41
42
43
44
45
46
47
   */
  static inline struct net *seq_file_single_net(struct seq_file *seq)
  {
  #ifdef CONFIG_NET_NS
  	return (struct net *)seq->private;
  #else
  	return &init_net;
  #endif
  }
6f7edb488   Catalin(ux) M. BOIE   IPVS: Allow boot ...
48
49
50
  
  /* Connections' size value needed by ip_vs_ctl.c */
  extern int ip_vs_conn_tab_size;
64aae3cb9   Julius Volz   IPVS: Add general...
51
  struct ip_vs_iphdr {
4fd9beef3   Alex Gartrell   ipvs: Add hdr_fla...
52
  	int hdr_flags;	/* ipvs flags */
b0e010c52   Alex Gartrell   ipvs: replace ip_...
53
  	__u32 off;	/* Where IP or IPv4 header starts */
63dca2c0b   Jesper Dangaard Brouer   ipvs: Fix faulty ...
54
  	__u32 len;	/* IPv4 simply where L4 starts
07dcc686f   Simon Horman   ipvs: Clean up co...
55
  			 * IPv6 where L4 Transport Header starts */
63dca2c0b   Jesper Dangaard Brouer   ipvs: Fix faulty ...
56
57
58
  	__u16 fragoffs; /* IPv6 fragment offset, 0 if first frag (or not frag)*/
  	__s16 protocol;
  	__s32 flags;
64aae3cb9   Julius Volz   IPVS: Add general...
59
60
61
  	union nf_inet_addr saddr;
  	union nf_inet_addr daddr;
  };
2f74713d1   Jesper Dangaard Brouer   ipvs: Complete IP...
62
63
64
65
66
67
  static inline void *frag_safe_skb_hp(const struct sk_buff *skb, int offset,
  				      int len, void *buffer,
  				      const struct ip_vs_iphdr *ipvsh)
  {
  	return skb_header_pointer(skb, offset, len, buffer);
  }
2f74713d1   Jesper Dangaard Brouer   ipvs: Complete IP...
68

63dca2c0b   Jesper Dangaard Brouer   ipvs: Fix faulty ...
69
70
71
72
  /* This function handles filling *ip_vs_iphdr, both for IPv4 and IPv6.
   * IPv6 requires some extra work, as finding proper header position,
   * depend on the IPv6 extension headers.
   */
b0e010c52   Alex Gartrell   ipvs: replace ip_...
73
74
  static inline int
  ip_vs_fill_iph_skb_off(int af, const struct sk_buff *skb, int offset,
4fd9beef3   Alex Gartrell   ipvs: Add hdr_fla...
75
  		       int hdr_flags, struct ip_vs_iphdr *iphdr)
64aae3cb9   Julius Volz   IPVS: Add general...
76
  {
4fd9beef3   Alex Gartrell   ipvs: Add hdr_fla...
77
  	iphdr->hdr_flags = hdr_flags;
b0e010c52   Alex Gartrell   ipvs: replace ip_...
78
  	iphdr->off = offset;
4fd9beef3   Alex Gartrell   ipvs: Add hdr_fla...
79

64aae3cb9   Julius Volz   IPVS: Add general...
80
81
  #ifdef CONFIG_IP_VS_IPV6
  	if (af == AF_INET6) {
b0e010c52   Alex Gartrell   ipvs: replace ip_...
82
83
84
85
86
  		struct ipv6hdr _iph;
  		const struct ipv6hdr *iph = skb_header_pointer(
  			skb, offset, sizeof(_iph), &_iph);
  		if (!iph)
  			return 0;
4e3fd7a06   Alexey Dobriyan   net: remove ipv6_...
87
88
  		iphdr->saddr.in6 = iph->saddr;
  		iphdr->daddr.in6 = iph->daddr;
6aafeef03   Jiri Pirko   netfilter: push r...
89
  		/* ipv6_find_hdr() updates len, flags */
b0e010c52   Alex Gartrell   ipvs: replace ip_...
90
  		iphdr->len	 = offset;
63dca2c0b   Jesper Dangaard Brouer   ipvs: Fix faulty ...
91
92
93
94
  		iphdr->flags	 = 0;
  		iphdr->protocol  = ipv6_find_hdr(skb, &iphdr->len, -1,
  						 &iphdr->fragoffs,
  						 &iphdr->flags);
b0e010c52   Alex Gartrell   ipvs: replace ip_...
95
96
  		if (iphdr->protocol < 0)
  			return 0;
64aae3cb9   Julius Volz   IPVS: Add general...
97
98
99
  	} else
  #endif
  	{
b0e010c52   Alex Gartrell   ipvs: replace ip_...
100
101
102
103
104
105
106
  		struct iphdr _iph;
  		const struct iphdr *iph = skb_header_pointer(
  			skb, offset, sizeof(_iph), &_iph);
  		if (!iph)
  			return 0;
  
  		iphdr->len	= offset + iph->ihl * 4;
63dca2c0b   Jesper Dangaard Brouer   ipvs: Fix faulty ...
107
108
109
110
111
  		iphdr->fragoffs	= 0;
  		iphdr->protocol	= iph->protocol;
  		iphdr->saddr.ip	= iph->saddr;
  		iphdr->daddr.ip	= iph->daddr;
  	}
b0e010c52   Alex Gartrell   ipvs: replace ip_...
112
113
114
115
116
  
  	return 1;
  }
  
  static inline int
4fd9beef3   Alex Gartrell   ipvs: Add hdr_fla...
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
  ip_vs_fill_iph_skb_icmp(int af, const struct sk_buff *skb, int offset,
  			bool inverse, struct ip_vs_iphdr *iphdr)
  {
  	int hdr_flags = IP_VS_HDR_ICMP;
  
  	if (inverse)
  		hdr_flags |= IP_VS_HDR_INVERSE;
  
  	return ip_vs_fill_iph_skb_off(af, skb, offset, hdr_flags, iphdr);
  }
  
  static inline int
  ip_vs_fill_iph_skb(int af, const struct sk_buff *skb, bool inverse,
  		   struct ip_vs_iphdr *iphdr)
  {
  	int hdr_flags = 0;
  
  	if (inverse)
  		hdr_flags |= IP_VS_HDR_INVERSE;
  
  	return ip_vs_fill_iph_skb_off(af, skb, skb_network_offset(skb),
  				      hdr_flags, iphdr);
  }
  
  static inline bool
  ip_vs_iph_inverse(const struct ip_vs_iphdr *iph)
  {
  	return !!(iph->hdr_flags & IP_VS_HDR_INVERSE);
  }
  
  static inline bool
  ip_vs_iph_icmp(const struct ip_vs_iphdr *iph)
b0e010c52   Alex Gartrell   ipvs: replace ip_...
149
  {
4fd9beef3   Alex Gartrell   ipvs: Add hdr_fla...
150
  	return !!(iph->hdr_flags & IP_VS_HDR_ICMP);
63dca2c0b   Jesper Dangaard Brouer   ipvs: Fix faulty ...
151
  }
64aae3cb9   Julius Volz   IPVS: Add general...
152
153
154
155
156
  static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst,
  				   const union nf_inet_addr *src)
  {
  #ifdef CONFIG_IP_VS_IPV6
  	if (af == AF_INET6)
4e3fd7a06   Alexey Dobriyan   net: remove ipv6_...
157
  		dst->in6 = src->in6;
64aae3cb9   Julius Volz   IPVS: Add general...
158
159
160
161
  	else
  #endif
  	dst->ip = src->ip;
  }
9a05475ce   Julian Anastasov   ipvs: avoid kmem_...
162
163
164
165
166
167
168
169
170
171
172
173
174
175
  static inline void ip_vs_addr_set(int af, union nf_inet_addr *dst,
  				  const union nf_inet_addr *src)
  {
  #ifdef CONFIG_IP_VS_IPV6
  	if (af == AF_INET6) {
  		dst->in6 = src->in6;
  		return;
  	}
  #endif
  	dst->ip = src->ip;
  	dst->all[1] = 0;
  	dst->all[2] = 0;
  	dst->all[3] = 0;
  }
64aae3cb9   Julius Volz   IPVS: Add general...
176
177
178
179
180
181
182
183
184
  static inline int ip_vs_addr_equal(int af, const union nf_inet_addr *a,
  				   const union nf_inet_addr *b)
  {
  #ifdef CONFIG_IP_VS_IPV6
  	if (af == AF_INET6)
  		return ipv6_addr_equal(&a->in6, &b->in6);
  #endif
  	return a->ip == b->ip;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
185
  #ifdef CONFIG_IP_VS_DEBUG
14c850212   Arnaldo Carvalho de Melo   [INET_SOCK]: Move...
186
  #include <linux/net.h>
5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
187
  int ip_vs_get_debug_level(void);
c842a3ada   Julius Volz   IPVS: Add debug m...
188
189
190
191
192
193
194
195
  
  static inline const char *ip_vs_dbg_addr(int af, char *buf, size_t buf_len,
  					 const union nf_inet_addr *addr,
  					 int *idx)
  {
  	int len;
  #ifdef CONFIG_IP_VS_IPV6
  	if (af == AF_INET6)
120b9c14f   Jesper Dangaard Brouer   ipvs: Trivial cha...
196
  		len = snprintf(&buf[*idx], buf_len - *idx, "[%pI6c]",
0c6ce78ab   Harvey Harrison   net: replace uses...
197
  			       &addr->in6) + 1;
c842a3ada   Julius Volz   IPVS: Add debug m...
198
199
  	else
  #endif
3685f25de   Harvey Harrison   misc: replace NIP...
200
201
  		len = snprintf(&buf[*idx], buf_len - *idx, "%pI4",
  			       &addr->ip) + 1;
c842a3ada   Julius Volz   IPVS: Add debug m...
202
203
204
205
206
  
  	*idx += len;
  	BUG_ON(*idx > buf_len + 1);
  	return &buf[*idx - len];
  }
9aada7ac0   Hannes Eder   IPVS: use pr_fmt
207
208
209
210
211
212
213
214
215
216
217
218
219
  #define IP_VS_DBG_BUF(level, msg, ...)					\
  	do {								\
  		char ip_vs_dbg_buf[160];				\
  		int ip_vs_dbg_idx = 0;					\
  		if (level <= ip_vs_get_debug_level())			\
  			printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__);	\
  	} while (0)
  #define IP_VS_ERR_BUF(msg...)						\
  	do {								\
  		char ip_vs_dbg_buf[160];				\
  		int ip_vs_dbg_idx = 0;					\
  		pr_err(msg);						\
  	} while (0)
c842a3ada   Julius Volz   IPVS: Add debug m...
220
221
  
  /* Only use from within IP_VS_DBG_BUF() or IP_VS_ERR_BUF macros */
9aada7ac0   Hannes Eder   IPVS: use pr_fmt
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
  #define IP_VS_DBG_ADDR(af, addr)					\
  	ip_vs_dbg_addr(af, ip_vs_dbg_buf,				\
  		       sizeof(ip_vs_dbg_buf), addr,			\
  		       &ip_vs_dbg_idx)
  
  #define IP_VS_DBG(level, msg, ...)					\
  	do {								\
  		if (level <= ip_vs_get_debug_level())			\
  			printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__);	\
  	} while (0)
  #define IP_VS_DBG_RL(msg, ...)						\
  	do {								\
  		if (net_ratelimit())					\
  			printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__);	\
  	} while (0)
0d79641a9   Julian Anastasov   ipvs: provide add...
237
  #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg)			\
9aada7ac0   Hannes Eder   IPVS: use pr_fmt
238
239
  	do {								\
  		if (level <= ip_vs_get_debug_level())			\
0d79641a9   Julian Anastasov   ipvs: provide add...
240
  			pp->debug_packet(af, pp, skb, ofs, msg);	\
9aada7ac0   Hannes Eder   IPVS: use pr_fmt
241
  	} while (0)
0d79641a9   Julian Anastasov   ipvs: provide add...
242
  #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg)			\
9aada7ac0   Hannes Eder   IPVS: use pr_fmt
243
244
245
  	do {								\
  		if (level <= ip_vs_get_debug_level() &&			\
  		    net_ratelimit())					\
0d79641a9   Julian Anastasov   ipvs: provide add...
246
  			pp->debug_packet(af, pp, skb, ofs, msg);	\
9aada7ac0   Hannes Eder   IPVS: use pr_fmt
247
  	} while (0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
248
  #else	/* NO DEBUGGING at ALL */
c842a3ada   Julius Volz   IPVS: Add debug m...
249
250
  #define IP_VS_DBG_BUF(level, msg...)  do {} while (0)
  #define IP_VS_ERR_BUF(msg...)  do {} while (0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
251
252
  #define IP_VS_DBG(level, msg...)  do {} while (0)
  #define IP_VS_DBG_RL(msg...)  do {} while (0)
0d79641a9   Julian Anastasov   ipvs: provide add...
253
254
  #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg)	do {} while (0)
  #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg)	do {} while (0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
255
256
257
  #endif
  
  #define IP_VS_BUG() BUG()
1e3e238e9   Hannes Eder   IPVS: use pr_err ...
258
  #define IP_VS_ERR_RL(msg, ...)						\
9aada7ac0   Hannes Eder   IPVS: use pr_fmt
259
260
  	do {								\
  		if (net_ratelimit())					\
1e3e238e9   Hannes Eder   IPVS: use pr_err ...
261
  			pr_err(msg, ##__VA_ARGS__);			\
9aada7ac0   Hannes Eder   IPVS: use pr_fmt
262
  	} while (0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
263
264
265
  
  #ifdef CONFIG_IP_VS_DEBUG
  #define EnterFunction(level)						\
9aada7ac0   Hannes Eder   IPVS: use pr_fmt
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
  	do {								\
  		if (level <= ip_vs_get_debug_level())			\
  			printk(KERN_DEBUG				\
  			       pr_fmt("Enter: %s, %s line %i
  "),	\
  			       __func__, __FILE__, __LINE__);		\
  	} while (0)
  #define LeaveFunction(level)						\
  	do {								\
  		if (level <= ip_vs_get_debug_level())			\
  			printk(KERN_DEBUG				\
  			       pr_fmt("Leave: %s, %s line %i
  "),	\
  			       __func__, __FILE__, __LINE__);		\
  	} while (0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
281
282
283
284
  #else
  #define EnterFunction(level)   do {} while (0)
  #define LeaveFunction(level)   do {} while (0)
  #endif
07dcc686f   Simon Horman   ipvs: Clean up co...
285
  /* The port number of FTP service (in network order). */
f3a7c66b5   Harvey Harrison   net: replace __co...
286
287
  #define FTPPORT  cpu_to_be16(21)
  #define FTPDATA  cpu_to_be16(20)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
288

07dcc686f   Simon Horman   ipvs: Clean up co...
289
  /* TCP State Values */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
290
291
292
293
294
295
296
297
298
299
300
301
302
303
  enum {
  	IP_VS_TCP_S_NONE = 0,
  	IP_VS_TCP_S_ESTABLISHED,
  	IP_VS_TCP_S_SYN_SENT,
  	IP_VS_TCP_S_SYN_RECV,
  	IP_VS_TCP_S_FIN_WAIT,
  	IP_VS_TCP_S_TIME_WAIT,
  	IP_VS_TCP_S_CLOSE,
  	IP_VS_TCP_S_CLOSE_WAIT,
  	IP_VS_TCP_S_LAST_ACK,
  	IP_VS_TCP_S_LISTEN,
  	IP_VS_TCP_S_SYNACK,
  	IP_VS_TCP_S_LAST
  };
07dcc686f   Simon Horman   ipvs: Clean up co...
304
  /* UDP State Values */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
305
306
307
308
  enum {
  	IP_VS_UDP_S_NORMAL,
  	IP_VS_UDP_S_LAST,
  };
07dcc686f   Simon Horman   ipvs: Clean up co...
309
  /* ICMP State Values */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
310
311
312
313
  enum {
  	IP_VS_ICMP_S_NORMAL,
  	IP_VS_ICMP_S_LAST,
  };
07dcc686f   Simon Horman   ipvs: Clean up co...
314
  /* SCTP State Values */
2906f66a5   Venkata Mohan Reddy   ipvs: SCTP Traspo...
315
316
  enum ip_vs_sctp_states {
  	IP_VS_SCTP_S_NONE,
61e7c420b   Julian Anastasov   ipvs: replace the...
317
318
319
320
321
322
323
  	IP_VS_SCTP_S_INIT1,
  	IP_VS_SCTP_S_INIT,
  	IP_VS_SCTP_S_COOKIE_SENT,
  	IP_VS_SCTP_S_COOKIE_REPLIED,
  	IP_VS_SCTP_S_COOKIE_WAIT,
  	IP_VS_SCTP_S_COOKIE,
  	IP_VS_SCTP_S_COOKIE_ECHOED,
2906f66a5   Venkata Mohan Reddy   ipvs: SCTP Traspo...
324
  	IP_VS_SCTP_S_ESTABLISHED,
61e7c420b   Julian Anastasov   ipvs: replace the...
325
326
327
328
  	IP_VS_SCTP_S_SHUTDOWN_SENT,
  	IP_VS_SCTP_S_SHUTDOWN_RECEIVED,
  	IP_VS_SCTP_S_SHUTDOWN_ACK_SENT,
  	IP_VS_SCTP_S_REJECTED,
2906f66a5   Venkata Mohan Reddy   ipvs: SCTP Traspo...
329
330
331
  	IP_VS_SCTP_S_CLOSED,
  	IP_VS_SCTP_S_LAST
  };
07dcc686f   Simon Horman   ipvs: Clean up co...
332
333
334
  /* Delta sequence info structure
   * Each ip_vs_conn has 2 (output AND input seq. changes).
   * Only used in the VS/NAT.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
335
336
337
338
339
   */
  struct ip_vs_seq {
  	__u32			init_seq;	/* Add delta from this seq */
  	__u32			delta;		/* Delta in sequence numbers */
  	__u32			previous_delta;	/* Delta in sequence numbers
07dcc686f   Simon Horman   ipvs: Clean up co...
340
  						 * before last resized pkt */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
341
  };
07dcc686f   Simon Horman   ipvs: Clean up co...
342
  /* counters per cpu */
b17fc9963   Hans Schillstrom   IPVS: netns, ip_v...
343
  struct ip_vs_counters {
cd67cd5eb   Julian Anastasov   ipvs: use 64-bit ...
344
345
346
  	__u64		conns;		/* connections scheduled */
  	__u64		inpkts;		/* incoming packets */
  	__u64		outpkts;	/* outgoing packets */
b17fc9963   Hans Schillstrom   IPVS: netns, ip_v...
347
348
349
  	__u64		inbytes;	/* incoming bytes */
  	__u64		outbytes;	/* outgoing bytes */
  };
07dcc686f   Simon Horman   ipvs: Clean up co...
350
  /* Stats per cpu */
b17fc9963   Hans Schillstrom   IPVS: netns, ip_v...
351
  struct ip_vs_cpu_stats {
cd67cd5eb   Julian Anastasov   ipvs: use 64-bit ...
352
  	struct ip_vs_counters   cnt;
b17fc9963   Hans Schillstrom   IPVS: netns, ip_v...
353
354
  	struct u64_stats_sync   syncp;
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
355

07dcc686f   Simon Horman   ipvs: Clean up co...
356
  /* IPVS statistics objects */
3a14a313f   Sven Wegener   ipvs: Embed estim...
357
358
359
360
361
  struct ip_vs_estimator {
  	struct list_head	list;
  
  	u64			last_inbytes;
  	u64			last_outbytes;
cd67cd5eb   Julian Anastasov   ipvs: use 64-bit ...
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
  	u64			last_conns;
  	u64			last_inpkts;
  	u64			last_outpkts;
  
  	u64			cps;
  	u64			inpps;
  	u64			outpps;
  	u64			inbps;
  	u64			outbps;
  };
  
  /*
   * IPVS statistics object, 64-bit kernel version of struct ip_vs_stats_user
   */
  struct ip_vs_kstats {
  	u64			conns;		/* connections scheduled */
  	u64			inpkts;		/* incoming packets */
  	u64			outpkts;	/* outgoing packets */
  	u64			inbytes;	/* incoming bytes */
  	u64			outbytes;	/* outgoing bytes */
  
  	u64			cps;		/* current connection rate */
  	u64			inpps;		/* current in packet rate */
  	u64			outpps;		/* current out packet rate */
  	u64			inbps;		/* current in byte rate */
  	u64			outbps;		/* current out byte rate */
3a14a313f   Sven Wegener   ipvs: Embed estim...
388
  };
fd2c3ef76   Eric Dumazet   net: cleanup incl...
389
  struct ip_vs_stats {
cd67cd5eb   Julian Anastasov   ipvs: use 64-bit ...
390
  	struct ip_vs_kstats	kstats;		/* kernel statistics */
e9c0ce232   Sven Wegener   ipvs: Embed user ...
391
  	struct ip_vs_estimator	est;		/* estimator */
b962abdc6   Julian Anastasov   ipvs: fix some sp...
392
  	struct ip_vs_cpu_stats __percpu	*cpustats;	/* per cpu counters */
b17fc9963   Hans Schillstrom   IPVS: netns, ip_v...
393
  	spinlock_t		lock;		/* spin lock */
cd67cd5eb   Julian Anastasov   ipvs: use 64-bit ...
394
  	struct ip_vs_kstats	kstats0;	/* reset values */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
395
  };
14c850212   Arnaldo Carvalho de Melo   [INET_SOCK]: Move...
396
397
  struct dst_entry;
  struct iphdr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
398
399
  struct ip_vs_conn;
  struct ip_vs_app;
14c850212   Arnaldo Carvalho de Melo   [INET_SOCK]: Move...
400
  struct sk_buff;
252c64103   Hans Schillstrom   IPVS: netns, prep...
401
  struct ip_vs_proto_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
402
403
404
405
  
  struct ip_vs_protocol {
  	struct ip_vs_protocol	*next;
  	char			*name;
2ad17defd   Julian Anastasov   ipvs: fix oops in...
406
407
  	u16			protocol;
  	u16			num_states;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
408
  	int			dont_defrag;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
409
410
411
412
  
  	void (*init)(struct ip_vs_protocol *pp);
  
  	void (*exit)(struct ip_vs_protocol *pp);
1281a9c2d   Eric W. Biederman   ipvs: Pass ipvs n...
413
  	int (*init_netns)(struct netns_ipvs *ipvs, struct ip_vs_proto_data *pd);
252c64103   Hans Schillstrom   IPVS: netns, prep...
414

1281a9c2d   Eric W. Biederman   ipvs: Pass ipvs n...
415
  	void (*exit_netns)(struct netns_ipvs *ipvs, struct ip_vs_proto_data *pd);
252c64103   Hans Schillstrom   IPVS: netns, prep...
416

d8f44c335   Eric W. Biederman   ipvs: Pass ipvs i...
417
418
  	int (*conn_schedule)(struct netns_ipvs *ipvs,
  			     int af, struct sk_buff *skb,
9330419d9   Hans Schillstrom   IPVS: netns, use ...
419
  			     struct ip_vs_proto_data *pd,
d4383f04d   Jesper Dangaard Brouer   ipvs: API change ...
420
421
  			     int *verdict, struct ip_vs_conn **cpp,
  			     struct ip_vs_iphdr *iph);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
422
423
  
  	struct ip_vs_conn *
ab1619764   Eric W. Biederman   ipvs: Pass ipvs i...
424
425
  	(*conn_in_get)(struct netns_ipvs *ipvs,
  		       int af,
51ef348b1   Julius Volz   IPVS: Add 'af' ar...
426
  		       const struct sk_buff *skb,
802c41adc   Alex Gartrell   ipvs: drop invers...
427
  		       const struct ip_vs_iphdr *iph);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
428
429
  
  	struct ip_vs_conn *
0cf705c8c   Eric W. Biederman   ipvs: Pass ipvs i...
430
431
  	(*conn_out_get)(struct netns_ipvs *ipvs,
  			int af,
51ef348b1   Julius Volz   IPVS: Add 'af' ar...
432
  			const struct sk_buff *skb,
802c41adc   Alex Gartrell   ipvs: drop invers...
433
  			const struct ip_vs_iphdr *iph);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
434

d4383f04d   Jesper Dangaard Brouer   ipvs: API change ...
435
436
  	int (*snat_handler)(struct sk_buff *skb, struct ip_vs_protocol *pp,
  			    struct ip_vs_conn *cp, struct ip_vs_iphdr *iph);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
437

d4383f04d   Jesper Dangaard Brouer   ipvs: API change ...
438
439
  	int (*dnat_handler)(struct sk_buff *skb, struct ip_vs_protocol *pp,
  			    struct ip_vs_conn *cp, struct ip_vs_iphdr *iph);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
440

51ef348b1   Julius Volz   IPVS: Add 'af' ar...
441
442
  	int (*csum_check)(int af, struct sk_buff *skb,
  			  struct ip_vs_protocol *pp);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
443
444
  
  	const char *(*state_name)(int state);
4a516f110   Simon Horman   ipvs: Remove unus...
445
446
447
  	void (*state_transition)(struct ip_vs_conn *cp, int direction,
  				 const struct sk_buff *skb,
  				 struct ip_vs_proto_data *pd);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
448

19648918f   Eric W. Biederman   ipvs: Pass ipvs n...
449
  	int (*register_app)(struct netns_ipvs *ipvs, struct ip_vs_app *inc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
450

19648918f   Eric W. Biederman   ipvs: Pass ipvs n...
451
  	void (*unregister_app)(struct netns_ipvs *ipvs, struct ip_vs_app *inc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
452
453
  
  	int (*app_conn_bind)(struct ip_vs_conn *cp);
0d79641a9   Julian Anastasov   ipvs: provide add...
454
  	void (*debug_packet)(int af, struct ip_vs_protocol *pp,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
455
456
457
  			     const struct sk_buff *skb,
  			     int offset,
  			     const char *msg);
9330419d9   Hans Schillstrom   IPVS: netns, use ...
458
  	void (*timeout_change)(struct ip_vs_proto_data *pd, int flags);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
459
  };
07dcc686f   Simon Horman   ipvs: Clean up co...
460
  /* protocol data per netns */
252c64103   Hans Schillstrom   IPVS: netns, prep...
461
462
463
464
465
466
467
  struct ip_vs_proto_data {
  	struct ip_vs_proto_data	*next;
  	struct ip_vs_protocol	*pp;
  	int			*timeout_table;	/* protocol timeout table */
  	atomic_t		appcnt;		/* counter of proto app incs. */
  	struct tcp_states_t	*tcp_state_table;
  };
5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
468
  struct ip_vs_protocol   *ip_vs_proto_get(unsigned short proto);
18d6ade63   Eric W. Biederman   ipvs: Pass ipvs n...
469
  struct ip_vs_proto_data *ip_vs_proto_data_get(struct netns_ipvs *ipvs,
5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
470
  					      unsigned short proto);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
471

f11017ec2   Simon Horman   IPVS: Add struct ...
472
  struct ip_vs_conn_param {
e64e2b460   Eric W. Biederman   ipvs: Store ipvs ...
473
  	struct netns_ipvs		*ipvs;
f11017ec2   Simon Horman   IPVS: Add struct ...
474
475
476
477
478
479
  	const union nf_inet_addr	*caddr;
  	const union nf_inet_addr	*vaddr;
  	__be16				cport;
  	__be16				vport;
  	__u16				protocol;
  	u16				af;
85999283a   Simon Horman   IPVS: Add struct ...
480
481
482
483
  
  	const struct ip_vs_pe		*pe;
  	char				*pe_data;
  	__u8				pe_data_len;
f11017ec2   Simon Horman   IPVS: Add struct ...
484
  };
07dcc686f   Simon Horman   ipvs: Clean up co...
485
  /* IP_VS structure allocated for each dynamically scheduled connection */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
486
  struct ip_vs_conn {
731109e78   Changli Gao   ipvs: use hlist i...
487
  	struct hlist_node	c_list;         /* hashed list heads */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
488
  	/* Protocol, addresses and port numbers */
6e67e586e   Hans Schillstrom   IPVS: netns, conn...
489
  	__be16                  cport;
6e67e586e   Hans Schillstrom   IPVS: netns, conn...
490
  	__be16                  dport;
1845ed0bb   Julian Anastasov   ipvs: reorder key...
491
492
  	__be16                  vport;
  	u16			af;		/* address family */
6e67e586e   Hans Schillstrom   IPVS: netns, conn...
493
494
495
496
  	union nf_inet_addr      caddr;          /* client address */
  	union nf_inet_addr      vaddr;          /* virtual address */
  	union nf_inet_addr      daddr;          /* destination address */
  	volatile __u32          flags;          /* status flags */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
497
  	__u16                   protocol;       /* Which protocol (TCP/UDP) */
ba38528aa   Alex Gartrell   ipvs: Supply dest...
498
  	__u16			daf;		/* Address family of the dest */
58dbc6f26   Eric W. Biederman   ipvs: Store ipvs ...
499
  	struct netns_ipvs	*ipvs;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
500
501
502
503
504
505
506
507
  
  	/* counter and timer */
  	atomic_t		refcnt;		/* reference count */
  	struct timer_list	timer;		/* Expiration timer */
  	volatile unsigned long	timeout;	/* timeout */
  
  	/* Flags and state transition */
  	spinlock_t              lock;           /* lock for state transition */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
508
  	volatile __u16          state;          /* state info */
efac52762   Rumen G. Bogdanovski   [IPVS]: Synchroni...
509
510
511
512
  	volatile __u16          old_state;      /* old state, to be used for
  						 * state transition triggerd
  						 * synchronization
  						 */
1845ed0bb   Julian Anastasov   ipvs: reorder key...
513
  	__u32			fwmark;		/* Fire wall mark from skb */
749c42b62   Julian Anastasov   ipvs: reduce sync...
514
  	unsigned long		sync_endtime;	/* jiffies + sent_retries */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
515
516
517
518
519
520
  
  	/* Control members */
  	struct ip_vs_conn       *control;       /* Master control connection */
  	atomic_t                n_control;      /* Number of controlled ones */
  	struct ip_vs_dest       *dest;          /* real server */
  	atomic_t                in_pkts;        /* incoming packet counter */
07dcc686f   Simon Horman   ipvs: Clean up co...
521
522
523
524
  	/* Packet transmitter for different forwarding methods.  If it
  	 * mangles the packet, it must return NF_DROP or better NF_STOLEN,
  	 * otherwise this must be changed to a sk_buff **.
  	 * NF_ACCEPT can be returned when destination is local.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
525
526
  	 */
  	int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp,
d4383f04d   Jesper Dangaard Brouer   ipvs: API change ...
527
  			   struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
528
529
  
  	/* Note: we can group the following members into a structure,
07dcc686f   Simon Horman   ipvs: Clean up co...
530
531
532
  	 * in order to save more space, and the following members are
  	 * only used in VS/NAT anyway
  	 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
533
534
535
536
  	struct ip_vs_app        *app;           /* bound ip_vs_app object */
  	void                    *app_data;      /* Application private data */
  	struct ip_vs_seq        in_seq;         /* incoming seq. struct */
  	struct ip_vs_seq        out_seq;        /* outgoing seq. struct */
85999283a   Simon Horman   IPVS: Add struct ...
537

e9e5eee87   Simon Horman   IPVS: Add persist...
538
  	const struct ip_vs_pe	*pe;
85999283a   Simon Horman   IPVS: Add struct ...
539
540
  	char			*pe_data;
  	__u8			pe_data_len;
088339a57   Julian Anastasov   ipvs: convert con...
541
542
  
  	struct rcu_head		rcu_head;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
543
  };
07dcc686f   Simon Horman   ipvs: Clean up co...
544
545
  /* Extended internal versions of struct ip_vs_service_user and ip_vs_dest_user
   * for IPv6 support.
c860c6b14   Julius Volz   IPVS: Add interna...
546
   *
07dcc686f   Simon Horman   ipvs: Clean up co...
547
548
549
   * We need these to conveniently pass around service and destination
   * options, but unfortunately, we also need to keep the old definitions to
   * maintain userspace backwards compatibility for the setsockopt interface.
c860c6b14   Julius Volz   IPVS: Add interna...
550
551
552
553
554
555
   */
  struct ip_vs_service_user_kern {
  	/* virtual service addresses */
  	u16			af;
  	u16			protocol;
  	union nf_inet_addr	addr;		/* virtual ip address */
0a925864c   Julian Anastasov   ipvs: fix sparse ...
556
  	__be16			port;
c860c6b14   Julius Volz   IPVS: Add interna...
557
558
559
560
  	u32			fwmark;		/* firwall mark of service */
  
  	/* virtual service options */
  	char			*sched_name;
0d1e71b04   Simon Horman   IPVS: Allow confi...
561
  	char			*pe_name;
95c961747   Eric Dumazet   net: cleanup unsi...
562
563
  	unsigned int		flags;		/* virtual service flags */
  	unsigned int		timeout;	/* persistent timeout in sec */
0a925864c   Julian Anastasov   ipvs: fix sparse ...
564
  	__be32			netmask;	/* persistent netmask or plen */
c860c6b14   Julius Volz   IPVS: Add interna...
565
566
567
568
569
570
  };
  
  
  struct ip_vs_dest_user_kern {
  	/* destination server address */
  	union nf_inet_addr	addr;
0a925864c   Julian Anastasov   ipvs: fix sparse ...
571
  	__be16			port;
c860c6b14   Julius Volz   IPVS: Add interna...
572
573
  
  	/* real server options */
95c961747   Eric Dumazet   net: cleanup unsi...
574
  	unsigned int		conn_flags;	/* connection flags */
c860c6b14   Julius Volz   IPVS: Add interna...
575
576
577
578
579
  	int			weight;		/* destination weight */
  
  	/* thresholds for active connections */
  	u32			u_threshold;	/* upper threshold */
  	u32			l_threshold;	/* lower threshold */
6cff339bb   Alex Gartrell   ipvs: Add destina...
580
581
582
  
  	/* Address family of addr */
  	u16			af;
c860c6b14   Julius Volz   IPVS: Add interna...
583
584
585
586
  };
  
  
  /*
07dcc686f   Simon Horman   ipvs: Clean up co...
587
588
   * The information about the virtual service offered to the net and the
   * forwarding entries.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
589
590
   */
  struct ip_vs_service {
ceec4c381   Julian Anastasov   ipvs: convert ser...
591
592
  	struct hlist_node	s_list;   /* for normal service table */
  	struct hlist_node	f_list;   /* for fwmark-based service table */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
593
  	atomic_t		refcnt;   /* reference counter */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
594

e7ade46a5   Julius Volz   IPVS: Change IPVS...
595
  	u16			af;       /* address family */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
596
  	__u16			protocol; /* which protocol (TCP/UDP) */
e7ade46a5   Julius Volz   IPVS: Change IPVS...
597
  	union nf_inet_addr	addr;	  /* IP address for virtual service */
014d730d5   Al Viro   [IPVS]: ipvs anno...
598
  	__be16			port;	  /* port number for the service */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
599
  	__u32                   fwmark;   /* firewall mark of the service */
95c961747   Eric Dumazet   net: cleanup unsi...
600
601
  	unsigned int		flags;	  /* service status flags */
  	unsigned int		timeout;  /* persistent timeout in ticks */
0a925864c   Julian Anastasov   ipvs: fix sparse ...
602
  	__be32			netmask;  /* grouping granularity, mask/plen */
3109d2f2d   Eric W. Biederman   ipvs: Store ipvs ...
603
  	struct netns_ipvs	*ipvs;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
604
605
606
607
  
  	struct list_head	destinations;  /* real server d-linked list */
  	__u32			num_dests;     /* number of servers */
  	struct ip_vs_stats      stats;         /* statistics for the service */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
608
609
  
  	/* for scheduling */
ceec4c381   Julian Anastasov   ipvs: convert ser...
610
  	struct ip_vs_scheduler __rcu *scheduler; /* bound scheduler object */
ba3a3ce14   Julian Anastasov   ipvs: convert sch...
611
  	spinlock_t		sched_lock;    /* lock sched_data */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
612
  	void			*sched_data;   /* scheduler application data */
85999283a   Simon Horman   IPVS: Add struct ...
613
614
  
  	/* alternate persistence engine */
ceec4c381   Julian Anastasov   ipvs: convert ser...
615
616
617
  	struct ip_vs_pe __rcu	*pe;
  
  	struct rcu_head		rcu_head;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
618
  };
026ace060   Julian Anastasov   ipvs: optimize ds...
619
620
621
622
623
624
625
  /* Information for cached dst */
  struct ip_vs_dest_dst {
  	struct dst_entry	*dst_cache;	/* destination cache entry */
  	u32			dst_cookie;
  	union nf_inet_addr	dst_saddr;
  	struct rcu_head		rcu_head;
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
626

07dcc686f   Simon Horman   ipvs: Clean up co...
627
628
  /* The real server destination forwarding entry with ip address, port number,
   * and so on.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
629
630
631
   */
  struct ip_vs_dest {
  	struct list_head	n_list;   /* for the dests in the service */
276472eae   Julian Anastasov   ipvs: remove rs_l...
632
  	struct hlist_node	d_list;   /* for table with all the dests */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
633

e7ade46a5   Julius Volz   IPVS: Change IPVS...
634
  	u16			af;		/* address family */
014d730d5   Al Viro   [IPVS]: ipvs anno...
635
  	__be16			port;		/* port number of the server */
f2431e6e9   Hans Schillstrom   IPVS: netns, tras...
636
  	union nf_inet_addr	addr;		/* IP address of the server */
95c961747   Eric Dumazet   net: cleanup unsi...
637
  	volatile unsigned int	flags;		/* dest status flags */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
638
639
640
641
642
  	atomic_t		conn_flags;	/* flags to copy to conn */
  	atomic_t		weight;		/* server weight */
  
  	atomic_t		refcnt;		/* reference counter */
  	struct ip_vs_stats      stats;          /* statistics */
bcbde4c0a   Julian Anastasov   ipvs: make the se...
643
  	unsigned long		idle_start;	/* start time, jiffies */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
644
645
646
647
648
649
650
651
652
653
  
  	/* connection counters and thresholds */
  	atomic_t		activeconns;	/* active connections */
  	atomic_t		inactconns;	/* inactive connections */
  	atomic_t		persistconns;	/* persistent connections */
  	__u32			u_threshold;	/* upper threshold */
  	__u32			l_threshold;	/* lower threshold */
  
  	/* for destination cache */
  	spinlock_t		dst_lock;	/* lock of dst_cache */
026ace060   Julian Anastasov   ipvs: optimize ds...
654
  	struct ip_vs_dest_dst __rcu *dest_dst;	/* cached dst info */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
655
656
  
  	/* for virtual service */
bcbde4c0a   Julian Anastasov   ipvs: make the se...
657
  	struct ip_vs_service __rcu *svc;	/* service it belongs to */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
658
  	__u16			protocol;	/* which protocol (TCP/UDP) */
014d730d5   Al Viro   [IPVS]: ipvs anno...
659
  	__be16			vport;		/* virtual port number */
f2431e6e9   Hans Schillstrom   IPVS: netns, tras...
660
  	union nf_inet_addr	vaddr;		/* virtual IP address */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
661
  	__u32			vfwmark;	/* firewall mark of service */
276472eae   Julian Anastasov   ipvs: remove rs_l...
662

578bc3ef1   Julian Anastasov   ipvs: reorganize ...
663
  	struct list_head	t_list;		/* in dest_trash */
276472eae   Julian Anastasov   ipvs: remove rs_l...
664
  	unsigned int		in_rs_table:1;	/* we are in rs_table */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
665
  };
07dcc686f   Simon Horman   ipvs: Clean up co...
666
  /* The scheduler object */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
667
668
669
670
671
672
673
674
675
  struct ip_vs_scheduler {
  	struct list_head	n_list;		/* d-linked list head */
  	char			*name;		/* scheduler name */
  	atomic_t		refcnt;		/* reference counter */
  	struct module		*module;	/* THIS_MODULE/NULL */
  
  	/* scheduler initializing service */
  	int (*init_service)(struct ip_vs_service *svc);
  	/* scheduling service finish */
ed3ffc4e4   Julian Anastasov   ipvs: do not expe...
676
  	void (*done_service)(struct ip_vs_service *svc);
6b6df4666   Julian Anastasov   ipvs: preparation...
677
678
679
680
681
682
  	/* dest is linked */
  	int (*add_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest);
  	/* dest is unlinked */
  	int (*del_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest);
  	/* dest is updated */
  	int (*upd_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
683
684
685
  
  	/* selecting a server from the given service */
  	struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc,
bba54de5b   Julian Anastasov   ipvs: provide iph...
686
687
  				       const struct sk_buff *skb,
  				       struct ip_vs_iphdr *iph);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
688
  };
85999283a   Simon Horman   IPVS: Add struct ...
689
690
691
692
693
694
695
696
697
698
699
700
701
  /* The persistence engine object */
  struct ip_vs_pe {
  	struct list_head	n_list;		/* d-linked list head */
  	char			*name;		/* scheduler name */
  	atomic_t		refcnt;		/* reference counter */
  	struct module		*module;	/* THIS_MODULE/NULL */
  
  	/* get the connection template, if any */
  	int (*fill_param)(struct ip_vs_conn_param *p, struct sk_buff *skb);
  	bool (*ct_match)(const struct ip_vs_conn_param *p,
  			 struct ip_vs_conn *ct);
  	u32 (*hashkey_raw)(const struct ip_vs_conn_param *p, u32 initval,
  			   bool inverse);
a3c918acd   Simon Horman   IPVS: Add persist...
702
  	int (*show_pe_data)(const struct ip_vs_conn *cp, char *buf);
39b972231   Marco Angaroni   ipvs: handle conn...
703
704
705
706
707
708
  	/* create connections for real-server outgoing packets */
  	struct ip_vs_conn* (*conn_out)(struct ip_vs_service *svc,
  				       struct ip_vs_dest *dest,
  				       struct sk_buff *skb,
  				       const struct ip_vs_iphdr *iph,
  				       __be16 dport, __be16 cport);
85999283a   Simon Horman   IPVS: Add struct ...
709
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
710

07dcc686f   Simon Horman   ipvs: Clean up co...
711
  /* The application module object (a.k.a. app incarnation) */
fd2c3ef76   Eric Dumazet   net: cleanup incl...
712
  struct ip_vs_app {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
713
714
715
716
717
718
719
720
721
722
  	struct list_head	a_list;		/* member in app list */
  	int			type;		/* IP_VS_APP_TYPE_xxx */
  	char			*name;		/* application module name */
  	__u16			protocol;
  	struct module		*module;	/* THIS_MODULE/NULL */
  	struct list_head	incs_list;	/* list of incarnations */
  
  	/* members for application incarnations */
  	struct list_head	p_list;		/* member in proto app list */
  	struct ip_vs_app	*app;		/* its real application */
014d730d5   Al Viro   [IPVS]: ipvs anno...
723
  	__be16			port;		/* port number in net order */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
724
  	atomic_t		usecnt;		/* usage counter */
363c97d74   Julian Anastasov   ipvs: convert app...
725
  	struct rcu_head		rcu_head;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
726

07dcc686f   Simon Horman   ipvs: Clean up co...
727
  	/* output hook: Process packet in inout direction, diff set for TCP.
8b27b10f5   Julian Anastasov   ipvs: optimize ch...
728
729
730
  	 * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
  	 *	   2=Mangled but checksum was not updated
  	 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
731
  	int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *,
3db05fea5   Herbert Xu   [NETFILTER]: Repl...
732
  		       struct sk_buff *, int *diff);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
733

07dcc686f   Simon Horman   ipvs: Clean up co...
734
  	/* input hook: Process packet in outin direction, diff set for TCP.
8b27b10f5   Julian Anastasov   ipvs: optimize ch...
735
736
737
  	 * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
  	 *	   2=Mangled but checksum was not updated
  	 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
738
  	int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *,
3db05fea5   Herbert Xu   [NETFILTER]: Repl...
739
  		      struct sk_buff *, int *diff);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
  
  	/* ip_vs_app initializer */
  	int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *);
  
  	/* ip_vs_app finish */
  	int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *);
  
  
  	/* not used now */
  	int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *,
  			 struct ip_vs_protocol *);
  
  	void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *);
  
  	int *			timeout_table;
  	int *			timeouts;
  	int			timeouts_size;
  
  	int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app,
  			     int *verdict, struct ip_vs_conn **cpp);
  
  	struct ip_vs_conn *
  	(*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app,
d4383f04d   Jesper Dangaard Brouer   ipvs: API change ...
763
  		       const struct iphdr *iph, int inverse);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
764
765
766
  
  	struct ip_vs_conn *
  	(*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app,
d4383f04d   Jesper Dangaard Brouer   ipvs: API change ...
767
  			const struct iphdr *iph, int inverse);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
768
769
770
771
772
773
774
  
  	int (*state_transition)(struct ip_vs_conn *cp, int direction,
  				const struct sk_buff *skb,
  				struct ip_vs_app *app);
  
  	void (*timeout_change)(struct ip_vs_app *app, int flags);
  };
f73181c82   Pablo Neira Ayuso   ipvs: add support...
775
776
777
  struct ipvs_master_sync_state {
  	struct list_head	sync_queue;
  	struct ip_vs_sync_buff	*sync_buff;
079956742   Zhang Yanfei   ipvs: change type...
778
  	unsigned long		sync_queue_len;
f73181c82   Pablo Neira Ayuso   ipvs: add support...
779
780
781
782
783
  	unsigned int		sync_queue_delay;
  	struct task_struct	*master_thread;
  	struct delayed_work	master_wakeup_work;
  	struct netns_ipvs	*ipvs;
  };
578bc3ef1   Julian Anastasov   ipvs: reorganize ...
784
785
  /* How much time to keep dests in trash */
  #define IP_VS_DEST_TRASH_PERIOD		(120 * HZ)
e4ff67513   Julian Anastasov   ipvs: add sync_ma...
786
  struct ipvs_sync_daemon_cfg {
d33288172   Julian Anastasov   ipvs: add more mc...
787
  	union nf_inet_addr	mcast_group;
e4ff67513   Julian Anastasov   ipvs: add sync_ma...
788
789
  	int			syncid;
  	u16			sync_maxlen;
d33288172   Julian Anastasov   ipvs: add more mc...
790
791
792
  	u16			mcast_port;
  	u8			mcast_af;
  	u8			mcast_ttl;
e4ff67513   Julian Anastasov   ipvs: add sync_ma...
793
794
795
  	/* multicast interface name */
  	char			mcast_ifn[IP_VS_IFNAME_MAXLEN];
  };
2553d064f   Julian Anastasov   ipvs: move struct...
796
797
798
  /* IPVS in network namespace */
  struct netns_ipvs {
  	int			gen;		/* Generation */
7a4f0761f   Hans Schillstrom   IPVS: init and cl...
799
  	int			enable;		/* enable like nf_hooks do */
07dcc686f   Simon Horman   ipvs: Clean up co...
800
  	/* Hash table: for real service lookups */
2553d064f   Julian Anastasov   ipvs: move struct...
801
802
803
  	#define IP_VS_RTAB_BITS 4
  	#define IP_VS_RTAB_SIZE (1 << IP_VS_RTAB_BITS)
  	#define IP_VS_RTAB_MASK (IP_VS_RTAB_SIZE - 1)
276472eae   Julian Anastasov   ipvs: remove rs_l...
804
  	struct hlist_head	rs_table[IP_VS_RTAB_SIZE];
2553d064f   Julian Anastasov   ipvs: move struct...
805
806
  	/* ip_vs_app */
  	struct list_head	app_list;
2553d064f   Julian Anastasov   ipvs: move struct...
807
808
809
810
811
812
813
814
815
  	/* ip_vs_proto */
  	#define IP_VS_PROTO_TAB_SIZE	32	/* must be power of 2 */
  	struct ip_vs_proto_data *proto_data_table[IP_VS_PROTO_TAB_SIZE];
  	/* ip_vs_proto_tcp */
  #ifdef CONFIG_IP_VS_PROTO_TCP
  	#define	TCP_APP_TAB_BITS	4
  	#define	TCP_APP_TAB_SIZE	(1 << TCP_APP_TAB_BITS)
  	#define	TCP_APP_TAB_MASK	(TCP_APP_TAB_SIZE - 1)
  	struct list_head	tcp_apps[TCP_APP_TAB_SIZE];
2553d064f   Julian Anastasov   ipvs: move struct...
816
817
818
819
820
821
822
  #endif
  	/* ip_vs_proto_udp */
  #ifdef CONFIG_IP_VS_PROTO_UDP
  	#define	UDP_APP_TAB_BITS	4
  	#define	UDP_APP_TAB_SIZE	(1 << UDP_APP_TAB_BITS)
  	#define	UDP_APP_TAB_MASK	(UDP_APP_TAB_SIZE - 1)
  	struct list_head	udp_apps[UDP_APP_TAB_SIZE];
2553d064f   Julian Anastasov   ipvs: move struct...
823
824
825
826
827
828
829
830
  #endif
  	/* ip_vs_proto_sctp */
  #ifdef CONFIG_IP_VS_PROTO_SCTP
  	#define SCTP_APP_TAB_BITS	4
  	#define SCTP_APP_TAB_SIZE	(1 << SCTP_APP_TAB_BITS)
  	#define SCTP_APP_TAB_MASK	(SCTP_APP_TAB_SIZE - 1)
  	/* Hash table for SCTP application incarnations	 */
  	struct list_head	sctp_apps[SCTP_APP_TAB_SIZE];
2553d064f   Julian Anastasov   ipvs: move struct...
831
832
  #endif
  	/* ip_vs_conn */
07dcc686f   Simon Horman   ipvs: Clean up co...
833
  	atomic_t		conn_count;      /* connection counter */
2553d064f   Julian Anastasov   ipvs: move struct...
834
835
  
  	/* ip_vs_ctl */
2a0751af0   Julian Anastasov   ipvs: reorganize ...
836
  	struct ip_vs_stats		tot_stats;  /* Statistics & est. */
2553d064f   Julian Anastasov   ipvs: move struct...
837
838
  
  	int			num_services;    /* no of virtual services */
f2247fbdc   Simon Horman   IPVS: Conditional...
839

f2247fbdc   Simon Horman   IPVS: Conditional...
840
841
  	/* Trash for destinations */
  	struct list_head	dest_trash;
578bc3ef1   Julian Anastasov   ipvs: reorganize ...
842
843
  	spinlock_t		dest_trash_lock;
  	struct timer_list	dest_trash_timer; /* expiration timer */
f2247fbdc   Simon Horman   IPVS: Conditional...
844
845
846
  	/* Service counters */
  	atomic_t		ftpsvc_counter;
  	atomic_t		nullsvc_counter;
39b972231   Marco Angaroni   ipvs: handle conn...
847
  	atomic_t		conn_out_counter;
f2247fbdc   Simon Horman   IPVS: Conditional...
848
849
  
  #ifdef CONFIG_SYSCTL
2553d064f   Julian Anastasov   ipvs: move struct...
850
851
852
853
854
855
856
857
858
  	/* 1/rate drop and drop-entry variables */
  	struct delayed_work	defense_work;   /* Work handler */
  	int			drop_rate;
  	int			drop_counter;
  	atomic_t		dropentry;
  	/* locks in ctl.c */
  	spinlock_t		dropentry_lock;  /* drop entry handling */
  	spinlock_t		droppacket_lock; /* drop packet handling */
  	spinlock_t		securetcp_lock;  /* state and timeout tables */
2553d064f   Julian Anastasov   ipvs: move struct...
859
860
861
862
  
  	/* sys-ctl struct */
  	struct ctl_table_header	*sysctl_hdr;
  	struct ctl_table	*sysctl_tbl;
f2247fbdc   Simon Horman   IPVS: Conditional...
863
  #endif
2553d064f   Julian Anastasov   ipvs: move struct...
864
865
866
867
868
869
870
871
872
873
874
  	/* sysctl variables */
  	int			sysctl_amemthresh;
  	int			sysctl_am_droprate;
  	int			sysctl_drop_entry;
  	int			sysctl_drop_packet;
  	int			sysctl_secure_tcp;
  #ifdef CONFIG_IP_VS_NFCT
  	int			sysctl_conntrack;
  #endif
  	int			sysctl_snat_reroute;
  	int			sysctl_sync_ver;
f73181c82   Pablo Neira Ayuso   ipvs: add support...
875
  	int			sysctl_sync_ports;
4d0c875dc   Julian Anastasov   ipvs: add sync_pe...
876
  	int			sysctl_sync_persist_mode;
079956742   Zhang Yanfei   ipvs: change type...
877
  	unsigned long		sysctl_sync_qlen_max;
1c003b158   Pablo Neira Ayuso   ipvs: wakeup mast...
878
  	int			sysctl_sync_sock_size;
2553d064f   Julian Anastasov   ipvs: move struct...
879
880
  	int			sysctl_cache_bypass;
  	int			sysctl_expire_nodest_conn;
c6c96c188   Alexander Frolkin   ipvs: sloppy TCP ...
881
882
  	int			sysctl_sloppy_tcp;
  	int			sysctl_sloppy_sctp;
2553d064f   Julian Anastasov   ipvs: move struct...
883
884
  	int			sysctl_expire_quiescent_template;
  	int			sysctl_sync_threshold[2];
749c42b62   Julian Anastasov   ipvs: reduce sync...
885
886
  	unsigned int		sysctl_sync_refresh_period;
  	int			sysctl_sync_retries;
2553d064f   Julian Anastasov   ipvs: move struct...
887
  	int			sysctl_nat_icmp_send;
3654e6113   Julian Anastasov   ipvs: add pmtu_di...
888
  	int			sysctl_pmtu_disc;
0c12582fb   Julian Anastasov   ipvs: add backup_...
889
  	int			sysctl_backup_only;
d752c3645   Marcelo Ricardo Leitner   ipvs: allow resch...
890
  	int			sysctl_conn_reuse_mode;
94485fedc   Alex Gartrell   ipvs: add schedul...
891
  	int			sysctl_schedule_icmp;
4e478098a   Alex Gartrell   ipvs: add sysctl ...
892
  	int			sysctl_ignore_tunneled;
2553d064f   Julian Anastasov   ipvs: move struct...
893
894
895
896
897
898
899
900
901
902
903
904
905
906
  
  	/* ip_vs_lblc */
  	int			sysctl_lblc_expiration;
  	struct ctl_table_header	*lblc_ctl_header;
  	struct ctl_table	*lblc_ctl_table;
  	/* ip_vs_lblcr */
  	int			sysctl_lblcr_expiration;
  	struct ctl_table_header	*lblcr_ctl_header;
  	struct ctl_table	*lblcr_ctl_table;
  	/* ip_vs_est */
  	struct list_head	est_list;	/* estimator list */
  	spinlock_t		est_lock;
  	struct timer_list	est_timer;	/* Estimation timer */
  	/* ip_vs_sync */
2553d064f   Julian Anastasov   ipvs: move struct...
907
  	spinlock_t		sync_lock;
f73181c82   Pablo Neira Ayuso   ipvs: add support...
908
  	struct ipvs_master_sync_state *ms;
2553d064f   Julian Anastasov   ipvs: move struct...
909
  	spinlock_t		sync_buff_lock;
f73181c82   Pablo Neira Ayuso   ipvs: add support...
910
911
  	struct task_struct	**backup_threads;
  	int			threads_mask;
2553d064f   Julian Anastasov   ipvs: move struct...
912
  	volatile int		sync_state;
ae1d48b23   Hans Schillstrom   IPVS netns shutdo...
913
  	struct mutex		sync_mutex;
e4ff67513   Julian Anastasov   ipvs: add sync_ma...
914
915
  	struct ipvs_sync_daemon_cfg	mcfg;	/* Master Configuration */
  	struct ipvs_sync_daemon_cfg	bcfg;	/* Backup Configuration */
2553d064f   Julian Anastasov   ipvs: move struct...
916
917
  	/* net name space ptr */
  	struct net		*net;            /* Needed by timer routines */
07dcc686f   Simon Horman   ipvs: Clean up co...
918
919
920
  	/* Number of heterogeneous destinations, needed becaus heterogeneous
  	 * are not supported when synchronization is enabled.
  	 */
391f503d6   Alex Gartrell   ipvs: prevent mix...
921
  	unsigned int		mixed_address_family_dests;
2553d064f   Julian Anastasov   ipvs: move struct...
922
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
923

59e0350ea   Simon Horman   IPVS: Add {sysctl...
924
925
  #define DEFAULT_SYNC_THRESHOLD	3
  #define DEFAULT_SYNC_PERIOD	50
7532e8d40   Simon Horman   IPVS: Add sysctl_...
926
  #define DEFAULT_SYNC_VER	1
c6c96c188   Alexander Frolkin   ipvs: sloppy TCP ...
927
928
  #define DEFAULT_SLOPPY_TCP	0
  #define DEFAULT_SLOPPY_SCTP	0
749c42b62   Julian Anastasov   ipvs: reduce sync...
929
930
  #define DEFAULT_SYNC_REFRESH_PERIOD	(0U * HZ)
  #define DEFAULT_SYNC_RETRIES		0
1c003b158   Pablo Neira Ayuso   ipvs: wakeup mast...
931
932
933
934
  #define IPVS_SYNC_WAKEUP_RATE	8
  #define IPVS_SYNC_QLEN_MAX	(IPVS_SYNC_WAKEUP_RATE * 4)
  #define IPVS_SYNC_SEND_DELAY	(HZ / 50)
  #define IPVS_SYNC_CHECK_PERIOD	HZ
749c42b62   Julian Anastasov   ipvs: reduce sync...
935
  #define IPVS_SYNC_FLUSH_TIME	(HZ * 2)
f73181c82   Pablo Neira Ayuso   ipvs: add support...
936
  #define IPVS_SYNC_PORTS_MAX	(1 << 6)
59e0350ea   Simon Horman   IPVS: Add {sysctl...
937
938
939
940
941
942
943
944
945
946
  
  #ifdef CONFIG_SYSCTL
  
  static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs)
  {
  	return ipvs->sysctl_sync_threshold[0];
  }
  
  static inline int sysctl_sync_period(struct netns_ipvs *ipvs)
  {
749c42b62   Julian Anastasov   ipvs: reduce sync...
947
948
949
950
951
952
953
954
955
956
957
  	return ACCESS_ONCE(ipvs->sysctl_sync_threshold[1]);
  }
  
  static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs *ipvs)
  {
  	return ACCESS_ONCE(ipvs->sysctl_sync_refresh_period);
  }
  
  static inline int sysctl_sync_retries(struct netns_ipvs *ipvs)
  {
  	return ipvs->sysctl_sync_retries;
59e0350ea   Simon Horman   IPVS: Add {sysctl...
958
  }
7532e8d40   Simon Horman   IPVS: Add sysctl_...
959
960
961
962
  static inline int sysctl_sync_ver(struct netns_ipvs *ipvs)
  {
  	return ipvs->sysctl_sync_ver;
  }
c6c96c188   Alexander Frolkin   ipvs: sloppy TCP ...
963
964
965
966
967
968
969
970
971
  static inline int sysctl_sloppy_tcp(struct netns_ipvs *ipvs)
  {
  	return ipvs->sysctl_sloppy_tcp;
  }
  
  static inline int sysctl_sloppy_sctp(struct netns_ipvs *ipvs)
  {
  	return ipvs->sysctl_sloppy_sctp;
  }
f73181c82   Pablo Neira Ayuso   ipvs: add support...
972
973
974
975
  static inline int sysctl_sync_ports(struct netns_ipvs *ipvs)
  {
  	return ACCESS_ONCE(ipvs->sysctl_sync_ports);
  }
4d0c875dc   Julian Anastasov   ipvs: add sync_pe...
976
977
978
979
  static inline int sysctl_sync_persist_mode(struct netns_ipvs *ipvs)
  {
  	return ipvs->sysctl_sync_persist_mode;
  }
079956742   Zhang Yanfei   ipvs: change type...
980
  static inline unsigned long sysctl_sync_qlen_max(struct netns_ipvs *ipvs)
1c003b158   Pablo Neira Ayuso   ipvs: wakeup mast...
981
982
983
984
985
986
987
988
  {
  	return ipvs->sysctl_sync_qlen_max;
  }
  
  static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs)
  {
  	return ipvs->sysctl_sync_sock_size;
  }
3654e6113   Julian Anastasov   ipvs: add pmtu_di...
989
990
991
992
  static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs)
  {
  	return ipvs->sysctl_pmtu_disc;
  }
0c12582fb   Julian Anastasov   ipvs: add backup_...
993
994
995
996
997
  static inline int sysctl_backup_only(struct netns_ipvs *ipvs)
  {
  	return ipvs->sync_state & IP_VS_STATE_BACKUP &&
  	       ipvs->sysctl_backup_only;
  }
d752c3645   Marcelo Ricardo Leitner   ipvs: allow resch...
998
999
1000
1001
  static inline int sysctl_conn_reuse_mode(struct netns_ipvs *ipvs)
  {
  	return ipvs->sysctl_conn_reuse_mode;
  }
94485fedc   Alex Gartrell   ipvs: add schedul...
1002
1003
1004
1005
  static inline int sysctl_schedule_icmp(struct netns_ipvs *ipvs)
  {
  	return ipvs->sysctl_schedule_icmp;
  }
4e478098a   Alex Gartrell   ipvs: add sysctl ...
1006
1007
1008
1009
  static inline int sysctl_ignore_tunneled(struct netns_ipvs *ipvs)
  {
  	return ipvs->sysctl_ignore_tunneled;
  }
570329487   Eric W. Biederman   ipvs: Wrap sysctl...
1010
1011
1012
1013
  static inline int sysctl_cache_bypass(struct netns_ipvs *ipvs)
  {
  	return ipvs->sysctl_cache_bypass;
  }
59e0350ea   Simon Horman   IPVS: Add {sysctl...
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
  #else
  
  static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs)
  {
  	return DEFAULT_SYNC_THRESHOLD;
  }
  
  static inline int sysctl_sync_period(struct netns_ipvs *ipvs)
  {
  	return DEFAULT_SYNC_PERIOD;
  }
749c42b62   Julian Anastasov   ipvs: reduce sync...
1025
1026
1027
1028
1029
1030
1031
1032
1033
  static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs *ipvs)
  {
  	return DEFAULT_SYNC_REFRESH_PERIOD;
  }
  
  static inline int sysctl_sync_retries(struct netns_ipvs *ipvs)
  {
  	return DEFAULT_SYNC_RETRIES & 3;
  }
7532e8d40   Simon Horman   IPVS: Add sysctl_...
1034
1035
1036
1037
  static inline int sysctl_sync_ver(struct netns_ipvs *ipvs)
  {
  	return DEFAULT_SYNC_VER;
  }
c6c96c188   Alexander Frolkin   ipvs: sloppy TCP ...
1038
1039
1040
1041
1042
1043
1044
1045
1046
  static inline int sysctl_sloppy_tcp(struct netns_ipvs *ipvs)
  {
  	return DEFAULT_SLOPPY_TCP;
  }
  
  static inline int sysctl_sloppy_sctp(struct netns_ipvs *ipvs)
  {
  	return DEFAULT_SLOPPY_SCTP;
  }
f73181c82   Pablo Neira Ayuso   ipvs: add support...
1047
1048
1049
1050
  static inline int sysctl_sync_ports(struct netns_ipvs *ipvs)
  {
  	return 1;
  }
4d0c875dc   Julian Anastasov   ipvs: add sync_pe...
1051
1052
1053
1054
  static inline int sysctl_sync_persist_mode(struct netns_ipvs *ipvs)
  {
  	return 0;
  }
079956742   Zhang Yanfei   ipvs: change type...
1055
  static inline unsigned long sysctl_sync_qlen_max(struct netns_ipvs *ipvs)
1c003b158   Pablo Neira Ayuso   ipvs: wakeup mast...
1056
1057
1058
1059
1060
1061
1062
1063
  {
  	return IPVS_SYNC_QLEN_MAX;
  }
  
  static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs)
  {
  	return 0;
  }
3654e6113   Julian Anastasov   ipvs: add pmtu_di...
1064
1065
1066
1067
  static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs)
  {
  	return 1;
  }
0c12582fb   Julian Anastasov   ipvs: add backup_...
1068
1069
1070
1071
  static inline int sysctl_backup_only(struct netns_ipvs *ipvs)
  {
  	return 0;
  }
d752c3645   Marcelo Ricardo Leitner   ipvs: allow resch...
1072
1073
1074
1075
  static inline int sysctl_conn_reuse_mode(struct netns_ipvs *ipvs)
  {
  	return 1;
  }
94485fedc   Alex Gartrell   ipvs: add schedul...
1076
1077
1078
1079
  static inline int sysctl_schedule_icmp(struct netns_ipvs *ipvs)
  {
  	return 0;
  }
4e478098a   Alex Gartrell   ipvs: add sysctl ...
1080
1081
1082
1083
  static inline int sysctl_ignore_tunneled(struct netns_ipvs *ipvs)
  {
  	return 0;
  }
570329487   Eric W. Biederman   ipvs: Wrap sysctl...
1084
1085
1086
1087
  static inline int sysctl_cache_bypass(struct netns_ipvs *ipvs)
  {
  	return 0;
  }
59e0350ea   Simon Horman   IPVS: Add {sysctl...
1088
  #endif
07dcc686f   Simon Horman   ipvs: Clean up co...
1089
1090
  /* IPVS core functions
   * (from ip_vs_core.c)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1091
   */
5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
1092
1093
  const char *ip_vs_proto_name(unsigned int proto);
  void ip_vs_init_hash_table(struct list_head *table, int rows);
39b972231   Marco Angaroni   ipvs: handle conn...
1094
1095
1096
1097
1098
1099
  struct ip_vs_conn *ip_vs_new_conn_out(struct ip_vs_service *svc,
  				      struct ip_vs_dest *dest,
  				      struct sk_buff *skb,
  				      const struct ip_vs_iphdr *iph,
  				      __be16 dport,
  				      __be16 cport);
afdd61407   Sven Wegener   ipvs: Use ARRAY_S...
1100
  #define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t)))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1101

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1102
  #define IP_VS_APP_TYPE_FTP	1
07dcc686f   Simon Horman   ipvs: Clean up co...
1103
1104
  /* ip_vs_conn handling functions
   * (from ip_vs_conn.c)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1105
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1106
1107
1108
1109
1110
1111
  enum {
  	IP_VS_DIR_INPUT = 0,
  	IP_VS_DIR_OUTPUT,
  	IP_VS_DIR_INPUT_ONLY,
  	IP_VS_DIR_LAST,
  };
19913dec1   Eric W. Biederman   ipvs: Pass ipvs n...
1112
  static inline void ip_vs_conn_fill_param(struct netns_ipvs *ipvs, int af, int protocol,
f11017ec2   Simon Horman   IPVS: Add struct ...
1113
1114
1115
1116
1117
1118
  					 const union nf_inet_addr *caddr,
  					 __be16 cport,
  					 const union nf_inet_addr *vaddr,
  					 __be16 vport,
  					 struct ip_vs_conn_param *p)
  {
19913dec1   Eric W. Biederman   ipvs: Pass ipvs n...
1119
  	p->ipvs = ipvs;
f11017ec2   Simon Horman   IPVS: Add struct ...
1120
1121
1122
1123
1124
1125
  	p->af = af;
  	p->protocol = protocol;
  	p->caddr = caddr;
  	p->cport = cport;
  	p->vaddr = vaddr;
  	p->vport = vport;
85999283a   Simon Horman   IPVS: Add struct ...
1126
1127
  	p->pe = NULL;
  	p->pe_data = NULL;
f11017ec2   Simon Horman   IPVS: Add struct ...
1128
  }
28364a59f   Julius Volz   IPVS: Extend func...
1129

f11017ec2   Simon Horman   IPVS: Add struct ...
1130
1131
  struct ip_vs_conn *ip_vs_conn_in_get(const struct ip_vs_conn_param *p);
  struct ip_vs_conn *ip_vs_ct_in_get(const struct ip_vs_conn_param *p);
28364a59f   Julius Volz   IPVS: Extend func...
1132

ab1619764   Eric W. Biederman   ipvs: Pass ipvs i...
1133
1134
  struct ip_vs_conn * ip_vs_conn_in_get_proto(struct netns_ipvs *ipvs, int af,
  					    const struct sk_buff *skb,
802c41adc   Alex Gartrell   ipvs: drop invers...
1135
  					    const struct ip_vs_iphdr *iph);
5c0d2374a   Simon Horman   ipvs: provide def...
1136

f11017ec2   Simon Horman   IPVS: Add struct ...
1137
  struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1138

0cf705c8c   Eric W. Biederman   ipvs: Pass ipvs i...
1139
1140
  struct ip_vs_conn * ip_vs_conn_out_get_proto(struct netns_ipvs *ipvs, int af,
  					     const struct sk_buff *skb,
802c41adc   Alex Gartrell   ipvs: drop invers...
1141
  					     const struct ip_vs_iphdr *iph);
5c0d2374a   Simon Horman   ipvs: provide def...
1142

088339a57   Julian Anastasov   ipvs: convert con...
1143
1144
1145
1146
1147
1148
1149
1150
  /* Get reference to gain full access to conn.
   * By default, RCU read-side critical sections have access only to
   * conn fields and its PE data, see ip_vs_conn_rcu_free() for reference.
   */
  static inline bool __ip_vs_conn_get(struct ip_vs_conn *cp)
  {
  	return atomic_inc_not_zero(&cp->refcnt);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1151
1152
1153
  /* put back the conn without restarting its timer */
  static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
  {
4e857c58e   Peter Zijlstra   arch: Mass conver...
1154
  	smp_mb__before_atomic();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1155
1156
  	atomic_dec(&cp->refcnt);
  }
5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
1157
1158
  void ip_vs_conn_put(struct ip_vs_conn *cp);
  void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1159

ba38528aa   Alex Gartrell   ipvs: Supply dest...
1160
  struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af,
f11017ec2   Simon Horman   IPVS: Add struct ...
1161
  				  const union nf_inet_addr *daddr,
95c961747   Eric Dumazet   net: cleanup unsi...
1162
  				  __be16 dport, unsigned int flags,
0e051e683   Hans Schillstrom   IPVS: Backup, Pre...
1163
  				  struct ip_vs_dest *dest, __u32 fwmark);
5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
1164
  void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1165

5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
1166
  const char *ip_vs_state_name(__u16 proto, int state);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1167

69f390934   Eric W. Biederman   ipvs: Remove net ...
1168
  void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp);
3ec10d3a2   Marco Angaroni   ipvs: update real...
1169
  int ip_vs_check_template(struct ip_vs_conn *ct, struct ip_vs_dest *cdest);
423b55954   Eric W. Biederman   ipvs: Pass ipvs n...
1170
  void ip_vs_random_dropentry(struct netns_ipvs *ipvs);
5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
1171
1172
  int ip_vs_conn_init(void);
  void ip_vs_conn_cleanup(void);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1173
1174
1175
1176
1177
  
  static inline void ip_vs_control_del(struct ip_vs_conn *cp)
  {
  	struct ip_vs_conn *ctl_cp = cp->control;
  	if (!ctl_cp) {
cfc78c5a0   Julius Volz   IPVS: Adjust vari...
1178
1179
1180
1181
1182
1183
1184
  		IP_VS_ERR_BUF("request control DEL for uncontrolled: "
  			      "%s:%d to %s:%d
  ",
  			      IP_VS_DBG_ADDR(cp->af, &cp->caddr),
  			      ntohs(cp->cport),
  			      IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
  			      ntohs(cp->vport));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1185
1186
  		return;
  	}
cfc78c5a0   Julius Volz   IPVS: Adjust vari...
1187
1188
1189
1190
1191
1192
1193
  	IP_VS_DBG_BUF(7, "DELeting control for: "
  		      "cp.dst=%s:%d ctl_cp.dst=%s:%d
  ",
  		      IP_VS_DBG_ADDR(cp->af, &cp->caddr),
  		      ntohs(cp->cport),
  		      IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
  		      ntohs(ctl_cp->cport));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1194
1195
1196
  
  	cp->control = NULL;
  	if (atomic_read(&ctl_cp->n_control) == 0) {
cfc78c5a0   Julius Volz   IPVS: Adjust vari...
1197
1198
1199
1200
1201
1202
1203
  		IP_VS_ERR_BUF("BUG control DEL with n=0 : "
  			      "%s:%d to %s:%d
  ",
  			      IP_VS_DBG_ADDR(cp->af, &cp->caddr),
  			      ntohs(cp->cport),
  			      IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
  			      ntohs(cp->vport));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1204
1205
1206
1207
1208
1209
1210
1211
1212
  		return;
  	}
  	atomic_dec(&ctl_cp->n_control);
  }
  
  static inline void
  ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)
  {
  	if (cp->control) {
cfc78c5a0   Julius Volz   IPVS: Adjust vari...
1213
1214
1215
1216
1217
1218
1219
  		IP_VS_ERR_BUF("request control ADD for already controlled: "
  			      "%s:%d to %s:%d
  ",
  			      IP_VS_DBG_ADDR(cp->af, &cp->caddr),
  			      ntohs(cp->cport),
  			      IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
  			      ntohs(cp->vport));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1220
1221
  		ip_vs_control_del(cp);
  	}
cfc78c5a0   Julius Volz   IPVS: Adjust vari...
1222
1223
1224
1225
1226
1227
1228
  	IP_VS_DBG_BUF(7, "ADDing control for: "
  		      "cp.dst=%s:%d ctl_cp.dst=%s:%d
  ",
  		      IP_VS_DBG_ADDR(cp->af, &cp->caddr),
  		      ntohs(cp->cport),
  		      IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
  		      ntohs(ctl_cp->cport));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1229
1230
1231
1232
  
  	cp->control = ctl_cp;
  	atomic_inc(&ctl_cp->n_control);
  }
07dcc686f   Simon Horman   ipvs: Clean up co...
1233
  /* IPVS netns init & cleanup functions */
a4dd0360c   Eric W. Biederman   ipvs: Pass ipvs n...
1234
  int ip_vs_estimator_net_init(struct netns_ipvs *ipvs);
3d9937668   Eric W. Biederman   ipvs: Pass ipvs n...
1235
  int ip_vs_control_net_init(struct netns_ipvs *ipvs);
7d1f88eca   Eric W. Biederman   ipvs: Pass ipvs n...
1236
  int ip_vs_protocol_net_init(struct netns_ipvs *ipvs);
b5dd212cc   Eric W. Biederman   ipvs: Pass ipvs n...
1237
  int ip_vs_app_net_init(struct netns_ipvs *ipvs);
2f3edc6a5   Eric W. Biederman   ipvs: Pass ipvs n...
1238
  int ip_vs_conn_net_init(struct netns_ipvs *ipvs);
802cb4370   Eric W. Biederman   ipvs: Pass ipvs n...
1239
  int ip_vs_sync_net_init(struct netns_ipvs *ipvs);
2f3edc6a5   Eric W. Biederman   ipvs: Pass ipvs n...
1240
  void ip_vs_conn_net_cleanup(struct netns_ipvs *ipvs);
b5dd212cc   Eric W. Biederman   ipvs: Pass ipvs n...
1241
  void ip_vs_app_net_cleanup(struct netns_ipvs *ipvs);
7d1f88eca   Eric W. Biederman   ipvs: Pass ipvs n...
1242
  void ip_vs_protocol_net_cleanup(struct netns_ipvs *ipvs);
3d9937668   Eric W. Biederman   ipvs: Pass ipvs n...
1243
  void ip_vs_control_net_cleanup(struct netns_ipvs *ipvs);
a4dd0360c   Eric W. Biederman   ipvs: Pass ipvs n...
1244
  void ip_vs_estimator_net_cleanup(struct netns_ipvs *ipvs);
ebea1f7c0   Eric W. Biederman   ipvs: Pass ipvs n...
1245
  void ip_vs_sync_net_cleanup(struct netns_ipvs *ipvs);
56d2169b7   Eric W. Biederman   ipvs: Pass ipvs n...
1246
  void ip_vs_service_net_cleanup(struct netns_ipvs *ipvs);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1247

07dcc686f   Simon Horman   ipvs: Clean up co...
1248
1249
  /* IPVS application functions
   * (from ip_vs_app.c)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1250
1251
   */
  #define IP_VS_APP_MAX_PORTS  8
9f8128a56   Eric W. Biederman   ipvs: Pass ipvs n...
1252
1253
  struct ip_vs_app *register_ip_vs_app(struct netns_ipvs *ipvs, struct ip_vs_app *app);
  void unregister_ip_vs_app(struct netns_ipvs *ipvs, struct ip_vs_app *app);
5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
1254
1255
  int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
  void ip_vs_unbind_app(struct ip_vs_conn *cp);
3250dc9c5   Eric W. Biederman   ipvs: Pass ipvs n...
1256
  int register_ip_vs_app_inc(struct netns_ipvs *ipvs, struct ip_vs_app *app, __u16 proto,
5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
1257
1258
1259
1260
1261
1262
  			   __u16 port);
  int ip_vs_app_inc_get(struct ip_vs_app *inc);
  void ip_vs_app_inc_put(struct ip_vs_app *inc);
  
  int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb);
  int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1263

8be67a661   Simon Horman   IPVS: management ...
1264
1265
  int register_ip_vs_pe(struct ip_vs_pe *pe);
  int unregister_ip_vs_pe(struct ip_vs_pe *pe);
e9e5eee87   Simon Horman   IPVS: Add persist...
1266
  struct ip_vs_pe *ip_vs_pe_getbyname(const char *name);
fe5e7a1ef   Hans Schillstrom   IPVS: Backup, Add...
1267
  struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name);
e9e5eee87   Simon Horman   IPVS: Add persist...
1268

07dcc686f   Simon Horman   ipvs: Clean up co...
1269
  /* Use a #define to avoid all of module.h just for these trivial ops */
69e7dae40   Paul Gortmaker   ip_vs.h: fix impl...
1270
1271
  #define ip_vs_pe_get(pe)			\
  	if (pe && pe->module)			\
e9e5eee87   Simon Horman   IPVS: Add persist...
1272
  		__module_get(pe->module);
e9e5eee87   Simon Horman   IPVS: Add persist...
1273

69e7dae40   Paul Gortmaker   ip_vs.h: fix impl...
1274
1275
  #define ip_vs_pe_put(pe)			\
  	if (pe && pe->module)			\
e9e5eee87   Simon Horman   IPVS: Add persist...
1276
  		module_put(pe->module);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1277

07dcc686f   Simon Horman   ipvs: Clean up co...
1278
  /* IPVS protocol functions (from ip_vs_proto.c) */
5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
1279
1280
1281
1282
1283
1284
1285
1286
1287
  int ip_vs_protocol_init(void);
  void ip_vs_protocol_cleanup(void);
  void ip_vs_protocol_timeout_change(struct netns_ipvs *ipvs, int flags);
  int *ip_vs_create_timeout_table(int *table, int size);
  int ip_vs_set_state_timeout(int *table, int num, const char *const *names,
  			    const char *name, int to);
  void ip_vs_tcpudp_debug_packet(int af, struct ip_vs_protocol *pp,
  			       const struct sk_buff *skb, int offset,
  			       const char *msg);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1288
1289
1290
1291
1292
1293
  
  extern struct ip_vs_protocol ip_vs_protocol_tcp;
  extern struct ip_vs_protocol ip_vs_protocol_udp;
  extern struct ip_vs_protocol ip_vs_protocol_icmp;
  extern struct ip_vs_protocol ip_vs_protocol_esp;
  extern struct ip_vs_protocol ip_vs_protocol_ah;
2906f66a5   Venkata Mohan Reddy   ipvs: SCTP Traspo...
1294
  extern struct ip_vs_protocol ip_vs_protocol_sctp;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1295

07dcc686f   Simon Horman   ipvs: Clean up co...
1296
1297
  /* Registering/unregistering scheduler functions
   * (from ip_vs_sched.c)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1298
   */
5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
1299
1300
1301
1302
1303
1304
1305
1306
1307
  int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
  int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
  int ip_vs_bind_scheduler(struct ip_vs_service *svc,
  			 struct ip_vs_scheduler *scheduler);
  void ip_vs_unbind_scheduler(struct ip_vs_service *svc,
  			    struct ip_vs_scheduler *sched);
  struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name);
  void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler);
  struct ip_vs_conn *
190ecd27c   Julian Anastasov   ipvs: do not sche...
1308
  ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,
d4383f04d   Jesper Dangaard Brouer   ipvs: API change ...
1309
1310
  	       struct ip_vs_proto_data *pd, int *ignored,
  	       struct ip_vs_iphdr *iph);
5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
1311
1312
  int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
  		struct ip_vs_proto_data *pd, struct ip_vs_iphdr *iph);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1313

5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
1314
  void ip_vs_scheduler_err(struct ip_vs_service *svc, const char *msg);
41ac51eed   Patrick Schaaf   ipvs: make "no de...
1315

07dcc686f   Simon Horman   ipvs: Clean up co...
1316
  /* IPVS control data and functions (from ip_vs_ctl.c) */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1317
  extern struct ip_vs_stats ip_vs_stats;
b880c1f07   Hans Schillstrom   IPVS: Backup, add...
1318
  extern int sysctl_ip_vs_sync_ver;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1319

5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
1320
  struct ip_vs_service *
0a4fd6ce9   Eric W. Biederman   ipvs: Pass ipvs n...
1321
  ip_vs_service_find(struct netns_ipvs *ipvs, int af, __u32 fwmark, __u16 protocol,
3c2e0505d   Julius Volz   IPVS: Add v6 supp...
1322
  		  const union nf_inet_addr *vaddr, __be16 vport);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1323

48aed1b02   Eric W. Biederman   ipvs: Pass ipvs n...
1324
  bool ip_vs_has_real_service(struct netns_ipvs *ipvs, int af, __u16 protocol,
5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
1325
  			    const union nf_inet_addr *daddr, __be16 dport);
39b972231   Marco Angaroni   ipvs: handle conn...
1326
1327
1328
  struct ip_vs_dest *
  ip_vs_find_real_service(struct netns_ipvs *ipvs, int af, __u16 protocol,
  			const union nf_inet_addr *daddr, __be16 dport);
5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
1329
1330
1331
1332
1333
1334
1335
  int ip_vs_use_count_inc(void);
  void ip_vs_use_count_dec(void);
  int ip_vs_register_nl_ioctl(void);
  void ip_vs_unregister_nl_ioctl(void);
  int ip_vs_control_init(void);
  void ip_vs_control_cleanup(void);
  struct ip_vs_dest *
dc2add6f2   Eric W. Biederman   ipvs: Pass ipvs n...
1336
  ip_vs_find_dest(struct netns_ipvs *ipvs, int svc_af, int dest_af,
655eef103   Alex Gartrell   ipvs: Supply dest...
1337
1338
  		const union nf_inet_addr *daddr, __be16 dport,
  		const union nf_inet_addr *vaddr, __be16 vport,
52793dbe3   Julian Anastasov   ipvs: try also re...
1339
  		__u16 protocol, __u32 fwmark, __u32 flags);
5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
1340
  void ip_vs_try_bind_dest(struct ip_vs_conn *cp);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1341

fca9c20ae   Julian Anastasov   ipvs: add ip_vs_d...
1342
1343
1344
1345
1346
1347
1348
  static inline void ip_vs_dest_hold(struct ip_vs_dest *dest)
  {
  	atomic_inc(&dest->refcnt);
  }
  
  static inline void ip_vs_dest_put(struct ip_vs_dest *dest)
  {
4e857c58e   Peter Zijlstra   arch: Mass conver...
1349
  	smp_mb__before_atomic();
fca9c20ae   Julian Anastasov   ipvs: add ip_vs_d...
1350
1351
  	atomic_dec(&dest->refcnt);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1352

9e4e948a3   Julian Anastasov   ipvs: avoid rcu_b...
1353
1354
1355
1356
1357
  static inline void ip_vs_dest_put_and_free(struct ip_vs_dest *dest)
  {
  	if (atomic_dec_return(&dest->refcnt) < 0)
  		kfree(dest);
  }
07dcc686f   Simon Horman   ipvs: Clean up co...
1358
1359
  /* IPVS sync daemon data and function prototypes
   * (from ip_vs_sync.c)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1360
   */
6ac121d71   Eric W. Biederman   ipvs: Pass ipvs n...
1361
  int start_sync_thread(struct netns_ipvs *ipvs, struct ipvs_sync_daemon_cfg *cfg,
e4ff67513   Julian Anastasov   ipvs: add sync_ma...
1362
  		      int state);
b3cf3cbfb   Eric W. Biederman   ipvs: Pass ipvs n...
1363
  int stop_sync_thread(struct netns_ipvs *ipvs, int state);
b61a8c1a4   Eric W. Biederman   ipvs: Pass ipvs n...
1364
  void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1365

07dcc686f   Simon Horman   ipvs: Clean up co...
1366
  /* IPVS rate estimator prototypes (from ip_vs_est.c) */
0f34d54bf   Eric W. Biederman   ipvs: Pass ipvs n...
1367
1368
  void ip_vs_start_estimator(struct netns_ipvs *ipvs, struct ip_vs_stats *stats);
  void ip_vs_stop_estimator(struct netns_ipvs *ipvs, struct ip_vs_stats *stats);
5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
1369
  void ip_vs_zero_estimator(struct ip_vs_stats *stats);
cd67cd5eb   Julian Anastasov   ipvs: use 64-bit ...
1370
  void ip_vs_read_estimator(struct ip_vs_kstats *dst, struct ip_vs_stats *stats);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1371

07dcc686f   Simon Horman   ipvs: Clean up co...
1372
  /* Various IPVS packet transmitters (from ip_vs_xmit.c) */
5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
  int ip_vs_null_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
  		    struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
  int ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
  		      struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
  int ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
  		   struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
  int ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
  		      struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
  int ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
  		  struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
  int ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
  		    struct ip_vs_protocol *pp, int offset,
  		    unsigned int hooknum, struct ip_vs_iphdr *iph);
  void ip_vs_dest_dst_rcu_free(struct rcu_head *head);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1387

b3cdd2a73   Julius Volz   IPVS: Add and bin...
1388
  #ifdef CONFIG_IP_VS_IPV6
5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
  int ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
  			 struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
  int ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
  		      struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
  int ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
  			 struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
  int ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
  		     struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
  int ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
  		       struct ip_vs_protocol *pp, int offset,
  		       unsigned int hooknum, struct ip_vs_iphdr *iph);
b3cdd2a73   Julius Volz   IPVS: Add and bin...
1400
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1401

3a1bbf188   Simon Horman   IPVS: ip_vs_todro...
1402
  #ifdef CONFIG_SYSCTL
07dcc686f   Simon Horman   ipvs: Clean up co...
1403
1404
1405
  /* This is a simple mechanism to ignore packets when
   * we are loaded. Just set ip_vs_drop_rate to 'n' and
   * we start to drop 1/rate of the packets
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1406
   */
a0840e2e1   Hans Schillstrom   IPVS: netns, ip_v...
1407
  static inline int ip_vs_todrop(struct netns_ipvs *ipvs)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1408
  {
a0840e2e1   Hans Schillstrom   IPVS: netns, ip_v...
1409
1410
1411
1412
1413
  	if (!ipvs->drop_rate)
  		return 0;
  	if (--ipvs->drop_counter > 0)
  		return 0;
  	ipvs->drop_counter = ipvs->drop_rate;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1414
1415
  	return 1;
  }
3a1bbf188   Simon Horman   IPVS: ip_vs_todro...
1416
1417
1418
  #else
  static inline int ip_vs_todrop(struct netns_ipvs *ipvs) { return 0; }
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1419

07dcc686f   Simon Horman   ipvs: Clean up co...
1420
  /* ip_vs_fwd_tag returns the forwarding tag of the connection */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1421
  #define IP_VS_FWD_METHOD(cp)  (cp->flags & IP_VS_CONN_F_FWD_MASK)
732db659b   Adrian Bunk   [IPVS]: "extern i...
1422
  static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
  {
  	char fwd;
  
  	switch (IP_VS_FWD_METHOD(cp)) {
  	case IP_VS_CONN_F_MASQ:
  		fwd = 'M'; break;
  	case IP_VS_CONN_F_LOCALNODE:
  		fwd = 'L'; break;
  	case IP_VS_CONN_F_TUNNEL:
  		fwd = 'T'; break;
  	case IP_VS_CONN_F_DROUTE:
  		fwd = 'R'; break;
  	case IP_VS_CONN_F_BYPASS:
  		fwd = 'B'; break;
  	default:
  		fwd = '?'; break;
  	}
  	return fwd;
  }
5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
1442
1443
  void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,
  		    struct ip_vs_conn *cp, int dir);
b3cdd2a73   Julius Volz   IPVS: Add and bin...
1444
1445
  
  #ifdef CONFIG_IP_VS_IPV6
5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
1446
1447
  void ip_vs_nat_icmp_v6(struct sk_buff *skb, struct ip_vs_protocol *pp,
  		       struct ip_vs_conn *cp, int dir);
b3cdd2a73   Julius Volz   IPVS: Add and bin...
1448
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1449

5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
1450
  __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1451

f9214b262   Al Viro   [NET]: ipvs check...
1452
  static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1453
  {
f9214b262   Al Viro   [NET]: ipvs check...
1454
  	__be32 diff[2] = { ~old, new };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1455

07f0757a6   Joe Perches   include/net net/ ...
1456
  	return csum_partial(diff, sizeof(diff), oldsum);
f9214b262   Al Viro   [NET]: ipvs check...
1457
  }
0bbdd42b7   Julius Volz   IPVS: Extend prot...
1458
1459
1460
1461
1462
1463
  #ifdef CONFIG_IP_VS_IPV6
  static inline __wsum ip_vs_check_diff16(const __be32 *old, const __be32 *new,
  					__wsum oldsum)
  {
  	__be32 diff[8] = { ~old[3], ~old[2], ~old[1], ~old[0],
  			    new[3],  new[2],  new[1],  new[0] };
07f0757a6   Joe Perches   include/net net/ ...
1464
  	return csum_partial(diff, sizeof(diff), oldsum);
0bbdd42b7   Julius Volz   IPVS: Extend prot...
1465
1466
  }
  #endif
f9214b262   Al Viro   [NET]: ipvs check...
1467
1468
1469
  static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum)
  {
  	__be16 diff[2] = { ~old, new };
07f0757a6   Joe Perches   include/net net/ ...
1470
  	return csum_partial(diff, sizeof(diff), oldsum);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1471
  }
07dcc686f   Simon Horman   ipvs: Clean up co...
1472
  /* Forget current conntrack (unconfirmed) and attach notrack entry */
cf356d69d   Julian Anastasov   ipvs: switch to n...
1473
1474
1475
1476
  static inline void ip_vs_notrack(struct sk_buff *skb)
  {
  #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
  	enum ip_conntrack_info ctinfo;
06b69390a   Jesper Juhl   IPVS: Fix variabl...
1477
  	struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
cf356d69d   Julian Anastasov   ipvs: switch to n...
1478
1479
  
  	if (!ct || !nf_ct_is_untracked(ct)) {
9e33ce453   Lin Ming   ipvs: fix oops on...
1480
  		nf_conntrack_put(skb->nfct);
cf356d69d   Julian Anastasov   ipvs: switch to n...
1481
1482
1483
1484
1485
1486
  		skb->nfct = &nf_ct_untracked_get()->ct_general;
  		skb->nfctinfo = IP_CT_NEW;
  		nf_conntrack_get(skb->nfct);
  	}
  #endif
  }
f4bc17cdd   Julian Anastasov   ipvs: netfilter c...
1487
  #ifdef CONFIG_IP_VS_NFCT
07dcc686f   Simon Horman   ipvs: Clean up co...
1488
1489
  /* Netfilter connection tracking
   * (from ip_vs_nfct.c)
f4bc17cdd   Julian Anastasov   ipvs: netfilter c...
1490
   */
a0840e2e1   Hans Schillstrom   IPVS: netns, ip_v...
1491
  static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs)
f4bc17cdd   Julian Anastasov   ipvs: netfilter c...
1492
  {
a4e2f5a70   Simon Horman   IPVS: Conditional...
1493
  #ifdef CONFIG_SYSCTL
a0840e2e1   Hans Schillstrom   IPVS: netns, ip_v...
1494
  	return ipvs->sysctl_conntrack;
a4e2f5a70   Simon Horman   IPVS: Conditional...
1495
1496
1497
  #else
  	return 0;
  #endif
f4bc17cdd   Julian Anastasov   ipvs: netfilter c...
1498
  }
5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
1499
1500
1501
1502
1503
1504
1505
  void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp,
  			    int outin);
  int ip_vs_confirm_conntrack(struct sk_buff *skb);
  void ip_vs_nfct_expect_related(struct sk_buff *skb, struct nf_conn *ct,
  			       struct ip_vs_conn *cp, u_int8_t proto,
  			       const __be16 port, int from_rs);
  void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp);
f4bc17cdd   Julian Anastasov   ipvs: netfilter c...
1506
1507
  
  #else
a0840e2e1   Hans Schillstrom   IPVS: netns, ip_v...
1508
  static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs)
f4bc17cdd   Julian Anastasov   ipvs: netfilter c...
1509
1510
1511
1512
1513
1514
1515
1516
  {
  	return 0;
  }
  
  static inline void ip_vs_update_conntrack(struct sk_buff *skb,
  					  struct ip_vs_conn *cp, int outin)
  {
  }
e23ebf0fa   Krzysztof Wilczynski   ipvs: Fix compila...
1517
  static inline int ip_vs_confirm_conntrack(struct sk_buff *skb)
f4bc17cdd   Julian Anastasov   ipvs: netfilter c...
1518
1519
1520
1521
1522
1523
1524
  {
  	return NF_ACCEPT;
  }
  
  static inline void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp)
  {
  }
07dcc686f   Simon Horman   ipvs: Clean up co...
1525
  #endif /* CONFIG_IP_VS_NFCT */
6523ce152   Julian Anastasov   ipvs: fix active FTP
1526

f719e3754   Julian Anastasov   ipvs: drop first ...
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
  /* Really using conntrack? */
  static inline bool ip_vs_conn_uses_conntrack(struct ip_vs_conn *cp,
  					     struct sk_buff *skb)
  {
  #ifdef CONFIG_IP_VS_NFCT
  	enum ip_conntrack_info ctinfo;
  	struct nf_conn *ct;
  
  	if (!(cp->flags & IP_VS_CONN_F_NFCT))
  		return false;
  	ct = nf_ct_get(skb, &ctinfo);
  	if (ct && !nf_ct_is_untracked(ct))
  		return true;
  #endif
  	return false;
  }
c16526a7b   Simon Kirby   ipvs: fix overflo...
1543
  static inline int
b552f7e3a   Changli Gao   ipvs: unify the f...
1544
1545
  ip_vs_dest_conn_overhead(struct ip_vs_dest *dest)
  {
07dcc686f   Simon Horman   ipvs: Clean up co...
1546
  	/* We think the overhead of processing active connections is 256
b552f7e3a   Changli Gao   ipvs: unify the f...
1547
1548
1549
1550
1551
1552
1553
1554
  	 * times higher than that of inactive connections in average. (This
  	 * 256 times might not be accurate, we will change it later) We
  	 * use the following formula to estimate the overhead now:
  	 *		  dest->activeconns*256 + dest->inactconns
  	 */
  	return (atomic_read(&dest->activeconns) << 8) +
  		atomic_read(&dest->inactconns);
  }
bc4768eb0   Julius Volz   ipvs: Move usersp...
1555
  #endif	/* _NET_IP_VS_H */