From 392a4f54cb25e48eed9cf5443febeeba7eaf7cbc Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Mon, 12 Mar 2001 22:59:01 +0000 Subject: [PATCH] make establish/disestablish_ppp members of the channel struct, make restore_loop part of disestablish_ppp --- pppd/main.c | 12 +++++------- pppd/pppd.h | 13 ++++++++----- pppd/sys-linux.c | 20 ++++++++++++++------ pppd/sys-solaris.c | 19 +++++-------------- pppd/sys-sunos4.c | 17 ++++------------- pppd/tty.c | 4 +++- 6 files changed, 39 insertions(+), 46 deletions(-) diff --git a/pppd/main.c b/pppd/main.c index a6f4e06..e0352f0 100644 --- a/pppd/main.c +++ b/pppd/main.c @@ -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 #include @@ -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)(); diff --git a/pppd/pppd.h b/pppd/pppd.h index 03dd28a..38788ce 100644 --- a/pppd/pppd.h +++ b/pppd/pppd.h @@ -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 */ diff --git a/pppd/sys-linux.c b/pppd/sys-linux.c index 74ee20a..b1c58aa 100644 --- a/pppd/sys-linux.c +++ b/pppd/sys-linux.c @@ -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; diff --git a/pppd/sys-solaris.c b/pppd/sys-solaris.c index 859cd2a..2cba082 100644 --- a/pppd/sys-solaris.c +++ b/pppd/sys-solaris.c @@ -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 #include @@ -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; diff --git a/pppd/sys-sunos4.c b/pppd/sys-sunos4.c index 6897641..00f2ec5 100644 --- a/pppd/sys-sunos4.c +++ b/pppd/sys-sunos4.c @@ -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 #include @@ -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; diff --git a/pppd/tty.c b/pppd/tty.c index f245427..b21a158 100644 --- a/pppd/tty.c +++ b/pppd/tty.c @@ -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 #include @@ -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, -- 2.39.2