From f79bc033609a66c3a49f69c769f28d21d79368c4 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sat, 18 Apr 2015 13:41:38 +0200 Subject: [PATCH] PPP, MPPE, optimized struct ppp_mppe_state size --- src/include/netif/ppp/mppe.h | 29 +++++++++++++++-------------- src/netif/ppp/mppe.c | 12 ++++++------ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/include/netif/ppp/mppe.h b/src/include/netif/ppp/mppe.h index 4fa0274f..1556cd78 100644 --- a/src/include/netif/ppp/mppe.h +++ b/src/include/netif/ppp/mppe.h @@ -137,23 +137,24 @@ */ struct ppp_mppe_state { arc4_context arc4; - unsigned char master_key[MPPE_MAX_KEY_LEN]; - unsigned char session_key[MPPE_MAX_KEY_LEN]; - unsigned keylen; /* key length in bytes */ - /* NB: 128-bit == 16, 40-bit == 8! */ - /* If we want to support 56-bit, */ - /* the unit has to change to bits */ - unsigned char bits; /* MPPE control bits */ - unsigned ccount; /* 12-bit coherency count (seqno) */ - unsigned stateful; /* stateful mode flag */ - int discard; /* stateful mode packet loss flag */ - int sanity_errors; /* take down LCP if too many */ - int unit; - int debug; + u8_t master_key[MPPE_MAX_KEY_LEN]; + u8_t session_key[MPPE_MAX_KEY_LEN]; + u8_t keylen; /* key length in bytes */ + /* NB: 128-bit == 16, 40-bit == 8! + * If we want to support 56-bit, the unit has to change to bits + */ + u8_t bits; /* MPPE control bits */ + u16_t ccount; /* 12-bit coherency count (seqno) */ + unsigned int stateful :1; /* stateful mode flag */ + unsigned int discard :1; /* stateful mode packet loss flag */ + unsigned int debug :1; /* debug flag */ + unsigned int :5; /* 5 bit of padding to round out to 8 bits */ + u16_t sanity_errors; /* take down LCP if too many */ + u8_t unit; }; int mppe_init(struct ppp_mppe_state *state, unsigned char *options, int optlen, - int unit, int debug, const char *debugstr); + u8_t unit, u8_t debug, const char *debugstr); void mppe_comp_reset(struct ppp_mppe_state *state); err_t mppe_compress(struct ppp_mppe_state *state, struct pbuf **pb, u16_t protocol); void mppe_decomp_reset(struct ppp_mppe_state *state); diff --git a/src/netif/ppp/mppe.c b/src/netif/ppp/mppe.c index be8d3df7..fe197b46 100644 --- a/src/netif/ppp/mppe.c +++ b/src/netif/ppp/mppe.c @@ -117,7 +117,7 @@ static void mppe_rekey(struct ppp_mppe_state * state, int initial_key) * Initialize (de)compressor state. */ int -mppe_init(struct ppp_mppe_state *state, unsigned char *options, int optlen, int unit, int debug, +mppe_init(struct ppp_mppe_state *state, unsigned char *options, int optlen, u8_t unit, u8_t debug, const char *debugstr) { unsigned char mppe_opts; @@ -218,7 +218,7 @@ mppe_compress(struct ppp_mppe_state *state, struct pbuf **pb, u16_t protocol) pl = (u8_t*)np->payload; state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE; - if (state->debug >= 7) + if (state->debug) PPPDEBUG(LOG_DEBUG, ("mppe_compress[%d]: ccount %d\n", state->unit, state->ccount)); /* FIXME: use PUT* macros */ @@ -274,9 +274,9 @@ mppe_decompress(struct ppp_mppe_state *state, struct pbuf **pb) { struct pbuf *n0 = *pb, *n; u8_t *pl; - unsigned ccount; - int flushed; - int sanity = 0; + u16_t ccount; + u8_t flushed; + u8_t sanity = 0; /* MPPE Header */ if (n0->len < MPPE_OVHD) { @@ -290,7 +290,7 @@ mppe_decompress(struct ppp_mppe_state *state, struct pbuf **pb) pl = (u8_t*)n0->payload; flushed = MPPE_BITS(pl) & MPPE_BIT_FLUSHED; ccount = MPPE_CCOUNT(pl); - if (state->debug >= 7) + if (state->debug) PPPDEBUG(LOG_DEBUG, ("mppe_decompress[%d]: ccount %d\n", state->unit, ccount));