]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/sys-linux.c
minor bugfixes, now 2.4.2b1, add pkts_in/out to pppd_stats,
[ppp.git] / pppd / sys-linux.c
index 74ee20a8832f53502a5e32958752659e62a37329..189b809cc97d128ed8944fc012f3b6424369c4b0 100644 (file)
@@ -353,10 +353,10 @@ static int set_kdebugflag (int requested_level)
 
 /********************************************************************
  *
- * establish_ppp - Turn the serial port into a ppp interface.
+ * tty_establish_ppp - Turn the serial port into a ppp interface.
  */
 
-int establish_ppp (int tty_fd)
+int tty_establish_ppp (int tty_fd)
 {
     int x;
     int fd = -1;
@@ -491,11 +491,12 @@ int establish_ppp (int tty_fd)
 
 /********************************************************************
  *
- * disestablish_ppp - Restore the serial port to normal operation.
+ * tty_disestablish_ppp - Restore the serial port to normal operation,
+ * and reconnect the ppp unit to the loopback if in demand mode.
  * This shouldn't call die() because it's called from die().
  */
 
-void disestablish_ppp(int tty_fd)
+void tty_disestablish_ppp(int tty_fd)
 {
     if (!hungup) {
 /*
@@ -527,10 +528,17 @@ void disestablish_ppp(int tty_fd)
     if (new_style_driver) {
        close(ppp_fd);
        ppp_fd = -1;
-       if (!looped && ifunit >= 0 && ioctl(ppp_dev_fd, PPPIOCDETACH) < 0)
+       if (demand) {
+           set_flags(ppp_dev_fd, get_flags(ppp_dev_fd) | SC_LOOP_TRAFFIC);
+           looped = 1;
+       } else if (ifunit >= 0 && ioctl(ppp_dev_fd, PPPIOCDETACH) < 0)
            error("Couldn't release PPP unit: %m");
        if (!multilink)
            remove_fd(ppp_dev_fd);
+    } else {
+       /* old-style driver */
+       if (demand)
+           set_ppp_fd(slave_fd);
     }
 }
 
@@ -991,12 +999,16 @@ int read_packet (unsigned char *buf)
        nr = read(ppp_fd, buf, len);
        if (nr < 0 && errno != EWOULDBLOCK && errno != EIO && errno != EINTR)
            error("read: %m");
+       if (nr < 0 && errno == ENXIO)
+           return 0;
     }
     if (nr < 0 && new_style_driver && ifunit >= 0) {
        /* N.B. we read ppp_fd first since LCP packets come in there. */
        nr = read(ppp_dev_fd, buf, len);
        if (nr < 0 && errno != EWOULDBLOCK && errno != EIO && errno != EINTR)
            error("read /dev/ppp: %m");
+       if (nr < 0 && errno == ENXIO)
+           return 0;
     }
     return (new_style_driver && nr > 0)? nr+2: nr;
 }
@@ -1048,7 +1060,7 @@ netif_set_mtu(int unit, int mtu)
     ifr.ifr_mtu = mtu;
        
     if (ifunit >= 0 && ioctl(sock_fd, SIOCSIFMTU, (caddr_t) &ifr) < 0)
-       fatal("ioctl(SIOCSIFMTU): %m(%d)", errno);
+       fatal("ioctl(SIOCSIFMTU): %m");
 }
 
 /********************************************************************
@@ -1160,7 +1172,7 @@ int ccp_test (int unit, u_char *opt_ptr, int opt_len, int for_transmit)
 
 void ccp_flags_set (int unit, int isopen, int isup)
 {
-    if (still_ppp()) {
+    if (still_ppp() && ifunit >= 0) {
        int x = get_flags(ppp_dev_fd);
        x = isopen? x | SC_CCP_OPEN : x &~ SC_CCP_OPEN;
        x = isup?   x | SC_CCP_UP   : x &~ SC_CCP_UP;
@@ -1228,6 +1240,8 @@ get_ppp_stats(u, stats)
     }
     stats->bytes_in = req.stats.p.ppp_ibytes;
     stats->bytes_out = req.stats.p.ppp_obytes;
+    stats->pkts_in = req.stats.p.ppp_ipackets;
+    stats->pkts_out = req.stats.p.ppp_opackets;
     return 1;
 }
 
@@ -1920,8 +1934,15 @@ int ppp_available(void)
        close(fd);
        return 1;
     }
-    if (kernel_version >= KVERSION(2,3,13))
+    if (kernel_version >= KVERSION(2,3,13)) {
+       if (errno == ENOENT)
+           no_ppp_msg =
+               "pppd is unable to open the /dev/ppp device.\n"
+               "You need to create the /dev/ppp device node by\n"
+               "executing the following command as root:\n"
+               "       mknod /dev/ppp c 108 0\n";
        return 0;
+    }
 
 /*
  * Open a socket for doing the ioctl operations.
@@ -2539,33 +2560,6 @@ open_ppp_loopback(void)
     return master_fd;
 }
 
-/********************************************************************
- *
- * restore_loop - reattach the ppp unit to the loopback.
- *
- * The kernel ppp driver automatically reattaches the ppp unit to
- * the loopback if the serial port is set to a line discipline other
- * than ppp, or if it detects a modem hangup.  The former will happen
- * in disestablish_ppp if the latter hasn't already happened, so we
- * shouldn't need to do anything.
- *
- * Just to be sure, set the real serial port to the normal discipline.
- */
-
-void
-restore_loop(void)
-{
-    looped = 1;
-    if (new_style_driver) {
-       set_flags(ppp_dev_fd, get_flags(ppp_dev_fd) | SC_LOOP_TRAFFIC);
-       return;
-    }
-    if (ppp_fd != slave_fd) {
-       (void) ioctl(ppp_fd, TIOCSETD, &tty_disc);
-       set_ppp_fd(slave_fd);
-    }
-}
-
 /********************************************************************
  *
  * sifnpmode - Set the mode for handling packets for a given NP.