You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by vm...@apache.org on 2011/08/19 01:15:21 UTC
svn commit: r1159440 - in /trafficserver/traffic/trunk/proxy:
config/remap.config.default http/remap/RemapProcessor.cc
http/remap/UrlRewrite.cc http/remap/UrlRewrite.h
Author: vmamidi
Date: Thu Aug 18 23:15:21 2011
New Revision: 1159440
URL: http://svn.apache.org/viewvc?rev=1159440&view=rev
Log:
TS-876 commiting Manjesh's changes for port based regex.
Modified:
trafficserver/traffic/trunk/proxy/config/remap.config.default
trafficserver/traffic/trunk/proxy/http/remap/RemapProcessor.cc
trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.cc
trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.h
Modified: trafficserver/traffic/trunk/proxy/config/remap.config.default
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/config/remap.config.default?rev=1159440&r1=1159439&r2=1159440&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/config/remap.config.default (original)
+++ trafficserver/traffic/trunk/proxy/config/remap.config.default Thu Aug 18 23:15:21 2011
@@ -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,11 @@
# 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.
Modified: trafficserver/traffic/trunk/proxy/http/remap/RemapProcessor.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/remap/RemapProcessor.cc?rev=1159440&r1=1159439&r2=1159440&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/remap/RemapProcessor.cc (original)
+++ trafficserver/traffic/trunk/proxy/http/remap/RemapProcessor.cc Thu Aug 18 23:15:21 2011
@@ -61,10 +61,14 @@ RemapProcessor::setup_for_remap(HttpTran
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(HttpTran
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
Modified: trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.cc?rev=1159440&r1=1159439&r2=1159440&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.cc (original)
+++ trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.cc Thu Aug 18 23:15:21 2011
@@ -483,7 +483,8 @@ UrlRewrite::UrlRewrite(const char *file_
{
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 *
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;
Modified: trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.h?rev=1159440&r1=1159439&r2=1159440&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.h (original)
+++ trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.h Thu Aug 18 23:15:21 2011
@@ -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);