You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by am...@apache.org on 2011/10/05 21:14:09 UTC

svn commit: r1179389 [1/2] - in /trafficserver/traffic/trunk: ./ iocore/dns/ iocore/net/ iocore/utils/ lib/ts/ proxy/ proxy/api/ts/ proxy/congest/ proxy/http/ proxy/http/remap/ proxy/logging/

Author: amc
Date: Wed Oct  5 19:14:07 2011
New Revision: 1179389

URL: http://svn.apache.org/viewvc?rev=1179389&view=rev
Log:
TS-926 - IPv6 conversion of iocore.

Modified:
    trafficserver/traffic/trunk/CHANGES
    trafficserver/traffic/trunk/iocore/dns/P_SplitDNSProcessor.h
    trafficserver/traffic/trunk/iocore/net/SSLNetVConnection.cc
    trafficserver/traffic/trunk/iocore/net/Socks.cc
    trafficserver/traffic/trunk/iocore/utils/I_Machine.h
    trafficserver/traffic/trunk/iocore/utils/Machine.cc
    trafficserver/traffic/trunk/lib/ts/IpMap.cc
    trafficserver/traffic/trunk/lib/ts/IpMap.h
    trafficserver/traffic/trunk/lib/ts/IpMapConf.cc
    trafficserver/traffic/trunk/lib/ts/ink_inet.cc
    trafficserver/traffic/trunk/lib/ts/ink_inet.h
    trafficserver/traffic/trunk/lib/ts/ink_memory.h
    trafficserver/traffic/trunk/proxy/ControlBase.cc
    trafficserver/traffic/trunk/proxy/ControlMatcher.cc
    trafficserver/traffic/trunk/proxy/ControlMatcher.h
    trafficserver/traffic/trunk/proxy/IPAllow.cc
    trafficserver/traffic/trunk/proxy/InkAPI.cc
    trafficserver/traffic/trunk/proxy/Main.cc
    trafficserver/traffic/trunk/proxy/ParentSelection.cc
    trafficserver/traffic/trunk/proxy/ParentSelection.h
    trafficserver/traffic/trunk/proxy/Prefetch.cc
    trafficserver/traffic/trunk/proxy/Prefetch.h
    trafficserver/traffic/trunk/proxy/UglyLogStubs.cc
    trafficserver/traffic/trunk/proxy/api/ts/InkAPIHughes.h
    trafficserver/traffic/trunk/proxy/congest/Congestion.cc
    trafficserver/traffic/trunk/proxy/congest/Congestion.h
    trafficserver/traffic/trunk/proxy/congest/CongestionDB.cc
    trafficserver/traffic/trunk/proxy/congest/CongestionTest.cc
    trafficserver/traffic/trunk/proxy/http/HttpConfig.cc
    trafficserver/traffic/trunk/proxy/http/HttpConfig.h
    trafficserver/traffic/trunk/proxy/http/HttpConnectionCount.h
    trafficserver/traffic/trunk/proxy/http/HttpSM.cc
    trafficserver/traffic/trunk/proxy/http/HttpServerSession.cc
    trafficserver/traffic/trunk/proxy/http/HttpServerSession.h
    trafficserver/traffic/trunk/proxy/http/HttpSessionManager.cc
    trafficserver/traffic/trunk/proxy/http/HttpSessionManager.h
    trafficserver/traffic/trunk/proxy/http/HttpTransact.cc
    trafficserver/traffic/trunk/proxy/http/HttpTransact.h
    trafficserver/traffic/trunk/proxy/http/HttpTransactHeaders.cc
    trafficserver/traffic/trunk/proxy/http/HttpUpdateSM.cc
    trafficserver/traffic/trunk/proxy/http/remap/AclFiltering.cc
    trafficserver/traffic/trunk/proxy/http/remap/AclFiltering.h
    trafficserver/traffic/trunk/proxy/http/remap/RemapProcessor.cc
    trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.cc
    trafficserver/traffic/trunk/proxy/logging/LogAccess.cc
    trafficserver/traffic/trunk/proxy/logging/LogAccessHttp.cc
    trafficserver/traffic/trunk/proxy/logging/LogFile.cc
    trafficserver/traffic/trunk/proxy/logging/LogStandalone.cc
    trafficserver/traffic/trunk/proxy/sac.cc

Modified: trafficserver/traffic/trunk/CHANGES
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/CHANGES?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/CHANGES (original)
+++ trafficserver/traffic/trunk/CHANGES Wed Oct  5 19:14:07 2011
@@ -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.

Modified: trafficserver/traffic/trunk/iocore/dns/P_SplitDNSProcessor.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/dns/P_SplitDNSProcessor.h?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/dns/P_SplitDNSProcessor.h (original)
+++ trafficserver/traffic/trunk/iocore/dns/P_SplitDNSProcessor.h Wed Oct  5 19:14:07 2011
@@ -197,8 +197,8 @@ public:
 
   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;
 }
 
 /* --------------------------------------------------------------

Modified: trafficserver/traffic/trunk/iocore/net/SSLNetVConnection.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/net/SSLNetVConnection.cc?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/net/SSLNetVConnection.cc (original)
+++ trafficserver/traffic/trunk/iocore/net/SSLNetVConnection.cc Wed Oct  5 19:14:07 2011
@@ -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;

Modified: trafficserver/traffic/trunk/iocore/net/Socks.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/net/Socks.cc?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/net/Socks.cc (original)
+++ trafficserver/traffic/trunk/iocore/net/Socks.cc Wed Oct  5 19:14:07 2011
@@ -63,10 +63,10 @@ SocksEntry::init(ProxyMutex * m, SocksNe
   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

Modified: trafficserver/traffic/trunk/iocore/utils/I_Machine.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/utils/I_Machine.h?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/utils/I_Machine.h (original)
+++ trafficserver/traffic/trunk/iocore/utils/I_Machine.h Wed Oct  5 19:14:07 2011
@@ -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.
 };
 
 /**

Modified: trafficserver/traffic/trunk/iocore/utils/Machine.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/utils/Machine.cc?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/utils/Machine.cc (original)
+++ trafficserver/traffic/trunk/iocore/utils/Machine.cc Wed Oct  5 19:14:07 2011
@@ -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.
 
-// 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()");
+    *dst++ = n1 > 9 ? n1 + 'A' - 10 : n1 + '0';
+    *dst++ = n0 > 9 ? n0 + 'A' - 10 : n0 + '0';
   }
-  return machine;
+  *dst = 0; // terminate but don't include that in the length.
+  return zret;
 }
 
-void
-create_this_machine(char *hostname, unsigned int ip)
-{
-  machine = NEW(new Machine(hostname, ip));
+Machine*
+Machine::instance() {
+  ink_assert(_instance || !"Machine instance accessed before initialization");
+  return Machine::_instance;
 }
 
-Machine::Machine(char *ahostname, unsigned int aip)
-  : hostname(ahostname), ip(aip)
+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 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;
+  ip_string[0] = 0;
+  ip_hex_string[0] = 0;
+  ink_zero(ip);
+  ink_zero(ip4);
+  ink_zero(ip6);
+
+  localhost[sizeof(localhost)-1] = 0; // ensure termination.
+
+  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(ahostname);
-
-    ink_gethostbyname_r_data data;
-    struct hostent *r = ink_gethostbyname_r(ahostname, &data);
+    hostname = ats_strdup(the_hostname);
 
-    if (!r) {
-      Warning("unable to DNS %s: %d", ahostname, data.herrno);
-      ip = 0;
+    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];
-
-  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]);
-  ip_string_len = strlen(ip_string);
+  hostname_len = hostname ? strlen(hostname) : 0;
 
-  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);
+  ink_inet_ntop(&ip.sa, ip_string, sizeof(ip_string));
+  ip_string_len = strlen(ip_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);
 }

Modified: trafficserver/traffic/trunk/lib/ts/IpMap.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/lib/ts/IpMap.cc?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/lib/ts/IpMap.cc (original)
+++ trafficserver/traffic/trunk/lib/ts/IpMap.cc Wed Oct  5 19:14:07 2011
@@ -1036,11 +1036,11 @@ IpMap::contains(sockaddr const* target, 
   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;

Modified: trafficserver/traffic/trunk/lib/ts/IpMap.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/lib/ts/IpMap.h?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/lib/ts/IpMap.h (original)
+++ trafficserver/traffic/trunk/lib/ts/IpMap.h Wed Oct  5 19:14:07 2011
@@ -363,22 +363,22 @@ public:
 
   /** 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 @@ public:
     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
   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

Modified: trafficserver/traffic/trunk/lib/ts/IpMapConf.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/lib/ts/IpMapConf.cc?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/lib/ts/IpMapConf.cc (original)
+++ trafficserver/traffic/trunk/lib/ts/IpMapConf.cc Wed Oct  5 19:14:07 2011
@@ -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
 {
   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
     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
           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);

Modified: trafficserver/traffic/trunk/lib/ts/ink_inet.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/lib/ts/ink_inet.cc?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/lib/ts/ink_inet.cc (original)
+++ trafficserver/traffic/trunk/lib/ts/ink_inet.cc Wed Oct  5 19:14:07 2011
@@ -243,7 +243,7 @@ int ink_inet_pton(char const* text, sock
     }
   }
 
-  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, sock
   }
   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;
+}

Modified: trafficserver/traffic/trunk/lib/ts/ink_inet.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/lib/ts/ink_inet.h?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/lib/ts/ink_inet.h (original)
+++ trafficserver/traffic/trunk/lib/ts/ink_inet.h Wed Oct  5 19:14:07 2011
@@ -244,7 +244,7 @@ inline sockaddr_in6 const& ink_inet_ip6_
   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_c
     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

Modified: trafficserver/traffic/trunk/lib/ts/ink_memory.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/lib/ts/ink_memory.h?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/lib/ts/ink_memory.h (original)
+++ trafficserver/traffic/trunk/lib/ts/ink_memory.h Wed Oct  5 19:14:07 2011
@@ -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

Modified: trafficserver/traffic/trunk/proxy/ControlBase.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/ControlBase.cc?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/ControlBase.cc (original)
+++ trafficserver/traffic/trunk/proxy/ControlBase.cc Wed Oct  5 19:14:07 2011
@@ -250,8 +250,8 @@ IPortMod::make(char* value, char const *
 // ----------
 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::ty
 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;

Modified: trafficserver/traffic/trunk/proxy/ControlMatcher.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/ControlMatcher.cc?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/ControlMatcher.cc (original)
+++ trafficserver/traffic/trunk/proxy/ControlMatcher.cc Wed Oct  5 19:14:07 2011
@@ -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 
   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 
   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 
     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 
 // 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)) {

Modified: trafficserver/traffic/trunk/proxy/ControlMatcher.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/ControlMatcher.h?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/ControlMatcher.h (original)
+++ trafficserver/traffic/trunk/proxy/ControlMatcher.h Wed Oct  5 19:14:07 2011
@@ -121,9 +121,9 @@ public:
   }
   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
 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();

Modified: trafficserver/traffic/trunk/proxy/IPAllow.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/IPAllow.cc?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/IPAllow.cc (original)
+++ trafficserver/traffic/trunk/proxy/IPAllow.cc Wed Oct  5 19:14:07 2011
@@ -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 {

Modified: trafficserver/traffic/trunk/proxy/InkAPI.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/InkAPI.cc?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/InkAPI.cc (original)
+++ trafficserver/traffic/trunk/proxy/InkAPI.cc Wed Oct  5 19:14:07 2011
@@ -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
   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,
   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,
   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 requ
   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);

Modified: trafficserver/traffic/trunk/proxy/Main.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/Main.cc?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/Main.cc (original)
+++ trafficserver/traffic/trunk/proxy/Main.cc Wed Oct  5 19:14:07 2011
@@ -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)

Modified: trafficserver/traffic/trunk/proxy/ParentSelection.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/ParentSelection.cc?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/ParentSelection.cc (original)
+++ trafficserver/traffic/trunk/proxy/ParentSelection.cc Wed Oct  5 19:14:07 2011
@@ -509,7 +509,15 @@ ParentRecord::FindParent(bool first_call
         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, i
 }
 
 
-#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(PARENTSELECTIO
       (!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(PARENTSELECTIO
     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(PARENTSELECTIO
     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(PARENTSELECTIO
   // 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, ParentResultTyp
 
 // 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();
 }

Modified: trafficserver/traffic/trunk/proxy/ParentSelection.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/ParentSelection.h?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/ParentSelection.h (original)
+++ trafficserver/traffic/trunk/proxy/ParentSelection.h Wed Oct  5 19:14:07 2011
@@ -212,7 +212,7 @@ int parentSelection_CB(const char *name,
 
 // 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);
 
 /*

Modified: trafficserver/traffic/trunk/proxy/Prefetch.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/Prefetch.cc?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/Prefetch.cc (original)
+++ trafficserver/traffic/trunk/proxy/Prefetch.cc Wed Oct  5 19:14:07 2011
@@ -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(Htt
   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 *res
       }
 
       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(IOBufferRe
       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
             "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
     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 ev
       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);
+        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, (sockaddr *) & saddr, sizeof(saddr), block, block->read_avail());
+        udpNet.sendto_re(this, NULL, prefetch_udp_fd, &saddr.sa, sizeof(saddr), block, block->read_avail());
       }
       break;
     }
@@ -994,13 +995,11 @@ PrefetchBlaster::init(PrefetchUrlEntry *
   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, 
       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, 
 
       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 
 
 #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 
 
   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 
 }
 
 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, MI
   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, vo
     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, vo
     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;
 

Modified: trafficserver/traffic/trunk/proxy/Prefetch.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/Prefetch.h?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/Prefetch.h (original)
+++ trafficserver/traffic/trunk/proxy/Prefetch.h Wed Oct  5 19:14:07 2011
@@ -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 @@ public:
   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 @@ public:
   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 @@ public:
   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 @@ public:
   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 @@ public:
   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 @@ public:
 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 @@ public:
 
     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 @@ public:
 
   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 @@ public:
 
   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 Conti
 
 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 @@ public:
 
   int handleEvent(int event, void *data);
 
-  unsigned int ip;
+  ts_ip_endpoint ip;
   MIOBuffer *buf;
   IOBufferReader *reader;
 };

Modified: trafficserver/traffic/trunk/proxy/UglyLogStubs.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/UglyLogStubs.cc?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/UglyLogStubs.cc (original)
+++ trafficserver/traffic/trunk/proxy/UglyLogStubs.cc Wed Oct  5 19:14:07 2011
@@ -92,11 +92,8 @@ event_int_to_string(int event, int blen,
   return NULL;
 }
 
-
-struct Machine;
-Machine *
-this_machine()
-{
+struct Machine {  static Machine* instance(); };
+Machine* Machine::instance() {
   ink_release_assert(false);
   return NULL;
 }

Modified: trafficserver/traffic/trunk/proxy/api/ts/InkAPIHughes.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/api/ts/InkAPIHughes.h?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/api/ts/InkAPIHughes.h (original)
+++ trafficserver/traffic/trunk/proxy/api/ts/InkAPIHughes.h Wed Oct  5 19:14:07 2011
@@ -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;
 
@@ -71,12 +89,6 @@ enum
 
 enum
 {
-  TS_PREFETCH_PROTO_TCP = 1,
-  TS_PREFETCH_PROTO_UDP
-};
-
-enum
-{
   TS_PREFETCH_OBJ_BUF_NOT_NEEDED = 0,
   TS_PREFETCH_OBJ_BUF_NEEDED,  /* The user wants the buffer but does not
                                    want it to be transmitted to the child */

Modified: trafficserver/traffic/trunk/proxy/congest/Congestion.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/congest/Congestion.cc?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/congest/Congestion.cc (original)
+++ trafficserver/traffic/trunk/proxy/congest/Congestion.cc Wed Oct  5 19:14:07 2011
@@ -455,7 +455,7 @@ CongestionControlled(RD * rdata)
 }
 
 uint64_t
-make_key(char *hostname, unsigned long ip, CongestionControlRecord * record)
+make_key(char *hostname, sockaddr const* ip, CongestionControlRecord * record)
 {
   int host_len = 0;
   if (hostname) {
@@ -465,7 +465,7 @@ make_key(char *hostname, unsigned long i
 }
 
 uint64_t
-make_key(char *hostname, int len, unsigned long ip, CongestionControlRecord * record)
+make_key(char *hostname, int len, sockaddr const* ip, CongestionControlRecord * record)
 {
   INK_MD5 md5;
 #ifdef USE_MMH
@@ -474,7 +474,7 @@ make_key(char *hostname, int len, unsign
   if (record->congestion_scheme == PER_HOST && len > 0)
     ink_code_incr_MMH_update(&ctx, hostname, len);
   else
-    ink_code_incr_MMH_update(&ctx, (char *) &ip, sizeof(ip));
+    ink_code_incr_MMH_update(&ctx, reinterpret_cast<char const*>(ink_inet_addr8_cast(ip)), ink_inet_addr_size(ip));
   if (record->port != 0) {
     unsigned short p = port;
     p = htons(p);
@@ -490,7 +490,7 @@ make_key(char *hostname, int len, unsign
   if (record->congestion_scheme == PER_HOST && len > 0)
     ink_code_incr_md5_update(&ctx, hostname, len);
   else
-    ink_code_incr_md5_update(&ctx, (char *) &ip, sizeof(ip));
+    ink_code_incr_md5_update(&ctx, reinterpret_cast<char const*>(ink_inet_addr8_cast(ip)), ink_inet_addr_size(ip));
   if (record->port != 0) {
     unsigned short p = record->port;
     p = htons(p);
@@ -505,7 +505,7 @@ make_key(char *hostname, int len, unsign
 }
 
 uint64_t
-make_key(char *hostname, int len, unsigned long ip, char *prefix, int prelen, short port)
+make_key(char *hostname, int len, sockaddr const* ip, char *prefix, int prelen, short port)
 {
   /* if the hostname != NULL, use hostname, else, use ip */
   INK_MD5 md5;
@@ -515,7 +515,7 @@ make_key(char *hostname, int len, unsign
   if (hostname && len > 0)
     ink_code_incr_MMH_update(&ctx, hostname, len);
   else
-    ink_code_incr_MMH_update(&ctx, (char *) &ip, sizeof(ip));
+    ink_code_incr_MMH_update(&ctx, reinterpret_cast<char const*>(ink_inet_addr8_cast(ip)), ink_inet_addr_size(ip));
   if (port != 0) {
     unsigned short p = port;
     p = htons(p);
@@ -531,7 +531,7 @@ make_key(char *hostname, int len, unsign
   if (hostname && len > 0)
     ink_code_incr_md5_update(&ctx, hostname, len);
   else
-    ink_code_incr_md5_update(&ctx, (char *) &ip, sizeof(ip));
+    ink_code_incr_md5_update(&ctx, reinterpret_cast<char const*>(ink_inet_addr8_cast(ip)), ink_inet_addr_size(ip));
   if (port != 0) {
     unsigned short p = port;
     p = htons(p);
@@ -608,14 +608,17 @@ FailHistory::regist_event(long t, int n)
 //----------------------------------------------------------
 // CongestionEntry Implementation
 //----------------------------------------------------------
-CongestionEntry::CongestionEntry(const char *hostname, in_addr_t ip, CongestionControlRecord * rule, uint64_t key)
+CongestionEntry::CongestionEntry(const char *hostname, sockaddr const* ip, CongestionControlRecord * rule, uint64_t key)
 :m_key(key),
-m_ip(ip),
 m_last_congested(0),
 m_congested(0),
 m_stat_congested_conn_failures(0),
 m_M_congested(0), m_last_M_congested(0), m_num_connections(0), m_stat_congested_max_conn(0), m_ref_count(1)
 {
+  memset(&m_ip, 0, sizeof(m_ip));
+  if (ip != NULL) {
+    ink_inet_copy(&m_ip.sa, ip);
+  }
   m_hostname = ats_strdup(hostname);
   rule->get();
   pRecord = rule;
@@ -648,7 +651,7 @@ CongestionEntry::validate()
   }
 
   uint64_t key = make_key(m_hostname,
-                        m_ip,
+                        &m_ip.sa,
                         p);
   if (key != m_key) {
     return false;
@@ -696,8 +699,8 @@ CongestionEntry::applyNewRule(Congestion
 int
 CongestionEntry::sprint(char *buf, int buflen, int format)
 {
-  struct in_addr addr;
   char str_time[100] = " ";
+  char addrbuf[INET6_ADDRSTRLEN];
   int len = 0;
   ink_hrtime timestamp = 0;
   char state;
@@ -711,7 +714,7 @@ CongestionEntry::sprint(char *buf, int b
   len += snprintf(buf + len, buflen - len, "%" PRId64 "|%d|%s|%s",
                       timestamp,
                       pRecord->line_num,
-                      (m_hostname ? m_hostname : " "), (m_ip ? (addr.s_addr = htonl(m_ip), inet_ntoa(addr)) : " "));
+                      (m_hostname ? m_hostname : " "), (ink_inet_is_ip(&m_ip) ? ink_inet_ntop(&m_ip.sa, addrbuf, sizeof(addrbuf)) : " "));
 
   len += snprintf(buf + len, buflen - len, "|%s|%s|%c",
                       (pRecord->congestion_scheme == PER_IP ? "per_ip" : "per_host"),

Modified: trafficserver/traffic/trunk/proxy/congest/Congestion.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/congest/Congestion.h?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/congest/Congestion.h (original)
+++ trafficserver/traffic/trunk/proxy/congest/Congestion.h Wed Oct  5 19:14:07 2011
@@ -202,7 +202,7 @@ struct CongestionEntry: public RequestDa
   // key in the hash table;
   uint64_t m_key;
   // host info
-  in_addr_t m_ip;
+  ts_ip_endpoint m_ip;
   char *m_hostname;
 
   // Pointer to the congestion.config entry
@@ -226,7 +226,7 @@ struct CongestionEntry: public RequestDa
   // Reference count
   int m_ref_count;
 
-    CongestionEntry(const char *hostname, in_addr_t ip, CongestionControlRecord * rule, uint64_t key);
+    CongestionEntry(const char *hostname, sockaddr const* ip, CongestionControlRecord * rule, uint64_t key);
     CongestionEntry();
     virtual ~ CongestionEntry();
 
@@ -239,13 +239,13 @@ struct CongestionEntry: public RequestDa
   {
     return m_hostname;
   }
-  virtual in_addr_t get_ip()
+  virtual sockaddr const* get_ip()
   {
-    return m_ip;
+    return &m_ip.sa;
   }
-  virtual in_addr_t get_client_ip()
+  virtual const sockaddr* get_client_ip()
   {
-    return (in_addr_t) 0;
+    return NULL;
   }
   virtual RD_Type data_type(void)
   {
@@ -410,11 +410,12 @@ CongestionEntry::clearFailHistory()
 }
 
 inline CongestionEntry::CongestionEntry()
-:m_key(0), m_ip(0), m_hostname(NULL), pRecord(NULL),
+:m_key(0), m_hostname(NULL), pRecord(NULL),
 m_last_congested(0), m_congested(0),
 m_stat_congested_conn_failures(0),
 m_M_congested(0), m_last_M_congested(0), m_num_connections(0), m_stat_congested_max_conn(0), m_ref_count(1)
 {
+  memset(&m_ip, 0, sizeof(m_ip));
   m_hist_lock = new_ProxyMutex();
 }
 
@@ -451,9 +452,9 @@ void initCongestionControl();
 CongestionControlRecord *CongestionControlled(RD * rdata);
 void reloadCongestionControl();
 
-uint64_t make_key(char *hostname, int len, unsigned long ip, CongestionControlRecord * record);
-uint64_t make_key(char *hostname, unsigned long ip, CongestionControlRecord * record);
-uint64_t make_key(char *hostname, int len, unsigned long ip, char *prefix, int prelen, short port = 0);
+uint64_t make_key(char *hostname, int len, sockaddr const* ip, CongestionControlRecord * record);
+uint64_t make_key(char *hostname, sockaddr const* ip, CongestionControlRecord * record);
+uint64_t make_key(char *hostname, int len, sockaddr const* ip, char *prefix, int prelen, short port = 0);
 
 //----------------------------------------------------
 // the following functions are actually declared in

Modified: trafficserver/traffic/trunk/proxy/congest/CongestionDB.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/congest/CongestionDB.cc?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/congest/CongestionDB.cc (original)
+++ trafficserver/traffic/trunk/proxy/congest/CongestionDB.cc Wed Oct  5 19:14:07 2011
@@ -75,7 +75,7 @@ public:
     {
       uint64_t m_key;
       char *m_hostname;
-      in_addr_t m_ip;
+      ts_ip_endpoint m_ip;
       CongestionControlRecord *m_rule;
       CongestionEntry **m_ppEntry;
     } entry_info;
@@ -419,7 +419,7 @@ CongestionDBCont::get_congest_entry(int 
       m_action.continuation->handleEvent(CONGESTION_EVENT_CONTROL_LOOKUP_DONE, NULL);
     } else {
       /* create a new entry and add it to the congestDB */
-      *CDBC_ppE = new CongestionEntry(CDBC_host, CDBC_ip, CDBC_rule, CDBC_key);
+      *CDBC_ppE = new CongestionEntry(CDBC_host, &CDBC_ip.sa, CDBC_rule, CDBC_key);
       CDBC_rule->put();
       (*CDBC_ppE)->get();
       theCongestionDB->insert_entry(CDBC_key, *CDBC_ppE);
@@ -515,7 +515,7 @@ get_congest_entry(Continuation * cont, H
     Ccont->mutex = cont->mutex;
     Ccont->CDBC_key = key;
     Ccont->CDBC_host = (char *) data->get_host();
-    Ccont->CDBC_ip = data->get_ip();
+    ink_inet_copy(&Ccont->CDBC_ip.sa, data->get_ip());
     p->get();
     Ccont->CDBC_rule = p;
     Ccont->CDBC_ppE = ppEntry;
@@ -623,8 +623,10 @@ remove_congested_entry(char *buf, MIOBuf
     remove_congested_entry(key);
     len = snprintf(msg, MSG_LEN, "host=%s prefix=%s removed\n", p, prefix ? prefix : "(nil)");
   } else if (strncasecmp(buf, "ip=", 3) == 0) {
+    ts_ip_endpoint ip;
+    memset(&ip, 0, sizeof(ip));
+    
     char *p = buf + 3;
-    in_addr_t ip = 0;
     char *prefix = strchr(p, '/');
     int prelen = 0;
     if (prefix) {
@@ -632,11 +634,11 @@ remove_congested_entry(char *buf, MIOBuf
       prefix++;
       prelen = strlen(prefix);
     }
-    ip = htonl(inet_addr(p));
-    if (ip == (in_addr_t) - 1 && strcmp(p, "255.255.255.255") != 0) {
+    ink_inet_pton(p, &ip);
+    if (!ink_inet_is_ip(&ip)) {
       len = snprintf(msg, MSG_LEN, "invalid ip: %s\n", buf);
     } else {
-      key = make_key(NULL, 0, ip, prefix, prelen);
+      key = make_key(NULL, 0, &ip.sa, prefix, prelen);
       remove_congested_entry(key);
       len = snprintf(msg, MSG_LEN, "ip=%s prefix=%s removed\n", p, prefix ? prefix : "(nil)");
     }

Modified: trafficserver/traffic/trunk/proxy/congest/CongestionTest.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/congest/CongestionTest.cc?rev=1179389&r1=1179388&r2=1179389&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/congest/CongestionTest.cc (original)
+++ trafficserver/traffic/trunk/proxy/congest/CongestionTest.cc Wed Oct  5 19:14:07 2011
@@ -383,7 +383,7 @@ struct CCCongestionDBTestCont: public Co
   CongestionControlRecord *rule;
   CongestionDB *db;
   int dbsize;
-  CongestionEntry *gen_CongestionEntry(in_addr_t ip, int congested = 0);
+  CongestionEntry *gen_CongestionEntry(sockaddr const* ip, int congested = 0);
 
 
     CCCongestionDBTestCont(ProxyMutexPtr _mutex, RegressionTest * _test):Continuation(_mutex),
@@ -403,12 +403,11 @@ struct CCCongestionDBTestCont: public Co
 };
 
 CongestionEntry *
-CCCongestionDBTestCont::gen_CongestionEntry(in_addr_t ip, int congested)
+CCCongestionDBTestCont::gen_CongestionEntry(sockaddr const* ip, int congested)
 {
-  char *hostname;
-  struct in_addr addr;
+  char hostname[INET6_ADDRSTRLEN];
   uint64_t key;
-  hostname = (addr.s_addr = htonl(ip), inet_ntoa(addr));
+  ink_inet_ntop(ip, hostname, sizeof(hostname));
   key = make_key(hostname, strlen(hostname), ip, rule->pRecord);
   CongestionEntry *ret = new CongestionEntry(hostname,
                                              ip,
@@ -474,7 +473,11 @@ CCCongestionDBTestCont::mainEvent(int ev
   for (i = 0; i < dbsize; i++) {
     if (i % (dbsize / 25) == 0)
       fprintf(stderr, ".");
-    CongestionEntry *tmp = gen_CongestionEntry(i + 255);
+
+    ts_ip_endpoint ip;
+    ink_inet_ip4_set(&ip, i + 255);
+    
+    CongestionEntry *tmp = gen_CongestionEntry(&ip.sa);
     db->addRecord(tmp->m_key, tmp);
   }
   fprintf(stderr, "done\n");
@@ -490,7 +493,10 @@ CCCongestionDBTestCont::mainEvent(int ev
   for (i = 0; i < to_add; i++) {
     if (i % (to_add / 25) == 0)
       fprintf(stderr, ".");
-    CongestionEntry *tmp = gen_CongestionEntry(i + 255);
+
+    ts_ip_endpoint ip;
+    ink_inet_ip4_set(&ip, i + 255);
+    CongestionEntry *tmp = gen_CongestionEntry(&ip.sa);
     db->addRecord(tmp->m_key, tmp);
   }
 
@@ -505,7 +511,11 @@ CCCongestionDBTestCont::mainEvent(int ev
   for (i = 0; i < to_add; i++) {
     if (i % (to_add / 25) == 0)
       fprintf(stderr, ".");
-    CongestionEntry *tmp = gen_CongestionEntry(i + 255, 1);
+
+    ts_ip_endpoint ip;
+    ink_inet_ip4_set(&ip, i + 255);
+    
+    CongestionEntry *tmp = gen_CongestionEntry(&ip.sa, 1);
     db->addRecord(tmp->m_key, tmp);
   }
   items[2] = get_congest_list();