]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/Eui64.cc
Incorporated Amos suggestions
[thirdparty/squid.git] / src / acl / Eui64.cc
1 /*
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9 /* DEBUG: section 28 Access Control */
10
11 #include "squid.h"
12
13 #if USE_SQUID_EUI
14
15 #include "acl/Eui64.h"
16 #include "acl/FilledChecklist.h"
17 #include "cache_cf.h"
18 #include "Debug.h"
19 #include "eui/Eui64.h"
20 #include "globals.h"
21 #include "ip/Address.h"
22
23 ACL *
24 ACLEui64::clone() const
25 {
26 return new ACLEui64(*this);
27 }
28
29 ACLEui64::ACLEui64 (char const *theClass) : class_ (theClass)
30 {}
31
32 ACLEui64::ACLEui64 (ACLEui64 const & old) : eui64Data(old.eui64Data), class_ (old.class_)
33 {
34 }
35
36 char const *
37 ACLEui64::typeString() const
38 {
39 return class_;
40 }
41
42 bool
43 ACLEui64::empty () const
44 {
45 return eui64Data.empty();
46 }
47
48 Eui::Eui64 *
49 aclParseEuiData(const char *t)
50 {
51 char buf[256];
52 Eui::Eui64 *q = new Eui::Eui64;
53 debugs(28, 5, "aclParseEuiData: " << t);
54
55 if (sscanf(t, "%[0-9a-fA-F:]", buf) != 1) {
56 debugs(28, DBG_CRITICAL, "aclParseEuiData: Bad EUI-64 address: '" << t << "'");
57 safe_free(q);
58 return NULL;
59 }
60
61 if (!q->decode(buf)) {
62 debugs(28, DBG_CRITICAL, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
63 debugs(28, DBG_CRITICAL, "aclParseEuiData: Ignoring invalid EUI-64 acl entry: can't parse '" << buf << "'");
64 safe_free(q);
65 return NULL;
66 }
67
68 return q;
69 }
70
71 /*******************/
72 /* aclParseEuiList */
73 /*******************/
74 void
75 ACLEui64::parse()
76 {
77 while (const char * t = strtokFile()) {
78 if (Eui::Eui64 * q = aclParseEuiData(t)) {
79 eui64Data.insert(*q);
80 safe_free(q);
81 }
82 }
83 }
84
85 int
86 ACLEui64::match(ACLChecklist *cl)
87 {
88 ACLFilledChecklist *checklist = Filled(cl);
89
90 /* IPv4 does not do EUI-64 (yet) */
91 if (!checklist->src_addr.isIPv6()) {
92 debugs(14, 3, "ACLEui64::match: IPv6 Required for EUI-64 Lookups. Skipping " << checklist->src_addr );
93 return 0;
94 }
95
96 Eui::Eui64 lookingFor;
97 if (lookingFor.lookup(checklist->src_addr)) {
98 bool found = (eui64Data.find(lookingFor) != eui64Data.end());
99 debugs(28, 3, checklist->src_addr << "' " << (found ? "found" : "NOT found"));
100 return found;
101 }
102
103 debugs(28, 3, checklist->src_addr << " NOT found");
104 return 0;
105 }
106
107 SBufList
108 ACLEui64::dump() const
109 {
110 SBufList sl;
111 for (auto i = eui64Data.cbegin(); i != eui64Data.end(); ++i) {
112 static char buf[48];
113 i->encode(buf,48);
114 sl.push_back(SBuf(buf));
115 }
116 return sl;
117 }
118
119 #endif /* USE_SQUID_EUI */
120