]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/sys-str.c
update to 2.2
[ppp.git] / pppd / sys-str.c
index e34d54779c6c5e361334e2b75251534e59bb1996..0754553d6c96df77e8dc668628b6f3769755e264 100644 (file)
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
+#ifndef lint
+static char rcsid[] = "$Id: sys-str.c,v 1.16 1994/10/24 04:30:35 paulus Exp $";
+#endif
+
 /*
  * TODO:
  */
 #include <sys/stropts.h>
 
 #include <net/if.h>
+#include <net/ppp_defs.h>
+#include <net/ppp_str.h>
 #include <net/route.h>
 #include <net/if_arp.h>
 #include <netinet/in.h>
 
 #include "pppd.h"
-#include "ppp.h"
-#include <net/ppp_str.h>
 
 #ifndef ifr_mtu
 #define ifr_mtu                ifr_metric
@@ -383,9 +387,11 @@ set_up_tty(fd, local)
     if (!restore_term)
        inittermios = tios;
 
-    tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB | CLOCAL | CRTSCTS);
-    if (crtscts == 1)
+    tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB | CLOCAL);
+    if (crtscts > 0)
        tios.c_cflag |= CRTSCTS;
+    else if (crtscts < 0)
+       tios.c_cflag &= ~CRTSCTS;
 
     tios.c_cflag |= CS8 | CREAD | HUPCL;
     if (local || !modem)
@@ -510,14 +516,14 @@ read_packet(buf)
     int len, i;
     unsigned char ctlbuf[16];
 
-    str.maxlen = MTU+DLLHEADERLEN;
+    str.maxlen = PPP_MTU + PPP_HDRLEN;
     str.buf = (caddr_t) buf;
     ctl.maxlen = sizeof(ctlbuf);
     ctl.buf = (caddr_t) ctlbuf;
     i = 0;
     len = getmsg(fd, &ctl, &str, &i);
     if (len < 0) {
-       if (errno == EAGAIN || errno == EWOULDBLOCK) {
+       if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
            return -1;
        }
        syslog(LOG_ERR, "getmsg(fd) %m");
@@ -545,7 +551,7 @@ read_packet(buf)
 void
 ppp_send_config(unit, mtu, asyncmap, pcomp, accomp)
     int unit, mtu;
-    uint32 asyncmap;
+    u_int32_t asyncmap;
     int pcomp, accomp;
 {
     char c;
@@ -597,7 +603,7 @@ ppp_set_xaccm(unit, accm)
 void
 ppp_recv_config(unit, mru, asyncmap, pcomp, accomp)
     int unit, mru;
-    uint32 asyncmap;
+    u_int32_t asyncmap;
     int pcomp, accomp;
 {
     char c;
@@ -653,6 +659,24 @@ ccp_flags_set(unit, isopen, isup)
        syslog(LOG_ERR, "ioctl (SIOCSIFCOMP): %m");
 }
 
+/*
+ * ccp_fatal_error - returns 1 if decompression was disabled as a
+ * result of an error detected after decompression of a packet,
+ * 0 otherwise.  This is necessary because of patent nonsense.
+ */
+int
+ccp_fatal_error(unit)
+    int unit;
+{
+    int x;
+
+    if (ioctl(fd, SIOCGIFCOMP, (caddr_t) &x) < 0) {
+       syslog(LOG_ERR, "ioctl(SIOCGIFCOMP): %m");
+       return 0;
+    }
+    return x & CCP_FATALERROR;
+}
+
 /*
  * sifvjcomp - config tcp header compression
  */
@@ -671,13 +695,14 @@ sifvjcomp(u, vjcomp, cidcomp, maxcid)
 }
 
 /*
- * sifup - Config the interface up.
+ * sifup - Config the interface up and enable IP packets to pass.
  */
 int
 sifup(u)
     int u;
 {
     struct ifreq ifr;
+    struct npioctl npi;
 
     strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
     if (ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
@@ -689,6 +714,14 @@ sifup(u)
        syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
        return 0;
     }
+    npi.protocol = PPP_IP;
+    npi.mode = NPMODE_PASS;
+    if (ioctl(fd, SIOCSETNPMODE, &npi) < 0) {
+       if (errno != ENOTTY) {
+           syslog(LOG_ERR, "ioctl(SIOCSETNPMODE): %m");
+           return 0;
+       }
+    }
     return 1;
 }
 
@@ -700,17 +733,31 @@ sifdown(u)
     int u;
 {
     struct ifreq ifr;
+    int rv;
+    struct npioctl npi;
+
+    rv = 1;
+    npi.protocol = PPP_IP;
+    npi.mode = NPMODE_ERROR;
+    if (ioctl(fd, SIOCSETNPMODE, (caddr_t) &npi) < 0) {
+       if (errno != ENOTTY) {
+           syslog(LOG_ERR, "ioctl(SIOCSETNPMODE): %m");
+           rv = 0;
+       }
+    }
+
     strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
     if (ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
        syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
-       return 0;
-    }
-    ifr.ifr_flags &= ~IFF_UP;
-    if (ioctl(s, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
-       return 0;
+       rv = 0;
+    } else {
+       ifr.ifr_flags &= ~IFF_UP;
+       if (ioctl(s, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
+           syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
+           rv = 0;
+       }
     }
-    return 1;
+    return rv;
 }
 
 /*
@@ -726,7 +773,7 @@ sifdown(u)
 int
 sifaddr(u, o, h, m)
     int u;
-    uint32 o, h, m;
+    u_int32_t o, h, m;
 {
     int ret;
     struct ifreq ifr;
@@ -762,7 +809,7 @@ sifaddr(u, o, h, m)
 int
 cifaddr(u, o, h)
     int u;
-    uint32 o, h;
+    u_int32_t o, h;
 {
     struct rtentry rt;
 
@@ -784,7 +831,7 @@ cifaddr(u, o, h)
 int
 sifdefaultroute(u, g)
     int u;
-    uint32 g;
+    u_int32_t g;
 {
     struct rtentry rt;
 
@@ -805,7 +852,7 @@ sifdefaultroute(u, g)
 int
 cifdefaultroute(u, g)
     int u;
-    uint32 g;
+    u_int32_t g;
 {
     struct rtentry rt;
 
@@ -826,7 +873,7 @@ cifdefaultroute(u, g)
 int
 sifproxyarp(unit, hisaddr)
     int unit;
-    uint32 hisaddr;
+    u_int32_t hisaddr;
 {
     struct arpreq arpreq;
 
@@ -858,7 +905,7 @@ sifproxyarp(unit, hisaddr)
 int
 cifproxyarp(unit, hisaddr)
     int unit;
-    uint32 hisaddr;
+    u_int32_t hisaddr;
 {
     struct arpreq arpreq;
 
@@ -929,7 +976,7 @@ static void kread();
 
 int
 get_ether_addr(ipaddr, hwaddr)
-    uint32 ipaddr;
+    u_int32_t ipaddr;
     struct sockaddr *hwaddr;
 {
     register kvm_t *kd;
@@ -945,7 +992,7 @@ get_ether_addr(ipaddr, hwaddr)
        struct in_ifaddr in;
     } ifaddr;
 #endif
-    uint32 addr, mask;
+    u_int32_t addr, mask;
 
     /* Open kernel memory for reading */
     kd = kvm_open(0, 0, 0, O_RDONLY, NULL);
@@ -972,7 +1019,7 @@ get_ether_addr(ipaddr, hwaddr)
        syslog(LOG_ERR, "error reading ifnet addr");
        return 0;
     }
-    for ( ; addr; addr = (uint32)ifp->if_next) {
+    for ( ; addr; addr = (u_int32_t)ifp->if_next) {
        if (kvm_read(kd, addr, (char *)ac, sizeof(*ac)) != sizeof(*ac)) {
            syslog(LOG_ERR, "error reading ifnet");
            return 0;
@@ -989,7 +1036,7 @@ get_ether_addr(ipaddr, hwaddr)
 
        /* Get interface ip address */
 #ifdef SUNOS4
-       if (kvm_read(kd, (uint32)ifp->if_addrlist, (char *)&ifaddr,
+       if (kvm_read(kd, (u_int32_t)ifp->if_addrlist, (char *)&ifaddr,
                     sizeof(ifaddr)) != sizeof(ifaddr)) {
            syslog(LOG_ERR, "error reading ifaddr");
            return 0;