warp-vpn

point to point VPN implementation
git clone git://git.2f30.org/warp-vpn
Log | Files | Refs | README

commit ce1ba4c3c02baff82aa025f1091c71ab24d6f882
parent c1abd8c852684b34530c53c8dd2d00fc720e2645
Author: sin <sin@2f30.org>
Date:   Sat, 30 Apr 2016 18:30:43 +0100

Rename state to rxstate along with associated enum

Diffstat:
Mnetpkt.c | 50+++++++++++++++++++++++++-------------------------
1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/netpkt.c b/netpkt.c @@ -11,13 +11,13 @@ /* the various states the input handler can be in */ enum { - INPUTINITIAL, - INPUTNONCE, - INPUTHDR, - INPUTPAYLOAD, - INPUTTAG, - INPUTDECRYPT, - INPUTDISCARD + RXINITIAL, + RXNONCE, + RXHDR, + RXPAYLOAD, + RXTAG, + RXDECRYPT, + RXDISCARD }; /* output buffer for writing data to the network */ @@ -39,7 +39,7 @@ static size_t noncelen; static size_t taglen; /* state tracking for input handling */ -static int state; +static int rxstate; int netwrite(int fd, unsigned char *pt, size_t ptlen, size_t *outlen) @@ -91,23 +91,23 @@ netread(int fd, unsigned char *pt, size_t ptlen, size_t *outlen) } for (;;) { - switch (state) { - case INPUTINITIAL: + switch (rxstate) { + case RXINITIAL: rbuftotal = 0; rbufrem = noncelen; - state = INPUTNONCE; + rxstate = RXNONCE; break; - case INPUTNONCE: + case RXNONCE: if ((n = read(fd, rbuf + rbuftotal, rbufrem)) <= 0) goto out; rbuftotal += n; rbufrem -= n; if (rbufrem == 0) { rbufrem = HDRLEN; - state = INPUTHDR; + rxstate = RXHDR; } break; - case INPUTHDR: + case RXHDR: if ((n = read(fd, rbuf + rbuftotal, rbufrem)) <= 0) goto out; rbuftotal += n; @@ -115,33 +115,33 @@ netread(int fd, unsigned char *pt, size_t ptlen, size_t *outlen) if (rbufrem == 0) { ctlen = unpack16(&rbuf[noncelen]); if (ctlen > ptlen) { - state = INPUTDISCARD; + rxstate = RXDISCARD; } else { rbufrem = ctlen; - state = INPUTPAYLOAD; + rxstate = RXPAYLOAD; } } break; - case INPUTPAYLOAD: + case RXPAYLOAD: if ((n = read(fd, rbuf + rbuftotal, rbufrem)) <= 0) goto out; rbuftotal += n; rbufrem -= n; if (rbufrem == 0) { rbufrem = taglen; - state = INPUTTAG; + rxstate = RXTAG; } break; - case INPUTTAG: + case RXTAG: if ((n = read(fd, rbuf + rbuftotal, rbufrem)) <= 0) goto out; rbuftotal += n; rbufrem -= n; if (rbufrem == 0) - state = INPUTDECRYPT; + rxstate = RXDECRYPT; break; - case INPUTDECRYPT: - state = INPUTINITIAL; + case RXDECRYPT: + rxstate = RXINITIAL; if (!cryptoopen(pt, outlen, ptlen, rbuf, noncelen, &rbuf[noncelen + HDRLEN], rbuftotal - noncelen - HDRLEN, @@ -150,8 +150,8 @@ netread(int fd, unsigned char *pt, size_t ptlen, size_t *outlen) return PKTPARTIAL; } return PKTCOMPLETE; - case INPUTDISCARD: - state = INPUTINITIAL; + case RXDISCARD: + rxstate = RXINITIAL; for (;;) if ((n = read(fd, rbuf, maxbuflen)) <= 0) goto out; @@ -168,7 +168,7 @@ out: void netreset(void) { - state = INPUTINITIAL; + rxstate = RXINITIAL; } void