Telnetd improvement: allow specifying a maximum silence time and kill the connection after that time. This is to avoid the telnet connection getting stuck forever if the connecting host reboots.
This commit is contained in:
parent
0a135eeba1
commit
0b882cd516
|
@ -72,8 +72,8 @@ struct telnetd_state {
|
|||
#define STATE_WONT 3
|
||||
#define STATE_DO 4
|
||||
#define STATE_DONT 5
|
||||
|
||||
#define STATE_CLOSE 6
|
||||
struct timer silence_timer;
|
||||
};
|
||||
static struct telnetd_state s;
|
||||
|
||||
|
@ -101,6 +101,8 @@ static struct telnetd_buf buf;
|
|||
|
||||
static uint8_t connected;
|
||||
|
||||
#define MAX_SILENCE_TIME (CLOCK_SECOND * 30)
|
||||
|
||||
#define MIN(a, b) ((a) < (b)? (a): (b))
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
|
@ -357,6 +359,7 @@ telnetd_appcall(void *ts)
|
|||
s.state = STATE_NORMAL;
|
||||
connected = 1;
|
||||
shell_start();
|
||||
timer_set(&s.silence_timer, MAX_SILENCE_TIME);
|
||||
ts = (char *)0;
|
||||
} else {
|
||||
uip_send(telnetd_reject_text, strlen(telnetd_reject_text));
|
||||
|
@ -378,9 +381,11 @@ telnetd_appcall(void *ts)
|
|||
connected = 0;
|
||||
}
|
||||
if(uip_acked()) {
|
||||
timer_set(&s.silence_timer, MAX_SILENCE_TIME);
|
||||
acked();
|
||||
}
|
||||
if(uip_newdata()) {
|
||||
timer_set(&s.silence_timer, MAX_SILENCE_TIME);
|
||||
newdata();
|
||||
}
|
||||
if(uip_rexmit() ||
|
||||
|
@ -389,15 +394,22 @@ telnetd_appcall(void *ts)
|
|||
uip_connected() ||
|
||||
uip_poll()) {
|
||||
senddata();
|
||||
if(s.numsent > 0) {
|
||||
timer_set(&s.silence_timer, MAX_SILENCE_TIME);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(uip_poll()) {
|
||||
if(ts == (char *)10) {
|
||||
if(timer_expired(&s.silence_timer)) {
|
||||
uip_close();
|
||||
} else {
|
||||
tcp_markconn(uip_conn, (char *)ts + 1);
|
||||
tcp_markconn(uip_conn, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
telnetd_init(void)
|
||||
{
|
||||
process_start(&telnetd_process, NULL);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -38,6 +38,8 @@
|
|||
|
||||
PROCESS_NAME(telnetd_process);
|
||||
|
||||
void telnetd_init(void);
|
||||
|
||||
void telnetd_gui_eventhandler(process_event_t ev, process_data_t data);
|
||||
void telnetd_appcall(void *data);
|
||||
void telnetd_gui_init(void);
|
||||
|
|
Loading…
Reference in a new issue