--------------------- PatchSet 1110 Date: 2004/12/09 20:32:25 Author: serassio Branch: nt Tag: (none) Log: Added native Windows ARP ACL support Members: configure.in:1.26.2.36->1.26.2.37 src/ACLARP.cc:1.1.2.7->1.1.2.8 Index: squid3/configure.in =================================================================== RCS file: /cvsroot/squid-sf//squid3/configure.in,v retrieving revision 1.26.2.36 retrieving revision 1.26.2.37 diff -u -r1.26.2.36 -r1.26.2.37 --- squid3/configure.in 21 Oct 2004 07:35:57 -0000 1.26.2.36 +++ squid3/configure.in 9 Dec 2004 20:33:02 -0000 1.26.2.37 @@ -3,7 +3,7 @@ dnl dnl Duane Wessels, wessels@nlanr.net, February 1996 (autoconf v2.9) dnl -dnl $Id: configure.in,v 1.26.2.36 2004/10/21 07:35:57 serassio Exp $ +dnl $Id: configure.in,v 1.26.2.37 2004/12/09 20:33:02 serassio Exp $ dnl dnl dnl @@ -13,7 +13,7 @@ AC_CONFIG_AUX_DIR(cfgaux) AM_INIT_AUTOMAKE(squid, 3.0-PRE3-CVS-NT) AM_CONFIG_HEADER(include/autoconf.h) -AC_REVISION($Revision: 1.26.2.36 $)dnl +AC_REVISION($Revision: 1.26.2.37 $)dnl AC_PREFIX_DEFAULT(/usr/local/squid) AM_MAINTAINER_MODE @@ -696,6 +696,12 @@ ;; *-freebsd*) ;; + *-cygwin*) + LIBS="$LIBS -liphlpapi" + ;; + *-mingw*) + LIBS="$LIBS -liphlpapi" + ;; *) echo "WARNING: ARP ACL support probably won't work on $host." sleep 10 Index: squid3/src/ACLARP.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ACLARP.cc,v retrieving revision 1.1.2.7 retrieving revision 1.1.2.8 diff -u -r1.1.2.7 -r1.1.2.8 --- squid3/src/ACLARP.cc 7 Nov 2004 09:29:38 -0000 1.1.2.7 +++ squid3/src/ACLARP.cc 9 Dec 2004 20:32:25 -0000 1.1.2.8 @@ -1,5 +1,5 @@ /* - * $Id: ACLARP.cc,v 1.1.2.7 2004/11/07 09:29:38 serassio Exp $ + * $Id: ACLARP.cc,v 1.1.2.8 2004/12/09 20:32:25 serassio Exp $ * * DEBUG: section 28 Access Control * AUTHOR: Duane Wessels @@ -37,6 +37,19 @@ #include "config.h" #include "squid.h" +#if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) +#ifdef _SQUID_CYGWIN_ +#include +#endif + +struct arpreq { + struct sockaddr arp_pa; /* protocol address */ + struct sockaddr arp_ha; /* hardware address */ + int arp_flags; /* flags */ +}; + +#include +#else #ifdef _SQUID_SOLARIS_ #include #else @@ -56,6 +69,7 @@ #if HAVE_NETINET_IF_ETHER_H #include #endif +#endif #include "ACLARP.h" @@ -524,6 +538,62 @@ 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 = (*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;