]> git.ozlabs.org Git - ppp.git/commitdiff
added accept_local and accept_remote flags to give better control
authorPaul Mackerras <paulus@samba.org>
Tue, 8 Feb 1994 23:49:52 +0000 (23:49 +0000)
committerPaul Mackerras <paulus@samba.org>
Tue, 8 Feb 1994 23:49:52 +0000 (23:49 +0000)
over whether we accept addresses from the peer.

pppd/ipcp.c
pppd/ipcp.h

index 08befff160c13c809de89ff479719d7d550ce486..36d53829e3090490e8fe087800297515f1e044d1 100644 (file)
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: ipcp.c,v 1.1 1993/11/11 03:54:25 paulus Exp $";
+static char rcsid[] = "$Id: ipcp.c,v 1.2 1994/02/08 23:49:52 paulus Exp $";
 #endif
 
 /*
  * TODO:
- * Fix IP address negotiation (wantoptions or hisoptions).
- * Don't set zero IP addresses.
  */
 
 #include <stdio.h>
@@ -242,6 +240,10 @@ ipcp_resetci(f)
     ipcp_options *wo = &ipcp_wantoptions[f->unit];
 
     wo->req_addr = wo->neg_addr && ipcp_allowoptions[f->unit].neg_addr;
+    if (wo->ouraddr == 0)
+       wo->accept_local = 1;
+    if (wo->hisaddr == 0)
+       wo->accept_remote = 1;
     ipcp_gotoptions[f->unit] = *wo;
     cis_received[f->unit] = 0;
 }
@@ -501,16 +503,16 @@ ipcp_nakci(f, p, len)
     }
 
     /*
-     * Accept the peer's idea of our address if we don't know it.
-     * Accept the peer's idea of his address if he knows it.
+     * 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,
-             if (!go->ouraddr && ciaddr1) {    /* Do we know our address? */
+             if (go->accept_local && ciaddr1) { /* Do we know our address? */
                  go->ouraddr = ciaddr1;
                  IPCPDEBUG((LOG_INFO, "local IP address %s",
                             ip_ntoa(ciaddr1)));
              }
-             if (ciaddr2) {                    /* Does he know his? */
+             if (go->accept_remote && ciaddr2) { /* Does he know his? */
                  go->hisaddr = ciaddr2;
                  IPCPDEBUG((LOG_INFO, "remote IP address %s",
                             ip_ntoa(ciaddr2)));
@@ -572,11 +574,11 @@ ipcp_nakci(f, p, len)
            try.old_addrs = 1;
            GETLONG(l, p);
            ciaddr1 = htonl(l);
-           if (ciaddr1)
+           if (ciaddr1 && go->accept_local)
                try.ouraddr = ciaddr1;
            GETLONG(l, p);
            ciaddr2 = htonl(l);
-           if (ciaddr2)
+           if (ciaddr2 && go->accept_remote)
                try.hisaddr = ciaddr2;
            no.old_addrs = 1;
            break;
@@ -587,7 +589,7 @@ ipcp_nakci(f, p, len)
            try.old_addrs = 0;
            GETLONG(l, p);
            ciaddr1 = htonl(l);
-           if (ciaddr1)
+           if (ciaddr1 && go->accept_local)
                try.ouraddr = ciaddr1;
            no.neg_addr = 1;
            break;
@@ -778,7 +780,8 @@ ipcp_reqci(f, inp, len, reject_if_disagree)
            GETLONG(tl, p);             /* Parse source address (his) */
            ciaddr1 = htonl(tl);
            IPCPDEBUG((LOG_INFO, "(%s:", ip_ntoa(ciaddr1)));
-           if (wo->hisaddr && ciaddr1 != wo->hisaddr) {
+           if (ciaddr1 != wo->hisaddr
+               && (ciaddr1 == 0 || !wo->accept_remote)) {
                orc = CONFNAK;
                if (!reject_if_disagree) {
                    DECPTR(sizeof (long), p);
@@ -794,12 +797,16 @@ ipcp_reqci(f, inp, len, reject_if_disagree)
            GETLONG(tl, p);             /* Parse desination address (ours) */
            ciaddr2 = htonl(tl);
            IPCPDEBUG((LOG_INFO, "%s)", ip_ntoa(ciaddr2)));
-           if (wo->ouraddr && ciaddr2 != wo->ouraddr) {
-               orc = CONFNAK;
-               if (!reject_if_disagree) {
-                   DECPTR(sizeof (long), p);
-                   tl = ntohl(wo->ouraddr);
-                   PUTLONG(tl, p);
+           if (ciaddr2 != wo->ouraddr) {
+               if (ciaddr2 == 0 || !wo->accept_local) {
+                   orc = CONFNAK;
+                   if (!reject_if_disagree) {
+                       DECPTR(sizeof (long), p);
+                       tl = ntohl(wo->ouraddr);
+                       PUTLONG(tl, p);
+                   }
+               } else {
+                   go->ouraddr = ciaddr2;      /* accept peer's idea */
                }
            }
            if (orc == CONFNAK)
@@ -829,7 +836,8 @@ ipcp_reqci(f, inp, len, reject_if_disagree)
            GETLONG(tl, p);     /* Parse source address (his) */
            ciaddr1 = htonl(tl);
            IPCPDEBUG((LOG_INFO, "(%s)", ip_ntoa(ciaddr1)));
-           if (wo->hisaddr && ciaddr1 != wo->hisaddr) {
+           if (ciaddr1 != wo->hisaddr
+               && (ciaddr1 == 0 || !wo->accept_remote)) {
                orc = CONFNAK;
                if (!reject_if_disagree) {
                    DECPTR(sizeof (long), p);
@@ -972,7 +980,7 @@ ipcp_up(f)
     /*
      * We must have a non-zero IP address for both ends of the link.
      */
-    if (ho->hisaddr == 0)
+    if (!ho->neg_addr)
        ho->hisaddr = ipcp_wantoptions[f->unit].hisaddr;
 
     if (ho->hisaddr == 0) {
index 8ebfe63f2365821d6881ba92ff19702d07bf669c..93c39b8f011ce71a5c297b8df1b3239ecceb1010 100644 (file)
@@ -16,7 +16,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * $Id: ipcp.h,v 1.1 1993/11/11 03:54:25 paulus Exp $
+ * $Id: ipcp.h,v 1.2 1994/02/08 23:49:37 paulus Exp $
  */
 
 /*
@@ -45,6 +45,8 @@ typedef struct ipcp_options {
     int proxy_arp : 1;         /* Make proxy ARP entry for peer? */
     int neg_vj : 1;            /* Van Jacobson Compression? */
     int old_vj : 1;            /* use old (short) form of VJ option? */
+    int accept_local : 1;      /* accept peer's value for ouraddr */
+    int accept_remote : 1;     /* accept peer's value for hisaddr */
     u_short vj_protocol;       /* protocol value to use in VJ option */
     u_char maxslotindex, cflag;        /* values for RFC1332 VJ compression neg. */
     u_long ouraddr, hisaddr;   /* Addresses in NETWORK BYTE ORDER */