From 4c79ed3d5360b47ed83359633bc59bc8c1b5d821 Mon Sep 17 00:00:00 2001 From: Francesco Chemolli Date: Tue, 30 Dec 2014 15:24:28 +0100 Subject: [PATCH] Reworked acl/Arp to use Splay instead of SplayNode --- src/acl/Arp.cc | 56 ++++++++++++++++++---------------------- src/acl/Arp.h | 2 +- src/eui/Eui48.cc | 2 +- src/eui/Eui48.h | 2 +- src/tests/stub_libeui.cc | 2 +- 5 files changed, 29 insertions(+), 35 deletions(-) diff --git a/src/acl/Arp.cc b/src/acl/Arp.cc index 1aa682d9de..ec1ff3a720 100644 --- a/src/acl/Arp.cc +++ b/src/acl/Arp.cc @@ -20,10 +20,9 @@ #include "globals.h" #include "ip/Address.h" -static void aclParseArpList(SplayNode **curlist); -static int aclMatchArp(SplayNode **dataptr, Ip::Address &c); -static SplayNode::SPLAYCMP aclArpCompare; -static SplayNode::SPLAYWALKEE aclDumpArpListWalkee; +static void aclParseArpList(Splay **curlist); +static int aclMatchArp(Splay **dataptr, Ip::Address &c); +static Splay::SPLAYCMP aclArpCompare; ACL * ACLARP::clone() const @@ -43,7 +42,7 @@ ACLARP::ACLARP (ACLARP const & old) : data (NULL), class_ (old.class_) ACLARP::~ACLARP() { if (data) - data->destroy(SplayNode::DefaultFree); + data->destroy(); } char const * @@ -117,17 +116,16 @@ ACLARP::parse() } void -aclParseArpList(SplayNode **curlist) +aclParseArpList(Splay **curlist) { char *t = NULL; - SplayNode **Top = curlist; Eui::Eui48 *q = NULL; while ((t = strtokFile())) { if ((q = aclParseArpData(t)) == NULL) continue; - *Top = (*Top)->insert(q, aclArpCompare); + (*curlist)->insert(q, aclArpCompare); } } @@ -149,21 +147,15 @@ ACLARP::match(ACLChecklist *cl) /* aclMatchArp */ /***************/ int -aclMatchArp(SplayNode **dataptr, Ip::Address &c) +aclMatchArp(Splay **dataptr, Ip::Address &c) { - Eui::Eui48 result; - SplayNode **Top = dataptr; - - if (result.lookup(c)) { - /* Do ACL match lookup */ - *Top = (*Top)->splay(&result, aclArpCompare); - debugs(28, 3, "aclMatchArp: '" << c << "' " << (splayLastResult ? "NOT found" : "found")); - return (0 == splayLastResult); + Eui::Eui48 lookingFor; + if (lookingFor.lookup(c)) { + Eui::Eui48 * const* lookupResult; + lookupResult = (*dataptr)->find(&lookingFor,aclArpCompare); + debugs(28, 3, "aclMatchArp: '" << c << "' " << (lookupResult ? "found" : "NOT found")); + return (lookupResult != NULL); } - - /* - * Address was not found on any interface - */ debugs(28, 3, "aclMatchArp: " << c << " NOT found"); return 0; } @@ -174,20 +166,22 @@ aclArpCompare(Eui::Eui48 * const &a, Eui::Eui48 * const &b) return memcmp(a, b, sizeof(Eui::Eui48)); } -static void -aclDumpArpListWalkee(Eui::Eui48 * const &node, void *state) -{ - static char buf[48]; - node->encode(buf, 48); - static_cast(state)->push_back(SBuf(buf)); -} +// visitor functor to collect the contents of the Arp Acl +struct ArpAclDumpVisitor { + SBufList contents; + void operator() (const Eui::Eui48 * v) { + static char buf[48]; + v->encode(buf,48); + contents.push_back(SBuf(buf)); + } +}; SBufList ACLARP::dump() const { - SBufList sl; - data->walk(aclDumpArpListWalkee, &sl); - return sl; + ArpAclDumpVisitor visitor; + data->visit(visitor); + return visitor.contents; } /* ==== END ARP ACL SUPPORT =============================================== */ diff --git a/src/acl/Arp.h b/src/acl/Arp.h index c6f61847bd..2654bbdb36 100644 --- a/src/acl/Arp.h +++ b/src/acl/Arp.h @@ -39,7 +39,7 @@ public: protected: static Prototype RegistryProtoype; static ACLARP RegistryEntry_; - SplayNode *data; + Splay *data; char const *class_; }; diff --git a/src/eui/Eui48.cc b/src/eui/Eui48.cc index 3556c3c151..41c8691be3 100644 --- a/src/eui/Eui48.cc +++ b/src/eui/Eui48.cc @@ -116,7 +116,7 @@ Eui::Eui48::decode(const char *asc) } bool -Eui::Eui48::encode(char *buf, const int len) +Eui::Eui48::encode(char *buf, const int len) const { if (len < SZ_EUI48_BUF) return false; diff --git a/src/eui/Eui48.h b/src/eui/Eui48.h index dad409a8cb..3100f1de53 100644 --- a/src/eui/Eui48.h +++ b/src/eui/Eui48.h @@ -62,7 +62,7 @@ public: * \retval false Conversion to ASCII failed. * \retval true Conversion completed successfully. */ - bool encode(char *buf, const int len); + bool encode(char *buf, const int len) const; // lookup an EUI-48 / MAC address via ARP bool lookup(const Ip::Address &c); diff --git a/src/tests/stub_libeui.cc b/src/tests/stub_libeui.cc index 2e1730f87b..e2ae9b6c0e 100644 --- a/src/tests/stub_libeui.cc +++ b/src/tests/stub_libeui.cc @@ -18,7 +18,7 @@ Eui::EuiConfig Eui::TheConfig; #if USE_SQUID_EUI const unsigned char *Eui::Eui48::get(void) STUB_RETVAL(NULL) bool Eui::Eui48::decode(const char *asc) STUB_RETVAL(false) -bool Eui::Eui48::encode(char *buf, const int len) STUB_RETVAL(false) +bool Eui::Eui48::encode(char *buf, const int len) const STUB_RETVAL(false) bool Eui::Eui48::lookup(const Ip::Address &c) STUB_RETVAL(false) #endif -- 2.47.3