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.19.2.1 1995/06/01 07:01:26 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 */
48 static int default_route_set[NUM_PPP]; /* Have set up a default route */
49 static int proxy_arp_set[NUM_PPP]; /* Have created proxy arp entry */
52 * Callbacks for fsm code. (CI = Configuration Information)
54 static void ipcp_resetci __P((fsm *)); /* Reset our CI */
55 static int ipcp_cilen __P((fsm *)); /* Return length of our CI */
56 static void ipcp_addci __P((fsm *, u_char *, int *)); /* Add our CI */
57 static int ipcp_ackci __P((fsm *, u_char *, int)); /* Peer ack'd our CI */
58 static int ipcp_nakci __P((fsm *, u_char *, int)); /* Peer nak'd our CI */
59 static int ipcp_rejci __P((fsm *, u_char *, int)); /* Peer rej'd our CI */
60 static int ipcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv CI */
61 static void ipcp_up __P((fsm *)); /* We're UP */
62 static void ipcp_down __P((fsm *)); /* We're DOWN */
63 static void ipcp_script __P((fsm *, char *)); /* Run an up/down script */
64 static void ipcp_finished __P((fsm *)); /* Don't need lower layer */
66 fsm ipcp_fsm[NUM_PPP]; /* IPCP fsm structure */
68 static fsm_callbacks ipcp_callbacks = { /* IPCP callback routines */
69 ipcp_resetci, /* Reset our Configuration Information */
70 ipcp_cilen, /* Length of our Configuration Information */
71 ipcp_addci, /* Add our Configuration Information */
72 ipcp_ackci, /* ACK our Configuration Information */
73 ipcp_nakci, /* NAK our Configuration Information */
74 ipcp_rejci, /* Reject our Configuration Information */
75 ipcp_reqci, /* Request peer's Configuration Information */
76 ipcp_up, /* Called when fsm reaches OPENED state */
77 ipcp_down, /* Called when fsm leaves OPENED state */
78 NULL, /* Called when we want the lower layer up */
79 ipcp_finished, /* Called when we want the lower layer down */
80 NULL, /* Called when Protocol-Reject received */
81 NULL, /* Retransmission is necessary */
82 NULL, /* Called to handle protocol-specific codes */
83 "IPCP" /* String name of protocol */
87 * Lengths of configuration options.
90 #define CILEN_COMPRESS 4 /* min length for compression protocol opt. */
91 #define CILEN_VJ 6 /* length for RFC1332 Van-Jacobson opt. */
92 #define CILEN_ADDR 6 /* new-style single address option */
93 #define CILEN_ADDRS 10 /* old-style dual address option */
96 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
97 (x) == CONFNAK ? "NAK" : "REJ")
101 * Make a string representation of a network IP address.
109 ipaddr = ntohl(ipaddr);
111 sprintf(b, "%d.%d.%d.%d",
112 (u_char)(ipaddr >> 24),
113 (u_char)(ipaddr >> 16),
114 (u_char)(ipaddr >> 8),
121 * ipcp_init - Initialize IPCP.
127 fsm *f = &ipcp_fsm[unit];
128 ipcp_options *wo = &ipcp_wantoptions[unit];
129 ipcp_options *ao = &ipcp_allowoptions[unit];
132 f->protocol = PPP_IPCP;
133 f->callbacks = &ipcp_callbacks;
134 fsm_init(&ipcp_fsm[unit]);
143 wo->vj_protocol = IPCP_VJ_COMP;
144 wo->maxslotindex = MAX_STATES - 1; /* really max index */
147 /* max slots and slot-id compression are currently hardwired in */
148 /* ppp_if.c to 16 and 1, this needs to be changed (among other */
153 ao->maxslotindex = MAX_STATES - 1;
155 ao->default_route = 1;
161 * ipcp_open - IPCP is allowed to come up.
167 fsm_open(&ipcp_fsm[unit]);
172 * ipcp_close - Take IPCP down.
178 fsm_close(&ipcp_fsm[unit]);
183 * ipcp_lowerup - The lower layer is up.
189 fsm_lowerup(&ipcp_fsm[unit]);
194 * ipcp_lowerdown - The lower layer is down.
200 fsm_lowerdown(&ipcp_fsm[unit]);
205 * ipcp_input - Input IPCP packet.
208 ipcp_input(unit, p, len)
213 fsm_input(&ipcp_fsm[unit], p, len);
218 * ipcp_protrej - A Protocol-Reject was received for IPCP.
220 * Pretend the lower layer went down, so we shut up.
226 fsm_lowerdown(&ipcp_fsm[unit]);
231 * ipcp_resetci - Reset our CI.
237 ipcp_options *wo = &ipcp_wantoptions[f->unit];
239 wo->req_addr = wo->neg_addr && ipcp_allowoptions[f->unit].neg_addr;
240 if (wo->ouraddr == 0)
241 wo->accept_local = 1;
242 if (wo->hisaddr == 0)
243 wo->accept_remote = 1;
244 ipcp_gotoptions[f->unit] = *wo;
245 cis_received[f->unit] = 0;
250 * ipcp_cilen - Return length of our CI.
256 ipcp_options *go = &ipcp_gotoptions[f->unit];
258 #define LENCIVJ(neg, old) (neg ? (old? CILEN_COMPRESS : CILEN_VJ) : 0)
259 #define LENCIADDR(neg, old) (neg ? (old? CILEN_ADDRS : CILEN_ADDR) : 0)
261 return (LENCIADDR(go->neg_addr, go->old_addrs) +
262 LENCIVJ(go->neg_vj, go->old_vj));
267 * ipcp_addci - Add our desired CIs to a packet.
270 ipcp_addci(f, ucp, lenp)
275 ipcp_options *wo = &ipcp_wantoptions[f->unit];
276 ipcp_options *go = &ipcp_gotoptions[f->unit];
277 ipcp_options *ho = &ipcp_hisoptions[f->unit];
280 #define ADDCIVJ(opt, neg, val, old, maxslotindex, cflag) \
282 int vjlen = old? CILEN_COMPRESS : CILEN_VJ; \
283 if (len >= vjlen) { \
285 PUTCHAR(vjlen, ucp); \
286 PUTSHORT(val, ucp); \
288 PUTCHAR(maxslotindex, ucp); \
289 PUTCHAR(cflag, ucp); \
296 #define ADDCIADDR(opt, neg, old, val1, val2) \
298 int addrlen = (old? CILEN_ADDRS: CILEN_ADDR); \
299 if (len >= addrlen) { \
302 PUTCHAR(addrlen, ucp); \
315 * First see if we want to change our options to the old
316 * forms because we have received old forms from the peer.
318 if (wo->neg_addr && !go->neg_addr && !go->old_addrs) {
319 /* use the old style of address negotiation */
323 if (wo->neg_vj && !go->neg_vj && !go->old_vj) {
324 /* try an older style of VJ negotiation */
325 if (cis_received[f->unit] == 0) {
326 /* keep trying the new style until we see some CI from the peer */
329 /* use the old style only if the peer did */
330 if (ho->neg_vj && ho->old_vj) {
333 go->vj_protocol = ho->vj_protocol;
338 ADDCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), go->neg_addr,
339 go->old_addrs, go->ouraddr, go->hisaddr);
341 ADDCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol, go->old_vj,
342 go->maxslotindex, go->cflag);
349 * ipcp_ackci - Ack our CIs.
356 ipcp_ackci(f, p, len)
361 ipcp_options *go = &ipcp_gotoptions[f->unit];
362 u_short cilen, citype, cishort;
364 u_char cimaxslotindex, cicflag;
367 * CIs must be in exactly the same order that we sent...
368 * Check packet length and CI length at each step.
369 * If we find any deviations, then this packet is bad.
372 #define ACKCIVJ(opt, neg, val, old, maxslotindex, cflag) \
374 int vjlen = old? CILEN_COMPRESS : CILEN_VJ; \
375 if ((len -= vjlen) < 0) \
377 GETCHAR(citype, p); \
379 if (cilen != vjlen || \
382 GETSHORT(cishort, p); \
383 if (cishort != val) \
386 GETCHAR(cimaxslotindex, p); \
387 if (cimaxslotindex != maxslotindex) \
389 GETCHAR(cicflag, p); \
390 if (cicflag != cflag) \
395 #define ACKCIADDR(opt, neg, old, val1, val2) \
397 int addrlen = (old? CILEN_ADDRS: CILEN_ADDR); \
399 if ((len -= addrlen) < 0) \
401 GETCHAR(citype, p); \
403 if (cilen != addrlen || \
408 if (val1 != cilong) \
413 if (val2 != cilong) \
418 ACKCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), go->neg_addr,
419 go->old_addrs, go->ouraddr, go->hisaddr);
421 ACKCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol, go->old_vj,
422 go->maxslotindex, go->cflag);
425 * If there are any remaining CIs, then this packet is bad.
432 IPCPDEBUG((LOG_INFO, "ipcp_ackci: received bad Ack!"));
437 * ipcp_nakci - Peer has sent a NAK for some of our CIs.
438 * This should not modify any state if the Nak is bad
439 * or if IPCP is in the OPENED state.
446 ipcp_nakci(f, p, len)
451 ipcp_options *go = &ipcp_gotoptions[f->unit];
452 u_char cimaxslotindex, cicflag;
453 u_char citype, cilen, *next;
455 u_int32_t ciaddr1, ciaddr2, l;
456 ipcp_options no; /* options we've seen Naks for */
457 ipcp_options try; /* options to request next time */
459 BZERO(&no, sizeof(no));
463 * Any Nak'd CIs must be in exactly the same order that we sent.
464 * Check packet length and CI length at each step.
465 * If we find any deviations, then this packet is bad.
467 #define NAKCIADDR(opt, neg, old, code) \
469 len >= (cilen = (old? CILEN_ADDRS: CILEN_ADDR)) && \
475 ciaddr1 = htonl(l); \
478 ciaddr2 = htonl(l); \
486 #define NAKCIVJ(opt, neg, code) \
488 ((cilen = p[1]) == CILEN_COMPRESS || cilen == CILEN_VJ) && \
493 GETSHORT(cishort, p); \
499 * Accept the peer's idea of {our,his} address, if different
500 * from our idea, only if the accept_{local,remote} flag is set.
502 NAKCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), neg_addr, go->old_addrs,
503 if (go->accept_local && ciaddr1) { /* Do we know our address? */
504 try.ouraddr = ciaddr1;
505 IPCPDEBUG((LOG_INFO, "local IP address %s",
508 if (go->accept_remote && ciaddr2) { /* Does he know his? */
509 try.hisaddr = ciaddr2;
510 IPCPDEBUG((LOG_INFO, "remote IP address %s",
516 * Accept the peer's value of maxslotindex provided that it
517 * is less than what we asked for. Turn off slot-ID compression
518 * if the peer wants. Send old-style compress-type option if
521 NAKCIVJ(CI_COMPRESSTYPE, neg_vj,
522 if (cilen == CILEN_VJ) {
523 GETCHAR(cimaxslotindex, p);
525 if (cishort == IPCP_VJ_COMP) {
527 if (cimaxslotindex < go->maxslotindex)
528 try.maxslotindex = cimaxslotindex;
535 if (cishort == IPCP_VJ_COMP || cishort == IPCP_VJ_COMP_OLD) {
537 try.vj_protocol = cishort;
545 * There may be remaining CIs, if the peer is requesting negotiation
546 * on an option that we didn't include in our request packet.
547 * If they want to negotiate about IP addresses, we comply.
548 * If they want us to ask for compression, we refuse.
550 while (len > CILEN_VOID) {
553 if( (len -= cilen) < 0 )
555 next = p + cilen - 2;
558 case CI_COMPRESSTYPE:
559 if (go->neg_vj || no.neg_vj ||
560 (cilen != CILEN_VJ && cilen != CILEN_COMPRESS))
565 if (go->neg_addr && go->old_addrs || no.old_addrs
566 || cilen != CILEN_ADDRS)
572 if (ciaddr1 && go->accept_local)
573 try.ouraddr = ciaddr1;
576 if (ciaddr2 && go->accept_remote)
577 try.hisaddr = ciaddr2;
581 if (go->neg_addr || no.neg_addr || cilen != CILEN_ADDR)
586 if (ciaddr1 && go->accept_local)
587 try.ouraddr = ciaddr1;
588 if (try.ouraddr != 0)
598 /* If there is still anything left, this packet is bad. */
603 * OK, the Nak is good. Now we can update state.
605 if (f->state != OPENED)
611 IPCPDEBUG((LOG_INFO, "ipcp_nakci: received bad Nak!"));
617 * ipcp_rejci - Reject some of our CIs.
620 ipcp_rejci(f, p, len)
625 ipcp_options *go = &ipcp_gotoptions[f->unit];
626 u_char cimaxslotindex, ciflag, cilen;
629 ipcp_options try; /* options to request next time */
633 * Any Rejected CIs must be in exactly the same order that we sent.
634 * Check packet length and CI length at each step.
635 * If we find any deviations, then this packet is bad.
637 #define REJCIADDR(opt, neg, old, val1, val2) \
639 len >= (cilen = old? CILEN_ADDRS: CILEN_ADDR) && \
647 /* Check rejected value. */ \
648 if (cilong != val1) \
653 /* Check rejected value. */ \
654 if (cilong != val2) \
660 #define REJCIVJ(opt, neg, val, old, maxslot, cflag) \
662 p[1] == (old? CILEN_COMPRESS : CILEN_VJ) && \
667 GETSHORT(cishort, p); \
668 /* Check rejected value. */ \
669 if (cishort != val) \
672 GETCHAR(cimaxslotindex, p); \
673 if (cimaxslotindex != maxslot) \
675 GETCHAR(ciflag, p); \
676 if (ciflag != cflag) \
682 REJCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), neg_addr,
683 go->old_addrs, go->ouraddr, go->hisaddr);
685 REJCIVJ(CI_COMPRESSTYPE, neg_vj, go->vj_protocol, go->old_vj,
686 go->maxslotindex, go->cflag);
689 * If there are any remaining CIs, then this packet is bad.
694 * Now we can update state.
696 if (f->state != OPENED)
701 IPCPDEBUG((LOG_INFO, "ipcp_rejci: received bad Reject!"));
707 * ipcp_reqci - Check the peer's requested CIs and send appropriate response.
709 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
710 * appropriately. If reject_if_disagree is non-zero, doesn't return
711 * CONFNAK; returns CONFREJ if it can't return CONFACK.
714 ipcp_reqci(f, inp, len, reject_if_disagree)
716 u_char *inp; /* Requested CIs */
717 int *len; /* Length of requested CIs */
718 int reject_if_disagree;
720 ipcp_options *wo = &ipcp_wantoptions[f->unit];
721 ipcp_options *ho = &ipcp_hisoptions[f->unit];
722 ipcp_options *ao = &ipcp_allowoptions[f->unit];
723 ipcp_options *go = &ipcp_gotoptions[f->unit];
724 u_char *cip, *next; /* Pointer to current and next CIs */
725 u_short cilen, citype; /* Parsed len, type */
726 u_short cishort; /* Parsed short value */
727 u_int32_t tl, ciaddr1, ciaddr2;/* Parsed address values */
728 int rc = CONFACK; /* Final packet return code */
729 int orc; /* Individual option return code */
730 u_char *p; /* Pointer to next char to parse */
731 u_char *ucp = inp; /* Pointer to current output char */
732 int l = *len; /* Length left */
733 u_char maxslotindex, cflag;
736 * Reset all his options.
738 BZERO(ho, sizeof(*ho));
741 * Process all his options.
745 orc = CONFACK; /* Assume success */
746 cip = p = next; /* Remember begining of CI */
747 if (l < 2 || /* Not enough data for CI header or */
748 p[1] < 2 || /* CI length too small or */
749 p[1] > l) { /* CI length too big? */
750 IPCPDEBUG((LOG_INFO, "ipcp_reqci: bad CI length!"));
751 orc = CONFREJ; /* Reject bad CI */
752 cilen = l; /* Reject till end of packet */
753 l = 0; /* Don't loop again */
756 GETCHAR(citype, p); /* Parse CI type */
757 GETCHAR(cilen, p); /* Parse CI length */
758 l -= cilen; /* Adjust remaining length */
759 next += cilen; /* Step to next CI */
761 switch (citype) { /* Check CI type */
763 IPCPDEBUG((LOG_INFO, "ipcp: received ADDRS "));
765 cilen != CILEN_ADDRS) { /* Check CI length */
766 orc = CONFREJ; /* Reject CI */
771 * If he has no address, or if we both have his address but
772 * disagree about it, then NAK it with our idea.
773 * In particular, if we don't know his address, but he does,
776 GETLONG(tl, p); /* Parse source address (his) */
778 IPCPDEBUG((LOG_INFO, "(%s:", ip_ntoa(ciaddr1)));
779 if (ciaddr1 != wo->hisaddr
780 && (ciaddr1 == 0 || !wo->accept_remote)) {
782 if (!reject_if_disagree) {
783 DECPTR(sizeof(u_int32_t), p);
784 tl = ntohl(wo->hisaddr);
787 } else if (ciaddr1 == 0 && wo->hisaddr == 0) {
789 * If neither we nor he knows his address, reject the option.
792 wo->req_addr = 0; /* don't NAK with 0.0.0.0 later */
797 * If he doesn't know our address, or if we both have our address
798 * but disagree about it, then NAK it with our idea.
800 GETLONG(tl, p); /* Parse desination address (ours) */
802 IPCPDEBUG((LOG_INFO, "%s)", ip_ntoa(ciaddr2)));
803 if (ciaddr2 != wo->ouraddr) {
804 if (ciaddr2 == 0 || !wo->accept_local) {
806 if (!reject_if_disagree) {
807 DECPTR(sizeof(u_int32_t), p);
808 tl = ntohl(wo->ouraddr);
812 go->ouraddr = ciaddr2; /* accept peer's idea */
818 ho->hisaddr = ciaddr1;
819 ho->ouraddr = ciaddr2;
823 IPCPDEBUG((LOG_INFO, "ipcp: received ADDR "));
826 cilen != CILEN_ADDR) { /* Check CI length */
827 orc = CONFREJ; /* Reject CI */
832 * If he has no address, or if we both have his address but
833 * disagree about it, then NAK it with our idea.
834 * In particular, if we don't know his address, but he does,
837 GETLONG(tl, p); /* Parse source address (his) */
839 IPCPDEBUG((LOG_INFO, "(%s)", ip_ntoa(ciaddr1)));
840 if (ciaddr1 != wo->hisaddr
841 && (ciaddr1 == 0 || !wo->accept_remote)) {
843 if (!reject_if_disagree) {
844 DECPTR(sizeof(u_int32_t), p);
845 tl = ntohl(wo->hisaddr);
848 } else if (ciaddr1 == 0 && wo->hisaddr == 0) {
850 * Don't ACK an address of 0.0.0.0 - reject it instead.
853 wo->req_addr = 0; /* don't NAK with 0.0.0.0 later */
858 ho->hisaddr = ciaddr1;
861 case CI_COMPRESSTYPE:
862 IPCPDEBUG((LOG_INFO, "ipcp: received COMPRESSTYPE "));
864 (cilen != CILEN_VJ && cilen != CILEN_COMPRESS)) {
868 GETSHORT(cishort, p);
869 IPCPDEBUG((LOG_INFO, "(%d)", cishort));
871 if (!(cishort == IPCP_VJ_COMP ||
872 (cishort == IPCP_VJ_COMP_OLD && cilen == CILEN_COMPRESS))) {
878 ho->vj_protocol = cishort;
879 if (cilen == CILEN_VJ) {
880 GETCHAR(maxslotindex, p);
881 if (maxslotindex > ao->maxslotindex) {
883 if (!reject_if_disagree){
885 PUTCHAR(ao->maxslotindex, p);
889 if (cflag && !ao->cflag) {
891 if (!reject_if_disagree){
893 PUTCHAR(wo->cflag, p);
896 ho->maxslotindex = maxslotindex;
900 ho->maxslotindex = MAX_STATES - 1;
911 IPCPDEBUG((LOG_INFO, " (%s)\n", CODENAME(orc)));
913 if (orc == CONFACK && /* Good CI */
914 rc != CONFACK) /* but prior CI wasnt? */
915 continue; /* Don't send this one */
917 if (orc == CONFNAK) { /* Nak this CI? */
918 if (reject_if_disagree) /* Getting fed up with sending NAKs? */
919 orc = CONFREJ; /* Get tough if so */
921 if (rc == CONFREJ) /* Rejecting prior CI? */
922 continue; /* Don't send this one */
923 if (rc == CONFACK) { /* Ack'd all prior CIs? */
924 rc = CONFNAK; /* Not anymore... */
925 ucp = inp; /* Backup */
930 if (orc == CONFREJ && /* Reject this CI */
931 rc != CONFREJ) { /* but no prior ones? */
933 ucp = inp; /* Backup */
936 /* Need to move CI? */
938 BCOPY(cip, ucp, cilen); /* Move it */
940 /* Update output pointer */
945 * If we aren't rejecting this packet, and we want to negotiate
946 * their address, and they didn't send their address, then we
947 * send a NAK with a CI_ADDR option appended. We assume the
948 * input buffer is long enough that we can append the extra
951 if (rc != CONFREJ && !ho->neg_addr &&
952 wo->req_addr && !reject_if_disagree) {
955 ucp = inp; /* reset pointer */
956 wo->req_addr = 0; /* don't ask again */
958 PUTCHAR(CI_ADDR, ucp);
959 PUTCHAR(CILEN_ADDR, ucp);
960 tl = ntohl(wo->hisaddr);
964 *len = ucp - inp; /* Compute output length */
965 IPCPDEBUG((LOG_INFO, "ipcp: returning Configure-%s", CODENAME(rc)));
966 return (rc); /* Return final code */
971 * ipcp_demand_conf - configure the interface as though
972 * IPCP were up, for use with dial-on-demand.
978 ipcp_options *wo = &ipcp_wantoptions[u];
980 if (!sifaddr(u, wo->ouraddr, wo->hisaddr, GetMask(wo->ouraddr)))
984 if (wo->default_route)
985 if (sifdefaultroute(u, wo->hisaddr))
986 default_route_set[u] = 1;
988 if (sifproxyarp(u, wo->hisaddr))
989 proxy_arp_set[u] = 1;
991 syslog(LOG_NOTICE, "local IP address %s", ip_ntoa(wo->ouraddr));
992 syslog(LOG_NOTICE, "remote IP address %s", ip_ntoa(wo->hisaddr));
999 * ipcp_demand_reset - reset the interface, which has been
1000 * configured for dial-on-demand.
1003 ipcp_demand_reset(u)
1006 ipcp_options *wo = &ipcp_wantoptions[u];
1008 if (proxy_arp_set[u]) {
1009 cifproxyarp(u, wo->hisaddr);
1010 proxy_arp_set[u] = 0;
1012 if (default_route_set[u]) {
1013 cifdefaultroute(u, wo->hisaddr);
1014 default_route_set[u] = 0;
1017 cifaddr(u, wo->ouraddr, wo->hisaddr);
1022 * ipcp_up - IPCP has come UP.
1024 * Configure the IP network interface appropriately and bring it up.
1031 ipcp_options *ho = &ipcp_hisoptions[f->unit];
1032 ipcp_options *go = &ipcp_gotoptions[f->unit];
1033 ipcp_options *wo = &ipcp_wantoptions[f->unit];
1035 np_up(f->unit, PPP_IP);
1036 IPCPDEBUG((LOG_INFO, "ipcp: up"));
1039 * We must have a non-zero IP address for both ends of the link.
1042 ho->hisaddr = wo->hisaddr;
1044 if (ho->hisaddr == 0) {
1045 syslog(LOG_ERR, "Could not determine remote IP address");
1046 ipcp_close(f->unit);
1049 if (go->ouraddr == 0) {
1050 syslog(LOG_ERR, "Could not determine local IP address");
1051 ipcp_close(f->unit);
1056 * Check that the peer is allowed to use the IP address it wants.
1058 if (!auth_ip_addr(f->unit, ho->hisaddr)) {
1059 syslog(LOG_ERR, "Peer is not authorized to use remote address %s",
1060 ip_ntoa(ho->hisaddr));
1061 ipcp_close(f->unit);
1065 /* set tcp compression */
1066 sifvjcomp(f->unit, ho->neg_vj, ho->cflag, ho->maxslotindex);
1069 * If we are doing dial-on-demand, the interface is already
1070 * configured, so we put out any saved-up packets, then set the
1071 * interface to pass IP packets.
1074 if (go->ouraddr != wo->ouraddr || ho->hisaddr != wo->hisaddr) {
1075 syslog(LOG_ERR, "Failed to negotiate desired IP addresses");
1076 ipcp_close(f->unit);
1079 demand_rexmit(PPP_IP);
1080 sifnpmode(f->unit, PPP_IP, NPMODE_PASS);
1085 * Set IP addresses and (if specified) netmask.
1087 mask = GetMask(go->ouraddr);
1088 if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
1089 IPCPDEBUG((LOG_WARNING, "sifaddr failed"));
1090 ipcp_close(f->unit);
1094 /* bring the interface up for IP */
1095 if (!sifup(f->unit)) {
1096 IPCPDEBUG((LOG_WARNING, "sifup failed"));
1097 ipcp_close(f->unit);
1101 /* assign a default route through the interface if required */
1102 if (ipcp_wantoptions[f->unit].default_route)
1103 if (sifdefaultroute(f->unit, ho->hisaddr))
1104 default_route_set[f->unit] = 1;
1106 /* Make a proxy ARP entry if requested. */
1107 if (ipcp_wantoptions[f->unit].proxy_arp)
1108 if (sifproxyarp(f->unit, ho->hisaddr))
1109 proxy_arp_set[f->unit] = 1;
1111 syslog(LOG_NOTICE, "local IP address %s", ip_ntoa(go->ouraddr));
1112 syslog(LOG_NOTICE, "remote IP address %s", ip_ntoa(ho->hisaddr));
1116 * Execute the ip-up script, like this:
1117 * /etc/ppp/ip-up interface tty speed local-IP remote-IP
1119 ipcp_script(f, _PATH_IPUP);
1125 * ipcp_down - IPCP has gone DOWN.
1127 * Take the IP network interface down, clear its addresses
1128 * and delete routes through it.
1134 u_int32_t ouraddr, hisaddr;
1136 np_down(f->unit, PPP_IP);
1137 IPCPDEBUG((LOG_INFO, "ipcp: down"));
1140 * If we are doing dial-on-demand, set the interface
1141 * to drop outgoing packets with an error (for now).
1144 sifnpmode(f->unit, PPP_IP, NPMODE_ERROR);
1147 ouraddr = ipcp_gotoptions[f->unit].ouraddr;
1148 hisaddr = ipcp_hisoptions[f->unit].hisaddr;
1149 if (proxy_arp_set[f->unit]) {
1150 cifproxyarp(f->unit, hisaddr);
1151 proxy_arp_set[f->unit] = 0;
1153 if (default_route_set[f->unit]) {
1154 cifdefaultroute(f->unit, hisaddr);
1155 default_route_set[f->unit] = 0;
1158 cifaddr(f->unit, ouraddr, hisaddr);
1161 /* Execute the ip-down script */
1162 ipcp_script(f, _PATH_IPDOWN);
1167 * ipcp_finished - possibly shut down the lower layers.
1173 np_finished(f->unit, PPP_IP);
1178 * ipcp_script - Execute a script with arguments
1179 * interface-name tty-name speed local-IP remote-IP.
1182 ipcp_script(f, script)
1186 char strspeed[32], strlocal[32], strremote[32];
1189 sprintf(strspeed, "%d", baud_rate);
1190 strcpy(strlocal, ip_ntoa(ipcp_gotoptions[f->unit].ouraddr));
1191 strcpy(strremote, ip_ntoa(ipcp_hisoptions[f->unit].hisaddr));
1198 argv[5] = strremote;
1201 run_program(script, argv, 0);
1205 * ipcp_printpkt - print the contents of an IPCP packet.
1207 char *ipcp_codenames[] = {
1208 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1209 "TermReq", "TermAck", "CodeRej"
1213 ipcp_printpkt(p, plen, printer, arg)
1219 int code, id, len, olen;
1220 u_char *pstart, *optend;
1224 if (plen < HEADERLEN)
1230 if (len < HEADERLEN || len > plen)
1233 if (code >= 1 && code <= sizeof(ipcp_codenames) / sizeof(char *))
1234 printer(arg, " %s", ipcp_codenames[code-1]);
1236 printer(arg, " code=0x%x", code);
1237 printer(arg, " id=0x%x", id);
1244 /* print option list */
1249 if (olen < 2 || olen > len) {
1257 if (olen == CILEN_ADDRS) {
1260 printer(arg, "addrs %s", ip_ntoa(htonl(cilong)));
1262 printer(arg, " %s", ip_ntoa(htonl(cilong)));
1265 case CI_COMPRESSTYPE:
1266 if (olen >= CILEN_COMPRESS) {
1268 GETSHORT(cishort, p);
1269 printer(arg, "compress ");
1274 case IPCP_VJ_COMP_OLD:
1275 printer(arg, "old-VJ");
1278 printer(arg, "0x%x", cishort);
1283 if (olen == CILEN_ADDR) {
1286 printer(arg, "addr %s", ip_ntoa(htonl(cilong)));
1290 while (p < optend) {
1292 printer(arg, " %.2x", code);
1299 /* print the rest of the bytes in the packet */
1300 for (; len > 0; --len) {
1302 printer(arg, " %.2x", code);