]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/sys-sunos4.c
fix up MD4 stuff - interface is better now
[ppp.git] / pppd / sys-sunos4.c
index 305b6b4b49f9e5d72db4bd37b5313f0176333305..74c0217ef2908d7c5ae160164b53dc0a42fec180 100644 (file)
@@ -26,7 +26,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: sys-sunos4.c,v 1.3 1996/01/01 23:06:37 paulus Exp $";
+static char rcsid[] = "$Id: sys-sunos4.c,v 1.8 1997/04/30 05:58:52 paulus Exp $";
 #endif
 
 #include <stdio.h>
@@ -63,6 +63,9 @@ static char rcsid[] = "$Id: sys-sunos4.c,v 1.3 1996/01/01 23:06:37 paulus Exp $"
 
 #if defined(sun) && defined(sparc)
 #include <alloca.h>
+#ifndef __GNUC__
+extern void *alloca();
+#endif
 #endif /*sparc*/
 
 static int     pppfd;
@@ -84,6 +87,7 @@ static int    tty_nmodules;
 static char    tty_modules[NMODULES][FMNAMESZ+1];
 
 static int     if_is_up;       /* Interface has been marked up */
+static u_int32_t ifaddrs[2];   /* local and remote addresses */
 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 */
 
@@ -102,11 +106,6 @@ sys_init()
 {
     int x;
 
-    openlog("pppd", LOG_PID | LOG_NDELAY, LOG_PPP);
-    setlogmask(LOG_UPTO(LOG_INFO));
-    if (debug)
-       setlogmask(LOG_UPTO(LOG_DEBUG));
-
     /* Get an internet socket for doing socket ioctl's on. */
     if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
        syslog(LOG_ERR, "Couldn't create IP socket: %m");
@@ -178,15 +177,17 @@ 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().
+ * This shouldn't call die() because it's called from die().
  */
 void
 sys_cleanup()
 {
     if (if_is_up)
        sifdown(0);
+    if (ifaddrs[0])
+       cifaddr(0, ifaddrs[0], ifaddrs[1]);
     if (default_route_gateway)
-       cifdefaultroute(0, default_route_gateway);
+       cifdefaultroute(0, 0, default_route_gateway);
     if (proxy_arp_addr)
        cifproxyarp(0, proxy_arp_addr);
 }
@@ -200,7 +201,6 @@ sys_close()
     close(iffd);
     close(pppfd);
     close(sockfd);
-    closelog();
 }
 
 /*
@@ -236,19 +236,6 @@ daemon(nochdir, noclose)
     return 0;
 }
 
-/*
- * note_debug_level - note a change in the debug level.
- */
-void
-note_debug_level()
-{
-    if (debug) {
-       setlogmask(LOG_UPTO(LOG_DEBUG));
-    } else {
-       setlogmask(LOG_UPTO(LOG_WARNING));
-    }
-}
-
 /*
  * ppp_available - check whether the system has any ppp interfaces
  */
@@ -616,7 +603,7 @@ output(unit, p, len)
     struct pollfd pfd;
 
     if (debug)
-       log_packet(p, len, "sent ");
+       log_packet(p, len, "sent ", LOG_DEBUG);
 
     data.len = len;
     data.buf = (caddr_t) p;
@@ -660,6 +647,7 @@ wait_input(timo)
  * loopback, for the length of time specified by *timo (indefinite
  * if timo is NULL).
  */
+void
 wait_loop_output(timo)
     struct timeval *timo;
 {
@@ -670,6 +658,7 @@ wait_loop_output(timo)
  * wait_time - wait for a given length of time or until a
  * signal is received.
  */
+void
 wait_time(timo)
     struct timeval *timo;
 {
@@ -749,6 +738,7 @@ ppp_send_config(unit, mtu, asyncmap, pcomp, accomp)
     int pcomp, accomp;
 {
     int cf[2];
+    struct ifreq ifr;
 
     link_mtu = mtu;
     if (strioctl(pppfd, PPPIO_MTU, &mtu, sizeof(mtu), 0) < 0) {
@@ -764,6 +754,14 @@ ppp_send_config(unit, mtu, asyncmap, pcomp, accomp)
     if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
        syslog(LOG_ERR, "Couldn't set prot/AC compression: %m");
     }
+
+    /* set mtu for ip as well */
+    memset(&ifr, 0, sizeof(ifr));
+    strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+    ifr.ifr_metric = link_mtu;
+    if (ioctl(sockfd, SIOCSIFMTU, &ifr) < 0) {
+       syslog(LOG_ERR, "Couldn't set IP MTU: %m");
+    }
 }
 
 /*
@@ -962,7 +960,7 @@ sifnpmode(u, proto, mode)
 
     npi[0] = proto;
     npi[1] = (int) mode;
-    if (strioctl(pppfd, PPPIO_NPMODE, &npi, 2 * sizeof(int), 0) < 0) {
+    if (strioctl(pppfd, PPPIO_NPMODE, npi, 2 * sizeof(int), 0) < 0) {
        syslog(LOG_ERR, "ioctl(set NP %d mode to %d): %m", proto, mode);
        return 0;
     }
@@ -984,6 +982,11 @@ sifaddr(u, o, h, m)
     memset(&ifr, 0, sizeof(ifr));
     strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
     ifr.ifr_addr.sa_family = AF_INET;
+    INET_ADDR(ifr.ifr_addr) = m;
+    if (ioctl(sockfd, SIOCSIFNETMASK, &ifr) < 0) {
+       syslog(LOG_ERR, "Couldn't set IP netmask: %m");
+    }
+    ifr.ifr_addr.sa_family = AF_INET;
     INET_ADDR(ifr.ifr_addr) = o;
     if (ioctl(sockfd, SIOCSIFADDR, &ifr) < 0) {
        syslog(LOG_ERR, "Couldn't set local IP address: %m");
@@ -993,15 +996,14 @@ sifaddr(u, o, h, m)
     if (ioctl(sockfd, SIOCSIFDSTADDR, &ifr) < 0) {
        syslog(LOG_ERR, "Couldn't set remote IP address: %m");
     }
-    ifr.ifr_addr.sa_family = AF_INET;
-    INET_ADDR(ifr.ifr_addr) = m;
-    if (ioctl(sockfd, SIOCSIFNETMASK, &ifr) < 0) {
-       syslog(LOG_ERR, "Couldn't set IP netmask: %m");
-    }
+#if 0  /* now done in ppp_send_config */
     ifr.ifr_metric = link_mtu;
     if (ioctl(sockfd, SIOCSIFMTU, &ifr) < 0) {
        syslog(LOG_ERR, "Couldn't set IP MTU: %m");
     }
+#endif
+    ifaddrs[0] = o;
+    ifaddrs[1] = h;
 
     return 1;
 }
@@ -1017,12 +1019,15 @@ cifaddr(u, o, h)
 {
     struct rtentry rt;
 
+    bzero(&rt, sizeof(rt));
     rt.rt_dst.sa_family = AF_INET;
     INET_ADDR(rt.rt_dst) = h;
     rt.rt_gateway.sa_family = AF_INET;
     INET_ADDR(rt.rt_gateway) = o;
     rt.rt_flags = RTF_HOST;
-    ioctl(sockfd, SIOCDELRT, &rt);
+    if (ioctl(sockfd, SIOCDELRT, &rt) < 0)
+       syslog(LOG_ERR, "Couldn't delete route through interface: %m");
+    ifaddrs[0] = 0;
     return 1;
 }
 
@@ -1030,12 +1035,13 @@ cifaddr(u, o, h)
  * sifdefaultroute - assign a default route through the address given.
  */
 int
-sifdefaultroute(u, g)
+sifdefaultroute(u, l, g)
     int u;
-    u_int32_t g;
+    u_int32_t l, g;
 {
     struct rtentry rt;
 
+    bzero(&rt, sizeof(rt));
     rt.rt_dst.sa_family = AF_INET;
     INET_ADDR(rt.rt_dst) = 0;
     rt.rt_gateway.sa_family = AF_INET;
@@ -1055,12 +1061,13 @@ sifdefaultroute(u, g)
  * cifdefaultroute - delete a default route through the address given.
  */
 int
-cifdefaultroute(u, g)
+cifdefaultroute(u, l, g)
     int u;
-    u_int32_t g;
+    u_int32_t l, g;
 {
     struct rtentry rt;
 
+    bzero(&rt, sizeof(rt));
     rt.rt_dst.sa_family = AF_INET;
     INET_ADDR(rt.rt_dst) = 0;
     rt.rt_gateway.sa_family = AF_INET;
@@ -1212,9 +1219,9 @@ get_ether_addr(ipaddr, hwaddr)
 
 #define        WTMPFILE        "/usr/adm/wtmp"
 
-int
+void
 logwtmp(line, name, host)
-    char *line, *name, *host;
+    const char *line, *name, *host;
 {
     int fd;
     struct stat buf;
@@ -1431,3 +1438,21 @@ strtoul(str, ptr, base)
 {
     return (unsigned long) strtol(str, ptr, base);
 }
+
+/*
+ * Or strerror :-(
+ */
+extern char *sys_errlist[];
+extern int sys_nerr;
+
+char *
+strerror(n)
+    int n;
+{
+    static char unknown[32];
+
+    if (n > 0 && n < sys_nerr)
+       return sys_errlist[n];
+    sprintf(unknown, "Error %d", n);
+    return unknown;
+}