]> git.pld-linux.org Git - packages/kernel.git/blob - linux-2.4.18-mppe.patch
- obsolete
[packages/kernel.git] / linux-2.4.18-mppe.patch
1 diff -urN linux-2.4.18.org/drivers/net/arcfour.c linux-2.4.18/drivers/net/arcfour.c
2 --- linux-2.4.18.org/drivers/net/arcfour.c      Thu Jan  1 01:00:00 1970
3 +++ linux-2.4.18/drivers/net/arcfour.c  Tue Apr  2 16:01:37 2002
4 @@ -0,0 +1,72 @@
5 +/*
6 + * arcfour.c
7 + * by Frank Cusack <frank@google.com>
8 + * 100% public domain
9 + *
10 + * Implemented from the description in _Applied Cryptography_, 2nd ed.
11 + *
12 + * ** Distribution ** of this software is unlimited and unrestricted.
13 + *
14 + * ** Use ** of this software is almost certainly legal; however, refer
15 + * to <http://theory.lcs.mit.edu/~rivest/faq.html>.
16 + */
17 +
18 +#include "arcfour.h"
19 +
20 +#define swap(a, b)             \
21 +{                              \
22 +    unsigned char t = b;       \
23 +    b = a;                     \
24 +    a = t;                     \
25 +}
26 +
27 +/*
28 + * Initialize arcfour from a key.
29 + */
30 +void
31 +arcfour_setkey(arcfour_context *context, const unsigned char *key,
32 +              unsigned keylen)
33 +{
34 +    unsigned i, j;
35 +    unsigned char K[256];
36 +
37 +    context->i = context->j = 0;
38 +
39 +    for (i = 0; i < 256; i++) {
40 +       context->S[i] = i;
41 +       K[i] = key[i % keylen];
42 +    }
43 +
44 +    j = 0;
45 +    for (i = 0; i < 256; i++) {
46 +       j = (j + context->S[i] + K[i]) % 256;
47 +       swap(context->S[i], context->S[j]);
48 +    }
49 +
50 +    memset(K, 0, sizeof(K));
51 +}
52 +
53 +/*
54 + * plaintext -> ciphertext (or vice versa)
55 + */
56 +void
57 +arcfour_encrypt(arcfour_context *context, const unsigned char *in, unsigned len,
58 +               unsigned char *out)
59 +{
60 +    unsigned i = context->i;
61 +    unsigned j = context->j;
62 +    unsigned char *S = context->S;
63 +    unsigned char K;
64 +
65 +    while (len--) {
66 +       i = (i + 1) % 256;
67 +       j = (j + S[i]) % 256;
68 +       swap(S[i], S[j]);
69 +       K = S[(S[i] + S[j]) % 256];
70 +       *out++ = *in++ ^ K;
71 +    }
72 +
73 +    context->i = i;
74 +    context->j = j;
75 +}
76 +
77 diff -urN linux-2.4.18.org/drivers/net/arcfour.h linux-2.4.18/drivers/net/arcfour.h
78 --- linux-2.4.18.org/drivers/net/arcfour.h      Thu Jan  1 01:00:00 1970
79 +++ linux-2.4.18/drivers/net/arcfour.h  Tue Apr  2 16:01:37 2002
80 @@ -0,0 +1,17 @@
81 +/* arcfour.h */
82 +
83 +#ifndef _ARCFOUR_H
84 +#define _ARCFOUR_H
85 +
86 +typedef struct {
87 +    unsigned i;
88 +    unsigned j;
89 +    unsigned char S[256];
90 +} arcfour_context;
91 +
92 +extern void arcfour_setkey(arcfour_context *, const unsigned char *, unsigned);
93 +extern void arcfour_encrypt(arcfour_context *, const unsigned char *, unsigned,
94 +                           unsigned char *);
95 +#define arcfour_decrypt arcfour_encrypt
96 +
97 +#endif /* _ARCFOUR_H */
98 diff -urN linux-2.4.18.org/drivers/net/ppp_mppe_compress.c linux-2.4.18/drivers/net/ppp_mppe_compress.c
99 --- linux-2.4.18.org/drivers/net/ppp_mppe_compress.c    Thu Jan  1 01:00:00 1970
100 +++ linux-2.4.18/drivers/net/ppp_mppe_compress.c        Tue Apr  2 16:12:48 2002
101 @@ -0,0 +1,615 @@
102 +/*
103 + *  ==FILEVERSION 20020320==
104 + *
105 + * ppp_mppe_compress.c - interface MPPE to the PPP code.
106 + * This version is for use with Linux kernel 2.2.19+ and 2.4.x.
107 + *
108 + * By Frank Cusack <frank@google.com>.
109 + * Copyright (c) 2002 Google, Inc.
110 + * All rights reserved.
111 + *
112 + * Permission to use, copy, modify, and distribute this software and its
113 + * documentation is hereby granted, provided that the above copyright
114 + * notice appears in all copies.  This software is provided without any
115 + * warranty, express or implied.
116 + *
117 + */
118 +
119 +#include <linux/module.h>
120 +#include <linux/kernel.h>
121 +#include <linux/init.h>
122 +#include <linux/types.h>
123 +#include <linux/slab.h>
124 +#include <linux/string.h>
125 +
126 +#include <linux/ppp_defs.h>
127 +#include <linux/ppp-comp.h>
128 +
129 +#include "arcfour.h"
130 +#include "sha1.h"
131 +
132 +/*
133 + * State for an MPPE (de)compressor.
134 + */
135 +typedef struct ppp_mppe_state {
136 +    unsigned char      master_key[MPPE_MAX_KEY_LEN];
137 +    unsigned char      session_key[MPPE_MAX_KEY_LEN];
138 +    arcfour_context    arcfour_context; /* encryption state */
139 +    unsigned           keylen;         /* key length in bytes             */
140 +                                       /* NB: 128-bit == 16, 40-bit == 8! */
141 +                                       /* If we want to support 56-bit,   */
142 +                                       /* the unit has to change to bits  */
143 +    unsigned char      bits;           /* MPPE control bits */
144 +    unsigned           ccount;         /* 12-bit coherency count (seqno)  */
145 +    unsigned           stateful;       /* stateful mode flag */
146 +    int                        discard;        /* stateful mode packet loss flag */
147 +    int                        sanity_errors;  /* take down LCP if too many */
148 +    int                        unit;
149 +    int                        debug;
150 +    struct compstat    stats;
151 +} ppp_mppe_state;
152 +
153 +/* ppp_mppe_state.bits definitions */
154 +#define MPPE_BIT_A     0x80    /* Encryption table were (re)inititalized */
155 +#define MPPE_BIT_B     0x40    /* MPPC only (not implemented) */
156 +#define MPPE_BIT_C     0x20    /* MPPC only (not implemented) */
157 +#define MPPE_BIT_D     0x10    /* This is an encrypted frame */
158 +
159 +#define MPPE_BIT_FLUSHED       MPPE_BIT_A
160 +#define MPPE_BIT_ENCRYPTED     MPPE_BIT_D
161 +
162 +#define MPPE_BITS(p) ((p)[4] & 0xf0)
163 +#define MPPE_CCOUNT(p) ((((p)[4] & 0x0f) << 8) + (p)[5])
164 +#define MPPE_CCOUNT_SPACE 0x1000       /* The size of the ccount space */
165 +
166 +/*
167 + * MPPE overhead/packet.
168 + * Note that we use this differently than other compressors.
169 + */
170 +#define MPPE_OVHD      2               /* MPPE overhead/packet */
171 +/* Max bogon factor we will tolerate */
172 +#define SANITY_MAX     1600
173 +
174 +static void    GetNewKeyFromSHA __P((unsigned char *StartKey,
175 +                                     unsigned char *SessionKey,
176 +                                     unsigned SessionKeyLength,
177 +                                     unsigned char *InterimKey));
178 +static void    mppe_rekey __P((ppp_mppe_state *state, int));
179 +static void    *mppe_alloc __P((unsigned char *options, int optlen));
180 +static void    mppe_free __P((void *state));
181 +static int     mppe_init __P((void *state, unsigned char *options,
182 +                              int optlen, int unit, int debug, const char *));
183 +static int     mppe_comp_init __P((void *state, unsigned char *options,
184 +                                   int optlen,
185 +                                   int unit, int hdrlen, int debug));
186 +static int     mppe_decomp_init __P((void *state, unsigned char *options,
187 +                                     int optlen, int unit,
188 +                                     int hdrlen, int mru, int debug));
189 +static int     mppe_compress __P((void *state, unsigned char *ibuf,
190 +                                  unsigned char *obuf,
191 +                                  int isize, int osize));
192 +static void    mppe_incomp __P((void *state, unsigned char *ibuf, int icnt));
193 +static int     mppe_decompress __P((void *state, unsigned char *ibuf,
194 +                                    int isize, unsigned char *obuf,int osize));
195 +static void    mppe_comp_reset __P((void *state));
196 +static void    mppe_decomp_reset __P((void *state));
197 +static void    mppe_comp_stats __P((void *state, struct compstat *stats));
198 +
199 +
200 +/*
201 + * Key Derivation, from RFC 3078, RFC 3079.
202 + * Equivalent to Get_Key() for MS-CHAP as described in RFC 3079.
203 + */
204 +static void
205 +GetNewKeyFromSHA(unsigned char *MasterKey, unsigned char *SessionKey,
206 +                unsigned SessionKeyLength, unsigned char *InterimKey)
207 +{
208 +    SHA1_CTX Context;
209 +    unsigned char Digest[SHA1_SIGNATURE_SIZE];
210 +
211 +    unsigned char SHApad1[40] =
212 +    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
213 +      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
214 +      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
215 +      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
216 +    unsigned char SHApad2[40] =
217 +    { 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2,
218 +      0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2,
219 +      0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2,
220 +      0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2 };
221 +
222 +    /* assert(SessionKeyLength <= SHA1_SIGNATURE_SIZE); */
223 +
224 +    SHA1_Init(&Context);
225 +    SHA1_Update(&Context, MasterKey, SessionKeyLength);
226 +    SHA1_Update(&Context, SHApad1, sizeof(SHApad1));
227 +    SHA1_Update(&Context, SessionKey, SessionKeyLength);
228 +    SHA1_Update(&Context, SHApad2, sizeof(SHApad2));
229 +    SHA1_Final(Digest, &Context);
230 +
231 +    memcpy(InterimKey, Digest, SessionKeyLength);
232 +}
233 +
234 +/*
235 + * Perform the MPPE rekey algorithm, from RFC 3078, sec. 7.3.
236 + * Well, not what's written there, but rather what they meant.
237 + */
238 +static void
239 +mppe_rekey(ppp_mppe_state *state, int initial_key)
240 +{
241 +    unsigned char InterimKey[MPPE_MAX_KEY_LEN];
242 +
243 +    GetNewKeyFromSHA(state->master_key, state->session_key,
244 +                    state->keylen, InterimKey);
245 +    if (!initial_key) {
246 +       arcfour_setkey(&state->arcfour_context, InterimKey, state->keylen);
247 +       arcfour_encrypt(&state->arcfour_context, InterimKey, state->keylen,
248 +                       state->session_key);
249 +    } else {
250 +       memcpy(state->session_key, InterimKey, state->keylen);
251 +    }
252 +    if (state->keylen == 8) {
253 +       /* See RFC 3078 */
254 +       state->session_key[0] = 0xd1;
255 +       state->session_key[1] = 0x26;
256 +       state->session_key[2] = 0x9e;
257 +    }
258 +    arcfour_setkey(&state->arcfour_context, state->session_key, state->keylen);
259 +}
260 +
261 +
262 +/*
263 + * Allocate space for a (de)compressor.
264 + */
265 +static void *
266 +mppe_alloc(unsigned char *options, int optlen)
267 +{
268 +    ppp_mppe_state *state;
269 +
270 +    if (optlen != CILEN_MPPE + sizeof(state->master_key)
271 +       || options[0] != CI_MPPE
272 +       || options[1] != CILEN_MPPE)
273 +       return NULL;
274 +
275 +    state = (ppp_mppe_state *) kmalloc(sizeof(*state), GFP_KERNEL);
276 +    if (state == NULL)
277 +       return NULL;
278 +
279 +    MOD_INC_USE_COUNT;
280 +    memset(state, 0, sizeof(*state));
281 +
282 +    /* Save keys. */
283 +    memcpy(state->master_key, &options[CILEN_MPPE], sizeof(state->master_key));
284 +    memcpy(state->session_key, state->master_key, sizeof(state->master_key));
285 +    /*
286 +     * We defer initial key generation until mppe_init(), as mppe_alloc()
287 +     * is called frequently during negotiation.
288 +     */
289 +
290 +    return (void *) state;
291 +}
292 +
293 +/*
294 + * Deallocate space for a (de)compressor.
295 + */
296 +static void
297 +mppe_free(void *arg)
298 +{
299 +    ppp_mppe_state *state = (ppp_mppe_state *) arg;
300 +
301 +    if (state) {
302 +       kfree(state);
303 +       MOD_DEC_USE_COUNT;
304 +    }
305 +}
306 +
307 +
308 +/* 
309 + * Initialize (de)compressor state.
310 + */
311 +static int
312 +mppe_init(void *arg, unsigned char *options, int optlen, int unit, int debug,
313 +         const char *debugstr)
314 +{
315 +    ppp_mppe_state *state = (ppp_mppe_state *) arg;
316 +    unsigned char mppe_opts;
317 +
318 +    if (optlen != CILEN_MPPE
319 +       || options[0] != CI_MPPE
320 +       || options[1] != CILEN_MPPE)
321 +       return 0;
322 +
323 +    MPPE_CI_TO_OPTS(&options[2], mppe_opts);
324 +    if (mppe_opts & MPPE_OPT_128)
325 +       state->keylen = 16;
326 +    else if (mppe_opts & MPPE_OPT_40)
327 +       state->keylen = 8;
328 +    else {
329 +       printk(KERN_WARNING "%s[%d]: unknown key length\n", debugstr, unit);
330 +       return 0;
331 +    }
332 +    if (mppe_opts & MPPE_OPT_STATEFUL)
333 +       state->stateful = 1;
334 +
335 +    /* Generate the initial session key. */
336 +    mppe_rekey(state, 1);
337 +
338 +    if (debug) {
339 +       int i;
340 +       char mkey[sizeof(state->master_key) * 3 + 1];
341 +       char skey[sizeof(state->session_key) * 3 + 1];
342 +
343 +       printk(KERN_DEBUG "%s[%d]: initialized with %d-bit %s mode\n", debugstr,
344 +              unit, (state->keylen == 16)? 128: 40,
345 +              (state->stateful)? "stateful": "stateless");
346 +
347 +       for (i = 0; i < sizeof(state->master_key); i++)
348 +           sprintf(mkey + i * 2, "%.2x ", state->master_key[i]);
349 +       for (i = 0; i < sizeof(state->session_key); i++)
350 +           sprintf(skey + i * 2, "%.2x ", state->session_key[i]);
351 +       printk(KERN_DEBUG "%s[%d]: keys: master: %s initial session: %s\n",
352 +              debugstr, unit, mkey, skey);
353 +    }
354 +
355 +    /*
356 +     * Initialize the coherency count.  The initial value is not specified
357 +     * in RFC 3078, but we can make a reasonable assumption that it will
358 +     * start at 0.  Setting it to the max here makes the comp/decomp code
359 +     * do the right thing (determined through experiment).
360 +     */
361 +    state->ccount = MPPE_CCOUNT_SPACE - 1;
362 +
363 +    /*
364 +     * Note that even though we have initialized the key table, we don't
365 +     * set the FLUSHED bit.  This is contrary to RFC 3078, sec. 3.1.
366 +     */
367 +    state->bits = MPPE_BIT_ENCRYPTED;
368 +
369 +    state->unit  = unit;
370 +    state->debug = debug;
371 +
372 +    return 1;
373 +}
374 +
375 +
376 +
377 +static int
378 +mppe_comp_init(void *arg, unsigned char *options, int optlen, int unit,
379 +              int hdrlen, int debug)
380 +{
381 +    /* ARGSUSED */
382 +    return mppe_init(arg, options, optlen, unit, debug, "mppe_comp_init");
383 +}
384 +
385 +/*
386 + * We received a CCP Reset-Request (actually, we are sending a Reset-Ack),
387 + * tell the compressor to rekey.  Note that we MUST NOT rekey for
388 + * every CCP Reset-Request; we only rekey on the next xmit packet.
389 + * We might get multiple CCP Reset-Requests if our CCP Reset-Ack is lost.
390 + * So, rekeying for every CCP Reset-Request is broken as the peer will not
391 + * know how many times we've rekeyed.  (If we rekey and THEN get another
392 + * CCP Reset-Request, we must rekey again.)
393 + */
394 +static void
395 +mppe_comp_reset(void *arg)
396 +{
397 +    ppp_mppe_state *state = (ppp_mppe_state *) arg;
398 +
399 +    state->bits |= MPPE_BIT_FLUSHED;
400 +}
401 +
402 +/*
403 + * Compress (encrypt) a packet.
404 + * It's strange to call this a compressor, since the output is always
405 + * MPPE_OVHD + 2 bytes larger than the input.
406 + */
407 +int
408 +mppe_compress(void *arg, unsigned char *ibuf, unsigned char *obuf,
409 +             int isize, int osize)
410 +{
411 +    ppp_mppe_state *state = (ppp_mppe_state *) arg;
412 +    int proto;
413 +
414 +    /*
415 +     * Check that the protocol is in the range we handle.
416 +     */
417 +    proto = PPP_PROTOCOL(ibuf);
418 +    if (proto < 0x0021 || proto > 0x00fa)
419 +       return 0;
420 +
421 +    /* Make sure we have enough room to generate an encrypted packet. */
422 +    if (osize < isize + MPPE_OVHD + 2) {
423 +       /* Drop the packet if we should encrypt it, but can't. */
424 +       printk(KERN_DEBUG "mppe_compress[%d]: osize too small! "
425 +              "(have: %d need: %d)\n", state->unit,
426 +              osize, osize + MPPE_OVHD + 2);
427 +       return -1;
428 +    }
429 +
430 +    osize = isize + MPPE_OVHD + 2;
431 +
432 +    /*
433 +     * Copy over the PPP header and set control bits.
434 +     */
435 +    obuf[0] = PPP_ADDRESS(ibuf);
436 +    obuf[1] = PPP_CONTROL(ibuf);
437 +    obuf[2] = PPP_COMP >> 8;           /* isize + MPPE_OVHD + 1 */
438 +    obuf[3] = PPP_COMP;                        /* isize + MPPE_OVHD + 2 */
439 +    obuf += PPP_HDRLEN;
440 +
441 +    state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE;
442 +    obuf[0] = state->ccount >> 8;
443 +    obuf[1] = state->ccount & 0xff;
444 +
445 +    if (!state->stateful ||                    /* stateless mode     */
446 +       ((state->ccount & 0xff) == 0xff) ||     /* "flag" packet      */
447 +       (state->bits & MPPE_BIT_FLUSHED)) {     /* CCP Reset-Request  */
448 +       /* We must rekey */
449 +       if (state->debug && state->stateful)
450 +           printk(KERN_DEBUG "mppe_compress[%d]: rekeying\n", state->unit);
451 +       mppe_rekey(state, 0);
452 +       state->bits |= MPPE_BIT_FLUSHED;
453 +    }
454 +    obuf[0] |= state->bits;
455 +    state->bits &= ~MPPE_BIT_FLUSHED;  /* reset for next xmit */
456 +
457 +    obuf  += MPPE_OVHD;
458 +    ibuf  += 2;        /* skip to proto field */
459 +    isize -= 2;
460 +
461 +    /* Encrypt packet */
462 +    arcfour_encrypt(&state->arcfour_context, ibuf, isize, obuf);
463 +
464 +    state->stats.unc_bytes += isize;
465 +    state->stats.unc_packets++;
466 +    state->stats.comp_bytes += osize;
467 +    state->stats.comp_packets++;
468 +
469 +    return osize;
470 +}
471 +
472 +/*
473 + * Since every frame grows by MPPE_OVHD + 2 bytes, this is always going
474 + * to look bad ... and the longer the link is up the worse it will get.
475 + */
476 +static void
477 +mppe_comp_stats(void *arg, struct compstat *stats)
478 +{
479 +    ppp_mppe_state *state = (ppp_mppe_state *) arg;
480 +
481 +    *stats = state->stats;
482 +}
483 +
484 +
485 +static int
486 +mppe_decomp_init(void *arg, unsigned char *options, int optlen, int unit,
487 +                int hdrlen, int mru, int debug)
488 +{
489 +    /* ARGSUSED */
490 +    return mppe_init(arg, options, optlen, unit, debug, "mppe_decomp_init");
491 +}
492 +
493 +/*
494 + * We received a CCP Reset-Ack.  Just ignore it.
495 + */
496 +static void
497 +mppe_decomp_reset(void *arg)
498 +{
499 +    /* ARGSUSED */
500 +    return;
501 +}
502 +
503 +/*
504 + * Decompress (decrypt) an MPPE packet.
505 + */
506 +int
507 +mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
508 +               int osize)
509 +{
510 +    ppp_mppe_state *state = (ppp_mppe_state *) arg;
511 +    unsigned ccount;
512 +    int flushed = MPPE_BITS(ibuf) & MPPE_BIT_FLUSHED;
513 +    int sanity = 0;
514 +
515 +    if (isize <= PPP_HDRLEN + MPPE_OVHD) {
516 +       if (state->debug)
517 +           printk(KERN_DEBUG "mppe_decompress[%d]: short pkt (%d)\n",
518 +                  state->unit, isize);
519 +       return DECOMP_ERROR;
520 +    }
521 +    /* Strange ... our output size is always LESS than the input size. */
522 +    /* assert(osize >= isize - MPPE_OVHD - 2); */
523 +
524 +    osize = isize - MPPE_OVHD - 2;
525 +
526 +    ccount = MPPE_CCOUNT(ibuf);
527 +
528 +    /* sanity checks -- terminate with extreme prejudice */
529 +    if (!(MPPE_BITS(ibuf) & MPPE_BIT_ENCRYPTED)) {
530 +       printk(KERN_DEBUG "mppe_decompress[%d]: ENCRYPTED bit not set!\n",
531 +              state->unit);
532 +       state->sanity_errors += 100;
533 +       sanity = 1;
534 +    }
535 +    if (!state->stateful && !flushed) {
536 +       printk(KERN_DEBUG "mppe_decompress[%d]: FLUSHED bit not set in "
537 +              "stateless mode!\n", state->unit);
538 +       state->sanity_errors += 100;
539 +       sanity = 1;
540 +    }
541 +    if (state->stateful && ((ccount & 0xff) == 0xff) && !flushed) {
542 +       printk(KERN_DEBUG "mppe_decompress[%d]: FLUSHED bit not set on "
543 +              "flag packet!\n", state->unit);
544 +       state->sanity_errors += 100;
545 +       sanity = 1;
546 +    }
547 +
548 +    if (sanity) {
549 +       if (state->sanity_errors < SANITY_MAX)
550 +           return DECOMP_ERROR;
551 +       else
552 +           /*
553 +            * Take LCP down if the peer is sending too many bogons.
554 +            * We don't want to do this for a single or just a few
555 +            * instances since it could just be due to packet corruption.
556 +            */
557 +           return DECOMP_FATALERROR;
558 +    }
559 +
560 +    /*
561 +     * Check the coherency count.
562 +     */
563 +
564 +    if (!state->stateful) {
565 +       /* RFC 3078, sec 8.1.  Rekey for every packet. */
566 +       while (state->ccount != ccount) {
567 +           mppe_rekey(state, 0);
568 +           state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE;
569 +       }
570 +    } else {
571 +       /* RFC 3078, sec 8.2. */
572 +       if (!state->discard) {
573 +           /* normal state */
574 +           state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE;
575 +           if (ccount != state->ccount) {
576 +               /*
577 +                * (ccount > state->ccount)
578 +                * Packet loss detected, enter the discard state.
579 +                * Signal the peer to rekey (by sending a CCP Reset-Request).
580 +                */
581 +               state->discard = 1;
582 +               return DECOMP_ERROR;
583 +           }
584 +       } else {
585 +           /* discard state */
586 +          if (!flushed) {
587 +               /* ccp.c will be silent (no additional CCP Reset-Requests). */
588 +               return DECOMP_ERROR;
589 +           } else {
590 +               /* Rekey for every missed "flag" packet. */
591 +               while ((ccount & ~0xff) != (state->ccount & ~0xff)) {
592 +                   mppe_rekey(state, 0);
593 +                   state->ccount = (state->ccount + 256) % MPPE_CCOUNT_SPACE;
594 +               }
595 +
596 +               /* reset */
597 +               state->discard = 0;
598 +               state->ccount = ccount;
599 +               /*
600 +                * Another problem with RFC 3078 here.  It implies that the
601 +                * peer need not send a Reset-Ack packet.  But RFC 1962
602 +                * requires it.  Hopefully, M$ does send a Reset-Ack; even
603 +                * though it isn't required for MPPE synchronization, it is
604 +                * required to reset CCP state.
605 +                */
606 +           }
607 +       }
608 +       if (flushed)
609 +           mppe_rekey(state, 0);
610 +    }
611 +
612 +    /*
613 +     * Fill in the first part of the PPP header.  The protocol field
614 +     * comes from the decrypted data.
615 +     */
616 +    obuf[0] = PPP_ADDRESS(ibuf);       /* +1 */
617 +    obuf[1] = PPP_CONTROL(ibuf);       /* +2 */
618 +    obuf  += 2;
619 +    ibuf  += PPP_HDRLEN + MPPE_OVHD;
620 +    isize -= PPP_HDRLEN + MPPE_OVHD;   /* -6 */
621 +                                       /* net: -4 */
622 +
623 +    /* And finally, decrypt the packet. */
624 +    arcfour_decrypt(&state->arcfour_context, ibuf, isize, obuf);
625 +
626 +    state->stats.unc_bytes += osize;
627 +    state->stats.unc_packets++;
628 +    state->stats.comp_bytes += isize;
629 +    state->stats.comp_packets++;
630 +
631 +    /* good packet credit */
632 +    state->sanity_errors >>= 1;
633 +
634 +    return osize;
635 +}
636 +
637 +/*
638 + * Incompressible data has arrived (this should never happen!).
639 + * We should probably drop the link if the protocol is in the range
640 + * of what should be encrypted.  At the least, we should drop this
641 + * packet.  (How to do this?)
642 + */
643 +static void
644 +mppe_incomp(void *arg, unsigned char *ibuf, int icnt)
645 +{
646 +    ppp_mppe_state *state = (ppp_mppe_state *) arg;
647 +
648 +    if (state->debug &&
649 +       (PPP_PROTOCOL(ibuf) >= 0x0021 && PPP_PROTOCOL(ibuf) <= 0x00fa))
650 +       printk(KERN_DEBUG "mppe_incomp[%d]: incompressible (unencrypted) data! "
651 +              "(proto %04x)\n", state->unit, PPP_PROTOCOL(ibuf));
652 +
653 +    state->stats.inc_bytes += icnt;
654 +    state->stats.inc_packets++;
655 +    state->stats.unc_bytes += icnt;
656 +    state->stats.unc_packets++;
657 +}
658 +
659 +/*************************************************************
660 + * Module interface table
661 + *************************************************************/
662 +
663 +/* These are in ppp.c (2.2.x) or ppp_generic.c (2.4.x) */
664 +extern int  ppp_register_compressor   (struct compressor *cp);
665 +extern void ppp_unregister_compressor (struct compressor *cp);
666 +
667 +/*
668 + * Procedures exported to if_ppp.c.
669 + */
670 +struct compressor ppp_mppe = {
671 +    CI_MPPE,           /* compress_proto */
672 +    mppe_alloc,                /* comp_alloc */
673 +    mppe_free,         /* comp_free */
674 +    mppe_comp_init,    /* comp_init */
675 +    mppe_comp_reset,   /* comp_reset */
676 +    mppe_compress,     /* compress */
677 +    mppe_comp_stats,   /* comp_stat */
678 +    mppe_alloc,                /* decomp_alloc */
679 +    mppe_free,         /* decomp_free */
680 +    mppe_decomp_init,  /* decomp_init */
681 +    mppe_decomp_reset, /* decomp_reset */
682 +    mppe_decompress,   /* decompress */
683 +    mppe_incomp,       /* incomp */
684 +    mppe_comp_stats,   /* decomp_stat */
685 +};
686 +
687 +/* 2.2 compatibility defines */
688 +#ifndef __init
689 +#define __init
690 +#endif
691 +#ifndef __exit
692 +#define __exit
693 +#endif
694 +#ifndef MODULE_LICENSE
695 +#define MODULE_LICENSE(license)
696 +#endif
697 +
698 +int __init
699 +ppp_mppe_init(void)
700 +{  
701 +    int answer = ppp_register_compressor(&ppp_mppe);
702 +
703 +    if (answer == 0)
704 +       printk(KERN_INFO "PPP MPPE Compression module registered\n");
705 +    return answer;
706 +}
707 +
708 +void __exit
709 +ppp_mppe_cleanup(void)
710 +{
711 +    ppp_unregister_compressor(&ppp_mppe);
712 +}
713 +
714 +module_init(ppp_mppe_init);
715 +module_exit(ppp_mppe_cleanup);
716 +MODULE_LICENSE("BSD without advertisement clause");
717 diff -urN linux-2.4.18.org/drivers/net/sha1.c linux-2.4.18/drivers/net/sha1.c
718 --- linux-2.4.18.org/drivers/net/sha1.c Thu Jan  1 01:00:00 1970
719 +++ linux-2.4.18/drivers/net/sha1.c     Tue Apr  2 16:01:37 2002
720 @@ -0,0 +1,185 @@
721 +/*
722 + * ftp://ftp.funet.fi/pub/crypt/hash/sha/sha1.c
723 + * 
724 + * SHA-1 in C
725 + * By Steve Reid <steve@edmweb.com>
726 + * 100% Public Domain
727 + * 
728 + * Test Vectors (from FIPS PUB 180-1)
729 + * "abc"
730 + * A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
731 + * "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
732 + * 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
733 + * A million repetitions of "a"
734 + * 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
735 + */
736 +
737 +/* #define SHA1HANDSOFF * Copies data before messing with it. */
738 +
739 +#if defined(__linux__)
740 +#include <asm/byteorder.h>
741 +#include <linux/string.h>
742 +#else if defined(__solaris__)
743 +#include <sys/isa_defs.h>
744 +#include <sys/ddi.h>
745 +#include <sys/sunddi.h>
746 +#define memcpy(d, s, c) bcopy(s, d, c)
747 +#define memset(d, b, c) bzero(d, c)
748 +#endif
749 +
750 +#include "sha1.h"
751 +
752 +static void SHA1_Transform(unsigned long[5], const unsigned char[64]);
753 +
754 +#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
755 +
756 +/* blk0() and blk() perform the initial expand. */
757 +/* I got the idea of expanding during the round function from SSLeay */
758 +#if defined(__LITTLE_ENDIAN) || defined(_LITTLE_ENDIAN)
759 +#define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \
760 +    |(rol(block->l[i],8)&0x00FF00FF))
761 +#elif defined(__BIG_ENDIAN) || defined(_BIG_ENDIAN)
762 +#define blk0(i) block->l[i]
763 +#else
764 +#error Endianness not defined
765 +#endif
766 +#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
767 +    ^block->l[(i+2)&15]^block->l[i&15],1))
768 +
769 +/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
770 +#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);
771 +#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30);
772 +#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);
773 +#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
774 +#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
775 +
776 +
777 +/* Hash a single 512-bit block. This is the core of the algorithm. */
778 +
779 +static void
780 +SHA1_Transform(unsigned long state[5], const unsigned char buffer[64])
781 +{
782 +    unsigned long a, b, c, d, e;
783 +    typedef union {
784 +       unsigned char c[64];
785 +       unsigned long l[16];
786 +    } CHAR64LONG16;
787 +    CHAR64LONG16 *block;
788 +
789 +#ifdef SHA1HANDSOFF
790 +    static unsigned char workspace[64];
791 +    block = (CHAR64LONG16 *) workspace;
792 +    memcpy(block, buffer, 64);
793 +#else
794 +    block = (CHAR64LONG16 *) buffer;
795 +#endif
796 +    /* Copy context->state[] to working vars */
797 +    a = state[0];
798 +    b = state[1];
799 +    c = state[2];
800 +    d = state[3];
801 +    e = state[4];
802 +    /* 4 rounds of 20 operations each. Loop unrolled. */
803 +    R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
804 +    R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
805 +    R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
806 +    R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
807 +    R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
808 +    R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
809 +    R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
810 +    R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
811 +    R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
812 +    R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
813 +    R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
814 +    R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
815 +    R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
816 +    R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
817 +    R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
818 +    R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
819 +    R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
820 +    R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
821 +    R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
822 +    R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
823 +    /* Add the working vars back into context.state[] */
824 +    state[0] += a;
825 +    state[1] += b;
826 +    state[2] += c;
827 +    state[3] += d;
828 +    state[4] += e;
829 +    /* Wipe variables */
830 +    a = b = c = d = e = 0;
831 +}
832 +
833 +
834 +/* SHA1Init - Initialize new context */
835 +
836 +void
837 +SHA1_Init(SHA1_CTX *context)
838 +{
839 +    /* SHA1 initialization constants */
840 +    context->state[0] = 0x67452301;
841 +    context->state[1] = 0xEFCDAB89;
842 +    context->state[2] = 0x98BADCFE;
843 +    context->state[3] = 0x10325476;
844 +    context->state[4] = 0xC3D2E1F0;
845 +    context->count[0] = context->count[1] = 0;
846 +}
847 +
848 +
849 +/* Run your data through this. */
850 +
851 +void
852 +SHA1_Update(SHA1_CTX *context, const unsigned char *data, unsigned int len)
853 +{
854 +    unsigned int i, j;
855 +
856 +    j = (context->count[0] >> 3) & 63;
857 +    if ((context->count[0] += len << 3) < (len << 3)) context->count[1]++;
858 +    context->count[1] += (len >> 29);
859 +    if ((j + len) > 63) {
860 +       memcpy(&context->buffer[j], data, (i = 64-j));
861 +       SHA1_Transform(context->state, context->buffer);
862 +       for ( ; i + 63 < len; i += 64) {
863 +           SHA1_Transform(context->state, &data[i]);
864 +       }
865 +       j = 0;
866 +    }
867 +    else
868 +       i = 0;
869 +
870 +    memcpy(&context->buffer[j], &data[i], len - i);
871 +}
872 +
873 +
874 +/* Add padding and return the message digest. */
875 +
876 +void
877 +SHA1_Final(unsigned char digest[20], SHA1_CTX *context)
878 +{
879 +    unsigned long i, j;
880 +    unsigned char finalcount[8];
881 +
882 +    for (i = 0; i < 8; i++) {
883 +        finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
884 +         >> ((3-(i & 3)) * 8) ) & 255);  /* Endian independent */
885 +    }
886 +    SHA1_Update(context, (unsigned char *) "\200", 1);
887 +    while ((context->count[0] & 504) != 448) {
888 +       SHA1_Update(context, (unsigned char *) "\0", 1);
889 +    }
890 +    SHA1_Update(context, finalcount, 8);  /* Should cause a SHA1Transform() */
891 +    for (i = 0; i < 20; i++) {
892 +       digest[i] = (unsigned char)
893 +                    ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
894 +    }
895 +    /* Wipe variables */
896 +    i = j = 0;
897 +    memset(context->buffer, 0, 64);
898 +    memset(context->state, 0, 20);
899 +    memset(context->count, 0, 8);
900 +    memset(&finalcount, 0, 8);
901 +#ifdef SHA1HANDSOFF  /* make SHA1Transform overwrite it's own static vars */
902 +    SHA1Transform(context->state, context->buffer);
903 +#endif
904 +}
905 +
906 diff -urN linux-2.4.18.org/drivers/net/sha1.h linux-2.4.18/drivers/net/sha1.h
907 --- linux-2.4.18.org/drivers/net/sha1.h Thu Jan  1 01:00:00 1970
908 +++ linux-2.4.18/drivers/net/sha1.h     Tue Apr  2 16:01:37 2002
909 @@ -0,0 +1,18 @@
910 +/* sha1.h */
911 +
912 +#ifndef _SHA1_H
913 +#define _SHA1_H
914 +
915 +typedef struct {
916 +    unsigned long state[5];
917 +    unsigned long count[2];
918 +    unsigned char buffer[64];
919 +} SHA1_CTX;
920 +
921 +#define SHA1_SIGNATURE_SIZE 20
922 +
923 +extern void SHA1_Init(SHA1_CTX *);
924 +extern void SHA1_Update(SHA1_CTX *, const unsigned char *, unsigned int);
925 +extern void SHA1_Final(unsigned char[SHA1_SIGNATURE_SIZE], SHA1_CTX *);
926 +
927 +#endif /* _SHA1_H */
928 --- linux/include/linux/ppp-comp.h.orig Fri Aug  6 10:44:11 1999
929 +++ linux/include/linux/ppp-comp.h      Mon Mar 25 09:11:33 2002
930 @@ -187,6 +187,100 @@
931  #define DEFLATE_CHK_SEQUENCE   0
932  
933  /*
934 + * Definitions for MPPE.
935 + */
936 +
937 +#define CI_MPPE                        18      /* config option for MPPE */
938 +#define CILEN_MPPE             6       /* length of config option */
939 +
940 +#define MPPE_PAD               4       /* MPPE growth per frame */
941 +#define MPPE_MAX_KEY_LEN       16      /* largest key length (128-bit) */
942 +
943 +/* option bits for ccp_options.mppe */
944 +#define MPPE_OPT_40            0x01    /* 40 bit */
945 +#define MPPE_OPT_128           0x02    /* 128 bit */
946 +#define MPPE_OPT_STATEFUL      0x04    /* stateful mode */
947 +/* unsupported opts */
948 +#define MPPE_OPT_56            0x08    /* 56 bit */
949 +#define MPPE_OPT_MPPC          0x10    /* MPPC compression */
950 +#define MPPE_OPT_D             0x20    /* Unknown */
951 +#define MPPE_OPT_UNSUPPORTED (MPPE_OPT_56|MPPE_OPT_MPPC|MPPE_OPT_D)
952 +#define MPPE_OPT_UNKNOWN       0x40    /* Bits !defined in RFC 3078 were set */
953 +
954 +/*
955 + * This is not nice ... the alternative is a bitfield struct though.
956 + * And unfortunately, we cannot share the same bits for the option
957 + * names above since C and H are the same bit.  We could do a u_int32
958 + * but then we have to do a htonl() all the time and/or we still need
959 + * to know which octet is which.
960 + */
961 +#define MPPE_C_BIT             0x01    /* MPPC */
962 +#define MPPE_D_BIT             0x10    /* Obsolete, usage unknown */
963 +#define MPPE_L_BIT             0x20    /* 40-bit */
964 +#define MPPE_S_BIT             0x40    /* 128-bit */
965 +#define MPPE_M_BIT             0x80    /* 56-bit, not supported */
966 +#define MPPE_H_BIT             0x01    /* Stateless (in a different byte) */
967 +
968 +/* Does not include H bit; used for least significant octet only. */
969 +#define MPPE_ALL_BITS (MPPE_D_BIT|MPPE_L_BIT|MPPE_S_BIT|MPPE_M_BIT|MPPE_H_BIT)
970 +
971 +/* Build a CI from mppe opts (see RFC 3078) */
972 +#define MPPE_OPTS_TO_CI(opts, ci)              \
973 +    do {                                       \
974 +       u_char *ptr = ci; /* u_char[4] */       \
975 +                                               \
976 +       /* H bit */                             \
977 +       if (opts & MPPE_OPT_STATEFUL)           \
978 +           *ptr++ = 0x0;                       \
979 +       else                                    \
980 +           *ptr++ = MPPE_H_BIT;                \
981 +       *ptr++ = 0;                             \
982 +       *ptr++ = 0;                             \
983 +                                               \
984 +       /* S,L bits */                          \
985 +       *ptr = 0;                               \
986 +       if (opts & MPPE_OPT_128)                \
987 +           *ptr |= MPPE_S_BIT;                 \
988 +       if (opts & MPPE_OPT_40)                 \
989 +           *ptr |= MPPE_L_BIT;                 \
990 +       /* M,D,C bits not supported */          \
991 +    } while (/* CONSTCOND */ 0)
992 +
993 +/* The reverse of the above */
994 +#define MPPE_CI_TO_OPTS(ci, opts)              \
995 +    do {                                       \
996 +       u_char *ptr = ci; /* u_char[4] */       \
997 +                                               \
998 +       opts = 0;                               \
999 +                                               \
1000 +       /* H bit */                             \
1001 +       if (!(ptr[0] & MPPE_H_BIT))             \
1002 +           opts |= MPPE_OPT_STATEFUL;          \
1003 +                                               \
1004 +       /* S,L bits */                          \
1005 +       if (ptr[3] & MPPE_S_BIT)                \
1006 +           opts |= MPPE_OPT_128;               \
1007 +       if (ptr[3] & MPPE_L_BIT)                \
1008 +           opts |= MPPE_OPT_40;                \
1009 +                                               \
1010 +       /* M,D,C bits */                        \
1011 +       if (ptr[3] & MPPE_M_BIT)                \
1012 +           opts |= MPPE_OPT_56;                \
1013 +       if (ptr[3] & MPPE_D_BIT)                \
1014 +           opts |= MPPE_OPT_D;                 \
1015 +       if (ptr[3] & MPPE_C_BIT)                \
1016 +           opts |= MPPE_OPT_MPPC;              \
1017 +                                               \
1018 +       /* Other bits */                        \
1019 +       if (ptr[0] & ~MPPE_H_BIT)               \
1020 +           opts |= MPPE_OPT_UNKNOWN;           \
1021 +       if (ptr[1] || ptr[2])                   \
1022 +           opts |= MPPE_OPT_UNKNOWN;           \
1023 +       if (ptr[3] & ~MPPE_ALL_BITS)            \
1024 +           opts |= MPPE_OPT_UNKNOWN;           \
1025 +    } while (/* CONSTCOND */ 0)
1026 +
1027 +/*
1028   * Definitions for other, as yet unsupported, compression methods.
1029   */
1030  
1031 --- linux/drivers/net/Config.in.orig    Mon Mar 25 09:07:26 2002
1032 +++ linux/drivers/net/Config.in Mon Mar 25 11:18:03 2002
1033 @@ -279,6 +279,7 @@
1034     dep_tristate '  PPP support for sync tty ports' CONFIG_PPP_SYNC_TTY $CONFIG_PPP
1035     dep_tristate '  PPP Deflate compression' CONFIG_PPP_DEFLATE $CONFIG_PPP
1036     dep_tristate '  PPP BSD-Compress compression' CONFIG_PPP_BSDCOMP $CONFIG_PPP
1037 +   dep_tristate '  PPP MPPE compression (encryption)' CONFIG_PPP_MPPE $CONFIG_PPP
1038     if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
1039        dep_tristate '  PPP over Ethernet (EXPERIMENTAL)' CONFIG_PPPOE $CONFIG_PPP
1040     fi
1041 --- linux/drivers/net/Makefile.orig     Mon Mar 25 09:07:26 2002
1042 +++ linux/drivers/net/Makefile  Mon Mar 25 11:58:11 2002
1043 @@ -18,8 +18,9 @@
1044  export-objs     :=     8390.o arlan.o aironet4500_core.o aironet4500_card.o \
1045                         ppp_async.o ppp_generic.o slhc.o pppox.o auto_irq.o \
1046                         net_init.o mii.o
1047 -list-multi     :=      rcpci.o
1048 +list-multi     :=      rcpci.o ppp_mppe.o
1049  rcpci-objs     :=      rcpci45.o rclanmtl.o
1050 +ppp_mppe-objs  :=      ppp_mppe_compress.o sha1.o arcfour.o
1051  
1052  ifeq ($(CONFIG_TULIP),y)
1053    obj-y += tulip/tulip.o
1054 @@ -139,6 +140,14 @@
1055  obj-$(CONFIG_PPP_BSDCOMP) += bsd_comp.o
1056  obj-$(CONFIG_PPPOE) += pppox.o pppoe.o
1057  
1058 +ifeq ($(CONFIG_PPP_MPPE),y)
1059 +  obj-y += $(ppp_mppe-objs)
1060 +else
1061 +  ifeq ($(CONFIG_PPP_MPPE),m)
1062 +    obj-m += ppp_mppe.o
1063 +  endif
1064 +endif
1065 +
1066  obj-$(CONFIG_SLIP) += slip.o
1067  ifeq ($(CONFIG_SLIP_COMPRESSED),y)
1068    obj-$(CONFIG_SLIP) += slhc.o
1069 @@ -237,3 +246,5 @@
1070  rcpci.o: $(rcpci-objs)
1071         $(LD) -r -o $@ $(rcpci-objs)
1072  
1073 +ppp_mppe.o: $(ppp_mppe-objs)
1074 +       $(LD) -r -o $@ $(ppp_mppe-objs)
1075 --- linux/drivers/net/ppp_generic.c.orig        Mon Feb 25 11:37:59 2002
1076 +++ linux/drivers/net/ppp_generic.c     Mon Mar 25 10:19:53 2002
1077 @@ -1006,8 +1006,15 @@
1078         /* try to do packet compression */
1079         if ((ppp->xstate & SC_COMP_RUN) && ppp->xc_state != 0
1080             && proto != PPP_LCP && proto != PPP_CCP) {
1081 -               new_skb = alloc_skb(ppp->dev->mtu + ppp->dev->hard_header_len,
1082 -                                   GFP_ATOMIC);
1083 +               int new_skb_size = ppp->dev->mtu + ppp->dev->hard_header_len;
1084 +               int compressor_skb_size = ppp->dev->mtu + PPP_HDRLEN;
1085 +
1086 +               if (ppp->xcomp->compress_proto == CI_MPPE) {
1087 +                       /* CCP [must have] reduced MTU by MPPE_PAD. */
1088 +                       new_skb_size += MPPE_PAD;
1089 +                       compressor_skb_size += MPPE_PAD;
1090 +               }
1091 +               new_skb = alloc_skb(new_skb_size, GFP_ATOMIC);
1092                 if (new_skb == 0) {
1093                         printk(KERN_ERR "PPP: no memory (comp pkt)\n");
1094                         goto drop;
1095 @@ -1019,15 +1026,27 @@
1096                 /* compressor still expects A/C bytes in hdr */
1097                 len = ppp->xcomp->compress(ppp->xc_state, skb->data - 2,
1098                                            new_skb->data, skb->len + 2,
1099 -                                          ppp->dev->mtu + PPP_HDRLEN);
1100 +                                          compressor_skb_size);
1101                 if (len > 0 && (ppp->flags & SC_CCP_UP)) {
1102                         kfree_skb(skb);
1103                         skb = new_skb;
1104                         skb_put(skb, len);
1105                         skb_pull(skb, 2);       /* pull off A/C bytes */
1106 -               } else {
1107 +               } else if (len == 0) {
1108                         /* didn't compress, or CCP not up yet */
1109                         kfree_skb(new_skb);
1110 +               } else {
1111 +                       /*
1112 +                        * (len < 0)
1113 +                        * MPPE requires that we do not send unencrypted
1114 +                        * frames.  The compressor will return -1 if we
1115 +                        * should drop the frame.  We cannot simply test
1116 +                        * the compress_proto because MPPE and MPPC share
1117 +                        * the same number.
1118 +                        */
1119 +                       printk(KERN_ERR "ppp: compressor dropped pkt\n");
1120 +                       kfree_skb(new_skb);
1121 +                       goto drop;
1122                 }
1123         }
1124  
1125 @@ -1515,7 +1534,7 @@
1126         int len;
1127  
1128         if (proto == PPP_COMP) {
1129 -               ns = dev_alloc_skb(ppp->mru + PPP_HDRLEN);
1130 +               ns = dev_alloc_skb(ppp->mru + 128 + PPP_HDRLEN);
1131                 if (ns == 0) {
1132                         printk(KERN_ERR "ppp_decompress_frame: no memory\n");
1133                         goto err;
This page took 0.112988 seconds and 3 git commands to generate.