]> bbs.cooldavid.org Git - net-next-2.6.git/blob - net/ipv4/ipvs/ip_vs_proto_tcp.c
IPVS: Add v6 support to ip_vs_service_get()
[net-next-2.6.git] / net / ipv4 / ipvs / ip_vs_proto_tcp.c
1 /*
2  * ip_vs_proto_tcp.c:   TCP load balancing support for IPVS
3  *
4  * Authors:     Wensong Zhang <wensong@linuxvirtualserver.org>
5  *              Julian Anastasov <ja@ssi.bg>
6  *
7  *              This program is free software; you can redistribute it and/or
8  *              modify it under the terms of the GNU General Public License
9  *              as published by the Free Software Foundation; either version
10  *              2 of the License, or (at your option) any later version.
11  *
12  * Changes:
13  *
14  */
15
16 #include <linux/kernel.h>
17 #include <linux/ip.h>
18 #include <linux/tcp.h>                  /* for tcphdr */
19 #include <net/ip.h>
20 #include <net/tcp.h>                    /* for csum_tcpudp_magic */
21 #include <linux/netfilter.h>
22 #include <linux/netfilter_ipv4.h>
23
24 #include <net/ip_vs.h>
25
26
27 static struct ip_vs_conn *
28 tcp_conn_in_get(const struct sk_buff *skb, struct ip_vs_protocol *pp,
29                 const struct iphdr *iph, unsigned int proto_off, int inverse)
30 {
31         __be16 _ports[2], *pptr;
32
33         pptr = skb_header_pointer(skb, proto_off, sizeof(_ports), _ports);
34         if (pptr == NULL)
35                 return NULL;
36
37         if (likely(!inverse)) {
38                 return ip_vs_conn_in_get(iph->protocol,
39                                          iph->saddr, pptr[0],
40                                          iph->daddr, pptr[1]);
41         } else {
42                 return ip_vs_conn_in_get(iph->protocol,
43                                          iph->daddr, pptr[1],
44                                          iph->saddr, pptr[0]);
45         }
46 }
47
48 static struct ip_vs_conn *
49 tcp_conn_out_get(const struct sk_buff *skb, struct ip_vs_protocol *pp,
50                  const struct iphdr *iph, unsigned int proto_off, int inverse)
51 {
52         __be16 _ports[2], *pptr;
53
54         pptr = skb_header_pointer(skb, proto_off, sizeof(_ports), _ports);
55         if (pptr == NULL)
56                 return NULL;
57
58         if (likely(!inverse)) {
59                 return ip_vs_conn_out_get(iph->protocol,
60                                           iph->saddr, pptr[0],
61                                           iph->daddr, pptr[1]);
62         } else {
63                 return ip_vs_conn_out_get(iph->protocol,
64                                           iph->daddr, pptr[1],
65                                           iph->saddr, pptr[0]);
66         }
67 }
68
69
70 static int
71 tcp_conn_schedule(struct sk_buff *skb,
72                   struct ip_vs_protocol *pp,
73                   int *verdict, struct ip_vs_conn **cpp)
74 {
75         struct ip_vs_service *svc;
76         struct tcphdr _tcph, *th;
77         struct ip_vs_iphdr iph;
78
79         ip_vs_fill_iphdr(AF_INET, skb_network_header(skb), &iph);
80
81         th = skb_header_pointer(skb, iph.len, sizeof(_tcph), &_tcph);
82         if (th == NULL) {
83                 *verdict = NF_DROP;
84                 return 0;
85         }
86
87         if (th->syn &&
88             (svc = ip_vs_service_get(AF_INET, skb->mark, iph.protocol,
89                                      &iph.daddr, th->dest))) {
90                 if (ip_vs_todrop()) {
91                         /*
92                          * It seems that we are very loaded.
93                          * We have to drop this packet :(
94                          */
95                         ip_vs_service_put(svc);
96                         *verdict = NF_DROP;
97                         return 0;
98                 }
99
100                 /*
101                  * Let the virtual server select a real server for the
102                  * incoming connection, and create a connection entry.
103                  */
104                 *cpp = ip_vs_schedule(svc, skb);
105                 if (!*cpp) {
106                         *verdict = ip_vs_leave(svc, skb, pp);
107                         return 0;
108                 }
109                 ip_vs_service_put(svc);
110         }
111         return 1;
112 }
113
114
115 static inline void
116 tcp_fast_csum_update(struct tcphdr *tcph, __be32 oldip, __be32 newip,
117                      __be16 oldport, __be16 newport)
118 {
119         tcph->check =
120                 csum_fold(ip_vs_check_diff4(oldip, newip,
121                                  ip_vs_check_diff2(oldport, newport,
122                                                 ~csum_unfold(tcph->check))));
123 }
124
125
126 static int
127 tcp_snat_handler(struct sk_buff *skb,
128                  struct ip_vs_protocol *pp, struct ip_vs_conn *cp)
129 {
130         struct tcphdr *tcph;
131         const unsigned int tcphoff = ip_hdrlen(skb);
132
133         /* csum_check requires unshared skb */
134         if (!skb_make_writable(skb, tcphoff+sizeof(*tcph)))
135                 return 0;
136
137         if (unlikely(cp->app != NULL)) {
138                 /* Some checks before mangling */
139                 if (pp->csum_check && !pp->csum_check(skb, pp))
140                         return 0;
141
142                 /* Call application helper if needed */
143                 if (!ip_vs_app_pkt_out(cp, skb))
144                         return 0;
145         }
146
147         tcph = (void *)ip_hdr(skb) + tcphoff;
148         tcph->source = cp->vport;
149
150         /* Adjust TCP checksums */
151         if (!cp->app) {
152                 /* Only port and addr are changed, do fast csum update */
153                 tcp_fast_csum_update(tcph, cp->daddr.ip, cp->vaddr.ip,
154                                      cp->dport, cp->vport);
155                 if (skb->ip_summed == CHECKSUM_COMPLETE)
156                         skb->ip_summed = CHECKSUM_NONE;
157         } else {
158                 /* full checksum calculation */
159                 tcph->check = 0;
160                 skb->csum = skb_checksum(skb, tcphoff, skb->len - tcphoff, 0);
161                 tcph->check = csum_tcpudp_magic(cp->vaddr.ip, cp->caddr.ip,
162                                                 skb->len - tcphoff,
163                                                 cp->protocol, skb->csum);
164                 IP_VS_DBG(11, "O-pkt: %s O-csum=%d (+%zd)\n",
165                           pp->name, tcph->check,
166                           (char*)&(tcph->check) - (char*)tcph);
167         }
168         return 1;
169 }
170
171
172 static int
173 tcp_dnat_handler(struct sk_buff *skb,
174                  struct ip_vs_protocol *pp, struct ip_vs_conn *cp)
175 {
176         struct tcphdr *tcph;
177         const unsigned int tcphoff = ip_hdrlen(skb);
178
179         /* csum_check requires unshared skb */
180         if (!skb_make_writable(skb, tcphoff+sizeof(*tcph)))
181                 return 0;
182
183         if (unlikely(cp->app != NULL)) {
184                 /* Some checks before mangling */
185                 if (pp->csum_check && !pp->csum_check(skb, pp))
186                         return 0;
187
188                 /*
189                  *      Attempt ip_vs_app call.
190                  *      It will fix ip_vs_conn and iph ack_seq stuff
191                  */
192                 if (!ip_vs_app_pkt_in(cp, skb))
193                         return 0;
194         }
195
196         tcph = (void *)ip_hdr(skb) + tcphoff;
197         tcph->dest = cp->dport;
198
199         /*
200          *      Adjust TCP checksums
201          */
202         if (!cp->app) {
203                 /* Only port and addr are changed, do fast csum update */
204                 tcp_fast_csum_update(tcph, cp->vaddr.ip, cp->daddr.ip,
205                                      cp->vport, cp->dport);
206                 if (skb->ip_summed == CHECKSUM_COMPLETE)
207                         skb->ip_summed = CHECKSUM_NONE;
208         } else {
209                 /* full checksum calculation */
210                 tcph->check = 0;
211                 skb->csum = skb_checksum(skb, tcphoff, skb->len - tcphoff, 0);
212                 tcph->check = csum_tcpudp_magic(cp->caddr.ip, cp->daddr.ip,
213                                                 skb->len - tcphoff,
214                                                 cp->protocol, skb->csum);
215                 skb->ip_summed = CHECKSUM_UNNECESSARY;
216         }
217         return 1;
218 }
219
220
221 static int
222 tcp_csum_check(struct sk_buff *skb, struct ip_vs_protocol *pp)
223 {
224         const unsigned int tcphoff = ip_hdrlen(skb);
225
226         switch (skb->ip_summed) {
227         case CHECKSUM_NONE:
228                 skb->csum = skb_checksum(skb, tcphoff, skb->len - tcphoff, 0);
229         case CHECKSUM_COMPLETE:
230                 if (csum_tcpudp_magic(ip_hdr(skb)->saddr, ip_hdr(skb)->daddr,
231                                       skb->len - tcphoff,
232                                       ip_hdr(skb)->protocol, skb->csum)) {
233                         IP_VS_DBG_RL_PKT(0, pp, skb, 0,
234                                          "Failed checksum for");
235                         return 0;
236                 }
237                 break;
238         default:
239                 /* No need to checksum. */
240                 break;
241         }
242
243         return 1;
244 }
245
246
247 #define TCP_DIR_INPUT           0
248 #define TCP_DIR_OUTPUT          4
249 #define TCP_DIR_INPUT_ONLY      8
250
251 static const int tcp_state_off[IP_VS_DIR_LAST] = {
252         [IP_VS_DIR_INPUT]               =       TCP_DIR_INPUT,
253         [IP_VS_DIR_OUTPUT]              =       TCP_DIR_OUTPUT,
254         [IP_VS_DIR_INPUT_ONLY]          =       TCP_DIR_INPUT_ONLY,
255 };
256
257 /*
258  *      Timeout table[state]
259  */
260 static int tcp_timeouts[IP_VS_TCP_S_LAST+1] = {
261         [IP_VS_TCP_S_NONE]              =       2*HZ,
262         [IP_VS_TCP_S_ESTABLISHED]       =       15*60*HZ,
263         [IP_VS_TCP_S_SYN_SENT]          =       2*60*HZ,
264         [IP_VS_TCP_S_SYN_RECV]          =       1*60*HZ,
265         [IP_VS_TCP_S_FIN_WAIT]          =       2*60*HZ,
266         [IP_VS_TCP_S_TIME_WAIT]         =       2*60*HZ,
267         [IP_VS_TCP_S_CLOSE]             =       10*HZ,
268         [IP_VS_TCP_S_CLOSE_WAIT]        =       60*HZ,
269         [IP_VS_TCP_S_LAST_ACK]          =       30*HZ,
270         [IP_VS_TCP_S_LISTEN]            =       2*60*HZ,
271         [IP_VS_TCP_S_SYNACK]            =       120*HZ,
272         [IP_VS_TCP_S_LAST]              =       2*HZ,
273 };
274
275 static char * tcp_state_name_table[IP_VS_TCP_S_LAST+1] = {
276         [IP_VS_TCP_S_NONE]              =       "NONE",
277         [IP_VS_TCP_S_ESTABLISHED]       =       "ESTABLISHED",
278         [IP_VS_TCP_S_SYN_SENT]          =       "SYN_SENT",
279         [IP_VS_TCP_S_SYN_RECV]          =       "SYN_RECV",
280         [IP_VS_TCP_S_FIN_WAIT]          =       "FIN_WAIT",
281         [IP_VS_TCP_S_TIME_WAIT]         =       "TIME_WAIT",
282         [IP_VS_TCP_S_CLOSE]             =       "CLOSE",
283         [IP_VS_TCP_S_CLOSE_WAIT]        =       "CLOSE_WAIT",
284         [IP_VS_TCP_S_LAST_ACK]          =       "LAST_ACK",
285         [IP_VS_TCP_S_LISTEN]            =       "LISTEN",
286         [IP_VS_TCP_S_SYNACK]            =       "SYNACK",
287         [IP_VS_TCP_S_LAST]              =       "BUG!",
288 };
289
290 #define sNO IP_VS_TCP_S_NONE
291 #define sES IP_VS_TCP_S_ESTABLISHED
292 #define sSS IP_VS_TCP_S_SYN_SENT
293 #define sSR IP_VS_TCP_S_SYN_RECV
294 #define sFW IP_VS_TCP_S_FIN_WAIT
295 #define sTW IP_VS_TCP_S_TIME_WAIT
296 #define sCL IP_VS_TCP_S_CLOSE
297 #define sCW IP_VS_TCP_S_CLOSE_WAIT
298 #define sLA IP_VS_TCP_S_LAST_ACK
299 #define sLI IP_VS_TCP_S_LISTEN
300 #define sSA IP_VS_TCP_S_SYNACK
301
302 struct tcp_states_t {
303         int next_state[IP_VS_TCP_S_LAST];
304 };
305
306 static const char * tcp_state_name(int state)
307 {
308         if (state >= IP_VS_TCP_S_LAST)
309                 return "ERR!";
310         return tcp_state_name_table[state] ? tcp_state_name_table[state] : "?";
311 }
312
313 static struct tcp_states_t tcp_states [] = {
314 /*      INPUT */
315 /*        sNO, sES, sSS, sSR, sFW, sTW, sCL, sCW, sLA, sLI, sSA */
316 /*syn*/ {{sSR, sES, sES, sSR, sSR, sSR, sSR, sSR, sSR, sSR, sSR }},
317 /*fin*/ {{sCL, sCW, sSS, sTW, sTW, sTW, sCL, sCW, sLA, sLI, sTW }},
318 /*ack*/ {{sCL, sES, sSS, sES, sFW, sTW, sCL, sCW, sCL, sLI, sES }},
319 /*rst*/ {{sCL, sCL, sCL, sSR, sCL, sCL, sCL, sCL, sLA, sLI, sSR }},
320
321 /*      OUTPUT */
322 /*        sNO, sES, sSS, sSR, sFW, sTW, sCL, sCW, sLA, sLI, sSA */
323 /*syn*/ {{sSS, sES, sSS, sSR, sSS, sSS, sSS, sSS, sSS, sLI, sSR }},
324 /*fin*/ {{sTW, sFW, sSS, sTW, sFW, sTW, sCL, sTW, sLA, sLI, sTW }},
325 /*ack*/ {{sES, sES, sSS, sES, sFW, sTW, sCL, sCW, sLA, sES, sES }},
326 /*rst*/ {{sCL, sCL, sSS, sCL, sCL, sTW, sCL, sCL, sCL, sCL, sCL }},
327
328 /*      INPUT-ONLY */
329 /*        sNO, sES, sSS, sSR, sFW, sTW, sCL, sCW, sLA, sLI, sSA */
330 /*syn*/ {{sSR, sES, sES, sSR, sSR, sSR, sSR, sSR, sSR, sSR, sSR }},
331 /*fin*/ {{sCL, sFW, sSS, sTW, sFW, sTW, sCL, sCW, sLA, sLI, sTW }},
332 /*ack*/ {{sCL, sES, sSS, sES, sFW, sTW, sCL, sCW, sCL, sLI, sES }},
333 /*rst*/ {{sCL, sCL, sCL, sSR, sCL, sCL, sCL, sCL, sLA, sLI, sCL }},
334 };
335
336 static struct tcp_states_t tcp_states_dos [] = {
337 /*      INPUT */
338 /*        sNO, sES, sSS, sSR, sFW, sTW, sCL, sCW, sLA, sLI, sSA */
339 /*syn*/ {{sSR, sES, sES, sSR, sSR, sSR, sSR, sSR, sSR, sSR, sSA }},
340 /*fin*/ {{sCL, sCW, sSS, sTW, sTW, sTW, sCL, sCW, sLA, sLI, sSA }},
341 /*ack*/ {{sCL, sES, sSS, sSR, sFW, sTW, sCL, sCW, sCL, sLI, sSA }},
342 /*rst*/ {{sCL, sCL, sCL, sSR, sCL, sCL, sCL, sCL, sLA, sLI, sCL }},
343
344 /*      OUTPUT */
345 /*        sNO, sES, sSS, sSR, sFW, sTW, sCL, sCW, sLA, sLI, sSA */
346 /*syn*/ {{sSS, sES, sSS, sSA, sSS, sSS, sSS, sSS, sSS, sLI, sSA }},
347 /*fin*/ {{sTW, sFW, sSS, sTW, sFW, sTW, sCL, sTW, sLA, sLI, sTW }},
348 /*ack*/ {{sES, sES, sSS, sES, sFW, sTW, sCL, sCW, sLA, sES, sES }},
349 /*rst*/ {{sCL, sCL, sSS, sCL, sCL, sTW, sCL, sCL, sCL, sCL, sCL }},
350
351 /*      INPUT-ONLY */
352 /*        sNO, sES, sSS, sSR, sFW, sTW, sCL, sCW, sLA, sLI, sSA */
353 /*syn*/ {{sSA, sES, sES, sSR, sSA, sSA, sSA, sSA, sSA, sSA, sSA }},
354 /*fin*/ {{sCL, sFW, sSS, sTW, sFW, sTW, sCL, sCW, sLA, sLI, sTW }},
355 /*ack*/ {{sCL, sES, sSS, sES, sFW, sTW, sCL, sCW, sCL, sLI, sES }},
356 /*rst*/ {{sCL, sCL, sCL, sSR, sCL, sCL, sCL, sCL, sLA, sLI, sCL }},
357 };
358
359 static struct tcp_states_t *tcp_state_table = tcp_states;
360
361
362 static void tcp_timeout_change(struct ip_vs_protocol *pp, int flags)
363 {
364         int on = (flags & 1);           /* secure_tcp */
365
366         /*
367         ** FIXME: change secure_tcp to independent sysctl var
368         ** or make it per-service or per-app because it is valid
369         ** for most if not for all of the applications. Something
370         ** like "capabilities" (flags) for each object.
371         */
372         tcp_state_table = (on? tcp_states_dos : tcp_states);
373 }
374
375 static int
376 tcp_set_state_timeout(struct ip_vs_protocol *pp, char *sname, int to)
377 {
378         return ip_vs_set_state_timeout(pp->timeout_table, IP_VS_TCP_S_LAST,
379                                        tcp_state_name_table, sname, to);
380 }
381
382 static inline int tcp_state_idx(struct tcphdr *th)
383 {
384         if (th->rst)
385                 return 3;
386         if (th->syn)
387                 return 0;
388         if (th->fin)
389                 return 1;
390         if (th->ack)
391                 return 2;
392         return -1;
393 }
394
395 static inline void
396 set_tcp_state(struct ip_vs_protocol *pp, struct ip_vs_conn *cp,
397               int direction, struct tcphdr *th)
398 {
399         int state_idx;
400         int new_state = IP_VS_TCP_S_CLOSE;
401         int state_off = tcp_state_off[direction];
402
403         /*
404          *    Update state offset to INPUT_ONLY if necessary
405          *    or delete NO_OUTPUT flag if output packet detected
406          */
407         if (cp->flags & IP_VS_CONN_F_NOOUTPUT) {
408                 if (state_off == TCP_DIR_OUTPUT)
409                         cp->flags &= ~IP_VS_CONN_F_NOOUTPUT;
410                 else
411                         state_off = TCP_DIR_INPUT_ONLY;
412         }
413
414         if ((state_idx = tcp_state_idx(th)) < 0) {
415                 IP_VS_DBG(8, "tcp_state_idx=%d!!!\n", state_idx);
416                 goto tcp_state_out;
417         }
418
419         new_state = tcp_state_table[state_off+state_idx].next_state[cp->state];
420
421   tcp_state_out:
422         if (new_state != cp->state) {
423                 struct ip_vs_dest *dest = cp->dest;
424
425                 IP_VS_DBG(8, "%s %s [%c%c%c%c] %u.%u.%u.%u:%d->"
426                           "%u.%u.%u.%u:%d state: %s->%s conn->refcnt:%d\n",
427                           pp->name,
428                           (state_off==TCP_DIR_OUTPUT)?"output ":"input ",
429                           th->syn? 'S' : '.',
430                           th->fin? 'F' : '.',
431                           th->ack? 'A' : '.',
432                           th->rst? 'R' : '.',
433                           NIPQUAD(cp->daddr.ip), ntohs(cp->dport),
434                           NIPQUAD(cp->caddr.ip), ntohs(cp->cport),
435                           tcp_state_name(cp->state),
436                           tcp_state_name(new_state),
437                           atomic_read(&cp->refcnt));
438                 if (dest) {
439                         if (!(cp->flags & IP_VS_CONN_F_INACTIVE) &&
440                             (new_state != IP_VS_TCP_S_ESTABLISHED)) {
441                                 atomic_dec(&dest->activeconns);
442                                 atomic_inc(&dest->inactconns);
443                                 cp->flags |= IP_VS_CONN_F_INACTIVE;
444                         } else if ((cp->flags & IP_VS_CONN_F_INACTIVE) &&
445                                    (new_state == IP_VS_TCP_S_ESTABLISHED)) {
446                                 atomic_inc(&dest->activeconns);
447                                 atomic_dec(&dest->inactconns);
448                                 cp->flags &= ~IP_VS_CONN_F_INACTIVE;
449                         }
450                 }
451         }
452
453         cp->timeout = pp->timeout_table[cp->state = new_state];
454 }
455
456
457 /*
458  *      Handle state transitions
459  */
460 static int
461 tcp_state_transition(struct ip_vs_conn *cp, int direction,
462                      const struct sk_buff *skb,
463                      struct ip_vs_protocol *pp)
464 {
465         struct tcphdr _tcph, *th;
466
467         th = skb_header_pointer(skb, ip_hdrlen(skb), sizeof(_tcph), &_tcph);
468         if (th == NULL)
469                 return 0;
470
471         spin_lock(&cp->lock);
472         set_tcp_state(pp, cp, direction, th);
473         spin_unlock(&cp->lock);
474
475         return 1;
476 }
477
478
479 /*
480  *      Hash table for TCP application incarnations
481  */
482 #define TCP_APP_TAB_BITS        4
483 #define TCP_APP_TAB_SIZE        (1 << TCP_APP_TAB_BITS)
484 #define TCP_APP_TAB_MASK        (TCP_APP_TAB_SIZE - 1)
485
486 static struct list_head tcp_apps[TCP_APP_TAB_SIZE];
487 static DEFINE_SPINLOCK(tcp_app_lock);
488
489 static inline __u16 tcp_app_hashkey(__be16 port)
490 {
491         return (((__force u16)port >> TCP_APP_TAB_BITS) ^ (__force u16)port)
492                 & TCP_APP_TAB_MASK;
493 }
494
495
496 static int tcp_register_app(struct ip_vs_app *inc)
497 {
498         struct ip_vs_app *i;
499         __u16 hash;
500         __be16 port = inc->port;
501         int ret = 0;
502
503         hash = tcp_app_hashkey(port);
504
505         spin_lock_bh(&tcp_app_lock);
506         list_for_each_entry(i, &tcp_apps[hash], p_list) {
507                 if (i->port == port) {
508                         ret = -EEXIST;
509                         goto out;
510                 }
511         }
512         list_add(&inc->p_list, &tcp_apps[hash]);
513         atomic_inc(&ip_vs_protocol_tcp.appcnt);
514
515   out:
516         spin_unlock_bh(&tcp_app_lock);
517         return ret;
518 }
519
520
521 static void
522 tcp_unregister_app(struct ip_vs_app *inc)
523 {
524         spin_lock_bh(&tcp_app_lock);
525         atomic_dec(&ip_vs_protocol_tcp.appcnt);
526         list_del(&inc->p_list);
527         spin_unlock_bh(&tcp_app_lock);
528 }
529
530
531 static int
532 tcp_app_conn_bind(struct ip_vs_conn *cp)
533 {
534         int hash;
535         struct ip_vs_app *inc;
536         int result = 0;
537
538         /* Default binding: bind app only for NAT */
539         if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ)
540                 return 0;
541
542         /* Lookup application incarnations and bind the right one */
543         hash = tcp_app_hashkey(cp->vport);
544
545         spin_lock(&tcp_app_lock);
546         list_for_each_entry(inc, &tcp_apps[hash], p_list) {
547                 if (inc->port == cp->vport) {
548                         if (unlikely(!ip_vs_app_inc_get(inc)))
549                                 break;
550                         spin_unlock(&tcp_app_lock);
551
552                         IP_VS_DBG(9, "%s: Binding conn %u.%u.%u.%u:%u->"
553                                   "%u.%u.%u.%u:%u to app %s on port %u\n",
554                                   __func__,
555                                   NIPQUAD(cp->caddr.ip), ntohs(cp->cport),
556                                   NIPQUAD(cp->vaddr.ip), ntohs(cp->vport),
557                                   inc->name, ntohs(inc->port));
558                         cp->app = inc;
559                         if (inc->init_conn)
560                                 result = inc->init_conn(inc, cp);
561                         goto out;
562                 }
563         }
564         spin_unlock(&tcp_app_lock);
565
566   out:
567         return result;
568 }
569
570
571 /*
572  *      Set LISTEN timeout. (ip_vs_conn_put will setup timer)
573  */
574 void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp)
575 {
576         spin_lock(&cp->lock);
577         cp->state = IP_VS_TCP_S_LISTEN;
578         cp->timeout = ip_vs_protocol_tcp.timeout_table[IP_VS_TCP_S_LISTEN];
579         spin_unlock(&cp->lock);
580 }
581
582
583 static void ip_vs_tcp_init(struct ip_vs_protocol *pp)
584 {
585         IP_VS_INIT_HASH_TABLE(tcp_apps);
586         pp->timeout_table = tcp_timeouts;
587 }
588
589
590 static void ip_vs_tcp_exit(struct ip_vs_protocol *pp)
591 {
592 }
593
594
595 struct ip_vs_protocol ip_vs_protocol_tcp = {
596         .name =                 "TCP",
597         .protocol =             IPPROTO_TCP,
598         .num_states =           IP_VS_TCP_S_LAST,
599         .dont_defrag =          0,
600         .appcnt =               ATOMIC_INIT(0),
601         .init =                 ip_vs_tcp_init,
602         .exit =                 ip_vs_tcp_exit,
603         .register_app =         tcp_register_app,
604         .unregister_app =       tcp_unregister_app,
605         .conn_schedule =        tcp_conn_schedule,
606         .conn_in_get =          tcp_conn_in_get,
607         .conn_out_get =         tcp_conn_out_get,
608         .snat_handler =         tcp_snat_handler,
609         .dnat_handler =         tcp_dnat_handler,
610         .csum_check =           tcp_csum_check,
611         .state_name =           tcp_state_name,
612         .state_transition =     tcp_state_transition,
613         .app_conn_bind =        tcp_app_conn_bind,
614         .debug_packet =         ip_vs_tcpudp_debug_packet,
615         .timeout_change =       tcp_timeout_change,
616         .set_state_timeout =    tcp_set_state_timeout,
617 };