Frédéric BERNON
2007-02-15 15:17:03 UTC
Hi group,
Can you give me some informations about he LwIP KEEPALIVE features? I use Socket Layer API, and I would like to know if it's possible to enable it "per socket" and to fix for each one a different timeout? I found in several files these informations :
In sockets.h/.c, I see :
#define SO_KEEPALIVE 0x0008 /* keep connections alive */
For this one, except seeing it is set/unset in the sock->conn->pcb.tcp->so_options.
In ip.h "These are the same like SO_XXX." :
#define SOF_KEEPALIVE (u16_t)0x0008U /* keep connections alive */
In tcp.h, I see :
#define TCP_KEEPALIVE 0x02 /* send KEEPALIVE probes when idle for pcb->keepalive miliseconds */
/* Keepalive values */
#define TCP_KEEPDEFAULT 7200000 /* KEEPALIVE timer in miliseconds */
#define TCP_KEEPINTVL 75000 /* Time between KEEPALIVE probes in miliseconds */
#define TCP_KEEPCNT 9 /* Counter for KEEPALIVE probes */
#define TCP_MAXIDLE TCP_KEEPCNT * TCP_KEEPINTVL /* Maximum KEEPALIVE probe time */
So, TCP_MAXIDLE is 675 seconds (11.25min), and TCP_KEEPDEFAULT is 7200 seconds (~120min : 2 hours) !?!?!!
In my lwipopts.h, I have set :
/* The TCP timer interval in milliseconds. */
#define TCP_TMR_INTERVAL 100
/* the fine grained timeout in milliseconds */
#define TCP_FAST_INTERVAL TCP_TMR_INTERVAL
/* the coarse grained timeout in milliseconds */
#define TCP_SLOW_INTERVAL (2*TCP_TMR_INTERVAL)
In tcp.c, I see :
In tcp.c :
/* Check if KEEPALIVE should be sent */
if((pcb->so_options & SOF_KEEPALIVE) && ((pcb->state == ESTABLISHED) || (pcb->state == CLOSE_WAIT))) {
if((u32_t)(tcp_ticks - pcb->tmr) > (pcb->keepalive + TCP_MAXIDLE) / TCP_SLOW_INTERVAL) {
LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: KEEPALIVE timeout. Aborting connection to %"U16_F".%"U16_F".%"U16_F".%"U16_F".\n",
ip4_addr1(&pcb->remote_ip), ip4_addr2(&pcb->remote_ip),
ip4_addr3(&pcb->remote_ip), ip4_addr4(&pcb->remote_ip)));
tcp_abort(pcb);
}
else if((u32_t)(tcp_ticks - pcb->tmr) > (pcb->keepalive + pcb->keep_cnt * TCP_KEEPINTVL) / TCP_SLOW_INTERVAL) {
tcp_keepalive(pcb);
pcb->keep_cnt++;
}
}
If I unserstand all these informations, at socket layer, I can set with setsockopt on a TCP socket the TCP_KEEPALIVE with my own timeout (in the setsockopt value), and set the SO_KEEPALIVE option to 1 to enable KEEPALIVE checking.
(pcb->keepalive + TCP_MAXIDLE) / TCP_SLOW_INTERVAL) give with default values (TCP_KEEPDEFAULT + TCP_MAXIDLE) / TCP_SLOW_INTERVAL) : (7200000+675000)/(2*100) = 7875000/200 = 39375 ticks.
After that, if my connection is in ESTABLISHED or CLOSE_WAIT state, if (tcp_ticks - pcb->tmr) > 39375 , I suppose the tcp connection will be abort. Right?
So, if I dont do any mistake, if a router between my lwip devices crashs, the connection will detect it in... 39375*200 ms = 7875 sec = 131.25 min !?!?!
I suppose I do a mistake somewhere, or I don't understand (because more than 2 hours - by default - to detect a connection failure seems to be very very long)...
Can you help me ?
Thank you
====================================
Frédéric BERNON
HYMATOM SA
Chef de projet informatique
Microsoft Certified Professional
Tél. : +33 (0)4-67-87-61-10
Fax. : +33 (0)4-67-70-85-44
Email : ***@hymatom.fr
Web Site : http://www.hymatom.fr
====================================
P Avant d'imprimer, penser à l'environnement
Can you give me some informations about he LwIP KEEPALIVE features? I use Socket Layer API, and I would like to know if it's possible to enable it "per socket" and to fix for each one a different timeout? I found in several files these informations :
In sockets.h/.c, I see :
#define SO_KEEPALIVE 0x0008 /* keep connections alive */
For this one, except seeing it is set/unset in the sock->conn->pcb.tcp->so_options.
In ip.h "These are the same like SO_XXX." :
#define SOF_KEEPALIVE (u16_t)0x0008U /* keep connections alive */
In tcp.h, I see :
#define TCP_KEEPALIVE 0x02 /* send KEEPALIVE probes when idle for pcb->keepalive miliseconds */
/* Keepalive values */
#define TCP_KEEPDEFAULT 7200000 /* KEEPALIVE timer in miliseconds */
#define TCP_KEEPINTVL 75000 /* Time between KEEPALIVE probes in miliseconds */
#define TCP_KEEPCNT 9 /* Counter for KEEPALIVE probes */
#define TCP_MAXIDLE TCP_KEEPCNT * TCP_KEEPINTVL /* Maximum KEEPALIVE probe time */
So, TCP_MAXIDLE is 675 seconds (11.25min), and TCP_KEEPDEFAULT is 7200 seconds (~120min : 2 hours) !?!?!!
In my lwipopts.h, I have set :
/* The TCP timer interval in milliseconds. */
#define TCP_TMR_INTERVAL 100
/* the fine grained timeout in milliseconds */
#define TCP_FAST_INTERVAL TCP_TMR_INTERVAL
/* the coarse grained timeout in milliseconds */
#define TCP_SLOW_INTERVAL (2*TCP_TMR_INTERVAL)
In tcp.c, I see :
In tcp.c :
/* Check if KEEPALIVE should be sent */
if((pcb->so_options & SOF_KEEPALIVE) && ((pcb->state == ESTABLISHED) || (pcb->state == CLOSE_WAIT))) {
if((u32_t)(tcp_ticks - pcb->tmr) > (pcb->keepalive + TCP_MAXIDLE) / TCP_SLOW_INTERVAL) {
LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: KEEPALIVE timeout. Aborting connection to %"U16_F".%"U16_F".%"U16_F".%"U16_F".\n",
ip4_addr1(&pcb->remote_ip), ip4_addr2(&pcb->remote_ip),
ip4_addr3(&pcb->remote_ip), ip4_addr4(&pcb->remote_ip)));
tcp_abort(pcb);
}
else if((u32_t)(tcp_ticks - pcb->tmr) > (pcb->keepalive + pcb->keep_cnt * TCP_KEEPINTVL) / TCP_SLOW_INTERVAL) {
tcp_keepalive(pcb);
pcb->keep_cnt++;
}
}
If I unserstand all these informations, at socket layer, I can set with setsockopt on a TCP socket the TCP_KEEPALIVE with my own timeout (in the setsockopt value), and set the SO_KEEPALIVE option to 1 to enable KEEPALIVE checking.
(pcb->keepalive + TCP_MAXIDLE) / TCP_SLOW_INTERVAL) give with default values (TCP_KEEPDEFAULT + TCP_MAXIDLE) / TCP_SLOW_INTERVAL) : (7200000+675000)/(2*100) = 7875000/200 = 39375 ticks.
After that, if my connection is in ESTABLISHED or CLOSE_WAIT state, if (tcp_ticks - pcb->tmr) > 39375 , I suppose the tcp connection will be abort. Right?
So, if I dont do any mistake, if a router between my lwip devices crashs, the connection will detect it in... 39375*200 ms = 7875 sec = 131.25 min !?!?!
I suppose I do a mistake somewhere, or I don't understand (because more than 2 hours - by default - to detect a connection failure seems to be very very long)...
Can you help me ?
Thank you
====================================
Frédéric BERNON
HYMATOM SA
Chef de projet informatique
Microsoft Certified Professional
Tél. : +33 (0)4-67-87-61-10
Fax. : +33 (0)4-67-70-85-44
Email : ***@hymatom.fr
Web Site : http://www.hymatom.fr
====================================
P Avant d'imprimer, penser à l'environnement