17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * lcp.c - PPP Link Control Protocol.
37c478bd9Sstevel@tonic-gate *
4f53eecf5SJames Carlson * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
57c478bd9Sstevel@tonic-gate * Use is subject to license terms.
67c478bd9Sstevel@tonic-gate *
77c478bd9Sstevel@tonic-gate * Copyright (c) 1989 Carnegie Mellon University.
87c478bd9Sstevel@tonic-gate * All rights reserved.
97c478bd9Sstevel@tonic-gate *
10*48bbca81SDaniel Hoffman * Copyright (c) 2016 by Delphix. All rights reserved.
11*48bbca81SDaniel Hoffman *
127c478bd9Sstevel@tonic-gate * Redistribution and use in source and binary forms are permitted
137c478bd9Sstevel@tonic-gate * provided that the above copyright notice and this paragraph are
147c478bd9Sstevel@tonic-gate * duplicated in all such forms and that any documentation,
157c478bd9Sstevel@tonic-gate * advertising materials, and other materials related to such
167c478bd9Sstevel@tonic-gate * distribution and use acknowledge that the software was developed
177c478bd9Sstevel@tonic-gate * by Carnegie Mellon University. The name of the
187c478bd9Sstevel@tonic-gate * University may not be used to endorse or promote products derived
197c478bd9Sstevel@tonic-gate * from this software without specific prior written permission.
207c478bd9Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
217c478bd9Sstevel@tonic-gate * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
227c478bd9Sstevel@tonic-gate * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
237c478bd9Sstevel@tonic-gate */
247c478bd9Sstevel@tonic-gate
257c478bd9Sstevel@tonic-gate #include <stdio.h>
267c478bd9Sstevel@tonic-gate #include <string.h>
277c478bd9Sstevel@tonic-gate #include <stdlib.h>
287c478bd9Sstevel@tonic-gate #include <ctype.h>
297c478bd9Sstevel@tonic-gate #if defined(CHAPMS) || defined(CHAPMSV2)
307c478bd9Sstevel@tonic-gate #ifdef HAVE_CRYPT_H
317c478bd9Sstevel@tonic-gate #include <crypt.h>
327c478bd9Sstevel@tonic-gate #endif
337c478bd9Sstevel@tonic-gate #ifndef USE_CRYPT
347c478bd9Sstevel@tonic-gate #include <des.h>
357c478bd9Sstevel@tonic-gate #endif
367c478bd9Sstevel@tonic-gate #ifdef SOL2
377c478bd9Sstevel@tonic-gate #include <errno.h>
387c478bd9Sstevel@tonic-gate #endif
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate #include "pppd.h"
427c478bd9Sstevel@tonic-gate #include "fsm.h"
437c478bd9Sstevel@tonic-gate #include "lcp.h"
447c478bd9Sstevel@tonic-gate #include "chap.h"
457c478bd9Sstevel@tonic-gate #include "magic.h"
467c478bd9Sstevel@tonic-gate #include "patchlevel.h"
477c478bd9Sstevel@tonic-gate
487c478bd9Sstevel@tonic-gate /*
497c478bd9Sstevel@tonic-gate * Special failure codes for logging link failure reasons.
507c478bd9Sstevel@tonic-gate */
517c478bd9Sstevel@tonic-gate bool peer_nak_auth; /* Peer sent nak for our auth request */
527c478bd9Sstevel@tonic-gate u_short nak_auth_orig; /* Auth proto peer naked */
537c478bd9Sstevel@tonic-gate u_short nak_auth_proto; /* Auth proto peer suggested instead */
547c478bd9Sstevel@tonic-gate bool unsolicited_nak_auth; /* Peer asked us to authenticate */
557c478bd9Sstevel@tonic-gate u_short unsolicit_auth_proto; /* Auth proto peer wants */
567c478bd9Sstevel@tonic-gate bool peer_reject_auth; /* Peer sent reject for auth */
577c478bd9Sstevel@tonic-gate u_short reject_auth_proto; /* Protocol that peer rejected */
587c478bd9Sstevel@tonic-gate bool rejected_peers_auth; /* We sent a reject to the peer */
597c478bd9Sstevel@tonic-gate u_short rejected_auth_proto; /* Protocol that peer wanted to use */
607c478bd9Sstevel@tonic-gate bool naked_peers_auth; /* We sent a nak to the peer */
617c478bd9Sstevel@tonic-gate u_short naked_auth_orig; /* Protocol that we wanted to use */
627c478bd9Sstevel@tonic-gate u_short naked_auth_proto; /* Protocol that peer wants us to use */
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate /*
657c478bd9Sstevel@tonic-gate * LCP-related command-line options.
667c478bd9Sstevel@tonic-gate */
677c478bd9Sstevel@tonic-gate int lcp_echo_interval = 0; /* Interval between LCP echo-requests */
687c478bd9Sstevel@tonic-gate int lcp_echo_fails = 0; /* Tolerance to unanswered echo-requests */
697c478bd9Sstevel@tonic-gate bool lax_recv = 0; /* accept control chars in asyncmap */
707c478bd9Sstevel@tonic-gate static int use_accm_test = 2; /* use big echo-requests to check ACCM */
717c478bd9Sstevel@tonic-gate #define ACCM_TEST_FAILS 5
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate #define _tostr2(x) #x
747c478bd9Sstevel@tonic-gate #define _tostr(x) _tostr2(x)
757c478bd9Sstevel@tonic-gate static char identstr[256] = /* Identification string */
767c478bd9Sstevel@tonic-gate "ppp-" VERSION "." _tostr(PATCHLEVEL) IMPLEMENTATION;
777c478bd9Sstevel@tonic-gate static int noident = 0; /* 1 to disable; 2 to reject */
787c478bd9Sstevel@tonic-gate static int sentident = 0; /* counts the # of ident codes sent */
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate /* set if we're allowed to send an unsolicited Configure-Nak for MRU. */
817c478bd9Sstevel@tonic-gate static bool unsolicit_mru;
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate static int setescape __P((char **, option_t *));
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate static bool do_msft_workaround = 1;
867c478bd9Sstevel@tonic-gate static int setasyncmap __P((char **, option_t *));
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate bool noendpoint = 0; /* don't send/accept endpoint discriminator */
897c478bd9Sstevel@tonic-gate static int setendpoint __P((char **, option_t *));
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate static char *callback_strings[] = {
927c478bd9Sstevel@tonic-gate "auth", "dialstring", "location", "E.164", "X.500", "", "CBCP", NULL
937c478bd9Sstevel@tonic-gate };
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate /* This is used in packet printing even if NEGOTIATE_FCS isn't enabled */
967c478bd9Sstevel@tonic-gate static char *fcsalt_strings[] = {
977c478bd9Sstevel@tonic-gate "null", "crc16", "crc32", NULL
987c478bd9Sstevel@tonic-gate };
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate #ifdef NEGOTIATE_FCS
1017c478bd9Sstevel@tonic-gate static int setfcsallow __P((char **, option_t *));
1027c478bd9Sstevel@tonic-gate static int setfcswant __P((char **, option_t *));
1037c478bd9Sstevel@tonic-gate #endif
1047c478bd9Sstevel@tonic-gate
1057c478bd9Sstevel@tonic-gate /* Backward compatibility for Linux */
1067c478bd9Sstevel@tonic-gate #ifndef PPP_MAXMRU
1077c478bd9Sstevel@tonic-gate #define PPP_MTU 1500 /* Default MTU (size of Info field) */
1087c478bd9Sstevel@tonic-gate #define PPP_MAXMTU 65535 - (PPP_HDRLEN + PPP_FCSLEN)
1097c478bd9Sstevel@tonic-gate #define PPP_MINMTU 64
1107c478bd9Sstevel@tonic-gate #define PPP_MAXMRU 65000 /* Largest MRU we allow */
1117c478bd9Sstevel@tonic-gate #define PPP_MINMRU 128
1127c478bd9Sstevel@tonic-gate #endif
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate static option_t lcp_option_list[] = {
1157c478bd9Sstevel@tonic-gate /* LCP options */
1167c478bd9Sstevel@tonic-gate { "noaccomp", o_bool, &lcp_wantoptions[0].neg_accompression,
1177c478bd9Sstevel@tonic-gate "Disable address/control compression",
1187c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_accompression },
1197c478bd9Sstevel@tonic-gate { "-ac", o_bool, &lcp_wantoptions[0].neg_accompression,
1207c478bd9Sstevel@tonic-gate "Disable address/control compression",
1217c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_accompression },
1227c478bd9Sstevel@tonic-gate { "default-asyncmap", o_bool, &lcp_wantoptions[0].neg_asyncmap,
1237c478bd9Sstevel@tonic-gate "Disable asyncmap negotiation",
1247c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_asyncmap },
1257c478bd9Sstevel@tonic-gate { "-am", o_bool, &lcp_wantoptions[0].neg_asyncmap,
1267c478bd9Sstevel@tonic-gate "Disable asyncmap negotiation",
1277c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_asyncmap },
1287c478bd9Sstevel@tonic-gate { "asyncmap", o_special, (void *)setasyncmap,
1297c478bd9Sstevel@tonic-gate "Set asyncmap (for received packets)" },
1307c478bd9Sstevel@tonic-gate { "-as", o_special, (void *)setasyncmap,
1317c478bd9Sstevel@tonic-gate "Set asyncmap (for received packets)" },
1327c478bd9Sstevel@tonic-gate { "nomagic", o_bool, &lcp_wantoptions[0].neg_magicnumber,
1337c478bd9Sstevel@tonic-gate "Disable magic number option (looped-back line detect)",
1347c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_magicnumber },
1357c478bd9Sstevel@tonic-gate { "-mn", o_bool, &lcp_wantoptions[0].neg_magicnumber,
1367c478bd9Sstevel@tonic-gate "Disable magic number option (looped-back line detect)",
1377c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_magicnumber },
1387c478bd9Sstevel@tonic-gate { "default-mru", o_bool, &lcp_wantoptions[0].neg_mru,
1397c478bd9Sstevel@tonic-gate "Disable MRU negotiation (use default 1500)",
1407c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_mru },
1417c478bd9Sstevel@tonic-gate { "-mru", o_bool, &lcp_wantoptions[0].neg_mru,
1427c478bd9Sstevel@tonic-gate "Disable MRU negotiation (use default 1500)",
1437c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_mru },
1447c478bd9Sstevel@tonic-gate { "mru", o_int, &lcp_wantoptions[0].mru,
1457c478bd9Sstevel@tonic-gate "Set MRU (maximum received packet size) for negotiation",
1467c478bd9Sstevel@tonic-gate OPT_LIMITS, &lcp_wantoptions[0].neg_mru, PPP_MAXMRU, PPP_MINMRU },
1477c478bd9Sstevel@tonic-gate { "mtu", o_int, &lcp_allowoptions[0].mru,
1487c478bd9Sstevel@tonic-gate "Set our MTU", OPT_LIMITS|OPT_A2COPY, &lcp_allowoptions[0].mrru,
1497c478bd9Sstevel@tonic-gate PPP_MAXMTU, PPP_MINMTU },
1507c478bd9Sstevel@tonic-gate { "nopcomp", o_bool, &lcp_wantoptions[0].neg_pcompression,
1517c478bd9Sstevel@tonic-gate "Disable protocol field compression",
1527c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_pcompression },
1537c478bd9Sstevel@tonic-gate { "-pc", o_bool, &lcp_wantoptions[0].neg_pcompression,
1547c478bd9Sstevel@tonic-gate "Disable protocol field compression",
1557c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_pcompression },
1567c478bd9Sstevel@tonic-gate { "-p", o_bool, &lcp_wantoptions[0].passive,
1577c478bd9Sstevel@tonic-gate "Set passive mode", 1 },
1587c478bd9Sstevel@tonic-gate { "passive", o_bool, &lcp_wantoptions[0].passive,
1597c478bd9Sstevel@tonic-gate "Set passive mode", 1 },
1607c478bd9Sstevel@tonic-gate { "silent", o_bool, &lcp_wantoptions[0].silent,
1617c478bd9Sstevel@tonic-gate "Set silent mode", 1 },
1627c478bd9Sstevel@tonic-gate { "escape", o_special, (void *)setescape,
1637c478bd9Sstevel@tonic-gate "List of character codes to escape on transmission" },
1647c478bd9Sstevel@tonic-gate { "lcp-echo-failure", o_int, &lcp_echo_fails,
1657c478bd9Sstevel@tonic-gate "Number of consecutive echo failures for link failure" },
1667c478bd9Sstevel@tonic-gate { "lcp-echo-interval", o_int, &lcp_echo_interval,
1677c478bd9Sstevel@tonic-gate "Set time in seconds between LCP echo requests" },
1687c478bd9Sstevel@tonic-gate { "no-accm-test", o_int, &use_accm_test,
1697c478bd9Sstevel@tonic-gate "Disable use of LCP Echo-Request asyncmap checking",
1707c478bd9Sstevel@tonic-gate OPT_NOARG|OPT_VAL(0) },
1717c478bd9Sstevel@tonic-gate { "small-accm-test", o_int, &use_accm_test,
1727c478bd9Sstevel@tonic-gate "Use only small Echo-Requests for asyncmap checking",
1737c478bd9Sstevel@tonic-gate OPT_NOARG|OPT_VAL(1) },
1747c478bd9Sstevel@tonic-gate { "lcp-restart", o_int, &lcp_fsm[0].timeouttime,
1757c478bd9Sstevel@tonic-gate "Set time in seconds between LCP retransmissions" },
1767c478bd9Sstevel@tonic-gate { "lcp-max-terminate", o_int, &lcp_fsm[0].maxtermtransmits,
1777c478bd9Sstevel@tonic-gate "Maximum number of LCP terminate-request transmissions" },
1787c478bd9Sstevel@tonic-gate { "lcp-max-configure", o_int, &lcp_fsm[0].maxconfreqtransmits,
1797c478bd9Sstevel@tonic-gate "Maximum number of LCP configure-request transmissions" },
1807c478bd9Sstevel@tonic-gate { "lcp-max-failure", o_int, &lcp_fsm[0].maxnakloops,
1817c478bd9Sstevel@tonic-gate "Set limit on number of LCP configure-naks" },
1827c478bd9Sstevel@tonic-gate { "receive-all", o_bool, &lax_recv,
1837c478bd9Sstevel@tonic-gate "Accept all received control characters", 1 },
1847c478bd9Sstevel@tonic-gate #ifdef HAVE_MULTILINK
1857c478bd9Sstevel@tonic-gate { "mrru", o_int, &lcp_wantoptions[0].mrru,
1867c478bd9Sstevel@tonic-gate "Maximum received packet size for multilink bundle",
1877c478bd9Sstevel@tonic-gate OPT_LIMITS, &lcp_wantoptions[0].neg_mrru, PPP_MAXMRU, PPP_MINMRU },
1887c478bd9Sstevel@tonic-gate { "mpshortseq", o_bool, &lcp_wantoptions[0].neg_ssnhf,
1897c478bd9Sstevel@tonic-gate "Use short sequence numbers in multilink headers",
1907c478bd9Sstevel@tonic-gate OPT_A2COPY | 1, &lcp_allowoptions[0].neg_ssnhf },
1917c478bd9Sstevel@tonic-gate { "nompshortseq", o_bool, &lcp_wantoptions[0].neg_ssnhf,
1927c478bd9Sstevel@tonic-gate "Don't use short sequence numbers in multilink headers",
1937c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_ssnhf },
1947c478bd9Sstevel@tonic-gate #endif /* HAVE_MULTILINK */
1957c478bd9Sstevel@tonic-gate { "endpoint", o_special, (void *)setendpoint,
1967c478bd9Sstevel@tonic-gate "Endpoint discriminator for multilink", },
1977c478bd9Sstevel@tonic-gate { "noendpoint", o_bool, &noendpoint,
1987c478bd9Sstevel@tonic-gate "Don't send or accept multilink endpoint discriminator", 1 },
1997c478bd9Sstevel@tonic-gate { "ident", o_string, identstr,
2007c478bd9Sstevel@tonic-gate "LCP Identification string", OPT_STATIC, NULL, sizeof(identstr) },
2017c478bd9Sstevel@tonic-gate { "noident", o_int, &noident,
2027c478bd9Sstevel@tonic-gate "Disable use of LCP Identification", OPT_INC|OPT_NOARG|1 },
2037c478bd9Sstevel@tonic-gate #ifdef NEGOTIATE_FCS
2047c478bd9Sstevel@tonic-gate { "default-fcs", o_bool, &lcp_wantoptions[0].neg_fcs,
2057c478bd9Sstevel@tonic-gate "Disable FCS Alternatives option (use default CRC-16)",
2067c478bd9Sstevel@tonic-gate OPT_A2COPY, &lcp_allowoptions[0].neg_fcs },
2077c478bd9Sstevel@tonic-gate { "allow-fcs", o_special, (void *)setfcsallow,
2087c478bd9Sstevel@tonic-gate "Set allowable FCS types; crc16, crc32, null, or number" },
2097c478bd9Sstevel@tonic-gate { "fcs", o_special, (void *)setfcswant,
2107c478bd9Sstevel@tonic-gate "Set FCS type(s) desired; crc16, crc32, null, or number" },
2117c478bd9Sstevel@tonic-gate #endif
2127c478bd9Sstevel@tonic-gate #ifdef MUX_FRAME
213*48bbca81SDaniel Hoffman /*
2147c478bd9Sstevel@tonic-gate * if pppmux option is turned on, then the parameter to this
215*48bbca81SDaniel Hoffman * is time value in microseconds
2167c478bd9Sstevel@tonic-gate */
2177c478bd9Sstevel@tonic-gate { "pppmux", o_int, &lcp_wantoptions[0].pppmux,
218*48bbca81SDaniel Hoffman "Set PPP Multiplexing option timer", OPT_LLIMIT | OPT_A2COPY,
2197c478bd9Sstevel@tonic-gate &lcp_allowoptions[0].pppmux, 0, 0 },
2207c478bd9Sstevel@tonic-gate #endif
2217c478bd9Sstevel@tonic-gate {NULL}
2227c478bd9Sstevel@tonic-gate };
2237c478bd9Sstevel@tonic-gate
2247c478bd9Sstevel@tonic-gate /* global vars */
2257c478bd9Sstevel@tonic-gate fsm lcp_fsm[NUM_PPP]; /* LCP fsm structure (global)*/
2267c478bd9Sstevel@tonic-gate lcp_options lcp_wantoptions[NUM_PPP]; /* Options that we want to request */
2277c478bd9Sstevel@tonic-gate lcp_options lcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
2287c478bd9Sstevel@tonic-gate lcp_options lcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
2297c478bd9Sstevel@tonic-gate lcp_options lcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
2307c478bd9Sstevel@tonic-gate u_int32_t xmit_accm[NUM_PPP][8]; /* extended transmit ACCM */
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate /*
2337c478bd9Sstevel@tonic-gate * These variables allow a plugin to assert limits on the maximum
2347c478bd9Sstevel@tonic-gate * MRU/MTU values that can be negotiated.
2357c478bd9Sstevel@tonic-gate */
2367c478bd9Sstevel@tonic-gate int absmax_mru = PPP_MAXMRU;
2377c478bd9Sstevel@tonic-gate int absmax_mtu = PPP_MAXMTU;
2387c478bd9Sstevel@tonic-gate
2397c478bd9Sstevel@tonic-gate static int lcp_echos_pending = 0; /* Number of outstanding echo msgs */
2407c478bd9Sstevel@tonic-gate static int lcp_echo_number = 0; /* ID number of next echo frame */
2417c478bd9Sstevel@tonic-gate static int lcp_echo_timer_running = 0; /* set if a timer is running */
242f53eecf5SJames Carlson static bool lcp_echo_accm_test = 0; /* flag if still testing ACCM */
2437c478bd9Sstevel@tonic-gate static int lcp_echo_badreplies = 0; /* number of bad replies from peer */
2447c478bd9Sstevel@tonic-gate /*
2457c478bd9Sstevel@tonic-gate * The maximum number of bad replies we tolerate before bringing the
2467c478bd9Sstevel@tonic-gate * link down.
2477c478bd9Sstevel@tonic-gate */
2487c478bd9Sstevel@tonic-gate #define LCP_ECHO_MAX_BADREPLIES 10
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate /*
2517c478bd9Sstevel@tonic-gate * Callbacks for fsm code. (CI = Configuration Information)
2527c478bd9Sstevel@tonic-gate */
2537c478bd9Sstevel@tonic-gate static void lcp_resetci __P((fsm *)); /* Reset our CI */
2547c478bd9Sstevel@tonic-gate static int lcp_cilen __P((fsm *)); /* Return length of our CI */
2557c478bd9Sstevel@tonic-gate static void lcp_addci __P((fsm *, u_char *, int *)); /* Add our CI to pkt */
2567c478bd9Sstevel@tonic-gate static int lcp_ackci __P((fsm *, u_char *, int)); /* Peer ack'd our CI */
2577c478bd9Sstevel@tonic-gate static int lcp_nakci __P((fsm *, u_char *, int)); /* Peer nak'd our CI */
2587c478bd9Sstevel@tonic-gate static int lcp_rejci __P((fsm *, u_char *, int)); /* Peer rej'd our CI */
2597c478bd9Sstevel@tonic-gate static int lcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv peer CI */
2607c478bd9Sstevel@tonic-gate static void lcp_up __P((fsm *)); /* We're UP */
2617c478bd9Sstevel@tonic-gate static void lcp_down __P((fsm *)); /* We're DOWN */
2627c478bd9Sstevel@tonic-gate static void lcp_starting __P((fsm *)); /* We need lower layer up */
2637c478bd9Sstevel@tonic-gate static void lcp_finished __P((fsm *)); /* We need lower layer down */
2647c478bd9Sstevel@tonic-gate static int lcp_extcode __P((fsm *, int, int, u_char *, int));
2657c478bd9Sstevel@tonic-gate static void lcp_rprotrej __P((fsm *, u_char *, int));
2667c478bd9Sstevel@tonic-gate static int lcp_coderej __P((fsm *f, int code, int id, u_char *inp, int len));
2677c478bd9Sstevel@tonic-gate
2687c478bd9Sstevel@tonic-gate /*
2697c478bd9Sstevel@tonic-gate * routines to send LCP echos to peer
2707c478bd9Sstevel@tonic-gate */
2717c478bd9Sstevel@tonic-gate
2727c478bd9Sstevel@tonic-gate static void lcp_echo_lowerup __P((int));
2737c478bd9Sstevel@tonic-gate static void lcp_echo_lowerdown __P((int));
2747c478bd9Sstevel@tonic-gate static void LcpEchoTimeout __P((void *));
2757c478bd9Sstevel@tonic-gate static int lcp_received_echo_reply __P((fsm *, int, u_char *, int));
2767c478bd9Sstevel@tonic-gate static void LcpSendEchoRequest __P((fsm *));
2777c478bd9Sstevel@tonic-gate static void LcpLinkFailure __P((fsm *));
2787c478bd9Sstevel@tonic-gate static void LcpEchoCheck __P((fsm *));
2797c478bd9Sstevel@tonic-gate
2807c478bd9Sstevel@tonic-gate /*
2817c478bd9Sstevel@tonic-gate * routines to send and receive additional LCP packets described in
2827c478bd9Sstevel@tonic-gate * section 1 of rfc1570.
2837c478bd9Sstevel@tonic-gate */
2847c478bd9Sstevel@tonic-gate static void LcpSendIdentification __P((fsm *));
2857c478bd9Sstevel@tonic-gate static void lcp_received_identification __P((fsm *, int, u_char *, int));
2867c478bd9Sstevel@tonic-gate static void LcpSendTimeRemaining __P((fsm *, u_int32_t));
2877c478bd9Sstevel@tonic-gate static void lcp_timeremaining __P((void *));
2887c478bd9Sstevel@tonic-gate static void lcp_received_timeremain __P((fsm *, int, u_char *, int));
2897c478bd9Sstevel@tonic-gate
2907c478bd9Sstevel@tonic-gate
2917c478bd9Sstevel@tonic-gate static fsm_callbacks lcp_callbacks = { /* LCP callback routines */
2927c478bd9Sstevel@tonic-gate lcp_resetci, /* Reset our Configuration Information */
2937c478bd9Sstevel@tonic-gate lcp_cilen, /* Length of our Configuration Information */
2947c478bd9Sstevel@tonic-gate lcp_addci, /* Add our Configuration Information */
2957c478bd9Sstevel@tonic-gate lcp_ackci, /* ACK our Configuration Information */
2967c478bd9Sstevel@tonic-gate lcp_nakci, /* NAK our Configuration Information */
2977c478bd9Sstevel@tonic-gate lcp_rejci, /* Reject our Configuration Information */
2987c478bd9Sstevel@tonic-gate lcp_reqci, /* Request peer's Configuration Information */
2997c478bd9Sstevel@tonic-gate lcp_up, /* Called when fsm reaches OPENED state */
3007c478bd9Sstevel@tonic-gate lcp_down, /* Called when fsm leaves OPENED state */
3017c478bd9Sstevel@tonic-gate lcp_starting, /* Called when we want the lower layer up */
3027c478bd9Sstevel@tonic-gate lcp_finished, /* Called when we want the lower layer down */
3037c478bd9Sstevel@tonic-gate NULL, /* Retransmission is necessary */
3047c478bd9Sstevel@tonic-gate lcp_extcode, /* Called to handle LCP-specific codes */
3057c478bd9Sstevel@tonic-gate "LCP", /* String name of protocol */
3067c478bd9Sstevel@tonic-gate lcp_coderej, /* Peer rejected a code number */
3077c478bd9Sstevel@tonic-gate };
3087c478bd9Sstevel@tonic-gate
3097c478bd9Sstevel@tonic-gate /*
3107c478bd9Sstevel@tonic-gate * Protocol entry points.
3117c478bd9Sstevel@tonic-gate * Some of these are called directly.
3127c478bd9Sstevel@tonic-gate */
3137c478bd9Sstevel@tonic-gate
3147c478bd9Sstevel@tonic-gate static void lcp_init __P((int));
3157c478bd9Sstevel@tonic-gate static void lcp_input __P((int, u_char *, int));
3167c478bd9Sstevel@tonic-gate static void lcp_protrej __P((int));
3177c478bd9Sstevel@tonic-gate static int lcp_printpkt __P((u_char *, int,
3187c478bd9Sstevel@tonic-gate void (*) __P((void *, const char *, ...)), void *));
3197c478bd9Sstevel@tonic-gate
3207c478bd9Sstevel@tonic-gate
3217c478bd9Sstevel@tonic-gate struct protent lcp_protent = {
3227c478bd9Sstevel@tonic-gate PPP_LCP, /* Protocol Number for LCP */
3237c478bd9Sstevel@tonic-gate lcp_init, /* Initializes LCP */
3247c478bd9Sstevel@tonic-gate lcp_input, /* Processes a received LCP packet */
3257c478bd9Sstevel@tonic-gate lcp_protrej, /* Process a received Protocol-reject */
3267c478bd9Sstevel@tonic-gate lcp_lowerup, /* Called after the serial device has been set up */
3277c478bd9Sstevel@tonic-gate lcp_lowerdown, /* Called when the link is brought down */
3287c478bd9Sstevel@tonic-gate lcp_open, /* Called after lcp_lowerup when bringing up the link */
3297c478bd9Sstevel@tonic-gate lcp_close, /* Called when the link goes down */
3307c478bd9Sstevel@tonic-gate lcp_printpkt, /* Print a packet in human readable form */
3317c478bd9Sstevel@tonic-gate NULL, /* Process a received data packet */
3327c478bd9Sstevel@tonic-gate 1, /* LCP is enabled by default */
3337c478bd9Sstevel@tonic-gate "LCP", /* Name of the protocol */
3347c478bd9Sstevel@tonic-gate NULL, /* Name of the corresponding data protocol */
3357c478bd9Sstevel@tonic-gate lcp_option_list, /* List of LCP command-line options */
3367c478bd9Sstevel@tonic-gate NULL, /* Assigns default values for options */
3377c478bd9Sstevel@tonic-gate NULL, /* Configures demand-dial */
3387c478bd9Sstevel@tonic-gate NULL /* Bring up the link for this packet? */
3397c478bd9Sstevel@tonic-gate };
3407c478bd9Sstevel@tonic-gate
3417c478bd9Sstevel@tonic-gate int lcp_loopbackfail = DEFLOOPBACKFAIL;
3427c478bd9Sstevel@tonic-gate
3437c478bd9Sstevel@tonic-gate /*
3447c478bd9Sstevel@tonic-gate * Length of each type of configuration option (in octets)
3457c478bd9Sstevel@tonic-gate */
3467c478bd9Sstevel@tonic-gate #define CILEN_VOID 2
3477c478bd9Sstevel@tonic-gate #define CILEN_CHAR 3
3487c478bd9Sstevel@tonic-gate #define CILEN_SHORT 4 /* CILEN_VOID + 2 */
3497c478bd9Sstevel@tonic-gate #define CILEN_CHAP 5 /* CILEN_VOID + 2 + 1 */
3507c478bd9Sstevel@tonic-gate #define CILEN_LONG 6 /* CILEN_VOID + 4 */
3517c478bd9Sstevel@tonic-gate #define CILEN_LQR 8 /* CILEN_VOID + 2 + 4 */
3527c478bd9Sstevel@tonic-gate #define CILEN_CBCP 3
3537c478bd9Sstevel@tonic-gate
3547c478bd9Sstevel@tonic-gate
3557c478bd9Sstevel@tonic-gate /*
3567c478bd9Sstevel@tonic-gate * setescape - add chars to the set we escape on transmission.
3577c478bd9Sstevel@tonic-gate */
3587c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3597c478bd9Sstevel@tonic-gate static int
setescape(argv,opt)3607c478bd9Sstevel@tonic-gate setescape(argv, opt)
3617c478bd9Sstevel@tonic-gate char **argv;
3627c478bd9Sstevel@tonic-gate option_t *opt;
3637c478bd9Sstevel@tonic-gate {
3647c478bd9Sstevel@tonic-gate int n, ret;
3657c478bd9Sstevel@tonic-gate char *p, *endp;
3667c478bd9Sstevel@tonic-gate
3677c478bd9Sstevel@tonic-gate p = *argv;
3687c478bd9Sstevel@tonic-gate ret = 1;
3697c478bd9Sstevel@tonic-gate while (*p != '\0') {
3707c478bd9Sstevel@tonic-gate n = strtol(p, &endp, 16);
3717c478bd9Sstevel@tonic-gate if (p == endp) {
3727c478bd9Sstevel@tonic-gate option_error("escape parameter contains invalid hex number '%s'",
3737c478bd9Sstevel@tonic-gate p);
3747c478bd9Sstevel@tonic-gate return 0;
3757c478bd9Sstevel@tonic-gate }
3767c478bd9Sstevel@tonic-gate p = endp;
3777c478bd9Sstevel@tonic-gate if (n < 0 || n == 0x5E || n > 0xFF) {
3787c478bd9Sstevel@tonic-gate option_error("can't escape character 0x%x", n);
3797c478bd9Sstevel@tonic-gate ret = 0;
3807c478bd9Sstevel@tonic-gate } else
3817c478bd9Sstevel@tonic-gate xmit_accm[0][n >> 5] |= 1 << (n & 0x1F);
3827c478bd9Sstevel@tonic-gate while (*p == ',' || *p == ' ')
3837c478bd9Sstevel@tonic-gate ++p;
3847c478bd9Sstevel@tonic-gate }
3857c478bd9Sstevel@tonic-gate return ret;
3867c478bd9Sstevel@tonic-gate }
3877c478bd9Sstevel@tonic-gate
3887c478bd9Sstevel@tonic-gate /*
3897c478bd9Sstevel@tonic-gate * setasyncmap - set async map negotiated
3907c478bd9Sstevel@tonic-gate */
3917c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3927c478bd9Sstevel@tonic-gate static int
setasyncmap(argv,opt)3937c478bd9Sstevel@tonic-gate setasyncmap(argv, opt)
3947c478bd9Sstevel@tonic-gate char **argv;
3957c478bd9Sstevel@tonic-gate option_t *opt;
3967c478bd9Sstevel@tonic-gate {
3977c478bd9Sstevel@tonic-gate u_int32_t val;
3987c478bd9Sstevel@tonic-gate char *endp;
3997c478bd9Sstevel@tonic-gate
4007c478bd9Sstevel@tonic-gate val = strtoul(*argv, &endp, 16);
4017c478bd9Sstevel@tonic-gate if (*argv == endp) {
4027c478bd9Sstevel@tonic-gate option_error("invalid numeric parameter '%s' for 'asyncmap' option",
4037c478bd9Sstevel@tonic-gate *argv);
4047c478bd9Sstevel@tonic-gate return 0;
4057c478bd9Sstevel@tonic-gate }
4067c478bd9Sstevel@tonic-gate lcp_wantoptions[0].asyncmap |= val;
4077c478bd9Sstevel@tonic-gate lcp_wantoptions[0].neg_asyncmap = (~lcp_wantoptions[0].asyncmap != 0);
4087c478bd9Sstevel@tonic-gate do_msft_workaround = 0;
4097c478bd9Sstevel@tonic-gate return 1;
4107c478bd9Sstevel@tonic-gate }
4117c478bd9Sstevel@tonic-gate
4127c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4137c478bd9Sstevel@tonic-gate static int
setendpoint(argv,opt)4147c478bd9Sstevel@tonic-gate setendpoint(argv, opt)
4157c478bd9Sstevel@tonic-gate char **argv;
4167c478bd9Sstevel@tonic-gate option_t *opt;
4177c478bd9Sstevel@tonic-gate {
4187c478bd9Sstevel@tonic-gate if (str_to_epdisc(&lcp_wantoptions[0].endpoint, *argv)) {
4197c478bd9Sstevel@tonic-gate lcp_wantoptions[0].neg_endpoint = 1;
4207c478bd9Sstevel@tonic-gate return 1;
4217c478bd9Sstevel@tonic-gate }
4227c478bd9Sstevel@tonic-gate option_error("Can't parse '%s' as an endpoint discriminator", *argv);
4237c478bd9Sstevel@tonic-gate return 0;
4247c478bd9Sstevel@tonic-gate }
4257c478bd9Sstevel@tonic-gate
4267c478bd9Sstevel@tonic-gate #ifdef NEGOTIATE_FCS
4277c478bd9Sstevel@tonic-gate static int
str_to_fcstype(opt,arg)4287c478bd9Sstevel@tonic-gate str_to_fcstype(opt,arg)
4297c478bd9Sstevel@tonic-gate lcp_options *opt;
4307c478bd9Sstevel@tonic-gate char *arg;
4317c478bd9Sstevel@tonic-gate {
4327c478bd9Sstevel@tonic-gate char **cpp, *cp;
4337c478bd9Sstevel@tonic-gate int val, len;
4347c478bd9Sstevel@tonic-gate
4357c478bd9Sstevel@tonic-gate if (*arg != '\0') {
4367c478bd9Sstevel@tonic-gate val = 0;
4377c478bd9Sstevel@tonic-gate while (*arg != '\0') {
4387c478bd9Sstevel@tonic-gate len = 0;
4397c478bd9Sstevel@tonic-gate if (isdigit(*arg)) {
4407c478bd9Sstevel@tonic-gate len = strtol(arg, &cp, 0);
4417c478bd9Sstevel@tonic-gate if (len < 0 || len > 255 || arg == cp ||
4427c478bd9Sstevel@tonic-gate (*cp != '\0' && *cp != ','))
4437c478bd9Sstevel@tonic-gate break;
4447c478bd9Sstevel@tonic-gate val |= len;
4457c478bd9Sstevel@tonic-gate len = cp - arg;
4467c478bd9Sstevel@tonic-gate } else {
4477c478bd9Sstevel@tonic-gate for (cpp = fcsalt_strings; *cpp != NULL; cpp++) {
4487c478bd9Sstevel@tonic-gate len = strlen(*cpp);
4497c478bd9Sstevel@tonic-gate if (strncasecmp(arg, *cpp, len) == 0 &&
4507c478bd9Sstevel@tonic-gate (arg[len] == '\0' || arg[len] == ','))
4517c478bd9Sstevel@tonic-gate break;
4527c478bd9Sstevel@tonic-gate }
4537c478bd9Sstevel@tonic-gate if (*cpp == NULL)
4547c478bd9Sstevel@tonic-gate break;
4557c478bd9Sstevel@tonic-gate val |= 1<<(cpp-fcsalt_strings);
4567c478bd9Sstevel@tonic-gate }
4577c478bd9Sstevel@tonic-gate if (arg[len] == '\0') {
4587c478bd9Sstevel@tonic-gate opt->neg_fcs = 1;
4597c478bd9Sstevel@tonic-gate opt->fcs_type = val;
4607c478bd9Sstevel@tonic-gate return (1);
4617c478bd9Sstevel@tonic-gate }
4627c478bd9Sstevel@tonic-gate arg += len+1;
4637c478bd9Sstevel@tonic-gate }
4647c478bd9Sstevel@tonic-gate }
4657c478bd9Sstevel@tonic-gate option_error("Can't parse '%s' as an FCS type", arg);
4667c478bd9Sstevel@tonic-gate return (0);
4677c478bd9Sstevel@tonic-gate }
4687c478bd9Sstevel@tonic-gate
4697c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4707c478bd9Sstevel@tonic-gate static int
setfcsallow(argv,opt)4717c478bd9Sstevel@tonic-gate setfcsallow(argv, opt)
4727c478bd9Sstevel@tonic-gate char **argv;
4737c478bd9Sstevel@tonic-gate option_t *opt;
4747c478bd9Sstevel@tonic-gate {
4757c478bd9Sstevel@tonic-gate return str_to_fcstype(&lcp_allowoptions[0], *argv);
4767c478bd9Sstevel@tonic-gate }
4777c478bd9Sstevel@tonic-gate
4787c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4797c478bd9Sstevel@tonic-gate static int
setfcswant(argv,opt)4807c478bd9Sstevel@tonic-gate setfcswant(argv, opt)
4817c478bd9Sstevel@tonic-gate char **argv;
4827c478bd9Sstevel@tonic-gate option_t *opt;
4837c478bd9Sstevel@tonic-gate {
4847c478bd9Sstevel@tonic-gate return str_to_fcstype(&lcp_wantoptions[0], *argv);
4857c478bd9Sstevel@tonic-gate }
4867c478bd9Sstevel@tonic-gate #endif
4877c478bd9Sstevel@tonic-gate
4887c478bd9Sstevel@tonic-gate /*
4897c478bd9Sstevel@tonic-gate * lcp_init - Initialize LCP.
4907c478bd9Sstevel@tonic-gate */
4917c478bd9Sstevel@tonic-gate static void
lcp_init(unit)4927c478bd9Sstevel@tonic-gate lcp_init(unit)
4937c478bd9Sstevel@tonic-gate int unit;
4947c478bd9Sstevel@tonic-gate {
4957c478bd9Sstevel@tonic-gate fsm *f = &lcp_fsm[unit];
4967c478bd9Sstevel@tonic-gate lcp_options *wo = &lcp_wantoptions[unit];
4977c478bd9Sstevel@tonic-gate lcp_options *ao = &lcp_allowoptions[unit];
4987c478bd9Sstevel@tonic-gate
4997c478bd9Sstevel@tonic-gate f->unit = unit;
5007c478bd9Sstevel@tonic-gate f->protocol = PPP_LCP;
5017c478bd9Sstevel@tonic-gate f->callbacks = &lcp_callbacks;
5027c478bd9Sstevel@tonic-gate
5037c478bd9Sstevel@tonic-gate fsm_init(f);
5047c478bd9Sstevel@tonic-gate
5057c478bd9Sstevel@tonic-gate BZERO(wo, sizeof(*wo));
5067c478bd9Sstevel@tonic-gate wo->neg_mru = 1;
5077c478bd9Sstevel@tonic-gate wo->mru = PPP_MRU;
5087c478bd9Sstevel@tonic-gate wo->neg_asyncmap = 1;
5097c478bd9Sstevel@tonic-gate wo->chap_mdtype = CHAP_DIGEST_MD5;
5107c478bd9Sstevel@tonic-gate wo->neg_magicnumber = 1;
5117c478bd9Sstevel@tonic-gate wo->neg_pcompression = 1;
5127c478bd9Sstevel@tonic-gate wo->neg_accompression = 1;
5137c478bd9Sstevel@tonic-gate
5147c478bd9Sstevel@tonic-gate /*
5157c478bd9Sstevel@tonic-gate * Leave allowed MRU (MTU) at zero; configuration option sets it
5167c478bd9Sstevel@tonic-gate * non-zero if we should nak for something else.
5177c478bd9Sstevel@tonic-gate */
5187c478bd9Sstevel@tonic-gate BZERO(ao, sizeof(*ao));
5197c478bd9Sstevel@tonic-gate ao->neg_mru = 1;
5207c478bd9Sstevel@tonic-gate ao->neg_asyncmap = 1;
5217c478bd9Sstevel@tonic-gate ao->neg_chap = 1;
5227c478bd9Sstevel@tonic-gate #if defined(CHAPMS) || defined(CHAPMSV2)
5237c478bd9Sstevel@tonic-gate #ifdef SOL2
5247c478bd9Sstevel@tonic-gate /* Check if DES wasn't exported */
5257c478bd9Sstevel@tonic-gate errno = 0;
5267c478bd9Sstevel@tonic-gate setkey("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
5277c478bd9Sstevel@tonic-gate "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
5287c478bd9Sstevel@tonic-gate if (errno == 0)
5297c478bd9Sstevel@tonic-gate #endif
5307c478bd9Sstevel@tonic-gate {
5317c478bd9Sstevel@tonic-gate #ifdef CHAPMS
5327c478bd9Sstevel@tonic-gate ao->neg_mschap = 1;
5337c478bd9Sstevel@tonic-gate #endif
5347c478bd9Sstevel@tonic-gate #ifdef CHAPMSV2
5357c478bd9Sstevel@tonic-gate ao->neg_mschapv2 = 1;
5367c478bd9Sstevel@tonic-gate #endif
5377c478bd9Sstevel@tonic-gate }
5387c478bd9Sstevel@tonic-gate #endif
5397c478bd9Sstevel@tonic-gate ao->chap_mdtype = CHAP_DIGEST_MD5;
5407c478bd9Sstevel@tonic-gate ao->neg_upap = 1;
5417c478bd9Sstevel@tonic-gate ao->neg_magicnumber = 1;
5427c478bd9Sstevel@tonic-gate ao->neg_pcompression = 1;
5437c478bd9Sstevel@tonic-gate ao->neg_accompression = 1;
5447c478bd9Sstevel@tonic-gate #ifdef CBCP_SUPPORT
5457c478bd9Sstevel@tonic-gate ao->neg_cbcp = 1;
5467c478bd9Sstevel@tonic-gate #endif
5477c478bd9Sstevel@tonic-gate ao->neg_endpoint = 1;
5487c478bd9Sstevel@tonic-gate #ifdef NEGOTIATE_FCS
5497c478bd9Sstevel@tonic-gate ao->neg_fcs = 1;
5507c478bd9Sstevel@tonic-gate ao->fcs_type = FCSALT_NULL|FCSALT_16|FCSALT_32;
5517c478bd9Sstevel@tonic-gate #endif
5527c478bd9Sstevel@tonic-gate
5537c478bd9Sstevel@tonic-gate BZERO(xmit_accm[unit], sizeof(xmit_accm[0]));
5547c478bd9Sstevel@tonic-gate xmit_accm[unit][3] = 0x60000000;
5557c478bd9Sstevel@tonic-gate }
5567c478bd9Sstevel@tonic-gate
5577c478bd9Sstevel@tonic-gate
5587c478bd9Sstevel@tonic-gate /*
5597c478bd9Sstevel@tonic-gate * lcp_open - LCP is allowed to come up.
5607c478bd9Sstevel@tonic-gate */
5617c478bd9Sstevel@tonic-gate void
lcp_open(unit)5627c478bd9Sstevel@tonic-gate lcp_open(unit)
5637c478bd9Sstevel@tonic-gate int unit;
5647c478bd9Sstevel@tonic-gate {
5657c478bd9Sstevel@tonic-gate fsm *f = &lcp_fsm[unit];
5667c478bd9Sstevel@tonic-gate lcp_options *wo = &lcp_wantoptions[unit];
5677c478bd9Sstevel@tonic-gate
5687c478bd9Sstevel@tonic-gate f->flags = 0;
5697c478bd9Sstevel@tonic-gate if (wo->passive)
5707c478bd9Sstevel@tonic-gate f->flags |= OPT_PASSIVE;
5717c478bd9Sstevel@tonic-gate if (wo->silent)
5727c478bd9Sstevel@tonic-gate f->flags |= OPT_SILENT;
5737c478bd9Sstevel@tonic-gate fsm_open(f);
5747c478bd9Sstevel@tonic-gate }
5757c478bd9Sstevel@tonic-gate
5767c478bd9Sstevel@tonic-gate
5777c478bd9Sstevel@tonic-gate /*
5787c478bd9Sstevel@tonic-gate * lcp_close - Take LCP down.
5797c478bd9Sstevel@tonic-gate */
5807c478bd9Sstevel@tonic-gate void
lcp_close(unit,reason)5817c478bd9Sstevel@tonic-gate lcp_close(unit, reason)
5827c478bd9Sstevel@tonic-gate int unit;
5837c478bd9Sstevel@tonic-gate char *reason;
5847c478bd9Sstevel@tonic-gate {
5857c478bd9Sstevel@tonic-gate fsm *f = &lcp_fsm[unit];
5867c478bd9Sstevel@tonic-gate
5877c478bd9Sstevel@tonic-gate if (phase != PHASE_DEAD)
5887c478bd9Sstevel@tonic-gate new_phase(PHASE_TERMINATE);
5897c478bd9Sstevel@tonic-gate if (f->state == STOPPED && (f->flags & (OPT_PASSIVE|OPT_SILENT))) {
5907c478bd9Sstevel@tonic-gate /*
5917c478bd9Sstevel@tonic-gate * This action is not strictly according to the FSM in RFC1548,
5927c478bd9Sstevel@tonic-gate * but it does mean that the program terminates if you do a
5937c478bd9Sstevel@tonic-gate * lcp_close() in passive/silent mode when a connection hasn't
5947c478bd9Sstevel@tonic-gate * been established.
5957c478bd9Sstevel@tonic-gate */
5967c478bd9Sstevel@tonic-gate f->state = CLOSED;
5977c478bd9Sstevel@tonic-gate lcp_finished(f);
5987c478bd9Sstevel@tonic-gate
5997c478bd9Sstevel@tonic-gate } else
6007c478bd9Sstevel@tonic-gate fsm_close(&lcp_fsm[unit], reason);
6017c478bd9Sstevel@tonic-gate }
6027c478bd9Sstevel@tonic-gate
6037c478bd9Sstevel@tonic-gate
6047c478bd9Sstevel@tonic-gate /*
6057c478bd9Sstevel@tonic-gate * lcp_lowerup - The lower layer is up.
6067c478bd9Sstevel@tonic-gate */
6077c478bd9Sstevel@tonic-gate void
lcp_lowerup(unit)6087c478bd9Sstevel@tonic-gate lcp_lowerup(unit)
6097c478bd9Sstevel@tonic-gate int unit;
6107c478bd9Sstevel@tonic-gate {
6117c478bd9Sstevel@tonic-gate lcp_options *wo = &lcp_wantoptions[unit];
6127c478bd9Sstevel@tonic-gate int mru, mtu;
6137c478bd9Sstevel@tonic-gate
6147c478bd9Sstevel@tonic-gate mru = PPP_MRU > absmax_mru ? absmax_mru : PPP_MRU;
6157c478bd9Sstevel@tonic-gate mtu = PPP_MTU > absmax_mtu ? absmax_mtu : PPP_MTU;
6167c478bd9Sstevel@tonic-gate
6177c478bd9Sstevel@tonic-gate /*
6187c478bd9Sstevel@tonic-gate * Don't use A/C or protocol compression on transmission,
6197c478bd9Sstevel@tonic-gate * but accept A/C and protocol compressed packets
6207c478bd9Sstevel@tonic-gate * if we are going to ask for A/C and protocol compression.
6217c478bd9Sstevel@tonic-gate */
6227c478bd9Sstevel@tonic-gate ppp_set_xaccm(unit, xmit_accm[unit]);
6237c478bd9Sstevel@tonic-gate ppp_send_config(unit, mtu, 0xffffffff, 0, 0);
6247c478bd9Sstevel@tonic-gate ppp_recv_config(unit, mru, (lax_recv? 0: 0xffffffff),
6257c478bd9Sstevel@tonic-gate wo->neg_pcompression, wo->neg_accompression);
6267c478bd9Sstevel@tonic-gate #ifdef NEGOTIATE_FCS
6277c478bd9Sstevel@tonic-gate ppp_send_fcs(unit, FCSALT_16);
6287c478bd9Sstevel@tonic-gate ppp_recv_fcs(unit, FCSALT_16);
6297c478bd9Sstevel@tonic-gate #endif
6307c478bd9Sstevel@tonic-gate
6317c478bd9Sstevel@tonic-gate fsm_setpeermru(unit, mtu);
6327c478bd9Sstevel@tonic-gate lcp_allowoptions[unit].asyncmap = xmit_accm[unit][0];
6337c478bd9Sstevel@tonic-gate
6347c478bd9Sstevel@tonic-gate fsm_lowerup(&lcp_fsm[unit]);
6357c478bd9Sstevel@tonic-gate }
6367c478bd9Sstevel@tonic-gate
6377c478bd9Sstevel@tonic-gate
6387c478bd9Sstevel@tonic-gate /*
6397c478bd9Sstevel@tonic-gate * lcp_lowerdown - The lower layer is down.
6407c478bd9Sstevel@tonic-gate */
6417c478bd9Sstevel@tonic-gate void
lcp_lowerdown(unit)6427c478bd9Sstevel@tonic-gate lcp_lowerdown(unit)
6437c478bd9Sstevel@tonic-gate int unit;
6447c478bd9Sstevel@tonic-gate {
6457c478bd9Sstevel@tonic-gate fsm_lowerdown(&lcp_fsm[unit]);
6467c478bd9Sstevel@tonic-gate }
6477c478bd9Sstevel@tonic-gate
6487c478bd9Sstevel@tonic-gate
6497c478bd9Sstevel@tonic-gate /*
6507c478bd9Sstevel@tonic-gate * lcp_input - Input LCP packet.
6517c478bd9Sstevel@tonic-gate */
6527c478bd9Sstevel@tonic-gate static void
lcp_input(unit,p,len)6537c478bd9Sstevel@tonic-gate lcp_input(unit, p, len)
6547c478bd9Sstevel@tonic-gate int unit;
6557c478bd9Sstevel@tonic-gate u_char *p;
6567c478bd9Sstevel@tonic-gate int len;
6577c478bd9Sstevel@tonic-gate {
6587c478bd9Sstevel@tonic-gate fsm *f = &lcp_fsm[unit];
6597c478bd9Sstevel@tonic-gate
6607c478bd9Sstevel@tonic-gate fsm_input(f, p, len);
6617c478bd9Sstevel@tonic-gate }
6627c478bd9Sstevel@tonic-gate
6637c478bd9Sstevel@tonic-gate
6647c478bd9Sstevel@tonic-gate /*
6657c478bd9Sstevel@tonic-gate * lcp_extcode - Handle a LCP-specific code.
6667c478bd9Sstevel@tonic-gate */
6677c478bd9Sstevel@tonic-gate static int
lcp_extcode(f,code,id,inp,len)6687c478bd9Sstevel@tonic-gate lcp_extcode(f, code, id, inp, len)
6697c478bd9Sstevel@tonic-gate fsm *f;
6707c478bd9Sstevel@tonic-gate int code, id;
6717c478bd9Sstevel@tonic-gate u_char *inp;
6727c478bd9Sstevel@tonic-gate int len;
6737c478bd9Sstevel@tonic-gate {
6747c478bd9Sstevel@tonic-gate u_char *magp;
6757c478bd9Sstevel@tonic-gate
6767c478bd9Sstevel@tonic-gate switch( code ){
6777c478bd9Sstevel@tonic-gate case CODE_PROTREJ:
6787c478bd9Sstevel@tonic-gate lcp_rprotrej(f, inp, len);
6797c478bd9Sstevel@tonic-gate break;
680*48bbca81SDaniel Hoffman
6817c478bd9Sstevel@tonic-gate case CODE_ECHOREQ:
6827c478bd9Sstevel@tonic-gate if (f->state != OPENED)
6837c478bd9Sstevel@tonic-gate break;
6847c478bd9Sstevel@tonic-gate magp = inp;
6857c478bd9Sstevel@tonic-gate PUTLONG(lcp_gotoptions[f->unit].magicnumber, magp);
6867c478bd9Sstevel@tonic-gate fsm_sdata(f, CODE_ECHOREP, id, inp, len);
6877c478bd9Sstevel@tonic-gate break;
688*48bbca81SDaniel Hoffman
6897c478bd9Sstevel@tonic-gate case CODE_ECHOREP:
6907c478bd9Sstevel@tonic-gate if (!lcp_received_echo_reply(f, id, inp, len)) {
6917c478bd9Sstevel@tonic-gate lcp_echo_badreplies++;
6927c478bd9Sstevel@tonic-gate if (lcp_echo_badreplies > LCP_ECHO_MAX_BADREPLIES) {
6937c478bd9Sstevel@tonic-gate LcpLinkFailure(f);
6947c478bd9Sstevel@tonic-gate lcp_echos_pending = 0;
6957c478bd9Sstevel@tonic-gate lcp_echo_badreplies = 0;
6967c478bd9Sstevel@tonic-gate }
6977c478bd9Sstevel@tonic-gate }
6987c478bd9Sstevel@tonic-gate break;
6997c478bd9Sstevel@tonic-gate
7007c478bd9Sstevel@tonic-gate case CODE_DISCREQ:
7017c478bd9Sstevel@tonic-gate break;
7027c478bd9Sstevel@tonic-gate
7037c478bd9Sstevel@tonic-gate case CODE_IDENT:
7047c478bd9Sstevel@tonic-gate /* More than one 'noident' tells us to reject the code number. */
7057c478bd9Sstevel@tonic-gate if (noident > 1)
7067c478bd9Sstevel@tonic-gate return 0;
7077c478bd9Sstevel@tonic-gate lcp_received_identification(f, id, inp, len);
7087c478bd9Sstevel@tonic-gate break;
7097c478bd9Sstevel@tonic-gate
7107c478bd9Sstevel@tonic-gate case CODE_TIMEREMAIN:
7117c478bd9Sstevel@tonic-gate lcp_received_timeremain(f, id, inp, len);
7127c478bd9Sstevel@tonic-gate break;
7137c478bd9Sstevel@tonic-gate
7147c478bd9Sstevel@tonic-gate default:
7157c478bd9Sstevel@tonic-gate return 0;
7167c478bd9Sstevel@tonic-gate }
7177c478bd9Sstevel@tonic-gate return 1;
7187c478bd9Sstevel@tonic-gate }
7197c478bd9Sstevel@tonic-gate
7207c478bd9Sstevel@tonic-gate /*
7217c478bd9Sstevel@tonic-gate * lcp_rprotrej - Receive an Protocol-Reject.
7227c478bd9Sstevel@tonic-gate *
7237c478bd9Sstevel@tonic-gate * Figure out which protocol is rejected and inform it.
7247c478bd9Sstevel@tonic-gate */
7257c478bd9Sstevel@tonic-gate static void
lcp_rprotrej(f,inp,len)7267c478bd9Sstevel@tonic-gate lcp_rprotrej(f, inp, len)
7277c478bd9Sstevel@tonic-gate fsm *f;
7287c478bd9Sstevel@tonic-gate u_char *inp;
7297c478bd9Sstevel@tonic-gate int len;
7307c478bd9Sstevel@tonic-gate {
7317c478bd9Sstevel@tonic-gate int i;
7327c478bd9Sstevel@tonic-gate struct protent *protp;
7337c478bd9Sstevel@tonic-gate u_short prot;
7347c478bd9Sstevel@tonic-gate
7357c478bd9Sstevel@tonic-gate if (len < 2) {
7367c478bd9Sstevel@tonic-gate dbglog("lcp_rprotrej: Rcvd short Protocol-Reject packet!");
7377c478bd9Sstevel@tonic-gate return;
7387c478bd9Sstevel@tonic-gate }
7397c478bd9Sstevel@tonic-gate
7407c478bd9Sstevel@tonic-gate GETSHORT(prot, inp);
7417c478bd9Sstevel@tonic-gate
7427c478bd9Sstevel@tonic-gate /*
7437c478bd9Sstevel@tonic-gate * Protocol-Reject packets received in any state other than the LCP
7447c478bd9Sstevel@tonic-gate * OPENED state SHOULD be silently discarded.
7457c478bd9Sstevel@tonic-gate */
7467c478bd9Sstevel@tonic-gate if( f->state != OPENED ){
7477c478bd9Sstevel@tonic-gate dbglog("Protocol-Reject discarded: LCP in state %s",
7487c478bd9Sstevel@tonic-gate fsm_state(f->state));
7497c478bd9Sstevel@tonic-gate return;
7507c478bd9Sstevel@tonic-gate }
7517c478bd9Sstevel@tonic-gate
7527c478bd9Sstevel@tonic-gate /*
7537c478bd9Sstevel@tonic-gate * Upcall the proper Protocol-Reject routine.
7547c478bd9Sstevel@tonic-gate */
7557c478bd9Sstevel@tonic-gate for (i = 0; (protp = protocols[i]) != NULL; ++i)
7567c478bd9Sstevel@tonic-gate if (protp->protocol == prot && protp->enabled_flag) {
7577c478bd9Sstevel@tonic-gate (*protp->protrej)(f->unit);
7587c478bd9Sstevel@tonic-gate return;
7597c478bd9Sstevel@tonic-gate }
7607c478bd9Sstevel@tonic-gate
7617c478bd9Sstevel@tonic-gate warn("Protocol-Reject for unsupported protocol 0x%x", prot);
7627c478bd9Sstevel@tonic-gate }
7637c478bd9Sstevel@tonic-gate
7647c478bd9Sstevel@tonic-gate
7657c478bd9Sstevel@tonic-gate /*
7667c478bd9Sstevel@tonic-gate * lcp_protrej - A Protocol-Reject was received.
7677c478bd9Sstevel@tonic-gate */
7687c478bd9Sstevel@tonic-gate /*ARGSUSED*/
7697c478bd9Sstevel@tonic-gate static void
lcp_protrej(unit)7707c478bd9Sstevel@tonic-gate lcp_protrej(unit)
7717c478bd9Sstevel@tonic-gate int unit;
7727c478bd9Sstevel@tonic-gate {
7737c478bd9Sstevel@tonic-gate /*
7747c478bd9Sstevel@tonic-gate * Can't reject LCP!
7757c478bd9Sstevel@tonic-gate */
7767c478bd9Sstevel@tonic-gate error("Received Protocol-Reject for LCP!");
7777c478bd9Sstevel@tonic-gate }
7787c478bd9Sstevel@tonic-gate
7797c478bd9Sstevel@tonic-gate /*
7807c478bd9Sstevel@tonic-gate * lcp_coderej - A Code-Reject was received.
7817c478bd9Sstevel@tonic-gate */
7827c478bd9Sstevel@tonic-gate /*ARGSUSED*/
7837c478bd9Sstevel@tonic-gate static int
lcp_coderej(f,code,id,inp,len)7847c478bd9Sstevel@tonic-gate lcp_coderej(f, code, id, inp, len)
7857c478bd9Sstevel@tonic-gate fsm *f;
7867c478bd9Sstevel@tonic-gate int code;
7877c478bd9Sstevel@tonic-gate int id;
7887c478bd9Sstevel@tonic-gate u_char *inp;
7897c478bd9Sstevel@tonic-gate int len;
7907c478bd9Sstevel@tonic-gate {
7917c478bd9Sstevel@tonic-gate /* The peer cannot reject these code numbers. */
7927c478bd9Sstevel@tonic-gate if (code >= CODE_CONFREQ && code <= CODE_PROTREJ)
7937c478bd9Sstevel@tonic-gate return 1;
7947c478bd9Sstevel@tonic-gate switch (code) {
7957c478bd9Sstevel@tonic-gate case CODE_ECHOREQ:
7967c478bd9Sstevel@tonic-gate /*
7977c478bd9Sstevel@tonic-gate * If the peer rejects an Echo-Request, then stop doing that.
7987c478bd9Sstevel@tonic-gate */
7997c478bd9Sstevel@tonic-gate if (lcp_echo_timer_running != 0) {
8007c478bd9Sstevel@tonic-gate UNTIMEOUT (LcpEchoTimeout, f);
8017c478bd9Sstevel@tonic-gate lcp_echo_timer_running = 0;
8027c478bd9Sstevel@tonic-gate lcp_echo_interval = 0;
8037c478bd9Sstevel@tonic-gate }
8047c478bd9Sstevel@tonic-gate break;
8057c478bd9Sstevel@tonic-gate }
8067c478bd9Sstevel@tonic-gate return 0;
8077c478bd9Sstevel@tonic-gate }
8087c478bd9Sstevel@tonic-gate
8097c478bd9Sstevel@tonic-gate /*
8107c478bd9Sstevel@tonic-gate * lcp_sprotrej - Send a Protocol-Reject for some protocol.
8117c478bd9Sstevel@tonic-gate */
8127c478bd9Sstevel@tonic-gate void
lcp_sprotrej(unit,p,len)8137c478bd9Sstevel@tonic-gate lcp_sprotrej(unit, p, len)
8147c478bd9Sstevel@tonic-gate int unit;
8157c478bd9Sstevel@tonic-gate u_char *p;
8167c478bd9Sstevel@tonic-gate int len;
8177c478bd9Sstevel@tonic-gate {
8187c478bd9Sstevel@tonic-gate /*
8197c478bd9Sstevel@tonic-gate * Send back the protocol and the information field of the
8207c478bd9Sstevel@tonic-gate * rejected packet. We only get here if LCP is in the OPENED state.
8217c478bd9Sstevel@tonic-gate */
8227c478bd9Sstevel@tonic-gate p += 2;
8237c478bd9Sstevel@tonic-gate len -= 2;
8247c478bd9Sstevel@tonic-gate
8257c478bd9Sstevel@tonic-gate fsm_sdata(&lcp_fsm[unit], CODE_PROTREJ, ++lcp_fsm[unit].id,
8267c478bd9Sstevel@tonic-gate p, len);
8277c478bd9Sstevel@tonic-gate }
8287c478bd9Sstevel@tonic-gate
8297c478bd9Sstevel@tonic-gate
8307c478bd9Sstevel@tonic-gate /*
8317c478bd9Sstevel@tonic-gate * lcp_resetci - Reset our CI.
8327c478bd9Sstevel@tonic-gate */
8337c478bd9Sstevel@tonic-gate static void
lcp_resetci(f)8347c478bd9Sstevel@tonic-gate lcp_resetci(f)
8357c478bd9Sstevel@tonic-gate fsm *f;
8367c478bd9Sstevel@tonic-gate {
8377c478bd9Sstevel@tonic-gate lcp_options *wo = &lcp_wantoptions[f->unit];
8387c478bd9Sstevel@tonic-gate lcp_options *go = &lcp_gotoptions[f->unit];
8397c478bd9Sstevel@tonic-gate lcp_options *ao = &lcp_allowoptions[f->unit];
8407c478bd9Sstevel@tonic-gate
8417c478bd9Sstevel@tonic-gate wo->magicnumber = magic();
8427c478bd9Sstevel@tonic-gate wo->numloops = 0;
8437c478bd9Sstevel@tonic-gate sentident = 0;
8447c478bd9Sstevel@tonic-gate *go = *wo;
8457c478bd9Sstevel@tonic-gate if (!multilink) {
8467c478bd9Sstevel@tonic-gate go->neg_mrru = 0;
8477c478bd9Sstevel@tonic-gate go->neg_ssnhf = 0;
8487c478bd9Sstevel@tonic-gate }
8497c478bd9Sstevel@tonic-gate if (noendpoint)
8507c478bd9Sstevel@tonic-gate ao->neg_endpoint = 0;
8517c478bd9Sstevel@tonic-gate if (go->mru > absmax_mru)
8527c478bd9Sstevel@tonic-gate go->mru = absmax_mru;
8537c478bd9Sstevel@tonic-gate if (ao->mru > absmax_mtu)
8547c478bd9Sstevel@tonic-gate ao->mru = absmax_mtu;
8557c478bd9Sstevel@tonic-gate unsolicit_mru = 1;
8567c478bd9Sstevel@tonic-gate fsm_setpeermru(f->unit, PPP_MTU > absmax_mtu ? absmax_mtu : PPP_MTU);
8577c478bd9Sstevel@tonic-gate auth_reset(f->unit);
8587c478bd9Sstevel@tonic-gate }
8597c478bd9Sstevel@tonic-gate
8607c478bd9Sstevel@tonic-gate
8617c478bd9Sstevel@tonic-gate /*
8627c478bd9Sstevel@tonic-gate * lcp_cilen - Return length of our CI.
8637c478bd9Sstevel@tonic-gate */
8647c478bd9Sstevel@tonic-gate static int
lcp_cilen(f)8657c478bd9Sstevel@tonic-gate lcp_cilen(f)
8667c478bd9Sstevel@tonic-gate fsm *f;
8677c478bd9Sstevel@tonic-gate {
8687c478bd9Sstevel@tonic-gate lcp_options *go = &lcp_gotoptions[f->unit];
8697c478bd9Sstevel@tonic-gate
8707c478bd9Sstevel@tonic-gate #define LENCIVOID(neg) ((neg) ? CILEN_VOID : 0)
8717c478bd9Sstevel@tonic-gate #define LENCICHAP(neg) ((neg) ? CILEN_CHAP : 0)
8727c478bd9Sstevel@tonic-gate #define LENCICHAR(neg) ((neg) ? CILEN_CHAR : 0)
8737c478bd9Sstevel@tonic-gate #define LENCISHORT(neg) ((neg) ? CILEN_SHORT : 0)
8747c478bd9Sstevel@tonic-gate #define LENCILONG(neg) ((neg) ? CILEN_LONG : 0)
8757c478bd9Sstevel@tonic-gate #define LENCILQR(neg) ((neg) ? CILEN_LQR: 0)
8767c478bd9Sstevel@tonic-gate #define LENCICBCP(neg) ((neg) ? CILEN_CBCP: 0)
8777c478bd9Sstevel@tonic-gate /*
8787c478bd9Sstevel@tonic-gate * NB: we only ask for one of CHAP and UPAP, even if we will
8797c478bd9Sstevel@tonic-gate * accept either.
8807c478bd9Sstevel@tonic-gate */
8817c478bd9Sstevel@tonic-gate return (LENCISHORT(go->neg_mru && go->mru != PPP_MRU) +
8827c478bd9Sstevel@tonic-gate LENCILONG(go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF) +
8837c478bd9Sstevel@tonic-gate LENCICHAP(go->neg_chap || go->neg_mschap || go->neg_mschapv2) +
8847c478bd9Sstevel@tonic-gate LENCISHORT(!go->neg_chap && go->neg_upap && !go->neg_mschap &&
8857c478bd9Sstevel@tonic-gate !go->neg_mschapv2) +
8867c478bd9Sstevel@tonic-gate LENCILQR(go->neg_lqr) +
8877c478bd9Sstevel@tonic-gate LENCICBCP(go->neg_cbcp) +
8887c478bd9Sstevel@tonic-gate LENCILONG(go->neg_magicnumber) +
8897c478bd9Sstevel@tonic-gate LENCIVOID(go->neg_pcompression) +
8907c478bd9Sstevel@tonic-gate LENCIVOID(go->neg_accompression) +
8917c478bd9Sstevel@tonic-gate LENCICHAR(go->neg_fcs) +
8927c478bd9Sstevel@tonic-gate LENCISHORT(go->neg_mrru) +
8937c478bd9Sstevel@tonic-gate LENCIVOID(go->neg_ssnhf) +
8947c478bd9Sstevel@tonic-gate #ifdef MUX_FRAME
8957c478bd9Sstevel@tonic-gate LENCIVOID(go->pppmux) +
8967c478bd9Sstevel@tonic-gate #endif
8977c478bd9Sstevel@tonic-gate (go->neg_endpoint? CILEN_CHAR + go->endpoint.length: 0));
8987c478bd9Sstevel@tonic-gate }
8997c478bd9Sstevel@tonic-gate
9007c478bd9Sstevel@tonic-gate
9017c478bd9Sstevel@tonic-gate /*
9027c478bd9Sstevel@tonic-gate * lcp_addci - Add our desired CIs to a packet.
9037c478bd9Sstevel@tonic-gate */
9047c478bd9Sstevel@tonic-gate static void
lcp_addci(f,ucp,lenp)9057c478bd9Sstevel@tonic-gate lcp_addci(f, ucp, lenp)
9067c478bd9Sstevel@tonic-gate fsm *f;
9077c478bd9Sstevel@tonic-gate u_char *ucp;
9087c478bd9Sstevel@tonic-gate int *lenp;
9097c478bd9Sstevel@tonic-gate {
9107c478bd9Sstevel@tonic-gate lcp_options *go = &lcp_gotoptions[f->unit];
9117c478bd9Sstevel@tonic-gate lcp_options *ho = &lcp_hisoptions[f->unit];
9127c478bd9Sstevel@tonic-gate u_char *start_ucp = ucp;
9137c478bd9Sstevel@tonic-gate
9147c478bd9Sstevel@tonic-gate #define ADDCIVOID(opt, neg) \
9157c478bd9Sstevel@tonic-gate if (neg) { \
9167c478bd9Sstevel@tonic-gate PUTCHAR(opt, ucp); \
9177c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_VOID, ucp); \
9187c478bd9Sstevel@tonic-gate }
9197c478bd9Sstevel@tonic-gate #define ADDCISHORT(opt, neg, val) \
9207c478bd9Sstevel@tonic-gate if (neg) { \
9217c478bd9Sstevel@tonic-gate PUTCHAR(opt, ucp); \
9227c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_SHORT, ucp); \
9237c478bd9Sstevel@tonic-gate PUTSHORT(val, ucp); \
9247c478bd9Sstevel@tonic-gate }
9257c478bd9Sstevel@tonic-gate #define ADDCICHAP(opt, neg, val, digest) \
9267c478bd9Sstevel@tonic-gate if (neg) { \
9277c478bd9Sstevel@tonic-gate PUTCHAR(opt, ucp); \
9287c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_CHAP, ucp); \
9297c478bd9Sstevel@tonic-gate PUTSHORT(val, ucp); \
9307c478bd9Sstevel@tonic-gate PUTCHAR(digest, ucp); \
9317c478bd9Sstevel@tonic-gate }
9327c478bd9Sstevel@tonic-gate #define ADDCILONG(opt, neg, val) \
9337c478bd9Sstevel@tonic-gate if (neg) { \
9347c478bd9Sstevel@tonic-gate PUTCHAR(opt, ucp); \
9357c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_LONG, ucp); \
9367c478bd9Sstevel@tonic-gate PUTLONG(val, ucp); \
9377c478bd9Sstevel@tonic-gate }
9387c478bd9Sstevel@tonic-gate #define ADDCILQR(opt, neg, val) \
9397c478bd9Sstevel@tonic-gate if (neg) { \
9407c478bd9Sstevel@tonic-gate PUTCHAR(opt, ucp); \
9417c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_LQR, ucp); \
9427c478bd9Sstevel@tonic-gate PUTSHORT(PPP_LQR, ucp); \
9437c478bd9Sstevel@tonic-gate PUTLONG(val, ucp); \
9447c478bd9Sstevel@tonic-gate }
9457c478bd9Sstevel@tonic-gate #define ADDCICHAR(opt, neg, val) \
9467c478bd9Sstevel@tonic-gate if (neg) { \
9477c478bd9Sstevel@tonic-gate PUTCHAR(opt, ucp); \
9487c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_CHAR, ucp); \
9497c478bd9Sstevel@tonic-gate PUTCHAR(val, ucp); \
9507c478bd9Sstevel@tonic-gate }
9517c478bd9Sstevel@tonic-gate #define ADDCIENDP(opt, neg, class, val, len) \
9527c478bd9Sstevel@tonic-gate if (neg) { \
9537c478bd9Sstevel@tonic-gate int i; \
9547c478bd9Sstevel@tonic-gate PUTCHAR(opt, ucp); \
9557c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_CHAR + len, ucp); \
9567c478bd9Sstevel@tonic-gate PUTCHAR(class, ucp); \
9577c478bd9Sstevel@tonic-gate for (i = 0; i < len; ++i) \
9587c478bd9Sstevel@tonic-gate PUTCHAR(val[i], ucp); \
9597c478bd9Sstevel@tonic-gate }
9607c478bd9Sstevel@tonic-gate
9617c478bd9Sstevel@tonic-gate ADDCISHORT(CI_MRU, go->neg_mru && go->mru != PPP_MRU, go->mru);
9627c478bd9Sstevel@tonic-gate ADDCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF,
9637c478bd9Sstevel@tonic-gate go->asyncmap);
9647c478bd9Sstevel@tonic-gate /* go->chap_mdtype always points to a useful value */
9657c478bd9Sstevel@tonic-gate ADDCICHAP(CI_AUTHTYPE, go->neg_chap || go->neg_mschap || go->neg_mschapv2,
9667c478bd9Sstevel@tonic-gate PPP_CHAP, go->chap_mdtype);
9677c478bd9Sstevel@tonic-gate ADDCISHORT(CI_AUTHTYPE, !(go->neg_chap || go->neg_mschap ||
9687c478bd9Sstevel@tonic-gate go->neg_mschapv2) && go->neg_upap, PPP_PAP);
9697c478bd9Sstevel@tonic-gate /* We can't both say zero for LQR period. */
9707c478bd9Sstevel@tonic-gate if (f->state == ACKSENT && go->neg_lqr && go->lqr_period == 0 &&
9717c478bd9Sstevel@tonic-gate ho->neg_lqr && ho->lqr_period == 0)
9727c478bd9Sstevel@tonic-gate go->lqr_period = 500;
9737c478bd9Sstevel@tonic-gate ADDCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
9747c478bd9Sstevel@tonic-gate ADDCICHAR(CI_CALLBACK, go->neg_cbcp, CBOP_CBCP);
9757c478bd9Sstevel@tonic-gate ADDCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
9767c478bd9Sstevel@tonic-gate ADDCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
9777c478bd9Sstevel@tonic-gate ADDCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
9787c478bd9Sstevel@tonic-gate ADDCICHAR(CI_FCSALTERN, (go->neg_fcs && go->fcs_type != 0), go->fcs_type);
9797c478bd9Sstevel@tonic-gate ADDCIENDP(CI_EPDISC, go->neg_endpoint, go->endpoint.class,
9807c478bd9Sstevel@tonic-gate go->endpoint.value, go->endpoint.length);
9817c478bd9Sstevel@tonic-gate #ifdef MUX_FRAME
9827c478bd9Sstevel@tonic-gate ADDCIVOID(CI_MUXING, go->pppmux);
9837c478bd9Sstevel@tonic-gate #endif
9847c478bd9Sstevel@tonic-gate ADDCISHORT(CI_MRRU, go->neg_mrru, go->mrru);
9857c478bd9Sstevel@tonic-gate ADDCIVOID(CI_SSNHF, go->neg_ssnhf);
9867c478bd9Sstevel@tonic-gate
9877c478bd9Sstevel@tonic-gate if (ucp - start_ucp != *lenp) {
9887c478bd9Sstevel@tonic-gate /* this should never happen, because peer_mtu should be 1500 */
9897c478bd9Sstevel@tonic-gate error("Bug in lcp_addci: wrong length");
9907c478bd9Sstevel@tonic-gate }
9917c478bd9Sstevel@tonic-gate }
9927c478bd9Sstevel@tonic-gate
9937c478bd9Sstevel@tonic-gate
9947c478bd9Sstevel@tonic-gate /*
9957c478bd9Sstevel@tonic-gate * lcp_ackci - Ack our CIs.
9967c478bd9Sstevel@tonic-gate * This should not modify any state if the Ack is bad.
9977c478bd9Sstevel@tonic-gate *
9987c478bd9Sstevel@tonic-gate * Returns:
9997c478bd9Sstevel@tonic-gate * 0 - Ack was bad.
10007c478bd9Sstevel@tonic-gate * 1 - Ack was good.
10017c478bd9Sstevel@tonic-gate */
10027c478bd9Sstevel@tonic-gate static int
lcp_ackci(f,p,len)10037c478bd9Sstevel@tonic-gate lcp_ackci(f, p, len)
10047c478bd9Sstevel@tonic-gate fsm *f;
10057c478bd9Sstevel@tonic-gate u_char *p;
10067c478bd9Sstevel@tonic-gate int len;
10077c478bd9Sstevel@tonic-gate {
10087c478bd9Sstevel@tonic-gate lcp_options *go = &lcp_gotoptions[f->unit];
10097c478bd9Sstevel@tonic-gate #ifdef MUX_FRAME
10107c478bd9Sstevel@tonic-gate lcp_options *ao = &lcp_allowoptions[f->unit];
10117c478bd9Sstevel@tonic-gate #endif
10127c478bd9Sstevel@tonic-gate u_char cilen, citype, cichar;
10137c478bd9Sstevel@tonic-gate u_short cishort;
10147c478bd9Sstevel@tonic-gate u_int32_t cilong;
10157c478bd9Sstevel@tonic-gate
10167c478bd9Sstevel@tonic-gate /*
10177c478bd9Sstevel@tonic-gate * CIs must be in exactly the same order that we sent.
10187c478bd9Sstevel@tonic-gate * Check packet length and CI length at each step.
10197c478bd9Sstevel@tonic-gate * If we find any deviations, then this packet is bad.
10207c478bd9Sstevel@tonic-gate */
10217c478bd9Sstevel@tonic-gate #define ACKCIVOID(opt, neg) \
10227c478bd9Sstevel@tonic-gate if (neg) { \
10237c478bd9Sstevel@tonic-gate if ((len -= CILEN_VOID) < 0) \
10247c478bd9Sstevel@tonic-gate goto bad; \
10257c478bd9Sstevel@tonic-gate GETCHAR(citype, p); \
10267c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); \
10277c478bd9Sstevel@tonic-gate if (cilen != CILEN_VOID || \
10287c478bd9Sstevel@tonic-gate citype != opt) \
10297c478bd9Sstevel@tonic-gate goto bad; \
10307c478bd9Sstevel@tonic-gate }
10317c478bd9Sstevel@tonic-gate #define ACKCISHORT(opt, neg, val) \
10327c478bd9Sstevel@tonic-gate if (neg) { \
10337c478bd9Sstevel@tonic-gate if ((len -= CILEN_SHORT) < 0) \
10347c478bd9Sstevel@tonic-gate goto bad; \
10357c478bd9Sstevel@tonic-gate GETCHAR(citype, p); \
10367c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); \
10377c478bd9Sstevel@tonic-gate if (cilen != CILEN_SHORT || \
10387c478bd9Sstevel@tonic-gate citype != opt) \
10397c478bd9Sstevel@tonic-gate goto bad; \
10407c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \
10417c478bd9Sstevel@tonic-gate if (cishort != val) \
10427c478bd9Sstevel@tonic-gate goto bad; \
10437c478bd9Sstevel@tonic-gate }
10447c478bd9Sstevel@tonic-gate #define ACKCIAUTH(opt, neg, val) \
10457c478bd9Sstevel@tonic-gate if (neg) { \
10467c478bd9Sstevel@tonic-gate if ((len -= CILEN_SHORT) < 0) \
10477c478bd9Sstevel@tonic-gate goto bad; \
10487c478bd9Sstevel@tonic-gate GETCHAR(citype, p); \
10497c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); \
10507c478bd9Sstevel@tonic-gate if (cilen != CILEN_SHORT || \
10517c478bd9Sstevel@tonic-gate citype != opt) \
10527c478bd9Sstevel@tonic-gate goto bad; \
10537c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \
10547c478bd9Sstevel@tonic-gate if (cishort != val) \
10557c478bd9Sstevel@tonic-gate goto bad; \
10567c478bd9Sstevel@tonic-gate peer_nak_auth = 0; \
10577c478bd9Sstevel@tonic-gate peer_reject_auth = 0; \
10587c478bd9Sstevel@tonic-gate }
10597c478bd9Sstevel@tonic-gate #define ACKCICHAR(opt, neg, val) \
10607c478bd9Sstevel@tonic-gate if (neg) { \
10617c478bd9Sstevel@tonic-gate if ((len -= CILEN_CHAR) < 0) \
10627c478bd9Sstevel@tonic-gate goto bad; \
10637c478bd9Sstevel@tonic-gate GETCHAR(citype, p); \
10647c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); \
10657c478bd9Sstevel@tonic-gate if (cilen != CILEN_CHAR || \
10667c478bd9Sstevel@tonic-gate citype != opt) \
10677c478bd9Sstevel@tonic-gate goto bad; \
10687c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); \
10697c478bd9Sstevel@tonic-gate if (cichar != val) \
10707c478bd9Sstevel@tonic-gate goto bad; \
10717c478bd9Sstevel@tonic-gate }
10727c478bd9Sstevel@tonic-gate #define ACKCICHAP(opt, neg, val, digest) \
10737c478bd9Sstevel@tonic-gate if (neg) { \
10747c478bd9Sstevel@tonic-gate if ((len -= CILEN_CHAP) < 0) \
10757c478bd9Sstevel@tonic-gate goto bad; \
10767c478bd9Sstevel@tonic-gate GETCHAR(citype, p); \
10777c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); \
10787c478bd9Sstevel@tonic-gate if (cilen != CILEN_CHAP || \
10797c478bd9Sstevel@tonic-gate citype != opt) \
10807c478bd9Sstevel@tonic-gate goto bad; \
10817c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \
10827c478bd9Sstevel@tonic-gate if (cishort != val) \
10837c478bd9Sstevel@tonic-gate goto bad; \
10847c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); \
10857c478bd9Sstevel@tonic-gate if (cichar != digest) \
10867c478bd9Sstevel@tonic-gate goto bad; \
10877c478bd9Sstevel@tonic-gate peer_nak_auth = 0; \
10887c478bd9Sstevel@tonic-gate peer_reject_auth = 0; \
10897c478bd9Sstevel@tonic-gate }
10907c478bd9Sstevel@tonic-gate #define ACKCILONG(opt, neg, val) \
10917c478bd9Sstevel@tonic-gate if (neg) { \
10927c478bd9Sstevel@tonic-gate if ((len -= CILEN_LONG) < 0) \
10937c478bd9Sstevel@tonic-gate goto bad; \
10947c478bd9Sstevel@tonic-gate GETCHAR(citype, p); \
10957c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); \
10967c478bd9Sstevel@tonic-gate if (cilen != CILEN_LONG || \
10977c478bd9Sstevel@tonic-gate citype != opt) \
10987c478bd9Sstevel@tonic-gate goto bad; \
10997c478bd9Sstevel@tonic-gate GETLONG(cilong, p); \
11007c478bd9Sstevel@tonic-gate if (cilong != val) \
11017c478bd9Sstevel@tonic-gate goto bad; \
11027c478bd9Sstevel@tonic-gate }
11037c478bd9Sstevel@tonic-gate #define ACKCILQR(opt, neg, val) \
11047c478bd9Sstevel@tonic-gate if (neg) { \
11057c478bd9Sstevel@tonic-gate if ((len -= CILEN_LQR) < 0) \
11067c478bd9Sstevel@tonic-gate goto bad; \
11077c478bd9Sstevel@tonic-gate GETCHAR(citype, p); \
11087c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); \
11097c478bd9Sstevel@tonic-gate if (cilen != CILEN_LQR || \
11107c478bd9Sstevel@tonic-gate citype != opt) \
11117c478bd9Sstevel@tonic-gate goto bad; \
11127c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \
11137c478bd9Sstevel@tonic-gate if (cishort != PPP_LQR) \
11147c478bd9Sstevel@tonic-gate goto bad; \
11157c478bd9Sstevel@tonic-gate GETLONG(cilong, p); \
11167c478bd9Sstevel@tonic-gate if (cilong != val) \
11177c478bd9Sstevel@tonic-gate goto bad; \
11187c478bd9Sstevel@tonic-gate }
11197c478bd9Sstevel@tonic-gate #define ACKCIENDP(opt, neg, class, val, vlen) \
11207c478bd9Sstevel@tonic-gate if (neg) { \
11217c478bd9Sstevel@tonic-gate int i; \
11227c478bd9Sstevel@tonic-gate if ((len -= CILEN_CHAR + vlen) < 0) \
11237c478bd9Sstevel@tonic-gate goto bad; \
11247c478bd9Sstevel@tonic-gate GETCHAR(citype, p); \
11257c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); \
11267c478bd9Sstevel@tonic-gate if (cilen != CILEN_CHAR + vlen || \
11277c478bd9Sstevel@tonic-gate citype != opt) \
11287c478bd9Sstevel@tonic-gate goto bad; \
11297c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); \
11307c478bd9Sstevel@tonic-gate if (cichar != class) \
11317c478bd9Sstevel@tonic-gate goto bad; \
11327c478bd9Sstevel@tonic-gate for (i = 0; i < vlen; ++i) { \
11337c478bd9Sstevel@tonic-gate GETCHAR(cichar, p); \
11347c478bd9Sstevel@tonic-gate if (cichar != val[i]) \
11357c478bd9Sstevel@tonic-gate goto bad; \
11367c478bd9Sstevel@tonic-gate } \
11377c478bd9Sstevel@tonic-gate }
11387c478bd9Sstevel@tonic-gate
11397c478bd9Sstevel@tonic-gate ACKCISHORT(CI_MRU, go->neg_mru && go->mru != PPP_MRU, go->mru);
11407c478bd9Sstevel@tonic-gate ACKCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF,
11417c478bd9Sstevel@tonic-gate go->asyncmap);
11427c478bd9Sstevel@tonic-gate /* go->chap_mdtype always points to a useful value */
1143