]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Add syncAle() to reduce external ACL format transition problems
authorAmos Jeffries <squid3@treenet.co.nz>
Fri, 9 Oct 2015 02:13:00 +0000 (19:13 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Fri, 9 Oct 2015 02:13:00 +0000 (19:13 -0700)
src/acl/Acl.cc
src/acl/Checklist.h
src/acl/FilledChecklist.cc
src/acl/FilledChecklist.h
src/format/Format.cc

index 91449e442b8b9aaeffc0e937418e38066c049863..81602c6682abdb2d029b2b397900e3ca640a302c 100644 (file)
@@ -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<ACL*>(this)->match(checklist);
     }
index aa07cf5e45c5fcfca9cae93de674b011036ea301..8575bdadc1024d80e2498e3c9b8bb2d050ac7c59 100644 (file)
@@ -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)
index fb8bf2f8a39cdb35c304c788516680c61a5e72ea..1bd16af2edf26ae1f979bf1bee4389eb1a7b8717 100644 (file)
@@ -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
 {
index c8ff41c1f59dcb42b86c815ea5369674cd470675..523569668c5fbeafb470553bc0442ff047b9b7a2 100644 (file)
@@ -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;
index 5553990f33b6bba7ac995709e8cd1c59a205115e..6f929779a6cdb4c95b4eb6054747c6d844fe2df2 100644 (file)
@@ -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;