]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/sys-sunos4.c
Patch from Frank Cusack to add support for MSCHAPv2.
[ppp.git] / pppd / sys-sunos4.c
index ba2cc3c7953cd1e57071567464221018575863f1..89eebf9071f045743b638559e02be9c18baa652f 100644 (file)
@@ -25,9 +25,7 @@
  * OR MODIFICATIONS.
  */
 
-#ifndef lint
-static char rcsid[] = "$Id: sys-sunos4.c,v 1.16 1999/03/19 01:29:47 paulus Exp $";
-#endif
+#define RCSID  "$Id: sys-sunos4.c,v 1.29 2002/02/12 20:07:09 dfs Exp $"
 
 #include <stdio.h>
 #include <stddef.h>
@@ -67,6 +65,8 @@ extern void *alloca();
 #endif
 #endif /*sparc*/
 
+static const char rcsid[] = RCSID;
+
 static int     pppfd;
 static int     fdmuxid = -1;
 static int     iffd;
@@ -201,7 +201,7 @@ sys_check_options()
     return 1;
 }
 
-
+#if 0
 /*
  * daemon - Detach us from controlling terminal session.
  */
@@ -225,6 +225,7 @@ daemon(nochdir, noclose)
     }
     return 0;
 }
+#endif
 
 /*
  * ppp_available - check whether the system has any ppp interfaces
@@ -238,10 +239,10 @@ ppp_available()
 }
 
 /*
- * establish_ppp - Turn the serial port into a ppp interface.
+ * tty_establish_ppp - Turn the serial port into a ppp interface.
  */
 int
-establish_ppp(fd)
+tty_establish_ppp(fd)
     int fd;
 {
     int i;
@@ -266,22 +267,13 @@ establish_ppp(fd)
     return pppfd;
 }
 
-/*
- * restore_loop - reattach the ppp unit to the loopback.
- * This doesn't need to do anything because disestablish_ppp does it.
- */
-void
-restore_loop()
-{
-}
-
 /*
  * disestablish_ppp - Restore the serial port to normal operation.
  * It attempts to reconstruct the stream with the previously popped
  * modules.  This shouldn't call die() because it's called from die().
  */
 void
-disestablish_ppp(fd)
+tty_disestablish_ppp(fd)
     int fd;
 {
     int i;
@@ -582,8 +574,8 @@ output(unit, p, len)
     int retries;
     struct pollfd pfd;
 
-    if (debug)
-       dbglog("sent %P", p, len);
+    dump_packet("sent", p, len);
+    if (snoop_send_hook) snoop_send_hook(p, len);
 
     data.len = len;
     data.buf = (caddr_t) p;
@@ -613,10 +605,53 @@ wait_input(timo)
     int t;
 
     t = timo == NULL? -1: timo->tv_sec * 1000 + timo->tv_usec / 1000;
-    if (poll(pollfds, n_pollfds, t) < 0 && errno != EINTR)
-       fatal("poll: %m");
+    if (poll(pollfds, n_pollfds, t) < 0 && errno != EINTR) {
+       if (errno != EAGAIN)
+           fatal("poll: %m");
+       /* we can get EAGAIN on a heavily loaded system,
+        * just wait a short time and try again. */
+       usleep(50000);
+    }
 }
 
+/*
+ * add_fd - add an fd to the set that wait_input waits for.
+ */
+void add_fd(fd)
+    int fd;
+{
+    int n;
+
+    for (n = 0; n < n_pollfds; ++n)
+       if (pollfds[n].fd == fd)
+           return;
+    if (n_pollfds < MAX_POLLFDS) {
+       pollfds[n_pollfds].fd = fd;
+       pollfds[n_pollfds].events = POLLIN | POLLPRI | POLLHUP;
+       ++n_pollfds;
+    } else
+       error("Too many inputs!");
+}
+
+/*
+ * remove_fd - remove an fd from the set that wait_input waits for.
+ */
+void remove_fd(fd)
+    int fd;
+{
+    int n;
+
+    for (n = 0; n < n_pollfds; ++n) {
+       if (pollfds[n].fd == fd) {
+           while (++n < n_pollfds)
+               pollfds[n-1] = pollfds[n];
+           --n_pollfds;
+           break;
+       }
+    }
+}
+
+#if 0
 /*
  * wait_loop_output - wait until there is data available on the
  * loopback, for the length of time specified by *timo (indefinite
@@ -643,7 +678,7 @@ wait_time(timo)
     if (n < 0 && errno != EINTR)
        fatal("select: %m");
 }
-
+#endif
 
 /*
  * read_packet - get a PPP packet from the serial device.
@@ -664,7 +699,7 @@ read_packet(buf)
        flags = 0;
        len = getmsg(pppfd, &ctrl, &data, &flags);
        if (len < 0) {
-           if (errno = EAGAIN || errno == EINTR)
+           if (errno == EAGAIN || errno == EINTR)
                return -1;
            fatal("Error reading packet: %m");
        }
@@ -700,17 +735,33 @@ get_loop_output()
 }
 
 /*
- * ppp_send_config - configure the transmit characteristics of
- * the ppp interface.
+ * netif_set_mtu - set the MTU on the PPP network interface.
  */
 void
-ppp_send_config(unit, mtu, asyncmap, pcomp, accomp)
+netif_set_mtu(unit, mtu)
     int unit, mtu;
+{
+    struct ifreq ifr;
+
+    memset(&ifr, 0, sizeof(ifr));
+    strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+    ifr.ifr_metric = link_mtu;
+    if (ioctl(sockfd, SIOCSIFMTU, &ifr) < 0) {
+       error("Couldn't set IP MTU: %m");
+    }
+}
+
+/*
+ * tty_send_config - configure the transmit characteristics of
+ * the ppp interface.
+ */
+void
+tty_send_config(mtu, asyncmap, pcomp, accomp)
+    int mtu;
     u_int32_t asyncmap;
     int pcomp, accomp;
 {
     int cf[2];
-    struct ifreq ifr;
 
     link_mtu = mtu;
     if (strioctl(pppfd, PPPIO_MTU, &mtu, sizeof(mtu), 0) < 0) {
@@ -726,21 +777,13 @@ ppp_send_config(unit, mtu, asyncmap, pcomp, accomp)
     if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
        error("Couldn't set prot/AC compression: %m");
     }
-
-    /* set mtu for ip as well */
-    memset(&ifr, 0, sizeof(ifr));
-    strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
-    ifr.ifr_metric = link_mtu;
-    if (ioctl(sockfd, SIOCSIFMTU, &ifr) < 0) {
-       error("Couldn't set IP MTU: %m");
-    }
 }
 
 /*
- * ppp_set_xaccm - set the extended transmit ACCM for the interface.
+ * tty_set_xaccm - set the extended transmit ACCM for the interface.
  */
 void
-ppp_set_xaccm(unit, accm)
+tty_set_xaccm(unit, accm)
     int unit;
     ext_accm accm;
 {
@@ -751,12 +794,12 @@ ppp_set_xaccm(unit, accm)
 }
 
 /*
- * ppp_recv_config - configure the receive-side characteristics of
+ * tty_recv_config - configure the receive-side characteristics of
  * the ppp interface.
  */
 void
-ppp_recv_config(unit, mru, asyncmap, pcomp, accomp)
-    int unit, mru;
+tty_recv_config(mru, asyncmap, pcomp, accomp)
+    int mru;
     u_int32_t asyncmap;
     int pcomp, accomp;
 {
@@ -821,6 +864,27 @@ get_idle_time(u, ip)
     return strioctl(pppfd, PPPIO_GIDLE, ip, 0, sizeof(struct ppp_idle)) >= 0;
 }
 
+/*
+ * get_ppp_stats - return statistics for the link.
+ */
+int
+get_ppp_stats(u, stats)
+    int u;
+    struct pppd_stats *stats;
+{
+    struct ppp_stats s;
+
+    if (strioctl(pppfd, PPPIO_GETSTAT, &s, 0, sizeof(s)) < 0) {
+       error("Couldn't get link statistics: %m");
+       return 0;
+    }
+    stats->bytes_in = s.p.ppp_ibytes;
+    stats->bytes_out = s.p.ppp_obytes;
+    stats->pkts_in = s.p.ppp_ipackets;
+    stats->pkts_out = s.p.ppp_opackets;
+    return 1;
+}
+
 
 /*
  * ccp_fatal_error - returns 1 if decompression was disabled as a
@@ -1214,9 +1278,9 @@ logwtmp(line, name, host)
     if ((fd = open(WTMPFILE, O_WRONLY|O_APPEND, 0)) < 0)
        return;
     if (!fstat(fd, &buf)) {
-       strlcpy(ut.ut_line, line, sizeof(ut.ut_line));
-       strlcpy(ut.ut_name, name, sizeof(ut.ut_name));
-       strlcpy(ut.ut_host, host, sizeof(ut.ut_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);
@@ -1319,6 +1383,7 @@ get_host_seed()
     return gethostid();
 }
 
+#if 0
 /*
  * Code for locking/unlocking the serial device.
  * This code is derived from chat.c.
@@ -1422,6 +1487,57 @@ unlock()
        lock_file = NULL;
     }
 }
+#endif /* lock stuff removed */
+
+/*
+ * get_pty - get a pty master/slave pair and chown the slave side
+ * to the uid given.  Assumes slave_name points to >= 12 bytes of space.
+ */
+int
+get_pty(master_fdp, slave_fdp, slave_name, uid)
+    int *master_fdp;
+    int *slave_fdp;
+    char *slave_name;
+    int uid;
+{
+    int i, mfd, sfd;
+    char pty_name[12];
+    struct termios tios;
+
+    sfd = -1;
+    for (i = 0; i < 64; ++i) {
+       slprintf(pty_name, sizeof(pty_name), "/dev/pty%c%x",
+                'p' + i / 16, i % 16);
+       mfd = open(pty_name, O_RDWR, 0);
+       if (mfd >= 0) {
+           pty_name[5] = 't';
+           sfd = open(pty_name, O_RDWR | O_NOCTTY, 0);
+           if (sfd >= 0)
+               break;
+           close(mfd);
+       }
+    }
+    if (sfd < 0)
+       return 0;
+
+    strlcpy(slave_name, pty_name, 12);
+    *master_fdp = mfd;
+    *slave_fdp = sfd;
+    fchown(sfd, uid, -1);
+    fchmod(sfd, S_IRUSR | S_IWUSR);
+    if (tcgetattr(sfd, &tios) == 0) {
+       tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB);
+       tios.c_cflag |= CS8 | CREAD;
+       tios.c_iflag  = IGNPAR | CLOCAL;
+       tios.c_oflag  = 0;
+       tios.c_lflag  = 0;
+       if (tcsetattr(sfd, TCSAFLUSH, &tios) < 0)
+           warn("couldn't set attributes on pty: %m");
+    } else
+       warn("couldn't get attributes on pty: %m");
+
+    return 1;
+}
 
 /*
  * SunOS doesn't have strtoul :-(