blob: f5dddad6d5e4986b6204aa2c4faf88fe2a51b4b1 [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
Andrew Mortone9242832006-01-05 14:57:36 -080025#include <linux/interrupt.h>
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020026#include <linux/in.h>
Arnaldo Carvalho de Melof1900552006-01-04 02:02:20 -020027#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/kernel.h>
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020029#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/vmalloc.h>
31#include <linux/proc_fs.h> /* for proc_net_* */
32#include <linux/seq_file.h>
33#include <linux/jhash.h>
34#include <linux/random.h>
35
Eric W. Biederman457c4cb2007-09-12 12:01:34 +020036#include <net/net_namespace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <net/ip_vs.h>
38
39
40/*
41 * Connection hash table: for input and output packets lookups of IPVS
42 */
43static struct list_head *ip_vs_conn_tab;
44
45/* SLAB cache for IPVS connections */
Christoph Lametere18b8902006-12-06 20:33:20 -080046static struct kmem_cache *ip_vs_conn_cachep __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48/* counter for current IPVS connections */
49static atomic_t ip_vs_conn_count = ATOMIC_INIT(0);
50
51/* counter for no client port connections */
52static atomic_t ip_vs_conn_no_cport_cnt = ATOMIC_INIT(0);
53
54/* random value for IPVS connection hash */
55static unsigned int ip_vs_conn_rnd;
56
57/*
58 * Fine locking granularity for big connection hash table
59 */
60#define CT_LOCKARRAY_BITS 4
61#define CT_LOCKARRAY_SIZE (1<<CT_LOCKARRAY_BITS)
62#define CT_LOCKARRAY_MASK (CT_LOCKARRAY_SIZE-1)
63
64struct ip_vs_aligned_lock
65{
66 rwlock_t l;
67} __attribute__((__aligned__(SMP_CACHE_BYTES)));
68
69/* lock array for conn table */
70static struct ip_vs_aligned_lock
71__ip_vs_conntbl_lock_array[CT_LOCKARRAY_SIZE] __cacheline_aligned;
72
73static inline void ct_read_lock(unsigned key)
74{
75 read_lock(&__ip_vs_conntbl_lock_array[key&CT_LOCKARRAY_MASK].l);
76}
77
78static inline void ct_read_unlock(unsigned key)
79{
80 read_unlock(&__ip_vs_conntbl_lock_array[key&CT_LOCKARRAY_MASK].l);
81}
82
83static inline void ct_write_lock(unsigned key)
84{
85 write_lock(&__ip_vs_conntbl_lock_array[key&CT_LOCKARRAY_MASK].l);
86}
87
88static inline void ct_write_unlock(unsigned key)
89{
90 write_unlock(&__ip_vs_conntbl_lock_array[key&CT_LOCKARRAY_MASK].l);
91}
92
93static inline void ct_read_lock_bh(unsigned key)
94{
95 read_lock_bh(&__ip_vs_conntbl_lock_array[key&CT_LOCKARRAY_MASK].l);
96}
97
98static inline void ct_read_unlock_bh(unsigned key)
99{
100 read_unlock_bh(&__ip_vs_conntbl_lock_array[key&CT_LOCKARRAY_MASK].l);
101}
102
103static inline void ct_write_lock_bh(unsigned key)
104{
105 write_lock_bh(&__ip_vs_conntbl_lock_array[key&CT_LOCKARRAY_MASK].l);
106}
107
108static inline void ct_write_unlock_bh(unsigned key)
109{
110 write_unlock_bh(&__ip_vs_conntbl_lock_array[key&CT_LOCKARRAY_MASK].l);
111}
112
113
114/*
115 * Returns hash value for IPVS connection entry
116 */
Julius Volz28364a52008-09-02 15:55:43 +0200117static unsigned int ip_vs_conn_hashkey(int af, unsigned proto,
118 const union nf_inet_addr *addr,
119 __be16 port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120{
Julius Volz28364a52008-09-02 15:55:43 +0200121#ifdef CONFIG_IP_VS_IPV6
122 if (af == AF_INET6)
123 return jhash_3words(jhash(addr, 16, ip_vs_conn_rnd),
124 (__force u32)port, proto, ip_vs_conn_rnd)
125 & IP_VS_CONN_TAB_MASK;
126#endif
127 return jhash_3words((__force u32)addr->ip, (__force u32)port, proto,
128 ip_vs_conn_rnd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 & IP_VS_CONN_TAB_MASK;
130}
131
132
133/*
134 * Hashes ip_vs_conn in ip_vs_conn_tab by proto,addr,port.
135 * returns bool success.
136 */
137static inline int ip_vs_conn_hash(struct ip_vs_conn *cp)
138{
139 unsigned hash;
140 int ret;
141
142 /* Hash by protocol, client address and port */
Julius Volz28364a52008-09-02 15:55:43 +0200143 hash = ip_vs_conn_hashkey(cp->af, cp->protocol, &cp->caddr, cp->cport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145 ct_write_lock(hash);
146
147 if (!(cp->flags & IP_VS_CONN_F_HASHED)) {
148 list_add(&cp->c_list, &ip_vs_conn_tab[hash]);
149 cp->flags |= IP_VS_CONN_F_HASHED;
150 atomic_inc(&cp->refcnt);
151 ret = 1;
152 } else {
153 IP_VS_ERR("ip_vs_conn_hash(): request for already hashed, "
154 "called from %p\n", __builtin_return_address(0));
155 ret = 0;
156 }
157
158 ct_write_unlock(hash);
159
160 return ret;
161}
162
163
164/*
165 * UNhashes ip_vs_conn from ip_vs_conn_tab.
166 * returns bool success.
167 */
168static inline int ip_vs_conn_unhash(struct ip_vs_conn *cp)
169{
170 unsigned hash;
171 int ret;
172
173 /* unhash it and decrease its reference counter */
Julius Volz28364a52008-09-02 15:55:43 +0200174 hash = ip_vs_conn_hashkey(cp->af, cp->protocol, &cp->caddr, cp->cport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
176 ct_write_lock(hash);
177
178 if (cp->flags & IP_VS_CONN_F_HASHED) {
179 list_del(&cp->c_list);
180 cp->flags &= ~IP_VS_CONN_F_HASHED;
181 atomic_dec(&cp->refcnt);
182 ret = 1;
183 } else
184 ret = 0;
185
186 ct_write_unlock(hash);
187
188 return ret;
189}
190
191
192/*
193 * Gets ip_vs_conn associated with supplied parameters in the ip_vs_conn_tab.
194 * Called for pkts coming from OUTside-to-INside.
195 * s_addr, s_port: pkt source address (foreign host)
196 * d_addr, d_port: pkt dest address (load balancer)
197 */
198static inline struct ip_vs_conn *__ip_vs_conn_in_get
Julius Volz28364a52008-09-02 15:55:43 +0200199(int af, int protocol, const union nf_inet_addr *s_addr, __be16 s_port,
200 const union nf_inet_addr *d_addr, __be16 d_port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201{
202 unsigned hash;
203 struct ip_vs_conn *cp;
204
Julius Volz28364a52008-09-02 15:55:43 +0200205 hash = ip_vs_conn_hashkey(af, protocol, s_addr, s_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
207 ct_read_lock(hash);
208
209 list_for_each_entry(cp, &ip_vs_conn_tab[hash], c_list) {
Julius Volz28364a52008-09-02 15:55:43 +0200210 if (cp->af == af &&
211 ip_vs_addr_equal(af, s_addr, &cp->caddr) &&
212 ip_vs_addr_equal(af, d_addr, &cp->vaddr) &&
213 s_port == cp->cport && d_port == cp->vport &&
Julian Anastasov87375ab2005-09-14 21:08:51 -0700214 ((!s_port) ^ (!(cp->flags & IP_VS_CONN_F_NO_CPORT))) &&
Julius Volze7ade462008-09-02 15:55:33 +0200215 protocol == cp->protocol) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 /* HIT */
217 atomic_inc(&cp->refcnt);
218 ct_read_unlock(hash);
219 return cp;
220 }
221 }
222
223 ct_read_unlock(hash);
224
225 return NULL;
226}
227
228struct ip_vs_conn *ip_vs_conn_in_get
Julius Volz28364a52008-09-02 15:55:43 +0200229(int af, int protocol, const union nf_inet_addr *s_addr, __be16 s_port,
230 const union nf_inet_addr *d_addr, __be16 d_port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
232 struct ip_vs_conn *cp;
233
Julius Volz28364a52008-09-02 15:55:43 +0200234 cp = __ip_vs_conn_in_get(af, protocol, s_addr, s_port, d_addr, d_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 if (!cp && atomic_read(&ip_vs_conn_no_cport_cnt))
Julius Volz28364a52008-09-02 15:55:43 +0200236 cp = __ip_vs_conn_in_get(af, protocol, s_addr, 0, d_addr,
237 d_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Julius Volz28364a52008-09-02 15:55:43 +0200239 IP_VS_DBG_BUF(9, "lookup/in %s %s:%d->%s:%d %s\n",
240 ip_vs_proto_name(protocol),
241 IP_VS_DBG_ADDR(af, s_addr), ntohs(s_port),
242 IP_VS_DBG_ADDR(af, d_addr), ntohs(d_port),
243 cp ? "hit" : "not hit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
245 return cp;
246}
247
Julian Anastasov87375ab2005-09-14 21:08:51 -0700248/* Get reference to connection template */
249struct ip_vs_conn *ip_vs_ct_in_get
Julius Volz28364a52008-09-02 15:55:43 +0200250(int af, int protocol, const union nf_inet_addr *s_addr, __be16 s_port,
251 const union nf_inet_addr *d_addr, __be16 d_port)
Julian Anastasov87375ab2005-09-14 21:08:51 -0700252{
253 unsigned hash;
254 struct ip_vs_conn *cp;
255
Julius Volz28364a52008-09-02 15:55:43 +0200256 hash = ip_vs_conn_hashkey(af, protocol, s_addr, s_port);
Julian Anastasov87375ab2005-09-14 21:08:51 -0700257
258 ct_read_lock(hash);
259
260 list_for_each_entry(cp, &ip_vs_conn_tab[hash], c_list) {
Julius Volz28364a52008-09-02 15:55:43 +0200261 if (cp->af == af &&
262 ip_vs_addr_equal(af, s_addr, &cp->caddr) &&
263 ip_vs_addr_equal(af, d_addr, &cp->vaddr) &&
264 s_port == cp->cport && d_port == cp->vport &&
Julian Anastasov87375ab2005-09-14 21:08:51 -0700265 cp->flags & IP_VS_CONN_F_TEMPLATE &&
Julius Volze7ade462008-09-02 15:55:33 +0200266 protocol == cp->protocol) {
Julian Anastasov87375ab2005-09-14 21:08:51 -0700267 /* HIT */
268 atomic_inc(&cp->refcnt);
269 goto out;
270 }
271 }
272 cp = NULL;
273
274 out:
275 ct_read_unlock(hash);
276
Julius Volz28364a52008-09-02 15:55:43 +0200277 IP_VS_DBG_BUF(9, "template lookup/in %s %s:%d->%s:%d %s\n",
278 ip_vs_proto_name(protocol),
279 IP_VS_DBG_ADDR(af, s_addr), ntohs(s_port),
280 IP_VS_DBG_ADDR(af, d_addr), ntohs(d_port),
281 cp ? "hit" : "not hit");
Julian Anastasov87375ab2005-09-14 21:08:51 -0700282
283 return cp;
284}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
286/*
287 * Gets ip_vs_conn associated with supplied parameters in the ip_vs_conn_tab.
288 * Called for pkts coming from inside-to-OUTside.
289 * s_addr, s_port: pkt source address (inside host)
290 * d_addr, d_port: pkt dest address (foreign host)
291 */
292struct ip_vs_conn *ip_vs_conn_out_get
Julius Volz28364a52008-09-02 15:55:43 +0200293(int af, int protocol, const union nf_inet_addr *s_addr, __be16 s_port,
294 const union nf_inet_addr *d_addr, __be16 d_port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
296 unsigned hash;
297 struct ip_vs_conn *cp, *ret=NULL;
298
299 /*
300 * Check for "full" addressed entries
301 */
Julius Volz28364a52008-09-02 15:55:43 +0200302 hash = ip_vs_conn_hashkey(af, protocol, d_addr, d_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
304 ct_read_lock(hash);
305
306 list_for_each_entry(cp, &ip_vs_conn_tab[hash], c_list) {
Julius Volz28364a52008-09-02 15:55:43 +0200307 if (cp->af == af &&
308 ip_vs_addr_equal(af, d_addr, &cp->caddr) &&
309 ip_vs_addr_equal(af, s_addr, &cp->daddr) &&
310 d_port == cp->cport && s_port == cp->dport &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 protocol == cp->protocol) {
312 /* HIT */
313 atomic_inc(&cp->refcnt);
314 ret = cp;
315 break;
316 }
317 }
318
319 ct_read_unlock(hash);
320
Julius Volz28364a52008-09-02 15:55:43 +0200321 IP_VS_DBG_BUF(9, "lookup/out %s %s:%d->%s:%d %s\n",
322 ip_vs_proto_name(protocol),
323 IP_VS_DBG_ADDR(af, s_addr), ntohs(s_port),
324 IP_VS_DBG_ADDR(af, d_addr), ntohs(d_port),
325 ret ? "hit" : "not hit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
327 return ret;
328}
329
330
331/*
332 * Put back the conn and restart its timer with its timeout
333 */
334void ip_vs_conn_put(struct ip_vs_conn *cp)
335{
336 /* reset it expire in its timeout */
337 mod_timer(&cp->timer, jiffies+cp->timeout);
338
339 __ip_vs_conn_put(cp);
340}
341
342
343/*
344 * Fill a no_client_port connection with a client port number
345 */
Al Viro014d7302006-09-28 14:29:52 -0700346void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347{
348 if (ip_vs_conn_unhash(cp)) {
349 spin_lock(&cp->lock);
350 if (cp->flags & IP_VS_CONN_F_NO_CPORT) {
351 atomic_dec(&ip_vs_conn_no_cport_cnt);
352 cp->flags &= ~IP_VS_CONN_F_NO_CPORT;
353 cp->cport = cport;
354 }
355 spin_unlock(&cp->lock);
356
357 /* hash on new dport */
358 ip_vs_conn_hash(cp);
359 }
360}
361
362
363/*
364 * Bind a connection entry with the corresponding packet_xmit.
365 * Called by ip_vs_conn_new.
366 */
367static inline void ip_vs_bind_xmit(struct ip_vs_conn *cp)
368{
369 switch (IP_VS_FWD_METHOD(cp)) {
370 case IP_VS_CONN_F_MASQ:
371 cp->packet_xmit = ip_vs_nat_xmit;
372 break;
373
374 case IP_VS_CONN_F_TUNNEL:
375 cp->packet_xmit = ip_vs_tunnel_xmit;
376 break;
377
378 case IP_VS_CONN_F_DROUTE:
379 cp->packet_xmit = ip_vs_dr_xmit;
380 break;
381
382 case IP_VS_CONN_F_LOCALNODE:
383 cp->packet_xmit = ip_vs_null_xmit;
384 break;
385
386 case IP_VS_CONN_F_BYPASS:
387 cp->packet_xmit = ip_vs_bypass_xmit;
388 break;
389 }
390}
391
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200392#ifdef CONFIG_IP_VS_IPV6
393static inline void ip_vs_bind_xmit_v6(struct ip_vs_conn *cp)
394{
395 switch (IP_VS_FWD_METHOD(cp)) {
396 case IP_VS_CONN_F_MASQ:
397 cp->packet_xmit = ip_vs_nat_xmit_v6;
398 break;
399
400 case IP_VS_CONN_F_TUNNEL:
401 cp->packet_xmit = ip_vs_tunnel_xmit_v6;
402 break;
403
404 case IP_VS_CONN_F_DROUTE:
405 cp->packet_xmit = ip_vs_dr_xmit_v6;
406 break;
407
408 case IP_VS_CONN_F_LOCALNODE:
409 cp->packet_xmit = ip_vs_null_xmit;
410 break;
411
412 case IP_VS_CONN_F_BYPASS:
413 cp->packet_xmit = ip_vs_bypass_xmit_v6;
414 break;
415 }
416}
417#endif
418
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
420static inline int ip_vs_dest_totalconns(struct ip_vs_dest *dest)
421{
422 return atomic_read(&dest->activeconns)
423 + atomic_read(&dest->inactconns);
424}
425
426/*
427 * Bind a connection entry with a virtual service destination
428 * Called just after a new connection entry is created.
429 */
430static inline void
431ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
432{
433 /* if dest is NULL, then return directly */
434 if (!dest)
435 return;
436
437 /* Increase the refcnt counter of the dest */
438 atomic_inc(&dest->refcnt);
439
440 /* Bind with the destination and its corresponding transmitter */
Rumen G. Bogdanovskib2096392007-11-19 21:53:27 -0800441 if ((cp->flags & IP_VS_CONN_F_SYNC) &&
442 (!(cp->flags & IP_VS_CONN_F_TEMPLATE)))
443 /* if the connection is not template and is created
444 * by sync, preserve the activity flag.
445 */
446 cp->flags |= atomic_read(&dest->conn_flags) &
447 (~IP_VS_CONN_F_INACTIVE);
448 else
449 cp->flags |= atomic_read(&dest->conn_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 cp->dest = dest;
451
Roberto Nibali4b5bdf52006-01-03 14:22:59 -0800452 IP_VS_DBG(7, "Bind-dest %s c:%u.%u.%u.%u:%d v:%u.%u.%u.%u:%d "
453 "d:%u.%u.%u.%u:%d fwd:%c s:%u conn->flags:%X conn->refcnt:%d "
454 "dest->refcnt:%d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 ip_vs_proto_name(cp->protocol),
Julius Volze7ade462008-09-02 15:55:33 +0200456 NIPQUAD(cp->caddr.ip), ntohs(cp->cport),
457 NIPQUAD(cp->vaddr.ip), ntohs(cp->vport),
458 NIPQUAD(cp->daddr.ip), ntohs(cp->dport),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 ip_vs_fwd_tag(cp), cp->state,
460 cp->flags, atomic_read(&cp->refcnt),
461 atomic_read(&dest->refcnt));
462
463 /* Update the connection counters */
Julian Anastasov87375ab2005-09-14 21:08:51 -0700464 if (!(cp->flags & IP_VS_CONN_F_TEMPLATE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 /* It is a normal connection, so increase the inactive
466 connection counter because it is in TCP SYNRECV
467 state (inactive) or other protocol inacive state */
Rumen G. Bogdanovskib2096392007-11-19 21:53:27 -0800468 if ((cp->flags & IP_VS_CONN_F_SYNC) &&
469 (!(cp->flags & IP_VS_CONN_F_INACTIVE)))
470 atomic_inc(&dest->activeconns);
471 else
472 atomic_inc(&dest->inactconns);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 } else {
474 /* It is a persistent connection/template, so increase
475 the peristent connection counter */
476 atomic_inc(&dest->persistconns);
477 }
478
479 if (dest->u_threshold != 0 &&
480 ip_vs_dest_totalconns(dest) >= dest->u_threshold)
481 dest->flags |= IP_VS_DEST_F_OVERLOAD;
482}
483
484
485/*
Rumen G. Bogdanovski1e356f92007-11-07 02:35:54 -0800486 * Check if there is a destination for the connection, if so
487 * bind the connection to the destination.
488 */
489struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp)
490{
491 struct ip_vs_dest *dest;
492
493 if ((cp) && (!cp->dest)) {
Julius Volze7ade462008-09-02 15:55:33 +0200494 dest = ip_vs_find_dest(cp->daddr.ip, cp->dport,
495 cp->vaddr.ip, cp->vport, cp->protocol);
Rumen G. Bogdanovski1e356f92007-11-07 02:35:54 -0800496 ip_vs_bind_dest(cp, dest);
497 return dest;
498 } else
499 return NULL;
500}
Rumen G. Bogdanovski1e356f92007-11-07 02:35:54 -0800501
502
503/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 * Unbind a connection entry with its VS destination
505 * Called by the ip_vs_conn_expire function.
506 */
507static inline void ip_vs_unbind_dest(struct ip_vs_conn *cp)
508{
509 struct ip_vs_dest *dest = cp->dest;
510
511 if (!dest)
512 return;
513
Roberto Nibali4b5bdf52006-01-03 14:22:59 -0800514 IP_VS_DBG(7, "Unbind-dest %s c:%u.%u.%u.%u:%d v:%u.%u.%u.%u:%d "
515 "d:%u.%u.%u.%u:%d fwd:%c s:%u conn->flags:%X conn->refcnt:%d "
516 "dest->refcnt:%d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 ip_vs_proto_name(cp->protocol),
Julius Volze7ade462008-09-02 15:55:33 +0200518 NIPQUAD(cp->caddr.ip), ntohs(cp->cport),
519 NIPQUAD(cp->vaddr.ip), ntohs(cp->vport),
520 NIPQUAD(cp->daddr.ip), ntohs(cp->dport),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 ip_vs_fwd_tag(cp), cp->state,
522 cp->flags, atomic_read(&cp->refcnt),
523 atomic_read(&dest->refcnt));
524
525 /* Update the connection counters */
Julian Anastasov87375ab2005-09-14 21:08:51 -0700526 if (!(cp->flags & IP_VS_CONN_F_TEMPLATE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 /* It is a normal connection, so decrease the inactconns
528 or activeconns counter */
529 if (cp->flags & IP_VS_CONN_F_INACTIVE) {
530 atomic_dec(&dest->inactconns);
531 } else {
532 atomic_dec(&dest->activeconns);
533 }
534 } else {
535 /* It is a persistent connection/template, so decrease
536 the peristent connection counter */
537 atomic_dec(&dest->persistconns);
538 }
539
540 if (dest->l_threshold != 0) {
541 if (ip_vs_dest_totalconns(dest) < dest->l_threshold)
542 dest->flags &= ~IP_VS_DEST_F_OVERLOAD;
543 } else if (dest->u_threshold != 0) {
544 if (ip_vs_dest_totalconns(dest) * 4 < dest->u_threshold * 3)
545 dest->flags &= ~IP_VS_DEST_F_OVERLOAD;
546 } else {
547 if (dest->flags & IP_VS_DEST_F_OVERLOAD)
548 dest->flags &= ~IP_VS_DEST_F_OVERLOAD;
549 }
550
551 /*
552 * Simply decrease the refcnt of the dest, because the
553 * dest will be either in service's destination list
554 * or in the trash.
555 */
556 atomic_dec(&dest->refcnt);
557}
558
559
560/*
561 * Checking if the destination of a connection template is available.
562 * If available, return 1, otherwise invalidate this connection
563 * template and return 0.
564 */
565int ip_vs_check_template(struct ip_vs_conn *ct)
566{
567 struct ip_vs_dest *dest = ct->dest;
568
569 /*
570 * Checking the dest server status.
571 */
572 if ((dest == NULL) ||
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900573 !(dest->flags & IP_VS_DEST_F_AVAILABLE) ||
574 (sysctl_ip_vs_expire_quiescent_template &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 (atomic_read(&dest->weight) == 0))) {
576 IP_VS_DBG(9, "check_template: dest not available for "
577 "protocol %s s:%u.%u.%u.%u:%d v:%u.%u.%u.%u:%d "
578 "-> d:%u.%u.%u.%u:%d\n",
579 ip_vs_proto_name(ct->protocol),
Julius Volze7ade462008-09-02 15:55:33 +0200580 NIPQUAD(ct->caddr.ip), ntohs(ct->cport),
581 NIPQUAD(ct->vaddr.ip), ntohs(ct->vport),
582 NIPQUAD(ct->daddr.ip), ntohs(ct->dport));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
584 /*
585 * Invalidate the connection template
586 */
Al Viro014d7302006-09-28 14:29:52 -0700587 if (ct->vport != htons(0xffff)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 if (ip_vs_conn_unhash(ct)) {
Al Viro014d7302006-09-28 14:29:52 -0700589 ct->dport = htons(0xffff);
590 ct->vport = htons(0xffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 ct->cport = 0;
592 ip_vs_conn_hash(ct);
593 }
594 }
595
596 /*
597 * Simply decrease the refcnt of the template,
598 * don't restart its timer.
599 */
600 atomic_dec(&ct->refcnt);
601 return 0;
602 }
603 return 1;
604}
605
606static void ip_vs_conn_expire(unsigned long data)
607{
608 struct ip_vs_conn *cp = (struct ip_vs_conn *)data;
609
610 cp->timeout = 60*HZ;
611
612 /*
613 * hey, I'm using it
614 */
615 atomic_inc(&cp->refcnt);
616
617 /*
618 * do I control anybody?
619 */
620 if (atomic_read(&cp->n_control))
621 goto expire_later;
622
623 /*
624 * unhash it if it is hashed in the conn table
625 */
626 if (!ip_vs_conn_unhash(cp))
627 goto expire_later;
628
629 /*
630 * refcnt==1 implies I'm the only one referrer
631 */
632 if (likely(atomic_read(&cp->refcnt) == 1)) {
633 /* delete the timer if it is activated by other users */
634 if (timer_pending(&cp->timer))
635 del_timer(&cp->timer);
636
637 /* does anybody control me? */
638 if (cp->control)
639 ip_vs_control_del(cp);
640
641 if (unlikely(cp->app != NULL))
642 ip_vs_unbind_app(cp);
643 ip_vs_unbind_dest(cp);
644 if (cp->flags & IP_VS_CONN_F_NO_CPORT)
645 atomic_dec(&ip_vs_conn_no_cport_cnt);
646 atomic_dec(&ip_vs_conn_count);
647
648 kmem_cache_free(ip_vs_conn_cachep, cp);
649 return;
650 }
651
652 /* hash it back to the table */
653 ip_vs_conn_hash(cp);
654
655 expire_later:
Roberto Nibali4b5bdf52006-01-03 14:22:59 -0800656 IP_VS_DBG(7, "delayed: conn->refcnt-1=%d conn->n_control=%d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 atomic_read(&cp->refcnt)-1,
658 atomic_read(&cp->n_control));
659
660 ip_vs_conn_put(cp);
661}
662
663
664void ip_vs_conn_expire_now(struct ip_vs_conn *cp)
665{
666 if (del_timer(&cp->timer))
667 mod_timer(&cp->timer, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668}
669
670
671/*
672 * Create a new connection entry and hash it into the ip_vs_conn_tab
673 */
674struct ip_vs_conn *
Julius Volz28364a52008-09-02 15:55:43 +0200675ip_vs_conn_new(int af, int proto, const union nf_inet_addr *caddr, __be16 cport,
676 const union nf_inet_addr *vaddr, __be16 vport,
677 const union nf_inet_addr *daddr, __be16 dport, unsigned flags,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 struct ip_vs_dest *dest)
679{
680 struct ip_vs_conn *cp;
681 struct ip_vs_protocol *pp = ip_vs_proto_get(proto);
682
Robert P. J. Dayc3762222007-02-10 01:45:03 -0800683 cp = kmem_cache_zalloc(ip_vs_conn_cachep, GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 if (cp == NULL) {
685 IP_VS_ERR_RL("ip_vs_conn_new: no memory available.\n");
686 return NULL;
687 }
688
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 INIT_LIST_HEAD(&cp->c_list);
Pavel Emelyanovb24b8a22008-01-23 21:20:07 -0800690 setup_timer(&cp->timer, ip_vs_conn_expire, (unsigned long)cp);
Julius Volz28364a52008-09-02 15:55:43 +0200691 cp->af = af;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 cp->protocol = proto;
Julius Volz28364a52008-09-02 15:55:43 +0200693 ip_vs_addr_copy(af, &cp->caddr, caddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 cp->cport = cport;
Julius Volz28364a52008-09-02 15:55:43 +0200695 ip_vs_addr_copy(af, &cp->vaddr, vaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 cp->vport = vport;
Julius Volz28364a52008-09-02 15:55:43 +0200697 ip_vs_addr_copy(af, &cp->daddr, daddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 cp->dport = dport;
699 cp->flags = flags;
700 spin_lock_init(&cp->lock);
701
702 /*
703 * Set the entry is referenced by the current thread before hashing
704 * it in the table, so that other thread run ip_vs_random_dropentry
705 * but cannot drop this entry.
706 */
707 atomic_set(&cp->refcnt, 1);
708
709 atomic_set(&cp->n_control, 0);
710 atomic_set(&cp->in_pkts, 0);
711
712 atomic_inc(&ip_vs_conn_count);
713 if (flags & IP_VS_CONN_F_NO_CPORT)
714 atomic_inc(&ip_vs_conn_no_cport_cnt);
715
716 /* Bind the connection with a destination server */
717 ip_vs_bind_dest(cp, dest);
718
719 /* Set its state and timeout */
720 cp->state = 0;
721 cp->timeout = 3*HZ;
722
723 /* Bind its packet transmitter */
Julius Volzb3cdd2a72008-09-02 15:55:45 +0200724#ifdef CONFIG_IP_VS_IPV6
725 if (af == AF_INET6)
726 ip_vs_bind_xmit_v6(cp);
727 else
728#endif
729 ip_vs_bind_xmit(cp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
731 if (unlikely(pp && atomic_read(&pp->appcnt)))
732 ip_vs_bind_app(cp, pp);
733
734 /* Hash it in the ip_vs_conn_tab finally */
735 ip_vs_conn_hash(cp);
736
737 return cp;
738}
739
740
741/*
742 * /proc/net/ip_vs_conn entries
743 */
744#ifdef CONFIG_PROC_FS
745
746static void *ip_vs_conn_array(struct seq_file *seq, loff_t pos)
747{
748 int idx;
749 struct ip_vs_conn *cp;
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900750
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 for(idx = 0; idx < IP_VS_CONN_TAB_SIZE; idx++) {
752 ct_read_lock_bh(idx);
753 list_for_each_entry(cp, &ip_vs_conn_tab[idx], c_list) {
754 if (pos-- == 0) {
755 seq->private = &ip_vs_conn_tab[idx];
756 return cp;
757 }
758 }
759 ct_read_unlock_bh(idx);
760 }
761
762 return NULL;
763}
764
765static void *ip_vs_conn_seq_start(struct seq_file *seq, loff_t *pos)
766{
767 seq->private = NULL;
768 return *pos ? ip_vs_conn_array(seq, *pos - 1) :SEQ_START_TOKEN;
769}
770
771static void *ip_vs_conn_seq_next(struct seq_file *seq, void *v, loff_t *pos)
772{
773 struct ip_vs_conn *cp = v;
774 struct list_head *e, *l = seq->private;
775 int idx;
776
777 ++*pos;
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900778 if (v == SEQ_START_TOKEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 return ip_vs_conn_array(seq, 0);
780
781 /* more on same hash chain? */
782 if ((e = cp->c_list.next) != l)
783 return list_entry(e, struct ip_vs_conn, c_list);
784
785 idx = l - ip_vs_conn_tab;
786 ct_read_unlock_bh(idx);
787
788 while (++idx < IP_VS_CONN_TAB_SIZE) {
789 ct_read_lock_bh(idx);
790 list_for_each_entry(cp, &ip_vs_conn_tab[idx], c_list) {
791 seq->private = &ip_vs_conn_tab[idx];
792 return cp;
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900793 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 ct_read_unlock_bh(idx);
795 }
796 seq->private = NULL;
797 return NULL;
798}
799
800static void ip_vs_conn_seq_stop(struct seq_file *seq, void *v)
801{
802 struct list_head *l = seq->private;
803
804 if (l)
805 ct_read_unlock_bh(l - ip_vs_conn_tab);
806}
807
808static int ip_vs_conn_seq_show(struct seq_file *seq, void *v)
809{
810
811 if (v == SEQ_START_TOKEN)
812 seq_puts(seq,
813 "Pro FromIP FPrt ToIP TPrt DestIP DPrt State Expires\n");
814 else {
815 const struct ip_vs_conn *cp = v;
816
817 seq_printf(seq,
818 "%-3s %08X %04X %08X %04X %08X %04X %-11s %7lu\n",
819 ip_vs_proto_name(cp->protocol),
Julius Volze7ade462008-09-02 15:55:33 +0200820 ntohl(cp->caddr.ip), ntohs(cp->cport),
821 ntohl(cp->vaddr.ip), ntohs(cp->vport),
822 ntohl(cp->daddr.ip), ntohs(cp->dport),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 ip_vs_state_name(cp->protocol, cp->state),
824 (cp->timer.expires-jiffies)/HZ);
825 }
826 return 0;
827}
828
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700829static const struct seq_operations ip_vs_conn_seq_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 .start = ip_vs_conn_seq_start,
831 .next = ip_vs_conn_seq_next,
832 .stop = ip_vs_conn_seq_stop,
833 .show = ip_vs_conn_seq_show,
834};
835
836static int ip_vs_conn_open(struct inode *inode, struct file *file)
837{
838 return seq_open(file, &ip_vs_conn_seq_ops);
839}
840
Arjan van de Ven9a321442007-02-12 00:55:35 -0800841static const struct file_operations ip_vs_conn_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 .owner = THIS_MODULE,
843 .open = ip_vs_conn_open,
844 .read = seq_read,
845 .llseek = seq_lseek,
846 .release = seq_release,
847};
Rumen G. Bogdanovski7a4fbb12007-11-19 21:52:42 -0800848
849static const char *ip_vs_origin_name(unsigned flags)
850{
851 if (flags & IP_VS_CONN_F_SYNC)
852 return "SYNC";
853 else
854 return "LOCAL";
855}
856
857static int ip_vs_conn_sync_seq_show(struct seq_file *seq, void *v)
858{
859
860 if (v == SEQ_START_TOKEN)
861 seq_puts(seq,
862 "Pro FromIP FPrt ToIP TPrt DestIP DPrt State Origin Expires\n");
863 else {
864 const struct ip_vs_conn *cp = v;
865
866 seq_printf(seq,
867 "%-3s %08X %04X %08X %04X %08X %04X %-11s %-6s %7lu\n",
868 ip_vs_proto_name(cp->protocol),
Julius Volze7ade462008-09-02 15:55:33 +0200869 ntohl(cp->caddr.ip), ntohs(cp->cport),
870 ntohl(cp->vaddr.ip), ntohs(cp->vport),
871 ntohl(cp->daddr.ip), ntohs(cp->dport),
Rumen G. Bogdanovski7a4fbb12007-11-19 21:52:42 -0800872 ip_vs_state_name(cp->protocol, cp->state),
873 ip_vs_origin_name(cp->flags),
874 (cp->timer.expires-jiffies)/HZ);
875 }
876 return 0;
877}
878
879static const struct seq_operations ip_vs_conn_sync_seq_ops = {
880 .start = ip_vs_conn_seq_start,
881 .next = ip_vs_conn_seq_next,
882 .stop = ip_vs_conn_seq_stop,
883 .show = ip_vs_conn_sync_seq_show,
884};
885
886static int ip_vs_conn_sync_open(struct inode *inode, struct file *file)
887{
888 return seq_open(file, &ip_vs_conn_sync_seq_ops);
889}
890
891static const struct file_operations ip_vs_conn_sync_fops = {
892 .owner = THIS_MODULE,
893 .open = ip_vs_conn_sync_open,
894 .read = seq_read,
895 .llseek = seq_lseek,
896 .release = seq_release,
897};
898
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899#endif
900
901
902/*
903 * Randomly drop connection entries before running out of memory
904 */
905static inline int todrop_entry(struct ip_vs_conn *cp)
906{
907 /*
908 * The drop rate array needs tuning for real environments.
909 * Called from timer bh only => no locking
910 */
Arjan van de Ven9b5b5cf2005-11-29 16:21:38 -0800911 static const char todrop_rate[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 static char todrop_counter[9] = {0};
913 int i;
914
915 /* if the conn entry hasn't lasted for 60 seconds, don't drop it.
916 This will leave enough time for normal connection to get
917 through. */
918 if (time_before(cp->timeout + jiffies, cp->timer.expires + 60*HZ))
919 return 0;
920
921 /* Don't drop the entry if its number of incoming packets is not
922 located in [0, 8] */
923 i = atomic_read(&cp->in_pkts);
924 if (i > 8 || i < 0) return 0;
925
926 if (!todrop_rate[i]) return 0;
927 if (--todrop_counter[i] > 0) return 0;
928
929 todrop_counter[i] = todrop_rate[i];
930 return 1;
931}
932
Julian Anastasovaf9debd2005-07-11 20:59:57 -0700933/* Called from keventd and must protect itself from softirqs */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934void ip_vs_random_dropentry(void)
935{
936 int idx;
937 struct ip_vs_conn *cp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
939 /*
940 * Randomly scan 1/32 of the whole table every second
941 */
942 for (idx = 0; idx < (IP_VS_CONN_TAB_SIZE>>5); idx++) {
943 unsigned hash = net_random() & IP_VS_CONN_TAB_MASK;
944
945 /*
946 * Lock is actually needed in this loop.
947 */
Julian Anastasovaf9debd2005-07-11 20:59:57 -0700948 ct_write_lock_bh(hash);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
950 list_for_each_entry(cp, &ip_vs_conn_tab[hash], c_list) {
Julian Anastasov87375ab2005-09-14 21:08:51 -0700951 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 /* connection template */
953 continue;
954
955 if (cp->protocol == IPPROTO_TCP) {
956 switch(cp->state) {
957 case IP_VS_TCP_S_SYN_RECV:
958 case IP_VS_TCP_S_SYNACK:
959 break;
960
961 case IP_VS_TCP_S_ESTABLISHED:
962 if (todrop_entry(cp))
963 break;
964 continue;
965
966 default:
967 continue;
968 }
969 } else {
970 if (!todrop_entry(cp))
971 continue;
972 }
973
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 IP_VS_DBG(4, "del connection\n");
975 ip_vs_conn_expire_now(cp);
Neil Hormanfb3d8942005-06-28 15:40:02 -0700976 if (cp->control) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 IP_VS_DBG(4, "del conn template\n");
Neil Hormanfb3d8942005-06-28 15:40:02 -0700978 ip_vs_conn_expire_now(cp->control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 }
Julian Anastasovaf9debd2005-07-11 20:59:57 -0700981 ct_write_unlock_bh(hash);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 }
983}
984
985
986/*
987 * Flush all the connection entries in the ip_vs_conn_tab
988 */
989static void ip_vs_conn_flush(void)
990{
991 int idx;
992 struct ip_vs_conn *cp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993
994 flush_again:
995 for (idx=0; idx<IP_VS_CONN_TAB_SIZE; idx++) {
996 /*
997 * Lock is actually needed in this loop.
998 */
999 ct_write_lock_bh(idx);
1000
1001 list_for_each_entry(cp, &ip_vs_conn_tab[idx], c_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 IP_VS_DBG(4, "del connection\n");
1004 ip_vs_conn_expire_now(cp);
Neil Hormanfb3d8942005-06-28 15:40:02 -07001005 if (cp->control) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 IP_VS_DBG(4, "del conn template\n");
Neil Hormanfb3d8942005-06-28 15:40:02 -07001007 ip_vs_conn_expire_now(cp->control);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 }
1010 ct_write_unlock_bh(idx);
1011 }
1012
1013 /* the counter may be not NULL, because maybe some conn entries
1014 are run by slow timer handler or unhashed but still referred */
1015 if (atomic_read(&ip_vs_conn_count) != 0) {
1016 schedule();
1017 goto flush_again;
1018 }
1019}
1020
1021
Sven Wegener048cf482008-08-10 18:24:35 +00001022int __init ip_vs_conn_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023{
1024 int idx;
1025
1026 /*
1027 * Allocate the connection hash table and initialize its list heads
1028 */
1029 ip_vs_conn_tab = vmalloc(IP_VS_CONN_TAB_SIZE*sizeof(struct list_head));
1030 if (!ip_vs_conn_tab)
1031 return -ENOMEM;
1032
1033 /* Allocate ip_vs_conn slab cache */
1034 ip_vs_conn_cachep = kmem_cache_create("ip_vs_conn",
1035 sizeof(struct ip_vs_conn), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09001036 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 if (!ip_vs_conn_cachep) {
1038 vfree(ip_vs_conn_tab);
1039 return -ENOMEM;
1040 }
1041
1042 IP_VS_INFO("Connection hash table configured "
1043 "(size=%d, memory=%ldKbytes)\n",
1044 IP_VS_CONN_TAB_SIZE,
1045 (long)(IP_VS_CONN_TAB_SIZE*sizeof(struct list_head))/1024);
1046 IP_VS_DBG(0, "Each connection entry needs %Zd bytes at least\n",
1047 sizeof(struct ip_vs_conn));
1048
1049 for (idx = 0; idx < IP_VS_CONN_TAB_SIZE; idx++) {
1050 INIT_LIST_HEAD(&ip_vs_conn_tab[idx]);
1051 }
1052
1053 for (idx = 0; idx < CT_LOCKARRAY_SIZE; idx++) {
1054 rwlock_init(&__ip_vs_conntbl_lock_array[idx].l);
1055 }
1056
Eric W. Biederman457c4cb2007-09-12 12:01:34 +02001057 proc_net_fops_create(&init_net, "ip_vs_conn", 0, &ip_vs_conn_fops);
Rumen G. Bogdanovski7a4fbb12007-11-19 21:52:42 -08001058 proc_net_fops_create(&init_net, "ip_vs_conn_sync", 0, &ip_vs_conn_sync_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059
1060 /* calculate the random value for connection hash */
1061 get_random_bytes(&ip_vs_conn_rnd, sizeof(ip_vs_conn_rnd));
1062
1063 return 0;
1064}
1065
1066
1067void ip_vs_conn_cleanup(void)
1068{
1069 /* flush all the connection entries first */
1070 ip_vs_conn_flush();
1071
1072 /* Release the empty cache */
1073 kmem_cache_destroy(ip_vs_conn_cachep);
Eric W. Biederman457c4cb2007-09-12 12:01:34 +02001074 proc_net_remove(&init_net, "ip_vs_conn");
Rumen G. Bogdanovski7a4fbb12007-11-19 21:52:42 -08001075 proc_net_remove(&init_net, "ip_vs_conn_sync");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 vfree(ip_vs_conn_tab);
1077}