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