From f753a728dd28ff65af3d4dd01cdad221dbf62eeb Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sat, 18 Apr 2015 01:10:25 +0200 Subject: [PATCH] PPP, CCP, compile-out a bit more MPPE code if MPPE is disabled --- src/include/netif/ppp/ccp.h | 2 ++ src/netif/ppp/ccp.c | 28 ++++++++++++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/include/netif/ppp/ccp.h b/src/include/netif/ppp/ccp.h index ad48129c..a09cb1e7 100644 --- a/src/include/netif/ppp/ccp.h +++ b/src/include/netif/ppp/ccp.h @@ -123,7 +123,9 @@ typedef struct ccp_options { unsigned int predictor_2 :1; /* do Predictor-2? */ unsigned int :2; /* 2 bit of padding to round out to 8 bits */ +#if MPPE_SUPPORT u8_t mppe; /* MPPE bitfield */ +#endif /* MPPE_SUPPORT */ u_short bsd_bits; /* # bits/code for BSD Compress */ u_short deflate_size; /* lg(window size) for Deflate */ short method; /* code for chosen compression method */ diff --git a/src/netif/ppp/ccp.c b/src/netif/ppp/ccp.c index f88cc65b..f22e64c7 100644 --- a/src/netif/ppp/ccp.c +++ b/src/netif/ppp/ccp.c @@ -243,9 +243,14 @@ static const fsm_callbacks ccp_callbacks = { /* * Do we want / did we get any compression? */ -#define ANY_COMPRESS(opt) ((opt)->deflate || (opt)->bsd_compress \ - || (opt)->predictor_1 || (opt)->predictor_2 \ - || (opt)->mppe) +static int ccp_anycompress(ccp_options *opt) { + return ((opt)->deflate || (opt)->bsd_compress + || (opt)->predictor_1 || (opt)->predictor_2 +#if MPPE_SUPPORT + || (opt)->mppe +#endif /* MPPE_SUPPORT */ + ); +} /* * Local state (mainly for handling reset-reqs and reset-acks). @@ -400,7 +405,7 @@ static void ccp_open(ppp_pcb *pcb) { * deciding whether to open in silent mode. */ ccp_resetci(f); - if (!ANY_COMPRESS(go)) + if (!ccp_anycompress(go)) f->flags |= OPT_SILENT; fsm_open(f); @@ -459,7 +464,7 @@ static void ccp_input(ppp_pcb *pcb, u_char *p, int len) { * close CCP. */ if (oldstate == PPP_FSM_REQSENT && p[0] == TERMACK - && !ANY_COMPRESS(go)) + && !ccp_anycompress(go)) ccp_close(pcb, "No compression negotiated"); } @@ -706,7 +711,10 @@ static int ccp_cilen(fsm *f) { + (go->deflate && go->deflate_draft? CILEN_DEFLATE: 0) + (go->predictor_1? CILEN_PREDICTOR_1: 0) + (go->predictor_2? CILEN_PREDICTOR_2: 0) - + (go->mppe? CILEN_MPPE: 0); +#if MPPE_SUPPORT + + (go->mppe? CILEN_MPPE: 0) +#endif /* MPPE_SUPPORT */ + ; } /* @@ -1316,7 +1324,7 @@ static int ccp_reqci(fsm *f, u_char *p, int *lenp, int dont_nak) { static const char *method_name(ccp_options *opt, ccp_options *opt2) { static char result[64]; - if (!ANY_COMPRESS(opt)) + if (!ccp_anycompress(opt)) return "(none)"; switch (opt->method) { #if MPPE_SUPPORT @@ -1382,8 +1390,8 @@ static void ccp_up(fsm *f) { char method1[64]; ccp_flags_set(pcb, 1, 1); - if (ANY_COMPRESS(go)) { - if (ANY_COMPRESS(ho)) { + if (ccp_anycompress(go)) { + if (ccp_anycompress(ho)) { if (go->method == ho->method) { ppp_notice("%s compression enabled", method_name(go, ho)); } else { @@ -1393,7 +1401,7 @@ static void ccp_up(fsm *f) { } } else ppp_notice("%s receive compression enabled", method_name(go, NULL)); - } else if (ANY_COMPRESS(ho)) + } else if (ccp_anycompress(ho)) ppp_notice("%s transmit compression enabled", method_name(ho, NULL)); #if MPPE_SUPPORT if (go->mppe) {