You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bc...@apache.org on 2019/05/23 16:27:51 UTC

[trafficserver] branch master updated: Added loop detection via code and squid logging code

This is an automated email from the ASF dual-hosted git repository.

bcall pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 9f19954  Added loop detection via code and squid logging code
9f19954 is described below

commit 9f1995477b94c602aef449a4a5d024b8ba10aa8a
Author: Bryan Call <bc...@apache.org>
AuthorDate: Thu Mar 14 10:00:15 2019 -0700

    Added loop detection via code and squid logging code
---
 doc/appendices/command-line/traffic_via.en.rst |  4 ++--
 doc/appendices/faq.en.rst                      |  1 +
 proxy/hdrs/HTTP.h                              |  3 ++-
 proxy/http/HttpTransact.cc                     | 22 ++++++++++++----------
 proxy/http/HttpTransact.h                      |  2 +-
 proxy/http/HttpTransactHeaders.cc              |  6 ++++--
 proxy/logging/Log.cc                           |  6 +++---
 src/traffic_via/traffic_via.cc                 |  1 +
 tools/traffic_via/traffic_via.pl               | 11 +++++------
 9 files changed, 31 insertions(+), 25 deletions(-)

diff --git a/doc/appendices/command-line/traffic_via.en.rst b/doc/appendices/command-line/traffic_via.en.rst
index 18cd8ec..bacedb3 100644
--- a/doc/appendices/command-line/traffic_via.en.rst
+++ b/doc/appendices/command-line/traffic_via.en.rst
@@ -56,8 +56,8 @@ Examples
 
 Decode the Via header from command-line arguments::
 
-    $ traffic_via "[uScMsEf p eC:t cCMi p sF]"
-    Via header is uScMsEf p eC:t cCMi p sF, Length is 24
+    $ traffic_via "[uScMsEf p eC:t cCMp sF]"
+    Via header is [uScMsEf p eC:t cCMp sF], Length is 22
     Via Header Details:
     Request headers received from client                   :simple request (not conditional)
     Result of Traffic Server cache lookup for URL          :miss (a cache "MISS")
diff --git a/doc/appendices/faq.en.rst b/doc/appendices/faq.en.rst
index 4e45fa4..e63f62e 100644
--- a/doc/appendices/faq.en.rst
+++ b/doc/appendices/faq.en.rst
@@ -225,6 +225,7 @@ Value             Meaning
 A     authorization failure
 C     connection to server failed
 D     dns failure
+L     loop detected
 F     request forbidden
 H     header syntax unacceptable
 N     no error
diff --git a/proxy/hdrs/HTTP.h b/proxy/hdrs/HTTP.h
index 68d48a4..41c91c9 100644
--- a/proxy/hdrs/HTTP.h
+++ b/proxy/hdrs/HTTP.h
@@ -142,7 +142,6 @@ enum SquidLogCode {
   SQUID_LOG_ERR_NO_CLIENTS_BIG_OBJ    = 'r',
   SQUID_LOG_ERR_READ_ERROR            = 's',
   SQUID_LOG_ERR_CLIENT_ABORT          = 't', // Client side abort logging
-  SQUID_LOG_ERR_CLIENT_READ_ERROR     = 'J', // Client side abort logging
   SQUID_LOG_ERR_CONNECT_FAIL          = 'u',
   SQUID_LOG_ERR_INVALID_REQ           = 'v',
   SQUID_LOG_ERR_UNSUP_REQ             = 'w',
@@ -157,6 +156,8 @@ enum SquidLogCode {
   SQUID_LOG_ERR_PROXY_DENIED          = 'G',
   SQUID_LOG_ERR_WEBFETCH_DETECTED     = 'H',
   SQUID_LOG_ERR_FUTURE_1              = 'I',
+  SQUID_LOG_ERR_CLIENT_READ_ERROR     = 'J', // Client side abort logging
+  SQUID_LOG_ERR_LOOP_DETECTED         = 'K', // Loop or cycle detected, request came back to this server
   SQUID_LOG_ERR_UNKNOWN               = 'Z'
 };
 
diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc
index 59de07b..dd32c24 100644
--- a/proxy/http/HttpTransact.cc
+++ b/proxy/http/HttpTransact.cc
@@ -6513,15 +6513,13 @@ HttpTransact::will_this_request_self_loop(State *s)
       if (host_port == local_port) {
         switch (s->dns_info.looking_up) {
         case ORIGIN_SERVER:
-          TxnDebug("http_transact", "[will_this_request_self_loop] host ip and port same as local ip and port - bailing");
+          TxnDebug("http_transact", "host ip and port same as local ip and port - bailing");
           break;
         case PARENT_PROXY:
-          TxnDebug("http_transact", "[will_this_request_self_loop] "
-                                    "parent proxy ip and port same as local ip and port - bailing");
+          TxnDebug("http_transact", "parent proxy ip and port same as local ip and port - bailing");
           break;
         default:
-          TxnDebug("http_transact", "[will_this_request_self_loop] "
-                                    "unknown's ip and port same as local ip and port - bailing");
+          TxnDebug("http_transact", "unknown's ip and port same as local ip and port - bailing");
           break;
         }
         build_error_response(s, HTTP_STATUS_BAD_REQUEST, "Cycle Detected", "request#cycle_detected");
@@ -6540,8 +6538,9 @@ HttpTransact::will_this_request_self_loop(State *s)
       const char *via_string = via_field->value_get(&via_len);
 
       if (via_string && ptr_len_str(via_string, via_len, uuid)) {
-        TxnDebug("http_transact", "[will_this_request_self_loop] Incoming via: %.*s has (%s[%s] (%s))", via_len, via_string,
-                 s->http_config_param->proxy_hostname, uuid, s->http_config_param->proxy_request_via_string);
+        SET_VIA_STRING(VIA_ERROR_TYPE, VIA_ERROR_LOOP_DETECTED);
+        TxnDebug("http_transact", "Incoming via: %.*s has (%s[%s] (%s))", via_len, via_string, s->http_config_param->proxy_hostname,
+                 uuid, s->http_config_param->proxy_request_via_string);
         build_error_response(s, HTTP_STATUS_BAD_REQUEST, "Multi-Hop Cycle Detected", "request#cycle_detected");
         return true;
       }
@@ -7900,7 +7899,10 @@ HttpTransact::build_error_response(State *s, HTTPStatus status_code, const char
   switch (status_code) {
   case HTTP_STATUS_BAD_REQUEST:
     SET_VIA_STRING(VIA_CLIENT_REQUEST, VIA_CLIENT_ERROR);
-    SET_VIA_STRING(VIA_ERROR_TYPE, VIA_ERROR_HEADER_SYNTAX);
+    // Did the via error already get set by the loop detection
+    if (s->via_string[VIA_ERROR_TYPE] != VIA_ERROR_LOOP_DETECTED) {
+      SET_VIA_STRING(VIA_ERROR_TYPE, VIA_ERROR_HEADER_SYNTAX);
+    }
     break;
   case HTTP_STATUS_BAD_GATEWAY:
     SET_VIA_STRING(VIA_ERROR_TYPE, VIA_ERROR_CONNECTION);
@@ -7940,9 +7942,9 @@ HttpTransact::build_error_response(State *s, HTTPStatus status_code, const char
   const char *reason_phrase = (reason_phrase_or_null ? reason_phrase_or_null : (char *)(http_hdr_reason_lookup(status_code)));
   if (unlikely(!reason_phrase)) {
     reason_phrase = "Unknown HTTP Status";
-
-    // set the source to internal so that chunking is handled correctly
   }
+
+  // set the source to internal so that chunking is handled correctly
   s->source = SOURCE_INTERNAL;
   build_response(s, &s->hdr_info.client_response, s->client_info.http_version, status_code, reason_phrase);
 
diff --git a/proxy/http/HttpTransact.h b/proxy/http/HttpTransact.h
index af40b15..afa5f5b 100644
--- a/proxy/http/HttpTransact.h
+++ b/proxy/http/HttpTransact.h
@@ -149,6 +149,7 @@ enum ViaString_t {
   VIA_ERROR_TIMEOUT           = 'T',
   VIA_ERROR_CACHE_READ        = 'R',
   VIA_ERROR_MOVED_TEMPORARILY = 'M',
+  VIA_ERROR_LOOP_DETECTED     = 'L',
   //
   // Now the detailed stuff
   //
@@ -164,7 +165,6 @@ enum ViaString_t {
   // cache type
   VIA_DETAIL_CACHE_DESCRIPTOR_STRING = 'c',
   VIA_DETAIL_CACHE                   = 'C',
-  VIA_DETAIL_CLUSTER                 = 'L',
   VIA_DETAIL_PARENT                  = 'P',
   VIA_DETAIL_SERVER                  = 'S',
   // result of cache lookup
diff --git a/proxy/http/HttpTransactHeaders.cc b/proxy/http/HttpTransactHeaders.cc
index 22a9da6..b6d62ef 100644
--- a/proxy/http/HttpTransactHeaders.cc
+++ b/proxy/http/HttpTransactHeaders.cc
@@ -631,12 +631,14 @@ HttpTransactHeaders::generate_and_set_squid_codes(HTTPHdr *header, char *via_str
     log_code  = SQUID_LOG_TCP_SWAPFAIL;
     hier_code = SQUID_HIER_NONE;
     break;
+  case VIA_ERROR_LOOP_DETECTED:
+    log_code  = SQUID_LOG_ERR_LOOP_DETECTED;
+    hier_code = SQUID_HIER_NONE;
+    break;
   default:
     break;
   }
 
-  Debug("http_trans", "[Squid code generation] Hit/Miss: %c, Log: %c, Hier: %c", hit_miss_code, log_code, hier_code);
-
   squid_codes->log_code      = log_code;
   squid_codes->hier_code     = hier_code;
   squid_codes->hit_miss_code = hit_miss_code;
diff --git a/proxy/logging/Log.cc b/proxy/logging/Log.cc
index 090b6a5..16e34e9 100644
--- a/proxy/logging/Log.cc
+++ b/proxy/logging/Log.cc
@@ -581,7 +581,7 @@ Log::init_fields()
 
   Ptr<LogFieldAliasTable> cache_code_map = make_ptr(new LogFieldAliasTable);
   cache_code_map->init(
-    51, SQUID_LOG_EMPTY, "UNDEFINED", SQUID_LOG_TCP_HIT, "TCP_HIT", SQUID_LOG_TCP_DISK_HIT, "TCP_DISK_HIT", SQUID_LOG_TCP_MEM_HIT,
+    52, SQUID_LOG_EMPTY, "UNDEFINED", SQUID_LOG_TCP_HIT, "TCP_HIT", SQUID_LOG_TCP_DISK_HIT, "TCP_DISK_HIT", SQUID_LOG_TCP_MEM_HIT,
     "TCP_MEM_HIT", SQUID_LOG_TCP_MISS, "TCP_MISS", SQUID_LOG_TCP_EXPIRED_MISS, "TCP_EXPIRED_MISS", SQUID_LOG_TCP_REFRESH_HIT,
     "TCP_REFRESH_HIT", SQUID_LOG_TCP_REF_FAIL_HIT, "TCP_REFRESH_FAIL_HIT", SQUID_LOG_TCP_REFRESH_MISS, "TCP_REFRESH_MISS",
     SQUID_LOG_TCP_CLIENT_REFRESH, "TCP_CLIENT_REFRESH_MISS", SQUID_LOG_TCP_IMS_HIT, "TCP_IMS_HIT", SQUID_LOG_TCP_IMS_MISS,
@@ -599,8 +599,8 @@ Log::init_fields()
     SQUID_LOG_ERR_DNS_FAIL, "ERR_DNS_FAIL", SQUID_LOG_ERR_NOT_IMPLEMENTED, "ERR_NOT_IMPLEMENTED", SQUID_LOG_ERR_CANNOT_FETCH,
     "ERR_CANNOT_FETCH", SQUID_LOG_ERR_NO_RELAY, "ERR_NO_RELAY", SQUID_LOG_ERR_DISK_IO, "ERR_DISK_IO",
     SQUID_LOG_ERR_ZERO_SIZE_OBJECT, "ERR_ZERO_SIZE_OBJECT", SQUID_LOG_ERR_PROXY_DENIED, "ERR_PROXY_DENIED",
-    SQUID_LOG_ERR_WEBFETCH_DETECTED, "ERR_WEBFETCH_DETECTED", SQUID_LOG_ERR_FUTURE_1, "ERR_FUTURE_1", SQUID_LOG_ERR_UNKNOWN,
-    "ERR_UNKNOWN");
+    SQUID_LOG_ERR_WEBFETCH_DETECTED, "ERR_WEBFETCH_DETECTED", SQUID_LOG_ERR_FUTURE_1, "ERR_FUTURE_1", SQUID_LOG_ERR_LOOP_DETECTED,
+    "ERR_LOOP_DETECTED", SQUID_LOG_ERR_UNKNOWN, "ERR_UNKNOWN");
 
   Ptr<LogFieldAliasTable> cache_subcode_map = make_ptr(new LogFieldAliasTable);
   cache_subcode_map->init(2, SQUID_SUBCODE_EMPTY, "NONE", SQUID_SUBCODE_NUM_REDIRECTIONS_EXCEEDED, "NUM_REDIRECTIONS_EXCEEDED");
diff --git a/src/traffic_via/traffic_via.cc b/src/traffic_via/traffic_via.cc
index cab5098..683d551 100644
--- a/src/traffic_via/traffic_via.cc
+++ b/src/traffic_via/traffic_via.cc
@@ -170,6 +170,7 @@ standardViaLookup(char flag)
     viaTable->viaData[(unsigned char)'F'] = "request forbidden";
     viaTable->viaData[(unsigned char)'R'] = "cache read error";
     viaTable->viaData[(unsigned char)'M'] = "moved temporarily";
+    viaTable->viaData[(unsigned char)'L'] = "looped detected";
     viaTable->viaData[(unsigned char)' '] = "unknown";
     break;
   default:
diff --git a/tools/traffic_via/traffic_via.pl b/tools/traffic_via/traffic_via.pl
index a135364..f34d52b 100755
--- a/tools/traffic_via/traffic_via.pl
+++ b/tools/traffic_via/traffic_via.pl
@@ -88,6 +88,7 @@ my @proxy_header_array = (
             'D' => "dns failure",
             'N' => "no error",
             'F' => "request forbidden",
+            'L' => "loop detected",
         },
     }, {
         "Tunnel info", {
@@ -144,8 +145,6 @@ sub usage()
     exit;
 }
 
-
-
 #Subroutine to decode via header
 sub decode_via_header($)
 {
@@ -222,7 +221,7 @@ sub valid_char ($$)
 sub validate_keys($)
 {
     my($viaHeader) = @_;
-    my($main, $detail) = split(';', $viaHeader);
+    my($main, $detail) = split(/[:;]/, $viaHeader);
     my $running_main = 1;
     my $return_value_valid = 1;
 
@@ -285,7 +284,7 @@ sub get_via_header_flags($$$)
 
         for my $element (@userinput) {
             #Pattern matching for Via
-            if ($element =~ /Via:\s+\[(.+)\]/i || $element =~ /\[(.+)\]/ ) {
+            if ($element =~ /Via:\s+\[([^\]]+)\]/i || $element =~ /\[([^\]]+)\]/ ) {
                 #Search and grep via header
                 my $via_string = $1;
                 chomp($via_string);
@@ -305,7 +304,7 @@ sub get_via_header_flags($$$)
         );
 
         if (defined $via_header) {
-            if ($via_header =~ /Via:\s+\[(.+)\]/i || $via_header =~ /\[(.+)\]/ || $via_header =~ /(.+)/) {
+            if ($via_header =~ /Via:\s+\[([^\]]+)\]/i || $via_header =~ /\[([^\]]+)\]/ || $via_header =~ /(.+)/) {
                 #if passed through commandline dashed argument
                 my $via_string = $1;
                 print "Via header is [$via_string], Length is ", length($via_string), "\n";
@@ -315,4 +314,4 @@ sub get_via_header_flags($$$)
         }
 
     }
-}
\ No newline at end of file
+}