trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iga...@apache.org
Subject [1/4] git commit: Backport TS-876: forward map based on request receive port Author: Brian Geffon (removing him from recent CHANGES since he became a committer. We are borg, you will be assimilated ; ) Review/Test: briang, zwoop, manjesh Backport: igalic
Date Sat, 11 Feb 2012 00:55:23 GMT
Updated Branches:
  refs/heads/3.0.x 40e3969c6 -> cefaa4071


Backport TS-876:
forward map based on request receive port
Author: Brian Geffon (removing him from recent CHANGES since he
became a committer. We are borg, you will be assimilated ;)
Review/Test: briang, zwoop, manjesh
Backport: igalic


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/cefaa407
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/cefaa407
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/cefaa407

Branch: refs/heads/3.0.x
Commit: cefaa40711986d24f3a2b7030d046b22b61f2ece
Parents: d0bf192
Author: Igor Galić <igalic@apache.org>
Authored: Sat Feb 11 01:52:26 2012 +0100
Committer: Igor Galić <igalic@apache.org>
Committed: Sat Feb 11 01:52:26 2012 +0100

----------------------------------------------------------------------
 CHANGES                            |    4 +-
 STATUS                             |    5 --
 proxy/config/remap.config.default  |   17 ++++--
 proxy/http/remap/RemapProcessor.cc |   26 ++++++++-
 proxy/http/remap/UrlRewrite.cc     |   95 ++++++++++++++++++++-----------
 proxy/http/remap/UrlRewrite.h      |   13 ++++-
 6 files changed, 111 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/cefaa407/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index c94bf4f..907b918 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,8 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache Traffic Server 3.0.3
 
+  *) [TS-876] forward map based on request receive port
+
   *) [TS-1004] Transformation plugins cause connection close when content
    length is not known ahead. Author: Otto van der Schaaf.
 
@@ -8,7 +10,7 @@ Changes with Apache Traffic Server 3.0.3
     Author: Yakov Kopel
 
   *) [TS-1074] PluginVC should schedule to the local queue instead of the
-  external queue. Author: Brian Geffon
+  external queue.
 
   *) [TS-1066] TSHttpTxnServerReqHdrBytesGet in InkAPI.cc has an extra
    parameter (int *bytes) from the prototype in <ts/ts.h>.

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/cefaa407/STATUS
----------------------------------------------------------------------
diff --git a/STATUS b/STATUS
index 68702ff..8be972e 100644
--- a/STATUS
+++ b/STATUS
@@ -40,11 +40,6 @@ A list of all bugs open for the next v3.0.2 release can be found at
 
 PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
 
-  *) forward map based on request receive port
-   Trunk patch: (see TS876.fixed.patch in JIRA)
-   Jira: https://issues.apache.org/jira/browse/TS-876
-   +1: briang, zwoop, manjesh
-
 
 PATCHES PROPOSED TO BACKPORT FROM TRUNK:
   [ New proposals should be added at the end of the list ]

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/cefaa407/proxy/config/remap.config.default
----------------------------------------------------------------------
diff --git a/proxy/config/remap.config.default b/proxy/config/remap.config.default
index 7341e00..ee8d785 100644
--- a/proxy/config/remap.config.default
+++ b/proxy/config/remap.config.default
@@ -7,11 +7,11 @@
 #  this last <tag_value> directive is optional and can be different for different types
of <map_type>
 #  <filtering arguments> are optional ACL-like argumens unique for each remap rule
 #
-#  Five different types of mappings are possible -- 'map', 'map_with_referer',
-#  'reverse_map', 'redirect', and 'redirect_temporary'. Each of these map types
-#  can be prefixed with the string 'regex_' to indicate that the rule will have
-#  regular expression strings. See the last part of this description for more 
-#  information on regex support.
+#  Six different types of mappings are possible -- 'map', 'map_with_referer',
+#  'map_with_recv_port', 'reverse_map', 'redirect', and 'redirect_temporary'.
+#  Each of these map types can be prefixed with the string 'regex_' to indicate
+#  that the rule will have regular expression strings. See the last part of
+#  this description for more information on regex support.
 #
 #  The 'map' mapping is the most straightforward.  Requests that match the
 #  from URL are changed into the to URL.  The user agent will see the new
@@ -19,6 +19,13 @@
 #  The 'map_with_referer' is an extended version of 'map', which can be used
 #  to activate the so-called "deep linking protection" feature avaialble in
 #  Traffic Server.
+#
+#  The 'map_with_recv_port' is exactly like 'map' except that it uses the 
+#  port at which the request was received to perform the mapping instead of
+#  the port present in the request. When present, 'map_with_recv_port' 
+#  mappings are checked first. If there is a match, then it is chosen without
+#  evaluating the "regular" forward mapping rules.
+#
 #  The 'reverse_map' mapping is used to rewrite location headers sent by
 #  the origin server.  The 'redirect' mapping creates a permanent redirect
 #  message and informs the browser of the URL change.

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/cefaa407/proxy/http/remap/RemapProcessor.cc
----------------------------------------------------------------------
diff --git a/proxy/http/remap/RemapProcessor.cc b/proxy/http/remap/RemapProcessor.cc
index 8984246..f7d184d 100644
--- a/proxy/http/remap/RemapProcessor.cc
+++ b/proxy/http/remap/RemapProcessor.cc
@@ -61,10 +61,14 @@ RemapProcessor::setup_for_remap(HttpTransact::State *s)
 
   ink_assert(redirect_url != NULL);
 
-  if (unlikely(rewrite_table->num_rules_forward == 0)) {
-    ink_assert(rewrite_table->forward_mappings.empty());
+  if (unlikely((rewrite_table->num_rules_forward == 0) &&
+               (rewrite_table->num_rules_forward_with_recv_port == 0))) {
+    ink_assert(rewrite_table->forward_mappings.empty() &&
+               rewrite_table->forward_mappings_with_recv_port.empty());
+    Debug("url_rewrite", "[lookup] No forward mappings found; Skipping...");
     return false;
   }
+
   // Since we are called before request validity checking
   // occurs, make sure that we have both a valid request
   // header and a valid URL
@@ -85,7 +89,23 @@ RemapProcessor::setup_for_remap(HttpTransact::State *s)
 
   Debug("url_rewrite", "[lookup] attempting %s lookup", proxy_request ? "proxy" : "normal");
 
-  mapping_found = rewrite_table->forwardMappingLookup(request_url, request_port, request_host,
request_host_len, s->url_map);
+  if (rewrite_table->num_rules_forward_with_recv_port) {
+    Debug("url_rewrite", "[lookup] forward mappings with recv port found; Using recv port
%d",
+          s->client_info.port);
+    if (rewrite_table->forwardMappingWithRecvPortLookup(request_url, s->client_info.port,
+                                                         request_host, request_host_len,
s->url_map)) {
+      Debug("url_rewrite", "Found forward mapping with recv port");
+      mapping_found = true;
+    } else if (rewrite_table->num_rules_forward == 0) {
+      ink_assert(rewrite_table->forward_mappings.empty());
+      Debug("url_rewrite", "No forward mappings left");
+      return false;
+    }
+  }
+
+  if (!mapping_found) {
+    mapping_found = rewrite_table->forwardMappingLookup(request_url, request_port, request_host,
request_host_len, s->url_map);
+  }
 
   if (!proxy_request) { // do extra checks on a server request
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/cefaa407/proxy/http/remap/UrlRewrite.cc
----------------------------------------------------------------------
diff --git a/proxy/http/remap/UrlRewrite.cc b/proxy/http/remap/UrlRewrite.cc
index f88e480..24a40e2 100644
--- a/proxy/http/remap/UrlRewrite.cc
+++ b/proxy/http/remap/UrlRewrite.cc
@@ -479,11 +479,12 @@ UrlRewrite::UrlRewrite(const char *file_var_in)
  : nohost_rules(0), reverse_proxy(0), backdoor_enabled(0),
    mgmt_autoconf_port(0), default_to_pac(0), default_to_pac_port(0), file_var(NULL), ts_name(NULL),
    http_default_redirect_url(NULL), num_rules_forward(0), num_rules_reverse(0), num_rules_redirect_permanent(0),
-   num_rules_redirect_temporary(0)
+   num_rules_redirect_temporary(0), num_rules_forward_with_recv_port(0)
 {
 
   forward_mappings.hash_lookup = reverse_mappings.hash_lookup =
-    permanent_redirects.hash_lookup = temporary_redirects.hash_lookup = NULL;
+    permanent_redirects.hash_lookup = temporary_redirects.hash_lookup = 
+    forward_mappings_with_recv_port.hash_lookup = NULL;
 
   char *config_file = NULL;
 
@@ -549,6 +550,7 @@ UrlRewrite::~UrlRewrite()
   DestroyStore(reverse_mappings);
   DestroyStore(permanent_redirects);
   DestroyStore(temporary_redirects);
+  DestroyStore(forward_mappings_with_recv_port);
 }
 
 /** Sets the reverse proxy flag. */
@@ -638,26 +640,25 @@ UrlRewrite::_destroyTable(InkHashTable *h_table)
 void
 UrlRewrite::Print()
 {
-  printf("URL Rewrite table with %d entries\n", num_rules_forward +
-         num_rules_reverse + num_rules_redirect_temporary + num_rules_redirect_permanent);
+  printf("URL Rewrite table with %d entries\n", num_rules_forward + num_rules_reverse +
+         num_rules_redirect_temporary + num_rules_redirect_permanent + num_rules_forward_with_recv_port);
   printf("  Reverse Proxy is %s\n", (reverse_proxy == 0) ? "Off" : "On");
 
-  if (forward_mappings.hash_lookup != NULL) {
-    printf("  Forward Mapping Table with %d entries\n", num_rules_forward);
-    PrintTable(forward_mappings.hash_lookup);
-  }
-  if (reverse_mappings.hash_lookup != NULL) {
-    printf("  Reverse Mapping Table with %d entries\n", num_rules_reverse);
-    PrintTable(reverse_mappings.hash_lookup);
-  }
-  if (permanent_redirects.hash_lookup != NULL) {
-    printf("  Permanent Redirect Mapping Table with %d entries\n", num_rules_redirect_permanent);
-    PrintTable(permanent_redirects.hash_lookup);
-  }
-  if (temporary_redirects.hash_lookup != NULL) {
-    printf("  Temporary Redirect Mapping Table with %d entries\n", num_rules_redirect_temporary);
-    PrintTable(temporary_redirects.hash_lookup);
-  }
+  printf("  Forward Mapping Table with %d entries\n", num_rules_forward);
+  PrintStore(forward_mappings);
+
+  printf("  Reverse Mapping Table with %d entries\n", num_rules_reverse);
+  PrintStore(reverse_mappings);
+
+  printf("  Permanent Redirect Mapping Table with %d entries\n", num_rules_redirect_permanent);
+  PrintStore(permanent_redirects);
+
+  printf("  Temporary Redirect Mapping Table with %d entries\n", num_rules_redirect_temporary);
+  PrintStore(temporary_redirects);
+
+  printf("  Forward Mapping With Recv Port Table with %d entries\n", num_rules_forward_with_recv_port);
+  PrintStore(forward_mappings_with_recv_port);
+
   if (http_default_redirect_url != NULL) {
     printf("  Referer filter default redirect URL: \"%s\"\n", http_default_redirect_url);
   }
@@ -665,16 +666,25 @@ UrlRewrite::Print()
 
 /** Debugging method. */
 void
-UrlRewrite::PrintTable(InkHashTable *h_table)
+UrlRewrite::PrintStore(MappingsStore &store)
 {
-  InkHashTableEntry *ht_entry;
-  InkHashTableIteratorState ht_iter;
-  UrlMappingPathIndex *value;
+  if (store.hash_lookup != NULL) {
+    InkHashTableEntry *ht_entry;
+    InkHashTableIteratorState ht_iter;
+    UrlMappingPathIndex *value;
 
-  for (ht_entry = ink_hash_table_iterator_first(h_table, &ht_iter); ht_entry != NULL;)
{
-    value = (UrlMappingPathIndex *)ink_hash_table_entry_value(h_table, ht_entry);
-    value->Print();
-    ht_entry = ink_hash_table_iterator_next(h_table, &ht_iter);
+    for (ht_entry = ink_hash_table_iterator_first(store.hash_lookup, &ht_iter); ht_entry
!= NULL;) {
+      value = (UrlMappingPathIndex *) ink_hash_table_entry_value(store.hash_lookup, ht_entry);
+      value->Print();
+      ht_entry = ink_hash_table_iterator_next(store.hash_lookup, &ht_iter);
+    }
+  }
+
+  if (!store.regex_list.empty()) {
+    printf("    Regex mappings:\n");
+    forl_LL(RegexMapping, list_iter, store.regex_list) {
+      list_iter->url_map->Print();
+    }
   }
 }
 
@@ -1068,10 +1078,12 @@ UrlRewrite::BuildTable()
   ink_assert(reverse_mappings.empty());
   ink_assert(permanent_redirects.empty());
   ink_assert(temporary_redirects.empty());
+  ink_assert(forward_mappings_with_recv_port.empty());
   ink_assert(num_rules_forward == 0);
   ink_assert(num_rules_reverse == 0);
   ink_assert(num_rules_redirect_permanent == 0);
   ink_assert(num_rules_redirect_temporary == 0);
+  ink_assert(num_rules_forward_with_recv_port == 0);
 
   memset(&bti, 0, sizeof(bti));
 
@@ -1084,6 +1096,7 @@ UrlRewrite::BuildTable()
   reverse_mappings.hash_lookup = ink_hash_table_create(InkHashTableKeyType_String);
   permanent_redirects.hash_lookup = ink_hash_table_create(InkHashTableKeyType_String);
   temporary_redirects.hash_lookup = ink_hash_table_create(InkHashTableKeyType_String);
+  forward_mappings_with_recv_port.hash_lookup = ink_hash_table_create(InkHashTableKeyType_String);
 
   bti.paramc = (bti.argc = 0);
   memset(bti.paramv, 0, sizeof(bti.paramv));
@@ -1176,6 +1189,9 @@ UrlRewrite::BuildTable()
     } else if (!strcasecmp("map_with_referer", type_id_str)) {
       Debug("url_rewrite", "[BuildTable] - FORWARD_MAP_REFERER");
       maptype = FORWARD_MAP_REFERER;
+    } else if (!strcasecmp("map_with_recv_port", type_id_str)) {
+      Debug("url_rewrite", "[BuildTable] - FORWARD_MAP_WITH_RECV_PORT");
+      maptype = FORWARD_MAP_WITH_RECV_PORT;
     } else {
       snprintf(errBuf, sizeof(errBuf) - 1, "%s Unknown mapping type at line %d", modulePrefix,
cln + 1);
       errStr = errStrBuf;
@@ -1301,7 +1317,7 @@ UrlRewrite::BuildTable()
     // Check to see the fromHost remapping is a relative one
     fromHost = new_mapping->fromURL.host_get(&fromHostLen);
     if (fromHost == NULL || fromHostLen <= 0) {
-      if (maptype == FORWARD_MAP || maptype == FORWARD_MAP_REFERER) {
+      if (maptype == FORWARD_MAP || maptype == FORWARD_MAP_REFERER || maptype == FORWARD_MAP_WITH_RECV_PORT)
{
         if (*map_from_start != '/') {
           errStr = "Relative remappings must begin with a /";
           goto MAP_ERROR;
@@ -1364,7 +1380,7 @@ UrlRewrite::BuildTable()
     // Therefore, for a remap rule like "map tunnel://hostname..."
     // in remap.config, we also needs to convert hostname to its IPv4 addr
     // and gives a new remap rule with the IPv4 addr.
-    if ((maptype == FORWARD_MAP || maptype == FORWARD_MAP_REFERER) &&
+    if ((maptype == FORWARD_MAP || maptype == FORWARD_MAP_REFERER || maptype == FORWARD_MAP_WITH_RECV_PORT)
&&
         fromScheme == URL_SCHEME_TUNNEL && (fromHost_lower[0]<'0' || fromHost_lower[0]>
'9')) {
       ink_gethostbyname_r_data d;
       struct hostent *h;
@@ -1389,11 +1405,14 @@ UrlRewrite::BuildTable()
             u_mapping->toUrl.copy(&new_mapping->toUrl);
             if (bti.paramv[3] != NULL)
               u_mapping->tag = xstrdup(&(bti.paramv[3][0]));
-            if (!TableInsert(forward_mappings.hash_lookup, u_mapping, ipv4_name)) {
+            bool insert_result = (maptype != FORWARD_MAP_WITH_RECV_PORT) ? 
+              TableInsert(forward_mappings.hash_lookup, u_mapping, ipv4_name) :
+              TableInsert(forward_mappings_with_recv_port.hash_lookup, u_mapping, ipv4_name);
+            if (!insert_result) {
               errStr = "Unable to add mapping rule to lookup table";
               goto MAP_ERROR;
             }
-            num_rules_forward++;
+            (maptype != FORWARD_MAP_WITH_RECV_PORT) ? ++num_rules_forward : ++num_rules_forward_with_recv_port;
             SetHomePageRedirectFlag(u_mapping, u_mapping->toUrl);
           }
         }
@@ -1401,7 +1420,8 @@ UrlRewrite::BuildTable()
     }
 
     // Check "remap" plugin options and load .so object
-    if ((bti.remap_optflg & REMAP_OPTFLG_PLUGIN) != 0 && (maptype == FORWARD_MAP
|| maptype == FORWARD_MAP_REFERER)) {
+    if ((bti.remap_optflg & REMAP_OPTFLG_PLUGIN) != 0 && (maptype == FORWARD_MAP
|| maptype == FORWARD_MAP_REFERER ||
+                                                          maptype == FORWARD_MAP_WITH_RECV_PORT))
{
       if ((check_remap_option(bti.argv, bti.argc, REMAP_OPTFLG_PLUGIN, &tok_count) &
REMAP_OPTFLG_PLUGIN) != 0) {
         int plugin_found_at = 0;
         int jump_to_argc = 0;
@@ -1448,6 +1468,10 @@ UrlRewrite::BuildTable()
       add_result = _addToStore(temporary_redirects, new_mapping, reg_map, fromHost_lower,
                                is_cur_mapping_regex, num_rules_redirect_temporary);
       break;
+    case FORWARD_MAP_WITH_RECV_PORT:
+      add_result = _addToStore(forward_mappings_with_recv_port, new_mapping, reg_map, fromHost_lower,
+                               is_cur_mapping_regex, num_rules_forward_with_recv_port);
+      break;
     default:
       // 'default' required to avoid compiler warning; unsupported map
       // type would have been dealt with much before this
@@ -1521,6 +1545,11 @@ UrlRewrite::BuildTable()
     temporary_redirects.hash_lookup = ink_hash_table_destroy(temporary_redirects.hash_lookup);
   }
 
+  if (num_rules_forward_with_recv_port == 0) {
+    forward_mappings_with_recv_port.hash_lookup = ink_hash_table_destroy(
+      forward_mappings_with_recv_port.hash_lookup);
+  }
+
   xfree(file_buf);
 
   return 0;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/cefaa407/proxy/http/remap/UrlRewrite.h
----------------------------------------------------------------------
diff --git a/proxy/http/remap/UrlRewrite.h b/proxy/http/remap/UrlRewrite.h
index 57692d6..1b10364 100644
--- a/proxy/http/remap/UrlRewrite.h
+++ b/proxy/http/remap/UrlRewrite.h
@@ -61,7 +61,8 @@ typedef struct s_build_table_info
  * used for redirection, mapping, and reverse mapping
 **/
 enum mapping_type
-{ FORWARD_MAP, REVERSE_MAP, PERMANENT_REDIRECT, TEMPORARY_REDIRECT, FORWARD_MAP_REFERER,
NONE };
+{ FORWARD_MAP, REVERSE_MAP, PERMANENT_REDIRECT, TEMPORARY_REDIRECT, FORWARD_MAP_REFERER,
+  FORWARD_MAP_WITH_RECV_PORT, NONE };
 
 /**
  *
@@ -116,7 +117,7 @@ public:
   void PerformACLFiltering(HttpTransact::State * s, url_mapping * mapping);
   url_mapping *SetupPacMapping();       // manager proxy-autconfig mapping
   url_mapping *SetupBackdoorMapping();
-  void PrintTable(InkHashTable * h_table);
+  void PrintStore(MappingsStore &store);
 
   void DestroyStore(MappingsStore &store)
   {
@@ -130,6 +131,7 @@ public:
   MappingsStore reverse_mappings;
   MappingsStore permanent_redirects;
   MappingsStore temporary_redirects;
+  MappingsStore forward_mappings_with_recv_port;
 
   bool forwardMappingLookup(URL *request_url, int request_port, const char *request_host,
                             int request_host_len, UrlMappingContainer &mapping_container)
@@ -155,6 +157,12 @@ public:
     return _mappingLookup(temporary_redirects, request_url, request_port, request_host, request_host_len,
                           mapping_container);
   }
+  bool forwardMappingWithRecvPortLookup(URL *request_url, int recv_port, const char *request_host,
+                                        int request_host_len, UrlMappingContainer &mapping_container)
+  {
+    return _mappingLookup(forward_mappings_with_recv_port, request_url, recv_port, request_host,
+                          request_host_len, mapping_container);
+  }
 
   int UrlWhack(char *toWhack, int *origLength);
 
@@ -179,6 +187,7 @@ public:
   int num_rules_reverse;
   int num_rules_redirect_permanent;
   int num_rules_redirect_temporary;
+  int num_rules_forward_with_recv_port;
 
 private:
   void _doRemap(UrlMappingContainer &mapping_container, URL *request_url);


Mime
View raw message