]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
use HDLC_OUT macro
authorDaniel Lenski <dlenski@gmail.com>
Wed, 13 May 2020 06:38:51 +0000 (23:38 -0700)
committerDaniel Lenski <dlenski@gmail.com>
Wed, 13 May 2020 06:53:05 +0000 (23:53 -0700)
Signed-off-by: Daniel Lenski <dlenski@gmail.com>
ppp.c

diff --git a/ppp.c b/ppp.c
index ac483acea542ed88f6d8f5c4e1cd236d14b504e6..5e234730ba734e8bdfdc3657ffeb167c03571dee 100644 (file)
--- a/ppp.c
+++ b/ppp.c
@@ -59,6 +59,13 @@ static const uint16_t fcstab[256] = {
 
 #define foldfcs(fcs, c) (  ( (fcs) >> 8 ) ^ fcstab[(fcs ^ (c)) & 0xff] )
 #define NEED_ESCAPE(c, map) ( (((c) < 0x20) && (map && (1UL << (c)))) || ((c) == 0x7d) || ((c) == 0x7e) )
+#define HDLC_OUT(outp, c, map) do {   \
+       if (NEED_ESCAPE((c), map)) {  \
+               *outp++ = 0x7d;       \
+               *outp++ = (c) ^ 0x20; \
+       } else                        \
+               *outp++ = (c);        \
+} while (0)
 
 static struct pkt *hdlc_into_new_pkt(struct openconnect_info *vpninfo, unsigned char *bytes, int len, int asyncmap)
 {
@@ -74,27 +81,13 @@ static struct pkt *hdlc_into_new_pkt(struct openconnect_info *vpninfo, unsigned
 
        for (; inp < endp; inp++) {
                fcs = foldfcs(fcs, *inp);
-               if (NEED_ESCAPE(*inp, asyncmap)) {
-                       *outp++ = 0x7d;
-                       *outp++ = *inp ^ 0x20;
-               } else
-                       *outp++ = *inp;
+               HDLC_OUT(outp, *inp, asyncmap);
        }
 
        /* Append FCS, escaped, little-endian */
        fcs ^= 0xffff;
-       if (NEED_ESCAPE(fcs & 0xff, asyncmap)) {
-               *outp++ = 0x7d;
-               *outp++ = (fcs & 0xff) ^ 0x20;
-       } else
-               *outp++ = fcs & 0xff;
-
-       fcs >>= 8;
-       if (NEED_ESCAPE(fcs, asyncmap)) {
-               *outp++ = 0x7d;
-               *outp++ = fcs ^ 0x20;
-       } else
-               *outp++ = fcs;
+       HDLC_OUT(outp, fcs & 0xff, asyncmap);
+       HDLC_OUT(outp, fcs >> 8, asyncmap);
 
        *outp++ = 0x7e;
        p->ppp.hlen = 0;