2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 28 Access Control */
15 #include "acl/Eui64.h"
16 #include "acl/FilledChecklist.h"
19 #include "eui/Eui64.h"
21 #include "ip/Address.h"
23 static void aclParseEuiList(Splay
<Eui::Eui64
*> **curlist
);
24 static int aclMatchEui(Splay
<Eui::Eui64
*> **dataptr
, Ip::Address
&c
);
25 static Splay
<Eui::Eui64
*>::SPLAYCMP aclEui64Compare
;
28 ACLEui64::clone() const
30 return new ACLEui64(*this);
33 ACLEui64::ACLEui64 (char const *theClass
) : data (NULL
), class_ (theClass
)
36 ACLEui64::ACLEui64 (ACLEui64
const & old
) : data (NULL
), class_ (old
.class_
)
38 /* we don't have copy constructors for the data yet */
51 ACLEui64::typeString() const
57 ACLEui64::empty () const
63 aclParseEuiData(const char *t
)
66 Eui::Eui64
*q
= new Eui::Eui64
;
67 debugs(28, 5, "aclParseEuiData: " << t
);
69 if (sscanf(t
, "%[0-9a-fA-F:]", buf
) != 1) {
70 debugs(28, DBG_CRITICAL
, "aclParseEuiData: Bad EUI-64 address: '" << t
<< "'");
75 if (!q
->decode(buf
)) {
76 debugs(28, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
77 debugs(28, DBG_CRITICAL
, "aclParseEuiData: Ignoring invalid EUI-64 acl entry: can't parse '" << buf
<< "'");
92 data
= new Splay
<Eui::Eui64
*>();
93 aclParseEuiList(&data
);
97 aclParseEuiList(Splay
<Eui::Eui64
*> **curlist
)
100 Eui::Eui64
*q
= NULL
;
102 while ((t
= strtokFile())) {
103 if ((q
= aclParseEuiData(t
)) == NULL
)
106 (*curlist
)->insert(q
, aclEui64Compare
);
111 ACLEui64::match(ACLChecklist
*cl
)
113 ACLFilledChecklist
*checklist
= Filled(cl
);
115 /* IPv4 does not do EUI-64 (yet) */
116 if (!checklist
->src_addr
.isIPv6()) {
117 debugs(14, 3, "ACLEui64::match: IPv6 Required for EUI-64 Lookups. Skipping " << checklist
->src_addr
);
121 return aclMatchEui(&data
, checklist
->src_addr
);
128 aclMatchEui(Splay
<Eui::Eui64
*> **dataptr
, Ip::Address
&c
)
130 Eui::Eui64 lookingFor
;
132 if (lookingFor
.lookup(c
)) {
133 Eui::Eui64
* const * lookupResult
= (*dataptr
)->find(&lookingFor
, aclEui64Compare
);
134 debugs(28, 3, "aclMatchEui: '" << c
<< "' " << (lookupResult
? "found" : "NOT found"));
135 return (lookupResult
!= NULL
);
139 * Address was not found on any interface
141 debugs(28, 3, "aclMatchEui: " << c
<< " NOT found");
146 aclEui64Compare(Eui::Eui64
* const &a
, Eui::Eui64
* const &b
)
148 return memcmp(a
, b
, sizeof(Eui::Eui64
));
151 struct AclEui64DumpVisitor
{
153 void operator() ( const Eui::Eui64
* v
) {
156 contents
.push_back(SBuf(buf
));
161 ACLEui64::dump() const
163 AclEui64DumpVisitor visitor
;
164 data
->visit(visitor
);
165 return visitor
.contents
;
168 #endif /* USE_SQUID_EUI */