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.17 1995/04/28 06:24:53 paulus Exp $";
31 #include <sys/types.h>
32 #include <sys/socket.h>
33 #include <netinet/in.h>
38 #include "pathnames.h"
41 ipcp_options ipcp_wantoptions[NUM_PPP]; /* Options that we want to request */
42 ipcp_options ipcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
43 ipcp_options ipcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
44 ipcp_options ipcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
47 static int cis_received[NUM_PPP]; /* # Conf-Reqs received */
50 * Callbacks for fsm code. (CI = Configuration Information)
52 static void ipcp_resetci __P((fsm *)); /* Reset our CI */
53 static int ipcp_cilen __P((fsm *)); /* Return length of our CI */
54 static void ipcp_addci __P((fsm *, u_char *, int *)); /* Add our CI */
55 static int ipcp_ackci __P((fsm *, u_char *, int)); /* Peer ack'd our CI */
56 static int ipcp_nakci __P((fsm *, u_char *, int)); /* Peer nak'd our CI */
57 static int ipcp_rejci __P((fsm *, u_char *, int)); /* Peer rej'd our CI */
58 static int ipcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv CI */
59 static void ipcp_up __P((fsm *)); /* We're UP */
60 static void ipcp_down __P((fsm *)); /* We're DOWN */
61 static void ipcp_script __P((fsm *, char *)); /* Run an up/down script */
63 fsm ipcp_fsm[NUM_PPP]; /* IPCP fsm structure */
65 static fsm_callbacks ipcp_callbacks = { /* IPCP callback routines */
66 ipcp_resetci, /* Reset our Configuration Information */
67 ipcp_cilen, /* Length of our Configuration Information */
68 ipcp_addci, /* Add our Configuration Information */
69 ipcp_ackci, /* ACK our Configuration Information */
70 ipcp_nakci, /* NAK our Configuration Information */
71 ipcp_rejci, /* Reject our Configuration Information */
72 ipcp_reqci, /* Request peer's Configuration Information */
73 ipcp_up, /* Called when fsm reaches OPENED state */
74 ipcp_down, /* Called when fsm leaves OPENED state */
75 NULL, /* Called when we want the lower layer up */
76 NULL, /* Called when we want the lower layer down */
77 NULL, /* Called when Protocol-Reject received */
78 NULL, /* Retransmission is necessary */
79 NULL, /* Called to handle protocol-specific codes */
80 "IPCP" /* String name of protocol */
84 * Lengths of configuration options.
87 #define CILEN_COMPRESS 4 /* min length for compression protocol opt. */
88 #define CILEN_VJ 6 /* length for RFC1332 Van-Jacobson opt. */
89 #define CILEN_ADDR 6 /* new-style single address option */
90 #define CILEN_ADDRS 10 /* old-style dual address option */
93 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
94 (x) == CONFNAK ? "NAK" : "REJ")
98 * Make a string representation of a network IP address.
106 ipaddr = ntohl(ipaddr);
108 sprintf(b, "%d.%d.%d.%d",
109 (u_char)(ipaddr >> 24),
110 (u_char)(ipaddr >> 16),
111 (u_char)(ipaddr >> 8),
118 * ipcp_init - Initialize IPCP.
124 fsm *f = &ipcp_fsm[unit];
125 ipcp_options *wo = &ipcp_wantoptions[unit];
126 ipcp_options *ao = &ipcp_allowoptions[unit];
129 f->protocol = PPP_IPCP;
130 f->callbacks = &ipcp_callbacks;
131 fsm_init(&ipcp_fsm[unit]);
140 wo->vj_protocol = IPCP_VJ_COMP;
141 wo->maxslotindex = MAX_STATES - 1; /* really max index */
144 /* max slots and slot-id compression are currently hardwired in */
145 /* ppp_if.c to 16 and 1, this needs to be changed (among other */
150 ao->maxslotindex = MAX_STATES - 1;
156 * ipcp_open - IPCP is allowed to come up.
162 fsm_open(&ipcp_fsm[unit]);
167 * ipcp_close - Take IPCP down.
173 fsm_close(&ipcp_fsm[unit]);
178 * ipcp_lowerup - The lower layer is up.
184 fsm_lowerup(&ipcp_fsm[unit]);
189 * ipcp_lowerdown - The lower layer is down.
195 fsm_lowerdown(&ipcp_fsm[unit]);
200 * ipcp_input - Input IPCP packet.
203 ipcp_input(unit, p, len)
208 fsm_input(&ipcp_fsm[unit], p, len);
213 * ipcp_protrej - A Protocol-Reject was received for IPCP.
215 * Pretend the lower layer went down, so we shut up.
221 fsm_lowerdown(&ipcp_fsm[unit]);
226 * ipcp_resetci - Reset our CI.
232 ipcp_options *wo = &ipcp_wantoptions[f->unit];
234 wo->req_addr = wo->neg_addr && ipcp_allowoptions[f->unit].neg_addr;
235 if (wo->ouraddr == 0)
236 wo->accept_local = 1;
237 if (wo->hisaddr == 0)
238 wo->accept_remote = 1;
239 ipcp_gotoptions[f->unit] = *wo;
240 cis_received[f->unit] = 0;
245 * ipcp_cilen - Return length of our CI.
251 ipcp_options *go = &ipcp_gotoptions[f->unit];
253 #define LENCIVJ(neg, old) (neg ? (old? CILEN_COMPRESS : CILEN_VJ) : 0)
254 #define LENCIADDR(neg, old) (neg ? (old? CILEN_ADDRS : CILEN_ADDR) : 0)
256 return (LENCIADDR(go->neg_addr, go->old_addrs) +
257 LENCIVJ(go->neg_vj, go->old_vj));
262 * ipcp_addci - Add our desired CIs to a packet.
265 ipcp_addci(f, ucp, lenp)
270 ipcp_options *wo = &ipcp_wantoptions[f->unit];
271 ipcp_options *go = &ipcp_gotoptions[f->unit];
272 ipcp_options *ho = &ipcp_hisoptions[f->unit];
275 #define ADDCIVJ(opt, neg, val, old, maxslotindex, cflag) \
277 int vjlen = old? CILEN_COMPRESS : CILEN_VJ; \
278 if (len >= vjlen) { \
280 PUTCHAR(vjlen, ucp); \
281 PUTSHORT(val, ucp); \
283 PUTCHAR(maxslotindex, ucp); \
284 PUTCHAR(cflag, ucp); \
291 #define ADDCIADDR(opt, neg, old, val1, val2) \
293 int addrlen = (old? CILEN_ADDRS: CILEN_ADDR); \
294 if (len >= addrlen) { \
297 PUTCHAR(addrlen, ucp); \
310 * First see if we want to change our options to the old
311 * forms because we have received old forms from the peer.
313 if (wo->neg_addr && !go->neg_addr && !go->old_addrs) {
314 /* use the old style of address negotiation */
318 if (wo->neg_vj && !go->neg_vj && !go->old_vj) {
319 /* try an older style of VJ negotiation */
320 if (cis_received[f->unit] == 0) {
321 /* keep trying the new style until we see some CI from the peer */
324 /* use the old style only if the peer did */
325 if (ho->neg_vj && ho->old_vj) {
328 go->vj_protocol = ho->vj_protocol;
333 ADDCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), go->neg_addr,
334 go->old_addrs, go->ouraddr, go->hisaddr);
336 ADDCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol, go->old_vj,
337 go->maxslotindex, go->cflag);
344 * ipcp_ackci - Ack our CIs.
351 ipcp_ackci(f, p, len)
356 ipcp_options *go = &ipcp_gotoptions[f->unit];
357 u_short cilen, citype, cishort;
359 u_char cimaxslotindex, cicflag;
362 * CIs must be in exactly the same order that we sent...
363 * Check packet length and CI length at each step.
364 * If we find any deviations, then this packet is bad.
367 #define ACKCIVJ(opt, neg, val, old, maxslotindex, cflag) \
369 int vjlen = old? CILEN_COMPRESS : CILEN_VJ; \
370 if ((len -= vjlen) < 0) \
372 GETCHAR(citype, p); \
374 if (cilen != vjlen || \
377 GETSHORT(cishort, p); \
378 if (cishort != val) \
381 GETCHAR(cimaxslotindex, p); \
382 if (cimaxslotindex != maxslotindex) \
384 GETCHAR(cicflag, p); \
385 if (cicflag != cflag) \
390 #define ACKCIADDR(opt, neg, old, val1, val2) \
392 int addrlen = (old? CILEN_ADDRS: CILEN_ADDR); \
394 if ((len -= addrlen) < 0) \
396 GETCHAR(citype, p); \
398 if (cilen != addrlen || \
403 if (val1 != cilong) \
408 if (val2 != cilong) \
413 ACKCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), go->neg_addr,
414 go->old_addrs, go->ouraddr, go->hisaddr);
416 ACKCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol, go->old_vj,
417 go->maxslotindex, go->cflag);
420 * If there are any remaining CIs, then this packet is bad.
427 IPCPDEBUG((LOG_INFO, "ipcp_ackci: received bad Ack!"));
432 * ipcp_nakci - Peer has sent a NAK for some of our CIs.
433 * This should not modify any state if the Nak is bad
434 * or if IPCP is in the OPENED state.
441 ipcp_nakci(f, p, len)
446 ipcp_options *go = &ipcp_gotoptions[f->unit];
447 u_char cimaxslotindex, cicflag;
448 u_char citype, cilen, *next;
450 u_int32_t ciaddr1, ciaddr2, l;
451 ipcp_options no; /* options we've seen Naks for */
452 ipcp_options try; /* options to request next time */
454 BZERO(&no, sizeof(no));
458 * Any Nak'd CIs must be in exactly the same order that we sent.
459 * Check packet length and CI length at each step.
460 * If we find any deviations, then this packet is bad.
462 #define NAKCIADDR(opt, neg, old, code) \
464 len >= (cilen = (old? CILEN_ADDRS: CILEN_ADDR)) && \
470 ciaddr1 = htonl(l); \
473 ciaddr2 = htonl(l); \
481 #define NAKCIVJ(opt, neg, code) \
483 ((cilen = p[1]) == CILEN_COMPRESS || cilen == CILEN_VJ) && \
488 GETSHORT(cishort, p); \
494 * Accept the peer's idea of {our,his} address, if different
495 * from our idea, only if the accept_{local,remote} flag is set.
497 NAKCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), neg_addr, go->old_addrs,
498 if (go->accept_local && ciaddr1) { /* Do we know our address? */
499 try.ouraddr = ciaddr1;
500 IPCPDEBUG((LOG_INFO, "local IP address %s",
503 if (go->accept_remote && ciaddr2) { /* Does he know his? */
504 try.hisaddr = ciaddr2;
505 IPCPDEBUG((LOG_INFO, "remote IP address %s",
511 * Accept the peer's value of maxslotindex provided that it
512 * is less than what we asked for. Turn off slot-ID compression
513 * if the peer wants. Send old-style compress-type option if
516 NAKCIVJ(CI_COMPRESSTYPE, neg_vj,
517 if (cilen == CILEN_VJ) {
518 GETCHAR(cimaxslotindex, p);
520 if (cishort == IPCP_VJ_COMP) {
522 if (cimaxslotindex < go->maxslotindex)
523 try.maxslotindex = cimaxslotindex;
530 if (cishort == IPCP_VJ_COMP || cishort == IPCP_VJ_COMP_OLD) {
532 try.vj_protocol = cishort;
540 * There may be remaining CIs, if the peer is requesting negotiation
541 * on an option that we didn't include in our request packet.
542 * If they want to negotiate about IP addresses, we comply.
543 * If they want us to ask for compression, we refuse.
545 while (len > CILEN_VOID) {
548 if( (len -= cilen) < 0 )
550 next = p + cilen - 2;
553 case CI_COMPRESSTYPE:
554 if (go->neg_vj || no.neg_vj ||
555 (cilen != CILEN_VJ && cilen != CILEN_COMPRESS))
560 if (go->neg_addr && go->old_addrs || no.old_addrs
561 || cilen != CILEN_ADDRS)
567 if (ciaddr1 && go->accept_local)
568 try.ouraddr = ciaddr1;
571 if (ciaddr2 && go->accept_remote)
572 try.hisaddr = ciaddr2;
576 if (go->neg_addr || no.neg_addr || cilen != CILEN_ADDR)
581 if (ciaddr1 && go->accept_local)
582 try.ouraddr = ciaddr1;
583 if (try.ouraddr != 0)
592 /* If there is still anything left, this packet is bad. */
597 * OK, the Nak is good. Now we can update state.
599 if (f->state != OPENED)
605 IPCPDEBUG((LOG_INFO, "ipcp_nakci: received bad Nak!"));
611 * ipcp_rejci - Reject some of our CIs.
614 ipcp_rejci(f, p, len)
619 ipcp_options *go = &ipcp_gotoptions[f->unit];
620 u_char cimaxslotindex, ciflag, cilen;
623 ipcp_options try; /* options to request next time */
627 * Any Rejected CIs must be in exactly the same order that we sent.
628 * Check packet length and CI length at each step.
629 * If we find any deviations, then this packet is bad.
631 #define REJCIADDR(opt, neg, old, val1, val2) \
633 len >= (cilen = old? CILEN_ADDRS: CILEN_ADDR) && \
641 /* Check rejected value. */ \
642 if (cilong != val1) \
647 /* Check rejected value. */ \
648 if (cilong != val2) \
654 #define REJCIVJ(opt, neg, val, old, maxslot, cflag) \
656 p[1] == (old? CILEN_COMPRESS : CILEN_VJ) && \
661 GETSHORT(cishort, p); \
662 /* Check rejected value. */ \
663 if (cishort != val) \
666 GETCHAR(cimaxslotindex, p); \
667 if (cimaxslotindex != maxslot) \
669 GETCHAR(ciflag, p); \
670 if (ciflag != cflag) \
676 REJCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), neg_addr,
677 go->old_addrs, go->ouraddr, go->hisaddr);
679 REJCIVJ(CI_COMPRESSTYPE, neg_vj, go->vj_protocol, go->old_vj,
680 go->maxslotindex, go->cflag);
683 * If there are any remaining CIs, then this packet is bad.
688 * Now we can update state.
690 if (f->state != OPENED)
695 IPCPDEBUG((LOG_INFO, "ipcp_rejci: received bad Reject!"));
701 * ipcp_reqci - Check the peer's requested CIs and send appropriate response.
703 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
704 * appropriately. If reject_if_disagree is non-zero, doesn't return
705 * CONFNAK; returns CONFREJ if it can't return CONFACK.
708 ipcp_reqci(f, inp, len, reject_if_disagree)
710 u_char *inp; /* Requested CIs */
711 int *len; /* Length of requested CIs */
712 int reject_if_disagree;
714 ipcp_options *wo = &ipcp_wantoptions[f->unit];
715 ipcp_options *ho = &ipcp_hisoptions[f->unit];
716 ipcp_options *ao = &ipcp_allowoptions[f->unit];
717 ipcp_options *go = &ipcp_gotoptions[f->unit];
718 u_char *cip, *next; /* Pointer to current and next CIs */
719 u_short cilen, citype; /* Parsed len, type */
720 u_short cishort; /* Parsed short value */
721 u_int32_t tl, ciaddr1, ciaddr2;/* Parsed address values */
722 int rc = CONFACK; /* Final packet return code */
723 int orc; /* Individual option return code */
724 u_char *p; /* Pointer to next char to parse */
725 u_char *ucp = inp; /* Pointer to current output char */
726 int l = *len; /* Length left */
727 u_char maxslotindex, cflag;
730 * Reset all his options.
732 BZERO(ho, sizeof(*ho));
735 * Process all his options.
739 orc = CONFACK; /* Assume success */
740 cip = p = next; /* Remember begining of CI */
741 if (l < 2 || /* Not enough data for CI header or */
742 p[1] < 2 || /* CI length too small or */
743 p[1] > l) { /* CI length too big? */
744 IPCPDEBUG((LOG_INFO, "ipcp_reqci: bad CI length!"));
745 orc = CONFREJ; /* Reject bad CI */
746 cilen = l; /* Reject till end of packet */
747 l = 0; /* Don't loop again */
750 GETCHAR(citype, p); /* Parse CI type */
751 GETCHAR(cilen, p); /* Parse CI length */
752 l -= cilen; /* Adjust remaining length */
753 next += cilen; /* Step to next CI */
755 switch (citype) { /* Check CI type */
757 IPCPDEBUG((LOG_INFO, "ipcp: received ADDRS "));
759 cilen != CILEN_ADDRS) { /* Check CI length */
760 orc = CONFREJ; /* Reject CI */
765 * If he has no address, or if we both have his address but
766 * disagree about it, then NAK it with our idea.
767 * In particular, if we don't know his address, but he does,
770 GETLONG(tl, p); /* Parse source address (his) */
772 IPCPDEBUG((LOG_INFO, "(%s:", ip_ntoa(ciaddr1)));
773 if (ciaddr1 != wo->hisaddr
774 && (ciaddr1 == 0 || !wo->accept_remote)) {
776 if (!reject_if_disagree) {
777 DECPTR(sizeof(u_int32_t), p);
778 tl = ntohl(wo->hisaddr);
781 } else if (ciaddr1 == 0 && wo->hisaddr == 0) {
783 * If neither we nor he knows his address, reject the option.
786 wo->req_addr = 0; /* don't NAK with 0.0.0.0 later */
791 * If he doesn't know our address, or if we both have our address
792 * but disagree about it, then NAK it with our idea.
794 GETLONG(tl, p); /* Parse desination address (ours) */
796 IPCPDEBUG((LOG_INFO, "%s)", ip_ntoa(ciaddr2)));
797 if (ciaddr2 != wo->ouraddr) {
798 if (ciaddr2 == 0 || !wo->accept_local) {
800 if (!reject_if_disagree) {
801 DECPTR(sizeof(u_int32_t), p);
802 tl = ntohl(wo->ouraddr);
806 go->ouraddr = ciaddr2; /* accept peer's idea */
812 ho->hisaddr = ciaddr1;
813 ho->ouraddr = ciaddr2;
817 IPCPDEBUG((LOG_INFO, "ipcp: received ADDR "));
820 cilen != CILEN_ADDR) { /* Check CI length */
821 orc = CONFREJ; /* Reject CI */
826 * If he has no address, or if we both have his address but
827 * disagree about it, then NAK it with our idea.
828 * In particular, if we don't know his address, but he does,
831 GETLONG(tl, p); /* Parse source address (his) */
833 IPCPDEBUG((LOG_INFO, "(%s)", ip_ntoa(ciaddr1)));
834 if (ciaddr1 != wo->hisaddr
835 && (ciaddr1 == 0 || !wo->accept_remote)) {
837 if (!reject_if_disagree) {
838 DECPTR(sizeof(u_int32_t), p);
839 tl = ntohl(wo->hisaddr);
842 } else if (ciaddr1 == 0 && wo->hisaddr == 0) {
844 * Don't ACK an address of 0.0.0.0 - reject it instead.
847 wo->req_addr = 0; /* don't NAK with 0.0.0.0 later */
852 ho->hisaddr = ciaddr1;
855 case CI_COMPRESSTYPE:
856 IPCPDEBUG((LOG_INFO, "ipcp: received COMPRESSTYPE "));
858 (cilen != CILEN_VJ && cilen != CILEN_COMPRESS)) {
862 GETSHORT(cishort, p);
863 IPCPDEBUG((LOG_INFO, "(%d)", cishort));
865 if (!(cishort == IPCP_VJ_COMP ||
866 (cishort == IPCP_VJ_COMP_OLD && cilen == CILEN_COMPRESS))) {
872 ho->vj_protocol = cishort;
873 if (cilen == CILEN_VJ) {
874 GETCHAR(maxslotindex, p);
875 if (maxslotindex > ao->maxslotindex) {
877 if (!reject_if_disagree){
879 PUTCHAR(ao->maxslotindex, p);
883 if (cflag && !ao->cflag) {
885 if (!reject_if_disagree){
887 PUTCHAR(wo->cflag, p);
890 ho->maxslotindex = maxslotindex;
891 ho->cflag = wo->cflag;
894 ho->maxslotindex = MAX_STATES - 1;
905 IPCPDEBUG((LOG_INFO, " (%s)\n", CODENAME(orc)));
907 if (orc == CONFACK && /* Good CI */
908 rc != CONFACK) /* but prior CI wasnt? */
909 continue; /* Don't send this one */
911 if (orc == CONFNAK) { /* Nak this CI? */
912 if (reject_if_disagree) /* Getting fed up with sending NAKs? */
913 orc = CONFREJ; /* Get tough if so */
915 if (rc == CONFREJ) /* Rejecting prior CI? */
916 continue; /* Don't send this one */
917 if (rc == CONFACK) { /* Ack'd all prior CIs? */
918 rc = CONFNAK; /* Not anymore... */
919 ucp = inp; /* Backup */
924 if (orc == CONFREJ && /* Reject this CI */
925 rc != CONFREJ) { /* but no prior ones? */
927 ucp = inp; /* Backup */
930 /* Need to move CI? */
932 BCOPY(cip, ucp, cilen); /* Move it */
934 /* Update output pointer */
939 * If we aren't rejecting this packet, and we want to negotiate
940 * their address, and they didn't send their address, then we
941 * send a NAK with a CI_ADDR option appended. We assume the
942 * input buffer is long enough that we can append the extra
945 if (rc != CONFREJ && !ho->neg_addr &&
946 wo->req_addr && !reject_if_disagree) {
949 ucp = inp; /* reset pointer */
950 wo->req_addr = 0; /* don't ask again */
952 PUTCHAR(CI_ADDR, ucp);
953 PUTCHAR(CILEN_ADDR, ucp);
954 tl = ntohl(wo->hisaddr);
958 *len = ucp - inp; /* Compute output length */
959 IPCPDEBUG((LOG_INFO, "ipcp: returning Configure-%s", CODENAME(rc)));
960 return (rc); /* Return final code */
965 * ipcp_up - IPCP has come UP.
967 * Configure the IP network interface appropriately and bring it up.
974 ipcp_options *ho = &ipcp_hisoptions[f->unit];
975 ipcp_options *go = &ipcp_gotoptions[f->unit];
977 IPCPDEBUG((LOG_INFO, "ipcp: up"));
978 go->default_route = 0;
982 * We must have a non-zero IP address for both ends of the link.
985 ho->hisaddr = ipcp_wantoptions[f->unit].hisaddr;
987 if (ho->hisaddr == 0) {
988 syslog(LOG_ERR, "Could not determine remote IP address");
992 if (go->ouraddr == 0) {
993 syslog(LOG_ERR, "Could not determine local IP address");
999 * Check that the peer is allowed to use the IP address it wants.
1001 if (!auth_ip_addr(f->unit, ho->hisaddr)) {
1002 syslog(LOG_ERR, "Peer is not authorized to use remote address %s",
1003 ip_ntoa(ho->hisaddr));
1004 ipcp_close(f->unit);
1008 syslog(LOG_NOTICE, "local IP address %s", ip_ntoa(go->ouraddr));
1009 syslog(LOG_NOTICE, "remote IP address %s", ip_ntoa(ho->hisaddr));
1012 * Set IP addresses and (if specified) netmask.
1014 mask = GetMask(go->ouraddr);
1015 if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
1016 IPCPDEBUG((LOG_WARNING, "sifaddr failed"));
1017 ipcp_close(f->unit);
1021 /* set tcp compression */
1022 sifvjcomp(f->unit, ho->neg_vj, ho->cflag, ho->maxslotindex);
1024 /* bring the interface up for IP */
1025 if (!sifup(f->unit)) {
1026 IPCPDEBUG((LOG_WARNING, "sifup failed"));
1027 ipcp_close(f->unit);
1031 /* assign a default route through the interface if required */
1032 if (ipcp_wantoptions[f->unit].default_route)
1033 if (sifdefaultroute(f->unit, ho->hisaddr))
1034 go->default_route = 1;
1036 /* Make a proxy ARP entry if requested. */
1037 if (ipcp_wantoptions[f->unit].proxy_arp)
1038 if (sifproxyarp(f->unit, ho->hisaddr))
1042 * Execute the ip-up script, like this:
1043 * /etc/ppp/ip-up interface tty speed local-IP remote-IP
1045 ipcp_script(f, _PATH_IPUP);
1051 * ipcp_down - IPCP has gone DOWN.
1053 * Take the IP network interface down, clear its addresses
1054 * and delete routes through it.
1060 u_int32_t ouraddr, hisaddr;
1062 IPCPDEBUG((LOG_INFO, "ipcp: down"));
1064 ouraddr = ipcp_gotoptions[f->unit].ouraddr;
1065 hisaddr = ipcp_hisoptions[f->unit].hisaddr;
1066 if (ipcp_gotoptions[f->unit].proxy_arp)
1067 cifproxyarp(f->unit, hisaddr);
1068 if (ipcp_gotoptions[f->unit].default_route)
1069 cifdefaultroute(f->unit, hisaddr);
1071 cifaddr(f->unit, ouraddr, hisaddr);
1073 /* Execute the ip-down script */
1074 ipcp_script(f, _PATH_IPDOWN);
1079 * ipcp_script - Execute a script with arguments
1080 * interface-name tty-name speed local-IP remote-IP.
1083 ipcp_script(f, script)
1087 char strspeed[32], strlocal[32], strremote[32];
1090 sprintf(strspeed, "%d", baud_rate);
1091 strcpy(strlocal, ip_ntoa(ipcp_gotoptions[f->unit].ouraddr));
1092 strcpy(strremote, ip_ntoa(ipcp_hisoptions[f->unit].hisaddr));
1099 argv[5] = strremote;
1102 run_program(script, argv, 0);
1106 * ipcp_printpkt - print the contents of an IPCP packet.
1108 char *ipcp_codenames[] = {
1109 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1110 "TermReq", "TermAck", "CodeRej"
1114 ipcp_printpkt(p, plen, printer, arg)
1120 int code, id, len, olen;
1121 u_char *pstart, *optend;
1125 if (plen < HEADERLEN)
1131 if (len < HEADERLEN || len > plen)
1134 if (code >= 1 && code <= sizeof(ipcp_codenames) / sizeof(char *))
1135 printer(arg, " %s", ipcp_codenames[code-1]);
1137 printer(arg, " code=0x%x", code);
1138 printer(arg, " id=0x%x", id);
1145 /* print option list */
1150 if (olen < 2 || olen > len) {
1158 if (olen == CILEN_ADDRS) {
1161 printer(arg, "addrs %s", ip_ntoa(htonl(cilong)));
1163 printer(arg, " %s", ip_ntoa(htonl(cilong)));
1166 case CI_COMPRESSTYPE:
1167 if (olen >= CILEN_COMPRESS) {
1169 GETSHORT(cishort, p);
1170 printer(arg, "compress ");
1175 case IPCP_VJ_COMP_OLD:
1176 printer(arg, "old-VJ");
1179 printer(arg, "0x%x", cishort);
1184 if (olen == CILEN_ADDR) {
1187 printer(arg, "addr %s", ip_ntoa(htonl(cilong)));
1191 while (p < optend) {
1193 printer(arg, " %.2x", code);
1200 /* print the rest of the bytes in the packet */
1201 for (; len > 0; --len) {
1203 printer(arg, " %.2x", code);