DestinationDomain.cc
Go to the documentation of this file.
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"
13#include "acl/DomainData.h"
14#include "acl/FilledChecklist.h"
15#include "acl/RegexData.h"
16#include "fqdncache.h"
17#include "HttpRequest.h"
18
20
23{
24 return &instance_;
25}
26
27void
29{
30 ACLFilledChecklist *checklist = Filled(cl);
31 fqdncache_nbgethostbyaddr(checklist->dst_addr, LookupDone, checklist);
32}
33
34void
35DestinationDomainLookup::LookupDone(const char *, const Dns::LookupDetails &details, void *data)
36{
37 ACLFilledChecklist *checklist = Filled((ACLChecklist*)data);
39 checklist->request->recordLookup(details);
41}
42
43/* Acl::DestinationDomainCheck */
44
45const Acl::Options &
47{
48 static const Acl::BooleanOption LookupBanFlag("-n");
49 static const Acl::Options MyOptions = { &LookupBanFlag };
50 LookupBanFlag.linkWith(&lookupBanned);
51 return MyOptions;
52}
53
54int
56{
57 const auto checklist = Filled(ch);
58
59 assert(checklist != nullptr && checklist->request != nullptr);
60
61 if (data->match(checklist->request->url.host())) {
62 return 1;
63 }
64
65 if (lookupBanned) {
66 debugs(28, 3, "No-lookup DNS ACL '" << AclMatchedName << "' for " << checklist->request->url.host());
67 return 0;
68 }
69
70 /* numeric IPA? no, trust the above result. */
71 if (!checklist->request->url.hostIsNumeric()) {
72 return 0;
73 }
74
75 /* do we already have the rDNS? match on it if we do. */
76 if (checklist->dst_rdns) {
77 debugs(28, 3, "'" << AclMatchedName << "' match with stored rDNS '" << checklist->dst_rdns << "' for " << checklist->request->url.host());
78 return data->match(checklist->dst_rdns);
79 }
80
81 /* raw IP without rDNS? look it up and wait for the result */
82 if (!checklist->dst_addr.fromHost(checklist->request->url.host())) {
83 /* not a valid IPA */
84 checklist->dst_rdns = xstrdup("invalid");
85 return 0;
86 }
87
88 const char *fqdn = fqdncache_gethostbyaddr(checklist->dst_addr, FQDN_LOOKUP_IF_MISS);
89
90 if (fqdn) {
91 checklist->dst_rdns = xstrdup(fqdn);
92 return data->match(fqdn);
93 } else if (!checklist->destinationDomainChecked()) {
94 // TODO: Using AclMatchedName here is not OO correct. Should find a way to the current acl
95 debugs(28, 3, "Can't yet compare '" << AclMatchedName << "' ACL for " << checklist->request->url.host());
96 if (checklist->goAsync(DestinationDomainLookup::Instance()))
97 return -1;
98 // else fall through to "none" match, hiding the lookup failure (XXX)
99 }
100
101 return data->match("none");
102}
103
ACLFilledChecklist * Filled(ACLChecklist *checklist)
convenience and safety wrapper for dynamic_cast<ACLFilledChecklist*>
#define assert(EX)
Definition: assert.h:17
void resumeNonBlockingCheck(AsyncState *state)
Definition: Checklist.cc:261
Ip::Address dst_addr
void markDestinationDomainChecked()
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.
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
void checkForAsync(ACLChecklist *) const override
static DestinationDomainLookup instance_
static void LookupDone(const char *, const Dns::LookupDetails &, void *)
static DestinationDomainLookup * Instance()
encapsulates DNS lookup results
Definition: LookupDetails.h:23
void recordLookup(const Dns::LookupDetails &detail)
Definition: HttpRequest.cc:580
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
#define FQDN_LOOKUP_IF_MISS
Definition: defines.h:34
const char * AclMatchedName
Definition: Acl.cc:29
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:214
#define xstrdup

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors