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.";
#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 */
}
}
/*---------------------------------------------------------------------------*/

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -171,6 +171,7 @@ 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
#endif /* PLATFORM_BUILD */