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