From b553df860cedb95ceb8f4b54a9ecc2cd1884ca38 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sat, 18 Apr 2015 02:02:00 +0200 Subject: [PATCH] PPP, CCP, deflate, BSD compress, predictor 1 & 2 are now optional at compile time --- src/include/netif/ppp/ccp.h | 24 +++++++++ src/include/netif/ppp/ppp.h | 11 ++++ src/netif/ppp/ccp.c | 105 ++++++++++++++++++++++++++++++++---- 3 files changed, 130 insertions(+), 10 deletions(-) diff --git a/src/include/netif/ppp/ccp.h b/src/include/netif/ppp/ccp.h index a09cb1e7..4c9c88aa 100644 --- a/src/include/netif/ppp/ccp.h +++ b/src/include/netif/ppp/ccp.h @@ -66,6 +66,7 @@ #define CCP_OPT_LENGTH(dp) ((dp)[1]) #define CCP_OPT_MINLEN 2 +#if BSDCOMPRESS_SUPPORT /* * Definitions for BSD-Compress. */ @@ -81,7 +82,9 @@ #define BSD_MIN_BITS 9 /* smallest code size supported */ #define BSD_MAX_BITS 15 /* largest code size supported */ +#endif /* BSDCOMPRESS_SUPPORT */ +#if DEFLATE_SUPPORT /* * Definitions for Deflate. */ @@ -97,14 +100,18 @@ #define DEFLATE_METHOD(x) ((x) & 0x0F) #define DEFLATE_MAKE_OPT(w) ((((w) - 8) << 4) + DEFLATE_METHOD_VAL) #define DEFLATE_CHK_SEQUENCE 0 +#endif /* DEFLATE_SUPPORT */ +#if MPPE_SUPPORT /* * Definitions for MPPE. */ #define CI_MPPE 18 /* config option for MPPE */ #define CILEN_MPPE 6 /* length of config option */ +#endif /* MPPE_SUPPORT */ +#if PREDICTOR_SUPPORT /* * Definitions for other, as yet unsupported, compression methods. */ @@ -113,21 +120,38 @@ #define CILEN_PREDICTOR_1 2 /* length of its config option */ #define CI_PREDICTOR_2 2 /* config option for Predictor-2 */ #define CILEN_PREDICTOR_2 2 /* length of its config option */ +#endif /* PREDICTOR_SUPPORT */ typedef struct ccp_options { +#if DEFLATE_SUPPORT unsigned int deflate :1; /* do Deflate? */ unsigned int deflate_correct :1; /* use correct code for deflate? */ unsigned int deflate_draft :1; /* use draft RFC code for deflate? */ +#else /* DEFLATE_SUPPORT */ + unsigned int :3; /* 3 bit of padding */ +#endif /* DEFLATE_SUPPORT */ +#if BSDCOMPRESS_SUPPORT unsigned int bsd_compress :1; /* do BSD Compress? */ +#else /* BSDCOMPRESS_SUPPORT */ + unsigned int :1; /* 1 bit of padding */ +#endif /* BSDCOMPRESS_SUPPORT */ +#if PREDICTOR_SUPPORT unsigned int predictor_1 :1; /* do Predictor-1? */ unsigned int predictor_2 :1; /* do Predictor-2? */ +#else /* PREDICTOR_SUPPORT */ + unsigned int :2; /* 2 bit of padding */ +#endif /* PREDICTOR_SUPPORT */ unsigned int :2; /* 2 bit of padding to round out to 8 bits */ #if MPPE_SUPPORT u8_t mppe; /* MPPE bitfield */ #endif /* MPPE_SUPPORT */ +#if BSDCOMPRESS_SUPPORT u_short bsd_bits; /* # bits/code for BSD Compress */ +#endif /* BSDCOMPRESS_SUPPORT */ +#if DEFLATE_SUPPORT u_short deflate_size; /* lg(window size) for Deflate */ +#endif /* DEFLATE_SUPPORT */ short method; /* code for chosen compression method */ } ccp_options; diff --git a/src/include/netif/ppp/ppp.h b/src/include/netif/ppp/ppp.h index 53c7554d..0f71c15b 100644 --- a/src/include/netif/ppp/ppp.h +++ b/src/include/netif/ppp/ppp.h @@ -85,6 +85,17 @@ #define PPP_STATS_SUPPORT 0 #endif +#ifndef DEFLATE_SUPPORT +#define DEFLATE_SUPPORT 0 +#endif + +#ifndef BSDCOMPRESS_SUPPORT +#define BSDCOMPRESS_SUPPORT 0 +#endif + +#ifndef PREDICTOR_SUPPORT +#define PREDICTOR_SUPPORT 0 +#endif /************************* *** PUBLIC DEFINITIONS *** diff --git a/src/netif/ppp/ccp.c b/src/netif/ppp/ccp.c index f22e64c7..0fc5a4a7 100644 --- a/src/netif/ppp/ccp.c +++ b/src/netif/ppp/ccp.c @@ -244,12 +244,20 @@ static const fsm_callbacks ccp_callbacks = { * Do we want / did we get any compression? */ static int ccp_anycompress(ccp_options *opt) { - return ((opt)->deflate || (opt)->bsd_compress - || (opt)->predictor_1 || (opt)->predictor_2 + return (0 +#if DEFLATE_SUPPORT + || (opt)->deflate +#endif /* DEFLATE_SUPPORT */ +#if BSDCOMPRESS_SUPPORT + || (opt)->bsd_compress +#endif /* BSDCOMPRESS_SUPPORT */ +#if PREDICTOR_SUPPORT + || (opt)->predictor_1 || (opt)->predictor_2 +#endif /* PREDICTOR_SUPPORT */ #if MPPE_SUPPORT - || (opt)->mppe + || (opt)->mppe #endif /* MPPE_SUPPORT */ - ); + ); } /* @@ -373,6 +381,7 @@ static void ccp_init(ppp_pcb *pcb) { memset(ao, 0, sizeof(*ao)); memset(ho, 0, sizeof(*ho)); +#if DEFLATE_SUPPORT wo->deflate = 1; wo->deflate_size = DEFLATE_MAX_SIZE; wo->deflate_correct = 1; @@ -381,13 +390,18 @@ static void ccp_init(ppp_pcb *pcb) { ao->deflate_size = DEFLATE_MAX_SIZE; ao->deflate_correct = 1; ao->deflate_draft = 1; +#endif /* DEFLATE_SUPPORT */ +#if BSDCOMPRESS_SUPPORT wo->bsd_compress = 1; wo->bsd_bits = BSD_MAX_BITS; ao->bsd_compress = 1; ao->bsd_bits = BSD_MAX_BITS; +#endif /* BSDCOMPRESS_SUPPORT */ +#if PREDICTOR_SUPPORT ao->predictor_1 = 1; +#endif /* PREDICTOR_SUPPORT */ } /* @@ -528,7 +542,9 @@ static void ccp_resetci(fsm *f) { ccp_options *go = &pcb->ccp_gotoptions; ccp_options *wo = &pcb->ccp_wantoptions; u_char opt_buf[CCP_MAX_OPTION_LENGTH]; +#if DEFLATE_SUPPORT || BSDCOMPRESS_SUPPORT int res; +#endif /* DEFLATE_SUPPORT || BSDCOMPRESS_SUPPORT */ *go = *wo; pcb->all_rejected = 0; @@ -599,10 +615,16 @@ static void ccp_resetci(fsm *f) { /* sync options */ ao->mppe = go->mppe; /* MPPE is not compatible with other compression types */ +#if BSDCOMPRESS_SUPPORT ao->bsd_compress = go->bsd_compress = 0; +#endif /* BSDCOMPRESS_SUPPORT */ +#if PREDICTOR_SUPPORT ao->predictor_1 = go->predictor_1 = 0; ao->predictor_2 = go->predictor_2 = 0; +#endif /* PREDICTOR_SUPPORT */ +#if DEFLATE_SUPPORT ao->deflate = go->deflate = 0; +#endif /* DEFLATE_SUPPORT */ } #endif /* MPPE_SUPPORT */ @@ -622,6 +644,7 @@ static void ccp_resetci(fsm *f) { } } #endif /* MPPE_SUPPORT */ +#if BSDCOMPRESS_SUPPORT if (go->bsd_compress) { opt_buf[0] = CI_BSD_COMPRESS; opt_buf[1] = CILEN_BSD_COMPRESS; @@ -641,6 +664,8 @@ static void ccp_resetci(fsm *f) { go->bsd_bits--; } } +#endif /* BSDCOMPRESS_SUPPORT */ +#if DEFLATE_SUPPORT if (go->deflate) { if (go->deflate_correct) { opt_buf[0] = CI_DEFLATE; @@ -685,6 +710,8 @@ static void ccp_resetci(fsm *f) { if (!go->deflate_correct && !go->deflate_draft) go->deflate = 0; } +#endif /* DEFLATE_SUPPORT */ +#if PREDICTOR_SUPPORT if (go->predictor_1) { opt_buf[0] = CI_PREDICTOR_1; opt_buf[1] = CILEN_PREDICTOR_1; @@ -697,6 +724,7 @@ static void ccp_resetci(fsm *f) { if (ccp_test(pcb, opt_buf, CILEN_PREDICTOR_2, 0) <= 0) go->predictor_2 = 0; } +#endif /* PREDICTOR_SUPPORT */ } /* @@ -706,11 +734,18 @@ static int ccp_cilen(fsm *f) { ppp_pcb *pcb = f->pcb; ccp_options *go = &pcb->ccp_gotoptions; - return (go->bsd_compress? CILEN_BSD_COMPRESS: 0) + return 0 +#if BSDCOMPRESS_SUPPORT + + (go->bsd_compress? CILEN_BSD_COMPRESS: 0) +#endif /* BSDCOMPRESS_SUPPORT */ +#if DEFLATE_SUPPORT + (go->deflate && go->deflate_correct? CILEN_DEFLATE: 0) + (go->deflate && go->deflate_draft? CILEN_DEFLATE: 0) +#endif /* DEFLATE_SUPPORT */ +#if PREDICTOR_SUPPORT + (go->predictor_1? CILEN_PREDICTOR_1: 0) + (go->predictor_2? CILEN_PREDICTOR_2: 0) +#endif /* PREDICTOR_SUPPORT */ #if MPPE_SUPPORT + (go->mppe? CILEN_MPPE: 0) #endif /* MPPE_SUPPORT */ @@ -743,6 +778,7 @@ static void ccp_addci(fsm *f, u_char *p, int *lenp) { p += CILEN_MPPE; } #endif /* MPPE_SUPPORT */ +#if DEFLATE_SUPPORT if (go->deflate) { if (go->deflate_correct) { p[0] = CI_DEFLATE; @@ -759,12 +795,16 @@ static void ccp_addci(fsm *f, u_char *p, int *lenp) { p += CILEN_DEFLATE; } } +#endif /* DEFLATE_SUPPORT */ +#if BSDCOMPRESS_SUPPORT if (go->bsd_compress) { p[0] = CI_BSD_COMPRESS; p[1] = CILEN_BSD_COMPRESS; p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits); p += CILEN_BSD_COMPRESS; } +#endif /* BSDCOMPRESS_SUPPORT */ +#if PREDICTOR_SUPPORT /* XXX Should Predictor 2 be preferable to Predictor 1? */ if (go->predictor_1) { p[0] = CI_PREDICTOR_1; @@ -776,6 +816,7 @@ static void ccp_addci(fsm *f, u_char *p, int *lenp) { p[1] = CILEN_PREDICTOR_2; p += CILEN_PREDICTOR_2; } +#endif /* PREDICTOR_SUPPORT */ go->method = (p > p0)? p0[0]: -1; @@ -789,7 +830,9 @@ static void ccp_addci(fsm *f, u_char *p, int *lenp) { static int ccp_ackci(fsm *f, u_char *p, int len) { ppp_pcb *pcb = f->pcb; ccp_options *go = &pcb->ccp_gotoptions; +#if BSDCOMPRESS_SUPPORT || PREDICTOR_SUPPORT u_char *p0 = p; +#endif /* BSDCOMPRESS_SUPPORT || PREDICTOR_SUPPORT */ #if MPPE_SUPPORT if (go->mppe) { @@ -807,6 +850,7 @@ static int ccp_ackci(fsm *f, u_char *p, int len) { return 1; } #endif /* MPPE_SUPPORT */ +#if DEFLATE_SUPPORT if (go->deflate) { if (len < CILEN_DEFLATE || p[0] != (go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT) @@ -830,6 +874,8 @@ static int ccp_ackci(fsm *f, u_char *p, int len) { len -= CILEN_DEFLATE; } } +#endif /* DEFLATE_SUPPORT */ +#if BSDCOMPRESS_SUPPORT if (go->bsd_compress) { if (len < CILEN_BSD_COMPRESS || p[0] != CI_BSD_COMPRESS || p[1] != CILEN_BSD_COMPRESS @@ -841,6 +887,8 @@ static int ccp_ackci(fsm *f, u_char *p, int len) { if (p == p0 && len == 0) return 1; } +#endif /* BSDCOMPRESS_SUPPORT */ +#if PREDICTOR_SUPPORT if (go->predictor_1) { if (len < CILEN_PREDICTOR_1 || p[0] != CI_PREDICTOR_1 || p[1] != CILEN_PREDICTOR_1) @@ -861,6 +909,7 @@ static int ccp_ackci(fsm *f, u_char *p, int len) { if (p == p0 && len == 0) return 1; } +#endif /* PREDICTOR_SUPPORT */ if (len != 0) return 0; @@ -877,6 +926,10 @@ static int ccp_nakci(fsm *f, u_char *p, int len, int treat_as_reject) { ccp_options no; /* options we've seen already */ ccp_options try_; /* options to ask for next time */ LWIP_UNUSED_ARG(treat_as_reject); +#if !MPPE_SUPPORT && !DEFLATE_SUPPORT && !BSDCOMPRESS_SUPPORT + LWIP_UNUSED_ARG(p); + LWIP_UNUSED_ARG(len); +#endif /* !MPPE_SUPPORT && !DEFLATE_SUPPORT && !BSDCOMPRESS_SUPPORT */ memset(&no, 0, sizeof(no)); try_ = *go; @@ -904,6 +957,7 @@ static int ccp_nakci(fsm *f, u_char *p, int len, int treat_as_reject) { } } #endif /* MPPE_SUPPORT */ +#if DEFLATE_SUPPORT if (go->deflate && len >= CILEN_DEFLATE && p[0] == (go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT) && p[1] == CILEN_DEFLATE) { @@ -927,7 +981,8 @@ static int ccp_nakci(fsm *f, u_char *p, int len, int treat_as_reject) { len -= CILEN_DEFLATE; } } - +#endif /* DEFLATE_SUPPORT */ +#if BSDCOMPRESS_SUPPORT if (go->bsd_compress && len >= CILEN_BSD_COMPRESS && p[0] == CI_BSD_COMPRESS && p[1] == CILEN_BSD_COMPRESS) { no.bsd_compress = 1; @@ -942,6 +997,7 @@ static int ccp_nakci(fsm *f, u_char *p, int len, int treat_as_reject) { p += CILEN_BSD_COMPRESS; len -= CILEN_BSD_COMPRESS; } +#endif /* BSDCOMPRESS_SUPPORT */ /* * Predictor-1 and 2 have no options, so they can't be Naked. @@ -980,6 +1036,7 @@ static int ccp_rejci(fsm *f, u_char *p, int len) { len -= CILEN_MPPE; } #endif /* MPPE_SUPPORT */ +#if DEFLATE_SUPPORT if (go->deflate_correct && len >= CILEN_DEFLATE && p[0] == CI_DEFLATE && p[1] == CILEN_DEFLATE) { if (p[2] != DEFLATE_MAKE_OPT(go->deflate_size) @@ -1000,6 +1057,8 @@ static int ccp_rejci(fsm *f, u_char *p, int len) { } if (!try_.deflate_correct && !try_.deflate_draft) try_.deflate = 0; +#endif /* DEFLATE_SUPPORT */ +#if BSDCOMPRESS_SUPPORT if (go->bsd_compress && len >= CILEN_BSD_COMPRESS && p[0] == CI_BSD_COMPRESS && p[1] == CILEN_BSD_COMPRESS) { if (p[2] != BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits)) @@ -1008,6 +1067,8 @@ static int ccp_rejci(fsm *f, u_char *p, int len) { p += CILEN_BSD_COMPRESS; len -= CILEN_BSD_COMPRESS; } +#endif /* BSDCOMPRESS_SUPPORT */ +#if PREDICTOR_SUPPORT if (go->predictor_1 && len >= CILEN_PREDICTOR_1 && p[0] == CI_PREDICTOR_1 && p[1] == CILEN_PREDICTOR_1) { try_.predictor_1 = 0; @@ -1020,6 +1081,7 @@ static int ccp_rejci(fsm *f, u_char *p, int len) { p += CILEN_PREDICTOR_2; len -= CILEN_PREDICTOR_2; } +#endif /* PREDICTOR_SUPPORT */ if (len != 0) return 0; @@ -1039,9 +1101,13 @@ static int ccp_reqci(fsm *f, u_char *p, int *lenp, int dont_nak) { ppp_pcb *pcb = f->pcb; ccp_options *ho = &pcb->ccp_hisoptions; ccp_options *ao = &pcb->ccp_allowoptions; - int ret, newret, res; + int ret, newret; +#if DEFLATE_SUPPORT || BSDCOMPRESS_SUPPORT + int res; + int nb; +#endif /* DEFLATE_SUPPORT || BSDCOMPRESS_SUPPORT */ u_char *p0, *retp; - int len, clen, type, nb; + int len, clen, type; #if MPPE_SUPPORT u8_t rej_for_ci_mppe = 1; /* Are we rejecting based on a bad/missing */ /* CI_MPPE, or due to other options? */ @@ -1168,6 +1234,7 @@ static int ccp_reqci(fsm *f, u_char *p, int *lenp, int dont_nak) { rej_for_ci_mppe = 0; break; #endif /* MPPE_SUPPORT */ +#if DEFLATE_SUPPORT case CI_DEFLATE: case CI_DEFLATE_DRAFT: if (!ao->deflate || clen != CILEN_DEFLATE @@ -1213,7 +1280,8 @@ static int ccp_reqci(fsm *f, u_char *p, int *lenp, int dont_nak) { } } break; - +#endif /* DEFLATE_SUPPORT */ +#if BSDCOMPRESS_SUPPORT case CI_BSD_COMPRESS: if (!ao->bsd_compress || clen != CILEN_BSD_COMPRESS) { newret = CONFREJ; @@ -1255,7 +1323,8 @@ static int ccp_reqci(fsm *f, u_char *p, int *lenp, int dont_nak) { } } break; - +#endif /* BSDCOMPRESS_SUPPORT */ +#if PREDICTOR_SUPPORT case CI_PREDICTOR_1: if (!ao->predictor_1 || clen != CILEN_PREDICTOR_1) { newret = CONFREJ; @@ -1281,6 +1350,7 @@ static int ccp_reqci(fsm *f, u_char *p, int *lenp, int dont_nak) { newret = CONFREJ; } break; +#endif /* PREDICTOR_SUPPORT */ default: newret = CONFREJ; @@ -1323,6 +1393,9 @@ 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 !DEFLATE_SUPPORT && !BSDCOMPRESS_SUPPORT + LWIP_UNUSED_ARG(opt2); +#endif /* !DEFLATE_SUPPORT && !BSDCOMPRESS_SUPPORT */ if (!ccp_anycompress(opt)) return "(none)"; @@ -1351,6 +1424,7 @@ static const char *method_name(ccp_options *opt, ccp_options *opt2) { break; } #endif /* MPPE_SUPPORT */ +#if DEFLATE_SUPPORT case CI_DEFLATE: case CI_DEFLATE_DRAFT: if (opt2 != NULL && opt2->deflate_size != opt->deflate_size) @@ -1362,6 +1436,8 @@ static const char *method_name(ccp_options *opt, ccp_options *opt2) { (opt->method == CI_DEFLATE_DRAFT? "(old#)": ""), opt->deflate_size); break; +#endif /* DEFLATE_SUPPORT */ +#if BSDCOMPRESS_SUPPORT case CI_BSD_COMPRESS: if (opt2 != NULL && opt2->bsd_bits != opt->bsd_bits) ppp_slprintf(result, sizeof(result), "BSD-Compress (%d/%d)", @@ -1370,10 +1446,13 @@ static const char *method_name(ccp_options *opt, ccp_options *opt2) { ppp_slprintf(result, sizeof(result), "BSD-Compress (%d)", opt->bsd_bits); break; +#endif /* BSDCOMPRESS_SUPPORT */ +#if PREDICTOR_SUPPORT case CI_PREDICTOR_1: return "Predictor 1"; case CI_PREDICTOR_2: return "Predictor 2"; +#endif /* PREDICTOR_SUPPORT */ default: ppp_slprintf(result, sizeof(result), "Method %d", opt->method); } @@ -1507,6 +1586,7 @@ static int ccp_printpkt(u_char *p, int plen, void (*printer) (void *, const char } break; #endif /* MPPE_SUPPORT */ +#if DEFLATE_SUPPORT case CI_DEFLATE: case CI_DEFLATE_DRAFT: if (optlen >= CILEN_DEFLATE) { @@ -1520,6 +1600,8 @@ static int ccp_printpkt(u_char *p, int plen, void (*printer) (void *, const char p += CILEN_DEFLATE; } break; +#endif /* DEFLATE_SUPPORT */ +#if BSDCOMPRESS_SUPPORT case CI_BSD_COMPRESS: if (optlen >= CILEN_BSD_COMPRESS) { printer(arg, "bsd v%d %d", BSD_VERSION(p[2]), @@ -1527,6 +1609,8 @@ static int ccp_printpkt(u_char *p, int plen, void (*printer) (void *, const char p += CILEN_BSD_COMPRESS; } break; +#endif /* BSDCOMPRESS_SUPPORT */ +#if PREDICTOR_SUPPORT case CI_PREDICTOR_1: if (optlen >= CILEN_PREDICTOR_1) { printer(arg, "predictor 1"); @@ -1539,6 +1623,7 @@ static int ccp_printpkt(u_char *p, int plen, void (*printer) (void *, const char p += CILEN_PREDICTOR_2; } break; +#endif /* PREDICTOR_SUPPORT */ default: break; }