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.
12 * Changes: Hans Schillstrom <hans.schillstrom@ericsson.com>
14 * Network name space (netns) aware.
15 * Global data moved to netns i.e struct netns_ipvs
16 * tcp_timeouts table has copy per netns in a hash table per
17 * protocol ip_vs_proto_data and is handled by netns
20 #define KMSG_COMPONENT "IPVS"
21 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
23 #include <linux/kernel.h>
25 #include <linux/tcp.h> /* for tcphdr */
27 #include <net/tcp.h> /* for csum_tcpudp_magic */
28 #include <net/ip6_checksum.h>
29 #include <linux/netfilter.h>
30 #include <linux/netfilter_ipv4.h>
32 #include <net/ip_vs.h>
35 tcp_conn_schedule(int af
, struct sk_buff
*skb
, struct ip_vs_proto_data
*pd
,
36 int *verdict
, struct ip_vs_conn
**cpp
,
37 struct ip_vs_iphdr
*iph
)
40 struct ip_vs_service
*svc
;
41 struct tcphdr _tcph
, *th
;
42 struct netns_ipvs
*ipvs
;
43 __be16 _ports
[2], *ports
= NULL
;
48 /* In the event of icmp, we're only guaranteed to have the first 8
49 * bytes of the transport header, so we only check the rest of the
50 * TCP packet for non-ICMP packets
52 if (likely(!ip_vs_iph_icmp(iph
))) {
53 th
= skb_header_pointer(skb
, iph
->len
, sizeof(_tcph
), &_tcph
);
55 if (th
->rst
|| !(sysctl_sloppy_tcp(ipvs
) || th
->syn
))
60 ports
= skb_header_pointer(
61 skb
, iph
->len
, sizeof(_ports
), &_ports
);
69 /* No !th->ack check to allow scheduling on SYN+ACK for Active FTP */
72 if (likely(!ip_vs_iph_inverse(iph
)))
73 svc
= ip_vs_service_find(ipvs
, af
, skb
->mark
, iph
->protocol
,
74 &iph
->daddr
, ports
[1]);
76 svc
= ip_vs_service_find(ipvs
, af
, skb
->mark
, iph
->protocol
,
77 &iph
->saddr
, ports
[0]);
82 if (ip_vs_todrop(ipvs
)) {
84 * It seems that we are very loaded.
85 * We have to drop this packet :(
93 * Let the virtual server select a real server for the
94 * incoming connection, and create a connection entry.
96 *cpp
= ip_vs_schedule(svc
, skb
, pd
, &ignored
, iph
);
97 if (!*cpp
&& ignored
<= 0) {
99 *verdict
= ip_vs_leave(svc
, skb
, pd
, iph
);
113 tcp_fast_csum_update(int af
, struct tcphdr
*tcph
,
114 const union nf_inet_addr
*oldip
,
115 const union nf_inet_addr
*newip
,
116 __be16 oldport
, __be16 newport
)
118 #ifdef CONFIG_IP_VS_IPV6
121 csum_fold(ip_vs_check_diff16(oldip
->ip6
, newip
->ip6
,
122 ip_vs_check_diff2(oldport
, newport
,
123 ~csum_unfold(tcph
->check
))));
127 csum_fold(ip_vs_check_diff4(oldip
->ip
, newip
->ip
,
128 ip_vs_check_diff2(oldport
, newport
,
129 ~csum_unfold(tcph
->check
))));
134 tcp_partial_csum_update(int af
, struct tcphdr
*tcph
,
135 const union nf_inet_addr
*oldip
,
136 const union nf_inet_addr
*newip
,
137 __be16 oldlen
, __be16 newlen
)
139 #ifdef CONFIG_IP_VS_IPV6
142 ~csum_fold(ip_vs_check_diff16(oldip
->ip6
, newip
->ip6
,
143 ip_vs_check_diff2(oldlen
, newlen
,
144 csum_unfold(tcph
->check
))));
148 ~csum_fold(ip_vs_check_diff4(oldip
->ip
, newip
->ip
,
149 ip_vs_check_diff2(oldlen
, newlen
,
150 csum_unfold(tcph
->check
))));
155 tcp_snat_handler(struct sk_buff
*skb
, struct ip_vs_protocol
*pp
,
156 struct ip_vs_conn
*cp
, struct ip_vs_iphdr
*iph
)
159 unsigned int tcphoff
= iph
->len
;
161 int payload_csum
= 0;
163 #ifdef CONFIG_IP_VS_IPV6
164 if (cp
->af
== AF_INET6
&& iph
->fragoffs
)
167 oldlen
= skb
->len
- tcphoff
;
169 /* csum_check requires unshared skb */
170 if (!skb_make_writable(skb
, tcphoff
+sizeof(*tcph
)))
173 if (unlikely(cp
->app
!= NULL
)) {
176 /* Some checks before mangling */
177 if (pp
->csum_check
&& !pp
->csum_check(cp
->af
, skb
, pp
))
180 /* Call application helper if needed */
181 if (!(ret
= ip_vs_app_pkt_out(cp
, skb
)))
183 /* ret=2: csum update is needed after payload mangling */
185 oldlen
= skb
->len
- tcphoff
;
190 tcph
= (void *)skb_network_header(skb
) + tcphoff
;
191 tcph
->source
= cp
->vport
;
193 /* Adjust TCP checksums */
194 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
195 tcp_partial_csum_update(cp
->af
, tcph
, &cp
->daddr
, &cp
->vaddr
,
197 htons(skb
->len
- tcphoff
));
198 } else if (!payload_csum
) {
199 /* Only port and addr are changed, do fast csum update */
200 tcp_fast_csum_update(cp
->af
, tcph
, &cp
->daddr
, &cp
->vaddr
,
201 cp
->dport
, cp
->vport
);
202 if (skb
->ip_summed
== CHECKSUM_COMPLETE
)
203 skb
->ip_summed
= (cp
->app
&& pp
->csum_check
) ?
204 CHECKSUM_UNNECESSARY
: CHECKSUM_NONE
;
206 /* full checksum calculation */
208 skb
->csum
= skb_checksum(skb
, tcphoff
, skb
->len
- tcphoff
, 0);
209 #ifdef CONFIG_IP_VS_IPV6
210 if (cp
->af
== AF_INET6
)
211 tcph
->check
= csum_ipv6_magic(&cp
->vaddr
.in6
,
214 cp
->protocol
, skb
->csum
);
217 tcph
->check
= csum_tcpudp_magic(cp
->vaddr
.ip
,
222 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
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
, struct ip_vs_protocol
*pp
,
234 struct ip_vs_conn
*cp
, struct ip_vs_iphdr
*iph
)
237 unsigned int tcphoff
= iph
->len
;
239 int payload_csum
= 0;
241 #ifdef CONFIG_IP_VS_IPV6
242 if (cp
->af
== AF_INET6
&& iph
->fragoffs
)
245 oldlen
= skb
->len
- tcphoff
;
247 /* csum_check requires unshared skb */
248 if (!skb_make_writable(skb
, tcphoff
+sizeof(*tcph
)))
251 if (unlikely(cp
->app
!= NULL
)) {
254 /* Some checks before mangling */
255 if (pp
->csum_check
&& !pp
->csum_check(cp
->af
, skb
, pp
))
259 * Attempt ip_vs_app call.
260 * It will fix ip_vs_conn and iph ack_seq stuff
262 if (!(ret
= ip_vs_app_pkt_in(cp
, skb
)))
264 /* ret=2: csum update is needed after payload mangling */
266 oldlen
= skb
->len
- tcphoff
;
271 tcph
= (void *)skb_network_header(skb
) + tcphoff
;
272 tcph
->dest
= cp
->dport
;
275 * Adjust TCP checksums
277 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
278 tcp_partial_csum_update(cp
->af
, tcph
, &cp
->vaddr
, &cp
->daddr
,
280 htons(skb
->len
- tcphoff
));
281 } else if (!payload_csum
) {
282 /* Only port and addr are changed, do fast csum update */
283 tcp_fast_csum_update(cp
->af
, tcph
, &cp
->vaddr
, &cp
->daddr
,
284 cp
->vport
, cp
->dport
);
285 if (skb
->ip_summed
== CHECKSUM_COMPLETE
)
286 skb
->ip_summed
= (cp
->app
&& pp
->csum_check
) ?
287 CHECKSUM_UNNECESSARY
: CHECKSUM_NONE
;
289 /* full checksum calculation */
291 skb
->csum
= skb_checksum(skb
, tcphoff
, skb
->len
- tcphoff
, 0);
292 #ifdef CONFIG_IP_VS_IPV6
293 if (cp
->af
== AF_INET6
)
294 tcph
->check
= csum_ipv6_magic(&cp
->caddr
.in6
,
297 cp
->protocol
, skb
->csum
);
300 tcph
->check
= csum_tcpudp_magic(cp
->caddr
.ip
,
305 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
312 tcp_csum_check(int af
, struct sk_buff
*skb
, struct ip_vs_protocol
*pp
)
314 unsigned int tcphoff
;
316 #ifdef CONFIG_IP_VS_IPV6
318 tcphoff
= sizeof(struct ipv6hdr
);
321 tcphoff
= ip_hdrlen(skb
);
323 switch (skb
->ip_summed
) {
325 skb
->csum
= skb_checksum(skb
, tcphoff
, skb
->len
- tcphoff
, 0);
326 case CHECKSUM_COMPLETE
:
327 #ifdef CONFIG_IP_VS_IPV6
328 if (af
== AF_INET6
) {
329 if (csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
330 &ipv6_hdr(skb
)->daddr
,
332 ipv6_hdr(skb
)->nexthdr
,
334 IP_VS_DBG_RL_PKT(0, af
, pp
, skb
, 0,
335 "Failed checksum for");
340 if (csum_tcpudp_magic(ip_hdr(skb
)->saddr
,
343 ip_hdr(skb
)->protocol
,
345 IP_VS_DBG_RL_PKT(0, af
, pp
, skb
, 0,
346 "Failed checksum for");
351 /* No need to checksum. */
359 #define TCP_DIR_INPUT 0
360 #define TCP_DIR_OUTPUT 4
361 #define TCP_DIR_INPUT_ONLY 8
363 static const int tcp_state_off
[IP_VS_DIR_LAST
] = {
364 [IP_VS_DIR_INPUT
] = TCP_DIR_INPUT
,
365 [IP_VS_DIR_OUTPUT
] = TCP_DIR_OUTPUT
,
366 [IP_VS_DIR_INPUT_ONLY
] = TCP_DIR_INPUT_ONLY
,
370 * Timeout table[state]
372 static const int tcp_timeouts
[IP_VS_TCP_S_LAST
+1] = {
373 [IP_VS_TCP_S_NONE
] = 2*HZ
,
374 [IP_VS_TCP_S_ESTABLISHED
] = 15*60*HZ
,
375 [IP_VS_TCP_S_SYN_SENT
] = 2*60*HZ
,
376 [IP_VS_TCP_S_SYN_RECV
] = 1*60*HZ
,
377 [IP_VS_TCP_S_FIN_WAIT
] = 2*60*HZ
,
378 [IP_VS_TCP_S_TIME_WAIT
] = 2*60*HZ
,
379 [IP_VS_TCP_S_CLOSE
] = 10*HZ
,
380 [IP_VS_TCP_S_CLOSE_WAIT
] = 60*HZ
,
381 [IP_VS_TCP_S_LAST_ACK
] = 30*HZ
,
382 [IP_VS_TCP_S_LISTEN
] = 2*60*HZ
,
383 [IP_VS_TCP_S_SYNACK
] = 120*HZ
,
384 [IP_VS_TCP_S_LAST
] = 2*HZ
,
387 static const char *const tcp_state_name_table
[IP_VS_TCP_S_LAST
+1] = {
388 [IP_VS_TCP_S_NONE
] = "NONE",
389 [IP_VS_TCP_S_ESTABLISHED
] = "ESTABLISHED",
390 [IP_VS_TCP_S_SYN_SENT
] = "SYN_SENT",
391 [IP_VS_TCP_S_SYN_RECV
] = "SYN_RECV",
392 [IP_VS_TCP_S_FIN_WAIT
] = "FIN_WAIT",
393 [IP_VS_TCP_S_TIME_WAIT
] = "TIME_WAIT",
394 [IP_VS_TCP_S_CLOSE
] = "CLOSE",
395 [IP_VS_TCP_S_CLOSE_WAIT
] = "CLOSE_WAIT",
396 [IP_VS_TCP_S_LAST_ACK
] = "LAST_ACK",
397 [IP_VS_TCP_S_LISTEN
] = "LISTEN",
398 [IP_VS_TCP_S_SYNACK
] = "SYNACK",
399 [IP_VS_TCP_S_LAST
] = "BUG!",
402 #define sNO IP_VS_TCP_S_NONE
403 #define sES IP_VS_TCP_S_ESTABLISHED
404 #define sSS IP_VS_TCP_S_SYN_SENT
405 #define sSR IP_VS_TCP_S_SYN_RECV
406 #define sFW IP_VS_TCP_S_FIN_WAIT
407 #define sTW IP_VS_TCP_S_TIME_WAIT
408 #define sCL IP_VS_TCP_S_CLOSE
409 #define sCW IP_VS_TCP_S_CLOSE_WAIT
410 #define sLA IP_VS_TCP_S_LAST_ACK
411 #define sLI IP_VS_TCP_S_LISTEN
412 #define sSA IP_VS_TCP_S_SYNACK
414 struct tcp_states_t
{
415 int next_state
[IP_VS_TCP_S_LAST
];
418 static const char * tcp_state_name(int state
)
420 if (state
>= IP_VS_TCP_S_LAST
)
422 return tcp_state_name_table
[state
] ? tcp_state_name_table
[state
] : "?";
425 static struct tcp_states_t tcp_states
[] = {
427 /* sNO, sES, sSS, sSR, sFW, sTW, sCL, sCW, sLA, sLI, sSA */
428 /*syn*/ {{sSR
, sES
, sES
, sSR
, sSR
, sSR
, sSR
, sSR
, sSR
, sSR
, sSR
}},
429 /*fin*/ {{sCL
, sCW
, sSS
, sTW
, sTW
, sTW
, sCL
, sCW
, sLA
, sLI
, sTW
}},
430 /*ack*/ {{sES
, sES
, sSS
, sES
, sFW
, sTW
, sCL
, sCW
, sCL
, sLI
, sES
}},
431 /*rst*/ {{sCL
, sCL
, sCL
, sSR
, sCL
, sCL
, sCL
, sCL
, sLA
, sLI
, sSR
}},
434 /* sNO, sES, sSS, sSR, sFW, sTW, sCL, sCW, sLA, sLI, sSA */
435 /*syn*/ {{sSS
, sES
, sSS
, sSR
, sSS
, sSS
, sSS
, sSS
, sSS
, sLI
, sSR
}},
436 /*fin*/ {{sTW
, sFW
, sSS
, sTW
, sFW
, sTW
, sCL
, sTW
, sLA
, sLI
, sTW
}},
437 /*ack*/ {{sES
, sES
, sSS
, sES
, sFW
, sTW
, sCL
, sCW
, sLA
, sES
, sES
}},
438 /*rst*/ {{sCL
, sCL
, sSS
, sCL
, sCL
, sTW
, sCL
, sCL
, sCL
, sCL
, sCL
}},
441 /* sNO, sES, sSS, sSR, sFW, sTW, sCL, sCW, sLA, sLI, sSA */
442 /*syn*/ {{sSR
, sES
, sES
, sSR
, sSR
, sSR
, sSR
, sSR
, sSR
, sSR
, sSR
}},
443 /*fin*/ {{sCL
, sFW
, sSS
, sTW
, sFW
, sTW
, sCL
, sCW
, sLA
, sLI
, sTW
}},
444 /*ack*/ {{sES
, sES
, sSS
, sES
, sFW
, sTW
, sCL
, sCW
, sCL
, sLI
, sES
}},
445 /*rst*/ {{sCL
, sCL
, sCL
, sSR
, sCL
, sCL
, sCL
, sCL
, sLA
, sLI
, sCL
}},
448 static struct tcp_states_t tcp_states_dos
[] = {
450 /* sNO, sES, sSS, sSR, sFW, sTW, sCL, sCW, sLA, sLI, sSA */
451 /*syn*/ {{sSR
, sES
, sES
, sSR
, sSR
, sSR
, sSR
, sSR
, sSR
, sSR
, sSA
}},
452 /*fin*/ {{sCL
, sCW
, sSS
, sTW
, sTW
, sTW
, sCL
, sCW
, sLA
, sLI
, sSA
}},
453 /*ack*/ {{sES
, sES
, sSS
, sSR
, sFW
, sTW
, sCL
, sCW
, sCL
, sLI
, sSA
}},
454 /*rst*/ {{sCL
, sCL
, sCL
, sSR
, sCL
, sCL
, sCL
, sCL
, sLA
, sLI
, sCL
}},
457 /* sNO, sES, sSS, sSR, sFW, sTW, sCL, sCW, sLA, sLI, sSA */
458 /*syn*/ {{sSS
, sES
, sSS
, sSA
, sSS
, sSS
, sSS
, sSS
, sSS
, sLI
, sSA
}},
459 /*fin*/ {{sTW
, sFW
, sSS
, sTW
, sFW
, sTW
, sCL
, sTW
, sLA
, sLI
, sTW
}},
460 /*ack*/ {{sES
, sES
, sSS
, sES
, sFW
, sTW
, sCL
, sCW
, sLA
, sES
, sES
}},
461 /*rst*/ {{sCL
, sCL
, sSS
, sCL
, sCL
, sTW
, sCL
, sCL
, sCL
, sCL
, sCL
}},
464 /* sNO, sES, sSS, sSR, sFW, sTW, sCL, sCW, sLA, sLI, sSA */
465 /*syn*/ {{sSA
, sES
, sES
, sSR
, sSA
, sSA
, sSA
, sSA
, sSA
, sSA
, sSA
}},
466 /*fin*/ {{sCL
, sFW
, sSS
, sTW
, sFW
, sTW
, sCL
, sCW
, sLA
, sLI
, sTW
}},
467 /*ack*/ {{sES
, sES
, sSS
, sES
, sFW
, sTW
, sCL
, sCW
, sCL
, sLI
, sES
}},
468 /*rst*/ {{sCL
, sCL
, sCL
, sSR
, sCL
, sCL
, sCL
, sCL
, sLA
, sLI
, sCL
}},
471 static void tcp_timeout_change(struct ip_vs_proto_data
*pd
, int flags
)
473 int on
= (flags
& 1); /* secure_tcp */
476 ** FIXME: change secure_tcp to independent sysctl var
477 ** or make it per-service or per-app because it is valid
478 ** for most if not for all of the applications. Something
479 ** like "capabilities" (flags) for each object.
481 pd
->tcp_state_table
= (on
? tcp_states_dos
: tcp_states
);
484 static inline int tcp_state_idx(struct tcphdr
*th
)
498 set_tcp_state(struct ip_vs_proto_data
*pd
, struct ip_vs_conn
*cp
,
499 int direction
, struct tcphdr
*th
)
502 int new_state
= IP_VS_TCP_S_CLOSE
;
503 int state_off
= tcp_state_off
[direction
];
506 * Update state offset to INPUT_ONLY if necessary
507 * or delete NO_OUTPUT flag if output packet detected
509 if (cp
->flags
& IP_VS_CONN_F_NOOUTPUT
) {
510 if (state_off
== TCP_DIR_OUTPUT
)
511 cp
->flags
&= ~IP_VS_CONN_F_NOOUTPUT
;
513 state_off
= TCP_DIR_INPUT_ONLY
;
516 if ((state_idx
= tcp_state_idx(th
)) < 0) {
517 IP_VS_DBG(8, "tcp_state_idx=%d!!!\n", state_idx
);
522 pd
->tcp_state_table
[state_off
+state_idx
].next_state
[cp
->state
];
525 if (new_state
!= cp
->state
) {
526 struct ip_vs_dest
*dest
= cp
->dest
;
528 IP_VS_DBG_BUF(8, "%s %s [%c%c%c%c] %s:%d->"
529 "%s:%d state: %s->%s conn->refcnt:%d\n",
531 ((state_off
== TCP_DIR_OUTPUT
) ?
532 "output " : "input "),
537 IP_VS_DBG_ADDR(cp
->daf
, &cp
->daddr
),
539 IP_VS_DBG_ADDR(cp
->af
, &cp
->caddr
),
541 tcp_state_name(cp
->state
),
542 tcp_state_name(new_state
),
543 atomic_read(&cp
->refcnt
));
546 if (!(cp
->flags
& IP_VS_CONN_F_INACTIVE
) &&
547 (new_state
!= IP_VS_TCP_S_ESTABLISHED
)) {
548 atomic_dec(&dest
->activeconns
);
549 atomic_inc(&dest
->inactconns
);
550 cp
->flags
|= IP_VS_CONN_F_INACTIVE
;
551 } else if ((cp
->flags
& IP_VS_CONN_F_INACTIVE
) &&
552 (new_state
== IP_VS_TCP_S_ESTABLISHED
)) {
553 atomic_inc(&dest
->activeconns
);
554 atomic_dec(&dest
->inactconns
);
555 cp
->flags
&= ~IP_VS_CONN_F_INACTIVE
;
561 cp
->timeout
= pd
->timeout_table
[cp
->state
= new_state
];
562 else /* What to do ? */
563 cp
->timeout
= tcp_timeouts
[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_proto_data
*pd
)
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_bh(&cp
->lock
);
587 set_tcp_state(pd
, cp
, direction
, th
);
588 spin_unlock_bh(&cp
->lock
);
591 static inline __u16
tcp_app_hashkey(__be16 port
)
593 return (((__force u16
)port
>> TCP_APP_TAB_BITS
) ^ (__force u16
)port
)
598 static int tcp_register_app(struct netns_ipvs
*ipvs
, struct ip_vs_app
*inc
)
602 __be16 port
= inc
->port
;
604 struct ip_vs_proto_data
*pd
= ip_vs_proto_data_get(ipvs
, IPPROTO_TCP
);
606 hash
= tcp_app_hashkey(port
);
608 list_for_each_entry(i
, &ipvs
->tcp_apps
[hash
], p_list
) {
609 if (i
->port
== port
) {
614 list_add_rcu(&inc
->p_list
, &ipvs
->tcp_apps
[hash
]);
615 atomic_inc(&pd
->appcnt
);
623 tcp_unregister_app(struct netns_ipvs
*ipvs
, struct ip_vs_app
*inc
)
625 struct ip_vs_proto_data
*pd
= ip_vs_proto_data_get(ipvs
, IPPROTO_TCP
);
627 atomic_dec(&pd
->appcnt
);
628 list_del_rcu(&inc
->p_list
);
633 tcp_app_conn_bind(struct ip_vs_conn
*cp
)
635 struct netns_ipvs
*ipvs
= cp
->ipvs
;
637 struct ip_vs_app
*inc
;
640 /* Default binding: bind app only for NAT */
641 if (IP_VS_FWD_METHOD(cp
) != IP_VS_CONN_F_MASQ
)
644 /* Lookup application incarnations and bind the right one */
645 hash
= tcp_app_hashkey(cp
->vport
);
648 list_for_each_entry_rcu(inc
, &ipvs
->tcp_apps
[hash
], p_list
) {
649 if (inc
->port
== cp
->vport
) {
650 if (unlikely(!ip_vs_app_inc_get(inc
)))
654 IP_VS_DBG_BUF(9, "%s(): Binding conn %s:%u->"
655 "%s:%u to app %s on port %u\n",
657 IP_VS_DBG_ADDR(cp
->af
, &cp
->caddr
),
659 IP_VS_DBG_ADDR(cp
->af
, &cp
->vaddr
),
661 inc
->name
, ntohs(inc
->port
));
665 result
= inc
->init_conn(inc
, cp
);
677 * Set LISTEN timeout. (ip_vs_conn_put will setup timer)
679 void ip_vs_tcp_conn_listen(struct net
*net
, struct ip_vs_conn
*cp
)
681 struct ip_vs_proto_data
*pd
= ip_vs_proto_data_get(net_ipvs(net
), IPPROTO_TCP
);
683 spin_lock_bh(&cp
->lock
);
684 cp
->state
= IP_VS_TCP_S_LISTEN
;
685 cp
->timeout
= (pd
? pd
->timeout_table
[IP_VS_TCP_S_LISTEN
]
686 : tcp_timeouts
[IP_VS_TCP_S_LISTEN
]);
687 spin_unlock_bh(&cp
->lock
);
690 /* ---------------------------------------------
691 * timeouts is netns related now.
692 * ---------------------------------------------
694 static int __ip_vs_tcp_init(struct net
*net
, struct ip_vs_proto_data
*pd
)
696 struct netns_ipvs
*ipvs
= net_ipvs(net
);
698 ip_vs_init_hash_table(ipvs
->tcp_apps
, TCP_APP_TAB_SIZE
);
699 pd
->timeout_table
= ip_vs_create_timeout_table((int *)tcp_timeouts
,
700 sizeof(tcp_timeouts
));
701 if (!pd
->timeout_table
)
703 pd
->tcp_state_table
= tcp_states
;
707 static void __ip_vs_tcp_exit(struct net
*net
, struct ip_vs_proto_data
*pd
)
709 kfree(pd
->timeout_table
);
713 struct ip_vs_protocol ip_vs_protocol_tcp
= {
715 .protocol
= IPPROTO_TCP
,
716 .num_states
= IP_VS_TCP_S_LAST
,
720 .init_netns
= __ip_vs_tcp_init
,
721 .exit_netns
= __ip_vs_tcp_exit
,
722 .register_app
= tcp_register_app
,
723 .unregister_app
= tcp_unregister_app
,
724 .conn_schedule
= tcp_conn_schedule
,
725 .conn_in_get
= ip_vs_conn_in_get_proto
,
726 .conn_out_get
= ip_vs_conn_out_get_proto
,
727 .snat_handler
= tcp_snat_handler
,
728 .dnat_handler
= tcp_dnat_handler
,
729 .csum_check
= tcp_csum_check
,
730 .state_name
= tcp_state_name
,
731 .state_transition
= tcp_state_transition
,
732 .app_conn_bind
= tcp_app_conn_bind
,
733 .debug_packet
= ip_vs_tcpudp_debug_packet
,
734 .timeout_change
= tcp_timeout_change
,