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.61 2002/09/09 04:19:57 carlsonj 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;
62 /* Notifiers for when IPCP goes up and down */
63 struct notifier *ip_up_notifier = NULL;
64 struct notifier *ip_down_notifier = NULL;
67 static int default_route_set[NUM_PPP]; /* Have set up a default route */
68 static int proxy_arp_set[NUM_PPP]; /* Have created proxy arp entry */
69 static bool usepeerdns; /* Ask peer for DNS addrs */
70 static int ipcp_is_up; /* have called np_up() */
71 static bool ask_for_local; /* request our address from peer */
72 static char vj_value[8]; /* string form of vj option value */
73 static char netmask_str[20]; /* string form of netmask value */
76 * Callbacks for fsm code. (CI = Configuration Information)
78 static void ipcp_resetci __P((fsm *)); /* Reset our CI */
79 static int ipcp_cilen __P((fsm *)); /* Return length of our CI */
80 static void ipcp_addci __P((fsm *, u_char *, int *)); /* Add our CI */
81 static int ipcp_ackci __P((fsm *, u_char *, int)); /* Peer ack'd our CI */
82 static int ipcp_nakci __P((fsm *, u_char *, int)); /* Peer nak'd our CI */
83 static int ipcp_rejci __P((fsm *, u_char *, int)); /* Peer rej'd our CI */
84 static int ipcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv CI */
85 static void ipcp_up __P((fsm *)); /* We're UP */
86 static void ipcp_down __P((fsm *)); /* We're DOWN */
87 static void ipcp_finished __P((fsm *)); /* Don't need lower layer */
89 fsm ipcp_fsm[NUM_PPP]; /* IPCP fsm structure */
91 static fsm_callbacks ipcp_callbacks = { /* IPCP callback routines */
92 ipcp_resetci, /* Reset our Configuration Information */
93 ipcp_cilen, /* Length of our Configuration Information */
94 ipcp_addci, /* Add our Configuration Information */
95 ipcp_ackci, /* ACK our Configuration Information */
96 ipcp_nakci, /* NAK our Configuration Information */
97 ipcp_rejci, /* Reject our Configuration Information */
98 ipcp_reqci, /* Request peer's Configuration Information */
99 ipcp_up, /* Called when fsm reaches OPENED state */
100 ipcp_down, /* Called when fsm leaves OPENED state */
101 NULL, /* Called when we want the lower layer up */
102 ipcp_finished, /* Called when we want the lower layer down */
103 NULL, /* Called when Protocol-Reject received */
104 NULL, /* Retransmission is necessary */
105 NULL, /* Called to handle protocol-specific codes */
106 "IPCP" /* String name of protocol */
110 * Command-line options.
112 static int setvjslots __P((char **));
113 static int setdnsaddr __P((char **));
114 static int setwinsaddr __P((char **));
115 static int setnetmask __P((char **));
116 int setipaddr __P((char *, char **, int));
117 static void printipaddr __P((option_t *, void (*)(void *, char *,...),void *));
119 static option_t ipcp_option_list[] = {
120 { "noip", o_bool, &ipcp_protent.enabled_flag,
121 "Disable IP and IPCP" },
122 { "-ip", o_bool, &ipcp_protent.enabled_flag,
123 "Disable IP and IPCP", OPT_ALIAS },
125 { "novj", o_bool, &ipcp_wantoptions[0].neg_vj,
126 "Disable VJ compression", OPT_A2CLR, &ipcp_allowoptions[0].neg_vj },
127 { "-vj", o_bool, &ipcp_wantoptions[0].neg_vj,
128 "Disable VJ compression", OPT_ALIAS | OPT_A2CLR,
129 &ipcp_allowoptions[0].neg_vj },
131 { "novjccomp", o_bool, &ipcp_wantoptions[0].cflag,
132 "Disable VJ connection-ID compression", OPT_A2CLR,
133 &ipcp_allowoptions[0].cflag },
134 { "-vjccomp", o_bool, &ipcp_wantoptions[0].cflag,
135 "Disable VJ connection-ID compression", OPT_ALIAS | OPT_A2CLR,
136 &ipcp_allowoptions[0].cflag },
138 { "vj-max-slots", o_special, (void *)setvjslots,
139 "Set maximum VJ header slots",
140 OPT_PRIO | OPT_A2STRVAL | OPT_STATIC, vj_value },
142 { "ipcp-accept-local", o_bool, &ipcp_wantoptions[0].accept_local,
143 "Accept peer's address for us", 1 },
144 { "ipcp-accept-remote", o_bool, &ipcp_wantoptions[0].accept_remote,
145 "Accept peer's address for it", 1 },
147 { "ipparam", o_string, &ipparam,
148 "Set ip script parameter", OPT_PRIO },
150 { "noipdefault", o_bool, &disable_defaultip,
151 "Don't use name for default IP adrs", 1 },
153 { "ms-dns", 1, (void *)setdnsaddr,
154 "DNS address for the peer's use" },
155 { "ms-wins", 1, (void *)setwinsaddr,
156 "Nameserver for SMB over TCP/IP for peer" },
158 { "ipcp-restart", o_int, &ipcp_fsm[0].timeouttime,
159 "Set timeout for IPCP", OPT_PRIO },
160 { "ipcp-max-terminate", o_int, &ipcp_fsm[0].maxtermtransmits,
161 "Set max #xmits for term-reqs", OPT_PRIO },
162 { "ipcp-max-configure", o_int, &ipcp_fsm[0].maxconfreqtransmits,
163 "Set max #xmits for conf-reqs", OPT_PRIO },
164 { "ipcp-max-failure", o_int, &ipcp_fsm[0].maxnakloops,
165 "Set max #conf-naks for IPCP", OPT_PRIO },
167 { "defaultroute", o_bool, &ipcp_wantoptions[0].default_route,
168 "Add default route", OPT_ENABLE|1, &ipcp_allowoptions[0].default_route },
169 { "nodefaultroute", o_bool, &ipcp_allowoptions[0].default_route,
170 "disable defaultroute option", OPT_A2CLR,
171 &ipcp_wantoptions[0].default_route },
172 { "-defaultroute", o_bool, &ipcp_allowoptions[0].default_route,
173 "disable defaultroute option", OPT_ALIAS | OPT_A2CLR,
174 &ipcp_wantoptions[0].default_route },
176 { "proxyarp", o_bool, &ipcp_wantoptions[0].proxy_arp,
177 "Add proxy ARP entry", OPT_ENABLE|1, &ipcp_allowoptions[0].proxy_arp },
178 { "noproxyarp", o_bool, &ipcp_allowoptions[0].proxy_arp,
179 "disable proxyarp option", OPT_A2CLR,
180 &ipcp_wantoptions[0].proxy_arp },
181 { "-proxyarp", o_bool, &ipcp_allowoptions[0].proxy_arp,
182 "disable proxyarp option", OPT_ALIAS | OPT_A2CLR,
183 &ipcp_wantoptions[0].proxy_arp },
185 { "usepeerdns", o_bool, &usepeerdns,
186 "Ask peer for DNS address(es)", 1 },
188 { "netmask", o_special, (void *)setnetmask,
189 "set netmask", OPT_PRIO | OPT_A2STRVAL | OPT_STATIC, netmask_str },
191 { "ipcp-no-addresses", o_bool, &ipcp_wantoptions[0].old_addrs,
192 "Disable old-style IP-Addresses usage", OPT_A2CLR,
193 &ipcp_allowoptions[0].old_addrs },
194 { "ipcp-no-address", o_bool, &ipcp_wantoptions[0].neg_addr,
195 "Disable IP-Address usage", OPT_A2CLR,
196 &ipcp_allowoptions[0].neg_addr },
198 { "IP addresses", o_wild, (void *) &setipaddr,
199 "set local and remote IP addresses",
200 OPT_NOARG | OPT_A2PRINTER, (void *) &printipaddr },
206 * Protocol entry points from main code.
208 static void ipcp_init __P((int));
209 static void ipcp_open __P((int));
210 static void ipcp_close __P((int, char *));
211 static void ipcp_lowerup __P((int));
212 static void ipcp_lowerdown __P((int));
213 static void ipcp_input __P((int, u_char *, int));
214 static void ipcp_protrej __P((int));
215 static int ipcp_printpkt __P((u_char *, int,
216 void (*) __P((void *, char *, ...)), void *));
217 static void ip_check_options __P((void));
218 static int ip_demand_conf __P((int));
219 static int ip_active_pkt __P((u_char *, int));
220 static void create_resolv __P((u_int32_t, u_int32_t));
222 struct protent ipcp_protent = {
242 static void ipcp_clear_addrs __P((int, u_int32_t, u_int32_t));
243 static void ipcp_script __P((char *)); /* Run an up/down script */
244 static void ipcp_script_done __P((void *));
247 * Lengths of configuration options.
250 #define CILEN_COMPRESS 4 /* min length for compression protocol opt. */
251 #define CILEN_VJ 6 /* length for RFC1332 Van-Jacobson opt. */
252 #define CILEN_ADDR 6 /* new-style single address option */
253 #define CILEN_ADDRS 10 /* old-style dual address option */
256 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
257 (x) == CONFNAK ? "NAK" : "REJ")
260 * This state variable is used to ensure that we don't
261 * run an ipcp-up/down script while one is already running.
263 static enum script_state {
267 static pid_t ipcp_script_pid;
270 * Make a string representation of a network IP address.
278 slprintf(b, sizeof(b), "%I", ipaddr);
287 * setvjslots - set maximum number of connection slots for VJ compression
295 if (!int_option(*argv, &value))
297 if (value < 2 || value > 16) {
298 option_error("vj-max-slots value must be between 2 and 16");
301 ipcp_wantoptions [0].maxslotindex =
302 ipcp_allowoptions[0].maxslotindex = value - 1;
303 slprintf(vj_value, sizeof(vj_value), "%d", value);
308 * setdnsaddr - set the dns address(es)
317 dns = inet_addr(*argv);
318 if (dns == (u_int32_t) -1) {
319 if ((hp = gethostbyname(*argv)) == NULL) {
320 option_error("invalid address parameter '%s' for ms-dns option",
324 dns = *(u_int32_t *)hp->h_addr;
327 /* We take the last 2 values given, the 2nd-last as the primary
328 and the last as the secondary. If only one is given it
329 becomes both primary and secondary. */
330 if (ipcp_allowoptions[0].dnsaddr[1] == 0)
331 ipcp_allowoptions[0].dnsaddr[0] = dns;
333 ipcp_allowoptions[0].dnsaddr[0] = ipcp_allowoptions[0].dnsaddr[1];
335 /* always set the secondary address value. */
336 ipcp_allowoptions[0].dnsaddr[1] = dns;
342 * setwinsaddr - set the wins address(es)
343 * This is primrarly used with the Samba package under UNIX or for pointing
344 * the caller to the existing WINS server on a Windows NT platform.
353 wins = inet_addr(*argv);
354 if (wins == (u_int32_t) -1) {
355 if ((hp = gethostbyname(*argv)) == NULL) {
356 option_error("invalid address parameter '%s' for ms-wins option",
360 wins = *(u_int32_t *)hp->h_addr;
363 /* We take the last 2 values given, the 2nd-last as the primary
364 and the last as the secondary. If only one is given it
365 becomes both primary and secondary. */
366 if (ipcp_allowoptions[0].winsaddr[1] == 0)
367 ipcp_allowoptions[0].winsaddr[0] = wins;
369 ipcp_allowoptions[0].winsaddr[0] = ipcp_allowoptions[0].winsaddr[1];
371 /* always set the secondary address value. */
372 ipcp_allowoptions[0].winsaddr[1] = wins;
378 * setipaddr - Set the IP address
379 * If doit is 0, the call is to check whether this option is
380 * potentially an IP address specification.
381 * Not static so that plugins can call it to set the addresses
384 setipaddr(arg, argv, doit)
391 u_int32_t local, remote;
392 ipcp_options *wo = &ipcp_wantoptions[0];
393 static int prio_local = 0, prio_remote = 0;
396 * IP address pair separated by ":".
398 if ((colon = strchr(arg, ':')) == NULL)
404 * If colon first character, then no local addr.
406 if (colon != arg && option_priority >= prio_local) {
408 if ((local = inet_addr(arg)) == (u_int32_t) -1) {
409 if ((hp = gethostbyname(arg)) == NULL) {
410 option_error("unknown host: %s", arg);
413 local = *(u_int32_t *)hp->h_addr;
415 if (bad_ip_adrs(local)) {
416 option_error("bad local IP address %s", ip_ntoa(local));
422 prio_local = option_priority;
426 * If colon last character, then no remote addr.
428 if (*++colon != '\0' && option_priority >= prio_remote) {
429 if ((remote = inet_addr(colon)) == (u_int32_t) -1) {
430 if ((hp = gethostbyname(colon)) == NULL) {
431 option_error("unknown host: %s", colon);
434 remote = *(u_int32_t *)hp->h_addr;
435 if (remote_name[0] == 0)
436 strlcpy(remote_name, colon, sizeof(remote_name));
438 if (bad_ip_adrs(remote)) {
439 option_error("bad remote IP address %s", ip_ntoa(remote));
443 wo->hisaddr = remote;
444 prio_remote = option_priority;
451 printipaddr(opt, printer, arg)
453 void (*printer) __P((void *, char *, ...));
456 ipcp_options *wo = &ipcp_wantoptions[0];
458 if (wo->ouraddr != 0)
459 printer(arg, "%I", wo->ouraddr);
461 if (wo->hisaddr != 0)
462 printer(arg, "%I", wo->hisaddr);
466 * setnetmask - set the netmask to be used on the interface.
477 * Unfortunately, if we use inet_addr, we can't tell whether
478 * a result of all 1s is an error or a valid 255.255.255.255.
481 n = parse_dotted_ip(p, &mask);
485 if (n == 0 || p[n] != 0 || (netmask & ~mask) != 0) {
486 option_error("invalid netmask value '%s'", *argv);
491 slprintf(netmask_str, sizeof(netmask_str), "%I", mask);
497 parse_dotted_ip(p, vp)
507 b = strtoul(p, &endp, 0);
513 /* accept e.g. 0xffffff00 */
531 * ipcp_init - Initialize IPCP.
537 fsm *f = &ipcp_fsm[unit];
538 ipcp_options *wo = &ipcp_wantoptions[unit];
539 ipcp_options *ao = &ipcp_allowoptions[unit];
542 f->protocol = PPP_IPCP;
543 f->callbacks = &ipcp_callbacks;
544 fsm_init(&ipcp_fsm[unit]);
546 memset(wo, 0, sizeof(*wo));
547 memset(ao, 0, sizeof(*ao));
549 wo->neg_addr = wo->old_addrs = 1;
551 wo->vj_protocol = IPCP_VJ_COMP;
552 wo->maxslotindex = MAX_STATES - 1; /* really max index */
556 /* max slots and slot-id compression are currently hardwired in */
557 /* ppp_if.c to 16 and 1, this needs to be changed (among other */
560 ao->neg_addr = ao->old_addrs = 1;
562 ao->maxslotindex = MAX_STATES - 1;
566 * XXX These control whether the user may use the proxyarp
567 * and defaultroute options.
570 ao->default_route = 1;
575 * ipcp_open - IPCP is allowed to come up.
581 fsm_open(&ipcp_fsm[unit]);
586 * ipcp_close - Take IPCP down.
589 ipcp_close(unit, reason)
593 fsm_close(&ipcp_fsm[unit], reason);
598 * ipcp_lowerup - The lower layer is up.
604 fsm_lowerup(&ipcp_fsm[unit]);
609 * ipcp_lowerdown - The lower layer is down.
615 fsm_lowerdown(&ipcp_fsm[unit]);
620 * ipcp_input - Input IPCP packet.
623 ipcp_input(unit, p, len)
628 fsm_input(&ipcp_fsm[unit], p, len);
633 * ipcp_protrej - A Protocol-Reject was received for IPCP.
635 * Pretend the lower layer went down, so we shut up.
641 fsm_lowerdown(&ipcp_fsm[unit]);
646 * ipcp_resetci - Reset our CI.
647 * Called by fsm_sconfreq, Send Configure Request.
653 ipcp_options *wo = &ipcp_wantoptions[f->unit];
654 ipcp_options *go = &ipcp_gotoptions[f->unit];
655 ipcp_options *ao = &ipcp_allowoptions[f->unit];
657 wo->req_addr = (wo->neg_addr || wo->old_addrs) &&
658 (ao->neg_addr || ao->old_addrs);
659 if (wo->ouraddr == 0)
660 wo->accept_local = 1;
661 if (wo->hisaddr == 0)
662 wo->accept_remote = 1;
663 wo->req_dns1 = usepeerdns; /* Request DNS addresses from the peer */
664 wo->req_dns2 = usepeerdns;
668 if (ip_choose_hook) {
669 ip_choose_hook(&wo->hisaddr);
671 wo->accept_remote = 0;
678 * ipcp_cilen - Return length of our CI.
679 * Called by fsm_sconfreq, Send Configure Request.
685 ipcp_options *go = &ipcp_gotoptions[f->unit];
686 ipcp_options *wo = &ipcp_wantoptions[f->unit];
687 ipcp_options *ho = &ipcp_hisoptions[f->unit];
689 #define LENCIADDRS(neg) (neg ? CILEN_ADDRS : 0)
690 #define LENCIVJ(neg, old) (neg ? (old? CILEN_COMPRESS : CILEN_VJ) : 0)
691 #define LENCIADDR(neg) (neg ? CILEN_ADDR : 0)
692 #define LENCIDNS(neg) (neg ? (CILEN_ADDR) : 0)
695 * First see if we want to change our options to the old
696 * forms because we have received old forms from the peer.
698 if ((wo->neg_addr || wo->old_addrs) && !go->neg_addr && !go->old_addrs) {
699 /* use the old style of address negotiation */
702 if (wo->neg_vj && !go->neg_vj && !go->old_vj) {
703 /* try an older style of VJ negotiation */
704 /* use the old style only if the peer did */
705 if (ho->neg_vj && ho->old_vj) {
708 go->vj_protocol = ho->vj_protocol;
712 return (LENCIADDRS(!go->neg_addr && go->old_addrs) +
713 LENCIVJ(go->neg_vj, go->old_vj) +
714 LENCIADDR(go->neg_addr) +
715 LENCIDNS(go->req_dns1) +
716 LENCIDNS(go->req_dns2)) ;
721 * ipcp_addci - Add our desired CIs to a packet.
722 * Called by fsm_sconfreq, Send Configure Request.
725 ipcp_addci(f, ucp, lenp)
730 ipcp_options *go = &ipcp_gotoptions[f->unit];
733 #define ADDCIADDRS(opt, neg, val1, val2) \
735 if (len >= CILEN_ADDRS) { \
738 PUTCHAR(CILEN_ADDRS, ucp); \
743 len -= CILEN_ADDRS; \
748 #define ADDCIVJ(opt, neg, val, old, maxslotindex, cflag) \
750 int vjlen = old? CILEN_COMPRESS : CILEN_VJ; \
751 if (len >= vjlen) { \
753 PUTCHAR(vjlen, ucp); \
754 PUTSHORT(val, ucp); \
756 PUTCHAR(maxslotindex, ucp); \
757 PUTCHAR(cflag, ucp); \
764 #define ADDCIADDR(opt, neg, val) \
766 if (len >= CILEN_ADDR) { \
769 PUTCHAR(CILEN_ADDR, ucp); \
777 #define ADDCIDNS(opt, neg, addr) \
779 if (len >= CILEN_ADDR) { \
782 PUTCHAR(CILEN_ADDR, ucp); \
790 ADDCIADDRS(CI_ADDRS, !go->neg_addr && go->old_addrs, go->ouraddr,
793 ADDCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol, go->old_vj,
794 go->maxslotindex, go->cflag);
796 ADDCIADDR(CI_ADDR, go->neg_addr, go->ouraddr);
798 ADDCIDNS(CI_MS_DNS1, go->req_dns1, go->dnsaddr[0]);
800 ADDCIDNS(CI_MS_DNS2, go->req_dns2, go->dnsaddr[1]);
807 * ipcp_ackci - Ack our CIs.
808 * Called by fsm_rconfack, Receive Configure ACK.
815 ipcp_ackci(f, p, len)
820 ipcp_options *go = &ipcp_gotoptions[f->unit];
821 u_short cilen, citype, cishort;
823 u_char cimaxslotindex, cicflag;
826 * CIs must be in exactly the same order that we sent...
827 * Check packet length and CI length at each step.
828 * If we find any deviations, then this packet is bad.
831 #define ACKCIADDRS(opt, neg, val1, val2) \
834 if ((len -= CILEN_ADDRS) < 0) \
836 GETCHAR(citype, p); \
838 if (cilen != CILEN_ADDRS || \
843 if (val1 != cilong) \
847 if (val2 != cilong) \
851 #define ACKCIVJ(opt, neg, val, old, maxslotindex, cflag) \
853 int vjlen = old? CILEN_COMPRESS : CILEN_VJ; \
854 if ((len -= vjlen) < 0) \
856 GETCHAR(citype, p); \
858 if (cilen != vjlen || \
861 GETSHORT(cishort, p); \
862 if (cishort != val) \
865 GETCHAR(cimaxslotindex, p); \
866 if (cimaxslotindex != maxslotindex) \
868 GETCHAR(cicflag, p); \
869 if (cicflag != cflag) \
874 #define ACKCIADDR(opt, neg, val) \
877 if ((len -= CILEN_ADDR) < 0) \
879 GETCHAR(citype, p); \
881 if (cilen != CILEN_ADDR || \
890 #define ACKCIDNS(opt, neg, addr) \
893 if ((len -= CILEN_ADDR) < 0) \
895 GETCHAR(citype, p); \
897 if (cilen != CILEN_ADDR || citype != opt) \
901 if (addr != cilong) \
905 ACKCIADDRS(CI_ADDRS, !go->neg_addr && go->old_addrs, go->ouraddr,
908 ACKCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol, go->old_vj,
909 go->maxslotindex, go->cflag);
911 ACKCIADDR(CI_ADDR, go->neg_addr, go->ouraddr);
913 ACKCIDNS(CI_MS_DNS1, go->req_dns1, go->dnsaddr[0]);
915 ACKCIDNS(CI_MS_DNS2, go->req_dns2, go->dnsaddr[1]);
918 * If there are any remaining CIs, then this packet is bad.
925 IPCPDEBUG(("ipcp_ackci: received bad Ack!"));
930 * ipcp_nakci - Peer has sent a NAK for some of our CIs.
931 * This should not modify any state if the Nak is bad
932 * or if IPCP is in the OPENED state.
933 * Calback from fsm_rconfnakrej - Receive Configure-Nak or Configure-Reject.
940 ipcp_nakci(f, p, len)
945 ipcp_options *go = &ipcp_gotoptions[f->unit];
946 u_char cimaxslotindex, cicflag;
947 u_char citype, cilen, *next;
949 u_int32_t ciaddr1, ciaddr2, l, cidnsaddr;
950 ipcp_options no; /* options we've seen Naks for */
951 ipcp_options try; /* options to request next time */
953 BZERO(&no, sizeof(no));
957 * Any Nak'd CIs must be in exactly the same order that we sent.
958 * Check packet length and CI length at each step.
959 * If we find any deviations, then this packet is bad.
961 #define NAKCIADDRS(opt, neg, code) \
963 (cilen = p[1]) == CILEN_ADDRS && \
969 ciaddr1 = htonl(l); \
971 ciaddr2 = htonl(l); \
976 #define NAKCIVJ(opt, neg, code) \
978 ((cilen = p[1]) == CILEN_COMPRESS || cilen == CILEN_VJ) && \
983 GETSHORT(cishort, p); \
988 #define NAKCIADDR(opt, neg, code) \
990 (cilen = p[1]) == CILEN_ADDR && \
996 ciaddr1 = htonl(l); \
1001 #define NAKCIDNS(opt, neg, code) \
1003 ((cilen = p[1]) == CILEN_ADDR) && \
1009 cidnsaddr = htonl(l); \
1015 * Accept the peer's idea of {our,his} address, if different
1016 * from our idea, only if the accept_{local,remote} flag is set.
1018 NAKCIADDRS(CI_ADDRS, !go->neg_addr && go->old_addrs,
1019 if (go->accept_local && ciaddr1) { /* Do we know our address? */
1020 try.ouraddr = ciaddr1;
1022 if (go->accept_remote && ciaddr2) { /* Does he know his? */
1023 try.hisaddr = ciaddr2;
1028 * Accept the peer's value of maxslotindex provided that it
1029 * is less than what we asked for. Turn off slot-ID compression
1030 * if the peer wants. Send old-style compress-type option if
1033 NAKCIVJ(CI_COMPRESSTYPE, neg_vj,
1034 if (cilen == CILEN_VJ) {
1035 GETCHAR(cimaxslotindex, p);
1036 GETCHAR(cicflag, p);
1037 if (cishort == IPCP_VJ_COMP) {
1039 if (cimaxslotindex < go->maxslotindex)
1040 try.maxslotindex = cimaxslotindex;
1047 if (cishort == IPCP_VJ_COMP || cishort == IPCP_VJ_COMP_OLD) {
1049 try.vj_protocol = cishort;
1056 NAKCIADDR(CI_ADDR, neg_addr,
1057 if (go->accept_local && ciaddr1) { /* Do we know our address? */
1058 try.ouraddr = ciaddr1;
1062 NAKCIDNS(CI_MS_DNS1, req_dns1,
1063 try.dnsaddr[0] = cidnsaddr;
1066 NAKCIDNS(CI_MS_DNS2, req_dns2,
1067 try.dnsaddr[1] = cidnsaddr;
1071 * There may be remaining CIs, if the peer is requesting negotiation
1072 * on an option that we didn't include in our request packet.
1073 * If they want to negotiate about IP addresses, we comply.
1074 * If they want us to ask for compression, we refuse.
1076 while (len > CILEN_VOID) {
1079 if( (len -= cilen) < 0 )
1081 next = p + cilen - 2;
1084 case CI_COMPRESSTYPE:
1085 if (go->neg_vj || no.neg_vj ||
1086 (cilen != CILEN_VJ && cilen != CILEN_COMPRESS))
1091 if ((!go->neg_addr && go->old_addrs) || no.old_addrs
1092 || cilen != CILEN_ADDRS)
1097 if (ciaddr1 && go->accept_local)
1098 try.ouraddr = ciaddr1;
1101 if (ciaddr2 && go->accept_remote)
1102 try.hisaddr = ciaddr2;
1106 if (go->neg_addr || no.neg_addr || cilen != CILEN_ADDR)
1111 if (ciaddr1 && go->accept_local)
1112 try.ouraddr = ciaddr1;
1113 if (try.ouraddr != 0)
1122 * OK, the Nak is good. Now we can update state.
1123 * If there are any remaining options, we ignore them.
1125 if (f->state != OPENED)
1131 IPCPDEBUG(("ipcp_nakci: received bad Nak!"));
1137 * ipcp_rejci - Reject some of our CIs.
1138 * Callback from fsm_rconfnakrej.
1141 ipcp_rejci(f, p, len)
1146 ipcp_options *go = &ipcp_gotoptions[f->unit];
1147 u_char cimaxslotindex, ciflag, cilen;
1150 ipcp_options try; /* options to request next time */
1154 * Any Rejected CIs must be in exactly the same order that we sent.
1155 * Check packet length and CI length at each step.
1156 * If we find any deviations, then this packet is bad.
1158 #define REJCIADDRS(opt, neg, val1, val2) \
1160 (cilen = p[1]) == CILEN_ADDRS && \
1167 cilong = htonl(l); \
1168 /* Check rejected value. */ \
1169 if (cilong != val1) \
1172 cilong = htonl(l); \
1173 /* Check rejected value. */ \
1174 if (cilong != val2) \
1176 try.old_addrs = 0; \
1179 #define REJCIVJ(opt, neg, val, old, maxslot, cflag) \
1181 p[1] == (old? CILEN_COMPRESS : CILEN_VJ) && \
1186 GETSHORT(cishort, p); \
1187 /* Check rejected value. */ \
1188 if (cishort != val) \
1191 GETCHAR(cimaxslotindex, p); \
1192 if (cimaxslotindex != maxslot) \
1194 GETCHAR(ciflag, p); \
1195 if (ciflag != cflag) \
1201 #define REJCIADDR(opt, neg, val) \
1203 (cilen = p[1]) == CILEN_ADDR && \
1210 cilong = htonl(l); \
1211 /* Check rejected value. */ \
1212 if (cilong != val) \
1217 #define REJCIDNS(opt, neg, dnsaddr) \
1219 ((cilen = p[1]) == CILEN_ADDR) && \
1226 cilong = htonl(l); \
1227 /* Check rejected value. */ \
1228 if (cilong != dnsaddr) \
1234 REJCIADDRS(CI_ADDRS, !go->neg_addr && go->old_addrs,
1235 go->ouraddr, go->hisaddr);
1237 REJCIVJ(CI_COMPRESSTYPE, neg_vj, go->vj_protocol, go->old_vj,
1238 go->maxslotindex, go->cflag);
1240 REJCIADDR(CI_ADDR, neg_addr, go->ouraddr);
1242 REJCIDNS(CI_MS_DNS1, req_dns1, go->dnsaddr[0]);
1244 REJCIDNS(CI_MS_DNS2, req_dns2, go->dnsaddr[1]);
1247 * If there are any remaining CIs, then this packet is bad.
1252 * Now we can update state.
1254 if (f->state != OPENED)
1259 IPCPDEBUG(("ipcp_rejci: received bad Reject!"));
1265 * ipcp_reqci - Check the peer's requested CIs and send appropriate response.
1266 * Callback from fsm_rconfreq, Receive Configure Request
1268 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
1269 * appropriately. If reject_if_disagree is non-zero, doesn't return
1270 * CONFNAK; returns CONFREJ if it can't return CONFACK.
1273 ipcp_reqci(f, inp, len, reject_if_disagree)
1275 u_char *inp; /* Requested CIs */
1276 int *len; /* Length of requested CIs */
1277 int reject_if_disagree;
1279 ipcp_options *wo = &ipcp_wantoptions[f->unit];
1280 ipcp_options *ho = &ipcp_hisoptions[f->unit];
1281 ipcp_options *ao = &ipcp_allowoptions[f->unit];
1282 u_char *cip, *next; /* Pointer to current and next CIs */
1283 u_short cilen, citype; /* Parsed len, type */
1284 u_short cishort; /* Parsed short value */
1285 u_int32_t tl, ciaddr1, ciaddr2;/* Parsed address values */
1286 int rc = CONFACK; /* Final packet return code */
1287 int orc; /* Individual option return code */
1288 u_char *p; /* Pointer to next char to parse */
1289 u_char *ucp = inp; /* Pointer to current output char */
1290 int l = *len; /* Length left */
1291 u_char maxslotindex, cflag;
1295 * Reset all his options.
1297 BZERO(ho, sizeof(*ho));
1300 * Process all his options.
1304 orc = CONFACK; /* Assume success */
1305 cip = p = next; /* Remember begining of CI */
1306 if (l < 2 || /* Not enough data for CI header or */
1307 p[1] < 2 || /* CI length too small or */
1308 p[1] > l) { /* CI length too big? */
1309 IPCPDEBUG(("ipcp_reqci: bad CI length!"));
1310 orc = CONFREJ; /* Reject bad CI */
1311 cilen = l; /* Reject till end of packet */
1312 l = 0; /* Don't loop again */
1315 GETCHAR(citype, p); /* Parse CI type */
1316 GETCHAR(cilen, p); /* Parse CI length */
1317 l -= cilen; /* Adjust remaining length */
1318 next += cilen; /* Step to next CI */
1320 switch (citype) { /* Check CI type */
1322 if (!ao->old_addrs || ho->neg_addr ||
1323 cilen != CILEN_ADDRS) { /* Check CI length */
1324 orc = CONFREJ; /* Reject CI */
1329 * If he has no address, or if we both have his address but
1330 * disagree about it, then NAK it with our idea.
1331 * In particular, if we don't know his address, but he does,
1334 GETLONG(tl, p); /* Parse source address (his) */
1335 ciaddr1 = htonl(tl);
1336 if (ciaddr1 != wo->hisaddr
1337 && (ciaddr1 == 0 || !wo->accept_remote)) {
1339 if (!reject_if_disagree) {
1340 DECPTR(sizeof(u_int32_t), p);
1341 tl = ntohl(wo->hisaddr);
1344 } else if (ciaddr1 == 0 && wo->hisaddr == 0) {
1346 * If neither we nor he knows his address, reject the option.
1349 wo->req_addr = 0; /* don't NAK with 0.0.0.0 later */
1354 * If he doesn't know our address, or if we both have our address
1355 * but disagree about it, then NAK it with our idea.
1357 GETLONG(tl, p); /* Parse desination address (ours) */
1358 ciaddr2 = htonl(tl);
1359 if (ciaddr2 != wo->ouraddr) {
1360 if (ciaddr2 == 0 || !wo->accept_local) {
1362 if (!reject_if_disagree) {
1363 DECPTR(sizeof(u_int32_t), p);
1364 tl = ntohl(wo->ouraddr);
1368 wo->ouraddr = ciaddr2; /* accept peer's idea */
1373 ho->hisaddr = ciaddr1;
1374 ho->ouraddr = ciaddr2;
1378 if (!ao->neg_addr || ho->old_addrs ||
1379 cilen != CILEN_ADDR) { /* Check CI length */
1380 orc = CONFREJ; /* Reject CI */
1385 * If he has no address, or if we both have his address but
1386 * disagree about it, then NAK it with our idea.
1387 * In particular, if we don't know his address, but he does,
1390 GETLONG(tl, p); /* Parse source address (his) */
1391 ciaddr1 = htonl(tl);
1392 if (ciaddr1 != wo->hisaddr
1393 && (ciaddr1 == 0 || !wo->accept_remote)) {
1395 if (!reject_if_disagree) {
1396 DECPTR(sizeof(u_int32_t), p);
1397 tl = ntohl(wo->hisaddr);
1400 } else if (ciaddr1 == 0 && wo->hisaddr == 0) {
1402 * Don't ACK an address of 0.0.0.0 - reject it instead.
1405 wo->req_addr = 0; /* don't NAK with 0.0.0.0 later */
1410 ho->hisaddr = ciaddr1;
1415 /* Microsoft primary or secondary DNS request */
1416 d = citype == CI_MS_DNS2;
1418 /* If we do not have a DNS address then we cannot send it */
1419 if (ao->dnsaddr[d] == 0 ||
1420 cilen != CILEN_ADDR) { /* Check CI length */
1421 orc = CONFREJ; /* Reject CI */
1425 if (htonl(tl) != ao->dnsaddr[d]) {
1426 DECPTR(sizeof(u_int32_t), p);
1427 tl = ntohl(ao->dnsaddr[d]);
1435 /* Microsoft primary or secondary WINS request */
1436 d = citype == CI_MS_WINS2;
1438 /* If we do not have a DNS address then we cannot send it */
1439 if (ao->winsaddr[d] == 0 ||
1440 cilen != CILEN_ADDR) { /* Check CI length */
1441 orc = CONFREJ; /* Reject CI */
1445 if (htonl(tl) != ao->winsaddr[d]) {
1446 DECPTR(sizeof(u_int32_t), p);
1447 tl = ntohl(ao->winsaddr[d]);
1453 case CI_COMPRESSTYPE:
1455 (cilen != CILEN_VJ && cilen != CILEN_COMPRESS)) {
1459 GETSHORT(cishort, p);
1461 if (!(cishort == IPCP_VJ_COMP ||
1462 (cishort == IPCP_VJ_COMP_OLD && cilen == CILEN_COMPRESS))) {
1468 ho->vj_protocol = cishort;
1469 if (cilen == CILEN_VJ) {
1470 GETCHAR(maxslotindex, p);
1471 if (maxslotindex > ao->maxslotindex) {
1473 if (!reject_if_disagree){
1475 PUTCHAR(ao->maxslotindex, p);
1479 if (cflag && !ao->cflag) {
1481 if (!reject_if_disagree){
1483 PUTCHAR(wo->cflag, p);
1486 ho->maxslotindex = maxslotindex;
1490 ho->maxslotindex = MAX_STATES - 1;
1500 if (orc == CONFACK && /* Good CI */
1501 rc != CONFACK) /* but prior CI wasnt? */
1502 continue; /* Don't send this one */
1504 if (orc == CONFNAK) { /* Nak this CI? */
1505 if (reject_if_disagree) /* Getting fed up with sending NAKs? */
1506 orc = CONFREJ; /* Get tough if so */
1508 if (rc == CONFREJ) /* Rejecting prior CI? */
1509 continue; /* Don't send this one */
1510 if (rc == CONFACK) { /* Ack'd all prior CIs? */
1511 rc = CONFNAK; /* Not anymore... */
1512 ucp = inp; /* Backup */
1517 if (orc == CONFREJ && /* Reject this CI */
1518 rc != CONFREJ) { /* but no prior ones? */
1520 ucp = inp; /* Backup */
1523 /* Need to move CI? */
1525 BCOPY(cip, ucp, cilen); /* Move it */
1527 /* Update output pointer */
1532 * If we aren't rejecting this packet, and we want to negotiate
1533 * their address, and they didn't send their address, then we
1534 * send a NAK with a CI_ADDR option appended. We assume the
1535 * input buffer is long enough that we can append the extra
1538 if (rc != CONFREJ && !ho->neg_addr && !ho->old_addrs &&
1539 wo->req_addr && !reject_if_disagree) {
1540 if (rc == CONFACK) {
1542 ucp = inp; /* reset pointer */
1543 wo->req_addr = 0; /* don't ask again */
1545 PUTCHAR(CI_ADDR, ucp);
1546 PUTCHAR(CILEN_ADDR, ucp);
1547 tl = ntohl(wo->hisaddr);
1551 *len = ucp - inp; /* Compute output length */
1552 IPCPDEBUG(("ipcp: returning Configure-%s", CODENAME(rc)));
1553 return (rc); /* Return final code */
1558 * ip_check_options - check that any IP-related options are OK,
1559 * and assign appropriate defaults.
1566 ipcp_options *wo = &ipcp_wantoptions[0];
1569 * Default our local IP address based on our hostname.
1570 * If local IP address already given, don't bother.
1572 if (wo->ouraddr == 0 && !disable_defaultip) {
1574 * Look up our hostname (possibly with domain name appended)
1575 * and take the first IP address as our local IP address.
1576 * If there isn't an IP address for our hostname, too bad.
1578 wo->accept_local = 1; /* don't insist on this default value */
1579 if ((hp = gethostbyname(hostname)) != NULL) {
1580 local = *(u_int32_t *)hp->h_addr;
1581 if (local != 0 && !bad_ip_adrs(local))
1582 wo->ouraddr = local;
1585 ask_for_local = wo->ouraddr != 0 || !disable_defaultip;
1590 * ip_demand_conf - configure the interface as though
1591 * IPCP were up, for use with dial-on-demand.
1597 ipcp_options *wo = &ipcp_wantoptions[u];
1599 if (wo->hisaddr == 0) {
1600 /* make up an arbitrary address for the peer */
1601 wo->hisaddr = htonl(0x0a707070 + ifunit);
1602 wo->accept_remote = 1;
1604 if (wo->ouraddr == 0) {
1605 /* make up an arbitrary address for us */
1606 wo->ouraddr = htonl(0x0a404040 + ifunit);
1607 wo->accept_local = 1;
1608 ask_for_local = 0; /* don't tell the peer this address */
1610 if (!sifaddr(u, wo->ouraddr, wo->hisaddr, GetMask(wo->ouraddr)))
1614 if (!sifnpmode(u, PPP_IP, NPMODE_QUEUE))
1616 if (wo->default_route)
1617 if (sifdefaultroute(u, wo->ouraddr, wo->hisaddr))
1618 default_route_set[u] = 1;
1620 if (sifproxyarp(u, wo->hisaddr))
1621 proxy_arp_set[u] = 1;
1623 notice("local IP address %I", wo->ouraddr);
1624 notice("remote IP address %I", wo->hisaddr);
1631 * ipcp_up - IPCP has come UP.
1633 * Configure the IP network interface appropriately and bring it up.
1640 ipcp_options *ho = &ipcp_hisoptions[f->unit];
1641 ipcp_options *go = &ipcp_gotoptions[f->unit];
1642 ipcp_options *wo = &ipcp_wantoptions[f->unit];
1644 IPCPDEBUG(("ipcp: up"));
1647 * We must have a non-zero IP address for both ends of the link.
1649 if (!ho->neg_addr && !ho->old_addrs)
1650 ho->hisaddr = wo->hisaddr;
1652 if (go->ouraddr == 0) {
1653 error("Could not determine local IP address");
1654 ipcp_close(f->unit, "Could not determine local IP address");
1657 if (ho->hisaddr == 0) {
1658 ho->hisaddr = htonl(0x0a404040 + ifunit);
1659 warn("Could not determine remote IP address: defaulting to %I",
1662 script_setenv("IPLOCAL", ip_ntoa(go->ouraddr), 0);
1663 script_setenv("IPREMOTE", ip_ntoa(ho->hisaddr), 1);
1665 if (usepeerdns && (go->dnsaddr[0] || go->dnsaddr[1])) {
1666 script_setenv("USEPEERDNS", "1", 0);
1668 script_setenv("DNS1", ip_ntoa(go->dnsaddr[0]), 0);
1670 script_setenv("DNS2", ip_ntoa(go->dnsaddr[1]), 0);
1671 create_resolv(go->dnsaddr[0], go->dnsaddr[1]);
1675 * Check that the peer is allowed to use the IP address it wants.
1677 if (!auth_ip_addr(f->unit, ho->hisaddr)) {
1678 error("Peer is not authorized to use remote address %I", ho->hisaddr);
1679 ipcp_close(f->unit, "Unauthorized remote IP address");
1683 /* set tcp compression */
1684 sifvjcomp(f->unit, ho->neg_vj, ho->cflag, ho->maxslotindex);
1687 * If we are doing dial-on-demand, the interface is already
1688 * configured, so we put out any saved-up packets, then set the
1689 * interface to pass IP packets.
1692 if (go->ouraddr != wo->ouraddr || ho->hisaddr != wo->hisaddr) {
1693 ipcp_clear_addrs(f->unit, wo->ouraddr, wo->hisaddr);
1694 if (go->ouraddr != wo->ouraddr) {
1695 warn("Local IP address changed to %I", go->ouraddr);
1696 script_setenv("OLDIPLOCAL", ip_ntoa(wo->ouraddr), 0);
1697 wo->ouraddr = go->ouraddr;
1699 script_unsetenv("OLDIPLOCAL");
1700 if (ho->hisaddr != wo->hisaddr) {
1701 warn("Remote IP address changed to %I", ho->hisaddr);
1702 script_setenv("OLDIPREMOTE", ip_ntoa(wo->hisaddr), 0);
1703 wo->hisaddr = ho->hisaddr;
1705 script_unsetenv("OLDIPREMOTE");
1707 /* Set the interface to the new addresses */
1708 mask = GetMask(go->ouraddr);
1709 if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
1711 warn("Interface configuration failed");
1712 ipcp_close(f->unit, "Interface configuration failed");
1716 /* assign a default route through the interface if required */
1717 if (ipcp_wantoptions[f->unit].default_route)
1718 if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr))
1719 default_route_set[f->unit] = 1;
1721 /* Make a proxy ARP entry if requested. */
1722 if (ipcp_wantoptions[f->unit].proxy_arp)
1723 if (sifproxyarp(f->unit, ho->hisaddr))
1724 proxy_arp_set[f->unit] = 1;
1727 demand_rexmit(PPP_IP);
1728 sifnpmode(f->unit, PPP_IP, NPMODE_PASS);
1732 * Set IP addresses and (if specified) netmask.
1734 mask = GetMask(go->ouraddr);
1736 #if !(defined(SVR4) && (defined(SNI) || defined(__USLC__)))
1737 if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
1739 warn("Interface configuration failed");
1740 ipcp_close(f->unit, "Interface configuration failed");
1745 /* bring the interface up for IP */
1746 if (!sifup(f->unit)) {
1748 warn("Interface failed to come up");
1749 ipcp_close(f->unit, "Interface configuration failed");
1753 #if (defined(SVR4) && (defined(SNI) || defined(__USLC__)))
1754 if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
1756 warn("Interface configuration failed");
1757 ipcp_close(f->unit, "Interface configuration failed");
1761 sifnpmode(f->unit, PPP_IP, NPMODE_PASS);
1763 /* assign a default route through the interface if required */
1764 if (ipcp_wantoptions[f->unit].default_route)
1765 if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr))
1766 default_route_set[f->unit] = 1;
1768 /* Make a proxy ARP entry if requested. */
1769 if (ipcp_wantoptions[f->unit].proxy_arp)
1770 if (sifproxyarp(f->unit, ho->hisaddr))
1771 proxy_arp_set[f->unit] = 1;
1773 ipcp_wantoptions[0].ouraddr = go->ouraddr;
1775 notice("local IP address %I", go->ouraddr);
1776 notice("remote IP address %I", ho->hisaddr);
1778 notice("primary DNS address %I", go->dnsaddr[0]);
1780 notice("secondary DNS address %I", go->dnsaddr[1]);
1783 np_up(f->unit, PPP_IP);
1786 notify(ip_up_notifier, 0);
1791 * Execute the ip-up script, like this:
1792 * /etc/ppp/ip-up interface tty speed local-IP remote-IP
1794 if (ipcp_script_state == s_down && ipcp_script_pid == 0) {
1795 ipcp_script_state = s_up;
1796 ipcp_script(_PATH_IPUP);
1802 * ipcp_down - IPCP has gone DOWN.
1804 * Take the IP network interface down, clear its addresses
1805 * and delete routes through it.
1811 IPCPDEBUG(("ipcp: down"));
1812 /* XXX a bit IPv4-centric here, we only need to get the stats
1813 * before the interface is marked down. */
1814 update_link_stats(f->unit);
1815 notify(ip_down_notifier, 0);
1820 np_down(f->unit, PPP_IP);
1822 sifvjcomp(f->unit, 0, 0, 0);
1825 * If we are doing dial-on-demand, set the interface
1826 * to queue up outgoing packets (for now).
1829 sifnpmode(f->unit, PPP_IP, NPMODE_QUEUE);
1831 sifnpmode(f->unit, PPP_IP, NPMODE_DROP);
1833 ipcp_clear_addrs(f->unit, ipcp_gotoptions[f->unit].ouraddr,
1834 ipcp_hisoptions[f->unit].hisaddr);
1837 /* Execute the ip-down script */
1838 if (ipcp_script_state == s_up && ipcp_script_pid == 0) {
1839 ipcp_script_state = s_down;
1840 ipcp_script(_PATH_IPDOWN);
1846 * ipcp_clear_addrs() - clear the interface addresses, routes,
1847 * proxy arp entries, etc.
1850 ipcp_clear_addrs(unit, ouraddr, hisaddr)
1852 u_int32_t ouraddr; /* local address */
1853 u_int32_t hisaddr; /* remote address */
1855 if (proxy_arp_set[unit]) {
1856 cifproxyarp(unit, hisaddr);
1857 proxy_arp_set[unit] = 0;
1859 if (default_route_set[unit]) {
1860 cifdefaultroute(unit, ouraddr, hisaddr);
1861 default_route_set[unit] = 0;
1863 cifaddr(unit, ouraddr, hisaddr);
1868 * ipcp_finished - possibly shut down the lower layers.
1874 np_finished(f->unit, PPP_IP);
1879 * ipcp_script_done - called when the ip-up or ip-down script
1883 ipcp_script_done(arg)
1886 ipcp_script_pid = 0;
1887 switch (ipcp_script_state) {
1889 if (ipcp_fsm[0].state != OPENED) {
1890 ipcp_script_state = s_down;
1891 ipcp_script(_PATH_IPDOWN);
1895 if (ipcp_fsm[0].state == OPENED) {
1896 ipcp_script_state = s_up;
1897 ipcp_script(_PATH_IPUP);
1905 * ipcp_script - Execute a script with arguments
1906 * interface-name tty-name speed local-IP remote-IP.
1912 char strspeed[32], strlocal[32], strremote[32];
1915 slprintf(strspeed, sizeof(strspeed), "%d", baud_rate);
1916 slprintf(strlocal, sizeof(strlocal), "%I", ipcp_gotoptions[0].ouraddr);
1917 slprintf(strremote, sizeof(strremote), "%I", ipcp_hisoptions[0].hisaddr);
1924 argv[5] = strremote;
1927 ipcp_script_pid = run_program(script, argv, 0, ipcp_script_done, NULL);
1931 * create_resolv - create the replacement resolv.conf file
1934 create_resolv(peerdns1, peerdns2)
1935 u_int32_t peerdns1, peerdns2;
1939 f = fopen(_PATH_RESOLV, "w");
1941 error("Failed to create %s: %m", _PATH_RESOLV);
1946 fprintf(f, "nameserver %s\n", ip_ntoa(peerdns1));
1949 fprintf(f, "nameserver %s\n", ip_ntoa(peerdns2));
1952 error("Write failed to %s: %m", _PATH_RESOLV);
1958 * ipcp_printpkt - print the contents of an IPCP packet.
1960 static char *ipcp_codenames[] = {
1961 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1962 "TermReq", "TermAck", "CodeRej"
1966 ipcp_printpkt(p, plen, printer, arg)
1969 void (*printer) __P((void *, char *, ...));
1972 int code, id, len, olen;
1973 u_char *pstart, *optend;
1977 if (plen < HEADERLEN)
1983 if (len < HEADERLEN || len > plen)
1986 if (code >= 1 && code <= sizeof(ipcp_codenames) / sizeof(char *))
1987 printer(arg, " %s", ipcp_codenames[code-1]);
1989 printer(arg, " code=0x%x", code);
1990 printer(arg, " id=0x%x", id);
1997 /* print option list */
2002 if (olen < 2 || olen > len) {
2010 if (olen == CILEN_ADDRS) {
2013 printer(arg, "addrs %I", htonl(cilong));
2015 printer(arg, " %I", htonl(cilong));
2018 case CI_COMPRESSTYPE:
2019 if (olen >= CILEN_COMPRESS) {
2021 GETSHORT(cishort, p);
2022 printer(arg, "compress ");
2027 case IPCP_VJ_COMP_OLD:
2028 printer(arg, "old-VJ");
2031 printer(arg, "0x%x", cishort);
2036 if (olen == CILEN_ADDR) {
2039 printer(arg, "addr %I", htonl(cilong));
2046 printer(arg, "ms-dns%d %I", code - CI_MS_DNS1 + 1,
2053 printer(arg, "ms-wins %I", htonl(cilong));
2056 while (p < optend) {
2058 printer(arg, " %.2x", code);
2066 if (len > 0 && *p >= ' ' && *p < 0x7f) {
2068 print_string((char *)p, len, printer, arg);
2075 /* print the rest of the bytes in the packet */
2076 for (; len > 0; --len) {
2078 printer(arg, " %.2x", code);
2085 * ip_active_pkt - see if this IP packet is worth bringing the link up for.
2086 * We don't bring the link up for IP fragments or for TCP FIN packets
2089 #define IP_HDRLEN 20 /* bytes */
2090 #define IP_OFFMASK 0x1fff
2092 #define IPPROTO_TCP 6
2094 #define TCP_HDRLEN 20
2098 * We use these macros because the IP header may be at an odd address,
2099 * and some compilers might use word loads to get th_off or ip_hl.
2102 #define net_short(x) (((x)[0] << 8) + (x)[1])
2103 #define get_iphl(x) (((unsigned char *)(x))[0] & 0xF)
2104 #define get_ipoff(x) net_short((unsigned char *)(x) + 6)
2105 #define get_ipproto(x) (((unsigned char *)(x))[9])
2106 #define get_tcpoff(x) (((unsigned char *)(x))[12] >> 4)
2107 #define get_tcpflags(x) (((unsigned char *)(x))[13])
2110 ip_active_pkt(pkt, len)
2119 if (len < IP_HDRLEN)
2121 if ((get_ipoff(pkt) & IP_OFFMASK) != 0)
2123 if (get_ipproto(pkt) != IPPROTO_TCP)
2125 hlen = get_iphl(pkt) * 4;
2126 if (len < hlen + TCP_HDRLEN)
2129 if ((get_tcpflags(tcp) & TH_FIN) != 0 && len == hlen + get_tcpoff(tcp) * 4)