X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Fsys-NeXT.c;h=dcae3bf62d48fd25e721f5c4c758638694e272d2;hp=a23f611251457806b012c49c0439b158fbfb3d3f;hb=9420784901517dbd06185b874d2a2bed3b8f6e25;hpb=a17e555c2c3755105dc62a6c96f6d49556aff1d5 diff --git a/pppd/sys-NeXT.c b/pppd/sys-NeXT.c index a23f611..dcae3bf 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.3 1995/12/18 03:30:47 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. */ @@ -160,6 +198,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"); + } } @@ -173,6 +219,11 @@ disestablish_ppp() 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 +332,12 @@ struct speed { #ifdef B57600 { 57600, B57600 }, #endif +/* +#ifndef B115200 +#warning Defining B115200 +#define B115200 20 +#endif +*/ #ifdef B115200 { 115200, B115200 }, #endif @@ -308,7 +365,7 @@ translate_speed(bps) /* * Translate from a speed_t to bits/second. */ -int +static int baud_rate_of(speed) int speed; { @@ -328,6 +385,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 +405,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 */ } @@ -405,6 +464,7 @@ restore_tty() * NXFax's capability to determine port usage. * */ +void setdtr(fd, on) int fd, on; { @@ -430,14 +490,17 @@ 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 (errno == EWOULDBLOCK || errno == ENOBUFS + || errno == ENXIO || errno == EIO) { + syslog(LOG_WARNING, "write: warning: %m"); + } else { + syslog(LOG_ERR, "write: %m"); + die(1); + } } } @@ -447,6 +510,7 @@ output(unit, p, len) * for the length of time specified by *timo (indefinite * if timo is NULL). */ +void wait_input(timo) struct timeval *timo; { @@ -570,6 +634,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 +644,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(fd, PPPIOCSCOMPRESS, (caddr_t) &data) >= 0) + return 1; + return (errno == ENOBUFS)? 0: -1; } /* @@ -670,6 +737,7 @@ 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) { @@ -734,7 +802,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 +924,7 @@ dodefaultroute(g, cmd) (cmd == 's') ? "SIOCADDRT" : "SIOCDELRT"); return 0; } + default_route_gateway = (cmd == 's')? g: 0; return 1; } @@ -887,6 +957,7 @@ sifproxyarp(unit, hisaddr) return 0; } + proxy_arp_addr = hisaddr; return 1; } @@ -907,6 +978,7 @@ cifproxyarp(unit, hisaddr) syslog(LOG_WARNING, "ioctl(SIOCDARP): %m"); return 0; } + proxy_arp_addr = 0; return 1; } @@ -989,7 +1061,7 @@ get_ether_addr(ipaddr, hwaddr) return 1; } -int +static int ether_by_host(hostname, etherptr) char *hostname; struct ether_addr *etherptr;