]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/ipcp.c
set env vars with link stats
[ppp.git] / pppd / ipcp.c
index a0956d9903884a52b5d352daa978d7d1062d3658..aeac233bf816e1d60448dc0d15cb0cb01da41c67 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: ipcp.c,v 1.41 1999/03/16 22:54:38 paulus Exp $";
+static char rcsid[] = "$Id: ipcp.c,v 1.46 1999/05/13 00:35:23 paulus Exp $";
 #endif
 
 /*
@@ -48,7 +48,6 @@ ipcp_options ipcp_hisoptions[NUM_PPP];        /* Options that we ack'd */
 bool   disable_defaultip = 0;  /* Don't use hostname for default IP adrs */
 
 /* local vars */
-static int cis_received[NUM_PPP];      /* # Conf-Reqs received */
 static int default_route_set[NUM_PPP]; /* Have set up a default route */
 static int proxy_arp_set[NUM_PPP];     /* Have created proxy arp entry */
 static bool usepeerdns;                        /* Ask peer for DNS addrs */
@@ -450,7 +449,6 @@ ipcp_resetci(f)
     wo->req_dns1 = usepeerdns; /* Request DNS addresses from the peer */
     wo->req_dns2 = usepeerdns;
     ipcp_gotoptions[f->unit] = *wo;
-    cis_received[f->unit] = 0;
 }
 
 
@@ -481,16 +479,11 @@ ipcp_cilen(f)
     }
     if (wo->neg_vj && !go->neg_vj && !go->old_vj) {
        /* try an older style of VJ negotiation */
-       if (cis_received[f->unit] == 0) {
-           /* keep trying the new style until we see some CI from the peer */
+       /* use the old style only if the peer did */
+       if (ho->neg_vj && ho->old_vj) {
            go->neg_vj = 1;
-       } else {
-           /* use the old style only if the peer did */
-           if (ho->neg_vj && ho->old_vj) {
-               go->neg_vj = 1;
-               go->old_vj = 1;
-               go->vj_protocol = ho->vj_protocol;
-           }
+           go->old_vj = 1;
+           go->vj_protocol = ho->vj_protocol;
        }
     }
 
@@ -548,16 +541,15 @@ ipcp_addci(f, ucp, lenp)
            neg = 0; \
     }
 
-#define ADDCIDNS(opt, neg) \
+#define ADDCIDNS(opt, neg, addr) \
     if (neg) { \
-       int addrlen = CILEN_ADDR; \
-       if (len >= addrlen) { \
+       if (len >= CILEN_ADDR) { \
            u_int32_t l; \
            PUTCHAR(opt, ucp); \
-           PUTCHAR(addrlen, ucp); \
-           l = ntohl(0); \
+           PUTCHAR(CILEN_ADDR, ucp); \
+           l = ntohl(addr); \
            PUTLONG(l, ucp); \
-           len -= addrlen; \
+           len -= CILEN_ADDR; \
        } else \
            neg = 0; \
     }
@@ -568,9 +560,9 @@ ipcp_addci(f, ucp, lenp)
     ADDCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol, go->old_vj,
            go->maxslotindex, go->cflag);
 
-    ADDCIDNS(CI_MS_DNS1, go->req_dns1);
+    ADDCIDNS(CI_MS_DNS1, go->req_dns1, go->dnsaddr[0]);
 
-    ADDCIDNS(CI_MS_DNS2, go->req_dns2);
+    ADDCIDNS(CI_MS_DNS2, go->req_dns2, go->dnsaddr[1]);
 
     *lenp -= len;
 }
@@ -647,12 +639,31 @@ ipcp_ackci(f, p, len)
        } \
     }
 
+#define ACKCIDNS(opt, neg, addr) \
+    if (neg) { \
+       u_int32_t l; \
+       if ((len -= CILEN_ADDR) < 0) \
+           goto bad; \
+       GETCHAR(citype, p); \
+       GETCHAR(cilen, p); \
+       if (cilen != CILEN_ADDR || citype != opt) \
+           goto bad; \
+       GETLONG(l, p); \
+       cilong = htonl(l); \
+       if (addr != cilong) \
+           goto bad; \
+    }
+
     ACKCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), go->neg_addr,
              go->old_addrs, go->ouraddr, go->hisaddr);
 
     ACKCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol, go->old_vj,
            go->maxslotindex, go->cflag);
 
+    ACKCIDNS(CI_MS_DNS1, go->req_dns1, go->dnsaddr[0]);
+
+    ACKCIDNS(CI_MS_DNS2, go->req_dns2, go->dnsaddr[1]);
+
     /*
      * If there are any remaining CIs, then this packet is bad.
      */
@@ -728,9 +739,6 @@ ipcp_nakci(f, p, len)
         code \
     }
 
-/*
- * Peer returns DNS address in a NAK packet
- */
 #define NAKCIDNS(opt, neg, code) \
     if (go->neg && \
        ((cilen = p[1]) == CILEN_ADDR) && \
@@ -788,12 +796,10 @@ ipcp_nakci(f, p, len)
 
     NAKCIDNS(CI_MS_DNS1, req_dns1,
            try.dnsaddr[0] = cidnsaddr;
-           try.req_dns1 = 0;
            );
 
     NAKCIDNS(CI_MS_DNS2, req_dns2,
            try.dnsaddr[1] = cidnsaddr;
-           try.req_dns2 = 0;
            );
 
     /*
@@ -848,12 +854,9 @@ ipcp_nakci(f, p, len)
        p = next;
     }
 
-    /* If there is still anything left, this packet is bad. */
-    if (len != 0)
-       goto bad;
-
     /*
      * OK, the Nak is good.  Now we can update state.
+     * If there are any remaining options, we ignore them.
      */
     if (f->state != OPENED)
        *go = try;
@@ -935,7 +938,7 @@ ipcp_rejci(f, p, len)
 
 #define REJCIDNS(opt, neg, dnsaddr) \
     if (go->neg && \
-       ((cilen = p[1]) == CI_MS_DNS1) && \
+       ((cilen = p[1]) == CILEN_ADDR) && \
        len >= cilen && \
        p[0] == opt) { \
        u_int32_t l; \
@@ -1009,8 +1012,6 @@ ipcp_reqci(f, inp, len, reject_if_disagree)
     u_char maxslotindex, cflag;
     int d;
 
-    cis_received[f->unit] = 1;
-
     /*
      * Reset all his options.
      */
@@ -1523,6 +1524,9 @@ ipcp_down(f)
     fsm *f;
 {
     IPCPDEBUG(("ipcp: down"));
+    /* XXX a bit IPv4-centric here, we only need to get the stats
+     * before the interface is marked down. */
+    update_link_stats(f->unit);
     if (ipcp_is_up) {
        ipcp_is_up = 0;
        np_down(f->unit, PPP_IP);
@@ -1751,7 +1755,8 @@ ipcp_printpkt(p, plen, printer, arg)
            case CI_MS_DNS2:
                p += 2;
                GETLONG(cilong, p);
-               printer(arg, "ms-dns %I", htonl(cilong));
+               printer(arg, "ms-dns%d %I", code - CI_MS_DNS1 + 1,
+                       htonl(cilong));
                break;
            case CI_MS_WINS1:
            case CI_MS_WINS2: