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