X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;ds=sidebyside;f=svr4%2Fppp_ahdlc.c;h=ffbe12078fa435a1b7b38af1a98adcd3b2cae75f;hb=db2e55aa1e6ae43e2846039325c22dbb671d2154;hp=dc35dda51c9688feb97a53d8eccc0c66259d1f69;hpb=c2b27e2f4f0a44fb3931383daf61d9e5b6aea053;p=ppp.git diff --git a/svr4/ppp_ahdlc.c b/svr4/ppp_ahdlc.c index dc35dda..ffbe120 100644 --- a/svr4/ppp_ahdlc.c +++ b/svr4/ppp_ahdlc.c @@ -24,7 +24,7 @@ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, * OR MODIFICATIONS. * - * $Id: ppp_ahdlc.c,v 1.3 1995/05/29 06:45:49 paulus Exp $ + * $Id: ppp_ahdlc.c,v 1.5 1995/10/27 03:57:10 paulus Exp $ */ /* @@ -566,6 +566,17 @@ static unsigned paritytab[8] = { 0x69969669, 0x96696996, 0x96696996, 0x69969669 }; +#define UPDATE_FLAGS(c) { \ + if ((c) & 0x80) \ + state->flags |= RCV_B7_1; \ + else \ + state->flags |= RCV_B7_0; \ + if (paritytab[(c) >> 5] & (1 << ((c) & 0x1F))) \ + state->flags |= RCV_ODDP; \ + else \ + state->flags |= RCV_EVNP; \ +} + /* * Process received characters. */ @@ -596,8 +607,7 @@ unstuff_chars(q, mp) } if ((state->flags & (IFLUSH|ESCAPED)) == 0 - && state->inlen >= PPP_HDRLEN - && (om = state->cur_blk) != 0) { + && state->inlen > 0 && (om = state->cur_blk) != 0) { /* * Process bulk chars as quickly as possible. */ @@ -616,26 +626,18 @@ unstuff_chars(q, mp) if (c == PPP_FLAG) break; ++cp; - if (c & 0x80) - state->flags |= RCV_B7_1; - else - state->flags |= RCV_B7_0; - if (paritytab[c >> 5] & (1 << (c & 0x1F))) - state->flags |= RCV_ODDP; - else - state->flags |= RCV_EVNP; + UPDATE_FLAGS(c); if (c == PPP_ESCAPE) { if (extra > 0) { --extra; ++cpend; - } else if (cp >= cpend) { + } + if (cp >= cpend || (c = *cp) == PPP_FLAG) { state->flags |= ESCAPED; break; } - c = *cp; - if (c == PPP_FLAG) - break; ++cp; + UPDATE_FLAGS(c); c ^= PPP_TRANS; } *dp++ = c; @@ -644,19 +646,12 @@ unstuff_chars(q, mp) state->inlen += dp - dp0; state->infcs = fcs; om->b_wptr = dp; - if (cp >= cpend) - continue; /* go back and check cp again */ + if (cp >= mp->b_wptr) + continue; /* advance to the next mblk */ } c = *cp++; - if (c & 0x80) - state->flags |= RCV_B7_1; - else - state->flags |= RCV_B7_0; - if (paritytab[c >> 5] & (1 << (c & 0x1F))) - state->flags |= RCV_ODDP; - else - state->flags |= RCV_EVNP; + UPDATE_FLAGS(c); if (c == PPP_FLAG) { /* * End of a frame. @@ -733,34 +728,26 @@ unstuff_chars(q, mp) state->cur_blk = om; } } - *om->b_wptr++ = c; - ++state->inlen; - state->infcs = PPP_FCS(state->infcs, c); - if (state->inlen == PPP_HDRLEN) { + if (state->inlen == 0) { /* * We don't do address/control & protocol decompression here, - * but we do leave space for the decompressed fields and - * arrange for the info field to start on a word boundary. + * but we try to put the first byte at an offset such that + * the info field starts on a word boundary. The code here + * will do this except for packets with protocol compression + * but not address/control compression. */ - dp = om->b_rptr; - if (PPP_ADDRESS(dp) == PPP_ALLSTATIONS - && PPP_CONTROL(dp) == PPP_UI) - dp += 2; - if ((*dp & 1) == 0) - ++dp; - /* dp is now pointing at the last byte of the ppp protocol field */ - offset = 3 - ((unsigned)dp & 3); - if (offset > 0) { - dp = om->b_wptr; - do { - --dp; - dp[offset] = dp[0]; - } while (dp > om->b_rptr); - om->b_rptr += offset; - om->b_wptr += offset; + if (c != PPP_ALLSTATIONS) { + om->b_wptr += 2; + if (c & 1) + ++om->b_wptr; + om->b_rptr = om->b_wptr; } } + + *om->b_wptr++ = c; + ++state->inlen; + state->infcs = PPP_FCS(state->infcs, c); } }