X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Fsys-svr4.c;h=08a2a01fd46599a338e7c527e6c91c31f92dcd87;hp=68e38cda5d757ab8b2d2f46d97da39e9ae8036f8;hb=70af02f3c54ba0ad45fe62e10ee7b71050b55c7b;hpb=4424e3f9ec75db16898568ca4453066e0e45a51b diff --git a/pppd/sys-svr4.c b/pppd/sys-svr4.c index 68e38cd..08a2a01 100644 --- a/pppd/sys-svr4.c +++ b/pppd/sys-svr4.c @@ -26,7 +26,7 @@ */ #ifndef lint -static char rcsid[] = "$Id: sys-svr4.c,v 1.2 1995/06/01 01:31:28 paulus Exp $"; +static char rcsid[] = "$Id: sys-svr4.c,v 1.4 1995/08/10 06:53:39 paulus Exp $"; #endif #include @@ -37,6 +37,7 @@ static char rcsid[] = "$Id: sys-svr4.c,v 1.2 1995/06/01 01:31:28 paulus Exp $"; #include #include #include +#include #include #include #include @@ -63,6 +64,7 @@ static int ipmuxid = -1; static int restore_term; static struct termios inittermios; +static pid_t tty_sid; /* original session ID for terminal */ static int link_mtu, link_mru; @@ -143,7 +145,10 @@ ppp_available() void establish_ppp() { - int i; + int i, ifd; + + if (default_device) + tty_sid = getsid((pid_t)0); pppfd = open("/dev/ppp", O_RDWR | O_NONBLOCK, 0); if (pppfd < 0) { @@ -157,6 +162,28 @@ establish_ppp() die(1); } + /* + * Open the ppp device again and link it under the ip multiplexor. + * IP will assign a unit number which hopefully is the same as ifunit. + * I don't know any way to be certain they will be the same. :-( + */ + ifd = open("/dev/ppp", O_RDWR, 0); + if (ifd < 0) { + syslog(LOG_ERR, "Can't open /dev/ppp (2): %m"); + die(1); + } + if (ioctl(ifd, I_PUSH, "ip") < 0) { + syslog(LOG_ERR, "Can't push IP module: %m"); + close(ifd); + die(1); + } + ipmuxid = ioctl(ipfd, I_LINK, ifd); + close(ifd); + if (ipmuxid < 0) { + syslog(LOG_ERR, "Can't link PPP device to IP: %m"); + die(1); + } + /* Pop any existing modules off the tty stream. */ for (i = 0;; ++i) if (ioctl(fd, I_LOOK, tty_modules[i]) < 0 @@ -205,6 +232,16 @@ disestablish_ppp() syslog(LOG_ERR, "Couldn't restore tty module %s: %m", tty_modules[i]); } + if (hungup && default_device && tty_sid > 0) { + /* + * If we have received a hangup, we need to send a SIGHUP + * to the terminal's controlling process. The reason is + * that the original stream head for the terminal hasn't + * seen the M_HANGUP message (it went up through the ppp + * driver to the stream head for our fd to /dev/ppp). + */ + kill(tty_sid, SIGHUP); + } } } @@ -659,10 +696,6 @@ sifup(u) { struct ifreq ifr; - if (ipmuxid < 0) { - syslog(LOG_DEBUG, "sifup: not plumbed!"); - return 0; - } strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); if (ioctl(ipfd, SIOCGIFFLAGS, &ifr) < 0) { syslog(LOG_ERR, "Couldn't mark interface up (get): %m"); @@ -710,26 +743,8 @@ sifaddr(u, o, h, m) int u; u_int32_t o, h, m; { - int fd; struct ifreq ifr; - fd = open("/dev/ppp", O_RDWR, 0); - if (fd < 0) { - syslog(LOG_ERR, "Can't open /dev/ppp (2): %m"); - die(1); - } - if (ioctl(fd, I_PUSH, "ip") < 0) { - syslog(LOG_ERR, "Can't push IP module: %m"); - close(fd); - return 0; - } - ipmuxid = ioctl(ipfd, I_LINK, fd); - close(fd); - if (ipmuxid < 0) { - syslog(LOG_ERR, "Can't link PPP device to IP: %m"); - return 0; - } - memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); ifr.ifr_addr.sa_family = AF_INET; @@ -764,6 +779,7 @@ cifaddr(u, o, h) int u; u_int32_t o, h; { +#if 0 if (ipmuxid >= 0) { if (ioctl(ipfd, I_UNLINK, ipmuxid) < 0) { syslog(LOG_ERR, "Can't remove ppp interface unit: %m"); @@ -771,6 +787,7 @@ cifaddr(u, o, h) } ipmuxid = -1; } +#endif return 1; } @@ -1160,7 +1177,7 @@ gethostid() syslog(LOG_ERR, "sysinfo: %m"); return 0; } - return strtol(buf, NULL, 16); + return (int) strtoul(buf, NULL, 16); } int