---------------------
PatchSet 6360 
Date: 2004/12/08 19:45:45
Author: serassio
Branch: nt-2_5
Tag: (none) 
Log:
Added native Windows support for ARP ACL

Members: 
	configure.in:1.42.2.5.4.59->1.42.2.5.4.60 
	src/acl.c:1.43.2.1.4.25->1.43.2.1.4.26 

Index: squid/configure.in
===================================================================
RCS file: /cvsroot/squid-sf//squid/configure.in,v
retrieving revision 1.42.2.5.4.59
retrieving revision 1.42.2.5.4.60
diff -u -r1.42.2.5.4.59 -r1.42.2.5.4.60
--- squid/configure.in	13 Oct 2004 19:08:07 -0000	1.42.2.5.4.59
+++ squid/configure.in	8 Dec 2004 19:46:18 -0000	1.42.2.5.4.60
@@ -3,7 +3,7 @@
 dnl
 dnl  Duane Wessels, wessels@nlanr.net, February 1996 (autoconf v2.9)
 dnl
-dnl  $Id: configure.in,v 1.42.2.5.4.59 2004/10/13 19:08:07 serassio Exp $
+dnl  $Id: configure.in,v 1.42.2.5.4.60 2004/12/08 19:46:18 serassio Exp $
 dnl
 dnl
 dnl
@@ -11,7 +11,7 @@
 AC_CONFIG_AUX_DIR(cfgaux)
 AM_INIT_AUTOMAKE(squid, 2.5.STABLE7-NT-CVS)
 AM_CONFIG_HEADER(include/autoconf.h)
-AC_REVISION($Revision: 1.42.2.5.4.59 $)dnl
+AC_REVISION($Revision: 1.42.2.5.4.60 $)dnl
 AC_PREFIX_DEFAULT(/usr/local/squid)
 AM_MAINTAINER_MODE
 
@@ -560,6 +560,10 @@
 	    ;;
 	*-freebsd*)
 	    ;;
+	*-cygwin*)
+	    ;;
+	*-mingw*)
+	    ;;
 	*)
 	    echo "WARNING: ARP ACL support probably won't work on $host."
 	    sleep 10
Index: squid/src/acl.c
===================================================================
RCS file: /cvsroot/squid-sf//squid/src/acl.c,v
retrieving revision 1.43.2.1.4.25
retrieving revision 1.43.2.1.4.26
diff -u -r1.43.2.1.4.25 -r1.43.2.1.4.26
--- squid/src/acl.c	21 Oct 2004 07:43:06 -0000	1.43.2.1.4.25
+++ squid/src/acl.c	8 Dec 2004 19:45:45 -0000	1.43.2.1.4.26
@@ -1,6 +1,6 @@
 
 /*
- * $Id: acl.c,v 1.43.2.1.4.25 2004/10/21 07:43:06 serassio Exp $
+ * $Id: acl.c,v 1.43.2.1.4.26 2004/12/08 19:45:45 serassio Exp $
  *
  * DEBUG: section 28    Access Control
  * AUTHOR: Duane Wessels
@@ -2775,6 +2775,9 @@
  *       Solaris code by R. Gancarz <radekg@solaris.elektrownia-lagisza.com.pl>
  */
 
+#if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_)
+#include <Iphlpapi.h>
+#else
 #ifdef _SQUID_SOLARIS_
 #include <sys/sockio.h>
 #else
@@ -2788,12 +2791,13 @@
 #include <net/route.h>
 #endif
 #include <net/if.h>
-#ifdef _SQUID_FREEBSD__
+#ifdef _SQUID_FREEBSD_
 #include <net/if_arp.h>
 #endif
 #if HAVE_NETINET_IF_ETHER_H
 #include <netinet/if_ether.h>
 #endif
+#endif
 
 /*
  * Decode an ascii representation (asc) of an ethernet adress, and place
@@ -3086,6 +3090,57 @@
     debug(28, 3) ("aclMatchArp: '%s' %s\n",
 	inet_ntoa(c), splayLastResult ? "NOT found" : "found");
     return (0 == splayLastResult);
+#elif defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_)
+
+    DWORD           dwNetTable = 0;
+    DWORD           ipNetTableLen = 0;
+    PMIB_IPNETTABLE NetTable = NULL;
+    DWORD            i;
+    splayNode **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 = splay_splay(&arpReq.arp_ha.sa_data, *Top, aclArpCompare);
+
+    debug(28, 3) ("aclMatchArp: '%s' %s\n",
+	inet_ntoa(c), splayLastResult ? "NOT found" : "found");
+    return (0 == splayLastResult);
 #else
     WRITE ME;
 #endif
@@ -3138,6 +3193,21 @@
 	return (d1[4] > d2[4]) ? 1 : -1;
     if (d1[5] != d2[5])
 	return (d1[5] > d2[5]) ? 1 : -1;
+#elif defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_)
+    const unsigned char *d1 = a;
+    const unsigned char *d2 = b;
+    if (d1[0] != d2[0])
+	return (d1[0] > d2[0]) ? 1 : -1;
+    if (d1[1] != d2[1])
+	return (d1[1] > d2[1]) ? 1 : -1;
+    if (d1[2] != d2[2])
+	return (d1[2] > d2[2]) ? 1 : -1;
+    if (d1[3] != d2[3])
+	return (d1[3] > d2[3]) ? 1 : -1;
+    if (d1[4] != d2[4])
+	return (d1[4] > d2[4]) ? 1 : -1;
+    if (d1[5] != d2[5])
+	return (d1[5] > d2[5]) ? 1 : -1;
 #else
     WRITE ME;
 #endif
