]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Windows native support for ARP acls
authorserassio <>
Thu, 6 Jan 2005 17:44:39 +0000 (17:44 +0000)
committerserassio <>
Thu, 6 Jan 2005 17:44:39 +0000 (17:44 +0000)
Supported build platforms:

Cygwin
MinGW + Msys
MS Visual Studio 2005

configure.in
src/ACLARP.cc

index 2422648ab89d206d0ffcee0b5f4f9c4af611f887..648a74461288b9d7eb31e77d23f2d3c308f64555 100644 (file)
@@ -3,7 +3,7 @@ dnl  Configuration input file for Squid
 dnl
 dnl  Duane Wessels, wessels@nlanr.net, February 1996 (autoconf v2.9)
 dnl
-dnl  $Id: configure.in,v 1.367 2004/12/26 11:23:15 serassio Exp $
+dnl  $Id: configure.in,v 1.368 2005/01/06 10:44:39 serassio Exp $
 dnl
 dnl
 dnl
@@ -13,7 +13,7 @@ AC_CONFIG_SRCDIR([src/main.cc])
 AC_CONFIG_AUX_DIR(cfgaux)
 AM_INIT_AUTOMAKE(squid, 3.0-PRE3-CVS)
 AM_CONFIG_HEADER(include/autoconf.h)
-AC_REVISION($Revision: 1.367 $)dnl
+AC_REVISION($Revision: 1.368 $)dnl
 AC_PREFIX_DEFAULT(/usr/local/squid)
 AM_MAINTAINER_MODE
 
@@ -784,6 +784,12 @@ AC_ARG_ENABLE(arp-acl,
            ;;
        *-freebsd*)
            ;;
+       *-cygwin*)
+        LIBS="$LIBS -liphlpapi"
+           ;;
+       *-mingw*)
+        LIBS="$LIBS -liphlpapi"
+           ;;
        *)
            echo "WARNING: ARP ACL support probably won't work on $host."
            sleep 10
index a4856ba7d137a06cb2310e9f74838be6431240b3..ffbf303648864c867de3a4df9da52eab34a8f097 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: ACLARP.cc,v 1.10 2004/12/21 19:40:16 serassio Exp $
+ * $Id: ACLARP.cc,v 1.11 2005/01/06 10:44:39 serassio Exp $
  *
  * DEBUG: section 28    Access Control
  * AUTHOR: Duane Wessels
  */
 
 #include "config.h"
+#ifdef _SQUID_CYGWIN_
+#include <squid_windows.h>
+#endif
 #include "squid.h"
 
+#ifdef _SQUID_WIN32_
+
+struct arpreq
+{
+
+    struct sockaddr arp_pa;   /* protocol address */
+
+    struct sockaddr arp_ha;   /* hardware address */
+    int arp_flags;            /* flags */
+};
+
+#include <Iphlpapi.h>
+#else
+
 #ifdef _SQUID_SOLARIS_
 #include <sys/sockio.h>
 #else
@@ -56,6 +73,7 @@
 #if HAVE_NETINET_IF_ETHER_H
 #include <netinet/if_ether.h>
 #endif
+#endif
 
 #include "ACLARP.h"
 
@@ -524,6 +542,67 @@ aclMatchArp(SplayNode<acl_arp_data *> **dataptr, struct in_addr c)
 
     return (0 == splayLastResult);
 
+#elif defined(_SQUID_WIN32_)
+
+    DWORD           dwNetTable = 0;
+
+    DWORD           ipNetTableLen = 0;
+
+    PMIB_IPNETTABLE NetTable = NULL;
+
+    DWORD            i;
+
+    SplayNode<acl_arp_data *> **Top = dataptr;
+
+    struct arpreq arpReq;
+
+    /* Get size of Windows ARP table */
+    if (GetIpNetTable(NetTable, &ipNetTableLen, FALSE) != ERROR_INSUFFICIENT_BUFFER) {
+        debug(28, 0) ("Can't estimate ARP table size!\n");
+        return 0;
+    }
+
+    /* Allocate space for ARP table and assign pointers */
+    if ((NetTable = (PMIB_IPNETTABLE)xmalloc(ipNetTableLen)) == NULL) {
+        debug(28, 0) ("Can't allocate temporary ARP table!\n");
+        return 0;
+    }
+
+    /* Get actual ARP table */
+    if ((dwNetTable = GetIpNetTable(NetTable, &ipNetTableLen, FALSE)) != NO_ERROR) {
+        debug(28, 0) ("Can't retrieve ARP table!\n");
+        xfree(NetTable);
+        return 0;
+    }
+
+    /* Find MAC address from net table */
+    for (i = 0 ; i < NetTable->dwNumEntries ; i++) {
+        if ((c.s_addr == NetTable->table[i].dwAddr) && (NetTable->table[i].dwType > 2)) {
+            arpReq.arp_ha.sa_family = AF_UNSPEC;
+            memcpy(arpReq.arp_ha.sa_data, NetTable->table[i].bPhysAddr, NetTable[i].table->dwPhysAddrLen);
+        }
+    }
+
+    xfree(NetTable);
+
+    if (arpReq.arp_ha.sa_data[0] == 0 && arpReq.arp_ha.sa_data[1] == 0 &&
+            arpReq.arp_ha.sa_data[2] == 0 && arpReq.arp_ha.sa_data[3] == 0 &&
+            arpReq.arp_ha.sa_data[4] == 0 && arpReq.arp_ha.sa_data[5] == 0)
+        return 0;
+
+    debug(28, 4) ("Got address %02x:%02x:%02x:%02x:%02x:%02x\n",
+                  arpReq.arp_ha.sa_data[0] & 0xff, arpReq.arp_ha.sa_data[1] & 0xff,
+                  arpReq.arp_ha.sa_data[2] & 0xff, arpReq.arp_ha.sa_data[3] & 0xff,
+                  arpReq.arp_ha.sa_data[4] & 0xff, arpReq.arp_ha.sa_data[5] & 0xff);
+
+    /* Do lookup */
+    *Top = (*Top)->splay((acl_arp_data *)&arpReq.arp_ha.sa_data, aclArpCompare);
+
+    debug(28, 3) ("aclMatchArp: '%s' %s\n",
+                  inet_ntoa(c), splayLastResult ? "NOT found" : "found");
+
+    return (0 == splayLastResult);
+
 #else
 
     WRITE ME;