From: Francesco Chemolli Date: Wed, 7 Jan 2015 10:41:24 +0000 (+0100) Subject: Migrated acl/Eui64 X-Git-Tag: merge-candidate-3-v1~345^2~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fdd757c55e38fbc0f2109e39ba359c32a57429e5;p=thirdparty%2Fsquid.git Migrated acl/Eui64 --- diff --git a/src/acl/Arp.cc b/src/acl/Arp.cc index 3a2fd46d1f..ea41239a2b 100644 --- a/src/acl/Arp.cc +++ b/src/acl/Arp.cc @@ -138,7 +138,6 @@ SBufList ACLARP::dump() const { SBufList sl; - // we need to sort. This is not performance-critical code for (auto i = aclArpData.cbegin(); i != aclArpData.cend(); ++i) { char buf[48]; i->encode(buf,48); diff --git a/src/acl/Eui64.cc b/src/acl/Eui64.cc index 14b08d2d88..005bf85fe3 100644 --- a/src/acl/Eui64.cc +++ b/src/acl/Eui64.cc @@ -20,31 +20,21 @@ #include "globals.h" #include "ip/Address.h" -static void aclParseEuiList(Splay **curlist); -static int aclMatchEui(Splay **dataptr, Ip::Address &c); -static Splay::SPLAYCMP aclEui64Compare; - ACL * ACLEui64::clone() const { return new ACLEui64(*this); } -ACLEui64::ACLEui64 (char const *theClass) : data (NULL), class_ (theClass) +ACLEui64::ACLEui64 (char const *theClass) : class_ (theClass) {} -ACLEui64::ACLEui64 (ACLEui64 const & old) : data (NULL), class_ (old.class_) +ACLEui64::ACLEui64 (ACLEui64 const & old) : eui64Data(old.eui64Data), class_ (old.class_) { - /* we don't have copy constructors for the data yet */ - assert (!old.data); } ACLEui64::~ACLEui64() { - if (data) { - data->destroy(); - delete data; - } } char const * @@ -56,7 +46,7 @@ ACLEui64::typeString() const bool ACLEui64::empty () const { - return data->empty(); + return eui64Data.empty(); } Eui::Eui64 * @@ -87,23 +77,14 @@ aclParseEuiData(const char *t) /*******************/ void ACLEui64::parse() -{ - if (!data) - data = new Splay(); - aclParseEuiList(&data); -} - -void -aclParseEuiList(Splay **curlist) { char *t = NULL; - Eui::Eui64 *q = NULL; - + Eui::Eui64 *q; while ((t = strtokFile())) { if ((q = aclParseEuiData(t)) == NULL) continue; - - (*curlist)->insert(q, aclEui64Compare); + eui64Data.insert(*q); + safe_free(q); } } @@ -118,51 +99,27 @@ ACLEui64::match(ACLChecklist *cl) return 0; } - return aclMatchEui(&data, checklist->src_addr); -} - -/***************/ -/* aclMatchEui */ -/***************/ -int -aclMatchEui(Splay **dataptr, Ip::Address &c) -{ 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); + if (lookingFor.lookup(checklist->src_addr)) { + bool found = (eui64Data.find(lookingFor) != eui64Data.end()); + debugs(28, 3, checklist->src_addr << "' " << (found ? "found" : "NOT found")); + return found; } - /* - * Address was not found on any interface - */ - debugs(28, 3, "aclMatchEui: " << c << " NOT found"); + debugs(28, 3, checklist->src_addr << " NOT found"); return 0; } -static int -aclEui64Compare(Eui::Eui64 * const &a, Eui::Eui64 * const &b) -{ - return memcmp(a, b, sizeof(Eui::Eui64)); -} - -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 { - AclEui64DumpVisitor visitor; - data->visit(visitor); - return visitor.contents; + SBufList sl; + for (auto i = eui64Data.cbegin(); i != eui64Data.end(); ++i) { + char buf[48]; + i->encode(buf,48); + sl.push_back(SBuf(buf)); + } + return sl; } #endif /* USE_SQUID_EUI */ diff --git a/src/acl/Eui64.h b/src/acl/Eui64.h index 4dc4fe1c94..d714c6317c 100644 --- a/src/acl/Eui64.h +++ b/src/acl/Eui64.h @@ -13,6 +13,8 @@ #include "acl/Checklist.h" #include "splay.h" +#include + namespace Eui { class Eui64; @@ -38,7 +40,8 @@ public: protected: static Prototype RegistryProtoype; static ACLEui64 RegistryEntry_; - Splay *data; + typedef std::set Eui64Data_t; + Eui64Data_t eui64Data; char const *class_; }; diff --git a/src/eui/Eui64.h b/src/eui/Eui64.h index 711331b533..d08c77c2d7 100644 --- a/src/eui/Eui64.h +++ b/src/eui/Eui64.h @@ -37,6 +37,9 @@ class Eui64 public: Eui64() { clear(); } Eui64(const Eui64 &t) { memcpy(this, &t, sizeof(Eui64)); } + Eui64& operator= (const Eui64 &t) {memcpy(this, &t, sizeof(Eui64)); return *this;} + bool operator== (const Eui64 &t) const { return (memcmp(eui,t.eui,SZ_EUI64_BUF) == 0); } + bool operator< (const Eui64 &t) const { return (memcmp(eui,t.eui,SZ_EUI64_BUF) < 0); } ~Eui64() {} const unsigned char *get(void);