From 736a77899f1dff93dc805b4211ee197b3eaf9cb1 Mon Sep 17 00:00:00 2001 From: Francesco Chemolli Date: Tue, 30 Dec 2014 17:52:25 +0100 Subject: [PATCH] Migrated acl/Eui64 to Splay --- src/acl/Arp.cc | 3 +-- src/acl/Eui64.cc | 49 +++++++++++++++++++++++------------------------- src/acl/Eui64.h | 2 +- src/eui/Eui64.cc | 2 +- src/eui/Eui64.h | 2 +- 5 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/acl/Arp.cc b/src/acl/Arp.cc index 88f16659c1..0d5520b154 100644 --- a/src/acl/Arp.cc +++ b/src/acl/Arp.cc @@ -151,8 +151,7 @@ aclMatchArp(Splay **dataptr, Ip::Address &c) { Eui::Eui48 lookingFor; if (lookingFor.lookup(c)) { - Eui::Eui48 * const* lookupResult; - lookupResult = (*dataptr)->find(&lookingFor,aclArpCompare); + Eui::Eui48 * const* lookupResult = (*dataptr)->find(&lookingFor,aclArpCompare); debugs(28, 3, "aclMatchArp: '" << c << "' " << (lookupResult ? "found" : "NOT found")); return (lookupResult != NULL); } diff --git a/src/acl/Eui64.cc b/src/acl/Eui64.cc index 0eedd6978f..dbc54c1aca 100644 --- a/src/acl/Eui64.cc +++ b/src/acl/Eui64.cc @@ -20,10 +20,9 @@ #include "globals.h" #include "ip/Address.h" -static void aclParseEuiList(SplayNode **curlist); -static int aclMatchEui(SplayNode **dataptr, Ip::Address &c); +static void aclParseEuiList(Splay **curlist); +static int aclMatchEui(Splay **dataptr, Ip::Address &c); static SplayNode::SPLAYCMP aclEui64Compare; -static SplayNode::SPLAYWALKEE aclDumpEuiListWalkee; ACL * ACLEui64::clone() const @@ -43,7 +42,7 @@ ACLEui64::ACLEui64 (ACLEui64 const & old) : data (NULL), class_ (old.class_) ACLEui64::~ACLEui64() { if (data) - data->destroy(SplayNode::DefaultFree); + data->destroy(); } char const * @@ -91,17 +90,16 @@ ACLEui64::parse() } void -aclParseEuiList(SplayNode **curlist) +aclParseEuiList(Splay **curlist) { char *t = NULL; - SplayNode **Top = curlist; Eui::Eui64 *q = NULL; while ((t = strtokFile())) { if ((q = aclParseEuiData(t)) == NULL) continue; - *Top = (*Top)->insert(q, aclEui64Compare); + (*curlist)->insert(q, aclEui64Compare); } } @@ -123,16 +121,14 @@ ACLEui64::match(ACLChecklist *cl) /* aclMatchEui */ /***************/ int -aclMatchEui(SplayNode **dataptr, Ip::Address &c) +aclMatchEui(Splay **dataptr, Ip::Address &c) { - Eui::Eui64 result; - SplayNode **Top = dataptr; - - if (result.lookup(c)) { - /* Do ACL match lookup */ - *Top = (*Top)->splay(&result, aclEui64Compare); - debugs(28, 3, "aclMatchEui: '" << c << "' " << (splayLastResult ? "NOT found" : "found")); - return (0 == splayLastResult); + Eui::Eui64 lookingFor; + + if (lookingFor.lookup(c)) { + Eui::Eui64 * const * lookupResult = (*dataptr)->find(&lookingFor, aclEui64Compare); + debugs(28, 3, "aclMatchEui: '" << c << "' " << (lookupResult ? "found" : "NOT found")); + return (lookupResult != NULL); } /* @@ -148,20 +144,21 @@ aclEui64Compare(Eui::Eui64 * const &a, Eui::Eui64 * const &b) return memcmp(a, b, sizeof(Eui::Eui64)); } -static void -aclDumpEuiListWalkee(Eui::Eui64 * const &node, void *state) -{ - static char buf[48]; - node->encode(buf, 48); - static_cast(state)->push_back(SBuf(buf)); -} +struct AclEui64DumpVisitor { + SBufList contents; + void operator() ( const Eui::Eui64 * v) { + static char buf[48]; + v->encode(buf, 48); + contents.push_back(SBuf(buf)); + } +}; SBufList ACLEui64::dump() const { - SBufList w; - data->walk(aclDumpEuiListWalkee, &w); - return w; + AclEui64DumpVisitor visitor; + data->visit(visitor); + return visitor.contents; } #endif /* USE_SQUID_EUI */ diff --git a/src/acl/Eui64.h b/src/acl/Eui64.h index 4b9e049548..4dc4fe1c94 100644 --- a/src/acl/Eui64.h +++ b/src/acl/Eui64.h @@ -38,7 +38,7 @@ public: protected: static Prototype RegistryProtoype; static ACLEui64 RegistryEntry_; - SplayNode *data; + Splay *data; char const *class_; }; diff --git a/src/eui/Eui64.cc b/src/eui/Eui64.cc index 654f36c42d..147a8d943d 100644 --- a/src/eui/Eui64.cc +++ b/src/eui/Eui64.cc @@ -31,7 +31,7 @@ Eui::Eui64::decode(const char *asc) } bool -Eui::Eui64::encode(char *buf, const int len) +Eui::Eui64::encode(char *buf, const int len) const { if (len < SZ_EUI64_BUF) return false; diff --git a/src/eui/Eui64.h b/src/eui/Eui64.h index 029833f502..711331b533 100644 --- a/src/eui/Eui64.h +++ b/src/eui/Eui64.h @@ -69,7 +69,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-64 address via IPv6 SLAAC or NDP bool lookup(const Ip::Address &c); -- 2.47.3