]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Migrated acl/Eui64 to Splay
authorFrancesco Chemolli <kinkie@squid-cache.org>
Tue, 30 Dec 2014 16:52:25 +0000 (17:52 +0100)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Tue, 30 Dec 2014 16:52:25 +0000 (17:52 +0100)
src/acl/Arp.cc
src/acl/Eui64.cc
src/acl/Eui64.h
src/eui/Eui64.cc
src/eui/Eui64.h

index 88f16659c1cba394878bcc7fdc5a15fc364c6575..0d5520b1549aa4b8ed39f180124f0831cbb7da85 100644 (file)
@@ -151,8 +151,7 @@ aclMatchArp(Splay<Eui::Eui48 *> **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);
     }
index 0eedd6978f6ff63e355e34f5346ad55f6d9c8d12..dbc54c1aca4293a9c5fb18fd5712963c3a1361cb 100644 (file)
 #include "globals.h"
 #include "ip/Address.h"
 
-static void aclParseEuiList(SplayNode<Eui::Eui64 *> **curlist);
-static int aclMatchEui(SplayNode<Eui::Eui64 *> **dataptr, Ip::Address &c);
+static void aclParseEuiList(Splay<Eui::Eui64 *> **curlist);
+static int aclMatchEui(Splay<Eui::Eui64 *> **dataptr, Ip::Address &c);
 static SplayNode<Eui::Eui64 *>::SPLAYCMP aclEui64Compare;
-static SplayNode<Eui::Eui64 *>::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<Eui::Eui64*>::DefaultFree);
+        data->destroy();
 }
 
 char const *
@@ -91,17 +90,16 @@ ACLEui64::parse()
 }
 
 void
-aclParseEuiList(SplayNode<Eui::Eui64 *> **curlist)
+aclParseEuiList(Splay<Eui::Eui64 *> **curlist)
 {
     char *t = NULL;
-    SplayNode<Eui::Eui64*> **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<Eui::Eui64 *> **dataptr, Ip::Address &c)
+aclMatchEui(Splay<Eui::Eui64 *> **dataptr, Ip::Address &c)
 {
-    Eui::Eui64 result;
-    SplayNode<Eui::Eui64 *> **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<SBufList *>(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 */
index 4b9e049548c02cda4d8fd87996ebfeeb1fa88e2c..4dc4fe1c9447c64a263ca228c4b5c8267e0640e5 100644 (file)
@@ -38,7 +38,7 @@ public:
 protected:
     static Prototype RegistryProtoype;
     static ACLEui64 RegistryEntry_;
-    SplayNode<Eui::Eui64 *> *data;
+    Splay<Eui::Eui64 *> *data;
     char const *class_;
 };
 
index 654f36c42d6168f359d73127cb75d00b550ab0e5..147a8d943d4f8b1bc330631f3db846d65f199182 100644 (file)
@@ -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;
 
index 029833f5028b5bdac03f9934a1249b6c2aca6297..711331b533351ea62a05008c191306f7172df51c 100644 (file)
@@ -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);