#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
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 *
bool
ACLARP::empty () const
{
- return data->empty();
+ return aclArpData.empty();
}
/* ==== BEGIN ARP ACL SUPPORT ============================================= */
/*******************/
void
ACLARP::parse()
-{
- aclParseArpList(&data);
-}
-
-void
-aclParseArpList(Splay<Eui::Eui48 *> **curlist)
{
char *t = NULL;
Eui::Eui48 *q = NULL;
if ((q = aclParseArpData(t)) == NULL)
continue;
- (*curlist)->insert(q, aclArpCompare);
+ aclArpData.insert(*q);
}
+
}
int
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 =============================================== */