From fbbea66208ab3b74f7c077855d6563444cb4b929 Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Thu, 8 Oct 2015 19:13:00 -0700 Subject: [PATCH] Add syncAle() to reduce external ACL format transition problems --- src/acl/Acl.cc | 4 +++ src/acl/Checklist.h | 1 + src/acl/FilledChecklist.cc | 56 ++++++++++++++++++++++++++++++++++++++ src/acl/FilledChecklist.h | 1 + src/format/Format.cc | 3 ++ 5 files changed, 65 insertions(+) diff --git a/src/acl/Acl.cc b/src/acl/Acl.cc index 91449e442b..81602c6682 100644 --- a/src/acl/Acl.cc +++ b/src/acl/Acl.cc @@ -163,6 +163,10 @@ ACL::matches(ACLChecklist *checklist) const debugs(28, DBG_IMPORTANT, "WARNING: " << name << " ACL is used in " << "context without an HTTP response. Assuming mismatch."); } else { + // make sure the ALE has as much data as possible + if (requiresAle()) + checklist->syncAle(); + // have to cast because old match() API is missing const result = const_cast(this)->match(checklist); } diff --git a/src/acl/Checklist.h b/src/acl/Checklist.h index aa07cf5e45..8575bdadc1 100644 --- a/src/acl/Checklist.h +++ b/src/acl/Checklist.h @@ -164,6 +164,7 @@ public: virtual bool hasRequest() const = 0; virtual bool hasReply() const = 0; virtual bool hasAle() const = 0; + virtual void syncAle() const = 0; /// change the current ACL list /// \return a pointer to the old list value (may be nullptr) diff --git a/src/acl/FilledChecklist.cc b/src/acl/FilledChecklist.cc index fb8bf2f8a3..1bd16af2ed 100644 --- a/src/acl/FilledChecklist.cc +++ b/src/acl/FilledChecklist.cc @@ -66,6 +66,62 @@ ACLFilledChecklist::~ACLFilledChecklist() debugs(28, 4, HERE << "ACLFilledChecklist destroyed " << this); } +static void +showDebugWarning(const char *msg) +{ + static uint16_t count = 0; + if (count > 100) + return; + + ++count; + debugs(28, DBG_IMPORTANT, "ALE missing " << msg); +} + +void +ACLFilledChecklist::syncAle() const +{ + // make sure the ALE fields used by Format::assemble to + // fill the old external_acl_type codes are set if any + // data on them exists in the Checklist + + if (!al->cache.port && conn()) { + showDebugWarning("listening port"); + al->cache.port = conn()->port; + } + + if (request) { + if (!al->request) { + showDebugWarning("HttpRequest object"); + al->request = request; + HTTPMSGLOCK(al->request); + } + + if (!al->adapted_request) { + showDebugWarning("adapted HttpRequest object"); + al->adapted_request = request; + HTTPMSGLOCK(al->adapted_request); + } + + if (!al->url) { + showDebugWarning("URL"); + al->url = xstrdup(request->url.absolute().c_str()); + } + } + + if (reply && !al->reply) { + showDebugWarning("HttpReply object"); + al->reply = reply; + HTTPMSGLOCK(al->reply); + } + +#if USE_IDENT + if (rfc931 && !al->cache.rfc931) { + showDebugWarning("IDENT"); + al->cache.rfc931 = xstrdup(rfc931); + } +#endif +} + ConnStateData * ACLFilledChecklist::conn() const { diff --git a/src/acl/FilledChecklist.h b/src/acl/FilledChecklist.h index c8ff41c1f5..523569668c 100644 --- a/src/acl/FilledChecklist.h +++ b/src/acl/FilledChecklist.h @@ -63,6 +63,7 @@ public: virtual bool hasRequest() const { return request != NULL; } virtual bool hasReply() const { return reply != NULL; } virtual bool hasAle() const { return al != NULL; } + virtual void syncAle() const; public: Ip::Address src_addr; diff --git a/src/format/Format.cc b/src/format/Format.cc index 5553990f33..6f929779a6 100644 --- a/src/format/Format.cc +++ b/src/format/Format.cc @@ -458,6 +458,9 @@ Format::Format::assemble(MemBuf &mb, const AccessLogEntry::Pointer &al, int logS if (al->cache.port != NULL) { outint = al->cache.port->s.port(); doint = 1; + } else if (al->request) { + outint = al->request->my_addr.port(); + doint = 1; } break; -- 2.47.3