Permalink
Browse files

TS-926 - IPv6 conversion of iocore.

git-svn-id: https://svn.apache.org/repos/asf/trafficserver/traffic/trunk@1179389 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent bf803ab commit bd749d56deae3e98bb9190d9244b9cfc0669fce0 @SolidWallOfCode SolidWallOfCode committed Oct 5, 2011
Showing with 759 additions and 625 deletions.
  1. +6 −1 CHANGES
  2. +6 −6 iocore/dns/P_SplitDNSProcessor.h
  3. +4 −4 iocore/net/SSLNetVConnection.cc
  4. +2 −2 iocore/net/Socks.cc
  5. +31 −6 iocore/utils/I_Machine.h
  6. +91 −81 iocore/utils/Machine.cc
  7. +2 −2 lib/ts/IpMap.cc
  8. +18 −9 lib/ts/IpMap.h
  9. +14 −4 lib/ts/IpMapConf.cc
  10. +16 −1 lib/ts/ink_inet.cc
  11. +27 −12 lib/ts/ink_inet.h
  12. +7 −0 lib/ts/ink_memory.h
  13. +11 −9 proxy/ControlBase.cc
  14. +8 −8 proxy/ControlMatcher.cc
  15. +12 −9 proxy/ControlMatcher.h
  16. +4 −4 proxy/IPAllow.cc
  17. +23 −40 proxy/InkAPI.cc
  18. +1 −1 proxy/Main.cc
  19. +73 −55 proxy/ParentSelection.cc
  20. +1 −1 proxy/ParentSelection.h
  21. +71 −70 proxy/Prefetch.cc
  22. +38 −49 proxy/Prefetch.h
  23. +2 −5 proxy/UglyLogStubs.cc
  24. +22 −10 proxy/api/ts/InkAPIHughes.h
  25. +15 −12 proxy/congest/Congestion.cc
  26. +11 −10 proxy/congest/Congestion.h
  27. +9 −7 proxy/congest/CongestionDB.cc
  28. +18 −8 proxy/congest/CongestionTest.cc
  29. +2 −2 proxy/http/HttpConfig.cc
  30. +5 −4 proxy/http/HttpConfig.h
  31. +22 −6 proxy/http/HttpConnectionCount.h
  32. +38 −60 proxy/http/HttpSM.cc
  33. +8 −2 proxy/http/HttpServerSession.cc
  34. +5 −4 proxy/http/HttpServerSession.h
  35. +16 −12 proxy/http/HttpSessionManager.cc
  36. +1 −1 proxy/http/HttpSessionManager.h
  37. +65 −58 proxy/http/HttpTransact.cc
  38. +8 −9 proxy/http/HttpTransact.h
  39. +2 −2 proxy/http/HttpTransactHeaders.cc
  40. +1 −2 proxy/http/HttpUpdateSM.cc
  41. +6 −5 proxy/http/remap/AclFiltering.cc
  42. +20 −17 proxy/http/remap/AclFiltering.h
  43. +2 −2 proxy/http/remap/RemapProcessor.cc
  44. +4 −4 proxy/http/remap/UrlRewrite.cc
  45. +2 −2 proxy/logging/LogAccess.cc
  46. +5 −3 proxy/logging/LogAccessHttp.cc
  47. +2 −2 proxy/logging/LogFile.cc
  48. +1 −1 proxy/logging/LogStandalone.cc
  49. +1 −1 proxy/sac.cc
View
7 CHANGES
@@ -51,6 +51,10 @@ Changes with Apache Traffic Server 3.1.1
*) [TS-936] Fix problems with core file generation on Linux.
+Changes with Apache Traffic Server 3.1.1
+
+ *) [TS-930] Fixed TSNetConnect to use network order for port.
+
Changes with Apache Traffic Server 3.1.0
*) Make sure --enable-purify works again
@@ -59,7 +63,8 @@ Changes with Apache Traffic Server 3.1.0
*) [TS-925] Switch from integer thread IDs to hex thread IDs with the
diagnostics output. Author: Brian Geffon.
- *) [TS-919] All of iocore is now IPv6 compatible.
+ *) [TS-919] All of iocore is now IPv6 compatible. Much of this work
+ was contributed by Yossi Gottlieb.
*) [TS-867] moving to a different thread only if the pluginvc is invoked
from a non regular thread.
View
12 iocore/dns/P_SplitDNSProcessor.h
@@ -197,8 +197,8 @@ class DNSRequestData: public RequestData
const char *get_host();
- in_addr_t get_ip(); // unused required virtual method.
- in_addr_t get_client_ip(); // unused required virtual method.
+ sockaddr const* get_ip(); // unused required virtual method.
+ sockaddr const* get_client_ip(); // unused required virtual method.
const char *m_pHost;
};
@@ -236,18 +236,18 @@ DNSRequestData::get_host()
/* --------------------------------------------------------------
DNSRequestData::get_ip()
-------------------------------------------------------------- */
-TS_INLINE in_addr_t DNSRequestData::get_ip()
+TS_INLINE sockaddr const* DNSRequestData::get_ip()
{
- return 0;
+ return NULL;
}
/* --------------------------------------------------------------
DNSRequestData::get_client_ip()
-------------------------------------------------------------- */
-TS_INLINE in_addr_t DNSRequestData::get_client_ip()
+TS_INLINE sockaddr const* DNSRequestData::get_client_ip()
{
- return 0;
+ return NULL;
}
/* --------------------------------------------------------------
View
8 iocore/net/SSLNetVConnection.cc
@@ -450,15 +450,15 @@ int
SSLNetVConnection::sslStartHandShake(int event, int &err)
{
SSL_CTX *ctx = NULL;
- sockaddr_in6 sa;
- int namelen = sizeof(sa);
+ ts_ip_endpoint ip;
+ int namelen = sizeof(ip);
if (event == SSL_EVENT_SERVER) {
if (ssl == NULL) {
if (sslCertLookup.multipleCerts) {
char buff[INET6_ADDRSTRLEN];
- safe_getsockname(get_socket(), ink_inet_sa_cast(&sa), &namelen);
- ink_inet_ntop(&sa, buff, sizeof(buff));
+ safe_getsockname(get_socket(), &ip.sa, &namelen);
+ ink_inet_ntop(&ip.sa, buff, sizeof(buff));
ctx = sslCertLookup.findInfoInHash(buff);
if (ctx == NULL)
ctx = ssl_NetProcessor.ctx;
View
4 iocore/net/Socks.cc
@@ -63,10 +63,10 @@ SocksEntry::init(ProxyMutex * m, SocksNetVC * vc, unsigned char socks_support, u
req_data.xact_start = time(0);
assert(ink_inet_is_ip4(&target_addr));
- req_data.dest_ip = ink_inet_ip4_addr_cast(&target_addr);
+ ink_inet_copy(&req_data.dest_ip, &target_addr);
//we dont have information about the source. set to destination's
- req_data.src_ip = ink_inet_ip4_addr_cast(&target_addr);
+ ink_inet_copy(&req_data.src_ip, &target_addr);
server_params = SocksServerConfig::acquire();
#endif
View
37 iocore/utils/I_Machine.h
@@ -42,20 +42,45 @@
multiple IP addresses, the numerically lowest IP address is used.
The IP address is stored in the network byte order.
+ @internal This does not handle multi-homed systems. That should be
+ fixed.
+
*/
-struct Machine
-{
+struct Machine {
+ typedef Machine self; ///< Self reference type.
+
char *hostname; // name of the internet host
int hostname_len; // size of the string pointed to by hostname
- unsigned int ip; // IP address of the host (network order)
- char *ip_string; // IP address of the host as a string.
+ ts_ip_endpoint ip; ///< Prefered IP address of the host (network order)
+ ts_ip_endpoint ip4; ///< IPv4 address if present.
+ ts_ip_endpoint ip6; ///< IPv6 address if present.
+
+ ip_text_buffer 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
+
+ char ip_hex_string[INK_IP6_SIZE*2 + 1]; ///< IP address as hex string
int ip_hex_string_len;
- Machine(char *hostname = 0, unsigned int ip = 0);
~Machine();
+
+ /** Initialize the singleton.
+ If @a hostname or @a ip are @c NULL then system defaults are used.
+
+ @note This must be called before called @c instance so that the
+ singleton is not @em inadvertently default initialized.
+ */
+ static self* init(
+ char const* name = 0, ///< Host name of the machine.
+ sockaddr const* addr = 0 ///< Primary IP adddress of the machine.
+ );
+ /// @return The global instance of this class.
+ static self* instance();
+
+protected:
+ Machine(char const* hostname, sockaddr const* addr);
+
+ static self* _instance; ///< Singleton for the class.
};
/**
View
172 iocore/utils/Machine.cc
@@ -1,6 +1,6 @@
/** @file
- A brief file description
+ Support class for describing the local machine.
@section license License
@@ -25,109 +25,119 @@
#include "I_Machine.h"
// Singleton
-static Machine *machine = NULL;
+Machine* Machine::_instance = 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;
+nstrhex(char *dst, uint8_t const* src, size_t len) {
+ int zret = 0;
+ for ( uint8_t const* limit = src + len ; src < limit ; ++src, zret += 2 ) {
+ uint8_t n1 = (*src >> 4) & 0xF; // high nybble.
+ uint8_t n0 = *src & 0xF; // low nybble.
+
+ *dst++ = n1 > 9 ? n1 + 'A' - 10 : n1 + '0';
+ *dst++ = n0 > 9 ? n0 + 'A' - 10 : n0 + '0';
+ }
+ *dst = 0; // terminate but don't include that in the length.
+ return zret;
}
-
-// Machine class. TODO: This has to deal with IPv6!
-Machine *
-this_machine()
-{
- if (machine == NULL) {
- ink_assert("need to call create_this_machine before accessing" "this_machine()");
- }
- return machine;
+Machine*
+Machine::instance() {
+ ink_assert(_instance || !"Machine instance accessed before initialization");
+ return Machine::_instance;
}
-void
-create_this_machine(char *hostname, unsigned int ip)
-{
- machine = NEW(new Machine(hostname, ip));
+Machine*
+Machine::init(char const* name, sockaddr const* ip) {
+ ink_assert(!_instance || !"Machine instance initialized twice.");
+ Machine::_instance = new Machine(name, ip);
+ return Machine::_instance;
}
-Machine::Machine(char *ahostname, unsigned int aip)
- : hostname(ahostname), ip(aip)
+Machine::Machine(char const* the_hostname, sockaddr const* addr)
+ : hostname(0), hostname_len(0)
+ , ip_string_len(0)
+ , ip_hex_string_len(0)
{
- if (!aip) {
- char localhost[1024];
+ char localhost[1024];
+ int status; // return for system calls.
- if (!ahostname) {
- ink_release_assert(!gethostname(localhost, 1023));
- ahostname = localhost;
- }
- hostname = ats_strdup(ahostname);
+ ip_string[0] = 0;
+ ip_hex_string[0] = 0;
+ ink_zero(ip);
+ ink_zero(ip4);
+ ink_zero(ip6);
- ink_gethostbyname_r_data data;
- struct hostent *r = ink_gethostbyname_r(ahostname, &data);
+ localhost[sizeof(localhost)-1] = 0; // ensure termination.
- if (!r) {
- Warning("unable to DNS %s: %d", ahostname, data.herrno);
- ip = 0;
+ if (!ink_inet_is_ip(addr)) {
+ addrinfo ai_hints;
+ addrinfo* ai_ret = 0;
+
+ if (!the_hostname) {
+ ink_release_assert(!gethostname(localhost, sizeof(localhost)-1));
+ the_hostname = localhost;
+ }
+ hostname = ats_strdup(the_hostname);
+
+ ink_zero(ai_hints);
+ ai_hints.ai_flags = AI_ADDRCONFIG; // require existence of IP family addr.
+ status = getaddrinfo(hostname, 0, &ai_hints, &ai_ret);
+ if (0 != status) {
+ Warning("Unable to determine local host '%s' address information - %s"
+ , hostname
+ , gai_strerror(status)
+ );
} else {
- ip = (unsigned int) -1; // 0xFFFFFFFF
- 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];
+ for (addrinfo* spot = ai_ret ; spot ; spot = spot->ai_next ) {
+ if (AF_INET == spot->ai_family) {
+ if (!ink_inet_is_ip4(&ip4)) {
+ ink_inet_copy(&ip4, spot->ai_addr);
+ if (!ink_inet_is_ip(&ip))
+ ink_inet_copy(&ip, spot->ai_addr);
+ if (ink_inet_is_ip6(&ip6)) break; // got both families, done.
+ }
+ } else if (AF_INET6 == spot->ai_family) {
+ if (!ink_inet_is_ip6(&ip6)) {
+ ink_inet_copy(&ip6, spot->ai_addr);
+ if (!ink_inet_is_ip(&ip))
+ ink_inet_copy(&ip, spot->ai_addr);
+ if (ink_inet_is_ip4(&ip4)) break; // got both families, done.
+ }
+ }
}
- if (ip == (unsigned int) -1)
- ip = 0;
+ freeaddrinfo(ai_ret);
}
- //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);
-
- if (r == NULL) {
- unsigned char x[4];
-
- memset(x, 0, sizeof(x));
- *(uint32_t *) & x = (uint32_t) ip;
- Debug("machine_debug", "unable to reverse DNS %hhu.%hhu.%hhu.%hhu: %d", x[0], x[1], x[2], x[3], data.herrno);
+ } else { // address provided.
+ ink_inet_copy(&ip, addr);
+ if (ink_inet_is_ip4(addr)) ink_inet_copy(&ip4, addr);
+ else if (ink_inet_is_ip6(addr)) ink_inet_copy(&ip6, addr);
+
+ status = getnameinfo(
+ addr, ink_inet_ip_size(addr),
+ localhost, sizeof(localhost) - 1,
+ 0, 0, // do not request service info
+ 0 // no flags.
+ );
+
+ if (0 != status) {
+ ip_text_buffer ipbuff;
+ Warning("Failed to find hostname for address '%s' - %s"
+ , ink_inet_ntop(addr, ipbuff, sizeof(ipbuff))
+ , gai_strerror(status)
+ );
} else
- hostname = ats_strdup(r->h_name);
+ hostname = ats_strdup(localhost);
}
- if (hostname)
- hostname_len = strlen(hostname);
- else
- hostname_len = 0;
-
- unsigned char x[4];
+ hostname_len = hostname ? strlen(hostname) : 0;
- memset(x, 0, sizeof(x));
- *(uint32_t *) & x = (uint32_t) ip;
- const size_t ip_string_size = sizeof(char) * 16;
- ip_string = (char *)ats_malloc(ip_string_size);
- snprintf(ip_string, ip_string_size, "%hhu.%hhu.%hhu.%hhu", x[0], x[1], x[2], x[3]);
+ ink_inet_ntop(&ip.sa, ip_string, sizeof(ip_string));
ip_string_len = strlen(ip_string);
-
- ip_hex_string = (char*)ats_malloc(9);
- memset(ip_hex_string, 0, 9);
- nstrhex(ip_hex_string, ip);
- ip_hex_string_len = strlen(ip_hex_string);
+ ip_hex_string_len = nstrhex(ip_hex_string, ink_inet_addr8_cast(&ip), ink_inet_addr_size(&ip));
}
Machine::~Machine()
{
ats_free(hostname);
- ats_free(ip_string);
- ats_free(ip_hex_string);
}
View
4 lib/ts/IpMap.cc
@@ -1036,11 +1036,11 @@ IpMap::contains(sockaddr const* target, void** ptr) const {
bool zret = false;
if (AF_INET == target->sa_family) {
if (_m4) {
- zret = _m4->contains(ntohl(ink_inet_ip4_addr_cast(target)));
+ zret = _m4->contains(ntohl(ink_inet_ip4_addr_cast(target)), ptr);
}
} else if (AF_INET6 == target->sa_family) {
if (_m6) {
- zret = _m6->contains(ink_inet_ip6_cast(target));
+ zret = _m6->contains(ink_inet_ip6_cast(target), ptr);
}
}
return zret;
View
27 lib/ts/IpMap.h
@@ -363,22 +363,22 @@ class IpMap {
/** Mark a range.
All addresses in the range [ @a min , @a max ] are marked with @a data.
- @note Convenience overload for IPv6 addresses.
+ @note Convenience overload.
@return This object.
*/
self& mark(
- sockaddr_in6 const* min, ///< Minimum address (network order).
- sockaddr_in6 const* max, ///< Maximum address (network order).
+ ts_ip_endpoint const* min, ///< Minimum address (network order).
+ ts_ip_endpoint const* max, ///< Maximum address (network order).
void* data = 0 ///< Client data.
);
/** Mark an IPv6 address @a addr with @a data.
This is equivalent to calling @c mark(addr, addr, data).
- @note Convenience overload for IPv6 addresses.
+ @note Convenience overload.
@return This object.
*/
self& mark(
- sockaddr_in6 const* addr, ///< Address (network order).
+ ts_ip_endpoint const* addr, ///< Address (network order).
void* data = 0 ///< Client data.
);
@@ -418,6 +418,11 @@ class IpMap {
void **ptr = 0 ///< Client data return.
) const;
+ bool contains(
+ ts_ip_endpoint const* target, ///< Search target (network order).
+ void **ptr = 0 ///< Client data return.
+ ) const;
+
/// Iterator for first element.
iterator begin();
/// Iterator past last element.
@@ -448,12 +453,16 @@ inline IpMap& IpMap::mark(in_addr_t addr, void* data) {
return this->mark(addr, addr, data);
}
-inline IpMap& IpMap::mark(sockaddr_in6 const* addr, void* data) {
- return this->mark(ink_inet_sa_cast(addr), ink_inet_sa_cast(addr), data);
+inline IpMap& IpMap::mark(ts_ip_endpoint const* addr, void* data) {
+ return this->mark(&addr->sa, &addr->sa, data);
+}
+
+inline IpMap& IpMap::mark(ts_ip_endpoint const* min, ts_ip_endpoint const* max, void* data) {
+ return this->mark(&min->sa, &max->sa, data);
}
-inline IpMap& IpMap::mark(sockaddr_in6 const* min, sockaddr_in6 const* max, void* data) {
- return this->mark(ink_inet_sa_cast(min), ink_inet_sa_cast(max), data);
+inline bool IpMap::contains(ts_ip_endpoint const* target, void** ptr) const {
+ return this->contains(&target->sa, ptr);
}
inline IpMap::iterator
View
18 lib/ts/IpMapConf.cc
@@ -42,6 +42,11 @@ read_addr(
int k;
char dst[INET6_ADDRSTRLEN];
char* src = line + *i;
+ bool bracketed_p = false;
+
+ // Allow enclosing brackets to be more consistent but
+ // don't bother passing it to @c ntop.
+ if (*i < n && '[' == *src) ++*i, ++src, bracketed_p = true;
for ( k = 0
; k < INET6_ADDRSTRLEN
@@ -52,6 +57,11 @@ read_addr(
dst[k] = *src;
}
+ if (bracketed_p && (! *i < n || ']' != *src)) {
+ snprintf(err, ERR_STRING_LEN, "Unclosed brackets");
+ return EINVAL;
+ }
+
if (k == sizeof(dst)) {
snprintf(err, ERR_STRING_LEN, "IP address too long");
return EINVAL;
@@ -96,7 +106,7 @@ Load_IpMap_From_File(IpMap* map, FILE* f, const char *key_str)
{
int i, n, line_no;
int key_len = strlen(key_str);
- sockaddr_in6 laddr, raddr;
+ ts_ip_endpoint laddr, raddr;
char line[MAX_LINE_SIZE];
char err_buff[ERR_STRING_LEN];
@@ -116,7 +126,7 @@ Load_IpMap_From_File(IpMap* map, FILE* f, const char *key_str)
while (true) {
if (!skip_space(line, n, i)) break;
- if (0 != read_addr(line, n, &i, ink_inet_sa_cast(&laddr), err_buff)) {
+ if (0 != read_addr(line, n, &i, &laddr.sa, err_buff)) {
char *error_str = (char *)ats_malloc(ERR_STRING_LEN);
snprintf(error_str, ERR_STRING_LEN, "Invalid input configuration (%s) at line %d offset %d - '%s'", err_buff, line_no, i, line);
return error_str;
@@ -137,12 +147,12 @@ Load_IpMap_From_File(IpMap* map, FILE* f, const char *key_str)
char *error_str = (char *)ats_malloc(ERR_STRING_LEN);
snprintf(error_str, ERR_STRING_LEN, "Invalid input (unterminated range) at line %d offset %d - '%s'", line_no, i, line);
return error_str;
- } else if (0 != read_addr(line, n, &i, ink_inet_sa_cast(&raddr), err_buff)) {
+ } else if (0 != read_addr(line, n, &i, &raddr.sa, err_buff)) {
char *error_str = (char *)ats_malloc(ERR_STRING_LEN);
snprintf(error_str, ERR_STRING_LEN, "Invalid input (%s) at line %d offset %d - '%s'", err_buff, line_no, i, line);
return error_str;
}
- map->mark(ink_inet_sa_cast(&laddr), ink_inet_sa_cast(&raddr));
+ map->mark(&laddr.sa, &raddr.sa);
if (!skip_space(line, n, i)) break;
if (line[i] != ',') {
char *error_str = (char *)ats_malloc(ERR_STRING_LEN);
View
17 lib/ts/ink_inet.cc
@@ -243,7 +243,7 @@ int ink_inet_pton(char const* text, sockaddr* addr) {
}
}
- memset(&hints, 0, sizeof(hints));
+ ink_zero(hints);
hints.ai_family = PF_UNSPEC;
hints.ai_flags = AI_NUMERICHOST|AI_PASSIVE;
if (0 == (zret = getaddrinfo(text, 0, &hints, &ai))) {
@@ -255,3 +255,18 @@ int ink_inet_pton(char const* text, sockaddr* addr) {
}
return zret;
}
+
+uint32_t ink_inet_hash(sockaddr const* addr) {
+ union md5sum {
+ unsigned char c[16];
+ uint32_t i;
+ } zret;
+ zret.i = 0;
+
+ if (ink_inet_is_ip4(addr)) {
+ zret.i = ink_inet_ip4_addr_cast(addr);
+ } else if (ink_inet_is_ip6(addr)) {
+ ink_code_md5(const_cast<uint8_t*>(ink_inet_addr8_cast(addr)), INK_IP6_SIZE, zret.c);
+ }
+ return zret.i;
+}
View
39 lib/ts/ink_inet.h
@@ -244,7 +244,7 @@ inline sockaddr_in6 const& ink_inet_ip6_cast(sockaddr const& a) {
return *static_cast<sockaddr_in6 const*>(static_cast<void const*>(&a));
}
-/// @return An appropriate size based on the address family.
+/// @return The @c sockaddr size for the family of @a addr.
inline size_t ink_inet_ip_size(
sockaddr const* addr ///< Address object.
) {
@@ -261,12 +261,22 @@ inline size_t ink_inet_ip_size(
: 0
;
}
-
-/// @return An appropriate size based on the address family.
-inline size_t ink_inet_ip_size(
- sockaddr_in6 const* addr ///< Address object.
+/// @return The size of the IP address only.
+inline size_t ink_inet_addr_size(
+ sockaddr const* addr ///< Address object.
) {
- return ink_inet_ip_size(ink_inet_sa_cast(addr));
+ return AF_INET == addr->sa_family ? sizeof(in_addr_t)
+ : AF_INET6 == addr->sa_family ? sizeof(in6_addr)
+ : 0
+ ;
+}
+inline size_t ink_inet_addr_size(
+ ts_ip_endpoint const* addr ///< Address object.
+) {
+ return AF_INET == addr->sa.sa_family ? sizeof(in_addr_t)
+ : AF_INET6 == addr->sa.sa_family ? sizeof(in6_addr)
+ : 0
+ ;
}
/** Get a reference to the port in an address.
@@ -397,6 +407,7 @@ inline uint32_t const* ink_inet_addr32_cast(sockaddr const* addr) {
must be checked independently of this function.
@return A pointer to the address information in @a addr or @c NULL
if @a addr is not an IP address.
+ @see ink_inet_addr_size
*/
inline uint8_t* ink_inet_addr8_cast(sockaddr* addr) {
uint8_t* zret = 0;
@@ -552,8 +563,8 @@ inline int ink_inet_cmp(
@note Convenience overload.
@see ink_inet_cmp(sockaddr const* lhs, sockaddr const* rhs)
*/
-inline int ink_inet_cmp(sockaddr_in6 const* lhs, sockaddr_in6 const* rhs) {
- return ink_inet_cmp(ink_inet_sa_cast(lhs), ink_inet_sa_cast(rhs));
+inline int ink_inet_cmp(ts_ip_endpoint const* lhs, ts_ip_endpoint const* rhs) {
+ return ink_inet_cmp(&lhs->sa, &rhs->sa);
}
/** Check if two addresses are equal.
@@ -692,11 +703,11 @@ char const* ink_inet_ntop(
A buffer of size INET6_ADDRSTRLEN suffices, including a terminating nul.
*/
inline char const* ink_inet_ntop(
- const sockaddr_in6 *addr, ///< Address.
+ ts_ip_endpoint const* addr, ///< Address.
char *dst, ///< Output buffer.
size_t size ///< Length of buffer.
) {
- return ink_inet_ntop(ink_inet_sa_cast(addr), dst, size);
+ return ink_inet_ntop(&addr->sa, dst, size);
}
/// Buffer size sufficient for IPv6 address and port.
@@ -719,11 +730,11 @@ char const* ink_inet_nptop(
A buffer of size INET6_ADDRPORTSTRLEN suffices, including a terminating nul.
*/
inline char const* ink_inet_nptop(
- const sockaddr_in6 *addr, ///< Address.
+ ts_ip_endpoint const*addr, ///< Address.
char *dst, ///< Output buffer.
size_t size ///< Length of buffer.
) {
- return ink_inet_nptop(ink_inet_sa_cast(addr), dst, size);
+ return ink_inet_nptop(&addr->sa, dst, size);
}
@@ -767,6 +778,10 @@ inline int ink_inet_pton(
return ink_inet_pton(text, &addr->sa);
}
+/** Generic IP address hash function.
+*/
+uint32_t ink_inet_hash(sockaddr const* addr);
+
/** Storage for an IP address.
In some cases we want to store just the address and not the
ancillary information (such as port, or flow data) in
View
7 lib/ts/ink_memory.h
@@ -57,6 +57,13 @@ extern "C"
#ifdef __cplusplus
}
+
+template < typename T >
+T& ink_zero(T& t) {
+ memset(&t, 0, sizeof(t));
+ return t;
+}
+
#endif /* __cplusplus */
#endif
View
20 proxy/ControlBase.cc
@@ -250,8 +250,8 @@ IPortMod::make(char* value, char const ** error) {
// ----------
struct SrcIPMod : public ControlBase::Modifier {
// Stored in host order because that's how they are compared.
- in_addr_t start_addr; ///< Start address in HOST order.
- in_addr_t end_addr; ///< End address in HOST order.
+ ts_ip_endpoint start_addr; ///< Start address in HOST order.
+ ts_ip_endpoint end_addr; ///< End address in HOST order.
static char const * const NAME;
@@ -267,22 +267,24 @@ ControlBase::Modifier::Type SrcIPMod::type() const { return MOD_SRC_IP; }
char const * SrcIPMod::name() const { return NAME; }
void SrcIPMod::print(FILE* f) const {
- in_addr_t a1 = htonl(start_addr);
- in_addr_t a2 = htonl(end_addr);
- fprintf(f, "%s=%d.%d.%d.%d-%d.%d.%d.%d ",
- this->name(), TS_IP_OCTETS(a1), TS_IP_OCTETS(a2)
+ ip_text_buffer b1, b2;
+ fprintf(f, "%s=%s-%s "
+ ,this->name()
+ , ink_inet_ntop(&start_addr.sa, b1, sizeof(b1))
+ , ink_inet_ntop(&end_addr.sa, b2, sizeof(b2))
);
}
bool SrcIPMod::check(HttpRequestData* req) const {
// Compare in host order
- uint32_t addr = ntohl(req->src_ip);
- return start_addr <= addr && addr <= end_addr;
+ return ink_inet_cmp(&start_addr, &req->src_ip) <= 0
+ && ink_inet_cmp(&req->src_ip, &end_addr) <= 0
+ ;
}
SrcIPMod*
SrcIPMod::make(char * value, char const ** error ) {
SrcIPMod tmp;
SrcIPMod* zret = 0;
- *error = ExtractIpRange(value, &tmp.start_addr, &tmp.end_addr);
+ *error = ExtractIpRange(value, &tmp.start_addr.sa, &tmp.end_addr.sa);
if (!*error) zret = new SrcIPMod(tmp);
return zret;
View
16 proxy/ControlMatcher.cc
@@ -70,16 +70,16 @@ HttpRequestData::get_host()
return hostname_str;
}
-in_addr_t
+sockaddr const*
HttpRequestData::get_ip()
{
- return dest_ip;
+ return &dest_ip.sa;
}
-in_addr_t
+sockaddr const*
HttpRequestData::get_client_ip()
{
- return src_ip;
+ return &src_ip.sa;
}
/*************************************************************
@@ -483,7 +483,7 @@ template<class Data, class Result> char *IpMatcher<Data, Result>::NewEntry(match
const char *errPtr;
char *errBuf;
char *match_data;
- in_addr_t addr1, addr2;
+ ts_ip_endpoint addr1, addr2;
// Make sure space has been allocated
ink_assert(num_el >= 0);
@@ -499,7 +499,7 @@ template<class Data, class Result> char *IpMatcher<Data, Result>::NewEntry(match
ink_assert(match_data != NULL);
// Extract the IP range
- errPtr = ExtractIpRange(match_data, &addr1, &addr2);
+ errPtr = ExtractIpRange(match_data, &addr1.sa, &addr2.sa);
if (errPtr != NULL) {
const size_t errorSize = 1024;
errBuf = (char *)ats_malloc(errorSize * sizeof(char));
@@ -518,7 +518,7 @@ template<class Data, class Result> char *IpMatcher<Data, Result>::NewEntry(match
return errBuf;
}
- ip_map.mark(addr1, addr2, cur_d);
+ ip_map.mark(&addr1.sa, &addr2.sa, cur_d);
++num_el;
return NULL;
@@ -528,7 +528,7 @@ template<class Data, class Result> char *IpMatcher<Data, Result>::NewEntry(match
// void IpMatcherData,Result>::Match(in_addr_t addr, RD* rdata, Result* result)
//
template<class Data, class Result>
- void IpMatcher<Data, Result>::Match(in_addr_t addr, RD * rdata, Result * result)
+ void IpMatcher<Data, Result>::Match(sockaddr const* addr, RD * rdata, Result * result)
{
void* raw;
if (ip_map.contains(addr, &raw)) {
View
21 proxy/ControlMatcher.h
@@ -121,9 +121,9 @@ struct RequestData
}
virtual char *get_string() = 0;
virtual const char *get_host() = 0;
- virtual in_addr_t get_ip() = 0;
+ virtual sockaddr const* get_ip() = 0;
- virtual in_addr_t get_client_ip() = 0;
+ virtual sockaddr const* get_client_ip() = 0;
enum RD_Type
{ RD_NULL, RD_HTTP, RD_CONGEST_ENTRY };
virtual RD_Type data_type(void)
@@ -138,20 +138,23 @@ class HttpRequestData:public RequestData
public:
inkcoreapi char *get_string();
inkcoreapi const char *get_host();
- inkcoreapi in_addr_t get_ip();
- inkcoreapi in_addr_t get_client_ip();
+ inkcoreapi sockaddr const* get_ip();
+ inkcoreapi sockaddr const* get_client_ip();
HttpRequestData()
: hdr(NULL), hostname_str(NULL), api_info(NULL),
- xact_start(0), src_ip(0), dest_ip(0), incoming_port(0), tag(NULL)
- { }
+ xact_start(0), incoming_port(0), tag(NULL)
+ {
+ ink_zero(src_ip);
+ ink_zero(dest_ip);
+ }
HTTPHdr *hdr;
char *hostname_str;
_HttpApiInfo *api_info;
time_t xact_start;
- in_addr_t src_ip;
- in_addr_t dest_ip;
+ ts_ip_endpoint src_ip;
+ ts_ip_endpoint dest_ip;
uint16_t incoming_port;
char *tag;
};
@@ -227,7 +230,7 @@ template<class Data, class Result> class IpMatcher {
public:
IpMatcher(const char *name, const char *filename);
~IpMatcher();
- void Match(in_addr_t ip_addr, RD * rdata, Result * result);
+ void Match(sockaddr const* ip_addr, RD * rdata, Result * result);
void AllocateSpace(int num_entries);
char *NewEntry(matcher_line * line_info);
void Print();
View
8 proxy/IPAllow.cc
@@ -196,8 +196,8 @@ IpAllow::BuildTable()
char errBuf[1024];
char *file_buf = NULL;
int line_num = 0;
- sockaddr_in6 addr1;
- sockaddr_in6 addr2;
+ ts_ip_endpoint addr1;
+ ts_ip_endpoint addr2;
matcher_line line_info;
bool alarmAlready = false;
@@ -234,7 +234,7 @@ IpAllow::BuildTable()
ink_assert(line_info.type == MATCH_IP);
- errPtr = ExtractIpRange(line_info.line[1][line_info.dest_entry], &addr1, &addr2);
+ errPtr = ExtractIpRange(line_info.line[1][line_info.dest_entry], &addr1.sa, &addr2.sa);
if (errPtr != NULL) {
snprintf(errBuf, sizeof(errBuf), "%s discarding %s entry at line %d : %s",
@@ -261,7 +261,7 @@ IpAllow::BuildTable()
// Color with index because at this point the address
// is volatile.
_map.mark(
- &addr1, &addr2,
+ &addr1.sa, &addr2.sa,
reinterpret_cast<void*>(_acls.size()-1)
);
} else {
View
63 proxy/InkAPI.cc
@@ -5125,7 +5125,7 @@ TSHttpTxnClientIPGet(TSHttpTxn txnp)
sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS);
HttpSM *sm = (HttpSM *) txnp;
- return sm->t_state.client_info.ip;
+ return ink_inet_ip4_addr_cast(&sm->t_state.client_info.addr);
}
sockaddr const*
@@ -5149,7 +5149,7 @@ TSHttpTxnClientIncomingPortGet(TSHttpTxn txnp)
sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS);
HttpSM *sm = (HttpSM *) txnp;
- return sm->t_state.client_info.port;
+ return ink_inet_get_port(&sm->t_state.client_info.addr);
}
sockaddr const*
@@ -5158,12 +5158,7 @@ TSHttpTxnServerAddrGet(TSHttpTxn txnp)
sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS);
HttpSM *sm = reinterpret_cast<HttpSM *>(txnp);
- ink_inet_ip4_set(
- ink_inet_sa_cast(&sm->t_state.server_info.addr),
- sm->t_state.server_info.ip,
- htons(sm->t_state.server_info.port)
- );
- return ink_inet_sa_cast(&sm->t_state.server_info.addr);
+ return &sm->t_state.server_info.addr.sa;
}
unsigned int
@@ -5172,7 +5167,7 @@ TSHttpTxnServerIPGet(TSHttpTxn txnp)
sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS);
HttpSM *sm = (HttpSM *) txnp;
- return sm->t_state.server_info.ip;
+ return ink_inet_ip4_addr_cast(&sm->t_state.server_info.addr.sa);
}
// This API does currently not use or honor the port specified in the sockaddr.
@@ -5184,22 +5179,9 @@ TSHttpTxnOutgoingAddrSet(TSHttpTxn txnp, const struct sockaddr *addr, socklen_t
HttpSM *sm = (HttpSM *) txnp;
sm->t_state.setup_per_txn_configs(); // Make sure the txn_conf struct is setup
+ ink_inet_copy(&sm->t_state.txn_conf->outgoing_ip_to_bind_saddr.sa, addr);
+ ink_inet_port_cast(&sm->t_state.txn_conf->outgoing_ip_to_bind_saddr) = 0;
- // TODO: For now only, we really ought to make all "internal" IP representations
- // use struct sockaddr_storage.
- switch (addr->sa_family) {
- case AF_INET:
- {
- sdk_assert(addrlen >= sizeof(struct sockaddr_in));
- const struct sockaddr_in *v4addr = reinterpret_cast<const struct sockaddr_in *>(addr);
- sm->t_state.txn_conf->outgoing_ip_to_bind_saddr = v4addr->sin_addr.s_addr;
-
- return TS_SUCCESS;
- }
- break;
- case AF_INET6:
- break;
- }
return TS_ERROR;
}
@@ -5214,13 +5196,9 @@ TSHttpTxnNextHopAddrGet(TSHttpTxn txnp)
* Return zero if the server structure is not yet constructed.
*/
if (sm->t_state.current.server == NULL)
- return 0;
- // IPv6 - is this set elsewhere? Can't be sure.
-// ink_inet_ip4_set(&sm->t_state.current.server->addr,
-// sm->t_state.current.server->ip,
-// sm->t_state.current.server->port
-// );
- return ink_inet_sa_cast(&sm->t_state.current.server->addr);
+ return NULL;
+
+ return &sm->t_state.current.server->addr.sa;
}
in_addr_t
@@ -5234,7 +5212,7 @@ TSHttpTxnNextHopIPGet(TSHttpTxn txnp)
*/
if (sm->t_state.current.server == NULL)
return 0;
- return sm->t_state.current.server->ip;
+ return ink_inet_ip4_addr_cast(&sm->t_state.current.server->addr.sa);
}
int
@@ -5246,7 +5224,7 @@ TSHttpTxnNextHopPortGet(TSHttpTxn txnp)
int port = 0;
if (sm && sm->t_state.current.server)
- port = sm->t_state.current.server->port;
+ port = ink_inet_get_port(&sm->t_state.current.server->addr);
return port;
}
@@ -6187,16 +6165,13 @@ TSAction
TSNetConnect(TSCont contp, sockaddr const* addr)
{
sdk_assert(sdk_sanity_check_continuation(contp) == TS_SUCCESS);
- sdk_assert(addr);
- sdk_assert(ink_inet_is_ip4(addr));
- in_addr_t ip = ink_inet_ip4_addr_cast(addr);
- uint16_t port = ink_inet_get_port(addr);
- sdk_assert(ip != 0 && port != 0);
+ sdk_assert(ink_inet_is_ip(addr));
FORCE_PLUGIN_MUTEX(contp);
- INKContInternal *i = (INKContInternal *) contp;
- return (TSAction)netProcessor.connect_re(i, ip, port);
+ return reinterpret_cast<TSAction>(
+ netProcessor.connect_re(reinterpret_cast<INKContInternal*>(contp), addr)
+ );
}
TSAction
@@ -6817,6 +6792,13 @@ TSMatcherExtractIPRange(char *match_str, uint32_t *addr1, uint32_t *addr2)
sdk_assert(sdk_sanity_check_null_ptr((void*)match_str) == TS_SUCCESS);
return (char*)ExtractIpRange(match_str, addr1, addr2);
}
+// Conflict in header due to overload (must be C compatible).
+char *
+TSMatcherExtractIPRange(char *match_str, sockaddr* addr1, sockaddr* addr2)
+{
+ sdk_assert(sdk_sanity_check_null_ptr((void*)match_str) == TS_SUCCESS);
+ return (char*)ExtractIpRange(match_str, addr1, addr2);
+}
TSMatcherLine
TSMatcherLineCreate(void)
@@ -7092,6 +7074,7 @@ TSFetchUrl(const char* headers, int request_len, sockaddr const* ip , TSCont con
if (callback_options != NO_CALLBACK) {
sdk_assert(sdk_sanity_check_continuation(contp) == TS_SUCCESS);
}
+ sdk_assert(ink_inet_is_ip4(ip));
FetchSM *fetch_sm = FetchSMAllocator.alloc();
in_addr_t addr = ink_inet_ip4_addr_cast(ip);
View
2 proxy/Main.cc
@@ -1760,7 +1760,7 @@ main(int argc, char **argv)
NetProcessor::accept_mss = accept_mss;
netProcessor.start();
- create_this_machine();
+ Machine::init();
#ifndef INK_NO_HOSTDB
dnsProcessor.start();
if (hostDBProcessor.start() < 0)
View
128 proxy/ParentSelection.cc
@@ -509,7 +509,15 @@ ParentRecord::FindParent(bool first_call, ParentResult * result, RD * rdata, Par
break;
case P_HASH_ROUND_ROBIN:
// INKqa12817 - make sure to convert to host byte order
- cur_index = ntohl(rdata->get_client_ip()) % num_parents;
+ // Why was it important to do host order here? And does this have any
+ // impact with the transition to IPv6? The IPv4 functionality is
+ // preserved for now anyway as ink_inet_hash returns the 32-bit address in
+ // that case.
+ if (rdata->get_client_ip() != NULL) {
+ cur_index = ntohl(ink_inet_hash(rdata->get_client_ip())) % num_parents;
+ } else {
+ cur_index = 0;
+ }
break;
case P_NO_ROUND_ROBIN:
cur_index = result->start_parent = 0;
@@ -1043,12 +1051,15 @@ SocksServerConfig::print()
}
void
-request_to_data(HttpRequestData * req, in_addr_t srcip, in_addr_t dstip, const char *str)
+request_to_data(HttpRequestData * req, sockaddr const* srcip, sockaddr const* dstip, const char *str)
{
HTTPParser parser;
- req->src_ip = srcip;
- req->dest_ip = dstip;
+ ink_zero(req->src_ip);
+ ink_inet_copy(&req->src_ip.sa, srcip);
+ ink_zero(req->dest_ip);
+ ink_inet_copy(&req->dest_ip.sa, dstip);
+
req->hdr = NEW(new HTTPHdr);
http_parser_init(&parser);
@@ -1059,8 +1070,6 @@ request_to_data(HttpRequestData * req, in_addr_t srcip, in_addr_t dstip, const c
}
-#define IP(a,b,c,d) htonl((a) << 24 | (b) << 16 | (c) << 8 | (d))
-
static int passes;
static int fails;
@@ -1116,7 +1125,10 @@ EXCLUSIVE_REGRESSION_TEST(PARENTSELECTION) (RegressionTest * t, int intensity_le
(!g && !b && !i && (v == 17))), 2)
// Test 3 - 6 Parenting Table
tbl[0] = '\0';
- T("dest_ip=209.131.62.14 parent=cat:37,dog:24 round_robin=strict\n") /* L1 */
+# define TEST_IP4_ADDR "209.131.62.14"
+# define TEST_IP6_ADDR "BEEF:DEAD:ABBA:CAFE:1337:1E1F:5EED:C0FF"
+ T("dest_ip=" TEST_IP4_ADDR " parent=cat:37,dog:24 round_robin=strict\n") /* L1 */
+ T("dest_ip=" TEST_IP6_ADDR " parent=zwoop:37,jMCg:24 round_robin=strict\n") /* L1 */
T("dest_host=www.pilot.net parent=pilot_net:80\n") /* L2 */
T("url_regex=snoopy parent=odie:80,garfield:80 round_robin=true\n") /* L3 */
T("dest_domain=i.am parent=amy:80,katie:80,carissa:771 round_robin=false\n") /* L4 */
@@ -1134,18 +1146,23 @@ EXCLUSIVE_REGRESSION_TEST(PARENTSELECTION) (RegressionTest * t, int intensity_le
T("dest_host=pluto scheme=HTTP parent=strategy:80\n") /* L16 */
REBUILD
// Test 3
- ST(3) REINIT br(request, "numeric_host", IP(209, 131, 62, 14));
+ ts_ip_endpoint ip;
+ ink_inet_pton(TEST_IP4_ADDR, &ip.sa);
+ ST(3) REINIT br(request, "numeric_host", &ip.sa);
FP RE(verify(result, PARENT_SPECIFIED, "cat", 37) + verify(result, PARENT_SPECIFIED, "dog", 24), 3)
- // Test 4
- ST(4) REINIT br(request, "www.pilot.net");
- FP RE(verify(result, PARENT_SPECIFIED, "pilot_net", 80), 4)
+ ink_inet_pton(TEST_IP6_ADDR, &ip.sa);
+ ST(4) REINIT br(request, "numeric_host", &ip.sa);
+ FP RE(verify(result, PARENT_SPECIFIED, "zwoop", 37) + verify(result, PARENT_SPECIFIED, "jMCg", 24), 4)
// Test 5
- ST(5) REINIT br(request, "www.snoopy.net");
+ ST(5) REINIT br(request, "www.pilot.net");
+ FP RE(verify(result, PARENT_SPECIFIED, "pilot_net", 80), 5)
+ // Test 6
+ ST(6) REINIT br(request, "www.snoopy.net");
const char *snoopy_dog = "http://www.snoopy.com/";
request->hdr->url_set(snoopy_dog, strlen(snoopy_dog));
FP RE(verify(result, PARENT_SPECIFIED, "odie", 80) + verify(result, PARENT_SPECIFIED, "garfield", 80), 5)
- // Test 6
- ST(6) REINIT br(request, "a.rabbit.i.am");
+ // Test 7
+ ST(7) REINIT br(request, "a.rabbit.i.am");
FP RE(verify(result, PARENT_SPECIFIED, "amy", 80) +
verify(result, PARENT_SPECIFIED, "katie", 80) + verify(result, PARENT_SPECIFIED, "carissa", 771), 6)
// Test 6+ BUGBUG needs to be fixed
@@ -1174,73 +1191,73 @@ EXCLUSIVE_REGRESSION_TEST(PARENTSELECTION) (RegressionTest * t, int intensity_le
tbl[0] = '\0';
T("dest_domain=rabbit.net parent=fuzzy:80,fluffy:80,furry:80,frisky:80 round_robin=strict go_direct=true\n")
REBUILD
- // Test 7
- ST(7) REINIT br(request, "i.am.rabbit.net");
+ // Test 8
+ ST(8) REINIT br(request, "i.am.rabbit.net");
FP RE(verify(result, PARENT_SPECIFIED, "fuzzy", 80), 7)
params->markParentDown(result);
- // Test 8
- ST(8) REINIT br(request, "i.am.rabbit.net");
+ // Test 9
+ ST(9) REINIT br(request, "i.am.rabbit.net");
FP RE(verify(result, PARENT_SPECIFIED, "fluffy", 80), 8)
- // Test 9
- ST(9) REINIT br(request, "i.am.rabbit.net");
- FP RE(verify(result, PARENT_SPECIFIED, "furry", 80), 9)
// Test 10
ST(10) REINIT br(request, "i.am.rabbit.net");
- FP RE(verify(result, PARENT_SPECIFIED, "frisky", 80), 10)
- // restart the loop
+ FP RE(verify(result, PARENT_SPECIFIED, "furry", 80), 9)
// Test 11
ST(11) REINIT br(request, "i.am.rabbit.net");
- FP RE(verify(result, PARENT_SPECIFIED, "fluffy", 80), 11)
+ FP RE(verify(result, PARENT_SPECIFIED, "frisky", 80), 10)
+ // restart the loop
// Test 12
ST(12) REINIT br(request, "i.am.rabbit.net");
- FP RE(verify(result, PARENT_SPECIFIED, "fluffy", 80), 12)
+ FP RE(verify(result, PARENT_SPECIFIED, "fluffy", 80), 11)
// Test 13
ST(13) REINIT br(request, "i.am.rabbit.net");
- FP RE(verify(result, PARENT_SPECIFIED, "furry", 80), 13)
+ FP RE(verify(result, PARENT_SPECIFIED, "fluffy", 80), 12)
// Test 14
ST(14) REINIT br(request, "i.am.rabbit.net");
+ FP RE(verify(result, PARENT_SPECIFIED, "furry", 80), 13)
+ // Test 15
+ ST(15) REINIT br(request, "i.am.rabbit.net");
FP RE(verify(result, PARENT_SPECIFIED, "frisky", 80), 14)
params->markParentDown(result);
// restart the loop
- // Test 15
- ST(15) REINIT br(request, "i.am.rabbit.net");
+ // Test 16
+ ST(16) REINIT br(request, "i.am.rabbit.net");
FP RE(verify(result, PARENT_SPECIFIED, "fluffy", 80), 15)
- // Test 16
- ST(16) REINIT br(request, "i.am.rabbit.net");
- FP RE(verify(result, PARENT_SPECIFIED, "fluffy", 80), 16)
// Test 17
ST(17) REINIT br(request, "i.am.rabbit.net");
- FP RE(verify(result, PARENT_SPECIFIED, "furry", 80), 17)
+ FP RE(verify(result, PARENT_SPECIFIED, "fluffy", 80), 16)
// Test 18
ST(18) REINIT br(request, "i.am.rabbit.net");
- FP RE(verify(result, PARENT_SPECIFIED, "fluffy", 80), 18)
- // restart the loop
+ FP RE(verify(result, PARENT_SPECIFIED, "furry", 80), 17)
// Test 19
ST(19) REINIT br(request, "i.am.rabbit.net");
- FP RE(verify(result, PARENT_SPECIFIED, "fluffy", 80), 19)
+ FP RE(verify(result, PARENT_SPECIFIED, "fluffy", 80), 18)
+ // restart the loop
// Test 20
ST(20) REINIT br(request, "i.am.rabbit.net");
- FP RE(verify(result, PARENT_SPECIFIED, "fluffy", 80), 20)
+ FP RE(verify(result, PARENT_SPECIFIED, "fluffy", 80), 19)
// Test 21
ST(21) REINIT br(request, "i.am.rabbit.net");
+ FP RE(verify(result, PARENT_SPECIFIED, "fluffy", 80), 20)
+ // Test 22
+ ST(22) REINIT br(request, "i.am.rabbit.net");
FP RE(verify(result, PARENT_SPECIFIED, "furry", 80), 21)
params->markParentDown(result);
- // Test 22 - 31
- for (i = 0; i < 10; i++) {
- ST(22 + i) REINIT br(request, "i.am.rabbit.net");
- FP RE(verify(result, PARENT_SPECIFIED, "fluffy", 80), 22 + i)
+ // Test 23 - 32
+ for (i = 23; i < 33; i++) {
+ ST(i) REINIT br(request, "i.am.rabbit.net");
+ FP RE(verify(result, PARENT_SPECIFIED, "fluffy", 80), i)
}
params->markParentDown(result); // now they're all down
- // Test 32 - 131
- for (i = 0; i < 100; i++) {
- ST(32 + i) REINIT br(request, "i.am.rabbit.net");
- FP RE(verify(result, PARENT_DIRECT, 0, 0), 32 + i)
+ // Test 33 - 132
+ for (i = 33; i < 133; i++) {
+ ST(i) REINIT br(request, "i.am.rabbit.net");
+ FP RE(verify(result, PARENT_DIRECT, 0, 0), i)
}
// sleep(5); // parents should come back up; they don't
@@ -1249,19 +1266,19 @@ EXCLUSIVE_REGRESSION_TEST(PARENTSELECTION) (RegressionTest * t, int intensity_le
// Fix: The following tests failed because
// br() should set xact_start correctly instead of 0.
- // Test 132 - 631
- for (i = 0; i < 40; i++) {
- ST(132 + i) REINIT br(request, "i.am.rabbit.net");
+ // Test 133 - 172
+ for (i = 133; i < 173; i++) {
+ ST(i) REINIT br(request, "i.am.rabbit.net");
FP sleep(1);
- switch ((i + 1) % 4) {
+ switch (i % 4) {
case 0:
- RE(verify(result, PARENT_SPECIFIED, "fuzzy", 80), 132 + i) break;
+ RE(verify(result, PARENT_SPECIFIED, "fuzzy", 80), i) break;
case 1:
- RE(verify(result, PARENT_SPECIFIED, "fluffy", 80), 132 + i) break;
+ RE(verify(result, PARENT_SPECIFIED, "fluffy", 80), i) break;
case 2:
- RE(verify(result, PARENT_SPECIFIED, "furry", 80), 132 + i) break;
+ RE(verify(result, PARENT_SPECIFIED, "furry", 80), i) break;
case 3:
- RE(verify(result, PARENT_SPECIFIED, "frisky", 80), 132 + i) break;
+ RE(verify(result, PARENT_SPECIFIED, "frisky", 80), i) break;
default:
ink_assert(0);
}
@@ -1284,14 +1301,15 @@ verify(ParentResult * r, ParentResultType e, const char *h, int p)
// br creates an HttpRequestData object
void
-br(HttpRequestData * h, const char *os_hostname, int dest_ip)
+br(HttpRequestData * h, const char *os_hostname, sockaddr const* dest_ip)
{
h->hdr = new HTTPHdr();
h->hdr->create(HTTP_TYPE_REQUEST);
h->hostname_str = (char *)ats_strdup(os_hostname);
h->xact_start = time(NULL);
- h->src_ip = 0;
- h->dest_ip = dest_ip;
+ ink_zero(h->src_ip);
+ ink_zero(h->dest_ip);
+ ink_inet_copy(&h->dest_ip.sa, dest_ip);
h->incoming_port = 80;
h->api_info = new _HttpApiInfo();
}
View
2 proxy/ParentSelection.h
@@ -212,7 +212,7 @@ int parentSelection_CB(const char *name, RecDataT data_type, RecData data, void
// Unit Test Functions
void show_result(ParentResult *aParentResult);
-void br(HttpRequestData *h, const char *os_hostname, int dest_ip = 0); // short for build request
+void br(HttpRequestData *h, const char *os_hostname, sockaddr const* dest_ip = NULL); // short for build request
int verify(ParentResult *r, ParentResultType e, const char *h, int p);
/*
View
141 proxy/Prefetch.cc
@@ -78,6 +78,9 @@ KeepAliveConnTable *g_conn_table;
static int prefetch_udp_fd = 0;
static int32_t udp_seq_no;
+PrefetchBlastData const UDP_BLAST_DATA = { UDP_BLAST };
+PrefetchBlastData const TCP_BLAST_DATA = { TCP_BLAST };
+
static inline uint32_t
get_udp_seq_no()
{
@@ -307,9 +310,9 @@ PrefetchTransform::PrefetchTransform(HttpSM *sm, HTTPHdr *resp)
memset(&hash_table[0], 0, HASH_TABLE_LENGTH * sizeof(hash_table[0]));
udp_url_list = blasterUrlListAllocator.alloc();
- udp_url_list->init(UDP_BLAST, prefetch_config.url_buffer_timeout, prefetch_config.url_buffer_size);
+ udp_url_list->init(UDP_BLAST_DATA, prefetch_config.url_buffer_timeout, prefetch_config.url_buffer_size);
tcp_url_list = blasterUrlListAllocator.alloc();
- tcp_url_list->init(TCP_BLAST, prefetch_config.url_buffer_timeout, prefetch_config.url_buffer_size);
+ tcp_url_list->init(TCP_BLAST_DATA, prefetch_config.url_buffer_timeout, prefetch_config.url_buffer_size);
//extract domain
host_start = request->url_get()->host_get(&host_len);
@@ -519,7 +522,7 @@ PrefetchTransform::redirect(HTTPHdr *resp)
}
Debug("PrefetchTransform", "Found embedded URL: %s", redirect_url);
- entry->req_ip = m_sm->t_state.client_info.ip;
+ entry->req_ip = m_sm->t_state.client_info.addr;
PrefetchBlaster *blaster = prefetchBlasterAllocator.alloc();
blaster->init(entry, &m_sm->t_state.hdr_info.client_request, this);
@@ -543,7 +546,7 @@ PrefetchTransform::parse_data(IOBufferReader *reader)
continue;
}
//Debug("PrefetchParserURLs", "Found embedded URL: %s", url_start);
- entry->req_ip = m_sm->t_state.client_info.ip;
+ ink_inet_copy(&entry->req_ip, &m_sm->t_state.client_info.addr);
PrefetchBlaster *blaster = prefetchBlasterAllocator.alloc();
blaster->init(entry, &m_sm->t_state.hdr_info.client_request, this);
@@ -577,17 +580,22 @@ PrefetchTransform::hash_add(char *s)
return *e;
}
-#define IS_RECURSIVE_PREFETCH(req_ip) (prefetch_config.max_recursion > 0 &&\
- (req_ip) == htonl((127<<24)|1))
+
+#define IS_RECURSIVE_PREFETCH(req_ip) \
+ (prefetch_config.max_recursion > 0 && ink_inet_is_loopback(&req_ip))
static void
check_n_attach_prefetch_transform(HttpSM *sm, HTTPHdr *resp, bool from_cache)
{
INKVConnInternal *prefetch_trans;
+ ip_text_buffer client_ipb;
- unsigned int client_ip = sm->t_state.client_info.ip;
+ ts_ip_endpoint client_ip = sm->t_state.client_info.addr;
- Debug("PrefetchParser", "Checking response for request from %u.%u.%u.%u\n", IPSTRARGS(client_ip));
+ // we depend on this to setup @a client_ipb for all subsequent Debug().
+ Debug("PrefetchParser", "Checking response for request from %s\n",
+ ink_inet_ntop(&client_ip, client_ipb, sizeof(client_ipb))
+ );
unsigned int rec_depth = 0;
HTTPHdr *request = &sm->t_state.hdr_info.client_request;
@@ -603,9 +611,9 @@ check_n_attach_prefetch_transform(HttpSM *sm, HTTPHdr *resp, bool from_cache)
"since recursion depth(%d) is greater than max allowed (%d)", rec_depth, prefetch_config.max_recursion);
return;
}
- } else if (!prefetch_config.ip_map.contains(client_ip)) {
- Debug("PrefetchParser", "client (%u.%u.%u.%u) does not match any of the "
- "prefetch_children mentioned in configuration\n", IPSTRARGS(client_ip));
+ } else if (!prefetch_config.ip_map.contains(&client_ip)) {
+ Debug("PrefetchParser", "client (%s) does not match any of the "
+ "prefetch_children mentioned in configuration\n", client_ipb);
return;
}
@@ -646,8 +654,8 @@ check_n_attach_prefetch_transform(HttpSM *sm, HTTPHdr *resp, bool from_cache)
info.client_ip = client_ip;
info.embedded_url = 0;
info.present_in_cache = from_cache;
- info.url_proto = 0;
- info.url_response_proto = 0;
+ ink_zero(info.url_blast);
+ ink_zero(info.url_response_blast);
info.object_buf = 0;
info.object_buf_reader = 0;
@@ -867,35 +875,28 @@ PrefetchUrlBlaster::udpUrlBlaster(int event, void *data)
MIOBuffer *buf = new_MIOBuffer();
IOBufferReader *reader = buf->alloc_reader();
- int udp_hdr_len = (proto == TCP_BLAST) ? 0 : PRELOAD_UDP_HEADER_LEN;
+ int udp_hdr_len = (TCP_BLAST == blast.type) ? 0 : PRELOAD_UDP_HEADER_LEN;
buf->fill(udp_hdr_len + PRELOAD_HEADER_LEN);
writeBuffer(buf);
-
- if (proto == TCP_BLAST) {
+ if (TCP_BLAST == blast.type) {
setup_object_header(reader->start(), reader->read_avail(), true);
g_conn_table->append(url_head->child_ip, buf, reader);
free();
} else {
-
IOBufferBlock *block = buf->get_current_block();
ink_assert(reader->read_avail() == block->read_avail());
setup_udp_header(block->start(), get_udp_seq_no(), 0, true);
setup_object_header(block->start() + PRELOAD_UDP_HEADER_LEN, block->read_avail() - PRELOAD_UDP_HEADER_LEN, true);
- struct sockaddr_in saddr;
- saddr.sin_family = AF_INET;
- saddr.sin_port = htons(prefetch_config.stuffer_port);
- if (url_head->url_multicast_ip)
- saddr.sin_addr.s_addr = url_head->url_multicast_ip;
- else
- saddr.sin_addr.s_addr = url_head->child_ip;
- //saddr.sin_addr.s_addr = htonl((209<<24)|(131<<16)|(60<<8)|243);
- //saddr.sin_addr.s_addr = htonl((209<<24)|(131<<16)|(48<<8)|52);
-
- udpNet.sendto_re(this, NULL, prefetch_udp_fd, (sockaddr *) & saddr, sizeof(saddr), block, block->read_avail());
+ ts_ip_endpoint saddr;
+ ink_inet_copy(&saddr, &url_head->url_multicast_ip) ||
+ ink_inet_copy(&saddr, &url_head->child_ip);
+ ink_inet_port_cast(&saddr.sa) = htons(prefetch_config.stuffer_port);
+
+ udpNet.sendto_re(this, NULL, prefetch_udp_fd, &saddr.sa, sizeof(saddr), block, block->read_avail());
}
break;
}
@@ -994,13 +995,11 @@ PrefetchBlaster::init(PrefetchUrlEntry *entry, HTTPHdr *req_hdr, PrefetchTransfo
const char *ip_str;
if (IS_RECURSIVE_PREFETCH(entry->req_ip) &&
(ip_str = request->value_get(MIME_FIELD_CLIENT_IP, MIME_LEN_CLIENT_IP, &ip_len))) {
+ ip_text_buffer b;
//this is a recursive prefetch. get child ip address from
//Client-IP header
-
- char ip_buf[16];
- ink_strlcpy(ip_buf, ip_str, sizeof(ip_buf));
-
- entry->child_ip = inet_addr(ip_buf);
+ ink_strlcpy(b, ip_str, sizeof(b));
+ ink_inet_pton(b, &entry->child_ip.sa);
} else
entry->child_ip = entry->req_ip;
@@ -1634,7 +1633,7 @@ PrefetchBlaster::blastObject(int event, void *data)
break;
}
- if (data_proto == TCP_BLAST) {
+ if (data_blast.type == TCP_BLAST) {
g_conn_table->append(url_ent->child_ip, buf, reader);
buf = 0;
free();
@@ -1673,15 +1672,18 @@ PrefetchBlaster::blastObject(int event, void *data)
setup_udp_header(io_block->start(), seq_no, n_pkts_sent++, (towrite >= nread_avail));
- struct sockaddr_in saddr;
- saddr.sin_family = AF_INET;
- saddr.sin_port = htons(prefetch_config.stuffer_port);
- saddr.sin_addr.s_addr = (url_ent->data_multicast_ip) ? url_ent->data_multicast_ip : url_ent->child_ip;
+ ts_ip_endpoint saddr;
+ ink_inet_copy(&saddr.sa,
+ ink_inet_is_ip(&url_ent->data_multicast_ip)
+ ? &url_ent->data_multicast_ip.sa
+ : &url_ent->child_ip.sa
+ );
+ ink_inet_port_cast(&saddr) = htons(prefetch_config.stuffer_port);
//saddr.sin_addr.s_addr = htonl((209<<24)|(131<<16)|(60<<8)|243);
//saddr.sin_addr.s_addr = htonl((209<<24)|(131<<16)|(48<<8)|52);
- udpNet.sendto_re(this, NULL, prefetch_udp_fd, (sockaddr *) & saddr, sizeof(saddr), io_block, io_block->read_avail());
+ udpNet.sendto_re(this, NULL, prefetch_udp_fd, &saddr.sa, sizeof(saddr), io_block, io_block->read_avail());
}
break;
@@ -1700,8 +1702,8 @@ PrefetchBlaster::invokeBlaster()
int ret = (cache_http_info && !prefetch_config.push_cached_objects)
? TS_PREFETCH_DISCONTINUE : TS_PREFETCH_CONTINUE;
- unsigned int url_proto = prefetch_config.default_url_proto;
- data_proto = prefetch_config.default_data_proto;
+ PrefetchBlastData url_blast = prefetch_config.default_url_blast;
+ data_blast = prefetch_config.default_data_blast;
if (prefetch_config.embedded_url_hook) {
@@ -1719,27 +1721,27 @@ PrefetchBlaster::invokeBlaster()
info.client_ip = url_ent->child_ip;
info.embedded_url = url_ent->url;
info.present_in_cache = (cache_http_info != NULL);
- info.url_proto = url_proto;
- info.url_response_proto = data_proto;
+ info.url_blast = url_blast;
+ info.url_response_blast = data_blast;
ret = (*prefetch_config.embedded_url_hook)
(TS_PREFETCH_EMBEDDED_URL_HOOK, &info);
- url_proto = info.url_proto;
- data_proto = info.url_response_proto;
+ url_blast = info.url_blast;
+ data_blast = info.url_response_blast;
url_ent->object_buf_status = info.object_buf_status;
}
if (ret == TS_PREFETCH_CONTINUE) {
- if (url_proto != TCP_BLAST && url_proto != UDP_BLAST)
- url_ent->url_multicast_ip = url_proto;
- if (data_proto != TCP_BLAST && data_proto != UDP_BLAST)
- url_ent->data_multicast_ip = data_proto;
+ if (MULTICAST_BLAST == url_blast.type)
+ ink_inet_copy(&url_ent->url_multicast_ip.sa, &url_blast.ip.sa);
+ if (MULTICAST_BLAST == data_blast.type)
+ ink_inet_copy(&url_ent->data_multicast_ip.sa, &data_blast.ip.sa);
if (url_ent->object_buf_status != TS_PREFETCH_OBJ_BUF_NEEDED) {
- if (url_proto == TCP_BLAST)
+ if (url_blast.type == TCP_BLAST)
url_list = transform->tcp_url_list;
else
url_list = transform->udp_url_list;
@@ -1781,23 +1783,22 @@ PrefetchBlaster::initCacheLookupConfig()
}
static int
-config_read_proto(unsigned int &proto, const char *str)
+config_read_proto(PrefetchBlastData &blast, const char *str)
{
if (strncasecmp(str, "udp", 3) == 0)
- proto = UDP_BLAST;
+ blast.type = UDP_BLAST;
else if (strncasecmp(str, "tcp", 3) == 0)
- proto = TCP_BLAST;
+ blast.type = TCP_BLAST;
else { // this is a multicast address:
if (strncasecmp("multicast:", str, 10) == 0) {
- unsigned int ip[4];
- // coverity[secure_coding]
- if (sscanf(str + 10, "%u.%u.%u.%u", &ip[0], &ip[1], &ip[2], &ip[3]) < 4) {
+ if (0 != ink_inet_pton(str, &blast.ip.sa)) {
Error("PrefetchProcessor: Address specified for multicast does not seem to "
"be of the form multicast:ip_addr (eg: multicast:224.0.0.1)");
return 1;
} else {
- proto = htonl(((ip[0] & 0xff) << 24) | ((ip[1] & 0xff) << 16) | ((ip[2] & 0xff) << 8) | (ip[3] & 0xff));
- Debug("Prefetch", "Setting multicast address: %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);
+ ip_text_buffer ipb;
+ blast.type = MULTICAST_BLAST;
+ Debug("Prefetch", "Setting multicast address: %s\n", ink_inet_ntop(&blast.ip.sa, ipb, sizeof(ipb)));
}
} else {
Error("PrefetchProcessor: The protocol for Prefetch should of the form: " "tcp or udp or multicast:ip_address");
@@ -1839,11 +1840,11 @@ PrefetchConfiguration::readConfiguration()
TS_ReadConfigInteger(redirection, "proxy.config.prefetch.redirection");
char *tstr = TS_ConfigReadString("proxy.config.prefetch.default_url_proto");
- if (config_read_proto(default_url_proto, tstr))
+ if (config_read_proto(default_url_blast, tstr))
goto Lerror;
tstr = TS_ConfigReadString("proxy.config.prefetch.default_data_proto");
- if (config_read_proto(default_data_proto, tstr))
+ if (config_read_proto(default_data_blast, tstr))
goto Lerror;
//pre_parse_hook = 0;
@@ -1956,11 +1957,9 @@ PrefetchConfiguration::readHtmlTags(int fd, html_tag ** ptags, html_tag ** pattr
#define CONN_ARR_SIZE 256
inline int
-KeepAliveConnTable::ip_hash(unsigned int ip)
+KeepAliveConnTable::ip_hash(ts_ip_endpoint const& ip)
{
- unsigned char *ip_str = (unsigned char *) &ip;
-
- return (ip_str[0] ^ ip_str[1] ^ ip_str[2] ^ ip_str[3]) & (CONN_ARR_SIZE - 1);
+ return ink_inet_hash(&ip.sa) & (CONN_ARR_SIZE - 1);
}
inline int
@@ -2002,7 +2001,7 @@ KeepAliveConnTable::free()
ClassAllocator<KeepAliveLockHandler> prefetchLockHandlerAllocator("prefetchLockHandlerAllocator");
int
-KeepAliveConnTable::append(unsigned int ip, MIOBuffer *buf, IOBufferReader *reader)
+KeepAliveConnTable::append(ts_ip_endpoint const& ip, MIOBuffer *buf, IOBufferReader *reader)
{
int index = ip_hash(ip);
@@ -2022,7 +2021,7 @@ KeepAliveConnTable::append(unsigned int ip, MIOBuffer *buf, IOBufferReader *read
KeepAliveConn **conn = &arr[index].conn;
- while (*conn && (*conn)->ip != ip)
+ while (*conn && ! ink_inet_eq(&(*conn)->ip, &ip))
conn = &(*conn)->next;
if (*conn) {
@@ -2037,7 +2036,7 @@ KeepAliveConnTable::append(unsigned int ip, MIOBuffer *buf, IOBufferReader *read
}
int
-KeepAliveConn::init(unsigned int xip, MIOBuffer *xbuf, IOBufferReader *xreader)
+KeepAliveConn::init(ts_ip_endpoint const& xip, MIOBuffer *xbuf, IOBufferReader *xreader)
{
mutex = g_conn_table->arr[KeepAliveConnTable::ip_hash(xip)].mutex;
@@ -2056,7 +2055,7 @@ KeepAliveConn::init(unsigned int xip, MIOBuffer *xbuf, IOBufferReader *xreader)
SET_HANDLER(&KeepAliveConn::handleEvent);
//we are already under lock
- netProcessor.connect_re(this, ip, prefetch_config.stuffer_port);
+ netProcessor.connect_re(this, &ip.sa);
return 0;
}
@@ -2094,6 +2093,8 @@ KeepAliveConn::free()
int
KeepAliveConn::handleEvent(int event, void *data)
{
+ ip_text_buffer ipb;
+
switch (event) {
case NET_EVENT_OPEN:
@@ -2109,7 +2110,7 @@ KeepAliveConn::handleEvent(int event, void *data)
break;
case NET_EVENT_OPEN_FAILED:
- Debug("PrefetchKeepAlive", "Connection to child %u.%u.%u.%u failed\n", IPSTRARGS(ip));
+ Debug("PrefetchKeepAlive", "Connection to child %s failed\n", ink_inet_ntop(&ip.sa, ipb, sizeof(ipb)));
free();
break;
@@ -2138,7 +2139,7 @@ KeepAliveConn::handleEvent(int event, void *data)
break;
case VC_EVENT_ERROR:
- Debug("PrefetchKeepAlive", "got VC_ERROR.. connection problem? " "(ip: %u.%u.%u.%u)", IPSTRARGS(ip));
+ Debug("PrefetchKeepAlive", "got VC_ERROR.. connection problem? " "(ip: %s)", ink_inet_ntop(&ip.sa, ipb, sizeof(ipb)));
free();
break;
View
87 proxy/Prefetch.h
@@ -33,19 +33,6 @@
#include "api/ts/experimental.h"
#include "api/ts/InkAPIHughes.h"
-#define IPSTRARGS(ip) (unsigned int) ((unsigned char *) &(ip))[0], \
- (unsigned int) ((unsigned char *) &(ip))[1], \
- (unsigned int) ((unsigned char *) &(ip))[2], \
- (unsigned int) ((unsigned char *) &(ip))[3]
-
-typedef enum
-{
- ILL_BLAST = 0,
- UDP_BLAST = TS_PREFETCH_PROTO_UDP,
- TCP_BLAST = TS_PREFETCH_PROTO_TCP
- //MULTICAST_BLAST = TS_PREFETCH_PROTO_UDP_MULTICAST
-} PrefetchBlastType;
-
class BlasterUrlList;
class PrefetchUrlBlaster;
class PrefetchBlaster;
@@ -64,8 +51,8 @@ struct PrefetchConfiguration
int url_buffer_size;
int url_buffer_timeout;
- unsigned int default_url_proto;
- unsigned int default_data_proto;
+ PrefetchBlastData default_url_blast;
+ PrefetchBlastData default_data_blast;
int keepalive_timeout;
int push_cached_objects;
@@ -90,8 +77,12 @@ class PrefetchUrlEntry: public RefCountObj
PrefetchUrlEntry()
: url(0), len(INT_MAX), resp_blaster(0),
object_buf_status(TS_PREFETCH_OBJ_BUF_NOT_NEEDED),
- req_ip(0), child_ip(0), url_multicast_ip(0), data_multicast_ip(0), blaster_link(0), hash_link(0)
+ blaster_link(0), hash_link(0)
{
+ ink_zero(req_ip);
+ ink_zero(child_ip);
+ ink_zero(url_multicast_ip);
+ ink_zero(data_multicast_ip);
refcount_inc();
}
@@ -112,16 +103,14 @@ class PrefetchUrlEntry: public RefCountObj
int len;
INK_MD5 md5;
- //PrefetchBlastType resp_blast_proto;
- //HTTPHdr * request;
PrefetchBlaster *resp_blaster;
int object_buf_status;
- uint32_t req_ip; /*ip address where request is coming from */
- uint32_t child_ip;
- uint32_t url_multicast_ip;
- uint32_t data_multicast_ip;
+ ts_ip_endpoint req_ip; /*ip address where request is coming from */
+ ts_ip_endpoint child_ip;
+ ts_ip_endpoint url_multicast_ip;
+ ts_ip_endpoint data_multicast_ip;
PrefetchUrlEntry *blaster_link;
PrefetchUrlEntry *hash_link;
@@ -176,12 +165,9 @@ class PrefetchTransform:public INKVConnInternal, public RefCountObj
VIO *m_output_vio;
HttpSM *m_sm;
- //HTTPHdr *m_request;
- //HTTPHdr *m_response;
char *url;
- //unsigned int child_ip;
HtmlParser html_parser;
PrefetchUrlEntry *hash_table[HASH_TABLE_LENGTH];
@@ -196,6 +182,8 @@ class PrefetchTransform:public INKVConnInternal, public RefCountObj
bool no_dot_in_host;
};
+extern PrefetchBlastData const UDP_BLAST_DATA;
+extern PrefetchBlastData const TCP_BLAST_DATA;
//blaster
class BlasterUrlList:public Continuation
@@ -204,20 +192,20 @@ class BlasterUrlList:public Continuation
int timeout; //in milliseconds
Action *action;
int mtu;
- PrefetchBlastType blast_proto;
+ PrefetchBlastData blast;
PrefetchUrlEntry *list_head;
int cur_len;
public:
BlasterUrlList()
- : Continuation(), timeout(0), action(0), mtu(0), blast_proto(ILL_BLAST), list_head(0), cur_len(0)
+ : Continuation(), timeout(0), action(0), mtu(0), list_head(0), cur_len(0)
{ }
- void init(PrefetchBlastType btype = UDP_BLAST, int tout = 0, int xmtu = INT_MAX) {
+ void init(PrefetchBlastData const& bdata = UDP_BLAST_DATA, int tout = 0, int xmtu = INT_MAX) {
SET_HANDLER((int (BlasterUrlList::*)(int, void *))(&BlasterUrlList::handleEvent));
mutex = new_ProxyMutex();
- blast_proto = btype;
+ blast = bdata;
timeout = tout;
mtu = xmtu;
}
@@ -243,16 +231,17 @@ class PrefetchUrlBlaster:public Continuation
typedef int (PrefetchUrlBlaster::*EventHandler) (int, void *);
PrefetchUrlBlaster()
- : url_head(0), proto(ILL_BLAST), action(0)
+ : url_head(0), action(0)
{
+ ink_zero(blast);
}
- void init(PrefetchUrlEntry * list_head, PrefetchBlastType u_proto = UDP_BLAST);
+ void init(PrefetchUrlEntry * list_head, PrefetchBlastData const& u_bd = UDP_BLAST_DATA);
void free();
PrefetchUrlEntry *url_head;
- PrefetchBlastType proto;
+ PrefetchBlastData blast;
Action *action;
@@ -265,14 +254,14 @@ class PrefetchUrlBlaster:public Continuation
extern ClassAllocator<PrefetchUrlBlaster> prefetchUrlBlasterAllocator;
void
-PrefetchUrlBlaster::init(PrefetchUrlEntry * list_head, PrefetchBlastType u_proto)
+PrefetchUrlBlaster::init(PrefetchUrlEntry * list_head, PrefetchBlastData const& u_bd)
{
/* More clean up necessary... we should not need this class
XXXXXXXXX */
mutex = new_ProxyMutex();
url_head = list_head;
- proto = u_proto;
+ blast = u_bd;
MUTEX_LOCK(lock, mutex, this_ethread());
@@ -283,7 +272,7 @@ inline void
BlasterUrlList::invokeUrlBlaster()
{
PrefetchUrlBlaster *u_blaster = prefetchUrlBlasterAllocator.alloc();
- u_blaster->init(list_head, blast_proto);
+ u_blaster->init(list_head, blast);
list_head = NULL;
cur_len = 0;
}
@@ -296,7 +285,7 @@ class PrefetchBlaster:public Continuation
PrefetchBlaster()
: Continuation(), url_ent(0), transform(0), url_list(0), request(0),
- cache_http_info(0), buf(0), reader(0), serverVC(0), data_proto(0), n_pkts_sent(0), seq_no(0), io_block(0)
+ cache_http_info(0), buf(0), reader(0), serverVC(0), n_pkts_sent(0), seq_no(0), io_block(0)
{
};
~PrefetchBlaster() {
@@ -330,7 +319,7 @@ class PrefetchBlaster:public Continuation
VConnection *serverVC;
- unsigned int data_proto;
+ PrefetchBlastData data_blast;
CacheLookupHttpConfig cache_lookup_config;
@@ -357,16 +346,16 @@ class KeepAliveConn: public Continuation
public:
KeepAliveConn()
- : Continuation(), ip(0), nbytes_added(0)
- { }
+ : Continuation(), nbytes_added(0)
+ { ink_zero(ip); }
- int init(unsigned int ip, MIOBuffer * buf, IOBufferReader * reader);
+ int init(ts_ip_endpoint const& ip, MIOBuffer * buf, IOBufferReader * reader);
void free();
int append(IOBufferReader * reader);
int handleEvent(int event, void *data);
- unsigned int ip;
+ ts_ip_endpoint ip;
MIOBuffer *buf;
IOBufferReader *reader;
@@ -391,8 +380,8 @@ class KeepAliveConnTable
int init();
void free();
- static int ip_hash(unsigned int ip);
- int append(unsigned int ip, MIOBuffer * buf, IOBufferReader * reader);
+ static int ip_hash(ts_ip_endpoint const& ip);
+ int append(ts_ip_endpoint const& ip, MIOBuffer * buf, IOBufferReader * reader);
typedef struct
{
@@ -410,15 +399,15 @@ class KeepAliveLockHandler: public Continuation
public:
KeepAliveLockHandler()
- :Continuation(), ip(0)
- {
+ :Continuation() {
+ ink_zero(ip);
};
- void init(unsigned int xip, MIOBuffer * xbuf, IOBufferReader * xreader)
+ void init(ts_ip_endpoint const& xip, MIOBuffer * xbuf, IOBufferReader * xreader)
{
- mutex = g_conn_table->arr[KeepAliveConnTable::ip_hash(ip)].mutex;
+ mutex = g_conn_table->arr[KeepAliveConnTable::ip_hash(xip)].mutex;
- ip = xip;
+ ink_inet_copy(&ip, &xip);
buf = xbuf;
reader = xreader;
@@ -432,7 +421,7 @@ class KeepAliveLockHandler: public Continuation
int handleEvent(int event, void *data);
- unsigned int ip;
+ ts_ip_endpoint ip;
MIOBuffer *buf;
IOBufferReader *reader;
};
View
7 proxy/UglyLogStubs.cc
@@ -92,11 +92,8 @@ event_int_to_string(int event, int blen, char *buffer)
return NULL;
}
-
-struct Machine;
-Machine *
-this_machine()
-{
+struct Machine { static Machine* instance(); };
+Machine* Machine::instance() {
ink_release_assert(false);
return NULL;
}
View
32 proxy/api/ts/InkAPIHughes.h
@@ -25,6 +25,20 @@
This file is created for Prefetch API and is used only by Hughes
*/
+/// Type of connection.
+typedef enum
+{
+ ILL_BLAST = 0,
+ UDP_BLAST,
+ TCP_BLAST,
+ MULTICAST_BLAST
+} PrefetchBlastType;
+
+typedef struct {
+ PrefetchBlastType type;
+ ts_ip_endpoint ip;
+} PrefetchBlastData;
+
typedef struct
{
@@ -37,7 +51,7 @@ typedef struct
TSMLoc response_loc;
/*child ip addr in network order */
- unsigned int client_ip;
+ ts_ip_endpoint client_ip;
/*the embedded url parsed by the parser */
const char *embedded_url;
@@ -55,9 +69,13 @@ typedef struct
*/
int object_buf_status;
- /*method of sending data to child */
- unsigned int url_proto;
- unsigned int url_response_proto;
+ /** Method of sending data to child.
+
+ If set to @c MULTICAST_BLAST then the corresponding address
+ value must be set to a multicast address to use.
+ */
+ PrefetchBlastData url_blast;
+ PrefetchBlastData url_response_blast;
} TSPrefetchInfo;