17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * ipcp.c - PPP IP 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 *
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 */
22*48bbca81SDaniel Hoffman /*
23*48bbca81SDaniel Hoffman * Copyright (c) 2016 by Delphix. All rights reserved.
24*48bbca81SDaniel Hoffman */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate #include <stdio.h>
277c478bd9Sstevel@tonic-gate #include <string.h>
287c478bd9Sstevel@tonic-gate #include <netdb.h>
297c478bd9Sstevel@tonic-gate #include <sys/param.h>
307c478bd9Sstevel@tonic-gate #include <sys/types.h>
317c478bd9Sstevel@tonic-gate #include <sys/socket.h>
327c478bd9Sstevel@tonic-gate #if defined(_linux_) || defined(__linux__)
337c478bd9Sstevel@tonic-gate #define __FAVOR_BSD
347c478bd9Sstevel@tonic-gate #endif
357c478bd9Sstevel@tonic-gate #include <netinet/in.h>
367c478bd9Sstevel@tonic-gate #include <netinet/tcp.h>
377c478bd9Sstevel@tonic-gate #include <arpa/inet.h>
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gate #include "pppd.h"
407c478bd9Sstevel@tonic-gate #include "fsm.h"
417c478bd9Sstevel@tonic-gate #include "ipcp.h"
427c478bd9Sstevel@tonic-gate #include "pathnames.h"
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate /* global vars */
457c478bd9Sstevel@tonic-gate ipcp_options ipcp_wantoptions[NUM_PPP]; /* Options that we want to request */
467c478bd9Sstevel@tonic-gate ipcp_options ipcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
477c478bd9Sstevel@tonic-gate ipcp_options ipcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
487c478bd9Sstevel@tonic-gate ipcp_options ipcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate bool ipcp_from_hostname = 0; /* Local IP address is from hostname lookup */
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate /* Hook for a plugin to know when IP protocol has come up */
537c478bd9Sstevel@tonic-gate void (*ip_up_hook) __P((void)) = NULL;
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate /* Hook for a plugin to know when IP protocol has come down */
567c478bd9Sstevel@tonic-gate void (*ip_down_hook) __P((void)) = NULL;
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gate /* local vars */
597c478bd9Sstevel@tonic-gate static bool default_route_set[NUM_PPP]; /* Have set up a default route */
607c478bd9Sstevel@tonic-gate static bool proxy_arp_set[NUM_PPP]; /* Have created proxy arp entry */
617c478bd9Sstevel@tonic-gate static bool ipcp_is_up[NUM_PPP]; /* have called np_up() */
627c478bd9Sstevel@tonic-gate static bool proxy_arp_quiet[NUM_PPP]; /* We should be quiet on error */
637c478bd9Sstevel@tonic-gate static bool disable_defaultip = 0; /* Don't use hostname for IP addr */
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gate /*
667c478bd9Sstevel@tonic-gate * Callbacks for fsm code. (CI = Configuration Information)
677c478bd9Sstevel@tonic-gate */
687c478bd9Sstevel@tonic-gate static void ipcp_resetci __P((fsm *)); /* Reset our CI */
697c478bd9Sstevel@tonic-gate static int ipcp_cilen __P((fsm *)); /* Return length of our CI */
707c478bd9Sstevel@tonic-gate static void ipcp_addci __P((fsm *, u_char *, int *)); /* Add our CI */
717c478bd9Sstevel@tonic-gate static int ipcp_ackci __P((fsm *, u_char *, int)); /* Peer ack'd our CI */
727c478bd9Sstevel@tonic-gate static int ipcp_nakci __P((fsm *, u_char *, int)); /* Peer nak'd our CI */
737c478bd9Sstevel@tonic-gate static int ipcp_rejci __P((fsm *, u_char *, int)); /* Peer rej'd our CI */
747c478bd9Sstevel@tonic-gate static int ipcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv CI */
757c478bd9Sstevel@tonic-gate static void ipcp_up __P((fsm *)); /* We're UP */
767c478bd9Sstevel@tonic-gate static void ipcp_down __P((fsm *)); /* We're DOWN */
777c478bd9Sstevel@tonic-gate static void ipcp_finished __P((fsm *)); /* Don't need lower layer */
787c478bd9Sstevel@tonic-gate static int setmsservaddr __P((char *, u_int32_t *));
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate fsm ipcp_fsm[NUM_PPP]; /* IPCP fsm structure */
817c478bd9Sstevel@tonic-gate
827c478bd9Sstevel@tonic-gate static fsm_callbacks ipcp_callbacks = { /* IPCP callback routines */
837c478bd9Sstevel@tonic-gate ipcp_resetci, /* Reset our Configuration Information */
847c478bd9Sstevel@tonic-gate ipcp_cilen, /* Length of our Configuration Information */
857c478bd9Sstevel@tonic-gate ipcp_addci, /* Add our Configuration Information */
867c478bd9Sstevel@tonic-gate ipcp_ackci, /* ACK our Configuration Information */
877c478bd9Sstevel@tonic-gate ipcp_nakci, /* NAK our Configuration Information */
887c478bd9Sstevel@tonic-gate ipcp_rejci, /* Reject our Configuration Information */
897c478bd9Sstevel@tonic-gate ipcp_reqci, /* Request peer's Configuration Information */
907c478bd9Sstevel@tonic-gate ipcp_up, /* Called when fsm reaches OPENED state */
917c478bd9Sstevel@tonic-gate ipcp_down, /* Called when fsm leaves OPENED state */
927c478bd9Sstevel@tonic-gate NULL, /* Called when we want the lower layer up */
937c478bd9Sstevel@tonic-gate ipcp_finished, /* Called when we want the lower layer down */
947c478bd9Sstevel@tonic-gate NULL, /* Retransmission is necessary */
957c478bd9Sstevel@tonic-gate NULL, /* Called to handle protocol-specific codes */
967c478bd9Sstevel@tonic-gate "IPCP", /* String name of protocol */
977c478bd9Sstevel@tonic-gate NULL /* Peer rejected a code number */
987c478bd9Sstevel@tonic-gate };
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate /*
1017c478bd9Sstevel@tonic-gate * Command-line options.
1027c478bd9Sstevel@tonic-gate */
1037c478bd9Sstevel@tonic-gate static int setvjslots __P((char **));
1047c478bd9Sstevel@tonic-gate static int setdnsaddr __P((char **));
1057c478bd9Sstevel@tonic-gate static int setwinsaddr __P((char **));
1067c478bd9Sstevel@tonic-gate static int autoproxyarp __P((char **));
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate static option_t ipcp_option_list[] = {
1097c478bd9Sstevel@tonic-gate { "noip", o_bool, &ipcp_protent.enabled_flag,
1107c478bd9Sstevel@tonic-gate "Disable IP and IPCP" },
1117c478bd9Sstevel@tonic-gate { "-ip", o_bool, &ipcp_protent.enabled_flag,
1127c478bd9Sstevel@tonic-gate "Disable IP and IPCP" },
1137c478bd9Sstevel@tonic-gate { "novj", o_bool, &ipcp_wantoptions[0].neg_vj,
1147c478bd9Sstevel@tonic-gate "Disable VJ compression", OPT_A2COPY, &ipcp_allowoptions[0].neg_vj },
1157c478bd9Sstevel@tonic-gate { "-vj", o_bool, &ipcp_wantoptions[0].neg_vj,
1167c478bd9Sstevel@tonic-gate "Disable VJ compression", OPT_A2COPY, &ipcp_allowoptions[0].neg_vj },
1177c478bd9Sstevel@tonic-gate { "novjccomp", o_bool, &ipcp_wantoptions[0].cflag,
1187c478bd9Sstevel@tonic-gate "Disable VJ connection-ID compression", OPT_A2COPY,
1197c478bd9Sstevel@tonic-gate &ipcp_allowoptions[0].cflag },
1207c478bd9Sstevel@tonic-gate { "-vjccomp", o_bool, &ipcp_wantoptions[0].cflag,
1217c478bd9Sstevel@tonic-gate "Disable VJ connection-ID compression", OPT_A2COPY,
1227c478bd9Sstevel@tonic-gate &ipcp_allowoptions[0].cflag },
1237c478bd9Sstevel@tonic-gate { "vj-max-slots", o_special, (void *)setvjslots,
1247c478bd9Sstevel@tonic-gate "Set maximum VJ header slots" },
1257c478bd9Sstevel@tonic-gate { "ipcp-accept-local", o_bool, &ipcp_wantoptions[0].accept_local,
1267c478bd9Sstevel@tonic-gate "Accept peer's address for us", 1 },
1277c478bd9Sstevel@tonic-gate { "ipcp-accept-remote", o_bool, &ipcp_wantoptions[0].accept_remote,
1287c478bd9Sstevel@tonic-gate "Accept peer's address for it", 1 },
1297c478bd9Sstevel@tonic-gate { "ipparam", o_string, &ipparam,
1307c478bd9Sstevel@tonic-gate "Set ip script parameter" },
1317c478bd9Sstevel@tonic-gate { "noipdefault", o_bool, &disable_defaultip,
1327c478bd9Sstevel@tonic-gate "Don't use name for default IP adrs", 1 },
1337c478bd9Sstevel@tonic-gate { "ms-dns", o_special, (void *)setdnsaddr,
1347c478bd9Sstevel@tonic-gate "DNS address for the peer's use" },
1357c478bd9Sstevel@tonic-gate { "ms-wins", o_special, (void *)setwinsaddr,
1367c478bd9Sstevel@tonic-gate "Nameserver for SMB over TCP/IP for peer" },
1377c478bd9Sstevel@tonic-gate { "ipcp-restart", o_int, &ipcp_fsm[0].timeouttime,
1387c478bd9Sstevel@tonic-gate "Set timeout for IPCP" },
1397c478bd9Sstevel@tonic-gate { "ipcp-max-terminate", o_int, &ipcp_fsm[0].maxtermtransmits,
1407c478bd9Sstevel@tonic-gate "Set max #xmits for term-reqs" },
1417c478bd9Sstevel@tonic-gate { "ipcp-max-configure", o_int, &ipcp_fsm[0].maxconfreqtransmits,
1427c478bd9Sstevel@tonic-gate "Set max #xmits for conf-reqs" },
1437c478bd9Sstevel@tonic-gate { "ipcp-max-failure", o_int, &ipcp_fsm[0].maxnakloops,
1447c478bd9Sstevel@tonic-gate "Set max #conf-naks for IPCP" },
1457c478bd9Sstevel@tonic-gate { "defaultroute", o_bool, &ipcp_wantoptions[0].default_route,
1467c478bd9Sstevel@tonic-gate "Add default route", OPT_ENABLE|1, &ipcp_allowoptions[0].default_route },
1477c478bd9Sstevel@tonic-gate { "nodefaultroute", o_bool, &ipcp_allowoptions[0].default_route,
1487c478bd9Sstevel@tonic-gate "disable defaultroute option", OPT_A2COPY,
1497c478bd9Sstevel@tonic-gate &ipcp_wantoptions[0].default_route },
1507c478bd9Sstevel@tonic-gate { "-defaultroute", o_bool, &ipcp_allowoptions[0].default_route,
1517c478bd9Sstevel@tonic-gate "disable defaultroute option", OPT_A2COPY,
1527c478bd9Sstevel@tonic-gate &ipcp_wantoptions[0].default_route },
1537c478bd9Sstevel@tonic-gate { "proxyarp", o_bool, &ipcp_wantoptions[0].proxy_arp,
1547c478bd9Sstevel@tonic-gate "Add proxy ARP entry", OPT_ENABLE|1, &ipcp_allowoptions[0].proxy_arp },
1557c478bd9Sstevel@tonic-gate { "autoproxyarp", o_special_noarg, (void *)autoproxyarp,
1567c478bd9Sstevel@tonic-gate "Add proxy ARP entry if needed", OPT_ENABLE,
1577c478bd9Sstevel@tonic-gate &ipcp_allowoptions[0].proxy_arp },
1587c478bd9Sstevel@tonic-gate { "noproxyarp", o_bool, &ipcp_allowoptions[0].proxy_arp,
1597c478bd9Sstevel@tonic-gate "disable proxyarp option", OPT_A2COPY, &ipcp_wantoptions[0].proxy_arp },
1607c478bd9Sstevel@tonic-gate { "-proxyarp", o_bool, &ipcp_allowoptions[0].proxy_arp,
1617c478bd9Sstevel@tonic-gate "disable proxyarp option", OPT_A2COPY, &ipcp_wantoptions[0].proxy_arp },
1627c478bd9Sstevel@tonic-gate { "usepeerdns", o_bool, &ipcp_wantoptions[0].req_dns1,
1637c478bd9Sstevel@tonic-gate "Ask peer for DNS address(es)", OPT_A2COPY|1,
1647c478bd9Sstevel@tonic-gate &ipcp_wantoptions[0].req_dns2 },
1657c478bd9Sstevel@tonic-gate { NULL }
1667c478bd9Sstevel@tonic-gate };
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate /*
1697c478bd9Sstevel@tonic-gate * Protocol entry points from main code.
1707c478bd9Sstevel@tonic-gate */
1717c478bd9Sstevel@tonic-gate static void ipcp_init __P((int));
1727c478bd9Sstevel@tonic-gate static void ipcp_open __P((int));
1737c478bd9Sstevel@tonic-gate static void ipcp_close __P((int, char *));
1747c478bd9Sstevel@tonic-gate static void ipcp_lowerup __P((int));
1757c478bd9Sstevel@tonic-gate static void ipcp_lowerdown __P((int));
1767c478bd9Sstevel@tonic-gate static void ipcp_input __P((int, u_char *, int));
1777c478bd9Sstevel@tonic-gate static void ipcp_protrej __P((int));
1787c478bd9Sstevel@tonic-gate static int ipcp_printpkt __P((u_char *, int,
1797c478bd9Sstevel@tonic-gate void (*) __P((void *, const char *, ...)), void *));
1807c478bd9Sstevel@tonic-gate static void ip_check_options __P((void));
1817c478bd9Sstevel@tonic-gate static int ip_demand_conf __P((int));
1827c478bd9Sstevel@tonic-gate static int ip_active_pkt __P((u_char *, int));
1837c478bd9Sstevel@tonic-gate static void ipcp_print_stat __P((int, FILE *));
1847c478bd9Sstevel@tonic-gate
1857c478bd9Sstevel@tonic-gate static void create_resolv __P((u_int32_t, u_int32_t));
1867c478bd9Sstevel@tonic-gate
1877c478bd9Sstevel@tonic-gate struct protent ipcp_protent = {
1887c478bd9Sstevel@tonic-gate PPP_IPCP,
1897c478bd9Sstevel@tonic-gate ipcp_init,
1907c478bd9Sstevel@tonic-gate ipcp_input,
1917c478bd9Sstevel@tonic-gate ipcp_protrej,
1927c478bd9Sstevel@tonic-gate ipcp_lowerup,
1937c478bd9Sstevel@tonic-gate ipcp_lowerdown,
1947c478bd9Sstevel@tonic-gate ipcp_open,
1957c478bd9Sstevel@tonic-gate ipcp_close,
1967c478bd9Sstevel@tonic-gate ipcp_printpkt,
1977c478bd9Sstevel@tonic-gate NULL,
1987c478bd9Sstevel@tonic-gate 1,
1997c478bd9Sstevel@tonic-gate "IPCP",
2007c478bd9Sstevel@tonic-gate "IP",
2017c478bd9Sstevel@tonic-gate ipcp_option_list,
2027c478bd9Sstevel@tonic-gate ip_check_options,
2037c478bd9Sstevel@tonic-gate ip_demand_conf,
2047c478bd9Sstevel@tonic-gate ip_active_pkt,
2057c478bd9Sstevel@tonic-gate ipcp_print_stat
2067c478bd9Sstevel@tonic-gate };
2077c478bd9Sstevel@tonic-gate
2087c478bd9Sstevel@tonic-gate static void ipcp_clear_addrs __P((int, u_int32_t, u_int32_t));
2097c478bd9Sstevel@tonic-gate static void ipcp_script __P((char *)); /* Run an up/down script */
2107c478bd9Sstevel@tonic-gate static void ipcp_script_done __P((void *, int));
2117c478bd9Sstevel@tonic-gate
2127c478bd9Sstevel@tonic-gate /*
2137c478bd9Sstevel@tonic-gate * Lengths of configuration options.
2147c478bd9Sstevel@tonic-gate */
2157c478bd9Sstevel@tonic-gate #define CILEN_VOID 2
2167c478bd9Sstevel@tonic-gate #define CILEN_COMPRESS 4 /* min length for compression protocol opt. */
2177c478bd9Sstevel@tonic-gate #define CILEN_VJ 6 /* length for RFC1332 Van-Jacobson opt. */
2187c478bd9Sstevel@tonic-gate #define CILEN_ADDR 6 /* new-style single address option */
2197c478bd9Sstevel@tonic-gate #define CILEN_ADDRS 10 /* old-style dual address option */
2207c478bd9Sstevel@tonic-gate
2217c478bd9Sstevel@tonic-gate
2227c478bd9Sstevel@tonic-gate /*
2237c478bd9Sstevel@tonic-gate * This state variable is used to ensure that we don't
2247c478bd9Sstevel@tonic-gate * run an ipcp-up/down script while one is already running.
2257c478bd9Sstevel@tonic-gate */
2267c478bd9Sstevel@tonic-gate static enum script_state {
2277c478bd9Sstevel@tonic-gate s_down,
2287c478bd9Sstevel@tonic-gate s_up
2297c478bd9Sstevel@tonic-gate } ipcp_script_state;
2307c478bd9Sstevel@tonic-gate static pid_t ipcp_script_pid;
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate /*
2337c478bd9Sstevel@tonic-gate * Make a string representation of a network IP address.
2347c478bd9Sstevel@tonic-gate */
2357c478bd9Sstevel@tonic-gate char *
ip_ntoa(ipaddr)2367c478bd9Sstevel@tonic-gate ip_ntoa(ipaddr)
2377c478bd9Sstevel@tonic-gate u_int32_t ipaddr;
2387c478bd9Sstevel@tonic-gate {
2397c478bd9Sstevel@tonic-gate static char b[64];
2407c478bd9Sstevel@tonic-gate
2417c478bd9Sstevel@tonic-gate (void) slprintf(b, sizeof(b), "%I", ipaddr);
2427c478bd9Sstevel@tonic-gate return b;
2437c478bd9Sstevel@tonic-gate }
2447c478bd9Sstevel@tonic-gate
2457c478bd9Sstevel@tonic-gate /*
2467c478bd9Sstevel@tonic-gate * Option parsing.
2477c478bd9Sstevel@tonic-gate */
2487c478bd9Sstevel@tonic-gate
2497c478bd9Sstevel@tonic-gate /*
2507c478bd9Sstevel@tonic-gate * setvjslots - set maximum number of connection slots for VJ compression
2517c478bd9Sstevel@tonic-gate */
2527c478bd9Sstevel@tonic-gate static int
setvjslots(argv)2537c478bd9Sstevel@tonic-gate setvjslots(argv)
2547c478bd9Sstevel@tonic-gate char **argv;
2557c478bd9Sstevel@tonic-gate {
2567c478bd9Sstevel@tonic-gate int value;
2577c478bd9Sstevel@tonic-gate
2587c478bd9Sstevel@tonic-gate if (!int_option(*argv, &value))
2597c478bd9Sstevel@tonic-gate return 0;
2607c478bd9Sstevel@tonic-gate if (value < 2 || value > 16) {
2617c478bd9Sstevel@tonic-gate option_error("vj-max-slots value must be between 2 and 16");
2627c478bd9Sstevel@tonic-gate return 0;
2637c478bd9Sstevel@tonic-gate }
2647c478bd9Sstevel@tonic-gate ipcp_wantoptions [0].maxslotindex =
2657c478bd9Sstevel@tonic-gate ipcp_allowoptions[0].maxslotindex = value - 1;
2667c478bd9Sstevel@tonic-gate return 1;
2677c478bd9Sstevel@tonic-gate }
2687c478bd9Sstevel@tonic-gate
2697c478bd9Sstevel@tonic-gate /*
2707c478bd9Sstevel@tonic-gate * setmsservaddr - Set the primary and secondary server addresses in the
2717c478bd9Sstevel@tonic-gate * array. setdnsaddr() and setwinsaddr() call this function with either
2727c478bd9Sstevel@tonic-gate * dnsaddr[] or winsaddr[] as the serverarray argument.
2737c478bd9Sstevel@tonic-gate */
2747c478bd9Sstevel@tonic-gate static int
setmsservaddr(servname,serverarray)2757c478bd9Sstevel@tonic-gate setmsservaddr(servname, serverarray)
2767c478bd9Sstevel@tonic-gate char *servname;
2777c478bd9Sstevel@tonic-gate u_int32_t *serverarray;
2787c478bd9Sstevel@tonic-gate {
2797c478bd9Sstevel@tonic-gate u_int32_t addr;
2807c478bd9Sstevel@tonic-gate struct hostent *hp = NULL;
2817c478bd9Sstevel@tonic-gate
2827c478bd9Sstevel@tonic-gate addr = inet_addr(servname);
2837c478bd9Sstevel@tonic-gate if (addr == (u_int32_t) -1) {
2847c478bd9Sstevel@tonic-gate if ((hp = gethostbyname(servname)) == NULL)
2857c478bd9Sstevel@tonic-gate return 0;
2867c478bd9Sstevel@tonic-gate BCOPY(hp->h_addr, &addr, sizeof (u_int32_t));
2877c478bd9Sstevel@tonic-gate }
2887c478bd9Sstevel@tonic-gate
2897c478bd9Sstevel@tonic-gate /*
2907c478bd9Sstevel@tonic-gate * If there is no primary then this is the first instance of the
2917c478bd9Sstevel@tonic-gate * option, we must set the primary. In that case, try to set the
2927c478bd9Sstevel@tonic-gate * secondary to h_addr_list[1]. If the primary is already set, then
2937c478bd9Sstevel@tonic-gate * this is the second instance of the option, and we must set
2947c478bd9Sstevel@tonic-gate * the secondary.
2957c478bd9Sstevel@tonic-gate */
2967c478bd9Sstevel@tonic-gate if (serverarray[0] == 0) {
2977c478bd9Sstevel@tonic-gate serverarray[0] = addr;
2987c478bd9Sstevel@tonic-gate if (hp != NULL && hp->h_addr_list[1] != NULL)
2997c478bd9Sstevel@tonic-gate BCOPY(hp->h_addr_list[1], &serverarray[1], sizeof (u_int32_t));
3007c478bd9Sstevel@tonic-gate else
3017c478bd9Sstevel@tonic-gate serverarray[1] = addr;
3027c478bd9Sstevel@tonic-gate } else {
3037c478bd9Sstevel@tonic-gate serverarray[1] = addr;
3047c478bd9Sstevel@tonic-gate }
3057c478bd9Sstevel@tonic-gate
3067c478bd9Sstevel@tonic-gate return (1);
3077c478bd9Sstevel@tonic-gate }
3087c478bd9Sstevel@tonic-gate
3097c478bd9Sstevel@tonic-gate /*
3107c478bd9Sstevel@tonic-gate * setdnsaddr - set the dns address(es)
3117c478bd9Sstevel@tonic-gate */
3127c478bd9Sstevel@tonic-gate static int
setdnsaddr(argv)3137c478bd9Sstevel@tonic-gate setdnsaddr(argv)
3147c478bd9Sstevel@tonic-gate char **argv;
3157c478bd9Sstevel@tonic-gate {
3167c478bd9Sstevel@tonic-gate if (setmsservaddr(*argv, &(ipcp_allowoptions[0].dnsaddr[0])) == 0) {
3177c478bd9Sstevel@tonic-gate option_error("invalid address parameter '%s' for ms-dns option", *argv);
3187c478bd9Sstevel@tonic-gate return (0);
3197c478bd9Sstevel@tonic-gate }
3207c478bd9Sstevel@tonic-gate
3217c478bd9Sstevel@tonic-gate return (1);
3227c478bd9Sstevel@tonic-gate }
3237c478bd9Sstevel@tonic-gate
3247c478bd9Sstevel@tonic-gate /*
3257c478bd9Sstevel@tonic-gate * setwinsaddr - set the wins address(es)
3267c478bd9Sstevel@tonic-gate * This is primrarly used with the Samba package under UNIX or for pointing
3277c478bd9Sstevel@tonic-gate * the caller to the existing WINS server on a Windows NT platform.
3287c478bd9Sstevel@tonic-gate */
3297c478bd9Sstevel@tonic-gate static int
setwinsaddr(argv)3307c478bd9Sstevel@tonic-gate setwinsaddr(argv)
3317c478bd9Sstevel@tonic-gate char **argv;
3327c478bd9Sstevel@tonic-gate {
3337c478bd9Sstevel@tonic-gate if (setmsservaddr(*argv, &(ipcp_allowoptions[0].winsaddr[0])) == 0) {
3347c478bd9Sstevel@tonic-gate option_error("invalid address parameter '%s' for ms-wins option",
3357c478bd9Sstevel@tonic-gate *argv);
3367c478bd9Sstevel@tonic-gate return (0);
3377c478bd9Sstevel@tonic-gate }
3387c478bd9Sstevel@tonic-gate
3397c478bd9Sstevel@tonic-gate return (1);
3407c478bd9Sstevel@tonic-gate }
3417c478bd9Sstevel@tonic-gate
3427c478bd9Sstevel@tonic-gate /*
3437c478bd9Sstevel@tonic-gate * autoproxyarp -- enable proxy ARP but don't emit error messages if
3447c478bd9Sstevel@tonic-gate * it's not actually needed.
3457c478bd9Sstevel@tonic-gate */
3467c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3477c478bd9Sstevel@tonic-gate static int
autoproxyarp(argv)3487c478bd9Sstevel@tonic-gate autoproxyarp(argv)
3497c478bd9Sstevel@tonic-gate char **argv;
3507c478bd9Sstevel@tonic-gate {
3517c478bd9Sstevel@tonic-gate ipcp_wantoptions[0].proxy_arp = 1;
3527c478bd9Sstevel@tonic-gate proxy_arp_quiet[0] = 1;
3537c478bd9Sstevel@tonic-gate
3547c478bd9Sstevel@tonic-gate return (1);
3557c478bd9Sstevel@tonic-gate }
3567c478bd9Sstevel@tonic-gate
3577c478bd9Sstevel@tonic-gate
3587c478bd9Sstevel@tonic-gate /*
3597c478bd9Sstevel@tonic-gate * ipcp_init - Initialize IPCP.
3607c478bd9Sstevel@tonic-gate */
3617c478bd9Sstevel@tonic-gate static void
ipcp_init(unit)3627c478bd9Sstevel@tonic-gate ipcp_init(unit)
3637c478bd9Sstevel@tonic-gate int unit;
3647c478bd9Sstevel@tonic-gate {
3657c478bd9Sstevel@tonic-gate fsm *f = &ipcp_fsm[unit];
3667c478bd9Sstevel@tonic-gate ipcp_options *wo = &ipcp_wantoptions[unit];
3677c478bd9Sstevel@tonic-gate ipcp_options *ao = &ipcp_allowoptions[unit];
3687c478bd9Sstevel@tonic-gate
3697c478bd9Sstevel@tonic-gate f->unit = unit;
3707c478bd9Sstevel@tonic-gate f->protocol = PPP_IPCP;
3717c478bd9Sstevel@tonic-gate f->callbacks = &ipcp_callbacks;
3727c478bd9Sstevel@tonic-gate fsm_init(&ipcp_fsm[unit]);
3737c478bd9Sstevel@tonic-gate
3747c478bd9Sstevel@tonic-gate BZERO(wo, sizeof(*wo));
3757c478bd9Sstevel@tonic-gate BZERO(ao, sizeof(*ao));
3767c478bd9Sstevel@tonic-gate
377f53eecf5SJames Carlson wo->neg_addr = wo->old_addrs = 1;
3787c478bd9Sstevel@tonic-gate wo->neg_vj = 1;
3797c478bd9Sstevel@tonic-gate wo->vj_protocol = IPCP_VJ_COMP;
3807c478bd9Sstevel@tonic-gate wo->maxslotindex = MAX_STATES - 1; /* really max index */
3817c478bd9Sstevel@tonic-gate wo->cflag = 1;
3827c478bd9Sstevel@tonic-gate
383f53eecf5SJames Carlson ao->neg_addr = ao->old_addrs = 1;
3847c478bd9Sstevel@tonic-gate ao->neg_vj = 1;
3857c478bd9Sstevel@tonic-gate ao->maxslotindex = MAX_STATES - 1;
3867c478bd9Sstevel@tonic-gate ao->cflag = 1;
3877c478bd9Sstevel@tonic-gate
3887c478bd9Sstevel@tonic-gate /*
3897c478bd9Sstevel@tonic-gate * These aren't actually negotiated. Instead, they control
3907c478bd9Sstevel@tonic-gate * whether the user may use the proxyarp and defaultroute options.
3917c478bd9Sstevel@tonic-gate */
3927c478bd9Sstevel@tonic-gate ao->proxy_arp = 1;
3937c478bd9Sstevel@tonic-gate ao->default_route = 1;
3947c478bd9Sstevel@tonic-gate proxy_arp_quiet[unit] = 0;
3957c478bd9Sstevel@tonic-gate }
3967c478bd9Sstevel@tonic-gate
3977c478bd9Sstevel@tonic-gate
3987c478bd9Sstevel@tonic-gate /*
3997c478bd9Sstevel@tonic-gate * ipcp_open - IPCP is allowed to come up.
4007c478bd9Sstevel@tonic-gate */
4017c478bd9Sstevel@tonic-gate static void
ipcp_open(unit)4027c478bd9Sstevel@tonic-gate ipcp_open(unit)
4037c478bd9Sstevel@tonic-gate int unit;
4047c478bd9Sstevel@tonic-gate {
4057c478bd9Sstevel@tonic-gate fsm_open(&ipcp_fsm[unit]);
4067c478bd9Sstevel@tonic-gate }
4077c478bd9Sstevel@tonic-gate
4087c478bd9Sstevel@tonic-gate
4097c478bd9Sstevel@tonic-gate /*
4107c478bd9Sstevel@tonic-gate * ipcp_close - Take IPCP down.
4117c478bd9Sstevel@tonic-gate */
4127c478bd9Sstevel@tonic-gate static void
ipcp_close(unit,reason)4137c478bd9Sstevel@tonic-gate ipcp_close(unit, reason)
4147c478bd9Sstevel@tonic-gate int unit;
4157c478bd9Sstevel@tonic-gate char *reason;
4167c478bd9Sstevel@tonic-gate {
4177c478bd9Sstevel@tonic-gate fsm_close(&ipcp_fsm[unit], reason);
4187c478bd9Sstevel@tonic-gate }
4197c478bd9Sstevel@tonic-gate
4207c478bd9Sstevel@tonic-gate
4217c478bd9Sstevel@tonic-gate /*
4227c478bd9Sstevel@tonic-gate * ipcp_lowerup - The lower layer is up.
4237c478bd9Sstevel@tonic-gate */
4247c478bd9Sstevel@tonic-gate static void
ipcp_lowerup(unit)4257c478bd9Sstevel@tonic-gate ipcp_lowerup(unit)
4267c478bd9Sstevel@tonic-gate int unit;
4277c478bd9Sstevel@tonic-gate {
4287c478bd9Sstevel@tonic-gate fsm_lowerup(&ipcp_fsm[unit]);
4297c478bd9Sstevel@tonic-gate }
4307c478bd9Sstevel@tonic-gate
4317c478bd9Sstevel@tonic-gate
4327c478bd9Sstevel@tonic-gate /*
4337c478bd9Sstevel@tonic-gate * ipcp_lowerdown - The lower layer is down.
4347c478bd9Sstevel@tonic-gate */
4357c478bd9Sstevel@tonic-gate static void
ipcp_lowerdown(unit)4367c478bd9Sstevel@tonic-gate ipcp_lowerdown(unit)
4377c478bd9Sstevel@tonic-gate int unit;
4387c478bd9Sstevel@tonic-gate {
4397c478bd9Sstevel@tonic-gate fsm_lowerdown(&ipcp_fsm[unit]);
4407c478bd9Sstevel@tonic-gate }
4417c478bd9Sstevel@tonic-gate
4427c478bd9Sstevel@tonic-gate
4437c478bd9Sstevel@tonic-gate /*
4447c478bd9Sstevel@tonic-gate * ipcp_input - Input IPCP packet.
4457c478bd9Sstevel@tonic-gate */
4467c478bd9Sstevel@tonic-gate static void
ipcp_input(unit,p,len)4477c478bd9Sstevel@tonic-gate ipcp_input(unit, p, len)
4487c478bd9Sstevel@tonic-gate int unit;
4497c478bd9Sstevel@tonic-gate u_char *p;
4507c478bd9Sstevel@tonic-gate int len;
4517c478bd9Sstevel@tonic-gate {
4527c478bd9Sstevel@tonic-gate fsm_input(&ipcp_fsm[unit], p, len);
4537c478bd9Sstevel@tonic-gate }
4547c478bd9Sstevel@tonic-gate
4557c478bd9Sstevel@tonic-gate
4567c478bd9Sstevel@tonic-gate /*
4577c478bd9Sstevel@tonic-gate * ipcp_protrej - A Protocol-Reject was received for IPCP.
4587c478bd9Sstevel@tonic-gate */
4597c478bd9Sstevel@tonic-gate static void
ipcp_protrej(unit)4607c478bd9Sstevel@tonic-gate ipcp_protrej(unit)
4617c478bd9Sstevel@tonic-gate int unit;
4627c478bd9Sstevel@tonic-gate {
4637c478bd9Sstevel@tonic-gate fsm_protreject(&ipcp_fsm[unit]);
4647c478bd9Sstevel@tonic-gate }
4657c478bd9Sstevel@tonic-gate
4667c478bd9Sstevel@tonic-gate
4677c478bd9Sstevel@tonic-gate /*
4687c478bd9Sstevel@tonic-gate * ipcp_resetci - Reset our CI.
4697c478bd9Sstevel@tonic-gate * Called by fsm_sconfreq, Send Configure Request.
4707c478bd9Sstevel@tonic-gate */
4717c478bd9Sstevel@tonic-gate static void
ipcp_resetci(f)4727c478bd9Sstevel@tonic-gate ipcp_resetci(f)
4737c478bd9Sstevel@tonic-gate fsm *f;
4747c478bd9Sstevel@tonic-gate {
4757c478bd9Sstevel@tonic-gate ipcp_options *wo = &ipcp_wantoptions[f->unit];
4767c478bd9Sstevel@tonic-gate ipcp_options *go = &ipcp_gotoptions[f->unit];
477f53eecf5SJames Carlson ipcp_options *ao = &ipcp_allowoptions[f->unit];
4787c478bd9Sstevel@tonic-gate
479f53eecf5SJames Carlson wo->req_addr = (wo->neg_addr || wo->old_addrs) &&
480f53eecf5SJames Carlson (ao->neg_addr || ao->old_addrs);
4817c478bd9Sstevel@tonic-gate if (wo->ouraddr == 0 || disable_defaultip)
4827c478bd9Sstevel@tonic-gate wo->accept_local = 1;
4837c478bd9Sstevel@tonic-gate if (wo->hisaddr == 0)
4847c478bd9Sstevel@tonic-gate wo->accept_remote = 1;
4857c478bd9Sstevel@tonic-gate *go = *wo;
4867c478bd9Sstevel@tonic-gate if (disable_defaultip)
4877c478bd9Sstevel@tonic-gate go->ouraddr = 0;
4887c478bd9Sstevel@tonic-gate }
4897c478bd9Sstevel@tonic-gate
4907c478bd9Sstevel@tonic-gate
4917c478bd9Sstevel@tonic-gate /*
4927c478bd9Sstevel@tonic-gate * ipcp_cilen - Return length of our CI.
4937c478bd9Sstevel@tonic-gate * Called by fsm_sconfreq, Send Configure Request.
4947c478bd9Sstevel@tonic-gate */
4957c478bd9Sstevel@tonic-gate static int
ipcp_cilen(f)4967c478bd9Sstevel@tonic-gate ipcp_cilen(f)
4977c478bd9Sstevel@tonic-gate fsm *f;
4987c478bd9Sstevel@tonic-gate {
4997c478bd9Sstevel@tonic-gate ipcp_options *go = &ipcp_gotoptions[f->unit];
5007c478bd9Sstevel@tonic-gate ipcp_options *wo = &ipcp_wantoptions[f->unit];
5017c478bd9Sstevel@tonic-gate ipcp_options *ho = &ipcp_hisoptions[f->unit];
5027c478bd9Sstevel@tonic-gate
503f53eecf5SJames Carlson #define LENCIADDRS(neg) (neg ? CILEN_ADDRS : 0)
5047c478bd9Sstevel@tonic-gate #define LENCIVJ(neg, old) (neg ? (old? CILEN_COMPRESS : CILEN_VJ) : 0)
505f53eecf5SJames Carlson #define LENCIADDR(neg) (neg ? (CILEN_ADDR) : 0)
5067c478bd9Sstevel@tonic-gate
5077c478bd9Sstevel@tonic-gate /*
5087c478bd9Sstevel@tonic-gate * First see if we want to change our options to the old
5097c478bd9Sstevel@tonic-gate * forms because we have received old forms from the peer.
5107c478bd9Sstevel@tonic-gate */
511f53eecf5SJames Carlson if (go->neg_addr && go->old_addrs && !ho->neg_addr && ho->old_addrs)
5127c478bd9Sstevel@tonic-gate /* use the old style of address negotiation */
513f53eecf5SJames Carlson go->neg_addr = 0;
5147c478bd9Sstevel@tonic-gate if (wo->neg_vj && !go->neg_vj && !go->old_vj) {
5157c478bd9Sstevel@tonic-gate /* try an older style of VJ negotiation */
5167c478bd9Sstevel@tonic-gate /* use the old style only if the peer did */
5177c478bd9Sstevel@tonic-gate if (ho->neg_vj && ho->old_vj) {
5187c478bd9Sstevel@tonic-gate go->neg_vj = 1;
5197c478bd9Sstevel@tonic-gate go->old_vj = 1;
5207c478bd9Sstevel@tonic-gate go->vj_protocol = ho->vj_protocol;
5217c478bd9Sstevel@tonic-gate }
5227c478bd9Sstevel@tonic-gate }
5237c478bd9Sstevel@tonic-gate
524f53eecf5SJames Carlson return (LENCIADDRS(!go->neg_addr && go->old_addrs) +
5257c478bd9Sstevel@tonic-gate LENCIVJ(go->neg_vj, go->old_vj) +
526f53eecf5SJames Carlson LENCIADDR(go->neg_addr) +
527f53eecf5SJames Carlson LENCIADDR(go->req_dns1) +
528f53eecf5SJames Carlson LENCIADDR(go->req_dns2)) ;
5297c478bd9Sstevel@tonic-gate }
5307c478bd9Sstevel@tonic-gate
5317c478bd9Sstevel@tonic-gate
5327c478bd9Sstevel@tonic-gate /*
5337c478bd9Sstevel@tonic-gate * ipcp_addci - Add our desired CIs to a packet.
5347c478bd9Sstevel@tonic-gate * Called by fsm_sconfreq, Send Configure Request.
5357c478bd9Sstevel@tonic-gate */
5367c478bd9Sstevel@tonic-gate static void
ipcp_addci(f,ucp,lenp)5377c478bd9Sstevel@tonic-gate ipcp_addci(f, ucp, lenp)
5387c478bd9Sstevel@tonic-gate fsm *f;
5397c478bd9Sstevel@tonic-gate u_char *ucp;
5407c478bd9Sstevel@tonic-gate int *lenp;
5417c478bd9Sstevel@tonic-gate {
5427c478bd9Sstevel@tonic-gate ipcp_options *go = &ipcp_gotoptions[f->unit];
5437c478bd9Sstevel@tonic-gate int len = *lenp;
5447c478bd9Sstevel@tonic-gate
545f53eecf5SJames Carlson #define ADDCIADDRS(opt, neg, val1, val2) \
546f53eecf5SJames Carlson if (neg) { \
547f53eecf5SJames Carlson if (len >= CILEN_ADDRS) { \
548f53eecf5SJames Carlson PUTCHAR(opt, ucp); \
549f53eecf5SJames Carlson PUTCHAR(CILEN_ADDRS, ucp); \
550f53eecf5SJames Carlson PUTNLONG(val1, ucp); \
551f53eecf5SJames Carlson PUTNLONG(val2, ucp); \
552f53eecf5SJames Carlson len -= CILEN_ADDRS; \
553f53eecf5SJames Carlson } else \
554f53eecf5SJames Carlson go->old_addrs = 0; \
555f53eecf5SJames Carlson }
556f53eecf5SJames Carlson
5577c478bd9Sstevel@tonic-gate #define ADDCIVJ(opt, neg, val, old, maxslotindex, cflag) \
5587c478bd9Sstevel@tonic-gate if (neg) { \
5597c478bd9Sstevel@tonic-gate int vjlen = old? CILEN_COMPRESS : CILEN_VJ; \
5607c478bd9Sstevel@tonic-gate if (len >= vjlen) { \
5617c478bd9Sstevel@tonic-gate PUTCHAR(opt, ucp); \
5627c478bd9Sstevel@tonic-gate PUTCHAR(vjlen, ucp); \
5637c478bd9Sstevel@tonic-gate PUTSHORT(val, ucp); \
5647c478bd9Sstevel@tonic-gate if (!old) { \
5657c478bd9Sstevel@tonic-gate PUTCHAR(maxslotindex, ucp); \
5667c478bd9Sstevel@tonic-gate PUTCHAR(cflag, ucp); \
5677c478bd9Sstevel@tonic-gate } \
5687c478bd9Sstevel@tonic-gate len -= vjlen; \
5697c478bd9Sstevel@tonic-gate } else \
5707c478bd9Sstevel@tonic-gate neg = 0; \
5717c478bd9Sstevel@tonic-gate }
5727c478bd9Sstevel@tonic-gate
573f53eecf5SJames Carlson #define ADDCIADDR(opt, neg, val) \
5747c478bd9Sstevel@tonic-gate if (neg) { \
5757c478bd9Sstevel@tonic-gate if (len >= CILEN_ADDR) { \
5767c478bd9Sstevel@tonic-gate PUTCHAR(opt, ucp); \
5777c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_ADDR, ucp); \
578f53eecf5SJames Carlson PUTNLONG(val, ucp); \
5797c478bd9Sstevel@tonic-gate len -= CILEN_ADDR; \
5807c478bd9Sstevel@tonic-gate } else \
5817c478bd9Sstevel@tonic-gate neg = 0; \
5827c478bd9Sstevel@tonic-gate }
5837c478bd9Sstevel@tonic-gate
584f53eecf5SJames Carlson ADDCIADDRS(CI_ADDRS, !go->neg_addr && go->old_addrs, go->ouraddr,
585f53eecf5SJames Carlson go->hisaddr);
5867c478bd9Sstevel@tonic-gate
5877c478bd9Sstevel@tonic-gate ADDCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol, go->old_vj,
5887c478bd9Sstevel@tonic-gate go->maxslotindex, go->cflag);
5897c478bd9Sstevel@tonic-gate
590f53eecf5SJames Carlson ADDCIADDR(CI_ADDR, go->neg_addr, go->ouraddr);
5917c478bd9Sstevel@tonic-gate
592f53eecf5SJames Carlson ADDCIADDR(CI_MS_DNS1, go->req_dns1, go->dnsaddr[0]);
593f53eecf5SJames Carlson
594f53eecf5SJames Carlson ADDCIADDR(CI_MS_DNS2, go->req_dns2, go->dnsaddr[1]);
5957c478bd9Sstevel@tonic-gate
5967c478bd9Sstevel@tonic-gate *lenp -= len;
5977c478bd9Sstevel@tonic-gate }
5987c478bd9Sstevel@tonic-gate
5997c478bd9Sstevel@tonic-gate
6007c478bd9Sstevel@tonic-gate /*
6017c478bd9Sstevel@tonic-gate * ipcp_ackci - Ack our CIs.
6027c478bd9Sstevel@tonic-gate * Called by fsm_rconfack, Receive Configure ACK.
6037c478bd9Sstevel@tonic-gate *
6047c478bd9Sstevel@tonic-gate * Returns:
6057c478bd9Sstevel@tonic-gate * 0 - Ack was bad.
6067c478bd9Sstevel@tonic-gate * 1 - Ack was good.
6077c478bd9Sstevel@tonic-gate */
6087c478bd9Sstevel@tonic-gate static int
ipcp_ackci(f,p,len)6097c478bd9Sstevel@tonic-gate ipcp_ackci(f, p, len)
6107c478bd9Sstevel@tonic-gate fsm *f;
6117c478bd9Sstevel@tonic-gate u_char *p;
6127c478bd9Sstevel@tonic-gate int len;
6137c478bd9Sstevel@tonic-gate {
6147c478bd9Sstevel@tonic-gate ipcp_options *go = &ipcp_gotoptions[f->unit];
6157c478bd9Sstevel@tonic-gate u_short cilen, citype, cishort;
6167c478bd9Sstevel@tonic-gate u_int32_t cilong;
6177c478bd9Sstevel@tonic-gate u_char cimaxslotindex, cicflag;
6187c478bd9Sstevel@tonic-gate
6197c478bd9Sstevel@tonic-gate /*
6207c478bd9Sstevel@tonic-gate * CIs must be in exactly the same order that we sent...
6217c478bd9Sstevel@tonic-gate * Check packet length and CI length at each step.
6227c478bd9Sstevel@tonic-gate * If we find any deviations, then this packet is bad.
6237c478bd9Sstevel@tonic-gate */
6247c478bd9Sstevel@tonic-gate
625f53eecf5SJames Carlson #define ACKCHECK(opt, olen) \
626f53eecf5SJames Carlson if ((len -= olen) < 0) \
6277c478bd9Sstevel@tonic-gate goto bad; \
6287c478bd9Sstevel@tonic-gate GETCHAR(citype, p); \
6297c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); \
630f53eecf5SJames Carlson if (cilen != olen || \
631f53eecf5SJames Carlson citype != opt) \
632f53eecf5SJames Carlson goto bad;
633f53eecf5SJames Carlson
634f53eecf5SJames Carlson #define ACKCIADDRS(opt, neg, val1, val2) \
635f53eecf5SJames Carlson if (neg) { \
636f53eecf5SJames Carlson ACKCHECK(opt, CILEN_ADDRS) \
637f53eecf5SJames Carlson GETNLONG(cilong, p); \
638f53eecf5SJames Carlson if (val1 != cilong) \
6397c478bd9Sstevel@tonic-gate goto bad; \
640f53eecf5SJames Carlson GETNLONG(cilong, p); \
641f53eecf5SJames Carlson if (val2 != cilong) \
642f53eecf5SJames Carlson goto bad; \
643f53eecf5SJames Carlson }
644f53eecf5SJames Carlson
645f53eecf5SJames Carlson #define ACKCIVJ(opt, neg, val, old, maxslotindex, cflag) \
646f53eecf5SJames Carlson if (neg) { \
647f53eecf5SJames Carlson int vjlen = old? CILEN_COMPRESS : CILEN_VJ; \
648f53eecf5SJames Carlson ACKCHECK(opt, vjlen) \
6497c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \
6507c478bd9Sstevel@tonic-gate if (cishort != val) \
6517c478bd9Sstevel@tonic-gate goto bad; \
6527c478bd9Sstevel@tonic-gate if (!old) { \
6537c478bd9Sstevel@tonic-gate GETCHAR(cimaxslotindex, p); \
6547c478bd9Sstevel@tonic-gate if (cimaxslotindex != maxslotindex) \
6557c478bd9Sstevel@tonic-gate goto bad; \
6567c478bd9Sstevel@tonic-gate GETCHAR(cicflag, p); \
6577c478bd9Sstevel@tonic-gate if (cicflag != cflag) \
6587c478bd9Sstevel@tonic-gate goto bad; \
6597c478bd9Sstevel@tonic-gate } \
6607c478bd9Sstevel@tonic-gate }
6617c478bd9Sstevel@tonic-gate
662f53eecf5SJames Carlson #define ACKCIADDR(opt, neg, val) \
6637c478bd9Sstevel@tonic-gate if (neg) { \
664f53eecf5SJames Carlson ACKCHECK(opt, CILEN_ADDR) \
6657c478bd9Sstevel@tonic-gate GETNLONG(cilong, p); \
666f53eecf5SJames Carlson if (val != cilong) \
6677c478bd9Sstevel@tonic-gate goto bad; \
6687c478bd9Sstevel@tonic-gate }
6697c478bd9Sstevel@tonic-gate
670f53eecf5SJames Carlson ACKCIADDRS(CI_ADDRS, !go->neg_addr && go->old_addrs, go->ouraddr,
671f53eecf5SJames Carlson go->hisaddr);
6727c478bd9Sstevel@tonic-gate
6737c478bd9Sstevel@tonic-gate ACKCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol, go->old_vj,
6747c478bd9Sstevel@tonic-gate go->maxslotindex, go->cflag);
6757c478bd9Sstevel@tonic-gate
676f53eecf5SJames Carlson ACKCIADDR(CI_ADDR, go->neg_addr, go->ouraddr);
677f53eecf5SJames Carlson
678f53eecf5SJames Carlson ACKCIADDR(CI_MS_DNS1, go->req_dns1, go->dnsaddr[0]);
6797c478bd9Sstevel@tonic-gate
680f53eecf5SJames Carlson ACKCIADDR(CI_MS_DNS2, go->req_dns2, go->dnsaddr[1]);
6817c478bd9Sstevel@tonic-gate
6827c478bd9Sstevel@tonic-gate /*
6837c478bd9Sstevel@tonic-gate * If there are any remaining CIs, then this packet is bad.
6847c478bd9Sstevel@tonic-gate */
6857c478bd9Sstevel@tonic-gate if (len != 0)
6867c478bd9Sstevel@tonic-gate goto bad;
6877c478bd9Sstevel@tonic-gate return (1);
6887c478bd9Sstevel@tonic-gate
6897c478bd9Sstevel@tonic-gate bad:
6907c478bd9Sstevel@tonic-gate IPCPDEBUG(("ipcp_ackci: received bad Ack!"));
6917c478bd9Sstevel@tonic-gate return (0);
6927c478bd9Sstevel@tonic-gate }
6937c478bd9Sstevel@tonic-gate
6947c478bd9Sstevel@tonic-gate /*
6957c478bd9Sstevel@tonic-gate * ipcp_nakci - Peer has sent a NAK for some of our CIs.
6967c478bd9Sstevel@tonic-gate * This should not modify any state if the Nak is bad
6977c478bd9Sstevel@tonic-gate * or if IPCP is in the OPENED state.
6987c478bd9Sstevel@tonic-gate * Calback from fsm_rconfnakrej - Receive Configure-Nak or Configure-Reject.
6997c478bd9Sstevel@tonic-gate *
7007c478bd9Sstevel@tonic-gate * Returns:
7017c478bd9Sstevel@tonic-gate * 0 - Nak was bad.
7027c478bd9Sstevel@tonic-gate * 1 - Nak was good.
7037c478bd9Sstevel@tonic-gate */
7047c478bd9Sstevel@tonic-gate static int
ipcp_nakci(f,p,len)7057c478bd9Sstevel@tonic-gate ipcp_nakci(f, p, len)
7067c478bd9Sstevel@tonic-gate fsm *f;
7077c478bd9Sstevel@tonic-gate u_char *p;
7087c478bd9Sstevel@tonic-gate int len;
7097c478bd9Sstevel@tonic-gate {
7107c478bd9Sstevel@tonic-gate ipcp_options *go = &ipcp_gotoptions[f->unit];
7117c478bd9Sstevel@tonic-gate u_char cimaxslotindex, cicflag;
7127c478bd9Sstevel@tonic-gate u_char citype, cilen, *next;
7137c478bd9Sstevel@tonic-gate u_short cishort;
714f53eecf5SJames Carlson u_int32_t ciaddr1, ciaddr2;
7157c478bd9Sstevel@tonic-gate ipcp_options no; /* options we've seen Naks for */
7167c478bd9Sstevel@tonic-gate ipcp_options try; /* options to request next time */
7177c478bd9Sstevel@tonic-gate
7187c478bd9Sstevel@tonic-gate BZERO(&no, sizeof(no));
7197c478bd9Sstevel@tonic-gate try = *go;
7207c478bd9Sstevel@tonic-gate
7217c478bd9Sstevel@tonic-gate /*
7227c478bd9Sstevel@tonic-gate * Any Nak'd CIs must be in exactly the same order that we sent.
7237c478bd9Sstevel@tonic-gate * Check packet length and CI length at each step.
7247c478bd9Sstevel@tonic-gate * If we find any deviations, then this packet is bad.
7257c478bd9Sstevel@tonic-gate */
726f53eecf5SJames Carlson #define NAKCIADDRS(opt, neg, code) \
727f53eecf5SJames Carlson if ((neg) && \
728f53eecf5SJames Carlson (cilen = p[1]) == CILEN_ADDRS && \
729f53eecf5SJames Carlson len >= cilen && \
7307c478bd9Sstevel@tonic-gate p[0] == opt) { \
7317c478bd9Sstevel@tonic-gate len -= cilen; \
7327c478bd9Sstevel@tonic-gate INCPTR(2, p); \
7337c478bd9Sstevel@tonic-gate GETNLONG(ciaddr1, p); \
734f53eecf5SJames Carlson GETNLONG(ciaddr2, p); \
735f53eecf5SJames Carlson no.old_addrs = 1; \
7367c478bd9Sstevel@tonic-gate code \
7377c478bd9Sstevel@tonic-gate }
7387c478bd9Sstevel@tonic-gate
7397c478bd9Sstevel@tonic-gate #define NAKCIVJ(opt, neg, code) \
7407c478bd9Sstevel@tonic-gate if (go->neg && \
7417c478bd9Sstevel@tonic-gate ((cilen = p[1]) == CILEN_COMPRESS || cilen == CILEN_VJ) && \
7427c478bd9Sstevel@tonic-gate len >= cilen && \
7437c478bd9Sstevel@tonic-gate p[0] == opt) { \
7447c478bd9Sstevel@tonic-gate len -= cilen; \
7457c478bd9Sstevel@tonic-gate INCPTR(2, p); \
7467c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \
7477c478bd9Sstevel@tonic-gate no.neg = 1; \
7487c478bd9Sstevel@tonic-gate code \
7497c478bd9Sstevel@tonic-gate }
7507c478bd9Sstevel@tonic-gate
751f53eecf5SJames Carlson #define NAKCIADDR(opt, neg, code) \
7527c478bd9Sstevel@tonic-gate if (go->neg && \
753f53eecf5SJames Carlson (cilen = p[1]) == CILEN_ADDR && \
7547c478bd9Sstevel@tonic-gate len >= cilen && \
7557c478bd9Sstevel@tonic-gate p[0] == opt) { \
7567c478bd9Sstevel@tonic-gate len -= cilen; \
7577c478bd9Sstevel@tonic-gate INCPTR(2, p); \
758f53eecf5SJames Carlson GETNLONG(ciaddr1, p); \
7597c478bd9Sstevel@tonic-gate no.neg = 1; \
7607c478bd9Sstevel@tonic-gate code \
7617c478bd9Sstevel@tonic-gate }
7627c478bd9Sstevel@tonic-gate
7637c478bd9Sstevel@tonic-gate /*
764*48bbca81SDaniel Hoffman * Accept the peer's idea of {our,its} address, if different
7657c478bd9Sstevel@tonic-gate * from our idea, only if the accept_{local,remote} flag is set.
7667c478bd9Sstevel@tonic-gate */
767f53eecf5SJames Carlson NAKCIADDRS(CI_ADDRS, !go->neg_addr && go->old_addrs,
7687c478bd9Sstevel@tonic-gate if (go->accept_local && ciaddr1) { /* Do we know our address? */
7697c478bd9Sstevel@tonic-gate try.ouraddr = ciaddr1;
7707c478bd9Sstevel@tonic-gate }
771*48bbca81SDaniel Hoffman if (go->accept_remote && ciaddr2) { /* Does it know its? */
7727c478bd9Sstevel@tonic-gate try.hisaddr = ciaddr2;
7737c478bd9Sstevel@tonic-gate }
7747c478bd9Sstevel@tonic-gate );
7757c478bd9Sstevel@tonic-gate
7767c478bd9Sstevel@tonic-gate /*
7777c478bd9Sstevel@tonic-gate * Accept the peer's value of maxslotindex provided that it
7787c478bd9Sstevel@tonic-gate * is less than what we asked for. Turn off slot-ID compression
7797c478bd9Sstevel@tonic-gate * if the peer wants. Send old-style compress-type option if
7807c478bd9Sstevel@tonic-gate * the peer wants.
7817c478bd9Sstevel@tonic-gate */
7827c478bd9Sstevel@tonic-gate NAKCIVJ(CI_COMPRESSTYPE, neg_vj,
7837c478bd9Sstevel@tonic-gate if (cilen == CILEN_VJ) {
7847c478bd9Sstevel@tonic-gate GETCHAR(cimaxslotindex, p);
7857c478bd9Sstevel@tonic-gate GETCHAR(cicflag, p);
7867c478bd9Sstevel@tonic-gate if (cishort == IPCP_VJ_COMP) {
7877c478bd9Sstevel@tonic-gate try.old_vj = 0;
7887c478bd9Sstevel@tonic-gate if (cimaxslotindex < go->maxslotindex)
7897c478bd9Sstevel@tonic-gate try.maxslotindex = cimaxslotindex;
7907c478bd9Sstevel@tonic-gate if (!cicflag)
7917c478bd9Sstevel@tonic-gate try.cflag = 0;
7927c478bd9Sstevel@tonic-gate } else {
7937c478bd9Sstevel@tonic-gate try.neg_vj = 0;
7947c478bd9Sstevel@tonic-gate }
7957c478bd9Sstevel@tonic-gate } else {
7967c478bd9Sstevel@tonic-gate if (cishort == IPCP_VJ_COMP || cishort == IPCP_VJ_COMP_OLD) {
7977c478bd9Sstevel@tonic-gate try.old_vj = 1;
7987c478bd9Sstevel@tonic-gate try.vj_protocol = cishort;
7997c478bd9Sstevel@tonic-gate } else {
8007c478bd9Sstevel@tonic-gate try.neg_vj = 0;
8017c478bd9Sstevel@tonic-gate }
8027c478bd9Sstevel@tonic-gate }
8037c478bd9Sstevel@tonic-gate );
8047c478bd9Sstevel@tonic-gate
805f53eecf5SJames Carlson NAKCIADDR(CI_ADDR, neg_addr,
806f53eecf5SJames Carlson if (go->accept_local && ciaddr1) { /* Do we know our address? */
807f53eecf5SJames Carlson try.ouraddr = ciaddr1;
808f53eecf5SJames Carlson }
809f53eecf5SJames Carlson );
8107c478bd9Sstevel@tonic-gate
811f53eecf5SJames Carlson NAKCIADDR(CI_MS_DNS1, req_dns1,
812f53eecf5SJames Carlson try.dnsaddr[0] = ciaddr1;
813f53eecf5SJames Carlson );
814f53eecf5SJames Carlson
815f53eecf5SJames Carlson NAKCIADDR(CI_MS_DNS2, req_dns2,
816f53eecf5SJames Carlson try.dnsaddr[1] = ciaddr1;
817f53eecf5SJames Carlson );
8187c478bd9Sstevel@tonic-gate
8197c478bd9Sstevel@tonic-gate /*
8207c478bd9Sstevel@tonic-gate * There may be remaining CIs, if the peer is requesting negotiation
8217c478bd9Sstevel@tonic-gate * on an option that we didn't include in our request packet.
8227c478bd9Sstevel@tonic-gate * If they want to negotiate about IP addresses, we comply.
8237c478bd9Sstevel@tonic-gate * If they want us to ask for compression, we refuse.
8247c478bd9Sstevel@tonic-gate */
8257c478bd9Sstevel@tonic-gate while (len > CILEN_VOID) {
8267c478bd9Sstevel@tonic-gate GETCHAR(citype, p);
8277c478bd9Sstevel@tonic-gate GETCHAR(cilen, p);
8287c478bd9Sstevel@tonic-gate if( (len -= cilen) < 0 )
8297c478bd9Sstevel@tonic-gate goto bad;
8307c478bd9Sstevel@tonic-gate next = p + cilen - 2;
8317c478bd9Sstevel@tonic-gate
8327c478bd9Sstevel@tonic-gate switch (citype) {
8337c478bd9Sstevel@tonic-gate case CI_COMPRESSTYPE:
8347c478bd9Sstevel@tonic-gate if (go->neg_vj || no.neg_vj ||
8357c478bd9Sstevel@tonic-gate (cilen != CILEN_VJ && cilen != CILEN_COMPRESS))
8367c478bd9Sstevel@tonic-gate goto bad;
8377c478bd9Sstevel@tonic-gate no.neg_vj = 1;
8387c478bd9Sstevel@tonic-gate break;
8397c478bd9Sstevel@tonic-gate case CI_ADDRS:
840f53eecf5SJames Carlson if ((!go->neg_addr && go->old_addrs) || no.old_addrs
8417c478bd9Sstevel@tonic-gate || cilen != CILEN_ADDRS)
8427c478bd9Sstevel@tonic-gate goto bad;
8437c478bd9Sstevel@tonic-gate try.neg_addr = 1;
8447c478bd9Sstevel@tonic-gate try.old_addrs = 1;
8457c478bd9Sstevel@tonic-gate GETNLONG(ciaddr1, p);
8467c478bd9Sstevel@tonic-gate if (ciaddr1 && go->accept_local)
8477c478bd9Sstevel@tonic-gate try.ouraddr = ciaddr1;
8487c478bd9Sstevel@tonic-gate GETNLONG(ciaddr2, p);
8497c478bd9Sstevel@tonic-gate if (ciaddr2 && go->accept_remote)
8507c478bd9Sstevel@tonic-gate try.hisaddr = ciaddr2;
8517c478bd9Sstevel@tonic-gate no.old_addrs = 1;
8527c478bd9Sstevel@tonic-gate break;
8537c478bd9Sstevel@tonic-gate case CI_ADDR:
8547c478bd9Sstevel@tonic-gate if (go->neg_addr || no.neg_addr || cilen != CILEN_ADDR)
8557c478bd9Sstevel@tonic-gate goto bad;
8567c478bd9Sstevel@tonic-gate try.old_addrs = 0;
8577c478bd9Sstevel@tonic-gate GETNLONG(ciaddr1, p);
8587c478bd9Sstevel@tonic-gate if (ciaddr1 && go->accept_local)
8597c478bd9Sstevel@tonic-gate try.ouraddr = ciaddr1;
8607c478bd9Sstevel@tonic-gate if (try.ouraddr != 0)
8617c478bd9Sstevel@tonic-gate try.neg_addr = 1;
8627c478bd9Sstevel@tonic-gate no.neg_addr = 1;
8637c478bd9Sstevel@tonic-gate break;
8647c478bd9Sstevel@tonic-gate }
8657c478bd9Sstevel@tonic-gate p = next;
8667c478bd9Sstevel@tonic-gate }
8677c478bd9Sstevel@tonic-gate
8687c478bd9Sstevel@tonic-gate /*
8697c478bd9Sstevel@tonic-gate * OK, the Nak is good. Now we can update state.
8707c478bd9Sstevel@tonic-gate * If there are any remaining options, we ignore them.
8717c478bd9Sstevel@tonic-gate */
8727c478bd9Sstevel@tonic-gate if (f->state != OPENED)
8737c478bd9Sstevel@tonic-gate *go = try;
8747c478bd9Sstevel@tonic-gate
8757c478bd9Sstevel@tonic-gate return 1;
8767c478bd9Sstevel@tonic-gate
8777c478bd9Sstevel@tonic-gate bad:
8787c478bd9Sstevel@tonic-gate IPCPDEBUG(("ipcp_nakci: received bad Nak!"));
8797c478bd9Sstevel@tonic-gate return 0;
8807c478bd9Sstevel@tonic-gate }
8817c478bd9Sstevel@tonic-gate
8827c478bd9Sstevel@tonic-gate
8837c478bd9Sstevel@tonic-gate /*
8847c478bd9Sstevel@tonic-gate * ipcp_rejci - Reject some of our CIs.
8857c478bd9Sstevel@tonic-gate * Callback from fsm_rconfnakrej.
8867c478bd9Sstevel@tonic-gate */
8877c478bd9Sstevel@tonic-gate static int
ipcp_rejci(f,p,len)8887c478bd9Sstevel@tonic-gate ipcp_rejci(f, p, len)
8897c478bd9Sstevel@tonic-gate fsm *f;
8907c478bd9Sstevel@tonic-gate u_char *p;
8917c478bd9Sstevel@tonic-gate int len;
8927c478bd9Sstevel@tonic-gate {
8937c478bd9Sstevel@tonic-gate ipcp_options *go = &ipcp_gotoptions[f->unit];
8947c478bd9Sstevel@tonic-gate u_char cimaxslotindex, ciflag, cilen;
8957c478bd9Sstevel@tonic-gate u_short cishort;
8967c478bd9Sstevel@tonic-gate u_int32_t cilong;
8977c478bd9Sstevel@tonic-gate ipcp_options try; /* options to request next time */
8987c478bd9Sstevel@tonic-gate
8997c478bd9Sstevel@tonic-gate try = *go;
9007c478bd9Sstevel@tonic-gate /*
9017c478bd9Sstevel@tonic-gate * Any Rejected CIs must be in exactly the same order that we sent.
9027c478bd9Sstevel@tonic-gate * Check packet length and CI length at each step.
9037c478bd9Sstevel@tonic-gate * If we find any deviations, then this packet is bad.
9047c478bd9Sstevel@tonic-gate */
905f53eecf5SJames Carlson #define REJCIADDRS(opt, neg, val1, val2) \
906f53eecf5SJames Carlson if ((neg) && \
907f53eecf5SJames Carlson (cilen = p[1]) == CILEN_ADDRS && \
908f53eecf5SJames Carlson len >= cilen && \
9097c478bd9Sstevel@tonic-gate p[0] == opt) { \
9107c478bd9Sstevel@tonic-gate len -= cilen; \
9117c478bd9Sstevel@tonic-gate INCPTR(2, p); \
9127c478bd9Sstevel@tonic-gate GETNLONG(cilong, p); \
9137c478bd9Sstevel@tonic-gate /* Check rejected value. */ \
9147c478bd9Sstevel@tonic-gate if (cilong != val1) \
9157c478bd9Sstevel@tonic-gate goto bad; \
916f53eecf5SJames Carlson GETNLONG(cilong, p); \
917f53eecf5SJames Carlson /* Check rejected value. */ \
918f53eecf5SJames Carlson if (cilong != val2) \
919