From 2c58e398bdcf154b77ef53878c2310f1225042f5 Mon Sep 17 00:00:00 2001 From: Pavlo Yatsukhnenko Date: Sun, 17 Jul 2016 13:15:32 +0300 Subject: [PATCH] TS-4624: use the server UUID in the Via header --- proxy/http/HttpTransact.cc | 36 ++++++++++++++----------------- proxy/http/HttpTransactHeaders.cc | 8 ++----- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc index a83bc34d2fa..c67055bbd09 100644 --- a/proxy/http/HttpTransact.cc +++ b/proxy/http/HttpTransact.cc @@ -6745,27 +6745,23 @@ HttpTransact::will_this_request_self_loop(State *s) } // Now check for a loop using the Via string. - // Since we insert our ip_address (in hex) into outgoing Via strings, - // look for our_ip address in the request's via string. - if (ats_is_ip(&Machine::instance()->ip)) { - MIMEField *via_field = s->hdr_info.client_request.field_find(MIME_FIELD_VIA, MIME_LEN_VIA); - - while (via_field) { - // No need to waste cycles comma separating the via values since we want to do a match anywhere in the - // in the string. We can just loop over the dup hdr fields - int via_len; - const char *via_string = via_field->value_get(&via_len); - - if (via_string && ptr_len_str(via_string, via_len, Machine::instance()->ip_hex_string)) { - DebugTxn("http_transact", "[will_this_request_self_loop] Incoming via: %.*s has (%s[%s] (%s))", via_len, via_string, - s->http_config_param->proxy_hostname, Machine::instance()->ip_hex_string, - s->http_config_param->proxy_request_via_string); - build_error_response(s, HTTP_STATUS_BAD_REQUEST, "Multi-Hop Cycle Detected", "request#cycle_detected", NULL); - return true; - } - - via_field = via_field->m_next_dup; + const char *uuid = Machine::instance()->uuid.getString(); + MIMEField *via_field = s->hdr_info.client_request.field_find(MIME_FIELD_VIA, MIME_LEN_VIA); + + while (via_field) { + // No need to waste cycles comma separating the via values since we want to do a match anywhere in the + // in the string. We can just loop over the dup hdr fields + int via_len; + const char *via_string = via_field->value_get(&via_len); + + if (via_string && ptr_len_str(via_string, via_len, uuid)) { + DebugTxn("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); + build_error_response(s, HTTP_STATUS_BAD_REQUEST, "Multi-Hop Cycle Detected", "request#cycle_detected", NULL); + return true; } + + via_field = via_field->m_next_dup; } } s->request_will_not_selfloop = true; diff --git a/proxy/http/HttpTransactHeaders.cc b/proxy/http/HttpTransactHeaders.cc index a06e833cc57..db66b4d87bd 100644 --- a/proxy/http/HttpTransactHeaders.cc +++ b/proxy/http/HttpTransactHeaders.cc @@ -750,12 +750,8 @@ HttpTransactHeaders::insert_via_header_in_request(HttpTransact::State *s, HTTPHd via_string += nstrcpy(via_string, s->http_config_param->proxy_hostname); *via_string++ = '['; - /* I thought we should use the transaction local outgoing IP address but - that makes cycle detection (which is the point) unrealiable. We must - use the same value every time to be sure. - */ - memcpy(via_string, Machine::instance()->ip_hex_string, Machine::instance()->ip_hex_string_len); - via_string += Machine::instance()->ip_hex_string_len; + memcpy(via_string, Machine::instance()->uuid.getString(), TS_UUID_STRING_LEN); + via_string += TS_UUID_STRING_LEN; *via_string++ = ']'; *via_string++ = ' '; *via_string++ = '(';