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.
21 static char rcsid[] = "$Id: ipcp.c,v 1.8 1994/05/26 06:37:34 paulus Exp $";
31 #include <sys/types.h>
32 #include <sys/socket.h>
38 #include "pathnames.h"
41 ipcp_options ipcp_wantoptions[NPPP]; /* Options that we want to request */
42 ipcp_options ipcp_gotoptions[NPPP]; /* Options that peer ack'd */
43 ipcp_options ipcp_allowoptions[NPPP]; /* Options we allow peer to request */
44 ipcp_options ipcp_hisoptions[NPPP]; /* Options that we ack'd */
47 extern char devname[];
51 static int cis_received[NPPP]; /* # Conf-Reqs received */
54 * Callbacks for fsm code. (CI = Configuration Information)
56 static void ipcp_resetci __ARGS((fsm *)); /* Reset our CI */
57 static int ipcp_cilen __ARGS((fsm *)); /* Return length of our CI */
58 static void ipcp_addci __ARGS((fsm *, u_char *, int *)); /* Add our CI */
59 static int ipcp_ackci __ARGS((fsm *, u_char *, int)); /* Peer ack'd our CI */
60 static int ipcp_nakci __ARGS((fsm *, u_char *, int)); /* Peer nak'd our CI */
61 static int ipcp_rejci __ARGS((fsm *, u_char *, int)); /* Peer rej'd our CI */
62 static int ipcp_reqci __ARGS((fsm *, u_char *, int *, int)); /* Rcv CI */
63 static void ipcp_up __ARGS((fsm *)); /* We're UP */
64 static void ipcp_down __ARGS((fsm *)); /* We're DOWN */
65 static void ipcp_script __ARGS((fsm *, char *)); /* Run an up/down script */
67 fsm ipcp_fsm[NPPP]; /* IPCP fsm structure */
69 static fsm_callbacks ipcp_callbacks = { /* IPCP callback routines */
70 ipcp_resetci, /* Reset our Configuration Information */
71 ipcp_cilen, /* Length of our Configuration Information */
72 ipcp_addci, /* Add our Configuration Information */
73 ipcp_ackci, /* ACK our Configuration Information */
74 ipcp_nakci, /* NAK our Configuration Information */
75 ipcp_rejci, /* Reject our Configuration Information */
76 ipcp_reqci, /* Request peer's Configuration Information */
77 ipcp_up, /* Called when fsm reaches OPENED state */
78 ipcp_down, /* Called when fsm leaves OPENED state */
79 NULL, /* Called when we want the lower layer up */
80 NULL, /* Called when we want the lower layer down */
81 NULL, /* Called when Protocol-Reject received */
82 NULL, /* Retransmission is necessary */
83 NULL, /* Called to handle protocol-specific codes */
84 "IPCP" /* String name of protocol */
88 * Lengths of configuration options.
91 #define CILEN_COMPRESS 4 /* min length for compression protocol opt. */
92 #define CILEN_VJ 6 /* length for RFC1332 Van-Jacobson opt. */
93 #define CILEN_ADDR 6 /* new-style single address option */
94 #define CILEN_ADDRS 10 /* old-style dual address option */
97 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
98 (x) == CONFNAK ? "NAK" : "REJ")
102 * Make a string representation of a network IP address.
110 ipaddr = ntohl(ipaddr);
112 sprintf(b, "%d.%d.%d.%d",
113 (u_char)(ipaddr >> 24),
114 (u_char)(ipaddr >> 16),
115 (u_char)(ipaddr >> 8),
122 * ipcp_init - Initialize IPCP.
128 fsm *f = &ipcp_fsm[unit];
129 ipcp_options *wo = &ipcp_wantoptions[unit];
130 ipcp_options *ao = &ipcp_allowoptions[unit];
134 f->callbacks = &ipcp_callbacks;
135 fsm_init(&ipcp_fsm[unit]);
144 wo->vj_protocol = IPCP_VJ_COMP;
145 wo->maxslotindex = MAX_STATES - 1; /* really max index */
148 /* max slots and slot-id compression are currently hardwired in */
149 /* ppp_if.c to 16 and 1, this needs to be changed (among other */
154 ao->maxslotindex = MAX_STATES - 1;
160 * ipcp_open - IPCP is allowed to come up.
166 fsm_open(&ipcp_fsm[unit]);
171 * ipcp_close - Take IPCP down.
177 fsm_close(&ipcp_fsm[unit]);
182 * ipcp_lowerup - The lower layer is up.
188 fsm_lowerup(&ipcp_fsm[unit]);
193 * ipcp_lowerdown - The lower layer is down.
199 fsm_lowerdown(&ipcp_fsm[unit]);
204 * ipcp_input - Input IPCP packet.
207 ipcp_input(unit, p, len)
212 fsm_input(&ipcp_fsm[unit], p, len);
217 * ipcp_protrej - A Protocol-Reject was received for IPCP.
219 * Pretend the lower layer went down, so we shut up.
225 fsm_lowerdown(&ipcp_fsm[unit]);
230 * ipcp_resetci - Reset our CI.
236 ipcp_options *wo = &ipcp_wantoptions[f->unit];
238 wo->req_addr = wo->neg_addr && ipcp_allowoptions[f->unit].neg_addr;
239 if (wo->ouraddr == 0)
240 wo->accept_local = 1;
241 if (wo->hisaddr == 0)
242 wo->accept_remote = 1;
243 ipcp_gotoptions[f->unit] = *wo;
244 cis_received[f->unit] = 0;
249 * ipcp_cilen - Return length of our CI.
255 ipcp_options *go = &ipcp_gotoptions[f->unit];
257 #define LENCIVJ(neg, old) (neg ? (old? CILEN_COMPRESS : CILEN_VJ) : 0)
258 #define LENCIADDR(neg, old) (neg ? (old? CILEN_ADDRS : CILEN_ADDR) : 0)
260 return (LENCIADDR(go->neg_addr, go->old_addrs) +
261 LENCIVJ(go->neg_vj, go->old_vj));
266 * ipcp_addci - Add our desired CIs to a packet.
269 ipcp_addci(f, ucp, lenp)
274 ipcp_options *wo = &ipcp_wantoptions[f->unit];
275 ipcp_options *go = &ipcp_gotoptions[f->unit];
276 ipcp_options *ho = &ipcp_hisoptions[f->unit];
279 #define ADDCIVJ(opt, neg, val, old, maxslotindex, cflag) \
281 int vjlen = old? CILEN_COMPRESS : CILEN_VJ; \
282 if (len >= vjlen) { \
284 PUTCHAR(vjlen, ucp); \
285 PUTSHORT(val, ucp); \
287 PUTCHAR(maxslotindex, ucp); \
288 PUTCHAR(cflag, ucp); \
295 #define ADDCIADDR(opt, neg, old, val1, val2) \
297 int addrlen = (old? CILEN_ADDRS: CILEN_ADDR); \
298 if (len >= addrlen) { \
301 PUTCHAR(addrlen, ucp); \
314 * First see if we want to change our options to the old
315 * forms because we have received old forms from the peer.
317 if (wo->neg_addr && !go->neg_addr && !go->old_addrs) {
318 /* use the old style of address negotiation */
322 if (wo->neg_vj && !go->neg_vj && !go->old_vj) {
323 /* try an older style of VJ negotiation */
324 if (cis_received[f->unit] == 0) {
325 /* keep trying the new style until we see some CI from the peer */
328 /* use the old style only if the peer did */
329 if (ho->neg_vj && ho->old_vj) {
332 go->vj_protocol = ho->vj_protocol;
337 ADDCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), go->neg_addr,
338 go->old_addrs, go->ouraddr, go->hisaddr);
340 ADDCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol, go->old_vj,
341 go->maxslotindex, go->cflag);
348 * ipcp_ackci - Ack our CIs.
355 ipcp_ackci(f, p, len)
360 ipcp_options *go = &ipcp_gotoptions[f->unit];
361 u_short cilen, citype, cishort;
363 u_char cimaxslotindex, cicflag;
366 * CIs must be in exactly the same order that we sent...
367 * Check packet length and CI length at each step.
368 * If we find any deviations, then this packet is bad.
371 #define ACKCIVJ(opt, neg, val, old, maxslotindex, cflag) \
373 int vjlen = old? CILEN_COMPRESS : CILEN_VJ; \
374 if ((len -= vjlen) < 0) \
376 GETCHAR(citype, p); \
378 if (cilen != vjlen || \
381 GETSHORT(cishort, p); \
382 if (cishort != val) \
385 GETCHAR(cimaxslotindex, p); \
386 if (cimaxslotindex != maxslotindex) \
388 GETCHAR(cicflag, p); \
389 if (cicflag != cflag) \
394 #define ACKCIADDR(opt, neg, old, val1, val2) \
396 int addrlen = (old? CILEN_ADDRS: CILEN_ADDR); \
398 if ((len -= addrlen) < 0) \
400 GETCHAR(citype, p); \
402 if (cilen != addrlen || \
407 if (val1 != cilong) \
412 if (val2 != cilong) \
417 ACKCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), go->neg_addr,
418 go->old_addrs, go->ouraddr, go->hisaddr);
420 ACKCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol, go->old_vj,
421 go->maxslotindex, go->cflag);
424 * If there are any remaining CIs, then this packet is bad.
431 IPCPDEBUG((LOG_INFO, "ipcp_ackci: received bad Ack!"));
436 * ipcp_nakci - Peer has sent a NAK for some of our CIs.
437 * This should not modify any state if the Nak is bad
438 * or if IPCP is in the OPENED state.
445 ipcp_nakci(f, p, len)
450 ipcp_options *go = &ipcp_gotoptions[f->unit];
451 u_char cimaxslotindex, cicflag;
452 u_char citype, cilen, *next;
454 u_long ciaddr1, ciaddr2, l;
455 ipcp_options no; /* options we've seen Naks for */
456 ipcp_options try; /* options to request next time */
458 BZERO(&no, sizeof(no));
462 * Any Nak'd CIs must be in exactly the same order that we sent.
463 * Check packet length and CI length at each step.
464 * If we find any deviations, then this packet is bad.
466 #define NAKCIADDR(opt, neg, old, code) \
468 len >= (cilen = (old? CILEN_ADDRS: CILEN_ADDR)) && \
474 ciaddr1 = htonl(l); \
477 ciaddr2 = htonl(l); \
485 #define NAKCIVJ(opt, neg, code) \
487 ((cilen = p[1]) == CILEN_COMPRESS || cilen == CILEN_VJ) && \
492 GETSHORT(cishort, p); \
498 * Accept the peer's idea of {our,his} address, if different
499 * from our idea, only if the accept_{local,remote} flag is set.
501 NAKCIADDR(CI_ADDR, neg_addr, go->old_addrs,
502 if (go->accept_local && ciaddr1) { /* Do we know our address? */
503 try.ouraddr = ciaddr1;
504 IPCPDEBUG((LOG_INFO, "local IP address %s",
507 if (go->accept_remote && ciaddr2) { /* Does he know his? */
508 try.hisaddr = ciaddr2;
509 IPCPDEBUG((LOG_INFO, "remote IP address %s",
515 * Accept the peer's value of maxslotindex provided that it
516 * is less than what we asked for. Turn off slot-ID compression
517 * if the peer wants. Send old-style compress-type option if
520 NAKCIVJ(CI_COMPRESSTYPE, neg_vj,
521 if (cilen == CILEN_VJ) {
522 GETCHAR(cimaxslotindex, p);
524 if (cishort == IPCP_VJ_COMP) {
526 if (cimaxslotindex < go->maxslotindex)
527 try.maxslotindex = cimaxslotindex;
534 if (cishort == IPCP_VJ_COMP || cishort == IPCP_VJ_COMP_OLD) {
536 try.vj_protocol = cishort;
544 * There may be remaining CIs, if the peer is requesting negotiation
545 * on an option that we didn't include in our request packet.
546 * If they want to negotiate about IP addresses, we comply.
547 * If they want us to ask for compression, we refuse.
549 while (len > CILEN_VOID) {
552 if( (len -= cilen) < 0 )
554 next = p + cilen - 2;
557 case CI_COMPRESSTYPE:
558 if (go->neg_vj || no.neg_vj ||
559 (cilen != CILEN_VJ && cilen != CILEN_COMPRESS))
564 if (go->neg_addr && go->old_addrs || no.old_addrs
565 || cilen != CILEN_ADDRS)
571 if (ciaddr1 && go->accept_local)
572 try.ouraddr = ciaddr1;
575 if (ciaddr2 && go->accept_remote)
576 try.hisaddr = ciaddr2;
580 if (go->neg_addr || no.neg_addr || cilen != CILEN_ADDR)
586 if (ciaddr1 && go->accept_local)
587 try.ouraddr = ciaddr1;
596 /* If there is still anything left, this packet is bad. */
601 * OK, the Nak is good. Now we can update state.
603 if (f->state != OPENED)
609 IPCPDEBUG((LOG_INFO, "ipcp_nakci: received bad Nak!"));
615 * ipcp_rejci - Reject some of our CIs.
618 ipcp_rejci(f, p, len)
623 ipcp_options *go = &ipcp_gotoptions[f->unit];
624 u_char cimaxslotindex, ciflag, cilen;
627 ipcp_options try; /* options to request next time */
631 * Any Rejected CIs must be in exactly the same order that we sent.
632 * Check packet length and CI length at each step.
633 * If we find any deviations, then this packet is bad.
635 #define REJCIADDR(opt, neg, old, val1, val2) \
637 len >= (cilen = old? CILEN_ADDRS: CILEN_ADDR) && \
645 /* Check rejected value. */ \
646 if (cilong != val1) \
651 /* Check rejected value. */ \
652 if (cilong != val2) \
658 #define REJCIVJ(opt, neg, val, old, maxslot, cflag) \
660 p[1] == (old? CILEN_COMPRESS : CILEN_VJ) && \
665 GETSHORT(cishort, p); \
666 /* Check rejected value. */ \
667 if (cishort != val) \
670 GETCHAR(cimaxslotindex, p); \
671 if (cimaxslotindex != maxslot) \
673 GETCHAR(ciflag, p); \
674 if (ciflag != cflag) \
680 REJCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), neg_addr,
681 go->old_addrs, go->ouraddr, go->hisaddr);
683 REJCIVJ(CI_COMPRESSTYPE, neg_vj, go->vj_protocol, go->old_vj,
684 go->maxslotindex, go->cflag);
687 * If there are any remaining CIs, then this packet is bad.
692 * Now we can update state.
694 if (f->state != OPENED)
699 IPCPDEBUG((LOG_INFO, "ipcp_rejci: received bad Reject!"));
705 * ipcp_reqci - Check the peer's requested CIs and send appropriate response.
707 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
708 * appropriately. If reject_if_disagree is non-zero, doesn't return
709 * CONFNAK; returns CONFREJ if it can't return CONFACK.
712 ipcp_reqci(f, inp, len, reject_if_disagree)
714 u_char *inp; /* Requested CIs */
715 int *len; /* Length of requested CIs */
716 int reject_if_disagree;
718 ipcp_options *wo = &ipcp_wantoptions[f->unit];
719 ipcp_options *ho = &ipcp_hisoptions[f->unit];
720 ipcp_options *ao = &ipcp_allowoptions[f->unit];
721 ipcp_options *go = &ipcp_gotoptions[f->unit];
722 u_char *cip, *next; /* Pointer to current and next CIs */
723 u_short cilen, citype; /* Parsed len, type */
724 u_short cishort; /* Parsed short value */
725 u_long tl, ciaddr1, ciaddr2;/* Parsed address values */
726 int rc = CONFACK; /* Final packet return code */
727 int orc; /* Individual option return code */
728 u_char *p; /* Pointer to next char to parse */
729 u_char *ucp = inp; /* Pointer to current output char */
730 int l = *len; /* Length left */
731 u_char maxslotindex, cflag;
734 * Reset all his options.
736 BZERO(ho, sizeof(*ho));
739 * Process all his options.
743 orc = CONFACK; /* Assume success */
744 cip = p = next; /* Remember begining of CI */
745 if (l < 2 || /* Not enough data for CI header or */
746 p[1] < 2 || /* CI length too small or */
747 p[1] > l) { /* CI length too big? */
748 IPCPDEBUG((LOG_INFO, "ipcp_reqci: bad CI length!"));
749 orc = CONFREJ; /* Reject bad CI */
750 cilen = l; /* Reject till end of packet */
751 l = 0; /* Don't loop again */
754 GETCHAR(citype, p); /* Parse CI type */
755 GETCHAR(cilen, p); /* Parse CI length */
756 l -= cilen; /* Adjust remaining length */
757 next += cilen; /* Step to next CI */
759 switch (citype) { /* Check CI type */
761 IPCPDEBUG((LOG_INFO, "ipcp: received ADDRS "));
763 cilen != CILEN_ADDRS) { /* Check CI length */
764 orc = CONFREJ; /* Reject CI */
769 * If he has no address, or if we both have his address but
770 * disagree about it, then NAK it with our idea.
771 * In particular, if we don't know his address, but he does,
774 GETLONG(tl, p); /* Parse source address (his) */
776 IPCPDEBUG((LOG_INFO, "(%s:", ip_ntoa(ciaddr1)));
777 if (ciaddr1 != wo->hisaddr
778 && (ciaddr1 == 0 || !wo->accept_remote)) {
780 if (!reject_if_disagree) {
781 DECPTR(sizeof (long), p);
782 tl = ntohl(wo->hisaddr);
788 * If he doesn't know our address, or if we both have our address
789 * but disagree about it, then NAK it with our idea.
791 GETLONG(tl, p); /* Parse desination address (ours) */
793 IPCPDEBUG((LOG_INFO, "%s)", ip_ntoa(ciaddr2)));
794 if (ciaddr2 != wo->ouraddr) {
795 if (ciaddr2 == 0 || !wo->accept_local) {
797 if (!reject_if_disagree) {
798 DECPTR(sizeof (long), p);
799 tl = ntohl(wo->ouraddr);
803 go->ouraddr = ciaddr2; /* accept peer's idea */
809 ho->hisaddr = ciaddr1;
810 ho->ouraddr = ciaddr2;
814 IPCPDEBUG((LOG_INFO, "ipcp: received ADDR "));
817 cilen != CILEN_ADDR) { /* Check CI length */
818 orc = CONFREJ; /* Reject CI */
823 * If he has no address, or if we both have his address but
824 * disagree about it, then NAK it with our idea.
825 * In particular, if we don't know his address, but he does,
828 GETLONG(tl, p); /* Parse source address (his) */
830 IPCPDEBUG((LOG_INFO, "(%s)", ip_ntoa(ciaddr1)));
831 if (ciaddr1 != wo->hisaddr
832 && (ciaddr1 == 0 || !wo->accept_remote)) {
834 if (!reject_if_disagree) {
835 DECPTR(sizeof (long), p);
836 tl = ntohl(wo->hisaddr);
842 ho->hisaddr = ciaddr1;
845 case CI_COMPRESSTYPE:
846 IPCPDEBUG((LOG_INFO, "ipcp: received COMPRESSTYPE "));
848 (cilen != CILEN_VJ && cilen != CILEN_COMPRESS)) {
852 GETSHORT(cishort, p);
853 IPCPDEBUG((LOG_INFO, "(%d)", cishort));
855 if (!(cishort == IPCP_VJ_COMP ||
856 (cishort == IPCP_VJ_COMP_OLD && cilen == CILEN_COMPRESS))) {
862 ho->vj_protocol = cishort;
863 if (cilen == CILEN_VJ) {
864 GETCHAR(maxslotindex, p);
865 if (maxslotindex > ao->maxslotindex) {
867 if (!reject_if_disagree){
869 PUTCHAR(ao->maxslotindex, p);
873 if (cflag && !ao->cflag) {
875 if (!reject_if_disagree){
877 PUTCHAR(wo->cflag, p);
880 ho->maxslotindex = maxslotindex;
881 ho->cflag = wo->cflag;
884 ho->maxslotindex = MAX_STATES - 1;
895 IPCPDEBUG((LOG_INFO, " (%s)\n", CODENAME(orc)));
897 if (orc == CONFACK && /* Good CI */
898 rc != CONFACK) /* but prior CI wasnt? */
899 continue; /* Don't send this one */
901 if (orc == CONFNAK) { /* Nak this CI? */
902 if (reject_if_disagree) /* Getting fed up with sending NAKs? */
903 orc = CONFREJ; /* Get tough if so */
905 if (rc == CONFREJ) /* Rejecting prior CI? */
906 continue; /* Don't send this one */
907 if (rc == CONFACK) { /* Ack'd all prior CIs? */
908 rc = CONFNAK; /* Not anymore... */
909 ucp = inp; /* Backup */
914 if (orc == CONFREJ && /* Reject this CI */
915 rc != CONFREJ) { /* but no prior ones? */
917 ucp = inp; /* Backup */
920 /* Need to move CI? */
922 BCOPY(cip, ucp, cilen); /* Move it */
924 /* Update output pointer */
929 * If we aren't rejecting this packet, and we want to negotiate
930 * their address, and they didn't send their address, then we
931 * send a NAK with a CI_ADDR option appended. We assume the
932 * input buffer is long enough that we can append the extra
935 if (rc != CONFREJ && !ho->neg_addr &&
936 wo->req_addr && !reject_if_disagree) {
939 ucp = inp; /* reset pointer */
940 wo->req_addr = 0; /* don't ask again */
942 PUTCHAR(CI_ADDR, ucp);
943 PUTCHAR(CILEN_ADDR, ucp);
944 tl = ntohl(wo->hisaddr);
948 *len = ucp - inp; /* Compute output length */
949 IPCPDEBUG((LOG_INFO, "ipcp: returning Configure-%s", CODENAME(rc)));
950 return (rc); /* Return final code */
955 * ipcp_up - IPCP has come UP.
957 * Configure the IP network interface appropriately and bring it up.
964 ipcp_options *ho = &ipcp_hisoptions[f->unit];
965 ipcp_options *go = &ipcp_gotoptions[f->unit];
967 IPCPDEBUG((LOG_INFO, "ipcp: up"));
968 go->default_route = 0;
972 * We must have a non-zero IP address for both ends of the link.
975 ho->hisaddr = ipcp_wantoptions[f->unit].hisaddr;
977 if (ho->hisaddr == 0) {
978 syslog(LOG_ERR, "Could not determine remote IP address");
982 if (go->ouraddr == 0) {
983 syslog(LOG_ERR, "Could not determine local IP address");
989 * Check that the peer is allowed to use the IP address it wants.
991 if (!auth_ip_addr(f->unit, ho->hisaddr)) {
992 syslog(LOG_ERR, "Peer is not authorized to use remote address %s",
993 ip_ntoa(ho->hisaddr));
998 syslog(LOG_NOTICE, "local IP address %s", ip_ntoa(go->ouraddr));
999 syslog(LOG_NOTICE, "remote IP address %s", ip_ntoa(ho->hisaddr));
1002 * Set IP addresses and (if specified) netmask.
1004 mask = GetMask(go->ouraddr);
1005 if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
1006 IPCPDEBUG((LOG_WARNING, "sifaddr failed"));
1007 ipcp_close(f->unit);
1011 /* set tcp compression */
1012 sifvjcomp(f->unit, ho->neg_vj, ho->cflag, ho->maxslotindex);
1014 /* bring the interface up for IP */
1015 if (!sifup(f->unit)) {
1016 IPCPDEBUG((LOG_WARNING, "sifup failed"));
1017 ipcp_close(f->unit);
1021 /* assign a default route through the interface if required */
1022 if (ipcp_wantoptions[f->unit].default_route)
1023 if (sifdefaultroute(f->unit, ho->hisaddr))
1024 go->default_route = 1;
1026 /* Make a proxy ARP entry if requested. */
1027 if (ipcp_wantoptions[f->unit].proxy_arp)
1028 if (sifproxyarp(f->unit, ho->hisaddr))
1032 * Execute the ip-up script, like this:
1033 * /etc/ppp/ip-up interface tty speed local-IP remote-IP
1035 ipcp_script(f, _PATH_IPUP);
1041 * ipcp_down - IPCP has gone DOWN.
1043 * Take the IP network interface down, clear its addresses
1044 * and delete routes through it.
1050 u_long ouraddr, hisaddr;
1052 IPCPDEBUG((LOG_INFO, "ipcp: down"));
1054 ouraddr = ipcp_gotoptions[f->unit].ouraddr;
1055 hisaddr = ipcp_hisoptions[f->unit].hisaddr;
1056 if (ipcp_gotoptions[f->unit].proxy_arp)
1057 cifproxyarp(f->unit, hisaddr);
1058 if (ipcp_gotoptions[f->unit].default_route)
1059 cifdefaultroute(f->unit, hisaddr);
1061 cifaddr(f->unit, ouraddr, hisaddr);
1063 /* Execute the ip-down script */
1064 ipcp_script(f, _PATH_IPDOWN);
1069 * ipcp_script - Execute a script with arguments
1070 * interface-name tty-name speed local-IP remote-IP.
1073 ipcp_script(f, script)
1077 char strspeed[32], strlocal[32], strremote[32];
1080 sprintf(strspeed, "%d", baud_rate);
1081 strcpy(strlocal, ip_ntoa(ipcp_gotoptions[f->unit].ouraddr));
1082 strcpy(strremote, ip_ntoa(ipcp_hisoptions[f->unit].hisaddr));
1089 argv[5] = strremote;
1091 run_program(script, argv, 0);
1095 * ipcp_printpkt - print the contents of an IPCP packet.
1097 char *ipcp_codenames[] = {
1098 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1099 "TermReq", "TermAck", "CodeRej"
1103 ipcp_printpkt(p, plen, printer, arg)
1109 int code, id, len, olen;
1110 u_char *pstart, *optend;
1114 if (plen < HEADERLEN)
1120 if (len < HEADERLEN || len > plen)
1123 if (code >= 1 && code <= sizeof(ipcp_codenames) / sizeof(char *))
1124 printer(arg, " %s", ipcp_codenames[code-1]);
1126 printer(arg, " code=0x%x", code);
1127 printer(arg, " id=0x%x", id);
1134 /* print option list */
1139 if (olen < 2 || olen > len) {
1147 if (olen == CILEN_ADDRS) {
1150 printer(arg, "addrs %s", ip_ntoa(htonl(cilong)));
1152 printer(arg, " %s", ip_ntoa(htonl(cilong)));
1155 case CI_COMPRESSTYPE:
1156 if (olen >= CILEN_COMPRESS) {
1158 GETSHORT(cishort, p);
1159 printer(arg, "compress ");
1164 case IPCP_VJ_COMP_OLD:
1165 printer(arg, "old-VJ");
1168 printer(arg, "0x%x", cishort);
1173 if (olen == CILEN_ADDR) {
1176 printer(arg, "addr %s", ip_ntoa(htonl(cilong)));
1180 while (p < optend) {
1182 printer(arg, " %.2x", code);
1189 /* print the rest of the bytes in the packet */
1190 for (; len > 0; --len) {
1192 printer(arg, " %.2x", code);