From: Mark Wooding Date: Sat, 22 May 2010 11:04:06 +0000 (+0100) Subject: server/tun-slip: Refactor state handling somewhat. X-Git-Tag: 1.0.0pre10~6 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/tripe/commitdiff_plain/574318e731155b6922d7b1dba1461f30ea664e9f server/tun-slip: Refactor state handling somewhat. Introduce a new ST_MASK which masks off the state-machine bits. Use this when reading SL_END or when setting ST_EOF, so as to preserve any other state bits which might happen to have been set. Not that I'm promising anything... --- diff --git a/server/tun-slip.c b/server/tun-slip.c index 609829f5..993aca9d 100644 --- a/server/tun-slip.c +++ b/server/tun-slip.c @@ -50,6 +50,7 @@ struct tunnel { unsigned st; /* Current parser state */ # define ST_ESC 1u /* Last saw an escape character */ # define ST_BAD 2u /* This packet is malformed */ +# define ST_MASK 3u /* Mask for the above bits */ # define ST_EOF 4u /* File descriptor reported EOF */ size_t n; /* Number of bytes used in buffer */ octet buf[PKBUFSZ]; /* Buffer for incoming data */ @@ -99,7 +100,7 @@ static void t_read(int fd, unsigned mode, void *v) } if (!n) { a_warn("TUN", "%s", p_ifname(t->p), "slip", "eof", A_END); - t->st = ST_EOF; + t->st = (t->st & ~ST_MASK) | ST_EOF; sel_rmfile(&t->f); return; } @@ -133,7 +134,7 @@ static void t_read(int fd, unsigned mode, void *v) p_tun(t->p, &b); } q = t->buf; - st &= ~(ST_ESC | ST_BAD); + st &= ~ST_MASK; break; case SL_ESC: if ((st & ST_ESC) && !(st & ST_BAD)) {