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) \
919f53eecf5SJames Carlson goto bad; \
920f53eecf5SJames Carlson try.old_addrs = 0; \
9217c478bd9Sstevel@tonic-gate }
9227c478bd9Sstevel@tonic-gate
9237c478bd9Sstevel@tonic-gate #define REJCIVJ(opt, neg, val, old, maxslot, cflag) \
9247c478bd9Sstevel@tonic-gate if (go->neg && \
9257c478bd9Sstevel@tonic-gate p[1] == (old? CILEN_COMPRESS : CILEN_VJ) && \
9267c478bd9Sstevel@tonic-gate len >= p[1] && \
9277c478bd9Sstevel@tonic-gate p[0] == opt) { \
9287c478bd9Sstevel@tonic-gate len -= p[1]; \
9297c478bd9Sstevel@tonic-gate INCPTR(2, p); \
9307c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \
9317c478bd9Sstevel@tonic-gate /* Check rejected value. */ \
9327c478bd9Sstevel@tonic-gate if (cishort != val) \
9337c478bd9Sstevel@tonic-gate goto bad; \
9347c478bd9Sstevel@tonic-gate if (!old) { \
9357c478bd9Sstevel@tonic-gate GETCHAR(cimaxslotindex, p); \
9367c478bd9Sstevel@tonic-gate if (cimaxslotindex != maxslot) \
9377c478bd9Sstevel@tonic-gate goto bad; \
9387c478bd9Sstevel@tonic-gate GETCHAR(ciflag, p); \
9397c478bd9Sstevel@tonic-gate if (ciflag != cflag) \
9407c478bd9Sstevel@tonic-gate goto bad; \
9417c478bd9Sstevel@tonic-gate } \
9427c478bd9Sstevel@tonic-gate try.neg = 0; \
9437c478bd9Sstevel@tonic-gate }
9447c478bd9Sstevel@tonic-gate
945f53eecf5SJames Carlson #define REJCIADDR(opt, neg, addr) \
9467c478bd9Sstevel@tonic-gate if (go->neg && \
9477c478bd9Sstevel@tonic-gate ((cilen = p[1]) == CILEN_ADDR) && \
9487c478bd9Sstevel@tonic-gate len >= cilen && \
9497c478bd9Sstevel@tonic-gate p[0] == opt) { \
9507c478bd9Sstevel@tonic-gate len -= cilen; \
9517c478bd9Sstevel@tonic-gate INCPTR(2, p); \
9527c478bd9Sstevel@tonic-gate GETNLONG(cilong, p); \
9537c478bd9Sstevel@tonic-gate /* Check rejected value. */ \
954f53eecf5SJames Carlson if (cilong != addr) \
9557c478bd9Sstevel@tonic-gate goto bad; \
9567c478bd9Sstevel@tonic-gate try.neg = 0; \
9577c478bd9Sstevel@tonic-gate }
9587c478bd9Sstevel@tonic-gate
959f53eecf5SJames Carlson REJCIADDRS(CI_ADDRS, !go->neg_addr && go->old_addrs,
960f53eecf5SJames Carlson go->ouraddr, go->hisaddr);
9617c478bd9Sstevel@tonic-gate
9627c478bd9Sstevel@tonic-gate REJCIVJ(CI_COMPRESSTYPE, neg_vj, go->vj_protocol, go->old_vj,
9637c478bd9Sstevel@tonic-gate go->maxslotindex, go->cflag);
9647c478bd9Sstevel@tonic-gate
965f53eecf5SJames Carlson REJCIADDR(CI_ADDR, neg_addr, go->ouraddr);
966f53eecf5SJames Carlson
967f53eecf5SJames Carlson REJCIADDR(CI_MS_DNS1, req_dns1, go->dnsaddr[0]);
9687c478bd9Sstevel@tonic-gate
969f53eecf5SJames Carlson REJCIADDR(CI_MS_DNS2, req_dns2, go->dnsaddr[1]);
9707c478bd9Sstevel@tonic-gate
9717c478bd9Sstevel@tonic-gate /*
9727c478bd9Sstevel@tonic-gate * If there are any remaining CIs, then this packet is bad.
9737c478bd9Sstevel@tonic-gate */
9747c478bd9Sstevel@tonic-gate if (len != 0)
9757c478bd9Sstevel@tonic-gate goto bad;
9767c478bd9Sstevel@tonic-gate /*
9777c478bd9Sstevel@tonic-gate * Now we can update state.
9787c478bd9Sstevel@tonic-gate */
9797c478bd9Sstevel@tonic-gate if (f->state != OPENED)
9807c478bd9Sstevel@tonic-gate *go = try;
9817c478bd9Sstevel@tonic-gate return 1;
9827c478bd9Sstevel@tonic-gate
9837c478bd9Sstevel@tonic-gate bad:
9847c478bd9Sstevel@tonic-gate IPCPDEBUG(("ipcp_rejci: received bad Reject!"));
9857c478bd9Sstevel@tonic-gate return 0;
9867c478bd9Sstevel@tonic-gate }
9877c478bd9Sstevel@tonic-gate
9887c478bd9Sstevel@tonic-gate
9897c478bd9Sstevel@tonic-gate /*
9907c478bd9Sstevel@tonic-gate * ipcp_reqci - Check the peer's requested CIs and send appropriate response.
9917c478bd9Sstevel@tonic-gate * Callback from fsm_rconfreq, Receive Configure Request
9927c478bd9Sstevel@tonic-gate *
9937c478bd9Sstevel@tonic-gate * Returns: CODE_CONFACK, CODE_CONFNAK or CODE_CONFREJ and input
9947c478bd9Sstevel@tonic-gate * packet modified appropriately. If reject_if_disagree is non-zero,
9957c478bd9Sstevel@tonic-gate * doesn't return CODE_CONFNAK; returns CODE_CONFREJ if it can't
9967c478bd9Sstevel@tonic-gate * return CODE_CONFACK.
9977c478bd9Sstevel@tonic-gate */
9987c478bd9Sstevel@tonic-gate static int
ipcp_reqci(f,p,lenp,dont_nak)9997c478bd9Sstevel@tonic-gate ipcp_reqci(f, p, lenp, dont_nak)
10007c478bd9Sstevel@tonic-gate fsm *f;
10017c478bd9Sstevel@tonic-gate u_char *p; /* Requested CIs */
10027c478bd9Sstevel@tonic-gate int *lenp; /* Length of requested CIs */
10037c478bd9Sstevel@tonic-gate bool dont_nak;
10047c478bd9Sstevel@tonic-gate {
10057c478bd9Sstevel@tonic-gate ipcp_options *wo = &ipcp_wantoptions[f->unit];
10067c478bd9Sstevel@tonic-gate ipcp_options *ho = &ipcp_hisoptions[f->unit];
10077c478bd9Sstevel@tonic-gate ipcp_options *ao = &ipcp_allowoptions[f->unit];
10087c478bd9Sstevel@tonic-gate ipcp_options *go = &ipcp_gotoptions[f->unit];
10097c478bd9Sstevel@tonic-gate int ret, newret;
10107c478bd9Sstevel@tonic-gate u_char *p0, *nakp, *rejp, *prev;
10117c478bd9Sstevel@tonic-gate u_short cishort;
10127c478bd9Sstevel@tonic-gate int len, cilen, type;
10137c478bd9Sstevel@tonic-gate u_int32_t tl, ciaddr1, ciaddr2; /* Parsed address values */
10147c478bd9Sstevel@tonic-gate u_char maxslotindex, cflag;
10157c478bd9Sstevel@tonic-gate int d;
10167c478bd9Sstevel@tonic-gate
10177c478bd9Sstevel@tonic-gate ret = CODE_CONFACK;
10187c478bd9Sstevel@tonic-gate rejp = p0 = p;
10197c478bd9Sstevel@tonic-gate nakp = nak_buffer;
10207c478bd9Sstevel@tonic-gate
10217c478bd9Sstevel@tonic-gate /*
1022*48bbca81SDaniel Hoffman * Reset all its options.
10237c478bd9Sstevel@tonic-gate */
10247c478bd9Sstevel@tonic-gate BZERO(ho, sizeof(*ho));
10257c478bd9Sstevel@tonic-gate
10267c478bd9Sstevel@tonic-gate /*
1027*48bbca81SDaniel Hoffman * Process all its options.
10287c478bd9Sstevel@tonic-gate */
10297c478bd9Sstevel@tonic-gate for (len = *lenp; len > 0; len -= cilen, p = prev + cilen) {
10307c478bd9Sstevel@tonic-gate if ((len < 2) || p[1] > len) {
10317c478bd9Sstevel@tonic-gate /*
10327c478bd9Sstevel@tonic-gate * RFC 1661 page 40 -- if the option extends beyond the
10337c478bd9Sstevel@tonic-gate * packet, then discard the entire packet.
10347c478bd9Sstevel@tonic-gate */
10357c478bd9Sstevel@tonic-gate return (0);
10367c478bd9Sstevel@tonic-gate }
10377c478bd9Sstevel@tonic-gate
10387c478bd9Sstevel@tonic-gate newret = CODE_CONFACK;
10397c478bd9Sstevel@tonic-gate prev = p;
10407c478bd9Sstevel@tonic-gate GETCHAR(type, p);
10417c478bd9Sstevel@tonic-gate GETCHAR(cilen, p);
10427c478bd9Sstevel@tonic-gate
10437c478bd9Sstevel@tonic-gate switch (type) { /* Check CI type */
10447c478bd9Sstevel@tonic-gate case CI_ADDRS:
1045f53eecf5SJames Carlson if (!ao->old_addrs || ho->neg_addr) {
10467c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ;
10477c478bd9Sstevel@tonic-gate break;
10487c478bd9Sstevel@tonic-gate }
10497c478bd9Sstevel@tonic-gate
10507c478bd9Sstevel@tonic-gate if (cilen != CILEN_ADDRS) {
10517c478bd9Sstevel@tonic-gate /*
10527c478bd9Sstevel@tonic-gate * rfc1661, page 40 -- a recongnized option with an
10537c478bd9Sstevel@tonic-gate * invalid length should be Nak'ed.
10547c478bd9Sstevel@tonic-gate */
10557c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
10567c478bd9Sstevel@tonic-gate ciaddr1 = wo->hisaddr;
10577c478bd9Sstevel@tonic-gate ciaddr2 = wo->ouraddr;
10587c478bd9Sstevel@tonic-gate } else {
10597c478bd9Sstevel@tonic-gate
10607c478bd9Sstevel@tonic-gate /*
1061*48bbca81SDaniel Hoffman * If it has no address, or if we both have its
10627c478bd9Sstevel@tonic-gate * address but disagree about it, then NAK it with our
1063*48bbca81SDaniel Hoffman * idea. In particular, if we don't know its address,
1064*48bbca81SDaniel Hoffman * but it does, then accept it.
10657c478bd9Sstevel@tonic-gate */
10667c478bd9Sstevel@tonic-gate GETNLONG(ciaddr1, p);
10677c478bd9Sstevel@tonic-gate if (ciaddr1 != wo->hisaddr &&
10687c478bd9Sstevel@tonic-gate (ciaddr1 == 0 || !wo->accept_remote)) {
10697c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
10707c478bd9Sstevel@tonic-gate ciaddr1 = wo->hisaddr;
10717c478bd9Sstevel@tonic-gate } else if (ciaddr1 == 0 && wo->hisaddr == 0) {
10727c478bd9Sstevel@tonic-gate /*
10737c478bd9Sstevel@tonic-gate * If neither we nor he knows his address, reject
10747c478bd9Sstevel@tonic-gate * the option.
10757c478bd9Sstevel@tonic-gate */
10767c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ;
10777c478bd9Sstevel@tonic-gate wo->req_addr = 0; /* don't NAK with 0.0.0.0 later */
10787c478bd9Sstevel@tonic-gate break;
10797c478bd9Sstevel@tonic-gate } else if (ciaddr1 != 0) {
10807c478bd9Sstevel@tonic-gate go->hisaddr = ciaddr1;
10817c478bd9Sstevel@tonic-gate }
10827c478bd9Sstevel@tonic-gate
10837c478bd9Sstevel@tonic-gate /*
10847c478bd9Sstevel@tonic-gate * If he doesn't know our address, or if we both have
10857c478bd9Sstevel@tonic-gate * our address * but disagree about it, then NAK it
10867c478bd9Sstevel@tonic-gate * with our idea.
10877c478bd9Sstevel@tonic-gate */
10887c478bd9Sstevel@tonic-gate GETNLONG(ciaddr2, p);
10897c478bd9Sstevel@tonic-gate if (ciaddr2 != wo->ouraddr) {
10907c478bd9Sstevel@tonic-gate if (ciaddr2 == 0 || !wo->accept_local) {
10917c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
10927c478bd9Sstevel@tonic-gate ciaddr2 = wo->ouraddr;
10937c478bd9Sstevel@tonic-gate } else {
10947c478bd9Sstevel@tonic-gate go->ouraddr = ciaddr2; /* accept peer's idea */
10957c478bd9Sstevel@tonic-gate }
10967c478bd9Sstevel@tonic-gate }
10977c478bd9Sstevel@tonic-gate }
10987c478bd9Sstevel@tonic-gate
10997c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK) {
11007c478bd9Sstevel@tonic-gate PUTCHAR(type, nakp);
11017c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_ADDRS, nakp);
11027c478bd9Sstevel@tonic-gate PUTNLONG(ciaddr1, nakp);
11037c478bd9Sstevel@tonic-gate PUTNLONG(ciaddr2, nakp);
11047c478bd9Sstevel@tonic-gate }
11057c478bd9Sstevel@tonic-gate
11067c478bd9Sstevel@tonic-gate ho->old_addrs = 1;
11077c478bd9Sstevel@tonic-gate ho->hisaddr = ciaddr1;
11087c478bd9Sstevel@tonic-gate ho->ouraddr = ciaddr2;
11097c478bd9Sstevel@tonic-gate break;
11107c478bd9Sstevel@tonic-gate
11117c478bd9Sstevel@tonic-gate case CI_ADDR:
1112f53eecf5SJames Carlson if (!ao->neg_addr || ho->old_addrs) {
11137c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ;
11147c478bd9Sstevel@tonic-gate break;
11157c478bd9Sstevel@tonic-gate }
11167c478bd9Sstevel@tonic-gate
11177c478bd9Sstevel@tonic-gate if (cilen != CILEN_ADDR) {
11187c478bd9Sstevel@tonic-gate /*
11197c478bd9Sstevel@tonic-gate * rfc1661, page 40 -- a recongnized option with an
11207c478bd9Sstevel@tonic-gate * invalid length should be Nak'ed.
11217c478bd9Sstevel@tonic-gate */
11227c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
11237c478bd9Sstevel@tonic-gate ciaddr1 = wo->hisaddr;
11247c478bd9Sstevel@tonic-gate } else {
11257c478bd9Sstevel@tonic-gate
11267c478bd9Sstevel@tonic-gate /*
11277c478bd9Sstevel@tonic-gate * If he has no address, or if we both have his
11287c478bd9Sstevel@tonic-gate * address but disagree about it, then NAK it with our
11297c478bd9Sstevel@tonic-gate * idea. In particular, if we don't know his address,
11307c478bd9Sstevel@tonic-gate * but he does, then accept it.
11317c478bd9Sstevel@tonic-gate */
11327c478bd9Sstevel@tonic-gate GETNLONG(ciaddr1, p);
11337c478bd9Sstevel@tonic-gate if (ciaddr1 != wo->hisaddr &&
11347c478bd9Sstevel@tonic-gate (ciaddr1 == 0 || !wo->accept_remote)) {
11357c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
11367c478bd9Sstevel@tonic-gate ciaddr1 = wo->hisaddr;
11377c478bd9Sstevel@tonic-gate } else if (ciaddr1 == 0 && wo->hisaddr == 0 &&
11387c478bd9Sstevel@tonic-gate wo->default_route != 0) {
11397c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
11407c478bd9Sstevel@tonic-gate /*
11417c478bd9Sstevel@tonic-gate * If this is a dialup line (default_route is
1142*48bbca81SDaniel Hoffman * set), and neither side knows about its address,
11437c478bd9Sstevel@tonic-gate * suggest an arbitrary rfc1918 address.
11447c478bd9Sstevel@tonic-gate */
11457c478bd9Sstevel@tonic-gate ciaddr1 = htonl(0xc0a80101 + ifunit);
11467c478bd9Sstevel@tonic-gate dbglog("Peer address unknown; suggesting %I", ciaddr1);
11477c478bd9Sstevel@tonic-gate } else if (ciaddr1 == 0 && wo->hisaddr == 0) {
11487c478bd9Sstevel@tonic-gate /*
11497c478bd9Sstevel@tonic-gate * If this is not a dialup line, don't ACK an
11507c478bd9Sstevel@tonic-gate * address of 0.0.0.0 - reject it instead.
11517c478bd9Sstevel@tonic-gate */
11527c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ;
11537c478bd9Sstevel@tonic-gate wo->req_addr = 0; /* don't NAK with 0.0.0.0 later */
11547c478bd9Sstevel@tonic-gate break;
11557c478bd9Sstevel@tonic-gate }
11567c478bd9Sstevel@tonic-gate }
11577c478bd9Sstevel@tonic-gate
11587c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK) {
11597c478bd9Sstevel@tonic-gate PUTCHAR(type, nakp);
11607c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_ADDR, nakp);
11617c478bd9Sstevel@tonic-gate PUTNLONG(ciaddr1, nakp);
11627c478bd9Sstevel@tonic-gate }
11637c478bd9Sstevel@tonic-gate
11647c478bd9Sstevel@tonic-gate ho->neg_addr = 1;
11657c478bd9Sstevel@tonic-gate ho->hisaddr = ciaddr1;
11667c478bd9Sstevel@tonic-gate break;
11677c478bd9Sstevel@tonic-gate
11687c478bd9Sstevel@tonic-gate case CI_MS_DNS1:
11697c478bd9Sstevel@tonic-gate case CI_MS_DNS2:
11707c478bd9Sstevel@tonic-gate /* Warning -- these options work backwards. */
11717c478bd9Sstevel@tonic-gate /* Microsoft primary or secondary DNS request */
11727c478bd9Sstevel@tonic-gate d = (type == CI_MS_DNS2 ? 1 : 0);
11737c478bd9Sstevel@tonic-gate
11747c478bd9Sstevel@tonic-gate if (ao->dnsaddr[d] == 0) {
11757c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ;
11767c478bd9Sstevel@tonic-gate break;
11777c478bd9Sstevel@tonic-gate }
11787c478bd9Sstevel@tonic-gate
11797c478bd9Sstevel@tonic-gate if (cilen != CILEN_ADDR) {
11807c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
11817c478bd9Sstevel@tonic-gate } else {
11827c478bd9Sstevel@tonic-gate GETNLONG(tl, p);
11837c478bd9Sstevel@tonic-gate if (tl != ao->dnsaddr[d]) {
11847c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
11857c478bd9Sstevel@tonic-gate }
11867c478bd9Sstevel@tonic-gate }
11877c478bd9Sstevel@tonic-gate
11887c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK) {
11897c478bd9Sstevel@tonic-gate PUTCHAR(type, nakp);
11907c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_ADDR, nakp);
11917c478bd9Sstevel@tonic-gate PUTNLONG(ao->dnsaddr[d], nakp);
11927c478bd9Sstevel@tonic-gate }
11937c478bd9Sstevel@tonic-gate break;
11947c478bd9Sstevel@tonic-gate
11957c478bd9Sstevel@tonic-gate case CI_MS_WINS1:
11967c478bd9Sstevel@tonic-gate case CI_MS_WINS2:
11977c478bd9Sstevel@tonic-gate /* Warning -- these options work backwards. */
11987c478bd9Sstevel@tonic-gate /* Microsoft primary or secondary WINS request */
11997c478bd9Sstevel@tonic-gate d = (type == CI_MS_WINS2 ? 1 : 0);
12007c478bd9Sstevel@tonic-gate
12017c478bd9Sstevel@tonic-gate if (ao->winsaddr[d] == 0) {
12027c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ;
12037c478bd9Sstevel@tonic-gate break;
12047c478bd9Sstevel@tonic-gate }
12057c478bd9Sstevel@tonic-gate
12067c478bd9Sstevel@tonic-gate if (cilen != CILEN_ADDR) {
12077c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
12087c478bd9Sstevel@tonic-gate } else {
12097c478bd9Sstevel@tonic-gate GETNLONG(tl, p);
12107c478bd9Sstevel@tonic-gate if (tl != ao->winsaddr[d]) {
12117c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
12127c478bd9Sstevel@tonic-gate }
12137c478bd9Sstevel@tonic-gate }
12147c478bd9Sstevel@tonic-gate
12157c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK) {
12167c478bd9Sstevel@tonic-gate PUTCHAR(type, nakp);
12177c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_ADDR, nakp);
12187c478bd9Sstevel@tonic-gate PUTNLONG(ao->winsaddr[d], nakp);
12197c478bd9Sstevel@tonic-gate }
12207c478bd9Sstevel@tonic-gate break;
1221*48bbca81SDaniel Hoffman
12227c478bd9Sstevel@tonic-gate case CI_COMPRESSTYPE:
12237c478bd9Sstevel@tonic-gate if (!ao->neg_vj) {
12247c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ;
12257c478bd9Sstevel@tonic-gate break;
12267c478bd9Sstevel@tonic-gate }
12277c478bd9Sstevel@tonic-gate
12287c478bd9Sstevel@tonic-gate maxslotindex = ao->maxslotindex;
12297c478bd9Sstevel@tonic-gate cflag = ao->cflag;
12307c478bd9Sstevel@tonic-gate if (cilen != CILEN_VJ && cilen != CILEN_COMPRESS) {
12317c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
12327c478bd9Sstevel@tonic-gate cishort = IPCP_VJ_COMP;
12337c478bd9Sstevel@tonic-gate } else {
12347c478bd9Sstevel@tonic-gate GETSHORT(cishort, p);
12357c478bd9Sstevel@tonic-gate if (cishort != IPCP_VJ_COMP &&
12367c478bd9Sstevel@tonic-gate (cishort != IPCP_VJ_COMP_OLD || cilen != CILEN_COMPRESS)) {
12377c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
12387c478bd9Sstevel@tonic-gate cishort = IPCP_VJ_COMP;
12397c478bd9Sstevel@tonic-gate } else if (cilen == CILEN_VJ) {
12407c478bd9Sstevel@tonic-gate GETCHAR(maxslotindex, p);
12417c478bd9Sstevel@tonic-gate if (maxslotindex > ao->maxslotindex) {
12427c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
12437c478bd9Sstevel@tonic-gate maxslotindex = ao->maxslotindex;
12447c478bd9Sstevel@tonic-gate }
12457c478bd9Sstevel@tonic-gate GETCHAR(cflag, p);
12467c478bd9Sstevel@tonic-gate if (cflag != 0 && ao->cflag == 0) {
12477c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
12487c478bd9Sstevel@tonic-gate cflag = 0;
12497c478bd9Sstevel@tonic-gate }
12507c478bd9Sstevel@tonic-gate } else {
12517c478bd9Sstevel@tonic-gate ho->old_vj = 1;
12527c478bd9Sstevel@tonic-gate maxslotindex = MAX_STATES - 1;
12537c478bd9Sstevel@tonic-gate cflag = 1;
12547c478bd9Sstevel@tonic-gate }
12557c478bd9Sstevel@tonic-gate }
12567c478bd9Sstevel@tonic-gate
12577c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK) {
12587c478bd9Sstevel@tonic-gate PUTCHAR(type, nakp);
12597c478bd9Sstevel@tonic-gate if (cishort == IPCP_VJ_COMP) {
12607c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_VJ, nakp);
12617c478bd9Sstevel@tonic-gate PUTSHORT(cishort, nakp);
12627c478bd9Sstevel@tonic-gate PUTCHAR(maxslotindex, nakp);
12637c478bd9Sstevel@tonic-gate PUTCHAR(cflag, nakp);
12647c478bd9Sstevel@tonic-gate } else {
12657c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_COMPRESS, nakp);
12667c478bd9Sstevel@tonic-gate PUTSHORT(cishort, nakp);
12677c478bd9Sstevel@tonic-gate }
12687c478bd9Sstevel@tonic-gate }
12697c478bd9Sstevel@tonic-gate ho->neg_vj = 1;
12707c478bd9Sstevel@tonic-gate ho->vj_protocol = cishort;
12717c478bd9Sstevel@tonic-gate ho->maxslotindex = maxslotindex;
12727c478bd9Sstevel@tonic-gate ho->cflag = cflag;
12737c478bd9Sstevel@tonic-gate break;
12747c478bd9Sstevel@tonic-gate
12757c478bd9Sstevel@tonic-gate default:
12767c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ;
12777c478bd9Sstevel@tonic-gate break;
12787c478bd9Sstevel@tonic-gate }
12797c478bd9Sstevel@tonic-gate
12807c478bd9Sstevel@tonic-gate /* Cope with confused peers. */
12817c478bd9Sstevel@tonic-gate if (cilen < 2)
12827c478bd9Sstevel@tonic-gate cilen = 2;
12837c478bd9Sstevel@tonic-gate
12847c478bd9Sstevel@tonic-gate /*
12857c478bd9Sstevel@tonic-gate * If this is an Ack'able CI, but we're sending back a Nak,
12867c478bd9Sstevel@tonic-gate * don't include this CI.
12877c478bd9Sstevel@tonic-gate */
12887c478bd9Sstevel@tonic-gate if (newret == CODE_CONFACK && ret != CODE_CONFACK)
12897c478bd9Sstevel@tonic-gate continue;
12907c478bd9Sstevel@tonic-gate
12917c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK) {
12927c478bd9Sstevel@tonic-gate if (dont_nak) {
12937c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ;
12947c478bd9Sstevel@tonic-gate } else {
12957c478bd9Sstevel@tonic-gate /* Ignore subsequent Nak'able things if rejecting. */
12967c478bd9Sstevel@tonic-gate if (ret == CODE_CONFREJ)
12977c478bd9Sstevel@tonic-gate continue;
12987c478bd9Sstevel@tonic-gate ret = CODE_CONFNAK;
12997c478bd9Sstevel@tonic-gate }
13007c478bd9Sstevel@tonic-gate }
13017c478bd9Sstevel@tonic-gate
13027c478bd9Sstevel@tonic-gate if (newret == CODE_CONFREJ) {
13037c478bd9Sstevel@tonic-gate ret = CODE_CONFREJ;
13047c478bd9Sstevel@tonic-gate if (prev != rejp)
13057c478bd9Sstevel@tonic-gate BCOPY(prev, rejp, cilen);
13067c478bd9Sstevel@tonic-gate rejp += cilen;
13077c478bd9Sstevel@tonic-gate }
13087c478bd9Sstevel@tonic-gate }
13097c478bd9Sstevel@tonic-gate
13107c478bd9Sstevel@tonic-gate /*
13117c478bd9Sstevel@tonic-gate * If we aren't rejecting this packet, and we want to negotiate
13127c478bd9Sstevel@tonic-gate * their address, and they didn't send their address, then we
13137c478bd9Sstevel@tonic-gate * send a NAK with a CI_ADDR option appended. We assume the
13147c478bd9Sstevel@tonic-gate * input buffer is long enough that we can append the extra
13157c478bd9Sstevel@tonic-gate * option safely.
13167c478bd9Sstevel@tonic-gate */
1317f53eecf5SJames Carlson if (ret != CODE_CONFREJ && !ho->neg_addr && !ho->old_addrs &&
1318f53eecf5SJames Carlson wo->req_addr && !dont_nak) {
13197c478bd9Sstevel@tonic-gate if (ret == CODE_CONFACK)
13207c478bd9Sstevel@tonic-gate wo->req_addr = 0; /* don't ask again */
13217c478bd9Sstevel@tonic-gate ret = CODE_CONFNAK;
13227c478bd9Sstevel@tonic-gate PUTCHAR(CI_ADDR, nakp);
13237c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_ADDR, nakp);
13247c478bd9Sstevel@tonic-gate PUTNLONG(wo->hisaddr, nakp);
13257c478bd9Sstevel@tonic-gate }
13267c478bd9Sstevel@tonic-gate
13277c478bd9Sstevel@tonic-gate switch (ret) {
13287c478bd9Sstevel@tonic-gate case CODE_CONFACK:
13297c478bd9Sstevel@tonic-gate *lenp = p - p0;
1330*48bbca81SDaniel Hoffman sys_block_proto(PPP_IP);
13317c478bd9Sstevel@tonic-gate break;
13327c478bd9Sstevel@tonic-gate case CODE_CONFNAK:
13337c478bd9Sstevel@tonic-gate *lenp = nakp - nak_buffer;
13347c478bd9Sstevel@tonic-gate BCOPY(nak_buffer, p0, *lenp);
13357c478bd9Sstevel@tonic-gate break;
13367c478bd9Sstevel@tonic-gate case CODE_CONFREJ:
13377c478bd9Sstevel@tonic-gate *lenp = rejp - p0;
13387c478bd9Sstevel@tonic-gate break;
13397c478bd9Sstevel@tonic-gate }
13407c478bd9Sstevel@tonic-gate
13417c478bd9Sstevel@tonic-gate return (ret); /* Return final code */
13427c478bd9Sstevel@tonic-gate }
13437c478bd9Sstevel@tonic-gate
13447c478bd9Sstevel@tonic-gate
13457c478bd9Sstevel@tonic-gate /*
13467c478bd9Sstevel@tonic-gate * ip_check_options - check that any IP-related options are OK,
13477c478bd9Sstevel@tonic-gate * and assign appropriate defaults.
13487c478bd9Sstevel@tonic-gate */
13497c478bd9Sstevel@tonic-gate static void
ip_check_options()13507c478bd9Sstevel@tonic-gate ip_check_options()
13517c478bd9Sstevel@tonic-gate {
13527c478bd9Sstevel@tonic-gate struct hostent *hp;
13537c478bd9Sstevel@tonic-gate u_int32_t local;
13547c478bd9Sstevel@tonic-gate ipcp_options *wo = &ipcp_wantoptions[0];
13557c478bd9Sstevel@tonic-gate
13567c478bd9Sstevel@tonic-gate /*
13577c478bd9Sstevel@tonic-gate * Default our local IP address based on our hostname.
13587c478bd9Sstevel@tonic-gate * If local IP address already given, don't bother.
13597c478bd9Sstevel@tonic-gate */
13607c478bd9Sstevel@tonic-gate if (wo->ouraddr == 0) {
13617c478bd9Sstevel@tonic-gate /*
13627c478bd9Sstevel@tonic-gate * Look up our hostname (possibly with domain name appended)
13637c478bd9Sstevel@tonic-gate * and take the first IP address as our local IP address.
13647c478bd9Sstevel@tonic-gate * If there isn't an IP address for our hostname, too bad.
13657c478bd9Sstevel@tonic-gate */
13667c478bd9Sstevel@tonic-gate wo->accept_local = 1; /* don't insist on this default value */
13677c478bd9Sstevel@tonic-gate if ((hp = gethostbyname(hostname)) != NULL) {
13687c478bd9Sstevel@tonic-gate BCOPY(hp->h_addr, &local, sizeof (hp->h_addr));
13697c478bd9Sstevel@tonic-gate if (local != 0 && !bad_ip_adrs(local)) {
13707c478bd9Sstevel@tonic-gate wo->ouraddr = local;
13717c478bd9Sstevel@tonic-gate ipcp_from_hostname = 1;
13727c478bd9Sstevel@tonic-gate }
13737c478bd9Sstevel@tonic-gate }
13747c478bd9Sstevel@tonic-gate }
13757c478bd9Sstevel@tonic-gate }
13767c478bd9Sstevel@tonic-gate
13777c478bd9Sstevel@tonic-gate
13787c478bd9Sstevel@tonic-gate /*
13797c478bd9Sstevel@tonic-gate * ip_demand_conf - configure the interface as though
13807c478bd9Sstevel@tonic-gate * IPCP were up, for use with dial-on-demand.
13817c478bd9Sstevel@tonic-gate */
13827c478bd9Sstevel@tonic-gate static int
ip_demand_conf(u)13837c478bd9Sstevel@tonic-gate ip_demand_conf(u)
13847c478bd9Sstevel@tonic-gate int u;
13857c478bd9Sstevel@tonic-gate {
13867c478bd9Sstevel@tonic-gate ipcp_options *wo = &ipcp_wantoptions[u];
13877c478bd9Sstevel@tonic-gate
13887c478bd9Sstevel@tonic-gate if (wo->hisaddr == 0) {
13897c478bd9Sstevel@tonic-gate /* make up an arbitrary address for the peer */
13907c478bd9Sstevel@tonic-gate wo->hisaddr = htonl(0x0a707070 + ifunit);
13917c478bd9Sstevel@tonic-gate wo->accept_remote = 1;
13927c478bd9Sstevel@tonic-gate }
13937c478bd9Sstevel@tonic-gate if (wo->ouraddr == 0) {
13947c478bd9Sstevel@tonic-gate /* make up an arbitrary address for us */
13957c478bd9Sstevel@tonic-gate wo->ouraddr = htonl(0x0a404040 + ifunit);
13967c478bd9Sstevel@tonic-gate wo->accept_local = 1;
13977c478bd9Sstevel@tonic-gate disable_defaultip = 1; /* don't tell the peer this address */
13987c478bd9Sstevel@tonic-gate }
13997c478bd9Sstevel@tonic-gate if (!sifaddr(u, wo->ouraddr, wo->hisaddr, GetMask(wo->ouraddr)))
14007c478bd9Sstevel@tonic-gate return 0;
14017c478bd9Sstevel@tonic-gate if (!sifup(u))
14027c478bd9Sstevel@tonic-gate return 0;
14037c478bd9Sstevel@tonic-gate if (!sifnpmode(u, PPP_IP, NPMODE_QUEUE))
14047c478bd9Sstevel@tonic-gate return 0;
14057c478bd9Sstevel@tonic-gate if (wo->default_route && sifdefaultroute(u, wo->ouraddr, wo->hisaddr))
14067c478bd9Sstevel@tonic-gate default_route_set[u] = 1;
14077c478bd9Sstevel@tonic-gate if (wo->proxy_arp && sifproxyarp(u, wo->hisaddr, proxy_arp_quiet[u]))
14087c478bd9Sstevel@tonic-gate proxy_arp_set[u] = 1;
14097c478bd9Sstevel@tonic-gate
14107c478bd9Sstevel@tonic-gate notice("local IP address %I", wo->ouraddr);
14117c478bd9Sstevel@tonic-gate notice("remote IP address %I", wo->hisaddr);
14127c478bd9Sstevel@tonic-gate
14137c478bd9Sstevel@tonic-gate return 1;
14147c478bd9Sstevel@tonic-gate }
14157c478bd9Sstevel@tonic-gate
14167c478bd9Sstevel@tonic-gate
14177c478bd9Sstevel@tonic-gate /*
14187c478bd9Sstevel@tonic-gate * ipcp_up - IPCP has come UP.
14197c478bd9Sstevel@tonic-gate *
14207c478bd9Sstevel@tonic-gate * Configure the IP network interface appropriately and bring it up.
14217c478bd9Sstevel@tonic-gate */
14227c478bd9Sstevel@tonic-gate static void
ipcp_up(f)14237c478bd9Sstevel@tonic-gate ipcp_up(f)
14247c478bd9Sstevel@tonic-gate fsm *f;
14257c478bd9Sstevel@tonic-gate {
14267c478bd9Sstevel@tonic-gate u_int32_t mask;
14277c478bd9Sstevel@tonic-gate ipcp_options *ho = &ipcp_hisoptions[f->unit];
14287c478bd9Sstevel@tonic-gate ipcp_options *go = &ipcp_gotoptions[f->unit];
14297c478bd9Sstevel@tonic-gate ipcp_options *wo = &ipcp_wantoptions[f->unit];
14307c478bd9Sstevel@tonic-gate
14317c478bd9Sstevel@tonic-gate IPCPDEBUG(("ipcp: up"));
14327c478bd9Sstevel@tonic-gate
14337c478bd9Sstevel@tonic-gate /*
14347c478bd9Sstevel@tonic-gate * We must have a non-zero IP address for both ends of the link.
14357c478bd9Sstevel@tonic-gate */
14367c478bd9Sstevel@tonic-gate if (ho->hisaddr == 0)
14377c478bd9Sstevel@tonic-gate ho->hisaddr = wo->hisaddr;
14387c478bd9Sstevel@tonic-gate
14397c478bd9Sstevel@tonic-gate if (ho->hisaddr == 0) {
14407c478bd9Sstevel@tonic-gate if (wo->accept_remote) {
14417c478bd9Sstevel@tonic-gate /* Pick some rfc1918 address. */
14427c478bd9Sstevel@tonic-gate ho->hisaddr = htonl(0xc0a80101 + ifunit);
14437c478bd9Sstevel@tonic-gate dbglog("Peer refused to provide his address; assuming %I",
14447c478bd9Sstevel@tonic-gate ho->hisaddr);
14457c478bd9Sstevel@tonic-gate } else {
14467c478bd9Sstevel@tonic-gate error("Could not determine remote IP address");
14477c478bd9Sstevel@tonic-gate ipcp_close(f->unit, "Could not determine remote IP address");
14487c478bd9Sstevel@tonic-gate return;
14497c478bd9Sstevel@tonic-gate }
14507c478bd9Sstevel@tonic-gate }
14517c478bd9Sstevel@tonic-gate if (go->ouraddr == 0) {
14527c478bd9Sstevel@tonic-gate error("Could not determine local IP address");
14537c478bd9Sstevel@tonic-gate ipcp_close(f->unit, "Could not determine local IP address");
14547c478bd9Sstevel@tonic-gate return;
14557c478bd9Sstevel@tonic-gate }
14567c478bd9Sstevel@tonic-gate script_setenv("IPLOCAL", ip_ntoa(go->ouraddr), 0);
14577c478bd9Sstevel@tonic-gate script_setenv("IPREMOTE", ip_ntoa(ho->hisaddr), 1);
14587c478bd9Sstevel@tonic-gate
14597c478bd9Sstevel@tonic-gate /*
14607c478bd9Sstevel@tonic-gate * Check that the peer is allowed to use the IP address it wants.
14617c478bd9Sstevel@tonic-gate */
14627c478bd9Sstevel@tonic-gate if (!auth_ip_addr(f->unit, ho->hisaddr)) {
14637c478bd9Sstevel@tonic-gate error("Peer is not authorized to use remote address %I", ho->hisaddr);
14647c478bd9Sstevel@tonic-gate ipcp_close(f->unit, "Unauthorized remote IP address");
14657c478bd9Sstevel@tonic-gate return;
14667c478bd9Sstevel@tonic-gate }
14677c478bd9Sstevel@tonic-gate
14687c478bd9Sstevel@tonic-gate if ((go->req_dns1 && go->dnsaddr[0] != 0) ||
14697c478bd9Sstevel@tonic-gate (go->req_dns2 && go->dnsaddr[1] != 0)) {
14707c478bd9Sstevel@tonic-gate script_setenv("USEPEERDNS", "1", 0);
14717c478bd9Sstevel@tonic-gate if (go->dnsaddr[0] != 0)
14727c478bd9Sstevel@tonic-gate script_setenv("DNS1", ip_ntoa(go->dnsaddr[0]), 0);
14737c478bd9Sstevel@tonic-gate if (go->dnsaddr[1] != 0)
14747c478bd9Sstevel@tonic-gate script_setenv("DNS2", ip_ntoa(go->dnsaddr[1]), 0);
14757c478bd9Sstevel@tonic-gate create_resolv(go->dnsaddr[0], go->dnsaddr[1]);
14767c478bd9Sstevel@tonic-gate }
14777c478bd9Sstevel@tonic-gate
14787c478bd9Sstevel@tonic-gate /* set tcp compression */
14797c478bd9Sstevel@tonic-gate if (sifvjcomp(f->unit, ho->neg_vj, ho->cflag, ho->maxslotindex) != 1) {
14807c478bd9Sstevel@tonic-gate ipcp_close(f->unit, "Could not enable VJ TCP header compression");
14817c478bd9Sstevel@tonic-gate return;
14827c478bd9Sstevel@tonic-gate }
14837c478bd9Sstevel@tonic-gate
14847c478bd9Sstevel@tonic-gate /*
14857c478bd9Sstevel@tonic-gate * If we are doing dial-on-demand, the interface is already
14867c478bd9Sstevel@tonic-gate * configured, so we put out any saved-up packets, then set the
14877c478bd9Sstevel@tonic-gate * interface to pass IP packets.
14887c478bd9Sstevel@tonic-gate */
14897c478bd9Sstevel@tonic-gate if (demand) {
14907c478bd9Sstevel@tonic-gate if (go->ouraddr != wo->ouraddr || ho->hisaddr != wo->hisaddr) {
14917c478bd9Sstevel@tonic-gate ipcp_clear_addrs(f->unit, wo->ouraddr, wo->hisaddr);
14927c478bd9Sstevel@tonic-gate if (go->ouraddr != wo->ouraddr) {
14937c478bd9Sstevel@tonic-gate warn("Local IP address changed to %I", go->ouraddr);
14947c478bd9Sstevel@tonic-gate script_setenv("OLDIPLOCAL", ip_ntoa(wo->ouraddr), 0);
14957c478bd9Sstevel@tonic-gate wo->ouraddr = go->ouraddr;
14967c478bd9Sstevel@tonic-gate } else
14977c478bd9Sstevel@tonic-gate script_unsetenv("OLDIPLOCAL");
14987c478bd9Sstevel@tonic-gate if (ho->hisaddr != wo->hisaddr) {
14997c478bd9Sstevel@tonic-gate warn("Remote IP address changed to %I", ho->hisaddr);
15007c478bd9Sstevel@tonic-gate script_setenv("OLDIPREMOTE", ip_ntoa(wo->hisaddr), 0);
15017c478bd9Sstevel@tonic-gate wo->hisaddr = ho->hisaddr;
15027c478bd9Sstevel@tonic-gate } else
15037c478bd9Sstevel@tonic-gate script_unsetenv("OLDIPREMOTE");
15047c478bd9Sstevel@tonic-gate
15057c478bd9Sstevel@tonic-gate /* Set the interface to the new addresses */
15067c478bd9Sstevel@tonic-gate mask = GetMask(go->ouraddr);
15077c478bd9Sstevel@tonic-gate if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
15087c478bd9Sstevel@tonic-gate warn("Interface configuration failed");
15097c478bd9Sstevel@tonic-gate ipcp_close(f->unit, "Interface configuration failed");
15107c478bd9Sstevel@tonic-gate return;
15117c478bd9Sstevel@tonic-gate }
15127c478bd9Sstevel@tonic-gate
15137c478bd9Sstevel@tonic-gate /* assign a default route through the interface if required */
1514*48bbca81SDaniel Hoffman if (wo->default_route)
15157c478bd9Sstevel@tonic-gate if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr))
15167c478bd9Sstevel@tonic-gate default_route_set[f->unit] = 1;
15177c478bd9Sstevel@tonic-gate
15187c478bd9Sstevel@tonic-gate /* Make a proxy ARP entry if requested. */
15197c478bd9Sstevel@tonic-gate if (wo->proxy_arp &&
15207c478bd9Sstevel@tonic-gate sifproxyarp(f->unit, ho->hisaddr, proxy_arp_quiet[f->unit]))
15217c478bd9Sstevel@tonic-gate proxy_arp_set[f->unit] = 1;
15227c478bd9Sstevel@tonic-gate
15237c478bd9Sstevel@tonic-gate }
15247c478bd9Sstevel@tonic-gate demand_rexmit(PPP_IP);
15257c478bd9Sstevel@tonic-gate if (sifnpmode(f->unit, PPP_IP, NPMODE_PASS) != 1) {
15267c478bd9Sstevel@tonic-gate ipcp_close(f->unit, "Interface configuration failed.");
15277c478bd9Sstevel@tonic-gate return;
15287c478bd9Sstevel@tonic-gate }
15297c478bd9Sstevel@tonic-gate
15307c478bd9Sstevel@tonic-gate } else {
15317c478bd9Sstevel@tonic-gate /*
15327c478bd9Sstevel@tonic-gate * Set IP addresses and (if specified) netmask.
15337c478bd9Sstevel@tonic-gate */
15347c478bd9Sstevel@tonic-gate mask = GetMask(go->ouraddr);
15357c478bd9Sstevel@tonic-gate
15367c478bd9Sstevel@tonic-gate #if SIFUPFIRST
15377c478bd9Sstevel@tonic-gate /* bring the interface up for IP */
15387c478bd9Sstevel@tonic-gate if (!sifup(f->unit)) {
15397c478bd9Sstevel@tonic-gate warn("Interface failed to come up");
15407c478bd9Sstevel@tonic-gate ipcp_close(f->unit, "Interface configuration failed");
15417c478bd9Sstevel@tonic-gate return;
15427c478bd9Sstevel@tonic-gate }
15437c478bd9Sstevel@tonic-gate #endif
15447c478bd9Sstevel@tonic-gate
15457c478bd9Sstevel@tonic-gate if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
15467c478bd9Sstevel@tonic-gate warn("Interface configuration failed");
15477c478bd9Sstevel@tonic-gate ipcp_close(f->unit, "Interface configuration failed");
15487c478bd9Sstevel@tonic-gate return;
15497c478bd9Sstevel@tonic-gate }
15507c478bd9Sstevel@tonic-gate
15517c478bd9Sstevel@tonic-gate #if !SIFUPFIRST
15527c478bd9Sstevel@tonic-gate /* bring the interface up for IP */
15537c478bd9Sstevel@tonic-gate if (!sifup(f->unit)) {
15547c478bd9Sstevel@tonic-gate warn("Interface failed to come up");
15557c478bd9Sstevel@tonic-gate ipcp_close(f->unit, "Interface configuration failed");
15567c478bd9Sstevel@tonic-gate return;
15577c478bd9Sstevel@tonic-gate }
15587c478bd9Sstevel@tonic-gate #endif
15597c478bd9Sstevel@tonic-gate
15607c478bd9Sstevel@tonic-gate if (sifnpmode(f->unit, PPP_IP, NPMODE_PASS) != 1) {
15617c478bd9Sstevel@tonic-gate ipcp_close(f->unit, "Interface configuration failed.");
15627c478bd9Sstevel@tonic-gate return;
15637c478bd9Sstevel@tonic-gate }
15647c478bd9Sstevel@tonic-gate
15657c478bd9Sstevel@tonic-gate /* assign a default route through the interface if required */
1566*48bbca81SDaniel Hoffman if (wo->default_route)
15677c478bd9Sstevel@tonic-gate if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr))
15687c478bd9Sstevel@tonic-gate default_route_set[f->unit] = 1;
15697c478bd9Sstevel@tonic-gate
15707c478bd9Sstevel@tonic-gate /* Make a proxy ARP entry if requested. */
15717c478bd9Sstevel@tonic-gate if (wo->proxy_arp &&
15727c478bd9Sstevel@tonic-gate sifproxyarp(f->unit, ho->hisaddr, proxy_arp_quiet[f->unit]))
15737c478bd9Sstevel@tonic-gate proxy_arp_set[f->unit] = 1;
15747c478bd9Sstevel@tonic-gate
15757c478bd9Sstevel@tonic-gate wo->ouraddr = go->ouraddr;
15767c478bd9Sstevel@tonic-gate
15777c478bd9Sstevel@tonic-gate notice("local IP address %I", go->ouraddr);
15787c478bd9Sstevel@tonic-gate notice("remote IP address %I", ho->hisaddr);
15797c478bd9Sstevel@tonic-gate if (go->dnsaddr[0] != 0)
15807c478bd9Sstevel@tonic-gate notice("primary DNS address %I", go->dnsaddr[0]);
15817c478bd9Sstevel@tonic-gate if (go->dnsaddr[1] != 0)
15827c478bd9Sstevel@tonic-gate notice("secondary DNS address %I", go->dnsaddr[1]);
15837c478bd9Sstevel@tonic-gate }
15847c478bd9Sstevel@tonic-gate
15857c478bd9Sstevel@tonic-gate np_up(f->unit, PPP_IP);
15867c478bd9Sstevel@tonic-gate ipcp_is_up[f->unit] = 1;
15877c478bd9Sstevel@tonic-gate
15887c478bd9Sstevel@tonic-gate if (ip_up_hook != NULL)
15897c478bd9Sstevel@tonic-gate (*ip_up_hook)();
15907c478bd9Sstevel@tonic-gate
15917c478bd9Sstevel@tonic-gate /*
15927c478bd9Sstevel@tonic-gate * Execute the ip-up script, like this:
15937c478bd9Sstevel@tonic-gate * /etc/ppp/ip-up interface tty speed local-IP remote-IP
15947c478bd9Sstevel@tonic-gate */
15957c478bd9Sstevel@tonic-gate if (ipcp_script_state == s_down && ipcp_script_pid == 0) {
15967c478bd9Sstevel@tonic-gate ipcp_script_state = s_up;
15977c478bd9Sstevel@tonic-gate ipcp_script(_PATH_IPUP);
15987c478bd9Sstevel@tonic-gate }
15997c478bd9Sstevel@tonic-gate sys_unblock_proto(PPP_IP);
16007c478bd9Sstevel@tonic-gate }
16017c478bd9Sstevel@tonic-gate
16027c478bd9Sstevel@tonic-gate
16037c478bd9Sstevel@tonic-gate /*
16047c478bd9Sstevel@tonic-gate * ipcp_down - IPCP has gone DOWN.
16057c478bd9Sstevel@tonic-gate *
16067c478bd9Sstevel@tonic-gate * Take the IP network interface down, clear its addresses
16077c478bd9Sstevel@tonic-gate * and delete routes through it.
16087c478bd9Sstevel@tonic-gate */
16097c478bd9Sstevel@tonic-gate static void
ipcp_down(f)16107c478bd9Sstevel@tonic-gate ipcp_down(f)
16117c478bd9Sstevel@tonic-gate fsm *f;
16127c478bd9Sstevel@tonic-gate {
16137c478bd9Sstevel@tonic-gate IPCPDEBUG(("ipcp: down"));
16147c478bd9Sstevel@tonic-gate /* XXX a bit IPv4-centric here, we only need to get the stats
16157c478bd9Sstevel@tonic-gate * before the interface is marked down. */
16167c478bd9Sstevel@tonic-gate update_link_stats(f->unit);
16177c478bd9Sstevel@tonic-gate if (ip_down_hook != NULL)
16187c478bd9Sstevel@tonic-gate (*ip_down_hook)();
16197c478bd9Sstevel@tonic-gate if (ipcp_is_up[f->unit]) {
16207c478bd9Sstevel@tonic-gate ipcp_is_up[f->unit] = 0;
16217c478bd9Sstevel@tonic-gate np_down(f->unit, PPP_IP);
16227c478bd9Sstevel@tonic-gate }
16237c478bd9Sstevel@tonic-gate if (sifvjcomp(f->unit, 0, 0, 0) != 1) {
16247c478bd9Sstevel@tonic-gate if (debug)
16257c478bd9Sstevel@tonic-gate warn("Failed to disable VJ TCP header compression.");
16267c478bd9Sstevel@tonic-gate }
16277c478bd9Sstevel@tonic-gate
16287c478bd9Sstevel@tonic-gate /*
16297c478bd9Sstevel@tonic-gate * If we are doing dial-on-demand, set the interface
16307c478bd9Sstevel@tonic-gate * to queue up outgoing packets (for now).
16317c478bd9Sstevel@tonic-gate */
16327c478bd9Sstevel@tonic-gate if (demand) {
16337c478bd9Sstevel@tonic-gate if (sifnpmode(f->unit, PPP_IP, NPMODE_QUEUE) != 1) {
16347c478bd9Sstevel@tonic-gate if (debug)
16357c478bd9Sstevel@tonic-gate warn("Failed to enable Queueing on outgoing packets.");
16367c478bd9Sstevel@tonic-gate }
16377c478bd9Sstevel@tonic-gate } else {
16387c478bd9Sstevel@tonic-gate if (sifnpmode(f->unit, PPP_IP, NPMODE_ERROR) != 1) {
16397c478bd9Sstevel@tonic-gate if (debug)
16407c478bd9Sstevel@tonic-gate warn("Could not set interface to drop packets.");
16417c478bd9Sstevel@tonic-gate }
16427c478bd9Sstevel@tonic-gate if (sifdown(f->unit) != 1)
16437c478bd9Sstevel@tonic-gate warn("Could not bring interface down.");
16447c478bd9Sstevel@tonic-gate ipcp_clear_addrs(f->unit, ipcp_gotoptions[f->unit].ouraddr,
16457c478bd9Sstevel@tonic-gate ipcp_hisoptions[f->unit].hisaddr);
16467c478bd9Sstevel@tonic-gate }
16477c478bd9Sstevel@tonic-gate
16487c478bd9Sstevel@tonic-gate /* Execute the ip-down script */
16497c478bd9Sstevel@tonic-gate if (ipcp_script_state == s_up && ipcp_script_pid == 0) {
16507c478bd9Sstevel@tonic-gate ipcp_script_state = s_down;
16517c478bd9Sstevel@tonic-gate ipcp_script(_PATH_IPDOWN);
16527c478bd9Sstevel@tonic-gate }
16537c478bd9Sstevel@tonic-gate }
16547c478bd9Sstevel@tonic-gate
16557c478bd9Sstevel@tonic-gate
16567c478bd9Sstevel@tonic-gate /*
16577c478bd9Sstevel@tonic-gate * ipcp_clear_addrs() - clear the interface addresses, routes,
16587c478bd9Sstevel@tonic-gate * proxy arp entries, etc.
16597c478bd9Sstevel@tonic-gate */
16607c478bd9Sstevel@tonic-gate static void
ipcp_clear_addrs(unit,ouraddr,hisaddr)16617c478bd9Sstevel@tonic-gate ipcp_clear_addrs(unit, ouraddr, hisaddr)
16627c478bd9Sstevel@tonic-gate int unit;
16637c478bd9Sstevel@tonic-gate u_int32_t ouraddr; /* local address */
16647c478bd9Sstevel@tonic-gate u_int32_t hisaddr; /* remote address */
16657c478bd9Sstevel@tonic-gate {
16667c478bd9Sstevel@tonic-gate if (proxy_arp_set[unit]) {
16677c478bd9Sstevel@tonic-gate (void) cifproxyarp(unit, hisaddr);
16687c478bd9Sstevel@tonic-gate proxy_arp_set[unit] = 0;
16697c478bd9Sstevel@tonic-gate }
16707c478bd9Sstevel@tonic-gate if (default_route_set[unit]) {
16717c478bd9Sstevel@tonic-gate (void) cifdefaultroute(unit, ouraddr, hisaddr);
16727c478bd9Sstevel@tonic-gate default_route_set[unit] = 0;
16737c478bd9Sstevel@tonic-gate }
16747c478bd9Sstevel@tonic-gate if (cifaddr(unit, ouraddr, hisaddr) != 1)
16757c478bd9Sstevel@tonic-gate warn("Could not clear addresses");
16767c478bd9Sstevel@tonic-gate }
16777c478bd9Sstevel@tonic-gate
16787c478bd9Sstevel@tonic-gate
16797c478bd9Sstevel@tonic-gate /*
16807c478bd9Sstevel@tonic-gate * ipcp_finished - possibly shut down the lower layers.
16817c478bd9Sstevel@tonic-gate */
16827c478bd9Sstevel@tonic-gate static void
ipcp_finished(f)16837c478bd9Sstevel@tonic-gate ipcp_finished(f)
16847c478bd9Sstevel@tonic-gate fsm *f;
16857c478bd9Sstevel@tonic-gate {
16867c478bd9Sstevel@tonic-gate np_finished(f->unit, PPP_IP);
16877c478bd9Sstevel@tonic-gate }
16887c478bd9Sstevel@tonic-gate
16897c478bd9Sstevel@tonic-gate
16907c478bd9Sstevel@tonic-gate /*
16917c478bd9Sstevel@tonic-gate * ipcp_script_done - called when the ip-up or ip-down script
16927c478bd9Sstevel@tonic-gate * has finished.
16937c478bd9Sstevel@tonic-gate */
16947c478bd9Sstevel@tonic-gate /*ARGSUSED*/
16957c478bd9Sstevel@tonic-gate static void
ipcp_script_done(arg,status)16967c478bd9Sstevel@tonic-gate ipcp_script_done(arg, status)
16977c478bd9Sstevel@tonic-gate void *arg;
16987c478bd9Sstevel@tonic-gate int status;
16997c478bd9Sstevel@tonic-gate {
17007c478bd9Sstevel@tonic-gate ipcp_script_pid = 0;
17017c478bd9Sstevel@tonic-gate switch (ipcp_script_state) {
17027c478bd9Sstevel@tonic-gate case s_up:
17037c478bd9Sstevel@tonic-gate if (ipcp_fsm[0].state != OPENED) {
17047c478bd9Sstevel@tonic-gate ipcp_script_state = s_down;
17057c478bd9Sstevel@tonic-gate ipcp_script(_PATH_IPDOWN);
17067c478bd9Sstevel@tonic-gate }
17077c478bd9Sstevel@tonic-gate break;
17087c478bd9Sstevel@tonic-gate case s_down:
17097c478bd9Sstevel@tonic-gate if (ipcp_fsm[0].state == OPENED) {
17107c478bd9Sstevel@tonic-gate ipcp_script_state = s_up;
17117c478bd9Sstevel@tonic-gate ipcp_script(_PATH_IPUP);
17127c478bd9Sstevel@tonic-gate }
17137c478bd9Sstevel@tonic-gate break;
17147c478bd9Sstevel@tonic-gate }
17157c478bd9Sstevel@tonic-gate }
17167c478bd9Sstevel@tonic-gate
17177c478bd9Sstevel@tonic-gate
17187c478bd9Sstevel@tonic-gate /*
17197c478bd9Sstevel@tonic-gate * ipcp_script - Execute a script with arguments
17207c478bd9Sstevel@tonic-gate * interface-name tty-name speed local-IP remote-IP.
17217c478bd9Sstevel@tonic-gate */
17227c478bd9Sstevel@tonic-gate static void
ipcp_script(script)17237c478bd9Sstevel@tonic-gate ipcp_script(script)
17247c478bd9Sstevel@tonic-gate char *script;
17257c478bd9Sstevel@tonic-gate {
17267c478bd9Sstevel@tonic-gate char strspeed[32], strlocal[32], strremote[32];
17277c478bd9Sstevel@tonic-gate char *argv[8];
17287c478bd9Sstevel@tonic-gate
17297c478bd9Sstevel@tonic-gate (void) slprintf(strspeed, sizeof(strspeed), "%d", baud_rate);
17307c478bd9Sstevel@tonic-gate (void) slprintf(strlocal, sizeof(strlocal), "%I",
17317c478bd9Sstevel@tonic-gate ipcp_gotoptions[0].ouraddr);
17327c478bd9Sstevel@tonic-gate (void) slprintf(strremote, sizeof(strremote), "%I",
17337c478bd9Sstevel@tonic-gate ipcp_hisoptions[0].hisaddr);
17347c478bd9Sstevel@tonic-gate
17357c478bd9Sstevel@tonic-gate argv[0] = script;
17367c478bd9Sstevel@tonic-gate argv[1] = ifname;
17377c478bd9Sstevel@tonic-gate argv[2] = devnam;
17387c478bd9Sstevel@tonic-gate argv[3] = strspeed;
17397c478bd9Sstevel@tonic-gate argv[4] = strlocal;
17407c478bd9Sstevel@tonic-gate argv[5] = strremote;
17417c478bd9Sstevel@tonic-gate argv[6] = ipparam;
17427c478bd9Sstevel@tonic-gate argv[7] = NULL;
17437c478bd9Sstevel@tonic-gate ipcp_script_pid = run_program(script, argv, 0, ipcp_script_done, NULL);
17447c478bd9Sstevel@tonic-gate }
17457c478bd9Sstevel@tonic-gate
17467c478bd9Sstevel@tonic-gate /*
17477c478bd9Sstevel@tonic-gate * create_resolv - create the replacement resolv.conf file
17487c478bd9Sstevel@tonic-gate */
17497c478bd9Sstevel@tonic-gate static void
create_resolv(peerdns1,peerdns2)17507c478bd9Sstevel@tonic-gate create_resolv(peerdns1, peerdns2)
17517c478bd9Sstevel@tonic-gate u_int32_t peerdns1, peerdns2;
17527c478bd9Sstevel@tonic-gate {
17537c478bd9Sstevel@tonic-gate FILE *f;
17547c478bd9Sstevel@tonic-gate
17557c478bd9Sstevel@tonic-gate f = fopen(_PATH_RESOLV, "w");
17567c478bd9Sstevel@tonic-gate if (f == NULL) {
17577c478bd9Sstevel@tonic-gate error("Failed to create %s: %m", _PATH_RESOLV);
17587c478bd9Sstevel@tonic-gate return;
17597c478bd9Sstevel@tonic-gate }
17607c478bd9Sstevel@tonic-gate
17617c478bd9Sstevel@tonic-gate if (peerdns1)
17627c478bd9Sstevel@tonic-gate if (fprintf(f, "nameserver %s\n", ip_ntoa(peerdns1)) <= 0)
17637c478bd9Sstevel@tonic-gate error("Write failed to %s: %m", _PATH_RESOLV);
17647c478bd9Sstevel@tonic-gate
17657c478bd9Sstevel@tonic-gate if (peerdns2)
17667c478bd9Sstevel@tonic-gate if (fprintf(f, "nameserver %s\n", ip_ntoa(peerdns2)) <= 0)
17677c478bd9Sstevel@tonic-gate error("Write failed to %s: %m", _PATH_RESOLV);
17687c478bd9Sstevel@tonic-gate
17697c478bd9Sstevel@tonic-gate if (fclose(f) != 0)
17707c478bd9Sstevel@tonic-gate error("Failed to close %s: %m", _PATH_RESOLV);
17717c478bd9Sstevel@tonic-gate }
17727c478bd9Sstevel@tonic-gate
17737c478bd9Sstevel@tonic-gate /*
17747c478bd9Sstevel@tonic-gate * ipcp_printpkt - print the contents of an IPCP packet.
17757c478bd9Sstevel@tonic-gate */
17767c478bd9Sstevel@tonic-gate static int
ipcp_printpkt(p,plen,printer,arg)17777c478bd9Sstevel@tonic-gate ipcp_printpkt(p, plen, printer, arg)
17787c478bd9Sstevel@tonic-gate u_char *p;
17797c478bd9Sstevel@tonic-gate int plen;
17807c478bd9Sstevel@tonic-gate void (*printer) __P((void *, const char *, ...));
17817c478bd9Sstevel@tonic-gate void *arg;
17827c478bd9Sstevel@tonic-gate {
17837c478bd9Sstevel@tonic-gate int code, id, len, olen;
17847c478bd9Sstevel@tonic-gate u_char *pstart, *optend;
17857c478bd9Sstevel@tonic-gate u_short cishort;
17867c478bd9Sstevel@tonic-gate u_int32_t cilong;
17877c478bd9Sstevel@tonic-gate
17887c478bd9Sstevel@tonic-gate if (plen < HEADERLEN)
17897c478bd9Sstevel@tonic-gate return 0;
17907c478bd9Sstevel@tonic-gate pstart = p;
17917c478bd9Sstevel@tonic-gate GETCHAR(code, p);
17927c478bd9Sstevel@tonic-gate GETCHAR(id, p);
17937c478bd9Sstevel@tonic-gate GETSHORT(len, p);
17947c478bd9Sstevel@tonic-gate if (len < HEADERLEN || len > plen)
17957c478bd9Sstevel@tonic-gate return 0;
17967c478bd9Sstevel@tonic-gate
17977c478bd9Sstevel@tonic-gate printer(arg, " %s id=0x%x", code_name(code, 1), id);
17987c478bd9Sstevel@tonic-gate len -= HEADERLEN;
17997c478bd9Sstevel@tonic-gate switch (code) {
18007c478bd9Sstevel@tonic-gate case CODE_CONFREQ:
18017c478bd9Sstevel@tonic-gate case CODE_CONFACK:
18027c478bd9Sstevel@tonic-gate case CODE_CONFNAK:
18037c478bd9Sstevel@tonic-gate case CODE_CONFREJ:
18047c478bd9Sstevel@tonic-gate /* print option list */
18057c478bd9Sstevel@tonic-gate while (len >= 2) {
18067c478bd9Sstevel@tonic-gate GETCHAR(code, p);
18077c478bd9Sstevel@tonic-gate GETCHAR(olen, p);
18087c478bd9Sstevel@tonic-gate p -= 2;
18097c478bd9Sstevel@tonic-gate if (olen < 2 || olen > len) {
18107c478bd9Sstevel@tonic-gate break;
18117c478bd9Sstevel@tonic-gate }
18127c478bd9Sstevel@tonic-gate printer(arg, " <");
18137c478bd9Sstevel@tonic-gate len -= olen;
18147c478bd9Sstevel@tonic-gate optend = p + olen;
18157c478bd9Sstevel@tonic-gate switch (code) {
18167c478bd9Sstevel@tonic-gate case CI_ADDRS:
18177c478bd9Sstevel@tonic-gate if (olen == CILEN_ADDRS) {
18187c478bd9Sstevel@tonic-gate p += 2;
18197c478bd9Sstevel@tonic-gate GETNLONG(cilong, p);
18207c478bd9Sstevel@tonic-gate printer(arg, "addrs %I", cilong);
18217c478bd9Sstevel@tonic-gate GETNLONG(cilong, p);
18227c478bd9Sstevel@tonic-gate printer(arg, " %I", cilong);
18237c478bd9Sstevel@tonic-gate }
18247c478bd9Sstevel@tonic-gate break;
18257c478bd9Sstevel@tonic-gate case CI_COMPRESSTYPE:
18267c478bd9Sstevel@tonic-gate if (olen >= CILEN_COMPRESS) {
18277c478bd9Sstevel@tonic-gate p += 2;
18287c478bd9Sstevel@tonic-gate GETSHORT(cishort, p);
18297c478bd9Sstevel@tonic-gate printer(arg, "compress ");
18307c478bd9Sstevel@tonic-gate switch (cishort) {
18317c478bd9Sstevel@tonic-gate case IPCP_VJ_COMP:
18327c478bd9Sstevel@tonic-gate printer(arg, "VJ");
18337c478bd9Sstevel@tonic-gate break;
18347c478bd9Sstevel@tonic-gate case IPCP_VJ_COMP_OLD:
18357c478bd9Sstevel@tonic-gate printer(arg, "old-VJ");
18367c478bd9Sstevel@tonic-gate break;
18377c478bd9Sstevel@tonic-gate default:
18387c478bd9Sstevel@tonic-gate printer(arg, "0x%x", cishort);
18397c478bd9Sstevel@tonic-gate }
18407c478bd9Sstevel@tonic-gate }
18417c478bd9Sstevel@tonic-gate break;
18427c478bd9Sstevel@tonic-gate case CI_ADDR:
18437c478bd9Sstevel@tonic-gate if (olen == CILEN_ADDR) {
18447c478bd9Sstevel@tonic-gate p += 2;
18457c478bd9Sstevel@tonic-gate GETNLONG(cilong, p);
18467c478bd9Sstevel@tonic-gate printer(arg, "addr %I", cilong);
18477c478bd9Sstevel@tonic-gate }
18487c478bd9Sstevel@tonic-gate break;
18497c478bd9Sstevel@tonic-gate case CI_MS_DNS1:
18507c478bd9Sstevel@tonic-gate case CI_MS_DNS2:
18517c478bd9Sstevel@tonic-gate p += 2;
18527c478bd9Sstevel@tonic-gate GETNLONG(cilong, p);
18537c478bd9Sstevel@tonic-gate printer(arg, "ms-dns%d %I", (code == CI_MS_DNS1 ? 1 : 2),
18547c478bd9Sstevel@tonic-gate cilong);
18557c478bd9Sstevel@tonic-gate break;
18567c478bd9Sstevel@tonic-gate case CI_MS_WINS1:
18577c478bd9Sstevel@tonic-gate case CI_MS_WINS2:
18587c478bd9Sstevel@tonic-gate p += 2;
18597c478bd9Sstevel@tonic-gate GETNLONG(cilong, p);
18607c478bd9Sstevel@tonic-gate printer(arg, "ms-wins%d %I", (code == CI_MS_WINS1 ? 1 : 2),
18617c478bd9Sstevel@tonic-gate cilong);
18627c478bd9Sstevel@tonic-gate break;
18637c478bd9Sstevel@tonic-gate case CI_SUBNET:
18647c478bd9Sstevel@tonic-gate p += 2;
18657c478bd9Sstevel@tonic-gate GETNLONG(cilong, p);
18667c478bd9Sstevel@tonic-gate printer(arg, "subnet %I", cilong);
18677c478bd9Sstevel@tonic-gate break;
18687c478bd9Sstevel@tonic-gate }
18697c478bd9Sstevel@tonic-gate while (p < optend) {
18707c478bd9Sstevel@tonic-gate GETCHAR(code, p);
18717c478bd9Sstevel@tonic-gate printer(arg, " %.2x", code);
18727c478bd9Sstevel@tonic-gate }
18737c478bd9Sstevel@tonic-gate printer(arg, ">");
18747c478bd9Sstevel@tonic-gate }
18757c478bd9Sstevel@tonic-gate break;
18767c478bd9Sstevel@tonic-gate
18777c478bd9Sstevel@tonic-gate case CODE_TERMACK:
18787c478bd9Sstevel@tonic-gate case CODE_TERMREQ:
18797c478bd9Sstevel@tonic-gate if (len > 0 && *p >= ' ' && *p < 0x7f) {
18807c478bd9Sstevel@tonic-gate printer(arg, " ");
18817c478bd9Sstevel@tonic-gate print_string((char *)p, len, printer, arg);
18827c478bd9Sstevel@tonic-gate p += len;
18837c478bd9Sstevel@tonic-gate len = 0;
18847c478bd9Sstevel@tonic-gate }
18857c478bd9Sstevel@tonic-gate break;
18867c478bd9Sstevel@tonic-gate }
18877c478bd9Sstevel@tonic-gate
18887c478bd9Sstevel@tonic-gate /* print the rest of the bytes in the packet */
18897c478bd9Sstevel@tonic-gate for (; len > 0; --len) {
18907c478bd9Sstevel@tonic-gate GETCHAR(code, p);
18917c478bd9Sstevel@tonic-gate printer(arg, " %.2x", code);
18927c478bd9Sstevel@tonic-gate }
18937c478bd9Sstevel@tonic-gate
18947c478bd9Sstevel@tonic-gate return p - pstart;
18957c478bd9Sstevel@tonic-gate }
18967c478bd9Sstevel@tonic-gate
1897f53eecf5SJames Carlson char *
tcp_flag_decode(val)1898f53eecf5SJames Carlson tcp_flag_decode(val)
1899f53eecf5SJames Carlson int val;
1900f53eecf5SJames Carlson {
1901f53eecf5SJames Carlson static char buf[32];
1902f53eecf5SJames Carlson char *cp = buf;
1903f53eecf5SJames Carlson
1904f53eecf5SJames Carlson if (val & TH_URG)
1905f53eecf5SJames Carlson *cp++ = 'U';
1906f53eecf5SJames Carlson if (val & TH_ACK)
1907f53eecf5SJames Carlson *cp++ = 'A';
1908f53eecf5SJames Carlson if (val & TH_PUSH)
1909f53eecf5SJames Carlson *cp++ = 'P';
1910f53eecf5SJames Carlson if (val & TH_RST)
1911f53eecf5SJames Carlson *cp++ = 'R';
1912f53eecf5SJames Carlson if (val & TH_SYN)
1913f53eecf5SJames Carlson *cp++ = 'S';
1914f53eecf5SJames Carlson if (val & TH_FIN)
1915f53eecf5SJames Carlson *cp++ = 'F';
1916f53eecf5SJames Carlson if (cp != buf)
1917f53eecf5SJames Carlson *cp++ = ' ';
1918f53eecf5SJames Carlson *cp = '\0';
1919f53eecf5SJames Carlson return buf;
1920f53eecf5SJames Carlson }
1921f53eecf5SJames Carlson
19227c478bd9Sstevel@tonic-gate /*
19237c478bd9Sstevel@tonic-gate * ip_active_pkt - see if this IP packet is worth bringing the link up for.
19247c478bd9Sstevel@tonic-gate * We don't bring the link up for IP fragments or for TCP FIN packets
19257c478bd9Sstevel@tonic-gate * with no data.
19267c478bd9Sstevel@tonic-gate */
19277c478bd9Sstevel@tonic-gate
19287c478bd9Sstevel@tonic-gate static int
ip_active_pkt(pkt,len)19297c478bd9Sstevel@tonic-gate ip_active_pkt(pkt, len)
19307c478bd9Sstevel@tonic-gate u_char *pkt;
19317c478bd9Sstevel@tonic-gate int len;
19327c478bd9Sstevel@tonic-gate {
19337c478bd9Sstevel@tonic-gate u_char *tcp;
19347c478bd9Sstevel@tonic-gate struct protoent *pep;
19357c478bd9Sstevel@tonic-gate int val;
19367c478bd9Sstevel@tonic-gate int hlen;
19377c478bd9Sstevel@tonic-gate char buf[32], *cp;
19387c478bd9Sstevel@tonic-gate u_int32_t src, dst;
19397c478bd9Sstevel@tonic-gate
19407c478bd9Sstevel@tonic-gate len -= PPP_HDRLEN;
19417c478bd9Sstevel@tonic-gate pkt += PPP_HDRLEN;
19427c478bd9Sstevel@tonic-gate if (len < IP_HDRLEN) {
19437c478bd9Sstevel@tonic-gate dbglog("IP packet of length %d is not activity", len);
19447c478bd9Sstevel@tonic-gate return 0;
19457c478bd9Sstevel@tonic-gate }
19467c478bd9Sstevel@tonic-gate src = get_ipsrc(pkt);
19477c478bd9Sstevel@tonic-gate dst = get_ipdst(pkt);
19487c478bd9Sstevel@tonic-gate if ((get_ipoff(pkt) & IP_OFFMASK) != 0) {
19497c478bd9Sstevel@tonic-gate dbglog("IP fragment from %I->%I is not activity", src, dst);
19507c478bd9Sstevel@tonic-gate return 0;
19517c478bd9Sstevel@tonic-gate }
19527c478bd9Sstevel@tonic-gate val = get_ipproto(pkt);
19537c478bd9Sstevel@tonic-gate if (val != IPPROTO_TCP) {
19547c478bd9Sstevel@tonic-gate if (debug) {
19557c478bd9Sstevel@tonic-gate if ((pep = getprotobynumber(val)) != NULL) {
19567c478bd9Sstevel@tonic-gate cp = pep->p_name;
19577c478bd9Sstevel@tonic-gate } else {
19587c478bd9Sstevel@tonic-gate (void) slprintf(buf, sizeof (buf), "IP proto %d", val);
19597c478bd9Sstevel@tonic-gate cp = buf;
19607c478bd9Sstevel@tonic-gate }
1961f53eecf5SJames Carlson info("%s from %I->%I is activity", cp, src, dst);
19627c478bd9Sstevel@tonic-gate }
19637c478bd9Sstevel@tonic-gate return 1;
19647c478bd9Sstevel@tonic-gate }
19657c478bd9Sstevel@tonic-gate hlen = get_iphl(pkt) * 4;
19667c478bd9Sstevel@tonic-gate if (len < hlen + TCP_HDRLEN) {
19677c478bd9Sstevel@tonic-gate dbglog("Bad TCP length %d<%d+%d %I->%I is not activity", len, hlen,
19687c478bd9Sstevel@tonic-gate TCP_HDRLEN, src, dst);
19697c478bd9Sstevel@tonic-gate return 0;
19707c478bd9Sstevel@tonic-gate }
19717c478bd9Sstevel@tonic-gate tcp = pkt + hlen;
19727c478bd9Sstevel@tonic-gate val = get_tcpflags(tcp);
19737c478bd9Sstevel@tonic-gate hlen += get_tcpoff(tcp) * 4;
19747c478bd9Sstevel@tonic-gate if ((val & TH_FIN) != 0 && len == hlen) {
19757c478bd9Sstevel@tonic-gate dbglog("Empty TCP FIN %I->%I is not activity", src, dst);
19767c478bd9Sstevel@tonic-gate return 0;
19777c478bd9Sstevel@tonic-gate }
1978f53eecf5SJames Carlson info("TCP %d data %s%I->%I is activity", len - hlen,
1979f53eecf5SJames Carlson tcp_flag_decode(get_tcpflags(tcp)), src, dst);
19807c478bd9Sstevel@tonic-gate return 1;
19817c478bd9Sstevel@tonic-gate }
19827c478bd9Sstevel@tonic-gate
19837c478bd9Sstevel@tonic-gate static void
ipcp_print_stat(unit,strptr)19847c478bd9Sstevel@tonic-gate ipcp_print_stat(unit, strptr)
19857c478bd9Sstevel@tonic-gate int unit;
19867c478bd9Sstevel@tonic-gate FILE *strptr;
19877c478bd9Sstevel@tonic-gate {
19887c478bd9Sstevel@tonic-gate ipcp_options *go = &ipcp_gotoptions[unit];
19897c478bd9Sstevel@tonic-gate ipcp_options *ho = &ipcp_hisoptions[unit];
19907c478bd9Sstevel@tonic-gate char *proto_name = ipcp_protent.name;
19917c478bd9Sstevel@tonic-gate
19927c478bd9Sstevel@tonic-gate if (!ipcp_protent.enabled_flag) {
19937c478bd9Sstevel@tonic-gate (void) flprintf(strptr, "%s disabled\n", proto_name);
19947c478bd9Sstevel@tonic-gate return;
19957c478bd9Sstevel@tonic-gate }
19967c478bd9Sstevel@tonic-gate
19977c478bd9Sstevel@tonic-gate (void) flprintf(strptr, "%s state: %s", proto_name,
19987c478bd9Sstevel@tonic-gate fsm_state(ipcp_fsm[unit].state));
19997c478bd9Sstevel@tonic-gate (void) flprintf(strptr, "%s local %I remote %I", proto_name, go->ouraddr,
20007c478bd9Sstevel@tonic-gate ho->ouraddr);
20017c478bd9Sstevel@tonic-gate }
2002