]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/ipcp.c
use option_error, fix ip_active_pkt
[ppp.git] / pppd / ipcp.c
index d8f1933ba98ac8dd3542d819ab2016ea798570ac..ecbb74904cac8f6c4baceee6ec6465a035290c73 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: ipcp.c,v 1.26 1996/07/01 01:13:53 paulus Exp $";
+static char rcsid[] = "$Id: ipcp.c,v 1.28 1996/08/28 06:40:29 paulus Exp $";
 #endif
 
 /*
@@ -1062,13 +1062,11 @@ ip_check_options()
     }
 
     if (demand && wo->hisaddr == 0) {
-       fprintf(stderr, "%s: remote IP address required for demand-dialling\n",
-               progname);
+       option_error("remote IP address required for demand-dialling\n");
        exit(1);
     }
     if (demand && wo->accept_remote) {
-       fprintf(stderr, "%s: ipcp-accept-remote is incompatible with demand\n",
-               progname);
+       option_error("ipcp-accept-remote is incompatible with demand\n");
        exit(1);
     }
 }
@@ -1086,10 +1084,10 @@ ip_demand_conf(u)
 
     if (!sifaddr(u, wo->ouraddr, wo->hisaddr, GetMask(wo->ouraddr)))
        return 0;
-    if (!sifnpmode(u, PPP_IP, NPMODE_QUEUE))
-       return 0;
     if (!sifup(u))
        return 0;
+    if (!sifnpmode(u, PPP_IP, NPMODE_QUEUE))
+       return 0;
     if (wo->default_route)
        if (sifdefaultroute(u, wo->hisaddr))
            default_route_set[u] = 1;
@@ -1222,8 +1220,9 @@ ipcp_down(f)
 {
     u_int32_t ouraddr, hisaddr;
 
-    np_down(f->unit, PPP_IP);
     IPCPDEBUG((LOG_INFO, "ipcp: down"));
+    np_down(f->unit, PPP_IP);
+    sifvjcomp(f->unit, 0, 0, 0);
 
     /*
      * If we are doing dial-on-demand, set the interface
@@ -1413,6 +1412,16 @@ ipcp_printpkt(p, plen, printer, arg)
 #define IP_OFFMASK     0x1fff
 #endif
 
+/*
+ * We use these macros because the IP header may be at an odd address,
+ * and some compilers might use word loads to get th_off or ip_hl.
+ */
+
+#define net_short(x)   (((x)[0] << 8) + (x)[1])
+#define get_iphl(x)    (((unsigned char *)(x))[0] & 0xF)
+#define get_ipoff(x)   net_short((unsigned char *)(x) + 6)
+#define get_tcpoff(x)  (((unsigned char *)(x))[12] >> 4)
+
 static int
 ip_active_pkt(pkt, len)
     u_char *pkt;
@@ -1422,18 +1431,20 @@ ip_active_pkt(pkt, len)
     struct tcphdr *tcp;
     int hlen;
 
+    len -= PPP_HDRLEN;
     if (len < sizeof(struct ip) + PPP_HDRLEN)
        return 0;
-    ip = (struct ip *) (pkt + PPP_HDRLEN);
-    if ((ntohs(ip->ip_off) & IP_OFFMASK) != 0)
+    pkt += PPP_HDRLEN;
+    ip = (struct ip *) pkt;
+    if ((get_ipoff(ip) & IP_OFFMASK) != 0)
        return 0;
     if (ip->ip_p != IPPROTO_TCP)
        return 1;
-    hlen = ip->ip_hl * 4;
-    if (len < hlen + sizeof(struct tcphdr) + PPP_HDRLEN)
+    hlen = get_iphl(ip) * 4;
+    if (len < hlen + sizeof(struct tcphdr))
        return 0;
-    tcp = (struct tcphdr *) (pkt + PPP_HDRLEN + hlen);
-    if ((tcp->th_flags & TH_FIN) != 0 && hlen + tcp->th_off * 4 == len)
+    tcp = (struct tcphdr *) (pkt + hlen);
+    if ((tcp->th_flags & TH_FIN) != 0 && len == hlen + get_tcpoff(tcp) * 4)
        return 0;
     return 1;
 }