X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;ds=sidebyside;f=linux%2Fmppe%2Fppp_mppe_compress.c;h=051213273970fa4affb73b00d68c0c1bafe1945e;hb=98b641cbee0c4489e83320962ddf652eb9070f03;hp=33885df433211f92c433a65ef0548a30469b98e3;hpb=b02bd2ca354d02096940e3926bd7e37bfd0359ab;p=ppp.git diff --git a/linux/mppe/ppp_mppe_compress.c b/linux/mppe/ppp_mppe_compress.c index 33885df..0512132 100644 --- a/linux/mppe/ppp_mppe_compress.c +++ b/linux/mppe/ppp_mppe_compress.c @@ -1,11 +1,9 @@ /* - * ==FILEVERSION 20020521== - * * ppp_mppe_compress.c - interface MPPE to the PPP code. - * This version is for use with Linux kernel 2.2.19+ and 2.4.x. + * This version is for use with Linux kernel 2.2.19+, 2.4.18+ and 2.6.2+. * * By Frank Cusack . - * Copyright (c) 2002 Google, Inc. + * Copyright (c) 2002,2003,2004 Google, Inc. * All rights reserved. * * Permission to use, copy, modify, and distribute this software and its @@ -13,10 +11,16 @@ * notice appears in all copies. This software is provided without any * warranty, express or implied. * + * Changelog: + * 2/15/04 - TS: added #include and testing for Kernel + * version before using + * MOD_DEC_USAGE_COUNT/MOD_INC_USAGE_COUNT which are + * deprecated in 2.6 */ #include #include +#include #include #include #include @@ -170,7 +174,11 @@ mppe_alloc(unsigned char *options, int optlen) if (state == NULL) return NULL; +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)) + try_module_get(THIS_MODULE); +#else MOD_INC_USE_COUNT; +#endif memset(state, 0, sizeof(*state)); /* Save keys. */ @@ -194,7 +202,11 @@ mppe_free(void *arg) if (state) { kfree(state); +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)) + module_put(THIS_MODULE); +#else MOD_DEC_USE_COUNT; +#endif } } @@ -416,14 +428,19 @@ mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf, return DECOMP_ERROR; } - /* Make sure we have enough room to decrypt the packet. */ - if (osize < isize - MPPE_OVHD - 2) { + /* + * Make sure we have enough room to decrypt the packet. + * Note that for our test we only subtract 1 byte whereas in + * mppe_compress() we added 2 bytes (+MPPE_OVHD); + * this is to account for possible PFC. + */ + if (osize < isize - MPPE_OVHD - 1) { printk(KERN_DEBUG "mppe_decompress[%d]: osize too small! " "(have: %d need: %d)\n", state->unit, - osize, isize - MPPE_OVHD - 2); + osize, isize - MPPE_OVHD - 1); return DECOMP_ERROR; } - osize = isize - MPPE_OVHD - 2; + osize = isize - MPPE_OVHD - 2; /* assume no PFC */ ccount = MPPE_CCOUNT(ibuf); if (state->debug >= 7) @@ -525,8 +542,26 @@ mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf, isize -= PPP_HDRLEN + MPPE_OVHD; /* -6 */ /* net osize: isize-4 */ - /* And finally, decrypt the packet. */ - arcfour_decrypt(&state->arcfour_context, ibuf, isize, obuf); + /* + * Decrypt the first byte in order to check if it is + * a compressed or uncompressed protocol field. + */ + arcfour_decrypt(&state->arcfour_context, ibuf, 1, obuf); + + /* + * 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. */ + arcfour_decrypt(&state->arcfour_context, ibuf + 1, isize - 1, obuf + 1); state->stats.unc_bytes += osize; state->stats.unc_packets++;