Allow to configure Telnetd idle timeout.

The default Telnetd idle timeout of 30 seconds seems somewhat short. Best to have it user-configurable (incl. the option to turn it off with an config value of 0).
This commit is contained in:
Oliver Schmidt 2015-07-06 12:25:20 +02:00
parent 5d039d9848
commit a30e2e0045
6 changed files with 38 additions and 7 deletions

View file

@ -62,6 +62,10 @@ static char telnetd_reject_text[] =
"Too many connections, please try again later.";
#endif
#ifndef TELNETD_CONF_MAX_IDLE_TIME
#define TELNETD_CONF_MAX_IDLE_TIME (CLOCK_SECOND * 30)
#endif
struct telnetd_state {
char buf[TELNETD_CONF_LINELEN + 1];
char bufptr;
@ -74,7 +78,9 @@ struct telnetd_state {
#define STATE_DO 4
#define STATE_DONT 5
#define STATE_CLOSE 6
#if TELNETD_CONF_MAX_IDLE_TIME
struct timer silence_timer;
#endif /* TELNETD_CONF_MAX_IDLE_TIME */
};
static struct telnetd_state s;
@ -102,8 +108,6 @@ static struct telnetd_buf buf;
static uint8_t connected;
#define MAX_SILENCE_TIME (CLOCK_SECOND * 30)
/*---------------------------------------------------------------------------*/
static void
buf_init(struct telnetd_buf *buf)
@ -359,7 +363,9 @@ telnetd_appcall(void *ts)
s.state = STATE_NORMAL;
connected = 1;
shell_start();
timer_set(&s.silence_timer, MAX_SILENCE_TIME);
#if TELNETD_CONF_MAX_IDLE_TIME
timer_set(&s.silence_timer, TELNETD_CONF_MAX_IDLE_TIME);
#endif /* TELNETD_CONF_MAX_IDLE_TIME */
ts = (char *)0;
} else {
uip_send(telnetd_reject_text, strlen(telnetd_reject_text));
@ -381,11 +387,15 @@ telnetd_appcall(void *ts)
connected = 0;
}
if(uip_acked()) {
timer_set(&s.silence_timer, MAX_SILENCE_TIME);
#if TELNETD_CONF_MAX_IDLE_TIME
timer_set(&s.silence_timer, TELNETD_CONF_MAX_IDLE_TIME);
#endif /* TELNETD_CONF_MAX_IDLE_TIME */
acked();
}
if(uip_newdata()) {
timer_set(&s.silence_timer, MAX_SILENCE_TIME);
#if TELNETD_CONF_MAX_IDLE_TIME
timer_set(&s.silence_timer, TELNETD_CONF_MAX_IDLE_TIME);
#endif /* TELNETD_CONF_MAX_IDLE_TIME */
newdata();
}
if(uip_rexmit() ||
@ -394,16 +404,20 @@ telnetd_appcall(void *ts)
uip_connected() ||
uip_poll()) {
senddata();
#if TELNETD_CONF_MAX_IDLE_TIME
if(s.numsent > 0) {
timer_set(&s.silence_timer, MAX_SILENCE_TIME);
timer_set(&s.silence_timer, TELNETD_CONF_MAX_IDLE_TIME);
}
#endif /* TELNETD_CONF_MAX_IDLE_TIME */
}
#if TELNETD_CONF_MAX_IDLE_TIME
if(uip_poll()) {
if(timer_expired(&s.silence_timer)) {
uip_close();
tcp_markconn(uip_conn, NULL);
}
}
#endif /* TELNETD_CONF_MAX_IDLE_TIME */
}
}
/*---------------------------------------------------------------------------*/