]>
Commit | Line | Data |
---|---|---|
a98c2da5 | 1 | /* |
bde978a6 | 2 | * Copyright (C) 1996-2015 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" | |
06390e4b | 17 | #include "cache_cf.h" |
582c2af2 | 18 | #include "Debug.h" |
a98c2da5 | 19 | #include "eui/Eui64.h" |
9b859d6f | 20 | #include "globals.h" |
96d89ea0 | 21 | #include "ip/Address.h" |
a98c2da5 | 22 | |
736a7789 FC |
23 | static void aclParseEuiList(Splay<Eui::Eui64 *> **curlist); |
24 | static int aclMatchEui(Splay<Eui::Eui64 *> **dataptr, Ip::Address &c); | |
1e4f953d | 25 | static Splay<Eui::Eui64 *>::SPLAYCMP aclEui64Compare; |
a98c2da5 | 26 | |
a98c2da5 AJ |
27 | ACL * |
28 | ACLEui64::clone() const | |
29 | { | |
30 | return new ACLEui64(*this); | |
31 | } | |
32 | ||
33 | ACLEui64::ACLEui64 (char const *theClass) : data (NULL), class_ (theClass) | |
34 | {} | |
35 | ||
36 | ACLEui64::ACLEui64 (ACLEui64 const & old) : data (NULL), class_ (old.class_) | |
37 | { | |
38 | /* we don't have copy constructors for the data yet */ | |
39 | assert (!old.data); | |
40 | } | |
41 | ||
42 | ACLEui64::~ACLEui64() | |
43 | { | |
f5dc4237 | 44 | if (data) { |
736a7789 | 45 | data->destroy(); |
f5dc4237 FC |
46 | delete data; |
47 | } | |
a98c2da5 AJ |
48 | } |
49 | ||
50 | char const * | |
51 | ACLEui64::typeString() const | |
52 | { | |
53 | return class_; | |
54 | } | |
55 | ||
56 | bool | |
57 | ACLEui64::empty () const | |
58 | { | |
59 | return data->empty(); | |
60 | } | |
61 | ||
62 | Eui::Eui64 * | |
63 | aclParseEuiData(const char *t) | |
64 | { | |
65 | char buf[256]; | |
66 | Eui::Eui64 *q = new Eui::Eui64; | |
67 | debugs(28, 5, "aclParseEuiData: " << t); | |
68 | ||
69 | if (sscanf(t, "%[0-9a-fA-F:]", buf) != 1) { | |
fa84c01d | 70 | debugs(28, DBG_CRITICAL, "aclParseEuiData: Bad EUI-64 address: '" << t << "'"); |
a98c2da5 AJ |
71 | safe_free(q); |
72 | return NULL; | |
73 | } | |
74 | ||
75 | if (!q->decode(buf)) { | |
fa84c01d FC |
76 | debugs(28, DBG_CRITICAL, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line); |
77 | debugs(28, DBG_CRITICAL, "aclParseEuiData: Ignoring invalid EUI-64 acl entry: can't parse '" << buf << "'"); | |
a98c2da5 AJ |
78 | safe_free(q); |
79 | return NULL; | |
80 | } | |
81 | ||
82 | return q; | |
83 | } | |
84 | ||
a98c2da5 AJ |
85 | /*******************/ |
86 | /* aclParseEuiList */ | |
87 | /*******************/ | |
88 | void | |
89 | ACLEui64::parse() | |
90 | { | |
5bc2be30 FC |
91 | if (!data) |
92 | data = new Splay<Eui::Eui64 *>(); | |
a98c2da5 AJ |
93 | aclParseEuiList(&data); |
94 | } | |
95 | ||
96 | void | |
736a7789 | 97 | aclParseEuiList(Splay<Eui::Eui64 *> **curlist) |
a98c2da5 AJ |
98 | { |
99 | char *t = NULL; | |
a98c2da5 AJ |
100 | Eui::Eui64 *q = NULL; |
101 | ||
102 | while ((t = strtokFile())) { | |
103 | if ((q = aclParseEuiData(t)) == NULL) | |
104 | continue; | |
105 | ||
736a7789 | 106 | (*curlist)->insert(q, aclEui64Compare); |
a98c2da5 AJ |
107 | } |
108 | } | |
109 | ||
110 | int | |
111 | ACLEui64::match(ACLChecklist *cl) | |
112 | { | |
113 | ACLFilledChecklist *checklist = Filled(cl); | |
114 | ||
115 | /* IPv4 does not do EUI-64 (yet) */ | |
4dd643d5 | 116 | if (!checklist->src_addr.isIPv6()) { |
a98c2da5 AJ |
117 | debugs(14, 3, "ACLEui64::match: IPv6 Required for EUI-64 Lookups. Skipping " << checklist->src_addr ); |
118 | return 0; | |
119 | } | |
120 | ||
121 | return aclMatchEui(&data, checklist->src_addr); | |
122 | } | |
123 | ||
124 | /***************/ | |
125 | /* aclMatchEui */ | |
126 | /***************/ | |
127 | int | |
736a7789 | 128 | aclMatchEui(Splay<Eui::Eui64 *> **dataptr, Ip::Address &c) |
a98c2da5 | 129 | { |
736a7789 FC |
130 | Eui::Eui64 lookingFor; |
131 | ||
132 | if (lookingFor.lookup(c)) { | |
133 | Eui::Eui64 * const * lookupResult = (*dataptr)->find(&lookingFor, aclEui64Compare); | |
134 | debugs(28, 3, "aclMatchEui: '" << c << "' " << (lookupResult ? "found" : "NOT found")); | |
135 | return (lookupResult != NULL); | |
a98c2da5 AJ |
136 | } |
137 | ||
138 | /* | |
139 | * Address was not found on any interface | |
140 | */ | |
141 | debugs(28, 3, "aclMatchEui: " << c << " NOT found"); | |
142 | return 0; | |
143 | } | |
144 | ||
145 | static int | |
146 | aclEui64Compare(Eui::Eui64 * const &a, Eui::Eui64 * const &b) | |
147 | { | |
148 | return memcmp(a, b, sizeof(Eui::Eui64)); | |
149 | } | |
150 | ||
736a7789 FC |
151 | struct AclEui64DumpVisitor { |
152 | SBufList contents; | |
153 | void operator() ( const Eui::Eui64 * v) { | |
154 | static char buf[48]; | |
155 | v->encode(buf, 48); | |
156 | contents.push_back(SBuf(buf)); | |
157 | } | |
158 | }; | |
a98c2da5 | 159 | |
9b859d6f | 160 | SBufList |
a98c2da5 AJ |
161 | ACLEui64::dump() const |
162 | { | |
736a7789 FC |
163 | AclEui64DumpVisitor visitor; |
164 | data->visit(visitor); | |
165 | return visitor.contents; | |
a98c2da5 AJ |
166 | } |
167 | ||
168 | #endif /* USE_SQUID_EUI */ | |
f53969cc | 169 |