mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-02-22 12:39:55 +00:00
PPP, MPPE, adapt compressor to use pbuf
mppe_compress() now takes a pointer to a pbuf pointer and re-use the passed buffer for MPPE "compression".
This commit is contained in:
parent
dc93c2afec
commit
caf9fc5687
@ -131,8 +131,7 @@ void mppe_free(void *arg);
|
|||||||
int mppe_comp_init(void *arg, unsigned char *options, int optlen, int unit,
|
int mppe_comp_init(void *arg, unsigned char *options, int optlen, int unit,
|
||||||
int hdrlen, int debug);
|
int hdrlen, int debug);
|
||||||
void mppe_comp_reset(void *arg);
|
void mppe_comp_reset(void *arg);
|
||||||
int mppe_compress(void *arg, unsigned char *ibuf, unsigned char *obuf,
|
err_t mppe_compress(void *arg, struct pbuf **pb, u16_t protocol);
|
||||||
int isize, int osize, u16_t protocol);
|
|
||||||
int mppe_decomp_init(void *arg, unsigned char *options, int optlen, int unit,
|
int mppe_decomp_init(void *arg, unsigned char *options, int optlen, int unit,
|
||||||
int hdrlen, int mru, int debug);
|
int hdrlen, int mru, int debug);
|
||||||
void mppe_decomp_reset(void *arg);
|
void mppe_decomp_reset(void *arg);
|
||||||
|
@ -280,31 +280,28 @@ void mppe_comp_reset(void *arg)
|
|||||||
* It's strange to call this a compressor, since the output is always
|
* It's strange to call this a compressor, since the output is always
|
||||||
* MPPE_OVHD + 2 bytes larger than the input.
|
* MPPE_OVHD + 2 bytes larger than the input.
|
||||||
*/
|
*/
|
||||||
int
|
err_t
|
||||||
mppe_compress(void *arg, unsigned char *ibuf, unsigned char *obuf,
|
mppe_compress(void *arg, struct pbuf **pb, u16_t protocol)
|
||||||
int isize, int osize, u16_t protocol)
|
|
||||||
{
|
{
|
||||||
struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
|
struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
|
||||||
|
struct pbuf *np, *n;
|
||||||
|
u8_t *pl;
|
||||||
|
|
||||||
/* Make sure we have enough room to generate an encrypted packet. */
|
/* FIXME: try to use pbuf_header() here! */
|
||||||
if (osize < isize + MPPE_OVHD + 2) {
|
np = pbuf_alloc(PBUF_RAW, MPPE_OVHD + sizeof(protocol), PBUF_RAM);
|
||||||
/* Drop the packet if we should encrypt it, but can't. */
|
if (!np) {
|
||||||
PPPDEBUG(LOG_DEBUG, ("mppe_compress[%d]: osize too small! "
|
return ERR_MEM;
|
||||||
"(have: %d need: %d)\n", state->unit,
|
|
||||||
osize, osize + MPPE_OVHD + 2));
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
pbuf_chain(np, *pb);
|
||||||
osize = isize + MPPE_OVHD + 2;
|
pl = (u8_t*)np->payload;
|
||||||
|
|
||||||
|
|
||||||
state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE;
|
state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE;
|
||||||
if (state->debug >= 7)
|
if (state->debug >= 7)
|
||||||
PPPDEBUG(LOG_DEBUG, ("mppe_compress[%d]: ccount %d\n", state->unit,
|
PPPDEBUG(LOG_DEBUG, ("mppe_compress[%d]: ccount %d\n", state->unit,
|
||||||
state->ccount));
|
state->ccount));
|
||||||
/* FIXME: use PUT* macros */
|
/* FIXME: use PUT* macros */
|
||||||
obuf[0] = state->ccount>>8;
|
pl[0] = state->ccount>>8;
|
||||||
obuf[1] = state->ccount;
|
pl[1] = state->ccount;
|
||||||
|
|
||||||
if (!state->stateful || /* stateless mode */
|
if (!state->stateful || /* stateless mode */
|
||||||
((state->ccount & 0xff) == 0xff) || /* "flag" packet */
|
((state->ccount & 0xff) == 0xff) || /* "flag" packet */
|
||||||
@ -316,21 +313,26 @@ mppe_compress(void *arg, unsigned char *ibuf, unsigned char *obuf,
|
|||||||
mppe_rekey(state, 0);
|
mppe_rekey(state, 0);
|
||||||
state->bits |= MPPE_BIT_FLUSHED;
|
state->bits |= MPPE_BIT_FLUSHED;
|
||||||
}
|
}
|
||||||
obuf[0] |= state->bits;
|
pl[0] |= state->bits;
|
||||||
state->bits &= ~MPPE_BIT_FLUSHED; /* reset for next xmit */
|
state->bits &= ~MPPE_BIT_FLUSHED; /* reset for next xmit */
|
||||||
obuf += MPPE_OVHD;
|
pl += MPPE_OVHD;
|
||||||
|
|
||||||
/* Add and encrypt protocol */
|
/* Add and encrypt protocol */
|
||||||
/* FIXME: add PFC support */
|
/* FIXME: add PFC support */
|
||||||
obuf[0] = protocol >> 8;
|
pl[0] = protocol >> 8;
|
||||||
obuf[1] = protocol;
|
pl[1] = protocol;
|
||||||
arc4_crypt(&state->arc4, obuf, 2);
|
arc4_crypt(&state->arc4, pl, sizeof(protocol));
|
||||||
obuf += 2;
|
|
||||||
|
|
||||||
/* Encrypt packet */
|
/* Encrypt packet */
|
||||||
MEMCPY(obuf, ibuf, isize);
|
for (n = *pb; n != NULL; n = n->next) {
|
||||||
arc4_crypt(&state->arc4, obuf, isize);
|
arc4_crypt(&state->arc4, (u8_t*)n->payload, n->len);
|
||||||
return osize;
|
if (n->tot_len == n->len) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*pb = np;
|
||||||
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Loading…
x
Reference in New Issue
Block a user