2 * ipcp.c - PPP IP Control Protocol.
4 * Copyright (c) 1989 Carnegie Mellon University.
7 * Redistribution and use in source and binary forms are permitted
8 * provided that the above copyright notice and this paragraph are
9 * duplicated in all such forms and that any documentation,
10 * advertising materials, and other materials related to such
11 * distribution and use acknowledge that the software was developed
12 * by Carnegie Mellon University. The name of the
13 * University may not be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 #define RCSID "$Id: ipcp.c,v 1.57 2001/03/08 05:11:12 paulus Exp $"
30 #include <sys/param.h>
31 #include <sys/types.h>
32 #include <sys/socket.h>
33 #include <netinet/in.h>
34 #include <arpa/inet.h>
39 #include "pathnames.h"
41 static const char rcsid[] = RCSID;
44 ipcp_options ipcp_wantoptions[NUM_PPP]; /* Options that we want to request */
45 ipcp_options ipcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
46 ipcp_options ipcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
47 ipcp_options ipcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
49 u_int32_t netmask = 0; /* IP netmask to set on interface */
51 bool disable_defaultip = 0; /* Don't use hostname for default IP adrs */
53 /* Hook for a plugin to know when IP protocol has come up */
54 void (*ip_up_hook) __P((void)) = NULL;
56 /* Hook for a plugin to know when IP protocol has come down */
57 void (*ip_down_hook) __P((void)) = NULL;
59 /* Hook for a plugin to choose the remote IP address */
60 void (*ip_choose_hook) __P((u_int32_t *)) = NULL;
63 static int default_route_set[NUM_PPP]; /* Have set up a default route */
64 static int proxy_arp_set[NUM_PPP]; /* Have created proxy arp entry */
65 static bool usepeerdns; /* Ask peer for DNS addrs */
66 static int ipcp_is_up; /* have called np_up() */
67 static bool ask_for_local; /* request our address from peer */
68 static char vj_value[8]; /* string form of vj option value */
69 static char netmask_str[20]; /* string form of netmask value */
72 * Callbacks for fsm code. (CI = Configuration Information)
74 static void ipcp_resetci __P((fsm *)); /* Reset our CI */
75 static int ipcp_cilen __P((fsm *)); /* Return length of our CI */
76 static void ipcp_addci __P((fsm *, u_char *, int *)); /* Add our CI */
77 static int ipcp_ackci __P((fsm *, u_char *, int)); /* Peer ack'd our CI */
78 static int ipcp_nakci __P((fsm *, u_char *, int)); /* Peer nak'd our CI */
79 static int ipcp_rejci __P((fsm *, u_char *, int)); /* Peer rej'd our CI */
80 static int ipcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv CI */
81 static void ipcp_up __P((fsm *)); /* We're UP */
82 static void ipcp_down __P((fsm *)); /* We're DOWN */
83 static void ipcp_finished __P((fsm *)); /* Don't need lower layer */
85 fsm ipcp_fsm[NUM_PPP]; /* IPCP fsm structure */
87 static fsm_callbacks ipcp_callbacks = { /* IPCP callback routines */
88 ipcp_resetci, /* Reset our Configuration Information */
89 ipcp_cilen, /* Length of our Configuration Information */
90 ipcp_addci, /* Add our Configuration Information */
91 ipcp_ackci, /* ACK our Configuration Information */
92 ipcp_nakci, /* NAK our Configuration Information */
93 ipcp_rejci, /* Reject our Configuration Information */
94 ipcp_reqci, /* Request peer's Configuration Information */
95 ipcp_up, /* Called when fsm reaches OPENED state */
96 ipcp_down, /* Called when fsm leaves OPENED state */
97 NULL, /* Called when we want the lower layer up */
98 ipcp_finished, /* Called when we want the lower layer down */
99 NULL, /* Called when Protocol-Reject received */
100 NULL, /* Retransmission is necessary */
101 NULL, /* Called to handle protocol-specific codes */
102 "IPCP" /* String name of protocol */
106 * Command-line options.
108 static int setvjslots __P((char **));
109 static int setdnsaddr __P((char **));
110 static int setwinsaddr __P((char **));
111 static int setnetmask __P((char **));
112 static int setipaddr __P((char *, char **, int));
113 static void printipaddr __P((option_t *, void (*)(void *, char *,...),void *));
115 static option_t ipcp_option_list[] = {
116 { "noip", o_bool, &ipcp_protent.enabled_flag,
117 "Disable IP and IPCP" },
118 { "-ip", o_bool, &ipcp_protent.enabled_flag,
119 "Disable IP and IPCP", OPT_ALIAS },
121 { "novj", o_bool, &ipcp_wantoptions[0].neg_vj,
122 "Disable VJ compression", OPT_A2CLR, &ipcp_allowoptions[0].neg_vj },
123 { "-vj", o_bool, &ipcp_wantoptions[0].neg_vj,
124 "Disable VJ compression", OPT_ALIAS | OPT_A2CLR,
125 &ipcp_allowoptions[0].neg_vj },
127 { "novjccomp", o_bool, &ipcp_wantoptions[0].cflag,
128 "Disable VJ connection-ID compression", OPT_A2CLR,
129 &ipcp_allowoptions[0].cflag },
130 { "-vjccomp", o_bool, &ipcp_wantoptions[0].cflag,
131 "Disable VJ connection-ID compression", OPT_ALIAS | OPT_A2CLR,
132 &ipcp_allowoptions[0].cflag },
134 { "vj-max-slots", o_special, (void *)setvjslots,
135 "Set maximum VJ header slots",
136 OPT_PRIO | OPT_A2STRVAL | OPT_STATIC, vj_value },
138 { "ipcp-accept-local", o_bool, &ipcp_wantoptions[0].accept_local,
139 "Accept peer's address for us", 1 },
140 { "ipcp-accept-remote", o_bool, &ipcp_wantoptions[0].accept_remote,
141 "Accept peer's address for it", 1 },
143 { "ipparam", o_string, &ipparam,
144 "Set ip script parameter", OPT_PRIO },
146 { "noipdefault", o_bool, &disable_defaultip,
147 "Don't use name for default IP adrs", 1 },
149 { "ms-dns", 1, (void *)setdnsaddr,
150 "DNS address for the peer's use" },
151 { "ms-wins", 1, (void *)setwinsaddr,
152 "Nameserver for SMB over TCP/IP for peer" },
154 { "ipcp-restart", o_int, &ipcp_fsm[0].timeouttime,
155 "Set timeout for IPCP", OPT_PRIO },
156 { "ipcp-max-terminate", o_int, &ipcp_fsm[0].maxtermtransmits,
157 "Set max #xmits for term-reqs", OPT_PRIO },
158 { "ipcp-max-configure", o_int, &ipcp_fsm[0].maxconfreqtransmits,
159 "Set max #xmits for conf-reqs", OPT_PRIO },
160 { "ipcp-max-failure", o_int, &ipcp_fsm[0].maxnakloops,
161 "Set max #conf-naks for IPCP", OPT_PRIO },
163 { "defaultroute", o_bool, &ipcp_wantoptions[0].default_route,
164 "Add default route", OPT_ENABLE|1, &ipcp_allowoptions[0].default_route },
165 { "nodefaultroute", o_bool, &ipcp_allowoptions[0].default_route,
166 "disable defaultroute option", OPT_A2CLR,
167 &ipcp_wantoptions[0].default_route },
168 { "-defaultroute", o_bool, &ipcp_allowoptions[0].default_route,
169 "disable defaultroute option", OPT_ALIAS | OPT_A2CLR,
170 &ipcp_wantoptions[0].default_route },
172 { "proxyarp", o_bool, &ipcp_wantoptions[0].proxy_arp,
173 "Add proxy ARP entry", OPT_ENABLE|1, &ipcp_allowoptions[0].proxy_arp },
174 { "noproxyarp", o_bool, &ipcp_allowoptions[0].proxy_arp,
175 "disable proxyarp option", OPT_A2CLR,
176 &ipcp_wantoptions[0].proxy_arp },
177 { "-proxyarp", o_bool, &ipcp_allowoptions[0].proxy_arp,
178 "disable proxyarp option", OPT_ALIAS | OPT_A2CLR,
179 &ipcp_wantoptions[0].proxy_arp },
181 { "usepeerdns", o_bool, &usepeerdns,
182 "Ask peer for DNS address(es)", 1 },
184 { "netmask", o_special, (void *)setnetmask,
185 "set netmask", OPT_PRIO | OPT_A2STRVAL | OPT_STATIC, netmask_str },
187 { "IP addresses", o_wild, (void *) &setipaddr,
188 "set local and remote IP addresses",
189 OPT_NOARG | OPT_A2PRINTER, (void *) &printipaddr },
195 * Protocol entry points from main code.
197 static void ipcp_init __P((int));
198 static void ipcp_open __P((int));
199 static void ipcp_close __P((int, char *));
200 static void ipcp_lowerup __P((int));
201 static void ipcp_lowerdown __P((int));
202 static void ipcp_input __P((int, u_char *, int));
203 static void ipcp_protrej __P((int));
204 static int ipcp_printpkt __P((u_char *, int,
205 void (*) __P((void *, char *, ...)), void *));
206 static void ip_check_options __P((void));
207 static int ip_demand_conf __P((int));
208 static int ip_active_pkt __P((u_char *, int));
209 static void create_resolv __P((u_int32_t, u_int32_t));
211 struct protent ipcp_protent = {
231 static void ipcp_clear_addrs __P((int, u_int32_t, u_int32_t));
232 static void ipcp_script __P((char *)); /* Run an up/down script */
233 static void ipcp_script_done __P((void *));
236 * Lengths of configuration options.
239 #define CILEN_COMPRESS 4 /* min length for compression protocol opt. */
240 #define CILEN_VJ 6 /* length for RFC1332 Van-Jacobson opt. */
241 #define CILEN_ADDR 6 /* new-style single address option */
242 #define CILEN_ADDRS 10 /* old-style dual address option */
245 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
246 (x) == CONFNAK ? "NAK" : "REJ")
249 * This state variable is used to ensure that we don't
250 * run an ipcp-up/down script while one is already running.
252 static enum script_state {
256 static pid_t ipcp_script_pid;
259 * Make a string representation of a network IP address.
267 slprintf(b, sizeof(b), "%I", ipaddr);
276 * setvjslots - set maximum number of connection slots for VJ compression
284 if (!int_option(*argv, &value))
286 if (value < 2 || value > 16) {
287 option_error("vj-max-slots value must be between 2 and 16");
290 ipcp_wantoptions [0].maxslotindex =
291 ipcp_allowoptions[0].maxslotindex = value - 1;
292 slprintf(vj_value, sizeof(vj_value), "%d", value);
297 * setdnsaddr - set the dns address(es)
306 dns = inet_addr(*argv);
307 if (dns == (u_int32_t) -1) {
308 if ((hp = gethostbyname(*argv)) == NULL) {
309 option_error("invalid address parameter '%s' for ms-dns option",
313 dns = *(u_int32_t *)hp->h_addr;
316 /* We take the last 2 values given, the 2nd-last as the primary
317 and the last as the secondary. If only one is given it
318 becomes both primary and secondary. */
319 if (ipcp_allowoptions[0].dnsaddr[1] == 0)
320 ipcp_allowoptions[0].dnsaddr[0] = dns;
322 ipcp_allowoptions[0].dnsaddr[0] = ipcp_allowoptions[0].dnsaddr[1];
324 /* always set the secondary address value. */
325 ipcp_allowoptions[0].dnsaddr[1] = dns;
331 * setwinsaddr - set the wins address(es)
332 * This is primrarly used with the Samba package under UNIX or for pointing
333 * the caller to the existing WINS server on a Windows NT platform.
342 wins = inet_addr(*argv);
343 if (wins == (u_int32_t) -1) {
344 if ((hp = gethostbyname(*argv)) == NULL) {
345 option_error("invalid address parameter '%s' for ms-wins option",
349 wins = *(u_int32_t *)hp->h_addr;
352 /* We take the last 2 values given, the 2nd-last as the primary
353 and the last as the secondary. If only one is given it
354 becomes both primary and secondary. */
355 if (ipcp_allowoptions[0].winsaddr[1] == 0)
356 ipcp_allowoptions[0].winsaddr[0] = wins;
358 ipcp_allowoptions[0].winsaddr[0] = ipcp_allowoptions[0].winsaddr[1];
360 /* always set the secondary address value. */
361 ipcp_allowoptions[0].winsaddr[1] = wins;
367 * setipaddr - Set the IP address
368 * If doit is 0, the call is to check whether this option is
369 * potentially an IP address specification.
372 setipaddr(arg, argv, doit)
379 u_int32_t local, remote;
380 ipcp_options *wo = &ipcp_wantoptions[0];
381 static int prio_local = 0, prio_remote = 0;
384 * IP address pair separated by ":".
386 if ((colon = strchr(arg, ':')) == NULL)
392 * If colon first character, then no local addr.
394 if (colon != arg && option_priority >= prio_local) {
396 if ((local = inet_addr(arg)) == (u_int32_t) -1) {
397 if ((hp = gethostbyname(arg)) == NULL) {
398 option_error("unknown host: %s", arg);
401 local = *(u_int32_t *)hp->h_addr;
403 if (bad_ip_adrs(local)) {
404 option_error("bad local IP address %s", ip_ntoa(local));
410 prio_local = option_priority;
414 * If colon last character, then no remote addr.
416 if (*++colon != '\0' && option_priority >= prio_remote) {
417 if ((remote = inet_addr(colon)) == (u_int32_t) -1) {
418 if ((hp = gethostbyname(colon)) == NULL) {
419 option_error("unknown host: %s", colon);
422 remote = *(u_int32_t *)hp->h_addr;
423 if (remote_name[0] == 0)
424 strlcpy(remote_name, colon, sizeof(remote_name));
426 if (bad_ip_adrs(remote)) {
427 option_error("bad remote IP address %s", ip_ntoa(remote));
431 wo->hisaddr = remote;
432 prio_remote = option_priority;
439 printipaddr(opt, printer, arg)
441 void (*printer) __P((void *, char *, ...));
444 ipcp_options *wo = &ipcp_wantoptions[0];
446 if (wo->ouraddr != 0)
447 printer(arg, "%I", wo->ouraddr);
449 if (wo->hisaddr != 0)
450 printer(arg, "%I", wo->hisaddr);
454 * setnetmask - set the netmask to be used on the interface.
465 * Unfortunately, if we use inet_addr, we can't tell whether
466 * a result of all 1s is an error or a valid 255.255.255.255.
469 n = parse_dotted_ip(p, &mask);
473 if (n == 0 || p[n] != 0 || (netmask & ~mask) != 0) {
474 option_error("invalid netmask value '%s'", *argv);
479 slprintf(netmask_str, sizeof(netmask_str), "%I", mask);
485 parse_dotted_ip(p, vp)
495 b = strtoul(p, &endp, 0);
501 /* accept e.g. 0xffffff00 */
519 * ipcp_init - Initialize IPCP.
525 fsm *f = &ipcp_fsm[unit];
526 ipcp_options *wo = &ipcp_wantoptions[unit];
527 ipcp_options *ao = &ipcp_allowoptions[unit];
530 f->protocol = PPP_IPCP;
531 f->callbacks = &ipcp_callbacks;
532 fsm_init(&ipcp_fsm[unit]);
534 memset(wo, 0, sizeof(*wo));
535 memset(ao, 0, sizeof(*ao));
539 wo->vj_protocol = IPCP_VJ_COMP;
540 wo->maxslotindex = MAX_STATES - 1; /* really max index */
544 /* max slots and slot-id compression are currently hardwired in */
545 /* ppp_if.c to 16 and 1, this needs to be changed (among other */
550 ao->maxslotindex = MAX_STATES - 1;
554 * XXX These control whether the user may use the proxyarp
555 * and defaultroute options.
558 ao->default_route = 1;
563 * ipcp_open - IPCP is allowed to come up.
569 fsm_open(&ipcp_fsm[unit]);
574 * ipcp_close - Take IPCP down.
577 ipcp_close(unit, reason)
581 fsm_close(&ipcp_fsm[unit], reason);
586 * ipcp_lowerup - The lower layer is up.
592 fsm_lowerup(&ipcp_fsm[unit]);
597 * ipcp_lowerdown - The lower layer is down.
603 fsm_lowerdown(&ipcp_fsm[unit]);
608 * ipcp_input - Input IPCP packet.
611 ipcp_input(unit, p, len)
616 fsm_input(&ipcp_fsm[unit], p, len);
621 * ipcp_protrej - A Protocol-Reject was received for IPCP.
623 * Pretend the lower layer went down, so we shut up.
629 fsm_lowerdown(&ipcp_fsm[unit]);
634 * ipcp_resetci - Reset our CI.
635 * Called by fsm_sconfreq, Send Configure Request.
641 ipcp_options *wo = &ipcp_wantoptions[f->unit];
642 ipcp_options *go = &ipcp_gotoptions[f->unit];
644 wo->req_addr = wo->neg_addr && ipcp_allowoptions[f->unit].neg_addr;
645 if (wo->ouraddr == 0)
646 wo->accept_local = 1;
647 if (wo->hisaddr == 0)
648 wo->accept_remote = 1;
649 wo->req_dns1 = usepeerdns; /* Request DNS addresses from the peer */
650 wo->req_dns2 = usepeerdns;
655 ip_choose_hook(&wo->hisaddr);
660 * ipcp_cilen - Return length of our CI.
661 * Called by fsm_sconfreq, Send Configure Request.
667 ipcp_options *go = &ipcp_gotoptions[f->unit];
668 ipcp_options *wo = &ipcp_wantoptions[f->unit];
669 ipcp_options *ho = &ipcp_hisoptions[f->unit];
671 #define LENCIVJ(neg, old) (neg ? (old? CILEN_COMPRESS : CILEN_VJ) : 0)
672 #define LENCIADDR(neg, old) (neg ? (old? CILEN_ADDRS : CILEN_ADDR) : 0)
673 #define LENCIDNS(neg) (neg ? (CILEN_ADDR) : 0)
676 * First see if we want to change our options to the old
677 * forms because we have received old forms from the peer.
679 if (wo->neg_addr && !go->neg_addr && !go->old_addrs) {
680 /* use the old style of address negotiation */
684 if (wo->neg_vj && !go->neg_vj && !go->old_vj) {
685 /* try an older style of VJ negotiation */
686 /* use the old style only if the peer did */
687 if (ho->neg_vj && ho->old_vj) {
690 go->vj_protocol = ho->vj_protocol;
694 return (LENCIADDR(go->neg_addr, go->old_addrs) +
695 LENCIVJ(go->neg_vj, go->old_vj) +
696 LENCIDNS(go->req_dns1) +
697 LENCIDNS(go->req_dns2)) ;
702 * ipcp_addci - Add our desired CIs to a packet.
703 * Called by fsm_sconfreq, Send Configure Request.
706 ipcp_addci(f, ucp, lenp)
711 ipcp_options *go = &ipcp_gotoptions[f->unit];
714 #define ADDCIVJ(opt, neg, val, old, maxslotindex, cflag) \
716 int vjlen = old? CILEN_COMPRESS : CILEN_VJ; \
717 if (len >= vjlen) { \
719 PUTCHAR(vjlen, ucp); \
720 PUTSHORT(val, ucp); \
722 PUTCHAR(maxslotindex, ucp); \
723 PUTCHAR(cflag, ucp); \
730 #define ADDCIADDR(opt, neg, old, val1, val2) \
732 int addrlen = (old? CILEN_ADDRS: CILEN_ADDR); \
733 if (len >= addrlen) { \
736 PUTCHAR(addrlen, ucp); \
748 #define ADDCIDNS(opt, neg, addr) \
750 if (len >= CILEN_ADDR) { \
753 PUTCHAR(CILEN_ADDR, ucp); \
761 ADDCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), go->neg_addr,
762 go->old_addrs, go->ouraddr, go->hisaddr);
764 ADDCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol, go->old_vj,
765 go->maxslotindex, go->cflag);
767 ADDCIDNS(CI_MS_DNS1, go->req_dns1, go->dnsaddr[0]);
769 ADDCIDNS(CI_MS_DNS2, go->req_dns2, go->dnsaddr[1]);
776 * ipcp_ackci - Ack our CIs.
777 * Called by fsm_rconfack, Receive Configure ACK.
784 ipcp_ackci(f, p, len)
789 ipcp_options *go = &ipcp_gotoptions[f->unit];
790 u_short cilen, citype, cishort;
792 u_char cimaxslotindex, cicflag;
795 * CIs must be in exactly the same order that we sent...
796 * Check packet length and CI length at each step.
797 * If we find any deviations, then this packet is bad.
800 #define ACKCIVJ(opt, neg, val, old, maxslotindex, cflag) \
802 int vjlen = old? CILEN_COMPRESS : CILEN_VJ; \
803 if ((len -= vjlen) < 0) \
805 GETCHAR(citype, p); \
807 if (cilen != vjlen || \
810 GETSHORT(cishort, p); \
811 if (cishort != val) \
814 GETCHAR(cimaxslotindex, p); \
815 if (cimaxslotindex != maxslotindex) \
817 GETCHAR(cicflag, p); \
818 if (cicflag != cflag) \
823 #define ACKCIADDR(opt, neg, old, val1, val2) \
825 int addrlen = (old? CILEN_ADDRS: CILEN_ADDR); \
827 if ((len -= addrlen) < 0) \
829 GETCHAR(citype, p); \
831 if (cilen != addrlen || \
836 if (val1 != cilong) \
841 if (val2 != cilong) \
846 #define ACKCIDNS(opt, neg, addr) \
849 if ((len -= CILEN_ADDR) < 0) \
851 GETCHAR(citype, p); \
853 if (cilen != CILEN_ADDR || citype != opt) \
857 if (addr != cilong) \
861 ACKCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), go->neg_addr,
862 go->old_addrs, go->ouraddr, go->hisaddr);
864 ACKCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol, go->old_vj,
865 go->maxslotindex, go->cflag);
867 ACKCIDNS(CI_MS_DNS1, go->req_dns1, go->dnsaddr[0]);
869 ACKCIDNS(CI_MS_DNS2, go->req_dns2, go->dnsaddr[1]);
872 * If there are any remaining CIs, then this packet is bad.
879 IPCPDEBUG(("ipcp_ackci: received bad Ack!"));
884 * ipcp_nakci - Peer has sent a NAK for some of our CIs.
885 * This should not modify any state if the Nak is bad
886 * or if IPCP is in the OPENED state.
887 * Calback from fsm_rconfnakrej - Receive Configure-Nak or Configure-Reject.
894 ipcp_nakci(f, p, len)
899 ipcp_options *go = &ipcp_gotoptions[f->unit];
900 u_char cimaxslotindex, cicflag;
901 u_char citype, cilen, *next;
903 u_int32_t ciaddr1, ciaddr2, l, cidnsaddr;
904 ipcp_options no; /* options we've seen Naks for */
905 ipcp_options try; /* options to request next time */
907 BZERO(&no, sizeof(no));
911 * Any Nak'd CIs must be in exactly the same order that we sent.
912 * Check packet length and CI length at each step.
913 * If we find any deviations, then this packet is bad.
915 #define NAKCIADDR(opt, neg, old, code) \
917 len >= (cilen = (old? CILEN_ADDRS: CILEN_ADDR)) && \
923 ciaddr1 = htonl(l); \
926 ciaddr2 = htonl(l); \
934 #define NAKCIVJ(opt, neg, code) \
936 ((cilen = p[1]) == CILEN_COMPRESS || cilen == CILEN_VJ) && \
941 GETSHORT(cishort, p); \
946 #define NAKCIDNS(opt, neg, code) \
948 ((cilen = p[1]) == CILEN_ADDR) && \
954 cidnsaddr = htonl(l); \
960 * Accept the peer's idea of {our,his} address, if different
961 * from our idea, only if the accept_{local,remote} flag is set.
963 NAKCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), neg_addr, go->old_addrs,
964 if (go->accept_local && ciaddr1) { /* Do we know our address? */
965 try.ouraddr = ciaddr1;
967 if (go->accept_remote && ciaddr2) { /* Does he know his? */
968 try.hisaddr = ciaddr2;
973 * Accept the peer's value of maxslotindex provided that it
974 * is less than what we asked for. Turn off slot-ID compression
975 * if the peer wants. Send old-style compress-type option if
978 NAKCIVJ(CI_COMPRESSTYPE, neg_vj,
979 if (cilen == CILEN_VJ) {
980 GETCHAR(cimaxslotindex, p);
982 if (cishort == IPCP_VJ_COMP) {
984 if (cimaxslotindex < go->maxslotindex)
985 try.maxslotindex = cimaxslotindex;
992 if (cishort == IPCP_VJ_COMP || cishort == IPCP_VJ_COMP_OLD) {
994 try.vj_protocol = cishort;
1001 NAKCIDNS(CI_MS_DNS1, req_dns1,
1002 try.dnsaddr[0] = cidnsaddr;
1005 NAKCIDNS(CI_MS_DNS2, req_dns2,
1006 try.dnsaddr[1] = cidnsaddr;
1010 * There may be remaining CIs, if the peer is requesting negotiation
1011 * on an option that we didn't include in our request packet.
1012 * If they want to negotiate about IP addresses, we comply.
1013 * If they want us to ask for compression, we refuse.
1015 while (len > CILEN_VOID) {
1018 if( (len -= cilen) < 0 )
1020 next = p + cilen - 2;
1023 case CI_COMPRESSTYPE:
1024 if (go->neg_vj || no.neg_vj ||
1025 (cilen != CILEN_VJ && cilen != CILEN_COMPRESS))
1030 if ((go->neg_addr && go->old_addrs) || no.old_addrs
1031 || cilen != CILEN_ADDRS)
1037 if (ciaddr1 && go->accept_local)
1038 try.ouraddr = ciaddr1;
1041 if (ciaddr2 && go->accept_remote)
1042 try.hisaddr = ciaddr2;
1046 if (go->neg_addr || no.neg_addr || cilen != CILEN_ADDR)
1051 if (ciaddr1 && go->accept_local)
1052 try.ouraddr = ciaddr1;
1053 if (try.ouraddr != 0)
1062 * OK, the Nak is good. Now we can update state.
1063 * If there are any remaining options, we ignore them.
1065 if (f->state != OPENED)
1071 IPCPDEBUG(("ipcp_nakci: received bad Nak!"));
1077 * ipcp_rejci - Reject some of our CIs.
1078 * Callback from fsm_rconfnakrej.
1081 ipcp_rejci(f, p, len)
1086 ipcp_options *go = &ipcp_gotoptions[f->unit];
1087 u_char cimaxslotindex, ciflag, cilen;
1090 ipcp_options try; /* options to request next time */
1094 * Any Rejected CIs must be in exactly the same order that we sent.
1095 * Check packet length and CI length at each step.
1096 * If we find any deviations, then this packet is bad.
1098 #define REJCIADDR(opt, neg, old, val1, val2) \
1100 len >= (cilen = old? CILEN_ADDRS: CILEN_ADDR) && \
1107 cilong = htonl(l); \
1108 /* Check rejected value. */ \
1109 if (cilong != val1) \
1113 cilong = htonl(l); \
1114 /* Check rejected value. */ \
1115 if (cilong != val2) \
1121 #define REJCIVJ(opt, neg, val, old, maxslot, cflag) \
1123 p[1] == (old? CILEN_COMPRESS : CILEN_VJ) && \
1128 GETSHORT(cishort, p); \
1129 /* Check rejected value. */ \
1130 if (cishort != val) \
1133 GETCHAR(cimaxslotindex, p); \
1134 if (cimaxslotindex != maxslot) \
1136 GETCHAR(ciflag, p); \
1137 if (ciflag != cflag) \
1143 #define REJCIDNS(opt, neg, dnsaddr) \
1145 ((cilen = p[1]) == CILEN_ADDR) && \
1152 cilong = htonl(l); \
1153 /* Check rejected value. */ \
1154 if (cilong != dnsaddr) \
1160 REJCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), neg_addr,
1161 go->old_addrs, go->ouraddr, go->hisaddr);
1163 REJCIVJ(CI_COMPRESSTYPE, neg_vj, go->vj_protocol, go->old_vj,
1164 go->maxslotindex, go->cflag);
1166 REJCIDNS(CI_MS_DNS1, req_dns1, go->dnsaddr[0]);
1168 REJCIDNS(CI_MS_DNS2, req_dns2, go->dnsaddr[1]);
1171 * If there are any remaining CIs, then this packet is bad.
1176 * Now we can update state.
1178 if (f->state != OPENED)
1183 IPCPDEBUG(("ipcp_rejci: received bad Reject!"));
1189 * ipcp_reqci - Check the peer's requested CIs and send appropriate response.
1190 * Callback from fsm_rconfreq, Receive Configure Request
1192 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
1193 * appropriately. If reject_if_disagree is non-zero, doesn't return
1194 * CONFNAK; returns CONFREJ if it can't return CONFACK.
1197 ipcp_reqci(f, inp, len, reject_if_disagree)
1199 u_char *inp; /* Requested CIs */
1200 int *len; /* Length of requested CIs */
1201 int reject_if_disagree;
1203 ipcp_options *wo = &ipcp_wantoptions[f->unit];
1204 ipcp_options *ho = &ipcp_hisoptions[f->unit];
1205 ipcp_options *ao = &ipcp_allowoptions[f->unit];
1206 ipcp_options *go = &ipcp_gotoptions[f->unit];
1207 u_char *cip, *next; /* Pointer to current and next CIs */
1208 u_short cilen, citype; /* Parsed len, type */
1209 u_short cishort; /* Parsed short value */
1210 u_int32_t tl, ciaddr1, ciaddr2;/* Parsed address values */
1211 int rc = CONFACK; /* Final packet return code */
1212 int orc; /* Individual option return code */
1213 u_char *p; /* Pointer to next char to parse */
1214 u_char *ucp = inp; /* Pointer to current output char */
1215 int l = *len; /* Length left */
1216 u_char maxslotindex, cflag;
1220 * Reset all his options.
1222 BZERO(ho, sizeof(*ho));
1225 * Process all his options.
1229 orc = CONFACK; /* Assume success */
1230 cip = p = next; /* Remember begining of CI */
1231 if (l < 2 || /* Not enough data for CI header or */
1232 p[1] < 2 || /* CI length too small or */
1233 p[1] > l) { /* CI length too big? */
1234 IPCPDEBUG(("ipcp_reqci: bad CI length!"));
1235 orc = CONFREJ; /* Reject bad CI */
1236 cilen = l; /* Reject till end of packet */
1237 l = 0; /* Don't loop again */
1240 GETCHAR(citype, p); /* Parse CI type */
1241 GETCHAR(cilen, p); /* Parse CI length */
1242 l -= cilen; /* Adjust remaining length */
1243 next += cilen; /* Step to next CI */
1245 switch (citype) { /* Check CI type */
1247 if (!ao->neg_addr ||
1248 cilen != CILEN_ADDRS) { /* Check CI length */
1249 orc = CONFREJ; /* Reject CI */
1254 * If he has no address, or if we both have his address but
1255 * disagree about it, then NAK it with our idea.
1256 * In particular, if we don't know his address, but he does,
1259 GETLONG(tl, p); /* Parse source address (his) */
1260 ciaddr1 = htonl(tl);
1261 if (ciaddr1 != wo->hisaddr
1262 && (ciaddr1 == 0 || !wo->accept_remote)) {
1264 if (!reject_if_disagree) {
1265 DECPTR(sizeof(u_int32_t), p);
1266 tl = ntohl(wo->hisaddr);
1269 } else if (ciaddr1 == 0 && wo->hisaddr == 0) {
1271 * If neither we nor he knows his address, reject the option.
1274 wo->req_addr = 0; /* don't NAK with 0.0.0.0 later */
1279 * If he doesn't know our address, or if we both have our address
1280 * but disagree about it, then NAK it with our idea.
1282 GETLONG(tl, p); /* Parse desination address (ours) */
1283 ciaddr2 = htonl(tl);
1284 if (ciaddr2 != wo->ouraddr) {
1285 if (ciaddr2 == 0 || !wo->accept_local) {
1287 if (!reject_if_disagree) {
1288 DECPTR(sizeof(u_int32_t), p);
1289 tl = ntohl(wo->ouraddr);
1293 go->ouraddr = ciaddr2; /* accept peer's idea */
1299 ho->hisaddr = ciaddr1;
1300 ho->ouraddr = ciaddr2;
1304 if (!ao->neg_addr ||
1305 cilen != CILEN_ADDR) { /* Check CI length */
1306 orc = CONFREJ; /* Reject CI */
1311 * If he has no address, or if we both have his address but
1312 * disagree about it, then NAK it with our idea.
1313 * In particular, if we don't know his address, but he does,
1316 GETLONG(tl, p); /* Parse source address (his) */
1317 ciaddr1 = htonl(tl);
1318 if (ciaddr1 != wo->hisaddr
1319 && (ciaddr1 == 0 || !wo->accept_remote)) {
1321 if (!reject_if_disagree) {
1322 DECPTR(sizeof(u_int32_t), p);
1323 tl = ntohl(wo->hisaddr);
1326 } else if (ciaddr1 == 0 && wo->hisaddr == 0) {
1328 * Don't ACK an address of 0.0.0.0 - reject it instead.
1331 wo->req_addr = 0; /* don't NAK with 0.0.0.0 later */
1336 ho->hisaddr = ciaddr1;
1341 /* Microsoft primary or secondary DNS request */
1342 d = citype == CI_MS_DNS2;
1344 /* If we do not have a DNS address then we cannot send it */
1345 if (ao->dnsaddr[d] == 0 ||
1346 cilen != CILEN_ADDR) { /* Check CI length */
1347 orc = CONFREJ; /* Reject CI */
1351 if (htonl(tl) != ao->dnsaddr[d]) {
1352 DECPTR(sizeof(u_int32_t), p);
1353 tl = ntohl(ao->dnsaddr[d]);
1361 /* Microsoft primary or secondary WINS request */
1362 d = citype == CI_MS_WINS2;
1364 /* If we do not have a DNS address then we cannot send it */
1365 if (ao->winsaddr[d] == 0 ||
1366 cilen != CILEN_ADDR) { /* Check CI length */
1367 orc = CONFREJ; /* Reject CI */
1371 if (htonl(tl) != ao->winsaddr[d]) {
1372 DECPTR(sizeof(u_int32_t), p);
1373 tl = ntohl(ao->winsaddr[d]);
1379 case CI_COMPRESSTYPE:
1381 (cilen != CILEN_VJ && cilen != CILEN_COMPRESS)) {
1385 GETSHORT(cishort, p);
1387 if (!(cishort == IPCP_VJ_COMP ||
1388 (cishort == IPCP_VJ_COMP_OLD && cilen == CILEN_COMPRESS))) {
1394 ho->vj_protocol = cishort;
1395 if (cilen == CILEN_VJ) {
1396 GETCHAR(maxslotindex, p);
1397 if (maxslotindex > ao->maxslotindex) {
1399 if (!reject_if_disagree){
1401 PUTCHAR(ao->maxslotindex, p);
1405 if (cflag && !ao->cflag) {
1407 if (!reject_if_disagree){
1409 PUTCHAR(wo->cflag, p);
1412 ho->maxslotindex = maxslotindex;
1416 ho->maxslotindex = MAX_STATES - 1;
1426 if (orc == CONFACK && /* Good CI */
1427 rc != CONFACK) /* but prior CI wasnt? */
1428 continue; /* Don't send this one */
1430 if (orc == CONFNAK) { /* Nak this CI? */
1431 if (reject_if_disagree) /* Getting fed up with sending NAKs? */
1432 orc = CONFREJ; /* Get tough if so */
1434 if (rc == CONFREJ) /* Rejecting prior CI? */
1435 continue; /* Don't send this one */
1436 if (rc == CONFACK) { /* Ack'd all prior CIs? */
1437 rc = CONFNAK; /* Not anymore... */
1438 ucp = inp; /* Backup */
1443 if (orc == CONFREJ && /* Reject this CI */
1444 rc != CONFREJ) { /* but no prior ones? */
1446 ucp = inp; /* Backup */
1449 /* Need to move CI? */
1451 BCOPY(cip, ucp, cilen); /* Move it */
1453 /* Update output pointer */
1458 * If we aren't rejecting this packet, and we want to negotiate
1459 * their address, and they didn't send their address, then we
1460 * send a NAK with a CI_ADDR option appended. We assume the
1461 * input buffer is long enough that we can append the extra
1464 if (rc != CONFREJ && !ho->neg_addr &&
1465 wo->req_addr && !reject_if_disagree) {
1466 if (rc == CONFACK) {
1468 ucp = inp; /* reset pointer */
1469 wo->req_addr = 0; /* don't ask again */
1471 PUTCHAR(CI_ADDR, ucp);
1472 PUTCHAR(CILEN_ADDR, ucp);
1473 tl = ntohl(wo->hisaddr);
1477 *len = ucp - inp; /* Compute output length */
1478 IPCPDEBUG(("ipcp: returning Configure-%s", CODENAME(rc)));
1479 return (rc); /* Return final code */
1484 * ip_check_options - check that any IP-related options are OK,
1485 * and assign appropriate defaults.
1492 ipcp_options *wo = &ipcp_wantoptions[0];
1495 * Default our local IP address based on our hostname.
1496 * If local IP address already given, don't bother.
1498 if (wo->ouraddr == 0 && !disable_defaultip) {
1500 * Look up our hostname (possibly with domain name appended)
1501 * and take the first IP address as our local IP address.
1502 * If there isn't an IP address for our hostname, too bad.
1504 wo->accept_local = 1; /* don't insist on this default value */
1505 if ((hp = gethostbyname(hostname)) != NULL) {
1506 local = *(u_int32_t *)hp->h_addr;
1507 if (local != 0 && !bad_ip_adrs(local))
1508 wo->ouraddr = local;
1511 ask_for_local = wo->ouraddr != 0 || !disable_defaultip;
1516 * ip_demand_conf - configure the interface as though
1517 * IPCP were up, for use with dial-on-demand.
1523 ipcp_options *wo = &ipcp_wantoptions[u];
1525 if (wo->hisaddr == 0) {
1526 /* make up an arbitrary address for the peer */
1527 wo->hisaddr = htonl(0x0a707070 + ifunit);
1528 wo->accept_remote = 1;
1530 if (wo->ouraddr == 0) {
1531 /* make up an arbitrary address for us */
1532 wo->ouraddr = htonl(0x0a404040 + ifunit);
1533 wo->accept_local = 1;
1534 ask_for_local = 0; /* don't tell the peer this address */
1536 if (!sifaddr(u, wo->ouraddr, wo->hisaddr, GetMask(wo->ouraddr)))
1540 if (!sifnpmode(u, PPP_IP, NPMODE_QUEUE))
1542 if (wo->default_route)
1543 if (sifdefaultroute(u, wo->ouraddr, wo->hisaddr))
1544 default_route_set[u] = 1;
1546 if (sifproxyarp(u, wo->hisaddr))
1547 proxy_arp_set[u] = 1;
1549 notice("local IP address %I", wo->ouraddr);
1550 notice("remote IP address %I", wo->hisaddr);
1557 * ipcp_up - IPCP has come UP.
1559 * Configure the IP network interface appropriately and bring it up.
1566 ipcp_options *ho = &ipcp_hisoptions[f->unit];
1567 ipcp_options *go = &ipcp_gotoptions[f->unit];
1568 ipcp_options *wo = &ipcp_wantoptions[f->unit];
1570 IPCPDEBUG(("ipcp: up"));
1573 * We must have a non-zero IP address for both ends of the link.
1576 ho->hisaddr = wo->hisaddr;
1578 if (go->ouraddr == 0) {
1579 error("Could not determine local IP address");
1580 ipcp_close(f->unit, "Could not determine local IP address");
1583 if (ho->hisaddr == 0) {
1584 ho->hisaddr = htonl(0x0a404040 + ifunit);
1585 warn("Could not determine remote IP address: defaulting to %I",
1588 script_setenv("IPLOCAL", ip_ntoa(go->ouraddr), 0);
1589 script_setenv("IPREMOTE", ip_ntoa(ho->hisaddr), 1);
1591 if (usepeerdns && (go->dnsaddr[0] || go->dnsaddr[1])) {
1592 script_setenv("USEPEERDNS", "1", 0);
1594 script_setenv("DNS1", ip_ntoa(go->dnsaddr[0]), 0);
1596 script_setenv("DNS2", ip_ntoa(go->dnsaddr[1]), 0);
1597 create_resolv(go->dnsaddr[0], go->dnsaddr[1]);
1601 * Check that the peer is allowed to use the IP address it wants.
1603 if (!auth_ip_addr(f->unit, ho->hisaddr)) {
1604 error("Peer is not authorized to use remote address %I", ho->hisaddr);
1605 ipcp_close(f->unit, "Unauthorized remote IP address");
1609 /* set tcp compression */
1610 sifvjcomp(f->unit, ho->neg_vj, ho->cflag, ho->maxslotindex);
1613 * If we are doing dial-on-demand, the interface is already
1614 * configured, so we put out any saved-up packets, then set the
1615 * interface to pass IP packets.
1618 if (go->ouraddr != wo->ouraddr || ho->hisaddr != wo->hisaddr) {
1619 ipcp_clear_addrs(f->unit, wo->ouraddr, wo->hisaddr);
1620 if (go->ouraddr != wo->ouraddr) {
1621 warn("Local IP address changed to %I", go->ouraddr);
1622 script_setenv("OLDIPLOCAL", ip_ntoa(wo->ouraddr), 0);
1623 wo->ouraddr = go->ouraddr;
1625 script_unsetenv("OLDIPLOCAL");
1626 if (ho->hisaddr != wo->hisaddr) {
1627 warn("Remote IP address changed to %I", ho->hisaddr);
1628 script_setenv("OLDIPREMOTE", ip_ntoa(wo->hisaddr), 0);
1629 wo->hisaddr = ho->hisaddr;
1631 script_unsetenv("OLDIPREMOTE");
1633 /* Set the interface to the new addresses */
1634 mask = GetMask(go->ouraddr);
1635 if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
1637 warn("Interface configuration failed");
1638 ipcp_close(f->unit, "Interface configuration failed");
1642 /* assign a default route through the interface if required */
1643 if (ipcp_wantoptions[f->unit].default_route)
1644 if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr))
1645 default_route_set[f->unit] = 1;
1647 /* Make a proxy ARP entry if requested. */
1648 if (ipcp_wantoptions[f->unit].proxy_arp)
1649 if (sifproxyarp(f->unit, ho->hisaddr))
1650 proxy_arp_set[f->unit] = 1;
1653 demand_rexmit(PPP_IP);
1654 sifnpmode(f->unit, PPP_IP, NPMODE_PASS);
1658 * Set IP addresses and (if specified) netmask.
1660 mask = GetMask(go->ouraddr);
1662 #if !(defined(SVR4) && (defined(SNI) || defined(__USLC__)))
1663 if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
1665 warn("Interface configuration failed");
1666 ipcp_close(f->unit, "Interface configuration failed");
1671 /* bring the interface up for IP */
1672 if (!sifup(f->unit)) {
1674 warn("Interface failed to come up");
1675 ipcp_close(f->unit, "Interface configuration failed");
1679 #if (defined(SVR4) && (defined(SNI) || defined(__USLC__)))
1680 if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
1682 warn("Interface configuration failed");
1683 ipcp_close(f->unit, "Interface configuration failed");
1687 sifnpmode(f->unit, PPP_IP, NPMODE_PASS);
1689 /* assign a default route through the interface if required */
1690 if (ipcp_wantoptions[f->unit].default_route)
1691 if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr))
1692 default_route_set[f->unit] = 1;
1694 /* Make a proxy ARP entry if requested. */
1695 if (ipcp_wantoptions[f->unit].proxy_arp)
1696 if (sifproxyarp(f->unit, ho->hisaddr))
1697 proxy_arp_set[f->unit] = 1;
1699 ipcp_wantoptions[0].ouraddr = go->ouraddr;
1701 notice("local IP address %I", go->ouraddr);
1702 notice("remote IP address %I", ho->hisaddr);
1704 notice("primary DNS address %I", go->dnsaddr[0]);
1706 notice("secondary DNS address %I", go->dnsaddr[1]);
1709 np_up(f->unit, PPP_IP);
1716 * Execute the ip-up script, like this:
1717 * /etc/ppp/ip-up interface tty speed local-IP remote-IP
1719 if (ipcp_script_state == s_down && ipcp_script_pid == 0) {
1720 ipcp_script_state = s_up;
1721 ipcp_script(_PATH_IPUP);
1727 * ipcp_down - IPCP has gone DOWN.
1729 * Take the IP network interface down, clear its addresses
1730 * and delete routes through it.
1736 IPCPDEBUG(("ipcp: down"));
1737 /* XXX a bit IPv4-centric here, we only need to get the stats
1738 * before the interface is marked down. */
1739 update_link_stats(f->unit);
1744 np_down(f->unit, PPP_IP);
1746 sifvjcomp(f->unit, 0, 0, 0);
1749 * If we are doing dial-on-demand, set the interface
1750 * to queue up outgoing packets (for now).
1753 sifnpmode(f->unit, PPP_IP, NPMODE_QUEUE);
1755 sifnpmode(f->unit, PPP_IP, NPMODE_DROP);
1757 ipcp_clear_addrs(f->unit, ipcp_gotoptions[f->unit].ouraddr,
1758 ipcp_hisoptions[f->unit].hisaddr);
1761 /* Execute the ip-down script */
1762 if (ipcp_script_state == s_up && ipcp_script_pid == 0) {
1763 ipcp_script_state = s_down;
1764 ipcp_script(_PATH_IPDOWN);
1770 * ipcp_clear_addrs() - clear the interface addresses, routes,
1771 * proxy arp entries, etc.
1774 ipcp_clear_addrs(unit, ouraddr, hisaddr)
1776 u_int32_t ouraddr; /* local address */
1777 u_int32_t hisaddr; /* remote address */
1779 if (proxy_arp_set[unit]) {
1780 cifproxyarp(unit, hisaddr);
1781 proxy_arp_set[unit] = 0;
1783 if (default_route_set[unit]) {
1784 cifdefaultroute(unit, ouraddr, hisaddr);
1785 default_route_set[unit] = 0;
1787 cifaddr(unit, ouraddr, hisaddr);
1792 * ipcp_finished - possibly shut down the lower layers.
1798 np_finished(f->unit, PPP_IP);
1803 * ipcp_script_done - called when the ip-up or ip-down script
1807 ipcp_script_done(arg)
1810 ipcp_script_pid = 0;
1811 switch (ipcp_script_state) {
1813 if (ipcp_fsm[0].state != OPENED) {
1814 ipcp_script_state = s_down;
1815 ipcp_script(_PATH_IPDOWN);
1819 if (ipcp_fsm[0].state == OPENED) {
1820 ipcp_script_state = s_up;
1821 ipcp_script(_PATH_IPUP);
1829 * ipcp_script - Execute a script with arguments
1830 * interface-name tty-name speed local-IP remote-IP.
1836 char strspeed[32], strlocal[32], strremote[32];
1839 slprintf(strspeed, sizeof(strspeed), "%d", baud_rate);
1840 slprintf(strlocal, sizeof(strlocal), "%I", ipcp_gotoptions[0].ouraddr);
1841 slprintf(strremote, sizeof(strremote), "%I", ipcp_hisoptions[0].hisaddr);
1848 argv[5] = strremote;
1851 ipcp_script_pid = run_program(script, argv, 0, ipcp_script_done, NULL);
1855 * create_resolv - create the replacement resolv.conf file
1858 create_resolv(peerdns1, peerdns2)
1859 u_int32_t peerdns1, peerdns2;
1863 f = fopen(_PATH_RESOLV, "w");
1865 error("Failed to create %s: %m", _PATH_RESOLV);
1870 fprintf(f, "nameserver %s\n", ip_ntoa(peerdns1));
1873 fprintf(f, "nameserver %s\n", ip_ntoa(peerdns2));
1876 error("Write failed to %s: %m", _PATH_RESOLV);
1882 * ipcp_printpkt - print the contents of an IPCP packet.
1884 static char *ipcp_codenames[] = {
1885 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1886 "TermReq", "TermAck", "CodeRej"
1890 ipcp_printpkt(p, plen, printer, arg)
1893 void (*printer) __P((void *, char *, ...));
1896 int code, id, len, olen;
1897 u_char *pstart, *optend;
1901 if (plen < HEADERLEN)
1907 if (len < HEADERLEN || len > plen)
1910 if (code >= 1 && code <= sizeof(ipcp_codenames) / sizeof(char *))
1911 printer(arg, " %s", ipcp_codenames[code-1]);
1913 printer(arg, " code=0x%x", code);
1914 printer(arg, " id=0x%x", id);
1921 /* print option list */
1926 if (olen < 2 || olen > len) {
1934 if (olen == CILEN_ADDRS) {
1937 printer(arg, "addrs %I", htonl(cilong));
1939 printer(arg, " %I", htonl(cilong));
1942 case CI_COMPRESSTYPE:
1943 if (olen >= CILEN_COMPRESS) {
1945 GETSHORT(cishort, p);
1946 printer(arg, "compress ");
1951 case IPCP_VJ_COMP_OLD:
1952 printer(arg, "old-VJ");
1955 printer(arg, "0x%x", cishort);
1960 if (olen == CILEN_ADDR) {
1963 printer(arg, "addr %I", htonl(cilong));
1970 printer(arg, "ms-dns%d %I", code - CI_MS_DNS1 + 1,
1977 printer(arg, "ms-wins %I", htonl(cilong));
1980 while (p < optend) {
1982 printer(arg, " %.2x", code);
1990 if (len > 0 && *p >= ' ' && *p < 0x7f) {
1992 print_string((char *)p, len, printer, arg);
1999 /* print the rest of the bytes in the packet */
2000 for (; len > 0; --len) {
2002 printer(arg, " %.2x", code);
2009 * ip_active_pkt - see if this IP packet is worth bringing the link up for.
2010 * We don't bring the link up for IP fragments or for TCP FIN packets
2013 #define IP_HDRLEN 20 /* bytes */
2014 #define IP_OFFMASK 0x1fff
2015 #define IPPROTO_TCP 6
2016 #define TCP_HDRLEN 20
2020 * We use these macros because the IP header may be at an odd address,
2021 * and some compilers might use word loads to get th_off or ip_hl.
2024 #define net_short(x) (((x)[0] << 8) + (x)[1])
2025 #define get_iphl(x) (((unsigned char *)(x))[0] & 0xF)
2026 #define get_ipoff(x) net_short((unsigned char *)(x) + 6)
2027 #define get_ipproto(x) (((unsigned char *)(x))[9])
2028 #define get_tcpoff(x) (((unsigned char *)(x))[12] >> 4)
2029 #define get_tcpflags(x) (((unsigned char *)(x))[13])
2032 ip_active_pkt(pkt, len)
2041 if (len < IP_HDRLEN)
2043 if ((get_ipoff(pkt) & IP_OFFMASK) != 0)
2045 if (get_ipproto(pkt) != IPPROTO_TCP)
2047 hlen = get_iphl(pkt) * 4;
2048 if (len < hlen + TCP_HDRLEN)
2051 if ((get_tcpflags(tcp) & TH_FIN) != 0 && len == hlen + get_tcpoff(tcp) * 4)