]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/sys-linux.c
make establish/disestablish_ppp members of the channel struct,
[ppp.git] / pppd / sys-linux.c
index d5dbfafbc47107c8b86fea1d3a9abe0b471c9438..b1c58aa007436629f0c42bc5d7126019487c7dd3 100644 (file)
@@ -182,6 +182,7 @@ static void decode_version (char *buf, int *version, int *mod, int *patch);
 static int set_kdebugflag(int level);
 static int ppp_registered(void);
 static int make_ppp_unit(void);
 static int set_kdebugflag(int level);
 static int ppp_registered(void);
 static int make_ppp_unit(void);
+static void restore_loop(void);        /* Transfer ppp unit back to loopback */
 
 extern u_char  inpacket_buf[]; /* borrowed from main.c */
 
 
 extern u_char  inpacket_buf[]; /* borrowed from main.c */
 
@@ -263,11 +264,6 @@ void sys_init(void)
 {
     int flags;
 
 {
     int flags;
 
-    openlog("pppd", LOG_PID | LOG_NDELAY, LOG_PPP);
-    setlogmask(LOG_UPTO(LOG_INFO));
-    if (debug)
-       setlogmask(LOG_UPTO(LOG_DEBUG));
-
     if (new_style_driver) {
        ppp_dev_fd = open("/dev/ppp", O_RDWR);
        if (ppp_dev_fd < 0)
     if (new_style_driver) {
        ppp_dev_fd = open("/dev/ppp", O_RDWR);
        if (ppp_dev_fd < 0)
@@ -358,10 +354,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;
 {
     int x;
     int fd = -1;
@@ -474,8 +470,12 @@ int establish_ppp (int tty_fd)
     if (!looped)
        set_kdebugflag (kdebugflag);
 
     if (!looped)
        set_kdebugflag (kdebugflag);
 
-    set_flags(ppp_fd, get_flags(ppp_fd) & ~(SC_RCV_B7_0 | SC_RCV_B7_1 |
-                                           SC_RCV_EVNP | SC_RCV_ODDP));
+#define SC_RCVB        (SC_RCV_B7_0 | SC_RCV_B7_1 | SC_RCV_EVNP | SC_RCV_ODDP)
+#define SC_LOGB        (SC_DEBUG | SC_LOG_INPKT | SC_LOG_OUTPKT | SC_LOG_RAWIN \
+                | SC_LOG_FLUSH)
+
+    set_flags(ppp_fd, ((get_flags(ppp_fd) & ~(SC_RCVB | SC_LOGB))
+                      | ((kdebugflag * SC_DEBUG) & SC_LOGB)));
 
     SYSDEBUG ((LOG_NOTICE, "Using version %d.%d.%d of PPP driver",
            driver_version, driver_modification, driver_patch));
 
     SYSDEBUG ((LOG_NOTICE, "Using version %d.%d.%d of PPP driver",
            driver_version, driver_modification, driver_patch));
@@ -492,12 +492,15 @@ 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().
  */
 
  * 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 (demand)
+       restore_loop();
     if (!hungup) {
 /*
  * Flush the tty output buffer so that the TIOCSETD doesn't hang.
     if (!hungup) {
 /*
  * Flush the tty output buffer so that the TIOCSETD doesn't hang.
@@ -992,12 +995,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");
        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 && 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;
 }
     }
     return (new_style_driver && nr > 0)? nr+2: nr;
 }
@@ -1049,7 +1056,7 @@ netif_set_mtu(int unit, int mtu)
     ifr.ifr_mtu = mtu;
        
     if (ifunit >= 0 && ioctl(sock_fd, SIOCSIFMTU, (caddr_t) &ifr) < 0)
     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");
 }
 
 /********************************************************************
 }
 
 /********************************************************************
@@ -1813,24 +1820,20 @@ u_int32_t GetMask (u_int32_t addr)
 static void decode_version (char *buf, int *version,
                            int *modification, int *patch)
 {
 static void decode_version (char *buf, int *version,
                            int *modification, int *patch)
 {
-    *version      = (int) strtoul (buf, &buf, 10);
+    char *endp;
+
+    *version      = (int) strtoul (buf, &endp, 10);
     *modification = 0;
     *patch        = 0;
     
     *modification = 0;
     *patch        = 0;
     
-    if (*buf == '.') {
-       ++buf;
-       *modification = (int) strtoul (buf, &buf, 10);
-       if (*buf == '.') {
-           ++buf;
+    if (endp != buf && *endp == '.') {
+       buf = endp + 1;
+       *modification = (int) strtoul (buf, &endp, 10);
+       if (endp != buf && *endp == '.') {
+           buf = endp + 1;
            *patch = (int) strtoul (buf, &buf, 10);
        }
     }
            *patch = (int) strtoul (buf, &buf, 10);
        }
     }
-    
-    if (*buf != '\0') {
-       *version      =
-       *modification =
-       *patch        = 0;
-    }
 }
 
 /********************************************************************
 }
 
 /********************************************************************
@@ -2557,7 +2560,7 @@ open_ppp_loopback(void)
  * Just to be sure, set the real serial port to the normal discipline.
  */
 
  * Just to be sure, set the real serial port to the normal discipline.
  */
 
-void
+static void
 restore_loop(void)
 {
     looped = 1;
 restore_loop(void)
 {
     looped = 1;