You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2010/10/14 23:50:51 UTC

svn commit: r1022734 - in /trafficserver/traffic/trunk: iocore/utils/I_Machine.h iocore/utils/Machine.cc proxy/http2/HttpTransact.cc proxy/http2/HttpTransactHeaders.cc proxy/http2/HttpTransactHeaders.h

Author: zwoop
Date: Thu Oct 14 21:50:49 2010
New Revision: 1022734

URL: http://svn.apache.org/viewvc?rev=1022734&view=rev
Log:
TS-490 Loop detection in Via: headers

Although this wasn't quit the bug I thought it was, I decided
to cleanup the code here while I was looking at it. The problem
is that if our hostname resolves to 127.0.0.1, you can get into
loop detection, so the solution is to make sure your hostnames
don't resolve to 127.0.0.1 ...

Modified:
    trafficserver/traffic/trunk/iocore/utils/I_Machine.h
    trafficserver/traffic/trunk/iocore/utils/Machine.cc
    trafficserver/traffic/trunk/proxy/http2/HttpTransact.cc
    trafficserver/traffic/trunk/proxy/http2/HttpTransactHeaders.cc
    trafficserver/traffic/trunk/proxy/http2/HttpTransactHeaders.h

Modified: trafficserver/traffic/trunk/iocore/utils/I_Machine.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/utils/I_Machine.h?rev=1022734&r1=1022733&r2=1022734&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/utils/I_Machine.h (original)
+++ trafficserver/traffic/trunk/iocore/utils/I_Machine.h Thu Oct 14 21:50:49 2010
@@ -50,10 +50,12 @@ struct Machine
 
   unsigned int ip;              // IP address of the host (network order)
   char *ip_string;              // IP address of the host as a string.
+  int ip_string_len;
+  char *ip_hex_string;          // IP address of the host as a hex string
+  int ip_hex_string_len;
 
-    Machine(char *hostname = 0, unsigned int ip = 0);
-   ~Machine();
-
+  Machine(char *hostname = 0, unsigned int ip = 0);
+  ~Machine();
 };
 
 /**

Modified: trafficserver/traffic/trunk/iocore/utils/Machine.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/utils/Machine.cc?rev=1022734&r1=1022733&r2=1022734&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/utils/Machine.cc (original)
+++ trafficserver/traffic/trunk/iocore/utils/Machine.cc Thu Oct 14 21:50:49 2010
@@ -24,8 +24,28 @@
 #include "inktomi++.h"
 #include "I_Machine.h"
 
+// Singleton
 static Machine *machine = NULL;
 
+// Moved from HttpTransactHeaders.cc, we should probably move this somewhere ...
+#define H(_x) (((_x)>9)?((_x)-10+'A'):((_x)+'0'))
+int
+nstrhex(char *d, unsigned int i)
+{
+  unsigned char *p = (unsigned char *) &i;
+  d[0] = H(p[0] >> 4);
+  d[1] = H(p[0] & 0xF);
+  d[2] = H(p[1] >> 4);
+  d[3] = H(p[1] & 0xF);
+  d[4] = H(p[2] >> 4);
+  d[5] = H(p[2] & 0xF);
+  d[6] = H(p[3] >> 4);
+  d[7] = H(p[3] & 0xF);
+  return 8;
+}
+
+
+// Machine class. TODO: This has to deal with IPv6!
 Machine *
 this_machine()
 {
@@ -41,12 +61,12 @@ create_this_machine(char *hostname, unsi
   machine = NEW(new Machine(hostname, ip));
 }
 
-Machine::Machine(char *ahostname, unsigned int aip):
-hostname(ahostname),
-ip(aip)
+Machine::Machine(char *ahostname, unsigned int aip)
+  : hostname(ahostname), ip(aip)
 {
   if (!aip) {
     char localhost[1024];
+
     if (!ahostname) {
       ink_release_assert(!gethostname(localhost, 1023));
       ahostname = localhost;
@@ -55,49 +75,54 @@ ip(aip)
 
     ink_gethostbyname_r_data data;
     struct hostent *r = ink_gethostbyname_r(ahostname, &data);
+
     if (!r) {
       Warning("unable to DNS %s: %d", ahostname, data.herrno);
       ip = 0;
     } else {
-      // lowest IP address
-
       ip = (unsigned int) -1;   // 0xFFFFFFFF
-      for (int i = 0; r->h_addr_list[i]; i++)
+      for (int i = 0; r->h_addr_list[i]; i++) {
         if (ip > *(unsigned int *) r->h_addr_list[i])
           ip = *(unsigned int *) r->h_addr_list[i];
+      }
       if (ip == (unsigned int) -1)
         ip = 0;
     }
-    //ip = htonl(ip); for the alpha!
+    //ip = htonl(ip); for the alpha! TODO
   } else {
-
     ip = aip;
 
     ink_gethostbyaddr_r_data data;
-    struct hostent *r = ink_gethostbyaddr_r((char *) &ip, sizeof(int),
-                                            AF_INET, &data);
+    struct hostent *r = ink_gethostbyaddr_r((char *) &ip, sizeof(int), AF_INET, &data);
 
     if (r == NULL) {
       unsigned char x[4];
+
       memset(x, 0, sizeof(x));
       *(uint32 *) & x = (uint32) ip;
-      Debug("machine_debug", "unable to reverse DNS %u.%u.%u.%u: %d", x[0], x[1], x[2], x[3], data.herrno);
+      Debug("machine_debug", "unable to reverse DNS %hhu.%hhu.%hhu.%hhu: %d", x[0], x[1], x[2], x[3], data.herrno);
     } else
       hostname = xstrdup(r->h_name);
   }
+
   if (hostname)
     hostname_len = strlen(hostname);
   else
     hostname_len = 0;
 
-  {
-    unsigned char x[4];
-    memset(x, 0, sizeof(x));
-    *(uint32 *) & x = (uint32) ip;
-    const size_t ip_string_size = sizeof(char) * 16;
-    ip_string = (char *) xmalloc(ip_string_size);
-    snprintf(ip_string, ip_string_size, "%hhu.%hhu.%hhu.%hhu", x[0], x[1], x[2], x[3]);
-  }
+  unsigned char x[4];
+
+  memset(x, 0, sizeof(x));
+  *(uint32 *) & x = (uint32) ip;
+  const size_t ip_string_size = sizeof(char) * 16;
+  ip_string = (char *) xmalloc(ip_string_size);
+  snprintf(ip_string, ip_string_size, "%hhu.%hhu.%hhu.%hhu", x[0], x[1], x[2], x[3]);
+  ip_string_len = strlen(ip_string);
+
+  ip_hex_string = (char*)xmalloc(9);
+  memset(ip_hex_string, 0, 9);
+  nstrhex(ip_hex_string, ip);
+  ip_hex_string_len = strlen(ip_hex_string);
 }
 
 Machine::~Machine()
@@ -106,4 +131,6 @@ Machine::~Machine()
     xfree(hostname);
   if (ip_string)
     xfree(ip_string);
+  if (ip_hex_string)
+    xfree(ip_hex_string);
 }

Modified: trafficserver/traffic/trunk/proxy/http2/HttpTransact.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http2/HttpTransact.cc?rev=1022734&r1=1022733&r2=1022734&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http2/HttpTransact.cc (original)
+++ trafficserver/traffic/trunk/proxy/http2/HttpTransact.cc Thu Oct 14 21:50:49 2010
@@ -282,12 +282,10 @@ is_negative_caching_appropriate(HttpTran
   return false;
 }
 
-inline static
-  HttpTransact::LookingUp_t
+inline static HttpTransact::LookingUp_t
 find_server_and_update_current_info(HttpTransact::State * s)
 {
   URL *url = s->hdr_info.client_request.url_get();
-
   int host_len;
   const char *host = s->hdr_info.client_request.host_get(&host_len);
 
@@ -5441,12 +5439,9 @@ HttpTransact::RequestError_t HttpTransac
     return FAILED_PROXY_AUTHORIZATION;
   }
 
-  URL *
-    incoming_url = incoming_hdr->url_get();
-  int
-    hostname_len;
-  const char *
-    hostname = incoming_hdr->host_get(&hostname_len);
+  URL *incoming_url = incoming_hdr->url_get();
+  int hostname_len;
+  const char *hostname = incoming_hdr->host_get(&hostname_len);
 
   if (hostname == NULL) {
     return MISSING_HOST_FIELD;
@@ -5456,10 +5451,8 @@ HttpTransact::RequestError_t HttpTransac
     return BAD_HTTP_HEADER_SYNTAX;
   }
 
-  int
-    scheme = incoming_url->scheme_get_wksidx();
-  int
-    method = incoming_hdr->method_get_wksidx();
+  int scheme = incoming_url->scheme_get_wksidx();
+  int method = incoming_hdr->method_get_wksidx();
 
   if (!((scheme == URL_WKSIDX_HTTP) && (method == HTTP_WKSIDX_GET))) {
 
@@ -5483,23 +5476,17 @@ HttpTransact::RequestError_t HttpTransac
     if ((scheme == URL_WKSIDX_HTTP || scheme == URL_WKSIDX_HTTPS) &&
         (method == HTTP_WKSIDX_POST || method == HTTP_WKSIDX_PUSH || method == HTTP_WKSIDX_PUT)) {
       if (scheme == URL_WKSIDX_HTTP && !incoming_hdr->presence(MIME_PRESENCE_CONTENT_LENGTH)) {
-        bool
-          chunked_encoding = false;
+        bool chunked_encoding = false;
+
         if (incoming_hdr->presence(MIME_PRESENCE_TRANSFER_ENCODING)) {
-          MIMEField *
-            field = incoming_hdr->field_find(MIME_FIELD_TRANSFER_ENCODING,
-                                             MIME_LEN_TRANSFER_ENCODING);
-
-          HdrCsvIter
-            enc_val_iter;
-          int
-            enc_val_len;
-          const char *
-            enc_value = enc_val_iter.get_first(field, &enc_val_len);
+          MIMEField *field = incoming_hdr->field_find(MIME_FIELD_TRANSFER_ENCODING, MIME_LEN_TRANSFER_ENCODING);
+          HdrCsvIter enc_val_iter;
+          int enc_val_len;
+          const char *enc_value = enc_val_iter.get_first(field, &enc_val_len);
 
           while (enc_value) {
-            const char *
-              wks_value = hdrtoken_string_to_wks(enc_value, enc_val_len);
+            const char *wks_value = hdrtoken_string_to_wks(enc_value, enc_val_len);
+
             if (wks_value == HTTP_VALUE_CHUNKED) {
               chunked_encoding = true;
               break;
@@ -5526,19 +5513,14 @@ HttpTransact::RequestError_t HttpTransac
   // Transfer Encoding.
 
   if (incoming_hdr->presence(MIME_PRESENCE_TE)) {
-    MIMEField *
-      te_field = incoming_hdr->field_find(MIME_FIELD_TE, MIME_LEN_TE);
-    HTTPValTE *
-      te_val;
+    MIMEField *te_field = incoming_hdr->field_find(MIME_FIELD_TE, MIME_LEN_TE);
+    HTTPValTE *te_val;
 
     if (te_field) {
-      HdrCsvIter
-        csv_iter;
+      HdrCsvIter csv_iter;
+      int te_raw_len;
+      const char *te_raw = csv_iter.get_first(te_field, &te_raw_len);
 
-      int
-        te_raw_len;
-      const char *
-        te_raw = csv_iter.get_first(te_field, &te_raw_len);
       while (te_raw) {
         te_val = http_parse_te(te_raw, te_raw_len, &s->arena);
         if (te_val->encoding == HTTP_VALUE_IDENTITY) {
@@ -6890,10 +6872,8 @@ HttpTransact::process_quick_http_filter(
 
 HttpTransact::HostNameExpansionError_t HttpTransact::try_to_expand_host_name(State * s)
 {
-  static int
-    max_dns_lookups = 2 + s->http_config_param->num_url_expansions;
-  static int
-    last_expansion = max_dns_lookups - 2;
+  static int max_dns_lookups = 2 + s->http_config_param->num_url_expansions;
+  static int last_expansion = max_dns_lookups - 2;
 
   HTTP_RELEASE_ASSERT(!s->dns_info.lookup_success);
 
@@ -6903,16 +6883,15 @@ HttpTransact::HostNameExpansionError_t H
     // we try to expand hostname.                    //
     ///////////////////////////////////////////////////
     if (s->http_config_param->enable_url_expandomatic) {
-      int
-        attempts = s->dns_info.attempts;
+      int attempts = s->dns_info.attempts;
       HTTP_DEBUG_ASSERT(attempts >= 1 && attempts <= max_dns_lookups);
+
       if (attempts < max_dns_lookups) {
         // Try a URL expansion
         if (attempts <= last_expansion) {
-          char *
-            expansion = s->http_config_param->url_expansions[attempts - 1];
-          int
-            length = strlen(s->server_info.name) + strlen(expansion) + 1;
+          char *expansion = s->http_config_param->url_expansions[attempts - 1];
+          int length = strlen(s->server_info.name) + strlen(expansion) + 1;
+
           s->dns_info.lookup_name = s->arena.str_alloc(length);
           ink_string_concatenate_strings_n(s->dns_info.lookup_name,
                                            length + 1, s->server_info.name, ".", expansion, NULL);
@@ -6922,11 +6901,10 @@ HttpTransact::HostNameExpansionError_t H
             return (EXPANSION_FAILED);
           }
           // Try www.<server_name>.com
-          int
-            length = strlen(s->server_info.name) + 8;
+          int length = strlen(s->server_info.name) + 8;
+
           s->dns_info.lookup_name = s->arena.str_alloc(length);
-          ink_string_concatenate_strings_n(s->dns_info.lookup_name,
-                                           length + 1, "www.", s->server_info.name, ".com", NULL);
+          ink_string_concatenate_strings_n(s->dns_info.lookup_name, length + 1, "www.", s->server_info.name, ".com", NULL);
         }
         return (RETRY_EXPANDED_NAME);
       } else {
@@ -6985,35 +6963,23 @@ HttpTransact::will_this_request_self_loo
         return TRUE;
       }
     }
-    // Now check for a loop using the Via string.
 
+    // 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.
-    //
-    MIMEField *via_field;
-    via_field = s->hdr_info.client_request.field_find(MIME_FIELD_VIA, MIME_LEN_VIA);
-    if (via_field) {
-      // look for hex-based ip_string in Via string (which we would have inserted)
-      char proxy_ip_string[9];
-
-      int bits = nstrhex(proxy_ip_string, this_machine()->ip);
-      proxy_ip_string[bits] = '\0';
+    if (local_ip > 0) {
+      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
+        // 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, proxy_ip_string)) {
 
-          Debug("http_transact", "[will_this_request_self_loop] "
-                "Incoming via: %.*s has (%s[%s] (%s))",
-                via_len, via_string,
-                s->http_config_param->proxy_hostname, proxy_ip_string, s->http_config_param->proxy_request_via_string);
-          build_error_response(s, HTTP_STATUS_BAD_REQUEST,
-                               "Multi-Hop Cycle Detected",
+        if (via_string && ptr_len_str(via_string, via_len, this_machine()->ip_hex_string)) {
+          Debug("http_transact", "[will_this_request_self_loop] Incoming via: %.*s has (%s[%s] (%s))", via_len, via_string,
+                s->http_config_param->proxy_hostname, this_machine()->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", "Your request is prohibited because it would cause a cycle.");
           return TRUE;
         }
@@ -7480,21 +7446,10 @@ HttpTransact::does_client_request_permit
 
 
 int
-HttpTransact::calculate_document_freshness_limit(Arena * arena,
-                                                 HTTPHdr * response,
-                                                 time_t response_date,
-                                                 bool * heuristic,
-                                                 time_t
-                                                 request_sent_time,
-                                                 int
-                                                 cache_heuristic_min_lifetime,
-                                                 int
-                                                 cache_heuristic_max_lifetime,
-                                                 double
-                                                 cache_heuristic_lm_factor,
-                                                 int
-                                                 cache_guaranteed_min_lifetime,
-                                                 int cache_guaranteed_max_lifetime,
+HttpTransact::calculate_document_freshness_limit(Arena * arena, HTTPHdr * response, time_t response_date, bool * heuristic,
+                                                 time_t request_sent_time, int cache_heuristic_min_lifetime,
+                                                 int cache_heuristic_max_lifetime, double cache_heuristic_lm_factor,
+                                                 int cache_guaranteed_min_lifetime, int cache_guaranteed_max_lifetime,
                                                  time_t plugin_set_expire_time, State * s)
 {
   NOWARN_UNUSED(arena);
@@ -7690,8 +7645,8 @@ HttpTransact::what_is_document_freshness
   if (s->cache_control.ttl_in_cache > 0) {
     // what matters if ttl is set is not the age of the document
     // but for how long it has been stored in the cache (resident time)
-    int
-      resident_time = s->current.now - s->response_received_time;
+    int resident_time = s->current.now - s->response_received_time;
+
     Debug("http_match",
           "[..._document_freshness] ttl-in-cache = %d, resident time = %d",
           s->cache_control.ttl_in_cache, resident_time);
@@ -8133,10 +8088,9 @@ HttpTransact::build_request(State * s, H
     s->next_hop_scheme = URL_WKSIDX_HTTP;
   if (s->orig_scheme < 0)
     s->orig_scheme = URL_WKSIDX_HTTP;
-  HttpTransactHeaders::insert_via_header_in_request(s->http_config_param,
-                                                    s->orig_scheme,
-                                                    &s->cache_info,
-                                                    outgoing_request, s->via_string, this_machine()->ip);
+
+  HttpTransactHeaders::insert_via_header_in_request(s->http_config_param, s->orig_scheme, &s->cache_info,
+                                                    outgoing_request, s->via_string);
 
   // We build 1.1 request header and then convert as necessary to
   //  the appropriate version in HttpTransact::build_request
@@ -8151,8 +8105,6 @@ HttpTransact::build_request(State * s, H
   // Check whether a Host header field is missing from a 1.0 or 1.1 request.
   if (outgoing_version != HTTPVersion(0, 9) && !outgoing_request->presence(MIME_PRESENCE_HOST)) {
     URL *url = outgoing_request->url_get();
-
-
     int host_len;
     const char *host = url->host_get(&host_len);
 
@@ -9066,21 +9018,13 @@ HttpTransact::update_aol_stats(State * s
 
 
 void
-HttpTransact::update_size_and_time_stats(State * s,
-                                         ink_hrtime total_time,
-                                         ink_hrtime user_agent_write_time,
-                                         ink_hrtime origin_server_read_time,
-                                         ink_hrtime cache_lookup_time,
-                                         int user_agent_request_header_size,
-                                         int64 user_agent_request_body_size,
-                                         int user_agent_response_header_size,
-                                         int64 user_agent_response_body_size,
-                                         int origin_server_request_header_size,
-                                         int64 origin_server_request_body_size,
-                                         int origin_server_response_header_size,
-                                         int64 origin_server_response_body_size,
-                                         int pushed_response_header_size,
-                                         int64 pushed_response_body_size, CacheAction_t cache_action)
+HttpTransact::update_size_and_time_stats(State * s, ink_hrtime total_time, ink_hrtime user_agent_write_time,
+                                         ink_hrtime origin_server_read_time, ink_hrtime cache_lookup_time,
+                                         int user_agent_request_header_size, int64 user_agent_request_body_size,
+                                         int user_agent_response_header_size, int64 user_agent_response_body_size,
+                                         int origin_server_request_header_size, int64 origin_server_request_body_size,
+                                         int origin_server_response_header_size, int64 origin_server_response_body_size,
+                                         int pushed_response_header_size, int64 pushed_response_body_size, CacheAction_t cache_action)
 {
   NOWARN_UNUSED(cache_action);
   int64 user_agent_request_size = user_agent_request_header_size + user_agent_request_body_size;
@@ -9261,8 +9205,6 @@ HttpTransact::add_new_stat_block(State *
 void
 HttpTransact::delete_warning_value(HTTPHdr * to_warn, HTTPWarningCode warning_code)
 {
-
-
   int w_code = (int) warning_code;
   MIMEField *field = to_warn->field_find(MIME_FIELD_WARNING, MIME_LEN_WARNING);;
 

Modified: trafficserver/traffic/trunk/proxy/http2/HttpTransactHeaders.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http2/HttpTransactHeaders.cc?rev=1022734&r1=1022733&r2=1022734&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http2/HttpTransactHeaders.cc (original)
+++ trafficserver/traffic/trunk/proxy/http2/HttpTransactHeaders.cc Thu Oct 14 21:50:49 2010
@@ -29,23 +29,7 @@
 #include "HttpCompat.h"
 #include "HttpMessageBody.h"
 
-
-#define H(_x) (((_x)>9)?((_x)-10+'A'):((_x)+'0'))
-int
-nstrhex(char *d, unsigned int i)
-{
-  unsigned char *p = (unsigned char *) &i;
-  d[0] = H(p[0] >> 4);
-  d[1] = H(p[0] & 0xF);
-  d[2] = H(p[1] >> 4);
-  d[3] = H(p[1] & 0xF);
-  d[4] = H(p[2] >> 4);
-  d[5] = H(p[2] & 0xF);
-  d[6] = H(p[3] >> 4);
-  d[7] = H(p[3] & 0xF);
-  return 8;
-}
-
+#include "I_Machine.h"
 
 bool
 HttpTransactHeaders::is_method_cacheable(int method)
@@ -1120,66 +1104,66 @@ HttpTransactHeaders::insert_server_heade
 //
 ///////////////////////////////////////////////////////////////////////////////
 void
-HttpTransactHeaders::insert_via_header_in_request(HttpConfigParams * http_config_param,
-                                                  int scheme,
+HttpTransactHeaders::insert_via_header_in_request(HttpConfigParams * http_config_param, int scheme,
                                                   HttpTransact::CacheLookupInfo * cache_info,
-                                                  HTTPHdr * header, char *incoming_via, int proxy_ip_address)
+                                                  HTTPHdr * header, char *incoming_via)
 {
   NOWARN_UNUSED(cache_info);
-  char new_via_string[8192];
-  char *via_string = new_via_string;
-
-  if (!http_config_param->insert_request_via_string)
-    return;
 
-  if ((http_config_param->proxy_hostname_len + http_config_param->proxy_response_via_string_len) > 200) {
-    header->value_append(MIME_FIELD_VIA, MIME_LEN_VIA, "TrafficServer", 18, true);
-    return;
-  }
-
-  ink_assert(scheme >= 0);
-  int scheme_len = hdrtoken_index_to_length(scheme);
-  int32 hversion = header->version_get().m_version;
-
-  memcpy(via_string, hdrtoken_index_to_wks(scheme), scheme_len);
-  via_string += scheme_len;
-
-  // Common case (I hope?)
-  if ((HTTP_MAJOR(hversion) == 1) && HTTP_MINOR(hversion) == 1) {
-    memcpy(via_string, "/1.1 ", 5);
-    via_string += 5;
-  } else {
-    *via_string++ = '/';
-    *via_string++ = '0' + HTTP_MAJOR(hversion);
-    *via_string++ = '.';
-    *via_string++ = '0' + HTTP_MINOR(hversion);
+  if (http_config_param->insert_request_via_string) {
+    char new_via_string[8192];
+    char *via_string = new_via_string;
+
+    if ((http_config_param->proxy_hostname_len + http_config_param->proxy_response_via_string_len) > 200) {
+      header->value_append(MIME_FIELD_VIA, MIME_LEN_VIA, "TrafficServer", 18, true);
+      return;
+    }
+
+    ink_assert(scheme >= 0);
+    int scheme_len = hdrtoken_index_to_length(scheme);
+    int32 hversion = header->version_get().m_version;
+
+    memcpy(via_string, hdrtoken_index_to_wks(scheme), scheme_len);
+    via_string += scheme_len;
+
+    // Common case (I hope?)
+    if ((HTTP_MAJOR(hversion) == 1) && HTTP_MINOR(hversion) == 1) {
+      memcpy(via_string, "/1.1 ", 5);
+      via_string += 5;
+    } else {
+      *via_string++ = '/';
+      *via_string++ = '0' + HTTP_MAJOR(hversion);
+      *via_string++ = '.';
+      *via_string++ = '0' + HTTP_MINOR(hversion);
+      *via_string++ = ' ';
+    }
+    via_string += nstrcpy(via_string, http_config_param->proxy_hostname);
+    *via_string++ = '[';
+    memcpy(via_string, this_machine()->ip_hex_string, this_machine()->ip_hex_string_len);
+    via_string += this_machine()->ip_hex_string_len;
+    *via_string++ = ']';
     *via_string++ = ' ';
-  }
-  via_string += nstrcpy(via_string, http_config_param->proxy_hostname);
-  *via_string++ = '[';
-  via_string += nstrhex(via_string, proxy_ip_address);
-  *via_string++ = ']';
-  *via_string++ = ' ';
-  *via_string++ = '(';
-  via_string += nstrcpy(via_string, http_config_param->proxy_request_via_string);
+    *via_string++ = '(';
+    via_string += nstrcpy(via_string, http_config_param->proxy_request_via_string);
 
-  if (http_config_param->verbose_via_string != 0) {
-    *via_string++ = ' ';
-    *via_string++ = '[';
+    if (http_config_param->verbose_via_string != 0) {
+      *via_string++ = ' ';
+      *via_string++ = '[';
 
-    if (http_config_param->verbose_via_string == 1) {
-      via_string += nstrcpy(via_string, incoming_via);
-    } else {
-      memcpy(via_string, incoming_via + VIA_CLIENT, VIA_SERVER - VIA_CLIENT);
-      via_string += VIA_SERVER - VIA_CLIENT;
+      if (http_config_param->verbose_via_string == 1) {
+        via_string += nstrcpy(via_string, incoming_via);
+      } else {
+        memcpy(via_string, incoming_via + VIA_CLIENT, VIA_SERVER - VIA_CLIENT);
+        via_string += VIA_SERVER - VIA_CLIENT;
+      }
+      *via_string++ = ']';
     }
-    *via_string++ = ']';
-  }
 
-  *via_string++ = ')';
-  *via_string = 0;
+    *via_string++ = ')';
+    *via_string = 0;
 
-  header->value_append(MIME_FIELD_VIA, MIME_LEN_VIA, new_via_string, via_string - new_via_string, true);
+    header->value_append(MIME_FIELD_VIA, MIME_LEN_VIA, new_via_string, via_string - new_via_string, true);
+  }
 }
 
 
@@ -1190,57 +1174,57 @@ HttpTransactHeaders::insert_via_header_i
                                                    HTTPHdr * header, char *incoming_via)
 {
   NOWARN_UNUSED(cache_info);
-  char new_via_string[8192];
-  char *via_string = new_via_string;
-
-  if (!http_config_param->insert_response_via_string)
-    return;
-
-  if ((http_config_param->proxy_hostname_len + http_config_param->proxy_response_via_string_len) > 200) {
-    header->value_append(MIME_FIELD_VIA, MIME_LEN_VIA, "TrafficServer", 18, true);
-    return;
-  }
-
-  ink_assert(scheme >= 0);
-  int scheme_len = hdrtoken_index_to_length(scheme);
-  int32 hversion = header->version_get().m_version;
-
-  memcpy(via_string, hdrtoken_index_to_wks(scheme), scheme_len);
-  via_string += scheme_len;
-
-  // Common case (I hope?)
-  if ((HTTP_MAJOR(hversion) == 1) && HTTP_MINOR(hversion) == 1) {
-    memcpy(via_string, "/1.1 ", 5);
-    via_string += 5;
-  } else {
-    *via_string++ = '/';
-    *via_string++ = '0' + HTTP_MAJOR(hversion);
-    *via_string++ = '.';
-    *via_string++ = '0' + HTTP_MINOR(hversion);
-    *via_string++ = ' ';
-  }
-  via_string += nstrcpy(via_string, http_config_param->proxy_hostname);
-  *via_string++ = ' ';
-  *via_string++ = '(';
-  memcpy(via_string, http_config_param->proxy_response_via_string, http_config_param->proxy_response_via_string_len);
-  via_string += http_config_param->proxy_response_via_string_len;
 
-  if (http_config_param->verbose_via_string != 0) {
+  if (http_config_param->insert_response_via_string) {
+    char new_via_string[8192];
+    char *via_string = new_via_string;
+
+    if ((http_config_param->proxy_hostname_len + http_config_param->proxy_response_via_string_len) > 200) {
+      header->value_append(MIME_FIELD_VIA, MIME_LEN_VIA, "TrafficServer", 18, true);
+      return;
+    }
+
+    ink_assert(scheme >= 0);
+    int scheme_len = hdrtoken_index_to_length(scheme);
+    int32 hversion = header->version_get().m_version;
+
+    memcpy(via_string, hdrtoken_index_to_wks(scheme), scheme_len);
+    via_string += scheme_len;
+
+    // Common case (I hope?)
+    if ((HTTP_MAJOR(hversion) == 1) && HTTP_MINOR(hversion) == 1) {
+      memcpy(via_string, "/1.1 ", 5);
+      via_string += 5;
+    } else {
+      *via_string++ = '/';
+      *via_string++ = '0' + HTTP_MAJOR(hversion);
+      *via_string++ = '.';
+      *via_string++ = '0' + HTTP_MINOR(hversion);
+      *via_string++ = ' ';
+    }
+    via_string += nstrcpy(via_string, http_config_param->proxy_hostname);
     *via_string++ = ' ';
-    *via_string++ = '[';
+    *via_string++ = '(';
+    memcpy(via_string, http_config_param->proxy_response_via_string, http_config_param->proxy_response_via_string_len);
+    via_string += http_config_param->proxy_response_via_string_len;
+
+    if (http_config_param->verbose_via_string != 0) {
+      *via_string++ = ' ';
+      *via_string++ = '[';
 
-    if (http_config_param->verbose_via_string == 1) {
-      via_string += nstrcpy(via_string, incoming_via);
-    } else {
-      memcpy(via_string, incoming_via + VIA_CACHE, VIA_PROXY - VIA_CACHE);
-      via_string += VIA_PROXY - VIA_CACHE;
+      if (http_config_param->verbose_via_string == 1) {
+        via_string += nstrcpy(via_string, incoming_via);
+      } else {
+        memcpy(via_string, incoming_via + VIA_CACHE, VIA_PROXY - VIA_CACHE);
+        via_string += VIA_PROXY - VIA_CACHE;
+      }
+      *via_string++ = ']';
     }
-    *via_string++ = ']';
-  }
-  *via_string++ = ')';
-  *via_string = 0;
+    *via_string++ = ')';
+    *via_string = 0;
 
-  header->value_append(MIME_FIELD_VIA, MIME_LEN_VIA, new_via_string, via_string - new_via_string, true);
+    header->value_append(MIME_FIELD_VIA, MIME_LEN_VIA, new_via_string, via_string - new_via_string, true);
+  }
 }
 
 

Modified: trafficserver/traffic/trunk/proxy/http2/HttpTransactHeaders.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http2/HttpTransactHeaders.h?rev=1022734&r1=1022733&r2=1022734&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http2/HttpTransactHeaders.h (original)
+++ trafficserver/traffic/trunk/proxy/http2/HttpTransactHeaders.h Thu Oct 14 21:50:49 2010
@@ -89,7 +89,7 @@ public:
   static void insert_server_header_in_response(const char *server_tag, int server_tag_size, HTTPHdr * header);
   static void insert_via_header_in_request(HttpConfigParams * http_config_param, int scheme,
                                            HttpTransact::CacheLookupInfo * cache_info, HTTPHdr * header,
-                                           char *incoming_via, int proxy_ip_address);
+                                           char *incoming_via);
   static void insert_via_header_in_response(HttpConfigParams * http_config_param, int scheme,
                                             HttpTransact::CacheLookupInfo * cache_info,
                                             HTTPHdr * header, char *incoming_via);