From: Francesco Chemolli Date: Tue, 6 Jan 2015 17:45:21 +0000 (+0100) Subject: Migrated ARP acl to std::map X-Git-Tag: merge-candidate-3-v1~345^2~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=41b91720118a5cf1d0eb47fdb903a841f46bb750;p=thirdparty%2Fsquid.git Migrated ARP acl to std::map --- diff --git a/src/acl/Arp.cc b/src/acl/Arp.cc index 5eae6100b4..3a2fd46d1f 100644 --- a/src/acl/Arp.cc +++ b/src/acl/Arp.cc @@ -20,9 +20,7 @@ #include "globals.h" #include "ip/Address.h" -static void aclParseArpList(Splay **curlist); -static int aclMatchArp(Splay **dataptr, Ip::Address &c); -static Splay::SPLAYCMP aclArpCompare; +#include ACL * ACLARP::clone() const @@ -30,21 +28,15 @@ ACLARP::clone() const return new ACLARP(*this); } -ACLARP::ACLARP (char const *theClass) : data (NULL), class_ (theClass) +ACLARP::ACLARP (char const *theClass) : class_ (theClass) {} -ACLARP::ACLARP (ACLARP const & old) : data (NULL), class_ (old.class_) +ACLARP::ACLARP (ACLARP const & old) : class_ (old.class_), aclArpData(old.aclArpData) { - /* we don't have copy constructors for the data yet */ - assert (!old.data); } ACLARP::~ACLARP() { - if (data) { - data->destroy(); - delete data; - } } char const * @@ -56,7 +48,7 @@ ACLARP::typeString() const bool ACLARP::empty () const { - return data->empty(); + return aclArpData.empty(); } /* ==== BEGIN ARP ACL SUPPORT ============================================= */ @@ -113,12 +105,6 @@ aclParseArpData(const char *t) /*******************/ void ACLARP::parse() -{ - aclParseArpList(&data); -} - -void -aclParseArpList(Splay **curlist) { char *t = NULL; Eui::Eui48 *q = NULL; @@ -127,8 +113,9 @@ aclParseArpList(Splay **curlist) if ((q = aclParseArpData(t)) == NULL) continue; - (*curlist)->insert(q, aclArpCompare); + aclArpData.insert(*q); } + } int @@ -142,47 +129,22 @@ ACLARP::match(ACLChecklist *cl) return 0; } - return aclMatchArp(&data, checklist->src_addr); -} - -/***************/ -/* aclMatchArp */ -/***************/ -int -aclMatchArp(Splay **dataptr, Ip::Address &c) -{ Eui::Eui48 lookingFor; - if (lookingFor.lookup(c)) { - Eui::Eui48 * const* lookupResult = (*dataptr)->find(&lookingFor,aclArpCompare); - debugs(28, 3, "aclMatchArp: '" << c << "' " << (lookupResult ? "found" : "NOT found")); - return (lookupResult != NULL); - } - debugs(28, 3, "aclMatchArp: " << c << " NOT found"); - return 0; -} - -static int -aclArpCompare(Eui::Eui48 * const &a, Eui::Eui48 * const &b) -{ - return memcmp(a, b, sizeof(Eui::Eui48)); + lookingFor.lookup(checklist->src_addr); + return (aclArpData.find(lookingFor) != aclArpData.end()); } -// 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 { - ArpAclDumpVisitor visitor; - data->visit(visitor); - return visitor.contents; + 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); + sl.push_back(SBuf(buf)); + } + return sl; } /* ==== END ARP ACL SUPPORT =============================================== */ diff --git a/src/acl/Arp.h b/src/acl/Arp.h index e6b3bc8c67..2363316675 100644 --- a/src/acl/Arp.h +++ b/src/acl/Arp.h @@ -13,6 +13,8 @@ #include "acl/Checklist.h" #include "splay.h" +#include + namespace Eui { class Eui48; @@ -39,8 +41,9 @@ public: protected: static Prototype RegistryProtoype; static ACLARP RegistryEntry_; - Splay *data; char const *class_; + typedef std::set AclArpData_t; + AclArpData_t aclArpData; }; #endif /* SQUID_ACLARP_H */ diff --git a/src/eui/Eui48.h b/src/eui/Eui48.h index dade176463..fc968830aa 100644 --- a/src/eui/Eui48.h +++ b/src/eui/Eui48.h @@ -30,6 +30,8 @@ class Eui48 public: Eui48() { clear(); } Eui48(const Eui48 &t) { memcpy(this, &t, sizeof(Eui48)); } + bool operator== (const Eui48 &t) const { return memcmp(eui, t.eui, SZ_EUI48_BUF) == 0; } + bool operator< (const Eui48 &t) const { return memcmp(eui, t.eui, SZ_EUI48_BUF) < 0; } ~Eui48() {} const unsigned char *get(void);