]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/ipcp.c
old DLPI doesn't have dl_sap_length
[ppp.git] / pppd / ipcp.c
index 49144056c92600a21af1fed129cac18016458e8c..2566fc82e0ddc1663bbc300a15c94bae16969399 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: ipcp.c,v 1.6 1994/05/24 05:57:56 paulus Exp $";
+static char rcsid[] = "$Id: ipcp.c,v 1.21 1995/08/17 11:57:12 paulus Exp $";
 #endif
 
 /*
@@ -30,44 +30,37 @@ static char rcsid[] = "$Id: ipcp.c,v 1.6 1994/05/24 05:57:56 paulus Exp $";
 #include <syslog.h>
 #include <sys/types.h>
 #include <sys/socket.h>
-
-#include <net/if.h>
-#include <net/if_ppp.h>
+#include <netinet/in.h>
 
 #include "pppd.h"
-#include "ppp.h"
 #include "fsm.h"
 #include "ipcp.h"
 #include "pathnames.h"
 
 /* global vars */
-ipcp_options ipcp_wantoptions[NPPP];   /* Options that we want to request */
-ipcp_options ipcp_gotoptions[NPPP];    /* Options that peer ack'd */
-ipcp_options ipcp_allowoptions[NPPP];  /* Options we allow peer to request */
-ipcp_options ipcp_hisoptions[NPPP];    /* Options that we ack'd */
-
-extern char ifname[];
-extern char devname[];
-extern int baud_rate;
+ipcp_options ipcp_wantoptions[NUM_PPP];        /* Options that we want to request */
+ipcp_options ipcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
+ipcp_options ipcp_allowoptions[NUM_PPP];       /* Options we allow peer to request */
+ipcp_options ipcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
 
 /* local vars */
-static int cis_received[NPPP];         /* # Conf-Reqs received */
+static int cis_received[NUM_PPP];              /* # Conf-Reqs received */
 
 /*
  * Callbacks for fsm code.  (CI = Configuration Information)
  */
-static void ipcp_resetci __ARGS((fsm *));      /* Reset our CI */
-static int  ipcp_cilen __ARGS((fsm *));                /* Return length of our CI */
-static void ipcp_addci __ARGS((fsm *, u_char *, int *)); /* Add our CI */
-static int  ipcp_ackci __ARGS((fsm *, u_char *, int)); /* Peer ack'd our CI */
-static int  ipcp_nakci __ARGS((fsm *, u_char *, int)); /* Peer nak'd our CI */
-static int  ipcp_rejci __ARGS((fsm *, u_char *, int)); /* Peer rej'd our CI */
-static int  ipcp_reqci __ARGS((fsm *, u_char *, int *, int)); /* Rcv CI */
-static void ipcp_up __ARGS((fsm *));           /* We're UP */
-static void ipcp_down __ARGS((fsm *));         /* We're DOWN */
-static void ipcp_script __ARGS((fsm *, char *)); /* Run an up/down script */
-
-fsm ipcp_fsm[NPPP];            /* IPCP fsm structure */
+static void ipcp_resetci __P((fsm *)); /* Reset our CI */
+static int  ipcp_cilen __P((fsm *));           /* Return length of our CI */
+static void ipcp_addci __P((fsm *, u_char *, int *)); /* Add our CI */
+static int  ipcp_ackci __P((fsm *, u_char *, int));    /* Peer ack'd our CI */
+static int  ipcp_nakci __P((fsm *, u_char *, int));    /* Peer nak'd our CI */
+static int  ipcp_rejci __P((fsm *, u_char *, int));    /* Peer rej'd our CI */
+static int  ipcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv CI */
+static void ipcp_up __P((fsm *));              /* We're UP */
+static void ipcp_down __P((fsm *));            /* We're DOWN */
+static void ipcp_script __P((fsm *, char *)); /* Run an up/down script */
+
+fsm ipcp_fsm[NUM_PPP];         /* IPCP fsm structure */
 
 static fsm_callbacks ipcp_callbacks = { /* IPCP callback routines */
     ipcp_resetci,              /* Reset our Configuration Information */
@@ -106,7 +99,7 @@ static fsm_callbacks ipcp_callbacks = { /* IPCP callback routines */
  */
 char *
 ip_ntoa(ipaddr)
-u_long ipaddr;
+u_int32_t ipaddr;
 {
     static char b[64];
 
@@ -133,7 +126,7 @@ ipcp_init(unit)
     ipcp_options *ao = &ipcp_allowoptions[unit];
 
     f->unit = unit;
-    f->protocol = IPCP;
+    f->protocol = PPP_IPCP;
     f->callbacks = &ipcp_callbacks;
     fsm_init(&ipcp_fsm[unit]);
 
@@ -156,6 +149,13 @@ ipcp_init(unit)
     ao->neg_vj = 1;
     ao->maxslotindex = MAX_STATES - 1;
     ao->cflag = 1;
+
+    /*
+     * XXX These control whether the user may use the proxyarp
+     * and defaultroute options.
+     */
+    ao->proxy_arp = 1;
+    ao->default_route = 1;
 }
 
 
@@ -299,7 +299,7 @@ ipcp_addci(f, ucp, lenp)
     if (neg) { \
        int addrlen = (old? CILEN_ADDRS: CILEN_ADDR); \
        if (len >= addrlen) { \
-           u_long l; \
+           u_int32_t l; \
            PUTCHAR(opt, ucp); \
            PUTCHAR(addrlen, ucp); \
            l = ntohl(val1); \
@@ -362,7 +362,7 @@ ipcp_ackci(f, p, len)
 {
     ipcp_options *go = &ipcp_gotoptions[f->unit];
     u_short cilen, citype, cishort;
-    u_long cilong;
+    u_int32_t cilong;
     u_char cimaxslotindex, cicflag;
 
     /*
@@ -397,7 +397,7 @@ ipcp_ackci(f, p, len)
 #define ACKCIADDR(opt, neg, old, val1, val2) \
     if (neg) { \
        int addrlen = (old? CILEN_ADDRS: CILEN_ADDR); \
-       u_long l; \
+       u_int32_t l; \
        if ((len -= addrlen) < 0) \
            goto bad; \
        GETCHAR(citype, p); \
@@ -454,7 +454,7 @@ ipcp_nakci(f, p, len)
     u_char cimaxslotindex, cicflag;
     u_char citype, cilen, *next;
     u_short cishort;
-    u_long ciaddr1, ciaddr2, l;
+    u_int32_t ciaddr1, ciaddr2, l;
     ipcp_options no;           /* options we've seen Naks for */
     ipcp_options try;          /* options to request next time */
 
@@ -493,10 +493,6 @@ ipcp_nakci(f, p, len)
        len -= cilen; \
        INCPTR(2, p); \
        GETSHORT(cishort, p); \
-       if (cilen == CILEN_VJ) { \
-           GETCHAR(cimaxslotindex, p); \
-            GETCHAR(cicflag, p); \
-        } \
        no.neg = 1; \
         code \
     }
@@ -505,7 +501,7 @@ ipcp_nakci(f, p, len)
      * Accept the peer's idea of {our,his} address, if different
      * from our idea, only if the accept_{local,remote} flag is set.
      */
-    NAKCIADDR(CI_ADDR, neg_addr, go->old_addrs,
+    NAKCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), neg_addr, go->old_addrs,
              if (go->accept_local && ciaddr1) { /* Do we know our address? */
                  try.ouraddr = ciaddr1;
                  IPCPDEBUG((LOG_INFO, "local IP address %s",
@@ -526,6 +522,8 @@ ipcp_nakci(f, p, len)
      */
     NAKCIVJ(CI_COMPRESSTYPE, neg_vj,
            if (cilen == CILEN_VJ) {
+               GETCHAR(cimaxslotindex, p);
+               GETCHAR(cicflag, p);
                if (cishort == IPCP_VJ_COMP) {
                    try.old_vj = 0;
                    if (cimaxslotindex < go->maxslotindex)
@@ -584,16 +582,15 @@ ipcp_nakci(f, p, len)
        case CI_ADDR:
            if (go->neg_addr || no.neg_addr || cilen != CILEN_ADDR)
                goto bad;
-           try.neg_addr = 1;
            try.old_addrs = 0;
            GETLONG(l, p);
            ciaddr1 = htonl(l);
            if (ciaddr1 && go->accept_local)
                try.ouraddr = ciaddr1;
+           if (try.ouraddr != 0)
+               try.neg_addr = 1;
            no.neg_addr = 1;
            break;
-       default:
-           goto bad;
        }
        p = next;
     }
@@ -628,7 +625,7 @@ ipcp_rejci(f, p, len)
     ipcp_options *go = &ipcp_gotoptions[f->unit];
     u_char cimaxslotindex, ciflag, cilen;
     u_short cishort;
-    u_long cilong;
+    u_int32_t cilong;
     ipcp_options try;          /* options to request next time */
 
     try = *go;
@@ -642,7 +639,7 @@ ipcp_rejci(f, p, len)
        len >= (cilen = old? CILEN_ADDRS: CILEN_ADDR) && \
        p[1] == cilen && \
        p[0] == opt) { \
-       u_long l; \
+       u_int32_t l; \
        len -= cilen; \
        INCPTR(2, p); \
        GETLONG(l, p); \
@@ -727,7 +724,7 @@ ipcp_reqci(f, inp, len, reject_if_disagree)
     u_char *cip, *next;                /* Pointer to current and next CIs */
     u_short cilen, citype;     /* Parsed len, type */
     u_short cishort;           /* Parsed short value */
-    u_long tl, ciaddr1, ciaddr2;/* Parsed address values */
+    u_int32_t tl, ciaddr1, ciaddr2;/* Parsed address values */
     int rc = CONFACK;          /* Final packet return code */
     int orc;                   /* Individual option return code */
     u_char *p;                 /* Pointer to next char to parse */
@@ -783,10 +780,17 @@ ipcp_reqci(f, inp, len, reject_if_disagree)
                && (ciaddr1 == 0 || !wo->accept_remote)) {
                orc = CONFNAK;
                if (!reject_if_disagree) {
-                   DECPTR(sizeof (long), p);
+                   DECPTR(sizeof(u_int32_t), p);
                    tl = ntohl(wo->hisaddr);
                    PUTLONG(tl, p);
                }
+           } else if (ciaddr1 == 0 && wo->hisaddr == 0) {
+               /*
+                * If neither we nor he knows his address, reject the option.
+                */
+               orc = CONFREJ;
+               wo->req_addr = 0;       /* don't NAK with 0.0.0.0 later */
+               break;
            }
 
            /*
@@ -800,7 +804,7 @@ ipcp_reqci(f, inp, len, reject_if_disagree)
                if (ciaddr2 == 0 || !wo->accept_local) {
                    orc = CONFNAK;
                    if (!reject_if_disagree) {
-                       DECPTR(sizeof (long), p);
+                       DECPTR(sizeof(u_int32_t), p);
                        tl = ntohl(wo->ouraddr);
                        PUTLONG(tl, p);
                    }
@@ -837,10 +841,17 @@ ipcp_reqci(f, inp, len, reject_if_disagree)
                && (ciaddr1 == 0 || !wo->accept_remote)) {
                orc = CONFNAK;
                if (!reject_if_disagree) {
-                   DECPTR(sizeof (long), p);
+                   DECPTR(sizeof(u_int32_t), p);
                    tl = ntohl(wo->hisaddr);
                    PUTLONG(tl, p);
                }
+           } else if (ciaddr1 == 0 && wo->hisaddr == 0) {
+               /*
+                * Don't ACK an address of 0.0.0.0 - reject it instead.
+                */
+               orc = CONFREJ;
+               wo->req_addr = 0;       /* don't NAK with 0.0.0.0 later */
+               break;
            }
        
            ho->neg_addr = 1;
@@ -883,7 +894,7 @@ ipcp_reqci(f, inp, len, reject_if_disagree)
                    }
                }
                ho->maxslotindex = maxslotindex;
-               ho->cflag = wo->cflag;
+               ho->cflag = cflag;
            } else {
                ho->old_vj = 1;
                ho->maxslotindex = MAX_STATES - 1;
@@ -965,7 +976,7 @@ static void
 ipcp_up(f)
     fsm *f;
 {
-    u_long mask;
+    u_int32_t mask;
     ipcp_options *ho = &ipcp_hisoptions[f->unit];
     ipcp_options *go = &ipcp_gotoptions[f->unit];
 
@@ -1052,7 +1063,7 @@ static void
 ipcp_down(f)
     fsm *f;
 {
-    u_long ouraddr, hisaddr;
+    u_int32_t ouraddr, hisaddr;
 
     IPCPDEBUG((LOG_INFO, "ipcp: down"));
 
@@ -1088,11 +1099,12 @@ ipcp_script(f, script)
 
     argv[0] = script;
     argv[1] = ifname;
-    argv[2] = devname;
+    argv[2] = devnam;
     argv[3] = strspeed;
     argv[4] = strlocal;
     argv[5] = strremote;
-    argv[6] = NULL;
+    argv[6] = ipparam;
+    argv[7] = NULL;
     run_program(script, argv, 0);
 }
 
@@ -1114,7 +1126,7 @@ ipcp_printpkt(p, plen, printer, arg)
     int code, id, len, olen;
     u_char *pstart, *optend;
     u_short cishort;
-    u_long cilong;
+    u_int32_t cilong;
 
     if (plen < HEADERLEN)
        return 0;