17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * ipcp.c - PPP IP Control Protocol.
37c478bd9Sstevel@tonic-gate *
4*f53eecf5SJames Carlson * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
57c478bd9Sstevel@tonic-gate * Use is subject to license terms.
67c478bd9Sstevel@tonic-gate *
77c478bd9Sstevel@tonic-gate * Copyright (c) 1989 Carnegie Mellon University.
87c478bd9Sstevel@tonic-gate * All rights reserved.
97c478bd9Sstevel@tonic-gate *
107c478bd9Sstevel@tonic-gate * Redistribution and use in source and binary forms are permitted
117c478bd9Sstevel@tonic-gate * provided that the above copyright notice and this paragraph are
127c478bd9Sstevel@tonic-gate * duplicated in all such forms and that any documentation,
137c478bd9Sstevel@tonic-gate * advertising materials, and other materials related to such
147c478bd9Sstevel@tonic-gate * distribution and use acknowledge that the software was developed
157c478bd9Sstevel@tonic-gate * by Carnegie Mellon University. The name of the
167c478bd9Sstevel@tonic-gate * University may not be used to endorse or promote products derived
177c478bd9Sstevel@tonic-gate * from this software without specific prior written permission.
187c478bd9Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
197c478bd9Sstevel@tonic-gate * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
207c478bd9Sstevel@tonic-gate * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate
237c478bd9Sstevel@tonic-gate #define RCSID "$Id: ipcp.c,v 1.54 2000/04/15 01:27:11 masputra Exp $"
247c478bd9Sstevel@tonic-gate
257c478bd9Sstevel@tonic-gate /*
267c478bd9Sstevel@tonic-gate * TODO:
277c478bd9Sstevel@tonic-gate */
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate #include <stdio.h>
307c478bd9Sstevel@tonic-gate #include <string.h>
317c478bd9Sstevel@tonic-gate #include <netdb.h>
327c478bd9Sstevel@tonic-gate #include <sys/param.h>
337c478bd9Sstevel@tonic-gate #include <sys/types.h>
347c478bd9Sstevel@tonic-gate #include <sys/socket.h>
357c478bd9Sstevel@tonic-gate #if defined(_linux_) || defined(__linux__)
367c478bd9Sstevel@tonic-gate #define __FAVOR_BSD
377c478bd9Sstevel@tonic-gate #endif
387c478bd9Sstevel@tonic-gate #include <netinet/in.h>
397c478bd9Sstevel@tonic-gate #include <netinet/tcp.h>
407c478bd9Sstevel@tonic-gate #include <arpa/inet.h>
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate #include "pppd.h"
437c478bd9Sstevel@tonic-gate #include "fsm.h"
447c478bd9Sstevel@tonic-gate #include "ipcp.h"
457c478bd9Sstevel@tonic-gate #include "pathnames.h"
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate #if !defined(lint) && !defined(_lint)
487c478bd9Sstevel@tonic-gate static const char rcsid[] = RCSID;
497c478bd9Sstevel@tonic-gate #endif
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate /* global vars */
527c478bd9Sstevel@tonic-gate ipcp_options ipcp_wantoptions[NUM_PPP]; /* Options that we want to request */
537c478bd9Sstevel@tonic-gate ipcp_options ipcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
547c478bd9Sstevel@tonic-gate ipcp_options ipcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
557c478bd9Sstevel@tonic-gate ipcp_options ipcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate bool ipcp_from_hostname = 0; /* Local IP address is from hostname lookup */
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate /* Hook for a plugin to know when IP protocol has come up */
607c478bd9Sstevel@tonic-gate void (*ip_up_hook) __P((void)) = NULL;
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate /* Hook for a plugin to know when IP protocol has come down */
637c478bd9Sstevel@tonic-gate void (*ip_down_hook) __P((void)) = NULL;
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gate /* local vars */
667c478bd9Sstevel@tonic-gate static bool default_route_set[NUM_PPP]; /* Have set up a default route */
677c478bd9Sstevel@tonic-gate static bool proxy_arp_set[NUM_PPP]; /* Have created proxy arp entry */
687c478bd9Sstevel@tonic-gate static bool ipcp_is_up[NUM_PPP]; /* have called np_up() */
697c478bd9Sstevel@tonic-gate static bool proxy_arp_quiet[NUM_PPP]; /* We should be quiet on error */
707c478bd9Sstevel@tonic-gate static bool disable_defaultip = 0; /* Don't use hostname for IP addr */
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate /*
737c478bd9Sstevel@tonic-gate * Callbacks for fsm code. (CI = Configuration Information)
747c478bd9Sstevel@tonic-gate */
757c478bd9Sstevel@tonic-gate static void ipcp_resetci __P((fsm *)); /* Reset our CI */
767c478bd9Sstevel@tonic-gate static int ipcp_cilen __P((fsm *)); /* Return length of our CI */
777c478bd9Sstevel@tonic-gate static void ipcp_addci __P((fsm *, u_char *, int *)); /* Add our CI */
787c478bd9Sstevel@tonic-gate static int ipcp_ackci __P((fsm *, u_char *, int)); /* Peer ack'd our CI */
797c478bd9Sstevel@tonic-gate static int ipcp_nakci __P((fsm *, u_char *, int)); /* Peer nak'd our CI */
807c478bd9Sstevel@tonic-gate static int ipcp_rejci __P((fsm *, u_char *, int)); /* Peer rej'd our CI */
817c478bd9Sstevel@tonic-gate static int ipcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv CI */
827c478bd9Sstevel@tonic-gate static void ipcp_up __P((fsm *)); /* We're UP */
837c478bd9Sstevel@tonic-gate static void ipcp_down __P((fsm *)); /* We're DOWN */
847c478bd9Sstevel@tonic-gate static void ipcp_finished __P((fsm *)); /* Don't need lower layer */
857c478bd9Sstevel@tonic-gate static int setmsservaddr __P((char *, u_int32_t *));
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gate fsm ipcp_fsm[NUM_PPP]; /* IPCP fsm structure */
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gate static fsm_callbacks ipcp_callbacks = { /* IPCP callback routines */
907c478bd9Sstevel@tonic-gate ipcp_resetci, /* Reset our Configuration Information */
917c478bd9Sstevel@tonic-gate ipcp_cilen, /* Length of our Configuration Information */
927c478bd9Sstevel@tonic-gate ipcp_addci, /* Add our Configuration Information */
937c478bd9Sstevel@tonic-gate ipcp_ackci, /* ACK our Configuration Information */
947c478bd9Sstevel@tonic-gate ipcp_nakci, /* NAK our Configuration Information */
957c478bd9Sstevel@tonic-gate ipcp_rejci, /* Reject our Configuration Information */
967c478bd9Sstevel@tonic-gate ipcp_reqci, /* Request peer's Configuration Information */
977c478bd9Sstevel@tonic-gate ipcp_up, /* Called when fsm reaches OPENED state */
987c478bd9Sstevel@tonic-gate ipcp_down, /* Called when fsm leaves OPENED state */
997c478bd9Sstevel@tonic-gate NULL, /* Called when we want the lower layer up */
1007c478bd9Sstevel@tonic-gate ipcp_finished, /* Called when we want the lower layer down */
1017c478bd9Sstevel@tonic-gate NULL, /* Retransmission is necessary */
1027c478bd9Sstevel@tonic-gate NULL, /* Called to handle protocol-specific codes */
1037c478bd9Sstevel@tonic-gate "IPCP", /* String name of protocol */
1047c478bd9Sstevel@tonic-gate NULL /* Peer rejected a code number */
1057c478bd9Sstevel@tonic-gate };
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate /*
1087c478bd9Sstevel@tonic-gate * Command-line options.
1097c478bd9Sstevel@tonic-gate */
1107c478bd9Sstevel@tonic-gate static int setvjslots __P((char **));
1117c478bd9Sstevel@tonic-gate static int setdnsaddr __P((char **));
1127c478bd9Sstevel@tonic-gate static int setwinsaddr __P((char **));
1137c478bd9Sstevel@tonic-gate static int autoproxyarp __P((char **));
1147c478bd9Sstevel@tonic-gate
1157c478bd9Sstevel@tonic-gate static option_t ipcp_option_list[] = {
1167c478bd9Sstevel@tonic-gate { "noip", o_bool, &ipcp_protent.enabled_flag,
1177c478bd9Sstevel@tonic-gate "Disable IP and IPCP" },
1187c478bd9Sstevel@tonic-gate { "-ip", o_bool, &ipcp_protent.enabled_flag,
1197c478bd9Sstevel@tonic-gate "Disable IP and IPCP" },
1207c478bd9Sstevel@tonic-gate { "novj", o_bool, &ipcp_wantoptions[0].neg_vj,
1217c478bd9Sstevel@tonic-gate "Disable VJ compression", OPT_A2COPY, &ipcp_allowoptions[0].neg_vj },
1227c478bd9Sstevel@tonic-gate { "-vj", o_bool, &ipcp_wantoptions[0].neg_vj,
1237c478bd9Sstevel@tonic-gate "Disable VJ compression", OPT_A2COPY, &ipcp_allowoptions[0].neg_vj },
1247c478bd9Sstevel@tonic-gate { "novjccomp", o_bool, &ipcp_wantoptions[0].cflag,
1257c478bd9Sstevel@tonic-gate "Disable VJ connection-ID compression", OPT_A2COPY,
1267c478bd9Sstevel@tonic-gate &ipcp_allowoptions[0].cflag },
1277c478bd9Sstevel@tonic-gate { "-vjccomp", o_bool, &ipcp_wantoptions[0].cflag,
1287c478bd9Sstevel@tonic-gate "Disable VJ connection-ID compression", OPT_A2COPY,
1297c478bd9Sstevel@tonic-gate &ipcp_allowoptions[0].cflag },
1307c478bd9Sstevel@tonic-gate { "vj-max-slots", o_special, (void *)setvjslots,
1317c478bd9Sstevel@tonic-gate "Set maximum VJ header slots" },
1327c478bd9Sstevel@tonic-gate { "ipcp-accept-local", o_bool, &ipcp_wantoptions[0].accept_local,
1337c478bd9Sstevel@tonic-gate "Accept peer's address for us", 1 },
1347c478bd9Sstevel@tonic-gate { "ipcp-accept-remote", o_bool, &ipcp_wantoptions[0].accept_remote,
1357c478bd9Sstevel@tonic-gate "Accept peer's address for it", 1 },
1367c478bd9Sstevel@tonic-gate { "ipparam", o_string, &ipparam,
1377c478bd9Sstevel@tonic-gate "Set ip script parameter" },
1387c478bd9Sstevel@tonic-gate { "noipdefault", o_bool, &disable_defaultip,
1397c478bd9Sstevel@tonic-gate "Don't use name for default IP adrs", 1 },
1407c478bd9Sstevel@tonic-gate { "ms-dns", o_special, (void *)setdnsaddr,
1417c478bd9Sstevel@tonic-gate "DNS address for the peer's use" },
1427c478bd9Sstevel@tonic-gate { "ms-wins", o_special, (void *)setwinsaddr,
1437c478bd9Sstevel@tonic-gate "Nameserver for SMB over TCP/IP for peer" },
1447c478bd9Sstevel@tonic-gate { "ipcp-restart", o_int, &ipcp_fsm[0].timeouttime,
1457c478bd9Sstevel@tonic-gate "Set timeout for IPCP" },
1467c478bd9Sstevel@tonic-gate { "ipcp-max-terminate", o_int, &ipcp_fsm[0].maxtermtransmits,
1477c478bd9Sstevel@tonic-gate "Set max #xmits for term-reqs" },
1487c478bd9Sstevel@tonic-gate { "ipcp-max-configure", o_int, &ipcp_fsm[0].maxconfreqtransmits,
1497c478bd9Sstevel@tonic-gate "Set max #xmits for conf-reqs" },
1507c478bd9Sstevel@tonic-gate { "ipcp-max-failure", o_int, &ipcp_fsm[0].maxnakloops,
1517c478bd9Sstevel@tonic-gate "Set max #conf-naks for IPCP" },
1527c478bd9Sstevel@tonic-gate { "defaultroute", o_bool, &ipcp_wantoptions[0].default_route,
1537c478bd9Sstevel@tonic-gate "Add default route", OPT_ENABLE|1, &ipcp_allowoptions[0].default_route },
1547c478bd9Sstevel@tonic-gate { "nodefaultroute", o_bool, &ipcp_allowoptions[0].default_route,
1557c478bd9Sstevel@tonic-gate "disable defaultroute option", OPT_A2COPY,
1567c478bd9Sstevel@tonic-gate &ipcp_wantoptions[0].default_route },
1577c478bd9Sstevel@tonic-gate { "-defaultroute", o_bool, &ipcp_allowoptions[0].default_route,
1587c478bd9Sstevel@tonic-gate "disable defaultroute option", OPT_A2COPY,
1597c478bd9Sstevel@tonic-gate &ipcp_wantoptions[0].default_route },
1607c478bd9Sstevel@tonic-gate { "proxyarp", o_bool, &ipcp_wantoptions[0].proxy_arp,
1617c478bd9Sstevel@tonic-gate "Add proxy ARP entry", OPT_ENABLE|1, &ipcp_allowoptions[0].proxy_arp },
1627c478bd9Sstevel@tonic-gate { "autoproxyarp", o_special_noarg, (void *)autoproxyarp,
1637c478bd9Sstevel@tonic-gate "Add proxy ARP entry if needed", OPT_ENABLE,
1647c478bd9Sstevel@tonic-gate &ipcp_allowoptions[0].proxy_arp },
1657c478bd9Sstevel@tonic-gate { "noproxyarp", o_bool, &ipcp_allowoptions[0].proxy_arp,
1667c478bd9Sstevel@tonic-gate "disable proxyarp option", OPT_A2COPY, &ipcp_wantoptions[0].proxy_arp },
1677c478bd9Sstevel@tonic-gate { "-proxyarp", o_bool, &ipcp_allowoptions[0].proxy_arp,
1687c478bd9Sstevel@tonic-gate "disable proxyarp option", OPT_A2COPY, &ipcp_wantoptions[0].proxy_arp },
1697c478bd9Sstevel@tonic-gate { "usepeerdns", o_bool, &ipcp_wantoptions[0].req_dns1,
1707c478bd9Sstevel@tonic-gate "Ask peer for DNS address(es)", OPT_A2COPY|1,
1717c478bd9Sstevel@tonic-gate &ipcp_wantoptions[0].req_dns2 },
1727c478bd9Sstevel@tonic-gate { NULL }
1737c478bd9Sstevel@tonic-gate };
1747c478bd9Sstevel@tonic-gate
1757c478bd9Sstevel@tonic-gate /*
1767c478bd9Sstevel@tonic-gate * Protocol entry points from main code.
1777c478bd9Sstevel@tonic-gate */
1787c478bd9Sstevel@tonic-gate static void ipcp_init __P((int));
1797c478bd9Sstevel@tonic-gate static void ipcp_open __P((int));
1807c478bd9Sstevel@tonic-gate static void ipcp_close __P((int, char *));
1817c478bd9Sstevel@tonic-gate static void ipcp_lowerup __P((int));
1827c478bd9Sstevel@tonic-gate static void ipcp_lowerdown __P((int));
1837c478bd9Sstevel@tonic-gate static void ipcp_input __P((int, u_char *, int));
1847c478bd9Sstevel@tonic-gate static void ipcp_protrej __P((int));
1857c478bd9Sstevel@tonic-gate static int ipcp_printpkt __P((u_char *, int,
1867c478bd9Sstevel@tonic-gate void (*) __P((void *, const char *, ...)), void *));
1877c478bd9Sstevel@tonic-gate static void ip_check_options __P((void));
1887c478bd9Sstevel@tonic-gate static int ip_demand_conf __P((int));
1897c478bd9Sstevel@tonic-gate static int ip_active_pkt __P((u_char *, int));
1907c478bd9Sstevel@tonic-gate static void ipcp_print_stat __P((int, FILE *));
1917c478bd9Sstevel@tonic-gate
1927c478bd9Sstevel@tonic-gate static void create_resolv __P((u_int32_t, u_int32_t));
1937c478bd9Sstevel@tonic-gate
1947c478bd9Sstevel@tonic-gate struct protent ipcp_protent = {
1957c478bd9Sstevel@tonic-gate PPP_IPCP,
1967c478bd9Sstevel@tonic-gate ipcp_init,
1977c478bd9Sstevel@tonic-gate ipcp_input,
1987c478bd9Sstevel@tonic-gate ipcp_protrej,
1997c478bd9Sstevel@tonic-gate ipcp_lowerup,
2007c478bd9Sstevel@tonic-gate ipcp_lowerdown,
2017c478bd9Sstevel@tonic-gate ipcp_open,
2027c478bd9Sstevel@tonic-gate ipcp_close,
2037c478bd9Sstevel@tonic-gate ipcp_printpkt,
2047c478bd9Sstevel@tonic-gate NULL,
2057c478bd9Sstevel@tonic-gate 1,
2067c478bd9Sstevel@tonic-gate "IPCP",
2077c478bd9Sstevel@tonic-gate "IP",
2087c478bd9Sstevel@tonic-gate ipcp_option_list,
2097c478bd9Sstevel@tonic-gate ip_check_options,
2107c478bd9Sstevel@tonic-gate ip_demand_conf,
2117c478bd9Sstevel@tonic-gate ip_active_pkt,
2127c478bd9Sstevel@tonic-gate ipcp_print_stat
2137c478bd9Sstevel@tonic-gate };
2147c478bd9Sstevel@tonic-gate
2157c478bd9Sstevel@tonic-gate static void ipcp_clear_addrs __P((int, u_int32_t, u_int32_t));
2167c478bd9Sstevel@tonic-gate static void ipcp_script __P((char *)); /* Run an up/down script */
2177c478bd9Sstevel@tonic-gate static void ipcp_script_done __P((void *, int));
2187c478bd9Sstevel@tonic-gate
2197c478bd9Sstevel@tonic-gate /*
2207c478bd9Sstevel@tonic-gate * Lengths of configuration options.
2217c478bd9Sstevel@tonic-gate */
2227c478bd9Sstevel@tonic-gate #define CILEN_VOID 2
2237c478bd9Sstevel@tonic-gate #define CILEN_COMPRESS 4 /* min length for compression protocol opt. */
2247c478bd9Sstevel@tonic-gate #define CILEN_VJ 6 /* length for RFC1332 Van-Jacobson opt. */
2257c478bd9Sstevel@tonic-gate #define CILEN_ADDR 6 /* new-style single address option */
2267c478bd9Sstevel@tonic-gate #define CILEN_ADDRS 10 /* old-style dual address option */
2277c478bd9Sstevel@tonic-gate
2287c478bd9Sstevel@tonic-gate
2297c478bd9Sstevel@tonic-gate /*
2307c478bd9Sstevel@tonic-gate * This state variable is used to ensure that we don't
2317c478bd9Sstevel@tonic-gate * run an ipcp-up/down script while one is already running.
2327c478bd9Sstevel@tonic-gate */
2337c478bd9Sstevel@tonic-gate static enum script_state {
2347c478bd9Sstevel@tonic-gate s_down,
2357c478bd9Sstevel@tonic-gate s_up
2367c478bd9Sstevel@tonic-gate } ipcp_script_state;
2377c478bd9Sstevel@tonic-gate static pid_t ipcp_script_pid;
2387c478bd9Sstevel@tonic-gate
2397c478bd9Sstevel@tonic-gate /*
2407c478bd9Sstevel@tonic-gate * Make a string representation of a network IP address.
2417c478bd9Sstevel@tonic-gate */
2427c478bd9Sstevel@tonic-gate char *
ip_ntoa(ipaddr)2437c478bd9Sstevel@tonic-gate ip_ntoa(ipaddr)
2447c478bd9Sstevel@tonic-gate u_int32_t ipaddr;
2457c478bd9Sstevel@tonic-gate {
2467c478bd9Sstevel@tonic-gate static char b[64];
2477c478bd9Sstevel@tonic-gate
2487c478bd9Sstevel@tonic-gate (void) slprintf(b, sizeof(b), "%I", ipaddr);
2497c478bd9Sstevel@tonic-gate return b;
2507c478bd9Sstevel@tonic-gate }
2517c478bd9Sstevel@tonic-gate
2527c478bd9Sstevel@tonic-gate /*
2537c478bd9Sstevel@tonic-gate * Option parsing.
2547c478bd9Sstevel@tonic-gate */
2557c478bd9Sstevel@tonic-gate
2567c478bd9Sstevel@tonic-gate /*
2577c478bd9Sstevel@tonic-gate * setvjslots - set maximum number of connection slots for VJ compression
2587c478bd9Sstevel@tonic-gate */
2597c478bd9Sstevel@tonic-gate static int
setvjslots(argv)2607c478bd9Sstevel@tonic-gate setvjslots(argv)
2617c478bd9Sstevel@tonic-gate char **argv;
2627c478bd9Sstevel@tonic-gate {
2637c478bd9Sstevel@tonic-gate int value;
2647c478bd9Sstevel@tonic-gate
2657c478bd9Sstevel@tonic-gate if (!int_option(*argv, &value))
2667c478bd9Sstevel@tonic-gate return 0;
2677c478bd9Sstevel@tonic-gate if (value < 2 || value > 16) {
2687c478bd9Sstevel@tonic-gate option_error("vj-max-slots value must be between 2 and 16");
2697c478bd9Sstevel@tonic-gate return 0;
2707c478bd9Sstevel@tonic-gate }
2717c478bd9Sstevel@tonic-gate ipcp_wantoptions [0].maxslotindex =
2727c478bd9Sstevel@tonic-gate ipcp_allowoptions[0].maxslotindex = value - 1;
2737c478bd9Sstevel@tonic-gate return 1;
2747c478bd9Sstevel@tonic-gate }
2757c478bd9Sstevel@tonic-gate
2767c478bd9Sstevel@tonic-gate /*
2777c478bd9Sstevel@tonic-gate * setmsservaddr - Set the primary and secondary server addresses in the
2787c478bd9Sstevel@tonic-gate * array. setdnsaddr() and setwinsaddr() call this function with either
2797c478bd9Sstevel@tonic-gate * dnsaddr[] or winsaddr[] as the serverarray argument.
2807c478bd9Sstevel@tonic-gate */
2817c478bd9Sstevel@tonic-gate static int
setmsservaddr(servname,serverarray)2827c478bd9Sstevel@tonic-gate setmsservaddr(servname, serverarray)
2837c478bd9Sstevel@tonic-gate char *servname;
2847c478bd9Sstevel@tonic-gate u_int32_t *serverarray;
2857c478bd9Sstevel@tonic-gate {
2867c478bd9Sstevel@tonic-gate u_int32_t addr;
2877c478bd9Sstevel@tonic-gate struct hostent *hp = NULL;
2887c478bd9Sstevel@tonic-gate
2897c478bd9Sstevel@tonic-gate addr = inet_addr(servname);
2907c478bd9Sstevel@tonic-gate if (addr == (u_int32_t) -1) {
2917c478bd9Sstevel@tonic-gate if ((hp = gethostbyname(servname)) == NULL)
2927c478bd9Sstevel@tonic-gate return 0;
2937c478bd9Sstevel@tonic-gate BCOPY(hp->h_addr, &addr, sizeof (u_int32_t));
2947c478bd9Sstevel@tonic-gate }
2957c478bd9Sstevel@tonic-gate
2967c478bd9Sstevel@tonic-gate /*
2977c478bd9Sstevel@tonic-gate * If there is no primary then this is the first instance of the
2987c478bd9Sstevel@tonic-gate * option, we must set the primary. In that case, try to set the
2997c478bd9Sstevel@tonic-gate * secondary to h_addr_list[1]. If the primary is already set, then
3007c478bd9Sstevel@tonic-gate * this is the second instance of the option, and we must set
3017c478bd9Sstevel@tonic-gate * the secondary.
3027c478bd9Sstevel@tonic-gate */
3037c478bd9Sstevel@tonic-gate if (serverarray[0] == 0) {
3047c478bd9Sstevel@tonic-gate serverarray[0] = addr;
3057c478bd9Sstevel@tonic-gate if (hp != NULL && hp->h_addr_list[1] != NULL)
3067c478bd9Sstevel@tonic-gate BCOPY(hp->h_addr_list[1], &serverarray[1], sizeof (u_int32_t));
3077c478bd9Sstevel@tonic-gate else
3087c478bd9Sstevel@tonic-gate serverarray[1] = addr;
3097c478bd9Sstevel@tonic-gate } else {
3107c478bd9Sstevel@tonic-gate serverarray[1] = addr;
3117c478bd9Sstevel@tonic-gate }
3127c478bd9Sstevel@tonic-gate
3137c478bd9Sstevel@tonic-gate return (1);
3147c478bd9Sstevel@tonic-gate }
3157c478bd9Sstevel@tonic-gate
3167c478bd9Sstevel@tonic-gate /*
3177c478bd9Sstevel@tonic-gate * setdnsaddr - set the dns address(es)
3187c478bd9Sstevel@tonic-gate */
3197c478bd9Sstevel@tonic-gate static int
setdnsaddr(argv)3207c478bd9Sstevel@tonic-gate setdnsaddr(argv)
3217c478bd9Sstevel@tonic-gate char **argv;
3227c478bd9Sstevel@tonic-gate {
3237c478bd9Sstevel@tonic-gate if (setmsservaddr(*argv, &(ipcp_allowoptions[0].dnsaddr[0])) == 0) {
3247c478bd9Sstevel@tonic-gate option_error("invalid address parameter '%s' for ms-dns option", *argv);
3257c478bd9Sstevel@tonic-gate return (0);
3267c478bd9Sstevel@tonic-gate }
3277c478bd9Sstevel@tonic-gate
3287c478bd9Sstevel@tonic-gate return (1);
3297c478bd9Sstevel@tonic-gate }
3307c478bd9Sstevel@tonic-gate
3317c478bd9Sstevel@tonic-gate /*
3327c478bd9Sstevel@tonic-gate * setwinsaddr - set the wins address(es)
3337c478bd9Sstevel@tonic-gate * This is primrarly used with the Samba package under UNIX or for pointing
3347c478bd9Sstevel@tonic-gate * the caller to the existing WINS server on a Windows NT platform.
3357c478bd9Sstevel@tonic-gate */
3367c478bd9Sstevel@tonic-gate static int
setwinsaddr(argv)3377c478bd9Sstevel@tonic-gate setwinsaddr(argv)
3387c478bd9Sstevel@tonic-gate char **argv;
3397c478bd9Sstevel@tonic-gate {
3407c478bd9Sstevel@tonic-gate if (setmsservaddr(*argv, &(ipcp_allowoptions[0].winsaddr[0])) == 0) {
3417c478bd9Sstevel@tonic-gate option_error("invalid address parameter '%s' for ms-wins option",
3427c478bd9Sstevel@tonic-gate *argv);
3437c478bd9Sstevel@tonic-gate return (0);
3447c478bd9Sstevel@tonic-gate }
3457c478bd9Sstevel@tonic-gate
3467c478bd9Sstevel@tonic-gate return (1);
3477c478bd9Sstevel@tonic-gate }
3487c478bd9Sstevel@tonic-gate
3497c478bd9Sstevel@tonic-gate /*
3507c478bd9Sstevel@tonic-gate * autoproxyarp -- enable proxy ARP but don't emit error messages if
3517c478bd9Sstevel@tonic-gate * it's not actually needed.
3527c478bd9Sstevel@tonic-gate */
3537c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3547c478bd9Sstevel@tonic-gate static int
autoproxyarp(argv)3557c478bd9Sstevel@tonic-gate autoproxyarp(argv)
3567c478bd9Sstevel@tonic-gate char **argv;
3577c478bd9Sstevel@tonic-gate {
3587c478bd9Sstevel@tonic-gate ipcp_wantoptions[0].proxy_arp = 1;
3597c478bd9Sstevel@tonic-gate proxy_arp_quiet[0] = 1;
3607c478bd9Sstevel@tonic-gate
3617c478bd9Sstevel@tonic-gate return (1);
3627c478bd9Sstevel@tonic-gate }
3637c478bd9Sstevel@tonic-gate
3647c478bd9Sstevel@tonic-gate
3657c478bd9Sstevel@tonic-gate /*
3667c478bd9Sstevel@tonic-gate * ipcp_init - Initialize IPCP.
3677c478bd9Sstevel@tonic-gate */
3687c478bd9Sstevel@tonic-gate static void
ipcp_init(unit)3697c478bd9Sstevel@tonic-gate ipcp_init(unit)
3707c478bd9Sstevel@tonic-gate int unit;
3717c478bd9Sstevel@tonic-gate {
3727c478bd9Sstevel@tonic-gate fsm *f = &ipcp_fsm[unit];
3737c478bd9Sstevel@tonic-gate ipcp_options *wo = &ipcp_wantoptions[unit];
3747c478bd9Sstevel@tonic-gate ipcp_options *ao = &ipcp_allowoptions[unit];
3757c478bd9Sstevel@tonic-gate
3767c478bd9Sstevel@tonic-gate f->unit = unit;
3777c478bd9Sstevel@tonic-gate f->protocol = PPP_IPCP;
3787c478bd9Sstevel@tonic-gate f->callbacks = &ipcp_callbacks;
3797c478bd9Sstevel@tonic-gate fsm_init(&ipcp_fsm[unit]);
3807c478bd9Sstevel@tonic-gate
3817c478bd9Sstevel@tonic-gate BZERO(wo, sizeof(*wo));
3827c478bd9Sstevel@tonic-gate BZERO(ao, sizeof(*ao));
3837c478bd9Sstevel@tonic-gate
384*f53eecf5SJames Carlson wo->neg_addr = wo->old_addrs = 1;
3857c478bd9Sstevel@tonic-gate wo->neg_vj = 1;
3867c478bd9Sstevel@tonic-gate wo->vj_protocol = IPCP_VJ_COMP;
3877c478bd9Sstevel@tonic-gate wo->maxslotindex = MAX_STATES - 1; /* really max index */
3887c478bd9Sstevel@tonic-gate wo->cflag = 1;
3897c478bd9Sstevel@tonic-gate
390*f53eecf5SJames Carlson ao->neg_addr = ao->old_addrs = 1;
3917c478bd9Sstevel@tonic-gate ao->neg_vj = 1;
3927c478bd9Sstevel@tonic-gate ao->maxslotindex = MAX_STATES - 1;
3937c478bd9Sstevel@tonic-gate ao->cflag = 1;
3947c478bd9Sstevel@tonic-gate
3957c478bd9Sstevel@tonic-gate /*
3967c478bd9Sstevel@tonic-gate * These aren't actually negotiated. Instead, they control
3977c478bd9Sstevel@tonic-gate * whether the user may use the proxyarp and defaultroute options.
3987c478bd9Sstevel@tonic-gate */
3997c478bd9Sstevel@tonic-gate ao->proxy_arp = 1;
4007c478bd9Sstevel@tonic-gate ao->default_route = 1;
4017c478bd9Sstevel@tonic-gate proxy_arp_quiet[unit] = 0;
4027c478bd9Sstevel@tonic-gate }
4037c478bd9Sstevel@tonic-gate
4047c478bd9Sstevel@tonic-gate
4057c478bd9Sstevel@tonic-gate /*
4067c478bd9Sstevel@tonic-gate * ipcp_open - IPCP is allowed to come up.
4077c478bd9Sstevel@tonic-gate */
4087c478bd9Sstevel@tonic-gate static void
ipcp_open(unit)4097c478bd9Sstevel@tonic-gate ipcp_open(unit)
4107c478bd9Sstevel@tonic-gate int unit;
4117c478bd9Sstevel@tonic-gate {
4127c478bd9Sstevel@tonic-gate fsm_open(&ipcp_fsm[unit]);
4137c478bd9Sstevel@tonic-gate }
4147c478bd9Sstevel@tonic-gate
4157c478bd9Sstevel@tonic-gate
4167c478bd9Sstevel@tonic-gate /*
4177c478bd9Sstevel@tonic-gate * ipcp_close - Take IPCP down.
4187c478bd9Sstevel@tonic-gate */
4197c478bd9Sstevel@tonic-gate static void
ipcp_close(unit,reason)4207c478bd9Sstevel@tonic-gate ipcp_close(unit, reason)
4217c478bd9Sstevel@tonic-gate int unit;
4227c478bd9Sstevel@tonic-gate char *reason;
4237c478bd9Sstevel@tonic-gate {
4247c478bd9Sstevel@tonic-gate fsm_close(&ipcp_fsm[unit], reason);
4257c478bd9Sstevel@tonic-gate }
4267c478bd9Sstevel@tonic-gate
4277c478bd9Sstevel@tonic-gate
4287c478bd9Sstevel@tonic-gate /*
4297c478bd9Sstevel@tonic-gate * ipcp_lowerup - The lower layer is up.
4307c478bd9Sstevel@tonic-gate */
4317c478bd9Sstevel@tonic-gate static void
ipcp_lowerup(unit)4327c478bd9Sstevel@tonic-gate ipcp_lowerup(unit)
4337c478bd9Sstevel@tonic-gate int unit;
4347c478bd9Sstevel@tonic-gate {
4357c478bd9Sstevel@tonic-gate fsm_lowerup(&ipcp_fsm[unit]);
4367c478bd9Sstevel@tonic-gate }
4377c478bd9Sstevel@tonic-gate
4387c478bd9Sstevel@tonic-gate
4397c478bd9Sstevel@tonic-gate /*
4407c478bd9Sstevel@tonic-gate * ipcp_lowerdown - The lower layer is down.
4417c478bd9Sstevel@tonic-gate */
4427c478bd9Sstevel@tonic-gate static void
ipcp_lowerdown(unit)4437c478bd9Sstevel@tonic-gate ipcp_lowerdown(unit)
4447c478bd9Sstevel@tonic-gate int unit;
4457c478bd9Sstevel@tonic-gate {
4467c478bd9Sstevel@tonic-gate fsm_lowerdown(&ipcp_fsm[unit]);
4477c478bd9Sstevel@tonic-gate }
4487c478bd9Sstevel@tonic-gate
4497c478bd9Sstevel@tonic-gate
4507c478bd9Sstevel@tonic-gate /*
4517c478bd9Sstevel@tonic-gate * ipcp_input - Input IPCP packet.
4527c478bd9Sstevel@tonic-gate */
4537c478bd9Sstevel@tonic-gate static void
ipcp_input(unit,p,len)4547c478bd9Sstevel@tonic-gate ipcp_input(unit, p, len)
4557c478bd9Sstevel@tonic-gate int unit;
4567c478bd9Sstevel@tonic-gate u_char *p;
4577c478bd9Sstevel@tonic-gate int len;
4587c478bd9Sstevel@tonic-gate {
4597c478bd9Sstevel@tonic-gate fsm_input(&ipcp_fsm[unit], p, len);
4607c478bd9Sstevel@tonic-gate }
4617c478bd9Sstevel@tonic-gate
4627c478bd9Sstevel@tonic-gate
4637c478bd9Sstevel@tonic-gate /*
4647c478bd9Sstevel@tonic-gate * ipcp_protrej - A Protocol-Reject was received for IPCP.
4657c478bd9Sstevel@tonic-gate */
4667c478bd9Sstevel@tonic-gate static void
ipcp_protrej(unit)4677c478bd9Sstevel@tonic-gate ipcp_protrej(unit)
4687c478bd9Sstevel@tonic-gate int unit;
4697c478bd9Sstevel@tonic-gate {
4707c478bd9Sstevel@tonic-gate fsm_protreject(&ipcp_fsm[unit]);
4717c478bd9Sstevel@tonic-gate }
4727c478bd9Sstevel@tonic-gate
4737c478bd9Sstevel@tonic-gate
4747c478bd9Sstevel@tonic-gate /*
4757c478bd9Sstevel@tonic-gate * ipcp_resetci - Reset our CI.
4767c478bd9Sstevel@tonic-gate * Called by fsm_sconfreq, Send Configure Request.
4777c478bd9Sstevel@tonic-gate */
4787c478bd9Sstevel@tonic-gate static void
ipcp_resetci(f)4797c478bd9Sstevel@tonic-gate ipcp_resetci(f)
4807c478bd9Sstevel@tonic-gate fsm *f;
4817c478bd9Sstevel@tonic-gate {
4827c478bd9Sstevel@tonic-gate ipcp_options *wo = &ipcp_wantoptions[f->unit];
4837c478bd9Sstevel@tonic-gate ipcp_options *go = &ipcp_gotoptions[f->unit];
484*f53eecf5SJames Carlson ipcp_options *ao = &ipcp_allowoptions[f->unit];
4857c478bd9Sstevel@tonic-gate
486*f53eecf5SJames Carlson wo->req_addr = (wo->neg_addr || wo->old_addrs) &&
487*f53eecf5SJames Carlson (ao->neg_addr || ao->old_addrs);
4887c478bd9Sstevel@tonic-gate if (wo->ouraddr == 0 || disable_defaultip)
4897c478bd9Sstevel@tonic-gate wo->accept_local = 1;
4907c478bd9Sstevel@tonic-gate if (wo->hisaddr == 0)
4917c478bd9Sstevel@tonic-gate wo->accept_remote = 1;
4927c478bd9Sstevel@tonic-gate *go = *wo;
4937c478bd9Sstevel@tonic-gate if (disable_defaultip)
4947c478bd9Sstevel@tonic-gate go->ouraddr = 0;
4957c478bd9Sstevel@tonic-gate }
4967c478bd9Sstevel@tonic-gate
4977c478bd9Sstevel@tonic-gate
4987c478bd9Sstevel@tonic-gate /*
4997c478bd9Sstevel@tonic-gate * ipcp_cilen - Return length of our CI.
5007c478bd9Sstevel@tonic-gate * Called by fsm_sconfreq, Send Configure Request.
5017c478bd9Sstevel@tonic-gate */
5027c478bd9Sstevel@tonic-gate static int
ipcp_cilen(f)5037c478bd9Sstevel@tonic-gate ipcp_cilen(f)
5047c478bd9Sstevel@tonic-gate fsm *f;
5057c478bd9Sstevel@tonic-gate {
5067c478bd9Sstevel@tonic-gate ipcp_options *go = &ipcp_gotoptions[f->unit];
5077c478bd9Sstevel@tonic-gate ipcp_options *wo = &ipcp_wantoptions[f->unit];
5087c478bd9Sstevel@tonic-gate ipcp_options *ho = &ipcp_hisoptions[f->unit];
5097c478bd9Sstevel@tonic-gate
510*f53eecf5SJames Carlson #define LENCIADDRS(neg) (neg ? CILEN_ADDRS : 0)
5117c478bd9Sstevel@tonic-gate #define LENCIVJ(neg, old) (neg ? (old? CILEN_COMPRESS : CILEN_VJ) : 0)
512*f53eecf5SJames Carlson #define LENCIADDR(neg) (neg ? (CILEN_ADDR) : 0)
5137c478bd9Sstevel@tonic-gate
5147c478bd9Sstevel@tonic-gate /*
5157c478bd9Sstevel@tonic-gate * First see if we want to change our options to the old
5167c478bd9Sstevel@tonic-gate * forms because we have received old forms from the peer.
5177c478bd9Sstevel@tonic-gate */
518*f53eecf5SJames Carlson if (go->neg_addr && go->old_addrs && !ho->neg_addr && ho->old_addrs)
5197c478bd9Sstevel@tonic-gate /* use the old style of address negotiation */
520*f53eecf5SJames Carlson go->neg_addr = 0;
5217c478bd9Sstevel@tonic-gate if (wo->neg_vj && !go->neg_vj && !go->old_vj) {
5227c478bd9Sstevel@tonic-gate /* try an older style of VJ negotiation */
5237c478bd9Sstevel@tonic-gate /* use the old style only if the peer did */
5247c478bd9Sstevel@tonic-gate if (ho->neg_vj && ho->old_vj) {
5257c478bd9Sstevel@tonic-gate go->neg_vj = 1;
5267c478bd9Sstevel@tonic-gate go->old_vj = 1;
5277c478bd9Sstevel@tonic-gate go->vj_protocol = ho->vj_protocol;
5287c478bd9Sstevel@tonic-gate }
5297c478bd9Sstevel@tonic-gate }
5307c478bd9Sstevel@tonic-gate
531*f53eecf5SJames Carlson return (LENCIADDRS(!go->neg_addr && go->old_addrs) +
5327c478bd9Sstevel@tonic-gate LENCIVJ(go->neg_vj, go->old_vj) +
533*f53eecf5SJames Carlson LENCIADDR(go->neg_addr) +
534*f53eecf5SJames Carlson LENCIADDR(go->req_dns1) +
535*f53eecf5SJames Carlson LENCIADDR(go->req_dns2)) ;
5367c478bd9Sstevel@tonic-gate }
5377c478bd9Sstevel@tonic-gate
5387c478bd9Sstevel@tonic-gate
5397c478bd9Sstevel@tonic-gate /*
5407c478bd9Sstevel@tonic-gate * ipcp_addci - Add our desired CIs to a packet.
5417c478bd9Sstevel@tonic-gate * Called by fsm_sconfreq, Send Configure Request.
5427c478bd9Sstevel@tonic-gate */
5437c478bd9Sstevel@tonic-gate static void
ipcp_addci(f,ucp,lenp)5447c478bd9Sstevel@tonic-gate ipcp_addci(f, ucp, lenp)
5457c478bd9Sstevel@tonic-gate fsm *f;
5467c478bd9Sstevel@tonic-gate u_char *ucp;
5477c478bd9Sstevel@tonic-gate int *lenp;
5487c478bd9Sstevel@tonic-gate {
5497c478bd9Sstevel@tonic-gate ipcp_options *go = &ipcp_gotoptions[f->unit];
5507c478bd9Sstevel@tonic-gate int len = *lenp;
5517c478bd9Sstevel@tonic-gate
552*f53eecf5SJames Carlson #define ADDCIADDRS(opt, neg, val1, val2) \
553*f53eecf5SJames Carlson if (neg) { \
554*f53eecf5SJames Carlson if (len >= CILEN_ADDRS) { \
555*f53eecf5SJames Carlson PUTCHAR(opt, ucp); \
556*f53eecf5SJames Carlson PUTCHAR(CILEN_ADDRS, ucp); \
557*f53eecf5SJames Carlson PUTNLONG(val1, ucp); \
558*f53eecf5SJames Carlson PUTNLONG(val2, ucp); \
559*f53eecf5SJames Carlson len -= CILEN_ADDRS; \
560*f53eecf5SJames Carlson } else \
561*f53eecf5SJames Carlson go->old_addrs = 0; \
562*f53eecf5SJames Carlson }
563*f53eecf5SJames Carlson
5647c478bd9Sstevel@tonic-gate #define ADDCIVJ(opt, neg, val, old, maxslotindex, cflag) \
5657c478bd9Sstevel@tonic-gate if (neg) { \
5667c478bd9Sstevel@tonic-gate int vjlen = old? CILEN_COMPRESS : CILEN_VJ; \
5677c478bd9Sstevel@tonic-gate if (len >= vjlen) { \
5687c478bd9Sstevel@tonic-gate PUTCHAR(opt, ucp); \
5697c478bd9Sstevel@tonic-gate PUTCHAR(vjlen, ucp); \
5707c478bd9Sstevel@tonic-gate PUTSHORT(val, ucp); \
5717c478bd9Sstevel@tonic-gate if (!old) { \
5727c478bd9Sstevel@tonic-gate PUTCHAR(maxslotindex, ucp); \
5737c478bd9Sstevel@tonic-gate PUTCHAR(cflag, ucp); \
5747c478bd9Sstevel@tonic-gate } \
5757c478bd9Sstevel@tonic-gate len -= vjlen; \
5767c478bd9Sstevel@tonic-gate } else \
5777c478bd9Sstevel@tonic-gate neg = 0; \
5787c478bd9Sstevel@tonic-gate }
5797c478bd9Sstevel@tonic-gate
580*f53eecf5SJames Carlson #define ADDCIADDR(opt, neg, val) \
5817c478bd9Sstevel@tonic-gate if (neg) { \
5827c478bd9Sstevel@tonic-gate if (len >= CILEN_ADDR) { \
5837c478bd9Sstevel@tonic-gate PUTCHAR(opt, ucp); \
5847c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_ADDR, ucp); \
585*f53eecf5SJames Carlson PUTNLONG(val, ucp); \
5867c478bd9Sstevel@tonic-gate len -= CILEN_ADDR; \
5877c478bd9Sstevel@tonic-gate } else \
5887c478bd9Sstevel@tonic-gate neg = 0; \
5897c478bd9Sstevel@tonic-gate }
5907c478bd9Sstevel@tonic-gate
591*f53eecf5SJames Carlson ADDCIADDRS(CI_ADDRS, !go->neg_addr && go->old_addrs, go->ouraddr,
592*f53eecf5SJames Carlson go->hisaddr);
5937c478bd9Sstevel@tonic-gate
5947c478bd9Sstevel@tonic-gate ADDCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol, go->old_vj,
5957c478bd9Sstevel@tonic-gate go->maxslotindex, go->cflag);
5967c478bd9Sstevel@tonic-gate
597*f53eecf5SJames Carlson ADDCIADDR(CI_ADDR, go->neg_addr, go->ouraddr);
5987c478bd9Sstevel@tonic-gate
599*f53eecf5SJames Carlson ADDCIADDR(CI_MS_DNS1, go->req_dns1, go->dnsaddr[0]);
600*f53eecf5SJames Carlson
601*f53eecf5SJames Carlson ADDCIADDR(CI_MS_DNS2, go->req_dns2, go->dnsaddr[1]);
6027c478bd9Sstevel@tonic-gate
6037c478bd9Sstevel@tonic-gate *lenp -= len;
6047c478bd9Sstevel@tonic-gate }
6057c478bd9Sstevel@tonic-gate
6067c478bd9Sstevel@tonic-gate
6077c478bd9Sstevel@tonic-gate /*
6087c478bd9Sstevel@tonic-gate * ipcp_ackci - Ack our CIs.
6097c478bd9Sstevel@tonic-gate * Called by fsm_rconfack, Receive Configure ACK.
6107c478bd9Sstevel@tonic-gate *
6117c478bd9Sstevel@tonic-gate * Returns:
6127c478bd9Sstevel@tonic-gate * 0 - Ack was bad.
6137c478bd9Sstevel@tonic-gate * 1 - Ack was good.
6147c478bd9Sstevel@tonic-gate */
6157c478bd9Sstevel@tonic-gate static int
ipcp_ackci(f,p,len)6167c478bd9Sstevel@tonic-gate ipcp_ackci(f, p, len)
6177c478bd9Sstevel@tonic-gate fsm *f;
6187c478bd9Sstevel@tonic-gate u_char *p;
6197c478bd9Sstevel@tonic-gate int len;
6207c478bd9Sstevel@tonic-gate {
6217c478bd9Sstevel@tonic-gate ipcp_options *go = &ipcp_gotoptions[f->unit];
6227c478bd9Sstevel@tonic-gate u_short cilen, citype, cishort;
6237c478bd9Sstevel@tonic-gate u_int32_t cilong;
6247c478bd9Sstevel@tonic-gate u_char cimaxslotindex, cicflag;
6257c478bd9Sstevel@tonic-gate
6267c478bd9Sstevel@tonic-gate /*
6277c478bd9Sstevel@tonic-gate * CIs must be in exactly the same order that we sent...
6287c478bd9Sstevel@tonic-gate * Check packet length and CI length at each step.
6297c478bd9Sstevel@tonic-gate * If we find any deviations, then this packet is bad.
6307c478bd9Sstevel@tonic-gate */
6317c478bd9Sstevel@tonic-gate
632*f53eecf5SJames Carlson #define ACKCHECK(opt, olen) \
633*f53eecf5SJames Carlson if ((len -= olen) < 0) \
6347c478bd9Sstevel@tonic-gate goto bad; \
6357c478bd9Sstevel@tonic-gate GETCHAR(citype, p); \
6367c478bd9Sstevel@tonic-gate GETCHAR(cilen, p); \
637*f53eecf5SJames Carlson if (cilen != olen || \
6387c478bd9Sstevel@tonic-gate citype != opt) \
639*f53eecf5SJames Carlson goto bad;
640*f53eecf5SJames Carlson
641*f53eecf5SJames Carlson #define ACKCIADDRS(opt, neg, val1, val2) \
642*f53eecf5SJames Carlson if (neg) { \
643*f53eecf5SJames Carlson ACKCHECK(opt, CILEN_ADDRS) \
644*f53eecf5SJames Carlson GETNLONG(cilong, p); \
645*f53eecf5SJames Carlson if (val1 != cilong) \
6467c478bd9Sstevel@tonic-gate goto bad; \
647*f53eecf5SJames Carlson GETNLONG(cilong, p); \
648*f53eecf5SJames Carlson if (val2 != cilong) \
649*f53eecf5SJames Carlson goto bad; \
650*f53eecf5SJames Carlson }
651*f53eecf5SJames Carlson
652*f53eecf5SJames Carlson #define ACKCIVJ(opt, neg, val, old, maxslotindex, cflag) \
653*f53eecf5SJames Carlson if (neg) { \
654*f53eecf5SJames Carlson int vjlen = old? CILEN_COMPRESS : CILEN_VJ; \
655*f53eecf5SJames Carlson ACKCHECK(opt, vjlen) \
6567c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \
6577c478bd9Sstevel@tonic-gate if (cishort != val) \
6587c478bd9Sstevel@tonic-gate goto bad; \
6597c478bd9Sstevel@tonic-gate if (!old) { \
6607c478bd9Sstevel@tonic-gate GETCHAR(cimaxslotindex, p); \
6617c478bd9Sstevel@tonic-gate if (cimaxslotindex != maxslotindex) \
6627c478bd9Sstevel@tonic-gate goto bad; \
6637c478bd9Sstevel@tonic-gate GETCHAR(cicflag, p); \
6647c478bd9Sstevel@tonic-gate if (cicflag != cflag) \
6657c478bd9Sstevel@tonic-gate goto bad; \
6667c478bd9Sstevel@tonic-gate } \
6677c478bd9Sstevel@tonic-gate }
6687c478bd9Sstevel@tonic-gate
669*f53eecf5SJames Carlson #define ACKCIADDR(opt, neg, val) \
6707c478bd9Sstevel@tonic-gate if (neg) { \
671*f53eecf5SJames Carlson ACKCHECK(opt, CILEN_ADDR) \
6727c478bd9Sstevel@tonic-gate GETNLONG(cilong, p); \
673*f53eecf5SJames Carlson if (val != cilong) \
6747c478bd9Sstevel@tonic-gate goto bad; \
6757c478bd9Sstevel@tonic-gate }
6767c478bd9Sstevel@tonic-gate
677*f53eecf5SJames Carlson ACKCIADDRS(CI_ADDRS, !go->neg_addr && go->old_addrs, go->ouraddr,
678*f53eecf5SJames Carlson go->hisaddr);
6797c478bd9Sstevel@tonic-gate
6807c478bd9Sstevel@tonic-gate ACKCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol, go->old_vj,
6817c478bd9Sstevel@tonic-gate go->maxslotindex, go->cflag);
6827c478bd9Sstevel@tonic-gate
683*f53eecf5SJames Carlson ACKCIADDR(CI_ADDR, go->neg_addr, go->ouraddr);
6847c478bd9Sstevel@tonic-gate
685*f53eecf5SJames Carlson ACKCIADDR(CI_MS_DNS1, go->req_dns1, go->dnsaddr[0]);
686*f53eecf5SJames Carlson
687*f53eecf5SJames Carlson ACKCIADDR(CI_MS_DNS2, go->req_dns2, go->dnsaddr[1]);
6887c478bd9Sstevel@tonic-gate
6897c478bd9Sstevel@tonic-gate /*
6907c478bd9Sstevel@tonic-gate * If there are any remaining CIs, then this packet is bad.
6917c478bd9Sstevel@tonic-gate */
6927c478bd9Sstevel@tonic-gate if (len != 0)
6937c478bd9Sstevel@tonic-gate goto bad;
6947c478bd9Sstevel@tonic-gate return (1);
6957c478bd9Sstevel@tonic-gate
6967c478bd9Sstevel@tonic-gate bad:
6977c478bd9Sstevel@tonic-gate IPCPDEBUG(("ipcp_ackci: received bad Ack!"));
6987c478bd9Sstevel@tonic-gate return (0);
6997c478bd9Sstevel@tonic-gate }
7007c478bd9Sstevel@tonic-gate
7017c478bd9Sstevel@tonic-gate /*
7027c478bd9Sstevel@tonic-gate * ipcp_nakci - Peer has sent a NAK for some of our CIs.
7037c478bd9Sstevel@tonic-gate * This should not modify any state if the Nak is bad
7047c478bd9Sstevel@tonic-gate * or if IPCP is in the OPENED state.
7057c478bd9Sstevel@tonic-gate * Calback from fsm_rconfnakrej - Receive Configure-Nak or Configure-Reject.
7067c478bd9Sstevel@tonic-gate *
7077c478bd9Sstevel@tonic-gate * Returns:
7087c478bd9Sstevel@tonic-gate * 0 - Nak was bad.
7097c478bd9Sstevel@tonic-gate * 1 - Nak was good.
7107c478bd9Sstevel@tonic-gate */
7117c478bd9Sstevel@tonic-gate static int
ipcp_nakci(f,p,len)7127c478bd9Sstevel@tonic-gate ipcp_nakci(f, p, len)
7137c478bd9Sstevel@tonic-gate fsm *f;
7147c478bd9Sstevel@tonic-gate u_char *p;
7157c478bd9Sstevel@tonic-gate int len;
7167c478bd9Sstevel@tonic-gate {
7177c478bd9Sstevel@tonic-gate ipcp_options *go = &ipcp_gotoptions[f->unit];
7187c478bd9Sstevel@tonic-gate u_char cimaxslotindex, cicflag;
7197c478bd9Sstevel@tonic-gate u_char citype, cilen, *next;
7207c478bd9Sstevel@tonic-gate u_short cishort;
721*f53eecf5SJames Carlson u_int32_t ciaddr1, ciaddr2;
7227c478bd9Sstevel@tonic-gate ipcp_options no; /* options we've seen Naks for */
7237c478bd9Sstevel@tonic-gate ipcp_options try; /* options to request next time */
7247c478bd9Sstevel@tonic-gate
7257c478bd9Sstevel@tonic-gate BZERO(&no, sizeof(no));
7267c478bd9Sstevel@tonic-gate try = *go;
7277c478bd9Sstevel@tonic-gate
7287c478bd9Sstevel@tonic-gate /*
7297c478bd9Sstevel@tonic-gate * Any Nak'd CIs must be in exactly the same order that we sent.
7307c478bd9Sstevel@tonic-gate * Check packet length and CI length at each step.
7317c478bd9Sstevel@tonic-gate * If we find any deviations, then this packet is bad.
7327c478bd9Sstevel@tonic-gate */
733*f53eecf5SJames Carlson #define NAKCIADDRS(opt, neg, code) \
734*f53eecf5SJames Carlson if ((neg) && \
735*f53eecf5SJames Carlson (cilen = p[1]) == CILEN_ADDRS && \
736*f53eecf5SJames Carlson len >= cilen && \
7377c478bd9Sstevel@tonic-gate p[0] == opt) { \
7387c478bd9Sstevel@tonic-gate len -= cilen; \
7397c478bd9Sstevel@tonic-gate INCPTR(2, p); \
7407c478bd9Sstevel@tonic-gate GETNLONG(ciaddr1, p); \
7417c478bd9Sstevel@tonic-gate GETNLONG(ciaddr2, p); \
7427c478bd9Sstevel@tonic-gate no.old_addrs = 1; \
7437c478bd9Sstevel@tonic-gate code \
7447c478bd9Sstevel@tonic-gate }
7457c478bd9Sstevel@tonic-gate
7467c478bd9Sstevel@tonic-gate #define NAKCIVJ(opt, neg, code) \
7477c478bd9Sstevel@tonic-gate if (go->neg && \
7487c478bd9Sstevel@tonic-gate ((cilen = p[1]) == CILEN_COMPRESS || cilen == CILEN_VJ) && \
7497c478bd9Sstevel@tonic-gate len >= cilen && \
7507c478bd9Sstevel@tonic-gate p[0] == opt) { \
7517c478bd9Sstevel@tonic-gate len -= cilen; \
7527c478bd9Sstevel@tonic-gate INCPTR(2, p); \
7537c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \
7547c478bd9Sstevel@tonic-gate no.neg = 1; \
7557c478bd9Sstevel@tonic-gate code \
7567c478bd9Sstevel@tonic-gate }
7577c478bd9Sstevel@tonic-gate
758*f53eecf5SJames Carlson #define NAKCIADDR(opt, neg, code) \
7597c478bd9Sstevel@tonic-gate if (go->neg && \
760*f53eecf5SJames Carlson (cilen = p[1]) == CILEN_ADDR && \
7617c478bd9Sstevel@tonic-gate len >= cilen && \
7627c478bd9Sstevel@tonic-gate p[0] == opt) { \
7637c478bd9Sstevel@tonic-gate len -= cilen; \
7647c478bd9Sstevel@tonic-gate INCPTR(2, p); \
765*f53eecf5SJames Carlson GETNLONG(ciaddr1, p); \
7667c478bd9Sstevel@tonic-gate no.neg = 1; \
7677c478bd9Sstevel@tonic-gate code \
7687c478bd9Sstevel@tonic-gate }
7697c478bd9Sstevel@tonic-gate
7707c478bd9Sstevel@tonic-gate /*
7717c478bd9Sstevel@tonic-gate * Accept the peer's idea of {our,his} address, if different
7727c478bd9Sstevel@tonic-gate * from our idea, only if the accept_{local,remote} flag is set.
7737c478bd9Sstevel@tonic-gate */
774*f53eecf5SJames Carlson NAKCIADDRS(CI_ADDRS, !go->neg_addr && go->old_addrs,
7757c478bd9Sstevel@tonic-gate if (go->accept_local && ciaddr1) { /* Do we know our address? */
7767c478bd9Sstevel@tonic-gate try.ouraddr = ciaddr1;
7777c478bd9Sstevel@tonic-gate }
7787c478bd9Sstevel@tonic-gate if (go->accept_remote && ciaddr2) { /* Does he know his? */
7797c478bd9Sstevel@tonic-gate try.hisaddr = ciaddr2;
7807c478bd9Sstevel@tonic-gate }
7817c478bd9Sstevel@tonic-gate );
7827c478bd9Sstevel@tonic-gate
7837c478bd9Sstevel@tonic-gate /*
7847c478bd9Sstevel@tonic-gate * Accept the peer's value of maxslotindex provided that it
7857c478bd9Sstevel@tonic-gate * is less than what we asked for. Turn off slot-ID compression
7867c478bd9Sstevel@tonic-gate * if the peer wants. Send old-style compress-type option if
7877c478bd9Sstevel@tonic-gate * the peer wants.
7887c478bd9Sstevel@tonic-gate */
7897c478bd9Sstevel@tonic-gate NAKCIVJ(CI_COMPRESSTYPE, neg_vj,
7907c478bd9Sstevel@tonic-gate if (cilen == CILEN_VJ) {
7917c478bd9Sstevel@tonic-gate GETCHAR(cimaxslotindex, p);
7927c478bd9Sstevel@tonic-gate GETCHAR(cicflag, p);
7937c478bd9Sstevel@tonic-gate if (cishort == IPCP_VJ_COMP) {
7947c478bd9Sstevel@tonic-gate try.old_vj = 0;
7957c478bd9Sstevel@tonic-gate if (cimaxslotindex < go->maxslotindex)
7967c478bd9Sstevel@tonic-gate try.maxslotindex = cimaxslotindex;
7977c478bd9Sstevel@tonic-gate if (!cicflag)
7987c478bd9Sstevel@tonic-gate try.cflag = 0;
7997c478bd9Sstevel@tonic-gate } else {
8007c478bd9Sstevel@tonic-gate try.neg_vj = 0;
8017c478bd9Sstevel@tonic-gate }
8027c478bd9Sstevel@tonic-gate } else {
8037c478bd9Sstevel@tonic-gate if (cishort == IPCP_VJ_COMP || cishort == IPCP_VJ_COMP_OLD) {
8047c478bd9Sstevel@tonic-gate try.old_vj = 1;
8057c478bd9Sstevel@tonic-gate try.vj_protocol = cishort;
8067c478bd9Sstevel@tonic-gate } else {
8077c478bd9Sstevel@tonic-gate try.neg_vj = 0;
8087c478bd9Sstevel@tonic-gate }
8097c478bd9Sstevel@tonic-gate }
8107c478bd9Sstevel@tonic-gate );
8117c478bd9Sstevel@tonic-gate
812*f53eecf5SJames Carlson NAKCIADDR(CI_ADDR, neg_addr,
813*f53eecf5SJames Carlson if (go->accept_local && ciaddr1) { /* Do we know our address? */
814*f53eecf5SJames Carlson try.ouraddr = ciaddr1;
815*f53eecf5SJames Carlson }
8167c478bd9Sstevel@tonic-gate );
8177c478bd9Sstevel@tonic-gate
818*f53eecf5SJames Carlson NAKCIADDR(CI_MS_DNS1, req_dns1,
819*f53eecf5SJames Carlson try.dnsaddr[0] = ciaddr1;
820*f53eecf5SJames Carlson );
821*f53eecf5SJames Carlson
822*f53eecf5SJames Carlson NAKCIADDR(CI_MS_DNS2, req_dns2,
823*f53eecf5SJames Carlson try.dnsaddr[1] = ciaddr1;
8247c478bd9Sstevel@tonic-gate );
8257c478bd9Sstevel@tonic-gate
8267c478bd9Sstevel@tonic-gate /*
8277c478bd9Sstevel@tonic-gate * There may be remaining CIs, if the peer is requesting negotiation
8287c478bd9Sstevel@tonic-gate * on an option that we didn't include in our request packet.
8297c478bd9Sstevel@tonic-gate * If they want to negotiate about IP addresses, we comply.
8307c478bd9Sstevel@tonic-gate * If they want us to ask for compression, we refuse.
8317c478bd9Sstevel@tonic-gate */
8327c478bd9Sstevel@tonic-gate while (len > CILEN_VOID) {
8337c478bd9Sstevel@tonic-gate GETCHAR(citype, p);
8347c478bd9Sstevel@tonic-gate GETCHAR(cilen, p);
8357c478bd9Sstevel@tonic-gate if( (len -= cilen) < 0 )
8367c478bd9Sstevel@tonic-gate goto bad;
8377c478bd9Sstevel@tonic-gate next = p + cilen - 2;
8387c478bd9Sstevel@tonic-gate
8397c478bd9Sstevel@tonic-gate switch (citype) {
8407c478bd9Sstevel@tonic-gate case CI_COMPRESSTYPE:
8417c478bd9Sstevel@tonic-gate if (go->neg_vj || no.neg_vj ||
8427c478bd9Sstevel@tonic-gate (cilen != CILEN_VJ && cilen != CILEN_COMPRESS))
8437c478bd9Sstevel@tonic-gate goto bad;
8447c478bd9Sstevel@tonic-gate no.neg_vj = 1;
8457c478bd9Sstevel@tonic-gate break;
8467c478bd9Sstevel@tonic-gate case CI_ADDRS:
847*f53eecf5SJames Carlson if ((!go->neg_addr && go->old_addrs) || no.old_addrs
8487c478bd9Sstevel@tonic-gate || cilen != CILEN_ADDRS)
8497c478bd9Sstevel@tonic-gate goto bad;
8507c478bd9Sstevel@tonic-gate try.neg_addr = 1;
8517c478bd9Sstevel@tonic-gate try.old_addrs = 1;
8527c478bd9Sstevel@tonic-gate GETNLONG(ciaddr1, p);
8537c478bd9Sstevel@tonic-gate if (ciaddr1 && go->accept_local)
8547c478bd9Sstevel@tonic-gate try.ouraddr = ciaddr1;
8557c478bd9Sstevel@tonic-gate GETNLONG(ciaddr2, p);
8567c478bd9Sstevel@tonic-gate if (ciaddr2 && go->accept_remote)
8577c478bd9Sstevel@tonic-gate try.hisaddr = ciaddr2;
8587c478bd9Sstevel@tonic-gate no.old_addrs = 1;
8597c478bd9Sstevel@tonic-gate break;
8607c478bd9Sstevel@tonic-gate case CI_ADDR:
8617c478bd9Sstevel@tonic-gate if (go->neg_addr || no.neg_addr || cilen != CILEN_ADDR)
8627c478bd9Sstevel@tonic-gate goto bad;
8637c478bd9Sstevel@tonic-gate try.old_addrs = 0;
8647c478bd9Sstevel@tonic-gate GETNLONG(ciaddr1, p);
8657c478bd9Sstevel@tonic-gate if (ciaddr1 && go->accept_local)
8667c478bd9Sstevel@tonic-gate try.ouraddr = ciaddr1;
8677c478bd9Sstevel@tonic-gate if (try.ouraddr != 0)
8687c478bd9Sstevel@tonic-gate try.neg_addr = 1;
8697c478bd9Sstevel@tonic-gate no.neg_addr = 1;
8707c478bd9Sstevel@tonic-gate break;
8717c478bd9Sstevel@tonic-gate }
8727c478bd9Sstevel@tonic-gate p = next;
8737c478bd9Sstevel@tonic-gate }
8747c478bd9Sstevel@tonic-gate
8757c478bd9Sstevel@tonic-gate /*
8767c478bd9Sstevel@tonic-gate * OK, the Nak is good. Now we can update state.
8777c478bd9Sstevel@tonic-gate * If there are any remaining options, we ignore them.
8787c478bd9Sstevel@tonic-gate */
8797c478bd9Sstevel@tonic-gate if (f->state != OPENED)
8807c478bd9Sstevel@tonic-gate *go = try;
8817c478bd9Sstevel@tonic-gate
8827c478bd9Sstevel@tonic-gate return 1;
8837c478bd9Sstevel@tonic-gate
8847c478bd9Sstevel@tonic-gate bad:
8857c478bd9Sstevel@tonic-gate IPCPDEBUG(("ipcp_nakci: received bad Nak!"));
8867c478bd9Sstevel@tonic-gate return 0;
8877c478bd9Sstevel@tonic-gate }
8887c478bd9Sstevel@tonic-gate
8897c478bd9Sstevel@tonic-gate
8907c478bd9Sstevel@tonic-gate /*
8917c478bd9Sstevel@tonic-gate * ipcp_rejci - Reject some of our CIs.
8927c478bd9Sstevel@tonic-gate * Callback from fsm_rconfnakrej.
8937c478bd9Sstevel@tonic-gate */
8947c478bd9Sstevel@tonic-gate static int
ipcp_rejci(f,p,len)8957c478bd9Sstevel@tonic-gate ipcp_rejci(f, p, len)
8967c478bd9Sstevel@tonic-gate fsm *f;
8977c478bd9Sstevel@tonic-gate u_char *p;
8987c478bd9Sstevel@tonic-gate int len;
8997c478bd9Sstevel@tonic-gate {
9007c478bd9Sstevel@tonic-gate ipcp_options *go = &ipcp_gotoptions[f->unit];
9017c478bd9Sstevel@tonic-gate u_char cimaxslotindex, ciflag, cilen;
9027c478bd9Sstevel@tonic-gate u_short cishort;
9037c478bd9Sstevel@tonic-gate u_int32_t cilong;
9047c478bd9Sstevel@tonic-gate ipcp_options try; /* options to request next time */
9057c478bd9Sstevel@tonic-gate
9067c478bd9Sstevel@tonic-gate try = *go;
9077c478bd9Sstevel@tonic-gate /*
9087c478bd9Sstevel@tonic-gate * Any Rejected CIs must be in exactly the same order that we sent.
9097c478bd9Sstevel@tonic-gate * Check packet length and CI length at each step.
9107c478bd9Sstevel@tonic-gate * If we find any deviations, then this packet is bad.
9117c478bd9Sstevel@tonic-gate */
912*f53eecf5SJames Carlson #define REJCIADDRS(opt, neg, val1, val2) \
913*f53eecf5SJames Carlson if ((neg) && \
914*f53eecf5SJames Carlson (cilen = p[1]) == CILEN_ADDRS && \
915*f53eecf5SJames Carlson len >= cilen && \
9167c478bd9Sstevel@tonic-gate p[0] == opt) { \
9177c478bd9Sstevel@tonic-gate len -= cilen; \
9187c478bd9Sstevel@tonic-gate INCPTR(2, p); \
9197c478bd9Sstevel@tonic-gate GETNLONG(cilong, p); \
9207c478bd9Sstevel@tonic-gate /* Check rejected value. */ \
9217c478bd9Sstevel@tonic-gate if (cilong != val1) \
9227c478bd9Sstevel@tonic-gate goto bad; \
9237c478bd9Sstevel@tonic-gate GETNLONG(cilong, p); \
9247c478bd9Sstevel@tonic-gate /* Check rejected value. */ \
9257c478bd9Sstevel@tonic-gate if (cilong != val2) \
9267c478bd9Sstevel@tonic-gate goto bad; \
927*f53eecf5SJames Carlson try.old_addrs = 0; \
9287c478bd9Sstevel@tonic-gate }
9297c478bd9Sstevel@tonic-gate
9307c478bd9Sstevel@tonic-gate #define REJCIVJ(opt, neg, val, old, maxslot, cflag) \
9317c478bd9Sstevel@tonic-gate if (go->neg && \
9327c478bd9Sstevel@tonic-gate p[1] == (old? CILEN_COMPRESS : CILEN_VJ) && \
9337c478bd9Sstevel@tonic-gate len >= p[1] && \
9347c478bd9Sstevel@tonic-gate p[0] == opt) { \
9357c478bd9Sstevel@tonic-gate len -= p[1]; \
9367c478bd9Sstevel@tonic-gate INCPTR(2, p); \
9377c478bd9Sstevel@tonic-gate GETSHORT(cishort, p); \
9387c478bd9Sstevel@tonic-gate /* Check rejected value. */ \
9397c478bd9Sstevel@tonic-gate if (cishort != val) \
9407c478bd9Sstevel@tonic-gate goto bad; \
9417c478bd9Sstevel@tonic-gate if (!old) { \
9427c478bd9Sstevel@tonic-gate GETCHAR(cimaxslotindex, p); \
9437c478bd9Sstevel@tonic-gate if (cimaxslotindex != maxslot) \
9447c478bd9Sstevel@tonic-gate goto bad; \
9457c478bd9Sstevel@tonic-gate GETCHAR(ciflag, p); \
9467c478bd9Sstevel@tonic-gate if (ciflag != cflag) \
9477c478bd9Sstevel@tonic-gate goto bad; \
9487c478bd9Sstevel@tonic-gate } \
9497c478bd9Sstevel@tonic-gate try.neg = 0; \
9507c478bd9Sstevel@tonic-gate }
9517c478bd9Sstevel@tonic-gate
952*f53eecf5SJames Carlson #define REJCIADDR(opt, neg, addr) \
9537c478bd9Sstevel@tonic-gate if (go->neg && \
9547c478bd9Sstevel@tonic-gate ((cilen = p[1]) == CILEN_ADDR) && \
9557c478bd9Sstevel@tonic-gate len >= cilen && \
9567c478bd9Sstevel@tonic-gate p[0] == opt) { \
9577c478bd9Sstevel@tonic-gate len -= cilen; \
9587c478bd9Sstevel@tonic-gate INCPTR(2, p); \
9597c478bd9Sstevel@tonic-gate GETNLONG(cilong, p); \
9607c478bd9Sstevel@tonic-gate /* Check rejected value. */ \
961*f53eecf5SJames Carlson if (cilong != addr) \
9627c478bd9Sstevel@tonic-gate goto bad; \
9637c478bd9Sstevel@tonic-gate try.neg = 0; \
9647c478bd9Sstevel@tonic-gate }
9657c478bd9Sstevel@tonic-gate
966*f53eecf5SJames Carlson REJCIADDRS(CI_ADDRS, !go->neg_addr && go->old_addrs,
967*f53eecf5SJames Carlson go->ouraddr, go->hisaddr);
9687c478bd9Sstevel@tonic-gate
9697c478bd9Sstevel@tonic-gate REJCIVJ(CI_COMPRESSTYPE, neg_vj, go->vj_protocol, go->old_vj,
9707c478bd9Sstevel@tonic-gate go->maxslotindex, go->cflag);
9717c478bd9Sstevel@tonic-gate
972*f53eecf5SJames Carlson REJCIADDR(CI_ADDR, neg_addr, go->ouraddr);
9737c478bd9Sstevel@tonic-gate
974*f53eecf5SJames Carlson REJCIADDR(CI_MS_DNS1, req_dns1, go->dnsaddr[0]);
975*f53eecf5SJames Carlson
976*f53eecf5SJames Carlson REJCIADDR(CI_MS_DNS2, req_dns2, go->dnsaddr[1]);
9777c478bd9Sstevel@tonic-gate
9787c478bd9Sstevel@tonic-gate /*
9797c478bd9Sstevel@tonic-gate * If there are any remaining CIs, then this packet is bad.
9807c478bd9Sstevel@tonic-gate */
9817c478bd9Sstevel@tonic-gate if (len != 0)
9827c478bd9Sstevel@tonic-gate goto bad;
9837c478bd9Sstevel@tonic-gate /*
9847c478bd9Sstevel@tonic-gate * Now we can update state.
9857c478bd9Sstevel@tonic-gate */
9867c478bd9Sstevel@tonic-gate if (f->state != OPENED)
9877c478bd9Sstevel@tonic-gate *go = try;
9887c478bd9Sstevel@tonic-gate return 1;
9897c478bd9Sstevel@tonic-gate
9907c478bd9Sstevel@tonic-gate bad:
9917c478bd9Sstevel@tonic-gate IPCPDEBUG(("ipcp_rejci: received bad Reject!"));
9927c478bd9Sstevel@tonic-gate return 0;
9937c478bd9Sstevel@tonic-gate }
9947c478bd9Sstevel@tonic-gate
9957c478bd9Sstevel@tonic-gate
9967c478bd9Sstevel@tonic-gate /*
9977c478bd9Sstevel@tonic-gate * ipcp_reqci - Check the peer's requested CIs and send appropriate response.
9987c478bd9Sstevel@tonic-gate * Callback from fsm_rconfreq, Receive Configure Request
9997c478bd9Sstevel@tonic-gate *
10007c478bd9Sstevel@tonic-gate * Returns: CODE_CONFACK, CODE_CONFNAK or CODE_CONFREJ and input
10017c478bd9Sstevel@tonic-gate * packet modified appropriately. If reject_if_disagree is non-zero,
10027c478bd9Sstevel@tonic-gate * doesn't return CODE_CONFNAK; returns CODE_CONFREJ if it can't
10037c478bd9Sstevel@tonic-gate * return CODE_CONFACK.
10047c478bd9Sstevel@tonic-gate */
10057c478bd9Sstevel@tonic-gate static int
ipcp_reqci(f,p,lenp,dont_nak)10067c478bd9Sstevel@tonic-gate ipcp_reqci(f, p, lenp, dont_nak)
10077c478bd9Sstevel@tonic-gate fsm *f;
10087c478bd9Sstevel@tonic-gate u_char *p; /* Requested CIs */
10097c478bd9Sstevel@tonic-gate int *lenp; /* Length of requested CIs */
10107c478bd9Sstevel@tonic-gate bool dont_nak;
10117c478bd9Sstevel@tonic-gate {
10127c478bd9Sstevel@tonic-gate ipcp_options *wo = &ipcp_wantoptions[f->unit];
10137c478bd9Sstevel@tonic-gate ipcp_options *ho = &ipcp_hisoptions[f->unit];
10147c478bd9Sstevel@tonic-gate ipcp_options *ao = &ipcp_allowoptions[f->unit];
10157c478bd9Sstevel@tonic-gate ipcp_options *go = &ipcp_gotoptions[f->unit];
10167c478bd9Sstevel@tonic-gate int ret, newret;
10177c478bd9Sstevel@tonic-gate u_char *p0, *nakp, *rejp, *prev;
10187c478bd9Sstevel@tonic-gate u_short cishort;
10197c478bd9Sstevel@tonic-gate int len, cilen, type;
10207c478bd9Sstevel@tonic-gate u_int32_t tl, ciaddr1, ciaddr2; /* Parsed address values */
10217c478bd9Sstevel@tonic-gate u_char maxslotindex, cflag;
10227c478bd9Sstevel@tonic-gate int d;
10237c478bd9Sstevel@tonic-gate
10247c478bd9Sstevel@tonic-gate ret = CODE_CONFACK;
10257c478bd9Sstevel@tonic-gate rejp = p0 = p;
10267c478bd9Sstevel@tonic-gate nakp = nak_buffer;
10277c478bd9Sstevel@tonic-gate
10287c478bd9Sstevel@tonic-gate /*
10297c478bd9Sstevel@tonic-gate * Reset all his options.
10307c478bd9Sstevel@tonic-gate */
10317c478bd9Sstevel@tonic-gate BZERO(ho, sizeof(*ho));
10327c478bd9Sstevel@tonic-gate
10337c478bd9Sstevel@tonic-gate /*
10347c478bd9Sstevel@tonic-gate * Process all his options.
10357c478bd9Sstevel@tonic-gate */
10367c478bd9Sstevel@tonic-gate for (len = *lenp; len > 0; len -= cilen, p = prev + cilen) {
10377c478bd9Sstevel@tonic-gate if ((len < 2) || p[1] > len) {
10387c478bd9Sstevel@tonic-gate /*
10397c478bd9Sstevel@tonic-gate * RFC 1661 page 40 -- if the option extends beyond the
10407c478bd9Sstevel@tonic-gate * packet, then discard the entire packet.
10417c478bd9Sstevel@tonic-gate */
10427c478bd9Sstevel@tonic-gate return (0);
10437c478bd9Sstevel@tonic-gate }
10447c478bd9Sstevel@tonic-gate
10457c478bd9Sstevel@tonic-gate newret = CODE_CONFACK;
10467c478bd9Sstevel@tonic-gate prev = p;
10477c478bd9Sstevel@tonic-gate GETCHAR(type, p);
10487c478bd9Sstevel@tonic-gate GETCHAR(cilen, p);
10497c478bd9Sstevel@tonic-gate
10507c478bd9Sstevel@tonic-gate switch (type) { /* Check CI type */
10517c478bd9Sstevel@tonic-gate case CI_ADDRS:
1052*f53eecf5SJames Carlson if (!ao->old_addrs || ho->neg_addr) {
10537c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ;
10547c478bd9Sstevel@tonic-gate break;
10557c478bd9Sstevel@tonic-gate }
10567c478bd9Sstevel@tonic-gate
10577c478bd9Sstevel@tonic-gate if (cilen != CILEN_ADDRS) {
10587c478bd9Sstevel@tonic-gate /*
10597c478bd9Sstevel@tonic-gate * rfc1661, page 40 -- a recongnized option with an
10607c478bd9Sstevel@tonic-gate * invalid length should be Nak'ed.
10617c478bd9Sstevel@tonic-gate */
10627c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
10637c478bd9Sstevel@tonic-gate ciaddr1 = wo->hisaddr;
10647c478bd9Sstevel@tonic-gate ciaddr2 = wo->ouraddr;
10657c478bd9Sstevel@tonic-gate } else {
10667c478bd9Sstevel@tonic-gate
10677c478bd9Sstevel@tonic-gate /*
10687c478bd9Sstevel@tonic-gate * If he has no address, or if we both have his
10697c478bd9Sstevel@tonic-gate * address but disagree about it, then NAK it with our
10707c478bd9Sstevel@tonic-gate * idea. In particular, if we don't know his address,
10717c478bd9Sstevel@tonic-gate * but he does, then accept it.
10727c478bd9Sstevel@tonic-gate */
10737c478bd9Sstevel@tonic-gate GETNLONG(ciaddr1, p);
10747c478bd9Sstevel@tonic-gate if (ciaddr1 != wo->hisaddr &&
10757c478bd9Sstevel@tonic-gate (ciaddr1 == 0 || !wo->accept_remote)) {
10767c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
10777c478bd9Sstevel@tonic-gate ciaddr1 = wo->hisaddr;
10787c478bd9Sstevel@tonic-gate } else if (ciaddr1 == 0 && wo->hisaddr == 0) {
10797c478bd9Sstevel@tonic-gate /*
10807c478bd9Sstevel@tonic-gate * If neither we nor he knows his address, reject
10817c478bd9Sstevel@tonic-gate * the option.
10827c478bd9Sstevel@tonic-gate */
10837c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ;
10847c478bd9Sstevel@tonic-gate wo->req_addr = 0; /* don't NAK with 0.0.0.0 later */
10857c478bd9Sstevel@tonic-gate break;
10867c478bd9Sstevel@tonic-gate } else if (ciaddr1 != 0) {
10877c478bd9Sstevel@tonic-gate go->hisaddr = ciaddr1;
10887c478bd9Sstevel@tonic-gate }
10897c478bd9Sstevel@tonic-gate
10907c478bd9Sstevel@tonic-gate /*
10917c478bd9Sstevel@tonic-gate * If he doesn't know our address, or if we both have
10927c478bd9Sstevel@tonic-gate * our address * but disagree about it, then NAK it
10937c478bd9Sstevel@tonic-gate * with our idea.
10947c478bd9Sstevel@tonic-gate */
10957c478bd9Sstevel@tonic-gate GETNLONG(ciaddr2, p);
10967c478bd9Sstevel@tonic-gate if (ciaddr2 != wo->ouraddr) {
10977c478bd9Sstevel@tonic-gate if (ciaddr2 == 0 || !wo->accept_local) {
10987c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
10997c478bd9Sstevel@tonic-gate ciaddr2 = wo->ouraddr;
11007c478bd9Sstevel@tonic-gate } else {
11017c478bd9Sstevel@tonic-gate go->ouraddr = ciaddr2; /* accept peer's idea */
11027c478bd9Sstevel@tonic-gate }
11037c478bd9Sstevel@tonic-gate }
11047c478bd9Sstevel@tonic-gate }
11057c478bd9Sstevel@tonic-gate
11067c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK) {
11077c478bd9Sstevel@tonic-gate PUTCHAR(type, nakp);
11087c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_ADDRS, nakp);
11097c478bd9Sstevel@tonic-gate PUTNLONG(ciaddr1, nakp);
11107c478bd9Sstevel@tonic-gate PUTNLONG(ciaddr2, nakp);
11117c478bd9Sstevel@tonic-gate }
11127c478bd9Sstevel@tonic-gate
11137c478bd9Sstevel@tonic-gate ho->old_addrs = 1;
11147c478bd9Sstevel@tonic-gate ho->hisaddr = ciaddr1;
11157c478bd9Sstevel@tonic-gate ho->ouraddr = ciaddr2;
11167c478bd9Sstevel@tonic-gate break;
11177c478bd9Sstevel@tonic-gate
11187c478bd9Sstevel@tonic-gate case CI_ADDR:
1119*f53eecf5SJames Carlson if (!ao->neg_addr || ho->old_addrs) {
11207c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ;
11217c478bd9Sstevel@tonic-gate break;
11227c478bd9Sstevel@tonic-gate }
11237c478bd9Sstevel@tonic-gate
11247c478bd9Sstevel@tonic-gate if (cilen != CILEN_ADDR) {
11257c478bd9Sstevel@tonic-gate /*
11267c478bd9Sstevel@tonic-gate * rfc1661, page 40 -- a recongnized option with an
11277c478bd9Sstevel@tonic-gate * invalid length should be Nak'ed.
11287c478bd9Sstevel@tonic-gate */
11297c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
11307c478bd9Sstevel@tonic-gate ciaddr1 = wo->hisaddr;
11317c478bd9Sstevel@tonic-gate } else {
11327c478bd9Sstevel@tonic-gate
11337c478bd9Sstevel@tonic-gate /*
11347c478bd9Sstevel@tonic-gate * If he has no address, or if we both have his
11357c478bd9Sstevel@tonic-gate * address but disagree about it, then NAK it with our
11367c478bd9Sstevel@tonic-gate * idea. In particular, if we don't know his address,
11377c478bd9Sstevel@tonic-gate * but he does, then accept it.
11387c478bd9Sstevel@tonic-gate */
11397c478bd9Sstevel@tonic-gate GETNLONG(ciaddr1, p);
11407c478bd9Sstevel@tonic-gate if (ciaddr1 != wo->hisaddr &&
11417c478bd9Sstevel@tonic-gate (ciaddr1 == 0 || !wo->accept_remote)) {
11427c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
11437c478bd9Sstevel@tonic-gate ciaddr1 = wo->hisaddr;
11447c478bd9Sstevel@tonic-gate } else if (ciaddr1 == 0 && wo->hisaddr == 0 &&
11457c478bd9Sstevel@tonic-gate wo->default_route != 0) {
11467c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
11477c478bd9Sstevel@tonic-gate /*
11487c478bd9Sstevel@tonic-gate * If this is a dialup line (default_route is
11497c478bd9Sstevel@tonic-gate * set), and neither side knows about his address,
11507c478bd9Sstevel@tonic-gate * suggest an arbitrary rfc1918 address.
11517c478bd9Sstevel@tonic-gate */
11527c478bd9Sstevel@tonic-gate ciaddr1 = htonl(0xc0a80101 + ifunit);
11537c478bd9Sstevel@tonic-gate dbglog("Peer address unknown; suggesting %I", ciaddr1);
11547c478bd9Sstevel@tonic-gate } else if (ciaddr1 == 0 && wo->hisaddr == 0) {
11557c478bd9Sstevel@tonic-gate /*
11567c478bd9Sstevel@tonic-gate * If this is not a dialup line, don't ACK an
11577c478bd9Sstevel@tonic-gate * address of 0.0.0.0 - reject it instead.
11587c478bd9Sstevel@tonic-gate */
11597c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ;
11607c478bd9Sstevel@tonic-gate wo->req_addr = 0; /* don't NAK with 0.0.0.0 later */
11617c478bd9Sstevel@tonic-gate break;
11627c478bd9Sstevel@tonic-gate }
11637c478bd9Sstevel@tonic-gate }
11647c478bd9Sstevel@tonic-gate
11657c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK) {
11667c478bd9Sstevel@tonic-gate PUTCHAR(type, nakp);
11677c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_ADDR, nakp);
11687c478bd9Sstevel@tonic-gate PUTNLONG(ciaddr1, nakp);
11697c478bd9Sstevel@tonic-gate }
11707c478bd9Sstevel@tonic-gate
11717c478bd9Sstevel@tonic-gate ho->neg_addr = 1;
11727c478bd9Sstevel@tonic-gate ho->hisaddr = ciaddr1;
11737c478bd9Sstevel@tonic-gate break;
11747c478bd9Sstevel@tonic-gate
11757c478bd9Sstevel@tonic-gate case CI_MS_DNS1:
11767c478bd9Sstevel@tonic-gate case CI_MS_DNS2:
11777c478bd9Sstevel@tonic-gate /* Warning -- these options work backwards. */
11787c478bd9Sstevel@tonic-gate /* Microsoft primary or secondary DNS request */
11797c478bd9Sstevel@tonic-gate d = (type == CI_MS_DNS2 ? 1 : 0);
11807c478bd9Sstevel@tonic-gate
11817c478bd9Sstevel@tonic-gate if (ao->dnsaddr[d] == 0) {
11827c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ;
11837c478bd9Sstevel@tonic-gate break;
11847c478bd9Sstevel@tonic-gate }
11857c478bd9Sstevel@tonic-gate
11867c478bd9Sstevel@tonic-gate if (cilen != CILEN_ADDR) {
11877c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
11887c478bd9Sstevel@tonic-gate } else {
11897c478bd9Sstevel@tonic-gate GETNLONG(tl, p);
11907c478bd9Sstevel@tonic-gate if (tl != ao->dnsaddr[d]) {
11917c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
11927c478bd9Sstevel@tonic-gate }
11937c478bd9Sstevel@tonic-gate }
11947c478bd9Sstevel@tonic-gate
11957c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK) {
11967c478bd9Sstevel@tonic-gate PUTCHAR(type, nakp);
11977c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_ADDR, nakp);
11987c478bd9Sstevel@tonic-gate PUTNLONG(ao->dnsaddr[d], nakp);
11997c478bd9Sstevel@tonic-gate }
12007c478bd9Sstevel@tonic-gate break;
12017c478bd9Sstevel@tonic-gate
12027c478bd9Sstevel@tonic-gate case CI_MS_WINS1:
12037c478bd9Sstevel@tonic-gate case CI_MS_WINS2:
12047c478bd9Sstevel@tonic-gate /* Warning -- these options work backwards. */
12057c478bd9Sstevel@tonic-gate /* Microsoft primary or secondary WINS request */
12067c478bd9Sstevel@tonic-gate d = (type == CI_MS_WINS2 ? 1 : 0);
12077c478bd9Sstevel@tonic-gate
12087c478bd9Sstevel@tonic-gate if (ao->winsaddr[d] == 0) {
12097c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ;
12107c478bd9Sstevel@tonic-gate break;
12117c478bd9Sstevel@tonic-gate }
12127c478bd9Sstevel@tonic-gate
12137c478bd9Sstevel@tonic-gate if (cilen != CILEN_ADDR) {
12147c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
12157c478bd9Sstevel@tonic-gate } else {
12167c478bd9Sstevel@tonic-gate GETNLONG(tl, p);
12177c478bd9Sstevel@tonic-gate if (tl != ao->winsaddr[d]) {
12187c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
12197c478bd9Sstevel@tonic-gate }
12207c478bd9Sstevel@tonic-gate }
12217c478bd9Sstevel@tonic-gate
12227c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK) {
12237c478bd9Sstevel@tonic-gate PUTCHAR(type, nakp);
12247c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_ADDR, nakp);
12257c478bd9Sstevel@tonic-gate PUTNLONG(ao->winsaddr[d], nakp);
12267c478bd9Sstevel@tonic-gate }
12277c478bd9Sstevel@tonic-gate break;
12287c478bd9Sstevel@tonic-gate
12297c478bd9Sstevel@tonic-gate case CI_COMPRESSTYPE:
12307c478bd9Sstevel@tonic-gate if (!ao->neg_vj) {
12317c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ;
12327c478bd9Sstevel@tonic-gate break;
12337c478bd9Sstevel@tonic-gate }
12347c478bd9Sstevel@tonic-gate
12357c478bd9Sstevel@tonic-gate maxslotindex = ao->maxslotindex;
12367c478bd9Sstevel@tonic-gate cflag = ao->cflag;
12377c478bd9Sstevel@tonic-gate if (cilen != CILEN_VJ && cilen != CILEN_COMPRESS) {
12387c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
12397c478bd9Sstevel@tonic-gate cishort = IPCP_VJ_COMP;
12407c478bd9Sstevel@tonic-gate } else {
12417c478bd9Sstevel@tonic-gate GETSHORT(cishort, p);
12427c478bd9Sstevel@tonic-gate if (cishort != IPCP_VJ_COMP &&
12437c478bd9Sstevel@tonic-gate (cishort != IPCP_VJ_COMP_OLD || cilen != CILEN_COMPRESS)) {
12447c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
12457c478bd9Sstevel@tonic-gate cishort = IPCP_VJ_COMP;
12467c478bd9Sstevel@tonic-gate } else if (cilen == CILEN_VJ) {
12477c478bd9Sstevel@tonic-gate GETCHAR(maxslotindex, p);
12487c478bd9Sstevel@tonic-gate if (maxslotindex > ao->maxslotindex) {
12497c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
12507c478bd9Sstevel@tonic-gate maxslotindex = ao->maxslotindex;
12517c478bd9Sstevel@tonic-gate }
12527c478bd9Sstevel@tonic-gate GETCHAR(cflag, p);
12537c478bd9Sstevel@tonic-gate if (cflag != 0 && ao->cflag == 0) {
12547c478bd9Sstevel@tonic-gate newret = CODE_CONFNAK;
12557c478bd9Sstevel@tonic-gate cflag = 0;
12567c478bd9Sstevel@tonic-gate }
12577c478bd9Sstevel@tonic-gate } else {
12587c478bd9Sstevel@tonic-gate ho->old_vj = 1;
12597c478bd9Sstevel@tonic-gate maxslotindex = MAX_STATES - 1;
12607c478bd9Sstevel@tonic-gate cflag = 1;
12617c478bd9Sstevel@tonic-gate }
12627c478bd9Sstevel@tonic-gate }
12637c478bd9Sstevel@tonic-gate
12647c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK) {
12657c478bd9Sstevel@tonic-gate PUTCHAR(type, nakp);
12667c478bd9Sstevel@tonic-gate if (cishort == IPCP_VJ_COMP) {
12677c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_VJ, nakp);
12687c478bd9Sstevel@tonic-gate PUTSHORT(cishort, nakp);
12697c478bd9Sstevel@tonic-gate PUTCHAR(maxslotindex, nakp);
12707c478bd9Sstevel@tonic-gate PUTCHAR(cflag, nakp);
12717c478bd9Sstevel@tonic-gate } else {
12727c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_COMPRESS, nakp);
12737c478bd9Sstevel@tonic-gate PUTSHORT(cishort, nakp);
12747c478bd9Sstevel@tonic-gate }
12757c478bd9Sstevel@tonic-gate }
12767c478bd9Sstevel@tonic-gate ho->neg_vj = 1;
12777c478bd9Sstevel@tonic-gate ho->vj_protocol = cishort;
12787c478bd9Sstevel@tonic-gate ho->maxslotindex = maxslotindex;
12797c478bd9Sstevel@tonic-gate ho->cflag = cflag;
12807c478bd9Sstevel@tonic-gate break;
12817c478bd9Sstevel@tonic-gate
12827c478bd9Sstevel@tonic-gate default:
12837c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ;
12847c478bd9Sstevel@tonic-gate break;
12857c478bd9Sstevel@tonic-gate }
12867c478bd9Sstevel@tonic-gate
12877c478bd9Sstevel@tonic-gate /* Cope with confused peers. */
12887c478bd9Sstevel@tonic-gate if (cilen < 2)
12897c478bd9Sstevel@tonic-gate cilen = 2;
12907c478bd9Sstevel@tonic-gate
12917c478bd9Sstevel@tonic-gate /*
12927c478bd9Sstevel@tonic-gate * If this is an Ack'able CI, but we're sending back a Nak,
12937c478bd9Sstevel@tonic-gate * don't include this CI.
12947c478bd9Sstevel@tonic-gate */
12957c478bd9Sstevel@tonic-gate if (newret == CODE_CONFACK && ret != CODE_CONFACK)
12967c478bd9Sstevel@tonic-gate continue;
12977c478bd9Sstevel@tonic-gate
12987c478bd9Sstevel@tonic-gate if (newret == CODE_CONFNAK) {
12997c478bd9Sstevel@tonic-gate if (dont_nak) {
13007c478bd9Sstevel@tonic-gate newret = CODE_CONFREJ;
13017c478bd9Sstevel@tonic-gate } else {
13027c478bd9Sstevel@tonic-gate /* Ignore subsequent Nak'able things if rejecting. */
13037c478bd9Sstevel@tonic-gate if (ret == CODE_CONFREJ)
13047c478bd9Sstevel@tonic-gate continue;
13057c478bd9Sstevel@tonic-gate ret = CODE_CONFNAK;
13067c478bd9Sstevel@tonic-gate }
13077c478bd9Sstevel@tonic-gate }
13087c478bd9Sstevel@tonic-gate
13097c478bd9Sstevel@tonic-gate if (newret == CODE_CONFREJ) {
13107c478bd9Sstevel@tonic-gate ret = CODE_CONFREJ;
13117c478bd9Sstevel@tonic-gate if (prev != rejp)
13127c478bd9Sstevel@tonic-gate BCOPY(prev, rejp, cilen);
13137c478bd9Sstevel@tonic-gate rejp += cilen;
13147c478bd9Sstevel@tonic-gate }
13157c478bd9Sstevel@tonic-gate }
13167c478bd9Sstevel@tonic-gate
13177c478bd9Sstevel@tonic-gate /*
13187c478bd9Sstevel@tonic-gate * If we aren't rejecting this packet, and we want to negotiate
13197c478bd9Sstevel@tonic-gate * their address, and they didn't send their address, then we
13207c478bd9Sstevel@tonic-gate * send a NAK with a CI_ADDR option appended. We assume the
13217c478bd9Sstevel@tonic-gate * input buffer is long enough that we can append the extra
13227c478bd9Sstevel@tonic-gate * option safely.
13237c478bd9Sstevel@tonic-gate */
1324*f53eecf5SJames Carlson if (ret != CODE_CONFREJ && !ho->neg_addr && !ho->old_addrs &&
1325*f53eecf5SJames Carlson wo->req_addr && !dont_nak) {
13267c478bd9Sstevel@tonic-gate if (ret == CODE_CONFACK)
13277c478bd9Sstevel@tonic-gate wo->req_addr = 0; /* don't ask again */
13287c478bd9Sstevel@tonic-gate ret = CODE_CONFNAK;
13297c478bd9Sstevel@tonic-gate PUTCHAR(CI_ADDR, nakp);
13307c478bd9Sstevel@tonic-gate PUTCHAR(CILEN_ADDR, nakp);
13317c478bd9Sstevel@tonic-gate PUTNLONG(wo->hisaddr, nakp);
13327c478bd9Sstevel@tonic-gate }
13337c478bd9Sstevel@tonic-gate
13347c478bd9Sstevel@tonic-gate switch (ret) {
13357c478bd9Sstevel@tonic-gate case CODE_CONFACK:
13367c478bd9Sstevel@tonic-gate *lenp = p - p0;
13377c478bd9Sstevel@tonic-gate sys_block_proto(PPP_IP);
13387c478bd9Sstevel@tonic-gate break;
13397c478bd9Sstevel@tonic-gate case CODE_CONFNAK:
13407c478bd9Sstevel@tonic-gate *lenp = nakp - nak_buffer;
13417c478bd9Sstevel@tonic-gate BCOPY(nak_buffer, p0, *lenp);
13427c478bd9Sstevel@tonic-gate break;
13437c478bd9Sstevel@tonic-gate case CODE_CONFREJ:
13447c478bd9Sstevel@tonic-gate *lenp = rejp - p0;
13457c478bd9Sstevel@tonic-gate break;
13467c478bd9Sstevel@tonic-gate }
13477c478bd9Sstevel@tonic-gate
13487c478bd9Sstevel@tonic-gate return (ret); /* Return final code */
13497c478bd9Sstevel@tonic-gate }
13507c478bd9Sstevel@tonic-gate
13517c478bd9Sstevel@tonic-gate
13527c478bd9Sstevel@tonic-gate /*
13537c478bd9Sstevel@tonic-gate * ip_check_options - check that any IP-related options are OK,
13547c478bd9Sstevel@tonic-gate * and assign appropriate defaults.
13557c478bd9Sstevel@tonic-gate */
13567c478bd9Sstevel@tonic-gate static void
ip_check_options()13577c478bd9Sstevel@tonic-gate ip_check_options()
13587c478bd9Sstevel@tonic-gate {
13597c478bd9Sstevel@tonic-gate struct hostent *hp;
13607c478bd9Sstevel@tonic-gate u_int32_t local;
13617c478bd9Sstevel@tonic-gate ipcp_options *wo = &ipcp_wantoptions[0];
13627c478bd9Sstevel@tonic-gate
13637c478bd9Sstevel@tonic-gate /*
13647c478bd9Sstevel@tonic-gate * Default our local IP address based on our hostname.
13657c478bd9Sstevel@tonic-gate * If local IP address already given, don't bother.
13667c478bd9Sstevel@tonic-gate */
13677c478bd9Sstevel@tonic-gate if (wo->ouraddr == 0) {
13687c478bd9Sstevel@tonic-gate /*
13697c478bd9Sstevel@tonic-gate * Look up our hostname (possibly with domain name appended)
13707c478bd9Sstevel@tonic-gate * and take the first IP address as our local IP address.
13717c478bd9Sstevel@tonic-gate * If there isn't an IP address for our hostname, too bad.
13727c478bd9Sstevel@tonic-gate */
13737c478bd9Sstevel@tonic-gate wo->accept_local = 1; /* don't insist on this default value */
13747c478bd9Sstevel@tonic-gate if ((hp = gethostbyname(hostname)) != NULL) {
13757c478bd9Sstevel@tonic-gate BCOPY(hp->h_addr, &local, sizeof (hp->h_addr));
13767c478bd9Sstevel@tonic-gate if (local != 0 && !bad_ip_adrs(local)) {
13777c478bd9Sstevel@tonic-gate wo->ouraddr = local;
13787c478bd9Sstevel@tonic-gate ipcp_from_hostname = 1;
13797c478bd9Sstevel@tonic-gate }
13807c478bd9Sstevel@tonic-gate }
13817c478bd9Sstevel@tonic-gate }
13827c478bd9Sstevel@tonic-gate }
13837c478bd9Sstevel@tonic-gate
13847c478bd9Sstevel@tonic-gate
13857c478bd9Sstevel@tonic-gate /*
13867c478bd9Sstevel@tonic-gate * ip_demand_conf - configure the interface as though
13877c478bd9Sstevel@tonic-gate * IPCP were up, for use with dial-on-demand.
13887c478bd9Sstevel@tonic-gate */
13897c478bd9Sstevel@tonic-gate static int
ip_demand_conf(u)13907c478bd9Sstevel@tonic-gate ip_demand_conf(u)
13917c478bd9Sstevel@tonic-gate int u;
13927c478bd9Sstevel@tonic-gate {
13937c478bd9Sstevel@tonic-gate ipcp_options *wo = &ipcp_wantoptions[u];
13947c478bd9Sstevel@tonic-gate
13957c478bd9Sstevel@tonic-gate if (wo->hisaddr == 0) {
13967c478bd9Sstevel@tonic-gate /* make up an arbitrary address for the peer */
13977c478bd9Sstevel@tonic-gate wo->hisaddr = htonl(0x0a707070 + ifunit);
13987c478bd9Sstevel@tonic-gate wo->accept_remote = 1;
13997c478bd9Sstevel@tonic-gate }
14007c478bd9Sstevel@tonic-gate if (wo->ouraddr == 0) {
14017c478bd9Sstevel@tonic-gate /* make up an arbitrary address for us */
14027c478bd9Sstevel@tonic-gate wo->ouraddr = htonl(0x0a404040 + ifunit);
14037c478bd9Sstevel@tonic-gate wo->accept_local = 1;
14047c478bd9Sstevel@tonic-gate disable_defaultip = 1; /* don't tell the peer this address */
14057c478bd9Sstevel@tonic-gate }
14067c478bd9Sstevel@tonic-gate if (!sifaddr(u, wo->ouraddr, wo->hisaddr, GetMask(wo->ouraddr)))
14077c478bd9Sstevel@tonic-gate return 0;
14087c478bd9Sstevel@tonic-gate if (!sifup(u))
14097c478bd9Sstevel@tonic-gate return 0;
14107c478bd9Sstevel@tonic-gate if (!sifnpmode(u, PPP_IP, NPMODE_QUEUE))
14117c478bd9Sstevel@tonic-gate return 0;
14127c478bd9Sstevel@tonic-gate if (wo->default_route && sifdefaultroute(u, wo->ouraddr, wo->hisaddr))
14137c478bd9Sstevel@tonic-gate default_route_set[u] = 1;
14147c478bd9Sstevel@tonic-gate if (wo->proxy_arp && sifproxyarp(u, wo->hisaddr, proxy_arp_quiet[u]))
14157c478bd9Sstevel@tonic-gate proxy_arp_set[u] = 1;
14167c478bd9Sstevel@tonic-gate
14177c478bd9Sstevel@tonic-gate notice("local IP address %I", wo->ouraddr);
14187c478bd9Sstevel@tonic-gate notice("remote IP address %I", wo->hisaddr);
14197c478bd9Sstevel@tonic-gate
14207c478bd9Sstevel@tonic-gate return 1;
14217c478bd9Sstevel@tonic-gate }
14227c478bd9Sstevel@tonic-gate
14237c478bd9Sstevel@tonic-gate
14247c478bd9Sstevel@tonic-gate /*
14257c478bd9Sstevel@tonic-gate * ipcp_up - IPCP has come UP.
14267c478bd9Sstevel@tonic-gate *
14277c478bd9Sstevel@tonic-gate * Configure the IP network interface appropriately and bring it up.
14287c478bd9Sstevel@tonic-gate */
14297c478bd9Sstevel@tonic-gate static void
ipcp_up(f)14307c478bd9Sstevel@tonic-gate ipcp_up(f)
14317c478bd9Sstevel@tonic-gate fsm *f;
14327c478bd9Sstevel@tonic-gate {
14337c478bd9Sstevel@tonic-gate u_int32_t mask;
14347c478bd9Sstevel@tonic-gate ipcp_options *ho = &ipcp_hisoptions[f->unit];
14357c478bd9Sstevel@tonic-gate ipcp_options *go = &ipcp_gotoptions[f->unit];
14367c478bd9Sstevel@tonic-gate ipcp_options *wo = &ipcp_wantoptions[f->unit];
14377c478bd9Sstevel@tonic-gate
14387c478bd9Sstevel@tonic-gate IPCPDEBUG(("ipcp: up"));
14397c478bd9Sstevel@tonic-gate
14407c478bd9Sstevel@tonic-gate /*
14417c478bd9Sstevel@tonic-gate * We must have a non-zero IP address for both ends of the link.
14427c478bd9Sstevel@tonic-gate */
14437c478bd9Sstevel@tonic-gate if (ho->hisaddr == 0)
14447c478bd9Sstevel@tonic-gate ho->hisaddr = wo->hisaddr;
14457c478bd9Sstevel@tonic-gate
14467c478bd9Sstevel@tonic-gate if (ho->hisaddr == 0) {
14477c478bd9Sstevel@tonic-gate if (wo->accept_remote) {
14487c478bd9Sstevel@tonic-gate /* Pick some rfc1918 address. */
14497c478bd9Sstevel@tonic-gate ho->hisaddr = htonl(0xc0a80101 + ifunit);
14507c478bd9Sstevel@tonic-gate dbglog("Peer refused to provide his address; assuming %I",
14517c478bd9Sstevel@tonic-gate ho->hisaddr);
14527c478bd9Sstevel@tonic-gate } else {
14537c478bd9Sstevel@tonic-gate error("Could not determine remote IP address");
14547c478bd9Sstevel@tonic-gate ipcp_close(f->unit, "Could not determine remote IP address");
14557c478bd9Sstevel@tonic-gate return;
14567c478bd9Sstevel@tonic-gate }
14577c478bd9Sstevel@tonic-gate }
14587c478bd9Sstevel@tonic-gate if (go->ouraddr == 0) {
14597c478bd9Sstevel@tonic-gate error("Could not determine local IP address");
14607c478bd9Sstevel@tonic-gate ipcp_close(f->unit, "Could not determine local IP address");
14617c478bd9Sstevel@tonic-gate return;
14627c478bd9Sstevel@tonic-gate }
14637c478bd9Sstevel@tonic-gate script_setenv("IPLOCAL", ip_ntoa(go->ouraddr), 0);
14647c478bd9Sstevel@tonic-gate script_setenv("IPREMOTE", ip_ntoa(ho->hisaddr), 1);
14657c478bd9Sstevel@tonic-gate
14667c478bd9Sstevel@tonic-gate /*
14677c478bd9Sstevel@tonic-gate * Check that the peer is allowed to use the IP address it wants.
14687c478bd9Sstevel@tonic-gate */
14697c478bd9Sstevel@tonic-gate if (!auth_ip_addr(f->unit, ho->hisaddr)) {
14707c478bd9Sstevel@tonic-gate error("Peer is not authorized to use remote address %I", ho->hisaddr);
14717c478bd9Sstevel@tonic-gate ipcp_close(f->unit, "Unauthorized remote IP address");
14727c478bd9Sstevel@tonic-gate return;
14737c478bd9Sstevel@tonic-gate }
14747c478bd9Sstevel@tonic-gate
14757c478bd9Sstevel@tonic-gate if ((go->req_dns1 && go->dnsaddr[0] != 0) ||
14767c478bd9Sstevel@tonic-gate (go->req_dns2 && go->dnsaddr[1] != 0)) {
14777c478bd9Sstevel@tonic-gate script_setenv("USEPEERDNS", "1", 0);
14787c478bd9Sstevel@tonic-gate if (go->dnsaddr[0] != 0)
14797c478bd9Sstevel@tonic-gate script_setenv("DNS1", ip_ntoa(go->dnsaddr[0]), 0);
14807c478bd9Sstevel@tonic-gate if (go->dnsaddr[1] != 0)
14817c478bd9Sstevel@tonic-gate script_setenv("DNS2", ip_ntoa(go->dnsaddr[1]), 0);
14827c478bd9Sstevel@tonic-gate create_resolv(go->dnsaddr[0], go->dnsaddr[1]);
14837c478bd9Sstevel@tonic-gate }
14847c478bd9Sstevel@tonic-gate
14857c478bd9Sstevel@tonic-gate /* set tcp compression */
14867c478bd9Sstevel@tonic-gate if (sifvjcomp(f->unit, ho->neg_vj, ho->cflag, ho->maxslotindex) != 1) {
14877c478bd9Sstevel@tonic-gate ipcp_close(f->unit, "Could not enable VJ TCP header compression");
14887c478bd9Sstevel@tonic-gate return;
14897c478bd9Sstevel@tonic-gate }
14907c478bd9Sstevel@tonic-gate
14917c478bd9Sstevel@tonic-gate /*
14927c478bd9Sstevel@tonic-gate * If we are doing dial-on-demand, the interface is already
14937c478bd9Sstevel@tonic-gate * configured, so we put out any saved-up packets, then set the
14947c478bd9Sstevel@tonic-gate * interface to pass IP packets.
14957c478bd9Sstevel@tonic-gate */
14967c478bd9Sstevel@tonic-gate if (demand) {
14977c478bd9Sstevel@tonic-gate if (go->ouraddr != wo->ouraddr || ho->hisaddr != wo->hisaddr) {
14987c478bd9Sstevel@tonic-gate ipcp_clear_addrs(f->unit, wo->ouraddr, wo->hisaddr);
14997c478bd9Sstevel@tonic-gate if (go->ouraddr != wo->ouraddr) {
15007c478bd9Sstevel@tonic-gate warn("Local IP address changed to %I", go->ouraddr);
15017c478bd9Sstevel@tonic-gate script_setenv("OLDIPLOCAL", ip_ntoa(wo->ouraddr), 0);
15027c478bd9Sstevel@tonic-gate wo->ouraddr = go->ouraddr;
15037c478bd9Sstevel@tonic-gate } else
15047c478bd9Sstevel@tonic-gate script_unsetenv("OLDIPLOCAL");
15057c478bd9Sstevel@tonic-gate if (ho->hisaddr != wo->hisaddr) {
15067c478bd9Sstevel@tonic-gate warn("Remote IP address changed to %I", ho->hisaddr);
15077c478bd9Sstevel@tonic-gate script_setenv("OLDIPREMOTE", ip_ntoa(wo->hisaddr), 0);
15087c478bd9Sstevel@tonic-gate wo->hisaddr = ho->hisaddr;
15097c478bd9Sstevel@tonic-gate } else
15107c478bd9Sstevel@tonic-gate script_unsetenv("OLDIPREMOTE");
15117c478bd9Sstevel@tonic-gate
15127c478bd9Sstevel@tonic-gate /* Set the interface to the new addresses */
15137c478bd9Sstevel@tonic-gate mask = GetMask(go->ouraddr);
15147c478bd9Sstevel@tonic-gate if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
15157c478bd9Sstevel@tonic-gate warn("Interface configuration failed");
15167c478bd9Sstevel@tonic-gate ipcp_close(f->unit, "Interface configuration failed");
15177c478bd9Sstevel@tonic-gate return;
15187c478bd9Sstevel@tonic-gate }
15197c478bd9Sstevel@tonic-gate
15207c478bd9Sstevel@tonic-gate /* assign a default route through the interface if required */
15217c478bd9Sstevel@tonic-gate if (wo->default_route)
15227c478bd9Sstevel@tonic-gate if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr))
15237c478bd9Sstevel@tonic-gate default_route_set[f->unit] = 1;
15247c478bd9Sstevel@tonic-gate
15257c478bd9Sstevel@tonic-gate /* Make a proxy ARP entry if requested. */
15267c478bd9Sstevel@tonic-gate if (wo->proxy_arp &&
15277c478bd9Sstevel@tonic-gate sifproxyarp(f->unit, ho->hisaddr, proxy_arp_quiet[f->unit]))
15287c478bd9Sstevel@tonic-gate proxy_arp_set[f->unit] = 1;
15297c478bd9Sstevel@tonic-gate
15307c478bd9Sstevel@tonic-gate }
15317c478bd9Sstevel@tonic-gate demand_rexmit(PPP_IP);
15327c478bd9Sstevel@tonic-gate if (sifnpmode(f->unit, PPP_IP, NPMODE_PASS) != 1) {
15337c478bd9Sstevel@tonic-gate ipcp_close(f->unit, "Interface configuration failed.");
15347c478bd9Sstevel@tonic-gate return;
15357c478bd9Sstevel@tonic-gate }
15367c478bd9Sstevel@tonic-gate
15377c478bd9Sstevel@tonic-gate } else {
15387c478bd9Sstevel@tonic-gate /*
15397c478bd9Sstevel@tonic-gate * Set IP addresses and (if specified) netmask.
15407c478bd9Sstevel@tonic-gate */
15417c478bd9Sstevel@tonic-gate mask = GetMask(go->ouraddr);
15427c478bd9Sstevel@tonic-gate
15437c478bd9Sstevel@tonic-gate #if SIFUPFIRST
15447c478bd9Sstevel@tonic-gate /* bring the interface up for IP */
15457c478bd9Sstevel@tonic-gate if (!sifup(f->unit)) {
15467c478bd9Sstevel@tonic-gate warn("Interface failed to come up");
15477c478bd9Sstevel@tonic-gate ipcp_close(f->unit, "Interface configuration failed");
15487c478bd9Sstevel@tonic-gate return;
15497c478bd9Sstevel@tonic-gate }
15507c478bd9Sstevel@tonic-gate #endif
15517c478bd9Sstevel@tonic-gate
15527c478bd9Sstevel@tonic-gate if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
15537c478bd9Sstevel@tonic-gate warn("Interface configuration failed");
15547c478bd9Sstevel@tonic-gate ipcp_close(f->unit, "Interface configuration failed");
15557c478bd9Sstevel@tonic-gate return;
15567c478bd9Sstevel@tonic-gate }
15577c478bd9Sstevel@tonic-gate
15587c478bd9Sstevel@tonic-gate #if !SIFUPFIRST
15597c478bd9Sstevel@tonic-gate /* bring the interface up for IP */
15607c478bd9Sstevel@tonic-gate if (!sifup(f->unit)) {
15617c478bd9Sstevel@tonic-gate warn("Interface failed to come up");
15627c478bd9Sstevel@tonic-gate ipcp_close(f->unit, "Interface configuration failed");
15637c478bd9Sstevel@tonic-gate return;
15647c478bd9Sstevel@tonic-gate }
15657c478bd9Sstevel@tonic-gate #endif
15667c478bd9Sstevel@tonic-gate
15677c478bd9Sstevel@tonic-gate if (sifnpmode(f->unit, PPP_IP, NPMODE_PASS) != 1) {
15687c478bd9Sstevel@tonic-gate ipcp_close(f->unit, "Interface configuration failed.");
15697c478bd9Sstevel@tonic-gate return;
15707c478bd9Sstevel@tonic-gate }
15717c478bd9Sstevel@tonic-gate
15727c478bd9Sstevel@tonic-gate /* assign a default route through the interface if required */
15737c478bd9Sstevel@tonic-gate if (wo->default_route)
15747c478bd9Sstevel@tonic-gate if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr))
15757c478bd9Sstevel@tonic-gate default_route_set[f->unit] = 1;
15767c478bd9Sstevel@tonic-gate
15777c478bd9Sstevel@tonic-gate /* Make a proxy ARP entry if requested. */
15787c478bd9Sstevel@tonic-gate if (wo->proxy_arp &&
15797c478bd9Sstevel@tonic-gate sifproxyarp(f->unit, ho->hisaddr, proxy_arp_quiet[f->unit]))
15807c478bd9Sstevel@tonic-gate proxy_arp_set[f->unit] = 1;
15817c478bd9Sstevel@tonic-gate
15827c478bd9Sstevel@tonic-gate wo->ouraddr = go->ouraddr;
15837c478bd9Sstevel@tonic-gate
15847c478bd9Sstevel@tonic-gate notice("local IP address %I", go->ouraddr);
15857c478bd9Sstevel@tonic-gate notice("remote IP address %I", ho->hisaddr);
15867c478bd9Sstevel@tonic-gate if (go->dnsaddr[0] != 0)
15877c478bd9Sstevel@tonic-gate notice("primary DNS address %I", go->dnsaddr[0]);
15887c478bd9Sstevel@tonic-gate if (go->dnsaddr[1] != 0)
15897c478bd9Sstevel@tonic-gate notice("secondary DNS address %I", go->dnsaddr[1]);
15907c478bd9Sstevel@tonic-gate }
15917c478bd9Sstevel@tonic-gate
15927c478bd9Sstevel@tonic-gate np_up(f->unit, PPP_IP);
15937c478bd9Sstevel@tonic-gate ipcp_is_up[f->unit] = 1;
15947c478bd9Sstevel@tonic-gate
15957c478bd9Sstevel@tonic-gate if (ip_up_hook != NULL)
15967c478bd9Sstevel@tonic-gate (*ip_up_hook)();
15977c478bd9Sstevel@tonic-gate
15987c478bd9Sstevel@tonic-gate /*
15997c478bd9Sstevel@tonic-gate * Execute the ip-up script, like this:
16007c478bd9Sstevel@tonic-gate * /etc/ppp/ip-up interface tty speed local-IP remote-IP
16017c478bd9Sstevel@tonic-gate */
16027c478bd9Sstevel@tonic-gate if (ipcp_script_state == s_down && ipcp_script_pid == 0) {
16037c478bd9Sstevel@tonic-gate ipcp_script_state = s_up;
16047c478bd9Sstevel@tonic-gate ipcp_script(_PATH_IPUP);
16057c478bd9Sstevel@tonic-gate }
16067c478bd9Sstevel@tonic-gate sys_unblock_proto(PPP_IP);
16077c478bd9Sstevel@tonic-gate }
16087c478bd9Sstevel@tonic-gate
16097c478bd9Sstevel@tonic-gate
16107c478bd9Sstevel@tonic-gate /*
16117c478bd9Sstevel@tonic-gate * ipcp_down - IPCP has gone DOWN.
16127c478bd9Sstevel@tonic-gate *
16137c478bd9Sstevel@tonic-gate * Take the IP network interface down, clear its addresses
16147c478bd9Sstevel@tonic-gate * and delete routes through it.
16157c478bd9Sstevel@tonic-gate */
16167c478bd9Sstevel@tonic-gate static void
ipcp_down(f)16177c478bd9Sstevel@tonic-gate ipcp_down(f)
16187c478bd9Sstevel@tonic-gate fsm *f;
16197c478bd9Sstevel@tonic-gate {
16207c478bd9Sstevel@tonic-gate IPCPDEBUG(("ipcp: down"));
16217c478bd9Sstevel@tonic-gate /* XXX a bit IPv4-centric here, we only need to get the stats
16227c478bd9Sstevel@tonic-gate * before the interface is marked down. */
16237c478bd9Sstevel@tonic-gate update_link_stats(f->unit);
16247c478bd9Sstevel@tonic-gate if (ip_down_hook != NULL)
16257c478bd9Sstevel@tonic-gate (*ip_down_hook)();
16267c478bd9Sstevel@tonic-gate if (ipcp_is_up[f->unit]) {
16277c478bd9Sstevel@tonic-gate ipcp_is_up[f->unit] = 0;
16287c478bd9Sstevel@tonic-gate np_down(f->unit, PPP_IP);
16297c478bd9Sstevel@tonic-gate }
16307c478bd9Sstevel@tonic-gate if (sifvjcomp(f->unit, 0, 0, 0) != 1) {
16317c478bd9Sstevel@tonic-gate if (debug)
16327c478bd9Sstevel@tonic-gate warn("Failed to disable VJ TCP header compression.");
16337c478bd9Sstevel@tonic-gate }
16347c478bd9Sstevel@tonic-gate
16357c478bd9Sstevel@tonic-gate /*
16367c478bd9Sstevel@tonic-gate * If we are doing dial-on-demand, set the interface
16377c478bd9Sstevel@tonic-gate * to queue up outgoing packets (for now).
16387c478bd9Sstevel@tonic-gate */
16397c478bd9Sstevel@tonic-gate if (demand) {
16407c478bd9Sstevel@tonic-gate if (sifnpmode(f->unit, PPP_IP, NPMODE_QUEUE) != 1) {
16417c478bd9Sstevel@tonic-gate if (debug)
16427c478bd9Sstevel@tonic-gate warn("Failed to enable Queueing on outgoing packets.");
16437c478bd9Sstevel@tonic-gate }
16447c478bd9Sstevel@tonic-gate } else {
16457c478bd9Sstevel@tonic-gate if (sifnpmode(f->unit, PPP_IP, NPMODE_ERROR) != 1) {
16467c478bd9Sstevel@tonic-gate if (debug)
16477c478bd9Sstevel@tonic-gate warn("Could not set interface to drop packets.");
16487c478bd9Sstevel@tonic-gate }
16497c478bd9Sstevel@tonic-gate if (sifdown(f->unit) != 1)
16507c478bd9Sstevel@tonic-gate warn("Could not bring interface down.");
16517c478bd9Sstevel@tonic-gate ipcp_clear_addrs(f->unit, ipcp_gotoptions[f->unit].ouraddr,
16527c478bd9Sstevel@tonic-gate ipcp_hisoptions[f->unit].hisaddr);
16537c478bd9Sstevel@tonic-gate }
16547c478bd9Sstevel@tonic-gate
16557c478bd9Sstevel@tonic-gate /* Execute the ip-down script */
16567c478bd9Sstevel@tonic-gate if (ipcp_script_state == s_up && ipcp_script_pid == 0) {
16577c478bd9Sstevel@tonic-gate ipcp_script_state = s_down;
16587c478bd9Sstevel@tonic-gate ipcp_script(_PATH_IPDOWN);
16597c478bd9Sstevel@tonic-gate }
16607c478bd9Sstevel@tonic-gate }
16617c478bd9Sstevel@tonic-gate
16627c478bd9Sstevel@tonic-gate
16637c478bd9Sstevel@tonic-gate /*
16647c478bd9Sstevel@tonic-gate * ipcp_clear_addrs() - clear the interface addresses, routes,
16657c478bd9Sstevel@tonic-gate * proxy arp entries, etc.
16667c478bd9Sstevel@tonic-gate */
16677c478bd9Sstevel@tonic-gate static void
ipcp_clear_addrs(unit,ouraddr,hisaddr)16687c478bd9Sstevel@tonic-gate ipcp_clear_addrs(unit, ouraddr, hisaddr)
16697c478bd9Sstevel@tonic-gate int unit;
16707c478bd9Sstevel@tonic-gate u_int32_t ouraddr; /* local address */
16717c478bd9Sstevel@tonic-gate u_int32_t hisaddr; /* remote address */
16727c478bd9Sstevel@tonic-gate {
16737c478bd9Sstevel@tonic-gate if (proxy_arp_set[unit]) {
16747c478bd9Sstevel@tonic-gate (void) cifproxyarp(unit, hisaddr);
16757c478bd9Sstevel@tonic-gate proxy_arp_set[unit] = 0;
16767c478bd9Sstevel@tonic-gate }
16777c478bd9Sstevel@tonic-gate if (default_route_set[unit]) {
16787c478bd9Sstevel@tonic-gate (void) cifdefaultroute(unit, ouraddr, hisaddr);
16797c478bd9Sstevel@tonic-gate default_route_set[unit] = 0;
16807c478bd9Sstevel@tonic-gate }
16817c478bd9Sstevel@tonic-gate if (cifaddr(unit, ouraddr, hisaddr) != 1)
16827c478bd9Sstevel@tonic-gate warn("Could not clear addresses");
16837c478bd9Sstevel@tonic-gate }
16847c478bd9Sstevel@tonic-gate
16857c478bd9Sstevel@tonic-gate
16867c478bd9Sstevel@tonic-gate /*
16877c478bd9Sstevel@tonic-gate * ipcp_finished - possibly shut down the lower layers.
16887c478bd9Sstevel@tonic-gate */
16897c478bd9Sstevel@tonic-gate static void
ipcp_finished(f)16907c478bd9Sstevel@tonic-gate ipcp_finished(f)
16917c478bd9Sstevel@tonic-gate fsm *f;
16927c478bd9Sstevel@tonic-gate {
16937c478bd9Sstevel@tonic-gate np_finished(f->unit, PPP_IP);
16947c478bd9Sstevel@tonic-gate }
16957c478bd9Sstevel@tonic-gate
16967c478bd9Sstevel@tonic-gate
16977c478bd9Sstevel@tonic-gate /*
16987c478bd9Sstevel@tonic-gate * ipcp_script_done - called when the ip-up or ip-down script
16997c478bd9Sstevel@tonic-gate * has finished.
17007c478bd9Sstevel@tonic-gate */
17017c478bd9Sstevel@tonic-gate /*ARGSUSED*/
17027c478bd9Sstevel@tonic-gate static void
ipcp_script_done(arg,status)17037c478bd9Sstevel@tonic-gate ipcp_script_done(arg, status)
17047c478bd9Sstevel@tonic-gate void *arg;
17057c478bd9Sstevel@tonic-gate int status;
17067c478bd9Sstevel@tonic-gate {
17077c478bd9Sstevel@tonic-gate ipcp_script_pid = 0;
17087c478bd9Sstevel@tonic-gate switch (ipcp_script_state) {
17097c478bd9Sstevel@tonic-gate case s_up:
17107c478bd9Sstevel@tonic-gate if (ipcp_fsm[0].state != OPENED) {
17117c478bd9Sstevel@tonic-gate ipcp_script_state = s_down;
17127c478bd9Sstevel@tonic-gate ipcp_script(_PATH_IPDOWN);
17137c478bd9Sstevel@tonic-gate }
17147c478bd9Sstevel@tonic-gate break;
17157c478bd9Sstevel@tonic-gate case s_down:
17167c478bd9Sstevel@tonic-gate if (ipcp_fsm[0].state == OPENED) {
17177c478bd9Sstevel@tonic-gate ipcp_script_state = s_up;
17187c478bd9Sstevel@tonic-gate ipcp_script(_PATH_IPUP);
17197c478bd9Sstevel@tonic-gate }
17207c478bd9Sstevel@tonic-gate break;
17217c478bd9Sstevel@tonic-gate }
17227c478bd9Sstevel@tonic-gate }
17237c478bd9Sstevel@tonic-gate
17247c478bd9Sstevel@tonic-gate
17257c478bd9Sstevel@tonic-gate /*
17267c478bd9Sstevel@tonic-gate * ipcp_script - Execute a script with arguments
17277c478bd9Sstevel@tonic-gate * interface-name tty-name speed local-IP remote-IP.
17287c478bd9Sstevel@tonic-gate */
17297c478bd9Sstevel@tonic-gate static void
ipcp_script(script)17307c478bd9Sstevel@tonic-gate ipcp_script(script)
17317c478bd9Sstevel@tonic-gate char *script;
17327c478bd9Sstevel@tonic-gate {
17337c478bd9Sstevel@tonic-gate char strspeed[32], strlocal[32], strremote[32];
17347c478bd9Sstevel@tonic-gate char *argv[8];
17357c478bd9Sstevel@tonic-gate
17367c478bd9Sstevel@tonic-gate (void) slprintf(strspeed, sizeof(strspeed), "%d", baud_rate);
17377c478bd9Sstevel@tonic-gate (void) slprintf(strlocal, sizeof(strlocal), "%I",
17387c478bd9Sstevel@tonic-gate ipcp_gotoptions[0].ouraddr);
17397c478bd9Sstevel@tonic-gate (void) slprintf(strremote, sizeof(strremote), "%I",
17407c478bd9Sstevel@tonic-gate ipcp_hisoptions[0].hisaddr);
17417c478bd9Sstevel@tonic-gate
17427c478bd9Sstevel@tonic-gate argv[0] = script;
17437c478bd9Sstevel@tonic-gate argv[1] = ifname;
17447c478bd9Sstevel@tonic-gate argv[2] = devnam;
17457c478bd9Sstevel@tonic-gate argv[3] = strspeed;
17467c478bd9Sstevel@tonic-gate argv[4] = strlocal;
17477c478bd9Sstevel@tonic-gate argv[5] = strremote;
17487c478bd9Sstevel@tonic-gate argv[6] = ipparam;
17497c478bd9Sstevel@tonic-gate argv[7] = NULL;
17507c478bd9Sstevel@tonic-gate ipcp_script_pid = run_program(script, argv, 0, ipcp_script_done, NULL);
17517c478bd9Sstevel@tonic-gate }
17527c478bd9Sstevel@tonic-gate
17537c478bd9Sstevel@tonic-gate /*
17547c478bd9Sstevel@tonic-gate * create_resolv - create the replacement resolv.conf file
17557c478bd9Sstevel@tonic-gate */
17567c478bd9Sstevel@tonic-gate static void
create_resolv(peerdns1,peerdns2)17577c478bd9Sstevel@tonic-gate create_resolv(peerdns1, peerdns2)
17587c478bd9Sstevel@tonic-gate u_int32_t peerdns1, peerdns2;
17597c478bd9Sstevel@tonic-gate {
17607c478bd9Sstevel@tonic-gate FILE *f;
17617c478bd9Sstevel@tonic-gate
17627c478bd9Sstevel@tonic-gate f = fopen(_PATH_RESOLV, "w");
17637c478bd9Sstevel@tonic-gate if (f == NULL) {
17647c478bd9Sstevel@tonic-gate error("Failed to create %s: %m", _PATH_RESOLV);
17657c478bd9Sstevel@tonic-gate return;
17667c478bd9Sstevel@tonic-gate }
17677c478bd9Sstevel@tonic-gate
17687c478bd9Sstevel@tonic-gate if (peerdns1)
17697c478bd9Sstevel@tonic-gate if (fprintf(f, "nameserver %s\n", ip_ntoa(peerdns1)) <= 0)
17707c478bd9Sstevel@tonic-gate error("Write failed to %s: %m", _PATH_RESOLV);
17717c478bd9Sstevel@tonic-gate
17727c478bd9Sstevel@tonic-gate if (peerdns2)
17737c478bd9Sstevel@tonic-gate if (fprintf(f, "nameserver %s\n", ip_ntoa(peerdns2)) <= 0)
17747c478bd9Sstevel@tonic-gate error("Write failed to %s: %m", _PATH_RESOLV);
17757c478bd9Sstevel@tonic-gate
17767c478bd9Sstevel@tonic-gate if (fclose(f) != 0)
17777c478bd9Sstevel@tonic-gate error("Failed to close %s: %m", _PATH_RESOLV);
17787c478bd9Sstevel@tonic-gate }
17797c478bd9Sstevel@tonic-gate
17807c478bd9Sstevel@tonic-gate /*
17817c478bd9Sstevel@tonic-gate * ipcp_printpkt - print the contents of an IPCP packet.
17827c478bd9Sstevel@tonic-gate */
17837c478bd9Sstevel@tonic-gate static int
ipcp_printpkt(p,plen,printer,arg)17847c478bd9Sstevel@tonic-gate ipcp_printpkt(p, plen, printer, arg)
17857c478bd9Sstevel@tonic-gate u_char *p;
17867c478bd9Sstevel@tonic-gate int plen;
17877c478bd9Sstevel@tonic-gate void (*printer) __P((void *, const char *, ...));
17887c478bd9Sstevel@tonic-gate void *arg;
17897c478bd9Sstevel@tonic-gate {
17907c478bd9Sstevel@tonic-gate int code, id, len, olen;
17917c478bd9Sstevel@tonic-gate u_char *pstart, *optend;
17927c478bd9Sstevel@tonic-gate u_short cishort;
17937c478bd9Sstevel@tonic-gate u_int32_t cilong;
17947c478bd9Sstevel@tonic-gate
17957c478bd9Sstevel@tonic-gate if (plen < HEADERLEN)
17967c478bd9Sstevel@tonic-gate return 0;
17977c478bd9Sstevel@tonic-gate pstart = p;
17987c478bd9Sstevel@tonic-gate GETCHAR(code, p);
17997c478bd9Sstevel@tonic-gate GETCHAR(id, p);
18007c478bd9Sstevel@tonic-gate GETSHORT(len, p);
18017c478bd9Sstevel@tonic-gate if (len < HEADERLEN || len > plen)
18027c478bd9Sstevel@tonic-gate return 0;
18037c478bd9Sstevel@tonic-gate
18047c478bd9Sstevel@tonic-gate printer(arg, " %s id=0x%x", code_name(code, 1), id);
18057c478bd9Sstevel@tonic-gate len -= HEADERLEN;
18067c478bd9Sstevel@tonic-gate switch (code) {
18077c478bd9Sstevel@tonic-gate case CODE_CONFREQ:
18087c478bd9Sstevel@tonic-gate case CODE_CONFACK:
18097c478bd9Sstevel@tonic-gate case CODE_CONFNAK:
18107c478bd9Sstevel@tonic-gate case CODE_CONFREJ:
18117c478bd9Sstevel@tonic-gate /* print option list */
18127c478bd9Sstevel@tonic-gate while (len >= 2) {
18137c478bd9Sstevel@tonic-gate GETCHAR(code, p);
18147c478bd9Sstevel@tonic-gate GETCHAR(olen, p);
18157c478bd9Sstevel@tonic-gate p -= 2;
18167c478bd9Sstevel@tonic-gate if (olen < 2 || olen > len) {
18177c478bd9Sstevel@tonic-gate break;
18187c478bd9Sstevel@tonic-gate }
18197c478bd9Sstevel@tonic-gate printer(arg, " <");
18207c478bd9Sstevel@tonic-gate len -= olen;
18217c478bd9Sstevel@tonic-gate optend = p + olen;
18227c478bd9Sstevel@tonic-gate switch (code) {
18237c478bd9Sstevel@tonic-gate case CI_ADDRS:
18247c478bd9Sstevel@tonic-gate if (olen == CILEN_ADDRS) {
18257c478bd9Sstevel@tonic-gate p += 2;
18267c478bd9Sstevel@tonic-gate GETNLONG(cilong, p);
18277c478bd9Sstevel@tonic-gate printer(arg, "addrs %I", cilong);
18287c478bd9Sstevel@tonic-gate GETNLONG(cilong, p);
18297c478bd9Sstevel@tonic-gate printer(arg, " %I", cilong);
18307c478bd9Sstevel@tonic-gate }
18317c478bd9Sstevel@tonic-gate break;
18327c478bd9Sstevel@tonic-gate case CI_COMPRESSTYPE:
18337c478bd9Sstevel@tonic-gate if (olen >= CILEN_COMPRESS) {
18347c478bd9Sstevel@tonic-gate p += 2;
18357c478bd9Sstevel@tonic-gate GETSHORT(cishort, p);
18367c478bd9Sstevel@tonic-gate printer(arg, "compress ");
18377c478bd9Sstevel@tonic-gate switch (cishort) {
18387c478bd9Sstevel@tonic-gate case IPCP_VJ_COMP:
18397c478bd9Sstevel@tonic-gate printer(arg, "VJ");
18407c478bd9Sstevel@tonic-gate break;
18417c478bd9Sstevel@tonic-gate case IPCP_VJ_COMP_OLD:
18427c478bd9Sstevel@tonic-gate printer(arg, "old-VJ");
18437c478bd9Sstevel@tonic-gate break;
18447c478bd9Sstevel@tonic-gate default:
18457c478bd9Sstevel@tonic-gate printer(arg, "0x%x", cishort);
18467c478bd9Sstevel@tonic-gate }
18477c478bd9Sstevel@tonic-gate }
18487c478bd9Sstevel@tonic-gate break;
18497c478bd9Sstevel@tonic-gate case CI_ADDR:
18507c478bd9Sstevel@tonic-gate if (olen == CILEN_ADDR) {
18517c478bd9Sstevel@tonic-gate p += 2;
18527c478bd9Sstevel@tonic-gate GETNLONG(cilong, p);
18537c478bd9Sstevel@tonic-gate printer(arg, "addr %I", cilong);
18547c478bd9Sstevel@tonic-gate }
18557c478bd9Sstevel@tonic-gate break;
18567c478bd9Sstevel@tonic-gate case CI_MS_DNS1:
18577c478bd9Sstevel@tonic-gate case CI_MS_DNS2:
18587c478bd9Sstevel@tonic-gate p += 2;
18597c478bd9Sstevel@tonic-gate GETNLONG(cilong, p);
18607c478bd9Sstevel@tonic-gate printer(arg, "ms-dns%d %I", (code == CI_MS_DNS1 ? 1 : 2),
18617c478bd9Sstevel@tonic-gate cilong);
18627c478bd9Sstevel@tonic-gate break;
18637c478bd9Sstevel@tonic-gate case CI_MS_WINS1:
18647c478bd9Sstevel@tonic-gate case CI_MS_WINS2:
18657c478bd9Sstevel@tonic-gate p += 2;
18667c478bd9Sstevel@tonic-gate GETNLONG(cilong, p);
18677c478bd9Sstevel@tonic-gate printer(arg, "ms-wins%d %I", (code == CI_MS_WINS1 ? 1 : 2),
18687c478bd9Sstevel@tonic-gate cilong);
18697c478bd9Sstevel@tonic-gate break;
18707c478bd9Sstevel@tonic-gate case CI_SUBNET:
18717c478bd9Sstevel@tonic-gate p += 2;
18727c478bd9Sstevel@tonic-gate GETNLONG(cilong, p);
18737c478bd9Sstevel@tonic-gate printer(arg, "subnet %I", cilong);
18747c478bd9Sstevel@tonic-gate break;
18757c478bd9Sstevel@tonic-gate }
18767c478bd9Sstevel@tonic-gate while (p < optend) {
18777c478bd9Sstevel@tonic-gate GETCHAR(code, p);
18787c478bd9Sstevel@tonic-gate printer(arg, " %.2x", code);
18797c478bd9Sstevel@tonic-gate }
18807c478bd9Sstevel@tonic-gate printer(arg, ">");
18817c478bd9Sstevel@tonic-gate }
18827c478bd9Sstevel@tonic-gate break;
18837c478bd9Sstevel@tonic-gate
18847c478bd9Sstevel@tonic-gate case CODE_TERMACK:
18857c478bd9Sstevel@tonic-gate case CODE_TERMREQ:
18867c478bd9Sstevel@tonic-gate if (len > 0 && *p >= ' ' && *p < 0x7f) {
18877c478bd9Sstevel@tonic-gate printer(arg, " ");
18887c478bd9Sstevel@tonic-gate print_string((char *)p, len, printer, arg);
18897c478bd9Sstevel@tonic-gate p += len;
18907c478bd9Sstevel@tonic-gate len = 0;
18917c478bd9Sstevel@tonic-gate }
18927c478bd9Sstevel@tonic-gate break;
18937c478bd9Sstevel@tonic-gate }
18947c478bd9Sstevel@tonic-gate
18957c478bd9Sstevel@tonic-gate /* print the rest of the bytes in the packet */
18967c478bd9Sstevel@tonic-gate for (; len > 0; --len) {
18977c478bd9Sstevel@tonic-gate GETCHAR(code, p);
18987c478bd9Sstevel@tonic-gate printer(arg, " %.2x", code);
18997c478bd9Sstevel@tonic-gate }
19007c478bd9Sstevel@tonic-gate
19017c478bd9Sstevel@tonic-gate return p - pstart;
19027c478bd9Sstevel@tonic-gate }
19037c478bd9Sstevel@tonic-gate
1904*f53eecf5SJames Carlson char *
tcp_flag_decode(val)1905*f53eecf5SJames Carlson tcp_flag_decode(val)
1906*f53eecf5SJames Carlson int val;
1907*f53eecf5SJames Carlson {
1908*f53eecf5SJames Carlson static char buf[32];
1909*f53eecf5SJames Carlson char *cp = buf;
1910*f53eecf5SJames Carlson
1911*f53eecf5SJames Carlson if (val & TH_URG)
1912*f53eecf5SJames Carlson *cp++ = 'U';
1913*f53eecf5SJames Carlson if (val & TH_ACK)
1914*f53eecf5SJames Carlson *cp++ = 'A';
1915*f53eecf5SJames Carlson if (val & TH_PUSH)
1916*f53eecf5SJames Carlson *cp++ = 'P';
1917*f53eecf5SJames Carlson if (val & TH_RST)
1918*f53eecf5SJames Carlson *cp++ = 'R';
1919*f53eecf5SJames Carlson if (val & TH_SYN)
1920*f53eecf5SJames Carlson *cp++ = 'S';
1921*f53eecf5SJames Carlson if (val & TH_FIN)
1922*f53eecf5SJames Carlson *cp++ = 'F';
1923*f53eecf5SJames Carlson if (cp != buf)
1924*f53eecf5SJames Carlson *cp++ = ' ';
1925*f53eecf5SJames Carlson *cp = '\0';
1926*f53eecf5SJames Carlson return buf;
1927*f53eecf5SJames Carlson }
1928*f53eecf5SJames Carlson
19297c478bd9Sstevel@tonic-gate /*
19307c478bd9Sstevel@tonic-gate * ip_active_pkt - see if this IP packet is worth bringing the link up for.
19317c478bd9Sstevel@tonic-gate * We don't bring the link up for IP fragments or for TCP FIN packets
19327c478bd9Sstevel@tonic-gate * with no data.
19337c478bd9Sstevel@tonic-gate */
19347c478bd9Sstevel@tonic-gate
19357c478bd9Sstevel@tonic-gate static int
ip_active_pkt(pkt,len)19367c478bd9Sstevel@tonic-gate ip_active_pkt(pkt, len)
19377c478bd9Sstevel@tonic-gate u_char *pkt;
19387c478bd9Sstevel@tonic-gate int len;
19397c478bd9Sstevel@tonic-gate {
19407c478bd9Sstevel@tonic-gate u_char *tcp;
19417c478bd9Sstevel@tonic-gate struct protoent *pep;
19427c478bd9Sstevel@tonic-gate int val;
19437c478bd9Sstevel@tonic-gate int hlen;
19447c478bd9Sstevel@tonic-gate char buf[32], *cp;
19457c478bd9Sstevel@tonic-gate u_int32_t src, dst;
19467c478bd9Sstevel@tonic-gate
19477c478bd9Sstevel@tonic-gate len -= PPP_HDRLEN;
19487c478bd9Sstevel@tonic-gate pkt += PPP_HDRLEN;
19497c478bd9Sstevel@tonic-gate if (len < IP_HDRLEN) {
19507c478bd9Sstevel@tonic-gate dbglog("IP packet of length %d is not activity", len);
19517c478bd9Sstevel@tonic-gate return 0;
19527c478bd9Sstevel@tonic-gate }
19537c478bd9Sstevel@tonic-gate src = get_ipsrc(pkt);
19547c478bd9Sstevel@tonic-gate dst = get_ipdst(pkt);
19557c478bd9Sstevel@tonic-gate if ((get_ipoff(pkt) & IP_OFFMASK) != 0) {
19567c478bd9Sstevel@tonic-gate dbglog("IP fragment from %I->%I is not activity", src, dst);
19577c478bd9Sstevel@tonic-gate return 0;
19587c478bd9Sstevel@tonic-gate }
19597c478bd9Sstevel@tonic-gate val = get_ipproto(pkt);
19607c478bd9Sstevel@tonic-gate if (val != IPPROTO_TCP) {
19617c478bd9Sstevel@tonic-gate if (debug) {
19627c478bd9Sstevel@tonic-gate if ((pep = getprotobynumber(val)) != NULL) {
19637c478bd9Sstevel@tonic-gate cp = pep->p_name;
19647c478bd9Sstevel@tonic-gate } else {
19657c478bd9Sstevel@tonic-gate (void) slprintf(buf, sizeof (buf), "IP proto %d", val);
19667c478bd9Sstevel@tonic-gate cp = buf;
19677c478bd9Sstevel@tonic-gate }
1968*f53eecf5SJames Carlson info("%s from %I->%I is activity", cp, src, dst);
19697c478bd9Sstevel@tonic-gate }
19707c478bd9Sstevel@tonic-gate return 1;
19717c478bd9Sstevel@tonic-gate }
19727c478bd9Sstevel@tonic-gate hlen = get_iphl(pkt) * 4;
19737c478bd9Sstevel@tonic-gate if (len < hlen + TCP_HDRLEN) {
19747c478bd9Sstevel@tonic-gate dbglog("Bad TCP length %d<%d+%d %I->%I is not activity", len, hlen,
19757c478bd9Sstevel@tonic-gate TCP_HDRLEN, src, dst);
19767c478bd9Sstevel@tonic-gate return 0;
19777c478bd9Sstevel@tonic-gate }
19787c478bd9Sstevel@tonic-gate tcp = pkt + hlen;
19797c478bd9Sstevel@tonic-gate val = get_tcpflags(tcp);
19807c478bd9Sstevel@tonic-gate hlen += get_tcpoff(tcp) * 4;
19817c478bd9Sstevel@tonic-gate if ((val & TH_FIN) != 0 && len == hlen) {
19827c478bd9Sstevel@tonic-gate dbglog("Empty TCP FIN %I->%I is not activity", src, dst);
19837c478bd9Sstevel@tonic-gate return 0;
19847c478bd9Sstevel@tonic-gate }
1985*f53eecf5SJames Carlson info("TCP %d data %s%I->%I is activity", len - hlen,
1986*f53eecf5SJames Carlson tcp_flag_decode(get_tcpflags(tcp)), src, dst);
19877c478bd9Sstevel@tonic-gate return 1;
19887c478bd9Sstevel@tonic-gate }
19897c478bd9Sstevel@tonic-gate
19907c478bd9Sstevel@tonic-gate static void
ipcp_print_stat(unit,strptr)19917c478bd9Sstevel@tonic-gate ipcp_print_stat(unit, strptr)
19927c478bd9Sstevel@tonic-gate int unit;
19937c478bd9Sstevel@tonic-gate FILE *strptr;
19947c478bd9Sstevel@tonic-gate {
19957c478bd9Sstevel@tonic-gate ipcp_options *go = &ipcp_gotoptions[unit];
19967c478bd9Sstevel@tonic-gate ipcp_options *ho = &ipcp_hisoptions[unit];
19977c478bd9Sstevel@tonic-gate char *proto_name = ipcp_protent.name;
19987c478bd9Sstevel@tonic-gate
19997c478bd9Sstevel@tonic-gate if (!ipcp_protent.enabled_flag) {
20007c478bd9Sstevel@tonic-gate (void) flprintf(strptr, "%s disabled\n", proto_name);
20017c478bd9Sstevel@tonic-gate return;
20027c478bd9Sstevel@tonic-gate }
20037c478bd9Sstevel@tonic-gate
20047c478bd9Sstevel@tonic-gate (void) flprintf(strptr, "%s state: %s", proto_name,
20057c478bd9Sstevel@tonic-gate fsm_state(ipcp_fsm[unit].state));
20067c478bd9Sstevel@tonic-gate (void) flprintf(strptr, "%s local %I remote %I", proto_name, go->ouraddr,
20077c478bd9Sstevel@tonic-gate ho->ouraddr);
20087c478bd9Sstevel@tonic-gate }
2009