]> git.ozlabs.org Git - ppp.git/commitdiff
make establish/disestablish_ppp members of the channel struct,
authorPaul Mackerras <paulus@samba.org>
Mon, 12 Mar 2001 22:59:01 +0000 (22:59 +0000)
committerPaul Mackerras <paulus@samba.org>
Mon, 12 Mar 2001 22:59:01 +0000 (22:59 +0000)
make restore_loop part of disestablish_ppp

pppd/main.c
pppd/pppd.h
pppd/sys-linux.c
pppd/sys-solaris.c
pppd/sys-sunos4.c
pppd/tty.c

index a6f4e06d6274ff721d2b3b4517167f5ba1385db6..e0352f02d462726e7ab9e54f75aed64268e58db7 100644 (file)
@@ -17,7 +17,7 @@
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
-#define RCSID  "$Id: main.c,v 1.104 2001/03/09 00:55:14 paulus Exp $"
+#define RCSID  "$Id: main.c,v 1.105 2001/03/12 22:58:59 paulus Exp $"
 
 #include <stdio.h>
 #include <ctype.h>
@@ -453,7 +453,7 @@ main(argc, argv)
 
        /* set up the serial device as a ppp interface */
        tdb_writelock(pppdb);
-       fd_ppp = establish_ppp(devfd);
+       fd_ppp = the_channel->establish_ppp(devfd);
        if (fd_ppp < 0) {
            tdb_writeunlock(pppdb);
            status = EXIT_FATAL_ERROR;
@@ -499,7 +499,7 @@ main(argc, argv)
        if (link_stats_valid) {
            int t = (link_connect_time + 5) / 6;    /* 1/10ths of minutes */
            info("Connect time %d.%d minutes.", t/10, t%10);
-           info("Sent %d bytes, received %d bytes.",
+           info("Sent %u bytes, received %u bytes.",
                 link_stats.bytes_out, link_stats.bytes_in);
        }
 
@@ -522,9 +522,7 @@ main(argc, argv)
         */
        remove_fd(fd_ppp);
        clean_check();
-       if (demand)
-           restore_loop();
-       disestablish_ppp(devfd);        /* XXX */
+       the_channel->disestablish_ppp(devfd);
        fd_ppp = -1;
        if (!hungup)
            lcp_lowerdown(0);
@@ -1037,7 +1035,7 @@ cleanup()
     sys_cleanup();
 
     if (fd_ppp >= 0)
-       disestablish_ppp(devfd);
+       the_channel->disestablish_ppp(devfd);
     if (the_channel->cleanup)
        (*the_channel->cleanup)();
 
index 03dd28a20261656685cbc28b9dd6a7572cc1d8e1..38788ce4aa078d633347114d89ca4133d2cd0598 100644 (file)
@@ -16,7 +16,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * $Id: pppd.h,v 1.58 2001/03/08 05:11:16 paulus Exp $
+ * $Id: pppd.h,v 1.59 2001/03/12 22:58:59 paulus Exp $
  */
 
 /*
@@ -361,8 +361,12 @@ struct channel {
        void (*check_options) __P((void));
        /* get the channel ready to do PPP, return a file descriptor */
        int  (*connect) __P((void));
-       /* we're finished doing PPP on the channel */
+       /* we're finished with the channel */
        void (*disconnect) __P((void));
+       /* put the channel into PPP `mode' */
+       int  (*establish_ppp) __P((int));
+       /* take the channel out of PPP `mode', restore loopback if demand */
+       void (*disestablish_ppp) __P((int));
        /* set the transmit-side PPP parameters of the channel */
        void (*send_config) __P((int, u_int32_t, int, int));
        /* set the receive-side PPP parameters of the channel */
@@ -490,9 +494,8 @@ void sys_close __P((void)); /* Clean up in a child before execing */
 int  ppp_available __P((void));        /* Test whether ppp kernel support exists */
 int  get_pty __P((int *, int *, char *, int)); /* Get pty master/slave */
 int  open_ppp_loopback __P((void)); /* Open loopback for demand-dialling */
-int  establish_ppp __P((int)); /* Turn serial port into a ppp interface */
-void restore_loop __P((void)); /* Transfer ppp unit back to loopback */
-void disestablish_ppp __P((int)); /* Restore port to normal operation */
+int  tty_establish_ppp __P((int));  /* Turn serial port into a ppp interface */
+void tty_disestablish_ppp __P((int)); /* Restore port to normal operation */
 void make_new_bundle __P((int, int, int, int)); /* Create new bundle */
 int  bundle_attach __P((int)); /* Attach link to existing bundle */
 void cfg_bundle __P((int, int, int, int)); /* Configure existing bundle */
index 74ee20a8832f53502a5e32958752659e62a37329..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 void restore_loop(void);        /* Transfer ppp unit back to loopback */
 
 extern u_char  inpacket_buf[]; /* borrowed from main.c */
 
@@ -353,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;
@@ -491,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().
  */
 
-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.
@@ -991,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");
+       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 +1056,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");
 }
 
 /********************************************************************
@@ -2552,7 +2560,7 @@ open_ppp_loopback(void)
  * Just to be sure, set the real serial port to the normal discipline.
  */
 
-void
+static void
 restore_loop(void)
 {
     looped = 1;
index 859cd2a1a3caa8665f5968137b5c9060ffe71539..2cba082652649376134971423e5c06a607ed8df3 100644 (file)
@@ -42,7 +42,7 @@
  * OR MODIFICATIONS.
  */
 
-#define RCSID  "$Id: sys-solaris.c,v 1.3 2001/03/08 05:14:26 paulus Exp $"
+#define RCSID  "$Id: sys-solaris.c,v 1.4 2001/03/12 22:59:00 paulus Exp $"
 
 #include <limits.h>
 #include <stdio.h>
@@ -875,10 +875,10 @@ any_compressions()
 }
 
 /*
- * establish_ppp - Turn the serial port into a ppp interface.
+ * tty_establish_ppp - Turn the serial port into a ppp interface.
  */
 int
-establish_ppp(fd)
+tty_establish_ppp(fd)
     int fd;
 {
     int i;
@@ -933,21 +933,12 @@ establish_ppp(fd)
 }
 
 /*
- * restore_loop - reattach the ppp unit to the loopback.
- * This doesn't need to do anything because disestablish_ppp does it.
- */
-void
-restore_loop()
-{
-}
-
-/*
- * disestablish_ppp - Restore the serial port to normal operation.
+ * tty_disestablish_ppp - Restore the serial port to normal operation.
  * It attempts to reconstruct the stream with the previously popped
  * modules.  This shouldn't call die() because it's called from die().
  */
 void
-disestablish_ppp(fd)
+tty_disestablish_ppp(fd)
     int fd;
 {
     int i;
index 68976414e1cd182baceac5404e446947ab2770a3..00f2ec521f5001006c091d7fa96970e84f361b07 100644 (file)
@@ -25,7 +25,7 @@
  * OR MODIFICATIONS.
  */
 
-#define RCSID  "$Id: sys-sunos4.c,v 1.25 1999/12/23 01:38:19 paulus Exp $"
+#define RCSID  "$Id: sys-sunos4.c,v 1.26 2001/03/12 22:59:00 paulus Exp $"
 
 #include <stdio.h>
 #include <stddef.h>
@@ -239,10 +239,10 @@ ppp_available()
 }
 
 /*
- * establish_ppp - Turn the serial port into a ppp interface.
+ * tty_establish_ppp - Turn the serial port into a ppp interface.
  */
 int
-establish_ppp(fd)
+tty_establish_ppp(fd)
     int fd;
 {
     int i;
@@ -267,22 +267,13 @@ establish_ppp(fd)
     return pppfd;
 }
 
-/*
- * restore_loop - reattach the ppp unit to the loopback.
- * This doesn't need to do anything because disestablish_ppp does it.
- */
-void
-restore_loop()
-{
-}
-
 /*
  * disestablish_ppp - Restore the serial port to normal operation.
  * It attempts to reconstruct the stream with the previously popped
  * modules.  This shouldn't call die() because it's called from die().
  */
 void
-disestablish_ppp(fd)
+tty_disestablish_ppp(fd)
     int fd;
 {
     int i;
index f2454279fedb5b17d10af6630b69e1b0c457a68a..b21a158f2e927298bcd8342df514843017358fec 100644 (file)
@@ -20,7 +20,7 @@
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
-#define RCSID  "$Id: tty.c,v 1.5 2001/03/08 05:11:16 paulus Exp $"
+#define RCSID  "$Id: tty.c,v 1.6 2001/03/12 22:59:01 paulus Exp $"
 
 #include <stdio.h>
 #include <ctype.h>
@@ -197,6 +197,8 @@ struct channel tty_channel = {
        &tty_check_options,
        &connect_tty,
        &disconnect_tty,
+       &tty_establish_ppp,
+       &tty_disestablish_ppp,
        &tty_do_send_config,
        &tty_recv_config,
        &cleanup_tty,