]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Reworked acl/Arp to use Splay instead of SplayNode
authorFrancesco Chemolli <kinkie@squid-cache.org>
Tue, 30 Dec 2014 14:24:28 +0000 (15:24 +0100)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Tue, 30 Dec 2014 14:24:28 +0000 (15:24 +0100)
src/acl/Arp.cc
src/acl/Arp.h
src/eui/Eui48.cc
src/eui/Eui48.h
src/tests/stub_libeui.cc

index 1aa682d9dec81ae54716ecbfad586a17abaaa92c..ec1ff3a720bc128735c00cfe5d8c4bdafb62694c 100644 (file)
 #include "globals.h"
 #include "ip/Address.h"
 
-static void aclParseArpList(SplayNode<Eui::Eui48 *> **curlist);
-static int aclMatchArp(SplayNode<Eui::Eui48 *> **dataptr, Ip::Address &c);
-static SplayNode<Eui::Eui48 *>::SPLAYCMP aclArpCompare;
-static SplayNode<Eui::Eui48 *>::SPLAYWALKEE aclDumpArpListWalkee;
+static void aclParseArpList(Splay<Eui::Eui48 *> **curlist);
+static int aclMatchArp(Splay<Eui::Eui48 *> **dataptr, Ip::Address &c);
+static Splay<Eui::Eui48 *>::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<Eui::Eui48*>::DefaultFree);
+        data->destroy();
 }
 
 char const *
@@ -117,17 +116,16 @@ ACLARP::parse()
 }
 
 void
-aclParseArpList(SplayNode<Eui::Eui48 *> **curlist)
+aclParseArpList(Splay<Eui::Eui48 *> **curlist)
 {
     char *t = NULL;
-    SplayNode<Eui::Eui48*> **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<Eui::Eui48 *> **dataptr, Ip::Address &c)
+aclMatchArp(Splay<Eui::Eui48 *> **dataptr, Ip::Address &c)
 {
-    Eui::Eui48 result;
-    SplayNode<Eui::Eui48 *> **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<SBufList *>(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 =============================================== */
index c6f61847bd41a8006d1f091e82fa2d7cfce4af4e..2654bbdb36dc9397392c06ccdb052a441e19a346 100644 (file)
@@ -39,7 +39,7 @@ public:
 protected:
     static Prototype RegistryProtoype;
     static ACLARP RegistryEntry_;
-    SplayNode<Eui::Eui48 *> *data;
+    Splay<Eui::Eui48 *> *data;
     char const *class_;
 };
 
index 3556c3c151b048ea67fe29a1a89bf6dce334523d..41c8691be30bf616bcd57dfeada79b3858ed68ce 100644 (file)
@@ -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;
index dad409a8cb5c71d0aac37d58994b678246f32820..3100f1de53695fedc2bc926a9eebb8a11aaff89c 100644 (file)
@@ -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);
index 2e1730f87b56009762b39886943a091dd2bdd316..e2ae9b6c0e36cb134bd86d16d061a8916b201730 100644 (file)
@@ -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