blob: 28bdaf7c02f4cc78823d6f2987e85ceec4c9422e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * IPVS An implementation of the IP virtual server support for the
3 * LINUX operating system. IPVS is now implemented as a module
4 * over the Netfilter framework. IPVS can be used to build a
5 * high-performance and highly available server based on a
6 * cluster of servers.
7 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Authors: Wensong Zhang <wensong@linuxvirtualserver.org>
9 * Peter Kese <peter.kese@ijs.si>
10 * Julian Anastasov <ja@ssi.bg>
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version
15 * 2 of the License, or (at your option) any later version.
16 *
17 * The IPVS code for kernel 2.2 was done by Wensong Zhang and Peter Kese,
18 * with changes/fixes from Julian Anastasov, Lars Marowsky-Bree, Horms
19 * and others. Many code here is taken from IP MASQ code of kernel 2.2.
20 *
21 * Changes:
22 *
23 */
24
Hannes Eder9aada7a2009-07-30 14:29:44 -070025#define KMSG_COMPONENT "IPVS"
26#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
27
Andrew Mortone9242832006-01-05 14:57:36 -080028#include <linux/interrupt.h>
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020029#include <linux/in.h>
Arnaldo Carvalho de Melof1900552006-01-04 02:02:20 -020030#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/kernel.h>
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020032#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/vmalloc.h>
34#include <linux/proc_fs.h> /* for proc_net_* */
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090035#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/seq_file.h>
37#include <linux/jhash.h>
38#include <linux/random.h>
39
Eric W. Biederman457c4cb2007-09-12 12:01:34 +020040#include <net/net_namespace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <net/ip_vs.h>
42
43
Catalin(ux) M. BOIE6f7edb42010-01-05 05:50:24 +010044#ifndef CONFIG_IP_VS_TAB_BITS
45#define CONFIG_IP_VS_TAB_BITS 12
46#endif
47
48/*
49 * Connection hash size. Default is what was selected at compile time.
50*/
Eric Dumazet4ecd2942010-11-15 18:38:52 +010051static int ip_vs_conn_tab_bits = CONFIG_IP_VS_TAB_BITS;
Catalin(ux) M. BOIE6f7edb42010-01-05 05:50:24 +010052module_param_named(conn_tab_bits, ip_vs_conn_tab_bits, int, 0444);
53MODULE_PARM_DESC(conn_tab_bits, "Set connections' hash size");
54
55/* size and mask values */
Eric Dumazet4ecd2942010-11-15 18:38:52 +010056int ip_vs_conn_tab_size __read_mostly;
57static int ip_vs_conn_tab_mask __read_mostly;
Catalin(ux) M. BOIE6f7edb42010-01-05 05:50:24 +010058
Linus Torvalds1da177e2005-04-16 15:20:36 -070059/*
60 * Connection hash table: for input and output packets lookups of IPVS
61 */
Eric Dumazet4ecd2942010-11-15 18:38:52 +010062static struct list_head *ip_vs_conn_tab __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64/* SLAB cache for IPVS connections */
Christoph Lametere18b8902006-12-06 20:33:20 -080065static struct kmem_cache *ip_vs_conn_cachep __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Linus Torvalds1da177e2005-04-16 15:20:36 -070067/* counter for no client port connections */
68static atomic_t ip_vs_conn_no_cport_cnt = ATOMIC_INIT(0);
69
70/* random value for IPVS connection hash */
Eric Dumazet4ecd2942010-11-15 18:38:52 +010071static unsigned int ip_vs_conn_rnd __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73/*
74 * Fine locking granularity for big connection hash table
75 */
Hans Schillstrom6e67e582011-01-03 14:44:57 +010076#define CT_LOCKARRAY_BITS 5
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#define CT_LOCKARRAY_SIZE (1<<CT_LOCKARRAY_BITS)
78#define CT_LOCKARRAY_MASK (CT_LOCKARRAY_SIZE-1)
79
80struct ip_vs_aligned_lock
81{
82 rwlock_t l;
83} __attribute__((__aligned__(SMP_CACHE_BYTES)));
84
85/* lock array for conn table */
86static struct ip_vs_aligned_lock
87__ip_vs_conntbl_lock_array[CT_LOCKARRAY_SIZE] __cacheline_aligned;
88
89static inline void ct_read_lock(unsigned key)
90{
91 read_lock(&__ip_vs_conntbl_lock_array[key&CT_LOCKARRAY_MASK].l);
92}
93
94static inline void ct_read_unlock(unsigned key)
95{
96 read_unlock(&__ip_vs_conntbl_lock_array[key&CT_LOCKARRAY_MASK].l);
97}
98
99static inline void ct_write_lock(unsigned key)
100{
101 write_lock(&__ip_vs_conntbl_lock_array[key&CT_LOCKARRAY_MASK].l);
102}
103
104static inline void ct_write_unlock(unsigned key)
105{
106 write_unlock(&__ip_vs_conntbl_lock_array[key&CT_LOCKARRAY_MASK].l);
107}
108
109static inline void ct_read_lock_bh(unsigned key)
110{
111 read_lock_bh(&__ip_vs_conntbl_lock_array[key&CT_LOCKARRAY_MASK].l);
112}
113
114static inline void ct_read_unlock_bh(unsigned key)
115{
116 read_unlock_bh(&__ip_vs_conntbl_lock_array[key&CT_LOCKARRAY_MASK].l);
117}
118
119static inline void ct_write_lock_bh(unsigned key)
120{
121 write_lock_bh(&__ip_vs_conntbl_lock_array[key&CT_LOCKARRAY_MASK].l);
122}
123
124static inline void ct_write_unlock_bh(unsigned key)
125{
126 write_unlock_bh(&__ip_vs_conntbl_lock_array[key&CT_LOCKARRAY_MASK].l);
127}
128
129
130/*
131 * Returns hash value for IPVS connection entry
132 */
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100133static unsigned int ip_vs_conn_hashkey(struct net *net, int af, unsigned proto,
Julius Volz28364a52008-09-02 15:55:43 +0200134 const union nf_inet_addr *addr,
135 __be16 port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136{
Julius Volz28364a52008-09-02 15:55:43 +0200137#ifdef CONFIG_IP_VS_IPV6
138 if (af == AF_INET6)
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100139 return (jhash_3words(jhash(addr, 16, ip_vs_conn_rnd),
140 (__force u32)port, proto, ip_vs_conn_rnd) ^
141 ((size_t)net>>8)) & ip_vs_conn_tab_mask;
Julius Volz28364a52008-09-02 15:55:43 +0200142#endif
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100143 return (jhash_3words((__force u32)addr->ip, (__force u32)port, proto,
144 ip_vs_conn_rnd) ^
145 ((size_t)net>>8)) & ip_vs_conn_tab_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146}
147
Simon Horman85999282010-08-22 21:37:53 +0900148static unsigned int ip_vs_conn_hashkey_param(const struct ip_vs_conn_param *p,
149 bool inverse)
150{
151 const union nf_inet_addr *addr;
152 __be16 port;
153
Simon Hormanf71499a2010-08-22 21:37:54 +0900154 if (p->pe_data && p->pe->hashkey_raw)
Simon Horman85999282010-08-22 21:37:53 +0900155 return p->pe->hashkey_raw(p, ip_vs_conn_rnd, inverse) &
156 ip_vs_conn_tab_mask;
157
158 if (likely(!inverse)) {
159 addr = p->caddr;
160 port = p->cport;
161 } else {
162 addr = p->vaddr;
163 port = p->vport;
164 }
165
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100166 return ip_vs_conn_hashkey(p->net, p->af, p->protocol, addr, port);
Simon Horman85999282010-08-22 21:37:53 +0900167}
168
169static unsigned int ip_vs_conn_hashkey_conn(const struct ip_vs_conn *cp)
170{
171 struct ip_vs_conn_param p;
172
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100173 ip_vs_conn_fill_param(ip_vs_conn_net(cp), cp->af, cp->protocol,
174 &cp->caddr, cp->cport, NULL, 0, &p);
Simon Horman85999282010-08-22 21:37:53 +0900175
Simon Hormane9e5eee2010-11-08 20:05:57 +0900176 if (cp->pe) {
177 p.pe = cp->pe;
Simon Horman85999282010-08-22 21:37:53 +0900178 p.pe_data = cp->pe_data;
179 p.pe_data_len = cp->pe_data_len;
180 }
181
182 return ip_vs_conn_hashkey_param(&p, false);
183}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185/*
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100186 * Hashes ip_vs_conn in ip_vs_conn_tab by netns,proto,addr,port.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 * returns bool success.
188 */
189static inline int ip_vs_conn_hash(struct ip_vs_conn *cp)
190{
191 unsigned hash;
192 int ret;
193
Nick Chalk26ec0372010-06-22 08:07:01 +0200194 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
195 return 0;
196
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 /* Hash by protocol, client address and port */
Simon Horman85999282010-08-22 21:37:53 +0900198 hash = ip_vs_conn_hashkey_conn(cp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200 ct_write_lock(hash);
Sven Wegeneraea9d712010-06-09 16:10:57 +0200201 spin_lock(&cp->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
203 if (!(cp->flags & IP_VS_CONN_F_HASHED)) {
204 list_add(&cp->c_list, &ip_vs_conn_tab[hash]);
205 cp->flags |= IP_VS_CONN_F_HASHED;
206 atomic_inc(&cp->refcnt);
207 ret = 1;
208 } else {
Hannes Eder1e3e2382009-08-02 11:05:41 +0000209 pr_err("%s(): request for already hashed, called from %pF\n",
210 __func__, __builtin_return_address(0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 ret = 0;
212 }
213
Sven Wegeneraea9d712010-06-09 16:10:57 +0200214 spin_unlock(&cp->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 ct_write_unlock(hash);
216
217 return ret;
218}
219
220
221/*
222 * UNhashes ip_vs_conn from ip_vs_conn_tab.
223 * returns bool success.
224 */
225static inline int ip_vs_conn_unhash(struct ip_vs_conn *cp)
226{
227 unsigned hash;
228 int ret;
229
230 /* unhash it and decrease its reference counter */
Simon Horman85999282010-08-22 21:37:53 +0900231 hash = ip_vs_conn_hashkey_conn(cp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
233 ct_write_lock(hash);
Sven Wegeneraea9d712010-06-09 16:10:57 +0200234 spin_lock(&cp->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
236 if (cp->flags & IP_VS_CONN_F_HASHED) {
237 list_del(&cp->c_list);
238 cp->flags &= ~IP_VS_CONN_F_HASHED;
239 atomic_dec(&cp->refcnt);
240 ret = 1;
241 } else
242 ret = 0;
243
Sven Wegeneraea9d712010-06-09 16:10:57 +0200244 spin_unlock(&cp->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 ct_write_unlock(hash);
246
247 return ret;
248}
249
250
251/*
252 * Gets ip_vs_conn associated with supplied parameters in the ip_vs_conn_tab.
253 * Called for pkts coming from OUTside-to-INside.
Simon Hormanf11017e2010-08-22 21:37:52 +0900254 * p->caddr, p->cport: pkt source address (foreign host)
255 * p->vaddr, p->vport: pkt dest address (load balancer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 */
Simon Hormanf11017e2010-08-22 21:37:52 +0900257static inline struct ip_vs_conn *
258__ip_vs_conn_in_get(const struct ip_vs_conn_param *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259{
260 unsigned hash;
261 struct ip_vs_conn *cp;
262
Simon Horman85999282010-08-22 21:37:53 +0900263 hash = ip_vs_conn_hashkey_param(p, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
265 ct_read_lock(hash);
266
267 list_for_each_entry(cp, &ip_vs_conn_tab[hash], c_list) {
Simon Hormanf11017e2010-08-22 21:37:52 +0900268 if (cp->af == p->af &&
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100269 p->cport == cp->cport && p->vport == cp->vport &&
Simon Hormanf11017e2010-08-22 21:37:52 +0900270 ip_vs_addr_equal(p->af, p->caddr, &cp->caddr) &&
271 ip_vs_addr_equal(p->af, p->vaddr, &cp->vaddr) &&
Simon Hormanf11017e2010-08-22 21:37:52 +0900272 ((!p->cport) ^ (!(cp->flags & IP_VS_CONN_F_NO_CPORT))) &&
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100273 p->protocol == cp->protocol &&
274 ip_vs_conn_net_eq(cp, p->net)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 /* HIT */
276 atomic_inc(&cp->refcnt);
277 ct_read_unlock(hash);
278 return cp;
279 }
280 }
281
282 ct_read_unlock(hash);
283
284 return NULL;
285}
286
Simon Hormanf11017e2010-08-22 21:37:52 +0900287struct ip_vs_conn *ip_vs_conn_in_get(const struct ip_vs_conn_param *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
289 struct ip_vs_conn *cp;
290
Simon Hormanf11017e2010-08-22 21:37:52 +0900291 cp = __ip_vs_conn_in_get(p);
292 if (!cp && atomic_read(&ip_vs_conn_no_cport_cnt)) {
293 struct ip_vs_conn_param cport_zero_p = *p;
294 cport_zero_p.cport = 0;
295 cp = __ip_vs_conn_in_get(&cport_zero_p);
296 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
Julius Volz28364a52008-09-02 15:55:43 +0200298 IP_VS_DBG_BUF(9, "lookup/in %s %s:%d->%s:%d %s\n",
Simon Hormanf11017e2010-08-22 21:37:52 +0900299 ip_vs_proto_name(p->protocol),
300 IP_VS_DBG_ADDR(p->af, p->caddr), ntohs(p->cport),
301 IP_VS_DBG_ADDR(p->af, p->vaddr), ntohs(p->vport),
Julius Volz28364a52008-09-02 15:55:43 +0200302 cp ? "hit" : "not hit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
304 return cp;
305}
306
Simon Hormanf11017e2010-08-22 21:37:52 +0900307static int
308ip_vs_conn_fill_param_proto(int af, const struct sk_buff *skb,
309 const struct ip_vs_iphdr *iph,
310 unsigned int proto_off, int inverse,
311 struct ip_vs_conn_param *p)
312{
313 __be16 _ports[2], *pptr;
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100314 struct net *net = skb_net(skb);
Simon Hormanf11017e2010-08-22 21:37:52 +0900315
316 pptr = skb_header_pointer(skb, proto_off, sizeof(_ports), _ports);
317 if (pptr == NULL)
318 return 1;
319
320 if (likely(!inverse))
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100321 ip_vs_conn_fill_param(net, af, iph->protocol, &iph->saddr,
322 pptr[0], &iph->daddr, pptr[1], p);
Simon Hormanf11017e2010-08-22 21:37:52 +0900323 else
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100324 ip_vs_conn_fill_param(net, af, iph->protocol, &iph->daddr,
325 pptr[1], &iph->saddr, pptr[0], p);
Simon Hormanf11017e2010-08-22 21:37:52 +0900326 return 0;
327}
328
Simon Horman5c0d2372010-08-02 17:12:44 +0200329struct ip_vs_conn *
330ip_vs_conn_in_get_proto(int af, const struct sk_buff *skb,
Simon Horman5c0d2372010-08-02 17:12:44 +0200331 const struct ip_vs_iphdr *iph,
332 unsigned int proto_off, int inverse)
333{
Simon Hormanf11017e2010-08-22 21:37:52 +0900334 struct ip_vs_conn_param p;
Simon Horman5c0d2372010-08-02 17:12:44 +0200335
Simon Hormanf11017e2010-08-22 21:37:52 +0900336 if (ip_vs_conn_fill_param_proto(af, skb, iph, proto_off, inverse, &p))
Simon Horman5c0d2372010-08-02 17:12:44 +0200337 return NULL;
338
Simon Hormanf11017e2010-08-22 21:37:52 +0900339 return ip_vs_conn_in_get(&p);
Simon Horman5c0d2372010-08-02 17:12:44 +0200340}
341EXPORT_SYMBOL_GPL(ip_vs_conn_in_get_proto);
342
Julian Anastasov87375ab2005-09-14 21:08:51 -0700343/* Get reference to connection template */
Simon Hormanf11017e2010-08-22 21:37:52 +0900344struct ip_vs_conn *ip_vs_ct_in_get(const struct ip_vs_conn_param *p)
Julian Anastasov87375ab2005-09-14 21:08:51 -0700345{
346 unsigned hash;
347 struct ip_vs_conn *cp;
348
Simon Horman85999282010-08-22 21:37:53 +0900349 hash = ip_vs_conn_hashkey_param(p, false);
Julian Anastasov87375ab2005-09-14 21:08:51 -0700350
351 ct_read_lock(hash);
352
353 list_for_each_entry(cp, &ip_vs_conn_tab[hash], c_list) {
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100354 if (!ip_vs_conn_net_eq(cp, p->net))
355 continue;
Simon Hormanf71499a2010-08-22 21:37:54 +0900356 if (p->pe_data && p->pe->ct_match) {
Simon Hormanea2c73a2010-11-08 20:06:30 +0900357 if (p->pe == cp->pe && p->pe->ct_match(p, cp))
Simon Horman85999282010-08-22 21:37:53 +0900358 goto out;
359 continue;
360 }
361
Simon Hormanf11017e2010-08-22 21:37:52 +0900362 if (cp->af == p->af &&
363 ip_vs_addr_equal(p->af, p->caddr, &cp->caddr) &&
Simon Hormanbe8be9e2009-05-06 15:02:29 +0000364 /* protocol should only be IPPROTO_IP if
Simon Hormanf11017e2010-08-22 21:37:52 +0900365 * p->vaddr is a fwmark */
366 ip_vs_addr_equal(p->protocol == IPPROTO_IP ? AF_UNSPEC :
367 p->af, p->vaddr, &cp->vaddr) &&
368 p->cport == cp->cport && p->vport == cp->vport &&
Julian Anastasov87375ab2005-09-14 21:08:51 -0700369 cp->flags & IP_VS_CONN_F_TEMPLATE &&
Simon Horman85999282010-08-22 21:37:53 +0900370 p->protocol == cp->protocol)
Julian Anastasov87375ab2005-09-14 21:08:51 -0700371 goto out;
Julian Anastasov87375ab2005-09-14 21:08:51 -0700372 }
373 cp = NULL;
374
375 out:
Simon Horman85999282010-08-22 21:37:53 +0900376 if (cp)
377 atomic_inc(&cp->refcnt);
Julian Anastasov87375ab2005-09-14 21:08:51 -0700378 ct_read_unlock(hash);
379
Julius Volz28364a52008-09-02 15:55:43 +0200380 IP_VS_DBG_BUF(9, "template lookup/in %s %s:%d->%s:%d %s\n",
Simon Hormanf11017e2010-08-22 21:37:52 +0900381 ip_vs_proto_name(p->protocol),
382 IP_VS_DBG_ADDR(p->af, p->caddr), ntohs(p->cport),
383 IP_VS_DBG_ADDR(p->af, p->vaddr), ntohs(p->vport),
Julius Volz28364a52008-09-02 15:55:43 +0200384 cp ? "hit" : "not hit");
Julian Anastasov87375ab2005-09-14 21:08:51 -0700385
386 return cp;
387}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Simon Hormanf11017e2010-08-22 21:37:52 +0900389/* Gets ip_vs_conn associated with supplied parameters in the ip_vs_conn_tab.
390 * Called for pkts coming from inside-to-OUTside.
391 * p->caddr, p->cport: pkt source address (inside host)
392 * p->vaddr, p->vport: pkt dest address (foreign host) */
393struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394{
395 unsigned hash;
396 struct ip_vs_conn *cp, *ret=NULL;
397
398 /*
399 * Check for "full" addressed entries
400 */
Simon Horman85999282010-08-22 21:37:53 +0900401 hash = ip_vs_conn_hashkey_param(p, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
403 ct_read_lock(hash);
404
405 list_for_each_entry(cp, &ip_vs_conn_tab[hash], c_list) {
Simon Hormanf11017e2010-08-22 21:37:52 +0900406 if (cp->af == p->af &&
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100407 p->vport == cp->cport && p->cport == cp->dport &&
Simon Hormanf11017e2010-08-22 21:37:52 +0900408 ip_vs_addr_equal(p->af, p->vaddr, &cp->caddr) &&
409 ip_vs_addr_equal(p->af, p->caddr, &cp->daddr) &&
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100410 p->protocol == cp->protocol &&
411 ip_vs_conn_net_eq(cp, p->net)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 /* HIT */
413 atomic_inc(&cp->refcnt);
414 ret = cp;
415 break;
416 }
417 }
418
419 ct_read_unlock(hash);
420
Julius Volz28364a52008-09-02 15:55:43 +0200421 IP_VS_DBG_BUF(9, "lookup/out %s %s:%d->%s:%d %s\n",
Simon Hormanf11017e2010-08-22 21:37:52 +0900422 ip_vs_proto_name(p->protocol),
423 IP_VS_DBG_ADDR(p->af, p->caddr), ntohs(p->cport),
424 IP_VS_DBG_ADDR(p->af, p->vaddr), ntohs(p->vport),
Julius Volz28364a52008-09-02 15:55:43 +0200425 ret ? "hit" : "not hit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
427 return ret;
428}
429
Simon Horman5c0d2372010-08-02 17:12:44 +0200430struct ip_vs_conn *
431ip_vs_conn_out_get_proto(int af, const struct sk_buff *skb,
Simon Horman5c0d2372010-08-02 17:12:44 +0200432 const struct ip_vs_iphdr *iph,
433 unsigned int proto_off, int inverse)
434{
Simon Hormanf11017e2010-08-22 21:37:52 +0900435 struct ip_vs_conn_param p;
Simon Horman5c0d2372010-08-02 17:12:44 +0200436
Simon Hormanf11017e2010-08-22 21:37:52 +0900437 if (ip_vs_conn_fill_param_proto(af, skb, iph, proto_off, inverse, &p))
Simon Horman5c0d2372010-08-02 17:12:44 +0200438 return NULL;
439
Simon Hormanf11017e2010-08-22 21:37:52 +0900440 return ip_vs_conn_out_get(&p);
Simon Horman5c0d2372010-08-02 17:12:44 +0200441}
442EXPORT_SYMBOL_GPL(ip_vs_conn_out_get_proto);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
444/*
445 * Put back the conn and restart its timer with its timeout
446 */
447void ip_vs_conn_put(struct ip_vs_conn *cp)
448{
Nick Chalk26ec0372010-06-22 08:07:01 +0200449 unsigned long t = (cp->flags & IP_VS_CONN_F_ONE_PACKET) ?
450 0 : cp->timeout;
451 mod_timer(&cp->timer, jiffies+t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
453 __ip_vs_conn_put(cp);
454}
455
456
457/*
458 * Fill a no_client_port connection with a client port number
459 */
Al Viro014d7302006-09-28 14:29:52 -0700460void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461{
462 if (ip_vs_conn_unhash(cp)) {
463 spin_lock(&cp->lock);
464 if (cp->flags & IP_VS_CONN_F_NO_CPORT) {
465 atomic_dec(&ip_vs_conn_no_cport_cnt);
466 cp->flags &= ~IP_VS_CONN_F_NO_CPORT;
467 cp->cport = cport;
468 }
469 spin_unlock(&cp->lock);
470
471 /* hash on new dport */
472 ip_vs_conn_hash(cp);
473 }
474}
475
476
477/*
478 * Bind a connection entry with the corresponding packet_xmit.
479 * Called by ip_vs_conn_new.
480 */
481static inline void ip_vs_bind_xmit(struct ip_vs_conn *cp)
482{
483 switch (IP_VS_FWD_METHOD(cp)) {
484 case IP_VS_CONN_F_MASQ:
485 cp->packet_xmit = ip_vs_nat_xmit;
486 break;
487
488 case IP_VS_CONN_F_TUNNEL:
489 cp->packet_xmit = ip_vs_tunnel_xmit;
490 break;
491
492 case IP_VS_CONN_F_DROUTE:
493 cp->packet_xmit = ip_vs_dr_xmit;
494 break;
495
496 case IP_VS_CONN_F_LOCALNODE:
497 cp->packet_xmit = ip_vs_null_xmit;
498 break;
499
500 case IP_VS_CONN_F_BYPASS:
501 cp->packet_xmit = ip_vs_bypass_xmit;
502 break;
503 }
504}
505
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200506#ifdef CONFIG_IP_VS_IPV6
507static inline void ip_vs_bind_xmit_v6(struct ip_vs_conn *cp)
508{
509 switch (IP_VS_FWD_METHOD(cp)) {
510 case IP_VS_CONN_F_MASQ:
511 cp->packet_xmit = ip_vs_nat_xmit_v6;
512 break;
513
514 case IP_VS_CONN_F_TUNNEL:
515 cp->packet_xmit = ip_vs_tunnel_xmit_v6;
516 break;
517
518 case IP_VS_CONN_F_DROUTE:
519 cp->packet_xmit = ip_vs_dr_xmit_v6;
520 break;
521
522 case IP_VS_CONN_F_LOCALNODE:
523 cp->packet_xmit = ip_vs_null_xmit;
524 break;
525
526 case IP_VS_CONN_F_BYPASS:
527 cp->packet_xmit = ip_vs_bypass_xmit_v6;
528 break;
529 }
530}
531#endif
532
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
534static inline int ip_vs_dest_totalconns(struct ip_vs_dest *dest)
535{
536 return atomic_read(&dest->activeconns)
537 + atomic_read(&dest->inactconns);
538}
539
540/*
541 * Bind a connection entry with a virtual service destination
542 * Called just after a new connection entry is created.
543 */
544static inline void
545ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
546{
Julian Anastasov35757922010-09-17 14:18:16 +0200547 unsigned int conn_flags;
548
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 /* if dest is NULL, then return directly */
550 if (!dest)
551 return;
552
553 /* Increase the refcnt counter of the dest */
554 atomic_inc(&dest->refcnt);
555
Julian Anastasov35757922010-09-17 14:18:16 +0200556 conn_flags = atomic_read(&dest->conn_flags);
557 if (cp->protocol != IPPROTO_UDP)
558 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 /* Bind with the destination and its corresponding transmitter */
Julian Anastasov35757922010-09-17 14:18:16 +0200560 if (cp->flags & IP_VS_CONN_F_SYNC) {
Rumen G. Bogdanovskib2096392007-11-19 21:53:27 -0800561 /* if the connection is not template and is created
562 * by sync, preserve the activity flag.
563 */
Julian Anastasov35757922010-09-17 14:18:16 +0200564 if (!(cp->flags & IP_VS_CONN_F_TEMPLATE))
565 conn_flags &= ~IP_VS_CONN_F_INACTIVE;
Julian Anastasov32337592010-10-17 16:43:36 +0300566 /* connections inherit forwarding method from dest */
567 cp->flags &= ~IP_VS_CONN_F_FWD_MASK;
Julian Anastasov35757922010-09-17 14:18:16 +0200568 }
569 cp->flags |= conn_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 cp->dest = dest;
571
Julius Volzcfc78c52008-09-02 15:55:53 +0200572 IP_VS_DBG_BUF(7, "Bind-dest %s c:%s:%d v:%s:%d "
573 "d:%s:%d fwd:%c s:%u conn->flags:%X conn->refcnt:%d "
574 "dest->refcnt:%d\n",
575 ip_vs_proto_name(cp->protocol),
576 IP_VS_DBG_ADDR(cp->af, &cp->caddr), ntohs(cp->cport),
577 IP_VS_DBG_ADDR(cp->af, &cp->vaddr), ntohs(cp->vport),
578 IP_VS_DBG_ADDR(cp->af, &cp->daddr), ntohs(cp->dport),
579 ip_vs_fwd_tag(cp), cp->state,
580 cp->flags, atomic_read(&cp->refcnt),
581 atomic_read(&dest->refcnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
583 /* Update the connection counters */
Julian Anastasov87375ab2005-09-14 21:08:51 -0700584 if (!(cp->flags & IP_VS_CONN_F_TEMPLATE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 /* It is a normal connection, so increase the inactive
586 connection counter because it is in TCP SYNRECV
587 state (inactive) or other protocol inacive state */
Rumen G. Bogdanovskib2096392007-11-19 21:53:27 -0800588 if ((cp->flags & IP_VS_CONN_F_SYNC) &&
589 (!(cp->flags & IP_VS_CONN_F_INACTIVE)))
590 atomic_inc(&dest->activeconns);
591 else
592 atomic_inc(&dest->inactconns);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 } else {
594 /* It is a persistent connection/template, so increase
595 the peristent connection counter */
596 atomic_inc(&dest->persistconns);
597 }
598
599 if (dest->u_threshold != 0 &&
600 ip_vs_dest_totalconns(dest) >= dest->u_threshold)
601 dest->flags |= IP_VS_DEST_F_OVERLOAD;
602}
603
604
605/*
Rumen G. Bogdanovski1e356f92007-11-07 02:35:54 -0800606 * Check if there is a destination for the connection, if so
607 * bind the connection to the destination.
608 */
609struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp)
610{
611 struct ip_vs_dest *dest;
612
613 if ((cp) && (!cp->dest)) {
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100614 dest = ip_vs_find_dest(ip_vs_conn_net(cp), cp->af, &cp->daddr,
615 cp->dport, &cp->vaddr, cp->vport,
Hans Schillstrom0e051e62010-11-19 14:25:07 +0100616 cp->protocol, cp->fwmark);
Rumen G. Bogdanovski1e356f92007-11-07 02:35:54 -0800617 ip_vs_bind_dest(cp, dest);
618 return dest;
619 } else
620 return NULL;
621}
Rumen G. Bogdanovski1e356f92007-11-07 02:35:54 -0800622
623
624/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 * Unbind a connection entry with its VS destination
626 * Called by the ip_vs_conn_expire function.
627 */
628static inline void ip_vs_unbind_dest(struct ip_vs_conn *cp)
629{
630 struct ip_vs_dest *dest = cp->dest;
631
632 if (!dest)
633 return;
634
Julius Volzcfc78c52008-09-02 15:55:53 +0200635 IP_VS_DBG_BUF(7, "Unbind-dest %s c:%s:%d v:%s:%d "
636 "d:%s:%d fwd:%c s:%u conn->flags:%X conn->refcnt:%d "
637 "dest->refcnt:%d\n",
638 ip_vs_proto_name(cp->protocol),
639 IP_VS_DBG_ADDR(cp->af, &cp->caddr), ntohs(cp->cport),
640 IP_VS_DBG_ADDR(cp->af, &cp->vaddr), ntohs(cp->vport),
641 IP_VS_DBG_ADDR(cp->af, &cp->daddr), ntohs(cp->dport),
642 ip_vs_fwd_tag(cp), cp->state,
643 cp->flags, atomic_read(&cp->refcnt),
644 atomic_read(&dest->refcnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
646 /* Update the connection counters */
Julian Anastasov87375ab2005-09-14 21:08:51 -0700647 if (!(cp->flags & IP_VS_CONN_F_TEMPLATE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 /* It is a normal connection, so decrease the inactconns
649 or activeconns counter */
650 if (cp->flags & IP_VS_CONN_F_INACTIVE) {
651 atomic_dec(&dest->inactconns);
652 } else {
653 atomic_dec(&dest->activeconns);
654 }
655 } else {
656 /* It is a persistent connection/template, so decrease
657 the peristent connection counter */
658 atomic_dec(&dest->persistconns);
659 }
660
661 if (dest->l_threshold != 0) {
662 if (ip_vs_dest_totalconns(dest) < dest->l_threshold)
663 dest->flags &= ~IP_VS_DEST_F_OVERLOAD;
664 } else if (dest->u_threshold != 0) {
665 if (ip_vs_dest_totalconns(dest) * 4 < dest->u_threshold * 3)
666 dest->flags &= ~IP_VS_DEST_F_OVERLOAD;
667 } else {
668 if (dest->flags & IP_VS_DEST_F_OVERLOAD)
669 dest->flags &= ~IP_VS_DEST_F_OVERLOAD;
670 }
671
672 /*
673 * Simply decrease the refcnt of the dest, because the
674 * dest will be either in service's destination list
675 * or in the trash.
676 */
677 atomic_dec(&dest->refcnt);
678}
679
680
681/*
682 * Checking if the destination of a connection template is available.
683 * If available, return 1, otherwise invalidate this connection
684 * template and return 0.
685 */
686int ip_vs_check_template(struct ip_vs_conn *ct)
687{
688 struct ip_vs_dest *dest = ct->dest;
Hans Schillstroma0840e22011-01-03 14:44:58 +0100689 struct netns_ipvs *ipvs = net_ipvs(ip_vs_conn_net(ct));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
691 /*
692 * Checking the dest server status.
693 */
694 if ((dest == NULL) ||
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900695 !(dest->flags & IP_VS_DEST_F_AVAILABLE) ||
Hans Schillstroma0840e22011-01-03 14:44:58 +0100696 (ipvs->sysctl_expire_quiescent_template &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 (atomic_read(&dest->weight) == 0))) {
Julius Volzcfc78c52008-09-02 15:55:53 +0200698 IP_VS_DBG_BUF(9, "check_template: dest not available for "
699 "protocol %s s:%s:%d v:%s:%d "
700 "-> d:%s:%d\n",
701 ip_vs_proto_name(ct->protocol),
702 IP_VS_DBG_ADDR(ct->af, &ct->caddr),
703 ntohs(ct->cport),
704 IP_VS_DBG_ADDR(ct->af, &ct->vaddr),
705 ntohs(ct->vport),
706 IP_VS_DBG_ADDR(ct->af, &ct->daddr),
707 ntohs(ct->dport));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
709 /*
710 * Invalidate the connection template
711 */
Al Viro014d7302006-09-28 14:29:52 -0700712 if (ct->vport != htons(0xffff)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 if (ip_vs_conn_unhash(ct)) {
Al Viro014d7302006-09-28 14:29:52 -0700714 ct->dport = htons(0xffff);
715 ct->vport = htons(0xffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 ct->cport = 0;
717 ip_vs_conn_hash(ct);
718 }
719 }
720
721 /*
722 * Simply decrease the refcnt of the template,
723 * don't restart its timer.
724 */
725 atomic_dec(&ct->refcnt);
726 return 0;
727 }
728 return 1;
729}
730
731static void ip_vs_conn_expire(unsigned long data)
732{
733 struct ip_vs_conn *cp = (struct ip_vs_conn *)data;
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100734 struct netns_ipvs *ipvs = net_ipvs(ip_vs_conn_net(cp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
736 cp->timeout = 60*HZ;
737
738 /*
739 * hey, I'm using it
740 */
741 atomic_inc(&cp->refcnt);
742
743 /*
744 * do I control anybody?
745 */
746 if (atomic_read(&cp->n_control))
747 goto expire_later;
748
749 /*
750 * unhash it if it is hashed in the conn table
751 */
Nick Chalk26ec0372010-06-22 08:07:01 +0200752 if (!ip_vs_conn_unhash(cp) && !(cp->flags & IP_VS_CONN_F_ONE_PACKET))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 goto expire_later;
754
755 /*
756 * refcnt==1 implies I'm the only one referrer
757 */
758 if (likely(atomic_read(&cp->refcnt) == 1)) {
759 /* delete the timer if it is activated by other users */
760 if (timer_pending(&cp->timer))
761 del_timer(&cp->timer);
762
763 /* does anybody control me? */
764 if (cp->control)
765 ip_vs_control_del(cp);
766
Julian Anastasovf4bc17c2010-09-21 17:35:41 +0200767 if (cp->flags & IP_VS_CONN_F_NFCT)
768 ip_vs_conn_drop_conntrack(cp);
769
Simon Hormane9e5eee2010-11-08 20:05:57 +0900770 ip_vs_pe_put(cp->pe);
Simon Horman85999282010-08-22 21:37:53 +0900771 kfree(cp->pe_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 if (unlikely(cp->app != NULL))
773 ip_vs_unbind_app(cp);
774 ip_vs_unbind_dest(cp);
775 if (cp->flags & IP_VS_CONN_F_NO_CPORT)
776 atomic_dec(&ip_vs_conn_no_cport_cnt);
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100777 atomic_dec(&ipvs->conn_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
779 kmem_cache_free(ip_vs_conn_cachep, cp);
780 return;
781 }
782
783 /* hash it back to the table */
784 ip_vs_conn_hash(cp);
785
786 expire_later:
Roberto Nibali4b5bdf52006-01-03 14:22:59 -0800787 IP_VS_DBG(7, "delayed: conn->refcnt-1=%d conn->n_control=%d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 atomic_read(&cp->refcnt)-1,
789 atomic_read(&cp->n_control));
790
791 ip_vs_conn_put(cp);
792}
793
794
795void ip_vs_conn_expire_now(struct ip_vs_conn *cp)
796{
797 if (del_timer(&cp->timer))
798 mod_timer(&cp->timer, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799}
800
801
802/*
803 * Create a new connection entry and hash it into the ip_vs_conn_tab
804 */
805struct ip_vs_conn *
Simon Hormanf11017e2010-08-22 21:37:52 +0900806ip_vs_conn_new(const struct ip_vs_conn_param *p,
Julius Volz28364a52008-09-02 15:55:43 +0200807 const union nf_inet_addr *daddr, __be16 dport, unsigned flags,
Hans Schillstrom0e051e62010-11-19 14:25:07 +0100808 struct ip_vs_dest *dest, __u32 fwmark)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809{
810 struct ip_vs_conn *cp;
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100811 struct netns_ipvs *ipvs = net_ipvs(p->net);
812 struct ip_vs_proto_data *pd = ip_vs_proto_data_get(p->net,
813 p->protocol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
Robert P. J. Dayc3762222007-02-10 01:45:03 -0800815 cp = kmem_cache_zalloc(ip_vs_conn_cachep, GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 if (cp == NULL) {
Hannes Eder1e3e2382009-08-02 11:05:41 +0000817 IP_VS_ERR_RL("%s(): no memory\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 return NULL;
819 }
820
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 INIT_LIST_HEAD(&cp->c_list);
Pavel Emelyanovb24b8a22008-01-23 21:20:07 -0800822 setup_timer(&cp->timer, ip_vs_conn_expire, (unsigned long)cp);
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100823 ip_vs_conn_net_set(cp, p->net);
Simon Hormanf11017e2010-08-22 21:37:52 +0900824 cp->af = p->af;
825 cp->protocol = p->protocol;
826 ip_vs_addr_copy(p->af, &cp->caddr, p->caddr);
827 cp->cport = p->cport;
828 ip_vs_addr_copy(p->af, &cp->vaddr, p->vaddr);
829 cp->vport = p->vport;
Simon Hormanbe8be9e2009-05-06 15:02:29 +0000830 /* proto should only be IPPROTO_IP if d_addr is a fwmark */
Simon Hormanf11017e2010-08-22 21:37:52 +0900831 ip_vs_addr_copy(p->protocol == IPPROTO_IP ? AF_UNSPEC : p->af,
Simon Hormanbe8be9e2009-05-06 15:02:29 +0000832 &cp->daddr, daddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 cp->dport = dport;
834 cp->flags = flags;
Hans Schillstrom0e051e62010-11-19 14:25:07 +0100835 cp->fwmark = fwmark;
Simon Hormane9e5eee2010-11-08 20:05:57 +0900836 if (flags & IP_VS_CONN_F_TEMPLATE && p->pe) {
837 ip_vs_pe_get(p->pe);
838 cp->pe = p->pe;
Simon Horman85999282010-08-22 21:37:53 +0900839 cp->pe_data = p->pe_data;
840 cp->pe_data_len = p->pe_data_len;
841 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 spin_lock_init(&cp->lock);
843
844 /*
845 * Set the entry is referenced by the current thread before hashing
846 * it in the table, so that other thread run ip_vs_random_dropentry
847 * but cannot drop this entry.
848 */
849 atomic_set(&cp->refcnt, 1);
850
851 atomic_set(&cp->n_control, 0);
852 atomic_set(&cp->in_pkts, 0);
853
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100854 atomic_inc(&ipvs->conn_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 if (flags & IP_VS_CONN_F_NO_CPORT)
856 atomic_inc(&ip_vs_conn_no_cport_cnt);
857
858 /* Bind the connection with a destination server */
859 ip_vs_bind_dest(cp, dest);
860
861 /* Set its state and timeout */
862 cp->state = 0;
863 cp->timeout = 3*HZ;
864
865 /* Bind its packet transmitter */
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200866#ifdef CONFIG_IP_VS_IPV6
Simon Hormanf11017e2010-08-22 21:37:52 +0900867 if (p->af == AF_INET6)
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200868 ip_vs_bind_xmit_v6(cp);
869 else
870#endif
871 ip_vs_bind_xmit(cp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
Hans Schillstrom9bbac6a2011-01-03 14:44:52 +0100873 if (unlikely(pd && atomic_read(&pd->appcnt)))
874 ip_vs_bind_app(cp, pd->pp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
Julian Anastasovf4bc17c2010-09-21 17:35:41 +0200876 /*
877 * Allow conntrack to be preserved. By default, conntrack
878 * is created and destroyed for every packet.
879 * Sometimes keeping conntrack can be useful for
880 * IP_VS_CONN_F_ONE_PACKET too.
881 */
882
Hans Schillstroma0840e22011-01-03 14:44:58 +0100883 if (ip_vs_conntrack_enabled(ipvs))
Julian Anastasovf4bc17c2010-09-21 17:35:41 +0200884 cp->flags |= IP_VS_CONN_F_NFCT;
885
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 /* Hash it in the ip_vs_conn_tab finally */
887 ip_vs_conn_hash(cp);
888
889 return cp;
890}
891
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892/*
893 * /proc/net/ip_vs_conn entries
894 */
895#ifdef CONFIG_PROC_FS
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100896struct ip_vs_iter_state {
897 struct seq_net_private p;
898 struct list_head *l;
899};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900
901static void *ip_vs_conn_array(struct seq_file *seq, loff_t pos)
902{
903 int idx;
904 struct ip_vs_conn *cp;
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100905 struct ip_vs_iter_state *iter = seq->private;
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900906
Catalin(ux) M. BOIE6f7edb42010-01-05 05:50:24 +0100907 for (idx = 0; idx < ip_vs_conn_tab_size; idx++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 ct_read_lock_bh(idx);
909 list_for_each_entry(cp, &ip_vs_conn_tab[idx], c_list) {
910 if (pos-- == 0) {
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100911 iter->l = &ip_vs_conn_tab[idx];
Simon Horman85999282010-08-22 21:37:53 +0900912 return cp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 }
914 }
915 ct_read_unlock_bh(idx);
916 }
917
918 return NULL;
919}
920
921static void *ip_vs_conn_seq_start(struct seq_file *seq, loff_t *pos)
922{
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100923 struct ip_vs_iter_state *iter = seq->private;
924
925 iter->l = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 return *pos ? ip_vs_conn_array(seq, *pos - 1) :SEQ_START_TOKEN;
927}
928
929static void *ip_vs_conn_seq_next(struct seq_file *seq, void *v, loff_t *pos)
930{
931 struct ip_vs_conn *cp = v;
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100932 struct ip_vs_iter_state *iter = seq->private;
933 struct list_head *e, *l = iter->l;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 int idx;
935
936 ++*pos;
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900937 if (v == SEQ_START_TOKEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 return ip_vs_conn_array(seq, 0);
939
940 /* more on same hash chain? */
941 if ((e = cp->c_list.next) != l)
942 return list_entry(e, struct ip_vs_conn, c_list);
943
944 idx = l - ip_vs_conn_tab;
945 ct_read_unlock_bh(idx);
946
Catalin(ux) M. BOIE6f7edb42010-01-05 05:50:24 +0100947 while (++idx < ip_vs_conn_tab_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 ct_read_lock_bh(idx);
949 list_for_each_entry(cp, &ip_vs_conn_tab[idx], c_list) {
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100950 iter->l = &ip_vs_conn_tab[idx];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 return cp;
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900952 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 ct_read_unlock_bh(idx);
954 }
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100955 iter->l = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 return NULL;
957}
958
959static void ip_vs_conn_seq_stop(struct seq_file *seq, void *v)
960{
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100961 struct ip_vs_iter_state *iter = seq->private;
962 struct list_head *l = iter->l;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
964 if (l)
965 ct_read_unlock_bh(l - ip_vs_conn_tab);
966}
967
968static int ip_vs_conn_seq_show(struct seq_file *seq, void *v)
969{
970
971 if (v == SEQ_START_TOKEN)
972 seq_puts(seq,
Simon Hormana3c918a2010-08-22 21:37:53 +0900973 "Pro FromIP FPrt ToIP TPrt DestIP DPrt State Expires PEName PEData\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 else {
975 const struct ip_vs_conn *cp = v;
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100976 struct net *net = seq_file_net(seq);
Simon Hormana3c918a2010-08-22 21:37:53 +0900977 char pe_data[IP_VS_PENAME_MAXLEN + IP_VS_PEDATA_MAXLEN + 3];
978 size_t len = 0;
979
Hans Schillstrom6e67e582011-01-03 14:44:57 +0100980 if (!ip_vs_conn_net_eq(cp, net))
981 return 0;
Simon Hormane9e5eee2010-11-08 20:05:57 +0900982 if (cp->pe_data) {
Simon Hormana3c918a2010-08-22 21:37:53 +0900983 pe_data[0] = ' ';
Simon Hormane9e5eee2010-11-08 20:05:57 +0900984 len = strlen(cp->pe->name);
985 memcpy(pe_data + 1, cp->pe->name, len);
Simon Hormana3c918a2010-08-22 21:37:53 +0900986 pe_data[len + 1] = ' ';
987 len += 2;
Simon Hormane9e5eee2010-11-08 20:05:57 +0900988 len += cp->pe->show_pe_data(cp, pe_data + len);
Simon Hormana3c918a2010-08-22 21:37:53 +0900989 }
990 pe_data[len] = '\0';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991
Vince Busam667a5f12008-09-02 15:55:49 +0200992#ifdef CONFIG_IP_VS_IPV6
993 if (cp->af == AF_INET6)
Simon Hormana3c918a2010-08-22 21:37:53 +0900994 seq_printf(seq, "%-3s %pI6 %04X %pI6 %04X "
995 "%pI6 %04X %-11s %7lu%s\n",
Vince Busam667a5f12008-09-02 15:55:49 +0200996 ip_vs_proto_name(cp->protocol),
Harvey Harrison38ff4fa2008-10-28 16:08:13 -0700997 &cp->caddr.in6, ntohs(cp->cport),
998 &cp->vaddr.in6, ntohs(cp->vport),
999 &cp->daddr.in6, ntohs(cp->dport),
Vince Busam667a5f12008-09-02 15:55:49 +02001000 ip_vs_state_name(cp->protocol, cp->state),
Simon Hormana3c918a2010-08-22 21:37:53 +09001001 (cp->timer.expires-jiffies)/HZ, pe_data);
Vince Busam667a5f12008-09-02 15:55:49 +02001002 else
1003#endif
1004 seq_printf(seq,
1005 "%-3s %08X %04X %08X %04X"
Simon Hormana3c918a2010-08-22 21:37:53 +09001006 " %08X %04X %-11s %7lu%s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 ip_vs_proto_name(cp->protocol),
Julius Volze7ade462008-09-02 15:55:33 +02001008 ntohl(cp->caddr.ip), ntohs(cp->cport),
1009 ntohl(cp->vaddr.ip), ntohs(cp->vport),
1010 ntohl(cp->daddr.ip), ntohs(cp->dport),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 ip_vs_state_name(cp->protocol, cp->state),
Simon Hormana3c918a2010-08-22 21:37:53 +09001012 (cp->timer.expires-jiffies)/HZ, pe_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 }
1014 return 0;
1015}
1016
Philippe De Muyter56b3d972007-07-10 23:07:31 -07001017static const struct seq_operations ip_vs_conn_seq_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 .start = ip_vs_conn_seq_start,
1019 .next = ip_vs_conn_seq_next,
1020 .stop = ip_vs_conn_seq_stop,
1021 .show = ip_vs_conn_seq_show,
1022};
1023
1024static int ip_vs_conn_open(struct inode *inode, struct file *file)
1025{
Hans Schillstrom6e67e582011-01-03 14:44:57 +01001026 return seq_open_net(inode, file, &ip_vs_conn_seq_ops,
1027 sizeof(struct ip_vs_iter_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028}
1029
Arjan van de Ven9a321442007-02-12 00:55:35 -08001030static const struct file_operations ip_vs_conn_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 .owner = THIS_MODULE,
1032 .open = ip_vs_conn_open,
1033 .read = seq_read,
1034 .llseek = seq_lseek,
1035 .release = seq_release,
1036};
Rumen G. Bogdanovski7a4fbb12007-11-19 21:52:42 -08001037
1038static const char *ip_vs_origin_name(unsigned flags)
1039{
1040 if (flags & IP_VS_CONN_F_SYNC)
1041 return "SYNC";
1042 else
1043 return "LOCAL";
1044}
1045
1046static int ip_vs_conn_sync_seq_show(struct seq_file *seq, void *v)
1047{
1048
1049 if (v == SEQ_START_TOKEN)
1050 seq_puts(seq,
1051 "Pro FromIP FPrt ToIP TPrt DestIP DPrt State Origin Expires\n");
1052 else {
1053 const struct ip_vs_conn *cp = v;
Hans Schillstrom6e67e582011-01-03 14:44:57 +01001054 struct net *net = seq_file_net(seq);
1055
1056 if (!ip_vs_conn_net_eq(cp, net))
1057 return 0;
Rumen G. Bogdanovski7a4fbb12007-11-19 21:52:42 -08001058
Vince Busam667a5f12008-09-02 15:55:49 +02001059#ifdef CONFIG_IP_VS_IPV6
1060 if (cp->af == AF_INET6)
Harvey Harrison5b095d9892008-10-29 12:52:50 -07001061 seq_printf(seq, "%-3s %pI6 %04X %pI6 %04X %pI6 %04X %-11s %-6s %7lu\n",
Vince Busam667a5f12008-09-02 15:55:49 +02001062 ip_vs_proto_name(cp->protocol),
Harvey Harrison38ff4fa2008-10-28 16:08:13 -07001063 &cp->caddr.in6, ntohs(cp->cport),
1064 &cp->vaddr.in6, ntohs(cp->vport),
1065 &cp->daddr.in6, ntohs(cp->dport),
Vince Busam667a5f12008-09-02 15:55:49 +02001066 ip_vs_state_name(cp->protocol, cp->state),
1067 ip_vs_origin_name(cp->flags),
1068 (cp->timer.expires-jiffies)/HZ);
1069 else
1070#endif
1071 seq_printf(seq,
1072 "%-3s %08X %04X %08X %04X "
1073 "%08X %04X %-11s %-6s %7lu\n",
Rumen G. Bogdanovski7a4fbb12007-11-19 21:52:42 -08001074 ip_vs_proto_name(cp->protocol),
Julius Volze7ade462008-09-02 15:55:33 +02001075 ntohl(cp->caddr.ip), ntohs(cp->cport),
1076 ntohl(cp->vaddr.ip), ntohs(cp->vport),
1077 ntohl(cp->daddr.ip), ntohs(cp->dport),
Rumen G. Bogdanovski7a4fbb12007-11-19 21:52:42 -08001078 ip_vs_state_name(cp->protocol, cp->state),
1079 ip_vs_origin_name(cp->flags),
1080 (cp->timer.expires-jiffies)/HZ);
1081 }
1082 return 0;
1083}
1084
1085static const struct seq_operations ip_vs_conn_sync_seq_ops = {
1086 .start = ip_vs_conn_seq_start,
1087 .next = ip_vs_conn_seq_next,
1088 .stop = ip_vs_conn_seq_stop,
1089 .show = ip_vs_conn_sync_seq_show,
1090};
1091
1092static int ip_vs_conn_sync_open(struct inode *inode, struct file *file)
1093{
Hans Schillstrom6e67e582011-01-03 14:44:57 +01001094 return seq_open_net(inode, file, &ip_vs_conn_sync_seq_ops,
1095 sizeof(struct ip_vs_iter_state));
Rumen G. Bogdanovski7a4fbb12007-11-19 21:52:42 -08001096}
1097
1098static const struct file_operations ip_vs_conn_sync_fops = {
1099 .owner = THIS_MODULE,
1100 .open = ip_vs_conn_sync_open,
1101 .read = seq_read,
1102 .llseek = seq_lseek,
1103 .release = seq_release,
1104};
1105
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106#endif
1107
1108
1109/*
1110 * Randomly drop connection entries before running out of memory
1111 */
1112static inline int todrop_entry(struct ip_vs_conn *cp)
1113{
1114 /*
1115 * The drop rate array needs tuning for real environments.
1116 * Called from timer bh only => no locking
1117 */
Arjan van de Ven9b5b5cf2005-11-29 16:21:38 -08001118 static const char todrop_rate[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 static char todrop_counter[9] = {0};
1120 int i;
1121
1122 /* if the conn entry hasn't lasted for 60 seconds, don't drop it.
1123 This will leave enough time for normal connection to get
1124 through. */
1125 if (time_before(cp->timeout + jiffies, cp->timer.expires + 60*HZ))
1126 return 0;
1127
1128 /* Don't drop the entry if its number of incoming packets is not
1129 located in [0, 8] */
1130 i = atomic_read(&cp->in_pkts);
1131 if (i > 8 || i < 0) return 0;
1132
1133 if (!todrop_rate[i]) return 0;
1134 if (--todrop_counter[i] > 0) return 0;
1135
1136 todrop_counter[i] = todrop_rate[i];
1137 return 1;
1138}
1139
Julian Anastasovaf9debd2005-07-11 20:59:57 -07001140/* Called from keventd and must protect itself from softirqs */
Hans Schillstromf6340ee2011-01-03 14:44:59 +01001141void ip_vs_random_dropentry(struct net *net)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142{
1143 int idx;
1144 struct ip_vs_conn *cp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
1146 /*
1147 * Randomly scan 1/32 of the whole table every second
1148 */
Catalin(ux) M. BOIE6f7edb42010-01-05 05:50:24 +01001149 for (idx = 0; idx < (ip_vs_conn_tab_size>>5); idx++) {
1150 unsigned hash = net_random() & ip_vs_conn_tab_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
1152 /*
1153 * Lock is actually needed in this loop.
1154 */
Julian Anastasovaf9debd2005-07-11 20:59:57 -07001155 ct_write_lock_bh(hash);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
1157 list_for_each_entry(cp, &ip_vs_conn_tab[hash], c_list) {
Julian Anastasov87375ab2005-09-14 21:08:51 -07001158 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 /* connection template */
1160 continue;
Hans Schillstromf6340ee2011-01-03 14:44:59 +01001161 if (!ip_vs_conn_net_eq(cp, net))
1162 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 if (cp->protocol == IPPROTO_TCP) {
1164 switch(cp->state) {
1165 case IP_VS_TCP_S_SYN_RECV:
1166 case IP_VS_TCP_S_SYNACK:
1167 break;
1168
1169 case IP_VS_TCP_S_ESTABLISHED:
1170 if (todrop_entry(cp))
1171 break;
1172 continue;
1173
1174 default:
1175 continue;
1176 }
1177 } else {
1178 if (!todrop_entry(cp))
1179 continue;
1180 }
1181
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 IP_VS_DBG(4, "del connection\n");
1183 ip_vs_conn_expire_now(cp);
Neil Hormanfb3d8942005-06-28 15:40:02 -07001184 if (cp->control) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 IP_VS_DBG(4, "del conn template\n");
Neil Hormanfb3d8942005-06-28 15:40:02 -07001186 ip_vs_conn_expire_now(cp->control);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 }
Julian Anastasovaf9debd2005-07-11 20:59:57 -07001189 ct_write_unlock_bh(hash);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 }
1191}
1192
1193
1194/*
1195 * Flush all the connection entries in the ip_vs_conn_tab
1196 */
Hans Schillstrom6e67e582011-01-03 14:44:57 +01001197static void ip_vs_conn_flush(struct net *net)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198{
1199 int idx;
1200 struct ip_vs_conn *cp;
Hans Schillstrom6e67e582011-01-03 14:44:57 +01001201 struct netns_ipvs *ipvs = net_ipvs(net);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202
Hans Schillstroma0840e22011-01-03 14:44:58 +01001203flush_again:
Catalin(ux) M. BOIE6f7edb42010-01-05 05:50:24 +01001204 for (idx = 0; idx < ip_vs_conn_tab_size; idx++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 /*
1206 * Lock is actually needed in this loop.
1207 */
1208 ct_write_lock_bh(idx);
1209
1210 list_for_each_entry(cp, &ip_vs_conn_tab[idx], c_list) {
Hans Schillstrom6e67e582011-01-03 14:44:57 +01001211 if (!ip_vs_conn_net_eq(cp, net))
1212 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 IP_VS_DBG(4, "del connection\n");
1214 ip_vs_conn_expire_now(cp);
Neil Hormanfb3d8942005-06-28 15:40:02 -07001215 if (cp->control) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 IP_VS_DBG(4, "del conn template\n");
Neil Hormanfb3d8942005-06-28 15:40:02 -07001217 ip_vs_conn_expire_now(cp->control);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 }
1220 ct_write_unlock_bh(idx);
1221 }
1222
1223 /* the counter may be not NULL, because maybe some conn entries
1224 are run by slow timer handler or unhashed but still referred */
Hans Schillstrom6e67e582011-01-03 14:44:57 +01001225 if (atomic_read(&ipvs->conn_count) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 schedule();
1227 goto flush_again;
1228 }
1229}
Hans Schillstrom61b1ab42011-01-03 14:44:42 +01001230/*
1231 * per netns init and exit
1232 */
1233int __net_init __ip_vs_conn_init(struct net *net)
1234{
Hans Schillstrom6e67e582011-01-03 14:44:57 +01001235 struct netns_ipvs *ipvs = net_ipvs(net);
1236
Hans Schillstrom61b1ab42011-01-03 14:44:42 +01001237 if (!net_eq(net, &init_net)) /* netns not enabled yet */
1238 return -EPERM;
Hans Schillstrom6e67e582011-01-03 14:44:57 +01001239 atomic_set(&ipvs->conn_count, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240
Hans Schillstrom61b1ab42011-01-03 14:44:42 +01001241 proc_net_fops_create(net, "ip_vs_conn", 0, &ip_vs_conn_fops);
1242 proc_net_fops_create(net, "ip_vs_conn_sync", 0, &ip_vs_conn_sync_fops);
1243 return 0;
1244}
1245
1246static void __net_exit __ip_vs_conn_cleanup(struct net *net)
1247{
1248 if (!net_eq(net, &init_net)) /* netns not enabled yet */
1249 return;
1250
Hans Schillstrom6e67e582011-01-03 14:44:57 +01001251 /* flush all the connection entries first */
1252 ip_vs_conn_flush(net);
Hans Schillstrom61b1ab42011-01-03 14:44:42 +01001253 proc_net_remove(net, "ip_vs_conn");
1254 proc_net_remove(net, "ip_vs_conn_sync");
1255}
1256static struct pernet_operations ipvs_conn_ops = {
1257 .init = __ip_vs_conn_init,
1258 .exit = __ip_vs_conn_cleanup,
1259};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260
Sven Wegener048cf482008-08-10 18:24:35 +00001261int __init ip_vs_conn_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262{
1263 int idx;
Hans Schillstrom61b1ab42011-01-03 14:44:42 +01001264 int retc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265
Catalin(ux) M. BOIE6f7edb42010-01-05 05:50:24 +01001266 /* Compute size and mask */
1267 ip_vs_conn_tab_size = 1 << ip_vs_conn_tab_bits;
1268 ip_vs_conn_tab_mask = ip_vs_conn_tab_size - 1;
1269
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 /*
1271 * Allocate the connection hash table and initialize its list heads
1272 */
Catalin(ux) M. BOIE6f7edb42010-01-05 05:50:24 +01001273 ip_vs_conn_tab = vmalloc(ip_vs_conn_tab_size *
1274 sizeof(struct list_head));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 if (!ip_vs_conn_tab)
1276 return -ENOMEM;
1277
1278 /* Allocate ip_vs_conn slab cache */
1279 ip_vs_conn_cachep = kmem_cache_create("ip_vs_conn",
1280 sizeof(struct ip_vs_conn), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09001281 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 if (!ip_vs_conn_cachep) {
1283 vfree(ip_vs_conn_tab);
1284 return -ENOMEM;
1285 }
1286
Hannes Eder1e3e2382009-08-02 11:05:41 +00001287 pr_info("Connection hash table configured "
1288 "(size=%d, memory=%ldKbytes)\n",
Catalin(ux) M. BOIE6f7edb42010-01-05 05:50:24 +01001289 ip_vs_conn_tab_size,
1290 (long)(ip_vs_conn_tab_size*sizeof(struct list_head))/1024);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 IP_VS_DBG(0, "Each connection entry needs %Zd bytes at least\n",
1292 sizeof(struct ip_vs_conn));
1293
Catalin(ux) M. BOIE6f7edb42010-01-05 05:50:24 +01001294 for (idx = 0; idx < ip_vs_conn_tab_size; idx++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 INIT_LIST_HEAD(&ip_vs_conn_tab[idx]);
1296 }
1297
1298 for (idx = 0; idx < CT_LOCKARRAY_SIZE; idx++) {
1299 rwlock_init(&__ip_vs_conntbl_lock_array[idx].l);
1300 }
1301
Hans Schillstrom61b1ab42011-01-03 14:44:42 +01001302 retc = register_pernet_subsys(&ipvs_conn_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303
1304 /* calculate the random value for connection hash */
1305 get_random_bytes(&ip_vs_conn_rnd, sizeof(ip_vs_conn_rnd));
1306
Hans Schillstrom61b1ab42011-01-03 14:44:42 +01001307 return retc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308}
1309
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310void ip_vs_conn_cleanup(void)
1311{
Hans Schillstrom61b1ab42011-01-03 14:44:42 +01001312 unregister_pernet_subsys(&ipvs_conn_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 /* Release the empty cache */
1314 kmem_cache_destroy(ip_vs_conn_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 vfree(ip_vs_conn_tab);
1316}