2 * ip_vs_proto_tcp.c: TCP load balancing support for IPVS
4 * Authors: Wensong Zhang <wensong@linuxvirtualserver.org>
5 * Julian Anastasov <ja@ssi.bg>
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.
16 #define KMSG_COMPONENT "IPVS"
17 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
19 #include <linux/kernel.h>
21 #include <linux/tcp.h> /* for tcphdr */
23 #include <net/tcp.h> /* for csum_tcpudp_magic */
24 #include <net/ip6_checksum.h>
25 #include <linux/netfilter.h>
26 #include <linux/netfilter_ipv4.h>
28 #include <net/ip_vs.h>
31 static struct ip_vs_conn
*
32 tcp_conn_in_get(int af
, const struct sk_buff
*skb
, struct ip_vs_protocol
*pp
,
33 const struct ip_vs_iphdr
*iph
, unsigned int proto_off
,
36 __be16 _ports
[2], *pptr
;
38 pptr
= skb_header_pointer(skb
, proto_off
, sizeof(_ports
), _ports
);
42 if (likely(!inverse
)) {
43 return ip_vs_conn_in_get(af
, iph
->protocol
,
45 &iph
->daddr
, pptr
[1]);
47 return ip_vs_conn_in_get(af
, iph
->protocol
,
49 &iph
->saddr
, pptr
[0]);
53 static struct ip_vs_conn
*
54 tcp_conn_out_get(int af
, const struct sk_buff
*skb
, struct ip_vs_protocol
*pp
,
55 const struct ip_vs_iphdr
*iph
, unsigned int proto_off
,
58 __be16 _ports
[2], *pptr
;
60 pptr
= skb_header_pointer(skb
, proto_off
, sizeof(_ports
), _ports
);
64 if (likely(!inverse
)) {
65 return ip_vs_conn_out_get(af
, iph
->protocol
,
67 &iph
->daddr
, pptr
[1]);
69 return ip_vs_conn_out_get(af
, iph
->protocol
,
71 &iph
->saddr
, pptr
[0]);
77 tcp_conn_schedule(int af
, struct sk_buff
*skb
, struct ip_vs_protocol
*pp
,
78 int *verdict
, struct ip_vs_conn
**cpp
)
80 struct ip_vs_service
*svc
;
81 struct tcphdr _tcph
, *th
;
82 struct ip_vs_iphdr iph
;
84 ip_vs_fill_iphdr(af
, skb_network_header(skb
), &iph
);
86 th
= skb_header_pointer(skb
, iph
.len
, sizeof(_tcph
), &_tcph
);
93 (svc
= ip_vs_service_get(af
, skb
->mark
, iph
.protocol
, &iph
.daddr
,
97 * It seems that we are very loaded.
98 * We have to drop this packet :(
100 ip_vs_service_put(svc
);
106 * Let the virtual server select a real server for the
107 * incoming connection, and create a connection entry.
109 *cpp
= ip_vs_schedule(svc
, skb
);
111 *verdict
= ip_vs_leave(svc
, skb
, pp
);
114 ip_vs_service_put(svc
);
121 tcp_fast_csum_update(int af
, struct tcphdr
*tcph
,
122 const union nf_inet_addr
*oldip
,
123 const union nf_inet_addr
*newip
,
124 __be16 oldport
, __be16 newport
)
126 #ifdef CONFIG_IP_VS_IPV6
129 csum_fold(ip_vs_check_diff16(oldip
->ip6
, newip
->ip6
,
130 ip_vs_check_diff2(oldport
, newport
,
131 ~csum_unfold(tcph
->check
))));
135 csum_fold(ip_vs_check_diff4(oldip
->ip
, newip
->ip
,
136 ip_vs_check_diff2(oldport
, newport
,
137 ~csum_unfold(tcph
->check
))));
142 tcp_partial_csum_update(int af
, struct tcphdr
*tcph
,
143 const union nf_inet_addr
*oldip
,
144 const union nf_inet_addr
*newip
,
145 __be16 oldlen
, __be16 newlen
)
147 #ifdef CONFIG_IP_VS_IPV6
150 csum_fold(ip_vs_check_diff16(oldip
->ip6
, newip
->ip6
,
151 ip_vs_check_diff2(oldlen
, newlen
,
152 ~csum_unfold(tcph
->check
))));
156 csum_fold(ip_vs_check_diff4(oldip
->ip
, newip
->ip
,
157 ip_vs_check_diff2(oldlen
, newlen
,
158 ~csum_unfold(tcph
->check
))));
163 tcp_snat_handler(struct sk_buff
*skb
,
164 struct ip_vs_protocol
*pp
, struct ip_vs_conn
*cp
)
167 unsigned int tcphoff
;
170 #ifdef CONFIG_IP_VS_IPV6
171 if (cp
->af
== AF_INET6
)
172 tcphoff
= sizeof(struct ipv6hdr
);
175 tcphoff
= ip_hdrlen(skb
);
176 oldlen
= skb
->len
- tcphoff
;
178 /* csum_check requires unshared skb */
179 if (!skb_make_writable(skb
, tcphoff
+sizeof(*tcph
)))
182 if (unlikely(cp
->app
!= NULL
)) {
183 /* Some checks before mangling */
184 if (pp
->csum_check
&& !pp
->csum_check(cp
->af
, skb
, pp
))
187 /* Call application helper if needed */
188 if (!ip_vs_app_pkt_out(cp
, skb
))
192 tcph
= (void *)skb_network_header(skb
) + tcphoff
;
193 tcph
->source
= cp
->vport
;
195 /* Adjust TCP checksums */
196 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
197 tcp_partial_csum_update(cp
->af
, tcph
, &cp
->daddr
, &cp
->vaddr
,
199 htons(skb
->len
- tcphoff
));
200 } else if (!cp
->app
) {
201 /* Only port and addr are changed, do fast csum update */
202 tcp_fast_csum_update(cp
->af
, tcph
, &cp
->daddr
, &cp
->vaddr
,
203 cp
->dport
, cp
->vport
);
204 if (skb
->ip_summed
== CHECKSUM_COMPLETE
)
205 skb
->ip_summed
= CHECKSUM_NONE
;
207 /* full checksum calculation */
209 skb
->csum
= skb_checksum(skb
, tcphoff
, skb
->len
- tcphoff
, 0);
210 #ifdef CONFIG_IP_VS_IPV6
211 if (cp
->af
== AF_INET6
)
212 tcph
->check
= csum_ipv6_magic(&cp
->vaddr
.in6
,
215 cp
->protocol
, skb
->csum
);
218 tcph
->check
= csum_tcpudp_magic(cp
->vaddr
.ip
,
224 IP_VS_DBG(11, "O-pkt: %s O-csum=%d (+%zd)\n",
225 pp
->name
, tcph
->check
,
226 (char*)&(tcph
->check
) - (char*)tcph
);
233 tcp_dnat_handler(struct sk_buff
*skb
,
234 struct ip_vs_protocol
*pp
, struct ip_vs_conn
*cp
)
237 unsigned int tcphoff
;
240 #ifdef CONFIG_IP_VS_IPV6
241 if (cp
->af
== AF_INET6
)
242 tcphoff
= sizeof(struct ipv6hdr
);
245 tcphoff
= ip_hdrlen(skb
);
246 oldlen
= skb
->len
- tcphoff
;
248 /* csum_check requires unshared skb */
249 if (!skb_make_writable(skb
, tcphoff
+sizeof(*tcph
)))
252 if (unlikely(cp
->app
!= NULL
)) {
253 /* Some checks before mangling */
254 if (pp
->csum_check
&& !pp
->csum_check(cp
->af
, skb
, pp
))
258 * Attempt ip_vs_app call.
259 * It will fix ip_vs_conn and iph ack_seq stuff
261 if (!ip_vs_app_pkt_in(cp
, skb
))
265 tcph
= (void *)skb_network_header(skb
) + tcphoff
;
266 tcph
->dest
= cp
->dport
;
269 * Adjust TCP checksums
271 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
272 tcp_partial_csum_update(cp
->af
, tcph
, &cp
->daddr
, &cp
->vaddr
,
274 htons(skb
->len
- tcphoff
));
275 } else if (!cp
->app
) {
276 /* Only port and addr are changed, do fast csum update */
277 tcp_fast_csum_update(cp
->af
, tcph
, &cp
->vaddr
, &cp
->daddr
,
278 cp
->vport
, cp
->dport
);
279 if (skb
->ip_summed
== CHECKSUM_COMPLETE
)
280 skb
->ip_summed
= CHECKSUM_NONE
;
282 /* full checksum calculation */
284 skb
->csum
= skb_checksum(skb
, tcphoff
, skb
->len
- tcphoff
, 0);
285 #ifdef CONFIG_IP_VS_IPV6
286 if (cp
->af
== AF_INET6
)
287 tcph
->check
= csum_ipv6_magic(&cp
->caddr
.in6
,
290 cp
->protocol
, skb
->csum
);
293 tcph
->check
= csum_tcpudp_magic(cp
->caddr
.ip
,
298 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
305 tcp_csum_check(int af
, struct sk_buff
*skb
, struct ip_vs_protocol
*pp
)
307 unsigned int tcphoff
;
309 #ifdef CONFIG_IP_VS_IPV6
311 tcphoff
= sizeof(struct ipv6hdr
);
314 tcphoff
= ip_hdrlen(skb
);
316 switch (skb
->ip_summed
) {
318 skb
->csum
= skb_checksum(skb
, tcphoff
, skb
->len
- tcphoff
, 0);
319 case CHECKSUM_COMPLETE
:
320 #ifdef CONFIG_IP_VS_IPV6
321 if (af
== AF_INET6
) {
322 if (csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
323 &ipv6_hdr(skb
)->daddr
,
325 ipv6_hdr(skb
)->nexthdr
,
327 IP_VS_DBG_RL_PKT(0, pp
, skb
, 0,
328 "Failed checksum for");
333 if (csum_tcpudp_magic(ip_hdr(skb
)->saddr
,
336 ip_hdr(skb
)->protocol
,
338 IP_VS_DBG_RL_PKT(0, pp
, skb
, 0,
339 "Failed checksum for");
344 /* No need to checksum. */
352 #define TCP_DIR_INPUT 0
353 #define TCP_DIR_OUTPUT 4
354 #define TCP_DIR_INPUT_ONLY 8
356 static const int tcp_state_off
[IP_VS_DIR_LAST
] = {
357 [IP_VS_DIR_INPUT
] = TCP_DIR_INPUT
,
358 [IP_VS_DIR_OUTPUT
] = TCP_DIR_OUTPUT
,
359 [IP_VS_DIR_INPUT_ONLY
] = TCP_DIR_INPUT_ONLY
,
363 * Timeout table[state]
365 static int tcp_timeouts
[IP_VS_TCP_S_LAST
+1] = {
366 [IP_VS_TCP_S_NONE
] = 2*HZ
,
367 [IP_VS_TCP_S_ESTABLISHED
] = 15*60*HZ
,
368 [IP_VS_TCP_S_SYN_SENT
] = 2*60*HZ
,
369 [IP_VS_TCP_S_SYN_RECV
] = 1*60*HZ
,
370 [IP_VS_TCP_S_FIN_WAIT
] = 2*60*HZ
,
371 [IP_VS_TCP_S_TIME_WAIT
] = 2*60*HZ
,
372 [IP_VS_TCP_S_CLOSE
] = 10*HZ
,
373 [IP_VS_TCP_S_CLOSE_WAIT
] = 60*HZ
,
374 [IP_VS_TCP_S_LAST_ACK
] = 30*HZ
,
375 [IP_VS_TCP_S_LISTEN
] = 2*60*HZ
,
376 [IP_VS_TCP_S_SYNACK
] = 120*HZ
,
377 [IP_VS_TCP_S_LAST
] = 2*HZ
,
380 static const char *const tcp_state_name_table
[IP_VS_TCP_S_LAST
+1] = {
381 [IP_VS_TCP_S_NONE
] = "NONE",
382 [IP_VS_TCP_S_ESTABLISHED
] = "ESTABLISHED",
383 [IP_VS_TCP_S_SYN_SENT
] = "SYN_SENT",
384 [IP_VS_TCP_S_SYN_RECV
] = "SYN_RECV",
385 [IP_VS_TCP_S_FIN_WAIT
] = "FIN_WAIT",
386 [IP_VS_TCP_S_TIME_WAIT
] = "TIME_WAIT",
387 [IP_VS_TCP_S_CLOSE
] = "CLOSE",
388 [IP_VS_TCP_S_CLOSE_WAIT
] = "CLOSE_WAIT",
389 [IP_VS_TCP_S_LAST_ACK
] = "LAST_ACK",
390 [IP_VS_TCP_S_LISTEN
] = "LISTEN",
391 [IP_VS_TCP_S_SYNACK
] = "SYNACK",
392 [IP_VS_TCP_S_LAST
] = "BUG!",
395 #define sNO IP_VS_TCP_S_NONE
396 #define sES IP_VS_TCP_S_ESTABLISHED
397 #define sSS IP_VS_TCP_S_SYN_SENT
398 #define sSR IP_VS_TCP_S_SYN_RECV
399 #define sFW IP_VS_TCP_S_FIN_WAIT
400 #define sTW IP_VS_TCP_S_TIME_WAIT
401 #define sCL IP_VS_TCP_S_CLOSE
402 #define sCW IP_VS_TCP_S_CLOSE_WAIT
403 #define sLA IP_VS_TCP_S_LAST_ACK
404 #define sLI IP_VS_TCP_S_LISTEN
405 #define sSA IP_VS_TCP_S_SYNACK
407 struct tcp_states_t
{
408 int next_state
[IP_VS_TCP_S_LAST
];
411 static const char * tcp_state_name(int state
)
413 if (state
>= IP_VS_TCP_S_LAST
)
415 return tcp_state_name_table
[state
] ? tcp_state_name_table
[state
] : "?";
418 static struct tcp_states_t tcp_states
[] = {
420 /* sNO, sES, sSS, sSR, sFW, sTW, sCL, sCW, sLA, sLI, sSA */
421 /*syn*/ {{sSR
, sES
, sES
, sSR
, sSR
, sSR
, sSR
, sSR
, sSR
, sSR
, sSR
}},
422 /*fin*/ {{sCL
, sCW
, sSS
, sTW
, sTW
, sTW
, sCL
, sCW
, sLA
, sLI
, sTW
}},
423 /*ack*/ {{sCL
, sES
, sSS
, sES
, sFW
, sTW
, sCL
, sCW
, sCL
, sLI
, sES
}},
424 /*rst*/ {{sCL
, sCL
, sCL
, sSR
, sCL
, sCL
, sCL
, sCL
, sLA
, sLI
, sSR
}},
427 /* sNO, sES, sSS, sSR, sFW, sTW, sCL, sCW, sLA, sLI, sSA */
428 /*syn*/ {{sSS
, sES
, sSS
, sSR
, sSS
, sSS
, sSS
, sSS
, sSS
, sLI
, sSR
}},
429 /*fin*/ {{sTW
, sFW
, sSS
, sTW
, sFW
, sTW
, sCL
, sTW
, sLA
, sLI
, sTW
}},
430 /*ack*/ {{sES
, sES
, sSS
, sES
, sFW
, sTW
, sCL
, sCW
, sLA
, sES
, sES
}},
431 /*rst*/ {{sCL
, sCL
, sSS
, sCL
, sCL
, sTW
, sCL
, sCL
, sCL
, sCL
, sCL
}},
434 /* sNO, sES, sSS, sSR, sFW, sTW, sCL, sCW, sLA, sLI, sSA */
435 /*syn*/ {{sSR
, sES
, sES
, sSR
, sSR
, sSR
, sSR
, sSR
, sSR
, sSR
, sSR
}},
436 /*fin*/ {{sCL
, sFW
, sSS
, sTW
, sFW
, sTW
, sCL
, sCW
, sLA
, sLI
, sTW
}},
437 /*ack*/ {{sCL
, sES
, sSS
, sES
, sFW
, sTW
, sCL
, sCW
, sCL
, sLI
, sES
}},
438 /*rst*/ {{sCL
, sCL
, sCL
, sSR
, sCL
, sCL
, sCL
, sCL
, sLA
, sLI
, sCL
}},
441 static struct tcp_states_t tcp_states_dos
[] = {
443 /* sNO, sES, sSS, sSR, sFW, sTW, sCL, sCW, sLA, sLI, sSA */
444 /*syn*/ {{sSR
, sES
, sES
, sSR
, sSR
, sSR
, sSR
, sSR
, sSR
, sSR
, sSA
}},
445 /*fin*/ {{sCL
, sCW
, sSS
, sTW
, sTW
, sTW
, sCL
, sCW
, sLA
, sLI
, sSA
}},
446 /*ack*/ {{sCL
, sES
, sSS
, sSR
, sFW
, sTW
, sCL
, sCW
, sCL
, sLI
, sSA
}},
447 /*rst*/ {{sCL
, sCL
, sCL
, sSR
, sCL
, sCL
, sCL
, sCL
, sLA
, sLI
, sCL
}},
450 /* sNO, sES, sSS, sSR, sFW, sTW, sCL, sCW, sLA, sLI, sSA */
451 /*syn*/ {{sSS
, sES
, sSS
, sSA
, sSS
, sSS
, sSS
, sSS
, sSS
, sLI
, sSA
}},
452 /*fin*/ {{sTW
, sFW
, sSS
, sTW
, sFW
, sTW
, sCL
, sTW
, sLA
, sLI
, sTW
}},
453 /*ack*/ {{sES
, sES
, sSS
, sES
, sFW
, sTW
, sCL
, sCW
, sLA
, sES
, sES
}},
454 /*rst*/ {{sCL
, sCL
, sSS
, sCL
, sCL
, sTW
, sCL
, sCL
, sCL
, sCL
, sCL
}},
457 /* sNO, sES, sSS, sSR, sFW, sTW, sCL, sCW, sLA, sLI, sSA */
458 /*syn*/ {{sSA
, sES
, sES
, sSR
, sSA
, sSA
, sSA
, sSA
, sSA
, sSA
, sSA
}},
459 /*fin*/ {{sCL
, sFW
, sSS
, sTW
, sFW
, sTW
, sCL
, sCW
, sLA
, sLI
, sTW
}},
460 /*ack*/ {{sCL
, sES
, sSS
, sES
, sFW
, sTW
, sCL
, sCW
, sCL
, sLI
, sES
}},
461 /*rst*/ {{sCL
, sCL
, sCL
, sSR
, sCL
, sCL
, sCL
, sCL
, sLA
, sLI
, sCL
}},
464 static struct tcp_states_t
*tcp_state_table
= tcp_states
;
467 static void tcp_timeout_change(struct ip_vs_protocol
*pp
, int flags
)
469 int on
= (flags
& 1); /* secure_tcp */
472 ** FIXME: change secure_tcp to independent sysctl var
473 ** or make it per-service or per-app because it is valid
474 ** for most if not for all of the applications. Something
475 ** like "capabilities" (flags) for each object.
477 tcp_state_table
= (on
? tcp_states_dos
: tcp_states
);
481 tcp_set_state_timeout(struct ip_vs_protocol
*pp
, char *sname
, int to
)
483 return ip_vs_set_state_timeout(pp
->timeout_table
, IP_VS_TCP_S_LAST
,
484 tcp_state_name_table
, sname
, to
);
487 static inline int tcp_state_idx(struct tcphdr
*th
)
501 set_tcp_state(struct ip_vs_protocol
*pp
, struct ip_vs_conn
*cp
,
502 int direction
, struct tcphdr
*th
)
505 int new_state
= IP_VS_TCP_S_CLOSE
;
506 int state_off
= tcp_state_off
[direction
];
509 * Update state offset to INPUT_ONLY if necessary
510 * or delete NO_OUTPUT flag if output packet detected
512 if (cp
->flags
& IP_VS_CONN_F_NOOUTPUT
) {
513 if (state_off
== TCP_DIR_OUTPUT
)
514 cp
->flags
&= ~IP_VS_CONN_F_NOOUTPUT
;
516 state_off
= TCP_DIR_INPUT_ONLY
;
519 if ((state_idx
= tcp_state_idx(th
)) < 0) {
520 IP_VS_DBG(8, "tcp_state_idx=%d!!!\n", state_idx
);
524 new_state
= tcp_state_table
[state_off
+state_idx
].next_state
[cp
->state
];
527 if (new_state
!= cp
->state
) {
528 struct ip_vs_dest
*dest
= cp
->dest
;
530 IP_VS_DBG_BUF(8, "%s %s [%c%c%c%c] %s:%d->"
531 "%s:%d state: %s->%s conn->refcnt:%d\n",
533 ((state_off
== TCP_DIR_OUTPUT
) ?
534 "output " : "input "),
539 IP_VS_DBG_ADDR(cp
->af
, &cp
->daddr
),
541 IP_VS_DBG_ADDR(cp
->af
, &cp
->caddr
),
543 tcp_state_name(cp
->state
),
544 tcp_state_name(new_state
),
545 atomic_read(&cp
->refcnt
));
548 if (!(cp
->flags
& IP_VS_CONN_F_INACTIVE
) &&
549 (new_state
!= IP_VS_TCP_S_ESTABLISHED
)) {
550 atomic_dec(&dest
->activeconns
);
551 atomic_inc(&dest
->inactconns
);
552 cp
->flags
|= IP_VS_CONN_F_INACTIVE
;
553 } else if ((cp
->flags
& IP_VS_CONN_F_INACTIVE
) &&
554 (new_state
== IP_VS_TCP_S_ESTABLISHED
)) {
555 atomic_inc(&dest
->activeconns
);
556 atomic_dec(&dest
->inactconns
);
557 cp
->flags
&= ~IP_VS_CONN_F_INACTIVE
;
562 cp
->timeout
= pp
->timeout_table
[cp
->state
= new_state
];
567 * Handle state transitions
570 tcp_state_transition(struct ip_vs_conn
*cp
, int direction
,
571 const struct sk_buff
*skb
,
572 struct ip_vs_protocol
*pp
)
574 struct tcphdr _tcph
, *th
;
576 #ifdef CONFIG_IP_VS_IPV6
577 int ihl
= cp
->af
== AF_INET
? ip_hdrlen(skb
) : sizeof(struct ipv6hdr
);
579 int ihl
= ip_hdrlen(skb
);
582 th
= skb_header_pointer(skb
, ihl
, sizeof(_tcph
), &_tcph
);
586 spin_lock(&cp
->lock
);
587 set_tcp_state(pp
, cp
, direction
, th
);
588 spin_unlock(&cp
->lock
);
595 * Hash table for TCP application incarnations
597 #define TCP_APP_TAB_BITS 4
598 #define TCP_APP_TAB_SIZE (1 << TCP_APP_TAB_BITS)
599 #define TCP_APP_TAB_MASK (TCP_APP_TAB_SIZE - 1)
601 static struct list_head tcp_apps
[TCP_APP_TAB_SIZE
];
602 static DEFINE_SPINLOCK(tcp_app_lock
);
604 static inline __u16
tcp_app_hashkey(__be16 port
)
606 return (((__force u16
)port
>> TCP_APP_TAB_BITS
) ^ (__force u16
)port
)
611 static int tcp_register_app(struct ip_vs_app
*inc
)
615 __be16 port
= inc
->port
;
618 hash
= tcp_app_hashkey(port
);
620 spin_lock_bh(&tcp_app_lock
);
621 list_for_each_entry(i
, &tcp_apps
[hash
], p_list
) {
622 if (i
->port
== port
) {
627 list_add(&inc
->p_list
, &tcp_apps
[hash
]);
628 atomic_inc(&ip_vs_protocol_tcp
.appcnt
);
631 spin_unlock_bh(&tcp_app_lock
);
637 tcp_unregister_app(struct ip_vs_app
*inc
)
639 spin_lock_bh(&tcp_app_lock
);
640 atomic_dec(&ip_vs_protocol_tcp
.appcnt
);
641 list_del(&inc
->p_list
);
642 spin_unlock_bh(&tcp_app_lock
);
647 tcp_app_conn_bind(struct ip_vs_conn
*cp
)
650 struct ip_vs_app
*inc
;
653 /* Default binding: bind app only for NAT */
654 if (IP_VS_FWD_METHOD(cp
) != IP_VS_CONN_F_MASQ
)
657 /* Lookup application incarnations and bind the right one */
658 hash
= tcp_app_hashkey(cp
->vport
);
660 spin_lock(&tcp_app_lock
);
661 list_for_each_entry(inc
, &tcp_apps
[hash
], p_list
) {
662 if (inc
->port
== cp
->vport
) {
663 if (unlikely(!ip_vs_app_inc_get(inc
)))
665 spin_unlock(&tcp_app_lock
);
667 IP_VS_DBG_BUF(9, "%s(): Binding conn %s:%u->"
668 "%s:%u to app %s on port %u\n",
670 IP_VS_DBG_ADDR(cp
->af
, &cp
->caddr
),
672 IP_VS_DBG_ADDR(cp
->af
, &cp
->vaddr
),
674 inc
->name
, ntohs(inc
->port
));
678 result
= inc
->init_conn(inc
, cp
);
682 spin_unlock(&tcp_app_lock
);
690 * Set LISTEN timeout. (ip_vs_conn_put will setup timer)
692 void ip_vs_tcp_conn_listen(struct ip_vs_conn
*cp
)
694 spin_lock(&cp
->lock
);
695 cp
->state
= IP_VS_TCP_S_LISTEN
;
696 cp
->timeout
= ip_vs_protocol_tcp
.timeout_table
[IP_VS_TCP_S_LISTEN
];
697 spin_unlock(&cp
->lock
);
701 static void ip_vs_tcp_init(struct ip_vs_protocol
*pp
)
703 IP_VS_INIT_HASH_TABLE(tcp_apps
);
704 pp
->timeout_table
= tcp_timeouts
;
708 static void ip_vs_tcp_exit(struct ip_vs_protocol
*pp
)
713 struct ip_vs_protocol ip_vs_protocol_tcp
= {
715 .protocol
= IPPROTO_TCP
,
716 .num_states
= IP_VS_TCP_S_LAST
,
718 .appcnt
= ATOMIC_INIT(0),
719 .init
= ip_vs_tcp_init
,
720 .exit
= ip_vs_tcp_exit
,
721 .register_app
= tcp_register_app
,
722 .unregister_app
= tcp_unregister_app
,
723 .conn_schedule
= tcp_conn_schedule
,
724 .conn_in_get
= tcp_conn_in_get
,
725 .conn_out_get
= tcp_conn_out_get
,
726 .snat_handler
= tcp_snat_handler
,
727 .dnat_handler
= tcp_dnat_handler
,
728 .csum_check
= tcp_csum_check
,
729 .state_name
= tcp_state_name
,
730 .state_transition
= tcp_state_transition
,
731 .app_conn_bind
= tcp_app_conn_bind
,
732 .debug_packet
= ip_vs_tcpudp_debug_packet
,
733 .timeout_change
= tcp_timeout_change
,
734 .set_state_timeout
= tcp_set_state_timeout
,