17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * lcp.c - PPP Link Control Protocol. 37c478bd9Sstevel@tonic-gate * 4f53eecf5SJames Carlson * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 57c478bd9Sstevel@tonic-gate * Use is subject to license terms. 67c478bd9Sstevel@tonic-gate * 77c478bd9Sstevel@tonic-gate * Copyright (c) 1989 Carnegie Mellon University. 87c478bd9Sstevel@tonic-gate * All rights reserved. 97c478bd9Sstevel@tonic-gate * 10*48bbca81SDaniel Hoffman * Copyright (c) 2016 by Delphix. All rights reserved. 11*48bbca81SDaniel Hoffman * 127c478bd9Sstevel@tonic-gate * Redistribution and use in source and binary forms are permitted 137c478bd9Sstevel@tonic-gate * provided that the above copyright notice and this paragraph are 147c478bd9Sstevel@tonic-gate * duplicated in all such forms and that any documentation, 157c478bd9Sstevel@tonic-gate * advertising materials, and other materials related to such 167c478bd9Sstevel@tonic-gate * distribution and use acknowledge that the software was developed 177c478bd9Sstevel@tonic-gate * by Carnegie Mellon University. The name of the 187c478bd9Sstevel@tonic-gate * University may not be used to endorse or promote products derived 197c478bd9Sstevel@tonic-gate * from this software without specific prior written permission. 207c478bd9Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 217c478bd9Sstevel@tonic-gate * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 227c478bd9Sstevel@tonic-gate * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 237c478bd9Sstevel@tonic-gate */ 247c478bd9Sstevel@tonic-gate 257c478bd9Sstevel@tonic-gate #define RCSID "$Id: lcp.c,v 1.54 2000/04/27 03:51:18 masputra Exp $" 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /* 287c478bd9Sstevel@tonic-gate * TODO: 297c478bd9Sstevel@tonic-gate */ 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #include <stdio.h> 327c478bd9Sstevel@tonic-gate #include <string.h> 337c478bd9Sstevel@tonic-gate #include <stdlib.h> 347c478bd9Sstevel@tonic-gate #include <ctype.h> 357c478bd9Sstevel@tonic-gate #if defined(CHAPMS) || defined(CHAPMSV2) 367c478bd9Sstevel@tonic-gate #ifdef HAVE_CRYPT_H 377c478bd9Sstevel@tonic-gate #include <crypt.h> 387c478bd9Sstevel@tonic-gate #endif 397c478bd9Sstevel@tonic-gate #ifndef USE_CRYPT 407c478bd9Sstevel@tonic-gate #include <des.h> 417c478bd9Sstevel@tonic-gate #endif 427c478bd9Sstevel@tonic-gate #ifdef SOL2 437c478bd9Sstevel@tonic-gate #include <errno.h> 447c478bd9Sstevel@tonic-gate #endif 457c478bd9Sstevel@tonic-gate #endif 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate #include "pppd.h" 487c478bd9Sstevel@tonic-gate #include "fsm.h" 497c478bd9Sstevel@tonic-gate #include "lcp.h" 507c478bd9Sstevel@tonic-gate #include "chap.h" 517c478bd9Sstevel@tonic-gate #include "magic.h" 527c478bd9Sstevel@tonic-gate #include "patchlevel.h" 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate #if !defined(lint) && !defined(_lint) 557c478bd9Sstevel@tonic-gate static const char rcsid[] = RCSID; 567c478bd9Sstevel@tonic-gate #endif 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate /* 597c478bd9Sstevel@tonic-gate * Special failure codes for logging link failure reasons. 607c478bd9Sstevel@tonic-gate */ 617c478bd9Sstevel@tonic-gate bool peer_nak_auth; /* Peer sent nak for our auth request */ 627c478bd9Sstevel@tonic-gate u_short nak_auth_orig; /* Auth proto peer naked */ 637c478bd9Sstevel@tonic-gate u_short nak_auth_proto; /* Auth proto peer suggested instead */ 647c478bd9Sstevel@tonic-gate bool unsolicited_nak_auth; /* Peer asked us to authenticate */ 657c478bd9Sstevel@tonic-gate u_short unsolicit_auth_proto; /* Auth proto peer wants */ 667c478bd9Sstevel@tonic-gate bool peer_reject_auth; /* Peer sent reject for auth */ 677c478bd9Sstevel@tonic-gate u_short reject_auth_proto; /* Protocol that peer rejected */ 687c478bd9Sstevel@tonic-gate bool rejected_peers_auth; /* We sent a reject to the peer */ 697c478bd9Sstevel@tonic-gate u_short rejected_auth_proto; /* Protocol that peer wanted to use */ 707c478bd9Sstevel@tonic-gate bool naked_peers_auth; /* We sent a nak to the peer */ 717c478bd9Sstevel@tonic-gate u_short naked_auth_orig; /* Protocol that we wanted to use */ 727c478bd9Sstevel@tonic-gate u_short naked_auth_proto; /* Protocol that peer wants us to use */ 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate /* 757c478bd9Sstevel@tonic-gate * LCP-related command-line options. 767c478bd9Sstevel@tonic-gate */ 777c478bd9Sstevel@tonic-gate int lcp_echo_interval = 0; /* Interval between LCP echo-requests */ 787c478bd9Sstevel@tonic-gate int lcp_echo_fails = 0; /* Tolerance to unanswered echo-requests */ 797c478bd9Sstevel@tonic-gate bool lax_recv = 0; /* accept control chars in asyncmap */ 807c478bd9Sstevel@tonic-gate static int use_accm_test = 2; /* use big echo-requests to check ACCM */ 817c478bd9Sstevel@tonic-gate #define ACCM_TEST_FAILS 5 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate #define _tostr2(x) #x 847c478bd9Sstevel@tonic-gate #define _tostr(x) _tostr2(x) 857c478bd9Sstevel@tonic-gate static char identstr[256] = /* Identification string */ 867c478bd9Sstevel@tonic-gate "ppp-" VERSION "." _tostr(PATCHLEVEL) IMPLEMENTATION; 877c478bd9Sstevel@tonic-gate static int noident = 0; /* 1 to disable; 2 to reject */ 887c478bd9Sstevel@tonic-gate static int sentident = 0; /* counts the # of ident codes sent */ 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate /* set if we're allowed to send an unsolicited Configure-Nak for MRU. */ 917c478bd9Sstevel@tonic-gate static bool unsolicit_mru; 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate static int setescape __P((char **, option_t *)); 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate static bool do_msft_workaround = 1; 967c478bd9Sstevel@tonic-gate static int setasyncmap __P((char **, option_t *)); 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate bool noendpoint = 0; /* don't send/accept endpoint discriminator */ 997c478bd9Sstevel@tonic-gate static int setendpoint __P((char **, option_t *)); 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate static char *callback_strings[] = { 1027c478bd9Sstevel@tonic-gate "auth", "dialstring", "location", "E.164", "X.500", "", "CBCP", NULL 1037c478bd9Sstevel@tonic-gate }; 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate /* This is used in packet printing even if NEGOTIATE_FCS isn't enabled */ 1067c478bd9Sstevel@tonic-gate static char *fcsalt_strings[] = { 1077c478bd9Sstevel@tonic-gate "null", "crc16", "crc32", NULL 1087c478bd9Sstevel@tonic-gate }; 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate #ifdef NEGOTIATE_FCS 1117c478bd9Sstevel@tonic-gate static int setfcsallow __P((char **, option_t *)); 1127c478bd9Sstevel@tonic-gate static int setfcswant __P((char **, option_t *)); 1137c478bd9Sstevel@tonic-gate #endif 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate /* Backward compatibility for Linux */ 1167c478bd9Sstevel@tonic-gate #ifndef PPP_MAXMRU 1177c478bd9Sstevel@tonic-gate #define PPP_MTU 1500 /* Default MTU (size of Info field) */ 1187c478bd9Sstevel@tonic-gate #define PPP_MAXMTU 65535 - (PPP_HDRLEN + PPP_FCSLEN) 1197c478bd9Sstevel@tonic-gate #define PPP_MINMTU 64 1207c478bd9Sstevel@tonic-gate #define PPP_MAXMRU 65000 /* Largest MRU we allow */ 1217c478bd9Sstevel@tonic-gate #define PPP_MINMRU 128 1227c478bd9Sstevel@tonic-gate #endif 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate static option_t lcp_option_list[] = { 1257c478bd9Sstevel@tonic-gate /* LCP options */ 1267c478bd9Sstevel@tonic-gate { "noaccomp", o_bool, &lcp_wantoptions[0].neg_accompression, 1277c478bd9Sstevel@tonic-gate "Disable address/control compression", 1287c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_accompression }, 1297c478bd9Sstevel@tonic-gate { "-ac", o_bool, &lcp_wantoptions[0].neg_accompression, 1307c478bd9Sstevel@tonic-gate "Disable address/control compression", 1317c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_accompression }, 1327c478bd9Sstevel@tonic-gate { "default-asyncmap", o_bool, &lcp_wantoptions[0].neg_asyncmap, 1337c478bd9Sstevel@tonic-gate "Disable asyncmap negotiation", 1347c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_asyncmap }, 1357c478bd9Sstevel@tonic-gate { "-am", o_bool, &lcp_wantoptions[0].neg_asyncmap, 1367c478bd9Sstevel@tonic-gate "Disable asyncmap negotiation", 1377c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_asyncmap }, 1387c478bd9Sstevel@tonic-gate { "asyncmap", o_special, (void *)setasyncmap, 1397c478bd9Sstevel@tonic-gate "Set asyncmap (for received packets)" }, 1407c478bd9Sstevel@tonic-gate { "-as", o_special, (void *)setasyncmap, 1417c478bd9Sstevel@tonic-gate "Set asyncmap (for received packets)" }, 1427c478bd9Sstevel@tonic-gate { "nomagic", o_bool, &lcp_wantoptions[0].neg_magicnumber, 1437c478bd9Sstevel@tonic-gate "Disable magic number option (looped-back line detect)", 1447c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_magicnumber }, 1457c478bd9Sstevel@tonic-gate { "-mn", o_bool, &lcp_wantoptions[0].neg_magicnumber, 1467c478bd9Sstevel@tonic-gate "Disable magic number option (looped-back line detect)", 1477c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_magicnumber }, 1487c478bd9Sstevel@tonic-gate { "default-mru", o_bool, &lcp_wantoptions[0].neg_mru, 1497c478bd9Sstevel@tonic-gate "Disable MRU negotiation (use default 1500)", 1507c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_mru }, 1517c478bd9Sstevel@tonic-gate { "-mru", o_bool, &lcp_wantoptions[0].neg_mru, 1527c478bd9Sstevel@tonic-gate "Disable MRU negotiation (use default 1500)", 1537c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_mru }, 1547c478bd9Sstevel@tonic-gate { "mru", o_int, &lcp_wantoptions[0].mru, 1557c478bd9Sstevel@tonic-gate "Set MRU (maximum received packet size) for negotiation", 1567c478bd9Sstevel@tonic-gate OPT_LIMITS, &lcp_wantoptions[0].neg_mru, PPP_MAXMRU, PPP_MINMRU }, 1577c478bd9Sstevel@tonic-gate { "mtu", o_int, &lcp_allowoptions[0].mru, 1587c478bd9Sstevel@tonic-gate "Set our MTU", OPT_LIMITS|OPT_A2COPY, &lcp_allowoptions[0].mrru, 1597c478bd9Sstevel@tonic-gate PPP_MAXMTU, PPP_MINMTU }, 1607c478bd9Sstevel@tonic-gate { "nopcomp", o_bool, &lcp_wantoptions[0].neg_pcompression, 1617c478bd9Sstevel@tonic-gate "Disable protocol field compression", 1627c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_pcompression }, 1637c478bd9Sstevel@tonic-gate { "-pc", o_bool, &lcp_wantoptions[0].neg_pcompression, 1647c478bd9Sstevel@tonic-gate "Disable protocol field compression", 1657c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_pcompression }, 1667c478bd9Sstevel@tonic-gate { "-p", o_bool, &lcp_wantoptions[0].passive, 1677c478bd9Sstevel@tonic-gate "Set passive mode", 1 }, 1687c478bd9Sstevel@tonic-gate { "passive", o_bool, &lcp_wantoptions[0].passive, 1697c478bd9Sstevel@tonic-gate "Set passive mode", 1 }, 1707c478bd9Sstevel@tonic-gate { "silent", o_bool, &lcp_wantoptions[0].silent, 1717c478bd9Sstevel@tonic-gate "Set silent mode", 1 }, 1727c478bd9Sstevel@tonic-gate { "escape", o_special, (void *)setescape, 1737c478bd9Sstevel@tonic-gate "List of character codes to escape on transmission" }, 1747c478bd9Sstevel@tonic-gate { "lcp-echo-failure", o_int, &lcp_echo_fails, 1757c478bd9Sstevel@tonic-gate "Number of consecutive echo failures for link failure" }, 1767c478bd9Sstevel@tonic-gate { "lcp-echo-interval", o_int, &lcp_echo_interval, 1777c478bd9Sstevel@tonic-gate "Set time in seconds between LCP echo requests" }, 1787c478bd9Sstevel@tonic-gate { "no-accm-test", o_int, &use_accm_test, 1797c478bd9Sstevel@tonic-gate "Disable use of LCP Echo-Request asyncmap checking", 1807c478bd9Sstevel@tonic-gate OPT_NOARG|OPT_VAL(0) }, 1817c478bd9Sstevel@tonic-gate { "small-accm-test", o_int, &use_accm_test, 1827c478bd9Sstevel@tonic-gate "Use only small Echo-Requests for asyncmap checking", 1837c478bd9Sstevel@tonic-gate OPT_NOARG|OPT_VAL(1) }, 1847c478bd9Sstevel@tonic-gate { "lcp-restart", o_int, &lcp_fsm[0].timeouttime, 1857c478bd9Sstevel@tonic-gate "Set time in seconds between LCP retransmissions" }, 1867c478bd9Sstevel@tonic-gate { "lcp-max-terminate", o_int, &lcp_fsm[0].maxtermtransmits, 1877c478bd9Sstevel@tonic-gate "Maximum number of LCP terminate-request transmissions" }, 1887c478bd9Sstevel@tonic-gate { "lcp-max-configure", o_int, &lcp_fsm[0].maxconfreqtransmits, 1897c478bd9Sstevel@tonic-gate "Maximum number of LCP configure-request transmissions" }, 1907c478bd9Sstevel@tonic-gate { "lcp-max-failure", o_int, &lcp_fsm[0].maxnakloops, 1917c478bd9Sstevel@tonic-gate "Set limit on number of LCP configure-naks" }, 1927c478bd9Sstevel@tonic-gate { "receive-all", o_bool, &lax_recv, 1937c478bd9Sstevel@tonic-gate "Accept all received control characters", 1 }, 1947c478bd9Sstevel@tonic-gate #ifdef HAVE_MULTILINK 1957c478bd9Sstevel@tonic-gate { "mrru", o_int, &lcp_wantoptions[0].mrru, 1967c478bd9Sstevel@tonic-gate "Maximum received packet size for multilink bundle", 1977c478bd9Sstevel@tonic-gate OPT_LIMITS, &lcp_wantoptions[0].neg_mrru, PPP_MAXMRU, PPP_MINMRU }, 1987c478bd9Sstevel@tonic-gate { "mpshortseq", o_bool, &lcp_wantoptions[0].neg_ssnhf, 1997c478bd9Sstevel@tonic-gate "Use short sequence numbers in multilink headers", 2007c478bd9Sstevel@tonic-gate OPT_A2COPY | 1, &lcp_allowoptions[0].neg_ssnhf }, 2017c478bd9Sstevel@tonic-gate { "nompshortseq", o_bool, &lcp_wantoptions[0].neg_ssnhf, 2027c478bd9Sstevel@tonic-gate "Don't use short sequence numbers in multilink headers", 2037c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_ssnhf }, 2047c478bd9Sstevel@tonic-gate #endif /* HAVE_MULTILINK */ 2057c478bd9Sstevel@tonic-gate { "endpoint", o_special, (void *)setendpoint, 2067c478bd9Sstevel@tonic-gate "Endpoint discriminator for multilink", }, 2077c478bd9Sstevel@tonic-gate { "noendpoint", o_bool, &noendpoint, 2087c478bd9Sstevel@tonic-gate "Don't send or accept multilink endpoint discriminator", 1 }, 2097c478bd9Sstevel@tonic-gate { "ident", o_string, identstr, 2107c478bd9Sstevel@tonic-gate "LCP Identification string", OPT_STATIC, NULL, sizeof(identstr) }, 2117c478bd9Sstevel@tonic-gate { "noident", o_int, &noident, 2127c478bd9Sstevel@tonic-gate "Disable use of LCP Identification", OPT_INC|OPT_NOARG|1 }, 2137c478bd9Sstevel@tonic-gate #ifdef NEGOTIATE_FCS 2147c478bd9Sstevel@tonic-gate { "default-fcs", o_bool, &lcp_wantoptions[0].neg_fcs, 2157c478bd9Sstevel@tonic-gate "Disable FCS Alternatives option (use default CRC-16)", 2167c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_fcs }, 2177c478bd9Sstevel@tonic-gate { "allow-fcs", o_special, (void *)setfcsallow, 2187c478bd9Sstevel@tonic-gate "Set allowable FCS types; crc16, crc32, null, or number" }, 2197c478bd9Sstevel@tonic-gate { "fcs", o_special, (void *)setfcswant, 2207c478bd9Sstevel@tonic-gate "Set FCS type(s) desired; crc16, crc32, null, or number" }, 2217c478bd9Sstevel@tonic-gate #endif 2227c478bd9Sstevel@tonic-gate #ifdef MUX_FRAME 2237c478bd9Sstevel@tonic-gate /* 2247c478bd9Sstevel@tonic-gate * if pppmux option is turned on, then the parameter to this 2257c478bd9Sstevel@tonic-gate * is time value in microseconds 2267c478bd9Sstevel@tonic-gate */ 2277c478bd9Sstevel@tonic-gate { "pppmux", o_int, &lcp_wantoptions[0].pppmux, 2287c478bd9Sstevel@tonic-gate "Set PPP Multiplexing option timer", OPT_LLIMIT | OPT_A2COPY, 2297c478bd9Sstevel@tonic-gate &lcp_allowoptions[0].pppmux, 0, 0 }, 2307c478bd9Sstevel@tonic-gate #endif 2317c478bd9Sstevel@tonic-gate {NULL} 2327c478bd9Sstevel@tonic-gate }; 2337c478bd9Sstevel@tonic-gate 2347c478bd9Sstevel@tonic-gate /* global vars */ 2357c478bd9Sstevel@tonic-gate fsm lcp_fsm[NUM_PPP]; /* LCP fsm structure (global)*/ 2367c478bd9Sstevel@tonic-gate lcp_options lcp_wantoptions[NUM_PPP]; /* Options that we want to request */ 2377c478bd9Sstevel@tonic-gate lcp_options lcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */ 2387c478bd9Sstevel@tonic-gate lcp_options lcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */ 2397c478bd9Sstevel@tonic-gate lcp_options lcp_hisoptions[NUM_PPP]; /* Options that we ack'd */ 2407c478bd9Sstevel@tonic-gate u_int32_t xmit_accm[NUM_PPP][8]; /* extended transmit ACCM */ 2417c478bd9Sstevel@tonic-gate 2427c478bd9Sstevel@tonic-gate /* 2437c478bd9Sstevel@tonic-gate * These variables allow a plugin to assert limits on the maximum 2447c478bd9Sstevel@tonic-gate * MRU/MTU values that can be negotiated. 2457c478bd9Sstevel@tonic-gate */ 2467c478bd9Sstevel@tonic-gate int absmax_mru = PPP_MAXMRU; 2477c478bd9Sstevel@tonic-gate int absmax_mtu = PPP_MAXMTU; 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate static int lcp_echos_pending = 0; /* Number of outstanding echo msgs */ 2507c478bd9Sstevel@tonic-gate static int lcp_echo_number = 0; /* ID number of next echo frame */ 2517c478bd9Sstevel@tonic-gate static int lcp_echo_timer_running = 0; /* set if a timer is running */ 252f53eecf5SJames Carlson static bool lcp_echo_accm_test = 0; /* flag if still testing ACCM */ 2537c478bd9Sstevel@tonic-gate static int lcp_echo_badreplies = 0; /* number of bad replies from peer */ 2547c478bd9Sstevel@tonic-gate /* 2557c478bd9Sstevel@tonic-gate * The maximum number of bad replies we tolerate before bringing the 2567c478bd9Sstevel@tonic-gate * link down. 2577c478bd9Sstevel@tonic-gate */ 2587c478bd9Sstevel@tonic-gate #define LCP_ECHO_MAX_BADREPLIES 10 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate /* 2617c478bd9Sstevel@tonic-gate * Callbacks for fsm code. (CI = Configuration Information) 2627c478bd9Sstevel@tonic-gate */ 2637c478bd9Sstevel@tonic-gate static void lcp_resetci __P((fsm *)); /* Reset our CI */ 2647c478bd9Sstevel@tonic-gate static int lcp_cilen __P((fsm *)); /* Return length of our CI */ 2657c478bd9Sstevel@tonic-gate static void lcp_addci __P((fsm *, u_char *, int *)); /* Add our CI to pkt */ 2667c478bd9Sstevel@tonic-gate static int lcp_ackci __P((fsm *, u_char *, int)); /* Peer ack'd our CI */ 2677c478bd9Sstevel@tonic-gate static int lcp_nakci __P((fsm *, u_char *, int)); /* Peer nak'd our CI */ 2687c478bd9Sstevel@tonic-gate static int lcp_rejci __P((fsm *, u_char *, int)); /* Peer rej'd our CI */ 2697c478bd9Sstevel@tonic-gate static int lcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv peer CI */ 2707c478bd9Sstevel@tonic-gate static void lcp_up __P((fsm *)); /* We're UP */ 2717c478bd9Sstevel@tonic-gate static void lcp_down __P((fsm *)); /* We're DOWN */ 2727c478bd9Sstevel@tonic-gate static void lcp_starting __P((fsm *)); /* We need lower layer up */ 2737c478bd9Sstevel@tonic-gate static void lcp_finished __P((fsm *)); /* We need lower layer down */ 2747c478bd9Sstevel@tonic-gate static int lcp_extcode __P((fsm *, int, int, u_char *, int)); 2757c478bd9Sstevel@tonic-gate static void lcp_rprotrej __P((fsm *, u_char *, int)); 2767c478bd9Sstevel@tonic-gate static int lcp_coderej __P((fsm *f, int code, int id, u_char *inp, int len)); 2777c478bd9Sstevel@tonic-gate 2787c478bd9Sstevel@tonic-gate /* 2797c478bd9Sstevel@tonic-gate * routines to send LCP echos to peer 2807c478bd9Sstevel@tonic-gate */ 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate static void lcp_echo_lowerup __P((int)); 2837c478bd9Sstevel@tonic-gate static void lcp_echo_lowerdown __P((int)); 2847c478bd9Sstevel@tonic-gate static void LcpEchoTimeout __P((void *)); 2857c478bd9Sstevel@tonic-gate static int lcp_received_echo_reply __P((fsm *, int, u_char *, int)); 2867c478bd9Sstevel@tonic-gate static void LcpSendEchoRequest __P((fsm *)); 2877c478bd9Sstevel@tonic-gate static void LcpLinkFailure __P((fsm *)); 2887c478bd9Sstevel@tonic-gate static void LcpEchoCheck __P((fsm *)); 2897c478bd9Sstevel@tonic-gate 2907c478bd9Sstevel@tonic-gate /* 2917c478bd9Sstevel@tonic-gate * routines to send and receive additional LCP packets described in 2927c478bd9Sstevel@tonic-gate * section 1 of rfc1570. 2937c478bd9Sstevel@tonic-gate */ 2947c478bd9Sstevel@tonic-gate static void LcpSendIdentification __P((fsm *)); 2957c478bd9Sstevel@tonic-gate static void lcp_received_identification __P((fsm *, int, u_char *, int)); 2967c478bd9Sstevel@tonic-gate static void LcpSendTimeRemaining __P((fsm *, u_int32_t)); 2977c478bd9Sstevel@tonic-gate static void lcp_timeremaining __P((void *)); 2987c478bd9Sstevel@tonic-gate static void lcp_received_timeremain __P((fsm *, int, u_char *, int)); 2997c478bd9Sstevel@tonic-gate 3007c478bd9Sstevel@tonic-gate 3017c478bd9Sstevel@tonic-gate static fsm_callbacks lcp_callbacks = { /* LCP callback routines */ 3027c478bd9Sstevel@tonic-gate lcp_resetci, /* Reset our Configuration Information */ 3037c478bd9Sstevel@tonic-gate lcp_cilen, /* Length of our Configuration Information */ 3047c478bd9Sstevel@tonic-gate lcp_addci, /* Add our Configuration Information */ 3057c478bd9Sstevel@tonic-gate lcp_ackci, /* ACK our Configuration Information */ 3067c478bd9Sstevel@tonic-gate lcp_nakci, /* NAK our Configuration Information */ 3077c478bd9Sstevel@tonic-gate lcp_rejci, /* Reject our Configuration Information */ 3087c478bd9Sstevel@tonic-gate lcp_reqci, /* Request peer's Configuration Information */ 3097c478bd9Sstevel@tonic-gate lcp_up, /* Called when fsm reaches OPENED state */ 3107c478bd9Sstevel@tonic-gate lcp_down, /* Called when fsm leaves OPENED state */ 3117c478bd9Sstevel@tonic-gate lcp_starting, /* Called when we want the lower layer up */ 3127c478bd9Sstevel@tonic-gate lcp_finished, /* Called when we want the lower layer down */ 3137c478bd9Sstevel@tonic-gate NULL, /* Retransmission is necessary */ 3147c478bd9Sstevel@tonic-gate lcp_extcode, /* Called to handle LCP-specific codes */ 3157c478bd9Sstevel@tonic-gate "LCP", /* String name of protocol */ 3167c478bd9Sstevel@tonic-gate lcp_coderej, /* Peer rejected a code number */ 3177c478bd9Sstevel@tonic-gate }; 3187c478bd9Sstevel@tonic-gate 3197c478bd9Sstevel@tonic-gate /* 3207c478bd9Sstevel@tonic-gate * Protocol entry points. 3217c478bd9Sstevel@tonic-gate * Some of these are called directly. 3227c478bd9Sstevel@tonic-gate */ 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate static void lcp_init __P((int)); 3257c478bd9Sstevel@tonic-gate static void lcp_input __P((int, u_char *, int)); 3267c478bd9Sstevel@tonic-gate static void lcp_protrej __P((int)); 3277c478bd9Sstevel@tonic-gate static int lcp_printpkt __P((u_char *, int, 3287c478bd9Sstevel@tonic-gate void (*) __P((void *, const char *, ...)), void *)); 3297c478bd9Sstevel@tonic-gate 3307c478bd9Sstevel@tonic-gate 3317c478bd9Sstevel@tonic-gate struct protent lcp_protent = { 3327c478bd9Sstevel@tonic-gate PPP_LCP, /* Protocol Number for LCP */ 3337c478bd9Sstevel@tonic-gate lcp_init, /* Initializes LCP */ 3347c478bd9Sstevel@tonic-gate lcp_input, /* Processes a received LCP packet */ 3357c478bd9Sstevel@tonic-gate lcp_protrej, /* Process a received Protocol-reject */ 3367c478bd9Sstevel@tonic-gate lcp_lowerup, /* Called after the serial device has been set up */ 3377c478bd9Sstevel@tonic-gate lcp_lowerdown, /* Called when the link is brought down */ 3387c478bd9Sstevel@tonic-gate lcp_open, /* Called after lcp_lowerup when bringing up the link */ 3397c478bd9Sstevel@tonic-gate lcp_close, /* Called when the link goes down */ 3407c478bd9Sstevel@tonic-gate lcp_printpkt, /* Print a packet in human readable form */ 3417c478bd9Sstevel@tonic-gate NULL, /* Process a received data packet */ 3427c478bd9Sstevel@tonic-gate 1, /* LCP is enabled by default */ 3437c478bd9Sstevel@tonic-gate "LCP", /* Name of the protocol */ 3447c478bd9Sstevel@tonic-gate NULL, /* Name of the corresponding data protocol */ 3457c478bd9Sstevel@tonic-gate lcp_option_list, /* List of LCP command-line options */ 3467c478bd9Sstevel@tonic-gate NULL, /* Assigns default values for options */ 3477c478bd9Sstevel@tonic-gate NULL, /* Configures demand-dial */ 3487c478bd9Sstevel@tonic-gate NULL /* Bring up the link for this packet? */ 3497c478bd9Sstevel@tonic-gate }; 3507c478bd9Sstevel@tonic-gate 3517c478bd9Sstevel@tonic-gate int lcp_loopbackfail = DEFLOOPBACKFAIL; 3527c478bd9Sstevel@tonic-gate 3537c478bd9Sstevel@tonic-gate /* 3547c478bd9Sstevel@tonic-gate * Length of each type of configuration option (in octets) 3557c478bd9Sstevel@tonic-gate */ 3567c478bd9Sstevel@tonic-gate #define CILEN_VOID 2 3577c478bd9Sstevel@tonic-gate #define CILEN_CHAR 3 3587c478bd9Sstevel@tonic-gate #define CILEN_SHORT 4 /* CILEN_VOID + 2 */ 3597c478bd9Sstevel@tonic-gate #define CILEN_CHAP 5 /* CILEN_VOID + 2 + 1 */ 3607c478bd9Sstevel@tonic-gate #define CILEN_LONG 6 /* CILEN_VOID + 4 */ 3617c478bd9Sstevel@tonic-gate #define CILEN_LQR 8 /* CILEN_VOID + 2 + 4 */ 3627c478bd9Sstevel@tonic-gate #define CILEN_CBCP 3 3637c478bd9Sstevel@tonic-gate 3647c478bd9Sstevel@tonic-gate 3657c478bd9Sstevel@tonic-gate /* 3667c478bd9Sstevel@tonic-gate * setescape - add chars to the set we escape on transmission. 3677c478bd9Sstevel@tonic-gate */ 3687c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 3697c478bd9Sstevel@tonic-gate static int 3707c478bd9Sstevel@tonic-gate setescape(argv, opt) 3717c478bd9Sstevel@tonic-gate char **argv; 3727c478bd9Sstevel@tonic-gate option_t *opt; 3737c478bd9Sstevel@tonic-gate { 3747c478bd9Sstevel@tonic-gate int n, ret; 3757c478bd9Sstevel@tonic-gate char *p, *endp; 3767c478bd9Sstevel@tonic-gate 3777c478bd9Sstevel@tonic-gate p = *argv; 3787c478bd9Sstevel@tonic-gate ret = 1; 3797c478bd9Sstevel@tonic-gate while (*p != '\0') { 3807c478bd9Sstevel@tonic-gate n = strtol(p, &endp, 16); 3817c478bd9Sstevel@tonic-gate if (p == endp) { 3827c478bd9Sstevel@tonic-gate option_error("escape parameter contains invalid hex number '%s'", 3837c478bd9Sstevel@tonic-gate p); 3847c478bd9Sstevel@tonic-gate return 0; 3857c478bd9Sstevel@tonic-gate } 3867c478bd9Sstevel@tonic-gate p = endp; 3877c478bd9Sstevel@tonic-gate if (n < 0 || n == 0x5E || n > 0xFF) { 3887c478bd9Sstevel@tonic-gate option_error("can't escape character 0x%x", n); 3897c478bd9Sstevel@tonic-gate ret = 0; 3907c478bd9Sstevel@tonic-gate } else 3917c478bd9Sstevel@tonic-gate xmit_accm[0][n >> 5] |= 1 << (n & 0x1F); 3927c478bd9Sstevel@tonic-gate while (*p == ',' || *p == ' ') 3937c478bd9Sstevel@tonic-gate ++p; 3947c478bd9Sstevel@tonic-gate } 3957c478bd9Sstevel@tonic-gate return ret; 3967c478bd9Sstevel@tonic-gate } 3977c478bd9Sstevel@tonic-gate 3987c478bd9Sstevel@tonic-gate /* 3997c478bd9Sstevel@tonic-gate * setasyncmap - set async map negotiated 4007c478bd9Sstevel@tonic-gate */ 4017c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 4027c478bd9Sstevel@tonic-gate static int 4037c478bd9Sstevel@tonic-gate setasyncmap(argv, opt) 4047c478bd9Sstevel@tonic-gate char **argv; 4057c478bd9Sstevel@tonic-gate option_t *opt; 4067c478bd9Sstevel@tonic-gate { 4077c478bd9Sstevel@tonic-gate u_int32_t val; 4087c478bd9Sstevel@tonic-gate char *endp; 4097c478bd9Sstevel@tonic-gate 4107c478bd9Sstevel@tonic-gate val = strtoul(*argv, &endp, 16); 4117c478bd9Sstevel@tonic-gate if (*argv == endp) { 4127c478bd9Sstevel@tonic-gate option_error("invalid numeric parameter '%s' for 'asyncmap' option", 4137c478bd9Sstevel@tonic-gate *argv); 4147c478bd9Sstevel@tonic-gate return 0; 4157c478bd9Sstevel@tonic-gate } 4167c478bd9Sstevel@tonic-gate lcp_wantoptions[0].asyncmap |= val; 4177c478bd9Sstevel@tonic-gate lcp_wantoptions[0].neg_asyncmap = (~lcp_wantoptions[0].asyncmap != 0); 4187c478bd9Sstevel@tonic-gate do_msft_workaround = 0; 4197c478bd9Sstevel@tonic-gate return 1; 4207c478bd9Sstevel@tonic-gate } 4217c478bd9Sstevel@tonic-gate 4227c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 4237c478bd9Sstevel@tonic-gate static int 4247c478bd9Sstevel@tonic-gate setendpoint(argv, opt) 4257c478bd9Sstevel@tonic-gate char **argv; 4267c478bd9Sstevel@tonic-gate option_t *opt; 4277c478bd9Sstevel@tonic-gate { 4287c478bd9Sstevel@tonic-gate if (str_to_epdisc(&lcp_wantoptions[0].endpoint, *argv)) { 4297c478bd9Sstevel@tonic-gate lcp_wantoptions[0].neg_endpoint = 1; 4307c478bd9Sstevel@tonic-gate return 1; 4317c478bd9Sstevel@tonic-gate } 4327c478bd9Sstevel@tonic-gate option_error("Can't parse '%s' as an endpoint discriminator", *argv); 4337c478bd9Sstevel@tonic-gate return 0; 4347c478bd9Sstevel@tonic-gate } 4357c478bd9Sstevel@tonic-gate 4367c478bd9Sstevel@tonic-gate #ifdef NEGOTIATE_FCS 4377c478bd9Sstevel@tonic-gate static int 4387c478bd9Sstevel@tonic-gate str_to_fcstype(opt,arg) 4397c478bd9Sstevel@tonic-gate lcp_options *opt; 4407c478bd9Sstevel@tonic-gate char *arg; 4417c478bd9Sstevel@tonic-gate { 4427c478bd9Sstevel@tonic-gate char **cpp, *cp; 4437c478bd9Sstevel@tonic-gate int val, len; 4447c478bd9Sstevel@tonic-gate 4457c478bd9Sstevel@tonic-gate if (*arg != '\0') { 4467c478bd9Sstevel@tonic-gate val = 0; 4477c478bd9Sstevel@tonic-gate while (*arg != '\0') { 4487c478bd9Sstevel@tonic-gate len = 0; 4497c478bd9Sstevel@tonic-gate if (isdigit(*arg)) { 4507c478bd9Sstevel@tonic-gate len = strtol(arg, &cp, 0); 4517c478bd9Sstevel@tonic-gate if (len < 0 || len > 255 || arg == cp || 4527c478bd9Sstevel@tonic-gate (*cp != '\0' && *cp != ',')) 4537c478bd9Sstevel@tonic-gate break; 4547c478bd9Sstevel@tonic-gate val |= len; 4557c478bd9Sstevel@tonic-gate len = cp - arg; 4567c478bd9Sstevel@tonic-gate } else { 4577c478bd9Sstevel@tonic-gate for (cpp = fcsalt_strings; *cpp != NULL; cpp++) { 4587c478bd9Sstevel@tonic-gate len = strlen(*cpp); 4597c478bd9Sstevel@tonic-gate if (strncasecmp(arg, *cpp, len) == 0 && 4607c478bd9Sstevel@tonic-gate (arg[len] == '\0' || arg[len] == ',')) 4617c478bd9Sstevel@tonic-gate break; 4627c478bd9Sstevel@tonic-gate } 4637c478bd9Sstevel@tonic-gate if (*cpp == NULL) 4647c478bd9Sstevel@tonic-gate break; 4657c478bd9Sstevel@tonic-gate val |= 1<<(cpp-fcsalt_strings); 4667c478bd9Sstevel@tonic-gate } 4677c478bd9Sstevel@tonic-gate if (arg[len] == '\0') { 4687c478bd9Sstevel@tonic-gate opt->neg_fcs = 1; 4697c478bd9Sstevel@tonic-gate opt->fcs_type = val; 4707c478bd9Sstevel@tonic-gate return (1); 4717c478bd9Sstevel@tonic-gate } 4727c478bd9Sstevel@tonic-gate arg += len+1; 4737c478bd9Sstevel@tonic-gate } 4747c478bd9Sstevel@tonic-gate } 4757c478bd9Sstevel@tonic-gate option_error("Can't parse '%s' as an FCS type", arg); 4767c478bd9Sstevel@tonic-gate return (0); 4777c478bd9Sstevel@tonic-gate } 4787c478bd9Sstevel@tonic-gate 4797c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 4807c478bd9Sstevel@tonic-gate static int 4817c478bd9Sstevel@tonic-gate setfcsallow(argv, opt) 4827c478bd9Sstevel@tonic-gate char **argv; 4837c478bd9Sstevel@tonic-gate option_t *opt; 4847c478bd9Sstevel@tonic-gate { 4857c478bd9Sstevel@tonic-gate return str_to_fcstype(&lcp_allowoptions[0], *argv); 4867c478bd9Sstevel@tonic-gate } 4877c478bd9Sstevel@tonic-gate 4887c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 4897c478bd9Sstevel@tonic-gate static int 4907c478bd9Sstevel@tonic-gate setfcswant(argv, opt) 4917c478bd9Sstevel@tonic-gate char **argv; 4927c478bd9Sstevel@tonic-gate option_t *opt; 4937c478bd9Sstevel@tonic-gate { 4947c478bd9Sstevel@tonic-gate return str_to_fcstype(&lcp_wantoptions[0], *argv); 4957c478bd9Sstevel@tonic-gate } 4967c478bd9Sstevel@tonic-gate #endif 4977c478bd9Sstevel@tonic-gate 4987c478bd9Sstevel@tonic-gate /* 4997c478bd9Sstevel@tonic-gate * lcp_init - Initialize LCP. 5007c478bd9Sstevel@tonic-gate */ 5017c478bd9Sstevel@tonic-gate static void 5027c478bd9Sstevel@tonic-gate lcp_init(unit) 5037c478bd9Sstevel@tonic-gate int unit; 5047c478bd9Sstevel@tonic-gate { 5057c478bd9Sstevel@tonic-gate fsm *f = &lcp_fsm[unit]; 5067c478bd9Sstevel@tonic-gate lcp_options *wo = &lcp_wantoptions[unit]; 5077c478bd9Sstevel@tonic-gate lcp_options *ao = &lcp_allowoptions[unit]; 5087c478bd9Sstevel@tonic-gate 5097c478bd9Sstevel@tonic-gate f->unit = unit; 5107c478bd9Sstevel@tonic-gate f->protocol = PPP_LCP; 5117c478bd9Sstevel@tonic-gate f->callbacks = &lcp_callbacks; 5127c478bd9Sstevel@tonic-gate 5137c478bd9Sstevel@tonic-gate fsm_init(f); 5147c478bd9Sstevel@tonic-gate 5157c478bd9Sstevel@tonic-gate BZERO(wo, sizeof(*wo)); 5167c478bd9Sstevel@tonic-gate wo->neg_mru = 1; 5177c478bd9Sstevel@tonic-gate wo->mru = PPP_MRU; 5187c478bd9Sstevel@tonic-gate wo->neg_asyncmap = 1; 5197c478bd9Sstevel@tonic-gate wo->chap_mdtype = CHAP_DIGEST_MD5; 5207c478bd9Sstevel@tonic-gate wo->neg_magicnumber = 1; 5217c478bd9Sstevel@tonic-gate wo->neg_pcompression = 1; 5227c478bd9Sstevel@tonic-gate wo->neg_accompression = 1; 5237c478bd9Sstevel@tonic-gate 5247c478bd9Sstevel@tonic-gate /* 5257c478bd9Sstevel@tonic-gate * Leave allowed MRU (MTU) at zero; configuration option sets it 5267c478bd9Sstevel@tonic-gate * non-zero if we should nak for something else. 5277c478bd9Sstevel@tonic-gate */ 5287c478bd9Sstevel@tonic-gate BZERO(ao, sizeof(*ao)); 5297c478bd9Sstevel@tonic-gate ao->neg_mru = 1; 5307c478bd9Sstevel@tonic-gate ao->neg_asyncmap = 1; 5317c478bd9Sstevel@tonic-gate ao->neg_chap = 1; 5327c478bd9Sstevel@tonic-gate #if defined(CHAPMS) || defined(CHAPMSV2) 5337c478bd9Sstevel@tonic-gate #ifdef SOL2 5347c478bd9Sstevel@tonic-gate /* Check if DES wasn't exported */ 5357c478bd9Sstevel@tonic-gate errno = 0; 5367c478bd9Sstevel@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" 5377c478bd9Sstevel@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"); 5387c478bd9Sstevel@tonic-gate if (errno == 0) 5397c478bd9Sstevel@tonic-gate #endif 5407c478bd9Sstevel@tonic-gate { 5417c478bd9Sstevel@tonic-gate #ifdef CHAPMS 5427c478bd9Sstevel@tonic-gate ao->neg_mschap = 1; 5437c478bd9Sstevel@tonic-gate #endif 5447c478bd9Sstevel@tonic-gate #ifdef CHAPMSV2 5457c478bd9Sstevel@tonic-gate ao->neg_mschapv2 = 1; 5467c478bd9Sstevel@tonic-gate #endif 5477c478bd9Sstevel@tonic-gate } 5487c478bd9Sstevel@tonic-gate #endif 5497c478bd9Sstevel@tonic-gate ao->chap_mdtype = CHAP_DIGEST_MD5; 5507c478bd9Sstevel@tonic-gate ao->neg_upap = 1; 5517c478bd9Sstevel@tonic-gate ao->neg_magicnumber = 1; 5527c478bd9Sstevel@tonic-gate ao->neg_pcompression = 1; 5537c478bd9Sstevel@tonic-gate ao->neg_accompression = 1; 5547c478bd9Sstevel@tonic-gate #ifdef CBCP_SUPPORT 5557c478bd9Sstevel@tonic-gate ao->neg_cbcp = 1; 5567c478bd9Sstevel@tonic-gate #endif 5577c478bd9Sstevel@tonic-gate ao->neg_endpoint = 1; 5587c478bd9Sstevel@tonic-gate #ifdef NEGOTIATE_FCS 5597c478bd9Sstevel@tonic-gate ao->neg_fcs = 1; 5607c478bd9Sstevel@tonic-gate ao->fcs_type = FCSALT_NULL|FCSALT_16|FCSALT_32; 5617c478bd9Sstevel@tonic-gate #endif 5627c478bd9Sstevel@tonic-gate 5637c478bd9Sstevel@tonic-gate BZERO(xmit_accm[unit], sizeof(xmit_accm[0])); 5647c478bd9Sstevel@tonic-gate xmit_accm[unit][3] = 0x60000000; 5657c478bd9Sstevel@tonic-gate } 5667c478bd9Sstevel@tonic-gate 5677c478bd9Sstevel@tonic-gate 5687c478bd9Sstevel@tonic-gate /* 5697c478bd9Sstevel@tonic-gate * lcp_open - LCP is allowed to come up. 5707c478bd9Sstevel@tonic-gate */ 5717c478bd9Sstevel@tonic-gate void 5727c478bd9Sstevel@tonic-gate lcp_open(unit) 5737c478bd9Sstevel@tonic-gate int unit; 5747c478bd9Sstevel@tonic-gate { 5757c478bd9Sstevel@tonic-gate fsm *f = &lcp_fsm[unit]; 5767c478bd9Sstevel@tonic-gate lcp_options *wo = &lcp_wantoptions[unit]; 5777c478bd9Sstevel@tonic-gate 5787c478bd9Sstevel@tonic-gate f->flags = 0; 5797c478bd9Sstevel@tonic-gate if (wo->passive) 5807c478bd9Sstevel@tonic-gate f->flags |= OPT_PASSIVE; 5817c478bd9Sstevel@tonic-gate if (wo->silent) 5827c478bd9Sstevel@tonic-gate f->flags |= OPT_SILENT; 5837c478bd9Sstevel@tonic-gate fsm_open(f); 5847c478bd9Sstevel@tonic-gate } 5857c478bd9Sstevel@tonic-gate 5867c478bd9Sstevel@tonic-gate 5877c478bd9Sstevel@tonic-gate /* 5887c478bd9Sstevel@tonic-gate * lcp_close - Take LCP down. 5897c478bd9Sstevel@tonic-gate */ 5907c478bd9Sstevel@tonic-gate void 5917c478bd9Sstevel@tonic-gate lcp_close(unit, reason) 5927c478bd9Sstevel@tonic-gate int unit; 5937c478bd9Sstevel@tonic-gate char *reason; 5947c478bd9Sstevel@tonic-gate { 5957c478bd9Sstevel@tonic-gate fsm *f = &lcp_fsm[unit]; 5967c478bd9Sstevel@tonic-gate 5977c478bd9Sstevel@tonic-gate if (phase != PHASE_DEAD) 5987c478bd9Sstevel@tonic-gate new_phase(PHASE_TERMINATE); 5997c478bd9Sstevel@tonic-gate if (f->state == STOPPED && (f->flags & (OPT_PASSIVE|OPT_SILENT))) { 6007c478bd9Sstevel@tonic-gate /* 6017c478bd9Sstevel@tonic-gate * This action is not strictly according to the FSM in RFC1548, 6027c478bd9Sstevel@tonic-gate * but it does mean that the program terminates if you do a 6037c478bd9Sstevel@tonic-gate * lcp_close() in passive/silent mode when a connection hasn't 6047c478bd9Sstevel@tonic-gate * been established. 6057c478bd9Sstevel@tonic-gate */ 6067c478bd9Sstevel@tonic-gate f->state = CLOSED; 6077c478bd9Sstevel@tonic-gate lcp_finished(f); 6087c478bd9Sstevel@tonic-gate 6097c478bd9Sstevel@tonic-gate } else 6107c478bd9Sstevel@tonic-gate fsm_close(&lcp_fsm[unit], reason); 6117c478bd9Sstevel@tonic-gate } 6127c478bd9Sstevel@tonic-gate 6137c478bd9Sstevel@tonic-gate 6147c478bd9Sstevel@tonic-gate /* 6157c478bd9Sstevel@tonic-gate * lcp_lowerup - The lower layer is up. 6167c478bd9Sstevel@tonic-gate */ 6177c478bd9Sstevel@tonic-gate void 6187c478bd9Sstevel@tonic-gate lcp_lowerup(unit) 6197c478bd9Sstevel@tonic-gate int unit; 6207c478bd9Sstevel@tonic-gate { 6217c478bd9Sstevel@tonic-gate lcp_options *wo = &lcp_wantoptions[unit]; 6227c478bd9Sstevel@tonic-gate int mru, mtu; 6237c478bd9Sstevel@tonic-gate 6247c478bd9Sstevel@tonic-gate mru = PPP_MRU > absmax_mru ? absmax_mru : PPP_MRU; 6257c478bd9Sstevel@tonic-gate mtu = PPP_MTU > absmax_mtu ? absmax_mtu : PPP_MTU; 6267c478bd9Sstevel@tonic-gate 6277c478bd9Sstevel@tonic-gate /* 6287c478bd9Sstevel@tonic-gate * Don't use A/C or protocol compression on transmission, 6297c478bd9Sstevel@tonic-gate * but accept A/C and protocol compressed packets 6307c478bd9Sstevel@tonic-gate * if we are going to ask for A/C and protocol compression. 6317c478bd9Sstevel@tonic-gate */ 6327c478bd9Sstevel@tonic-gate ppp_set_xaccm(unit, xmit_accm[unit]); 6337c478bd9Sstevel@tonic-gate ppp_send_config(unit, mtu, 0xffffffff, 0, 0); 6347c478bd9Sstevel@tonic-gate ppp_recv_config(unit, mru, (lax_recv? 0: 0xffffffff), 6357c478bd9Sstevel@tonic-gate wo->neg_pcompression, wo->neg_accompression); 6367c478bd9Sstevel@tonic-gate #ifdef NEGOTIATE_FCS 6377c478bd9Sstevel@tonic-gate ppp_send_fcs(unit, FCSALT_16); 6387c478bd9Sstevel@tonic-gate ppp_recv_fcs(unit, FCSALT_16); 6397c478bd9Sstevel@tonic-gate #endif 6407c478bd9Sstevel@tonic-gate 6417c478bd9Sstevel@tonic-gate fsm_setpeermru(unit, mtu); 6427c478bd9Sstevel@tonic-gate lcp_allowoptions[unit].asyncmap = xmit_accm[unit][0]; 6437c478bd9Sstevel@tonic-gate 6447c478bd9Sstevel@tonic-gate fsm_lowerup(&lcp_fsm[unit]); 6457c478bd9Sstevel@tonic-gate } 6467c478bd9Sstevel@tonic-gate 6477c478bd9Sstevel@tonic-gate 6487c478bd9Sstevel@tonic-gate /* 6497c478bd9Sstevel@tonic-gate * lcp_lowerdown - The lower layer is down. 6507c478bd9Sstevel@tonic-gate */ 6517c478bd9Sstevel@tonic-gate void 6527c478bd9Sstevel@tonic-gate lcp_lowerdown(unit) 6537c478bd9Sstevel@tonic-gate int unit; 6547c478bd9Sstevel@tonic-gate { 6557c478bd9Sstevel@tonic-gate fsm_lowerdown(&lcp_fsm[unit]); 6567c478bd9Sstevel@tonic-gate } 6577c478bd9Sstevel@tonic-gate 6587c478bd9Sstevel@tonic-gate 6597c478bd9Sstevel@tonic-gate /* 6607c478bd9Sstevel@tonic-gate * lcp_input - Input LCP packet. 6617c478bd9Sstevel@tonic-gate */ 6627c478bd9Sstevel@tonic-gate static void 6637c478bd9Sstevel@tonic-gate lcp_input(unit, p, len) 6647c478bd9Sstevel@tonic-gate int unit; 6657c478bd9Sstevel@tonic-gate u_char *p; 6667c478bd9Sstevel@tonic-gate int len; 6677c478bd9Sstevel@tonic-gate { 6687c478bd9Sstevel@tonic-gate fsm *f = &lcp_fsm[unit]; 6697c478bd9Sstevel@tonic-gate 6707c478bd9Sstevel@tonic-gate fsm_input(f, p, len); 6717c478bd9Sstevel@tonic-gate } 6727c478bd9Sstevel@tonic-gate 6737c478bd9Sstevel@tonic-gate 6747c478bd9Sstevel@tonic-gate /* 6757c478bd9Sstevel@tonic-gate * lcp_extcode - Handle a LCP-specific code. 6767c478bd9Sstevel@tonic-gate */ 6777c478bd9Sstevel@tonic-gate static int 6787c478bd9Sstevel@tonic-gate lcp_extcode(f, code, id, inp, len) 6797c478bd9Sstevel@tonic-gate fsm *f; 6807c478bd9Sstevel@tonic-gate int code, id; 6817c478bd9Sstevel@tonic-gate u_char *inp; 6827c478bd9Sstevel@tonic-gate int len; 6837c478bd9Sstevel@tonic-gate { 6847c478bd9Sstevel@tonic-gate u_char *magp; 6857c478bd9Sstevel@tonic-gate 6867c478bd9Sstevel@tonic-gate switch( code ){ 6877c478bd9Sstevel@tonic-gate case CODE_PROTREJ: 6887c478bd9Sstevel@tonic-gate lcp_rprotrej(f, inp, len); 6897c478bd9Sstevel@tonic-gate break; 6907c478bd9Sstevel@tonic-gate 6917c478bd9Sstevel@tonic-gate case CODE_ECHOREQ: 6927c478bd9Sstevel@tonic-gate if (f->state != OPENED) 6937c478bd9Sstevel@tonic-gate break; 6947c478bd9Sstevel@tonic-gate magp = inp; 6957c478bd9Sstevel@tonic-gate PUTLONG(lcp_gotoptions[f->unit].magicnumber, magp); 6967c478bd9Sstevel@tonic-gate fsm_sdata(f, CODE_ECHOREP, id, inp, len); 6977c478bd9Sstevel@tonic-gate break; 6987c478bd9Sstevel@tonic-gate 6997c478bd9Sstevel@tonic-gate case CODE_ECHOREP: 7007c478bd9Sstevel@tonic-gate if (!lcp_received_echo_reply(f, id, inp, len)) { 7017c478bd9Sstevel@tonic-gate lcp_echo_badreplies++; 7027c478bd9Sstevel@tonic-gate if (lcp_echo_badreplies > LCP_ECHO_MAX_BADREPLIES) { 7037c478bd9Sstevel@tonic-gate LcpLinkFailure(f); 7047c478bd9Sstevel@tonic-gate lcp_echos_pending = 0; 7057c478bd9Sstevel@tonic-gate lcp_echo_badreplies = 0; 7067c478bd9Sstevel@tonic-gate } 7077c478bd9Sstevel@tonic-gate } 7087c478bd9Sstevel@tonic-gate break; 7097c478bd9Sstevel@tonic-gate 7107c478bd9Sstevel@tonic-gate case CODE_DISCREQ: 7117c478bd9Sstevel@tonic-gate break; 7127c478bd9Sstevel@tonic-gate 7137c478bd9Sstevel@tonic-gate case CODE_IDENT: 7147c478bd9Sstevel@tonic-gate /* More than one 'noident' tells us to reject the code number. */ 7157c478bd9Sstevel@tonic-gate if (noident > 1) 7167c478bd9Sstevel@tonic-gate return 0; 7177c478bd9Sstevel@tonic-gate lcp_received_identification(f, id, inp, len); 7187c478bd9Sstevel@tonic-gate break; 7197c478bd9Sstevel@tonic-gate 7207c478bd9Sstevel@tonic-gate case CODE_TIMEREMAIN: 7217c478bd9Sstevel@tonic-gate lcp_received_timeremain(f, id, inp, len); 7227c478bd9Sstevel@tonic-gate break; 7237c478bd9Sstevel@tonic-gate 7247c478bd9Sstevel@tonic-gate default: 7257c478bd9Sstevel@tonic-gate return 0; 7267c478bd9Sstevel@tonic-gate } 7277c478bd9Sstevel@tonic-gate return 1; 7287c478bd9Sstevel@tonic-gate } 7297c478bd9Sstevel@tonic-gate 7307c478bd9Sstevel@tonic-gate /* 7317c478bd9Sstevel@tonic-gate * lcp_rprotrej - Receive an Protocol-Reject. 7327c478bd9Sstevel@tonic-gate * 7337c478bd9Sstevel@tonic-gate * Figure out which protocol is rejected and inform it. 7347c478bd9Sstevel@tonic-gate */ 7357c478bd9Sstevel@tonic-gate static void 7367c478bd9Sstevel@tonic-gate lcp_rprotrej(f, inp, len) 7377c478bd9Sstevel@tonic-gate fsm *f; 7387c478bd9Sstevel@tonic-gate u_char *inp; 7397c478bd9Sstevel@tonic-gate int len; 7407c478bd9Sstevel@tonic-gate { 7417c478bd9Sstevel@tonic-gate int i; 7427c478bd9Sstevel@tonic-gate struct protent *protp; 7437c478bd9Sstevel@tonic-gate u_short prot; 7447c478bd9Sstevel@tonic-gate 7457c478bd9Sstevel@tonic-gate if (len < 2) { 7467c478bd9Sstevel@tonic-gate dbglog("lcp_rprotrej: Rcvd short Protocol-Reject packet!"); 7477c478bd9Sstevel@tonic-gate return; 7487c478bd9Sstevel@tonic-gate } 7497c478bd9Sstevel@tonic-gate 7507c478bd9Sstevel@tonic-gate GETSHORT(prot, inp); 7517c478bd9Sstevel@tonic-gate 7527c478bd9Sstevel@tonic-gate /* 7537c478bd9Sstevel@tonic-gate * Protocol-Reject packets received in any state other than the LCP 7547c478bd9Sstevel@tonic-gate * OPENED state SHOULD be silently discarded. 7557c478bd9Sstevel@tonic-gate */ 7567c478bd9Sstevel@tonic-gate if( f->state != OPENED ){ 7577c478bd9Sstevel@tonic-gate dbglog("Protocol-Reject discarded: LCP in state %s", 7587c478bd9Sstevel@tonic-gate fsm_state(f->state)); 7597c478bd9Sstevel@tonic-gate return; 7607c478bd9Sstevel@tonic-gate } 7617c478bd9Sstevel@tonic-gate 7627c478bd9Sstevel@tonic-gate /* 7637c478bd9Sstevel@tonic-gate * Upcall the proper Protocol-Reject routine. 7647c478bd9Sstevel@tonic-gate */ 7657c478bd9Sstevel@tonic-gate for (i = 0; (protp = protocols[i]) != NULL; ++i) 7667c478bd9Sstevel@tonic-gate if (protp->protocol == prot && protp->enabled_flag) { 7677c478bd9Sstevel@tonic-gate (*protp->protrej)(f->unit); 7687c478bd9Sstevel@tonic-gate return; 7697c478bd9Sstevel@tonic-gate } 7707c478bd9Sstevel@tonic-gate 7717c478bd9Sstevel@tonic-gate warn("Protocol-Reject for unsupported protocol 0x%x", prot); 7727c478bd9Sstevel@tonic-gate } 7737c478bd9Sstevel@tonic-gate 7747c478bd9Sstevel@tonic-gate 7757c478bd9Sstevel@tonic-gate /* 7767c478bd9Sstevel@tonic-gate * lcp_protrej - A Protocol-Reject was received. 7777c478bd9Sstevel@tonic-gate */ 7787c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 7797c478bd9Sstevel@tonic-gate static void 7807c478bd9Sstevel@tonic-gate lcp_protrej(unit) 7817c478bd9Sstevel@tonic-gate int unit; 7827c478bd9Sstevel@tonic-gate { 7837c478bd9Sstevel@tonic-gate /* 7847c478bd9Sstevel@tonic-gate * Can't reject LCP! 7857c478bd9Sstevel@tonic-gate */ 7867c478bd9Sstevel@tonic-gate error("Received Protocol-Reject for LCP!"); 7877c478bd9Sstevel@tonic-gate } 7887c478bd9Sstevel@tonic-gate 7897c478bd9Sstevel@tonic-gate /* 7907c478bd9Sstevel@tonic-gate * lcp_coderej - A Code-Reject was received. 7917c478bd9Sstevel@tonic-gate */ 7927c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 7937c478bd9Sstevel@tonic-gate static int 7947c478bd9Sstevel@tonic-gate lcp_coderej(f, code, id, inp, len) 7957c478bd9Sstevel@tonic-gate fsm *f; 7967c478bd9Sstevel@tonic-gate int code; 7977c478bd9Sstevel@tonic-gate int id; 7987c478bd9Sstevel@tonic-gate u_char *inp; 7997c478bd9Sstevel@tonic-gate int len; 8007c478bd9Sstevel@tonic-gate { 8017c478bd9Sstevel@tonic-gate /* The peer cannot reject these code numbers. */ 8027c478bd9Sstevel@tonic-gate if (code >= CODE_CONFREQ && code <= CODE_PROTREJ) 8037c478bd9Sstevel@tonic-gate return 1; 8047c478bd9Sstevel@tonic-gate switch (code) { 8057c478bd9Sstevel@tonic-gate case CODE_ECHOREQ: 8067c478bd9Sstevel@tonic-gate /* 8077c478bd9Sstevel@tonic-gate * If the peer rejects an Echo-Request, then stop doing that. 8087c478bd9Sstevel@tonic-gate */ 8097c478bd9Sstevel@tonic-gate if (lcp_echo_timer_running != 0) { 8107c478bd9Sstevel@tonic-gate UNTIMEOUT (LcpEchoTimeout, f); 8117c478bd9Sstevel@tonic-gate lcp_echo_timer_running = 0; 8127c478bd9Sstevel@tonic-gate lcp_echo_interval = 0; 8137c478bd9Sstevel@tonic-gate } 8147c478bd9Sstevel@tonic-gate break; 8157c478bd9Sstevel@tonic-gate } 8167c478bd9Sstevel@tonic-gate return 0; 8177c478bd9Sstevel@tonic-gate } 8187c478bd9Sstevel@tonic-gate 8197c478bd9Sstevel@tonic-gate /* 8207c478bd9Sstevel@tonic-gate * lcp_sprotrej - Send a Protocol-Reject for some protocol. 8217c478bd9Sstevel@tonic-gate */ 8227c478bd9Sstevel@tonic-gate void 8237c478bd9Sstevel@tonic-gate lcp_sprotrej(unit, p, len) 8247c478bd9Sstevel@tonic-gate int unit; 8257c478bd9Sstevel@tonic-gate u_char *p; 8267c478bd9Sstevel@tonic-gate int len; 8277c478bd9Sstevel@tonic-gate { 8287c478bd9Sstevel@tonic-gate /* 8297c478bd9Sstevel@tonic-gate * Send back the protocol and the information field of the 8307c478bd9Sstevel@tonic-gate * rejected packet. We only get here if LCP is in the OPENED state. 8317c478bd9Sstevel@tonic-gate */ 8327c478bd9Sstevel@tonic-gate p += 2; 8337c478bd9Sstevel@tonic-gate len -= 2; 8347c478bd9Sstevel@tonic-gate 8357c478bd9Sstevel@tonic-gate fsm_sdata(&lcp_fsm[unit], CODE_PROTREJ, ++lcp_fsm[unit].id, 8367c478bd9Sstevel@tonic-gate p, len); 8377c478bd9Sstevel@tonic-gate } 8387c478bd9Sstevel@tonic-gate 8397c478bd9Sstevel@tonic-gate 8407c478bd9Sstevel@tonic-gate /* 8417c478bd9Sstevel@tonic-gate * lcp_resetci - Reset our CI. 8427c478bd9Sstevel@tonic-gate */ 8437c478bd9Sstevel@tonic-gate static void 8447c478bd9Sstevel@tonic-gate lcp_resetci(f) 8457c478bd9Sstevel@tonic-gate fsm *f; 8467c478bd9Sstevel@tonic-gate { 8477c478bd9Sstevel@tonic-gate lcp_options *wo = &lcp_wantoptions[f->unit]; 8487c478bd9Sstevel@tonic-gate lcp_options *go = &lcp_gotoptions[f->unit]; 8497c478bd9Sstevel@tonic-gate lcp_options *ao = &lcp_allowoptions[f->unit]; 8507c478bd9Sstevel@tonic-gate 8517c478bd9Sstevel@tonic-gate wo->magicnumber = magic(); 8527c478bd9Sstevel@tonic-gate wo->numloops = 0; 8537c478bd9Sstevel@tonic-gate sentident = 0; 8547c478bd9Sstevel@tonic-gate *go = *wo; 8557c478bd9Sstevel@tonic-gate if (!multilink) { 8567c478bd9Sstevel@tonic-gate go->neg_mrru = 0; 8577c478bd9Sstevel@tonic-gate go->neg_ssnhf = 0; 8587c478bd9Sstevel@tonic-gate } 8597c478bd9Sstevel@tonic-gate if (noendpoint) 8607c478bd9Sstevel@tonic-gate ao->neg_endpoint = 0; 8617c478bd9Sstevel@tonic-gate if (go->mru > absmax_mru) 8627c478bd9Sstevel@tonic-gate go->mru = absmax_mru; 8637c478bd9Sstevel@tonic-gate if (ao->mru > absmax_mtu) 8647c478bd9Sstevel@tonic-gate ao->mru = absmax_mtu; 8657c478bd9Sstevel@tonic-gate unsolicit_mru = 1; 8667c478bd9Sstevel@tonic-gate fsm_setpeermru(f->unit, PPP_MTU > absmax_mtu ? absmax_mtu : PPP_MTU); 8677c478bd9Sstevel@tonic-gate auth_reset(f->unit); 8687c478bd9Sstevel@tonic-gate } 8697c478bd9Sstevel@tonic-gate 8707c478bd9Sstevel@tonic-gate 8717c478bd9Sstevel@tonic-gate /* 8727c478bd9Sstevel@tonic-gate * lcp_cilen - Return length of our CI. 8737c478bd9Sstevel@tonic-gate */ 8747c478bd9Sstevel@tonic-gate static int 8757c478bd9Sstevel@tonic-gate lcp_cilen(f) 8767c478bd9Sstevel@tonic-gate fsm *f; 8777c478bd9Sstevel@tonic-gate { 8787c478bd9Sstevel@tonic-gate lcp_options *go = &lcp_gotoptions[f->unit]; 8797c478bd9Sstevel@tonic-gate 8807c478bd9Sstevel@tonic-gate #define LENCIVOID(neg) ((neg) ? CILEN_VOID : 0) 8817c478bd9Sstevel@tonic-gate #define LENCICHAP(neg) ((neg) ? CILEN_CHAP : 0) 8827c478bd9Sstevel@tonic-gate #define LENCICHAR(neg) ((neg) ? CILEN_CHAR : 0) 8837c478bd9Sstevel@tonic-gate #define LENCISHORT(neg) ((neg) ? CILEN_SHORT : 0) 8847c478bd9Sstevel@tonic-gate #define LENCILONG(neg) ((neg) ? CILEN_LONG : 0) 8857c478bd9Sstevel@tonic-gate #define LENCILQR(neg) ((neg) ? CILEN_LQR: 0) 8867c478bd9Sstevel@tonic-gate #define LENCICBCP(neg) ((neg) ? CILEN_CBCP: 0) 8877c478bd9Sstevel@tonic-gate /* 8887c478bd9Sstevel@tonic-gate * NB: we only ask for one of CHAP and UPAP, even if we will 8897c478bd9Sstevel@tonic-gate * accept either. 8907c478bd9Sstevel@tonic-gate */ 8917c478bd9Sstevel@tonic-gate return (LENCISHORT(go->neg_mru && go->mru != PPP_MRU) + 8927c478bd9Sstevel@tonic-gate LENCILONG(go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF) + 8937c478bd9Sstevel@tonic-gate LENCICHAP(go->neg_chap || go->neg_mschap || go->neg_mschapv2) + 8947c478bd9Sstevel@tonic-gate LENCISHORT(!go->neg_chap && go->neg_upap && !go->neg_mschap && 8957c478bd9Sstevel@tonic-gate !go->neg_mschapv2) + 8967c478bd9Sstevel@tonic-gate LENCILQR(go->neg_lqr) + 8977c478bd9Sstevel@tonic-gate LENCICBCP(go->neg_cbcp) + 8987c478bd9Sstevel@tonic-gate LENCILONG(go->neg_magicnumber) + 8997c478bd9Sstevel@tonic-gate LENCIVOID(go->neg_pcompression) + 9007c478bd9Sstevel@tonic-gate LENCIVOID(go->neg_accompression) + 9017c478bd9Sstevel@tonic-gate LENCICHAR(go->neg_fcs) + 9027c478bd9Sstevel@tonic-gate LENCISHORT(go->neg_mrru) + 9037c478bd9Sstevel@tonic-gate LENCIVOID(go->neg_ssnhf) + 9047c478bd9Sstevel@tonic-gate #ifdef MUX_FRAME 9057c478bd9Sstevel@tonic-gate LENCIVOID(go->pppmux) + 9067c478bd9Sstevel@tonic-gate #endif 9077c478bd9Sstevel@tonic-gate (go->neg_endpoint? CILEN_CHAR + go->endpoint.length: 0)); 9087c478bd9Sstevel@tonic-gate } 9097c478bd9Sstevel@tonic-gate 9107c478bd9Sstevel@tonic-gate 9117c478bd9Sstevel@tonic-gate /* 9127c478bd9Sstevel@tonic-gate * lcp_addci - Add our desired CIs to a packet. 9137c478bd9Sstevel@tonic-gate */ 9147c478bd9Sstevel@tonic-gate static void 9157c478bd9Sstevel@tonic-gate lcp_addci(f, ucp, lenp) 9167c478bd9Sstevel@tonic-gate fsm *f; 9177c478bd9Sstevel@tonic-gate u_char *ucp; 9187c478bd9Sstevel@tonic-gate int *lenp; 9197c478bd9Sstevel@tonic-gate { 9207c478bd9Sstevel@tonic-gate lcp_options *go = &lcp_gotoptions[f->unit]; 9217c478bd9Sstevel@tonic-gate lcp_options *ho = &lcp_hisoptions[f->unit]; 9227c478bd9Sstevel@tonic-gate u_char *start_ucp = ucp; 9237c478bd9Sstevel@tonic-gate 9247c478bd9Sstevel@tonic-gate #define ADDCIVOID(opt, neg) \ 9257c478bd9Sstevel@tonic-gate if (neg) { \ 9267c478bd9Sstevel@tonic-gate PUTCHAR(opt, ucp); \ 9277c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_VOID, ucp); \ 9287c478bd9Sstevel@tonic-gate } 9297c478bd9Sstevel@tonic-gate #define ADDCISHORT(opt, neg, val) \ 9307c478bd9Sstevel@tonic-gate if (neg) { \ 9317c478bd9Sstevel@tonic-gate PUTCHAR(opt, ucp); \ 9327c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_SHORT, ucp); \ 9337c478bd9Sstevel@tonic-gate PUTSHORT(val, ucp); \ 9347c478bd9Sstevel@tonic-gate } 9357c478bd9Sstevel@tonic-gate #define ADDCICHAP(opt, neg, val, digest) \ 9367c478bd9Sstevel@tonic-gate if (neg) { \ 9377c478bd9Sstevel@tonic-gate PUTCHAR(opt, ucp); \ 9387c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_CHAP, ucp); \ 9397c478bd9Sstevel@tonic-gate PUTSHORT(val, ucp); \ 9407c478bd9Sstevel@tonic-gate PUTCHAR(digest, ucp); \ 9417c478bd9Sstevel@tonic-gate } 9427c478bd9Sstevel@tonic-gate #define ADDCILONG(opt, neg, val) \ 9437c478bd9Sstevel@tonic-gate if (neg) { \ 9447c478bd9Sstevel@tonic-gate PUTCHAR(opt, ucp); \ 9457c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_LONG, ucp); \ 9467c478bd9Sstevel@tonic-gate PUTLONG(val, ucp); \ 9477c478bd9Sstevel@tonic-gate } 9487c478bd9Sstevel@tonic-gate #define ADDCILQR(opt, neg, val) \ 9497c478bd9Sstevel@tonic-gate if (neg) { \ 9507c478bd9Sstevel@tonic-gate PUTCHAR(opt, ucp); \ 9517c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_LQR, ucp); \ 9527c478bd9Sstevel@tonic-gate PUTSHORT(PPP_LQR, ucp); \ 9537c478bd9Sstevel@tonic-gate PUTLONG(val, ucp); \ 9547c478bd9Sstevel@tonic-gate } 9557c478bd9Sstevel@tonic-gate #define ADDCICHAR(opt, neg, val) \ 9567c478bd9Sstevel@tonic-gate if (neg) { \ 9577c478bd9Sstevel@tonic-gate PUTCHAR(opt, ucp); \ 9587c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_CHAR, ucp); \ 9597c478bd9Sstevel@tonic-gate PUTCHAR(val, ucp); \ 9607c478bd9Sstevel@tonic-gate } 9617c478bd9Sstevel@tonic-gate #define ADDCIENDP(opt, neg, class, val, len) \ 9627c478bd9Sstevel@tonic-gate if (neg) { \ 9637c478bd9Sstevel@tonic-gate int i; \ 9647c478bd9Sstevel@tonic-gate PUTCHAR(opt, ucp); \ 9657c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_CHAR + len, ucp); \ 9667c478bd9Sstevel@tonic-gate PUTCHAR(class, ucp); \ 9677c478bd9Sstevel@tonic-gate for (i = 0; i < len; ++i) \ 9687c478bd9Sstevel@tonic-gate PUTCHAR(val[i], ucp); \ 9697c478bd9Sstevel@tonic-gate } 9707c478bd9Sstevel@tonic-gate 9717c478bd9Sstevel@tonic-gate ADDCISHORT(CI_MRU, go->neg_mru && go->mru != PPP_MRU, go->mru); 9727c478bd9Sstevel@tonic-gate ADDCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF, 9737c478bd9Sstevel@tonic-gate go->asyncmap); 9747c478bd9Sstevel@tonic-gate /* go->chap_mdtype always points to a useful value */ 9757c478bd9Sstevel@tonic-gate ADDCICHAP(CI_AUTHTYPE, go->neg_chap || go->neg_mschap || go->neg_mschapv2, 9767c478bd9Sstevel@tonic-gate PPP_CHAP, go->chap_mdtype); 9777c478bd9Sstevel@tonic-gate ADDCISHORT(CI_AUTHTYPE, !(go->neg_chap || go->neg_mschap || 9787c478bd9Sstevel@tonic-gate go->neg_mschapv2) && go->neg_upap, PPP_PAP); 9797c478bd9Sstevel@tonic-gate /* We can't both say zero for LQR period. */ 9807c478bd9Sstevel@tonic-gate if (f->state == ACKSENT && go->neg_lqr && go->lqr_period == 0 && 9817c478bd9Sstevel@tonic-gate ho->neg_lqr && ho->lqr_period == 0) 9827c478bd9Sstevel@tonic-gate go->lqr_period = 500; 9837c478bd9Sstevel@tonic-gate ADDCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period); 9847c478bd9Sstevel@tonic-gate ADDCICHAR(CI_CALLBACK, go->neg_cbcp, CBOP_CBCP); 9857c478bd9Sstevel@tonic-gate ADDCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber); 9867c478bd9Sstevel@tonic-gate ADDCIVOID(CI_PCOMPRESSION, go->neg_pcompression); 9877c478bd9Sstevel@tonic-gate ADDCIVOID(CI_ACCOMPRESSION, go->neg_accompression); 9887c478bd9Sstevel@tonic-gate ADDCICHAR(CI_FCSALTERN, (go->neg_fcs && go->fcs_type != 0), go->fcs_type); 9897c478bd9Sstevel@tonic-gate ADDCIENDP(CI_EPDISC, go->neg_endpoint, go->endpoint.class, 9907c478bd9Sstevel@tonic-gate go->endpoint.value, go->endpoint.length); 9917c478bd9Sstevel@tonic-gate #ifdef MUX_FRAME 9927c478bd9Sstevel@tonic-gate ADDCIVOID(CI_MUXING, go->pppmux); 9937c478bd9Sstevel@tonic-gate #endif 9947c478bd9Sstevel@tonic-gate ADDCISHORT(CI_MRRU, go->neg_mrru, go->mrru); 9957c478bd9Sstevel@tonic-gate ADDCIVOID(CI_SSNHF, go->neg_ssnhf); 9967c478bd9Sstevel@tonic-gate 9977c478bd9Sstevel@tonic-gate if (ucp - start_ucp != *lenp) { 9987c478bd9Sstevel@tonic-gate /* this should never happen, because peer_mtu should be 1500 */ 9997c478bd9Sstevel@tonic-gate error("Bug in lcp_addci: wrong length"); 10007c478bd9Sstevel@tonic-gate } 10017c478bd9Sstevel@tonic-gate } 10027c478bd9Sstevel@tonic-gate 10037c478bd9Sstevel@tonic-gate 10047c478bd9Sstevel@tonic-gate /* 10057c478bd9Sstevel@tonic-gate * lcp_ackci - Ack our CIs. 10067c478bd9Sstevel@tonic-gate * This should not modify any state if the Ack is bad. 10077c478bd9Sstevel@tonic-gate * 10087c478bd9Sstevel@tonic-gate * Returns: 10097c478bd9Sstevel@tonic-gate * 0 - Ack was bad. 10107c478bd9Sstevel@tonic-gate * 1 - Ack was good. 10117c478bd9Sstevel@tonic-gate */ 10127c478bd9Sstevel@tonic-gate static int 10137c478bd9Sstevel@tonic-gate lcp_ackci(f, p, len) 10147c478bd9Sstevel@tonic-gate fsm *f; 10157c478bd9Sstevel@tonic-gate u_char *p; 10167c478bd9Sstevel@tonic-gate int len; 10177c478bd9Sstevel@tonic-gate { 10187c478bd9Sstevel@tonic-gate lcp_options *go = &lcp_gotoptions[f->unit]; 10197c478bd9Sstevel@tonic-gate #ifdef MUX_FRAME 10207c478bd9Sstevel@tonic-gate lcp_options *ao = &lcp_allowoptions[f->unit]; 10217c478bd9Sstevel@tonic-gate #endif 10227c478bd9Sstevel@tonic-gate u_char cilen, citype, cichar; 10237c478bd9Sstevel@tonic-gate u_short cishort; 10247c478bd9Sstevel@tonic-gate u_int32_t cilong; 10257c478bd9Sstevel@tonic-gate 10267c478bd9Sstevel@tonic-gate /* 10277c478bd9Sstevel@tonic-gate * CIs must be in exactly the same order that we sent. 10287c478bd9Sstevel@tonic-gate * Check packet length and CI length at each step. 10297c478bd9Sstevel@tonic-gate * If we find any deviations, then this packet is bad. 10307c478bd9Sstevel@tonic-gate */ 10317c478bd9Sstevel@tonic-gate #define ACKCIVOID(opt, neg) \ 10327c478bd9Sstevel@tonic-gate if (neg) { \ 10337c478bd9Sstevel@tonic-gate if ((len -= CILEN_VOID) < 0) \ 10347c478bd9Sstevel@tonic-gate goto bad; \ 10357c478bd9Sstevel@tonic-gate GETCHAR(citype, p); \ 10367c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); \ 10377c478bd9Sstevel@tonic-gate if (cilen != CILEN_VOID || \ 10387c478bd9Sstevel@tonic-gate citype != opt) \ 10397c478bd9Sstevel@tonic-gate goto bad; \ 10407c478bd9Sstevel@tonic-gate } 10417c478bd9Sstevel@tonic-gate #define ACKCISHORT(opt, neg, val) \ 10427c478bd9Sstevel@tonic-gate if (neg) { \ 10437c478bd9Sstevel@tonic-gate if ((len -= CILEN_SHORT) < 0) \ 10447c478bd9Sstevel@tonic-gate goto bad; \ 10457c478bd9Sstevel@tonic-gate GETCHAR(citype, p); \ 10467c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); \ 10477c478bd9Sstevel@tonic-gate if (cilen != CILEN_SHORT || \ 10487c478bd9Sstevel@tonic-gate citype != opt) \ 10497c478bd9Sstevel@tonic-gate goto bad; \ 10507c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \ 10517c478bd9Sstevel@tonic-gate if (cishort != val) \ 10527c478bd9Sstevel@tonic-gate goto bad; \ 10537c478bd9Sstevel@tonic-gate } 10547c478bd9Sstevel@tonic-gate #define ACKCIAUTH(opt, neg, val) \ 10557c478bd9Sstevel@tonic-gate if (neg) { \ 10567c478bd9Sstevel@tonic-gate if ((len -= CILEN_SHORT) < 0) \ 10577c478bd9Sstevel@tonic-gate goto bad; \ 10587c478bd9Sstevel@tonic-gate GETCHAR(citype, p); \ 10597c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); \ 10607c478bd9Sstevel@tonic-gate if (cilen != CILEN_SHORT || \ 10617c478bd9Sstevel@tonic-gate citype != opt) \ 10627c478bd9Sstevel@tonic-gate goto bad; \ 10637c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \ 10647c478bd9Sstevel@tonic-gate if (cishort != val) \ 10657c478bd9Sstevel@tonic-gate goto bad; \ 10667c478bd9Sstevel@tonic-gate peer_nak_auth = 0; \ 10677c478bd9Sstevel@tonic-gate peer_reject_auth = 0; \ 10687c478bd9Sstevel@tonic-gate } 10697c478bd9Sstevel@tonic-gate #define ACKCICHAR(opt, neg, val) \ 10707c478bd9Sstevel@tonic-gate if (neg) { \ 10717c478bd9Sstevel@tonic-gate if ((len -= CILEN_CHAR) < 0) \ 10727c478bd9Sstevel@tonic-gate goto bad; \ 10737c478bd9Sstevel@tonic-gate GETCHAR(citype, p); \ 10747c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); \ 10757c478bd9Sstevel@tonic-gate if (cilen != CILEN_CHAR || \ 10767c478bd9Sstevel@tonic-gate citype != opt) \ 10777c478bd9Sstevel@tonic-gate goto bad; \ 10787c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); \ 10797c478bd9Sstevel@tonic-gate if (cichar != val) \ 10807c478bd9Sstevel@tonic-gate goto bad; \ 10817c478bd9Sstevel@tonic-gate } 10827c478bd9Sstevel@tonic-gate #define ACKCICHAP(opt, neg, val, digest) \ 10837c478bd9Sstevel@tonic-gate if (neg) { \ 10847c478bd9Sstevel@tonic-gate if ((len -= CILEN_CHAP) < 0) \ 10857c478bd9Sstevel@tonic-gate goto bad; \ 10867c478bd9Sstevel@tonic-gate GETCHAR(citype, p); \ 10877c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); \ 10887c478bd9Sstevel@tonic-gate if (cilen != CILEN_CHAP || \ 10897c478bd9Sstevel@tonic-gate citype != opt) \ 10907c478bd9Sstevel@tonic-gate goto bad; \ 10917c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \ 10927c478bd9Sstevel@tonic-gate if (cishort != val) \ 10937c478bd9Sstevel@tonic-gate goto bad; \ 10947c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); \ 10957c478bd9Sstevel@tonic-gate if (cichar != digest) \ 10967c478bd9Sstevel@tonic-gate goto bad; \ 10977c478bd9Sstevel@tonic-gate peer_nak_auth = 0; \ 10987c478bd9Sstevel@tonic-gate peer_reject_auth = 0; \ 10997c478bd9Sstevel@tonic-gate } 11007c478bd9Sstevel@tonic-gate #define ACKCILONG(opt, neg, val) \ 11017c478bd9Sstevel@tonic-gate if (neg) { \ 11027c478bd9Sstevel@tonic-gate if ((len -= CILEN_LONG) < 0) \ 11037c478bd9Sstevel@tonic-gate goto bad; \ 11047c478bd9Sstevel@tonic-gate GETCHAR(citype, p); \ 11057c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); \ 11067c478bd9Sstevel@tonic-gate if (cilen != CILEN_LONG || \ 11077c478bd9Sstevel@tonic-gate citype != opt) \ 11087c478bd9Sstevel@tonic-gate goto bad; \ 11097c478bd9Sstevel@tonic-gate GETLONG(cilong, p); \ 11107c478bd9Sstevel@tonic-gate if (cilong != val) \ 11117c478bd9Sstevel@tonic-gate goto bad; \ 11127c478bd9Sstevel@tonic-gate } 11137c478bd9Sstevel@tonic-gate #define ACKCILQR(opt, neg, val) \ 11147c478bd9Sstevel@tonic-gate if (neg) { \ 11157c478bd9Sstevel@tonic-gate if ((len -= CILEN_LQR) < 0) \ 11167c478bd9Sstevel@tonic-gate goto bad; \ 11177c478bd9Sstevel@tonic-gate GETCHAR(citype, p); \ 11187c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); \ 11197c478bd9Sstevel@tonic-gate if (cilen != CILEN_LQR || \ 11207c478bd9Sstevel@tonic-gate citype != opt) \ 11217c478bd9Sstevel@tonic-gate goto bad; \ 11227c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \ 11237c478bd9Sstevel@tonic-gate if (cishort != PPP_LQR) \ 11247c478bd9Sstevel@tonic-gate goto bad; \ 11257c478bd9Sstevel@tonic-gate GETLONG(cilong, p); \ 11267c478bd9Sstevel@tonic-gate if (cilong != val) \ 11277c478bd9Sstevel@tonic-gate goto bad; \ 11287c478bd9Sstevel@tonic-gate } 11297c478bd9Sstevel@tonic-gate #define ACKCIENDP(opt, neg, class, val, vlen) \ 11307c478bd9Sstevel@tonic-gate if (neg) { \ 11317c478bd9Sstevel@tonic-gate int i; \ 11327c478bd9Sstevel@tonic-gate if ((len -= CILEN_CHAR + vlen) < 0) \ 11337c478bd9Sstevel@tonic-gate goto bad; \ 11347c478bd9Sstevel@tonic-gate GETCHAR(citype, p); \ 11357c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); \ 11367c478bd9Sstevel@tonic-gate if (cilen != CILEN_CHAR + vlen || \ 11377c478bd9Sstevel@tonic-gate citype != opt) \ 11387c478bd9Sstevel@tonic-gate goto bad; \ 11397c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); \ 11407c478bd9Sstevel@tonic-gate if (cichar != class) \ 11417c478bd9Sstevel@tonic-gate goto bad; \ 11427c478bd9Sstevel@tonic-gate for (i = 0; i < vlen; ++i) { \ 11437c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); \ 11447c478bd9Sstevel@tonic-gate if (cichar != val[i]) \ 11457c478bd9Sstevel@tonic-gate goto bad; \ 11467c478bd9Sstevel@tonic-gate } \ 11477c478bd9Sstevel@tonic-gate } 11487c478bd9Sstevel@tonic-gate 11497c478bd9Sstevel@tonic-gate ACKCISHORT(CI_MRU, go->neg_mru && go->mru != PPP_MRU, go->mru); 11507c478bd9Sstevel@tonic-gate ACKCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF, 11517c478bd9Sstevel@tonic-gate go->asyncmap); 11527c478bd9Sstevel@tonic-gate /* go->chap_mdtype always points to a useful value */ 11537c478bd9Sstevel@tonic-gate ACKCICHAP(CI_AUTHTYPE, go->neg_chap || go->neg_mschap || go->neg_mschapv2, 11547c478bd9Sstevel@tonic-gate PPP_CHAP, go->chap_mdtype); 11557c478bd9Sstevel@tonic-gate ACKCIAUTH(CI_AUTHTYPE, !(go->neg_chap || go->neg_mschap || 11567c478bd9Sstevel@tonic-gate go->neg_mschapv2) && go->neg_upap, PPP_PAP); 11577c478bd9Sstevel@tonic-gate ACKCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period); 11587c478bd9Sstevel@tonic-gate ACKCICHAR(CI_CALLBACK, go->neg_cbcp, CBOP_CBCP); 11597c478bd9Sstevel@tonic-gate ACKCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber); 11607c478bd9Sstevel@tonic-gate ACKCIVOID(CI_PCOMPRESSION, go->neg_pcompression); 11617c478bd9Sstevel@tonic-gate ACKCIVOID(CI_ACCOMPRESSION, go->neg_accompression); 11627c478bd9Sstevel@tonic-gate ACKCICHAR(CI_FCSALTERN, go->neg_fcs, go->fcs_type); 11637c478bd9Sstevel@tonic-gate ACKCIENDP(CI_EPDISC, go->neg_endpoint, go->endpoint.class, 11647c478bd9Sstevel@tonic-gate go->endpoint.value, go->endpoint.length); 11657c478bd9Sstevel@tonic-gate #ifdef MUX_FRAME 11667c478bd9Sstevel@tonic-gate ACKCIVOID(CI_MUXING, go->pppmux); 11677c478bd9Sstevel@tonic-gate if (go->pppmux) 11687c478bd9Sstevel@tonic-gate go->pppmux = ao->pppmux; 11697c478bd9Sstevel@tonic-gate #endif 11707c478bd9Sstevel@tonic-gate ACKCISHORT(CI_MRRU, go->neg_mrru, go->mrru); 11717c478bd9Sstevel@tonic-gate ACKCIVOID(CI_SSNHF, go->neg_ssnhf); 11727c478bd9Sstevel@tonic-gate 11737c478bd9Sstevel@tonic-gate /* 11747c478bd9Sstevel@tonic-gate * If there are any remaining CIs, then this packet is bad. 11757c478bd9Sstevel@tonic-gate */ 11767c478bd9Sstevel@tonic-gate if (len != 0) 11777c478bd9Sstevel@tonic-gate goto bad; 11787c478bd9Sstevel@tonic-gate return (1); 11797c478bd9Sstevel@tonic-gate bad: 11807c478bd9Sstevel@tonic-gate dbglog("lcp_acki: received bad Ack!"); 11817c478bd9Sstevel@tonic-gate return (0); 11827c478bd9Sstevel@tonic-gate } 11837c478bd9Sstevel@tonic-gate 11847c478bd9Sstevel@tonic-gate 11857c478bd9Sstevel@tonic-gate /* 11867c478bd9Sstevel@tonic-gate * lcp_nakci - Peer has sent a NAK for some of our CIs. 11877c478bd9Sstevel@tonic-gate * This should not modify any state if the Nak is bad 11887c478bd9Sstevel@tonic-gate * or if LCP is in the OPENED state. 11897c478bd9Sstevel@tonic-gate * 11907c478bd9Sstevel@tonic-gate * Returns: 11917c478bd9Sstevel@tonic-gate * 0 - Nak was bad. 11927c478bd9Sstevel@tonic-gate * 1 - Nak was good. 11937c478bd9Sstevel@tonic-gate */ 11947c478bd9Sstevel@tonic-gate static int 11957c478bd9Sstevel@tonic-gate lcp_nakci(f, p, len) 11967c478bd9Sstevel@tonic-gate fsm *f; 11977c478bd9Sstevel@tonic-gate u_char *p; 11987c478bd9Sstevel@tonic-gate int len; 11997c478bd9Sstevel@tonic-gate { 12007c478bd9Sstevel@tonic-gate lcp_options *go = &lcp_gotoptions[f->unit]; 12017c478bd9Sstevel@tonic-gate lcp_options *wo = &lcp_wantoptions[f->unit]; 12027c478bd9Sstevel@tonic-gate u_char citype, cichar, *next; 12037c478bd9Sstevel@tonic-gate u_short cishort; 12047c478bd9Sstevel@tonic-gate u_int32_t cilong; 12057c478bd9Sstevel@tonic-gate lcp_options no; /* options we've seen Naks for */ 12067c478bd9Sstevel@tonic-gate lcp_options try; /* options to request next time */ 12077c478bd9Sstevel@tonic-gate int looped_back = 0; 12087c478bd9Sstevel@tonic-gate int cilen; 12097c478bd9Sstevel@tonic-gate 12107c478bd9Sstevel@tonic-gate BZERO(&no, sizeof(no)); 12117c478bd9Sstevel@tonic-gate try = *go; 12127c478bd9Sstevel@tonic-gate 12137c478bd9Sstevel@tonic-gate /* 12147c478bd9Sstevel@tonic-gate * Any Nak'd CIs must be in exactly the same order that we sent. 12157c478bd9Sstevel@tonic-gate * Check packet length and CI length at each step. 12167c478bd9Sstevel@tonic-gate * If we find any deviations, then this packet is bad. 12177c478bd9Sstevel@tonic-gate */ 12187c478bd9Sstevel@tonic-gate #define NAKCIVOID(opt, neg) \ 12197c478bd9Sstevel@tonic-gate if (go->neg && \ 12207c478bd9Sstevel@tonic-gate len >= CILEN_VOID && \ 12217c478bd9Sstevel@tonic-gate p[1] == CILEN_VOID && \ 12227c478bd9Sstevel@tonic-gate p[0] == opt) { \ 12237c478bd9Sstevel@tonic-gate len -= CILEN_VOID; \ 12247c478bd9Sstevel@tonic-gate INCPTR(CILEN_VOID, p); \ 12257c478bd9Sstevel@tonic-gate no.neg = 1; \ 12267c478bd9Sstevel@tonic-gate try.neg = 0; \ 12277c478bd9Sstevel@tonic-gate } 12287c478bd9Sstevel@tonic-gate #define NAKCICHAR(opt, neg, code) \ 12297c478bd9Sstevel@tonic-gate if (go->neg && \ 12307c478bd9Sstevel@tonic-gate len >= CILEN_CHAR && \ 12317c478bd9Sstevel@tonic-gate p[1] == CILEN_CHAR && \ 12327c478bd9Sstevel@tonic-gate p[0] == opt) { \ 12337c478bd9Sstevel@tonic-gate len -= CILEN_CHAR; \ 12347c478bd9Sstevel@tonic-gate INCPTR(2, p); \ 12357c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); \ 12367c478bd9Sstevel@tonic-gate no.neg = 1; \ 12377c478bd9Sstevel@tonic-gate code \ 12387c478bd9Sstevel@tonic-gate } 12397c478bd9Sstevel@tonic-gate #define NAKCISHORT(opt, neg, code) \ 12407c478bd9Sstevel@tonic-gate if (go->neg && \ 12417c478bd9Sstevel@tonic-gate len >= CILEN_SHORT && \ 12427c478bd9Sstevel@tonic-gate p[1] == CILEN_SHORT && \ 12437c478bd9Sstevel@tonic-gate p[0] == opt) { \ 12447c478bd9Sstevel@tonic-gate len -= CILEN_SHORT; \ 12457c478bd9Sstevel@tonic-gate INCPTR(2, p); \ 12467c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \ 12477c478bd9Sstevel@tonic-gate no.neg = 1; \ 12487c478bd9Sstevel@tonic-gate code \ 12497c478bd9Sstevel@tonic-gate } 12507c478bd9Sstevel@tonic-gate #define NAKCILONG(opt, neg, code) \ 12517c478bd9Sstevel@tonic-gate if (go->neg && \ 12527c478bd9Sstevel@tonic-gate len >= CILEN_LONG && \ 12537c478bd9Sstevel@tonic-gate p[1] == CILEN_LONG && \ 12547c478bd9Sstevel@tonic-gate p[0] == opt) { \ 12557c478bd9Sstevel@tonic-gate len -= CILEN_LONG; \ 12567c478bd9Sstevel@tonic-gate INCPTR(2, p); \ 12577c478bd9Sstevel@tonic-gate GETLONG(cilong, p); \ 12587c478bd9Sstevel@tonic-gate no.neg = 1; \ 12597c478bd9Sstevel@tonic-gate code \ 12607c478bd9Sstevel@tonic-gate } 12617c478bd9Sstevel@tonic-gate #define NAKCILQR(opt, neg, code) \ 12627c478bd9Sstevel@tonic-gate if (go->neg && \ 12637c478bd9Sstevel@tonic-gate len >= CILEN_LQR && \ 12647c478bd9Sstevel@tonic-gate p[1] == CILEN_LQR && \ 12657c478bd9Sstevel@tonic-gate p[0] == opt) { \ 12667c478bd9Sstevel@tonic-gate len -= CILEN_LQR; \ 12677c478bd9Sstevel@tonic-gate INCPTR(2, p); \ 12687c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \ 12697c478bd9Sstevel@tonic-gate GETLONG(cilong, p); \ 12707c478bd9Sstevel@tonic-gate no.neg = 1; \ 12717c478bd9Sstevel@tonic-gate code \ 12727c478bd9Sstevel@tonic-gate } 12737c478bd9Sstevel@tonic-gate #define NAKCIENDP(opt, neg) \ 12747c478bd9Sstevel@tonic-gate if (go->neg && \ 12757c478bd9Sstevel@tonic-gate len >= CILEN_CHAR && \ 12767c478bd9Sstevel@tonic-gate p[0] == opt && \ 12777c478bd9Sstevel@tonic-gate p[1] >= CILEN_CHAR && \ 12787c478bd9Sstevel@tonic-gate p[1] <= len) { \ 12797c478bd9Sstevel@tonic-gate len -= p[1]; \ 12807c478bd9Sstevel@tonic-gate INCPTR(p[1], p); \ 12817c478bd9Sstevel@tonic-gate no.neg = 1; \ 12827c478bd9Sstevel@tonic-gate try.neg = 0; \ 12837c478bd9Sstevel@tonic-gate } 12847c478bd9Sstevel@tonic-gate 12857c478bd9Sstevel@tonic-gate /* 12867c478bd9Sstevel@tonic-gate * We don't care if they want to send us smaller packets than 12877c478bd9Sstevel@tonic-gate * we want. Therefore, accept any MRU less than what we asked for, 12887c478bd9Sstevel@tonic-gate * but then ignore the new value when setting the MRU in the kernel. 12897c478bd9Sstevel@tonic-gate * If they send us a bigger MRU than what we asked, accept it, up to 12907c478bd9Sstevel@tonic-gate * the limit of the default MRU we'd get if we didn't negotiate. 12917c478bd9Sstevel@tonic-gate */ 12927c478bd9Sstevel@tonic-gate if (go->neg_mru && go->mru != PPP_MRU) { 12937c478bd9Sstevel@tonic-gate NAKCISHORT(CI_MRU, neg_mru, 12947c478bd9Sstevel@tonic-gate if (cishort <= wo->mru || 12957c478bd9Sstevel@tonic-gate (cishort <= PPP_MRU && cishort <= absmax_mru)) 12967c478bd9Sstevel@tonic-gate try.mru = cishort; 12977c478bd9Sstevel@tonic-gate ); 12987c478bd9Sstevel@tonic-gate } 12997c478bd9Sstevel@tonic-gate 13007c478bd9Sstevel@tonic-gate /* 13017c478bd9Sstevel@tonic-gate * Add any characters they want to our (receive-side) asyncmap. 13027c478bd9Sstevel@tonic-gate */ 13037c478bd9Sstevel@tonic-gate if (go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF) { 13047c478bd9Sstevel@tonic-gate NAKCILONG(CI_ASYNCMAP, neg_asyncmap, 13057c478bd9Sstevel@tonic-gate try.asyncmap = go->asyncmap | cilong; 13067c478bd9Sstevel@tonic-gate ); 13077c478bd9Sstevel@tonic-gate } 13087c478bd9Sstevel@tonic-gate 13097c478bd9Sstevel@tonic-gate /* 13107c478bd9Sstevel@tonic-gate * If they've nak'd our authentication-protocol, check whether 13117c478bd9Sstevel@tonic-gate * they are proposing a different protocol, or a different 13127c478bd9Sstevel@tonic-gate * hash algorithm for CHAP. 13137c478bd9Sstevel@tonic-gate */ 13147c478bd9Sstevel@tonic-gate if ((go->neg_chap || go->neg_mschap || go->neg_mschapv2 || go->neg_upap) && 13157c478bd9Sstevel@tonic-gate len >= CILEN_SHORT && p[0] == CI_AUTHTYPE && p[1] >= CILEN_SHORT && 13167c478bd9Sstevel@tonic-gate p[1] <= len) { 13177c478bd9Sstevel@tonic-gate cilen = p[1]; 13187c478bd9Sstevel@tonic-gate len -= cilen; 13197c478bd9Sstevel@tonic-gate INCPTR(2, p); 13207c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); 13217c478bd9Sstevel@tonic-gate peer_nak_auth = 1; 13227c478bd9Sstevel@tonic-gate nak_auth_orig = (go->neg_chap || go->neg_mschap || go->neg_mschapv2) ? 13237c478bd9Sstevel@tonic-gate PPP_CHAP : PPP_PAP; 13247c478bd9Sstevel@tonic-gate nak_auth_proto = cishort; 13257c478bd9Sstevel@tonic-gate if (cishort == PPP_PAP && cilen == CILEN_SHORT) { 13267c478bd9Sstevel@tonic-gate no.neg_upap = go->neg_upap; 13277c478bd9Sstevel@tonic-gate /* 13287c478bd9Sstevel@tonic-gate * If we were asking for CHAP, they obviously don't want to do it. 13297c478bd9Sstevel@tonic-gate * If we weren't asking for CHAP, then we were asking for PAP, 13307c478bd9Sstevel@tonic-gate * in which case this Nak is bad. 13317c478bd9Sstevel@tonic-gate */ 13327c478bd9Sstevel@tonic-gate if (!go->neg_chap && !go->neg_mschap && !go->neg_mschapv2) 13337c478bd9Sstevel@tonic-gate goto bad; 13347c478bd9Sstevel@tonic-gate try.neg_chap = 0; 13357c478bd9Sstevel@tonic-gate try.neg_mschap = 0; 13367c478bd9Sstevel@tonic-gate try.neg_mschapv2 = 0; 13377c478bd9Sstevel@tonic-gate 13387c478bd9Sstevel@tonic-gate } else if (cishort == PPP_CHAP && cilen >= CILEN_CHAP) { 13397c478bd9Sstevel@tonic-gate /* stop asking for that type */ 13407c478bd9Sstevel@tonic-gate switch (go->chap_mdtype) { 13417c478bd9Sstevel@tonic-gate case CHAP_DIGEST_MD5: 13427c478bd9Sstevel@tonic-gate no.neg_chap = go->neg_chap; 13437c478bd9Sstevel@tonic-gate try.neg_chap = 0; 13447c478bd9Sstevel@tonic-gate break; 13457c478bd9Sstevel@tonic-gate case CHAP_MICROSOFT: 13467c478bd9Sstevel@tonic-gate no.neg_mschap = go->neg_mschap; 13477c478bd9Sstevel@tonic-gate try.neg_mschap = 0; 13487c478bd9Sstevel@tonic-gate break; 13497c478bd9Sstevel@tonic-gate case CHAP_MICROSOFT_V2: 13507c478bd9Sstevel@tonic-gate no.neg_mschapv2 = go->neg_mschapv2; 13517c478bd9Sstevel@tonic-gate try.neg_mschapv2 = 0; 13527c478bd9Sstevel@tonic-gate break; 13537c478bd9Sstevel@tonic-gate } 13547c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); 13557c478bd9Sstevel@tonic-gate /* Allow >= on length here for broken and silly peers. */ 13567c478bd9Sstevel@tonic-gate p += cilen - CILEN_CHAP; 13577c478bd9Sstevel@tonic-gate try.neg_upap = 0; 13587c478bd9Sstevel@tonic-gate if ((cichar == CHAP_DIGEST_MD5 && wo->neg_chap) || 13597c478bd9Sstevel@tonic-gate (cichar == CHAP_MICROSOFT && wo->neg_mschap) || 13607c478bd9Sstevel@tonic-gate (cichar == CHAP_MICROSOFT_V2 && wo->neg_mschapv2)) { 1361*48bbca81SDaniel Hoffman /* Try its requested algorithm. */ 13627c478bd9Sstevel@tonic-gate try.chap_mdtype = cichar; 13637c478bd9Sstevel@tonic-gate } else { 13647c478bd9Sstevel@tonic-gate goto try_another; 13657c478bd9Sstevel@tonic-gate } 13667c478bd9Sstevel@tonic-gate 13677c478bd9Sstevel@tonic-gate } else { 13687c478bd9Sstevel@tonic-gate /* 13697c478bd9Sstevel@tonic-gate * We don't recognize what they're suggesting. 13707c478bd9Sstevel@tonic-gate * Stop asking for what we were asking for. 13717c478bd9Sstevel@tonic-gate */ 13727c478bd9Sstevel@tonic-gate try_another: 13737c478bd9Sstevel@tonic-gate if (go->neg_chap || go->neg_mschap || go->neg_mschapv2) { 13747c478bd9Sstevel@tonic-gate switch (go->chap_mdtype) { 13757c478bd9Sstevel@tonic-gate case CHAP_DIGEST_MD5: 13767c478bd9Sstevel@tonic-gate try.neg_chap = 0; 13777c478bd9Sstevel@tonic-gate if (wo->neg_mschap) { 13787c478bd9Sstevel@tonic-gate try.chap_mdtype = CHAP_MICROSOFT; 13797c478bd9Sstevel@tonic-gate break; 13807c478bd9Sstevel@tonic-gate } 13817c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/ 13827c478bd9Sstevel@tonic-gate case CHAP_MICROSOFT: 13837c478bd9Sstevel@tonic-gate try.neg_mschap = 0; 13847c478bd9Sstevel@tonic-gate if (wo->neg_mschapv2) { 13857c478bd9Sstevel@tonic-gate try.chap_mdtype = CHAP_MICROSOFT_V2; 13867c478bd9Sstevel@tonic-gate break; 13877c478bd9Sstevel@tonic-gate } 13887c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/ 13897c478bd9Sstevel@tonic-gate case CHAP_MICROSOFT_V2: 13907c478bd9Sstevel@tonic-gate try.neg_mschapv2 = 0; 13917c478bd9Sstevel@tonic-gate break; 13927c478bd9Sstevel@tonic-gate } 13937c478bd9Sstevel@tonic-gate } else 13947c478bd9Sstevel@tonic-gate try.neg_upap = 0; 13957c478bd9Sstevel@tonic-gate p += cilen - CILEN_SHORT; 13967c478bd9Sstevel@tonic-gate } 13977c478bd9Sstevel@tonic-gate } 13987c478bd9Sstevel@tonic-gate 13997c478bd9Sstevel@tonic-gate /* 14007c478bd9Sstevel@tonic-gate * If they can't cope with our link quality protocol, we'll have 14017c478bd9Sstevel@tonic-gate * to stop asking for LQR. We haven't got any other protocol. If 14027c478bd9Sstevel@tonic-gate * they Nak the reporting period, then the following logic 14037c478bd9Sstevel@tonic-gate * applies: 1404*48bbca81SDaniel Hoffman * If it suggests zero and go->neg_fcs is true and 1405*48bbca81SDaniel Hoffman * ao->lqr_period isn't zero, then take its suggestion. If it 1406*48bbca81SDaniel Hoffman * suggests zero otherwise, ignore it. If it suggests a nonzero 1407*48bbca81SDaniel Hoffman * value and wo->lqr_period is zero, then take its suggestion. If 1408*48bbca81SDaniel Hoffman * it suggests a nonzero value otherwise that's less than 14097c478bd9Sstevel@tonic-gate * wo->lqr_period, then ignore it. 14107c478bd9Sstevel@tonic-gate */ 14117c478bd9Sstevel@tonic-gate NAKCILQR(CI_QUALITY, neg_lqr, 14127c478bd9Sstevel@tonic-gate if (cishort != PPP_LQR) 14137c478bd9Sstevel@tonic-gate try.neg_lqr = 0; 14147c478bd9Sstevel@tonic-gate else if (cilong == 0 && go->neg_fcs && wo->lqr_period != 0) 14157c478bd9Sstevel@tonic-gate try.lqr_period = cilong; 14167c478bd9Sstevel@tonic-gate else if (cilong != 0 && 14177c478bd9Sstevel@tonic-gate (wo->lqr_period == 0 || cilong > wo->lqr_period)) 14187c478bd9Sstevel@tonic-gate try.lqr_period = cilong; 14197c478bd9Sstevel@tonic-gate ); 14207c478bd9Sstevel@tonic-gate 14217c478bd9Sstevel@tonic-gate /* 14227c478bd9Sstevel@tonic-gate * Only implementing CBCP...not the rest of the callback options 14237c478bd9Sstevel@tonic-gate */ 14247c478bd9Sstevel@tonic-gate NAKCICHAR(CI_CALLBACK, neg_cbcp, 14257c478bd9Sstevel@tonic-gate try.neg_cbcp = 0; 14267c478bd9Sstevel@tonic-gate ); 14277c478bd9Sstevel@tonic-gate 14287c478bd9Sstevel@tonic-gate /* 14297c478bd9Sstevel@tonic-gate * Check for a looped-back line. 14307c478bd9Sstevel@tonic-gate */ 14317c478bd9Sstevel@tonic-gate NAKCILONG(CI_MAGICNUMBER, neg_magicnumber, 14327c478bd9Sstevel@tonic-gate try.magicnumber = magic(); 14337c478bd9Sstevel@tonic-gate looped_back = 1; 14347c478bd9Sstevel@tonic-gate ); 14357c478bd9Sstevel@tonic-gate 14367c478bd9Sstevel@tonic-gate /* 14377c478bd9Sstevel@tonic-gate * Peer shouldn't send Nak for protocol compression or 14387c478bd9Sstevel@tonic-gate * address/control compression requests; they should send 14397c478bd9Sstevel@tonic-gate * a Reject instead. If they send a Nak, treat it as a Reject. 14407c478bd9Sstevel@tonic-gate */ 14417c478bd9Sstevel@tonic-gate NAKCIVOID(CI_PCOMPRESSION, neg_pcompression); 14427c478bd9Sstevel@tonic-gate NAKCIVOID(CI_ACCOMPRESSION, neg_accompression); 14437c478bd9Sstevel@tonic-gate 14447c478bd9Sstevel@tonic-gate /* 1445*48bbca81SDaniel Hoffman * Remove any FCS types it doesn't like from our (receive-side) 14467c478bd9Sstevel@tonic-gate * FCS list. 14477c478bd9Sstevel@tonic-gate */ 14487c478bd9Sstevel@tonic-gate NAKCICHAR(CI_FCSALTERN, neg_fcs, try.fcs_type = go->fcs_type & cichar;); 14497c478bd9Sstevel@tonic-gate 14507c478bd9Sstevel@tonic-gate #ifdef MUX_FRAME 14517c478bd9Sstevel@tonic-gate /* Nacked MUX option */ 14527c478bd9Sstevel@tonic-gate NAKCIVOID(CI_MUXING, pppmux); 14537c478bd9Sstevel@tonic-gate #endif 14547c478bd9Sstevel@tonic-gate 14557c478bd9Sstevel@tonic-gate /* 14567c478bd9Sstevel@tonic-gate * Nak of the endpoint discriminator option is not permitted, 14577c478bd9Sstevel@tonic-gate * treat it like a reject. 14587c478bd9Sstevel@tonic-gate */ 14597c478bd9Sstevel@tonic-gate NAKCIENDP(CI_EPDISC, neg_endpoint); 14607c478bd9Sstevel@tonic-gate 14617c478bd9Sstevel@tonic-gate /* 14627c478bd9Sstevel@tonic-gate * Nak for MRRU option - accept their value if it is smaller 14637c478bd9Sstevel@tonic-gate * than the one we want. 14647c478bd9Sstevel@tonic-gate */ 14657c478bd9Sstevel@tonic-gate if (go->neg_mrru) { 14667c478bd9Sstevel@tonic-gate NAKCISHORT(CI_MRRU, neg_mrru, 14677c478bd9Sstevel@tonic-gate if (cishort <= wo->mrru) 14687c478bd9Sstevel@tonic-gate try.mrru = cishort; 14697c478bd9Sstevel@tonic-gate ); 14707c478bd9Sstevel@tonic-gate } 14717c478bd9Sstevel@tonic-gate 14727c478bd9Sstevel@tonic-gate /* 14737c478bd9Sstevel@tonic-gate * Nak for short sequence numbers shouldn't be sent, treat it 14747c478bd9Sstevel@tonic-gate * like a reject. 14757c478bd9Sstevel@tonic-gate */ 14767c478bd9Sstevel@tonic-gate NAKCIVOID(CI_SSNHF, neg_ssnhf); 14777c478bd9Sstevel@tonic-gate 14787c478bd9Sstevel@tonic-gate /* 14797c478bd9Sstevel@tonic-gate * There may be remaining CIs, if the peer is requesting negotiation 14807c478bd9Sstevel@tonic-gate * on an option that we didn't include in our request packet. 14817c478bd9Sstevel@tonic-gate * If we see an option that we requested, or one we've already seen 14827c478bd9Sstevel@tonic-gate * in this packet, then this packet is bad. 14837c478bd9Sstevel@tonic-gate * If we wanted to respond by starting to negotiate on the requested 14847c478bd9Sstevel@tonic-gate * option(s), we could, but we don't, because except for the 14857c478bd9Sstevel@tonic-gate * authentication type and quality protocol, if we are not negotiating 14867c478bd9Sstevel@tonic-gate * an option, it is because we were told not to. 14877c478bd9Sstevel@tonic-gate * For the authentication type, the Nak from the peer means 14887c478bd9Sstevel@tonic-gate * `let me authenticate myself with you' which is a bit pointless. 14897c478bd9Sstevel@tonic-gate * For the quality protocol, the Nak means `ask me to send you quality 14907c478bd9Sstevel@tonic-gate * reports', but if we didn't ask for them, we don't want them. 14917c478bd9Sstevel@tonic-gate * An option we don't recognize represents the peer asking to 14927c478bd9Sstevel@tonic-gate * negotiate some option we don't support, so ignore it. 14937c478bd9Sstevel@tonic-gate */ 14947c478bd9Sstevel@tonic-gate while (len > CILEN_VOID) { 14957c478bd9Sstevel@tonic-gate GETCHAR(citype, p); 14967c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); 14977c478bd9Sstevel@tonic-gate if (cilen < CILEN_VOID || (len -= cilen) < 0) 14987c478bd9Sstevel@tonic-gate goto bad; 14997c478bd9Sstevel@tonic-gate next = p + cilen - 2; 15007c478bd9Sstevel@tonic-gate 15017c478bd9Sstevel@tonic-gate switch (citype) { 15027c478bd9Sstevel@tonic-gate case CI_MRU: 15037c478bd9Sstevel@tonic-gate if ((go->neg_mru && go->mru != PPP_MRU) 15047c478bd9Sstevel@tonic-gate || no.neg_mru || cilen != CILEN_SHORT) 15057c478bd9Sstevel@tonic-gate goto bad; 15067c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); 15077c478bd9Sstevel@tonic-gate if (cishort < PPP_MRU && cishort < absmax_mru) { 15087c478bd9Sstevel@tonic-gate try.neg_mru = 1; 15097c478bd9Sstevel@tonic-gate try.mru = cishort; 15107c478bd9Sstevel@tonic-gate notice("Peer sent unsolicited Nak for MRU less than default."); 15117c478bd9Sstevel@tonic-gate } 15127c478bd9Sstevel@tonic-gate break; 15137c478bd9Sstevel@tonic-gate case CI_ASYNCMAP: 15147c478bd9Sstevel@tonic-gate if ((go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF) 15157c478bd9Sstevel@tonic-gate || no.neg_asyncmap || cilen != CILEN_LONG) 15167c478bd9Sstevel@tonic-gate goto bad; 15177c478bd9Sstevel@tonic-gate break; 15187c478bd9Sstevel@tonic-gate case CI_AUTHTYPE: 15197c478bd9Sstevel@tonic-gate unsolicited_nak_auth = 1; 15207c478bd9Sstevel@tonic-gate if (cilen >= CILEN_SHORT) { 15217c478bd9Sstevel@tonic-gate GETSHORT(unsolicit_auth_proto, p); 15227c478bd9Sstevel@tonic-gate } else { 15237c478bd9Sstevel@tonic-gate unsolicit_auth_proto = 0; 15247c478bd9Sstevel@tonic-gate } 15257c478bd9Sstevel@tonic-gate if (go->neg_chap || no.neg_chap || 15267c478bd9Sstevel@tonic-gate go->neg_mschap || no.neg_mschap || 15277c478bd9Sstevel@tonic-gate go->neg_mschapv2 || no.neg_mschapv2 || 15287c478bd9Sstevel@tonic-gate go->neg_upap || no.neg_upap) 15297c478bd9Sstevel@tonic-gate goto bad; 15307c478bd9Sstevel@tonic-gate break; 15317c478bd9Sstevel@tonic-gate case CI_MAGICNUMBER: 15327c478bd9Sstevel@tonic-gate if (go->neg_magicnumber || no.neg_magicnumber || 15337c478bd9Sstevel@tonic-gate cilen != CILEN_LONG) 15347c478bd9Sstevel@tonic-gate goto bad; 15357c478bd9Sstevel@tonic-gate break; 15367c478bd9Sstevel@tonic-gate case CI_PCOMPRESSION: 15377c478bd9Sstevel@tonic-gate if (go->neg_pcompression || no.neg_pcompression 15387c478bd9Sstevel@tonic-gate || cilen != CILEN_VOID) 15397c478bd9Sstevel@tonic-gate goto bad; 15407c478bd9Sstevel@tonic-gate break; 15417c478bd9Sstevel@tonic-gate case CI_ACCOMPRESSION: 15427c478bd9Sstevel@tonic-gate if (go->neg_accompression || no.neg_accompression 15437c478bd9Sstevel@tonic-gate || cilen != CILEN_VOID) 15447c478bd9Sstevel@tonic-gate goto bad; 15457c478bd9Sstevel@tonic-gate break; 15467c478bd9Sstevel@tonic-gate case CI_QUALITY: 15477c478bd9Sstevel@tonic-gate if (go->neg_lqr || no.neg_lqr || cilen != CILEN_LQR) 15487c478bd9Sstevel@tonic-gate goto bad; 15497c478bd9Sstevel@tonic-gate break; 15507c478bd9Sstevel@tonic-gate case CI_MRRU: 15517c478bd9Sstevel@tonic-gate if (go->neg_mrru || no.neg_mrru || cilen != CILEN_SHORT) 15527c478bd9Sstevel@tonic-gate goto bad; 15537c478bd9Sstevel@tonic-gate break; 15547c478bd9Sstevel@tonic-gate case CI_SSNHF: 15557c478bd9Sstevel@tonic-gate if (go->neg_ssnhf || no.neg_ssnhf || cilen != CILEN_VOID) 15567c478bd9Sstevel@tonic-gate goto bad; 15577c478bd9Sstevel@tonic-gate try.neg_ssnhf = 1; 15587c478bd9Sstevel@tonic-gate break; 15597c478bd9Sstevel@tonic-gate case CI_EPDISC: 15607c478bd9Sstevel@tonic-gate if (go->neg_endpoint || no.neg_endpoint || cilen < CILEN_CHAR) 15617c478bd9Sstevel@tonic-gate goto bad; 15627c478bd9Sstevel@tonic-gate break; 15637c478bd9Sstevel@tonic-gate case CI_FCSALTERN: 15647c478bd9Sstevel@tonic-gate if (go->neg_fcs || no.neg_fcs || cilen < CILEN_CHAR) 15657c478bd9Sstevel@tonic-gate goto bad; 15667c478bd9Sstevel@tonic-gate break; 15677c478bd9Sstevel@tonic-gate #ifdef MUX_FRAME 15687c478bd9Sstevel@tonic-gate case CI_MUXING: 15697c478bd9Sstevel@tonic-gate if (go->pppmux || no.pppmux || cilen < CILEN_VOID) 15707c478bd9Sstevel@tonic-gate goto bad; 15717c478bd9Sstevel@tonic-gate break; 15727c478bd9Sstevel@tonic-gate #endif 15737c478bd9Sstevel@tonic-gate } 15747c478bd9Sstevel@tonic-gate p = next; 15757c478bd9Sstevel@tonic-gate } 15767c478bd9Sstevel@tonic-gate 15777c478bd9Sstevel@tonic-gate /* 15787c478bd9Sstevel@tonic-gate * OK, the Nak is good. Now we can update state. 15797c478bd9Sstevel@tonic-gate * If there are any options left we ignore them. 15807c478bd9Sstevel@tonic-gate */ 15817c478bd9Sstevel@tonic-gate if (f->state != OPENED) { 15827c478bd9Sstevel@tonic-gate /* 15837c478bd9Sstevel@tonic-gate * Note: the code once reset try.numloops to zero here if 15847c478bd9Sstevel@tonic-gate * looped_back wasn't set. This is wrong because a mixture of 15857c478bd9Sstevel@tonic-gate * looped-back and peer data (possible if half-duplex is used) 15867c478bd9Sstevel@tonic-gate * will allow the link to come up, and it shouldn't. 15877c478bd9Sstevel@tonic-gate */ 15887c478bd9Sstevel@tonic-gate if (looped_back) { 15897c478bd9Sstevel@tonic-gate if (++try.numloops >= lcp_loopbackfail) { 15907c478bd9Sstevel@tonic-gate notice("Serial line is looped back."); 15917c478bd9Sstevel@tonic-gate lcp_close(f->unit, "Loopback detected"); 15927c478bd9Sstevel@tonic-gate status = EXIT_LOOPBACK; 15937c478bd9Sstevel@tonic-gate } 15947c478bd9Sstevel@tonic-gate } 15957c478bd9Sstevel@tonic-gate *go = try; 15967c478bd9Sstevel@tonic-gate } 15977c478bd9Sstevel@tonic-gate 15987c478bd9Sstevel@tonic-gate return 1; 15997c478bd9Sstevel@tonic-gate 16007c478bd9Sstevel@tonic-gate bad: 16017c478bd9Sstevel@tonic-gate dbglog("lcp_nakci: received bad Nak!"); 16027c478bd9Sstevel@tonic-gate return 0; 16037c478bd9Sstevel@tonic-gate } 16047c478bd9Sstevel@tonic-gate 16057c478bd9Sstevel@tonic-gate 16067c478bd9Sstevel@tonic-gate /* 16077c478bd9Sstevel@tonic-gate * lcp_rejci - Peer has Rejected some of our CIs. 16087c478bd9Sstevel@tonic-gate * This should not modify any state if the Reject is bad 16097c478bd9Sstevel@tonic-gate * or if LCP is in the OPENED state. 16107c478bd9Sstevel@tonic-gate * 16117c478bd9Sstevel@tonic-gate * Returns: 16127c478bd9Sstevel@tonic-gate * 0 - Reject was bad. 16137c478bd9Sstevel@tonic-gate * 1 - Reject was good. 16147c478bd9Sstevel@tonic-gate */ 16157c478bd9Sstevel@tonic-gate static int 16167c478bd9Sstevel@tonic-gate lcp_rejci(f, p, len) 16177c478bd9Sstevel@tonic-gate fsm *f; 16187c478bd9Sstevel@tonic-gate u_char *p; 16197c478bd9Sstevel@tonic-gate int len; 16207c478bd9Sstevel@tonic-gate { 16217c478bd9Sstevel@tonic-gate lcp_options *go = &lcp_gotoptions[f->unit]; 16227c478bd9Sstevel@tonic-gate u_char cichar; 16237c478bd9Sstevel@tonic-gate u_short cishort; 16247c478bd9Sstevel@tonic-gate u_int32_t cilong; 16257c478bd9Sstevel@tonic-gate lcp_options try; /* options to request next time */ 16267c478bd9Sstevel@tonic-gate 16277c478bd9Sstevel@tonic-gate try = *go; 16287c478bd9Sstevel@tonic-gate 16297c478bd9Sstevel@tonic-gate /* 16307c478bd9Sstevel@tonic-gate * Any Rejected CIs must be in exactly the same order that we sent. 16317c478bd9Sstevel@tonic-gate * Check packet length and CI length at each step. 16327c478bd9Sstevel@tonic-gate * If we find any deviations, then this packet is bad. 16337c478bd9Sstevel@tonic-gate */ 16347c478bd9Sstevel@tonic-gate #define REJCIVOID(opt, neg) \ 16357c478bd9Sstevel@tonic-gate if (go->neg && \ 16367c478bd9Sstevel@tonic-gate len >= CILEN_VOID && \ 16377c478bd9Sstevel@tonic-gate p[1] == CILEN_VOID && \ 16387c478bd9Sstevel@tonic-gate p[0] == opt) { \ 16397c478bd9Sstevel@tonic-gate len -= CILEN_VOID; \ 16407c478bd9Sstevel@tonic-gate INCPTR(CILEN_VOID, p); \ 16417c478bd9Sstevel@tonic-gate try.neg = 0; \ 16427c478bd9Sstevel@tonic-gate } 16437c478bd9Sstevel@tonic-gate #define REJCICHAR(opt, neg, val) \ 16447c478bd9Sstevel@tonic-gate if (go->neg && \ 16457c478bd9Sstevel@tonic-gate len >= CILEN_CHAR && \ 16467c478bd9Sstevel@tonic-gate p[1] == CILEN_CHAR && \ 16477c478bd9Sstevel@tonic-gate p[0] == opt) { \ 16487c478bd9Sstevel@tonic-gate len -= CILEN_CHAR; \ 16497c478bd9Sstevel@tonic-gate INCPTR(2, p); \ 16507c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); \ 16517c478bd9Sstevel@tonic-gate /* Check rejected value. */ \ 16527c478bd9Sstevel@tonic-gate if (cichar != val) \ 16537c478bd9Sstevel@tonic-gate goto bad; \ 16547c478bd9Sstevel@tonic-gate try.neg = 0; \ 16557c478bd9Sstevel@tonic-gate } 16567c478bd9Sstevel@tonic-gate #define REJCISHORT(opt, neg, val) \ 16577c478bd9Sstevel@tonic-gate if (go->neg && \ 16587c478bd9Sstevel@tonic-gate len >= CILEN_SHORT && \ 16597c478bd9Sstevel@tonic-gate p[1] == CILEN_SHORT && \ 16607c478bd9Sstevel@tonic-gate p[0] == opt) { \ 16617c478bd9Sstevel@tonic-gate len -= CILEN_SHORT; \ 16627c478bd9Sstevel@tonic-gate INCPTR(2, p); \ 16637c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \ 16647c478bd9Sstevel@tonic-gate /* Check rejected value. */ \ 16657c478bd9Sstevel@tonic-gate if (cishort != val) \ 16667c478bd9Sstevel@tonic-gate goto bad; \ 16677c478bd9Sstevel@tonic-gate try.neg = 0; \ 16687c478bd9Sstevel@tonic-gate } 16697c478bd9Sstevel@tonic-gate #define REJCIAUTH(opt, neg, val) \ 16707c478bd9Sstevel@tonic-gate if (go->neg && \ 16717c478bd9Sstevel@tonic-gate len >= CILEN_SHORT && \ 16727c478bd9Sstevel@tonic-gate p[1] == CILEN_SHORT && \ 16737c478bd9Sstevel@tonic-gate p[0] == opt) { \ 16747c478bd9Sstevel@tonic-gate len -= CILEN_SHORT; \ 16757c478bd9Sstevel@tonic-gate INCPTR(2, p); \ 16767c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \ 16777c478bd9Sstevel@tonic-gate /* Check rejected value. */ \ 16787c478bd9Sstevel@tonic-gate peer_reject_auth = 1; \ 16797c478bd9Sstevel@tonic-gate reject_auth_proto = cishort; \ 16807c478bd9Sstevel@tonic-gate if (cishort != val) \ 16817c478bd9Sstevel@tonic-gate goto bad; \ 16827c478bd9Sstevel@tonic-gate try.neg = 0; \ 16837c478bd9Sstevel@tonic-gate } 16847c478bd9Sstevel@tonic-gate #define REJCILONG(opt, neg, val) \ 16857c478bd9Sstevel@tonic-gate if (go->neg && \ 16867c478bd9Sstevel@tonic-gate len >= CILEN_LONG && \ 16877c478bd9Sstevel@tonic-gate p[1] == CILEN_LONG && \ 16887c478bd9Sstevel@tonic-gate p[0] == opt) { \ 16897c478bd9Sstevel@tonic-gate len -= CILEN_LONG; \ 16907c478bd9Sstevel@tonic-gate INCPTR(2, p); \ 16917c478bd9Sstevel@tonic-gate GETLONG(cilong, p); \ 16927c478bd9Sstevel@tonic-gate /* Check rejected value. */ \ 16937c478bd9Sstevel@tonic-gate if (cilong != val) \ 16947c478bd9Sstevel@tonic-gate goto bad; \ 16957c478bd9Sstevel@tonic-gate try.neg = 0; \ 16967c478bd9Sstevel@tonic-gate } 16977c478bd9Sstevel@tonic-gate #define REJCILQR(opt, neg, val) \ 16987c478bd9Sstevel@tonic-gate if (go->neg && \ 16997c478bd9Sstevel@tonic-gate len >= CILEN_LQR && \ 17007c478bd9Sstevel@tonic-gate p[1] == CILEN_LQR && \ 17017c478bd9Sstevel@tonic-gate p[0] == opt) { \ 17027c478bd9Sstevel@tonic-gate len -= CILEN_LQR; \ 17037c478bd9Sstevel@tonic-gate INCPTR(2, p); \ 17047c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \ 17057c478bd9Sstevel@tonic-gate GETLONG(cilong, p); \ 17067c478bd9Sstevel@tonic-gate /* Check rejected value. */ \ 17077c478bd9Sstevel@tonic-gate if (cishort != PPP_LQR || cilong != val) \ 17087c478bd9Sstevel@tonic-gate goto bad; \ 17097c478bd9Sstevel@tonic-gate try.neg = 0; \ 17107c478bd9Sstevel@tonic-gate } 17117c478bd9Sstevel@tonic-gate #define REJCICBCP(opt, neg, val) \ 17127c478bd9Sstevel@tonic-gate if (go->neg && \ 17137c478bd9Sstevel@tonic-gate len >= CILEN_CBCP && \ 17147c478bd9Sstevel@tonic-gate p[1] == CILEN_CBCP && \ 17157c478bd9Sstevel@tonic-gate p[0] == opt) { \ 17167c478bd9Sstevel@tonic-gate len -= CILEN_CBCP; \ 17177c478bd9Sstevel@tonic-gate INCPTR(2, p); \ 17187c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); \ 17197c478bd9Sstevel@tonic-gate /* Check rejected value. */ \ 17207c478bd9Sstevel@tonic-gate if (cichar != val) \ 17217c478bd9Sstevel@tonic-gate goto bad; \ 17227c478bd9Sstevel@tonic-gate try.neg = 0; \ 17237c478bd9Sstevel@tonic-gate } 17247c478bd9Sstevel@tonic-gate #define REJCIENDP(opt, neg, class, val, vlen) \ 17257c478bd9Sstevel@tonic-gate if (go->neg && \ 17267c478bd9Sstevel@tonic-gate len >= CILEN_CHAR + vlen && \ 17277c478bd9Sstevel@tonic-gate p[0] == opt && \ 17287c478bd9Sstevel@tonic-gate p[1] == CILEN_CHAR + vlen) { \ 17297c478bd9Sstevel@tonic-gate int i; \ 17307c478bd9Sstevel@tonic-gate len -= CILEN_CHAR + vlen; \ 17317c478bd9Sstevel@tonic-gate INCPTR(2, p); \ 17327c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); \ 17337c478bd9Sstevel@tonic-gate if (cichar != class) \ 17347c478bd9Sstevel@tonic-gate goto bad; \ 17357c478bd9Sstevel@tonic-gate for (i = 0; i < vlen; ++i) { \ 17367c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); \ 17377c478bd9Sstevel@tonic-gate if (cichar != val[i]) \ 17387c478bd9Sstevel@tonic-gate goto bad; \ 17397c478bd9Sstevel@tonic-gate } \ 17407c478bd9Sstevel@tonic-gate try.neg = 0; \ 17417c478bd9Sstevel@tonic-gate } 17427c478bd9Sstevel@tonic-gate 17437c478bd9Sstevel@tonic-gate /* Received a Configure-Reject, try to send Identification now. */ 17447c478bd9Sstevel@tonic-gate if (!noident && sentident < 3) { 17457c478bd9Sstevel@tonic-gate LcpSendIdentification(f); 17467c478bd9Sstevel@tonic-gate sentident++; 17477c478bd9Sstevel@tonic-gate } 17487c478bd9Sstevel@tonic-gate 17497c478bd9Sstevel@tonic-gate REJCISHORT(CI_MRU, neg_mru, go->mru); 17507c478bd9Sstevel@tonic-gate REJCILONG(CI_ASYNCMAP, neg_asyncmap, go->asyncmap); 17517c478bd9Sstevel@tonic-gate 17527c478bd9Sstevel@tonic-gate /* 17537c478bd9Sstevel@tonic-gate * There are broken peers (such as unbundled Solaris PPP) that 17547c478bd9Sstevel@tonic-gate * send Configure-Reject for authentication when they really 17557c478bd9Sstevel@tonic-gate * intend Configure-Nak. This code works around this problem. 17567c478bd9Sstevel@tonic-gate */ 17577c478bd9Sstevel@tonic-gate if ((go->neg_chap || go->neg_mschap || go->neg_mschapv2) && 17587c478bd9Sstevel@tonic-gate len >= CILEN_CHAP && p[1] == CILEN_CHAP && p[0] == CI_AUTHTYPE) { 17597c478bd9Sstevel@tonic-gate len -= CILEN_CHAP; 17607c478bd9Sstevel@tonic-gate INCPTR(2, p); 17617c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); 17627c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); 17637c478bd9Sstevel@tonic-gate peer_reject_auth = 1; 17647c478bd9Sstevel@tonic-gate reject_auth_proto = cishort; 17657c478bd9Sstevel@tonic-gate /* Check rejected value. */ 17667c478bd9Sstevel@tonic-gate if (cishort != PPP_CHAP || cichar != go->chap_mdtype) 17677c478bd9Sstevel@tonic-gate goto bad; 1768*48bbca81SDaniel Hoffman /* Disable the one that it rejected */ 17697c478bd9Sstevel@tonic-gate switch (cichar) { 17707c478bd9Sstevel@tonic-gate case CHAP_DIGEST_MD5: 17717c478bd9Sstevel@tonic-gate try.neg_chap = 0; 17727c478bd9Sstevel@tonic-gate break; 17737c478bd9Sstevel@tonic-gate case CHAP_MICROSOFT: 17747c478bd9Sstevel@tonic-gate try.neg_mschap = 0; 17757c478bd9Sstevel@tonic-gate break; 17767c478bd9Sstevel@tonic-gate case CHAP_MICROSOFT_V2: 17777c478bd9Sstevel@tonic-gate try.neg_mschapv2 = 0; 17787c478bd9Sstevel@tonic-gate break; 17797c478bd9Sstevel@tonic-gate } 17807c478bd9Sstevel@tonic-gate /* Try another, if we can. */ 17817c478bd9Sstevel@tonic-gate if (try.neg_chap) 17827c478bd9Sstevel@tonic-gate try.chap_mdtype = CHAP_DIGEST_MD5; 17837c478bd9Sstevel@tonic-gate else if (try.neg_mschap) 17847c478bd9Sstevel@tonic-gate try.chap_mdtype = CHAP_MICROSOFT; 17857c478bd9Sstevel@tonic-gate else 17867c478bd9Sstevel@tonic-gate try.chap_mdtype = CHAP_MICROSOFT_V2; 17877c478bd9Sstevel@tonic-gate } 17887c478bd9Sstevel@tonic-gate 17897c478bd9Sstevel@tonic-gate if (!go->neg_chap && !go->neg_mschap && !go->neg_mschapv2) { 17907c478bd9Sstevel@tonic-gate REJCIAUTH(CI_AUTHTYPE, neg_upap, PPP_PAP); 17917c478bd9Sstevel@tonic-gate } 17927c478bd9Sstevel@tonic-gate REJCILQR(CI_QUALITY, neg_lqr, go->lqr_period); 17937c478bd9Sstevel@tonic-gate REJCICBCP(CI_CALLBACK, neg_cbcp, CBOP_CBCP); 17947c478bd9Sstevel@tonic-gate REJCILONG(CI_MAGICNUMBER, neg_magicnumber, go->magicnumber); 17957c478bd9Sstevel@tonic-gate REJCIVOID(CI_PCOMPRESSION, neg_pcompression); 17967c478bd9Sstevel@tonic-gate REJCIVOID(CI_ACCOMPRESSION, neg_accompression); 17977c478bd9Sstevel@tonic-gate REJCICHAR(CI_FCSALTERN, neg_fcs, go->fcs_type); 17987c478bd9Sstevel@tonic-gate #ifdef MUX_FRAME 17997c478bd9Sstevel@tonic-gate REJCIVOID(CI_MUXING,pppmux); 18007c478bd9Sstevel@tonic-gate #endif 18017c478bd9Sstevel@tonic-gate REJCIENDP(CI_EPDISC, neg_endpoint, go->endpoint.class, 18027c478bd9Sstevel@tonic-gate go->endpoint.value, go->endpoint.length); 18037c478bd9Sstevel@tonic-gate REJCISHORT(CI_MRRU, neg_mrru, go->mrru); 18047c478bd9Sstevel@tonic-gate REJCIVOID(CI_SSNHF, neg_ssnhf); 18057c478bd9Sstevel@tonic-gate 18067c478bd9Sstevel@tonic-gate /* 18077c478bd9Sstevel@tonic-gate * If there are any remaining CIs, then this packet is bad. 18087c478bd9Sstevel@tonic-gate */ 18097c478bd9Sstevel@tonic-gate if (len != 0) 18107c478bd9Sstevel@tonic-gate goto bad; 18117c478bd9Sstevel@tonic-gate /* 18127c478bd9Sstevel@tonic-gate * Now we can update state. 18137c478bd9Sstevel@tonic-gate */ 18147c478bd9Sstevel@tonic-gate if (f->state != OPENED) 18157c478bd9Sstevel@tonic-gate *go = try; 18167c478bd9Sstevel@tonic-gate return 1; 18177c478bd9Sstevel@tonic-gate 18187c478bd9Sstevel@tonic-gate bad: 18197c478bd9Sstevel@tonic-gate dbglog("lcp_rejci: received bad Reject!"); 18207c478bd9Sstevel@tonic-gate return 0; 18217c478bd9Sstevel@tonic-gate } 18227c478bd9Sstevel@tonic-gate 18237c478bd9Sstevel@tonic-gate 18247c478bd9Sstevel@tonic-gate /* 18257c478bd9Sstevel@tonic-gate * lcp_reqci - Check the peer's requested CIs and send appropriate response. 18267c478bd9Sstevel@tonic-gate * 18277c478bd9Sstevel@tonic-gate * Returns: CODE_CONFACK, CODE_CONFNAK or CODE_CONFREJ and input 18287c478bd9Sstevel@tonic-gate * packet modified appropriately. If reject_if_disagree is non-zero, 18297c478bd9Sstevel@tonic-gate * doesn't return CODE_CONFNAK; returns CODE_CONFREJ if it can't 18307c478bd9Sstevel@tonic-gate * return CODE_CONFACK. 18317c478bd9Sstevel@tonic-gate */ 18327c478bd9Sstevel@tonic-gate static int 18337c478bd9Sstevel@tonic-gate lcp_reqci(f, p, lenp, dont_nak) 18347c478bd9Sstevel@tonic-gate fsm *f; 18357c478bd9Sstevel@tonic-gate u_char *p; /* Requested CIs */ 18367c478bd9Sstevel@tonic-gate int *lenp; /* Length of requested CIs */ 18377c478bd9Sstevel@tonic-gate int dont_nak; 18387c478bd9Sstevel@tonic-gate { 18397c478bd9Sstevel@tonic-gate lcp_options *wo = &lcp_wantoptions[f->unit]; 18407c478bd9Sstevel@tonic-gate lcp_options *go = &lcp_gotoptions[f->unit]; 18417c478bd9Sstevel@tonic-gate lcp_options *ho = &lcp_hisoptions[f->unit]; 18427c478bd9Sstevel@tonic-gate lcp_options *ao = &lcp_allowoptions[f->unit]; 18437c478bd9Sstevel@tonic-gate int cilen, citype, cichar; /* Parsed len, type, char value */ 18447c478bd9Sstevel@tonic-gate u_short cishort; /* Parsed short value */ 18457c478bd9Sstevel@tonic-gate u_int32_t cilong; /* Parse long value */ 18467c478bd9Sstevel@tonic-gate int ret, newret; 18477c478bd9Sstevel@tonic-gate u_char *p0, *nakp, *rejp, *prev; 18487c478bd9Sstevel@tonic-gate int len; 18497c478bd9Sstevel@tonic-gate 18507c478bd9Sstevel@tonic-gate /* 18517c478bd9Sstevel@tonic-gate * Loop through options once to find out if peer is offering 18527c478bd9Sstevel@tonic-gate * Multilink, and repair values as needed. 18537c478bd9Sstevel@tonic-gate */ 18547c478bd9Sstevel@tonic-gate ao->mru = ao->mrru; 18557c478bd9Sstevel@tonic-gate p0 = p; 18567c478bd9Sstevel@tonic-gate for (len = *lenp; len > 0; len -= cilen, p = prev + cilen) { 18577c478bd9Sstevel@tonic-gate if (len < 2 || p[1] > len) { 18587c478bd9Sstevel@tonic-gate /* 18597c478bd9Sstevel@tonic-gate * RFC 1661 page 40 -- if the option extends beyond the 18607c478bd9Sstevel@tonic-gate * packet, then discard the entire packet. 18617c478bd9Sstevel@tonic-gate */ 18627c478bd9Sstevel@tonic-gate dbglog("discarding LCP Configure-Request due to truncated option"); 18637c478bd9Sstevel@tonic-gate return (0); 18647c478bd9Sstevel@tonic-gate } 18657c478bd9Sstevel@tonic-gate prev = p; 18667c478bd9Sstevel@tonic-gate GETCHAR(citype, p); 18677c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); 18687c478bd9Sstevel@tonic-gate if (citype == CI_MRRU) { 18697c478bd9Sstevel@tonic-gate if (ao->mrru != 0) { 18707c478bd9Sstevel@tonic-gate if (ao->mrru+6 > PPP_MTU) 18717c478bd9Sstevel@tonic-gate ao->mru = PPP_MTU; 18727c478bd9Sstevel@tonic-gate else 18737c478bd9Sstevel@tonic-gate ao->mru = ao->mrru + 6; 18747c478bd9Sstevel@tonic-gate } 18757c478bd9Sstevel@tonic-gate } 18767c478bd9Sstevel@tonic-gate if (cilen < 2) 18777c478bd9Sstevel@tonic-gate cilen = 2; 18787c478bd9Sstevel@tonic-gate } 18797c478bd9Sstevel@tonic-gate if (ao->mru > absmax_mtu) 18807c478bd9Sstevel@tonic-gate ao->mru = absmax_mtu; 18817c478bd9Sstevel@tonic-gate 18827c478bd9Sstevel@tonic-gate ret = CODE_CONFACK; 18837c478bd9Sstevel@tonic-gate rejp = p = p0; 18847c478bd9Sstevel@tonic-gate nakp = nak_buffer; 18857c478bd9Sstevel@tonic-gate 18867c478bd9Sstevel@tonic-gate /* 1887*48bbca81SDaniel Hoffman * Reset all its options. 18887c478bd9Sstevel@tonic-gate */ 18897c478bd9Sstevel@tonic-gate BZERO(ho, sizeof(*ho)); 18907c478bd9Sstevel@tonic-gate 18917c478bd9Sstevel@tonic-gate /* 1892*48bbca81SDaniel Hoffman * Process all its options. 18937c478bd9Sstevel@tonic-gate */ 18947c478bd9Sstevel@tonic-gate for (len = *lenp; len > 0; len -= cilen, p = prev + cilen) { 18957c478bd9Sstevel@tonic-gate newret = CODE_CONFACK; /* Assume success */ 18967c478bd9Sstevel@tonic-gate 18977c478bd9Sstevel@tonic-gate prev = p; 18987c478bd9Sstevel@tonic-gate GETCHAR(citype, p); 18997c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); 19007c478bd9Sstevel@tonic-gate 19017c478bd9Sstevel@tonic-gate switch (citype) { /* Check CI type */ 19027c478bd9Sstevel@tonic-gate case CI_MRU: 19037c478bd9Sstevel@tonic-gate if (!ao->neg_mru) { 19047c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 19057c478bd9Sstevel@tonic-gate break; 19067c478bd9Sstevel@tonic-gate } 19077c478bd9Sstevel@tonic-gate 19087c478bd9Sstevel@tonic-gate if (cilen != CILEN_SHORT) { /* Check CI length */ 19097c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 19107c478bd9Sstevel@tonic-gate cishort = ao->mru; 19117c478bd9Sstevel@tonic-gate } else { 19127c478bd9Sstevel@tonic-gate /* extract the MRU from the option */ 19137c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); 19147c478bd9Sstevel@tonic-gate 19157c478bd9Sstevel@tonic-gate /* 19167c478bd9Sstevel@tonic-gate * If the offered MRU is less than our desired MTU, we 19177c478bd9Sstevel@tonic-gate * should nak. This is especially helpful if we're 19187c478bd9Sstevel@tonic-gate * doing demand-dial, since those queued up packets 19197c478bd9Sstevel@tonic-gate * might be discarded otherwise. 19207c478bd9Sstevel@tonic-gate */ 19217c478bd9Sstevel@tonic-gate if (cishort < ao->mru) { 19227c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 19237c478bd9Sstevel@tonic-gate cishort = ao->mru; 19247c478bd9Sstevel@tonic-gate } 19257c478bd9Sstevel@tonic-gate } 19267c478bd9Sstevel@tonic-gate 19277c478bd9Sstevel@tonic-gate /* 19287c478bd9Sstevel@tonic-gate * If we're going to send a nak with something less than 19297c478bd9Sstevel@tonic-gate * or equal to the default PPP MTU, then just reject instead. 19307c478bd9Sstevel@tonic-gate */ 19317c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK && cishort <= PPP_MTU) 19327c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 19337c478bd9Sstevel@tonic-gate 19347c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK) { 19357c478bd9Sstevel@tonic-gate PUTCHAR(CI_MRU, nakp); 19367c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_SHORT, nakp); 1937*48bbca81SDaniel Hoffman PUTSHORT(cishort, nakp); /* Give it a hint */ 19387c478bd9Sstevel@tonic-gate } 19397c478bd9Sstevel@tonic-gate 1940*48bbca81SDaniel Hoffman ho->neg_mru = 1; /* Remember that it sent MRU */ 19417c478bd9Sstevel@tonic-gate ho->mru = cishort; /* And remember value */ 19427c478bd9Sstevel@tonic-gate break; 19437c478bd9Sstevel@tonic-gate 19447c478bd9Sstevel@tonic-gate case CI_ASYNCMAP: 19457c478bd9Sstevel@tonic-gate if (!ao->neg_asyncmap) { 19467c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 19477c478bd9Sstevel@tonic-gate break; 19487c478bd9Sstevel@tonic-gate } 19497c478bd9Sstevel@tonic-gate 19507c478bd9Sstevel@tonic-gate if (cilen != CILEN_LONG) { 19517c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 19527c478bd9Sstevel@tonic-gate cilong = 0; 19537c478bd9Sstevel@tonic-gate } else { 19547c478bd9Sstevel@tonic-gate GETLONG(cilong, p); 19557c478bd9Sstevel@tonic-gate 19567c478bd9Sstevel@tonic-gate /* 19577c478bd9Sstevel@tonic-gate * Asyncmap must have set at least the bits 19587c478bd9Sstevel@tonic-gate * which are set in lcp_allowoptions[unit].asyncmap. 19597c478bd9Sstevel@tonic-gate */ 19607c478bd9Sstevel@tonic-gate if ((ao->asyncmap & ~cilong) != 0) 19617c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 19627c478bd9Sstevel@tonic-gate } 19637c478bd9Sstevel@tonic-gate 19647c478bd9Sstevel@tonic-gate /* 19657c478bd9Sstevel@tonic-gate * Workaround for common broken Microsoft software -- if 1966*48bbca81SDaniel Hoffman * the peer is sending us a nonzero ACCM, then it *needs* 1967*48bbca81SDaniel Hoffman * us to send the same to it. Adjust our Configure- 19687c478bd9Sstevel@tonic-gate * Request message and restart LCP. 19697c478bd9Sstevel@tonic-gate */ 19707c478bd9Sstevel@tonic-gate if (do_msft_workaround && (cilong & ~wo->asyncmap)) { 19717c478bd9Sstevel@tonic-gate dbglog("adjusted requested asyncmap from %X to %X", 19727c478bd9Sstevel@tonic-gate wo->asyncmap, wo->asyncmap | cilong); 19737c478bd9Sstevel@tonic-gate do_msft_workaround = 0; 19747c478bd9Sstevel@tonic-gate wo->neg_asyncmap = 1; 19757c478bd9Sstevel@tonic-gate wo->asyncmap |= cilong; 19767c478bd9Sstevel@tonic-gate f->flags &= ~OPT_SILENT; 19777c478bd9Sstevel@tonic-gate info("possibly broken peer detected; restarting LCP"); 19787c478bd9Sstevel@tonic-gate fsm_lowerdown(f); 19797c478bd9Sstevel@tonic-gate fsm_lowerup(f); 19807c478bd9Sstevel@tonic-gate return (0); 19817c478bd9Sstevel@tonic-gate } 19827c478bd9Sstevel@tonic-gate 19837c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK) { 19847c478bd9Sstevel@tonic-gate PUTCHAR(CI_ASYNCMAP, nakp); 19857c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_LONG, nakp); 19867c478bd9Sstevel@tonic-gate PUTLONG(ao->asyncmap | cilong, nakp); 19877c478bd9Sstevel@tonic-gate } 19887c478bd9Sstevel@tonic-gate ho->neg_asyncmap = 1; 19897c478bd9Sstevel@tonic-gate ho->asyncmap = cilong; 19907c478bd9Sstevel@tonic-gate break; 19917c478bd9Sstevel@tonic-gate 19927c478bd9Sstevel@tonic-gate case CI_AUTHTYPE: 19937c478bd9Sstevel@tonic-gate if (!(ao->neg_upap || ao->neg_chap || ao->neg_mschap || 19947c478bd9Sstevel@tonic-gate ao->neg_mschapv2)) { 19957c478bd9Sstevel@tonic-gate rejected_peers_auth = 1; 19967c478bd9Sstevel@tonic-gate if (cilen >= CILEN_SHORT) { 19977c478bd9Sstevel@tonic-gate GETSHORT(rejected_auth_proto, p); 19987c478bd9Sstevel@tonic-gate } else { 19997c478bd9Sstevel@tonic-gate rejected_auth_proto = 0; 20007c478bd9Sstevel@tonic-gate } 20017c478bd9Sstevel@tonic-gate /* 20027c478bd9Sstevel@tonic-gate * Reject the option if we're not willing to authenticate. 20037c478bd9Sstevel@tonic-gate */ 20047c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 20057c478bd9Sstevel@tonic-gate break; 20067c478bd9Sstevel@tonic-gate } 20077c478bd9Sstevel@tonic-gate rejected_peers_auth = 0; 20087c478bd9Sstevel@tonic-gate naked_peers_auth = 0; 20097c478bd9Sstevel@tonic-gate 20107c478bd9Sstevel@tonic-gate if (cilen >= CILEN_SHORT) { 20117c478bd9Sstevel@tonic-gate /* Extract the authentication protocol from the option */ 20127c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); 20137c478bd9Sstevel@tonic-gate 20147c478bd9Sstevel@tonic-gate if (ho->neg_upap || ho->neg_chap || ho->neg_mschap || 20157c478bd9Sstevel@tonic-gate ho->neg_mschapv2) { 20167c478bd9Sstevel@tonic-gate dbglog("Rejecting extra authentication protocol option"); 20177c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 20187c478bd9Sstevel@tonic-gate break; 20197c478bd9Sstevel@tonic-gate } 20207c478bd9Sstevel@tonic-gate 20217c478bd9Sstevel@tonic-gate /* 20227c478bd9Sstevel@tonic-gate * Authtype must be PAP or CHAP. 20237c478bd9Sstevel@tonic-gate * 20247c478bd9Sstevel@tonic-gate * Note: if both ao->neg_upap and ao->neg_*chap* are 20257c478bd9Sstevel@tonic-gate * set, and the peer sends a Configure-Request with 20267c478bd9Sstevel@tonic-gate * two authenticate-protocol requests, one for CHAP 20277c478bd9Sstevel@tonic-gate * and one for UPAP, then we will reject the second 20287c478bd9Sstevel@tonic-gate * request. Whether we end up doing CHAP or UPAP 20297c478bd9Sstevel@tonic-gate * depends then on the ordering of the CIs in the 20307c478bd9Sstevel@tonic-gate * peer's Configure-Request. 20317c478bd9Sstevel@tonic-gate * 20327c478bd9Sstevel@tonic-gate * We're supposed to list all of the protocols we can 20337c478bd9Sstevel@tonic-gate * possibly use in the returned Configure-Nak. This 20347c478bd9Sstevel@tonic-gate * part of RFC 1661 (section 5.3) is in conflict with 20357c478bd9Sstevel@tonic-gate * the section that says the options shouldn't be 20367c478bd9Sstevel@tonic-gate * reordered, so it's often ignored. 20377c478bd9Sstevel@tonic-gate */ 20387c478bd9Sstevel@tonic-gate 20397c478bd9Sstevel@tonic-gate if (cishort == PPP_PAP) { 20407c478bd9Sstevel@tonic-gate if (ao->neg_upap) { 20417c478bd9Sstevel@tonic-gate if (cilen != CILEN_SHORT) 20427c478bd9Sstevel@tonic-gate goto try_pap_anyway; 20437c478bd9Sstevel@tonic-gate ho->neg_upap = 1; 20447c478bd9Sstevel@tonic-gate break; 20457c478bd9Sstevel@tonic-gate } 20467c478bd9Sstevel@tonic-gate } else if (cishort == PPP_CHAP) { 20477c478bd9Sstevel@tonic-gate /* Test >= here to allow for broken peers. */ 20487c478bd9Sstevel@tonic-gate if (cilen >= CILEN_CHAP && 20497c478bd9Sstevel@tonic-gate (ao->neg_chap || ao->neg_mschap || ao->neg_mschapv2)) { 20507c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); 20517c478bd9Sstevel@tonic-gate if (cichar == CHAP_DIGEST_MD5 && ao->neg_chap) 20527c478bd9Sstevel@tonic-gate ho->neg_chap = 1; 20537c478bd9Sstevel@tonic-gate else if (cichar == CHAP_MICROSOFT && ao->neg_mschap) 20547c478bd9Sstevel@tonic-gate ho->neg_mschap = 1; 20557c478bd9Sstevel@tonic-gate else if (cichar == CHAP_MICROSOFT_V2 && 20567c478bd9Sstevel@tonic-gate ao->neg_mschapv2) 20577c478bd9Sstevel@tonic-gate ho->neg_mschap = 1; 20587c478bd9Sstevel@tonic-gate if (ho->neg_chap || ho->neg_mschap || 20597c478bd9Sstevel@tonic-gate ho->neg_mschapv2) { 20607c478bd9Sstevel@tonic-gate ho->chap_mdtype = cichar; /* save md type */ 20617c478bd9Sstevel@tonic-gate break; 20627c478bd9Sstevel@tonic-gate } 20637c478bd9Sstevel@tonic-gate } 20647c478bd9Sstevel@tonic-gate } 20657c478bd9Sstevel@tonic-gate } 20667c478bd9Sstevel@tonic-gate 20677c478bd9Sstevel@tonic-gate /* 20687c478bd9Sstevel@tonic-gate * We don't recognize the protocol they're asking for. 20697c478bd9Sstevel@tonic-gate * Nak it with something we're willing to do. 20707c478bd9Sstevel@tonic-gate * (At this point we know ao->neg_upap || ao->neg_chap.) 20717c478bd9Sstevel@tonic-gate */ 20727c478bd9Sstevel@tonic-gate PUTCHAR(CI_AUTHTYPE, nakp); 20737c478bd9Sstevel@tonic-gate if (ao->neg_chap || ao->neg_mschap || ao->neg_mschapv2) { 20747c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_CHAP, nakp); 20757c478bd9Sstevel@tonic-gate PUTSHORT(PPP_CHAP, nakp); 20767c478bd9Sstevel@tonic-gate PUTCHAR(ao->chap_mdtype, nakp); 20777c478bd9Sstevel@tonic-gate naked_auth_proto = PPP_CHAP; 20787c478bd9Sstevel@tonic-gate } else { 20797c478bd9Sstevel@tonic-gate try_pap_anyway: 20807c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_SHORT, nakp); 20817c478bd9Sstevel@tonic-gate PUTSHORT(PPP_PAP, nakp); 20827c478bd9Sstevel@tonic-gate naked_auth_proto = PPP_PAP; 20837c478bd9Sstevel@tonic-gate } 20847c478bd9Sstevel@tonic-gate naked_peers_auth = 1; 20857c478bd9Sstevel@tonic-gate naked_auth_orig = cishort; 20867c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 20877c478bd9Sstevel@tonic-gate break; 20887c478bd9Sstevel@tonic-gate 20897c478bd9Sstevel@tonic-gate case CI_QUALITY: 20907c478bd9Sstevel@tonic-gate if (!ao->neg_lqr) { 20917c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 20927c478bd9Sstevel@tonic-gate break; 20937c478bd9Sstevel@tonic-gate } 20947c478bd9Sstevel@tonic-gate 20957c478bd9Sstevel@tonic-gate if (cilen != CILEN_LQR) { 20967c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 20977c478bd9Sstevel@tonic-gate cilong = ao->lqr_period; 20987c478bd9Sstevel@tonic-gate } else { 20997c478bd9Sstevel@tonic-gate 21007c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); 21017c478bd9Sstevel@tonic-gate GETLONG(cilong, p); 21027c478bd9Sstevel@tonic-gate 21037c478bd9Sstevel@tonic-gate /* Check the LQM protocol */ 21047c478bd9Sstevel@tonic-gate if (cishort != PPP_LQR) { 21057c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 21067c478bd9Sstevel@tonic-gate } 21077c478bd9Sstevel@tonic-gate 21087c478bd9Sstevel@tonic-gate /* Check the reporting period; we can't both send zero */ 21097c478bd9Sstevel@tonic-gate if ((cilong == 0 && go->lqr_period == 0) || 21107c478bd9Sstevel@tonic-gate cilong < ao->lqr_period) { 21117c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 21127c478bd9Sstevel@tonic-gate if ((cilong = ao->lqr_period) == 0) 21137c478bd9Sstevel@tonic-gate cilong = 500; 21147c478bd9Sstevel@tonic-gate } 21157c478bd9Sstevel@tonic-gate } 21167c478bd9Sstevel@tonic-gate 21177c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK) { 21187c478bd9Sstevel@tonic-gate PUTCHAR(CI_QUALITY, nakp); 21197c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_LQR, nakp); 21207c478bd9Sstevel@tonic-gate PUTSHORT(PPP_LQR, nakp); 21217c478bd9Sstevel@tonic-gate PUTLONG(cilong, nakp); 21227c478bd9Sstevel@tonic-gate } 21237c478bd9Sstevel@tonic-gate 21247c478bd9Sstevel@tonic-gate ho->neg_lqr = 1; 21257c478bd9Sstevel@tonic-gate ho->lqr_period = cilong; 21267c478bd9Sstevel@tonic-gate break; 21277c478bd9Sstevel@tonic-gate 21287c478bd9Sstevel@tonic-gate case CI_MAGICNUMBER: 21297c478bd9Sstevel@tonic-gate if (!(ao->neg_magicnumber || go->neg_magicnumber)) { 21307c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 21317c478bd9Sstevel@tonic-gate break; 21327c478bd9Sstevel@tonic-gate } 21337c478bd9Sstevel@tonic-gate 21347c478bd9Sstevel@tonic-gate ho->neg_magicnumber = 1; 21357c478bd9Sstevel@tonic-gate if (cilen < CILEN_LONG) { 21367c478bd9Sstevel@tonic-gate /* 21377c478bd9Sstevel@tonic-gate * If we send Magic-Number, then we must not reject it 2138*48bbca81SDaniel Hoffman * when the peer sends it to us, even if its version 2139*48bbca81SDaniel Hoffman * looks odd to us. Ack if the cilent is wrong in this 21407c478bd9Sstevel@tonic-gate * case. If we're not sending Magic-Number, then we don't 2141*48bbca81SDaniel Hoffman * much care what its value is anyway. 21427c478bd9Sstevel@tonic-gate */ 21437c478bd9Sstevel@tonic-gate break; 21447c478bd9Sstevel@tonic-gate } 21457c478bd9Sstevel@tonic-gate 21467c478bd9Sstevel@tonic-gate GETLONG(cilong, p); 21477c478bd9Sstevel@tonic-gate ho->magicnumber = cilong; 21487c478bd9Sstevel@tonic-gate if (cilen > CILEN_LONG) 21497c478bd9Sstevel@tonic-gate break; 21507c478bd9Sstevel@tonic-gate 21517c478bd9Sstevel@tonic-gate /* 2152*48bbca81SDaniel Hoffman * It must have a different magic number. Make sure we 2153*48bbca81SDaniel Hoffman * give it a good one to use. 21547c478bd9Sstevel@tonic-gate */ 21557c478bd9Sstevel@tonic-gate while (go->neg_magicnumber && cilong == go->magicnumber) { 21567c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 21577c478bd9Sstevel@tonic-gate cilong = magic(); 21587c478bd9Sstevel@tonic-gate } 21597c478bd9Sstevel@tonic-gate 21607c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK) { 21617c478bd9Sstevel@tonic-gate PUTCHAR(CI_MAGICNUMBER, nakp); 21627c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_LONG, nakp); 21637c478bd9Sstevel@tonic-gate PUTLONG(cilong, nakp); 21647c478bd9Sstevel@tonic-gate /* 21657c478bd9Sstevel@tonic-gate * We don't need to bump the numloops counter here 21667c478bd9Sstevel@tonic-gate * since it's already done upon reception of a nak. 21677c478bd9Sstevel@tonic-gate */ 21687c478bd9Sstevel@tonic-gate } 21697c478bd9Sstevel@tonic-gate break; 21707c478bd9Sstevel@tonic-gate 21717c478bd9Sstevel@tonic-gate case CI_PCOMPRESSION: 21727c478bd9Sstevel@tonic-gate if (!ao->neg_pcompression) { 21737c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 21747c478bd9Sstevel@tonic-gate break; 21757c478bd9Sstevel@tonic-gate } 21767c478bd9Sstevel@tonic-gate if (cilen != CILEN_VOID) { 21777c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 21787c478bd9Sstevel@tonic-gate PUTCHAR(CI_PCOMPRESSION, nakp); 21797c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_VOID, nakp); 21807c478bd9Sstevel@tonic-gate } 21817c478bd9Sstevel@tonic-gate ho->neg_pcompression = 1; 21827c478bd9Sstevel@tonic-gate break; 21837c478bd9Sstevel@tonic-gate 21847c478bd9Sstevel@tonic-gate case CI_ACCOMPRESSION: 21857c478bd9Sstevel@tonic-gate if (!ao->neg_accompression) { 21867c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 21877c478bd9Sstevel@tonic-gate break; 21887c478bd9Sstevel@tonic-gate } 21897c478bd9Sstevel@tonic-gate if (cilen != CILEN_VOID) { 21907c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 21917c478bd9Sstevel@tonic-gate PUTCHAR(CI_ACCOMPRESSION, nakp); 21927c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_VOID, nakp); 21937c478bd9Sstevel@tonic-gate } 21947c478bd9Sstevel@tonic-gate ho->neg_accompression = 1; 21957c478bd9Sstevel@tonic-gate break; 21967c478bd9Sstevel@tonic-gate 21977c478bd9Sstevel@tonic-gate case CI_FCSALTERN: 21987c478bd9Sstevel@tonic-gate if (!ao->neg_fcs) { 21997c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 22007c478bd9Sstevel@tonic-gate break; 22017c478bd9Sstevel@tonic-gate } 22027c478bd9Sstevel@tonic-gate 22037c478bd9Sstevel@tonic-gate if (cilen != CILEN_CHAR) { 22047c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 22057c478bd9Sstevel@tonic-gate cichar = ao->fcs_type; 22067c478bd9Sstevel@tonic-gate } else { 22077c478bd9Sstevel@tonic-gate 22087c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); 2209*48bbca81SDaniel Hoffman /* If it has bits we don't like, tell it to stop. */ 22107c478bd9Sstevel@tonic-gate if (cichar & ~ao->fcs_type) { 22117c478bd9Sstevel@tonic-gate if ((cichar &= ao->fcs_type) == 0) { 22127c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 22137c478bd9Sstevel@tonic-gate break; 22147c478bd9Sstevel@tonic-gate } 22157c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 22167c478bd9Sstevel@tonic-gate } 22177c478bd9Sstevel@tonic-gate } 22187c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK) { 22197c478bd9Sstevel@tonic-gate PUTCHAR(CI_FCSALTERN, nakp); 22207c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_CHAR, nakp); 22217c478bd9Sstevel@tonic-gate PUTCHAR(cichar, nakp); 22227c478bd9Sstevel@tonic-gate } 22237c478bd9Sstevel@tonic-gate ho->neg_fcs = 1; 22247c478bd9Sstevel@tonic-gate ho->fcs_type = cichar; 22257c478bd9Sstevel@tonic-gate break; 22267c478bd9Sstevel@tonic-gate 22277c478bd9Sstevel@tonic-gate case CI_MRRU: 22287c478bd9Sstevel@tonic-gate if (!ao->neg_mrru || !multilink) { 22297c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 22307c478bd9Sstevel@tonic-gate break; 22317c478bd9Sstevel@tonic-gate } 22327c478bd9Sstevel@tonic-gate if (cilen != CILEN_SHORT) { 22337c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 22347c478bd9Sstevel@tonic-gate cishort = ao->mrru; 22357c478bd9Sstevel@tonic-gate } else { 22367c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); 22377c478bd9Sstevel@tonic-gate if (cishort < ao->mrru) { 22387c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 22397c478bd9Sstevel@tonic-gate cishort = ao->mrru; 22407c478bd9Sstevel@tonic-gate } 22417c478bd9Sstevel@tonic-gate } 22427c478bd9Sstevel@tonic-gate 22437c478bd9Sstevel@tonic-gate if (cishort < PPP_MINMTU) { 22447c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 22457c478bd9Sstevel@tonic-gate cishort = PPP_MINMTU; 22467c478bd9Sstevel@tonic-gate } 22477c478bd9Sstevel@tonic-gate 22487c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK) { 22497c478bd9Sstevel@tonic-gate PUTCHAR(CI_MRRU, nakp); 22507c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_SHORT, nakp); 22517c478bd9Sstevel@tonic-gate PUTSHORT(cishort, nakp); 22527c478bd9Sstevel@tonic-gate } 22537c478bd9Sstevel@tonic-gate 22547c478bd9Sstevel@tonic-gate ho->neg_mrru = 1; 22557c478bd9Sstevel@tonic-gate ho->mrru = cishort; 22567c478bd9Sstevel@tonic-gate break; 22577c478bd9Sstevel@tonic-gate 22587c478bd9Sstevel@tonic-gate case CI_SSNHF: 22597c478bd9Sstevel@tonic-gate if (!ao->neg_ssnhf || !multilink) { 22607c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 22617c478bd9Sstevel@tonic-gate break; 22627c478bd9Sstevel@tonic-gate } 22637c478bd9Sstevel@tonic-gate if (cilen != CILEN_VOID) { 22647c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 22657c478bd9Sstevel@tonic-gate PUTCHAR(CI_SSNHF, nakp); 22667c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_VOID, nakp); 22677c478bd9Sstevel@tonic-gate } 22687c478bd9Sstevel@tonic-gate ho->neg_ssnhf = 1; 22697c478bd9Sstevel@tonic-gate break; 22707c478bd9Sstevel@tonic-gate 22717c478bd9Sstevel@tonic-gate case CI_EPDISC: 22727c478bd9Sstevel@tonic-gate if (!ao->neg_endpoint) { 22737c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 22747c478bd9Sstevel@tonic-gate break; 22757c478bd9Sstevel@tonic-gate } 22767c478bd9Sstevel@tonic-gate if (cilen < CILEN_CHAR || cilen > CILEN_CHAR + MAX_ENDP_LEN) { 22777c478bd9Sstevel@tonic-gate int i; 22787c478bd9Sstevel@tonic-gate 22797c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK; 22807c478bd9Sstevel@tonic-gate PUTCHAR(CI_EPDISC, nakp); 22817c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_CHAR + ao->endpoint.length, nakp); 22827c478bd9Sstevel@tonic-gate PUTCHAR(ao->endpoint.class, nakp); 22837c478bd9Sstevel@tonic-gate for (i = 0; i < ao->endpoint.length; i++) 22847c478bd9Sstevel@tonic-gate PUTCHAR(ao->endpoint.value[i], nakp); 22857c478bd9Sstevel@tonic-gate break; 22867c478bd9Sstevel@tonic-gate } 22877c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); 22887c478bd9Sstevel@tonic-gate ho->neg_endpoint = 1; 22897c478bd9Sstevel@tonic-gate ho->endpoint.class = cichar; 22907c478bd9Sstevel@tonic-gate ho->endpoint.length = cilen - 3; 22917c478bd9Sstevel@tonic-gate BCOPY(p, ho->endpoint.value, cilen - 3); 22927c478bd9Sstevel@tonic-gate break; 22937c478bd9Sstevel@tonic-gate 22947c478bd9Sstevel@tonic-gate #ifdef MUX_FRAME 22957c478bd9Sstevel@tonic-gate case CI_MUXING: 22967c478bd9Sstevel@tonic-gate if (ao->pppmux == 0 || cilen != CILEN_VOID) { 22977c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 22987c478bd9Sstevel@tonic-gate break; 22997c478bd9Sstevel@tonic-gate } 2300*48bbca81SDaniel Hoffman /* remember its option */ 23017c478bd9Sstevel@tonic-gate ho->pppmux = ao->pppmux; 23027c478bd9Sstevel@tonic-gate break; 23037c478bd9Sstevel@tonic-gate #endif 23047c478bd9Sstevel@tonic-gate 23057c478bd9Sstevel@tonic-gate default: 23067c478bd9Sstevel@tonic-gate dbglog("LCP: rejecting unknown option %d", citype); 23077c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 23087c478bd9Sstevel@tonic-gate break; 23097c478bd9Sstevel@tonic-gate } 23107c478bd9Sstevel@tonic-gate 23117c478bd9Sstevel@tonic-gate /* Cope with confused peers. */ 23127c478bd9Sstevel@tonic-gate if (cilen < 2) 23137c478bd9Sstevel@tonic-gate cilen = 2; 23147c478bd9Sstevel@tonic-gate 23157c478bd9Sstevel@tonic-gate /* 23167c478bd9Sstevel@tonic-gate * If this is an Ack'able CI, but we're sending back a Nak, 23177c478bd9Sstevel@tonic-gate * don't include this CI. 23187c478bd9Sstevel@tonic-gate */ 23197c478bd9Sstevel@tonic-gate if (newret == CODE_CONFACK && ret != CODE_CONFACK) 23207c478bd9Sstevel@tonic-gate continue; 23217c478bd9Sstevel@tonic-gate 23227c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK) { 23237c478bd9Sstevel@tonic-gate /* 23247c478bd9Sstevel@tonic-gate * Continue naking the Magic Number option until the cows come 23257c478bd9Sstevel@tonic-gate * home -- rejecting it is wrong. 23267c478bd9Sstevel@tonic-gate */ 23277c478bd9Sstevel@tonic-gate if (dont_nak && citype != CI_MAGICNUMBER) { 23287c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ; 23297c478bd9Sstevel@tonic-gate } else { 23307c478bd9Sstevel@tonic-gate /* Ignore subsequent Nak'able things if rejecting. */ 23317c478bd9Sstevel@tonic-gate if (ret == CODE_CONFREJ) 23327c478bd9Sstevel@tonic-gate continue; 23337c478bd9Sstevel@tonic-gate ret = CODE_CONFNAK; 23347c478bd9Sstevel@tonic-gate } 23357c478bd9Sstevel@tonic-gate } 23367c478bd9Sstevel@tonic-gate 23377c478bd9Sstevel@tonic-gate if (newret == CODE_CONFREJ) { 23387c478bd9Sstevel@tonic-gate ret = CODE_CONFREJ; 23397c478bd9Sstevel@tonic-gate if (prev != rejp) 23407c478bd9Sstevel@tonic-gate BCOPY(prev, rejp, cilen); 23417c478bd9Sstevel@tonic-gate rejp += cilen; 23427c478bd9Sstevel@tonic-gate } 23437c478bd9Sstevel@tonic-gate } 23447c478bd9Sstevel@tonic-gate 23457c478bd9Sstevel@tonic-gate /* 2346*48bbca81SDaniel Hoffman * If the peer hasn't negotiated its MRU, and we'd like an MTU 23477c478bd9Sstevel@tonic-gate * that's larger than the default, try sending an unsolicited 23487c478bd9Sstevel@tonic-gate * Nak for what we want. 23497c478bd9Sstevel@tonic-gate */ 23507c478bd9Sstevel@tonic-gate if (ret != CODE_CONFREJ && !ho->neg_mru && ao->mru > PPP_MTU && 23517c478bd9Sstevel@tonic-gate !dont_nak && unsolicit_mru) { 23527c478bd9Sstevel@tonic-gate unsolicit_mru = 0; /* don't ask again */ 23537c478bd9Sstevel@tonic-gate ret = CODE_CONFNAK; 23547c478bd9Sstevel@tonic-gate PUTCHAR(CI_MRU, nakp); 23557c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_SHORT, nakp); 23567c478bd9Sstevel@tonic-gate PUTSHORT(ao->mru, nakp); 23577c478bd9Sstevel@tonic-gate } 23587c478bd9Sstevel@tonic-gate 23597c478bd9Sstevel@tonic-gate switch (ret) { 23607c478bd9Sstevel@tonic-gate case CODE_CONFACK: 23617c478bd9Sstevel@tonic-gate *lenp = p - p0; 23627c478bd9Sstevel@tonic-gate break; 23637c478bd9Sstevel@tonic-gate case CODE_CONFNAK: 23647c478bd9Sstevel@tonic-gate /* 23657c478bd9Sstevel@tonic-gate * Copy the Nak'd options from the nak_buffer to the caller's buffer. 23667c478bd9Sstevel@tonic-gate */ 23677c478bd9Sstevel@tonic-gate *lenp = nakp - nak_buffer; 23687c478bd9Sstevel@tonic-gate BCOPY(nak_buffer, p0, *lenp); 23697c478bd9Sstevel@tonic-gate break; 23707c478bd9Sstevel@tonic-gate case CODE_CONFREJ: 23717c478bd9Sstevel@tonic-gate *lenp = rejp - p0; 23727c478bd9Sstevel@tonic-gate 23737c478bd9Sstevel@tonic-gate /* We're about to send Configure-Reject; send Identification */ 23747c478bd9Sstevel@tonic-gate if (!noident && sentident < 3) { 23757c478bd9Sstevel@tonic-gate LcpSendIdentification(f); 23767c478bd9Sstevel@tonic-gate sentident++; 23777c478bd9Sstevel@tonic-gate } 23787c478bd9Sstevel@tonic-gate break; 23797c478bd9Sstevel@tonic-gate } 23807c478bd9Sstevel@tonic-gate 23817c478bd9Sstevel@tonic-gate LCPDEBUG(("lcp_reqci: returning %s.", code_name(ret, 1))); 23827c478bd9Sstevel@tonic-gate return (ret); /* Return final code */ 23837c478bd9Sstevel@tonic-gate } 23847c478bd9Sstevel@tonic-gate 23857c478bd9Sstevel@tonic-gate 23867c478bd9Sstevel@tonic-gate /* 23877c478bd9Sstevel@tonic-gate * lcp_up - LCP has come UP. 23887c478bd9Sstevel@tonic-gate */ 23897c478bd9Sstevel@tonic-gate static void 23907c478bd9Sstevel@tonic-gate lcp_up(f) 23917c478bd9Sstevel@tonic-gate fsm *f; 23927c478bd9Sstevel@tonic-gate { 23937c478bd9Sstevel@tonic-gate lcp_options *wo = &lcp_wantoptions[f->unit]; 23947c478bd9Sstevel@tonic-gate lcp_options *ho = &lcp_hisoptions[f->unit]; 23957c478bd9Sstevel@tonic-gate lcp_options *go = &lcp_gotoptions[f->unit]; 23967c478bd9Sstevel@tonic-gate lcp_options *ao = &lcp_allowoptions[f->unit]; 23977c478bd9Sstevel@tonic-gate int mru, mtu; 23987c478bd9Sstevel@tonic-gate 23997c478bd9Sstevel@tonic-gate if (!go->neg_magicnumber) 24007c478bd9Sstevel@tonic-gate go->magicnumber = 0; 24017c478bd9Sstevel@tonic-gate if (!ho->neg_magicnumber) 24027c478bd9Sstevel@tonic-gate ho->magicnumber = 0; 24037c478bd9Sstevel@tonic-gate 24047c478bd9Sstevel@tonic-gate /* 24057c478bd9Sstevel@tonic-gate * Set our MTU to the smaller of the MTU we wanted and 24067c478bd9Sstevel@tonic-gate * the MRU our peer wanted. If we negotiated an MRU, 24077c478bd9Sstevel@tonic-gate * set our MRU to the larger of value we wanted and 24087c478bd9Sstevel@tonic-gate * the value we got in the negotiation. 24097c478bd9Sstevel@tonic-gate */ 24107c478bd9Sstevel@tonic-gate if (ao->mru != 0 && ho->mru > ao->mru) 24117c478bd9Sstevel@tonic-gate ho->mru = ao->mru; 24127c478bd9Sstevel@tonic-gate mtu = (ho->neg_mru ? ho->mru: PPP_MRU); 24137c478bd9Sstevel@tonic-gate if (mtu > absmax_mtu) 24147c478bd9Sstevel@tonic-gate mtu = absmax_mtu; 24157c478bd9Sstevel@tonic-gate ppp_send_config(f->unit, mtu, 24167c478bd9Sstevel@tonic-gate (ho->neg_asyncmap? ho->asyncmap: 0xffffffff), 24177c478bd9Sstevel@tonic-gate ho->neg_pcompression, ho->neg_accompression); 24187c478bd9Sstevel@tonic-gate fsm_setpeermru(f->unit, mtu); 24197c478bd9Sstevel@tonic-gate mru = (go->neg_mru? MAX(wo->mru, go->mru): PPP_MRU); 24207c478bd9Sstevel@tonic-gate if (mru > absmax_mru) 24217c478bd9Sstevel@tonic-gate mru = absmax_mru; 24227c478bd9Sstevel@tonic-gate ppp_recv_config(f->unit, mru, 24237c478bd9Sstevel@tonic-gate (lax_recv? 0: go->neg_asyncmap? go->asyncmap: 0xffffffff), 24247c478bd9Sstevel@tonic-gate go->neg_pcompression, go->neg_accompression); 24257c478bd9Sstevel@tonic-gate #ifdef NEGOTIATE_FCS 24267c478bd9Sstevel@tonic-gate ppp_send_fcs(f->unit, ho->neg_fcs ? ho->fcs_type : FCSALT_16); 24277c478bd9Sstevel@tonic-gate ppp_recv_fcs(f->unit, go->neg_fcs ? go->fcs_type : FCSALT_16); 24287c478bd9Sstevel@tonic-gate #endif 24297c478bd9Sstevel@tonic-gate #ifdef MUX_FRAME 24307c478bd9Sstevel@tonic-gate ppp_send_muxoption(f->unit, ho->pppmux); 24317c478bd9Sstevel@tonic-gate ppp_recv_muxoption(f->unit, go->pppmux); 24327c478bd9Sstevel@tonic-gate #endif 24337c478bd9Sstevel@tonic-gate 24347c478bd9Sstevel@tonic-gate lcp_echo_lowerup(f->unit); /* Enable echo messages */ 24357c478bd9Sstevel@tonic-gate 24367c478bd9Sstevel@tonic-gate /* LCP is Up; send Identification */ 24377c478bd9Sstevel@tonic-gate if (!noident) { 24387c478bd9Sstevel@tonic-gate LcpSendIdentification(f); 24397c478bd9Sstevel@tonic-gate sentident++; 24407c478bd9Sstevel@tonic-gate } 24417c478bd9Sstevel@tonic-gate 24427c478bd9Sstevel@tonic-gate link_established(f->unit); 24437c478bd9Sstevel@tonic-gate } 24447c478bd9Sstevel@tonic-gate 24457c478bd9Sstevel@tonic-gate 24467c478bd9Sstevel@tonic-gate /* 24477c478bd9Sstevel@tonic-gate * lcp_down - LCP has gone DOWN. 24487c478bd9Sstevel@tonic-gate * 24497c478bd9Sstevel@tonic-gate * Alert other protocols. 24507c478bd9Sstevel@tonic-gate */ 24517c478bd9Sstevel@tonic-gate static void 24527c478bd9Sstevel@tonic-gate lcp_down(f) 24537c478bd9Sstevel@tonic-gate fsm *f; 24547c478bd9Sstevel@tonic-gate { 24557c478bd9Sstevel@tonic-gate int mtu; 24567c478bd9Sstevel@tonic-gate lcp_options *go = &lcp_gotoptions[f->unit]; 24577c478bd9Sstevel@tonic-gate 24587c478bd9Sstevel@tonic-gate lcp_echo_lowerdown(f->unit); 24597c478bd9Sstevel@tonic-gate 24607c478bd9Sstevel@tonic-gate link_down(f->unit); 24617c478bd9Sstevel@tonic-gate 24627c478bd9Sstevel@tonic-gate mtu = PPP_MTU > absmax_mtu ? absmax_mtu : PPP_MTU; 24637c478bd9Sstevel@tonic-gate ppp_send_config(f->unit, mtu, 0xffffffff, 0, 0); 24647c478bd9Sstevel@tonic-gate ppp_recv_config(f->unit, (PPP_MRU > absmax_mru ? absmax_mru : PPP_MRU), 24657c478bd9Sstevel@tonic-gate (go->neg_asyncmap? go->asyncmap: 0xffffffff), 24667c478bd9Sstevel@tonic-gate go->neg_pcompression, go->neg_accompression); 24677c478bd9Sstevel@tonic-gate #ifdef NEGOTIATE_FCS 24687c478bd9Sstevel@tonic-gate ppp_send_fcs(f->unit, FCSALT_16); 24697c478bd9Sstevel@tonic-gate ppp_recv_fcs(f->unit, FCSALT_16); 24707c478bd9Sstevel@tonic-gate #endif 24717c478bd9Sstevel@tonic-gate fsm_setpeermru(f->unit, mtu); 24727c478bd9Sstevel@tonic-gate } 24737c478bd9Sstevel@tonic-gate 24747c478bd9Sstevel@tonic-gate 24757c478bd9Sstevel@tonic-gate /* 24767c478bd9Sstevel@tonic-gate * lcp_starting - LCP needs the lower layer up. 24777c478bd9Sstevel@tonic-gate */ 24787c478bd9Sstevel@tonic-gate static void 24797c478bd9Sstevel@tonic-gate lcp_starting(f) 24807c478bd9Sstevel@tonic-gate fsm *f; 24817c478bd9Sstevel@tonic-gate { 24827c478bd9Sstevel@tonic-gate link_required(f->unit); 24837c478bd9Sstevel@tonic-gate } 24847c478bd9Sstevel@tonic-gate 24857c478bd9Sstevel@tonic-gate 24867c478bd9Sstevel@tonic-gate /* 24877c478bd9Sstevel@tonic-gate * lcp_finished - LCP has finished with the lower layer. 24887c478bd9Sstevel@tonic-gate */ 24897c478bd9Sstevel@tonic-gate static void 24907c478bd9Sstevel@tonic-gate lcp_finished(f) 24917c478bd9Sstevel@tonic-gate fsm *f; 24927c478bd9Sstevel@tonic-gate { 24937c478bd9Sstevel@tonic-gate link_terminated(f->unit); 24947c478bd9Sstevel@tonic-gate } 24957c478bd9Sstevel@tonic-gate 24967c478bd9Sstevel@tonic-gate 24977c478bd9Sstevel@tonic-gate /* 24987c478bd9Sstevel@tonic-gate * lcp_printpkt - print the contents of an LCP packet. 24997c478bd9Sstevel@tonic-gate */ 25007c478bd9Sstevel@tonic-gate 25017c478bd9Sstevel@tonic-gate static int 25027c478bd9Sstevel@tonic-gate lcp_printpkt(p, plen, printer, arg) 25037c478bd9Sstevel@tonic-gate u_char *p; 25047c478bd9Sstevel@tonic-gate int plen; 25057c478bd9Sstevel@tonic-gate void (*printer) __P((void *, const char *, ...)); 25067c478bd9Sstevel@tonic-gate void *arg; 25077c478bd9Sstevel@tonic-gate { 25087c478bd9Sstevel@tonic-gate int code, id, len, olen, i; 25097c478bd9Sstevel@tonic-gate u_char *pstart, *optend, cichar; 25107c478bd9Sstevel@tonic-gate u_short cishort; 25117c478bd9Sstevel@tonic-gate u_int32_t cilong; 25127c478bd9Sstevel@tonic-gate 25137c478bd9Sstevel@tonic-gate if (plen < HEADERLEN) 25147c478bd9Sstevel@tonic-gate return 0; 25157c478bd9Sstevel@tonic-gate pstart = p; 25167c478bd9Sstevel@tonic-gate GETCHAR(code, p); 25177c478bd9Sstevel@tonic-gate GETCHAR(id, p); 25187c478bd9Sstevel@tonic-gate GETSHORT(len, p); 25197c478bd9Sstevel@tonic-gate if (len < HEADERLEN || len > plen) 25207c478bd9Sstevel@tonic-gate return 0; 25217c478bd9Sstevel@tonic-gate 25227c478bd9Sstevel@tonic-gate printer(arg, " %s id=0x%x", code_name(code,1), id); 25237c478bd9Sstevel@tonic-gate len -= HEADERLEN; 25247c478bd9Sstevel@tonic-gate switch (code) { 25257c478bd9Sstevel@tonic-gate case CODE_CONFREQ: 25267c478bd9Sstevel@tonic-gate case CODE_CONFACK: 25277c478bd9Sstevel@tonic-gate case CODE_CONFNAK: 25287c478bd9Sstevel@tonic-gate case CODE_CONFREJ: 25297c478bd9Sstevel@tonic-gate /* print option list */ 25307c478bd9Sstevel@tonic-gate while (len >= 2) { 25317c478bd9Sstevel@tonic-gate GETCHAR(code, p); 25327c478bd9Sstevel@tonic-gate GETCHAR(olen, p); 25337c478bd9Sstevel@tonic-gate p -= 2; 25347c478bd9Sstevel@tonic-gate if (olen < 2 || olen > len) { 25357c478bd9Sstevel@tonic-gate break; 25367c478bd9Sstevel@tonic-gate } 25377c478bd9Sstevel@tonic-gate printer(arg, " <"); 25387c478bd9Sstevel@tonic-gate len -= olen; 25397c478bd9Sstevel@tonic-gate optend = p + olen; 25407c478bd9Sstevel@tonic-gate switch (code) { 25417c478bd9Sstevel@tonic-gate case CI_MRU: 25427c478bd9Sstevel@tonic-gate if (olen >= CILEN_SHORT) { 25437c478bd9Sstevel@tonic-gate p += 2; 25447c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); 25457c478bd9Sstevel@tonic-gate printer(arg, "mru %d", cishort); 25467c478bd9Sstevel@tonic-gate } 25477c478bd9Sstevel@tonic-gate break; 25487c478bd9Sstevel@tonic-gate case CI_ASYNCMAP: 25497c478bd9Sstevel@tonic-gate if (olen >= CILEN_LONG) { 25507c478bd9Sstevel@tonic-gate p += 2; 25517c478bd9Sstevel@tonic-gate GETLONG(cilong, p); 25527c478bd9Sstevel@tonic-gate printer(arg, "asyncmap 0x%x", cilong); 25537c478bd9Sstevel@tonic-gate } 25547c478bd9Sstevel@tonic-gate break; 25557c478bd9Sstevel@tonic-gate case CI_AUTHTYPE: 25567c478bd9Sstevel@tonic-gate if (olen >= CILEN_SHORT) { 25577c478bd9Sstevel@tonic-gate p += 2; 25587c478bd9Sstevel@tonic-gate printer(arg, "auth "); 25597c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); 25607c478bd9Sstevel@tonic-gate switch (cishort) { 25617c478bd9Sstevel@tonic-gate case PPP_PAP: 25627c478bd9Sstevel@tonic-gate printer(arg, "pap"); 25637c478bd9Sstevel@tonic-gate break; 25647c478bd9Sstevel@tonic-gate case PPP_CHAP: 25657c478bd9Sstevel@tonic-gate printer(arg, "chap"); 25667c478bd9Sstevel@tonic-gate if (p < optend) { 25677c478bd9Sstevel@tonic-gate switch (*p) { 25687c478bd9Sstevel@tonic-gate case CHAP_DIGEST_MD5: 25697c478bd9Sstevel@tonic-gate printer(arg, " MD5"); 25707c478bd9Sstevel@tonic-gate ++p; 25717c478bd9Sstevel@tonic-gate break; 25727c478bd9Sstevel@tonic-gate case CHAP_MICROSOFT: 25737c478bd9Sstevel@tonic-gate printer(arg, " m$oft"); 25747c478bd9Sstevel@tonic-gate ++p; 25757c478bd9Sstevel@tonic-gate break; 25767c478bd9Sstevel@tonic-gate case CHAP_MICROSOFT_V2: 25777c478bd9Sstevel@tonic-gate printer(arg, " m$oft-v2"); 25787c478bd9Sstevel@tonic-gate ++p; 25797c478bd9Sstevel@tonic-gate break; 25807c478bd9Sstevel@tonic-gate } 25817c478bd9Sstevel@tonic-gate } 25827c478bd9Sstevel@tonic-gate break; 25837c478bd9Sstevel@tonic-gate #ifdef PPP_EAP 25847c478bd9Sstevel@tonic-gate case PPP_EAP: 25857c478bd9Sstevel@tonic-gate printer(arg, "eap"); 25867c478bd9Sstevel@tonic-gate break; 25877c478bd9Sstevel@tonic-gate #endif 25887c478bd9Sstevel@tonic-gate case 0xC027: 25897c478bd9Sstevel@tonic-gate printer(arg, "spap"); 25907c478bd9Sstevel@tonic-gate break; 25917c478bd9Sstevel@tonic-gate case 0xC123: 25927c478bd9Sstevel@tonic-gate printer(arg, "old-spap"); 25937c478bd9Sstevel@tonic-gate break; 25947c478bd9Sstevel@tonic-gate default: 25957c478bd9Sstevel@tonic-gate printer(arg, "0x%x", cishort); 25967c478bd9Sstevel@tonic-gate } 25977c478bd9Sstevel@tonic-gate } 25987c478bd9Sstevel@tonic-gate break; 25997c478bd9Sstevel@tonic-gate case CI_QUALITY: 26007c478bd9Sstevel@tonic-gate if (olen >= CILEN_SHORT) { 26017c478bd9Sstevel@tonic-gate p += 2; 26027c478bd9Sstevel@tonic-gate printer(arg, "quality "); 26037c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); 26047c478bd9Sstevel@tonic-gate switch (cishort) { 26057c478bd9Sstevel@tonic-gate case PPP_LQR: 26067c478bd9Sstevel@tonic-gate printer(arg, "lqr"); 26077c478bd9Sstevel@tonic-gate break; 26087c478bd9Sstevel@tonic-gate default: 26097c478bd9Sstevel@tonic-gate printer(arg, "0x%x", cishort); 26107c478bd9Sstevel@tonic-gate } 26117c478bd9Sstevel@tonic-gate } 26127c478bd9Sstevel@tonic-gate break; 26137c478bd9Sstevel@tonic-gate case CI_CALLBACK: 26147c478bd9Sstevel@tonic-gate if (olen >= CILEN_CHAR) { 26157c478bd9Sstevel@tonic-gate p += 2; 26167c478bd9Sstevel@tonic-gate printer(arg, "callback "); 26177c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); 26187c478bd9Sstevel@tonic-gate if (cichar <= 6 && 26197c478bd9Sstevel@tonic-gate *callback_strings[(int)cichar] != '\0') { 26207c478bd9Sstevel@tonic-gate printer(arg, "%s", callback_strings[(int)cichar]); 26217c478bd9Sstevel@tonic-gate } else { 26227c478bd9Sstevel@tonic-gate printer(arg, "0x%x", cichar); 26237c478bd9Sstevel@tonic-gate } 26247c478bd9Sstevel@tonic-gate } 26257c478bd9Sstevel@tonic-gate break; 26267c478bd9Sstevel@tonic-gate case CI_MAGICNUMBER: 26277c478bd9Sstevel@tonic-gate if (olen >= CILEN_LONG) { 26287c478bd9Sstevel@tonic-gate p += 2; 26297c478bd9Sstevel@tonic-gate GETLONG(cilong, p); 26307c478bd9Sstevel@tonic-gate printer(arg, "magic 0x%x", cilong); 26317c478bd9Sstevel@tonic-gate } 26327c478bd9Sstevel@tonic-gate break; 26337c478bd9Sstevel@tonic-gate case CI_PCOMPRESSION: 26347c478bd9Sstevel@tonic-gate if (olen >= CILEN_VOID) { 26357c478bd9Sstevel@tonic-gate p += 2; 26367c478bd9Sstevel@tonic-gate printer(arg, "pcomp"); 26377c478bd9Sstevel@tonic-gate } 26387c478bd9Sstevel@tonic-gate break; 26397c478bd9Sstevel@tonic-gate case CI_ACCOMPRESSION: 26407c478bd9Sstevel@tonic-gate if (olen >= CILEN_VOID) { 26417c478bd9Sstevel@tonic-gate p += 2; 26427c478bd9Sstevel@tonic-gate printer(arg, "accomp"); 26437c478bd9Sstevel@tonic-gate } 26447c478bd9Sstevel@tonic-gate break; 26457c478bd9Sstevel@tonic-gate case CI_FCSALTERN: 26467c478bd9Sstevel@tonic-gate if (olen >= CILEN_CHAR) { 26477c478bd9Sstevel@tonic-gate char **cpp; 26487c478bd9Sstevel@tonic-gate int needcomma = 0; 26497c478bd9Sstevel@tonic-gate 26507c478bd9Sstevel@tonic-gate p += 2; 26517c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); 26527c478bd9Sstevel@tonic-gate for (cpp = fcsalt_strings; *cpp != NULL; cpp++) 26537c478bd9Sstevel@tonic-gate if (cichar & 1<<(cpp-fcsalt_strings)) { 26547c478bd9Sstevel@tonic-gate cichar &= ~(1<<(cpp-fcsalt_strings)); 26557c478bd9Sstevel@tonic-gate printer(arg, (needcomma ? ",%s" : "fcs %s"), *cpp); 26567c478bd9Sstevel@tonic-gate needcomma = 1; 26577c478bd9Sstevel@tonic-gate } 26587c478bd9Sstevel@tonic-gate if (cichar != 0 || !needcomma) 26597c478bd9Sstevel@tonic-gate printer(arg, (needcomma ? ",0x%x" : "fcs 0x%x"), 26607c478bd9Sstevel@tonic-gate cichar); 26617c478bd9Sstevel@tonic-gate } 26627c478bd9Sstevel@tonic-gate break; 26637c478bd9Sstevel@tonic-gate case CI_NUMBERED: 26647c478bd9Sstevel@tonic-gate if (olen >= CILEN_SHORT) { 26657c478bd9Sstevel@tonic-gate p += 2; 26667c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); 26677c478bd9Sstevel@tonic-gate printer(arg, "numb win %d", cichar); 26687c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); 26697c478bd9Sstevel@tonic-gate printer(arg, " addr %d", cichar); 26707c478bd9Sstevel@tonic-gate } 26717c478bd9Sstevel@tonic-gate break; 26727c478bd9Sstevel@tonic-gate case CI_MRRU: 26737c478bd9Sstevel@tonic-gate if (olen >= CILEN_SHORT) { 26747c478bd9Sstevel@tonic-gate p += 2; 26757c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); 26767c478bd9Sstevel@tonic-gate printer(arg, "mrru %d", cishort); 26777c478bd9Sstevel@tonic-gate } 26787c478bd9Sstevel@tonic-gate break; 26797c478bd9Sstevel@tonic-gate case CI_SSNHF: 26807c478bd9Sstevel@tonic-gate if (olen >= CILEN_VOID) { 26817c478bd9Sstevel@tonic-gate p += 2; 26827c478bd9Sstevel@tonic-gate printer(arg, "ssnhf"); 26837c478bd9Sstevel@tonic-gate } 26847c478bd9Sstevel@tonic-gate break; 26857c478bd9Sstevel@tonic-gate case CI_EPDISC: 26867c478bd9Sstevel@tonic-gate if (olen >= CILEN_CHAR) { 26877c478bd9Sstevel@tonic-gate struct epdisc epd; 26887c478bd9Sstevel@tonic-gate p += 2; 26897c478bd9Sstevel@tonic-gate GETCHAR(epd.class, p); 26907c478bd9Sstevel@tonic-gate epd.length = olen - CILEN_CHAR; 26917c478bd9Sstevel@tonic-gate if (epd.length > MAX_ENDP_LEN) 26927c478bd9Sstevel@tonic-gate epd.length = MAX_ENDP_LEN; 26937c478bd9Sstevel@tonic-gate if (epd.length > 0) { 26947c478bd9Sstevel@tonic-gate BCOPY(p, epd.value, epd.length); 26957c478bd9Sstevel@tonic-gate p += epd.length; 26967c478bd9Sstevel@tonic-gate } 26977c478bd9Sstevel@tonic-gate printer(arg, "endpoint [%s]", epdisc_to_str(&epd)); 26987c478bd9Sstevel@tonic-gate } 26997c478bd9Sstevel@tonic-gate break; 27007c478bd9Sstevel@tonic-gate case CI_LINKDISC: 27017c478bd9Sstevel@tonic-gate if (olen >= CILEN_SHORT) { 27027c478bd9Sstevel@tonic-gate p += 2; 27037c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); 27047c478bd9Sstevel@tonic-gate printer(arg, "linkdisc %d", cishort); 27057c478bd9Sstevel@tonic-gate } 27067c478bd9Sstevel@tonic-gate break; 27077c478bd9Sstevel@tonic-gate case CI_COBS: 27087c478bd9Sstevel@tonic-gate if (olen >= CILEN_CHAR) { 27097c478bd9Sstevel@tonic-gate p += 2; 27107c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); 27117c478bd9Sstevel@tonic-gate printer(arg, "cobs 0x%x", cichar); 27127c478bd9Sstevel@tonic-gate } 27137c478bd9Sstevel@tonic-gate break; 27147c478bd9Sstevel@tonic-gate case CI_PFXELISION: 27157c478bd9Sstevel@tonic-gate if (olen >= CILEN_CHAR) { 27167c478bd9Sstevel@tonic-gate p += 2; 27177c478bd9Sstevel@tonic-gate printer(arg, "pfx"); 27187c478bd9Sstevel@tonic-gate } 27197c478bd9Sstevel@tonic-gate break; 27207c478bd9Sstevel@tonic-gate case CI_MPHDRFMT: 27217c478bd9Sstevel@tonic-gate if (olen >= CILEN_SHORT) { 27227c478bd9Sstevel@tonic-gate p += 2; 27237c478bd9Sstevel@tonic-gate printer(arg, "mphdr "); 27247c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); 27257c478bd9Sstevel@tonic-gate switch (cichar) { 27267c478bd9Sstevel@tonic-gate case 2: 27277c478bd9Sstevel@tonic-gate printer(arg, "long"); 27287c478bd9Sstevel@tonic-gate break; 27297c478bd9Sstevel@tonic-gate case 6: 27307c478bd9Sstevel@tonic-gate printer(arg, "short"); 27317c478bd9Sstevel@tonic-gate break; 27327c478bd9Sstevel@tonic-gate default: 27337c478bd9Sstevel@tonic-gate printer(arg, "0x%x", cichar); 27347c478bd9Sstevel@tonic-gate break; 27357c478bd9Sstevel@tonic-gate } 27367c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); 27377c478bd9Sstevel@tonic-gate printer(arg, " #cl %d", cichar); 27387c478bd9Sstevel@tonic-gate } 27397c478bd9Sstevel@tonic-gate break; 27407c478bd9Sstevel@tonic-gate case CI_I18N: 27417c478bd9Sstevel@tonic-gate if (olen >= CILEN_LONG) { 27427c478bd9Sstevel@tonic-gate p += 2; 27437c478bd9Sstevel@tonic-gate GETLONG(cilong, p); 27447c478bd9Sstevel@tonic-gate printer(arg, "i18n charset 0x%x", cilong); 27457c478bd9Sstevel@tonic-gate if (olen > CILEN_LONG) { 27467c478bd9Sstevel@tonic-gate printer(arg, " lang "); 27477c478bd9Sstevel@tonic-gate print_string((char *)p, olen-CILEN_LONG, printer, arg); 27487c478bd9Sstevel@tonic-gate p = optend; 27497c478bd9Sstevel@tonic-gate } 27507c478bd9Sstevel@tonic-gate } 27517c478bd9Sstevel@tonic-gate break; 27527c478bd9Sstevel@tonic-gate case CI_SDL: 27537c478bd9Sstevel@tonic-gate if (olen >= CILEN_VOID) { 27547c478bd9Sstevel@tonic-gate p += 2; 27557c478bd9Sstevel@tonic-gate printer(arg, "sdl"); 27567c478bd9Sstevel@tonic-gate } 27577c478bd9Sstevel@tonic-gate break; 27587c478bd9Sstevel@tonic-gate case CI_MUXING: 27597c478bd9Sstevel@tonic-gate if (olen >= CILEN_VOID) { 27607c478bd9Sstevel@tonic-gate p += 2; 27617c478bd9Sstevel@tonic-gate printer(arg, "mux"); 27627c478bd9Sstevel@tonic-gate } 27637c478bd9Sstevel@tonic-gate break; 27647c478bd9Sstevel@tonic-gate } 27657c478bd9Sstevel@tonic-gate while (p < optend) { 27667c478bd9Sstevel@tonic-gate GETCHAR(code, p); 27677c478bd9Sstevel@tonic-gate printer(arg, " %.2x", code); 27687c478bd9Sstevel@tonic-gate } 27697c478bd9Sstevel@tonic-gate printer(arg, ">"); 27707c478bd9Sstevel@tonic-gate } 27717c478bd9Sstevel@tonic-gate break; 27727c478bd9Sstevel@tonic-gate 27737c478bd9Sstevel@tonic-gate case CODE_TERMACK: 27747c478bd9Sstevel@tonic-gate case CODE_TERMREQ: 27757c478bd9Sstevel@tonic-gate if (len > 0 && *p >= ' ' && *p < 0x7f) { 27767c478bd9Sstevel@tonic-gate printer(arg, " "); 27777c478bd9Sstevel@tonic-gate print_string((char *)p, len, printer, arg); 27787c478bd9Sstevel@tonic-gate p += len; 27797c478bd9Sstevel@tonic-gate len = 0; 27807c478bd9Sstevel@tonic-gate } 27817c478bd9Sstevel@tonic-gate break; 27827c478bd9Sstevel@tonic-gate 27837c478bd9Sstevel@tonic-gate case CODE_ECHOREQ: 27847c478bd9Sstevel@tonic-gate case CODE_ECHOREP: 27857c478bd9Sstevel@tonic-gate case CODE_DISCREQ: 27867c478bd9Sstevel@tonic-gate if (len >= 4) { 27877c478bd9Sstevel@tonic-gate GETLONG(cilong, p); 27887c478bd9Sstevel@tonic-gate printer(arg, " magic=0x%x", cilong); 27897c478bd9Sstevel@tonic-gate len -= 4; 27907c478bd9Sstevel@tonic-gate } 27917c478bd9Sstevel@tonic-gate break; 27927c478bd9Sstevel@tonic-gate 27937c478bd9Sstevel@tonic-gate case CODE_IDENT: 27947c478bd9Sstevel@tonic-gate if (len >= 4) { 27957c478bd9Sstevel@tonic-gate GETLONG(cilong, p); 27967c478bd9Sstevel@tonic-gate printer(arg, " magic=0x%x", cilong); 27977c478bd9Sstevel@tonic-gate len -= 4; 27987c478bd9Sstevel@tonic-gate } else 27997c478bd9Sstevel@tonic-gate break; 28007c478bd9Sstevel@tonic-gate if (len > 0 && (len > 1 || *p != '\0')) { 28017c478bd9Sstevel@tonic-gate printer(arg, " "); 28027c478bd9Sstevel@tonic-gate print_string((char *)p, len, printer, arg); 28037c478bd9Sstevel@tonic-gate p += len; 28047c478bd9Sstevel@tonic-gate len = 0; 28057c478bd9Sstevel@tonic-gate } 28067c478bd9Sstevel@tonic-gate break; 28077c478bd9Sstevel@tonic-gate 28087c478bd9Sstevel@tonic-gate case CODE_TIMEREMAIN: 28097c478bd9Sstevel@tonic-gate if (len >= 4) { 28107c478bd9Sstevel@tonic-gate GETLONG(cilong, p); 28117c478bd9Sstevel@tonic-gate printer(arg, " magic=0x%x", cilong); 28127c478bd9Sstevel@tonic-gate len -= 4; 28137c478bd9Sstevel@tonic-gate } else 28147c478bd9Sstevel@tonic-gate break; 28157c478bd9Sstevel@tonic-gate if (len >= 4) { 28167c478bd9Sstevel@tonic-gate GETLONG(cilong, p); 28177c478bd9Sstevel@tonic-gate printer(arg, " seconds=%d", cilong); 28187c478bd9Sstevel@tonic-gate len -= 4; 28197c478bd9Sstevel@tonic-gate } else 28207c478bd9Sstevel@tonic-gate break; 28217c478bd9Sstevel@tonic-gate if (len > 0 && (len > 1 || *p != '\0')) { 28227c478bd9Sstevel@tonic-gate printer(arg, " "); 28237c478bd9Sstevel@tonic-gate print_string((char *)p, len, printer, arg); 28247c478bd9Sstevel@tonic-gate p += len; 28257c478bd9Sstevel@tonic-gate len = 0; 28267c478bd9Sstevel@tonic-gate } 28277c478bd9Sstevel@tonic-gate break; 28287c478bd9Sstevel@tonic-gate } 28297c478bd9Sstevel@tonic-gate 28307c478bd9Sstevel@tonic-gate /* print the rest of the bytes in the packet */ 28317c478bd9Sstevel@tonic-gate for (i = 0; i < len && i < 32; ++i) { 28327c478bd9Sstevel@tonic-gate GETCHAR(code, p); 28337c478bd9Sstevel@tonic-gate printer(arg, " %.2x", code); 28347c478bd9Sstevel@tonic-gate } 28357c478bd9Sstevel@tonic-gate if (i < len) { 28367c478bd9Sstevel@tonic-gate printer(arg, " ..."); 28377c478bd9Sstevel@tonic-gate p += len - i; 28387c478bd9Sstevel@tonic-gate } 28397c478bd9Sstevel@tonic-gate 28407c478bd9Sstevel@tonic-gate return p - pstart; 28417c478bd9Sstevel@tonic-gate } 28427c478bd9Sstevel@tonic-gate 28437c478bd9Sstevel@tonic-gate /* 28447c478bd9Sstevel@tonic-gate * Time to shut down the link because there is nothing out there. 28457c478bd9Sstevel@tonic-gate */ 28467c478bd9Sstevel@tonic-gate 28477c478bd9Sstevel@tonic-gate static void 28487c478bd9Sstevel@tonic-gate LcpLinkFailure (f) 28497c478bd9Sstevel@tonic-gate fsm *f; 28507c478bd9Sstevel@tonic-gate { 28517c478bd9Sstevel@tonic-gate char *close_message; 28527c478bd9Sstevel@tonic-gate 28537c478bd9Sstevel@tonic-gate if (f->state == OPENED) { 2854f53eecf5SJames Carlson if (lcp_echo_badreplies > LCP_ECHO_MAX_BADREPLIES) { 2855f53eecf5SJames Carlson info("Received %d bad echo-replies", lcp_echo_badreplies); 2856f53eecf5SJames Carlson close_message = "Receiving malformed Echo-Replies"; 2857f53eecf5SJames Carlson } else if (lcp_echo_accm_test) { 28587c478bd9Sstevel@tonic-gate /* 28597c478bd9Sstevel@tonic-gate * If this is an asynchronous line and we've missed all of 28607c478bd9Sstevel@tonic-gate * the initial echo requests, then this is probably due to 28617c478bd9Sstevel@tonic-gate * a bad ACCM. 28627c478bd9Sstevel@tonic-gate */ 28637c478bd9Sstevel@tonic-gate notice("Peer not responding to initial Echo-Requests."); 28647c478bd9Sstevel@tonic-gate notice("Negotiated asyncmap may be incorrect for this link."); 28657c478bd9Sstevel@tonic-gate close_message = "Peer not responding; perhaps bad asyncmap"; 2866f53eecf5SJames Carlson } else { 28677c478bd9Sstevel@tonic-gate info("No response to %d echo-requests", lcp_echos_pending); 28687c478bd9Sstevel@tonic-gate notice("Serial link appears to be disconnected."); 28697c478bd9Sstevel@tonic-gate close_message = "Peer not responding"; 28707c478bd9Sstevel@tonic-gate } 28717c478bd9Sstevel@tonic-gate 28727c478bd9Sstevel@tonic-gate lcp_close(f->unit, close_message); 28737c478bd9Sstevel@tonic-gate status = EXIT_PEER_DEAD; 28747c478bd9Sstevel@tonic-gate } 28757c478bd9Sstevel@tonic-gate } 28767c478bd9Sstevel@tonic-gate 28777c478bd9Sstevel@tonic-gate /* 28787c478bd9Sstevel@tonic-gate * Timer expired for the LCP echo requests from this process. 28797c478bd9Sstevel@tonic-gate */ 28807c478bd9Sstevel@tonic-gate 28817c478bd9Sstevel@tonic-gate static void 28827c478bd9Sstevel@tonic-gate LcpEchoCheck (f) 28837c478bd9Sstevel@tonic-gate fsm *f; 28847c478bd9Sstevel@tonic-gate { 28857c478bd9Sstevel@tonic-gate if (f->state != OPENED || lcp_echo_interval == 0) 28867c478bd9Sstevel@tonic-gate return; 28877c478bd9Sstevel@tonic-gate 28887c478bd9Sstevel@tonic-gate LcpSendEchoRequest (f); 28897c478bd9Sstevel@tonic-gate 28907c478bd9Sstevel@tonic-gate /* 28917c478bd9Sstevel@tonic-gate * Start the timer for the next interval. 28927c478bd9Sstevel@tonic-gate */ 28937c478bd9Sstevel@tonic-gate if (lcp_echo_timer_running) 28947c478bd9Sstevel@tonic-gate warn("assertion lcp_echo_timer_running==0 failed"); 28957c478bd9Sstevel@tonic-gate TIMEOUT (LcpEchoTimeout, f, lcp_echo_interval); 28967c478bd9Sstevel@tonic-gate lcp_echo_timer_running = 1; 28977c478bd9Sstevel@tonic-gate } 28987c478bd9Sstevel@tonic-gate 28997c478bd9Sstevel@tonic-gate /* 29007c478bd9Sstevel@tonic-gate * LcpEchoTimeout - Timer expired on the LCP echo 29017c478bd9Sstevel@tonic-gate */ 29027c478bd9Sstevel@tonic-gate 29037c478bd9Sstevel@tonic-gate static void 29047c478bd9Sstevel@tonic-gate LcpEchoTimeout (arg) 29057c478bd9Sstevel@tonic-gate void *arg; 29067c478bd9Sstevel@tonic-gate { 29077c478bd9Sstevel@tonic-gate if (lcp_echo_timer_running != 0) { 29087c478bd9Sstevel@tonic-gate lcp_echo_timer_running = 0; 29097c478bd9Sstevel@tonic-gate LcpEchoCheck ((fsm *) arg); 29107c478bd9Sstevel@tonic-gate } 29117c478bd9Sstevel@tonic-gate } 29127c478bd9Sstevel@tonic-gate 29137c478bd9Sstevel@tonic-gate /* 29147c478bd9Sstevel@tonic-gate * LcpEchoReply - LCP has received a reply to the echo 29157c478bd9Sstevel@tonic-gate */ 29167c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 29177c478bd9Sstevel@tonic-gate static int 29187c478bd9Sstevel@tonic-gate lcp_received_echo_reply (f, id, inp, len) 29197c478bd9Sstevel@tonic-gate fsm *f; 29207c478bd9Sstevel@tonic-gate int id; 29217c478bd9Sstevel@tonic-gate u_char *inp; 29227c478bd9Sstevel@tonic-gate int len; 29237c478bd9Sstevel@tonic-gate { 29247c478bd9Sstevel@tonic-gate u_int32_t magic; 29257c478bd9Sstevel@tonic-gate 29267c478bd9Sstevel@tonic-gate /* Check the magic number - don't count replies from ourselves. */ 29277c478bd9Sstevel@tonic-gate if (len < 4) { 29287c478bd9Sstevel@tonic-gate dbglog("lcp: received short Echo-Reply, length %d", len); 29297c478bd9Sstevel@tonic-gate return (0); 29307c478bd9Sstevel@tonic-gate } 29317c478bd9Sstevel@tonic-gate GETLONG(magic, inp); 29327c478bd9Sstevel@tonic-gate if (lcp_gotoptions[f->unit].neg_magicnumber && 29337c478bd9Sstevel@tonic-gate magic == lcp_gotoptions[f->unit].magicnumber) { 29347c478bd9Sstevel@tonic-gate warn("appear to have received our own echo-reply!"); 29357c478bd9Sstevel@tonic-gate return (0); 29367c478bd9Sstevel@tonic-gate } 29377c478bd9Sstevel@tonic-gate 29387c478bd9Sstevel@tonic-gate /* Reset the number of outstanding echo frames */ 29397c478bd9Sstevel@tonic-gate lcp_echos_pending = 0; 29407c478bd9Sstevel@tonic-gate 2941f53eecf5SJames Carlson if (lcp_echo_accm_test) { 29427c478bd9Sstevel@tonic-gate dbglog("lcp: validated asyncmap setting"); 2943f53eecf5SJames Carlson lcp_echo_accm_test = 0; 29447c478bd9Sstevel@tonic-gate if (lcp_echo_fails == 0) 29457c478bd9Sstevel@tonic-gate lcp_echo_interval = 0; 29467c478bd9Sstevel@tonic-gate } 29477c478bd9Sstevel@tonic-gate return (1); 29487c478bd9Sstevel@tonic-gate } 29497c478bd9Sstevel@tonic-gate 29507c478bd9Sstevel@tonic-gate /* 29517c478bd9Sstevel@tonic-gate * LcpSendEchoRequest - Send an echo request frame to the peer 29527c478bd9Sstevel@tonic-gate */ 29537c478bd9Sstevel@tonic-gate 29547c478bd9Sstevel@tonic-gate static void 29557c478bd9Sstevel@tonic-gate LcpSendEchoRequest (f) 29567c478bd9Sstevel@tonic-gate fsm *f; 29577c478bd9Sstevel@tonic-gate { 29587c478bd9Sstevel@tonic-gate u_int32_t lcp_magic; 29597c478bd9Sstevel@tonic-gate u_char pkt[4+256], *pktp; 29607c478bd9Sstevel@tonic-gate int i; 29617c478bd9Sstevel@tonic-gate 29627c478bd9Sstevel@tonic-gate /* 2963f53eecf5SJames Carlson * Detect the failure of the peer at this point. If we're not currently 2964f53eecf5SJames Carlson * performing the ACCM test, then we just check for the user's echo-failure 2965f53eecf5SJames Carlson * point. If we are performing the ACCM test, then use ACCM_TEST_FAILS if 2966f53eecf5SJames Carlson * the user hasn't specified a different failure point. 29677c478bd9Sstevel@tonic-gate */ 2968f53eecf5SJames Carlson i = lcp_echo_fails; 2969f53eecf5SJames Carlson if (i == 0) 2970f53eecf5SJames Carlson i = ACCM_TEST_FAILS; 2971f53eecf5SJames Carlson if ((!lcp_echo_accm_test && lcp_echo_fails != 0 && 2972f53eecf5SJames Carlson lcp_echos_pending >= lcp_echo_fails) || 2973f53eecf5SJames Carlson (lcp_echo_accm_test && lcp_echos_pending >= i)) { 29747c478bd9Sstevel@tonic-gate LcpLinkFailure(f); 29757c478bd9Sstevel@tonic-gate lcp_echos_pending = 0; 29767c478bd9Sstevel@tonic-gate lcp_echo_badreplies = 0; 29777c478bd9Sstevel@tonic-gate } 29787c478bd9Sstevel@tonic-gate 29797c478bd9Sstevel@tonic-gate /* 29807c478bd9Sstevel@tonic-gate * Make and send the echo request frame. 29817c478bd9Sstevel@tonic-gate */ 29827c478bd9Sstevel@tonic-gate if (f->state == OPENED) { 29837c478bd9Sstevel@tonic-gate lcp_magic = lcp_gotoptions[f->unit].magicnumber; 29847c478bd9Sstevel@tonic-gate pktp = pkt; 29857c478bd9Sstevel@tonic-gate PUTLONG(lcp_magic, pktp); 29867c478bd9Sstevel@tonic-gate /* Send some test packets so we can fail the link early. */ 2987f53eecf5SJames Carlson if (lcp_echo_accm_test) { 29887c478bd9Sstevel@tonic-gate switch (use_accm_test) { 29897c478bd9Sstevel@tonic-gate case 1: 29907c478bd9Sstevel@tonic-gate /* Only the characters covered by negotiated ACCM */ 29917c478bd9Sstevel@tonic-gate for (i = 0; i < 32; i++) 29927c478bd9Sstevel@tonic-gate *pktp++ = i; 29937c478bd9Sstevel@tonic-gate break; 29947c478bd9Sstevel@tonic-gate case 2: 29957c478bd9Sstevel@tonic-gate /* All characters */ 29967c478bd9Sstevel@tonic-gate for (i = 0; i < 256; i++) 29977c478bd9Sstevel@tonic-gate *pktp++ = i; 29987c478bd9Sstevel@tonic-gate break; 29997c478bd9Sstevel@tonic-gate } 30007c478bd9Sstevel@tonic-gate } 30017c478bd9Sstevel@tonic-gate fsm_sdata(f, CODE_ECHOREQ, lcp_echo_number++ & 0xFF, pkt, pktp - pkt); 30027c478bd9Sstevel@tonic-gate ++lcp_echos_pending; 30037c478bd9Sstevel@tonic-gate } 30047c478bd9Sstevel@tonic-gate } 30057c478bd9Sstevel@tonic-gate 30067c478bd9Sstevel@tonic-gate /* 30077c478bd9Sstevel@tonic-gate * lcp_echo_lowerup - Start the timer for the LCP frame 30087c478bd9Sstevel@tonic-gate */ 30097c478bd9Sstevel@tonic-gate 30107c478bd9Sstevel@tonic-gate static void 30117c478bd9Sstevel@tonic-gate lcp_echo_lowerup (unit) 30127c478bd9Sstevel@tonic-gate int unit; 30137c478bd9Sstevel@tonic-gate { 30147c478bd9Sstevel@tonic-gate fsm *f = &lcp_fsm[unit]; 30157c478bd9Sstevel@tonic-gate 30167c478bd9Sstevel@tonic-gate /* Clear the parameters for generating echo frames */ 30177c478bd9Sstevel@tonic-gate lcp_echos_pending = 0; 30187c478bd9Sstevel@tonic-gate lcp_echo_number = 0; 30197c478bd9Sstevel@tonic-gate lcp_echo_timer_running = 0; 3020f53eecf5SJames Carlson lcp_echo_accm_test = !sync_serial && use_accm_test; 30217c478bd9Sstevel@tonic-gate 30227c478bd9Sstevel@tonic-gate /* If a timeout interval is specified then start the timer */ 30237c478bd9Sstevel@tonic-gate LcpEchoCheck(f); 30247c478bd9Sstevel@tonic-gate } 30257c478bd9Sstevel@tonic-gate 30267c478bd9Sstevel@tonic-gate /* 30277c478bd9Sstevel@tonic-gate * lcp_echo_lowerdown - Stop the timer for the LCP frame 30287c478bd9Sstevel@tonic-gate */ 30297c478bd9Sstevel@tonic-gate 30307c478bd9Sstevel@tonic-gate static void 30317c478bd9Sstevel@tonic-gate lcp_echo_lowerdown (unit) 30327c478bd9Sstevel@tonic-gate int unit; 30337c478bd9Sstevel@tonic-gate { 30347c478bd9Sstevel@tonic-gate fsm *f = &lcp_fsm[unit]; 30357c478bd9Sstevel@tonic-gate 30367c478bd9Sstevel@tonic-gate if (lcp_echo_timer_running != 0) { 30377c478bd9Sstevel@tonic-gate UNTIMEOUT (LcpEchoTimeout, f); 30387c478bd9Sstevel@tonic-gate lcp_echo_timer_running = 0; 30397c478bd9Sstevel@tonic-gate } 30407c478bd9Sstevel@tonic-gate } 30417c478bd9Sstevel@tonic-gate 30427c478bd9Sstevel@tonic-gate /* 30437c478bd9Sstevel@tonic-gate * LcpSendIdentification - Send LCP Identification string to peer. 30447c478bd9Sstevel@tonic-gate */ 30457c478bd9Sstevel@tonic-gate 30467c478bd9Sstevel@tonic-gate static void 30477c478bd9Sstevel@tonic-gate LcpSendIdentification (f) 30487c478bd9Sstevel@tonic-gate fsm *f; 30497c478bd9Sstevel@tonic-gate { 30507c478bd9Sstevel@tonic-gate u_int32_t lcp_magic; 30517c478bd9Sstevel@tonic-gate u_char pkt[4 + sizeof(identstr)], *pktp; 30527c478bd9Sstevel@tonic-gate int idlen; 30537c478bd9Sstevel@tonic-gate 30547c478bd9Sstevel@tonic-gate /* 30557c478bd9Sstevel@tonic-gate * Make and send the Identification frame. 30567c478bd9Sstevel@tonic-gate */ 30577c478bd9Sstevel@tonic-gate if (f->state == OPENED) 30587c478bd9Sstevel@tonic-gate lcp_magic = lcp_gotoptions[f->unit].magicnumber; 30597c478bd9Sstevel@tonic-gate else 30607c478bd9Sstevel@tonic-gate lcp_magic = 0; 30617c478bd9Sstevel@tonic-gate 30627c478bd9Sstevel@tonic-gate pktp = pkt; 30637c478bd9Sstevel@tonic-gate PUTLONG(lcp_magic, pktp); 30647c478bd9Sstevel@tonic-gate idlen = strlen(identstr); 30657c478bd9Sstevel@tonic-gate BCOPY(identstr, pktp, idlen); 30667c478bd9Sstevel@tonic-gate INCPTR(idlen, pktp); 30677c478bd9Sstevel@tonic-gate fsm_sdata(f, CODE_IDENT, ++f->id, pkt, pktp - pkt); 30687c478bd9Sstevel@tonic-gate } 30697c478bd9Sstevel@tonic-gate 30707c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 30717c478bd9Sstevel@tonic-gate static void 30727c478bd9Sstevel@tonic-gate lcp_received_identification (f, id, inp, len) 30737c478bd9Sstevel@tonic-gate fsm *f; 30747c478bd9Sstevel@tonic-gate int id; 30757c478bd9Sstevel@tonic-gate u_char *inp; 30767c478bd9Sstevel@tonic-gate int len; 30777c478bd9Sstevel@tonic-gate { 30787c478bd9Sstevel@tonic-gate u_int32_t magic; 30797c478bd9Sstevel@tonic-gate 30807c478bd9Sstevel@tonic-gate /* Check the magic number - don't count replies from ourselves. */ 30817c478bd9Sstevel@tonic-gate if (len < 4) { 30827c478bd9Sstevel@tonic-gate dbglog("%s: received short Identification; %d < 4", len); 30837c478bd9Sstevel@tonic-gate return; 30847c478bd9Sstevel@tonic-gate } 30857c478bd9Sstevel@tonic-gate GETLONG(magic, inp); 30867c478bd9Sstevel@tonic-gate len -= 4; 30877c478bd9Sstevel@tonic-gate if (lcp_gotoptions[f->unit].neg_magicnumber && f->state == OPENED && 30887c478bd9Sstevel@tonic-gate magic == lcp_gotoptions[f->unit].magicnumber) { 30897c478bd9Sstevel@tonic-gate warn("appear to have received our own Identification!"); 30907c478bd9Sstevel@tonic-gate return; 30917c478bd9Sstevel@tonic-gate } 30927c478bd9Sstevel@tonic-gate if (len > 0 && (len > 1 || *inp != '\0')) 30937c478bd9Sstevel@tonic-gate notice("Peer Identification: %0.*v", len, inp); 30947c478bd9Sstevel@tonic-gate } 30957c478bd9Sstevel@tonic-gate 30967c478bd9Sstevel@tonic-gate /* 30977c478bd9Sstevel@tonic-gate * Send a Time-Remaining LCP packet. We don't include a message. 30987c478bd9Sstevel@tonic-gate */ 30997c478bd9Sstevel@tonic-gate static void 31007c478bd9Sstevel@tonic-gate LcpSendTimeRemaining(f, time_remaining) 31017c478bd9Sstevel@tonic-gate fsm *f; 31027c478bd9Sstevel@tonic-gate u_int32_t time_remaining; 31037c478bd9Sstevel@tonic-gate { 31047c478bd9Sstevel@tonic-gate u_int32_t lcp_magic; 31057c478bd9Sstevel@tonic-gate u_char pkt[8]; 31067c478bd9Sstevel@tonic-gate u_char *pktp; 31077c478bd9Sstevel@tonic-gate 31087c478bd9Sstevel@tonic-gate if (f->state != OPENED) 31097c478bd9Sstevel@tonic-gate return; 31107c478bd9Sstevel@tonic-gate 31117c478bd9Sstevel@tonic-gate lcp_magic = lcp_gotoptions[f->unit].magicnumber; 31127c478bd9Sstevel@tonic-gate pktp = pkt; 31137c478bd9Sstevel@tonic-gate PUTLONG(lcp_magic, pktp); 31147c478bd9Sstevel@tonic-gate PUTLONG(time_remaining, pktp); 31157c478bd9Sstevel@tonic-gate fsm_sdata(f, CODE_TIMEREMAIN, ++f->id, pkt, pktp - pkt); 31167c478bd9Sstevel@tonic-gate } 31177c478bd9Sstevel@tonic-gate 31187c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 31197c478bd9Sstevel@tonic-gate static void 31207c478bd9Sstevel@tonic-gate lcp_received_timeremain(f, id, inp, len) 31217c478bd9Sstevel@tonic-gate fsm *f; 31227c478bd9Sstevel@tonic-gate int id; 31237c478bd9Sstevel@tonic-gate u_char *inp; 31247c478bd9Sstevel@tonic-gate int len; 31257c478bd9Sstevel@tonic-gate { 31267c478bd9Sstevel@tonic-gate u_int32_t magic; 31277c478bd9Sstevel@tonic-gate u_int32_t time_remaining; 31287c478bd9Sstevel@tonic-gate 31297c478bd9Sstevel@tonic-gate /* Check the magic number - don't count replies from ourselves. */ 31307c478bd9Sstevel@tonic-gate if (len < 8) { 31317c478bd9Sstevel@tonic-gate dbglog("%s: received short Time-Remain; %d < 8", len); 31327c478bd9Sstevel@tonic-gate return; 31337c478bd9Sstevel@tonic-gate } 31347c478bd9Sstevel@tonic-gate GETLONG(magic, inp); 31357c478bd9Sstevel@tonic-gate if (lcp_gotoptions[f->unit].neg_magicnumber && f->state == OPENED && 31367c478bd9Sstevel@tonic-gate magic == lcp_gotoptions[f->unit].magicnumber) { 31377c478bd9Sstevel@tonic-gate warn("appear to have received our own Time-Remain!"); 31387c478bd9Sstevel@tonic-gate return; 31397c478bd9Sstevel@tonic-gate } 31407c478bd9Sstevel@tonic-gate GETLONG(time_remaining, inp); 31417c478bd9Sstevel@tonic-gate if (len > 8) { 31427c478bd9Sstevel@tonic-gate notice("%d seconds remain: \"%.*s\"", time_remaining, 31437c478bd9Sstevel@tonic-gate len-8, inp); 31447c478bd9Sstevel@tonic-gate } else { 31457c478bd9Sstevel@tonic-gate notice("Time Remaining: %d seconds", time_remaining); 31467c478bd9Sstevel@tonic-gate } 31477c478bd9Sstevel@tonic-gate } 31487c478bd9Sstevel@tonic-gate 31497c478bd9Sstevel@tonic-gate /* 31507c478bd9Sstevel@tonic-gate * lcp_timeremaining - timeout handler which sends LCP Time-Remaining 31517c478bd9Sstevel@tonic-gate * packet. 31527c478bd9Sstevel@tonic-gate */ 31537c478bd9Sstevel@tonic-gate static void 31547c478bd9Sstevel@tonic-gate lcp_timeremaining(arg) 31557c478bd9Sstevel@tonic-gate void *arg; 31567c478bd9Sstevel@tonic-gate { 31577c478bd9Sstevel@tonic-gate struct lcp_timer *lt = (struct lcp_timer *)arg; 31587c478bd9Sstevel@tonic-gate u_int32_t time_remaining; 31597c478bd9Sstevel@tonic-gate int unit; 31607c478bd9Sstevel@tonic-gate 31617c478bd9Sstevel@tonic-gate unit = lt->unit; 31627c478bd9Sstevel@tonic-gate time_remaining = lt->tr; 31637c478bd9Sstevel@tonic-gate LcpSendTimeRemaining(&lcp_fsm[unit], time_remaining); 31647c478bd9Sstevel@tonic-gate free(lt); 31657c478bd9Sstevel@tonic-gate } 31667c478bd9Sstevel@tonic-gate 31677c478bd9Sstevel@tonic-gate /* 31687c478bd9Sstevel@tonic-gate * lcp_settimeremaining - set a timeout to send an LCP Time-Remaining 31697c478bd9Sstevel@tonic-gate * packet. The first argument, connecttime, is the time remaining 31707c478bd9Sstevel@tonic-gate * at the time this function is called. The second argument is the 31717c478bd9Sstevel@tonic-gate * desired time remaining when the packet should be sent out. 31727c478bd9Sstevel@tonic-gate */ 31737c478bd9Sstevel@tonic-gate void 31747c478bd9Sstevel@tonic-gate lcp_settimeremaining(unit, connecttime, time_remaining) 31757c478bd9Sstevel@tonic-gate int unit; 31767c478bd9Sstevel@tonic-gate u_int32_t connecttime; 31777c478bd9Sstevel@tonic-gate u_int32_t time_remaining; 31787c478bd9Sstevel@tonic-gate { 31797c478bd9Sstevel@tonic-gate struct lcp_timer *lt; 31807c478bd9Sstevel@tonic-gate 31817c478bd9Sstevel@tonic-gate if (connecttime == time_remaining) { 31827c478bd9Sstevel@tonic-gate LcpSendTimeRemaining(&lcp_fsm[unit], time_remaining); 31837c478bd9Sstevel@tonic-gate } else { 31847c478bd9Sstevel@tonic-gate lt = (struct lcp_timer *)malloc(sizeof (struct lcp_timer)); 31857c478bd9Sstevel@tonic-gate lt->unit = unit; 31867c478bd9Sstevel@tonic-gate lt->tr = time_remaining; 31877c478bd9Sstevel@tonic-gate TIMEOUT(lcp_timeremaining, (void *)lt, connecttime - time_remaining); 31887c478bd9Sstevel@tonic-gate } 31897c478bd9Sstevel@tonic-gate } 3190