mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-01-30 03:32:50 +00:00
PPP, MPPE, adapt decompressor to use pbuf
mppe_decompress() now takes a pointer to a pbuf pointer and re-use the passed buffer for MPPE "decompression". Removed sub protocol handling which can be shared among all decompressors in ppp.c
This commit is contained in:
parent
bcfaeca373
commit
ab1606a0f6
@ -136,8 +136,7 @@ int mppe_compress(void *arg, unsigned char *ibuf, unsigned char *obuf,
|
|||||||
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);
|
||||||
int mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
|
int mppe_decompress(void *arg, struct pbuf **pb);
|
||||||
int osize);
|
|
||||||
void mppe_incomp(void *arg, unsigned char *ibuf, int icnt);
|
void mppe_incomp(void *arg, unsigned char *ibuf, int icnt);
|
||||||
|
|
||||||
#endif /* MPPE_H */
|
#endif /* MPPE_H */
|
||||||
|
@ -369,41 +369,33 @@ void mppe_decomp_reset(void *arg)
|
|||||||
* Decompress (decrypt) an MPPE packet.
|
* Decompress (decrypt) an MPPE packet.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
|
mppe_decompress(void *arg, struct pbuf **pb)
|
||||||
int osize)
|
|
||||||
{
|
{
|
||||||
struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
|
struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
|
||||||
|
struct pbuf *n0 = *pb, *n;
|
||||||
|
u8_t *pl;
|
||||||
unsigned ccount;
|
unsigned ccount;
|
||||||
int flushed = MPPE_BITS(ibuf) & MPPE_BIT_FLUSHED;
|
int flushed;
|
||||||
int sanity = 0;
|
int sanity = 0;
|
||||||
|
|
||||||
if (isize <= MPPE_OVHD) {
|
/* MPPE Header */
|
||||||
|
if (n0->len < MPPE_OVHD) {
|
||||||
if (state->debug)
|
if (state->debug)
|
||||||
PPPDEBUG(LOG_DEBUG,
|
PPPDEBUG(LOG_DEBUG,
|
||||||
("mppe_decompress[%d]: short pkt (%d)\n",
|
("mppe_decompress[%d]: short pkt (%d)\n",
|
||||||
state->unit, isize));
|
state->unit, n0->len));
|
||||||
return ERR_BUF;
|
return ERR_BUF;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
pl = (u8_t*)n0->payload;
|
||||||
* Make sure we have enough room to decrypt the packet.
|
flushed = MPPE_BITS(pl) & MPPE_BIT_FLUSHED;
|
||||||
* Note that for our test we add 1 byte to account for possible PFC.
|
ccount = MPPE_CCOUNT(pl);
|
||||||
*/
|
|
||||||
if (osize < isize - MPPE_OVHD + 1) {
|
|
||||||
PPPDEBUG(LOG_DEBUG, ("mppe_decompress[%d]: osize too small! "
|
|
||||||
"(have: %d need: %d)\n", state->unit,
|
|
||||||
osize, isize - MPPE_OVHD + 1));
|
|
||||||
return ERR_BUF;
|
|
||||||
}
|
|
||||||
osize = isize - MPPE_OVHD; /* assume no PFC */
|
|
||||||
|
|
||||||
ccount = MPPE_CCOUNT(ibuf);
|
|
||||||
if (state->debug >= 7)
|
if (state->debug >= 7)
|
||||||
PPPDEBUG(LOG_DEBUG, ("mppe_decompress[%d]: ccount %d\n",
|
PPPDEBUG(LOG_DEBUG, ("mppe_decompress[%d]: ccount %d\n",
|
||||||
state->unit, ccount));
|
state->unit, ccount));
|
||||||
|
|
||||||
/* sanity checks -- terminate with extreme prejudice */
|
/* sanity checks -- terminate with extreme prejudice */
|
||||||
if (!(MPPE_BITS(ibuf) & MPPE_BIT_ENCRYPTED)) {
|
if (!(MPPE_BITS(pl) & MPPE_BIT_ENCRYPTED)) {
|
||||||
PPPDEBUG(LOG_DEBUG,
|
PPPDEBUG(LOG_DEBUG,
|
||||||
("mppe_decompress[%d]: ENCRYPTED bit not set!\n",
|
("mppe_decompress[%d]: ENCRYPTED bit not set!\n",
|
||||||
state->unit));
|
state->unit));
|
||||||
@ -491,40 +483,21 @@ mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
|
|||||||
mppe_rekey(state, 0);
|
mppe_rekey(state, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* Hide MPPE header */
|
||||||
* Fill in the first part of the PPP header. The protocol field
|
pbuf_header(n0, -(s16_t)(MPPE_OVHD));
|
||||||
* comes from the decrypted data.
|
|
||||||
*/
|
|
||||||
ibuf += MPPE_OVHD;
|
|
||||||
isize -= MPPE_OVHD;
|
|
||||||
|
|
||||||
/*
|
/* Decrypt the packet. */
|
||||||
* Decrypt the first byte in order to check if it is
|
for (n = n0; n != NULL; n = n->next) {
|
||||||
* a compressed or uncompressed protocol field.
|
arc4_crypt(&state->arc4, (u8_t*)n->payload, n->len);
|
||||||
*/
|
if (n->tot_len == n->len) {
|
||||||
obuf[0] = ibuf[0];
|
break;
|
||||||
arc4_crypt(&state->arc4, obuf, 1);
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Do PFC decompression.
|
|
||||||
* This would be nicer if we were given the actual sk_buff
|
|
||||||
* instead of a char *.
|
|
||||||
*/
|
|
||||||
if ((obuf[0] & 0x01) != 0) {
|
|
||||||
obuf[1] = obuf[0];
|
|
||||||
obuf[0] = 0;
|
|
||||||
obuf++;
|
|
||||||
osize++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* And finally, decrypt the rest of the packet. */
|
|
||||||
MEMCPY(obuf+1, ibuf+1, isize-1);
|
|
||||||
arc4_crypt(&state->arc4, obuf+1, isize-1);
|
|
||||||
|
|
||||||
/* good packet credit */
|
/* good packet credit */
|
||||||
state->sanity_errors >>= 1;
|
state->sanity_errors >>= 1;
|
||||||
|
|
||||||
return osize;
|
return n0->tot_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user