]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/Eui64.cc
Merged from trunk
[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 ACLEui64::~ACLEui64()
37 {
38 }
39
40 char const *
41 ACLEui64::typeString() const
42 {
43 return class_;
44 }
45
46 bool
47 ACLEui64::empty () const
48 {
49 return eui64Data.empty();
50 }
51
52 Eui::Eui64 *
53 aclParseEuiData(const char *t)
54 {
55 char buf[256];
56 Eui::Eui64 *q = new Eui::Eui64;
57 debugs(28, 5, "aclParseEuiData: " << t);
58
59 if (sscanf(t, "%[0-9a-fA-F:]", buf) != 1) {
60 debugs(28, DBG_CRITICAL, "aclParseEuiData: Bad EUI-64 address: '" << t << "'");
61 safe_free(q);
62 return NULL;
63 }
64
65 if (!q->decode(buf)) {
66 debugs(28, DBG_CRITICAL, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
67 debugs(28, DBG_CRITICAL, "aclParseEuiData: Ignoring invalid EUI-64 acl entry: can't parse '" << buf << "'");
68 safe_free(q);
69 return NULL;
70 }
71
72 return q;
73 }
74
75 /*******************/
76 /* aclParseEuiList */
77 /*******************/
78 void
79 ACLEui64::parse()
80 {
81 char *t = NULL;
82 Eui::Eui64 *q;
83 while ((t = strtokFile())) {
84 if ((q = aclParseEuiData(t)) == NULL)
85 continue;
86 eui64Data.insert(*q);
87 safe_free(q);
88 }
89 }
90
91 int
92 ACLEui64::match(ACLChecklist *cl)
93 {
94 ACLFilledChecklist *checklist = Filled(cl);
95
96 /* IPv4 does not do EUI-64 (yet) */
97 if (!checklist->src_addr.isIPv6()) {
98 debugs(14, 3, "ACLEui64::match: IPv6 Required for EUI-64 Lookups. Skipping " << checklist->src_addr );
99 return 0;
100 }
101
102 Eui::Eui64 lookingFor;
103 if (lookingFor.lookup(checklist->src_addr)) {
104 bool found = (eui64Data.find(lookingFor) != eui64Data.end());
105 debugs(28, 3, checklist->src_addr << "' " << (found ? "found" : "NOT found"));
106 return found;
107 }
108
109 debugs(28, 3, checklist->src_addr << " NOT found");
110 return 0;
111 }
112
113 SBufList
114 ACLEui64::dump() const
115 {
116 SBufList sl;
117 for (auto i = eui64Data.cbegin(); i != eui64Data.end(); ++i) {
118 char buf[48];
119 i->encode(buf,48);
120 sl.push_back(SBuf(buf));
121 }
122 return sl;
123 }
124
125 #endif /* USE_SQUID_EUI */
126