1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * lcp.c - PPP Link Control Protocol. 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * Copyright 2000-2002 Sun Microsystems, Inc. All rights reserved. 5*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 6*7c478bd9Sstevel@tonic-gate * 7*7c478bd9Sstevel@tonic-gate * Copyright (c) 1989 Carnegie Mellon University. 8*7c478bd9Sstevel@tonic-gate * All rights reserved. 9*7c478bd9Sstevel@tonic-gate * 10*7c478bd9Sstevel@tonic-gate * Redistribution and use in source and binary forms are permitted 11*7c478bd9Sstevel@tonic-gate * provided that the above copyright notice and this paragraph are 12*7c478bd9Sstevel@tonic-gate * duplicated in all such forms and that any documentation, 13*7c478bd9Sstevel@tonic-gate * advertising materials, and other materials related to such 14*7c478bd9Sstevel@tonic-gate * distribution and use acknowledge that the software was developed 15*7c478bd9Sstevel@tonic-gate * by Carnegie Mellon University. The name of the 16*7c478bd9Sstevel@tonic-gate * University may not be used to endorse or promote products derived 17*7c478bd9Sstevel@tonic-gate * from this software without specific prior written permission. 18*7c478bd9Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19*7c478bd9Sstevel@tonic-gate * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20*7c478bd9Sstevel@tonic-gate * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate 23*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 24*7c478bd9Sstevel@tonic-gate #define RCSID "$Id: lcp.c,v 1.54 2000/04/27 03:51:18 masputra Exp $" 25*7c478bd9Sstevel@tonic-gate 26*7c478bd9Sstevel@tonic-gate /* 27*7c478bd9Sstevel@tonic-gate * TODO: 28*7c478bd9Sstevel@tonic-gate */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #include <stdio.h> 31*7c478bd9Sstevel@tonic-gate #include <string.h> 32*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 33*7c478bd9Sstevel@tonic-gate #include <ctype.h> 34*7c478bd9Sstevel@tonic-gate #if defined(CHAPMS) || defined(CHAPMSV2) 35*7c478bd9Sstevel@tonic-gate #ifdef HAVE_CRYPT_H 36*7c478bd9Sstevel@tonic-gate #include <crypt.h> 37*7c478bd9Sstevel@tonic-gate #endif 38*7c478bd9Sstevel@tonic-gate #ifndef USE_CRYPT 39*7c478bd9Sstevel@tonic-gate #include <des.h> 40*7c478bd9Sstevel@tonic-gate #endif 41*7c478bd9Sstevel@tonic-gate #ifdef SOL2 42*7c478bd9Sstevel@tonic-gate #include <errno.h> 43*7c478bd9Sstevel@tonic-gate #endif 44*7c478bd9Sstevel@tonic-gate #endif 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate #include "pppd.h" 47*7c478bd9Sstevel@tonic-gate #include "fsm.h" 48*7c478bd9Sstevel@tonic-gate #include "lcp.h" 49*7c478bd9Sstevel@tonic-gate #include "chap.h" 50*7c478bd9Sstevel@tonic-gate #include "magic.h" 51*7c478bd9Sstevel@tonic-gate #include "patchlevel.h" 52*7c478bd9Sstevel@tonic-gate 53*7c478bd9Sstevel@tonic-gate #if !defined(lint) && !defined(_lint) 54*7c478bd9Sstevel@tonic-gate static const char rcsid[] = RCSID; 55*7c478bd9Sstevel@tonic-gate #endif 56*7c478bd9Sstevel@tonic-gate 57*7c478bd9Sstevel@tonic-gate /* 58*7c478bd9Sstevel@tonic-gate * Special failure codes for logging link failure reasons. 59*7c478bd9Sstevel@tonic-gate */ 60*7c478bd9Sstevel@tonic-gate bool peer_nak_auth; /* Peer sent nak for our auth request */ 61*7c478bd9Sstevel@tonic-gate u_short nak_auth_orig; /* Auth proto peer naked */ 62*7c478bd9Sstevel@tonic-gate u_short nak_auth_proto; /* Auth proto peer suggested instead */ 63*7c478bd9Sstevel@tonic-gate bool unsolicited_nak_auth; /* Peer asked us to authenticate */ 64*7c478bd9Sstevel@tonic-gate u_short unsolicit_auth_proto; /* Auth proto peer wants */ 65*7c478bd9Sstevel@tonic-gate bool peer_reject_auth; /* Peer sent reject for auth */ 66*7c478bd9Sstevel@tonic-gate u_short reject_auth_proto; /* Protocol that peer rejected */ 67*7c478bd9Sstevel@tonic-gate bool rejected_peers_auth; /* We sent a reject to the peer */ 68*7c478bd9Sstevel@tonic-gate u_short rejected_auth_proto; /* Protocol that peer wanted to use */ 69*7c478bd9Sstevel@tonic-gate bool naked_peers_auth; /* We sent a nak to the peer */ 70*7c478bd9Sstevel@tonic-gate u_short naked_auth_orig; /* Protocol that we wanted to use */ 71*7c478bd9Sstevel@tonic-gate u_short naked_auth_proto; /* Protocol that peer wants us to use */ 72*7c478bd9Sstevel@tonic-gate 73*7c478bd9Sstevel@tonic-gate /* 74*7c478bd9Sstevel@tonic-gate * LCP-related command-line options. 75*7c478bd9Sstevel@tonic-gate */ 76*7c478bd9Sstevel@tonic-gate int lcp_echo_interval = 0; /* Interval between LCP echo-requests */ 77*7c478bd9Sstevel@tonic-gate int lcp_echo_fails = 0; /* Tolerance to unanswered echo-requests */ 78*7c478bd9Sstevel@tonic-gate bool lax_recv = 0; /* accept control chars in asyncmap */ 79*7c478bd9Sstevel@tonic-gate static int use_accm_test = 2; /* use big echo-requests to check ACCM */ 80*7c478bd9Sstevel@tonic-gate #define ACCM_TEST_FAILS 5 81*7c478bd9Sstevel@tonic-gate 82*7c478bd9Sstevel@tonic-gate #define _tostr2(x) #x 83*7c478bd9Sstevel@tonic-gate #define _tostr(x) _tostr2(x) 84*7c478bd9Sstevel@tonic-gate static char identstr[256] = /* Identification string */ 85*7c478bd9Sstevel@tonic-gate "ppp-" VERSION "." _tostr(PATCHLEVEL) IMPLEMENTATION; 86*7c478bd9Sstevel@tonic-gate static int noident = 0; /* 1 to disable; 2 to reject */ 87*7c478bd9Sstevel@tonic-gate static int sentident = 0; /* counts the # of ident codes sent */ 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate /* set if we're allowed to send an unsolicited Configure-Nak for MRU. */ 90*7c478bd9Sstevel@tonic-gate static bool unsolicit_mru; 91*7c478bd9Sstevel@tonic-gate 92*7c478bd9Sstevel@tonic-gate static int setescape __P((char **, option_t *)); 93*7c478bd9Sstevel@tonic-gate 94*7c478bd9Sstevel@tonic-gate static bool do_msft_workaround = 1; 95*7c478bd9Sstevel@tonic-gate static int setasyncmap __P((char **, option_t *)); 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate bool noendpoint = 0; /* don't send/accept endpoint discriminator */ 98*7c478bd9Sstevel@tonic-gate static int setendpoint __P((char **, option_t *)); 99*7c478bd9Sstevel@tonic-gate 100*7c478bd9Sstevel@tonic-gate static char *callback_strings[] = { 101*7c478bd9Sstevel@tonic-gate "auth", "dialstring", "location", "E.164", "X.500", "", "CBCP", NULL 102*7c478bd9Sstevel@tonic-gate }; 103*7c478bd9Sstevel@tonic-gate 104*7c478bd9Sstevel@tonic-gate /* This is used in packet printing even if NEGOTIATE_FCS isn't enabled */ 105*7c478bd9Sstevel@tonic-gate static char *fcsalt_strings[] = { 106*7c478bd9Sstevel@tonic-gate "null", "crc16", "crc32", NULL 107*7c478bd9Sstevel@tonic-gate }; 108*7c478bd9Sstevel@tonic-gate 109*7c478bd9Sstevel@tonic-gate #ifdef NEGOTIATE_FCS 110*7c478bd9Sstevel@tonic-gate static int setfcsallow __P((char **, option_t *)); 111*7c478bd9Sstevel@tonic-gate static int setfcswant __P((char **, option_t *)); 112*7c478bd9Sstevel@tonic-gate #endif 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate /* Backward compatibility for Linux */ 115*7c478bd9Sstevel@tonic-gate #ifndef PPP_MAXMRU 116*7c478bd9Sstevel@tonic-gate #define PPP_MTU 1500 /* Default MTU (size of Info field) */ 117*7c478bd9Sstevel@tonic-gate #define PPP_MAXMTU 65535 - (PPP_HDRLEN + PPP_FCSLEN) 118*7c478bd9Sstevel@tonic-gate #define PPP_MINMTU 64 119*7c478bd9Sstevel@tonic-gate #define PPP_MAXMRU 65000 /* Largest MRU we allow */ 120*7c478bd9Sstevel@tonic-gate #define PPP_MINMRU 128 121*7c478bd9Sstevel@tonic-gate #endif 122*7c478bd9Sstevel@tonic-gate 123*7c478bd9Sstevel@tonic-gate static option_t lcp_option_list[] = { 124*7c478bd9Sstevel@tonic-gate /* LCP options */ 125*7c478bd9Sstevel@tonic-gate { "noaccomp", o_bool, &lcp_wantoptions[0].neg_accompression, 126*7c478bd9Sstevel@tonic-gate "Disable address/control compression", 127*7c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_accompression }, 128*7c478bd9Sstevel@tonic-gate { "-ac", o_bool, &lcp_wantoptions[0].neg_accompression, 129*7c478bd9Sstevel@tonic-gate "Disable address/control compression", 130*7c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_accompression }, 131*7c478bd9Sstevel@tonic-gate { "default-asyncmap", o_bool, &lcp_wantoptions[0].neg_asyncmap, 132*7c478bd9Sstevel@tonic-gate "Disable asyncmap negotiation", 133*7c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_asyncmap }, 134*7c478bd9Sstevel@tonic-gate { "-am", o_bool, &lcp_wantoptions[0].neg_asyncmap, 135*7c478bd9Sstevel@tonic-gate "Disable asyncmap negotiation", 136*7c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_asyncmap }, 137*7c478bd9Sstevel@tonic-gate { "asyncmap", o_special, (void *)setasyncmap, 138*7c478bd9Sstevel@tonic-gate "Set asyncmap (for received packets)" }, 139*7c478bd9Sstevel@tonic-gate { "-as", o_special, (void *)setasyncmap, 140*7c478bd9Sstevel@tonic-gate "Set asyncmap (for received packets)" }, 141*7c478bd9Sstevel@tonic-gate { "nomagic", o_bool, &lcp_wantoptions[0].neg_magicnumber, 142*7c478bd9Sstevel@tonic-gate "Disable magic number option (looped-back line detect)", 143*7c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_magicnumber }, 144*7c478bd9Sstevel@tonic-gate { "-mn", o_bool, &lcp_wantoptions[0].neg_magicnumber, 145*7c478bd9Sstevel@tonic-gate "Disable magic number option (looped-back line detect)", 146*7c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_magicnumber }, 147*7c478bd9Sstevel@tonic-gate { "default-mru", o_bool, &lcp_wantoptions[0].neg_mru, 148*7c478bd9Sstevel@tonic-gate "Disable MRU negotiation (use default 1500)", 149*7c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_mru }, 150*7c478bd9Sstevel@tonic-gate { "-mru", o_bool, &lcp_wantoptions[0].neg_mru, 151*7c478bd9Sstevel@tonic-gate "Disable MRU negotiation (use default 1500)", 152*7c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_mru }, 153*7c478bd9Sstevel@tonic-gate { "mru", o_int, &lcp_wantoptions[0].mru, 154*7c478bd9Sstevel@tonic-gate "Set MRU (maximum received packet size) for negotiation", 155*7c478bd9Sstevel@tonic-gate OPT_LIMITS, &lcp_wantoptions[0].neg_mru, PPP_MAXMRU, PPP_MINMRU }, 156*7c478bd9Sstevel@tonic-gate { "mtu", o_int, &lcp_allowoptions[0].mru, 157*7c478bd9Sstevel@tonic-gate "Set our MTU", OPT_LIMITS|OPT_A2COPY, &lcp_allowoptions[0].mrru, 158*7c478bd9Sstevel@tonic-gate PPP_MAXMTU, PPP_MINMTU }, 159*7c478bd9Sstevel@tonic-gate { "nopcomp", o_bool, &lcp_wantoptions[0].neg_pcompression, 160*7c478bd9Sstevel@tonic-gate "Disable protocol field compression", 161*7c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_pcompression }, 162*7c478bd9Sstevel@tonic-gate { "-pc", o_bool, &lcp_wantoptions[0].neg_pcompression, 163*7c478bd9Sstevel@tonic-gate "Disable protocol field compression", 164*7c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_pcompression }, 165*7c478bd9Sstevel@tonic-gate { "-p", o_bool, &lcp_wantoptions[0].passive, 166*7c478bd9Sstevel@tonic-gate "Set passive mode", 1 }, 167*7c478bd9Sstevel@tonic-gate { "passive", o_bool, &lcp_wantoptions[0].passive, 168*7c478bd9Sstevel@tonic-gate "Set passive mode", 1 }, 169*7c478bd9Sstevel@tonic-gate { "silent", o_bool, &lcp_wantoptions[0].silent, 170*7c478bd9Sstevel@tonic-gate "Set silent mode", 1 }, 171*7c478bd9Sstevel@tonic-gate { "escape", o_special, (void *)setescape, 172*7c478bd9Sstevel@tonic-gate "List of character codes to escape on transmission" }, 173*7c478bd9Sstevel@tonic-gate { "lcp-echo-failure", o_int, &lcp_echo_fails, 174*7c478bd9Sstevel@tonic-gate "Number of consecutive echo failures for link failure" }, 175*7c478bd9Sstevel@tonic-gate { "lcp-echo-interval", o_int, &lcp_echo_interval, 176*7c478bd9Sstevel@tonic-gate "Set time in seconds between LCP echo requests" }, 177*7c478bd9Sstevel@tonic-gate { "no-accm-test", o_int, &use_accm_test, 178*7c478bd9Sstevel@tonic-gate "Disable use of LCP Echo-Request asyncmap checking", 179*7c478bd9Sstevel@tonic-gate OPT_NOARG|OPT_VAL(0) }, 180*7c478bd9Sstevel@tonic-gate { "small-accm-test", o_int, &use_accm_test, 181*7c478bd9Sstevel@tonic-gate "Use only small Echo-Requests for asyncmap checking", 182*7c478bd9Sstevel@tonic-gate OPT_NOARG|OPT_VAL(1) }, 183*7c478bd9Sstevel@tonic-gate { "lcp-restart", o_int, &lcp_fsm[0].timeouttime, 184*7c478bd9Sstevel@tonic-gate "Set time in seconds between LCP retransmissions" }, 185*7c478bd9Sstevel@tonic-gate { "lcp-max-terminate", o_int, &lcp_fsm[0].maxtermtransmits, 186*7c478bd9Sstevel@tonic-gate "Maximum number of LCP terminate-request transmissions" }, 187*7c478bd9Sstevel@tonic-gate { "lcp-max-configure", o_int, &lcp_fsm[0].maxconfreqtransmits, 188*7c478bd9Sstevel@tonic-gate "Maximum number of LCP configure-request transmissions" }, 189*7c478bd9Sstevel@tonic-gate { "lcp-max-failure", o_int, &lcp_fsm[0].maxnakloops, 190*7c478bd9Sstevel@tonic-gate "Set limit on number of LCP configure-naks" }, 191*7c478bd9Sstevel@tonic-gate { "receive-all", o_bool, &lax_recv, 192*7c478bd9Sstevel@tonic-gate "Accept all received control characters", 1 }, 193*7c478bd9Sstevel@tonic-gate #ifdef HAVE_MULTILINK 194*7c478bd9Sstevel@tonic-gate { "mrru", o_int, &lcp_wantoptions[0].mrru, 195*7c478bd9Sstevel@tonic-gate "Maximum received packet size for multilink bundle", 196*7c478bd9Sstevel@tonic-gate OPT_LIMITS, &lcp_wantoptions[0].neg_mrru, PPP_MAXMRU, PPP_MINMRU }, 197*7c478bd9Sstevel@tonic-gate { "mpshortseq", o_bool, &lcp_wantoptions[0].neg_ssnhf, 198*7c478bd9Sstevel@tonic-gate "Use short sequence numbers in multilink headers", 199*7c478bd9Sstevel@tonic-gate OPT_A2COPY | 1, &lcp_allowoptions[0].neg_ssnhf }, 200*7c478bd9Sstevel@tonic-gate { "nompshortseq", o_bool, &lcp_wantoptions[0].neg_ssnhf, 201*7c478bd9Sstevel@tonic-gate "Don't use short sequence numbers in multilink headers", 202*7c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_ssnhf }, 203*7c478bd9Sstevel@tonic-gate #endif /* HAVE_MULTILINK */ 204*7c478bd9Sstevel@tonic-gate { "endpoint", o_special, (void *)setendpoint, 205*7c478bd9Sstevel@tonic-gate "Endpoint discriminator for multilink", }, 206*7c478bd9Sstevel@tonic-gate { "noendpoint", o_bool, &noendpoint, 207*7c478bd9Sstevel@tonic-gate "Don't send or accept multilink endpoint discriminator", 1 }, 208*7c478bd9Sstevel@tonic-gate { "ident", o_string, identstr, 209*7c478bd9Sstevel@tonic-gate "LCP Identification string", OPT_STATIC, NULL, sizeof(identstr) }, 210*7c478bd9Sstevel@tonic-gate { "noident", o_int, &noident, 211*7c478bd9Sstevel@tonic-gate "Disable use of LCP Identification", OPT_INC|OPT_NOARG|1 }, 212*7c478bd9Sstevel@tonic-gate #ifdef NEGOTIATE_FCS 213*7c478bd9Sstevel@tonic-gate { "default-fcs", o_bool, &lcp_wantoptions[0].neg_fcs, 214*7c478bd9Sstevel@tonic-gate "Disable FCS Alternatives option (use default CRC-16)", 215*7c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_fcs }, 216*7c478bd9Sstevel@tonic-gate { "allow-fcs", o_special, (void *)setfcsallow, 217*7c478bd9Sstevel@tonic-gate "Set allowable FCS types; crc16, crc32, null, or number" }, 218*7c478bd9Sstevel@tonic-gate { "fcs", o_special, (void *)setfcswant, 219*7c478bd9Sstevel@tonic-gate "Set FCS type(s) desired; crc16, crc32, null, or number" }, 220*7c478bd9Sstevel@tonic-gate #endif 221*7c478bd9Sstevel@tonic-gate #ifdef MUX_FRAME 222*7c478bd9Sstevel@tonic-gate /* 223*7c478bd9Sstevel@tonic-gate * if pppmux option is turned on, then the parameter to this 224*7c478bd9Sstevel@tonic-gate * is time value in microseconds 225*7c478bd9Sstevel@tonic-gate */ 226*7c478bd9Sstevel@tonic-gate { "pppmux", o_int, &lcp_wantoptions[0].pppmux, 227*7c478bd9Sstevel@tonic-gate "Set PPP Multiplexing option timer", OPT_LLIMIT | OPT_A2COPY, 228*7c478bd9Sstevel@tonic-gate &lcp_allowoptions[0].pppmux, 0, 0 }, 229*7c478bd9Sstevel@tonic-gate #endif 230*7c478bd9Sstevel@tonic-gate {NULL} 231*7c478bd9Sstevel@tonic-gate }; 232*7c478bd9Sstevel@tonic-gate 233*7c478bd9Sstevel@tonic-gate /* global vars */ 234*7c478bd9Sstevel@tonic-gate fsm lcp_fsm[NUM_PPP]; /* LCP fsm structure (global)*/ 235*7c478bd9Sstevel@tonic-gate lcp_options lcp_wantoptions[NUM_PPP]; /* Options that we want to request */ 236*7c478bd9Sstevel@tonic-gate lcp_options lcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */ 237*7c478bd9Sstevel@tonic-gate lcp_options lcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */ 238*7c478bd9Sstevel@tonic-gate lcp_options lcp_hisoptions[NUM_PPP]; /* Options that we ack'd */ 239*7c478bd9Sstevel@tonic-gate u_int32_t xmit_accm[NUM_PPP][8]; /* extended transmit ACCM */ 240*7c478bd9Sstevel@tonic-gate 241*7c478bd9Sstevel@tonic-gate /* 242*7c478bd9Sstevel@tonic-gate * These variables allow a plugin to assert limits on the maximum 243*7c478bd9Sstevel@tonic-gate * MRU/MTU values that can be negotiated. 244*7c478bd9Sstevel@tonic-gate */ 245*7c478bd9Sstevel@tonic-gate int absmax_mru = PPP_MAXMRU; 246*7c478bd9Sstevel@tonic-gate int absmax_mtu = PPP_MAXMTU; 247*7c478bd9Sstevel@tonic-gate 248*7c478bd9Sstevel@tonic-gate static int lcp_echos_pending = 0; /* Number of outstanding echo msgs */ 249*7c478bd9Sstevel@tonic-gate static int lcp_echo_number = 0; /* ID number of next echo frame */ 250*7c478bd9Sstevel@tonic-gate static int lcp_echo_timer_running = 0; /* set if a timer is running */ 251*7c478bd9Sstevel@tonic-gate static int lcp_echo_badreplies = 0; /* number of bad replies from peer */ 252*7c478bd9Sstevel@tonic-gate /* 253*7c478bd9Sstevel@tonic-gate * The maximum number of bad replies we tolerate before bringing the 254*7c478bd9Sstevel@tonic-gate * link down. 255*7c478bd9Sstevel@tonic-gate */ 256*7c478bd9Sstevel@tonic-gate #define LCP_ECHO_MAX_BADREPLIES 10 257*7c478bd9Sstevel@tonic-gate 258*7c478bd9Sstevel@tonic-gate /* 259*7c478bd9Sstevel@tonic-gate * Callbacks for fsm code. (CI = Configuration Information) 260*7c478bd9Sstevel@tonic-gate */ 261*7c478bd9Sstevel@tonic-gate static void lcp_resetci __P((fsm *)); /* Reset our CI */ 262*7c478bd9Sstevel@tonic-gate static int lcp_cilen __P((fsm *)); /* Return length of our CI */ 263*7c478bd9Sstevel@tonic-gate static void lcp_addci __P((fsm *, u_char *, int *)); /* Add our CI to pkt */ 264*7c478bd9Sstevel@tonic-gate static int lcp_ackci __P((fsm *, u_char *, int)); /* Peer ack'd our CI */ 265*7c478bd9Sstevel@tonic-gate static int lcp_nakci __P((fsm *, u_char *, int)); /* Peer nak'd our CI */ 266*7c478bd9Sstevel@tonic-gate static int lcp_rejci __P((fsm *, u_char *, int)); /* Peer rej'd our CI */ 267*7c478bd9Sstevel@tonic-gate static int lcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv peer CI */ 268*7c478bd9Sstevel@tonic-gate static void lcp_up __P((fsm *)); /* We're UP */ 269*7c478bd9Sstevel@tonic-gate static void lcp_down __P((fsm *)); /* We're DOWN */ 270*7c478bd9Sstevel@tonic-gate static void lcp_starting __P((fsm *)); /* We need lower layer up */ 271*7c478bd9Sstevel@tonic-gate static void lcp_finished __P((fsm *)); /* We need lower layer down */ 272*7c478bd9Sstevel@tonic-gate static int lcp_extcode __P((fsm *, int, int, u_char *, int)); 273*7c478bd9Sstevel@tonic-gate static void lcp_rprotrej __P((fsm *, u_char *, int)); 274*7c478bd9Sstevel@tonic-gate static int lcp_coderej __P((fsm *f, int code, int id, u_char *inp, int len)); 275*7c478bd9Sstevel@tonic-gate 276*7c478bd9Sstevel@tonic-gate /* 277*7c478bd9Sstevel@tonic-gate * routines to send LCP echos to peer 278*7c478bd9Sstevel@tonic-gate */ 279*7c478bd9Sstevel@tonic-gate 280*7c478bd9Sstevel@tonic-gate static void lcp_echo_lowerup __P((int)); 281*7c478bd9Sstevel@tonic-gate static void lcp_echo_lowerdown __P((int)); 282*7c478bd9Sstevel@tonic-gate static void LcpEchoTimeout __P((void *)); 283*7c478bd9Sstevel@tonic-gate static int lcp_received_echo_reply __P((fsm *, int, u_char *, int)); 284*7c478bd9Sstevel@tonic-gate static void LcpSendEchoRequest __P((fsm *)); 285*7c478bd9Sstevel@tonic-gate static void LcpLinkFailure __P((fsm *)); 286*7c478bd9Sstevel@tonic-gate static void LcpEchoCheck __P((fsm *)); 287*7c478bd9Sstevel@tonic-gate 288*7c478bd9Sstevel@tonic-gate /* 289*7c478bd9Sstevel@tonic-gate * routines to send and receive additional LCP packets described in 290*7c478bd9Sstevel@tonic-gate * section 1 of rfc1570. 291*7c478bd9Sstevel@tonic-gate */ 292*7c478bd9Sstevel@tonic-gate static void LcpSendIdentification __P((fsm *)); 293*7c478bd9Sstevel@tonic-gate static void lcp_received_identification __P((fsm *, int, u_char *, int)); 294*7c478bd9Sstevel@tonic-gate static void LcpSendTimeRemaining __P((fsm *, u_int32_t)); 295*7c478bd9Sstevel@tonic-gate static void lcp_timeremaining __P((void *)); 296*7c478bd9Sstevel@tonic-gate static void lcp_received_timeremain __P((fsm *, int, u_char *, int)); 297*7c478bd9Sstevel@tonic-gate 298*7c478bd9Sstevel@tonic-gate 299*7c478bd9Sstevel@tonic-gate static fsm_callbacks lcp_callbacks = { /* LCP callback routines */ 300*7c478bd9Sstevel@tonic-gate lcp_resetci, /* Reset our Configuration Information */ 301*7c478bd9Sstevel@tonic-gate lcp_cilen, /* Length of our Configuration Information */ 302*7c478bd9Sstevel@tonic-gate lcp_addci, /* Add our Configuration Information */ 303*7c478bd9Sstevel@tonic-gate lcp_ackci, /* ACK our Configuration Information */ 304*7c478bd9Sstevel@tonic-gate lcp_nakci, /* NAK our Configuration Information */ 305*7c478bd9Sstevel@tonic-gate lcp_rejci, /* Reject our Configuration Information */ 306*7c478bd9Sstevel@tonic-gate lcp_reqci, /* Request peer's Configuration Information */ 307*7c478bd9Sstevel@tonic-gate lcp_up, /* Called when fsm reaches OPENED state */ 308*7c478bd9Sstevel@tonic-gate lcp_down, /* Called when fsm leaves OPENED state */ 309*7c478bd9Sstevel@tonic-gate lcp_starting, /* Called when we want the lower layer up */ 310*7c478bd9Sstevel@tonic-gate lcp_finished, /* Called when we want the lower layer down */ 311*7c478bd9Sstevel@tonic-gate NULL, /* Retransmission is necessary */ 312*7c478bd9Sstevel@tonic-gate lcp_extcode, /* Called to handle LCP-specific codes */ 313*7c478bd9Sstevel@tonic-gate "LCP", /* String name of protocol */ 314*7c478bd9Sstevel@tonic-gate lcp_coderej, /* Peer rejected a code number */ 315*7c478bd9Sstevel@tonic-gate }; 316*7c478bd9Sstevel@tonic-gate 317*7c478bd9Sstevel@tonic-gate /* 318*7c478bd9Sstevel@tonic-gate * Protocol entry points. 319*7c478bd9Sstevel@tonic-gate * Some of these are called directly. 320*7c478bd9Sstevel@tonic-gate */ 321*7c478bd9Sstevel@tonic-gate 322*7c478bd9Sstevel@tonic-gate static void lcp_init __P((int)); 323*7c478bd9Sstevel@tonic-gate static void lcp_input __P((int, u_char *, int)); 324*7c478bd9Sstevel@tonic-gate static void lcp_protrej __P((int)); 325*7c478bd9Sstevel@tonic-gate static int lcp_printpkt __P((u_char *, int, 326*7c478bd9Sstevel@tonic-gate void (*) __P((void *, const char *, ...)), void *)); 327*7c478bd9Sstevel@tonic-gate 328*7c478bd9Sstevel@tonic-gate 329*7c478bd9Sstevel@tonic-gate struct protent lcp_protent = { 330*7c478bd9Sstevel@tonic-gate PPP_LCP, /* Protocol Number for LCP */ 331*7c478bd9Sstevel@tonic-gate lcp_init, /* Initializes LCP */ 332*7c478bd9Sstevel@tonic-gate lcp_input, /* Processes a received LCP packet */ 333*7c478bd9Sstevel@tonic-gate lcp_protrej, /* Process a received Protocol-reject */ 334*7c478bd9Sstevel@tonic-gate lcp_lowerup, /* Called after the serial device has been set up */ 335*7c478bd9Sstevel@tonic-gate lcp_lowerdown, /* Called when the link is brought down */ 336*7c478bd9Sstevel@tonic-gate lcp_open, /* Called after lcp_lowerup when bringing up the link */ 337*7c478bd9Sstevel@tonic-gate lcp_close, /* Called when the link goes down */ 338*7c478bd9Sstevel@tonic-gate lcp_printpkt, /* Print a packet in human readable form */ 339*7c478bd9Sstevel@tonic-gate NULL, /* Process a received data packet */ 340*7c478bd9Sstevel@tonic-gate 1, /* LCP is enabled by default */ 341*7c478bd9Sstevel@tonic-gate "LCP", /* Name of the protocol */ 342*7c478bd9Sstevel@tonic-gate NULL, /* Name of the corresponding data protocol */ 343*7c478bd9Sstevel@tonic-gate lcp_option_list, /* List of LCP command-line options */ 344*7c478bd9Sstevel@tonic-gate NULL, /* Assigns default values for options */ 345*7c478bd9Sstevel@tonic-gate NULL, /* Configures demand-dial */ 346*7c478bd9Sstevel@tonic-gate NULL /* Bring up the link for this packet? */ 347*7c478bd9Sstevel@tonic-gate }; 348*7c478bd9Sstevel@tonic-gate 349*7c478bd9Sstevel@tonic-gate int lcp_loopbackfail = DEFLOOPBACKFAIL; 350*7c478bd9Sstevel@tonic-gate 351*7c478bd9Sstevel@tonic-gate /* 352*7c478bd9Sstevel@tonic-gate * Length of each type of configuration option (in octets) 353*7c478bd9Sstevel@tonic-gate */ 354*7c478bd9Sstevel@tonic-gate #define CILEN_VOID 2 355*7c478bd9Sstevel@tonic-gate #define CILEN_CHAR 3 356*7c478bd9Sstevel@tonic-gate #define CILEN_SHORT 4 /* CILEN_VOID + 2 */ 357*7c478bd9Sstevel@tonic-gate #define CILEN_CHAP 5 /* CILEN_VOID + 2 + 1 */ 358*7c478bd9Sstevel@tonic-gate #define CILEN_LONG 6 /* CILEN_VOID + 4 */ 359*7c478bd9Sstevel@tonic-gate #define CILEN_LQR 8 /* CILEN_VOID + 2 + 4 */ 360*7c478bd9Sstevel@tonic-gate #define CILEN_CBCP 3 361*7c478bd9Sstevel@tonic-gate 362*7c478bd9Sstevel@tonic-gate 363*7c478bd9Sstevel@tonic-gate /* 364*7c478bd9Sstevel@tonic-gate * setescape - add chars to the set we escape on transmission. 365*7c478bd9Sstevel@tonic-gate */ 366*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 367*7c478bd9Sstevel@tonic-gate static int 368*7c478bd9Sstevel@tonic-gate setescape(argv, opt) 369*7c478bd9Sstevel@tonic-gate char **argv; 370*7c478bd9Sstevel@tonic-gate option_t *opt; 371*7c478bd9Sstevel@tonic-gate { 372*7c478bd9Sstevel@tonic-gate int n, ret; 373*7c478bd9Sstevel@tonic-gate char *p, *endp; 374*7c478bd9Sstevel@tonic-gate 375*7c478bd9Sstevel@tonic-gate p = *argv; 376*7c478bd9Sstevel@tonic-gate ret = 1; 377*7c478bd9Sstevel@tonic-gate while (*p != '\0') { 378*7c478bd9Sstevel@tonic-gate n = strtol(p, &endp, 16); 379*7c478bd9Sstevel@tonic-gate if (p == endp) { 380*7c478bd9Sstevel@tonic-gate option_error("escape parameter contains invalid hex number '%s'", 381*7c478bd9Sstevel@tonic-gate p); 382*7c478bd9Sstevel@tonic-gate return 0; 383*7c478bd9Sstevel@tonic-gate } 384*7c478bd9Sstevel@tonic-gate p = endp; 385*7c478bd9Sstevel@tonic-gate if (n < 0 || n == 0x5E || n > 0xFF) { 386*7c478bd9Sstevel@tonic-gate option_error("can't escape character 0x%x", n); 387*7c478bd9Sstevel@tonic-gate ret = 0; 388*7c478bd9Sstevel@tonic-gate } else 389*7c478bd9Sstevel@tonic-gate xmit_accm[0][n >> 5] |= 1 << (n & 0x1F); 390*7c478bd9Sstevel@tonic-gate while (*p == ',' || *p == ' ') 391*7c478bd9Sstevel@tonic-gate ++p; 392*7c478bd9Sstevel@tonic-gate } 393*7c478bd9Sstevel@tonic-gate return ret; 394*7c478bd9Sstevel@tonic-gate } 395*7c478bd9Sstevel@tonic-gate 396*7c478bd9Sstevel@tonic-gate /* 397*7c478bd9Sstevel@tonic-gate * setasyncmap - set async map negotiated 398*7c478bd9Sstevel@tonic-gate */ 399*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 400*7c478bd9Sstevel@tonic-gate static int 401*7c478bd9Sstevel@tonic-gate setasyncmap(argv, opt) 402*7c478bd9Sstevel@tonic-gate char **argv; 403*7c478bd9Sstevel@tonic-gate option_t *opt; 404*7c478bd9Sstevel@tonic-gate { 405*7c478bd9Sstevel@tonic-gate u_int32_t val; 406*7c478bd9Sstevel@tonic-gate char *endp; 407*7c478bd9Sstevel@tonic-gate 408*7c478bd9Sstevel@tonic-gate val = strtoul(*argv, &endp, 16); 409*7c478bd9Sstevel@tonic-gate if (*argv == endp) { 410*7c478bd9Sstevel@tonic-gate option_error("invalid numeric parameter '%s' for 'asyncmap' option", 411*7c478bd9Sstevel@tonic-gate *argv); 412*7c478bd9Sstevel@tonic-gate return 0; 413*7c478bd9Sstevel@tonic-gate } 414*7c478bd9Sstevel@tonic-gate lcp_wantoptions[0].asyncmap |= val; 415*7c478bd9Sstevel@tonic-gate lcp_wantoptions[0].neg_asyncmap = (~lcp_wantoptions[0].asyncmap != 0); 416*7c478bd9Sstevel@tonic-gate do_msft_workaround = 0; 417*7c478bd9Sstevel@tonic-gate return 1; 418*7c478bd9Sstevel@tonic-gate } 419*7c478bd9Sstevel@tonic-gate 420*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 421*7c478bd9Sstevel@tonic-gate static int 422*7c478bd9Sstevel@tonic-gate setendpoint(argv, opt) 423*7c478bd9Sstevel@tonic-gate char **argv; 424*7c478bd9Sstevel@tonic-gate option_t *opt; 425*7c478bd9Sstevel@tonic-gate { 426*7c478bd9Sstevel@tonic-gate if (str_to_epdisc(&lcp_wantoptions[0].endpoint, *argv)) { 427*7c478bd9Sstevel@tonic-gate lcp_wantoptions[0].neg_endpoint = 1; 428*7c478bd9Sstevel@tonic-gate return 1; 429*7c478bd9Sstevel@tonic-gate } 430*7c478bd9Sstevel@tonic-gate option_error("Can't parse '%s' as an endpoint discriminator", *argv); 431*7c478bd9Sstevel@tonic-gate return 0; 432*7c478bd9Sstevel@tonic-gate } 433*7c478bd9Sstevel@tonic-gate 434*7c478bd9Sstevel@tonic-gate #ifdef NEGOTIATE_FCS 435*7c478bd9Sstevel@tonic-gate static int 436*7c478bd9Sstevel@tonic-gate str_to_fcstype(opt,arg) 437*7c478bd9Sstevel@tonic-gate lcp_options *opt; 438*7c478bd9Sstevel@tonic-gate char *arg; 439*7c478bd9Sstevel@tonic-gate { 440*7c478bd9Sstevel@tonic-gate char **cpp, *cp; 441*7c478bd9Sstevel@tonic-gate int val, len; 442*7c478bd9Sstevel@tonic-gate 443*7c478bd9Sstevel@tonic-gate if (*arg != '\0') { 444*7c478bd9Sstevel@tonic-gate val = 0; 445*7c478bd9Sstevel@tonic-gate while (*arg != '\0') { 446*7c478bd9Sstevel@tonic-gate len = 0; 447*7c478bd9Sstevel@tonic-gate if (isdigit(*arg)) { 448*7c478bd9Sstevel@tonic-gate len = strtol(arg, &cp, 0); 449*7c478bd9Sstevel@tonic-gate if (len < 0 || len > 255 || arg == cp || 450*7c478bd9Sstevel@tonic-gate (*cp != '\0' && *cp != ',')) 451*7c478bd9Sstevel@tonic-gate break; 452*7c478bd9Sstevel@tonic-gate val |= len; 453*7c478bd9Sstevel@tonic-gate len = cp - arg; 454*7c478bd9Sstevel@tonic-gate } else { 455*7c478bd9Sstevel@tonic-gate for (cpp = fcsalt_strings; *cpp != NULL; cpp++) { 456*7c478bd9Sstevel@tonic-gate len = strlen(*cpp); 457*7c478bd9Sstevel@tonic-gate if (strncasecmp(arg, *cpp, len) == 0 && 458*7c478bd9Sstevel@tonic-gate (arg[len] == '\0' || arg[len] == ',')) 459*7c478bd9Sstevel@tonic-gate break; 460*7c478bd9Sstevel@tonic-gate } 461*7c478bd9Sstevel@tonic-gate if (*cpp == NULL) 462*7c478bd9Sstevel@tonic-gate break; 463*7c478bd9Sstevel@tonic-gate val |= 1<<(cpp-fcsalt_strings); 464*7c478bd9Sstevel@tonic-gate } 465*7c478bd9Sstevel@tonic-gate if (arg[len] == '\0') { 466*7c478bd9Sstevel@tonic-gate opt->neg_fcs = 1; 467*7c478bd9Sstevel@tonic-gate opt->fcs_type = val; 468*7c478bd9Sstevel@tonic-gate return (1); 469*7c478bd9Sstevel@tonic-gate } 470*7c478bd9Sstevel@tonic-gate arg += len+1; 471*7c478bd9Sstevel@tonic-gate } 472*7c478bd9Sstevel@tonic-gate } 473*7c478bd9Sstevel@tonic-gate option_error("Can't parse '%s' as an FCS type", arg); 474*7c478bd9Sstevel@tonic-gate return (0); 475*7c478bd9Sstevel@tonic-gate } 476*7c478bd9Sstevel@tonic-gate 477*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 478*7c478bd9Sstevel@tonic-gate static int 479*7c478bd9Sstevel@tonic-gate setfcsallow(argv, opt) 480*7c478bd9Sstevel@tonic-gate char **argv; 481*7c478bd9Sstevel@tonic-gate option_t *opt; 482*7c478bd9Sstevel@tonic-gate { 483*7c478bd9Sstevel@tonic-gate return str_to_fcstype(&lcp_allowoptions[0], *argv); 484*7c478bd9Sstevel@tonic-gate } 485*7c478bd9Sstevel@tonic-gate 486*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 487*7c478bd9Sstevel@tonic-gate static int 488*7c478bd9Sstevel@tonic-gate setfcswant(argv, opt) 489*7c478bd9Sstevel@tonic-gate char **argv; 490*7c478bd9Sstevel@tonic-gate option_t *opt; 491*7c478bd9Sstevel@tonic-gate { 492*7c478bd9Sstevel@tonic-gate return str_to_fcstype(&lcp_wantoptions[0], *argv); 493*7c478bd9Sstevel@tonic-gate } 494*7c478bd9Sstevel@tonic-gate #endif 495*7c478bd9Sstevel@tonic-gate 496*7c478bd9Sstevel@tonic-gate /* 497*7c478bd9Sstevel@tonic-gate * lcp_init - Initialize LCP. 498*7c478bd9Sstevel@tonic-gate */ 499*7c478bd9Sstevel@tonic-gate static void 500*7c478bd9Sstevel@tonic-gate lcp_init(unit) 501*7c478bd9Sstevel@tonic-gate int unit; 502*7c478bd9Sstevel@tonic-gate { 503*7c478bd9Sstevel@tonic-gate fsm *f = &lcp_fsm[unit]; 504*7c478bd9Sstevel@tonic-gate lcp_options *wo = &lcp_wantoptions[unit]; 505*7c478bd9Sstevel@tonic-gate lcp_options *ao = &lcp_allowoptions[unit]; 506*7c478bd9Sstevel@tonic-gate 507*7c478bd9Sstevel@tonic-gate f->unit = unit; 508*7c478bd9Sstevel@tonic-gate f->protocol = PPP_LCP; 509*7c478bd9Sstevel@tonic-gate f->callbacks = &lcp_callbacks; 510*7c478bd9Sstevel@tonic-gate 511*7c478bd9Sstevel@tonic-gate fsm_init(f); 512*7c478bd9Sstevel@tonic-gate 513*7c478bd9Sstevel@tonic-gate BZERO(wo, sizeof(*wo)); 514*7c478bd9Sstevel@tonic-gate wo->neg_mru = 1; 515*7c478bd9Sstevel@tonic-gate wo->mru = PPP_MRU; 516*7c478bd9Sstevel@tonic-gate wo->neg_asyncmap = 1; 517*7c478bd9Sstevel@tonic-gate wo->chap_mdtype = CHAP_DIGEST_MD5; 518*7c478bd9Sstevel@tonic-gate wo->neg_magicnumber = 1; 519*7c478bd9Sstevel@tonic-gate wo->neg_pcompression = 1; 520*7c478bd9Sstevel@tonic-gate wo->neg_accompression = 1; 521*7c478bd9Sstevel@tonic-gate 522*7c478bd9Sstevel@tonic-gate /* 523*7c478bd9Sstevel@tonic-gate * Leave allowed MRU (MTU) at zero; configuration option sets it 524*7c478bd9Sstevel@tonic-gate * non-zero if we should nak for something else. 525*7c478bd9Sstevel@tonic-gate */ 526*7c478bd9Sstevel@tonic-gate BZERO(ao, sizeof(*ao)); 527*7c478bd9Sstevel@tonic-gate ao->neg_mru = 1; 528*7c478bd9Sstevel@tonic-gate ao->neg_asyncmap = 1; 529*7c478bd9Sstevel@tonic-gate ao->neg_chap = 1; 530*7c478bd9Sstevel@tonic-gate #if defined(CHAPMS) || defined(CHAPMSV2) 531*7c478bd9Sstevel@tonic-gate #ifdef SOL2 532*7c478bd9Sstevel@tonic-gate /* Check if DES wasn't exported */ 533*7c478bd9Sstevel@tonic-gate errno = 0; 534*7c478bd9Sstevel@tonic-gate setkey("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" 535*7c478bd9Sstevel@tonic-gate "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); 536*7c478bd9Sstevel@tonic-gate if (errno == 0) 537*7c478bd9Sstevel@tonic-gate #endif 538*7c478bd9Sstevel@tonic-gate { 539*7c478bd9Sstevel@tonic-gate #ifdef CHAPMS 540*7c478bd9Sstevel@tonic-gate ao->neg_mschap = 1; 541*7c478bd9Sstevel@tonic-gate #endif 542*7c478bd9Sstevel@tonic-gate #ifdef CHAPMSV2 543*7c478bd9Sstevel@tonic-gate ao->neg_mschapv2 = 1; 544*7c478bd9Sstevel@tonic-gate #endif 545*7c478bd9Sstevel@tonic-gate } 546*7c478bd9Sstevel@tonic-gate #endif 547*7c478bd9Sstevel@tonic-gate ao->chap_mdtype = CHAP_DIGEST_MD5; 548*7c478bd9Sstevel@tonic-gate ao->neg_upap = 1; 549*7c478bd9Sstevel@tonic-gate ao->neg_magicnumber = 1; 550*7c478bd9Sstevel@tonic-gate ao->neg_pcompression = 1; 551*7c478bd9Sstevel@tonic-gate ao->neg_accompression = 1; 552*7c478bd9Sstevel@tonic-gate #ifdef CBCP_SUPPORT 553*7c478bd9Sstevel@tonic-gate ao->neg_cbcp = 1; 554*7c478bd9Sstevel@tonic-gate #endif 555*7c478bd9Sstevel@tonic-gate ao->neg_endpoint = 1; 556*7c478bd9Sstevel@tonic-gate #ifdef NEGOTIATE_FCS 557*7c478bd9Sstevel@tonic-gate ao->neg_fcs = 1; 558*7c478bd9Sstevel@tonic-gate ao->fcs_type = FCSALT_NULL|FCSALT_16|FCSALT_32; 559*7c478bd9Sstevel@tonic-gate #endif 560*7c478bd9Sstevel@tonic-gate 561*7c478bd9Sstevel@tonic-gate BZERO(xmit_accm[unit], sizeof(xmit_accm[0])); 562*7c478bd9Sstevel@tonic-gate xmit_accm[unit][3] = 0x60000000; 563*7c478bd9Sstevel@tonic-gate } 564*7c478bd9Sstevel@tonic-gate 565*7c478bd9Sstevel@tonic-gate 566*7c478bd9Sstevel@tonic-gate /* 567*7c478bd9Sstevel@tonic-gate * lcp_open - LCP is allowed to come up. 568*7c478bd9Sstevel@tonic-gate */ 569*7c478bd9Sstevel@tonic-gate void 570*7c478bd9Sstevel@tonic-gate lcp_open(unit) 571*7c478bd9Sstevel@tonic-gate int unit; 572*7c478bd9Sstevel@tonic-gate { 573*7c478bd9Sstevel@tonic-gate fsm *f = &lcp_fsm[unit]; 574*7c478bd9Sstevel@tonic-gate lcp_options *wo = &lcp_wantoptions[unit]; 575*7c478bd9Sstevel@tonic-gate 576*7c478bd9Sstevel@tonic-gate f->flags = 0; 577*7c478bd9Sstevel@tonic-gate if (wo->passive) 578*7c478bd9Sstevel@tonic-gate f->flags |= OPT_PASSIVE; 579*7c478bd9Sstevel@tonic-gate if (wo->silent) 580*7c478bd9Sstevel@tonic-gate f->flags |= OPT_SILENT; 581*7c478bd9Sstevel@tonic-gate fsm_open(f); 582*7c478bd9Sstevel@tonic-gate } 583*7c478bd9Sstevel@tonic-gate 584*7c478bd9Sstevel@tonic-gate 585*7c478bd9Sstevel@tonic-gate /* 586*7c478bd9Sstevel@tonic-gate * lcp_close - Take LCP down. 587*7c478bd9Sstevel@tonic-gate */ 588*7c478bd9Sstevel@tonic-gate void 589*7c478bd9Sstevel@tonic-gate lcp_close(unit, reason) 590*7c478bd9Sstevel@tonic-gate int unit; 591*7c478bd9Sstevel@tonic-gate char *reason; 592*7c478bd9Sstevel@tonic-gate { 593*7c478bd9Sstevel@tonic-gate fsm *f = &lcp_fsm[unit]; 594*7c478bd9Sstevel@tonic-gate 595*7c478bd9Sstevel@tonic-gate if (phase != PHASE_DEAD) 596*7c478bd9Sstevel@tonic-gate new_phase(PHASE_TERMINATE); 597*7c478bd9Sstevel@tonic-gate if (f->state == STOPPED && (f->flags & (OPT_PASSIVE|OPT_SILENT))) { 598*7c478bd9Sstevel@tonic-gate /* 599*7c478bd9Sstevel@tonic-gate * This action is not strictly according to the FSM in RFC1548, 600*7c478bd9Sstevel@tonic-gate * but it does mean that the program terminates if you do a 601*7c478bd9Sstevel@tonic-gate * lcp_close() in passive/silent mode when a connection hasn't 602*7c478bd9Sstevel@tonic-gate * been established. 603*7c478bd9Sstevel@tonic-gate */ 604*7c478bd9Sstevel@tonic-gate f->state = CLOSED; 605*7c478bd9Sstevel@tonic-gate lcp_finished(f); 606*7c478bd9Sstevel@tonic-gate 607*7c478bd9Sstevel@tonic-gate } else 608*7c478bd9Sstevel@tonic-gate fsm_close(&lcp_fsm[unit], reason); 609*7c478bd9Sstevel@tonic-gate } 610*7c478bd9Sstevel@tonic-gate 611*7c478bd9Sstevel@tonic-gate 612*7c478bd9Sstevel@tonic-gate /* 613*7c478bd9Sstevel@tonic-gate * lcp_lowerup - The lower layer is up. 614*7c478bd9Sstevel@tonic-gate */ 615*7c478bd9Sstevel@tonic-gate void 616*7c478bd9Sstevel@tonic-gate lcp_lowerup(unit) 617*7c478bd9Sstevel@tonic-gate int unit; 618*7c478bd9Sstevel@tonic-gate { 619*7c478bd9Sstevel@tonic-gate lcp_options *wo = &lcp_wantoptions[unit]; 620*7c478bd9Sstevel@tonic-gate int mru, mtu; 621*7c478bd9Sstevel@tonic-gate 622*7c478bd9Sstevel@tonic-gate mru = PPP_MRU > absmax_mru ? absmax_mru : PPP_MRU; 623*7c478bd9Sstevel@tonic-gate mtu = PPP_MTU > absmax_mtu ? absmax_mtu : PPP_MTU; 624*7c478bd9Sstevel@tonic-gate 625*7c478bd9Sstevel@tonic-gate /* 626*7c478bd9Sstevel@tonic-gate * Don't use A/C or protocol compression on transmission, 627*7c478bd9Sstevel@tonic-gate * but accept A/C and protocol compressed packets 628*7c478bd9Sstevel@tonic-gate * if we are going to ask for A/C and protocol compression. 629*7c478bd9Sstevel@tonic-gate */ 630*7c478bd9Sstevel@tonic-gate ppp_set_xaccm(unit, xmit_accm[unit]); 631*7c478bd9Sstevel@tonic-gate ppp_send_config(unit, mtu, 0xffffffff, 0, 0); 632*7c478bd9Sstevel@tonic-gate ppp_recv_config(unit, mru, (lax_recv? 0: 0xffffffff), 633*7c478bd9Sstevel@tonic-gate wo->neg_pcompression, wo->neg_accompression); 634*7c478bd9Sstevel@tonic-gate #ifdef NEGOTIATE_FCS 635*7c478bd9Sstevel@tonic-gate ppp_send_fcs(unit, FCSALT_16); 636*7c478bd9Sstevel@tonic-gate ppp_recv_fcs(unit, FCSALT_16); 637*7c478bd9Sstevel@tonic-gate #endif 638*7c478bd9Sstevel@tonic-gate 639*7c478bd9Sstevel@tonic-gate fsm_setpeermru(unit, mtu); 640*7c478bd9Sstevel@tonic-gate lcp_allowoptions[unit].asyncmap = xmit_accm[unit][0]; 641*7c478bd9Sstevel@tonic-gate 642*7c478bd9Sstevel@tonic-gate fsm_lowerup(&lcp_fsm[unit]); 643*7c478bd9Sstevel@tonic-gate } 644*7c478bd9Sstevel@tonic-gate 645*7c478bd9Sstevel@tonic-gate 646*7c478bd9Sstevel@tonic-gate /* 647*7c478bd9Sstevel@tonic-gate * lcp_lowerdown - The lower layer is down. 648*7c478bd9Sstevel@tonic-gate */ 649*7c478bd9Sstevel@tonic-gate void 650*7c478bd9Sstevel@tonic-gate lcp_lowerdown(unit) 651*7c478bd9Sstevel@tonic-gate int unit; 652*7c478bd9Sstevel@tonic-gate { 653*7c478bd9Sstevel@tonic-gate fsm_lowerdown(&lcp_fsm[unit]); 654*7c478bd9Sstevel@tonic-gate } 655*7c478bd9Sstevel@tonic-gate 656*7c478bd9Sstevel@tonic-gate 657*7c478bd9Sstevel@tonic-gate /* 658*7c478bd9Sstevel@tonic-gate * lcp_input - Input LCP packet. 659*7c478bd9Sstevel@tonic-gate */ 660*7c478bd9Sstevel@tonic-gate static void 661*7c478bd9Sstevel@tonic-gate lcp_input(unit, p, len) 662*7c478bd9Sstevel@tonic-gate int unit; 663*7c478bd9Sstevel@tonic-gate u_char *p; 664*7c478bd9Sstevel@tonic-gate int len; 665*7c478bd9Sstevel@tonic-gate { 666*7c478bd9Sstevel@tonic-gate fsm *f = &lcp_fsm[unit]; 667*7c478bd9Sstevel@tonic-gate 668*7c478bd9Sstevel@tonic-gate fsm_input(f, p, len); 669*7c478bd9Sstevel@tonic-gate } 670*7c478bd9Sstevel@tonic-gate 671*7c478bd9Sstevel@tonic-gate 672*7c478bd9Sstevel@tonic-gate /* 673*7c478bd9Sstevel@tonic-gate * lcp_extcode - Handle a LCP-specific code. 674*7c478bd9Sstevel@tonic-gate */ 675*7c478bd9Sstevel@tonic-gate static int 676*7c478bd9Sstevel@tonic-gate lcp_extcode(f, code, id, inp, len) 677*7c478bd9Sstevel@tonic-gate fsm *f; 678*7c478bd9Sstevel@tonic-gate int code, id; 679*7c478bd9Sstevel@tonic-gate u_char *inp; 680*7c478bd9Sstevel@tonic-gate int len; 681*7c478bd9Sstevel@tonic-gate { 682*7c478bd9Sstevel@tonic-gate u_char *magp; 683*7c478bd9Sstevel@tonic-gate 684*7c478bd9Sstevel@tonic-gate switch( code ){ 685*7c478bd9Sstevel@tonic-gate case CODE_PROTREJ: 686*7c478bd9Sstevel@tonic-gate lcp_rprotrej(f, inp, len); 687*7c478bd9Sstevel@tonic-gate break; 688*7c478bd9Sstevel@tonic-gate 689*7c478bd9Sstevel@tonic-gate case CODE_ECHOREQ: 690*7c478bd9Sstevel@tonic-gate if (f->state != OPENED) 691*7c478bd9Sstevel@tonic-gate break; 692*7c478bd9Sstevel@tonic-gate magp = inp; 693*7c478bd9Sstevel@tonic-gate PUTLONG(lcp_gotoptions[f->unit].magicnumber, magp); 694*7c478bd9Sstevel@tonic-gate fsm_sdata(f, CODE_ECHOREP, id, inp, len); 695*7c478bd9Sstevel@tonic-gate break; 696*7c478bd9Sstevel@tonic-gate 697*7c478bd9Sstevel@tonic-gate case CODE_ECHOREP: 698*7c478bd9Sstevel@tonic-gate if (!lcp_received_echo_reply(f, id, inp, len)) { 699*7c478bd9Sstevel@tonic-gate lcp_echo_badreplies++; 700*7c478bd9Sstevel@tonic-gate if (lcp_echo_badreplies > LCP_ECHO_MAX_BADREPLIES) { 701*7c478bd9Sstevel@tonic-gate LcpLinkFailure(f); 702*7c478bd9Sstevel@tonic-gate lcp_echos_pending = 0; 703*7c478bd9Sstevel@tonic-gate lcp_echo_badreplies = 0; 704*7c478bd9Sstevel@tonic-gate } 705*7c478bd9Sstevel@tonic-gate } 706*7c478bd9Sstevel@tonic-gate break; 707*7c478bd9Sstevel@tonic-gate 708*7c478bd9Sstevel@tonic-gate case CODE_DISCREQ: 709*7c478bd9Sstevel@tonic-gate break; 710*7c478bd9Sstevel@tonic-gate 711*7c478bd9Sstevel@tonic-gate case CODE_IDENT: 712*7c478bd9Sstevel@tonic-gate /* More than one 'noident' tells us to reject the code number. */ 713*7c478bd9Sstevel@tonic-gate if (noident > 1) 714*7c478bd9Sstevel@tonic-gate return 0; 715*7c478bd9Sstevel@tonic-gate lcp_received_identification(f, id, inp, len); 716*7c478bd9Sstevel@tonic-gate break; 717*7c478bd9Sstevel@tonic-gate 718*7c478bd9Sstevel@tonic-gate case CODE_TIMEREMAIN: 719*7c478bd9Sstevel@tonic-gate lcp_received_timeremain(f, id, inp, len); 720*7c478bd9Sstevel@tonic-gate break; 721*7c478bd9Sstevel@tonic-gate 722*7c478bd9Sstevel@tonic-gate default: 723*7c478bd9Sstevel@tonic-gate return 0; 724*7c478bd9Sstevel@tonic-gate } 725*7c478bd9Sstevel@tonic-gate return 1; 726*7c478bd9Sstevel@tonic-gate } 727*7c478bd9Sstevel@tonic-gate 728*7c478bd9Sstevel@tonic-gate /* 729*7c478bd9Sstevel@tonic-gate * lcp_rprotrej - Receive an Protocol-Reject. 730*7c478bd9Sstevel@tonic-gate * 731*7c478bd9Sstevel@tonic-gate * Figure out which protocol is rejected and inform it. 732*7c478bd9Sstevel@tonic-gate */ 733*7c478bd9Sstevel@tonic-gate static void 734*7c478bd9Sstevel@tonic-gate lcp_rprotrej(f, inp, len) 735*7c478bd9Sstevel@tonic-gate fsm *f; 736*7c478bd9Sstevel@tonic-gate u_char *inp; 737*7c478bd9Sstevel@tonic-gate int len; 738*7c478bd9Sstevel@tonic-gate { 739*7c478bd9Sstevel@tonic-gate int i; 740*7c478bd9Sstevel@tonic-gate struct protent *protp; 741*7c478bd9Sstevel@tonic-gate u_short prot; 742*7c478bd9Sstevel@tonic-gate 743*7c478bd9Sstevel@tonic-gate if (len < 2) { 744*7c478bd9Sstevel@tonic-gate dbglog("lcp_rprotrej: Rcvd short Protocol-Reject packet!"); 745*7c478bd9Sstevel@tonic-gate return; 746*7c478bd9Sstevel@tonic-gate } 747*7c478bd9Sstevel@tonic-gate 748*7c478bd9Sstevel@tonic-gate GETSHORT(prot, inp); 749*7c478bd9Sstevel@tonic-gate 750*7c478bd9Sstevel@tonic-gate /* 751*7c478bd9Sstevel@tonic-gate * Protocol-Reject packets received in any state other than the LCP 752*7c478bd9Sstevel@tonic-gate * OPENED state SHOULD be silently discarded. 753*7c478bd9Sstevel@tonic-gate */ 754*7c478bd9Sstevel@tonic-gate if( f->state != OPENED ){ 755*7c478bd9Sstevel@tonic-gate dbglog("Protocol-Reject discarded: LCP in state %s", 756*7c478bd9Sstevel@tonic-gate fsm_state(f->state)); 757*7c478bd9Sstevel@tonic-gate return; 758*7c478bd9Sstevel@tonic-gate } 759*7c478bd9Sstevel@tonic-gate 760*7c478bd9Sstevel@tonic-gate /* 761*7c478bd9Sstevel@tonic-gate * Upcall the proper Protocol-Reject routine. 762*7c478bd9Sstevel@tonic-gate */ 763*7c478bd9Sstevel@tonic-gate for (i = 0; (protp = protocols[i]) != NULL; ++i) 764*7c478bd9Sstevel@tonic-gate if (protp->protocol == prot && protp->enabled_flag) { 765*7c478bd9Sstevel@tonic-gate (*protp->protrej)(f->unit); 766*7c478bd9Sstevel@tonic-gate return; 767*7c478bd9Sstevel@tonic-gate } 768*7c478bd9Sstevel@tonic-gate 769*7c478bd9Sstevel@tonic-gate warn("Protocol-Reject for unsupported protocol 0x%x", prot); 770*7c478bd9Sstevel@tonic-gate } 771*7c478bd9Sstevel@tonic-gate 772*7c478bd9Sstevel@tonic-gate 773*7c478bd9Sstevel@tonic-gate /* 774*7c478bd9Sstevel@tonic-gate * lcp_protrej - A Protocol-Reject was received. 775*7c478bd9Sstevel@tonic-gate */ 776*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 777*7c478bd9Sstevel@tonic-gate static void 778*7c478bd9Sstevel@tonic-gate lcp_protrej(unit) 779*7c478bd9Sstevel@tonic-gate int unit; 780*7c478bd9Sstevel@tonic-gate { 781*7c478bd9Sstevel@tonic-gate /* 782*7c478bd9Sstevel@tonic-gate * Can't reject LCP! 783*7c478bd9Sstevel@tonic-gate */ 784*7c478bd9Sstevel@tonic-gate error("Received Protocol-Reject for LCP!"); 785*7c478bd9Sstevel@tonic-gate } 786*7c478bd9Sstevel@tonic-gate 787*7c478bd9Sstevel@tonic-gate /* 788*7c478bd9Sstevel@tonic-gate * lcp_coderej - A Code-Reject was received. 789*7c478bd9Sstevel@tonic-gate */ 790*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 791*7c478bd9Sstevel@tonic-gate static int 792*7c478bd9Sstevel@tonic-gate lcp_coderej(f, code, id, inp, len) 793*7c478bd9Sstevel@tonic-gate fsm *f; 794*7c478bd9Sstevel@tonic-gate int code; 795*7c478bd9Sstevel@tonic-gate int id; 796*7c478bd9Sstevel@tonic-gate u_char *inp; 797*7c478bd9Sstevel@tonic-gate int len; 798*7c478bd9Sstevel@tonic-gate { 799*7c478bd9Sstevel@tonic-gate /* The peer cannot reject these code numbers. */ 800*7c478bd9Sstevel@tonic-gate if (code >= CODE_CONFREQ && code <= CODE_PROTREJ) 801*7c478bd9Sstevel@tonic-gate return 1; 802*7c478bd9Sstevel@tonic-gate switch (code) { 803*7c478bd9Sstevel@tonic-gate case CODE_ECHOREQ: 804*7c478bd9Sstevel@tonic-gate /* 805*7c478bd9Sstevel@tonic-gate * If the peer rejects an Echo-Request, then stop doing that. 806*7c478bd9Sstevel@tonic-gate */ 807*7c478bd9Sstevel@tonic-gate if (lcp_echo_timer_running != 0) { 808*7c478bd9Sstevel@tonic-gate UNTIMEOUT (LcpEchoTimeout, f); 809*7c478bd9Sstevel@tonic-gate lcp_echo_timer_running = 0; 810*7c478bd9Sstevel@tonic-gate lcp_echo_interval = 0; 811*7c478bd9Sstevel@tonic-gate } 812*7c478bd9Sstevel@tonic-gate break; 813*7c478bd9Sstevel@tonic-gate } 814*7c478bd9Sstevel@tonic-gate return 0; 815*7c478bd9Sstevel@tonic-gate } 816*7c478bd9Sstevel@tonic-gate 817*7c478bd9Sstevel@tonic-gate /* 818*7c478bd9Sstevel@tonic-gate * lcp_sprotrej - Send a Protocol-Reject for some protocol. 819*7c478bd9Sstevel@tonic-gate */ 820*7c478bd9Sstevel@tonic-gate void 821*7c478bd9Sstevel@tonic-gate lcp_sprotrej(unit, p, len) 822*7c478bd9Sstevel@tonic-gate int unit; 823*7c478bd9Sstevel@tonic-gate u_char *p; 824*7c478bd9Sstevel@tonic-gate int len; 825*7c478bd9Sstevel@tonic-gate { 826*7c478bd9Sstevel@tonic-gate /* 827*7c478bd9Sstevel@tonic-gate * Send back the protocol and the information field of the 828*7c478bd9Sstevel@tonic-gate * rejected packet. We only get here if LCP is in the OPENED state. 829*7c478bd9Sstevel@tonic-gate */ 830*7c478bd9Sstevel@tonic-gate p += 2; 831*7c478bd9Sstevel@tonic-gate len -= 2; 832*7c478bd9Sstevel@tonic-gate 833*7c478bd9Sstevel@tonic-gate fsm_sdata(&lcp_fsm[unit], CODE_PROTREJ, ++lcp_fsm[unit].id, 834*7c478bd9Sstevel@tonic-gate p, len); 835*7c478bd9Sstevel@tonic-gate } 836*7c478bd9Sstevel@tonic-gate 837*7c478bd9Sstevel@tonic-gate 838*7c478bd9Sstevel@tonic-gate /* 839*7c478bd9Sstevel@tonic-gate * lcp_resetci - Reset our CI. 840*7c478bd9Sstevel@tonic-gate */ 841*7c478bd9Sstevel@tonic-gate static void 842*7c478bd9Sstevel@tonic-gate lcp_resetci(f) 843*7c478bd9Sstevel@tonic-gate fsm *f; 844*7c478bd9Sstevel@tonic-gate { 845*7c478bd9Sstevel@tonic-gate lcp_options *wo = &lcp_wantoptions[f->unit]; 846*7c478bd9Sstevel@tonic-gate lcp_options *go = &lcp_gotoptions[f->unit]; 847*7c478bd9Sstevel@tonic-gate lcp_options *ao = &lcp_allowoptions[f->unit]; 848*7c478bd9Sstevel@tonic-gate 849*7c478bd9Sstevel@tonic-gate wo->magicnumber = magic(); 850*7c478bd9Sstevel@tonic-gate wo->numloops = 0; 851*7c478bd9Sstevel@tonic-gate sentident = 0; 852*7c478bd9Sstevel@tonic-gate *go = *wo; 853*7c478bd9Sstevel@tonic-gate if (!multilink) { 854*7c478bd9Sstevel@tonic-gate go->neg_mrru = 0; 855*7c478bd9Sstevel@tonic-gate go->neg_ssnhf = 0; 856*7c478bd9Sstevel@tonic-gate } 857*7c478bd9Sstevel@tonic-gate if (noendpoint) 858*7c478bd9Sstevel@tonic-gate ao->neg_endpoint = 0; 859*7c478bd9Sstevel@tonic-gate if (go->mru > absmax_mru) 860*7c478bd9Sstevel@tonic-gate go->mru = absmax_mru; 861*7c478bd9Sstevel@tonic-gate if (ao->mru > absmax_mtu) 862*7c478bd9Sstevel@tonic-gate ao->mru = absmax_mtu; 863*7c478bd9Sstevel@tonic-gate unsolicit_mru = 1; 864*7c478bd9Sstevel@tonic-gate fsm_setpeermru(f->unit, PPP_MTU > absmax_mtu ? absmax_mtu : PPP_MTU); 865*7c478bd9Sstevel@tonic-gate auth_reset(f->unit); 866*7c478bd9Sstevel@tonic-gate } 867*7c478bd9Sstevel@tonic-gate 868*7c478bd9Sstevel@tonic-gate 869*7c478bd9Sstevel@tonic-gate /* 870*7c478bd9Sstevel@tonic-gate * lcp_cilen - Return length of our CI. 871*7c478bd9Sstevel@tonic-gate */ 872*7c478bd9Sstevel@tonic-gate static int 873*7c478bd9Sstevel@tonic-gate lcp_cilen(f) 874*7c478bd9Sstevel@tonic-gate fsm *f; 875*7c478bd9Sstevel@tonic-gate { 876*7c478bd9Sstevel@tonic-gate lcp_options *go = &lcp_gotoptions[f->unit]; 877*7c478bd9Sstevel@tonic-gate 878*7c478bd9Sstevel@tonic-gate #define LENCIVOID(neg) ((neg) ? CILEN_VOID : 0) 879*7c478bd9Sstevel@tonic-gate #define LENCICHAP(neg) ((neg) ? CILEN_CHAP : 0) 880*7c478bd9Sstevel@tonic-gate #define LENCICHAR(neg) ((neg) ? CILEN_CHAR : 0) 881*7c478bd9Sstevel@tonic-gate #define LENCISHORT(neg) ((neg) ? CILEN_SHORT : 0) 882*7c478bd9Sstevel@tonic-gate #define LENCILONG(neg) ((neg) ? CILEN_LONG : 0) 883*7c478bd9Sstevel@tonic-gate #define LENCILQR(neg) ((neg) ? CILEN_LQR: 0) 884*7c478bd9Sstevel@tonic-gate #define LENCICBCP(neg) ((neg) ? CILEN_CBCP: 0) 885*7c478bd9Sstevel@tonic-gate /* 886*7c478bd9Sstevel@tonic-gate * NB: we only ask for one of CHAP and UPAP, even if we will 887*7c478bd9Sstevel@tonic-gate * accept either. 888*7c478bd9Sstevel@tonic-gate */ 889*7c478bd9Sstevel@tonic-gate return (LENCISHORT(go->neg_mru && go->mru != PPP_MRU) + 890*7c478bd9Sstevel@tonic-gate LENCILONG(go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF) + 891*7c478bd9Sstevel@tonic-gate LENCICHAP(go->neg_chap || go->neg_mschap || go->neg_mschapv2) + 892*7c478bd9Sstevel@tonic-gate LENCISHORT(!go->neg_chap && go->neg_upap && !go->neg_mschap && 893*7c478bd9Sstevel@tonic-gate !go->neg_mschapv2) + 894*7c478bd9Sstevel@tonic-gate LENCILQR(go->neg_lqr) + 895*7c478bd9Sstevel@tonic-gate LENCICBCP(go->neg_cbcp) + 896*7c478bd9Sstevel@tonic-gate LENCILONG(go->neg_magicnumber) + 897*7c478bd9Sstevel@tonic-gate LENCIVOID(go->neg_pcompression) + 898*7c478bd9Sstevel@tonic-gate LENCIVOID(go->neg_accompression) + 899*7c478bd9Sstevel@tonic-gate LENCICHAR(go->neg_fcs) + 900*7c478bd9Sstevel@tonic-gate LENCISHORT(go->neg_mrru) + 901*7c478bd9Sstevel@tonic-gate LENCIVOID(go->neg_ssnhf) + 902*7c478bd9Sstevel@tonic-gate #ifdef MUX_FRAME 903*7c478bd9Sstevel@tonic-gate LENCIVOID(go->pppmux) + 904*7c478bd9Sstevel@tonic-gate #endif 905*7c478bd9Sstevel@tonic-gate (go->neg_endpoint? CILEN_CHAR + go->endpoint.length: 0)); 906*7c478bd9Sstevel@tonic-gate } 907*7c478bd9Sstevel@tonic-gate 908*7c478bd9Sstevel@tonic-gate 909*7c478bd9Sstevel@tonic-gate /* 910*7c478bd9Sstevel@tonic-gate * lcp_addci - Add our desired CIs to a packet. 911*7c478bd9Sstevel@tonic-gate */ 912*7c478bd9Sstevel@tonic-gate static void 913*7c478bd9Sstevel@tonic-gate lcp_addci(f, ucp, lenp) 914*7c478bd9Sstevel@tonic-gate fsm *f; 915*7c478bd9Sstevel@tonic-gate u_char *ucp; 916*7c478bd9Sstevel@tonic-gate int *lenp; 917*7c478bd9Sstevel@tonic-gate { 918*7c478bd9Sstevel@tonic-gate lcp_options *go = &lcp_gotoptions[f->unit]; 919*7c478bd9Sstevel@tonic-gate lcp_options *ho = &lcp_hisoptions[f->unit]; 920*7c478bd9Sstevel@tonic-gate u_char *start_ucp = ucp; 921*7c478bd9Sstevel@tonic-gate 922*7c478bd9Sstevel@tonic-gate #define ADDCIVOID(opt, neg) \ 923*7c478bd9Sstevel@tonic-gate if (neg) { \ 924*7c478bd9Sstevel@tonic-gate PUTCHAR(opt, ucp); \ 925*7c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_VOID, ucp); \ 926*7c478bd9Sstevel@tonic-gate } 927*7c478bd9Sstevel@tonic-gate #define ADDCISHORT(opt, neg, val) \ 928*7c478bd9Sstevel@tonic-gate if (neg) { \ 929*7c478bd9Sstevel@tonic-gate PUTCHAR(opt, ucp); \ 930*7c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_SHORT, ucp); \ 931*7c478bd9Sstevel@tonic-gate PUTSHORT(val, ucp); \ 932*7c478bd9Sstevel@tonic-gate } 933*7c478bd9Sstevel@tonic-gate #define ADDCICHAP(opt, neg, val, digest) \ 934*7c478bd9Sstevel@tonic-gate if (neg) { \ 935*7c478bd9Sstevel@tonic-gate PUTCHAR(opt, ucp); \ 936*7c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_CHAP, ucp); \ 937*7c478bd9Sstevel@tonic-gate PUTSHORT(val, ucp); \ 938*7c478bd9Sstevel@tonic-gate PUTCHAR(digest, ucp); \ 939*7c478bd9Sstevel@tonic-gate } 940*7c478bd9Sstevel@tonic-gate #define ADDCILONG(opt, neg, val) \ 941*7c478bd9Sstevel@tonic-gate if (neg) { \ 942*7c478bd9Sstevel@tonic-gate PUTCHAR(opt, ucp); \ 943*7c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_LONG, ucp); \ 944*7c478bd9Sstevel@tonic-gate PUTLONG(val, ucp); \ 945*7c478bd9Sstevel@tonic-gate } 946*7c478bd9Sstevel@tonic-gate #define ADDCILQR(opt, neg, val) \ 947*7c478bd9Sstevel@tonic-gate if (neg) { \ 948*7c478bd9Sstevel@tonic-gate PUTCHAR(opt, ucp); \ 949*7c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_LQR, ucp); \ 950*7c478bd9Sstevel@tonic-gate PUTSHORT(PPP_LQR, ucp); \ 951*7c478bd9Sstevel@tonic-gate PUTLONG(val, ucp); \ 952*7c478bd9Sstevel@tonic-gate } 953*7c478bd9Sstevel@tonic-gate #define ADDCICHAR(opt, neg, val) \ 954*7c478bd9Sstevel@tonic-gate if (neg) { \ 955*7c478bd9Sstevel@tonic-gate PUTCHAR(opt, ucp); \ 956*7c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_CHAR, ucp); \ 957*7c478bd9Sstevel@tonic-gate PUTCHAR(val, ucp); \ 958*7c478bd9Sstevel@tonic-gate } 959*7c478bd9Sstevel@tonic-gate #define ADDCIENDP(opt, neg, class, val, len) \ 960*7c478bd9Sstevel@tonic-gate if (neg) { \ 961*7c478bd9Sstevel@tonic-gate int i; \ 962*7c478bd9Sstevel@tonic-gate PUTCHAR(opt, ucp); \ 963*7c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_CHAR + len, ucp); \ 964*7c478bd9Sstevel@tonic-gate PUTCHAR(class, ucp); \ 965*7c478bd9Sstevel@tonic-gate for (i = 0; i < len; ++i) \ 966*7c478bd9Sstevel@tonic-gate PUTCHAR(val[i], ucp); \ 967*7c478bd9Sstevel@tonic-gate } 968*7c478bd9Sstevel@tonic-gate 969*7c478bd9Sstevel@tonic-gate ADDCISHORT(CI_MRU, go->neg_mru && go->mru != PPP_MRU, go->mru); 970*7c478bd9Sstevel@tonic-gate ADDCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF, 971*7c478bd9Sstevel@tonic-gate go->asyncmap); 972*7c478bd9Sstevel@tonic-gate /* go->chap_mdtype always points to a useful value */ 973*7c478bd9Sstevel@tonic-gate ADDCICHAP(CI_AUTHTYPE, go->neg_chap || go->neg_mschap || go->neg_mschapv2, 974*7c478bd9Sstevel@tonic-gate PPP_CHAP, go->chap_mdtype); 975*7c478bd9Sstevel@tonic-gate ADDCISHORT(CI_AUTHTYPE, !(go->neg_chap || go->neg_mschap || 976*7c478bd9Sstevel@tonic-gate go->neg_mschapv2) && go->neg_upap, PPP_PAP); 977*7c478bd9Sstevel@tonic-gate /* We can't both say zero for LQR period. */ 978*7c478bd9Sstevel@tonic-gate if (f->state == ACKSENT && go->neg_lqr && go->lqr_period == 0 && 979*7c478bd9Sstevel@tonic-gate ho->neg_lqr && ho->lqr_period == 0) 980*7c478bd9Sstevel@tonic-gate go->lqr_period = 500; 981*7c478bd9Sstevel@tonic-gate ADDCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period); 982*7c478bd9Sstevel@tonic-gate ADDCICHAR(CI_CALLBACK, go->neg_cbcp, CBOP_CBCP); 983*7c478bd9Sstevel@tonic-gate ADDCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber); 984*7c478bd9Sstevel@tonic-gate ADDCIVOID(CI_PCOMPRESSION, go->neg_pcompression); 985*7c478bd9Sstevel@tonic-gate ADDCIVOID(CI_ACCOMPRESSION, go->neg_accompression); 986*7c478bd9Sstevel@tonic-gate ADDCICHAR(CI_FCSALTERN, (go->neg_fcs && go->fcs_type != 0), go->fcs_type); 987*7c478bd9Sstevel@tonic-gate ADDCIENDP(CI_EPDISC, go->neg_endpoint, go->endpoint.class, 988*7c478bd9Sstevel@tonic-gate go->endpoint.value, go->endpoint.length); 989*7c478bd9Sstevel@tonic-gate #ifdef MUX_FRAME 990*7c478bd9Sstevel@tonic-gate ADDCIVOID(CI_MUXING, go->pppmux); 991*7c478bd9Sstevel@tonic-gate #endif 992*7c478bd9Sstevel@tonic-gate ADDCISHORT(CI_MRRU, go->neg_mrru, go->mrru); 993*7c478bd9Sstevel@tonic-gate ADDCIVOID(CI_SSNHF, go->neg_ssnhf); 994*7c478bd9Sstevel@tonic-gate 995*7c478bd9Sstevel@tonic-gate if (ucp - start_ucp != *lenp) { 996*7c478bd9Sstevel@tonic-gate /* this should never happen, because peer_mtu should be 1500 */ 997*7c478bd9Sstevel@tonic-gate error("Bug in lcp_addci: wrong length"); 998*7c478bd9Sstevel@tonic-gate } 999*7c478bd9Sstevel@tonic-gate } 1000*7c478bd9Sstevel@tonic-gate 1001*7c478bd9Sstevel@tonic-gate 1002*7c478bd9Sstevel@tonic-gate /* 1003*7c478bd9Sstevel@tonic-gate * lcp_ackci - Ack our CIs. 1004*7c478bd9Sstevel@tonic-gate * This should not modify any state if the Ack is bad. 1005*7c478bd9Sstevel@tonic-gate * 1006*7c478bd9Sstevel@tonic-gate * Returns: 1007*7c478bd9Sstevel@tonic-gate * 0 - Ack was bad. 1008*7c478bd9Sstevel@tonic-gate * 1 - Ack was good. 1009*7c478bd9Sstevel@tonic-gate */ 1010*7c478bd9Sstevel@tonic-gate static int 1011*7c478bd9Sstevel@tonic-gate lcp_ackci(f, p, len) 1012*7c478bd9Sstevel@tonic-gate fsm *f; 1013*7c478bd9Sstevel@tonic-gate u_char *p; 1014*7c478bd9Sstevel@tonic-gate int len; 1015*7c478bd9Sstevel@tonic-gate { 1016*7c478bd9Sstevel@tonic-gate lcp_options *go = &lcp_gotoptions[f->unit]; 1017*7c478bd9Sstevel@tonic-gate #ifdef MUX_FRAME 1018*7c478bd9Sstevel@tonic-gate lcp_options *ao = &lcp_allowoptions[f->unit]; 1019*7c478bd9Sstevel@tonic-gate #endif 1020*7c478bd9Sstevel@tonic-gate u_char cilen, citype, cichar; 1021*7c478bd9Sstevel@tonic-gate u_short cishort; 1022*7c478bd9Sstevel@tonic-gate u_int32_t cilong; 1023*7c478bd9Sstevel@tonic-gate 1024*7c478bd9Sstevel@tonic-gate /* 1025*7c478bd9Sstevel@tonic-gate * CIs must be in exactly the same order that we sent. 1026*7c478bd9Sstevel@tonic-gate * Check packet length and CI length at each step. 1027*7c478bd9Sstevel@tonic-gate * If we find any deviations, then this packet is bad. 1028*7c478bd9Sstevel@tonic-gate */ 1029*7c478bd9Sstevel@tonic-gate #define ACKCIVOID(opt, neg) \ 1030*7c478bd9Sstevel@tonic-gate if (neg) { \ 1031*7c478bd9Sstevel@tonic-gate if ((len -= CILEN_VOID) < 0) \ 1032*7c478bd9Sstevel@tonic-gate goto bad; \ 1033*7c478bd9Sstevel@tonic-gate GETCHAR(citype, p); \ 1034*7c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); \ 1035*7c478bd9Sstevel@tonic-gate if (cilen != CILEN_VOID || \ 1036*7c478bd9Sstevel@tonic-gate citype != opt) \ 1037*7c478bd9Sstevel@tonic-gate goto bad; \ 1038*7c478bd9Sstevel@tonic-gate } 1039*7c478bd9Sstevel@tonic-gate #define ACKCISHORT(opt, neg, val) \ 1040*7c478bd9Sstevel@tonic-gate if (neg) { \ 1041*7c478bd9Sstevel@tonic-gate if ((len -= CILEN_SHORT) < 0) \ 1042*7c478bd9Sstevel@tonic-gate goto bad; \ 1043*7c478bd9Sstevel@tonic-gate GETCHAR(citype, p); \ 1044*7c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); \ 1045*7c478bd9Sstevel@tonic-gate if (cilen != CILEN_SHORT || \ 1046*7c478bd9Sstevel@tonic-gate citype != opt) \ 1047*7c478bd9Sstevel@tonic-gate goto bad; \ 1048*7c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \ 1049*7c478bd9Sstevel@tonic-gate if (cishort != val) \ 1050*7c478bd9Sstevel@tonic-gate goto bad; \ 1051*7c478bd9Sstevel@tonic-gate } 1052*7c478bd9Sstevel@tonic-gate #define ACKCIAUTH(opt, neg, val) \ 1053*7c478bd9Sstevel@tonic-gate if (neg) { \ 1054*7c478bd9Sstevel@tonic-gate if ((len -= CILEN_SHORT) < 0) \ 1055*7c478bd9Sstevel@tonic-gate goto bad; \ 1056*7c478bd9Sstevel@tonic-gate GETCHAR(citype, p); \ 1057*7c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); \ 1058*7c478bd9Sstevel@tonic-gate if (cilen != CILEN_SHORT || \ 1059*7c478bd9Sstevel@tonic-gate citype != opt) \ 1060*7c478bd9Sstevel@tonic-gate goto bad; \ 1061*7c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \ 1062*7c478bd9Sstevel@tonic-gate if (cishort != val) \ 1063*7c478bd9Sstevel@tonic-gate goto bad; \ 1064*7c478bd9Sstevel@tonic-gate peer_nak_auth = 0; \ 1065*7c478bd9Sstevel@tonic-gate peer_reject_auth = 0; \ 1066*7c478bd9Sstevel@tonic-gate } 1067*7c478bd9Sstevel@tonic-gate #define ACKCICHAR(opt, neg, val) \ 1068*7c478bd9Sstevel@tonic-gate if (neg) { \ 1069*7c478bd9Sstevel@tonic-gate if ((len -= CILEN_CHAR) < 0) \ 1070*7c478bd9Sstevel@tonic-gate goto bad; \ 1071*7c478bd9Sstevel@tonic-gate GETCHAR(citype, p); \ 1072*7c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); \ 1073*7c478bd9Sstevel@tonic-gate if (cilen != CILEN_CHAR || \ 1074*7c478bd9Sstevel@tonic-gate citype != opt) \ 1075*7c478bd9Sstevel@tonic-gate goto bad; \ 1076*7c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); \ 1077*7c478bd9Sstevel@tonic-gate if (cichar != val) \ 1078*7c478bd9Sstevel@tonic-gate goto bad; \ 1079*7c478bd9Sstevel@tonic-gate } 1080*7c478bd9Sstevel@tonic-gate #define ACKCICHAP(opt, neg, val, digest) \ 1081*7c478bd9Sstevel@tonic-gate if (neg) { \ 1082*7c478bd9Sstevel@tonic-gate if ((len -= CILEN_CHAP) < 0) \ 1083*7c478bd9Sstevel@tonic-gate goto bad; \ 1084*7c478bd9Sstevel@tonic-gate GETCHAR(citype, p); \ 1085*7c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); \ 1086*7c478bd9Sstevel@tonic-gate if (cilen != CILEN_CHAP || \ 1087*7c478bd9Sstevel@tonic-gate citype != opt) \ 1088*7c478bd9Sstevel@tonic-gate goto bad; \ 1089*7c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \ 1090*7c478bd9Sstevel@tonic-gate if (cishort != val) \ 1091*7c478bd9Sstevel@tonic-gate goto bad; \ 1092*7c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); \ 1093*7c478bd9Sstevel@tonic-gate if (cichar != digest) \ 1094*7c478bd9Sstevel@tonic-gate goto bad; \ 1095*7c478bd9Sstevel@tonic-gate peer_nak_auth = 0; \ 1096*7c478bd9Sstevel@tonic-gate peer_reject_auth = 0; \ 1097*7c478bd9Sstevel@tonic-gate } 1098*7c478bd9Sstevel@tonic-gate #define ACKCILONG(opt, neg, val) \ 1099*7c478bd9Sstevel@tonic-gate if (neg) { \ 1100*7c478bd9Sstevel@tonic-gate if ((len -= CILEN_LONG) < 0) \ 1101*7c478bd9Sstevel@tonic-gate goto bad; \ 1102*7c478bd9Sstevel@tonic-gate GETCHAR(citype, p); \ 1103*7c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); \ 1104*7c478bd9Sstevel@tonic-gate if (cilen != CILEN_LONG || \ 1105*7c478bd9Sstevel@tonic-gate citype != opt) \ 1106*7c478bd9Sstevel@tonic-gate goto bad; \ 1107*7c478bd9Sstevel@tonic-gate GETLONG(cilong, p); \ 1108*7c478bd9Sstevel@tonic-gate if (cilong != val) \ 1109*7c478bd9Sstevel@tonic-gate goto bad; \ 1110*7c478bd9Sstevel@tonic-gate } 1111*7c478bd9Sstevel@tonic-gate #define ACKCILQR(opt, neg, val) \ 1112*7c478bd9Sstevel@tonic-gate if (neg) { \ 1113*7c478bd9Sstevel@tonic-gate if ((len -= CILEN_LQR) < 0) \ 1114*7c478bd9Sstevel@tonic-gate goto bad; \ 1115*7c478bd9Sstevel@tonic-gate GETCHAR(citype, p); \ 1116*7c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); \ 1117*7c478bd9Sstevel@tonic-gate if (cilen != CILEN_LQR || \ 1118*7c478bd9Sstevel@tonic-gate citype != opt) \ 1119*7c478bd9Sstevel@tonic-gate goto bad; \ 1120*7c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \ 1121*7c478bd9Sstevel@tonic-gate if (cishort != PPP_LQR) \ 1122*7c478bd9Sstevel@tonic-gate goto bad; \ 1123*7c478bd9Sstevel@tonic-gate GETLONG(cilong, p); \ 1124*7c478bd9Sstevel@tonic-gate if (cilong != val) \ 1125*7c478bd9Sstevel@tonic-gate goto bad; \ 1126*7c478bd9Sstevel@tonic-gate } 1127*7c478bd9Sstevel@tonic-gate #define ACKCIENDP(opt, neg, class, val, vlen) \ 1128*7c478bd9Sstevel@tonic-gate if (neg) { \ 1129*7c478bd9Sstevel@tonic-gate int i; \ 1130*7c478bd9Sstevel@tonic-gate if ((len -= CILEN_CHAR + vlen) < 0) \ 1131*7c478bd9Sstevel@tonic-gate goto bad; \ 1132*7c478bd9Sstevel@tonic-gate GETCHAR(citype, p); \ 1133*7c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); \ 1134*7c478bd9Sstevel@tonic-gate if (cilen != CILEN_CHAR + vlen || \ 1135*7c478bd9Sstevel@tonic-gate citype != opt) \ 1136*7c478bd9Sstevel@tonic-gate goto bad; \ 1137*7c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); \ 1138*7c478bd9Sstevel@tonic-gate if (cichar != class) \ 1139*7c478bd9Sstevel@tonic-gate goto bad; \ 1140*7c478bd9Sstevel@tonic-gate for (i = 0; i < vlen; ++i) { \ 1141*7c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); \ 1142*7c478bd9Sstevel@tonic-gate if (cichar != val[i]) \ 1143*7c478bd9Sstevel@tonic-gate goto bad; \ 1144*7c478bd9Sstevel@tonic-gate } \ 1145*7c478bd9Sstevel@tonic-gate } 1146*7c478bd9Sstevel@tonic-gate 1147*7c478bd9Sstevel@tonic-gate ACKCISHORT(CI_MRU, go->neg_mru && go->mru != PPP_MRU, go->mru); 1148*7c478bd9Sstevel@tonic-gate ACKCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF, 1149*7c478bd9Sstevel@tonic-gate go->asyncmap); 1150*7c478bd9Sstevel@tonic-gate /* go->chap_mdtype always points to a useful value */ 1151*7c478bd9Sstevel@tonic-gate ACKCICHAP(CI_AUTHTYPE, go->neg_chap || go->neg_mschap || go->neg_mschapv2, 1152*7c478bd9Sstevel@tonic-gate PPP_CHAP, go->chap_mdtype); 1153*7c478bd9Sstevel@tonic-gate ACKCIAUTH(CI_AUTHTYPE, !(go->neg_chap || go->neg_mschap || 1154*7c478bd9Sstevel@tonic-gate go->neg_mschapv2) && go->neg_upap, PPP_PAP); 1155*7c478bd9Sstevel@tonic-gate ACKCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period); 1156*7c478bd9Sstevel@tonic-gate ACKCICHAR(CI_CALLBACK, go->neg_cbcp, CBOP_CBCP); 1157*7c478bd9Sstevel@tonic-gate ACKCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber); 1158*7c478bd9Sstevel@tonic-gate ACKCIVOID(CI_PCOMPRESSION, go->neg_pcompression); 1159*7c478bd9Sstevel@tonic-gate ACKCIVOID(CI_ACCOMPRESSION, go->neg_accompression); 1160*7c478bd9Sstevel@tonic-gate ACKCICHAR(CI_FCSALTERN, go->neg_fcs, go->fcs_type); 1161*7c478bd9Sstevel@tonic-gate ACKCIENDP(CI_EPDISC, go->neg_endpoint, go->endpoint.class, 1162*7c478bd9Sstevel@tonic-gate go->endpoint.value, go->endpoint.length); 1163*7c478bd9Sstevel@tonic-gate #ifdef MUX_FRAME 1164*7c478bd9Sstevel@tonic-gate ACKCIVOID(CI_MUXING, go->pppmux); 1165*7c478bd9Sstevel@tonic-gate if (go->pppmux) 1166*7c478bd9Sstevel@tonic-gate go->pppmux = ao->pppmux; 1167*7c478bd9Sstevel@tonic-gate #endif 1168*7c478bd9Sstevel@tonic-gate ACKCISHORT(CI_MRRU, go->neg_mrru, go->mrru); 1169*7c478bd9Sstevel@tonic-gate ACKCIVOID(CI_SSNHF, go->neg_ssnhf); 1170*7c478bd9Sstevel@tonic-gate 1171*7c478bd9Sstevel@tonic-gate /* 1172*7c478bd9Sstevel@tonic-gate * If there are any remaining CIs, then this packet is bad. 1173*7c478bd9Sstevel@tonic-gate */ 1174*7c478bd9Sstevel@tonic-gate if (len != 0) 1175*7c478bd9Sstevel@tonic-gate goto bad; 1176*7c478bd9Sstevel@tonic-gate return (1); 1177*7c478bd9Sstevel@tonic-gate bad: 1178*7c478bd9Sstevel@tonic-gate dbglog("lcp_acki: received bad Ack!"); 1179*7c478bd9Sstevel@tonic-gate return (0); 1180*7c478bd9Sstevel@tonic-gate } 1181*7c478bd9Sstevel@tonic-gate 1182*7c478bd9Sstevel@tonic-gate 1183*7c478bd9Sstevel@tonic-gate /* 1184*7c478bd9Sstevel@tonic-gate * lcp_nakci - Peer has sent a NAK for some of our CIs. 1185*7c478bd9Sstevel@tonic-gate * This should not modify any state if the Nak is bad 1186*7c478bd9Sstevel@tonic-gate * or if LCP is in the OPENED state. 1187*7c478bd9Sstevel@tonic-gate * 1188*7c478bd9Sstevel@tonic-gate * Returns: 1189*7c478bd9Sstevel@tonic-gate * 0 - Nak was bad. 1190*7c478bd9Sstevel@tonic-gate * 1 - Nak was good. 1191*7c478bd9Sstevel@tonic-gate */ 1192*7c478bd9Sstevel@tonic-gate static int 1193*7c478bd9Sstevel@tonic-gate lcp_nakci(f, p, len) 1194*7c478bd9Sstevel@tonic-gate fsm *f; 1195*7c478bd9Sstevel@tonic-gate u_char *p; 1196*7c478bd9Sstevel@tonic-gate int len; 1197*7c478bd9Sstevel@tonic-gate { 1198*7c478bd9Sstevel@tonic-gate lcp_options *go = &lcp_gotoptions[f->unit]; 1199*7c478bd9Sstevel@tonic-gate lcp_options *wo = &lcp_wantoptions[f->unit]; 1200*7c478bd9Sstevel@tonic-gate u_char citype, cichar, *next; 1201*7c478bd9Sstevel@tonic-gate u_short cishort; 1202*7c478bd9Sstevel@tonic-gate u_int32_t cilong; 1203*7c478bd9Sstevel@tonic-gate lcp_options no; /* options we've seen Naks for */ 1204*7c478bd9Sstevel@tonic-gate lcp_options try; /* options to request next time */ 1205*7c478bd9Sstevel@tonic-gate int looped_back = 0; 1206*7c478bd9Sstevel@tonic-gate int cilen; 1207*7c478bd9Sstevel@tonic-gate 1208*7c478bd9Sstevel@tonic-gate BZERO(&no, sizeof(no)); 1209*7c478bd9Sstevel@tonic-gate try = *go; 1210*7c478bd9Sstevel@tonic-gate 1211*7c478bd9Sstevel@tonic-gate /* 1212*7c478bd9Sstevel@tonic-gate * Any Nak'd CIs must be in exactly the same order that we sent. 1213*7c478bd9Sstevel@tonic-gate * Check packet length and CI length at each step. 1214*7c478bd9Sstevel@tonic-gate * If we find any deviations, then this packet is bad. 1215*7c478bd9Sstevel@tonic-gate */ 1216*7c478bd9Sstevel@tonic-gate #define NAKCIVOID(opt, neg) \ 1217*7c478bd9Sstevel@tonic-gate if (go->neg && \ 1218*7c478bd9Sstevel@tonic-gate len >= CILEN_VOID && \ 1219*7c478bd9Sstevel@tonic-gate p[1] == CILEN_VOID && \ 1220*7c478bd9Sstevel@tonic-gate p[0] == opt) { \ 1221*7c478bd9Sstevel@tonic-gate len -= CILEN_VOID; \ 1222*7c478bd9Sstevel@tonic-gate INCPTR(CILEN_VOID, p); \ 1223*7c478bd9Sstevel@tonic-gate no.neg = 1; \ 1224*7c478bd9Sstevel@tonic-gate try.neg = 0; \ 1225*7c478bd9Sstevel@tonic-gate } 1226*7c478bd9Sstevel@tonic-gate #define NAKCICHAR(opt, neg, code) \ 1227*7c478bd9Sstevel@tonic-gate if (go->neg && \ 1228*7c478bd9Sstevel@tonic-gate len >= CILEN_CHAR && \ 1229*7c478bd9Sstevel@tonic-gate p[1] == CILEN_CHAR && \ 1230*7c478bd9Sstevel@tonic-gate p[0] == opt) { \ 1231*7c478bd9Sstevel@tonic-gate len -= CILEN_CHAR; \ 1232*7c478bd9Sstevel@tonic-gate INCPTR(2, p); \ 1233*7c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); \ 1234*7c478bd9Sstevel@tonic-gate no.neg = 1; \ 1235*7c478bd9Sstevel@tonic-gate code \ 1236*7c478bd9Sstevel@tonic-gate } 1237*7c478bd9Sstevel@tonic-gate #define NAKCISHORT(opt, neg, code) \ 1238*7c478bd9Sstevel@tonic-gate if (go->neg && \ 1239*7c478bd9Sstevel@tonic-gate len >= CILEN_SHORT && \ 1240*7c478bd9Sstevel@tonic-gate p[1] == CILEN_SHORT && \ 1241*7c478bd9Sstevel@tonic-gate p[0] == opt) { \ 1242*7c478bd9Sstevel@tonic-gate len -= CILEN_SHORT; \ 1243*7c478bd9Sstevel@tonic-gate INCPTR(2, p); \ 1244*7c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \ 1245*7c478bd9Sstevel@tonic-gate no.neg = 1; \ 1246*7c478bd9Sstevel@tonic-gate code \ 1247*7c478bd9Sstevel@tonic-gate } 1248*7c478bd9Sstevel@tonic-gate #define NAKCILONG(opt, neg, code) \ 1249*7c478bd9Sstevel@tonic-gate if (go->neg && \ 1250*7c478bd9Sstevel@tonic-gate len >= CILEN_LONG && \ 1251*7c478bd9Sstevel@tonic-gate p[1] == CILEN_LONG && \ 1252*7c478bd9Sstevel@tonic-gate p[0] == opt) { \ 1253*7c478bd9Sstevel@tonic-gate len -= CILEN_LONG; \ 1254*7c478bd9Sstevel@tonic-gate INCPTR(2, p); \ 1255*7c478bd9Sstevel@tonic-gate GETLONG(cilong, p); \ 1256*7c478bd9Sstevel@tonic-gate no.neg = 1; \ 1257*7c478bd9Sstevel@tonic-gate code \ 1258*7c478bd9Sstevel@tonic-gate } 1259*7c478bd9Sstevel@tonic-gate #define NAKCILQR(opt, neg, code) \ 1260*7c478bd9Sstevel@tonic-gate if (go->neg && \ 1261*7c478bd9Sstevel@tonic-gate len >= CILEN_LQR && \ 1262*7c478bd9Sstevel@tonic-gate p[1] == CILEN_LQR && \ 1263*7c478bd9Sstevel@tonic-gate p[0] == opt) { \ 1264*7c478bd9Sstevel@tonic-gate len -= CILEN_LQR; \ 1265*7c478bd9Sstevel@tonic-gate INCPTR(2, p); \ 1266*7c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \ 1267*7c478bd9Sstevel@tonic-gate GETLONG(cilong, p); \ 1268*7c478bd9Sstevel@tonic-gate no.neg = 1; \ 1269*7c478bd9Sstevel@tonic-gate code \ 1270*7c478bd9Sstevel@tonic-gate } 1271*7c478bd9Sstevel@tonic-gate #define NAKCIENDP(opt, neg) \ 1272*7c478bd9Sstevel@tonic-gate if (go->neg && \ 1273*7c478bd9Sstevel@tonic-gate len >= CILEN_CHAR && \ 1274*7c478bd9Sstevel@tonic-gate p[0] == opt && \ 1275*7c478bd9Sstevel@tonic-gate p[1] >= CILEN_CHAR && \ 1276*7c478bd9Sstevel@tonic-gate p[1] <= len) { \ 1277*7c478bd9Sstevel@tonic-gate len -= p[1]; \ 1278*7c478bd9Sstevel@tonic-gate INCPTR(p[1], p); \ 1279*7c478bd9Sstevel@tonic-gate no.neg = 1; \ 1280*7c478bd9Sstevel@tonic-gate try.neg = 0; \ 1281*7c478bd9Sstevel@tonic-gate } 1282*7c478bd9Sstevel@tonic-gate 1283*7c478bd9Sstevel@tonic-gate /* 1284*7c478bd9Sstevel@tonic-gate * We don't care if they want to send us smaller packets than 1285*7c478bd9Sstevel@tonic-gate * we want. Therefore, accept any MRU less than what we asked for, 1286*7c478bd9Sstevel@tonic-gate * but then ignore the new value when setting the MRU in the kernel. 1287*7c478bd9Sstevel@tonic-gate * If they send us a bigger MRU than what we asked, accept it, up to 1288*7c478bd9Sstevel@tonic-gate * the limit of the default MRU we'd get if we didn't negotiate. 1289*7c478bd9Sstevel@tonic-gate */ 1290*7c478bd9Sstevel@tonic-gate if (go->neg_mru && go->mru != PPP_MRU) { 1291*7c478bd9Sstevel@tonic-gate NAKCISHORT(CI_MRU, neg_mru, 1292*7c478bd9Sstevel@tonic-gate if (cishort <= wo->mru || 1293*7c478bd9Sstevel@tonic-gate (cishort <= PPP_MRU && cishort <= absmax_mru)) 1294*7c478bd9Sstevel@tonic-gate try.mru = cishort; 1295*7c478bd9Sstevel@tonic-gate ); 1296*7c478bd9Sstevel@tonic-gate } 1297*7c478bd9Sstevel@tonic-gate 1298*7c478bd9Sstevel@tonic-gate /* 1299*7c478bd9Sstevel@tonic-gate * Add any characters they want to our (receive-side) asyncmap. 1300*7c478bd9Sstevel@tonic-gate */ 1301*7c478bd9Sstevel@tonic-gate if (go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF) { 1302*7c478bd9Sstevel@tonic-gate NAKCILONG(CI_ASYNCMAP, neg_asyncmap, 1303*7c478bd9Sstevel@tonic-gate try.asyncmap = go->asyncmap | cilong; 1304*7c478bd9Sstevel@tonic-gate ); 1305*7c478bd9Sstevel@tonic-gate } 1306*7c478bd9Sstevel@tonic-gate 1307*7c478bd9Sstevel@tonic-gate /* 1308*7c478bd9Sstevel@tonic-gate * If they've nak'd our authentication-protocol, check whether 1309*7c478bd9Sstevel@tonic-gate * they are proposing a different protocol, or a different 1310*7c478bd9Sstevel@tonic-gate * hash algorithm for CHAP. 1311*7c478bd9Sstevel@tonic-gate */ 1312*7c478bd9Sstevel@tonic-gate if ((go->neg_chap || go->neg_mschap || go->neg_mschapv2 || go->neg_upap) && 1313*7c478bd9Sstevel@tonic-gate len >= CILEN_SHORT && p[0] == CI_AUTHTYPE && p[1] >= CILEN_SHORT && 1314*7c478bd9Sstevel@tonic-gate p[1] <= len) { 1315*7c478bd9Sstevel@tonic-gate cilen = p[1]; 1316*7c478bd9Sstevel@tonic-gate len -= cilen; 1317*7c478bd9Sstevel@tonic-gate INCPTR(2, p); 1318*7c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); 1319*7c478bd9Sstevel@tonic-gate peer_nak_auth = 1; 1320*7c478bd9Sstevel@tonic-gate nak_auth_orig = (go->neg_chap || go->neg_mschap || go->neg_mschapv2) ? 1321*7c478bd9Sstevel@tonic-gate PPP_CHAP : PPP_PAP; 1322*7c478bd9Sstevel@tonic-gate nak_auth_proto = cishort; 1323*7c478bd9Sstevel@tonic-gate if (cishort == PPP_PAP && cilen == CILEN_SHORT) { 1324*7c478bd9Sstevel@tonic-gate no.neg_upap = go->neg_upap; 1325*7c478bd9Sstevel@tonic-gate /* 1326*7c478bd9Sstevel@tonic-gate * If we were asking for CHAP, they obviously don't want to do it. 1327*7c478bd9Sstevel@tonic-gate * If we weren't asking for CHAP, then we were asking for PAP, 1328*7c478bd9Sstevel@tonic-gate * in which case this Nak is bad. 1329*7c478bd9Sstevel@tonic-gate */ 1330*7c478bd9Sstevel@tonic-gate if (!go->neg_chap && !go->neg_mschap && !go->neg_mschapv2) 1331*7c478bd9Sstevel@tonic-gate goto bad; 1332*7c478bd9Sstevel@tonic-gate try.neg_chap = 0; 1333*7c478bd9Sstevel@tonic-gate try.neg_mschap = 0; 1334*7c478bd9Sstevel@tonic-gate try.neg_mschapv2 = 0; 1335*7c478bd9Sstevel@tonic-gate 1336*7c478bd9Sstevel@tonic-gate } else if (cishort == PPP_CHAP && cilen >= CILEN_CHAP) { 1337*7c478bd9Sstevel@tonic-gate /* stop asking for that type */ 1338*7c478bd9Sstevel@tonic-gate switch (go->chap_mdtype) { 1339*7c478bd9Sstevel@tonic-gate case CHAP_DIGEST_MD5: 1340*7c478bd9Sstevel@tonic-gate no.neg_chap = go->neg_chap; 1341*7c478bd9Sstevel@tonic-gate try.neg_chap = 0; 1342*7c478bd9Sstevel@tonic-gate break; 1343*7c478bd9Sstevel@tonic-gate case CHAP_MICROSOFT: 1344*7c478bd9Sstevel@tonic-gate no.neg_mschap = go->neg_mschap; 1345*7c478bd9Sstevel@tonic-gate try.neg_mschap = 0; 1346*7c478bd9Sstevel@tonic-gate break; 1347*7c478bd9Sstevel@tonic-gate case CHAP_MICROSOFT_V2: 1348*7c478bd9Sstevel@tonic-gate no.neg_mschapv2 = go->neg_mschapv2; 1349*7c478bd9Sstevel@tonic-gate try.neg_mschapv2 = 0; 1350*7c478bd9Sstevel@tonic-gate break; 1351*7c478bd9Sstevel@tonic-gate } 1352*7c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); 1353*7c478bd9Sstevel@tonic-gate /* Allow >= on length here for broken and silly peers. */ 1354*7c478bd9Sstevel@tonic-gate p += cilen - CILEN_CHAP; 1355*7c478bd9Sstevel@tonic-gate try.neg_upap = 0; 1356*7c478bd9Sstevel@tonic-gate if ((cichar == CHAP_DIGEST_MD5 && wo->neg_chap) || 1357*7c478bd9Sstevel@tonic-gate (cichar == CHAP_MICROSOFT && wo->neg_mschap) || 1358*7c478bd9Sstevel@tonic-gate (cichar == CHAP_MICROSOFT_V2 && wo->neg_mschapv2)) { 1359*7c478bd9Sstevel@tonic-gate /* Try his requested algorithm. */ 1360*7c478bd9Sstevel@tonic-gate try.chap_mdtype = cichar; 1361*7c478bd9Sstevel@tonic-gate } else { 1362*7c478bd9Sstevel@tonic-gate goto try_another; 1363*7c478bd9Sstevel@tonic-gate } 1364*7c478bd9Sstevel@tonic-gate 1365*7c478bd9Sstevel@tonic-gate } else { 1366*7c478bd9Sstevel@tonic-gate /* 1367*7c478bd9Sstevel@tonic-gate * We don't recognize what they're suggesting. 1368*7c478bd9Sstevel@tonic-gate * Stop asking for what we were asking for. 1369*7c478bd9Sstevel@tonic-gate */ 1370*7c478bd9Sstevel@tonic-gate try_another: 1371*7c478bd9Sstevel@tonic-gate if (go->neg_chap || go->neg_mschap || go->neg_mschapv2) { 1372*7c478bd9Sstevel@tonic-gate switch (go->chap_mdtype) { 1373*7c478bd9Sstevel@tonic-gate case CHAP_DIGEST_MD5: 1374*7c478bd9Sstevel@tonic-gate try.neg_chap = 0; 1375*7c478bd9Sstevel@tonic-gate if (wo->neg_mschap) { 1376*7c478bd9Sstevel@tonic-gate try.chap_mdtype = CHAP_MICROSOFT; 1377*7c478bd9Sstevel@tonic-gate break; 1378*7c478bd9Sstevel@tonic-gate } 1379*7c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/ 1380*7c478bd9Sstevel@tonic-gate case CHAP_MICROSOFT: 1381*7c478bd9Sstevel@tonic-gate try.neg_mschap = 0; 1382*7c478bd9Sstevel@tonic-gate if (wo->neg_mschapv2) { 1383*7c478bd9Sstevel@tonic-gate try.chap_mdtype = CHAP_MICROSOFT_V2; 1384*7c478bd9Sstevel@tonic-gate break; 1385*7c478bd9Sstevel@tonic-gate } 1386*7c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/ 1387*7c478bd9Sstevel@tonic-gate case CHAP_MICROSOFT_V2: 1388*7c478bd9Sstevel@tonic-gate try.neg_mschapv2 = 0; 1389*7c478bd9Sstevel@tonic-gate break; 1390*7c478bd9Sstevel@tonic-gate } 1391*7c478bd9Sstevel@tonic-gate } else 1392*7c478bd9Sstevel@tonic-gate try.neg_upap = 0; 1393*7c478bd9Sstevel@tonic-gate p += cilen - CILEN_SHORT; 1394*7c478bd9Sstevel@tonic-gate } 1395*7c478bd9Sstevel@tonic-gate } 1396*7c478bd9Sstevel@tonic-gate 1397*7c478bd9Sstevel@tonic-gate /* 1398*7c478bd9Sstevel@tonic-gate * If they can't cope with our link quality protocol, we'll have 1399*7c478bd9Sstevel@tonic-gate * to stop asking for LQR. We haven't got any other protocol. If 1400*7c478bd9Sstevel@tonic-gate * they Nak the reporting period, then the following logic 1401*7c478bd9Sstevel@tonic-gate * applies: 1402*7c478bd9Sstevel@tonic-gate * If he suggests zero and go->neg_fcs is true and 1403*7c478bd9Sstevel@tonic-gate * ao->lqr_period isn't zero, then take his suggestion. If he 1404*7c478bd9Sstevel@tonic-gate * suggests zero otherwise, ignore it. If he suggests a nonzero 1405*7c478bd9Sstevel@tonic-gate * value and wo->lqr_period is zero, then take his suggestion. If 1406*7c478bd9Sstevel@tonic-gate * he suggests a nonzero value otherwise that's less than 1407*7c478bd9Sstevel@tonic-gate * wo->lqr_period, then ignore it. 1408*7c478bd9Sstevel@tonic-gate */ 1409*7c478bd9Sstevel@tonic-gate NAKCILQR(CI_QUALITY, neg_lqr, 1410*7c478bd9Sstevel@tonic-gate if (cishort != PPP_LQR) 1411*7c478bd9Sstevel@tonic-gate try.neg_lqr = 0; 1412*7c478bd9Sstevel@tonic-gate else if (cilong == 0 && go->neg_fcs && wo->lqr_period != 0) 1413*7c478bd9Sstevel@tonic-gate try.lqr_period = cilong; 1414*7c478bd9Sstevel@tonic-gate else if (cilong != 0 && 1415*7c478bd9Sstevel@tonic-gate (wo->lqr_period == 0 || cilong > wo->lqr_period)) 1416*7c478bd9Sstevel@tonic-gate try.lqr_period = cilong; 1417*7c478bd9Sstevel@tonic-gate ); 1418*7c478bd9Sstevel@tonic-gate 1419*7c478bd9Sstevel@tonic-gate /* 1420*7c478bd9Sstevel@tonic-gate * Only implementing CBCP...not the rest of the callback options 1421*7c478bd9Sstevel@tonic-gate */ 1422*7c478bd9Sstevel@tonic-gate NAKCICHAR(CI_CALLBACK, neg_cbcp, 1423*7c478bd9Sstevel@tonic-gate try.neg_cbcp = 0; 1424*7c478bd9Sstevel@tonic-gate ); 1425*7c478bd9Sstevel@tonic-gate 1426*7c478bd9Sstevel@tonic-gate /* 1427*7c478bd9Sstevel@tonic-gate * Check for a looped-back line. 1428*7c478bd9Sstevel@tonic-gate */ 1429*7c478bd9Sstevel@tonic-gate NAKCILONG(CI_MAGICNUMBER, neg_magicnumber, 1430*7c478bd9Sstevel@tonic-gate try.magicnumber = magic(); 1431*7c478bd9Sstevel@tonic-gate looped_back = 1; 1432*7c478bd9Sstevel@tonic-gate ); 1433*7c478bd9Sstevel@tonic-gate 1434*7c478bd9Sstevel@tonic-gate /* 1435*7c478bd9Sstevel@tonic-gate * Peer shouldn't send Nak for protocol compression or 1436*7c478bd9Sstevel@tonic-gate * address/control compression requests; they should send 1437*7c478bd9Sstevel@tonic-gate * a Reject instead. If they send a Nak, treat it as a Reject. 1438*7c478bd9Sstevel@tonic-gate */ 1439*7c478bd9Sstevel@tonic-gate NAKCIVOID(CI_PCOMPRESSION, neg_pcompression); 1440*7c478bd9Sstevel@tonic-gate NAKCIVOID(CI_ACCOMPRESSION, neg_accompression); 1441*7c478bd9Sstevel@tonic-gate 1442*7c478bd9Sstevel@tonic-gate /* 1443*7c478bd9Sstevel@tonic-gate * Remove any FCS types he doesn't like from our (receive-side) 1444*7c478bd9Sstevel@tonic-gate * FCS list. 1445*7c478bd9Sstevel@tonic-gate */ 1446*7c478bd9Sstevel@tonic-gate NAKCICHAR(CI_FCSALTERN, neg_fcs, try.fcs_type = go->fcs_type & cichar;); 1447*7c478bd9Sstevel@tonic-gate 1448*7c478bd9Sstevel@tonic-gate #ifdef MUX_FRAME 1449*7c478bd9Sstevel@tonic-gate /* Nacked MUX option */ 1450*7c478bd9Sstevel@tonic-gate NAKCIVOID(CI_MUXING, pppmux); 1451*7c478bd9Sstevel@tonic-gate #endif 1452*7c478bd9Sstevel@tonic-gate 1453*7c478bd9Sstevel@tonic-gate /* 1454*7c478bd9Sstevel@tonic-gate * Nak of the endpoint discriminator option is not permitted, 1455*7c478bd9Sstevel@tonic-gate * treat it like a reject. 1456*7c478bd9Sstevel@tonic-gate */ 1457*7c478bd9Sstevel@tonic-gate NAKCIENDP(CI_EPDISC, neg_endpoint); 1458*7c478bd9Sstevel@tonic-gate 1459*7c478bd9Sstevel@tonic-gate /* 1460*7c478bd9Sstevel@tonic-gate * Nak for MRRU option - accept their value if it is smaller 1461*7c478bd9Sstevel@tonic-gate * than the one we want. 1462*7c478bd9Sstevel@tonic-gate */ 1463*7c478bd9Sstevel@tonic-gate if (go->neg_mrru) { 1464*7c478bd9Sstevel@tonic-gate NAKCISHORT(CI_MRRU, neg_mrru, 1465*7c478bd9Sstevel@tonic-gate if (cishort <= wo->mrru) 1466*7c478bd9Sstevel@tonic-gate try.mrru = cishort; 1467*7c478bd9Sstevel@tonic-gate ); 1468*7c478bd9Sstevel@tonic-gate } 1469*7c478bd9Sstevel@tonic-gate 1470*7c478bd9Sstevel@tonic-gate /* 1471*7c478bd9Sstevel@tonic-gate * Nak for short sequence numbers shouldn't be sent, treat it 1472*7c478bd9Sstevel@tonic-gate * like a reject. 1473*7c478bd9Sstevel@tonic-gate */ 1474*7c478bd9Sstevel@tonic-gate NAKCIVOID(CI_SSNHF, neg_ssnhf); 1475*7c478bd9Sstevel@tonic-gate 1476*7c478bd9Sstevel@tonic-gate /* 1477*7c478bd9Sstevel@tonic-gate * There may be remaining CIs, if the peer is requesting negotiation 1478*7c478bd9Sstevel@tonic-gate * on an option that we didn't include in our request packet. 1479*7c478bd9Sstevel@tonic-gate * If we see an option that we requested, or one we've already seen 1480*7c478bd9Sstevel@tonic-gate * in this packet, then this packet is bad. 1481*7c478bd9Sstevel@tonic-gate * If we wanted to respond by starting to negotiate on the requested 1482*7c478bd9Sstevel@tonic-gate * option(s), we could, but we don't, because except for the 1483*7c478bd9Sstevel@tonic-gate * authentication type and quality protocol, if we are not negotiating 1484*7c478bd9Sstevel@tonic-gate * an option, it is because we were told not to. 1485*7c478bd9Sstevel@tonic-gate * For the authentication type, the Nak from the peer means 1486*7c478bd9Sstevel@tonic-gate * `let me authenticate myself with you' which is a bit pointless. 1487*7c478bd9Sstevel@tonic-gate * For the quality protocol, the Nak means `ask me to send you quality 1488*7c478bd9Sstevel@tonic-gate * reports', but if we didn't ask for them, we don't want them. 1489*7c478bd9Sstevel@tonic-gate * An option we don't recognize represents the peer asking to 1490*7c478bd9Sstevel@tonic-gate * negotiate some option we don't support, so ignore it. 1491*7c478bd9Sstevel@tonic-gate */ 1492*7c478bd9Sstevel@tonic-gate while (len > CILEN_VOID) { 1493*7c478bd9Sstevel@tonic-gate GETCHAR(citype, p); 1494*7c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); 1495*7c478bd9Sstevel@tonic-gate if (cilen < CILEN_VOID || (len -= cilen) < 0) 1496*7c478bd9Sstevel@tonic-gate goto bad; 1497*7c478bd9Sstevel@tonic-gate next = p + cilen - 2; 1498*7c478bd9Sstevel@tonic-gate 1499*7c478bd9Sstevel@tonic-gate switch (citype) { 1500*7c478bd9Sstevel@tonic-gate case CI_MRU: 1501*7c478bd9Sstevel@tonic-gate if ((go->neg_mru && go->mru != PPP_MRU) 1502*7c478bd9Sstevel@tonic-gate || no.neg_mru || cilen != CILEN_SHORT) 1503*7c478bd9Sstevel@tonic-gate goto bad; 1504*7c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); 1505*7c478bd9Sstevel@tonic-gate if (cishort < PPP_MRU && cishort < absmax_mru) { 1506*7c478bd9Sstevel@tonic-gate try.neg_mru = 1; 1507*7c478bd9Sstevel@tonic-gate try.mru = cishort; 1508*7c478bd9Sstevel@tonic-gate notice("Peer sent unsolicited Nak for MRU less than default."); 1509*7c478bd9Sstevel@tonic-gate } 1510*7c478bd9Sstevel@tonic-gate break; 1511*7c478bd9Sstevel@tonic-gate case CI_ASYNCMAP: 1512*7c478bd9Sstevel@tonic-gate if ((go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF) 1513*7c478bd9Sstevel@tonic-gate || no.neg_asyncmap || cilen != CILEN_LONG) 1514*7c478bd9Sstevel@tonic-gate goto bad; 1515*7c478bd9Sstevel@tonic-gate break; 1516*7c478bd9Sstevel@tonic-gate case CI_AUTHTYPE: 1517*7c478bd9Sstevel@tonic-gate unsolicited_nak_auth = 1; 1518*7c478bd9Sstevel@tonic-gate if (cilen >= CILEN_SHORT) { 1519*7c478bd9Sstevel@tonic-gate GETSHORT(unsolicit_auth_proto, p); 1520*7c478bd9Sstevel@tonic-gate } else { 1521*7c478bd9Sstevel@tonic-gate unsolicit_auth_proto = 0; 1522*7c478bd9Sstevel@tonic-gate } 1523*7c478bd9Sstevel@tonic-gate if (go->neg_chap || no.neg_chap || 1524*7c478bd9Sstevel@tonic-gate go->neg_mschap || no.neg_mschap || 1525*7c478bd9Sstevel@tonic-gate go->neg_mschapv2 || no.neg_mschapv2 || 1526*7c478bd9Sstevel@tonic-gate go->neg_upap || no.neg_upap) 1527*7c478bd9Sstevel@tonic-gate goto bad; 1528*7c478bd9Sstevel@tonic-gate break; 1529*7c478bd9Sstevel@tonic-gate case CI_MAGICNUMBER: 1530*7c478bd9Sstevel@tonic-gate if (go->neg_magicnumber || no.neg_magicnumber || 1531*7c478bd9Sstevel@tonic-gate cilen != CILEN_LONG) 1532*7c478bd9Sstevel@tonic-gate goto bad; 1533*7c478bd9Sstevel@tonic-gate break; 1534*7c478bd9Sstevel@tonic-gate case CI_PCOMPRESSION: 1535*7c478bd9Sstevel@tonic-gate if (go->neg_pcompression || no.neg_pcompression 1536*7c478bd9Sstevel@tonic-gate || cilen != CILEN_VOID) 1537*7c478bd9Sstevel@tonic-gate goto bad; 1538*7c478bd9Sstevel@tonic-gate break; 1539*7c478bd9Sstevel@tonic-gate case CI_ACCOMPRESSION: 1540*7c478bd9Sstevel@tonic-gate if (go->neg_accompression || no.neg_accompression 1541*7c478bd9Sstevel@tonic-gate || cilen != CILEN_VOID) 1542*7c478bd9Sstevel@tonic-gate goto bad; 1543*7c478bd9Sstevel@tonic-gate break; 1544*7c478bd9Sstevel@tonic-gate case CI_QUALITY: 1545*7c478bd9Sstevel@tonic-gate if (go->neg_lqr || no.neg_lqr || cilen != CILEN_LQR) 1546*7c478bd9Sstevel@tonic-gate goto bad; 1547*7c478bd9Sstevel@tonic-gate break; 1548*7c478bd9Sstevel@tonic-gate case CI_MRRU: 1549*7c478bd9Sstevel@tonic-gate if (go->neg_mrru || no.neg_mrru || cilen != CILEN_SHORT) 1550*7c478bd9Sstevel@tonic-gate goto bad; 1551*7c478bd9Sstevel@tonic-gate break; 1552*7c478bd9Sstevel@tonic-gate case CI_SSNHF: 1553*7c478bd9Sstevel@tonic-gate if (go->neg_ssnhf || no.neg_ssnhf || cilen != CILEN_VOID) 1554*7c478bd9Sstevel@tonic-gate goto bad; 1555*7c478bd9Sstevel@tonic-gate try.neg_ssnhf = 1; 1556*7c478bd9Sstevel@tonic-gate break; 1557*7c478bd9Sstevel@tonic-gate case CI_EPDISC: 1558*7c478bd9Sstevel@tonic-gate if (go->neg_endpoint || no.neg_endpoint || cilen < CILEN_CHAR) 1559*7c478bd9Sstevel@tonic-gate goto bad; 1560*7c478bd9Sstevel@tonic-gate break; 1561*7c478bd9Sstevel@tonic-gate case CI_FCSALTERN: 1562*7c478bd9Sstevel@tonic-gate if (go->neg_fcs || no.neg_fcs || cilen < CILEN_CHAR) 1563*7c478bd9Sstevel@tonic-gate goto bad; 1564*7c478bd9Sstevel@tonic-gate break; 1565*7c478bd9Sstevel@tonic-gate #ifdef MUX_FRAME 1566*7c478bd9Sstevel@tonic-gate case CI_MUXING: 1567*7c478bd9Sstevel@tonic-gate if (go->pppmux || no.pppmux || cilen < CILEN_VOID) 1568*7c478bd9Sstevel@tonic-gate goto bad; 1569*7c478bd9Sstevel@tonic-gate break; 1570*7c478bd9Sstevel@tonic-gate #endif 1571*7c478bd9Sstevel@tonic-gate } 1572*7c478bd9Sstevel@tonic-gate p = next; 1573*7c478bd9Sstevel@tonic-gate } 1574*7c478bd9Sstevel@tonic-gate 1575*7c478bd9Sstevel@tonic-gate /* 1576*7c478bd9Sstevel@tonic-gate * OK, the Nak is good. Now we can update state. 1577*7c478bd9Sstevel@tonic-gate * If there are any options left we ignore them. 1578*7c478bd9Sstevel@tonic-gate */ 1579*7c478bd9Sstevel@tonic-gate if (f->state != OPENED) { 1580*7c478bd9Sstevel@tonic-gate /* 1581*7c478bd9Sstevel@tonic-gate * Note: the code once reset try.numloops to zero here if 1582*7c478bd9Sstevel@tonic-gate * looped_back wasn't set. This is wrong because a mixture of 1583*7c478bd9Sstevel@tonic-gate * looped-back and peer data (possible if half-duplex is used) 1584*7c478bd9Sstevel@tonic-gate * will allow the link to come up, and it shouldn't. 1585*7c478bd9Sstevel@tonic-gate */ 1586*7c478bd9Sstevel@tonic-gate if (looped_back) { 1587*7c478bd9Sstevel@tonic-gate if (++try.numloops >= lcp_loopbackfail) { 1588*7c478bd9Sstevel@tonic-gate notice("Serial line is looped back."); 1589*7c478bd9Sstevel@tonic-gate lcp_close(f->unit, "Loopback detected"); 1590*7c478bd9Sstevel@tonic-gate status = EXIT_LOOPBACK; 1591*7c478bd9Sstevel@tonic-gate } 1592*7c478bd9Sstevel@tonic-gate } 1593*7c478bd9Sstevel@tonic-gate *go = try; 1594*7c478bd9Sstevel@tonic-gate } 1595*7c478bd9Sstevel@tonic-gate 1596*7c478bd9Sstevel@tonic-gate return 1; 1597*7c478bd9Sstevel@tonic-gate 1598*7c478bd9Sstevel@tonic-gate bad: 1599*7c478bd9Sstevel@tonic-gate dbglog("lcp_nakci: received bad Nak!"); 1600*7c478bd9Sstevel@tonic-gate return 0; 1601*7c478bd9Sstevel@tonic-gate } 1602*7c478bd9Sstevel@tonic-gate 1603*7c478bd9Sstevel@tonic-gate 1604*7c478bd9Sstevel@tonic-gate /* 1605*7c478bd9Sstevel@tonic-gate * lcp_rejci - Peer has Rejected some of our CIs. 1606*7c478bd9Sstevel@tonic-gate * This should not modify any state if the Reject is bad 1607*7c478bd9Sstevel@tonic-gate * or if LCP is in the OPENED state. 1608*7c478bd9Sstevel@tonic-gate * 1609*7c478bd9Sstevel@tonic-gate * Returns: 1610*7c478bd9Sstevel@tonic-gate * 0 - Reject was bad. 1611*7c478bd9Sstevel@tonic-gate * 1 - Reject was good. 1612*7c478bd9Sstevel@tonic-gate */ 1613*7c478bd9Sstevel@tonic-gate static int 1614*7c478bd9Sstevel@tonic-gate lcp_rejci(f, p, len) 1615*7c478bd9Sstevel@tonic-gate fsm *f; 1616*7c478bd9Sstevel@tonic-gate u_char *p; 1617*7c478bd9Sstevel@tonic-gate int len; 1618*7c478bd9Sstevel@tonic-gate { 1619*7c478bd9Sstevel@tonic-gate lcp_options *go = &lcp_gotoptions[f->unit]; 1620*7c478bd9Sstevel@tonic-gate u_char cichar; 1621*7c478bd9Sstevel@tonic-gate u_short cishort; 1622*7c478bd9Sstevel@tonic-gate u_int32_t cilong; 1623*7c478bd9Sstevel@tonic-gate lcp_options try; /* options to request next time */ 1624*7c478bd9Sstevel@tonic-gate 1625*7c478bd9Sstevel@tonic-gate try = *go; 1626*7c478bd9Sstevel@tonic-gate 1627*7c478bd9Sstevel@tonic-gate /* 1628*7c478bd9Sstevel@tonic-gate * Any Rejected CIs must be in exactly the same order that we sent. 1629*7c478bd9Sstevel@tonic-gate * Check packet length and CI length at each step. 1630*7c478bd9Sstevel@tonic-gate * If we find any deviations, then this packet is bad. 1631*7c478bd9Sstevel@tonic-gate */ 1632*7c478bd9Sstevel@tonic-gate #define REJCIVOID(opt, neg) \ 1633*7c478bd9Sstevel@tonic-gate if (go->neg && \ 1634*7c478bd9Sstevel@tonic-gate len >= CILEN_VOID && \ 1635*7c478bd9Sstevel@tonic-gate p[1] == CILEN_VOID && \ 1636*7c478bd9Sstevel@tonic-gate p[0] == opt) { \ 1637*7c478bd9Sstevel@tonic-gate len -= CILEN_VOID; \ 1638*7c478bd9Sstevel@tonic-gate INCPTR(CILEN_VOID, p); \ 1639*7c478bd9Sstevel@tonic-gate try.neg = 0; \ 1640*7c478bd9Sstevel@tonic-gate } 1641*7c478bd9Sstevel@tonic-gate #define REJCICHAR(opt, neg, val) \ 1642*7c478bd9Sstevel@tonic-gate if (go->neg && \ 1643*7c478bd9Sstevel@tonic-gate len >= CILEN_CHAR && \ 1644*7c478bd9Sstevel@tonic-gate p[1] == CILEN_CHAR && \ 1645*7c478bd9Sstevel@tonic-gate p[0] == opt) { \ 1646*7c478bd9Sstevel@tonic-gate len -= CILEN_CHAR; \ 1647*7c478bd9Sstevel@tonic-gate INCPTR(2, p); \ 1648*7c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); \ 1649*7c478bd9Sstevel@tonic-gate /* Check rejected value. */ \ 1650*7c478bd9Sstevel@tonic-gate if (cichar != val) \ 1651*7c478bd9Sstevel@tonic-gate goto bad; \ 1652*7c478bd9Sstevel@tonic-gate try.neg = 0; \ 1653*7c478bd9Sstevel@tonic-gate } 1654*7c478bd9Sstevel@tonic-gate #define REJCISHORT(opt, neg, val) \ 1655*7c478bd9Sstevel@tonic-gate if (go->neg && \ 1656*7c478bd9Sstevel@tonic-gate len >= CILEN_SHORT && \ 1657*7c478bd9Sstevel@tonic-gate p[1] == CILEN_SHORT && \ 1658*7c478bd9Sstevel@tonic-gate p[0] == opt) { \ 1659*7c478bd9Sstevel@tonic-gate len -= CILEN_SHORT; \ 1660*7c478bd9Sstevel@tonic-gate INCPTR(2, p); \ 1661*7c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \ 1662*7c478bd9Sstevel@tonic-gate /* Check rejected value. */ \ 1663*7c478bd9Sstevel@tonic-gate if (cishort != val) \ 1664*7c478bd9Sstevel@tonic-gate goto bad; \ 1665*7c478bd9Sstevel@tonic-gate try.neg = 0; \ 1666*7c478bd9Sstevel@tonic-gate } 1667*7c478bd9Sstevel@tonic-gate #define REJCIAUTH(opt, neg, val) \ 1668*7c478bd9Sstevel@tonic-gate if (go->neg && \ 1669*7c478bd9Sstevel@tonic-gate len >= CILEN_SHORT && \ 1670*7c478bd9Sstevel@tonic-gate p[1] == CILEN_SHORT && \ 1671*7c478bd9Sstevel@tonic-gate p[0] == opt) { \ 1672*7c478bd9Sstevel@tonic-gate len -= CILEN_SHORT; \ 1673*7c478bd9Sstevel@tonic-gate INCPTR(2, p); \ 1674*7c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \ 1675*7c478bd9Sstevel@tonic-gate /* Check rejected value. */ \ 1676*7c478bd9Sstevel@tonic-gate peer_reject_auth = 1; \ 1677*7c478bd9Sstevel@tonic-gate reject_auth_proto = cishort; \ 1678*7c478bd9Sstevel@tonic-gate if (cishort != val) \ 1679*7c478bd9Sstevel@tonic-gate goto bad; \ 1680*7c478bd9Sstevel@tonic-gate try.neg = 0; \ 1681*7c478bd9Sstevel@tonic-gate } 1682*7c478bd9Sstevel@tonic-gate #define REJCILONG(opt, neg, val) \ 1683*7c478bd9Sstevel@tonic-gate if (go->neg && \ 1684*7c478bd9Sstevel@tonic-gate len >= CILEN_LONG && \ 1685*7c478bd9Sstevel@tonic-gate p[1] == CILEN_LONG && \ 1686*7c478bd9Sstevel@tonic-gate p[0] == opt) { \ 1687*7c478bd9Sstevel@tonic-gate len -= CILEN_LONG; \ 1688*7c478bd9Sstevel@tonic-gate INCPTR(2, p); \ 1689*7c478bd9Sstevel@tonic-gate GETLONG(cilong, p); \ 1690*7c478bd9Sstevel@tonic-gate /* Check rejected value. */ \ 1691*7c478bd9Sstevel@tonic-gate if (cilong != val) \ 1692*7c478bd9Sstevel@tonic-gate goto bad; \ 1693*7c478bd9Sstevel@tonic-gate try.neg = 0; \ 1694*7c478bd9Sstevel@tonic-gate } 1695*7c478bd9Sstevel@tonic-gate #define REJCILQR(opt, neg, val) \ 1696*7c478bd9Sstevel@tonic-gate if (go->neg && \ 1697*7c478bd9Sstevel@tonic-gate len >= CILEN_LQR && \ 1698*7c478bd9Sstevel@tonic-gate p[1] == CILEN_LQR && \ 1699*7c478bd9Sstevel@tonic-gate p[0] == opt) { \ 1700*7c478bd9Sstevel@tonic-gate len -= CILEN_LQR; \ 1701*7c478bd9Sstevel@tonic-gate INCPTR(2, p); \ 1702*7c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \ 1703*7c478bd9Sstevel@tonic-gate GETLONG(cilong, p); \ 1704*7c478bd9Sstevel@tonic-gate /* Check rejected value. */ \ 1705*7c478bd9Sstevel@tonic-gate if (cishort != PPP_LQR || cilong != val) \ 1706*7c478bd9Sstevel@tonic-gate goto bad; \ 1707*7c478bd9Sstevel@tonic-gate try.neg = 0; \ 1708*7c478bd9Sstevel@tonic-gate } 1709*7c478bd9Sstevel@tonic-gate #define REJCICBCP(opt, neg, val) \ 1710*7c478bd9Sstevel@tonic-gate if (go->neg && \ 1711*7c478bd9Sstevel@tonic-gate len >= CILEN_CBCP && \ 1712*7c478bd9Sstevel@tonic-gate p[1] == CILEN_CBCP && \ 1713*7c478bd9Sstevel@tonic-gate p[0] == opt) { \ 1714*7c478bd9Sstevel@tonic-gate len -= CILEN_CBCP; \ 1715*7c478bd9Sstevel@tonic-gate INCPTR(2, p); \ 1716*7c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); \ 1717*7c478bd9Sstevel@tonic-gate /* Check rejected value. */ \ 1718*7c478bd9Sstevel@tonic-gate if (cichar != val) \ 1719*7c478bd9Sstevel@tonic-gate goto bad; \ 1720*7c478bd9Sstevel@tonic-gate try.neg = 0; \ 1721*7c478bd9Sstevel@tonic-gate } 1722*7c478bd9Sstevel@tonic-gate #define REJCIENDP(opt, neg, class, val, vlen) \ 1723*7c478bd9Sstevel@tonic-gate if (go->neg && \ 1724*7c478bd9Sstevel@tonic-gate len >= CILEN_CHAR + vlen && \ 1725*7c478bd9Sstevel@tonic-gate p[0] == opt && \ 1726*7c478bd9Sstevel@tonic-gate p[1] == CILEN_CHAR + vlen) { \ 1727*7c478bd9Sstevel@tonic-gate int i; \ 1728*7c478bd9Sstevel@tonic-gate len -= CILEN_CHAR + vlen; \ 1729*7c478bd9Sstevel@tonic-gate INCPTR(2, p); \ 1730*7c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); \ 1731*7c478bd9Sstevel@tonic-gate if (cichar != class) \ 1732*7c478bd9Sstevel@tonic-gate goto bad; \ 1733*7c478bd9Sstevel@tonic-gate for (i = 0; i < vlen; ++i) { \ 1734*7c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); \ 1735*7c478bd9Sstevel@tonic-gate if (cichar != val[i]) \ 1736*7c478bd9Sstevel@tonic-gate goto bad; \ 1737*7c478bd9Sstevel@tonic-gate } \ 1738*7c478bd9Sstevel@tonic-gate try.neg = 0; \ 1739*7c478bd9Sstevel@tonic-gate } 1740*7c478bd9Sstevel@tonic-gate 1741*7c478bd9Sstevel@tonic-gate /* Received a Configure-Reject, try to send Identification now. */ 1742*7c478bd9Sstevel@tonic-gate if (!noident && sentident < 3) { 1743*7c478bd9Sstevel@tonic-gate LcpSendIdentification(f); 1744*7c478bd9Sstevel@tonic-gate sentident++; 1745*7c478bd9Sstevel@tonic-gate } 1746*7c478bd9Sstevel@tonic-gate 1747*7c478bd9Sstevel@tonic-gate REJCISHORT(CI_MRU, neg_mru, go->mru); 1748*7c478bd9Sstevel@tonic-gate REJCILONG(CI_ASYNCMAP, neg_asyncmap, go->asyncmap); 1749*7c478bd9Sstevel@tonic-gate 1750*7c478bd9Sstevel@tonic-gate /* 1751*7c478bd9Sstevel@tonic-gate * There are broken peers (such as unbundled Solaris PPP) that 1752*7c478bd9Sstevel@tonic-gate * send Configure-Reject for authentication when they really 1753*7c478bd9Sstevel@tonic-gate * intend Configure-Nak. This code works around this problem. 1754*7c478bd9Sstevel@tonic-gate */ 1755*7c478bd9Sstevel@tonic-gate if ((go->neg_chap || go->neg_mschap || go->neg_mschapv2) && 1756*7c478bd9Sstevel@tonic-gate len >= CILEN_CHAP && p[1] == CILEN_CHAP && p[0] == CI_AUTHTYPE) { 1757*7c478bd9Sstevel@tonic-gate len -= CILEN_CHAP; 1758*7c478bd9Sstevel@tonic-gate INCPTR(2, p); 1759*7c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); 1760*7c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); 1761*7c478bd9Sstevel@tonic-gate peer_reject_auth = 1; 1762*7c478bd9Sstevel@tonic-gate reject_auth_proto = cishort; 1763*7c478bd9Sstevel@tonic-gate /* Check rejected value. */ 1764*7c478bd9Sstevel@tonic-gate if (cishort != PPP_CHAP || cichar != go->chap_mdtype) 1765*7c478bd9Sstevel@tonic-gate goto bad; 1766*7c478bd9Sstevel@tonic-gate /* Disable the one that he rejected */ 1767*7c478bd9Sstevel@tonic-gate switch (cichar) { 1768*7c478bd9Sstevel@tonic-gate case CHAP_DIGEST_MD5: 1769*7c478bd9Sstevel@tonic-gate try.neg_chap = 0; 1770*7c478bd9Sstevel@tonic-gate break; 1771*7c478bd9Sstevel@tonic-gate case CHAP_MICROSOFT: 1772*7c478bd9Sstevel@tonic-gate try.neg_mschap = 0; 1773*7c478bd9Sstevel@tonic-gate break; 1774*7c478bd9Sstevel@tonic-gate case CHAP_MICROSOFT_V2: 1775*7c478bd9Sstevel@tonic-gate try.neg_mschapv2 = 0; 1776*7c478bd9Sstevel@tonic-gate break; 1777*7c478bd9Sstevel@tonic-gate } 1778*7c478bd9Sstevel@tonic-gate /* Try another, if we can. */ 1779*7c478bd9Sstevel@tonic-gate if (try.neg_chap) 1780*7c478bd9Sstevel@tonic-gate try.chap_mdtype = CHAP_DIGEST_MD5; 1781*7c478bd9Sstevel@tonic-gate else if (try.neg_mschap) 1782*7c478bd9Sstevel@tonic-gate try.chap_mdtype = CHAP_MICROSOFT; 1783*7c478bd9Sstevel@tonic-gate else 1784*7c478bd9Sstevel@tonic-gate try.chap_mdtype = CHAP_MICROSOFT_V2; 1785*7c478bd9Sstevel@tonic-gate } 1786*7c478bd9Sstevel@tonic-gate 1787*7c478bd9Sstevel@tonic-gate if (!go->neg_chap && !go->neg_mschap && !go->neg_mschapv2) { 1788*7c478bd9Sstevel@tonic-gate REJCIAUTH(CI_AUTHTYPE, neg_upap, PPP_PAP); 1789*7c478bd9Sstevel@tonic-gate } 1790*7c478bd9Sstevel@tonic-gate REJCILQR(CI_QUALITY, neg_lqr, go->lqr_period); 1791*7c478bd9Sstevel@tonic-gate REJCICBCP(CI_CALLBACK, neg_cbcp, CBOP_CBCP); 1792*7c478bd9Sstevel@tonic-gate REJCILONG(CI_MAGICNUMBER, neg_magicnumber, go->magicnumber); 1793*7c478bd9Sstevel@tonic-gate REJCIVOID(CI_PCOMPRESSION, neg_pcompression); 1794*7c478bd9Sstevel@tonic-gate REJCIVOID(CI_ACCOMPRESSION, neg_accompression); 1795*7c478bd9Sstevel@tonic-gate REJCICHAR(CI_FCSALTERN, neg_fcs, go->fcs_type); 1796*7c478bd9Sstevel@tonic-gate #ifdef MUX_FRAME 1797*7c478bd9Sstevel@tonic-gate REJCIVOID(CI_MUXING,pppmux); 1798*7c478bd9Sstevel@tonic-gate #endif 1799*7c478bd9Sstevel@tonic-gate REJCIENDP(CI_EPDISC, neg_endpoint, go->endpoint.class, 1800*7c478bd9Sstevel@tonic-gate go->endpoint.value, go->endpoint.length); 1801*7c478bd9Sstevel@tonic-gate REJCISHORT(CI_MRRU, neg_mrru, go->mrru); 1802*7c478bd9Sstevel@tonic-gate REJCIVOID(CI_SSNHF, neg_ssnhf); 1803*7c478bd9Sstevel@tonic-gate 1804*7c478bd9Sstevel@tonic-gate /* 1805*7c478bd9Sstevel@tonic-gate * If there are any remaining CIs, then this packet is bad. 1806*7c478bd9Sstevel@tonic-gate */ 1807*7c478bd9Sstevel@tonic-gate if (len != 0) 1808*7c478bd9Sstevel@tonic-gate goto bad; 1809*7c478bd9Sstevel@tonic-gate /* 1810*7c478bd9Sstevel@tonic-gate * Now we can update state. 1811*7c478bd9Sstevel@tonic-gate */ 1812*7c478bd9Sstevel@tonic-gate if (f->state != OPENED) 1813*7c478bd9Sstevel@tonic-gate *go = try; 1814*7c478bd9Sstevel@tonic-gate return 1; 1815*7c478bd9Sstevel@tonic-gate 1816*7c478bd9Sstevel@tonic-gate bad: 1817*7c478bd9Sstevel@tonic-gate dbglog("lcp_rejci: received bad Reject!"); 1818*7c478bd9Sstevel@tonic-gate return 0; 1819*7c478bd9Sstevel@tonic-gate } 1820*7c478bd9Sstevel@tonic-gate 1821*7c478bd9Sstevel@tonic-gate 1822*7c478bd9Sstevel@tonic-gate /* 1823*7c478bd9Sstevel@tonic-gate * lcp_reqci - Check the peer's requested CIs and send appropriate response. 1824*7c478bd9Sstevel@tonic-gate * 1825*7c478bd9Sstevel@tonic-gate * Returns: CODE_CONFACK, CODE_CONFNAK or CODE_CONFREJ and input 1826*7c478bd9Sstevel@tonic-gate * packet modified appropriately. If reject_if_disagree is non-zero, 1827*7c478bd9Sstevel@tonic-gate * doesn't return CODE_CONFNAK; returns CODE_CONFREJ if it can't 1828*7c478bd9Sstevel@tonic-gate * return CODE_CONFACK. 1829*7c478bd9Sstevel@tonic-gate */ 1830*7c478bd9Sstevel@tonic-gate static int 1831*7c478bd9Sstevel@tonic-gate lcp_reqci(f, p, lenp, dont_nak) 1832*7c478bd9Sstevel@tonic-gate fsm *f; 1833*7c478bd9Sstevel@tonic-gate u_char *p; /* Requested CIs */ 1834*7c478bd9Sstevel@tonic-gate int *lenp; /* Length of requested CIs */ 1835*7c478bd9Sstevel@tonic-gate int dont_nak; 1836*7c478bd9Sstevel@tonic-gate { 1837*7c478bd9Sstevel@tonic-gate lcp_options *wo = &lcp_wantoptions[f->unit]; 1838*7c478bd9Sstevel@tonic-gate lcp_options *go = &lcp_gotoptions[f->unit]; 1839*7c478bd9Sstevel@tonic-gate lcp_options *ho = &lcp_hisoptions[f->unit]; 1840*7c478bd9Sstevel@tonic-gate lcp_options *ao = &lcp_allowoptions[f->unit]; 1841*7c478bd9Sstevel@tonic-gate int cilen, citype, cichar; /* Parsed len, type, char value */ 1842*7c478bd9Sstevel@tonic-gate u_short cishort; /* Parsed short value */ 1843*7c478bd9Sstevel@tonic-gate u_int32_t cilong; /* Parse long value */ 1844*7c478bd9Sstevel@tonic-gate int ret, newret; 1845*7c478bd9Sstevel@tonic-gate u_char *p0, *nakp, *rejp, *prev; 1846*7c478bd9Sstevel@tonic-gate int len; 1847*7c478bd9Sstevel@tonic-gate 1848*7c478bd9Sstevel@tonic-gate /* 1849*7c478bd9Sstevel@tonic-gate * Loop through options once to find out if peer is offering 1850*7c478bd9Sstevel@tonic-gate * Multilink, and repair values as needed. 1851*7c478bd9Sstevel@tonic-gate */ 1852*7c478bd9Sstevel@tonic-gate ao->mru = ao->mrru; 1853*7c478bd9Sstevel@tonic-gate p0 = p; 1854*7c478bd9Sstevel@tonic-gate for (len = *lenp; len > 0; len -= cilen, p = prev + cilen) { 1855*7c478bd9Sstevel@tonic-gate if (len < 2 || p[1] > len) { 1856*7c478bd9Sstevel@tonic-gate /* 1857*7c478bd9Sstevel@tonic-gate * RFC 1661 page 40 -- if the option extends beyond the 1858*7c478bd9Sstevel@tonic-gate * packet, then discard the entire packet. 1859*7c478bd9Sstevel@tonic-gate */ 1860*7c478bd9Sstevel@tonic-gate dbglog("discarding LCP Configure-Request due to truncated option"); 1861*7c478bd9Sstevel@tonic-gate return (0); 1862*7c478bd9Sstevel@tonic-gate } 1863*7c478bd9Sstevel@tonic-gate prev = p; 1864*7c478bd9Sstevel@tonic-gate GETCHAR(citype, p); 1865*7c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); 1866*7c478bd9Sstevel@tonic-gate if (citype == CI_MRRU) { 1867*7c478bd9Sstevel@tonic-gate if (ao->mrru != 0) { 1868*7c478bd9Sstevel@tonic-gate if (ao->mrru+6 > PPP_MTU) 1869*7c478bd9Sstevel@tonic-gate ao->mru = PPP_MTU; 1870*7c478bd9Sstevel@tonic-gate else 1871*7c478bd9Sstevel@tonic-gate ao->mru = ao->mrru + 6; 1872*7c478bd9Sstevel@tonic-gate } 1873*7c478bd9Sstevel@tonic-gate } 1874*7c478bd9Sstevel@tonic-gate if (cilen < 2) 1875*7c478bd9Sstevel@tonic-gate cilen = 2; 1876*7c478bd9Sstevel@tonic-gate } 1877*7c478bd9Sstevel@tonic-gate if (ao->mru > absmax_mtu) 1878*7c478bd9Sstevel@tonic-gate ao->mru = absmax_mtu; 1879*7c478bd9Sstevel@tonic-gate 1880*7c478bd9Sstevel@tonic-gate ret = CODE_CONFACK; 1881*7c478bd9Sstevel@tonic-gate rejp = p = p0; 1882*7c478bd9Sstevel@tonic-gate nakp = nak_buffer; 1883*7c478bd9Sstevel@tonic-gate 1884*7c478bd9Sstevel@tonic-gate /* 1885*7c478bd9Sstevel@tonic-gate * Reset all his options. 1886*7c478bd9Sstevel@tonic-gate */ 1887*7c478bd9Sstevel@tonic-gate BZERO(ho, sizeof(*ho)); 1888*7c478bd9Sstevel@tonic-gate 1889*7c478bd9Sstevel@tonic-gate /* 1890*7c478bd9Sstevel@tonic-gate * Process all his options. 1891*7c478bd9Sstevel@tonic-gate */ 1892*7c478bd9Sstevel@tonic-gate for (len = *lenp; len > 0; len -= cilen, p = prev + cilen) { 1893*7c478bd9Sstevel@tonic-gate newret = CODE_CONFACK; /* Assume success */ 1894*7c478bd9Sstevel@tonic-gate 1895*7c478bd9Sstevel@tonic-gate prev = p; 1896*7c478bd9Sstevel@tonic-gate GETCHAR(citype, p); 1897*7c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); 1898*7c478bd9Sstevel@tonic-gate 1899*7c478bd9Sstevel@tonic-gate switch (citype) { /* Check CI type */ 1900*7c478bd9Sstevel@tonic-gate case CI_MRU: 1901*7c478bd9Sstevel@tonic-gate if (!ao->neg_mru) { 1902*7c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 1903*7c478bd9Sstevel@tonic-gate break; 1904*7c478bd9Sstevel@tonic-gate } 1905*7c478bd9Sstevel@tonic-gate 1906*7c478bd9Sstevel@tonic-gate if (cilen != CILEN_SHORT) { /* Check CI length */ 1907*7c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 1908*7c478bd9Sstevel@tonic-gate cishort = ao->mru; 1909*7c478bd9Sstevel@tonic-gate } else { 1910*7c478bd9Sstevel@tonic-gate /* extract the MRU from the option */ 1911*7c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); 1912*7c478bd9Sstevel@tonic-gate 1913*7c478bd9Sstevel@tonic-gate /* 1914*7c478bd9Sstevel@tonic-gate * If the offered MRU is less than our desired MTU, we 1915*7c478bd9Sstevel@tonic-gate * should nak. This is especially helpful if we're 1916*7c478bd9Sstevel@tonic-gate * doing demand-dial, since those queued up packets 1917*7c478bd9Sstevel@tonic-gate * might be discarded otherwise. 1918*7c478bd9Sstevel@tonic-gate */ 1919*7c478bd9Sstevel@tonic-gate if (cishort < ao->mru) { 1920*7c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 1921*7c478bd9Sstevel@tonic-gate cishort = ao->mru; 1922*7c478bd9Sstevel@tonic-gate } 1923*7c478bd9Sstevel@tonic-gate } 1924*7c478bd9Sstevel@tonic-gate 1925*7c478bd9Sstevel@tonic-gate /* 1926*7c478bd9Sstevel@tonic-gate * If we're going to send a nak with something less than 1927*7c478bd9Sstevel@tonic-gate * or equal to the default PPP MTU, then just reject instead. 1928*7c478bd9Sstevel@tonic-gate */ 1929*7c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK && cishort <= PPP_MTU) 1930*7c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 1931*7c478bd9Sstevel@tonic-gate 1932*7c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK) { 1933*7c478bd9Sstevel@tonic-gate PUTCHAR(CI_MRU, nakp); 1934*7c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_SHORT, nakp); 1935*7c478bd9Sstevel@tonic-gate PUTSHORT(cishort, nakp); /* Give him a hint */ 1936*7c478bd9Sstevel@tonic-gate } 1937*7c478bd9Sstevel@tonic-gate 1938*7c478bd9Sstevel@tonic-gate ho->neg_mru = 1; /* Remember he sent MRU */ 1939*7c478bd9Sstevel@tonic-gate ho->mru = cishort; /* And remember value */ 1940*7c478bd9Sstevel@tonic-gate break; 1941*7c478bd9Sstevel@tonic-gate 1942*7c478bd9Sstevel@tonic-gate case CI_ASYNCMAP: 1943*7c478bd9Sstevel@tonic-gate if (!ao->neg_asyncmap) { 1944*7c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 1945*7c478bd9Sstevel@tonic-gate break; 1946*7c478bd9Sstevel@tonic-gate } 1947*7c478bd9Sstevel@tonic-gate 1948*7c478bd9Sstevel@tonic-gate if (cilen != CILEN_LONG) { 1949*7c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 1950*7c478bd9Sstevel@tonic-gate cilong = 0; 1951*7c478bd9Sstevel@tonic-gate } else { 1952*7c478bd9Sstevel@tonic-gate GETLONG(cilong, p); 1953*7c478bd9Sstevel@tonic-gate 1954*7c478bd9Sstevel@tonic-gate /* 1955*7c478bd9Sstevel@tonic-gate * Asyncmap must have set at least the bits 1956*7c478bd9Sstevel@tonic-gate * which are set in lcp_allowoptions[unit].asyncmap. 1957*7c478bd9Sstevel@tonic-gate */ 1958*7c478bd9Sstevel@tonic-gate if ((ao->asyncmap & ~cilong) != 0) 1959*7c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 1960*7c478bd9Sstevel@tonic-gate } 1961*7c478bd9Sstevel@tonic-gate 1962*7c478bd9Sstevel@tonic-gate /* 1963*7c478bd9Sstevel@tonic-gate * Workaround for common broken Microsoft software -- if 1964*7c478bd9Sstevel@tonic-gate * the peer is sending us a nonzero ACCM, then he *needs* 1965*7c478bd9Sstevel@tonic-gate * us to send the same to him. Adjust our Configure- 1966*7c478bd9Sstevel@tonic-gate * Request message and restart LCP. 1967*7c478bd9Sstevel@tonic-gate */ 1968*7c478bd9Sstevel@tonic-gate if (do_msft_workaround && (cilong & ~wo->asyncmap)) { 1969*7c478bd9Sstevel@tonic-gate dbglog("adjusted requested asyncmap from %X to %X", 1970*7c478bd9Sstevel@tonic-gate wo->asyncmap, wo->asyncmap | cilong); 1971*7c478bd9Sstevel@tonic-gate do_msft_workaround = 0; 1972*7c478bd9Sstevel@tonic-gate wo->neg_asyncmap = 1; 1973*7c478bd9Sstevel@tonic-gate wo->asyncmap |= cilong; 1974*7c478bd9Sstevel@tonic-gate f->flags &= ~OPT_SILENT; 1975*7c478bd9Sstevel@tonic-gate info("possibly broken peer detected; restarting LCP"); 1976*7c478bd9Sstevel@tonic-gate fsm_lowerdown(f); 1977*7c478bd9Sstevel@tonic-gate fsm_lowerup(f); 1978*7c478bd9Sstevel@tonic-gate return (0); 1979*7c478bd9Sstevel@tonic-gate } 1980*7c478bd9Sstevel@tonic-gate 1981*7c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK) { 1982*7c478bd9Sstevel@tonic-gate PUTCHAR(CI_ASYNCMAP, nakp); 1983*7c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_LONG, nakp); 1984*7c478bd9Sstevel@tonic-gate PUTLONG(ao->asyncmap | cilong, nakp); 1985*7c478bd9Sstevel@tonic-gate } 1986*7c478bd9Sstevel@tonic-gate ho->neg_asyncmap = 1; 1987*7c478bd9Sstevel@tonic-gate ho->asyncmap = cilong; 1988*7c478bd9Sstevel@tonic-gate break; 1989*7c478bd9Sstevel@tonic-gate 1990*7c478bd9Sstevel@tonic-gate case CI_AUTHTYPE: 1991*7c478bd9Sstevel@tonic-gate if (!(ao->neg_upap || ao->neg_chap || ao->neg_mschap || 1992*7c478bd9Sstevel@tonic-gate ao->neg_mschapv2)) { 1993*7c478bd9Sstevel@tonic-gate rejected_peers_auth = 1; 1994*7c478bd9Sstevel@tonic-gate if (cilen >= CILEN_SHORT) { 1995*7c478bd9Sstevel@tonic-gate GETSHORT(rejected_auth_proto, p); 1996*7c478bd9Sstevel@tonic-gate } else { 1997*7c478bd9Sstevel@tonic-gate rejected_auth_proto = 0; 1998*7c478bd9Sstevel@tonic-gate } 1999*7c478bd9Sstevel@tonic-gate /* 2000*7c478bd9Sstevel@tonic-gate * Reject the option if we're not willing to authenticate. 2001*7c478bd9Sstevel@tonic-gate */ 2002*7c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 2003*7c478bd9Sstevel@tonic-gate break; 2004*7c478bd9Sstevel@tonic-gate } 2005*7c478bd9Sstevel@tonic-gate rejected_peers_auth = 0; 2006*7c478bd9Sstevel@tonic-gate naked_peers_auth = 0; 2007*7c478bd9Sstevel@tonic-gate 2008*7c478bd9Sstevel@tonic-gate if (cilen >= CILEN_SHORT) { 2009*7c478bd9Sstevel@tonic-gate /* Extract the authentication protocol from the option */ 2010*7c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); 2011*7c478bd9Sstevel@tonic-gate 2012*7c478bd9Sstevel@tonic-gate if (ho->neg_upap || ho->neg_chap || ho->neg_mschap || 2013*7c478bd9Sstevel@tonic-gate ho->neg_mschapv2) { 2014*7c478bd9Sstevel@tonic-gate dbglog("Rejecting extra authentication protocol option"); 2015*7c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 2016*7c478bd9Sstevel@tonic-gate break; 2017*7c478bd9Sstevel@tonic-gate } 2018*7c478bd9Sstevel@tonic-gate 2019*7c478bd9Sstevel@tonic-gate /* 2020*7c478bd9Sstevel@tonic-gate * Authtype must be PAP or CHAP. 2021*7c478bd9Sstevel@tonic-gate * 2022*7c478bd9Sstevel@tonic-gate * Note: if both ao->neg_upap and ao->neg_*chap* are 2023*7c478bd9Sstevel@tonic-gate * set, and the peer sends a Configure-Request with 2024*7c478bd9Sstevel@tonic-gate * two authenticate-protocol requests, one for CHAP 2025*7c478bd9Sstevel@tonic-gate * and one for UPAP, then we will reject the second 2026*7c478bd9Sstevel@tonic-gate * request. Whether we end up doing CHAP or UPAP 2027*7c478bd9Sstevel@tonic-gate * depends then on the ordering of the CIs in the 2028*7c478bd9Sstevel@tonic-gate * peer's Configure-Request. 2029*7c478bd9Sstevel@tonic-gate * 2030*7c478bd9Sstevel@tonic-gate * We're supposed to list all of the protocols we can 2031*7c478bd9Sstevel@tonic-gate * possibly use in the returned Configure-Nak. This 2032*7c478bd9Sstevel@tonic-gate * part of RFC 1661 (section 5.3) is in conflict with 2033*7c478bd9Sstevel@tonic-gate * the section that says the options shouldn't be 2034*7c478bd9Sstevel@tonic-gate * reordered, so it's often ignored. 2035*7c478bd9Sstevel@tonic-gate */ 2036*7c478bd9Sstevel@tonic-gate 2037*7c478bd9Sstevel@tonic-gate if (cishort == PPP_PAP) { 2038*7c478bd9Sstevel@tonic-gate if (ao->neg_upap) { 2039*7c478bd9Sstevel@tonic-gate if (cilen != CILEN_SHORT) 2040*7c478bd9Sstevel@tonic-gate goto try_pap_anyway; 2041*7c478bd9Sstevel@tonic-gate ho->neg_upap = 1; 2042*7c478bd9Sstevel@tonic-gate break; 2043*7c478bd9Sstevel@tonic-gate } 2044*7c478bd9Sstevel@tonic-gate } else if (cishort == PPP_CHAP) { 2045*7c478bd9Sstevel@tonic-gate /* Test >= here to allow for broken peers. */ 2046*7c478bd9Sstevel@tonic-gate if (cilen >= CILEN_CHAP && 2047*7c478bd9Sstevel@tonic-gate (ao->neg_chap || ao->neg_mschap || ao->neg_mschapv2)) { 2048*7c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); 2049*7c478bd9Sstevel@tonic-gate if (cichar == CHAP_DIGEST_MD5 && ao->neg_chap) 2050*7c478bd9Sstevel@tonic-gate ho->neg_chap = 1; 2051*7c478bd9Sstevel@tonic-gate else if (cichar == CHAP_MICROSOFT && ao->neg_mschap) 2052*7c478bd9Sstevel@tonic-gate ho->neg_mschap = 1; 2053*7c478bd9Sstevel@tonic-gate else if (cichar == CHAP_MICROSOFT_V2 && 2054*7c478bd9Sstevel@tonic-gate ao->neg_mschapv2) 2055*7c478bd9Sstevel@tonic-gate ho->neg_mschap = 1; 2056*7c478bd9Sstevel@tonic-gate if (ho->neg_chap || ho->neg_mschap || 2057*7c478bd9Sstevel@tonic-gate ho->neg_mschapv2) { 2058*7c478bd9Sstevel@tonic-gate ho->chap_mdtype = cichar; /* save md type */ 2059*7c478bd9Sstevel@tonic-gate break; 2060*7c478bd9Sstevel@tonic-gate } 2061*7c478bd9Sstevel@tonic-gate } 2062*7c478bd9Sstevel@tonic-gate } 2063*7c478bd9Sstevel@tonic-gate } 2064*7c478bd9Sstevel@tonic-gate 2065*7c478bd9Sstevel@tonic-gate /* 2066*7c478bd9Sstevel@tonic-gate * We don't recognize the protocol they're asking for. 2067*7c478bd9Sstevel@tonic-gate * Nak it with something we're willing to do. 2068*7c478bd9Sstevel@tonic-gate * (At this point we know ao->neg_upap || ao->neg_chap.) 2069*7c478bd9Sstevel@tonic-gate */ 2070*7c478bd9Sstevel@tonic-gate PUTCHAR(CI_AUTHTYPE, nakp); 2071*7c478bd9Sstevel@tonic-gate if (ao->neg_chap || ao->neg_mschap || ao->neg_mschapv2) { 2072*7c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_CHAP, nakp); 2073*7c478bd9Sstevel@tonic-gate PUTSHORT(PPP_CHAP, nakp); 2074*7c478bd9Sstevel@tonic-gate PUTCHAR(ao->chap_mdtype, nakp); 2075*7c478bd9Sstevel@tonic-gate naked_auth_proto = PPP_CHAP; 2076*7c478bd9Sstevel@tonic-gate } else { 2077*7c478bd9Sstevel@tonic-gate try_pap_anyway: 2078*7c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_SHORT, nakp); 2079*7c478bd9Sstevel@tonic-gate PUTSHORT(PPP_PAP, nakp); 2080*7c478bd9Sstevel@tonic-gate naked_auth_proto = PPP_PAP; 2081*7c478bd9Sstevel@tonic-gate } 2082*7c478bd9Sstevel@tonic-gate naked_peers_auth = 1; 2083*7c478bd9Sstevel@tonic-gate naked_auth_orig = cishort; 2084*7c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 2085*7c478bd9Sstevel@tonic-gate break; 2086*7c478bd9Sstevel@tonic-gate 2087*7c478bd9Sstevel@tonic-gate case CI_QUALITY: 2088*7c478bd9Sstevel@tonic-gate if (!ao->neg_lqr) { 2089*7c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 2090*7c478bd9Sstevel@tonic-gate break; 2091*7c478bd9Sstevel@tonic-gate } 2092*7c478bd9Sstevel@tonic-gate 2093*7c478bd9Sstevel@tonic-gate if (cilen != CILEN_LQR) { 2094*7c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 2095*7c478bd9Sstevel@tonic-gate cilong = ao->lqr_period; 2096*7c478bd9Sstevel@tonic-gate } else { 2097*7c478bd9Sstevel@tonic-gate 2098*7c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); 2099*7c478bd9Sstevel@tonic-gate GETLONG(cilong, p); 2100*7c478bd9Sstevel@tonic-gate 2101*7c478bd9Sstevel@tonic-gate /* Check the LQM protocol */ 2102*7c478bd9Sstevel@tonic-gate if (cishort != PPP_LQR) { 2103*7c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 2104*7c478bd9Sstevel@tonic-gate } 2105*7c478bd9Sstevel@tonic-gate 2106*7c478bd9Sstevel@tonic-gate /* Check the reporting period; we can't both send zero */ 2107*7c478bd9Sstevel@tonic-gate if ((cilong == 0 && go->lqr_period == 0) || 2108*7c478bd9Sstevel@tonic-gate cilong < ao->lqr_period) { 2109*7c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 2110*7c478bd9Sstevel@tonic-gate if ((cilong = ao->lqr_period) == 0) 2111*7c478bd9Sstevel@tonic-gate cilong = 500; 2112*7c478bd9Sstevel@tonic-gate } 2113*7c478bd9Sstevel@tonic-gate } 2114*7c478bd9Sstevel@tonic-gate 2115*7c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK) { 2116*7c478bd9Sstevel@tonic-gate PUTCHAR(CI_QUALITY, nakp); 2117*7c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_LQR, nakp); 2118*7c478bd9Sstevel@tonic-gate PUTSHORT(PPP_LQR, nakp); 2119*7c478bd9Sstevel@tonic-gate PUTLONG(cilong, nakp); 2120*7c478bd9Sstevel@tonic-gate } 2121*7c478bd9Sstevel@tonic-gate 2122*7c478bd9Sstevel@tonic-gate ho->neg_lqr = 1; 2123*7c478bd9Sstevel@tonic-gate ho->lqr_period = cilong; 2124*7c478bd9Sstevel@tonic-gate break; 2125*7c478bd9Sstevel@tonic-gate 2126*7c478bd9Sstevel@tonic-gate case CI_MAGICNUMBER: 2127*7c478bd9Sstevel@tonic-gate if (!(ao->neg_magicnumber || go->neg_magicnumber)) { 2128*7c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 2129*7c478bd9Sstevel@tonic-gate break; 2130*7c478bd9Sstevel@tonic-gate } 2131*7c478bd9Sstevel@tonic-gate 2132*7c478bd9Sstevel@tonic-gate ho->neg_magicnumber = 1; 2133*7c478bd9Sstevel@tonic-gate if (cilen < CILEN_LONG) { 2134*7c478bd9Sstevel@tonic-gate /* 2135*7c478bd9Sstevel@tonic-gate * If we send Magic-Number, then we must not reject it 2136*7c478bd9Sstevel@tonic-gate * when the peer sends it to us, even if his version 2137*7c478bd9Sstevel@tonic-gate * looks odd to us. Ack if the cilen is wrong in this 2138*7c478bd9Sstevel@tonic-gate * case. If we're not sending Magic-Number, then we don't 2139*7c478bd9Sstevel@tonic-gate * much care what his value is anyway. 2140*7c478bd9Sstevel@tonic-gate */ 2141*7c478bd9Sstevel@tonic-gate break; 2142*7c478bd9Sstevel@tonic-gate } 2143*7c478bd9Sstevel@tonic-gate 2144*7c478bd9Sstevel@tonic-gate GETLONG(cilong, p); 2145*7c478bd9Sstevel@tonic-gate ho->magicnumber = cilong; 2146*7c478bd9Sstevel@tonic-gate if (cilen > CILEN_LONG) 2147*7c478bd9Sstevel@tonic-gate break; 2148*7c478bd9Sstevel@tonic-gate 2149*7c478bd9Sstevel@tonic-gate /* 2150*7c478bd9Sstevel@tonic-gate * He must have a different magic number. Make sure we 2151*7c478bd9Sstevel@tonic-gate * give him a good one to use. 2152*7c478bd9Sstevel@tonic-gate */ 2153*7c478bd9Sstevel@tonic-gate while (go->neg_magicnumber && cilong == go->magicnumber) { 2154*7c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 2155*7c478bd9Sstevel@tonic-gate cilong = magic(); 2156*7c478bd9Sstevel@tonic-gate } 2157*7c478bd9Sstevel@tonic-gate 2158*7c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK) { 2159*7c478bd9Sstevel@tonic-gate PUTCHAR(CI_MAGICNUMBER, nakp); 2160*7c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_LONG, nakp); 2161*7c478bd9Sstevel@tonic-gate PUTLONG(cilong, nakp); 2162*7c478bd9Sstevel@tonic-gate /* 2163*7c478bd9Sstevel@tonic-gate * We don't need to bump the numloops counter here 2164*7c478bd9Sstevel@tonic-gate * since it's already done upon reception of a nak. 2165*7c478bd9Sstevel@tonic-gate */ 2166*7c478bd9Sstevel@tonic-gate } 2167*7c478bd9Sstevel@tonic-gate break; 2168*7c478bd9Sstevel@tonic-gate 2169*7c478bd9Sstevel@tonic-gate case CI_PCOMPRESSION: 2170*7c478bd9Sstevel@tonic-gate if (!ao->neg_pcompression) { 2171*7c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 2172*7c478bd9Sstevel@tonic-gate break; 2173*7c478bd9Sstevel@tonic-gate } 2174*7c478bd9Sstevel@tonic-gate if (cilen != CILEN_VOID) { 2175*7c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 2176*7c478bd9Sstevel@tonic-gate PUTCHAR(CI_PCOMPRESSION, nakp); 2177*7c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_VOID, nakp); 2178*7c478bd9Sstevel@tonic-gate } 2179*7c478bd9Sstevel@tonic-gate ho->neg_pcompression = 1; 2180*7c478bd9Sstevel@tonic-gate break; 2181*7c478bd9Sstevel@tonic-gate 2182*7c478bd9Sstevel@tonic-gate case CI_ACCOMPRESSION: 2183*7c478bd9Sstevel@tonic-gate if (!ao->neg_accompression) { 2184*7c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 2185*7c478bd9Sstevel@tonic-gate break; 2186*7c478bd9Sstevel@tonic-gate } 2187*7c478bd9Sstevel@tonic-gate if (cilen != CILEN_VOID) { 2188*7c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 2189*7c478bd9Sstevel@tonic-gate PUTCHAR(CI_ACCOMPRESSION, nakp); 2190*7c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_VOID, nakp); 2191*7c478bd9Sstevel@tonic-gate } 2192*7c478bd9Sstevel@tonic-gate ho->neg_accompression = 1; 2193*7c478bd9Sstevel@tonic-gate break; 2194*7c478bd9Sstevel@tonic-gate 2195*7c478bd9Sstevel@tonic-gate case CI_FCSALTERN: 2196*7c478bd9Sstevel@tonic-gate if (!ao->neg_fcs) { 2197*7c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 2198*7c478bd9Sstevel@tonic-gate break; 2199*7c478bd9Sstevel@tonic-gate } 2200*7c478bd9Sstevel@tonic-gate 2201*7c478bd9Sstevel@tonic-gate if (cilen != CILEN_CHAR) { 2202*7c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 2203*7c478bd9Sstevel@tonic-gate cichar = ao->fcs_type; 2204*7c478bd9Sstevel@tonic-gate } else { 2205*7c478bd9Sstevel@tonic-gate 2206*7c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); 2207*7c478bd9Sstevel@tonic-gate /* If he has bits we don't like, tell him to stop. */ 2208*7c478bd9Sstevel@tonic-gate if (cichar & ~ao->fcs_type) { 2209*7c478bd9Sstevel@tonic-gate if ((cichar &= ao->fcs_type) == 0) { 2210*7c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 2211*7c478bd9Sstevel@tonic-gate break; 2212*7c478bd9Sstevel@tonic-gate } 2213*7c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 2214*7c478bd9Sstevel@tonic-gate } 2215*7c478bd9Sstevel@tonic-gate } 2216*7c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK) { 2217*7c478bd9Sstevel@tonic-gate PUTCHAR(CI_FCSALTERN, nakp); 2218*7c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_CHAR, nakp); 2219*7c478bd9Sstevel@tonic-gate PUTCHAR(cichar, nakp); 2220*7c478bd9Sstevel@tonic-gate } 2221*7c478bd9Sstevel@tonic-gate ho->neg_fcs = 1; 2222*7c478bd9Sstevel@tonic-gate ho->fcs_type = cichar; 2223*7c478bd9Sstevel@tonic-gate break; 2224*7c478bd9Sstevel@tonic-gate 2225*7c478bd9Sstevel@tonic-gate case CI_MRRU: 2226*7c478bd9Sstevel@tonic-gate if (!ao->neg_mrru || !multilink) { 2227*7c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 2228*7c478bd9Sstevel@tonic-gate break; 2229*7c478bd9Sstevel@tonic-gate } 2230*7c478bd9Sstevel@tonic-gate if (cilen != CILEN_SHORT) { 2231*7c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 2232*7c478bd9Sstevel@tonic-gate cishort = ao->mrru; 2233*7c478bd9Sstevel@tonic-gate } else { 2234*7c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); 2235*7c478bd9Sstevel@tonic-gate if (cishort < ao->mrru) { 2236*7c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 2237*7c478bd9Sstevel@tonic-gate cishort = ao->mrru; 2238*7c478bd9Sstevel@tonic-gate } 2239*7c478bd9Sstevel@tonic-gate } 2240*7c478bd9Sstevel@tonic-gate 2241*7c478bd9Sstevel@tonic-gate if (cishort < PPP_MINMTU) { 2242*7c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 2243*7c478bd9Sstevel@tonic-gate cishort = PPP_MINMTU; 2244*7c478bd9Sstevel@tonic-gate } 2245*7c478bd9Sstevel@tonic-gate 2246*7c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK) { 2247*7c478bd9Sstevel@tonic-gate PUTCHAR(CI_MRRU, nakp); 2248*7c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_SHORT, nakp); 2249*7c478bd9Sstevel@tonic-gate PUTSHORT(cishort, nakp); 2250*7c478bd9Sstevel@tonic-gate } 2251*7c478bd9Sstevel@tonic-gate 2252*7c478bd9Sstevel@tonic-gate ho->neg_mrru = 1; 2253*7c478bd9Sstevel@tonic-gate ho->mrru = cishort; 2254*7c478bd9Sstevel@tonic-gate break; 2255*7c478bd9Sstevel@tonic-gate 2256*7c478bd9Sstevel@tonic-gate case CI_SSNHF: 2257*7c478bd9Sstevel@tonic-gate if (!ao->neg_ssnhf || !multilink) { 2258*7c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 2259*7c478bd9Sstevel@tonic-gate break; 2260*7c478bd9Sstevel@tonic-gate } 2261*7c478bd9Sstevel@tonic-gate if (cilen != CILEN_VOID) { 2262*7c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 2263*7c478bd9Sstevel@tonic-gate PUTCHAR(CI_SSNHF, nakp); 2264*7c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_VOID, nakp); 2265*7c478bd9Sstevel@tonic-gate } 2266*7c478bd9Sstevel@tonic-gate ho->neg_ssnhf = 1; 2267*7c478bd9Sstevel@tonic-gate break; 2268*7c478bd9Sstevel@tonic-gate 2269*7c478bd9Sstevel@tonic-gate case CI_EPDISC: 2270*7c478bd9Sstevel@tonic-gate if (!ao->neg_endpoint) { 2271*7c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 2272*7c478bd9Sstevel@tonic-gate break; 2273*7c478bd9Sstevel@tonic-gate } 2274*7c478bd9Sstevel@tonic-gate if (cilen < CILEN_CHAR || cilen > CILEN_CHAR + MAX_ENDP_LEN) { 2275*7c478bd9Sstevel@tonic-gate int i; 2276*7c478bd9Sstevel@tonic-gate 2277*7c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 2278*7c478bd9Sstevel@tonic-gate PUTCHAR(CI_EPDISC, nakp); 2279*7c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_CHAR + ao->endpoint.length, nakp); 2280*7c478bd9Sstevel@tonic-gate PUTCHAR(ao->endpoint.class, nakp); 2281*7c478bd9Sstevel@tonic-gate for (i = 0; i < ao->endpoint.length; i++) 2282*7c478bd9Sstevel@tonic-gate PUTCHAR(ao->endpoint.value[i], nakp); 2283*7c478bd9Sstevel@tonic-gate break; 2284*7c478bd9Sstevel@tonic-gate } 2285*7c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); 2286*7c478bd9Sstevel@tonic-gate ho->neg_endpoint = 1; 2287*7c478bd9Sstevel@tonic-gate ho->endpoint.class = cichar; 2288*7c478bd9Sstevel@tonic-gate ho->endpoint.length = cilen - 3; 2289*7c478bd9Sstevel@tonic-gate BCOPY(p, ho->endpoint.value, cilen - 3); 2290*7c478bd9Sstevel@tonic-gate break; 2291*7c478bd9Sstevel@tonic-gate 2292*7c478bd9Sstevel@tonic-gate #ifdef MUX_FRAME 2293*7c478bd9Sstevel@tonic-gate case CI_MUXING: 2294*7c478bd9Sstevel@tonic-gate if (ao->pppmux == 0 || cilen != CILEN_VOID) { 2295*7c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 2296*7c478bd9Sstevel@tonic-gate break; 2297*7c478bd9Sstevel@tonic-gate } 2298*7c478bd9Sstevel@tonic-gate /* remember his option */ 2299*7c478bd9Sstevel@tonic-gate ho->pppmux = ao->pppmux; 2300*7c478bd9Sstevel@tonic-gate break; 2301*7c478bd9Sstevel@tonic-gate #endif 2302*7c478bd9Sstevel@tonic-gate 2303*7c478bd9Sstevel@tonic-gate default: 2304*7c478bd9Sstevel@tonic-gate dbglog("LCP: rejecting unknown option %d", citype); 2305*7c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 2306*7c478bd9Sstevel@tonic-gate break; 2307*7c478bd9Sstevel@tonic-gate } 2308*7c478bd9Sstevel@tonic-gate 2309*7c478bd9Sstevel@tonic-gate /* Cope with confused peers. */ 2310*7c478bd9Sstevel@tonic-gate if (cilen < 2) 2311*7c478bd9Sstevel@tonic-gate cilen = 2; 2312*7c478bd9Sstevel@tonic-gate 2313*7c478bd9Sstevel@tonic-gate /* 2314*7c478bd9Sstevel@tonic-gate * If this is an Ack'able CI, but we're sending back a Nak, 2315*7c478bd9Sstevel@tonic-gate * don't include this CI. 2316*7c478bd9Sstevel@tonic-gate */ 2317*7c478bd9Sstevel@tonic-gate if (newret == CODE_CONFACK && ret != CODE_CONFACK) 2318*7c478bd9Sstevel@tonic-gate continue; 2319*7c478bd9Sstevel@tonic-gate 2320*7c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK) { 2321*7c478bd9Sstevel@tonic-gate /* 2322*7c478bd9Sstevel@tonic-gate * Continue naking the Magic Number option until the cows come 2323*7c478bd9Sstevel@tonic-gate * home -- rejecting it is wrong. 2324*7c478bd9Sstevel@tonic-gate */ 2325*7c478bd9Sstevel@tonic-gate if (dont_nak && citype != CI_MAGICNUMBER) { 2326*7c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 2327*7c478bd9Sstevel@tonic-gate } else { 2328*7c478bd9Sstevel@tonic-gate /* Ignore subsequent Nak'able things if rejecting. */ 2329*7c478bd9Sstevel@tonic-gate if (ret == CODE_CONFREJ) 2330*7c478bd9Sstevel@tonic-gate continue; 2331*7c478bd9Sstevel@tonic-gate ret = CODE_CONFNAK; 2332*7c478bd9Sstevel@tonic-gate } 2333*7c478bd9Sstevel@tonic-gate } 2334*7c478bd9Sstevel@tonic-gate 2335*7c478bd9Sstevel@tonic-gate if (newret == CODE_CONFREJ) { 2336*7c478bd9Sstevel@tonic-gate ret = CODE_CONFREJ; 2337*7c478bd9Sstevel@tonic-gate if (prev != rejp) 2338*7c478bd9Sstevel@tonic-gate BCOPY(prev, rejp, cilen); 2339*7c478bd9Sstevel@tonic-gate rejp += cilen; 2340*7c478bd9Sstevel@tonic-gate } 2341*7c478bd9Sstevel@tonic-gate } 2342*7c478bd9Sstevel@tonic-gate 2343*7c478bd9Sstevel@tonic-gate /* 2344*7c478bd9Sstevel@tonic-gate * If the peer hasn't negotiated his MRU, and we'd like an MTU 2345*7c478bd9Sstevel@tonic-gate * that's larger than the default, try sending an unsolicited 2346*7c478bd9Sstevel@tonic-gate * Nak for what we want. 2347*7c478bd9Sstevel@tonic-gate */ 2348*7c478bd9Sstevel@tonic-gate if (ret != CODE_CONFREJ && !ho->neg_mru && ao->mru > PPP_MTU && 2349*7c478bd9Sstevel@tonic-gate !dont_nak && unsolicit_mru) { 2350*7c478bd9Sstevel@tonic-gate unsolicit_mru = 0; /* don't ask again */ 2351*7c478bd9Sstevel@tonic-gate ret = CODE_CONFNAK; 2352*7c478bd9Sstevel@tonic-gate PUTCHAR(CI_MRU, nakp); 2353*7c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_SHORT, nakp); 2354*7c478bd9Sstevel@tonic-gate PUTSHORT(ao->mru, nakp); 2355*7c478bd9Sstevel@tonic-gate } 2356*7c478bd9Sstevel@tonic-gate 2357*7c478bd9Sstevel@tonic-gate switch (ret) { 2358*7c478bd9Sstevel@tonic-gate case CODE_CONFACK: 2359*7c478bd9Sstevel@tonic-gate *lenp = p - p0; 2360*7c478bd9Sstevel@tonic-gate break; 2361*7c478bd9Sstevel@tonic-gate case CODE_CONFNAK: 2362*7c478bd9Sstevel@tonic-gate /* 2363*7c478bd9Sstevel@tonic-gate * Copy the Nak'd options from the nak_buffer to the caller's buffer. 2364*7c478bd9Sstevel@tonic-gate */ 2365*7c478bd9Sstevel@tonic-gate *lenp = nakp - nak_buffer; 2366*7c478bd9Sstevel@tonic-gate BCOPY(nak_buffer, p0, *lenp); 2367*7c478bd9Sstevel@tonic-gate break; 2368*7c478bd9Sstevel@tonic-gate case CODE_CONFREJ: 2369*7c478bd9Sstevel@tonic-gate *lenp = rejp - p0; 2370*7c478bd9Sstevel@tonic-gate 2371*7c478bd9Sstevel@tonic-gate /* We're about to send Configure-Reject; send Identification */ 2372*7c478bd9Sstevel@tonic-gate if (!noident && sentident < 3) { 2373*7c478bd9Sstevel@tonic-gate LcpSendIdentification(f); 2374*7c478bd9Sstevel@tonic-gate sentident++; 2375*7c478bd9Sstevel@tonic-gate } 2376*7c478bd9Sstevel@tonic-gate break; 2377*7c478bd9Sstevel@tonic-gate } 2378*7c478bd9Sstevel@tonic-gate 2379*7c478bd9Sstevel@tonic-gate LCPDEBUG(("lcp_reqci: returning %s.", code_name(ret, 1))); 2380*7c478bd9Sstevel@tonic-gate return (ret); /* Return final code */ 2381*7c478bd9Sstevel@tonic-gate } 2382*7c478bd9Sstevel@tonic-gate 2383*7c478bd9Sstevel@tonic-gate 2384*7c478bd9Sstevel@tonic-gate /* 2385*7c478bd9Sstevel@tonic-gate * lcp_up - LCP has come UP. 2386*7c478bd9Sstevel@tonic-gate */ 2387*7c478bd9Sstevel@tonic-gate static void 2388*7c478bd9Sstevel@tonic-gate lcp_up(f) 2389*7c478bd9Sstevel@tonic-gate fsm *f; 2390*7c478bd9Sstevel@tonic-gate { 2391*7c478bd9Sstevel@tonic-gate lcp_options *wo = &lcp_wantoptions[f->unit]; 2392*7c478bd9Sstevel@tonic-gate lcp_options *ho = &lcp_hisoptions[f->unit]; 2393*7c478bd9Sstevel@tonic-gate lcp_options *go = &lcp_gotoptions[f->unit]; 2394*7c478bd9Sstevel@tonic-gate lcp_options *ao = &lcp_allowoptions[f->unit]; 2395*7c478bd9Sstevel@tonic-gate int mru, mtu; 2396*7c478bd9Sstevel@tonic-gate 2397*7c478bd9Sstevel@tonic-gate if (!go->neg_magicnumber) 2398*7c478bd9Sstevel@tonic-gate go->magicnumber = 0; 2399*7c478bd9Sstevel@tonic-gate if (!ho->neg_magicnumber) 2400*7c478bd9Sstevel@tonic-gate ho->magicnumber = 0; 2401*7c478bd9Sstevel@tonic-gate 2402*7c478bd9Sstevel@tonic-gate /* 2403*7c478bd9Sstevel@tonic-gate * Set our MTU to the smaller of the MTU we wanted and 2404*7c478bd9Sstevel@tonic-gate * the MRU our peer wanted. If we negotiated an MRU, 2405*7c478bd9Sstevel@tonic-gate * set our MRU to the larger of value we wanted and 2406*7c478bd9Sstevel@tonic-gate * the value we got in the negotiation. 2407*7c478bd9Sstevel@tonic-gate */ 2408*7c478bd9Sstevel@tonic-gate if (ao->mru != 0 && ho->mru > ao->mru) 2409*7c478bd9Sstevel@tonic-gate ho->mru = ao->mru; 2410*7c478bd9Sstevel@tonic-gate mtu = (ho->neg_mru ? ho->mru: PPP_MRU); 2411*7c478bd9Sstevel@tonic-gate if (mtu > absmax_mtu) 2412*7c478bd9Sstevel@tonic-gate mtu = absmax_mtu; 2413*7c478bd9Sstevel@tonic-gate ppp_send_config(f->unit, mtu, 2414*7c478bd9Sstevel@tonic-gate (ho->neg_asyncmap? ho->asyncmap: 0xffffffff), 2415*7c478bd9Sstevel@tonic-gate ho->neg_pcompression, ho->neg_accompression); 2416*7c478bd9Sstevel@tonic-gate fsm_setpeermru(f->unit, mtu); 2417*7c478bd9Sstevel@tonic-gate mru = (go->neg_mru? MAX(wo->mru, go->mru): PPP_MRU); 2418*7c478bd9Sstevel@tonic-gate if (mru > absmax_mru) 2419*7c478bd9Sstevel@tonic-gate mru = absmax_mru; 2420*7c478bd9Sstevel@tonic-gate ppp_recv_config(f->unit, mru, 2421*7c478bd9Sstevel@tonic-gate (lax_recv? 0: go->neg_asyncmap? go->asyncmap: 0xffffffff), 2422*7c478bd9Sstevel@tonic-gate go->neg_pcompression, go->neg_accompression); 2423*7c478bd9Sstevel@tonic-gate #ifdef NEGOTIATE_FCS 2424*7c478bd9Sstevel@tonic-gate ppp_send_fcs(f->unit, ho->neg_fcs ? ho->fcs_type : FCSALT_16); 2425*7c478bd9Sstevel@tonic-gate ppp_recv_fcs(f->unit, go->neg_fcs ? go->fcs_type : FCSALT_16); 2426*7c478bd9Sstevel@tonic-gate #endif 2427*7c478bd9Sstevel@tonic-gate #ifdef MUX_FRAME 2428*7c478bd9Sstevel@tonic-gate ppp_send_muxoption(f->unit, ho->pppmux); 2429*7c478bd9Sstevel@tonic-gate ppp_recv_muxoption(f->unit, go->pppmux); 2430*7c478bd9Sstevel@tonic-gate #endif 2431*7c478bd9Sstevel@tonic-gate 2432*7c478bd9Sstevel@tonic-gate lcp_echo_lowerup(f->unit); /* Enable echo messages */ 2433*7c478bd9Sstevel@tonic-gate 2434*7c478bd9Sstevel@tonic-gate /* LCP is Up; send Identification */ 2435*7c478bd9Sstevel@tonic-gate if (!noident) { 2436*7c478bd9Sstevel@tonic-gate LcpSendIdentification(f); 2437*7c478bd9Sstevel@tonic-gate sentident++; 2438*7c478bd9Sstevel@tonic-gate } 2439*7c478bd9Sstevel@tonic-gate 2440*7c478bd9Sstevel@tonic-gate link_established(f->unit); 2441*7c478bd9Sstevel@tonic-gate } 2442*7c478bd9Sstevel@tonic-gate 2443*7c478bd9Sstevel@tonic-gate 2444*7c478bd9Sstevel@tonic-gate /* 2445*7c478bd9Sstevel@tonic-gate * lcp_down - LCP has gone DOWN. 2446*7c478bd9Sstevel@tonic-gate * 2447*7c478bd9Sstevel@tonic-gate * Alert other protocols. 2448*7c478bd9Sstevel@tonic-gate */ 2449*7c478bd9Sstevel@tonic-gate static void 2450*7c478bd9Sstevel@tonic-gate lcp_down(f) 2451*7c478bd9Sstevel@tonic-gate fsm *f; 2452*7c478bd9Sstevel@tonic-gate { 2453*7c478bd9Sstevel@tonic-gate int mtu; 2454*7c478bd9Sstevel@tonic-gate lcp_options *go = &lcp_gotoptions[f->unit]; 2455*7c478bd9Sstevel@tonic-gate 2456*7c478bd9Sstevel@tonic-gate lcp_echo_lowerdown(f->unit); 2457*7c478bd9Sstevel@tonic-gate 2458*7c478bd9Sstevel@tonic-gate link_down(f->unit); 2459*7c478bd9Sstevel@tonic-gate 2460*7c478bd9Sstevel@tonic-gate mtu = PPP_MTU > absmax_mtu ? absmax_mtu : PPP_MTU; 2461*7c478bd9Sstevel@tonic-gate ppp_send_config(f->unit, mtu, 0xffffffff, 0, 0); 2462*7c478bd9Sstevel@tonic-gate ppp_recv_config(f->unit, (PPP_MRU > absmax_mru ? absmax_mru : PPP_MRU), 2463*7c478bd9Sstevel@tonic-gate (go->neg_asyncmap? go->asyncmap: 0xffffffff), 2464*7c478bd9Sstevel@tonic-gate go->neg_pcompression, go->neg_accompression); 2465*7c478bd9Sstevel@tonic-gate #ifdef NEGOTIATE_FCS 2466*7c478bd9Sstevel@tonic-gate ppp_send_fcs(f->unit, FCSALT_16); 2467*7c478bd9Sstevel@tonic-gate ppp_recv_fcs(f->unit, FCSALT_16); 2468*7c478bd9Sstevel@tonic-gate #endif 2469*7c478bd9Sstevel@tonic-gate fsm_setpeermru(f->unit, mtu); 2470*7c478bd9Sstevel@tonic-gate } 2471*7c478bd9Sstevel@tonic-gate 2472*7c478bd9Sstevel@tonic-gate 2473*7c478bd9Sstevel@tonic-gate /* 2474*7c478bd9Sstevel@tonic-gate * lcp_starting - LCP needs the lower layer up. 2475*7c478bd9Sstevel@tonic-gate */ 2476*7c478bd9Sstevel@tonic-gate static void 2477*7c478bd9Sstevel@tonic-gate lcp_starting(f) 2478*7c478bd9Sstevel@tonic-gate fsm *f; 2479*7c478bd9Sstevel@tonic-gate { 2480*7c478bd9Sstevel@tonic-gate link_required(f->unit); 2481*7c478bd9Sstevel@tonic-gate } 2482*7c478bd9Sstevel@tonic-gate 2483*7c478bd9Sstevel@tonic-gate 2484*7c478bd9Sstevel@tonic-gate /* 2485*7c478bd9Sstevel@tonic-gate * lcp_finished - LCP has finished with the lower layer. 2486*7c478bd9Sstevel@tonic-gate */ 2487*7c478bd9Sstevel@tonic-gate static void 2488*7c478bd9Sstevel@tonic-gate lcp_finished(f) 2489*7c478bd9Sstevel@tonic-gate fsm *f; 2490*7c478bd9Sstevel@tonic-gate { 2491*7c478bd9Sstevel@tonic-gate link_terminated(f->unit); 2492*7c478bd9Sstevel@tonic-gate } 2493*7c478bd9Sstevel@tonic-gate 2494*7c478bd9Sstevel@tonic-gate 2495*7c478bd9Sstevel@tonic-gate /* 2496*7c478bd9Sstevel@tonic-gate * lcp_printpkt - print the contents of an LCP packet. 2497*7c478bd9Sstevel@tonic-gate */ 2498*7c478bd9Sstevel@tonic-gate 2499*7c478bd9Sstevel@tonic-gate static int 2500*7c478bd9Sstevel@tonic-gate lcp_printpkt(p, plen, printer, arg) 2501*7c478bd9Sstevel@tonic-gate u_char *p; 2502*7c478bd9Sstevel@tonic-gate int plen; 2503*7c478bd9Sstevel@tonic-gate void (*printer) __P((void *, const char *, ...)); 2504*7c478bd9Sstevel@tonic-gate void *arg; 2505*7c478bd9Sstevel@tonic-gate { 2506*7c478bd9Sstevel@tonic-gate int code, id, len, olen, i; 2507*7c478bd9Sstevel@tonic-gate u_char *pstart, *optend, cichar; 2508*7c478bd9Sstevel@tonic-gate u_short cishort; 2509*7c478bd9Sstevel@tonic-gate u_int32_t cilong; 2510*7c478bd9Sstevel@tonic-gate 2511*7c478bd9Sstevel@tonic-gate if (plen < HEADERLEN) 2512*7c478bd9Sstevel@tonic-gate return 0; 2513*7c478bd9Sstevel@tonic-gate pstart = p; 2514*7c478bd9Sstevel@tonic-gate GETCHAR(code, p); 2515*7c478bd9Sstevel@tonic-gate GETCHAR(id, p); 2516*7c478bd9Sstevel@tonic-gate GETSHORT(len, p); 2517*7c478bd9Sstevel@tonic-gate if (len < HEADERLEN || len > plen) 2518*7c478bd9Sstevel@tonic-gate return 0; 2519*7c478bd9Sstevel@tonic-gate 2520*7c478bd9Sstevel@tonic-gate printer(arg, " %s id=0x%x", code_name(code,1), id); 2521*7c478bd9Sstevel@tonic-gate len -= HEADERLEN; 2522*7c478bd9Sstevel@tonic-gate switch (code) { 2523*7c478bd9Sstevel@tonic-gate case CODE_CONFREQ: 2524*7c478bd9Sstevel@tonic-gate case CODE_CONFACK: 2525*7c478bd9Sstevel@tonic-gate case CODE_CONFNAK: 2526*7c478bd9Sstevel@tonic-gate case CODE_CONFREJ: 2527*7c478bd9Sstevel@tonic-gate /* print option list */ 2528*7c478bd9Sstevel@tonic-gate while (len >= 2) { 2529*7c478bd9Sstevel@tonic-gate GETCHAR(code, p); 2530*7c478bd9Sstevel@tonic-gate GETCHAR(olen, p); 2531*7c478bd9Sstevel@tonic-gate p -= 2; 2532*7c478bd9Sstevel@tonic-gate if (olen < 2 || olen > len) { 2533*7c478bd9Sstevel@tonic-gate break; 2534*7c478bd9Sstevel@tonic-gate } 2535*7c478bd9Sstevel@tonic-gate printer(arg, " <"); 2536*7c478bd9Sstevel@tonic-gate len -= olen; 2537*7c478bd9Sstevel@tonic-gate optend = p + olen; 2538*7c478bd9Sstevel@tonic-gate switch (code) { 2539*7c478bd9Sstevel@tonic-gate case CI_MRU: 2540*7c478bd9Sstevel@tonic-gate if (olen >= CILEN_SHORT) { 2541*7c478bd9Sstevel@tonic-gate p += 2; 2542*7c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); 2543*7c478bd9Sstevel@tonic-gate printer(arg, "mru %d", cishort); 2544*7c478bd9Sstevel@tonic-gate } 2545*7c478bd9Sstevel@tonic-gate break; 2546*7c478bd9Sstevel@tonic-gate case CI_ASYNCMAP: 2547*7c478bd9Sstevel@tonic-gate if (olen >= CILEN_LONG) { 2548*7c478bd9Sstevel@tonic-gate p += 2; 2549*7c478bd9Sstevel@tonic-gate GETLONG(cilong, p); 2550*7c478bd9Sstevel@tonic-gate printer(arg, "asyncmap 0x%x", cilong); 2551*7c478bd9Sstevel@tonic-gate } 2552*7c478bd9Sstevel@tonic-gate break; 2553*7c478bd9Sstevel@tonic-gate case CI_AUTHTYPE: 2554*7c478bd9Sstevel@tonic-gate if (olen >= CILEN_SHORT) { 2555*7c478bd9Sstevel@tonic-gate p += 2; 2556*7c478bd9Sstevel@tonic-gate printer(arg, "auth "); 2557*7c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); 2558*7c478bd9Sstevel@tonic-gate switch (cishort) { 2559*7c478bd9Sstevel@tonic-gate case PPP_PAP: 2560*7c478bd9Sstevel@tonic-gate printer(arg, "pap"); 2561*7c478bd9Sstevel@tonic-gate break; 2562*7c478bd9Sstevel@tonic-gate case PPP_CHAP: 2563*7c478bd9Sstevel@tonic-gate printer(arg, "chap"); 2564*7c478bd9Sstevel@tonic-gate if (p < optend) { 2565*7c478bd9Sstevel@tonic-gate switch (*p) { 2566*7c478bd9Sstevel@tonic-gate case CHAP_DIGEST_MD5: 2567*7c478bd9Sstevel@tonic-gate printer(arg, " MD5"); 2568*7c478bd9Sstevel@tonic-gate ++p; 2569*7c478bd9Sstevel@tonic-gate break; 2570*7c478bd9Sstevel@tonic-gate case CHAP_MICROSOFT: 2571*7c478bd9Sstevel@tonic-gate printer(arg, " m$oft"); 2572*7c478bd9Sstevel@tonic-gate ++p; 2573*7c478bd9Sstevel@tonic-gate break; 2574*7c478bd9Sstevel@tonic-gate case CHAP_MICROSOFT_V2: 2575*7c478bd9Sstevel@tonic-gate printer(arg, " m$oft-v2"); 2576*7c478bd9Sstevel@tonic-gate ++p; 2577*7c478bd9Sstevel@tonic-gate break; 2578*7c478bd9Sstevel@tonic-gate } 2579*7c478bd9Sstevel@tonic-gate } 2580*7c478bd9Sstevel@tonic-gate break; 2581*7c478bd9Sstevel@tonic-gate #ifdef PPP_EAP 2582*7c478bd9Sstevel@tonic-gate case PPP_EAP: 2583*7c478bd9Sstevel@tonic-gate printer(arg, "eap"); 2584*7c478bd9Sstevel@tonic-gate break; 2585*7c478bd9Sstevel@tonic-gate #endif 2586*7c478bd9Sstevel@tonic-gate case 0xC027: 2587*7c478bd9Sstevel@tonic-gate printer(arg, "spap"); 2588*7c478bd9Sstevel@tonic-gate break; 2589*7c478bd9Sstevel@tonic-gate case 0xC123: 2590*7c478bd9Sstevel@tonic-gate printer(arg, "old-spap"); 2591*7c478bd9Sstevel@tonic-gate break; 2592*7c478bd9Sstevel@tonic-gate default: 2593*7c478bd9Sstevel@tonic-gate printer(arg, "0x%x", cishort); 2594*7c478bd9Sstevel@tonic-gate } 2595*7c478bd9Sstevel@tonic-gate } 2596*7c478bd9Sstevel@tonic-gate break; 2597*7c478bd9Sstevel@tonic-gate case CI_QUALITY: 2598*7c478bd9Sstevel@tonic-gate if (olen >= CILEN_SHORT) { 2599*7c478bd9Sstevel@tonic-gate p += 2; 2600*7c478bd9Sstevel@tonic-gate printer(arg, "quality "); 2601*7c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); 2602*7c478bd9Sstevel@tonic-gate switch (cishort) { 2603*7c478bd9Sstevel@tonic-gate case PPP_LQR: 2604*7c478bd9Sstevel@tonic-gate printer(arg, "lqr"); 2605*7c478bd9Sstevel@tonic-gate break; 2606*7c478bd9Sstevel@tonic-gate default: 2607*7c478bd9Sstevel@tonic-gate printer(arg, "0x%x", cishort); 2608*7c478bd9Sstevel@tonic-gate } 2609*7c478bd9Sstevel@tonic-gate } 2610*7c478bd9Sstevel@tonic-gate break; 2611*7c478bd9Sstevel@tonic-gate case CI_CALLBACK: 2612*7c478bd9Sstevel@tonic-gate if (olen >= CILEN_CHAR) { 2613*7c478bd9Sstevel@tonic-gate p += 2; 2614*7c478bd9Sstevel@tonic-gate printer(arg, "callback "); 2615*7c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); 2616*7c478bd9Sstevel@tonic-gate if (cichar <= 6 && 2617*7c478bd9Sstevel@tonic-gate *callback_strings[(int)cichar] != '\0') { 2618*7c478bd9Sstevel@tonic-gate printer(arg, "%s", callback_strings[(int)cichar]); 2619*7c478bd9Sstevel@tonic-gate } else { 2620*7c478bd9Sstevel@tonic-gate printer(arg, "0x%x", cichar); 2621*7c478bd9Sstevel@tonic-gate } 2622*7c478bd9Sstevel@tonic-gate } 2623*7c478bd9Sstevel@tonic-gate break; 2624*7c478bd9Sstevel@tonic-gate case CI_MAGICNUMBER: 2625*7c478bd9Sstevel@tonic-gate if (olen >= CILEN_LONG) { 2626*7c478bd9Sstevel@tonic-gate p += 2; 2627*7c478bd9Sstevel@tonic-gate GETLONG(cilong, p); 2628*7c478bd9Sstevel@tonic-gate printer(arg, "magic 0x%x", cilong); 2629*7c478bd9Sstevel@tonic-gate } 2630*7c478bd9Sstevel@tonic-gate break; 2631*7c478bd9Sstevel@tonic-gate case CI_PCOMPRESSION: 2632*7c478bd9Sstevel@tonic-gate if (olen >= CILEN_VOID) { 2633*7c478bd9Sstevel@tonic-gate p += 2; 2634*7c478bd9Sstevel@tonic-gate printer(arg, "pcomp"); 2635*7c478bd9Sstevel@tonic-gate } 2636*7c478bd9Sstevel@tonic-gate break; 2637*7c478bd9Sstevel@tonic-gate case CI_ACCOMPRESSION: 2638*7c478bd9Sstevel@tonic-gate if (olen >= CILEN_VOID) { 2639*7c478bd9Sstevel@tonic-gate p += 2; 2640*7c478bd9Sstevel@tonic-gate printer(arg, "accomp"); 2641*7c478bd9Sstevel@tonic-gate } 2642*7c478bd9Sstevel@tonic-gate break; 2643*7c478bd9Sstevel@tonic-gate case CI_FCSALTERN: 2644*7c478bd9Sstevel@tonic-gate if (olen >= CILEN_CHAR) { 2645*7c478bd9Sstevel@tonic-gate char **cpp; 2646*7c478bd9Sstevel@tonic-gate int needcomma = 0; 2647*7c478bd9Sstevel@tonic-gate 2648*7c478bd9Sstevel@tonic-gate p += 2; 2649*7c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); 2650*7c478bd9Sstevel@tonic-gate for (cpp = fcsalt_strings; *cpp != NULL; cpp++) 2651*7c478bd9Sstevel@tonic-gate if (cichar & 1<<(cpp-fcsalt_strings)) { 2652*7c478bd9Sstevel@tonic-gate cichar &= ~(1<<(cpp-fcsalt_strings)); 2653*7c478bd9Sstevel@tonic-gate printer(arg, (needcomma ? ",%s" : "fcs %s"), *cpp); 2654*7c478bd9Sstevel@tonic-gate needcomma = 1; 2655*7c478bd9Sstevel@tonic-gate } 2656*7c478bd9Sstevel@tonic-gate if (cichar != 0 || !needcomma) 2657*7c478bd9Sstevel@tonic-gate printer(arg, (needcomma ? ",0x%x" : "fcs 0x%x"), 2658*7c478bd9Sstevel@tonic-gate cichar); 2659*7c478bd9Sstevel@tonic-gate } 2660*7c478bd9Sstevel@tonic-gate break; 2661*7c478bd9Sstevel@tonic-gate case CI_NUMBERED: 2662*7c478bd9Sstevel@tonic-gate if (olen >= CILEN_SHORT) { 2663*7c478bd9Sstevel@tonic-gate p += 2; 2664*7c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); 2665*7c478bd9Sstevel@tonic-gate printer(arg, "numb win %d", cichar); 2666*7c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); 2667*7c478bd9Sstevel@tonic-gate printer(arg, " addr %d", cichar); 2668*7c478bd9Sstevel@tonic-gate } 2669*7c478bd9Sstevel@tonic-gate break; 2670*7c478bd9Sstevel@tonic-gate case CI_MRRU: 2671*7c478bd9Sstevel@tonic-gate if (olen >= CILEN_SHORT) { 2672*7c478bd9Sstevel@tonic-gate p += 2; 2673*7c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); 2674*7c478bd9Sstevel@tonic-gate printer(arg, "mrru %d", cishort); 2675*7c478bd9Sstevel@tonic-gate } 2676*7c478bd9Sstevel@tonic-gate break; 2677*7c478bd9Sstevel@tonic-gate case CI_SSNHF: 2678*7c478bd9Sstevel@tonic-gate if (olen >= CILEN_VOID) { 2679*7c478bd9Sstevel@tonic-gate p += 2; 2680*7c478bd9Sstevel@tonic-gate printer(arg, "ssnhf"); 2681*7c478bd9Sstevel@tonic-gate } 2682*7c478bd9Sstevel@tonic-gate break; 2683*7c478bd9Sstevel@tonic-gate case CI_EPDISC: 2684*7c478bd9Sstevel@tonic-gate if (olen >= CILEN_CHAR) { 2685*7c478bd9Sstevel@tonic-gate struct epdisc epd; 2686*7c478bd9Sstevel@tonic-gate p += 2; 2687*7c478bd9Sstevel@tonic-gate GETCHAR(epd.class, p); 2688*7c478bd9Sstevel@tonic-gate epd.length = olen - CILEN_CHAR; 2689*7c478bd9Sstevel@tonic-gate if (epd.length > MAX_ENDP_LEN) 2690*7c478bd9Sstevel@tonic-gate epd.length = MAX_ENDP_LEN; 2691*7c478bd9Sstevel@tonic-gate if (epd.length > 0) { 2692*7c478bd9Sstevel@tonic-gate BCOPY(p, epd.value, epd.length); 2693*7c478bd9Sstevel@tonic-gate p += epd.length; 2694*7c478bd9Sstevel@tonic-gate } 2695*7c478bd9Sstevel@tonic-gate printer(arg, "endpoint [%s]", epdisc_to_str(&epd)); 2696*7c478bd9Sstevel@tonic-gate } 2697*7c478bd9Sstevel@tonic-gate break; 2698*7c478bd9Sstevel@tonic-gate case CI_LINKDISC: 2699*7c478bd9Sstevel@tonic-gate if (olen >= CILEN_SHORT) { 2700*7c478bd9Sstevel@tonic-gate p += 2; 2701*7c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); 2702*7c478bd9Sstevel@tonic-gate printer(arg, "linkdisc %d", cishort); 2703*7c478bd9Sstevel@tonic-gate } 2704*7c478bd9Sstevel@tonic-gate break; 2705*7c478bd9Sstevel@tonic-gate case CI_COBS: 2706*7c478bd9Sstevel@tonic-gate if (olen >= CILEN_CHAR) { 2707*7c478bd9Sstevel@tonic-gate p += 2; 2708*7c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); 2709*7c478bd9Sstevel@tonic-gate printer(arg, "cobs 0x%x", cichar); 2710*7c478bd9Sstevel@tonic-gate } 2711*7c478bd9Sstevel@tonic-gate break; 2712*7c478bd9Sstevel@tonic-gate case CI_PFXELISION: 2713*7c478bd9Sstevel@tonic-gate if (olen >= CILEN_CHAR) { 2714*7c478bd9Sstevel@tonic-gate p += 2; 2715*7c478bd9Sstevel@tonic-gate printer(arg, "pfx"); 2716*7c478bd9Sstevel@tonic-gate } 2717*7c478bd9Sstevel@tonic-gate break; 2718*7c478bd9Sstevel@tonic-gate case CI_MPHDRFMT: 2719*7c478bd9Sstevel@tonic-gate if (olen >= CILEN_SHORT) { 2720*7c478bd9Sstevel@tonic-gate p += 2; 2721*7c478bd9Sstevel@tonic-gate printer(arg, "mphdr "); 2722*7c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); 2723*7c478bd9Sstevel@tonic-gate switch (cichar) { 2724*7c478bd9Sstevel@tonic-gate case 2: 2725*7c478bd9Sstevel@tonic-gate printer(arg, "long"); 2726*7c478bd9Sstevel@tonic-gate break; 2727*7c478bd9Sstevel@tonic-gate case 6: 2728*7c478bd9Sstevel@tonic-gate printer(arg, "short"); 2729*7c478bd9Sstevel@tonic-gate break; 2730*7c478bd9Sstevel@tonic-gate default: 2731*7c478bd9Sstevel@tonic-gate printer(arg, "0x%x", cichar); 2732*7c478bd9Sstevel@tonic-gate break; 2733*7c478bd9Sstevel@tonic-gate } 2734*7c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); 2735*7c478bd9Sstevel@tonic-gate printer(arg, " #cl %d", cichar); 2736*7c478bd9Sstevel@tonic-gate } 2737*7c478bd9Sstevel@tonic-gate break; 2738*7c478bd9Sstevel@tonic-gate case CI_I18N: 2739*7c478bd9Sstevel@tonic-gate if (olen >= CILEN_LONG) { 2740*7c478bd9Sstevel@tonic-gate p += 2; 2741*7c478bd9Sstevel@tonic-gate GETLONG(cilong, p); 2742*7c478bd9Sstevel@tonic-gate printer(arg, "i18n charset 0x%x", cilong); 2743*7c478bd9Sstevel@tonic-gate if (olen > CILEN_LONG) { 2744*7c478bd9Sstevel@tonic-gate printer(arg, " lang "); 2745*7c478bd9Sstevel@tonic-gate print_string((char *)p, olen-CILEN_LONG, printer, arg); 2746*7c478bd9Sstevel@tonic-gate p = optend; 2747*7c478bd9Sstevel@tonic-gate } 2748*7c478bd9Sstevel@tonic-gate } 2749*7c478bd9Sstevel@tonic-gate break; 2750*7c478bd9Sstevel@tonic-gate case CI_SDL: 2751*7c478bd9Sstevel@tonic-gate if (olen >= CILEN_VOID) { 2752*7c478bd9Sstevel@tonic-gate p += 2; 2753*7c478bd9Sstevel@tonic-gate printer(arg, "sdl"); 2754*7c478bd9Sstevel@tonic-gate } 2755*7c478bd9Sstevel@tonic-gate break; 2756*7c478bd9Sstevel@tonic-gate case CI_MUXING: 2757*7c478bd9Sstevel@tonic-gate if (olen >= CILEN_VOID) { 2758*7c478bd9Sstevel@tonic-gate p += 2; 2759*7c478bd9Sstevel@tonic-gate printer(arg, "mux"); 2760*7c478bd9Sstevel@tonic-gate } 2761*7c478bd9Sstevel@tonic-gate break; 2762*7c478bd9Sstevel@tonic-gate } 2763*7c478bd9Sstevel@tonic-gate while (p < optend) { 2764*7c478bd9Sstevel@tonic-gate GETCHAR(code, p); 2765*7c478bd9Sstevel@tonic-gate printer(arg, " %.2x", code); 2766*7c478bd9Sstevel@tonic-gate } 2767*7c478bd9Sstevel@tonic-gate printer(arg, ">"); 2768*7c478bd9Sstevel@tonic-gate } 2769*7c478bd9Sstevel@tonic-gate break; 2770*7c478bd9Sstevel@tonic-gate 2771*7c478bd9Sstevel@tonic-gate case CODE_TERMACK: 2772*7c478bd9Sstevel@tonic-gate case CODE_TERMREQ: 2773*7c478bd9Sstevel@tonic-gate if (len > 0 && *p >= ' ' && *p < 0x7f) { 2774*7c478bd9Sstevel@tonic-gate printer(arg, " "); 2775*7c478bd9Sstevel@tonic-gate print_string((char *)p, len, printer, arg); 2776*7c478bd9Sstevel@tonic-gate p += len; 2777*7c478bd9Sstevel@tonic-gate len = 0; 2778*7c478bd9Sstevel@tonic-gate } 2779*7c478bd9Sstevel@tonic-gate break; 2780*7c478bd9Sstevel@tonic-gate 2781*7c478bd9Sstevel@tonic-gate case CODE_ECHOREQ: 2782*7c478bd9Sstevel@tonic-gate case CODE_ECHOREP: 2783*7c478bd9Sstevel@tonic-gate case CODE_DISCREQ: 2784*7c478bd9Sstevel@tonic-gate if (len >= 4) { 2785*7c478bd9Sstevel@tonic-gate GETLONG(cilong, p); 2786*7c478bd9Sstevel@tonic-gate printer(arg, " magic=0x%x", cilong); 2787*7c478bd9Sstevel@tonic-gate len -= 4; 2788*7c478bd9Sstevel@tonic-gate } 2789*7c478bd9Sstevel@tonic-gate break; 2790*7c478bd9Sstevel@tonic-gate 2791*7c478bd9Sstevel@tonic-gate case CODE_IDENT: 2792*7c478bd9Sstevel@tonic-gate if (len >= 4) { 2793*7c478bd9Sstevel@tonic-gate GETLONG(cilong, p); 2794*7c478bd9Sstevel@tonic-gate printer(arg, " magic=0x%x", cilong); 2795*7c478bd9Sstevel@tonic-gate len -= 4; 2796*7c478bd9Sstevel@tonic-gate } else 2797*7c478bd9Sstevel@tonic-gate break; 2798*7c478bd9Sstevel@tonic-gate if (len > 0 && (len > 1 || *p != '\0')) { 2799*7c478bd9Sstevel@tonic-gate printer(arg, " "); 2800*7c478bd9Sstevel@tonic-gate print_string((char *)p, len, printer, arg); 2801*7c478bd9Sstevel@tonic-gate p += len; 2802*7c478bd9Sstevel@tonic-gate len = 0; 2803*7c478bd9Sstevel@tonic-gate } 2804*7c478bd9Sstevel@tonic-gate break; 2805*7c478bd9Sstevel@tonic-gate 2806*7c478bd9Sstevel@tonic-gate case CODE_TIMEREMAIN: 2807*7c478bd9Sstevel@tonic-gate if (len >= 4) { 2808*7c478bd9Sstevel@tonic-gate GETLONG(cilong, p); 2809*7c478bd9Sstevel@tonic-gate printer(arg, " magic=0x%x", cilong); 2810*7c478bd9Sstevel@tonic-gate len -= 4; 2811*7c478bd9Sstevel@tonic-gate } else 2812*7c478bd9Sstevel@tonic-gate break; 2813*7c478bd9Sstevel@tonic-gate if (len >= 4) { 2814*7c478bd9Sstevel@tonic-gate GETLONG(cilong, p); 2815*7c478bd9Sstevel@tonic-gate printer(arg, " seconds=%d", cilong); 2816*7c478bd9Sstevel@tonic-gate len -= 4; 2817*7c478bd9Sstevel@tonic-gate } else 2818*7c478bd9Sstevel@tonic-gate break; 2819*7c478bd9Sstevel@tonic-gate if (len > 0 && (len > 1 || *p != '\0')) { 2820*7c478bd9Sstevel@tonic-gate printer(arg, " "); 2821*7c478bd9Sstevel@tonic-gate print_string((char *)p, len, printer, arg); 2822*7c478bd9Sstevel@tonic-gate p += len; 2823*7c478bd9Sstevel@tonic-gate len = 0; 2824*7c478bd9Sstevel@tonic-gate } 2825*7c478bd9Sstevel@tonic-gate break; 2826*7c478bd9Sstevel@tonic-gate } 2827*7c478bd9Sstevel@tonic-gate 2828*7c478bd9Sstevel@tonic-gate /* print the rest of the bytes in the packet */ 2829*7c478bd9Sstevel@tonic-gate for (i = 0; i < len && i < 32; ++i) { 2830*7c478bd9Sstevel@tonic-gate GETCHAR(code, p); 2831*7c478bd9Sstevel@tonic-gate printer(arg, " %.2x", code); 2832*7c478bd9Sstevel@tonic-gate } 2833*7c478bd9Sstevel@tonic-gate if (i < len) { 2834*7c478bd9Sstevel@tonic-gate printer(arg, " ..."); 2835*7c478bd9Sstevel@tonic-gate p += len - i; 2836*7c478bd9Sstevel@tonic-gate } 2837*7c478bd9Sstevel@tonic-gate 2838*7c478bd9Sstevel@tonic-gate return p - pstart; 2839*7c478bd9Sstevel@tonic-gate } 2840*7c478bd9Sstevel@tonic-gate 2841*7c478bd9Sstevel@tonic-gate /* 2842*7c478bd9Sstevel@tonic-gate * Time to shut down the link because there is nothing out there. 2843*7c478bd9Sstevel@tonic-gate */ 2844*7c478bd9Sstevel@tonic-gate 2845*7c478bd9Sstevel@tonic-gate static void 2846*7c478bd9Sstevel@tonic-gate LcpLinkFailure (f) 2847*7c478bd9Sstevel@tonic-gate fsm *f; 2848*7c478bd9Sstevel@tonic-gate { 2849*7c478bd9Sstevel@tonic-gate char *close_message; 2850*7c478bd9Sstevel@tonic-gate 2851*7c478bd9Sstevel@tonic-gate if (f->state == OPENED) { 2852*7c478bd9Sstevel@tonic-gate /* 2853*7c478bd9Sstevel@tonic-gate * If this is an asynchronous line and we've missed all of 2854*7c478bd9Sstevel@tonic-gate * the initial echo requests, then this is probably due to 2855*7c478bd9Sstevel@tonic-gate * a bad ACCM. 2856*7c478bd9Sstevel@tonic-gate */ 2857*7c478bd9Sstevel@tonic-gate if (!sync_serial && lcp_echos_pending >= ACCM_TEST_FAILS && 2858*7c478bd9Sstevel@tonic-gate lcp_echo_number <= ACCM_TEST_FAILS && use_accm_test != 0) { 2859*7c478bd9Sstevel@tonic-gate notice("Peer not responding to initial Echo-Requests."); 2860*7c478bd9Sstevel@tonic-gate notice("Negotiated asyncmap may be incorrect for this link."); 2861*7c478bd9Sstevel@tonic-gate close_message = "Peer not responding; perhaps bad asyncmap"; 2862*7c478bd9Sstevel@tonic-gate } else if (lcp_echo_fails != 0 && 2863*7c478bd9Sstevel@tonic-gate lcp_echos_pending >= lcp_echo_fails) { 2864*7c478bd9Sstevel@tonic-gate info("No response to %d echo-requests", lcp_echos_pending); 2865*7c478bd9Sstevel@tonic-gate notice("Serial link appears to be disconnected."); 2866*7c478bd9Sstevel@tonic-gate close_message = "Peer not responding"; 2867*7c478bd9Sstevel@tonic-gate } else { 2868*7c478bd9Sstevel@tonic-gate info("Received %d bad echo-replies", lcp_echo_badreplies); 2869*7c478bd9Sstevel@tonic-gate close_message = "Receiving malformed Echo-Replies"; 2870*7c478bd9Sstevel@tonic-gate } 2871*7c478bd9Sstevel@tonic-gate 2872*7c478bd9Sstevel@tonic-gate lcp_close(f->unit, close_message); 2873*7c478bd9Sstevel@tonic-gate status = EXIT_PEER_DEAD; 2874*7c478bd9Sstevel@tonic-gate } 2875*7c478bd9Sstevel@tonic-gate } 2876*7c478bd9Sstevel@tonic-gate 2877*7c478bd9Sstevel@tonic-gate /* 2878*7c478bd9Sstevel@tonic-gate * Timer expired for the LCP echo requests from this process. 2879*7c478bd9Sstevel@tonic-gate */ 2880*7c478bd9Sstevel@tonic-gate 2881*7c478bd9Sstevel@tonic-gate static void 2882*7c478bd9Sstevel@tonic-gate LcpEchoCheck (f) 2883*7c478bd9Sstevel@tonic-gate fsm *f; 2884*7c478bd9Sstevel@tonic-gate { 2885*7c478bd9Sstevel@tonic-gate if (f->state != OPENED || lcp_echo_interval == 0) 2886*7c478bd9Sstevel@tonic-gate return; 2887*7c478bd9Sstevel@tonic-gate 2888*7c478bd9Sstevel@tonic-gate LcpSendEchoRequest (f); 2889*7c478bd9Sstevel@tonic-gate 2890*7c478bd9Sstevel@tonic-gate /* 2891*7c478bd9Sstevel@tonic-gate * Start the timer for the next interval. 2892*7c478bd9Sstevel@tonic-gate */ 2893*7c478bd9Sstevel@tonic-gate if (lcp_echo_timer_running) 2894*7c478bd9Sstevel@tonic-gate warn("assertion lcp_echo_timer_running==0 failed"); 2895*7c478bd9Sstevel@tonic-gate TIMEOUT (LcpEchoTimeout, f, lcp_echo_interval); 2896*7c478bd9Sstevel@tonic-gate lcp_echo_timer_running = 1; 2897*7c478bd9Sstevel@tonic-gate } 2898*7c478bd9Sstevel@tonic-gate 2899*7c478bd9Sstevel@tonic-gate /* 2900*7c478bd9Sstevel@tonic-gate * LcpEchoTimeout - Timer expired on the LCP echo 2901*7c478bd9Sstevel@tonic-gate */ 2902*7c478bd9Sstevel@tonic-gate 2903*7c478bd9Sstevel@tonic-gate static void 2904*7c478bd9Sstevel@tonic-gate LcpEchoTimeout (arg) 2905*7c478bd9Sstevel@tonic-gate void *arg; 2906*7c478bd9Sstevel@tonic-gate { 2907*7c478bd9Sstevel@tonic-gate if (lcp_echo_timer_running != 0) { 2908*7c478bd9Sstevel@tonic-gate lcp_echo_timer_running = 0; 2909*7c478bd9Sstevel@tonic-gate LcpEchoCheck ((fsm *) arg); 2910*7c478bd9Sstevel@tonic-gate } 2911*7c478bd9Sstevel@tonic-gate } 2912*7c478bd9Sstevel@tonic-gate 2913*7c478bd9Sstevel@tonic-gate /* 2914*7c478bd9Sstevel@tonic-gate * LcpEchoReply - LCP has received a reply to the echo 2915*7c478bd9Sstevel@tonic-gate */ 2916*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 2917*7c478bd9Sstevel@tonic-gate static int 2918*7c478bd9Sstevel@tonic-gate lcp_received_echo_reply (f, id, inp, len) 2919*7c478bd9Sstevel@tonic-gate fsm *f; 2920*7c478bd9Sstevel@tonic-gate int id; 2921*7c478bd9Sstevel@tonic-gate u_char *inp; 2922*7c478bd9Sstevel@tonic-gate int len; 2923*7c478bd9Sstevel@tonic-gate { 2924*7c478bd9Sstevel@tonic-gate u_int32_t magic; 2925*7c478bd9Sstevel@tonic-gate static int sayonce = 1; 2926*7c478bd9Sstevel@tonic-gate 2927*7c478bd9Sstevel@tonic-gate /* Check the magic number - don't count replies from ourselves. */ 2928*7c478bd9Sstevel@tonic-gate if (len < 4) { 2929*7c478bd9Sstevel@tonic-gate dbglog("lcp: received short Echo-Reply, length %d", len); 2930*7c478bd9Sstevel@tonic-gate return (0); 2931*7c478bd9Sstevel@tonic-gate } 2932*7c478bd9Sstevel@tonic-gate GETLONG(magic, inp); 2933*7c478bd9Sstevel@tonic-gate if (lcp_gotoptions[f->unit].neg_magicnumber && 2934*7c478bd9Sstevel@tonic-gate magic == lcp_gotoptions[f->unit].magicnumber) { 2935*7c478bd9Sstevel@tonic-gate warn("appear to have received our own echo-reply!"); 2936*7c478bd9Sstevel@tonic-gate return (0); 2937*7c478bd9Sstevel@tonic-gate } 2938*7c478bd9Sstevel@tonic-gate 2939*7c478bd9Sstevel@tonic-gate /* Reset the number of outstanding echo frames */ 2940*7c478bd9Sstevel@tonic-gate lcp_echos_pending = 0; 2941*7c478bd9Sstevel@tonic-gate 2942*7c478bd9Sstevel@tonic-gate if (!sync_serial && lcp_echo_number <= ACCM_TEST_FAILS && sayonce && 2943*7c478bd9Sstevel@tonic-gate use_accm_test != 0) { 2944*7c478bd9Sstevel@tonic-gate dbglog("lcp: validated asyncmap setting"); 2945*7c478bd9Sstevel@tonic-gate sayonce = 0; 2946*7c478bd9Sstevel@tonic-gate if (lcp_echo_fails == 0) 2947*7c478bd9Sstevel@tonic-gate lcp_echo_interval = 0; 2948*7c478bd9Sstevel@tonic-gate } 2949*7c478bd9Sstevel@tonic-gate return (1); 2950*7c478bd9Sstevel@tonic-gate } 2951*7c478bd9Sstevel@tonic-gate 2952*7c478bd9Sstevel@tonic-gate /* 2953*7c478bd9Sstevel@tonic-gate * LcpSendEchoRequest - Send an echo request frame to the peer 2954*7c478bd9Sstevel@tonic-gate */ 2955*7c478bd9Sstevel@tonic-gate 2956*7c478bd9Sstevel@tonic-gate static void 2957*7c478bd9Sstevel@tonic-gate LcpSendEchoRequest (f) 2958*7c478bd9Sstevel@tonic-gate fsm *f; 2959*7c478bd9Sstevel@tonic-gate { 2960*7c478bd9Sstevel@tonic-gate u_int32_t lcp_magic; 2961*7c478bd9Sstevel@tonic-gate u_char pkt[4+256], *pktp; 2962*7c478bd9Sstevel@tonic-gate int i; 2963*7c478bd9Sstevel@tonic-gate 2964*7c478bd9Sstevel@tonic-gate /* 2965*7c478bd9Sstevel@tonic-gate * Detect the failure of the peer at this point. 2966*7c478bd9Sstevel@tonic-gate */ 2967*7c478bd9Sstevel@tonic-gate if ((lcp_echo_fails != 0 && lcp_echos_pending >= lcp_echo_fails) || 2968*7c478bd9Sstevel@tonic-gate (!sync_serial && lcp_echos_pending >= ACCM_TEST_FAILS && 2969*7c478bd9Sstevel@tonic-gate use_accm_test != 0)) { 2970*7c478bd9Sstevel@tonic-gate LcpLinkFailure(f); 2971*7c478bd9Sstevel@tonic-gate lcp_echos_pending = 0; 2972*7c478bd9Sstevel@tonic-gate lcp_echo_badreplies = 0; 2973*7c478bd9Sstevel@tonic-gate } 2974*7c478bd9Sstevel@tonic-gate 2975*7c478bd9Sstevel@tonic-gate /* 2976*7c478bd9Sstevel@tonic-gate * Make and send the echo request frame. 2977*7c478bd9Sstevel@tonic-gate */ 2978*7c478bd9Sstevel@tonic-gate if (f->state == OPENED) { 2979*7c478bd9Sstevel@tonic-gate lcp_magic = lcp_gotoptions[f->unit].magicnumber; 2980*7c478bd9Sstevel@tonic-gate pktp = pkt; 2981*7c478bd9Sstevel@tonic-gate PUTLONG(lcp_magic, pktp); 2982*7c478bd9Sstevel@tonic-gate /* Send some test packets so we can fail the link early. */ 2983*7c478bd9Sstevel@tonic-gate if (!sync_serial && lcp_echo_number <= ACCM_TEST_FAILS) { 2984*7c478bd9Sstevel@tonic-gate switch (use_accm_test) { 2985*7c478bd9Sstevel@tonic-gate case 1: 2986*7c478bd9Sstevel@tonic-gate /* Only the characters covered by negotiated ACCM */ 2987*7c478bd9Sstevel@tonic-gate for (i = 0; i < 32; i++) 2988*7c478bd9Sstevel@tonic-gate *pktp++ = i; 2989*7c478bd9Sstevel@tonic-gate break; 2990*7c478bd9Sstevel@tonic-gate case 2: 2991*7c478bd9Sstevel@tonic-gate /* All characters */ 2992*7c478bd9Sstevel@tonic-gate for (i = 0; i < 256; i++) 2993*7c478bd9Sstevel@tonic-gate *pktp++ = i; 2994*7c478bd9Sstevel@tonic-gate break; 2995*7c478bd9Sstevel@tonic-gate } 2996*7c478bd9Sstevel@tonic-gate } 2997*7c478bd9Sstevel@tonic-gate fsm_sdata(f, CODE_ECHOREQ, lcp_echo_number++ & 0xFF, pkt, pktp - pkt); 2998*7c478bd9Sstevel@tonic-gate ++lcp_echos_pending; 2999*7c478bd9Sstevel@tonic-gate } 3000*7c478bd9Sstevel@tonic-gate } 3001*7c478bd9Sstevel@tonic-gate 3002*7c478bd9Sstevel@tonic-gate /* 3003*7c478bd9Sstevel@tonic-gate * lcp_echo_lowerup - Start the timer for the LCP frame 3004*7c478bd9Sstevel@tonic-gate */ 3005*7c478bd9Sstevel@tonic-gate 3006*7c478bd9Sstevel@tonic-gate static void 3007*7c478bd9Sstevel@tonic-gate lcp_echo_lowerup (unit) 3008*7c478bd9Sstevel@tonic-gate int unit; 3009*7c478bd9Sstevel@tonic-gate { 3010*7c478bd9Sstevel@tonic-gate fsm *f = &lcp_fsm[unit]; 3011*7c478bd9Sstevel@tonic-gate 3012*7c478bd9Sstevel@tonic-gate /* Clear the parameters for generating echo frames */ 3013*7c478bd9Sstevel@tonic-gate lcp_echos_pending = 0; 3014*7c478bd9Sstevel@tonic-gate lcp_echo_number = 0; 3015*7c478bd9Sstevel@tonic-gate lcp_echo_timer_running = 0; 3016*7c478bd9Sstevel@tonic-gate 3017*7c478bd9Sstevel@tonic-gate /* If a timeout interval is specified then start the timer */ 3018*7c478bd9Sstevel@tonic-gate LcpEchoCheck(f); 3019*7c478bd9Sstevel@tonic-gate } 3020*7c478bd9Sstevel@tonic-gate 3021*7c478bd9Sstevel@tonic-gate /* 3022*7c478bd9Sstevel@tonic-gate * lcp_echo_lowerdown - Stop the timer for the LCP frame 3023*7c478bd9Sstevel@tonic-gate */ 3024*7c478bd9Sstevel@tonic-gate 3025*7c478bd9Sstevel@tonic-gate static void 3026*7c478bd9Sstevel@tonic-gate lcp_echo_lowerdown (unit) 3027*7c478bd9Sstevel@tonic-gate int unit; 3028*7c478bd9Sstevel@tonic-gate { 3029*7c478bd9Sstevel@tonic-gate fsm *f = &lcp_fsm[unit]; 3030*7c478bd9Sstevel@tonic-gate 3031*7c478bd9Sstevel@tonic-gate if (lcp_echo_timer_running != 0) { 3032*7c478bd9Sstevel@tonic-gate UNTIMEOUT (LcpEchoTimeout, f); 3033*7c478bd9Sstevel@tonic-gate lcp_echo_timer_running = 0; 3034*7c478bd9Sstevel@tonic-gate } 3035*7c478bd9Sstevel@tonic-gate } 3036*7c478bd9Sstevel@tonic-gate 3037*7c478bd9Sstevel@tonic-gate /* 3038*7c478bd9Sstevel@tonic-gate * LcpSendIdentification - Send LCP Identification string to peer. 3039*7c478bd9Sstevel@tonic-gate */ 3040*7c478bd9Sstevel@tonic-gate 3041*7c478bd9Sstevel@tonic-gate static void 3042*7c478bd9Sstevel@tonic-gate LcpSendIdentification (f) 3043*7c478bd9Sstevel@tonic-gate fsm *f; 3044*7c478bd9Sstevel@tonic-gate { 3045*7c478bd9Sstevel@tonic-gate u_int32_t lcp_magic; 3046*7c478bd9Sstevel@tonic-gate u_char pkt[4 + sizeof(identstr)], *pktp; 3047*7c478bd9Sstevel@tonic-gate int idlen; 3048*7c478bd9Sstevel@tonic-gate 3049*7c478bd9Sstevel@tonic-gate /* 3050*7c478bd9Sstevel@tonic-gate * Make and send the Identification frame. 3051*7c478bd9Sstevel@tonic-gate */ 3052*7c478bd9Sstevel@tonic-gate if (f->state == OPENED) 3053*7c478bd9Sstevel@tonic-gate lcp_magic = lcp_gotoptions[f->unit].magicnumber; 3054*7c478bd9Sstevel@tonic-gate else 3055*7c478bd9Sstevel@tonic-gate lcp_magic = 0; 3056*7c478bd9Sstevel@tonic-gate 3057*7c478bd9Sstevel@tonic-gate pktp = pkt; 3058*7c478bd9Sstevel@tonic-gate PUTLONG(lcp_magic, pktp); 3059*7c478bd9Sstevel@tonic-gate idlen = strlen(identstr); 3060*7c478bd9Sstevel@tonic-gate BCOPY(identstr, pktp, idlen); 3061*7c478bd9Sstevel@tonic-gate INCPTR(idlen, pktp); 3062*7c478bd9Sstevel@tonic-gate fsm_sdata(f, CODE_IDENT, ++f->id, pkt, pktp - pkt); 3063*7c478bd9Sstevel@tonic-gate } 3064*7c478bd9Sstevel@tonic-gate 3065*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 3066*7c478bd9Sstevel@tonic-gate static void 3067*7c478bd9Sstevel@tonic-gate lcp_received_identification (f, id, inp, len) 3068*7c478bd9Sstevel@tonic-gate fsm *f; 3069*7c478bd9Sstevel@tonic-gate int id; 3070*7c478bd9Sstevel@tonic-gate u_char *inp; 3071*7c478bd9Sstevel@tonic-gate int len; 3072*7c478bd9Sstevel@tonic-gate { 3073*7c478bd9Sstevel@tonic-gate u_int32_t magic; 3074*7c478bd9Sstevel@tonic-gate 3075*7c478bd9Sstevel@tonic-gate /* Check the magic number - don't count replies from ourselves. */ 3076*7c478bd9Sstevel@tonic-gate if (len < 4) { 3077*7c478bd9Sstevel@tonic-gate dbglog("%s: received short Identification; %d < 4", len); 3078*7c478bd9Sstevel@tonic-gate return; 3079*7c478bd9Sstevel@tonic-gate } 3080*7c478bd9Sstevel@tonic-gate GETLONG(magic, inp); 3081*7c478bd9Sstevel@tonic-gate len -= 4; 3082*7c478bd9Sstevel@tonic-gate if (lcp_gotoptions[f->unit].neg_magicnumber && f->state == OPENED && 3083*7c478bd9Sstevel@tonic-gate magic == lcp_gotoptions[f->unit].magicnumber) { 3084*7c478bd9Sstevel@tonic-gate warn("appear to have received our own Identification!"); 3085*7c478bd9Sstevel@tonic-gate return; 3086*7c478bd9Sstevel@tonic-gate } 3087*7c478bd9Sstevel@tonic-gate if (len > 0 && (len > 1 || *inp != '\0')) 3088*7c478bd9Sstevel@tonic-gate notice("Peer Identification: %0.*v", len, inp); 3089*7c478bd9Sstevel@tonic-gate } 3090*7c478bd9Sstevel@tonic-gate 3091*7c478bd9Sstevel@tonic-gate /* 3092*7c478bd9Sstevel@tonic-gate * Send a Time-Remaining LCP packet. We don't include a message. 3093*7c478bd9Sstevel@tonic-gate */ 3094*7c478bd9Sstevel@tonic-gate static void 3095*7c478bd9Sstevel@tonic-gate LcpSendTimeRemaining(f, time_remaining) 3096*7c478bd9Sstevel@tonic-gate fsm *f; 3097*7c478bd9Sstevel@tonic-gate u_int32_t time_remaining; 3098*7c478bd9Sstevel@tonic-gate { 3099*7c478bd9Sstevel@tonic-gate u_int32_t lcp_magic; 3100*7c478bd9Sstevel@tonic-gate u_char pkt[8]; 3101*7c478bd9Sstevel@tonic-gate u_char *pktp; 3102*7c478bd9Sstevel@tonic-gate 3103*7c478bd9Sstevel@tonic-gate if (f->state != OPENED) 3104*7c478bd9Sstevel@tonic-gate return; 3105*7c478bd9Sstevel@tonic-gate 3106*7c478bd9Sstevel@tonic-gate lcp_magic = lcp_gotoptions[f->unit].magicnumber; 3107*7c478bd9Sstevel@tonic-gate pktp = pkt; 3108*7c478bd9Sstevel@tonic-gate PUTLONG(lcp_magic, pktp); 3109*7c478bd9Sstevel@tonic-gate PUTLONG(time_remaining, pktp); 3110*7c478bd9Sstevel@tonic-gate fsm_sdata(f, CODE_TIMEREMAIN, ++f->id, pkt, pktp - pkt); 3111*7c478bd9Sstevel@tonic-gate } 3112*7c478bd9Sstevel@tonic-gate 3113*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 3114*7c478bd9Sstevel@tonic-gate static void 3115*7c478bd9Sstevel@tonic-gate lcp_received_timeremain(f, id, inp, len) 3116*7c478bd9Sstevel@tonic-gate fsm *f; 3117*7c478bd9Sstevel@tonic-gate int id; 3118*7c478bd9Sstevel@tonic-gate u_char *inp; 3119*7c478bd9Sstevel@tonic-gate int len; 3120*7c478bd9Sstevel@tonic-gate { 3121*7c478bd9Sstevel@tonic-gate u_int32_t magic; 3122*7c478bd9Sstevel@tonic-gate u_int32_t time_remaining; 3123*7c478bd9Sstevel@tonic-gate 3124*7c478bd9Sstevel@tonic-gate /* Check the magic number - don't count replies from ourselves. */ 3125*7c478bd9Sstevel@tonic-gate if (len < 8) { 3126*7c478bd9Sstevel@tonic-gate dbglog("%s: received short Time-Remain; %d < 8", len); 3127*7c478bd9Sstevel@tonic-gate return; 3128*7c478bd9Sstevel@tonic-gate } 3129*7c478bd9Sstevel@tonic-gate GETLONG(magic, inp); 3130*7c478bd9Sstevel@tonic-gate if (lcp_gotoptions[f->unit].neg_magicnumber && f->state == OPENED && 3131*7c478bd9Sstevel@tonic-gate magic == lcp_gotoptions[f->unit].magicnumber) { 3132*7c478bd9Sstevel@tonic-gate warn("appear to have received our own Time-Remain!"); 3133*7c478bd9Sstevel@tonic-gate return; 3134*7c478bd9Sstevel@tonic-gate } 3135*7c478bd9Sstevel@tonic-gate GETLONG(time_remaining, inp); 3136*7c478bd9Sstevel@tonic-gate if (len > 8) { 3137*7c478bd9Sstevel@tonic-gate notice("%d seconds remain: \"%.*s\"", time_remaining, 3138*7c478bd9Sstevel@tonic-gate len-8, inp); 3139*7c478bd9Sstevel@tonic-gate } else { 3140*7c478bd9Sstevel@tonic-gate notice("Time Remaining: %d seconds", time_remaining); 3141*7c478bd9Sstevel@tonic-gate } 3142*7c478bd9Sstevel@tonic-gate } 3143*7c478bd9Sstevel@tonic-gate 3144*7c478bd9Sstevel@tonic-gate /* 3145*7c478bd9Sstevel@tonic-gate * lcp_timeremaining - timeout handler which sends LCP Time-Remaining 3146*7c478bd9Sstevel@tonic-gate * packet. 3147*7c478bd9Sstevel@tonic-gate */ 3148*7c478bd9Sstevel@tonic-gate static void 3149*7c478bd9Sstevel@tonic-gate lcp_timeremaining(arg) 3150*7c478bd9Sstevel@tonic-gate void *arg; 3151*7c478bd9Sstevel@tonic-gate { 3152*7c478bd9Sstevel@tonic-gate struct lcp_timer *lt = (struct lcp_timer *)arg; 3153*7c478bd9Sstevel@tonic-gate u_int32_t time_remaining; 3154*7c478bd9Sstevel@tonic-gate int unit; 3155*7c478bd9Sstevel@tonic-gate 3156*7c478bd9Sstevel@tonic-gate unit = lt->unit; 3157*7c478bd9Sstevel@tonic-gate time_remaining = lt->tr; 3158*7c478bd9Sstevel@tonic-gate LcpSendTimeRemaining(&lcp_fsm[unit], time_remaining); 3159*7c478bd9Sstevel@tonic-gate free(lt); 3160*7c478bd9Sstevel@tonic-gate } 3161*7c478bd9Sstevel@tonic-gate 3162*7c478bd9Sstevel@tonic-gate /* 3163*7c478bd9Sstevel@tonic-gate * lcp_settimeremaining - set a timeout to send an LCP Time-Remaining 3164*7c478bd9Sstevel@tonic-gate * packet. The first argument, connecttime, is the time remaining 3165*7c478bd9Sstevel@tonic-gate * at the time this function is called. The second argument is the 3166*7c478bd9Sstevel@tonic-gate * desired time remaining when the packet should be sent out. 3167*7c478bd9Sstevel@tonic-gate */ 3168*7c478bd9Sstevel@tonic-gate void 3169*7c478bd9Sstevel@tonic-gate lcp_settimeremaining(unit, connecttime, time_remaining) 3170*7c478bd9Sstevel@tonic-gate int unit; 3171*7c478bd9Sstevel@tonic-gate u_int32_t connecttime; 3172*7c478bd9Sstevel@tonic-gate u_int32_t time_remaining; 3173*7c478bd9Sstevel@tonic-gate { 3174*7c478bd9Sstevel@tonic-gate struct lcp_timer *lt; 3175*7c478bd9Sstevel@tonic-gate 3176*7c478bd9Sstevel@tonic-gate if (connecttime == time_remaining) { 3177*7c478bd9Sstevel@tonic-gate LcpSendTimeRemaining(&lcp_fsm[unit], time_remaining); 3178*7c478bd9Sstevel@tonic-gate } else { 3179*7c478bd9Sstevel@tonic-gate lt = (struct lcp_timer *)malloc(sizeof (struct lcp_timer)); 3180*7c478bd9Sstevel@tonic-gate lt->unit = unit; 3181*7c478bd9Sstevel@tonic-gate lt->tr = time_remaining; 3182*7c478bd9Sstevel@tonic-gate TIMEOUT(lcp_timeremaining, (void *)lt, connecttime - time_remaining); 3183*7c478bd9Sstevel@tonic-gate } 3184*7c478bd9Sstevel@tonic-gate } 3185