* sys-ultrix.c - System-dependent procedures for setting up
* PPP interfaces on Ultrix systems.
*
- * Copyright (c) 1989 Carnegie Mellon University.
- * Copyright (c) 1995 The Australian National University.
- * All rights reserved.
+ * Copyright (c) 1995-2002 Paul Mackerras. All rights reserved.
*
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by Carnegie Mellon University and The Australian National University.
- * The names of the Universities may not be used to endorse or promote
- * products derived from this software without specific prior written
- * permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. The name(s) of the authors of this software must not be used to
+ * endorse or promote products derived from this software without
+ * prior written permission.
+ *
+ * 3. Redistributions of any form whatsoever must retain the following
+ * acknowledgment:
+ * "This product includes software developed by Paul Mackerras
+ * <paulus@samba.org>".
+ *
+ * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Derived from main.c and pppd.h, which are:
+ *
+ * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The name "Carnegie Mellon University" must not be used to
+ * endorse or promote products derived from this software without
+ * prior written permission. For permission or any legal
+ * details, please contact
+ * Office of Technology Transfer
+ * Carnegie Mellon University
+ * 5000 Forbes Avenue
+ * Pittsburgh, PA 15213-3890
+ * (412) 268-4387, fax: (412) 268-7395
+ * tech-transfer@andrew.cmu.edu
+ *
+ * 4. Redistributions of any form whatsoever must retain the following
+ * acknowledgment:
+ * "This product includes software developed by Computing Services
+ * at Carnegie Mellon University (http://www.cmu.edu/computing/)."
+ *
+ * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
+ * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#ifndef lint
-static char rcsid[] = "$Id: sys-ultrix.c,v 1.27 1999/03/16 22:53:49 paulus Exp $";
-#endif
+#define RCSID "$Id: sys-ultrix.c,v 1.35 2004/11/04 10:02:26 paulus Exp $"
/*
* TODO:
#include "pppd.h"
+static const char rcsid[] = RCSID;
+
static int initdisc = -1; /* Initial TTY discipline for ppp_fd */
static int initfdflags = -1; /* Initial file descriptor flags for ppp_fd */
static int ppp_fd = -1; /* fd which is set to PPP discipline */
sys_init()
{
/* Get an internet socket for doing socket ioctl's on. */
- if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- error("Couldn't create IP socket: %m");
- die(1);
- }
+ if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+ fatal("Couldn't create IP socket: %m");
FD_ZERO(&in_fds);
max_in_fd = 0;
/*
* 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().
+ * This shouldn't call die() because it's called from die().
*/
void
sys_cleanup()
struct ifreq ifr;
if (if_is_up) {
- strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname);
+ strlcpy(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;
return 1;
}
-
+#if 0
/*
* daemon - Detach us from the terminal session.
*/
}
return 0;
}
+#endif
/*
* ppp_available - check whether the system has any ppp interfaces
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
return 1; /* can't tell */
- strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), "ppp0");
+ strlcpy(ifr.ifr_name, "ppp0", sizeof (ifr.ifr_name));
ok = ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) >= 0;
close(s);
/*
* Save the old line discipline of fd, and set it to PPP.
*/
- if (ioctl(fd, TIOCGETD, &initdisc) < 0) {
- error("ioctl(TIOCGETD): %m");
- die(1);
- }
- if (ioctl(fd, TIOCSETD, &pppdisc) < 0) {
- error("ioctl(TIOCSETD): %m");
- die(1);
- }
+ if (ioctl(fd, TIOCGETD, &initdisc) < 0)
+ fatal("ioctl(TIOCGETD): %m");
+ if (ioctl(fd, TIOCSETD, &pppdisc) < 0)
+ fatal("ioctl(TIOCSETD): %m");
/*
* Find out which interface we were given.
*/
- if (ioctl(fd, PPPIOCGUNIT, &ifunit) < 0) {
- error("ioctl(PPPIOCGUNIT): %m");
- die(1);
- }
+ if (ioctl(fd, PPPIOCGUNIT, &ifunit) < 0) {
+ fatal("ioctl(PPPIOCGUNIT): %m");
ppp_fd = fd;
int speed, x;
struct termios tios;
- if (tcgetattr(fd, &tios) < 0) {
- error("tcgetattr: %m");
- die(1);
- }
+ if (tcgetattr(fd, &tios) < 0)
+ fatal("tcgetattr: %m");
if (!restore_term) {
inittermios = tios;
* We can't proceed if the serial port speed is B0,
* since that implies that the serial port is disabled.
*/
- if (speed == B0) {
- error("Baud rate for %s is 0; need explicit baud rate",
- devnam);
- die(1);
- }
+ if (speed == B0)
+ fatal("Baud rate for %s is 0; need explicit baud rate", devnam);
}
- if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
- error("tcsetattr: %m");
- die(1);
- }
+ if (tcsetattr(fd, TCSAFLUSH, &tios) < 0)
+ fatal("tcsetattr: %m");
x = 0;
if (ioctl(fd, (crtscts > 0 || modem)? TIOCMODEM: TIOCNMODEM, &x) < 0)
warn("TIOC(N)CAR: %m");
baud_rate = inspeed = baud_rate_of(speed);
- restore_term = TRUE;
+ restore_term = 1;
}
/*
if (errno != ENXIO)
warn("tcsetattr: %m");
ioctl(fd, TIOCSWINSZ, &wsinfo);
- restore_term = FALSE;
+ restore_term = 0;
}
}
/*
* add_fd - add an fd to the set that wait_input waits for.
*/
-void add_fd(int fd)
+void add_fd(fd)
+ int fd;
{
FD_SET(fd, &in_fds);
if (fd > max_in_fd)
/*
* remove_fd - remove an fd from the set that wait_input waits for.
*/
-void remove_fd(int fd)
+void remove_fd(fd)
+ int fd;
{
FD_CLR(fd, &in_fds);
}
int n;
n = select(0, NULL, NULL, NULL, timo);
- if (n < 0 && errno != EINTR) {
- error("select: %m");
- die(1);
- }
+ if (n < 0 && errno != EINTR)
+ fatal("select: %m");
}
#endif
if ((len = read(ttyfd, buf, PPP_MTU + PPP_HDRLEN)) < 0) {
if (errno == EWOULDBLOCK || errno == EINTR)
return -1;
- error("read(fd): %m");
- die(1);
+ fatal("read(fd): %m");
}
return len;
}
{
u_int x;
- if (ioctl(ppp_fd, PPPIOCSMTU, &mtu) < 0) {
- error("ioctl(PPPIOCSMTU): %m");
- quit();
- }
+ if (ioctl(ppp_fd, PPPIOCSMTU, &mtu) < 0)
+ fatal("ioctl(PPPIOCSMTU): %m");
- if (ioctl(ppp_fd, PPPIOCSASYNCMAP, (caddr_t) &asyncmap) < 0) {
- error("ioctl(PPPIOCSASYNCMAP): %m");
- quit();
- }
+ if (ioctl(ppp_fd, PPPIOCSASYNCMAP, (caddr_t) &asyncmap) < 0)
+ fatal("ioctl(PPPIOCSASYNCMAP): %m");
- if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
- error("ioctl (PPPIOCGFLAGS): %m");
- quit();
- }
+ if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0)
+ fatal("ioctl (PPPIOCGFLAGS): %m");
x = pcomp? x | SC_COMP_PROT: x &~ SC_COMP_PROT;
x = accomp? x | SC_COMP_AC: x &~ SC_COMP_AC;
- if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
- error("ioctl(PPPIOCSFLAGS): %m");
- quit();
- }
+ if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
+ fatal("ioctl(PPPIOCSFLAGS): %m");
}
{
int x;
- if (ioctl(ppp_fd, PPPIOCSMRU, (caddr_t) &mru) < 0) {
- error("ioctl(PPPIOCSMRU): %m");
- quit();
- }
- if (ioctl(ppp_fd, PPPIOCSRASYNCMAP, (caddr_t) &asyncmap) < 0) {
- error("ioctl(PPPIOCSRASYNCMAP): %m");
- quit();
- }
- if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
- error("ioctl (PPPIOCGFLAGS): %m");
- quit();
- }
+ if (ioctl(ppp_fd, PPPIOCSMRU, (caddr_t) &mru) < 0)
+ fatal("ioctl(PPPIOCSMRU): %m");
+ if (ioctl(ppp_fd, PPPIOCSRASYNCMAP, (caddr_t) &asyncmap) < 0)
+ fatal("ioctl(PPPIOCSRASYNCMAP): %m");
+ if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0)
+ fatal("ioctl (PPPIOCGFLAGS): %m");
x = !accomp? x | SC_REJ_COMP_AC: x &~ SC_REJ_COMP_AC;
- if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
- error("ioctl(PPPIOCSFLAGS): %m");
- quit();
- }
+ if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
+ fatal("ioctl(PPPIOCSFLAGS): %m");
}
/*
return ioctl(ppp_fd, PPPIOCGIDLE, ip) >= 0;
}
+/*
+ * get_ppp_stats - return statistics for the link.
+ */
+int
+get_ppp_stats(u, stats)
+ int u;
+ struct pppd_stats *stats;
+{
+ struct ifpppstatsreq req;
+
+ memset (&req, 0, sizeof (req));
+ strlcpy(req.ifr_name, interface, sizeof(req.ifr_name));
+ if (ioctl(sockfd, SIOCGPPPSTATS, &req) < 0) {
+ error("Couldn't get PPP statistics: %m");
+ return 0;
+ }
+ stats->bytes_in = req.stats.p.ppp_ibytes;
+ stats->bytes_out = req.stats.p.ppp_obytes;
+ return 1;
+}
+
/*
* sifvjcomp - config tcp header compression
{
struct ifreq ifr;
- strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
+ strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
error("ioctl (SIOCGIFFLAGS): %m");
return 0;
ioctl(ppp_fd, PPPIOCSNPMODE, (caddr_t) &npi);
/* ignore errors, because ppp_fd might have been closed by now. */
- strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
+ strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
error("ioctl (SIOCGIFFLAGS): %m");
rv = 0;
struct ifreq ifr;
ret = 1;
- strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
+ strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
SET_SA_FAMILY(ifr.ifr_addr, AF_INET);
if (m != 0) {
((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = m;
((char *)&ifr->ifr_addr + sizeof(struct sockaddr))) {
if (ifr->ifr_addr.sa_family == AF_INET) {
ina = ((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr;
- strlcpy(ifreq.ifr_name, sizeof(ifreq.ifr_name), ifr->ifr_name);
+ strlcpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
/*
* Check that the interface is up, and not point-to-point
* or loopback.
/*
* Grab the physical address for this interface.
*/
- strlcpy(ifdevea.ifr_name, sizeof(ifdevea.ifr_name), ifr->ifr_name);
+ strlcpy(ifdevea.ifr_name, ifr->ifr_name, sizeof(ifdevea.ifr_name));
if (ioctl(sockfd, SIOCRPHYSADDR, &ifdevea) < 0) {
error("Couldn't get h/w address for %s: %m", ifr->ifr_name);
return 0;
/*
* Check that the interface is up, and not point-to-point or loopback.
*/
- strlcpy(ifreq.ifr_name, sizeof(ifreq.ifr_name), ifr->ifr_name);
+ strlcpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
if (ioctl(sockfd, SIOCGIFFLAGS, &ifreq) < 0)
continue;
if ((ifreq.ifr_flags & (IFF_UP|IFF_POINTOPOINT|IFF_LOOPBACK))
if ((fd = open(WTMPFILE, O_WRONLY|O_APPEND, 0)) < 0)
return;
if (!fstat(fd, &buf)) {
- strlcpy(ut.ut_line, sizeof(ut.ut_line), line);
- strlcpy(ut.ut_name, sizeof(ut.ut_name), name);
- strlcpy(ut.ut_host, sizeof(ut.ut_host), host);
+ strncpy(ut.ut_line, line, sizeof(ut.ut_line));
+ strncpy(ut.ut_name, name, sizeof(ut.ut_name));
+ strncpy(ut.ut_host, host, sizeof(ut.ut_host));
(void)time(&ut.ut_time);
if (write(fd, (char *)&ut, sizeof(struct utmp)) != sizeof(struct utmp))
(void)ftruncate(fd, buf.st_size);
close(fd);
}
+#if 0
/*
* Routines for locking and unlocking the serial device, moved here
* from chat.c.
lock_file = NULL;
}
}
+#endif