]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/Eui64.cc
Source Format Enforcement (#1234)
[thirdparty/squid.git] / src / acl / Eui64.cc
1 /*
2 * Copyright (C) 1996-2023 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/Stream.h"
19 #include "eui/Eui64.h"
20 #include "globals.h"
21 #include "ip/Address.h"
22
23 ACLEui64::ACLEui64 (char const *theClass) : class_ (theClass)
24 {}
25
26 char const *
27 ACLEui64::typeString() const
28 {
29 return class_;
30 }
31
32 bool
33 ACLEui64::empty () const
34 {
35 return eui64Data.empty();
36 }
37
38 static Eui::Eui64 *
39 aclParseEuiData(const char *t)
40 {
41 char buf[256];
42 Eui::Eui64 *q = new Eui::Eui64;
43 debugs(28, 5, "aclParseEuiData: " << t);
44
45 if (sscanf(t, "%[0-9a-fA-F:]", buf) != 1) {
46 debugs(28, DBG_CRITICAL, "ERROR: aclParseEuiData: Bad EUI-64 address: '" << t << "'");
47 delete q;
48 return nullptr;
49 }
50
51 if (!q->decode(buf)) {
52 debugs(28, DBG_CRITICAL, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
53 debugs(28, DBG_CRITICAL, "ERROR: aclParseEuiData: Ignoring invalid EUI-64 acl entry: cannot parse '" << buf << "'");
54 delete q;
55 return nullptr;
56 }
57
58 return q;
59 }
60
61 /*******************/
62 /* aclParseEuiList */
63 /*******************/
64 void
65 ACLEui64::parse()
66 {
67 while (const char * t = ConfigParser::strtokFile()) {
68 if (Eui::Eui64 * q = aclParseEuiData(t)) {
69 eui64Data.insert(*q);
70 delete q;
71 }
72 }
73 }
74
75 int
76 ACLEui64::match(ACLChecklist *cl)
77 {
78 ACLFilledChecklist *checklist = Filled(cl);
79
80 /* IPv4 does not do EUI-64 (yet) */
81 if (!checklist->src_addr.isIPv6()) {
82 debugs(14, 3, "ACLEui64::match: IPv6 Required for EUI-64 Lookups. Skipping " << checklist->src_addr );
83 return 0;
84 }
85
86 Eui::Eui64 lookingFor;
87 if (lookingFor.lookup(checklist->src_addr)) {
88 bool found = (eui64Data.find(lookingFor) != eui64Data.end());
89 debugs(28, 3, checklist->src_addr << "' " << (found ? "found" : "NOT found"));
90 return found;
91 }
92
93 debugs(28, 3, checklist->src_addr << " NOT found");
94 return 0;
95 }
96
97 SBufList
98 ACLEui64::dump() const
99 {
100 SBufList sl;
101 for (auto i = eui64Data.begin(); i != eui64Data.end(); ++i) {
102 static char buf[48];
103 i->encode(buf,48);
104 sl.push_back(SBuf(buf));
105 }
106 return sl;
107 }
108
109 #endif /* USE_SQUID_EUI */
110