]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Migrated ARP acl to std::map
authorFrancesco Chemolli <kinkie@squid-cache.org>
Tue, 6 Jan 2015 17:45:21 +0000 (18:45 +0100)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Tue, 6 Jan 2015 17:45:21 +0000 (18:45 +0100)
src/acl/Arp.cc
src/acl/Arp.h
src/eui/Eui48.h

index 5eae6100b432d78ad9ccd9e37f5de87599c8785c..3a2fd46d1fc31d2d94b28e7e3ae6e2ff2d41c03c 100644 (file)
@@ -20,9 +20,7 @@
 #include "globals.h"
 #include "ip/Address.h"
 
-static void aclParseArpList(Splay<Eui::Eui48 *> **curlist);
-static int aclMatchArp(Splay<Eui::Eui48 *> **dataptr, Ip::Address &c);
-static Splay<Eui::Eui48 *>::SPLAYCMP aclArpCompare;
+#include <algorithm>
 
 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<Eui::Eui48 *> **curlist)
 {
     char *t = NULL;
     Eui::Eui48 *q = NULL;
@@ -127,8 +113,9 @@ aclParseArpList(Splay<Eui::Eui48 *> **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<Eui::Eui48 *> **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 =============================================== */
index e6b3bc8c678121f5d4618795ed869a8bf84b5d00..23633166756e8f9c9149f9cdd4cfbfd31d38c83c 100644 (file)
@@ -13,6 +13,8 @@
 #include "acl/Checklist.h"
 #include "splay.h"
 
+#include <set>
+
 namespace Eui
 {
 class Eui48;
@@ -39,8 +41,9 @@ public:
 protected:
     static Prototype RegistryProtoype;
     static ACLARP RegistryEntry_;
-    Splay<Eui::Eui48 *> *data;
     char const *class_;
+    typedef std::set<Eui::Eui48> AclArpData_t;
+    AclArpData_t aclArpData;
 };
 
 #endif /* SQUID_ACLARP_H */
index dade176463487858f649221e52f5c9eb58e0d0e1..fc968830aa57f77b5a96e6d110991d88f9b4c3c6 100644 (file)
@@ -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);