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 #include <linux/kernel.h>
18 #include <linux/tcp.h> /* for tcphdr */
20 #include <net/tcp.h> /* for csum_tcpudp_magic */
21 #include <linux/netfilter.h>
22 #include <linux/netfilter_ipv4.h>
24 #include <net/ip_vs.h>
27 static struct ip_vs_conn *
28 tcp_conn_in_get(int af, const struct sk_buff *skb, struct ip_vs_protocol *pp,
29 const struct ip_vs_iphdr *iph, unsigned int proto_off,
32 __be16 _ports[2], *pptr;
34 pptr = skb_header_pointer(skb, proto_off, sizeof(_ports), _ports);
38 if (likely(!inverse)) {
39 return ip_vs_conn_in_get(af, iph->protocol,
41 &iph->daddr, pptr[1]);
43 return ip_vs_conn_in_get(af, iph->protocol,
45 &iph->saddr, pptr[0]);
49 static struct ip_vs_conn *
50 tcp_conn_out_get(int af, const struct sk_buff *skb, struct ip_vs_protocol *pp,
51 const struct ip_vs_iphdr *iph, unsigned int proto_off,
54 __be16 _ports[2], *pptr;
56 pptr = skb_header_pointer(skb, proto_off, sizeof(_ports), _ports);
60 if (likely(!inverse)) {
61 return ip_vs_conn_out_get(af, iph->protocol,
63 &iph->daddr, pptr[1]);
65 return ip_vs_conn_out_get(af, iph->protocol,
67 &iph->saddr, pptr[0]);
73 tcp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_protocol *pp,
74 int *verdict, struct ip_vs_conn **cpp)
76 struct ip_vs_service *svc;
77 struct tcphdr _tcph, *th;
78 struct ip_vs_iphdr iph;
80 ip_vs_fill_iphdr(af, skb_network_header(skb), &iph);
82 th = skb_header_pointer(skb, iph.len, sizeof(_tcph), &_tcph);
89 (svc = ip_vs_service_get(af, skb->mark, iph.protocol, &iph.daddr,
93 * It seems that we are very loaded.
94 * We have to drop this packet :(
96 ip_vs_service_put(svc);
102 * Let the virtual server select a real server for the
103 * incoming connection, and create a connection entry.
105 *cpp = ip_vs_schedule(svc, skb);
107 *verdict = ip_vs_leave(svc, skb, pp);
110 ip_vs_service_put(svc);
117 tcp_fast_csum_update(int af, struct tcphdr *tcph,
118 const union nf_inet_addr *oldip,
119 const union nf_inet_addr *newip,
120 __be16 oldport, __be16 newport)
122 #ifdef CONFIG_IP_VS_IPV6
125 csum_fold(ip_vs_check_diff16(oldip->ip6, newip->ip6,
126 ip_vs_check_diff2(oldport, newport,
127 ~csum_unfold(tcph->check))));
131 csum_fold(ip_vs_check_diff4(oldip->ip, newip->ip,
132 ip_vs_check_diff2(oldport, newport,
133 ~csum_unfold(tcph->check))));
138 tcp_partial_csum_update(int af, struct tcphdr *tcph,
139 const union nf_inet_addr *oldip,
140 const union nf_inet_addr *newip,
141 __be16 oldlen, __be16 newlen)
143 #ifdef CONFIG_IP_VS_IPV6
146 csum_fold(ip_vs_check_diff16(oldip->ip6, newip->ip6,
147 ip_vs_check_diff2(oldlen, newlen,
148 ~csum_unfold(tcph->check))));
152 csum_fold(ip_vs_check_diff4(oldip->ip, newip->ip,
153 ip_vs_check_diff2(oldlen, newlen,
154 ~csum_unfold(tcph->check))));
159 tcp_snat_handler(struct sk_buff *skb,
160 struct ip_vs_protocol *pp, struct ip_vs_conn *cp)
163 unsigned int tcphoff;
166 #ifdef CONFIG_IP_VS_IPV6
167 if (cp->af == AF_INET6)
168 tcphoff = sizeof(struct ipv6hdr);
171 tcphoff = ip_hdrlen(skb);
172 oldlen = skb->len - tcphoff;
174 /* csum_check requires unshared skb */
175 if (!skb_make_writable(skb, tcphoff+sizeof(*tcph)))
178 if (unlikely(cp->app != NULL)) {
179 /* Some checks before mangling */
180 if (pp->csum_check && !pp->csum_check(cp->af, skb, pp))
183 /* Call application helper if needed */
184 if (!ip_vs_app_pkt_out(cp, skb))
188 tcph = (void *)skb_network_header(skb) + tcphoff;
189 tcph->source = cp->vport;
191 /* Adjust TCP checksums */
192 if (skb->ip_summed == CHECKSUM_PARTIAL) {
193 tcp_partial_csum_update(cp->af, tcph, &cp->daddr, &cp->vaddr,
195 htonl(skb->len - tcphoff));
196 } else if (!cp->app) {
197 /* Only port and addr are changed, do fast csum update */
198 tcp_fast_csum_update(cp->af, tcph, &cp->daddr, &cp->vaddr,
199 cp->dport, cp->vport);
200 if (skb->ip_summed == CHECKSUM_COMPLETE)
201 skb->ip_summed = CHECKSUM_NONE;
203 /* full checksum calculation */
205 skb->csum = skb_checksum(skb, tcphoff, skb->len - tcphoff, 0);
206 #ifdef CONFIG_IP_VS_IPV6
207 if (cp->af == AF_INET6)
208 tcph->check = csum_ipv6_magic(&cp->vaddr.in6,
211 cp->protocol, skb->csum);
214 tcph->check = csum_tcpudp_magic(cp->vaddr.ip,
220 IP_VS_DBG(11, "O-pkt: %s O-csum=%d (+%zd)\n",
221 pp->name, tcph->check,
222 (char*)&(tcph->check) - (char*)tcph);
229 tcp_dnat_handler(struct sk_buff *skb,
230 struct ip_vs_protocol *pp, struct ip_vs_conn *cp)
233 unsigned int tcphoff;
236 #ifdef CONFIG_IP_VS_IPV6
237 if (cp->af == AF_INET6)
238 tcphoff = sizeof(struct ipv6hdr);
241 tcphoff = ip_hdrlen(skb);
242 oldlen = skb->len - tcphoff;
244 /* csum_check requires unshared skb */
245 if (!skb_make_writable(skb, tcphoff+sizeof(*tcph)))
248 if (unlikely(cp->app != NULL)) {
249 /* Some checks before mangling */
250 if (pp->csum_check && !pp->csum_check(cp->af, skb, pp))
254 * Attempt ip_vs_app call.
255 * It will fix ip_vs_conn and iph ack_seq stuff
257 if (!ip_vs_app_pkt_in(cp, skb))
261 tcph = (void *)skb_network_header(skb) + tcphoff;
262 tcph->dest = cp->dport;
265 * Adjust TCP checksums
267 if (skb->ip_summed == CHECKSUM_PARTIAL) {
268 tcp_partial_csum_update(cp->af, tcph, &cp->daddr, &cp->vaddr,
270 htonl(skb->len - tcphoff));
271 } else if (!cp->app) {
272 /* Only port and addr are changed, do fast csum update */
273 tcp_fast_csum_update(cp->af, tcph, &cp->vaddr, &cp->daddr,
274 cp->vport, cp->dport);
275 if (skb->ip_summed == CHECKSUM_COMPLETE)
276 skb->ip_summed = CHECKSUM_NONE;
278 /* full checksum calculation */
280 skb->csum = skb_checksum(skb, tcphoff, skb->len - tcphoff, 0);
281 #ifdef CONFIG_IP_VS_IPV6
282 if (cp->af == AF_INET6)
283 tcph->check = csum_ipv6_magic(&cp->caddr.in6,
286 cp->protocol, skb->csum);
289 tcph->check = csum_tcpudp_magic(cp->caddr.ip,
294 skb->ip_summed = CHECKSUM_UNNECESSARY;
301 tcp_csum_check(int af, struct sk_buff *skb, struct ip_vs_protocol *pp)
303 unsigned int tcphoff;
305 #ifdef CONFIG_IP_VS_IPV6
307 tcphoff = sizeof(struct ipv6hdr);
310 tcphoff = ip_hdrlen(skb);
312 switch (skb->ip_summed) {
314 skb->csum = skb_checksum(skb, tcphoff, skb->len - tcphoff, 0);
315 case CHECKSUM_COMPLETE:
316 #ifdef CONFIG_IP_VS_IPV6
317 if (af == AF_INET6) {
318 if (csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
319 &ipv6_hdr(skb)->daddr,
321 ipv6_hdr(skb)->nexthdr,
323 IP_VS_DBG_RL_PKT(0, pp, skb, 0,
324 "Failed checksum for");
329 if (csum_tcpudp_magic(ip_hdr(skb)->saddr,
332 ip_hdr(skb)->protocol,
334 IP_VS_DBG_RL_PKT(0, pp, skb, 0,
335 "Failed checksum for");
340 /* No need to checksum. */
348 #define TCP_DIR_INPUT 0
349 #define TCP_DIR_OUTPUT 4
350 #define TCP_DIR_INPUT_ONLY 8
352 static const int tcp_state_off[IP_VS_DIR_LAST] = {
353 [IP_VS_DIR_INPUT] = TCP_DIR_INPUT,
354 [IP_VS_DIR_OUTPUT] = TCP_DIR_OUTPUT,
355 [IP_VS_DIR_INPUT_ONLY] = TCP_DIR_INPUT_ONLY,
359 * Timeout table[state]
361 static int tcp_timeouts[IP_VS_TCP_S_LAST+1] = {
362 [IP_VS_TCP_S_NONE] = 2*HZ,
363 [IP_VS_TCP_S_ESTABLISHED] = 15*60*HZ,
364 [IP_VS_TCP_S_SYN_SENT] = 2*60*HZ,
365 [IP_VS_TCP_S_SYN_RECV] = 1*60*HZ,
366 [IP_VS_TCP_S_FIN_WAIT] = 2*60*HZ,
367 [IP_VS_TCP_S_TIME_WAIT] = 2*60*HZ,
368 [IP_VS_TCP_S_CLOSE] = 10*HZ,
369 [IP_VS_TCP_S_CLOSE_WAIT] = 60*HZ,
370 [IP_VS_TCP_S_LAST_ACK] = 30*HZ,
371 [IP_VS_TCP_S_LISTEN] = 2*60*HZ,
372 [IP_VS_TCP_S_SYNACK] = 120*HZ,
373 [IP_VS_TCP_S_LAST] = 2*HZ,
376 static char * tcp_state_name_table[IP_VS_TCP_S_LAST+1] = {
377 [IP_VS_TCP_S_NONE] = "NONE",
378 [IP_VS_TCP_S_ESTABLISHED] = "ESTABLISHED",
379 [IP_VS_TCP_S_SYN_SENT] = "SYN_SENT",
380 [IP_VS_TCP_S_SYN_RECV] = "SYN_RECV",
381 [IP_VS_TCP_S_FIN_WAIT] = "FIN_WAIT",
382 [IP_VS_TCP_S_TIME_WAIT] = "TIME_WAIT",
383 [IP_VS_TCP_S_CLOSE] = "CLOSE",
384 [IP_VS_TCP_S_CLOSE_WAIT] = "CLOSE_WAIT",
385 [IP_VS_TCP_S_LAST_ACK] = "LAST_ACK",
386 [IP_VS_TCP_S_LISTEN] = "LISTEN",
387 [IP_VS_TCP_S_SYNACK] = "SYNACK",
388 [IP_VS_TCP_S_LAST] = "BUG!",
391 #define sNO IP_VS_TCP_S_NONE
392 #define sES IP_VS_TCP_S_ESTABLISHED
393 #define sSS IP_VS_TCP_S_SYN_SENT
394 #define sSR IP_VS_TCP_S_SYN_RECV
395 #define sFW IP_VS_TCP_S_FIN_WAIT
396 #define sTW IP_VS_TCP_S_TIME_WAIT
397 #define sCL IP_VS_TCP_S_CLOSE
398 #define sCW IP_VS_TCP_S_CLOSE_WAIT
399 #define sLA IP_VS_TCP_S_LAST_ACK
400 #define sLI IP_VS_TCP_S_LISTEN
401 #define sSA IP_VS_TCP_S_SYNACK
403 struct tcp_states_t {
404 int next_state[IP_VS_TCP_S_LAST];
407 static const char * tcp_state_name(int state)
409 if (state >= IP_VS_TCP_S_LAST)
411 return tcp_state_name_table[state] ? tcp_state_name_table[state] : "?";
414 static struct tcp_states_t tcp_states [] = {
416 /* sNO, sES, sSS, sSR, sFW, sTW, sCL, sCW, sLA, sLI, sSA */
417 /*syn*/ {{sSR, sES, sES, sSR, sSR, sSR, sSR, sSR, sSR, sSR, sSR }},
418 /*fin*/ {{sCL, sCW, sSS, sTW, sTW, sTW, sCL, sCW, sLA, sLI, sTW }},
419 /*ack*/ {{sCL, sES, sSS, sES, sFW, sTW, sCL, sCW, sCL, sLI, sES }},
420 /*rst*/ {{sCL, sCL, sCL, sSR, sCL, sCL, sCL, sCL, sLA, sLI, sSR }},
423 /* sNO, sES, sSS, sSR, sFW, sTW, sCL, sCW, sLA, sLI, sSA */
424 /*syn*/ {{sSS, sES, sSS, sSR, sSS, sSS, sSS, sSS, sSS, sLI, sSR }},
425 /*fin*/ {{sTW, sFW, sSS, sTW, sFW, sTW, sCL, sTW, sLA, sLI, sTW }},
426 /*ack*/ {{sES, sES, sSS, sES, sFW, sTW, sCL, sCW, sLA, sES, sES }},
427 /*rst*/ {{sCL, sCL, sSS, sCL, sCL, sTW, sCL, sCL, sCL, sCL, sCL }},
430 /* sNO, sES, sSS, sSR, sFW, sTW, sCL, sCW, sLA, sLI, sSA */
431 /*syn*/ {{sSR, sES, sES, sSR, sSR, sSR, sSR, sSR, sSR, sSR, sSR }},
432 /*fin*/ {{sCL, sFW, sSS, sTW, sFW, sTW, sCL, sCW, sLA, sLI, sTW }},
433 /*ack*/ {{sCL, sES, sSS, sES, sFW, sTW, sCL, sCW, sCL, sLI, sES }},
434 /*rst*/ {{sCL, sCL, sCL, sSR, sCL, sCL, sCL, sCL, sLA, sLI, sCL }},
437 static struct tcp_states_t tcp_states_dos [] = {
439 /* sNO, sES, sSS, sSR, sFW, sTW, sCL, sCW, sLA, sLI, sSA */
440 /*syn*/ {{sSR, sES, sES, sSR, sSR, sSR, sSR, sSR, sSR, sSR, sSA }},
441 /*fin*/ {{sCL, sCW, sSS, sTW, sTW, sTW, sCL, sCW, sLA, sLI, sSA }},
442 /*ack*/ {{sCL, sES, sSS, sSR, sFW, sTW, sCL, sCW, sCL, sLI, sSA }},
443 /*rst*/ {{sCL, sCL, sCL, sSR, sCL, sCL, sCL, sCL, sLA, sLI, sCL }},
446 /* sNO, sES, sSS, sSR, sFW, sTW, sCL, sCW, sLA, sLI, sSA */
447 /*syn*/ {{sSS, sES, sSS, sSA, sSS, sSS, sSS, sSS, sSS, sLI, sSA }},
448 /*fin*/ {{sTW, sFW, sSS, sTW, sFW, sTW, sCL, sTW, sLA, sLI, sTW }},
449 /*ack*/ {{sES, sES, sSS, sES, sFW, sTW, sCL, sCW, sLA, sES, sES }},
450 /*rst*/ {{sCL, sCL, sSS, sCL, sCL, sTW, sCL, sCL, sCL, sCL, sCL }},
453 /* sNO, sES, sSS, sSR, sFW, sTW, sCL, sCW, sLA, sLI, sSA */
454 /*syn*/ {{sSA, sES, sES, sSR, sSA, sSA, sSA, sSA, sSA, sSA, sSA }},
455 /*fin*/ {{sCL, sFW, sSS, sTW, sFW, sTW, sCL, sCW, sLA, sLI, sTW }},
456 /*ack*/ {{sCL, sES, sSS, sES, sFW, sTW, sCL, sCW, sCL, sLI, sES }},
457 /*rst*/ {{sCL, sCL, sCL, sSR, sCL, sCL, sCL, sCL, sLA, sLI, sCL }},
460 static struct tcp_states_t *tcp_state_table = tcp_states;
463 static void tcp_timeout_change(struct ip_vs_protocol *pp, int flags)
465 int on = (flags & 1); /* secure_tcp */
468 ** FIXME: change secure_tcp to independent sysctl var
469 ** or make it per-service or per-app because it is valid
470 ** for most if not for all of the applications. Something
471 ** like "capabilities" (flags) for each object.
473 tcp_state_table = (on? tcp_states_dos : tcp_states);
477 tcp_set_state_timeout(struct ip_vs_protocol *pp, char *sname, int to)
479 return ip_vs_set_state_timeout(pp->timeout_table, IP_VS_TCP_S_LAST,
480 tcp_state_name_table, sname, to);
483 static inline int tcp_state_idx(struct tcphdr *th)
497 set_tcp_state(struct ip_vs_protocol *pp, struct ip_vs_conn *cp,
498 int direction, struct tcphdr *th)
501 int new_state = IP_VS_TCP_S_CLOSE;
502 int state_off = tcp_state_off[direction];
505 * Update state offset to INPUT_ONLY if necessary
506 * or delete NO_OUTPUT flag if output packet detected
508 if (cp->flags & IP_VS_CONN_F_NOOUTPUT) {
509 if (state_off == TCP_DIR_OUTPUT)
510 cp->flags &= ~IP_VS_CONN_F_NOOUTPUT;
512 state_off = TCP_DIR_INPUT_ONLY;
515 if ((state_idx = tcp_state_idx(th)) < 0) {
516 IP_VS_DBG(8, "tcp_state_idx=%d!!!\n", state_idx);
520 new_state = tcp_state_table[state_off+state_idx].next_state[cp->state];
523 if (new_state != cp->state) {
524 struct ip_vs_dest *dest = cp->dest;
526 IP_VS_DBG_BUF(8, "%s %s [%c%c%c%c] %s:%d->"
527 "%s:%d state: %s->%s conn->refcnt:%d\n",
529 ((state_off == TCP_DIR_OUTPUT) ?
530 "output " : "input "),
535 IP_VS_DBG_ADDR(cp->af, &cp->daddr),
537 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
539 tcp_state_name(cp->state),
540 tcp_state_name(new_state),
541 atomic_read(&cp->refcnt));
544 if (!(cp->flags & IP_VS_CONN_F_INACTIVE) &&
545 (new_state != IP_VS_TCP_S_ESTABLISHED)) {
546 atomic_dec(&dest->activeconns);
547 atomic_inc(&dest->inactconns);
548 cp->flags |= IP_VS_CONN_F_INACTIVE;
549 } else if ((cp->flags & IP_VS_CONN_F_INACTIVE) &&
550 (new_state == IP_VS_TCP_S_ESTABLISHED)) {
551 atomic_inc(&dest->activeconns);
552 atomic_dec(&dest->inactconns);
553 cp->flags &= ~IP_VS_CONN_F_INACTIVE;
558 cp->timeout = pp->timeout_table[cp->state = new_state];
563 * Handle state transitions
566 tcp_state_transition(struct ip_vs_conn *cp, int direction,
567 const struct sk_buff *skb,
568 struct ip_vs_protocol *pp)
570 struct tcphdr _tcph, *th;
572 #ifdef CONFIG_IP_VS_IPV6
573 int ihl = cp->af == AF_INET ? ip_hdrlen(skb) : sizeof(struct ipv6hdr);
575 int ihl = ip_hdrlen(skb);
578 th = skb_header_pointer(skb, ihl, sizeof(_tcph), &_tcph);
582 spin_lock(&cp->lock);
583 set_tcp_state(pp, cp, direction, th);
584 spin_unlock(&cp->lock);
591 * Hash table for TCP application incarnations
593 #define TCP_APP_TAB_BITS 4
594 #define TCP_APP_TAB_SIZE (1 << TCP_APP_TAB_BITS)
595 #define TCP_APP_TAB_MASK (TCP_APP_TAB_SIZE - 1)
597 static struct list_head tcp_apps[TCP_APP_TAB_SIZE];
598 static DEFINE_SPINLOCK(tcp_app_lock);
600 static inline __u16 tcp_app_hashkey(__be16 port)
602 return (((__force u16)port >> TCP_APP_TAB_BITS) ^ (__force u16)port)
607 static int tcp_register_app(struct ip_vs_app *inc)
611 __be16 port = inc->port;
614 hash = tcp_app_hashkey(port);
616 spin_lock_bh(&tcp_app_lock);
617 list_for_each_entry(i, &tcp_apps[hash], p_list) {
618 if (i->port == port) {
623 list_add(&inc->p_list, &tcp_apps[hash]);
624 atomic_inc(&ip_vs_protocol_tcp.appcnt);
627 spin_unlock_bh(&tcp_app_lock);
633 tcp_unregister_app(struct ip_vs_app *inc)
635 spin_lock_bh(&tcp_app_lock);
636 atomic_dec(&ip_vs_protocol_tcp.appcnt);
637 list_del(&inc->p_list);
638 spin_unlock_bh(&tcp_app_lock);
643 tcp_app_conn_bind(struct ip_vs_conn *cp)
646 struct ip_vs_app *inc;
649 /* Default binding: bind app only for NAT */
650 if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ)
653 /* Lookup application incarnations and bind the right one */
654 hash = tcp_app_hashkey(cp->vport);
656 spin_lock(&tcp_app_lock);
657 list_for_each_entry(inc, &tcp_apps[hash], p_list) {
658 if (inc->port == cp->vport) {
659 if (unlikely(!ip_vs_app_inc_get(inc)))
661 spin_unlock(&tcp_app_lock);
663 IP_VS_DBG_BUF(9, "%s: Binding conn %s:%u->"
664 "%s:%u to app %s on port %u\n",
666 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
668 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
670 inc->name, ntohs(inc->port));
674 result = inc->init_conn(inc, cp);
678 spin_unlock(&tcp_app_lock);
686 * Set LISTEN timeout. (ip_vs_conn_put will setup timer)
688 void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp)
690 spin_lock(&cp->lock);
691 cp->state = IP_VS_TCP_S_LISTEN;
692 cp->timeout = ip_vs_protocol_tcp.timeout_table[IP_VS_TCP_S_LISTEN];
693 spin_unlock(&cp->lock);
697 static void ip_vs_tcp_init(struct ip_vs_protocol *pp)
699 IP_VS_INIT_HASH_TABLE(tcp_apps);
700 pp->timeout_table = tcp_timeouts;
704 static void ip_vs_tcp_exit(struct ip_vs_protocol *pp)
709 struct ip_vs_protocol ip_vs_protocol_tcp = {
711 .protocol = IPPROTO_TCP,
712 .num_states = IP_VS_TCP_S_LAST,
714 .appcnt = ATOMIC_INIT(0),
715 .init = ip_vs_tcp_init,
716 .exit = ip_vs_tcp_exit,
717 .register_app = tcp_register_app,
718 .unregister_app = tcp_unregister_app,
719 .conn_schedule = tcp_conn_schedule,
720 .conn_in_get = tcp_conn_in_get,
721 .conn_out_get = tcp_conn_out_get,
722 .snat_handler = tcp_snat_handler,
723 .dnat_handler = tcp_dnat_handler,
724 .csum_check = tcp_csum_check,
725 .state_name = tcp_state_name,
726 .state_transition = tcp_state_transition,
727 .app_conn_bind = tcp_app_conn_bind,
728 .debug_packet = ip_vs_tcpudp_debug_packet,
729 .timeout_change = tcp_timeout_change,
730 .set_state_timeout = tcp_set_state_timeout,