From a30e2e0045c5cfa3b520d40d7d57fb2b3d848c83 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Mon, 6 Jul 2015 12:25:20 +0200 Subject: [PATCH] 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). --- apps/telnetd/telnetd.c | 26 ++++++++++++++++++++------ platform/apple2enh/contiki-conf.h | 4 ++++ platform/atarixl/contiki-conf.h | 4 ++++ platform/c128/contiki-conf.h | 4 ++++ platform/c64/contiki-conf.h | 4 ++++ platform/win32/contiki-conf.h | 3 ++- 6 files changed, 38 insertions(+), 7 deletions(-) diff --git a/apps/telnetd/telnetd.c b/apps/telnetd/telnetd.c index c168b19b8..37c3fd6cc 100644 --- a/apps/telnetd/telnetd.c +++ b/apps/telnetd/telnetd.c @@ -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 */ } } /*---------------------------------------------------------------------------*/ diff --git a/platform/apple2enh/contiki-conf.h b/platform/apple2enh/contiki-conf.h index 58316ca6d..2ad5ceb7f 100644 --- a/platform/apple2enh/contiki-conf.h +++ b/platform/apple2enh/contiki-conf.h @@ -55,6 +55,10 @@ #define IRC_CONF_WIDTH 80 #define IRC_CONF_HEIGHT 23 +#ifndef TELNETD_CONF_MAX_IDLE_TIME +#define TELNETD_CONF_MAX_IDLE_TIME 300 +#endif + #define WWW_CONF_WEBPAGE_HEIGHT 19 #define WWW_CONF_HISTORY_SIZE 4 #define WWW_CONF_WGET_EXEC(url) exec("wget", url) diff --git a/platform/atarixl/contiki-conf.h b/platform/atarixl/contiki-conf.h index 967112637..8c43fdcae 100644 --- a/platform/atarixl/contiki-conf.h +++ b/platform/atarixl/contiki-conf.h @@ -60,6 +60,10 @@ #define IRC_CONF_WIDTH 40 #define IRC_CONF_HEIGHT 23 +#ifndef TELNETD_CONF_MAX_IDLE_TIME +#define TELNETD_CONF_MAX_IDLE_TIME 300 +#endif + #define WWW_CONF_WEBPAGE_WIDTH 40 #define WWW_CONF_WEBPAGE_HEIGHT 19 #define WWW_CONF_HISTORY_SIZE 4 diff --git a/platform/c128/contiki-conf.h b/platform/c128/contiki-conf.h index 2bad0a6e6..53a6878f9 100644 --- a/platform/c128/contiki-conf.h +++ b/platform/c128/contiki-conf.h @@ -65,6 +65,10 @@ #define IRC_CONF_WIDTH 80 #define IRC_CONF_HEIGHT 24 +#ifndef TELNETD_CONF_MAX_IDLE_TIME +#define TELNETD_CONF_MAX_IDLE_TIME 300 +#endif + #define WWW_CONF_HISTORY_SIZE 0 #define WWW_CONF_FORMS 0 #define WWW_CONF_PAGEATTRIB_SIZE 1500 diff --git a/platform/c64/contiki-conf.h b/platform/c64/contiki-conf.h index 868d4dcd1..bfaf1c956 100644 --- a/platform/c64/contiki-conf.h +++ b/platform/c64/contiki-conf.h @@ -65,6 +65,10 @@ #define IRC_CONF_WIDTH 40 #define IRC_CONF_HEIGHT 24 +#ifndef TELNETD_CONF_MAX_IDLE_TIME +#define TELNETD_CONF_MAX_IDLE_TIME 300 +#endif + #define WWW_CONF_WEBPAGE_WIDTH 40 #define WWW_CONF_HISTORY_SIZE 4 #define WWW_CONF_WGET_EXEC(url) exec("wget", url) diff --git a/platform/win32/contiki-conf.h b/platform/win32/contiki-conf.h index 81d6b9fcd..060648c36 100644 --- a/platform/win32/contiki-conf.h +++ b/platform/win32/contiki-conf.h @@ -171,8 +171,9 @@ typedef unsigned short uip_stats_t; #define SHELL_GUI_CONF_YSIZE 30 +#define TELNETD_CONF_MAX_IDLE_TIME 300 #ifdef PLATFORM_BUILD -#define TELNETD_CONF_GUI 1 +#define TELNETD_CONF_GUI 1 #endif /* PLATFORM_BUILD */