From: Paul Mackerras Date: Fri, 27 Oct 1995 03:51:52 +0000 (+0000) Subject: Add prototypes; implement sys_cleanup; ccp_test provides more info; X-Git-Tag: RELEASE_2_3_6~597 X-Git-Url: https://git.ozlabs.org/?p=ppp.git;a=commitdiff_plain;h=65445bac89a82ee68c6d66ab1afc271e56543f12 Add prototypes; implement sys_cleanup; ccp_test provides more info; fix xon/xoff flow control settings; set device non-blocking; don't exit on write error --- diff --git a/pppd/sys-bsd.c b/pppd/sys-bsd.c index eea6125..14e517a 100644 --- a/pppd/sys-bsd.c +++ b/pppd/sys-bsd.c @@ -19,7 +19,7 @@ */ #ifndef lint -static char rcsid[] = "$Id: sys-bsd.c,v 1.21 1995/08/16 01:40:23 paulus Exp $"; +static char rcsid[] = "$Id: sys-bsd.c,v 1.22 1995/10/27 03:46:27 paulus Exp $"; #endif /* @@ -53,15 +53,26 @@ static char rcsid[] = "$Id: sys-bsd.c,v 1.21 1995/08/16 01:40:23 paulus Exp $"; #include "pppd.h" static int initdisc = -1; /* Initial TTY discipline */ +static int initfdflags = -1; /* Initial file descriptor flags for fd */ + static int rtm_seq; -static int restore_term; /* 1 => we've munged the terminal */ +static int restore_term; /* 1 => we've munged the terminal */ static struct termios inittermios; /* Initial TTY termios */ static struct winsize wsinfo; /* Initial window size info */ static char *lock_file; /* name of lock file created */ -int sockfd; /* socket for doing interface ioctls */ +static int sockfd; /* socket for doing interface ioctls */ + +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 dodefaultroute __P((u_int32_t, int)); +static int get_ether_addr __P((u_int32_t, struct sockaddr_dl *)); + /* * sys_init - System-dependent initialization. @@ -81,6 +92,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. */ @@ -158,6 +194,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"); + } } @@ -171,6 +215,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. @@ -209,6 +258,7 @@ disestablish_ppp() * * For *BSD, we assume that speed_t values numerically equal bits/second. */ +void set_up_tty(fd, local) int fd, local; { @@ -225,7 +275,7 @@ set_up_tty(fd, local) } tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB | CLOCAL); - if (crtscts > 0) + if (crtscts > 0 && !local) tios.c_cflag |= CRTSCTS; else if (crtscts < 0) tios.c_cflag &= ~CRTSCTS; @@ -239,8 +289,8 @@ set_up_tty(fd, local) 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 */ } @@ -298,6 +348,7 @@ restore_tty() * setdtr - control the DTR line on the serial port. * This is called from die(), so it shouldn't call die(). */ +void setdtr(fd, on) int fd, on; { @@ -316,14 +367,12 @@ 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 != EIO) + syslog(LOG_ERR, "write: %m"); } } @@ -333,6 +382,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; { @@ -452,8 +502,11 @@ ppp_recv_config(unit, mru, asyncmap, pcomp, accomp) /* * ccp_test - ask kernel whether a given compression method - * is acceptable for use. + * is acceptable for use. Returns 1 if the method and parameters + * are OK, 0 if the method is known but the parameters are not OK + * (e.g. code size should be reduced), or -1 if the method is unknown. */ +int ccp_test(unit, opt_ptr, opt_len, for_transmit) int unit, opt_len, for_transmit; u_char *opt_ptr; @@ -463,7 +516,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; } /* @@ -554,6 +609,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) { @@ -618,7 +674,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; } @@ -654,10 +711,11 @@ sifaddr(u, o, h, m) BZERO(&ifra.ifra_mask, sizeof(ifra.ifra_mask)); if (ioctl(sockfd, SIOCAIFADDR, (caddr_t) &ifra) < 0) { if (errno != EEXIST) { - syslog(LOG_ERR, "ioctl(SIOCAIFADDR): %m"); + syslog(LOG_ERR, "Couldn't set interface address: %m"); return 0; } - syslog(LOG_WARNING, "ioctl(SIOCAIFADDR): Address already exists"); + syslog(LOG_WARNING, + "Couldn't set interface address: Address already exists"); } return 1; } @@ -680,7 +738,7 @@ cifaddr(u, o, h) ((struct sockaddr_in *) &ifra.ifra_broadaddr)->sin_addr.s_addr = h; BZERO(&ifra.ifra_mask, sizeof(ifra.ifra_mask)); if (ioctl(sockfd, SIOCDIFADDR, (caddr_t) &ifra) < 0) { - syslog(LOG_WARNING, "ioctl(SIOCDIFADDR): %m"); + syslog(LOG_WARNING, "Couldn't delete interface address: %m"); return 0; } return 1; @@ -711,7 +769,7 @@ cifdefaultroute(u, g) /* * dodefaultroute - talk to a routing socket to add/delete a default route. */ -int +static int dodefaultroute(g, cmd) u_int32_t g; int cmd; @@ -725,7 +783,8 @@ dodefaultroute(g, cmd) } rtmsg; if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) { - syslog(LOG_ERR, "%cifdefaultroute: opening routing socket: %m", cmd); + syslog(LOG_ERR, "Couldn't %s default route: socket: %m", + cmd=='s'? "add": "delete"); return 0; } @@ -745,12 +804,14 @@ dodefaultroute(g, cmd) rtmsg.hdr.rtm_msglen = sizeof(rtmsg); if (write(routes, &rtmsg, sizeof(rtmsg)) < 0) { - syslog(LOG_ERR, "%s default route: %m", cmd=='s'? "add": "delete"); + syslog(LOG_ERR, "Couldn't %s default route: %m", + cmd=='s'? "add": "delete"); close(routes); return 0; } close(routes); + default_route_gateway = (cmd == 's')? g: 0; return 1; } @@ -787,7 +848,7 @@ sifproxyarp(unit, hisaddr) } if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) { - syslog(LOG_ERR, "sifproxyarp: opening routing socket: %m"); + syslog(LOG_ERR, "Couldn't add proxy arp entry: socket: %m"); return 0; } @@ -805,13 +866,14 @@ sifproxyarp(unit, hisaddr) arpmsg.hdr.rtm_msglen = (char *) &arpmsg.hwa - (char *) &arpmsg + arpmsg.hwa.sdl_len; if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) { - syslog(LOG_ERR, "add proxy arp entry: %m"); + syslog(LOG_ERR, "Couldn't add proxy arp entry: %m"); close(routes); return 0; } close(routes); arpmsg_valid = 1; + proxy_arp_addr = hisaddr; return 1; } @@ -833,17 +895,18 @@ cifproxyarp(unit, hisaddr) arpmsg.hdr.rtm_seq = ++rtm_seq; if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) { - syslog(LOG_ERR, "sifproxyarp: opening routing socket: %m"); + syslog(LOG_ERR, "Couldn't delete proxy arp entry: socket: %m"); return 0; } if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) { - syslog(LOG_ERR, "delete proxy arp entry: %m"); + syslog(LOG_ERR, "Couldn't delete proxy arp entry: %m"); close(routes); return 0; } close(routes); + proxy_arp_addr = 0; return 1; } @@ -881,10 +944,11 @@ sifproxyarp(unit, hisaddr) ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr; arpreq.arp_flags = ATF_PERM | ATF_PUBL; if (ioctl(sockfd, SIOCSARP, (caddr_t)&arpreq) < 0) { - syslog(LOG_ERR, "ioctl(SIOCSARP): %m"); + syslog(LOG_ERR, "Couldn't add proxy arp entry: %m"); return 0; } + proxy_arp_addr = hisaddr; return 1; } @@ -902,9 +966,10 @@ cifproxyarp(unit, hisaddr) SET_SA_FAMILY(arpreq.arp_pa, AF_INET); ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr; if (ioctl(sockfd, SIOCDARP, (caddr_t)&arpreq) < 0) { - syslog(LOG_WARNING, "ioctl(SIOCDARP): %m"); + syslog(LOG_WARNING, "Couldn't delete proxy arp entry: %m"); return 0; } + proxy_arp_addr = 0; return 1; } #endif /* RTM_VERSION */ @@ -916,7 +981,7 @@ cifproxyarp(unit, hisaddr) */ #define MAX_IFS 32 -int +static int get_ether_addr(ipaddr, hwaddr) u_int32_t ipaddr; struct sockaddr_dl *hwaddr; @@ -1125,6 +1190,7 @@ lock(dev) /* * unlock - remove our lockfile */ +void unlock() { if (lock_file) { diff --git a/pppd/sys-linux.c b/pppd/sys-linux.c index 1c4b8f3..705fa30 100644 --- a/pppd/sys-linux.c +++ b/pppd/sys-linux.c @@ -52,6 +52,7 @@ #include "ipcp.h" static int initdisc = -1; /* Initial TTY discipline */ +static int initfdflags = -1; /* Initial file descriptor flags for fd */ static int prev_kdebugflag = 0; static int has_default_route = 0; static int has_proxy_arp = 0; @@ -61,7 +62,11 @@ static int driver_patch = 0; static int restore_term = 0; /* 1 => we've munged the terminal */ static struct termios inittermios; /* Initial TTY termios */ -int sockfd; /* socket for doing interface ioctls */ +static int sockfd; /* socket for doing interface ioctls */ + +static int if_is_up; /* Interface has been marked up */ +static u_int32_t default_route_gateway; /* Gateway for default route added */ +static u_int32_t proxy_arp_addr; /* Addr for proxy arp entry added */ static char *lock_file; @@ -71,6 +76,20 @@ static char *lock_file; #define FLAGS_MASK (IFF_UP | IFF_BROADCAST | \ IFF_POINTOPOINT | IFF_LOOPBACK | IFF_NOARP) +/* Prototypes for procedures local to this file. */ +static int get_flags (void); +static void set_flags (int flags); +static int translate_speed (int bps); +static int baud_rate_of (int speed); +static char *path_to_route (void); +static void close_route_table (void); +static int open_route_table (void); +static int read_route_table (struct rtentry *rt); +static int defaultroute_exists (void); +static int get_ether_addr (u_int32_t ipaddr, struct sockaddr *hwaddr); +static void decode_version (char *buf, int *version, int *mod, int *patch); + + /* * SET_SA_FAMILY - set the sa_family field of a struct sockaddr, * if it exists. @@ -138,6 +157,24 @@ void sys_init(void) } } +/* + * 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) + sifdown(0); + /* XXX maybe we need to delete the route through the interface */ + if (has_default_route) + cifdefaultroute(0, default_route_gateway); + if (has_proxy_arp) + cifproxyarp(0, proxy_arp_addr); +} + /* * note_debug_level - note a change in the debug level. */ @@ -218,6 +255,15 @@ void establish_ppp (void) MAINDEBUG ((LOG_NOTICE, "Using version %d.%d.%d of PPP driver", driver_version, driver_modification, driver_patch)); + + /* + * 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"); + } } /* @@ -229,6 +275,12 @@ void disestablish_ppp(void) { 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 this is no longer PPP mode then there is nothing that can be done * about restoring the previous mode. @@ -378,7 +430,7 @@ struct speed { * Translate from bits/second to a speed_t. */ -int translate_speed (int bps) +static int translate_speed (int bps) { struct speed *speedp; @@ -400,7 +452,7 @@ int translate_speed (int bps) * Translate from a speed_t to bits/second. */ -int baud_rate_of (int speed) +static int baud_rate_of (int speed) { struct speed *speedp; @@ -459,8 +511,8 @@ void set_up_tty (int fd, int local) tios.c_cflag |= CRTSCTS; break; - case 2: - tios.c_iflag |= IXOFF; + case -2: + tios.c_iflag |= IXON | IXOFF; tios.c_cc[VSTOP] = 0x13; /* DC3 = XOFF = ^S */ tios.c_cc[VSTART] = 0x11; /* DC1 = XON = ^Q */ break; @@ -552,11 +604,6 @@ void restore_tty (void) void output (int unit, unsigned char *p, int len) { - if (unit != 0) - { - MAINDEBUG((LOG_WARNING, "output: unit != 0!")); - } - if (debug) { log_packet(p, len, "sent "); @@ -564,8 +611,16 @@ void output (int unit, unsigned char *p, int len) 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); + } } } @@ -724,7 +779,10 @@ int ccp_test (int unit, u_char *opt_ptr, int opt_len, int for_transmit) 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; } /* @@ -801,6 +859,7 @@ int sifup (int u) syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m"); return 0; } + if_is_up = 1; return 1; } @@ -827,6 +886,7 @@ int sifdown (int u) syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m"); return 0; } + if_is_up = 0; return 1; } @@ -1125,6 +1185,7 @@ int sifdefaultroute (int unit, int gateway) } } has_default_route = 1; + default_route_gateway = g; return 1; } @@ -1189,6 +1250,7 @@ int sifproxyarp (int unit, u_int32_t his_adr) } } + proxy_arp_addr = hisaddr; has_proxy_arp = 1; return 1; } @@ -1222,7 +1284,7 @@ int cifproxyarp (int unit, u_int32_t his_adr) * the same subnet as ipaddr. */ -int get_ether_addr (u_int32_t ipaddr, struct sockaddr *hwaddr) +static int get_ether_addr (u_int32_t ipaddr, struct sockaddr *hwaddr) { struct ifreq *ifr, *ifend, *ifp; int i; diff --git a/pppd/sys-ultrix.c b/pppd/sys-ultrix.c index 7fc4034..7d9795b 100644 --- a/pppd/sys-ultrix.c +++ b/pppd/sys-ultrix.c @@ -19,7 +19,7 @@ */ #ifndef lint -static char rcsid[] = "$Id: sys-ultrix.c,v 1.14 1995/08/11 02:36:26 paulus Exp $"; +static char rcsid[] = "$Id: sys-ultrix.c,v 1.15 1995/10/27 03:51:52 paulus Exp $"; #endif /* @@ -49,14 +49,25 @@ static char rcsid[] = "$Id: sys-ultrix.c,v 1.14 1995/08/11 02:36:26 paulus Exp $ #include "pppd.h" static int initdisc = -1; /* Initial TTY discipline */ +static int initfdflags = -1; /* Initial file descriptor flags for fd */ -static int restore_term; /* 1 => we've munged the terminal */ +static int restore_term; /* 1 => we've munged the terminal */ static struct termios inittermios; /* Initial TTY termios */ static struct winsize wsinfo; /* Initial window size info */ -static char *lock_file; +static char *lock_file; /* name of lock file created */ + +static int sockfd; /* socket for doing interface ioctls */ + +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 get_ether_addr __P((u_int32_t, struct sockaddr *)); -int sockfd; /* socket for doing interface ioctls */ /* * sys_init - System-dependent initialization. @@ -73,6 +84,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. */ @@ -106,29 +142,31 @@ daemon(nochdir, noclose) return 0; } - /* * ppp_available - check whether the system has any ppp interfaces * (in fact we check whether we can do an ioctl on ppp0). */ - int ppp_available() { int s, ok; struct ifreq ifr; + extern char *no_ppp_msg; if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) - return 1; /* can't tell - maybe we're not root */ + return 1; /* can't tell */ strncpy(ifr.ifr_name, "ppp0", sizeof (ifr.ifr_name)); ok = ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) >= 0; close(s); + no_ppp_msg = "\ +This system lacks kernel support for PPP. To include PPP support\n\ +in the kernel, please follow the steps detailed in the README.ultrix\n\ +file in the ppp-2.2 distribution.\n"; return ok; } - /* * establish_ppp - Turn the serial port into a ppp interface. */ @@ -167,6 +205,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"); + } } @@ -180,6 +226,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. @@ -326,6 +377,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; { @@ -344,7 +396,7 @@ set_up_tty(fd, local) tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB | CLOCAL); #ifdef CRTSCTS - if (crtscts > 0) + if (crtscts > 0 && !local) tios.c_cflag |= CRTSCTS; else if (crtscts < 0) tios.c_cflag &= ~CRTSCTS; @@ -359,8 +411,8 @@ set_up_tty(fd, local) 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 */ } @@ -388,7 +440,7 @@ set_up_tty(fd, local) } x = 0; - if (ioctl(fd, (crtscts || modem)? TIOCMODEM: TIOCNMODEM, &x) < 0) + if (ioctl(fd, (crtscts > 0 || modem)? TIOCMODEM: TIOCNMODEM, &x) < 0) syslog(LOG_WARNING, "TIOC(N)MODEM: %m"); if (ioctl(fd, (local || !modem)? TIOCNCAR: TIOCCAR) < 0) syslog(LOG_WARNING, "TIOC(N)CAR: %m"); @@ -425,6 +477,7 @@ restore_tty() * setdtr - control the DTR line on the serial port. * This is called from die(), so it shouldn't call die(). */ +void setdtr(fd, on) int fd, on; { @@ -443,14 +496,12 @@ 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 != EIO) + syslog(LOG_ERR, "write: %m"); } } @@ -460,6 +511,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; { @@ -486,10 +538,8 @@ read_packet(buf) int len; if ((len = read(fd, buf, PPP_MTU + PPP_HDRLEN)) < 0) { - if (errno == EWOULDBLOCK || errno == EINTR) { - MAINDEBUG((LOG_DEBUG, "read(fd): %m")); + if (errno == EWOULDBLOCK || errno == EINTR) return -1; - } syslog(LOG_ERR, "read(fd): %m"); die(1); } @@ -578,8 +628,11 @@ ppp_recv_config(unit, mru, asyncmap, pcomp, accomp) /* * ccp_test - ask kernel whether a given compression method - * is acceptable for use. + * is acceptable for use. Returns 1 if the method and parameters + * are OK, 0 if the method is known but the parameters are not OK + * (e.g. code size should be reduced), or -1 if the method is unknown. */ +int ccp_test(unit, opt_ptr, opt_len, for_transmit) int unit, opt_len, for_transmit; u_char *opt_ptr; @@ -589,7 +642,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; } /* @@ -680,6 +735,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) { @@ -744,7 +800,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; } @@ -831,6 +888,7 @@ sifdefaultroute(u, g) syslog(LOG_ERR, "default route ioctl(SIOCADDRT): %m"); return 0; } + default_route_gateway = g; return 1; } @@ -848,6 +906,8 @@ cifdefaultroute(u, g) rt.rt_flags = RTF_GATEWAY; if (ioctl(sockfd, SIOCDELRT, &rt) < 0) syslog(LOG_WARNING, "default route ioctl(SIOCDELRT): %m"); + default_route_gateway = 0; + return 1; } /* @@ -875,10 +935,11 @@ sifproxyarp(unit, hisaddr) ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr; arpreq.arp_flags = ATF_PERM | ATF_PUBL; if (ioctl(sockfd, SIOCSARP, (caddr_t)&arpreq) < 0) { - syslog(LOG_ERR, "ioctl(SIOCSARP): %m"); + syslog(LOG_ERR, "Couldn't add proxy arp entry: %m"); return 0; } + proxy_arp_addr = hisaddr; return 1; } @@ -896,9 +957,10 @@ cifproxyarp(unit, hisaddr) SET_SA_FAMILY(arpreq.arp_pa, AF_INET); ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr; if (ioctl(sockfd, SIOCDARP, (caddr_t)&arpreq) < 0) { - syslog(LOG_WARNING, "ioctl(SIOCDARP): %m"); + syslog(LOG_WARNING, "Couldn't delete proxy arp entry: %m"); return 0; } + proxy_arp_addr = 0; return 1; } @@ -908,7 +970,7 @@ cifproxyarp(unit, hisaddr) */ #define MAX_IFS 32 -int +static int get_ether_addr(ipaddr, hwaddr) u_int32_t ipaddr; struct sockaddr *hwaddr; @@ -956,8 +1018,8 @@ get_ether_addr(ipaddr, hwaddr) if ((ipaddr & mask) != (ina & mask)) continue; - break; - } + break; + } } if (ifr >= ifend)