X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=pppd%2Fccp.c;h=440ddc8f3cb8d14141daf6fbe5bdab14523130fe;hb=39c06d616dd4c9443ed390969e58cd53ca1e314d;hp=fa8a5a0cb950f6993ebe51d008c98b556b1c5272;hpb=b38527fb14af5ebe3d2559e2f861575c722a1ce9;p=ppp.git diff --git a/pppd/ccp.c b/pppd/ccp.c index fa8a5a0..440ddc8 100644 --- a/pppd/ccp.c +++ b/pppd/ccp.c @@ -1,31 +1,39 @@ /* * ccp.c - PPP Compression Control Protocol. * - * Copyright (c) 1994 The Australian National University. - * All rights reserved. + * Copyright (c) 1994-2002 Paul Mackerras. All rights reserved. * - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, provided that the above copyright - * notice appears in all copies. This software is provided without any - * warranty, express or implied. The Australian National University - * makes no representations about the suitability of this software for - * any purpose. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: * - * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY - * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES - * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF - * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. * - * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO - * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, - * OR MODIFICATIONS. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The name(s) of the authors of this software must not be used to + * endorse or promote products derived from this software without + * prior written permission. + * + * 4. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by Paul Mackerras + * ". + * + * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define RCSID "$Id: ccp.c,v 1.34 2002/04/02 13:54:59 dfs Exp $" +#define RCSID "$Id: ccp.c,v 1.44 2003/03/05 23:01:28 fcusack Exp $" #include #include @@ -36,8 +44,8 @@ #include #ifdef MPPE -#include "chap_ms.h" /* mppe_xx_key */ -#include "lcp.h" /* lcp_close() */ +#include "chap_ms.h" /* mppe_xxxx_key, mppe_keys_set */ +#include "lcp.h" /* lcp_close(), lcp_fsm */ #endif static const char rcsid[] = RCSID; @@ -453,7 +461,7 @@ ccp_input(unit, p, len) notice("Compression disabled by peer."); #ifdef MPPE if (ccp_gotoptions[unit].mppe) { - notice("MPPE disabled, closing LCP"); + error("MPPE disabled, closing LCP"); lcp_close(unit, "MPPE disabled by peer"); } #endif @@ -510,6 +518,14 @@ ccp_protrej(unit) { ccp_flags_set(unit, 0, 0); fsm_lowerdown(&ccp_fsm[unit]); + +#ifdef MPPE + if (ccp_gotoptions[unit].mppe) { + error("MPPE required but peer negotiation failed"); + lcp_close(unit, "MPPE required but peer negotiation failed"); + } +#endif + } /* @@ -542,10 +558,10 @@ ccp_resetci(f) */ /* Leave only the mschap auth bits set */ - auth_mschap_bits &= ~(PAP_WITHPEER | PAP_PEER | - CHAP_WITHPEER | CHAP_PEER | - CHAP_MD5_WITHPEER | CHAP_MD5_PEER); + auth_mschap_bits &= (CHAP_MS_WITHPEER | CHAP_MS_PEER | + CHAP_MS2_WITHPEER | CHAP_MS2_PEER); /* Count the mschap auths */ + auth_mschap_bits >>= CHAP_MS_SHIFT; numbits = 0; do { numbits += auth_mschap_bits & 1; @@ -562,12 +578,21 @@ ccp_resetci(f) return; } + /* A plugin (eg radius) may not have obtained key material. */ + if (!mppe_keys_set) { + error("MPPE required, but keys are not available. " + "Possible plugin problem?"); + lcp_close(f->unit, "MPPE required but not available"); + return; + } + /* LM auth not supported for MPPE */ if (auth_done[f->unit] & (CHAP_MS_WITHPEER | CHAP_MS_PEER)) { /* This might be noise */ if (go->mppe & MPPE_OPT_40) { notice("Disabling 40-bit MPPE; MS-CHAP LM not supported"); go->mppe &= ~MPPE_OPT_40; + ccp_wantoptions[f->unit].mppe &= ~MPPE_OPT_40; } } @@ -677,7 +702,8 @@ ccp_addci(f, p, lenp) /* * Add the compression types that we can receive, in decreasing - * preference order. + * preference order. Get the kernel to allocate the first one + * in case it gets Acked. */ #ifdef MPPE if (go->mppe) { @@ -729,21 +755,25 @@ ccp_addci(f, p, lenp) p[0] = CI_BSD_COMPRESS; p[1] = CILEN_BSD_COMPRESS; p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits); - for (;;) { - if (go->bsd_bits < BSD_MIN_BITS) { - go->bsd_compress = 0; - break; - } - res = ccp_test(f->unit, p, CILEN_BSD_COMPRESS, 0); - if (res > 0) { - p += CILEN_BSD_COMPRESS; - break; - } else if (res < 0) { - go->bsd_compress = 0; - break; + if (p != p0) { + p += CILEN_BSD_COMPRESS; /* not the first option */ + } else { + for (;;) { + if (go->bsd_bits < BSD_MIN_BITS) { + go->bsd_compress = 0; + break; + } + res = ccp_test(f->unit, p, CILEN_BSD_COMPRESS, 0); + if (res > 0) { + p += CILEN_BSD_COMPRESS; + break; + } else if (res < 0) { + go->bsd_compress = 0; + break; + } + --go->bsd_bits; + p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits); } - --go->bsd_bits; - p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits); } } /* XXX Should Predictor 2 be preferable to Predictor 1? */ @@ -888,12 +918,14 @@ ccp_nakci(f, p, len) MPPE_CI_TO_OPTS(&p[2], try.mppe); if ((try.mppe & MPPE_OPT_STATEFUL) && refuse_mppe_stateful) try.mppe = 0; - else if ((go->mppe & try.mppe) != try.mppe) + else if (((go->mppe | MPPE_OPT_STATEFUL) & try.mppe) != try.mppe) /* Peer must have set options we didn't request (suggest) */ try.mppe = 0; - if (!try.mppe) + if (!try.mppe) { + error("MPPE required but peer negotiation failed"); lcp_close(f->unit, "MPPE required but peer negotiation failed"); + } } #endif /* MPPE */ if (go->deflate && len >= CILEN_DEFLATE @@ -970,6 +1002,7 @@ ccp_rejci(f, p, len) #ifdef MPPE if (go->mppe && len >= CILEN_MPPE && p[0] == CI_MPPE && p[1] == CILEN_MPPE) { + error("MPPE required but peer refused"); lcp_close(f->unit, "MPPE required but peer refused"); p += CILEN_MPPE; len -= CILEN_MPPE; @@ -1047,6 +1080,10 @@ ccp_reqci(f, p, lenp, dont_nak) int len, clen, type, nb; ccp_options *ho = &ccp_hisoptions[f->unit]; ccp_options *ao = &ccp_allowoptions[f->unit]; +#ifdef MPPE + bool rej_for_ci_mppe = 1; /* Are we rejecting based on a bad/missing */ + /* CI_MPPE, or due to other options? */ +#endif ret = CONFACK; retp = p0 = p; @@ -1087,17 +1124,15 @@ ccp_reqci(f, p, lenp, dont_nak) /* Check state opt */ if (ho->mppe & MPPE_OPT_STATEFUL) { + /* + * We can Nak and request stateless, but it's a + * lot easier to just assume the peer will request + * it if he can do it; stateful mode is bad over + * the Internet -- which is where we expect MPPE. + */ if (refuse_mppe_stateful) { - /* - * We can Nak and request stateless, but it's a - * lot easier to just assume the peer will request - * it if he can do it; stateful mode is bad over - * the Internet -- which is where we expect MPPE. - */ newret = CONFREJ; break; - } else { - newret = CONFNAK; } } @@ -1159,6 +1194,12 @@ ccp_reqci(f, p, lenp, dont_nak) newret = CONFREJ; } + /* + * We have accepted MPPE or are willing to negotiate + * MPPE parameters. A CONFREJ is due to subsequent + * (non-MPPE) processing. + */ + rej_for_ci_mppe = 0; break; #endif /* MPPE */ case CI_DEFLATE: @@ -1302,8 +1343,12 @@ ccp_reqci(f, p, lenp, dont_nak) else *lenp = retp - p0; } - if (ret == CONFREJ && ao->mppe) +#ifdef MPPE + if (ret == CONFREJ && ao->mppe && rej_for_ci_mppe) { + error("MPPE required but peer negotiation failed"); lcp_close(f->unit, "MPPE required but peer negotiation failed"); + } +#endif return ret; } @@ -1397,6 +1442,13 @@ ccp_up(f) notice("%s receive compression enabled", method_name(go, NULL)); } else if (ANY_COMPRESS(*ho)) notice("%s transmit compression enabled", method_name(ho, NULL)); +#ifdef MPPE + if (go->mppe) { + BZERO(mppe_recv_key, MPPE_MAX_KEY_LEN); + BZERO(mppe_send_key, MPPE_MAX_KEY_LEN); + continue_networks(f->unit); /* Bring up IP et al */ + } +#endif } /* @@ -1410,6 +1462,16 @@ ccp_down(f) UNTIMEOUT(ccp_rack_timeout, f); ccp_localstate[f->unit] = 0; ccp_flags_set(f->unit, 1, 0); +#ifdef MPPE + if (ccp_gotoptions[f->unit].mppe) { + ccp_gotoptions[f->unit].mppe = 0; + if (lcp_fsm[f->unit].state == OPENED) { + /* If LCP is not already going down, make sure it does. */ + error("MPPE disabled"); + lcp_close(f->unit, "MPPE disabled"); + } + } +#endif } /* @@ -1480,6 +1542,9 @@ ccp_printpkt(p, plen, printer, arg) (p[5] & MPPE_D_BIT)? "+D": "-D", (p[5] & MPPE_C_BIT)? "+C": "-C", (mppe_opts & MPPE_OPT_UNKNOWN)? " +U": ""); + if (mppe_opts & MPPE_OPT_UNKNOWN) + printer(arg, " (%.2x %.2x %.2x %.2x)", + p[2], p[3], p[4], p[5]); p += CILEN_MPPE; } break;