Squid Web Cache master
Loading...
Searching...
No Matches
DestinationDomain.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 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"
13#include "acl/DomainData.h"
14#include "acl/FilledChecklist.h"
15#include "acl/RegexData.h"
16#include "fqdncache.h"
17#include "HttpRequest.h"
18
19static void LookupDone(const char *, const Dns::LookupDetails &, void *data);
20
21static void
26
27static void
28LookupDone(const char *, const Dns::LookupDetails &details, void *data)
29{
30 ACLFilledChecklist *checklist = Filled((ACLChecklist*)data);
32 checklist->request->recordLookup(details);
33 checklist->resumeNonBlockingCheck();
34}
35
36/* Acl::DestinationDomainCheck */
37
38const Acl::Options &
40{
41 static const Acl::BooleanOption LookupBanFlag("-n");
42 static const Acl::Options MyOptions = { &LookupBanFlag };
43 LookupBanFlag.linkWith(&lookupBanned);
44 return MyOptions;
45}
46
47int
49{
50 const auto checklist = Filled(ch);
51
52 assert(checklist != nullptr && checklist->request != nullptr);
53
54 if (data->match(checklist->request->url.host())) {
55 return 1;
56 }
57
58 if (lookupBanned) {
59 debugs(28, 3, "No-lookup DNS ACL '" << name << "' for " << checklist->request->url.host());
60 return 0;
61 }
62
63 /* numeric IPA? no, trust the above result. */
64 if (!checklist->request->url.hostIsNumeric()) {
65 return 0;
66 }
67
68 /* do we already have the rDNS? match on it if we do. */
69 if (checklist->dst_rdns) {
70 debugs(28, 3, "'" << name << "' match with stored rDNS '" << checklist->dst_rdns << "' for " << checklist->request->url.host());
71 return data->match(checklist->dst_rdns);
72 }
73
74 /* raw IP without rDNS? look it up and wait for the result */
75 if (!checklist->dst_addr.fromHost(checklist->request->url.host())) {
76 /* not a valid IPA */
77 checklist->dst_rdns = xstrdup("invalid");
78 return 0;
79 }
80
81 const char *fqdn = fqdncache_gethostbyaddr(checklist->dst_addr, FQDN_LOOKUP_IF_MISS);
82
83 if (fqdn) {
84 checklist->dst_rdns = xstrdup(fqdn);
85 return data->match(fqdn);
86 } else if (!checklist->destinationDomainChecked()) {
87 debugs(28, 3, "Can't yet compare '" << name << "' ACL for " << checklist->request->url.host());
88 if (checklist->goAsync(StartLookup, *this))
89 return -1;
90 // else fall through to "none" match, hiding the lookup failure (XXX)
91 }
92
93 return data->match("none");
94}
95
static void StartLookup(ACLFilledChecklist &cl, const Acl::Node &)
static void LookupDone(const char *, const Dns::LookupDetails &, void *data)
ACLFilledChecklist * Filled(ACLChecklist *checklist)
convenience and safety wrapper for dynamic_cast<ACLFilledChecklist*>
#define assert(EX)
Definition assert.h:17
void resumeNonBlockingCheck()
Definition Checklist.cc:230
HttpRequest::Pointer request
const Acl::Options & options() override
Acl::BooleanOptionValue lookupBanned
Are DNS lookups allowed?
int match(ACLChecklist *) override
Matches the actual data in checklist against this Acl::Node.
a type-specific Option (e.g., a boolean –toggle or -m=SBuf)
Definition Options.h:130
void linkWith(Recipient *recipient) const
who to tell when this option is enabled
Definition Options.h:137
encapsulates DNS lookup results
void recordLookup(const Dns::LookupDetails &detail)
#define debugs(SECTION, LEVEL, CONTENT)
Definition Stream.h:192
#define FQDN_LOOKUP_IF_MISS
Definition defines.h:34
const char * fqdncache_gethostbyaddr(const Ip::Address &addr, int flags)
Definition fqdncache.cc:481
void fqdncache_nbgethostbyaddr(const Ip::Address &addr, FQDNH *handler, void *handlerData)
Definition fqdncache.cc:414
std::vector< const Option * > Options
Definition Options.h:217
#define xstrdup