X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Fsys-NeXT.c;h=3f97b4cf74ed6de0330801fe6a2da58192a999ff;hp=a23f611251457806b012c49c0439b158fbfb3d3f;hb=41e270e1e197f693b019d8a9e54b9057c33a4108;hpb=a17e555c2c3755105dc62a6c96f6d49556aff1d5 diff --git a/pppd/sys-NeXT.c b/pppd/sys-NeXT.c index a23f611..3f97b4c 100644 --- a/pppd/sys-NeXT.c +++ b/pppd/sys-NeXT.c @@ -20,7 +20,7 @@ */ #ifndef lint -static char rcsid[] = "$Id: sys-NeXT.c,v 1.1 1995/08/10 06:48:34 paulus Exp $"; +static char rcsid[] = "$Id: sys-NeXT.c,v 1.4 1996/01/01 23:03:23 paulus Exp $"; #endif #include @@ -56,6 +56,7 @@ static char rcsid[] = "$Id: sys-NeXT.c,v 1.1 1995/08/10 06:48:34 paulus Exp $"; #include "pppd.h" static int initdisc = -1; /* Initial TTY discipline */ +static int initfdflags = -1; /* Initial file descriptor flags for fd */ extern int errno; @@ -64,12 +65,24 @@ static struct termios inittermios; /* Initial TTY termios */ static char *lock_file; -int sockfd; /* socket for doing interface ioctls */ +static int sockfd; /* socket for doing interface ioctls */ #if defined(i386) && defined(HAS_BROKEN_IOCTL) #define ioctl myioctl #endif +static int if_is_up; /* the interface is currently up */ +static u_int32_t default_route_gateway; /* gateway addr for default route */ +static u_int32_t proxy_arp_addr; /* remote addr for proxy arp */ + +/* Prototypes for procedures local to this file. */ +static int translate_speed __P((int)); +static int baud_rate_of __P((int)); +static int dodefaultroute __P((u_int32_t, int)); +static int get_ether_addr __P((u_int32_t, struct sockaddr *)); +static int ether_by_host __P((char *, struct ether_addr *)); + + /* * sys_init - System-dependent initialization. */ @@ -88,6 +101,31 @@ sys_init() } } +/* + * sys_cleanup - restore any system state we modified before exiting: + * mark the interface down, delete default route and/or proxy arp entry. + * This should call die() because it's called from die(). + */ +void +sys_cleanup() +{ + struct ifreq ifr; + + if (if_is_up) { + strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) >= 0 + && ((ifr.ifr_flags & IFF_UP) != 0)) { + ifr.ifr_flags &= ~IFF_UP; + ioctl(sockfd, SIOCSIFFLAGS, &ifr); + } + } + + if (default_route_gateway) + cifdefaultroute(0, default_route_gateway); + if (proxy_arp_addr) + cifproxyarp(0, proxy_arp_addr); +} + /* * note_debug_level - note a change in the debug level. */ @@ -126,7 +164,8 @@ ppp_available() * establish_ppp - Turn the serial port into a ppp interface. */ void -establish_ppp() +establish_ppp(fd) + int fd; { int pppdisc = PPPDISC; int x; @@ -160,6 +199,14 @@ establish_ppp() syslog(LOG_WARNING, "ioctl(PPPIOCSFLAGS): %m"); } } + + /* + * Set device for non-blocking reads. + */ + if ((initfdflags = fcntl(fd, F_GETFL)) == -1 + || fcntl(fd, F_SETFL, initfdflags | O_NONBLOCK) == -1) { + syslog(LOG_WARNING, "Couldn't set device to non-blocking mode: %m"); + } } @@ -168,11 +215,17 @@ establish_ppp() * This shouldn't call die() because it's called from die(). */ void -disestablish_ppp() +disestablish_ppp(fd) + int fd; { int x; char *s; + /* Reset non-blocking mode on the file descriptor. */ + if (initfdflags != -1 && fcntl(fd, F_SETFL, initfdflags) < 0) + syslog(LOG_WARNING, "Couldn't restore device fd flags: %m"); + initfdflags = -1; + if (initdisc >= 0) { /* * Check whether the link seems not to be 8-bit clean. @@ -281,6 +334,12 @@ struct speed { #ifdef B57600 { 57600, B57600 }, #endif +/* +#ifndef B115200 +#warning Defining B115200 +#define B115200 20 +#endif +*/ #ifdef B115200 { 115200, B115200 }, #endif @@ -308,7 +367,7 @@ translate_speed(bps) /* * Translate from a speed_t to bits/second. */ -int +static int baud_rate_of(speed) int speed; { @@ -328,6 +387,7 @@ baud_rate_of(speed) * at the requested speed, etc. If `local' is true, set CLOCAL * regardless of whether the modem option was specified. */ +void set_up_tty(fd, local) int fd, local; { @@ -347,14 +407,15 @@ set_up_tty(fd, local) tios.c_cflag |= CS8 | CREAD | HUPCL; if (local || !modem) tios.c_cflag |= CLOCAL; + tios.c_iflag = IGNBRK | IGNPAR; tios.c_oflag = 0; tios.c_lflag = 0; tios.c_cc[VMIN] = 1; tios.c_cc[VTIME] = 0; - if (crtscts == 2) { - tios.c_iflag |= IXOFF; + if (crtscts == -2) { + tios.c_iflag |= IXON | IXOFF; tios.c_cc[VSTOP] = 0x13; /* DC3 = XOFF = ^S */ tios.c_cc[VSTART] = 0x11; /* DC1 = XON = ^Q */ } @@ -386,7 +447,8 @@ set_up_tty(fd, local) * restore_tty - restore the terminal to the saved settings. */ void -restore_tty() +restore_tty(fd) + int fd; { if (restore_term) { if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0) @@ -405,6 +467,7 @@ restore_tty() * NXFax's capability to determine port usage. * */ +void setdtr(fd, on) int fd, on; { @@ -430,23 +493,27 @@ output(unit, p, len) u_char *p; int len; { - if (unit != 0) - MAINDEBUG((LOG_WARNING, "output: unit != 0!")); if (debug) log_packet(p, len, "sent "); - if (write(fd, p, len) < 0) { - syslog(LOG_ERR, "write: %m"); - die(1); + if (write(ttyfd, p, len) < 0) { + if (errno == EWOULDBLOCK || errno == ENOBUFS + || errno == ENXIO || errno == EIO) { + syslog(LOG_WARNING, "write: warning: %m"); + } else { + syslog(LOG_ERR, "write: %m"); + die(1); + } } } /* - * wait_input - wait until there is data available on fd, + * wait_input - wait until there is data available on ttyfd, * for the length of time specified by *timo (indefinite * if timo is NULL). */ +void wait_input(timo) struct timeval *timo; { @@ -454,8 +521,8 @@ wait_input(timo) int n; FD_ZERO(&ready); - FD_SET(fd, &ready); - n = select(fd+1, &ready, NULL, &ready, timo); + FD_SET(ttyfd, &ready); + n = select(ttyfd+1, &ready, NULL, &ready, timo); if (n < 0 && errno != EINTR) { syslog(LOG_ERR, "select: %m"); die(1); @@ -472,12 +539,12 @@ read_packet(buf) { int len; - if ((len = read(fd, buf, PPP_MTU + PPP_HDRLEN)) < 0) { + if ((len = read(ttyfd, buf, PPP_MTU + PPP_HDRLEN)) < 0) { if (errno == EWOULDBLOCK || errno == EINTR) { - MAINDEBUG((LOG_DEBUG, "read(fd): %m")); + MAINDEBUG((LOG_DEBUG, "read: %m")); return -1; } - syslog(LOG_ERR, "read(fd): %m"); + syslog(LOG_ERR, "read: %m"); die(1); } return len; @@ -504,18 +571,18 @@ ppp_send_config(unit, mtu, asyncmap, pcomp, accomp) quit(); } - if (ioctl(fd, PPPIOCSASYNCMAP, (caddr_t) &asyncmap) < 0) { + if (ioctl(ttyfd, PPPIOCSASYNCMAP, (caddr_t) &asyncmap) < 0) { syslog(LOG_ERR, "ioctl(PPPIOCSASYNCMAP): %m"); quit(); } - if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) { + if (ioctl(ttyfd, PPPIOCGFLAGS, (caddr_t) &x) < 0) { syslog(LOG_ERR, "ioctl(PPPIOCGFLAGS): %m"); quit(); } x = pcomp? x | SC_COMP_PROT: x &~ SC_COMP_PROT; x = accomp? x | SC_COMP_AC: x &~ SC_COMP_AC; - if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) { + if (ioctl(ttyfd, PPPIOCSFLAGS, (caddr_t) &x) < 0) { syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m"); quit(); } @@ -530,7 +597,7 @@ ppp_set_xaccm(unit, accm) int unit; ext_accm accm; { - if (ioctl(fd, PPPIOCSXASYNCMAP, accm) < 0 && errno != ENOTTY) + if (ioctl(ttyfd, PPPIOCSXASYNCMAP, accm) < 0 && errno != ENOTTY) syslog(LOG_WARNING, "ioctl(PPPIOCSXASYNCMAP): %m"); } @@ -547,20 +614,20 @@ ppp_recv_config(unit, mru, asyncmap, pcomp, accomp) { int x; - if (ioctl(fd, PPPIOCSMRU, (caddr_t) &mru) < 0) { + if (ioctl(ttyfd, PPPIOCSMRU, (caddr_t) &mru) < 0) { syslog(LOG_ERR, "ioctl(PPPIOCSMRU): %m"); quit(); } - if (ioctl(fd, PPPIOCSRASYNCMAP, (caddr_t) &asyncmap) < 0) { + if (ioctl(ttyfd, PPPIOCSRASYNCMAP, (caddr_t) &asyncmap) < 0) { syslog(LOG_ERR, "ioctl(PPPIOCSRASYNCMAP): %m"); quit(); } - if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) { + if (ioctl(ttyfd, PPPIOCGFLAGS, (caddr_t) &x) < 0) { syslog(LOG_ERR, "ioctl(PPPIOCGFLAGS): %m"); quit(); } x = !accomp? x | SC_REJ_COMP_AC: x &~ SC_REJ_COMP_AC; - if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) { + if (ioctl(ttyfd, PPPIOCSFLAGS, (caddr_t) &x) < 0) { syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m"); quit(); } @@ -570,6 +637,7 @@ ppp_recv_config(unit, mru, asyncmap, pcomp, accomp) * ccp_test - ask kernel whether a given compression method * is acceptable for use. */ +int ccp_test(unit, opt_ptr, opt_len, for_transmit) int unit, opt_len, for_transmit; u_char *opt_ptr; @@ -579,7 +647,9 @@ ccp_test(unit, opt_ptr, opt_len, for_transmit) data.ptr = opt_ptr; data.length = opt_len; data.transmit = for_transmit; - return ioctl(fd, PPPIOCSCOMPRESS, (caddr_t) &data) >= 0; + if (ioctl(ttyfd, PPPIOCSCOMPRESS, (caddr_t) &data) >= 0) + return 1; + return (errno == ENOBUFS)? 0: -1; } /* @@ -591,13 +661,13 @@ ccp_flags_set(unit, isopen, isup) { int x; - if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) { + if (ioctl(ttyfd, PPPIOCGFLAGS, (caddr_t) &x) < 0) { syslog(LOG_ERR, "ioctl(PPPIOCGFLAGS): %m"); return; } x = isopen? x | SC_CCP_OPEN: x &~ SC_CCP_OPEN; x = isup? x | SC_CCP_UP: x &~ SC_CCP_UP; - if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) + if (ioctl(ttyfd, PPPIOCSFLAGS, (caddr_t) &x) < 0) syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m"); } @@ -612,7 +682,7 @@ ccp_fatal_error(unit) { int x; - if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) { + if (ioctl(ttyfd, PPPIOCGFLAGS, (caddr_t) &x) < 0) { syslog(LOG_ERR, "ioctl(PPPIOCGFLAGS): %m"); return 0; } @@ -628,17 +698,17 @@ sifvjcomp(u, vjcomp, cidcomp, maxcid) { u_int x; - if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) { + if (ioctl(ttyfd, PPPIOCGFLAGS, (caddr_t) &x) < 0) { syslog(LOG_ERR, "ioctl(PPIOCGFLAGS): %m"); return 0; } x = vjcomp ? x | SC_COMP_TCP: x &~ SC_COMP_TCP; x = cidcomp? x & ~SC_NO_TCP_CCID: x | SC_NO_TCP_CCID; - if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) { + if (ioctl(ttyfd, PPPIOCSFLAGS, (caddr_t) &x) < 0) { syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m"); return 0; } - if (ioctl(fd, PPPIOCSMAXCID, (caddr_t) &maxcid) < 0) { + if (ioctl(ttyfd, PPPIOCSMAXCID, (caddr_t) &maxcid) < 0) { syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m"); return 0; } @@ -670,20 +740,21 @@ sifup(u) syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m"); return 0; } + if_is_up = 1; npi.protocol = PPP_IP; npi.mode = NPMODE_PASS; - if (ioctl(fd, PPPIOCSNPMODE, &npi) < 0) { + if (ioctl(ttyfd, PPPIOCSNPMODE, &npi) < 0) { if (errno != ENOTTY) { syslog(LOG_ERR, "ioctl(PPPIOCSNPMODE): %m"); return 0; } /* for backwards compatibility */ - if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) { + if (ioctl(ttyfd, PPPIOCGFLAGS, (caddr_t) &x) < 0) { syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m"); return 0; } x |= SC_ENABLE_IP; - if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) { + if (ioctl(ttyfd, PPPIOCSFLAGS, (caddr_t) &x) < 0) { syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m"); return 0; } @@ -706,18 +777,18 @@ sifdown(u) rv = 1; npi.protocol = PPP_IP; npi.mode = NPMODE_ERROR; - if (ioctl(fd, PPPIOCSNPMODE, (caddr_t) &npi) < 0) { + if (ioctl(ttyfd, PPPIOCSNPMODE, (caddr_t) &npi) < 0) { if (errno != ENOTTY) { syslog(LOG_ERR, "ioctl(PPPIOCSNPMODE): %m"); rv = 0; } else { /* backwards compatibility */ - if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) { + if (ioctl(ttyfd, PPPIOCGFLAGS, (caddr_t) &x) < 0) { syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m"); rv = 0; } else { x &= ~SC_ENABLE_IP; - if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) { + if (ioctl(ttyfd, PPPIOCSFLAGS, (caddr_t) &x) < 0) { syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m"); rv = 0; } @@ -734,7 +805,8 @@ sifdown(u) if (ioctl(sockfd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) { syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m"); rv = 0; - } + } else + if_is_up = 0; } return rv; } @@ -855,6 +927,7 @@ dodefaultroute(g, cmd) (cmd == 's') ? "SIOCADDRT" : "SIOCDELRT"); return 0; } + default_route_gateway = (cmd == 's')? g: 0; return 1; } @@ -887,6 +960,7 @@ sifproxyarp(unit, hisaddr) return 0; } + proxy_arp_addr = hisaddr; return 1; } @@ -907,6 +981,7 @@ cifproxyarp(unit, hisaddr) syslog(LOG_WARNING, "ioctl(SIOCDARP): %m"); return 0; } + proxy_arp_addr = 0; return 1; } @@ -989,7 +1064,7 @@ get_ether_addr(ipaddr, hwaddr) return 1; } -int +static int ether_by_host(hostname, etherptr) char *hostname; struct ether_addr *etherptr;