]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/sys-solaris.c
Use autoconf/automake to configure and make ppp
[ppp.git] / pppd / sys-solaris.c
index d96d23c26d6c587b2e7f44986bc6db4a339af85c..a0b1e3a11ebd13543f997f05a70ab9c71d37f17b 100644 (file)
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <limits.h>
 #include <stdio.h>
 #include <stddef.h>
 #include <sys/ethernet.h>
 #endif
 
+#ifdef PPP_FILTER
+#include <pcap.h>
+#endif
+
 #include "pppd.h"
 #include "fsm.h"
 #include "lcp.h"
@@ -218,10 +226,7 @@ static int if6_is_up = 0;  /* IPv6 interface has been marked up */
 
 #endif /* defined(INET6) && defined(SOL2) */
 
-#if defined(INET6) && defined(SOL2)
-static char    first_ether_name[LIFNAMSIZ];    /* Solaris 8 and above */
-#else
-static char    first_ether_name[IFNAMSIZ];     /* Before Solaris 8 */
+#if !defined(INET6) || !defined(SOL2)
 #define MAXIFS         256                     /* Max # of interfaces */
 #endif /* defined(INET6) && defined(SOL2) */
 
@@ -261,7 +266,7 @@ static int get_hw_addr(char *, u_int32_t, struct sockaddr *);
 static int get_hw_addr_dlpi(char *, struct sockaddr *);
 static int dlpi_attach(int, int);
 static int dlpi_info_req(int);
-static int dlpi_get_reply(int, union DL_primitives *, int, int);
+static int dlpi_get_reply(int, union DL_primitives *, int, size_t);
 static int strioctl(int, int, void *, int, int);
 
 #ifdef SOL2
@@ -294,13 +299,13 @@ sifppa(fd, ppa)
 
 #if defined(SOL2) && defined(INET6)
 /*
- * get_first_ethernet - returns the first Ethernet interface name found in 
- * the system, or NULL if none is found
+ * get_first_ether_hwaddr - get the hardware address for the first
+ * ethernet-style interface on this system.
  *
  * NOTE: This is the lifreq version (Solaris 8 and above)
  */
-char *
-get_first_ethernet(void)
+int
+get_first_ether_hwaddr(u_char *addr)
 {
     struct lifnum lifn;
     struct lifconf lifc;
@@ -312,7 +317,7 @@ get_first_ethernet(void)
 
     fd = socket(AF_INET, SOCK_DGRAM, 0);
     if (fd < 0) {
-       return 0;
+       return -1;
     }
 
     /*
@@ -323,7 +328,7 @@ get_first_ethernet(void)
     if (ioctl(fd, SIOCGLIFNUM, &lifn) < 0) {
        close(fd);
        error("could not determine number of interfaces: %m");
-       return 0;
+       return -1;
     }
 
     num_ifs = lifn.lifn_count;
@@ -332,7 +337,7 @@ get_first_ethernet(void)
     if (req == NULL) {
        close(fd);
        error("out of memory");
-       return 0;
+       return -1;
     }
 
     /*
@@ -346,7 +351,7 @@ get_first_ethernet(void)
        close(fd);
        free(req);
        error("SIOCGLIFCONF: %m");
-       return 0;
+       return -1;
     }
 
     /*
@@ -363,10 +368,8 @@ get_first_ethernet(void)
        memset(&lifr, 0, sizeof(lifr));
        strncpy(lifr.lifr_name, plifreq->lifr_name, sizeof(lifr.lifr_name));
        if (ioctl(fd, SIOCGLIFFLAGS, &lifr) < 0) {
-           close(fd);
-           free(req);
            error("SIOCGLIFFLAGS: %m");
-           return 0;
+           break;
        }
        fl = lifr.lifr_flags;
 
@@ -374,27 +377,29 @@ get_first_ethernet(void)
                != (IFF_UP | IFF_BROADCAST))
            continue;
 
+       if (get_if_hwaddr(addr, lifr.lifr_name) < 0)
+           continue;
+
        found = 1;
        break;
     }
     free(req);
     close(fd);
 
-    if (found) {
-       strncpy(first_ether_name, lifr.lifr_name, sizeof(first_ether_name));
-       return (char *)first_ether_name;
-    } else
-       return NULL;
+    if (found)
+       return 0;
+    else
+       return -1;
 }
 #else
 /*
- * get_first_ethernet - returns the first Ethernet interface name found in 
- * the system, or NULL if none is found
+ * get_first_ether_hwaddr - get the hardware address for the first
+ * ethernet-style interface on this system.
  *
  * NOTE: This is the ifreq version (before Solaris 8). 
  */
-char *
-get_first_ethernet(void)
+int
+get_first_ether_hwaddr(u_char *addr)
 {
     struct ifconf ifc;
     struct ifreq *pifreq;
@@ -405,7 +410,7 @@ get_first_ethernet(void)
 
     fd = socket(AF_INET, SOCK_DGRAM, 0);
     if (fd < 0) {
-       return 0;
+       return -1;
     }
 
     /*
@@ -420,7 +425,7 @@ get_first_ethernet(void)
     if (req == NULL) {
        close(fd);
        error("out of memory");
-       return 0;
+       return -1;
     }
 
     /*
@@ -432,7 +437,7 @@ get_first_ethernet(void)
        close(fd);
        free(req);
        error("SIOCGIFCONF: %m");
-       return 0;
+       return -1;
     }
 
     /*
@@ -449,10 +454,8 @@ get_first_ethernet(void)
        memset(&ifr, 0, sizeof(ifr));
        strncpy(ifr.ifr_name, pifreq->ifr_name, sizeof(ifr.ifr_name));
        if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
-           close(fd);
-           free(req);
            error("SIOCGIFFLAGS: %m");
-           return 0;
+           break;
        }
        fl = ifr.ifr_flags;
 
@@ -460,17 +463,19 @@ get_first_ethernet(void)
                != (IFF_UP | IFF_BROADCAST))
            continue;
 
+       if (get_if_hwaddr(addr, ifr.ifr_name) < 0)
+           continue;
+
        found = 1;
        break;
     }
     free(req);
     close(fd);
 
-    if (found) {
-       strncpy(first_ether_name, ifr.ifr_name, sizeof(first_ether_name));
-       return (char *)first_ether_name;
-    } else
-       return NULL;
+    if (found)
+       return 0;
+    else
+       return -1;
 }
 #endif /* defined(SOL2) && defined(INET6) */
 
@@ -531,50 +536,6 @@ slifname_done:
 
 
 }
-
-
-/*
- * ether_to_eui64 - Convert 48-bit Ethernet address into 64-bit EUI
- *
- * walks the list of valid ethernet interfaces, and convert the first
- * found 48-bit MAC address into EUI 64. caller also assumes that
- * the system has a properly configured Ethernet interface for this
- * function to return non-zero.
- */
-int
-ether_to_eui64(eui64_t *p_eui64)
-{
-    struct sockaddr s_eth_addr;
-    struct ether_addr *eth_addr = (struct ether_addr *)&s_eth_addr.sa_data;
-    char *if_name;
-
-    if ((if_name = get_first_ethernet()) == NULL) {
-       error("no persistent id can be found");
-       return 0;
-    }
-    /*
-     * Send DL_INFO_REQ to the driver to solicit its MAC address
-     */
-    if (!get_hw_addr_dlpi(if_name, &s_eth_addr)) {
-       error("could not obtain hardware address for %s", if_name);
-       return 0;
-    }
-
-    /*
-     * And convert the EUI-48 into EUI-64, per RFC 2472 [sec 4.1]
-     */
-    p_eui64->e8[0] = (eth_addr->ether_addr_octet[0] & 0xFF) | 0x02;
-    p_eui64->e8[1] = (eth_addr->ether_addr_octet[1] & 0xFF);
-    p_eui64->e8[2] = (eth_addr->ether_addr_octet[2] & 0xFF);
-    p_eui64->e8[3] = 0xFF;
-    p_eui64->e8[4] = 0xFE;
-    p_eui64->e8[5] = (eth_addr->ether_addr_octet[3] & 0xFF);
-    p_eui64->e8[6] = (eth_addr->ether_addr_octet[4] & 0xFF);
-    p_eui64->e8[7] = (eth_addr->ether_addr_octet[5] & 0xFF);
-
-    return 1;
-}
 #endif /* defined(SOL2) && defined(INET6) */
 
 /*
@@ -1508,7 +1469,7 @@ netif_set_mtu(int unit, int mtu)
 
     memset(&ifr, 0, sizeof(ifr));
     strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
-    ifr.ifr_metric = link_mtu;
+    ifr.ifr_metric = mtu;
     if (ioctl(ipfd, SIOCSIFMTU, &ifr) < 0) {
        error("Couldn't set IP MTU (%s): %m", ifr.ifr_name);
     }
@@ -1520,7 +1481,7 @@ netif_set_mtu(int unit, int mtu)
 
     memset(&lifr, 0, sizeof(lifr));
     strlcpy(lifr.lifr_name, ifname, sizeof(lifr.lifr_name));
-    lifr.lifr_mtu = link_mtu;
+    lifr.lifr_mtu = mtu;
     if (ioctl(fd, SIOCSLIFMTU, &lifr) < 0) {
        close(fd);
        error("Couldn't set IPv6 MTU (%s): %m", ifr.ifr_name);
@@ -1546,7 +1507,7 @@ netif_get_mtu(int unit)
     error("ioctl(SIOCGIFMTU): %m (line %d)", __LINE__);
     return 0;
     }
-    return ifr.ifr_mtu;
+    return ifr.ifr_metric;
 }
 
 /*
@@ -1683,7 +1644,7 @@ get_ppp_stats(int u, struct pppd_stats *stats)
     return 1;
 }
 
-#if 0
+#ifdef PPP_FILTER
 /*
  * set_filters - transfer the pass and active filters to the kernel.
  */
@@ -2082,10 +2043,15 @@ cifaddr(int u, u_int32_t o, u_int32_t h)
  * sifdefaultroute - assign a default route through the address given.
  */
 int
-sifdefaultroute(int u, u_int32_t l, u_int32_t g)
+sifdefaultroute(int u, u_int32_t l, u_int32_t g, bool replace)
 {
     struct rtentry rt;
 
+    if (replace) {
+       error("Replacing the default route is not implemented on Solaris yet");
+       return 0;
+    }
+
 #if defined(__USLC__)
     g = l;                     /* use the local address as gateway */
 #endif
@@ -2357,7 +2323,7 @@ dlpi_info_req(int fd)
 }
 
 static int
-dlpi_get_reply(int fd, union DL_primitives *reply, int expected_prim, maxlen)
+dlpi_get_reply(int fd, union DL_primitives *reply, int expected_prim, size_t maxlen)
 {
     struct strbuf buf;
     int flags, n;