]> git.ipfire.org Git - thirdparty/squid.git/blame - src/acl/Eui64.cc
Maintenance: Removed most NULLs using modernize-use-nullptr (#1075)
[thirdparty/squid.git] / src / acl / Eui64.cc
CommitLineData
a98c2da5 1/*
bf95c10a 2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
a98c2da5 3 *
bbc27441
AJ
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.
a98c2da5
AJ
7 */
8
bbc27441
AJ
9/* DEBUG: section 28 Access Control */
10
582c2af2 11#include "squid.h"
a98c2da5
AJ
12
13#if USE_SQUID_EUI
14
15#include "acl/Eui64.h"
16#include "acl/FilledChecklist.h"
aa3b39af 17#include "cache_cf.h"
675b8408 18#include "debug/Stream.h"
a98c2da5 19#include "eui/Eui64.h"
9b859d6f 20#include "globals.h"
96d89ea0 21#include "ip/Address.h"
a98c2da5 22
fdd757c5 23ACLEui64::ACLEui64 (char const *theClass) : class_ (theClass)
a98c2da5
AJ
24{}
25
a98c2da5
AJ
26char const *
27ACLEui64::typeString() const
28{
29 return class_;
30}
31
32bool
33ACLEui64::empty () const
34{
fdd757c5 35 return eui64Data.empty();
a98c2da5
AJ
36}
37
8b082ed9 38static Eui::Eui64 *
a98c2da5
AJ
39aclParseEuiData(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) {
d816f28d 46 debugs(28, DBG_CRITICAL, "ERROR: aclParseEuiData: Bad EUI-64 address: '" << t << "'");
2dd66a22 47 delete q;
aee3523a 48 return nullptr;
a98c2da5
AJ
49 }
50
51 if (!q->decode(buf)) {
fa84c01d 52 debugs(28, DBG_CRITICAL, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
d816f28d 53 debugs(28, DBG_CRITICAL, "ERROR: aclParseEuiData: Ignoring invalid EUI-64 acl entry: cannot parse '" << buf << "'");
2dd66a22 54 delete q;
aee3523a 55 return nullptr;
a98c2da5
AJ
56 }
57
58 return q;
59}
60
a98c2da5
AJ
61/*******************/
62/* aclParseEuiList */
63/*******************/
64void
65ACLEui64::parse()
a98c2da5 66{
16c5ad96 67 while (const char * t = ConfigParser::strtokFile()) {
68acf08e
FC
68 if (Eui::Eui64 * q = aclParseEuiData(t)) {
69 eui64Data.insert(*q);
2dd66a22 70 delete q;
68acf08e 71 }
a98c2da5
AJ
72 }
73}
74
75int
76ACLEui64::match(ACLChecklist *cl)
77{
78 ACLFilledChecklist *checklist = Filled(cl);
79
80 /* IPv4 does not do EUI-64 (yet) */
4dd643d5 81 if (!checklist->src_addr.isIPv6()) {
a98c2da5
AJ
82 debugs(14, 3, "ACLEui64::match: IPv6 Required for EUI-64 Lookups. Skipping " << checklist->src_addr );
83 return 0;
84 }
85
736a7789 86 Eui::Eui64 lookingFor;
fdd757c5
FC
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;
a98c2da5
AJ
91 }
92
fdd757c5 93 debugs(28, 3, checklist->src_addr << " NOT found");
a98c2da5
AJ
94 return 0;
95}
96
9b859d6f 97SBufList
a98c2da5
AJ
98ACLEui64::dump() const
99{
fdd757c5 100 SBufList sl;
b06c45a5 101 for (auto i = eui64Data.begin(); i != eui64Data.end(); ++i) {
68acf08e 102 static char buf[48];
fdd757c5
FC
103 i->encode(buf,48);
104 sl.push_back(SBuf(buf));
105 }
106 return sl;
a98c2da5
AJ
107}
108
109#endif /* USE_SQUID_EUI */
f53969cc 110