Merge pull request #1151 from oliverschmidt/master

Allow to configure Telnetd idle timeout.
This commit is contained in:
Oliver Schmidt 2015-07-06 15:05:16 +02:00
commit e7aba9b9ee
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."; "Too many connections, please try again later.";
#endif #endif
#ifndef TELNETD_CONF_MAX_IDLE_TIME
#define TELNETD_CONF_MAX_IDLE_TIME (CLOCK_SECOND * 30)
#endif
struct telnetd_state { struct telnetd_state {
char buf[TELNETD_CONF_LINELEN + 1]; char buf[TELNETD_CONF_LINELEN + 1];
char bufptr; char bufptr;
@ -74,7 +78,9 @@ struct telnetd_state {
#define STATE_DO 4 #define STATE_DO 4
#define STATE_DONT 5 #define STATE_DONT 5
#define STATE_CLOSE 6 #define STATE_CLOSE 6
#if TELNETD_CONF_MAX_IDLE_TIME
struct timer silence_timer; struct timer silence_timer;
#endif /* TELNETD_CONF_MAX_IDLE_TIME */
}; };
static struct telnetd_state s; static struct telnetd_state s;
@ -102,8 +108,6 @@ static struct telnetd_buf buf;
static uint8_t connected; static uint8_t connected;
#define MAX_SILENCE_TIME (CLOCK_SECOND * 30)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
buf_init(struct telnetd_buf *buf) buf_init(struct telnetd_buf *buf)
@ -359,7 +363,9 @@ telnetd_appcall(void *ts)
s.state = STATE_NORMAL; s.state = STATE_NORMAL;
connected = 1; connected = 1;
shell_start(); 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; ts = (char *)0;
} else { } else {
uip_send(telnetd_reject_text, strlen(telnetd_reject_text)); uip_send(telnetd_reject_text, strlen(telnetd_reject_text));
@ -381,11 +387,15 @@ telnetd_appcall(void *ts)
connected = 0; connected = 0;
} }
if(uip_acked()) { 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(); acked();
} }
if(uip_newdata()) { 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(); newdata();
} }
if(uip_rexmit() || if(uip_rexmit() ||
@ -394,16 +404,20 @@ telnetd_appcall(void *ts)
uip_connected() || uip_connected() ||
uip_poll()) { uip_poll()) {
senddata(); senddata();
#if TELNETD_CONF_MAX_IDLE_TIME
if(s.numsent > 0) { 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(uip_poll()) {
if(timer_expired(&s.silence_timer)) { if(timer_expired(&s.silence_timer)) {
uip_close(); uip_close();
tcp_markconn(uip_conn, NULL); tcp_markconn(uip_conn, NULL);
} }
} }
#endif /* TELNETD_CONF_MAX_IDLE_TIME */
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View file

@ -55,6 +55,10 @@
#define IRC_CONF_WIDTH 80 #define IRC_CONF_WIDTH 80
#define IRC_CONF_HEIGHT 23 #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_WEBPAGE_HEIGHT 19
#define WWW_CONF_HISTORY_SIZE 4 #define WWW_CONF_HISTORY_SIZE 4
#define WWW_CONF_WGET_EXEC(url) exec("wget", url) #define WWW_CONF_WGET_EXEC(url) exec("wget", url)

View file

@ -60,6 +60,10 @@
#define IRC_CONF_WIDTH 40 #define IRC_CONF_WIDTH 40
#define IRC_CONF_HEIGHT 23 #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_WIDTH 40
#define WWW_CONF_WEBPAGE_HEIGHT 19 #define WWW_CONF_WEBPAGE_HEIGHT 19
#define WWW_CONF_HISTORY_SIZE 4 #define WWW_CONF_HISTORY_SIZE 4

View file

@ -65,6 +65,10 @@
#define IRC_CONF_WIDTH 80 #define IRC_CONF_WIDTH 80
#define IRC_CONF_HEIGHT 24 #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_HISTORY_SIZE 0
#define WWW_CONF_FORMS 0 #define WWW_CONF_FORMS 0
#define WWW_CONF_PAGEATTRIB_SIZE 1500 #define WWW_CONF_PAGEATTRIB_SIZE 1500

View file

@ -65,6 +65,10 @@
#define IRC_CONF_WIDTH 40 #define IRC_CONF_WIDTH 40
#define IRC_CONF_HEIGHT 24 #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_WEBPAGE_WIDTH 40
#define WWW_CONF_HISTORY_SIZE 4 #define WWW_CONF_HISTORY_SIZE 4
#define WWW_CONF_WGET_EXEC(url) exec("wget", url) #define WWW_CONF_WGET_EXEC(url) exec("wget", url)

View file

@ -171,8 +171,9 @@ typedef unsigned short uip_stats_t;
#define SHELL_GUI_CONF_YSIZE 30 #define SHELL_GUI_CONF_YSIZE 30
#define TELNETD_CONF_MAX_IDLE_TIME 300
#ifdef PLATFORM_BUILD #ifdef PLATFORM_BUILD
#define TELNETD_CONF_GUI 1 #define TELNETD_CONF_GUI 1
#endif /* PLATFORM_BUILD */ #endif /* PLATFORM_BUILD */