trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r1187650 - in /trafficserver/traffic/trunk: ./ iocore/net/ lib/ts/ mgmt/ mgmt/utils/ proxy/ proxy/config/ proxy/logging/
Date Sat, 22 Oct 2011 04:47:28 GMT
Author: amc
Date: Sat Oct 22 04:47:26 2011
New Revision: 1187650

URL: http://svn.apache.org/viewvc?rev=1187650&view=rev
Log:
TS-988: IPv6 for ICP

Modified:
    trafficserver/traffic/trunk/CHANGES
    trafficserver/traffic/trunk/iocore/net/P_Connection.h
    trafficserver/traffic/trunk/lib/ts/ink_inet.cc
    trafficserver/traffic/trunk/lib/ts/ink_inet.h
    trafficserver/traffic/trunk/mgmt/LocalManager.cc
    trafficserver/traffic/trunk/mgmt/utils/MgmtUtils.cc
    trafficserver/traffic/trunk/mgmt/utils/MgmtUtils.h
    trafficserver/traffic/trunk/proxy/ICP.cc
    trafficserver/traffic/trunk/proxy/ICP.h
    trafficserver/traffic/trunk/proxy/ICPConfig.cc
    trafficserver/traffic/trunk/proxy/ICPlog.h
    trafficserver/traffic/trunk/proxy/config/icp.config.default
    trafficserver/traffic/trunk/proxy/logging/LogAccessICP.cc

Modified: trafficserver/traffic/trunk/CHANGES
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/CHANGES?rev=1187650&r1=1187649&r2=1187650&view=diff
==============================================================================
--- trafficserver/traffic/trunk/CHANGES (original)
+++ trafficserver/traffic/trunk/CHANGES Sat Oct 22 04:47:26 2011
@@ -1,5 +1,6 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache Traffic Server 3.1.1
+  *) [TS-988] Updated ICP for IPv6.
 
   *) [TS-994] Removed the extra splace from X-Forwarded-For.
 

Modified: trafficserver/traffic/trunk/iocore/net/P_Connection.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/net/P_Connection.h?rev=1187650&r1=1187649&r2=1187650&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/net/P_Connection.h (original)
+++ trafficserver/traffic/trunk/iocore/net/P_Connection.h Sat Oct 22 04:47:26 2011
@@ -120,7 +120,7 @@ struct Connection
   /// @internal Used only by ICP.
   void setRemote(
     sockaddr const* remote_addr ///< Address and port.
-	     ) {
+  ) {
     ink_inet_copy(&addr, remote_addr);
   }
 
@@ -130,7 +130,7 @@ struct Connection
   void setRemote(
     in_addr_t ip,
     int port
-	     ) {
+  ) {
 	ink_inet_ip4_set(&addr.sin, ip, htons(port));
   }
 

Modified: trafficserver/traffic/trunk/lib/ts/ink_inet.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/lib/ts/ink_inet.cc?rev=1187650&r1=1187649&r2=1187650&view=diff
==============================================================================
--- trafficserver/traffic/trunk/lib/ts/ink_inet.cc (original)
+++ trafficserver/traffic/trunk/lib/ts/ink_inet.cc Sat Oct 22 04:47:26 2011
@@ -293,3 +293,51 @@ ink_inet_to_hex(sockaddr const* src, cha
   return zret;
 }
 
+sockaddr* ink_inet_ip_set(
+  sockaddr* dst,
+  InkInetAddr const& addr,
+  uint16_t port
+) {
+  if (AF_INET == addr._family) ink_inet_ip4_set(dst, addr._addr._ip4, port);
+  else if (AF_INET6 == addr._family) ink_inet_ip6_set(dst, addr._addr._ip6, port);
+  else ink_inet_invalidate(dst);
+  return dst;
+}
+
+int
+InkInetAddr::load(char const* text) {
+  ts_ip_endpoint ip;
+  int zret = ink_inet_pton(text, &ip);
+  *this = ip;
+  return zret;
+}
+
+char*
+InkInetAddr::toString(char* dest, size_t len) const {
+  ts_ip_endpoint ip;
+  ip.assign(*this);
+  ink_inet_ntop(&ip, dest, len);
+  return dest;
+}
+
+bool
+InkInetAddr::isMulticast() const {
+  return (AF_INET == _family && 0xe == _addr._byte[0]) ||
+    (AF_INET6 == _family && IN6_IS_ADDR_MULTICAST(&_addr._ip6))
+    ;
+}
+
+bool
+operator == (InkInetAddr const& lhs, sockaddr const* rhs) {
+  bool zret = false;
+  if (lhs._family == rhs->sa_family) {
+    if (AF_INET == lhs._family) {
+      zret = lhs._addr._ip4 == ink_inet_ip4_addr_cast(rhs);
+    } else if (AF_INET6 == lhs._family) {
+      zret = 0 == memcmp(&lhs._addr._ip6, &ink_inet_ip6_addr_cast(rhs), sizeof(in6_addr));
+    } else { // map all non-IP to the same thing.
+      zret = true;
+    }
+  } // else different families, not equal.
+  return zret;
+}

Modified: trafficserver/traffic/trunk/lib/ts/ink_inet.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/lib/ts/ink_inet.h?rev=1187650&r1=1187649&r2=1187650&view=diff
==============================================================================
--- trafficserver/traffic/trunk/lib/ts/ink_inet.h (original)
+++ trafficserver/traffic/trunk/lib/ts/ink_inet.h Sat Oct 22 04:47:26 2011
@@ -31,6 +31,8 @@
 #define INK_GETHOSTBYNAME_R_DATA_SIZE 1024
 #define INK_GETHOSTBYADDR_R_DATA_SIZE 1024
 
+class InkInetAddr; // forward declare.
+
 /** A union to hold the standard IP address structures.
     By standard we mean @c sockaddr compliant.
 
@@ -47,9 +49,23 @@
 
  */
 union ts_ip_endpoint {
+  typedef ts_ip_endpoint self; ///< Self reference type.
+
+  struct sockaddr         sa; ///< Generic address.
   struct sockaddr_in      sin; ///< IPv4
   struct sockaddr_in6     sin6; ///< IPv6
-  struct sockaddr         sa; ///< Generic address.
+
+  self& assign(
+    sockaddr const* ip ///< Source address, family, port.
+  );
+  /// Construct from an @a addr and @a port.
+  self& assign(
+    InkInetAddr const& addr, ///< Address and address family.
+    uint16_t port = 0 ///< Port (network order).
+  );
+
+  /// Access to port.
+  uint16_t& port();
 };
 
 struct ink_gethostbyname_r_data
@@ -548,9 +564,9 @@ inline int ink_inet_cmp(
       if (la < ra) zret = -1;
       else if (la > ra) zret = 1;
       else zret = 0;
-    } else if (AF_INET6 == rtype) {
-      zret = -1; // IPv4 addresses are before IPv6
-    } else {
+    } else if (AF_INET6 == rtype) { // IPv4 < IPv6
+      zret = -1;
+    } else { // IP > not IP
       zret = 1;
     }
   } else if (AF_INET6 == ltype) {
@@ -812,9 +828,7 @@ ink_inet_to_hex(
 
 /** 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
-    @c sockaddr_storage. There are a couple of cases where this
-    makes sense.
+    ancillary information (such as port, or flow data).
     @note This is not easily used as an address for system calls.
 */
 struct InkInetAddr {
@@ -824,10 +838,16 @@ struct InkInetAddr {
   InkInetAddr() : _family(AF_UNSPEC) {}
   /// Construct as IPv4 @a addr.
   explicit InkInetAddr(
-    uint32_t addr ///< Address to assign.
+    in_addr_t addr ///< Address to assign.
   ) : _family(AF_INET) {
     _addr._ip4 = addr;
   }
+  /// Construct as IPv6 @a addr.
+  explicit InkInetAddr(
+    in6_addr const& addr ///< Address to assign.
+  ) : _family(AF_INET6) {
+    _addr._ip6 = addr;
+  }
   /// Construct from @c sockaddr.
   explicit InkInetAddr(sockaddr const* addr) { this->assign(addr); }
   /// Construct from @c sockaddr_in6.
@@ -836,6 +856,8 @@ struct InkInetAddr {
   explicit InkInetAddr(sockaddr_in6 const* addr) { this->assign(ink_inet_sa_cast(addr)); }
   /// Construct from @c ts_ip_endpoint.
   explicit InkInetAddr(ts_ip_endpoint const& addr) { this->assign(&addr.sa); }
+  /// Construct from @c ts_ip_endpoint.
+  explicit InkInetAddr(ts_ip_endpoint const* addr) { this->assign(&addr->sa); }
 
   /// Assign sockaddr storage.
   self& assign(sockaddr const* addr) {
@@ -843,12 +865,32 @@ struct InkInetAddr {
     if (ink_inet_is_ip4(addr)) {
       _addr._ip4 = ink_inet_ip4_addr_cast(addr);
     } else if (ink_inet_is_ip6(addr)) {
-      memcpy(&_addr._ip6, &ink_inet_ip6_cast(addr)->sin6_addr, INK_IP6_SIZE);
+      _addr._ip6 = ink_inet_ip6_addr_cast(addr);
     } else {
       _family = AF_UNSPEC;
     }
     return *this;
   }
+  /// Assign from end point.
+  self& operator = (ts_ip_endpoint const& ip) {
+    return this->assign(&ip.sa);
+  }
+
+  /** Load from string.
+      The address is copied to this object if the conversion is successful,
+      otherwise this object is invalidated.
+      @return 0 on success, non-zero on failure.
+  */
+  int load(
+    char const* str ///< Nul terminated input string.
+  );
+  /** Output to a string.
+      @return The string @a dest.
+  */
+  char* toString(
+    char* dest, ///< [out] Destination string buffer.
+    size_t len ///< [in] Size of buffer.
+  ) const;
 
   /// Equality.
   bool operator==(self const& that) {
@@ -869,14 +911,78 @@ struct InkInetAddr {
 
   /// Test for validity.
   bool isValid() const { return _family == AF_INET || _family == AF_INET6; }
+  /// Make invalid.
+  self& invalidate() { _family = AF_UNSPEC; return *this; }
+  /// Test for multicast
+  bool isMulticast() const;
 
-  uint8_t _family; ///< Protocol family.
-  uint8_t _pad[3]; ///< Pad it out.
+  uint16_t _family; ///< Protocol family.
   /// Address data.
   union {
     in_addr_t _ip4; ///< IPv4 address storage.
     in6_addr  _ip6; ///< IPv6 address storage.
+    uint8_t   _byte[INK_IP6_SIZE]; ///< As raw bytes.
   } _addr;
 };
 
+// Associated operators.
+bool operator == (InkInetAddr const& lhs, sockaddr const* rhs);
+inline bool operator == (sockaddr const* lhs, InkInetAddr const& rhs) {
+  return rhs == lhs;
+}
+inline bool operator != (InkInetAddr const& lhs, sockaddr const* rhs) {
+  return ! (lhs == rhs);
+}
+inline bool operator != (sockaddr const* lhs, InkInetAddr const& rhs) {
+  return ! (rhs == lhs);
+}
+inline bool operator == (InkInetAddr const& lhs, ts_ip_endpoint const& rhs) {
+  return lhs == &rhs.sa;
+}
+inline bool operator == (ts_ip_endpoint const& lhs, InkInetAddr const& rhs) {
+  return &lhs.sa == rhs;
+}
+inline bool operator != (InkInetAddr const& lhs, ts_ip_endpoint const& rhs) {
+  return ! (lhs == &rhs.sa);
+}
+inline bool operator != (ts_ip_endpoint const& lhs, InkInetAddr const& rhs) {
+  return ! (rhs == &lhs.sa);
+}
+
+/// Write IP @a addr to storage @a dst.
+/// @return @s dst.
+sockaddr* ink_inet_ip_set(
+  sockaddr* dst, ///< Destination storage.
+  InkInetAddr const& addr, ///< source address.
+  uint16_t port = 0 ///< port, network order.
+);
+
+/** Convert @a text to an IP address and write it to @a addr.
+    Convenience overload.
+    @return 0 on success, non-zero on failure.
+*/
+inline int ink_inet_pton(
+  char const* text, ///< [in] text.
+  InkInetAddr& addr ///< [out] address
+) {
+  return addr.load(text) ? 0 : -1;
+}
+
+inline ts_ip_endpoint&
+ts_ip_endpoint::assign(InkInetAddr const& addr, uint16_t port) {
+  ink_inet_ip_set(&sa, addr, port); 
+  return *this;
+}
+
+inline ts_ip_endpoint&
+ts_ip_endpoint::assign(sockaddr const* ip) {
+  ink_inet_copy(&sa, ip);
+  return *this;
+}
+
+inline uint16_t&
+ts_ip_endpoint::port() {
+  return ink_inet_port_cast(&sa);
+}
+
 #endif // _ink_inet.h

Modified: trafficserver/traffic/trunk/mgmt/LocalManager.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/mgmt/LocalManager.cc?rev=1187650&r1=1187649&r2=1187650&view=diff
==============================================================================
--- trafficserver/traffic/trunk/mgmt/LocalManager.cc (original)
+++ trafficserver/traffic/trunk/mgmt/LocalManager.cc Sat Oct 22 04:47:26 2011
@@ -392,8 +392,8 @@ void
 LocalManager::initCCom(int port, char *addr, int sport)
 {
   bool found;
-  struct in_addr cluster_addr;  // ip addr of the cluster interface
-  char *clusterAddrStr;         // cluster ip addr as a String
+  ts_ip_endpoint cluster_ip;    // ip addr of the cluster interface
+  ip_text_buffer clusterAddrStr;         // cluster ip addr as a String
   char *intrName;               // Name of the interface we are to use
   char hostname[1024];          // hostname of this machine
   const char envVar[] = "PROXY_CLUSTER_ADDR=";
@@ -406,12 +406,14 @@ LocalManager::initCCom(int port, char *a
   intrName = REC_readString("proxy.config.cluster.ethernet_interface", &found);
   ink_assert(intrName != NULL);
 
-  found = mgmt_getAddrForIntr(intrName, &cluster_addr);
+  found = mgmt_getAddrForIntr(intrName, &cluster_ip.sa);
   if (found == false) {
     mgmt_fatal(stderr, "[LocalManager::initCCom] Unable to find network interface %s.  Exiting...\n", intrName);
+  } else if (!ink_inet_is_ip4(&cluster_ip)) {
+    mgmt_fatal(stderr, "[LocalManager::initCCom] Unable to find IPv4 network interface %s.  Exiting...\n", intrName);
   }
 
-  clusterAddrStr = inet_ntoa(cluster_addr);
+  ink_inet_ntop(&cluster_ip, clusterAddrStr, sizeof(clusterAddrStr));
   Debug("ccom", "Cluster Interconnect is %s : %s\n", intrName, clusterAddrStr);
 
   // This an awful hack but I could not come up with a better way to
@@ -434,8 +436,8 @@ LocalManager::initCCom(int port, char *a
   ink_strlcat(envBuf, clusterAddrStr, envBuf_size);
   ink_release_assert(putenv(envBuf) == 0);
 
-  ccom = new ClusterCom(cluster_addr.s_addr, hostname, port, addr, sport, pserver_path);
-  virt_map = new VMap(intrName, cluster_addr.s_addr, &lmgmt->ccom->mutex);
+  ccom = new ClusterCom(ink_inet_ip4_addr_cast(&cluster_ip), hostname, port, addr, sport, pserver_path);
+  virt_map = new VMap(intrName, ink_inet_ip4_addr_cast(&cluster_ip), &lmgmt->ccom->mutex);
   virt_map->downAddrs();        // Just to be safe
   ccom->establishChannels();
   ats_free(intrName);

Modified: trafficserver/traffic/trunk/mgmt/utils/MgmtUtils.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/mgmt/utils/MgmtUtils.cc?rev=1187650&r1=1187649&r2=1187650&view=diff
==============================================================================
--- trafficserver/traffic/trunk/mgmt/utils/MgmtUtils.cc (original)
+++ trafficserver/traffic/trunk/mgmt/utils/MgmtUtils.cc Sat Oct 22 04:47:26 2011
@@ -584,7 +584,7 @@ get_interface_mtu(int sock_fd, struct if
 #endif
 
 bool
-mgmt_getAddrForIntr(char *intrName, struct in_addr * addr, int *mtu)
+mgmt_getAddrForIntr(char *intrName, sockaddr* addr, int *mtu)
 {
   bool found = false;
 
@@ -645,7 +645,7 @@ mgmt_getAddrForIntr(char *intrName, stru
         // Only look at the address if it an internet address
         if (ifr->ifr_ifru.ifru_addr.sa_family == AF_INET) {
           tmp = (struct sockaddr_in *) &ifr->ifr_ifru.ifru_addr;
-          *addr = tmp->sin_addr;
+          ink_inet_ip4_cast(addr)->sin_addr = tmp->sin_addr;
           found = true;
 
           if (mtu)

Modified: trafficserver/traffic/trunk/mgmt/utils/MgmtUtils.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/mgmt/utils/MgmtUtils.h?rev=1187650&r1=1187649&r2=1187650&view=diff
==============================================================================
--- trafficserver/traffic/trunk/mgmt/utils/MgmtUtils.h (original)
+++ trafficserver/traffic/trunk/mgmt/utils/MgmtUtils.h Sat Oct 22 04:47:26 2011
@@ -58,7 +58,7 @@ void mgmt_cleanup();
 
 struct in_addr *mgmt_sortipaddrs(int num, struct in_addr **list);
 char *mgmt_localhost_ip();
-bool mgmt_getAddrForIntr(char *intrName, struct in_addr *addr, int *mtu = 0);
+bool mgmt_getAddrForIntr(char *intrName, sockaddr* addr, int *mtu = 0);
 
 /* the following functions are all DEPRECATED.  The Diags
    interface should be used exclusively in the future */

Modified: trafficserver/traffic/trunk/proxy/ICP.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/ICP.cc?rev=1187650&r1=1187649&r2=1187650&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/ICP.cc (original)
+++ trafficserver/traffic/trunk/proxy/ICP.cc Sat Oct 22 04:47:26 2011
@@ -399,12 +399,13 @@ ICPPeerReadCont::ICPPeerReadEvent(int ev
 int
 ICPPeerReadCont::StaleCheck(int event, Event * e)
 {
+  ip_port_text_buffer ipb;
   NOWARN_UNUSED(e);
   ink_release_assert(mutex->thread_holding == this_ethread());
 
-  Debug("icp-stale", "Stale check res=%d for id=%d, [%s] from [%s:%d]",
+  Debug("icp-stale", "Stale check res=%d for id=%d, [%s] from [%s]",
         event, _state->_rICPmsg->h.requestno,
-        _state->_rICPmsg->un.query.URL, inet_ntoa(_state->_sender.sin_addr), ntohs(_state->_sender.sin_port));
+    _state->_rICPmsg->un.query.URL, ink_inet_nptop(&_state->_sender, ipb, sizeof(ipb)));
 
   switch (event) {
   case ICP_STALE_OBJECT:
@@ -433,10 +434,11 @@ ICPPeerReadCont::StaleCheck(int event, E
 int
 ICPPeerReadCont::ICPPeerQueryEvent(int event, Event * e)
 {
+  ip_port_text_buffer ipb;
   NOWARN_UNUSED(e);
-  Debug("icp", "Remote Query lookup res=%d for id=%d, [%s] from [%s:%d]",
+  Debug("icp", "Remote Query lookup res=%d for id=%d, [%s] from [%s]",
         event, _state->_rICPmsg->h.requestno,
-        _state->_rICPmsg->un.query.URL, inet_ntoa(_state->_sender.sin_addr), ntohs(_state->_sender.sin_port));
+    _state->_rICPmsg->un.query.URL, ink_inet_nptop(&_state->_sender, ipb, sizeof(ipb)));
   if (pluginFreshnessCalcFunc) {
     switch (event) {
     case CACHE_EVENT_OPEN_READ:
@@ -465,6 +467,7 @@ ICPPeerReadCont::ICPPeerQueryEvent(int e
 int
 ICPPeerReadCont::ICPPeerQueryCont(int event, Event * e)
 {
+  ip_port_text_buffer ipb;
   NOWARN_UNUSED(event);
   NOWARN_UNUSED(e);
 
@@ -476,9 +479,11 @@ ICPPeerReadCont::ICPPeerQueryCont(int ev
   _state->_cachelookupURL.create(NULL);
   const char *qurl = (const char *) _state->_rICPmsg->un.query.URL;
   _state->_cachelookupURL.parse(qurl, strlen(qurl));
-  Debug("icp", "Remote Query for id=%d, [%s] from [%s:%d]",
+  Debug("icp", "Remote Query for id=%d, [%s] from [%s]",
         _state->_rICPmsg->h.requestno,
-        _state->_rICPmsg->un.query.URL, inet_ntoa(_state->_sender.sin_addr), ntohs(_state->_sender.sin_port));
+        _state->_rICPmsg->un.query.URL,
+    ink_inet_nptop(&_state->_sender, ipb, sizeof(ipb))
+  );
 
   SET_HANDLER((ICPPeerReadContHandler) & ICPPeerReadCont::ICPPeerQueryEvent);
   if (_state->_rICPmsg->un.query.URL && *_state->_rICPmsg->un.query.URL) {
@@ -530,6 +535,7 @@ int
 ICPPeerReadCont::PeerReadStateMachine(PeerReadData * s, Event * e)
 {
   AutoReference l(&_recursion_depth);
+  ip_port_text_buffer ipb; // scratch buffer for diagnostic messages.
   //-----------------------------------------------------------
   // State machine to process ICP data received on UDP socket
   //-----------------------------------------------------------
@@ -594,8 +600,7 @@ ICPPeerReadCont::PeerReadStateMachine(Pe
         ink_assert(s->_peer->readAction == NULL);
         Action *a = s->_peer->RecvFrom_re(this, this, buf,
                                           buf->write_avail() - 1,
-                                          (struct sockaddr *)
-                                          &s->_peer->fromaddr,
+                                          &s->_peer->fromaddr.sa,
                                           &s->_peer->fromaddrlen);
         if (!a) {
           a = ACTION_IO_ERROR;
@@ -688,8 +693,8 @@ ICPPeerReadCont::PeerReadStateMachine(Pe
         }
         // Validate receiver and convert the received sockaddr
         //   to internal sockaddr format.
-        struct sockaddr_in from;
-        if (!s->_peer->ExtToIntRecvSockAddr(&s->_peer->fromaddr, &from)) {
+        ts_ip_endpoint from;
+        if (!s->_peer->ExtToIntRecvSockAddr(&s->_peer->fromaddr.sa, &from.sa)) {
           int status;
           ICPConfigData *cfg = _ICPpr->GetConfig()->globalConfig();
           ICPMsg_t *ICPmsg = (ICPMsg_t *) buf;
@@ -717,21 +722,24 @@ ICPPeerReadCont::PeerReadStateMachine(Pe
 
             int icp_reply_port = cfg->ICPDefaultReplyPort();
             if (!icp_reply_port) {
-              icp_reply_port = ntohs(s->_peer->fromaddr.sin_port);
+              icp_reply_port = ntohs(ink_inet_port_cast(&s->_peer->fromaddr));
             }
-            PeerConfigData *Pcfg = NEW(new PeerConfigData(PeerConfigData::CTYPE_SIBLING,
-                                                          &s->_peer->fromaddr.sin_addr, 0,
-                                                          icp_reply_port));
+            PeerConfigData *Pcfg = NEW(new PeerConfigData(
+                PeerConfigData::CTYPE_SIBLING,
+                InkInetAddr(s->_peer->fromaddr),
+                0,
+                icp_reply_port
+            ));
             ParentSiblingPeer *P = NEW(new ParentSiblingPeer(PEER_SIBLING, Pcfg, _ICPpr, true));
             status = _ICPpr->AddPeer(P);
             ink_release_assert(status);
             status = _ICPpr->AddPeerToSendList(P);
             ink_release_assert(status);
 
-	    P->GetChan()->setRemote(P->GetIP()->s_addr, P->GetPort());
+	    P->GetChan()->setRemote(P->GetIP());
 
             // coverity[uninit_use_in_call]
-            Note("ICP Peer added ip=%u.%u.%u.%u port=%d", PRINT_IP(P->GetIP()->s_addr), P->GetPort());
+            Note("ICP Peer added ip=%s", ink_inet_nptop(P->GetIP(), ipb, sizeof(ipb)));
             from = s->_peer->fromaddr;
           } else {
           invalid_message:
@@ -739,8 +747,8 @@ ICPPeerReadCont::PeerReadStateMachine(Pe
             // Sender does not exist in ICP configuration, terminate
             //
             ICP_INCREMENT_DYN_STAT(invalid_sender_stat);
-            Debug("icp", "Received msg from invalid sender [%s:%d]",
-                  inet_ntoa(s->_peer->fromaddr.sin_addr), ntohs(s->_peer->fromaddr.sin_port));
+            Debug("icp", "Received msg from invalid sender [%s]",
+              ink_inet_nptop(&s->_peer->fromaddr, ipb, sizeof(ipb)));
 
             s->_peer->buf = NULL;
             s->_next_state = READ_NOT_ACTIVE;
@@ -762,8 +770,8 @@ ICPPeerReadCont::PeerReadStateMachine(Pe
         if ((s->_rICPmsg->h.version != ICP_VERSION_2)
             && (s->_rICPmsg->h.version != ICP_VERSION_3)) {
           ICP_INCREMENT_DYN_STAT(read_not_v2_icp_stat);
-          Debug("icp", "Received (v=%d) !v2 && !v3 msg from sender [%s:%d]",
-                (uint32_t) s->_rICPmsg->h.version, inet_ntoa(from.sin_addr), ntohs(from.sin_port));
+          Debug("icp", "Received (v=%d) !v2 && !v3 msg from sender [%s]",
+            (uint32_t) s->_rICPmsg->h.version, ink_inet_nptop(&from, ipb, sizeof(ipb)));
 
           s->_rICPmsg = NULL;
           s->_buf = NULL;
@@ -788,8 +796,8 @@ ICPPeerReadCont::PeerReadStateMachine(Pe
           }
         } else {
           // We have a response message for an ICP query.
-          Debug("icp", "Response for Id=%d, from [%s:%d]",
-                s->_rICPmsg->h.requestno, inet_ntoa(s->_sender.sin_addr), ntohs(s->_sender.sin_port));
+          Debug("icp", "Response for Id=%d, from [%s]",
+            s->_rICPmsg->h.requestno, ink_inet_nptop(&s->_sender, ipb, sizeof(ipb)));
           ICP_INCREMENT_DYN_STAT(icp_remote_responses_stat);
           s->_next_state = GET_ICP_REQUEST;
           RECORD_ICP_STATE_CHANGE(s, 0, GET_ICP_REQUEST);
@@ -809,8 +817,8 @@ ICPPeerReadCont::PeerReadStateMachine(Pe
 
         if (s->_queryResult == CACHE_EVENT_LOOKUP) {
           // Use the received ICP data buffer for the response message
-          Debug("icp", "Sending ICP_OP_HIT for id=%d, [%s] to [%s:%d]",
-                s->_rICPmsg->h.requestno, data, inet_ntoa(s->_sender.sin_addr), ntohs(s->_sender.sin_port));
+          Debug("icp", "Sending ICP_OP_HIT for id=%d, [%s] to [%s]",
+            s->_rICPmsg->h.requestno, data, ink_inet_nptop(&s->_sender, ipb, sizeof(ipb)));
           ICP_INCREMENT_DYN_STAT(icp_cache_lookup_success_stat);
           status = ICPRequestCont::BuildICPMsg(ICP_OP_HIT,
                                                s->_rICPmsg->h.requestno, 0 /* optflags */ , 0 /* optdata */ ,
@@ -818,8 +826,8 @@ ICPPeerReadCont::PeerReadStateMachine(Pe
                                                data, datalen, &s->_mhdr, s->_iov, s->_rICPmsg);
         } else if (s->_queryResult == CACHE_EVENT_LOOKUP_FAILED) {
           // Use the received ICP data buffer for response message
-          Debug("icp", "Sending ICP_OP_MISS for id=%d, [%s] to [%s:%d]",
-                s->_rICPmsg->h.requestno, data, inet_ntoa(s->_sender.sin_addr), ntohs(s->_sender.sin_port));
+          Debug("icp", "Sending ICP_OP_MISS for id=%d, [%s] to [%s]",
+            s->_rICPmsg->h.requestno, data, ink_inet_nptop(&s->_sender, ipb, sizeof(ipb)));
           ICP_INCREMENT_DYN_STAT(icp_cache_lookup_fail_stat);
           status = ICPRequestCont::BuildICPMsg(ICP_OP_MISS,
                                                s->_rICPmsg->h.requestno, 0 /* optflags */ , 0 /* optdata */ ,
@@ -860,7 +868,7 @@ ICPPeerReadCont::PeerReadStateMachine(Pe
         RECORD_ICP_STATE_CHANGE(s, 0, WRITE_DONE);
         ink_assert(s->_peer->writeAction == NULL);
         Action *a = s->_peer->SendMsg_re(this, this,
-                                         &s->_mhdr, &s->_sender);
+                                         &s->_mhdr, &s->_sender.sa);
         if (!a) {
           a = ACTION_IO_ERROR;
         }
@@ -872,11 +880,9 @@ ICPPeerReadCont::PeerReadStateMachine(Pe
         } else if (a == ACTION_IO_ERROR) {
           // Partial write.
           ICP_INCREMENT_DYN_STAT(query_response_partial_write_stat);
-          unsigned char x[4];
-          *(uint32_t *) & x = (uint32_t) s->_sender.sin_addr.s_addr;
           // coverity[uninit_use_in_call]
-          Debug("icp_warn", "ICP response send, sent=%d res=%d, ip=%d.%d.%d.%d",
-                ntohs(s->_rICPmsg->h.msglen), -1, x[0], x[1], x[2], x[3]);
+          Debug("icp_warn", "ICP response send, sent=%d res=%d, ip=%s",
+            ntohs(s->_rICPmsg->h.msglen), -1, ink_inet_ntop(&s->_sender, ipb, sizeof(ipb)));
           s->_next_state = READ_NOT_ACTIVE;
           RECORD_ICP_STATE_CHANGE(s, 0, READ_NOT_ACTIVE);
           break;
@@ -897,15 +903,13 @@ ICPPeerReadCont::PeerReadStateMachine(Pe
 
         if (len == (int)ntohs(s->_rICPmsg->h.msglen)) {
           ICP_INCREMENT_DYN_STAT(query_response_write_stat);
-          s->_peer->LogSendMsg(s->_rICPmsg, &s->_sender);       // log query reply
+          s->_peer->LogSendMsg(s->_rICPmsg, &s->_sender.sa);       // log query reply
         } else {
           // Partial write.
           ICP_INCREMENT_DYN_STAT(query_response_partial_write_stat);
-          unsigned char x[4];
-          *(uint32_t *) & x = (uint32_t) s->_sender.sin_addr.s_addr;
           // coverity[uninit_use_in_call]
-          Debug("icp_warn", "ICP response send, sent=%d res=%d, ip=%d.%d.%d.%d",
-                ntohs(s->_rICPmsg->h.msglen), len, x[0], x[1], x[2], x[3]);
+          Debug("icp_warn", "ICP response send, sent=%d res=%d, ip=%s",
+            ntohs(s->_rICPmsg->h.msglen), len, ink_inet_ntop(&s->_sender, ipb, sizeof(ipb)));
         }
         // Processing complete, perform completion actions
         s->_next_state = READ_NOT_ACTIVE;
@@ -941,8 +945,7 @@ ICPPeerReadCont::PeerReadStateMachine(Pe
         //
         Debug("icp", "No ICP Request for Id=%d", s->_rICPmsg->h.requestno);
         ICP_INCREMENT_DYN_STAT(no_icp_request_for_response_stat);
-        Peer *p = _ICPpr->FindPeer(&s->_sender.sin_addr,
-                                   ntohs(s->_sender.sin_port));
+        Peer *p = _ICPpr->FindPeer(s->_sender);
         p->LogRecvMsg(s->_rICPmsg, 0);
         s->_next_state = READ_NOT_ACTIVE;
         RECORD_ICP_STATE_CHANGE(s, 0, READ_NOT_ACTIVE);
@@ -975,8 +978,7 @@ ICPPeerReadCont::PeerReadStateMachine(Pe
           return EVENT_CONT;
         }
         // Log as "response for ICP request"
-        Peer *p = _ICPpr->FindPeer(&s->_sender.sin_addr,
-                                   ntohs(s->_sender.sin_port));
+        Peer *p = _ICPpr->FindPeer(s->_sender);
         p->LogRecvMsg(s->_rICPmsg, 1);
 
         // Process the ICP response for the given ICP request
@@ -1210,6 +1212,7 @@ ICPRequestCont::ICPStateMachine(int even
   // ICP message processing state machine
   //*******************************************
   ICPConfiguration *ICPcf = _ICPpr->GetConfig();
+  ip_port_text_buffer ipb;
 
   while (1) {                   // loop forever
 
@@ -1322,9 +1325,7 @@ ICPRequestCont::ICPStateMachine(int even
           int was_expected = P->ExpectedReplies(&_expected_replies_list);
           _expected_replies += was_expected;
           npending_actions++;
-          Action *a = P->SendMsg_re(this,
-                                    P,
-                                    &_sendMsgHdr, (struct sockaddr_in *) 0);
+          Action *a = P->SendMsg_re(this, P, &_sendMsgHdr, NULL);
           if (!a) {
             a = ACTION_IO_ERROR;
           }
@@ -1335,19 +1336,18 @@ ICPRequestCont::ICPStateMachine(int even
               }
               (*pendingActions) (npending_actions) = a;
             }
-            P->LogSendMsg(&_ICPmsg, (struct sockaddr_in *) 0);  // log as send query
-            Debug("icp", "[ICP_QUEUE_REQUEST] Id=%d send query to [%s:%d]",
-                  _sequence_number, inet_ntoa(*P->GetIP()), P->GetPort());
+            P->LogSendMsg(&_ICPmsg, NULL);  // log as send query
+            Debug("icp", "[ICP_QUEUE_REQUEST] Id=%d send query to [%s]",
+              _sequence_number, ink_inet_nptop(P->GetIP(), ipb, sizeof(ipb)));
           } else {
             _expected_replies_list.ClearBit(P->GetPeerID());
             _expected_replies -= was_expected;
             // Partial or failed write.
             ICP_INCREMENT_DYN_STAT(send_query_partial_write_stat);
-            unsigned char x[4];
-            *(uint32_t *) & x = (uint32_t) (*P->GetIP()).s_addr;
             // coverity[uninit_use_in_call]
             Debug("icp_warn",
-                  "ICP query send, res=%d, ip=%d.%d.%d.%d", ntohs(_ICPmsg.h.msglen), x[0], x[1], x[2], x[3]);
+                  "ICP query send, res=%d, ip=%s", ntohs(_ICPmsg.h.msglen),
+              ink_inet_ntop(P->GetIP(), ipb, sizeof(ipb)));
           }
           SendPeers--;
         }
@@ -1493,7 +1493,9 @@ int
 ICPRequestCont::ICPResponseMessage(int event, ICPMsg_t * m, int ICPMsg_len, Peer * peer)
 {
   NOWARN_UNUSED(ICPMsg_len);
+  ip_port_text_buffer ipb, ipb2;
   if (event == EVENT_INTERVAL) {
+
     _timeout = 0;
     remove_all_pendingActions();
 
@@ -1509,14 +1511,16 @@ ICPRequestCont::ICPResponseMessage(int e
           pp = _ICPpr->GetNthParentPeer(0, _ICPpr->GetStartingParentPeerBias());
           if (pp && !_expected_replies_list.IsBitSet(pp->GetPeerID())
               && pp->isUp()) {
-            _ret_sockaddr.sin_addr.s_addr = (pp->GetIP())->s_addr;
-            _ret_sockaddr.sin_port = htons(((ParentSiblingPeer *) pp)->GetProxyPort());
+            ink_inet_copy(&_ret_sockaddr.sa, pp->GetIP());
+            _ret_sockaddr.port() = htons(static_cast<ParentSiblingPeer*>(pp)->GetProxyPort());
             _ret_status = ICP_LOOKUP_FOUND;
 
             Debug("icp",
-                  "ICP timeout using parent Id=%d from [%s:%d] return [%s:%d]",
-                  _sequence_number, inet_ntoa(*pp->GetIP()),
-                  pp->GetPort(), inet_ntoa(_ret_sockaddr.sin_addr), ntohs(_ret_sockaddr.sin_port));
+              "ICP timeout using parent Id=%d from [%s] return [%s]",
+              _sequence_number,
+              ink_inet_nptop(pp->GetIP(), ipb, sizeof(ipb)),
+              ink_inet_nptop(&_ret_sockaddr, ipb2, sizeof(ipb2))
+            );
             return EVENT_DONE;
           }
         }
@@ -1542,14 +1546,16 @@ ICPRequestCont::ICPResponseMessage(int e
 
         ICP_INCREMENT_DYN_STAT(icp_query_hits_stat);
         ++_received_replies;
-        _ret_sockaddr.sin_addr.s_addr = (peer->GetIP())->s_addr;
-        _ret_sockaddr.sin_port = htons(((ParentSiblingPeer *) peer)->GetProxyPort());
+        ink_inet_copy(&_ret_sockaddr, peer->GetIP());
+        _ret_sockaddr.port() =  htons(static_cast<ParentSiblingPeer*>(peer)->GetProxyPort());
         _ret_status = ICP_LOOKUP_FOUND;
 
         Debug("icp",
-              "ICP Response HIT for Id=%d from [%s:%d] return [%s:%d]",
-              _sequence_number, inet_ntoa(*peer->GetIP()), peer->GetPort(),
-              inet_ntoa(_ret_sockaddr.sin_addr), ntohs(_ret_sockaddr.sin_port));
+          "ICP Response HIT for Id=%d from [%s] return [%s]",
+          _sequence_number,
+          ink_inet_nptop(peer->GetIP(), ipb, sizeof(ipb)),
+          ink_inet_nptop(&_ret_sockaddr, ipb2, sizeof(ipb2))
+        );
         return EVENT_DONE;
       }
     case ICP_OP_MISS:
@@ -1557,8 +1563,8 @@ ICPRequestCont::ICPResponseMessage(int e
     case ICP_OP_MISS_NOFETCH:
     case ICP_OP_DENIED:
       {
-        Debug("icp", "ICP MISS response for Id=%d from [%s:%d]",
-              _sequence_number, inet_ntoa(*peer->GetIP()), peer->GetPort());
+        Debug("icp", "ICP MISS response for Id=%d from [%s]",
+          _sequence_number, ink_inet_nptop(peer->GetIP(), ipb, sizeof(ipb)));
         // "received_replies" is only for Peers who we expect a reply
         //  from (Peers which are in the expected_replies_list).
         int Id = peer->GetPeerID();
@@ -1600,27 +1606,25 @@ ICPRequestCont::ICPResponseMessage(int e
             }
           }
           if (p) {
-            _ret_sockaddr.sin_addr.s_addr = (p->GetIP())->s_addr;
-            _ret_sockaddr.sin_port = htons(((ParentSiblingPeer *) p)->GetProxyPort());
+            ink_inet_copy(&_ret_sockaddr, p->GetIP());
+            _ret_sockaddr.port() = htons(static_cast<ParentSiblingPeer*>(p)->GetProxyPort());
             _ret_status = ICP_LOOKUP_FOUND;
 
-            Debug("icp", "ICP ALL MISS(1) for Id=%d return [%s:%d]",
-                  _sequence_number, inet_ntoa(_ret_sockaddr.sin_addr), ntohs(_ret_sockaddr.sin_port));
+            Debug("icp", "ICP ALL MISS(1) for Id=%d return [%s]",
+              _sequence_number, ink_inet_nptop(&_ret_sockaddr, ipb, sizeof(ipb)));
             return EVENT_DONE;
           }
         }
-        Debug("icp", "ICP ALL MISS(2) for Id=%d return [%s:%d]",
-              _sequence_number, inet_ntoa(_ret_sockaddr.sin_addr), ntohs(_ret_sockaddr.sin_port));
+        Debug("icp", "ICP ALL MISS(2) for Id=%d return [%s]",
+          _sequence_number, ink_inet_nptop(&_ret_sockaddr, ipb, sizeof(ipb)));
         return EVENT_DONE;
       }
     default:
       {
         ICP_INCREMENT_DYN_STAT(invalid_icp_query_response_stat);
-        unsigned char x[4];
-        *(uint32_t *) & x = (uint32_t) peer->GetIP()->s_addr;
         // coverity[uninit_use_in_call]
-        Warning("Invalid ICP response, op=%d reqno=%d ip=%d.%d.%d.%d",
-                m->h.opcode, m->h.requestno, x[0], x[1], x[2], x[3]);
+        Warning("Invalid ICP response, op=%d reqno=%d ip=%s",
+          m->h.opcode, m->h.requestno, ink_inet_ntop(peer->GetIP(), ipb, sizeof(ipb)));
         return EVENT_CONT;      // wait for more responses
       }
 
@@ -2025,18 +2029,19 @@ ICPProcessor::BuildPeerList()
   Pcfg->_ctype = PeerConfigData::CTYPE_LOCAL;
 
   // Get IP address for given interface
-  if (!mgmt_getAddrForIntr(GetConfig()->globalConfig()->ICPinterface(), &Pcfg->_ip_addr)) {
+  ts_ip_endpoint tmp_ip;
+  if (!mgmt_getAddrForIntr(GetConfig()->globalConfig()->ICPinterface(), &tmp_ip.sa)) {
+    Pcfg->_ip_addr._family = AF_UNSPEC;
     // No IP address for given interface
     Warning("ICP interface [%s] has no IP address", GetConfig()->globalConfig()->ICPinterface());
     REC_SignalWarning(REC_SIGNAL_CONFIG_ERROR, "ICP interface has no IP address");
-    Pcfg->_ip_addr.s_addr = 0;
   } else {
-    Pcfg->_my_ip_addr.s_addr = Pcfg->_ip_addr.s_addr;
+    Pcfg->_my_ip_addr = Pcfg->_ip_addr = tmp_ip;
   }
   Pcfg->_proxy_port = 0;
   Pcfg->_icp_port = GetConfig()->globalConfig()->ICPport();
   Pcfg->_mc_member = 0;
-  Pcfg->_mc_ip_addr.s_addr = 0;
+  Pcfg->_mc_ip_addr._family = AF_UNSPEC;
   Pcfg->_mc_ttl = 0;
 
   //***************************************************
@@ -2059,18 +2064,18 @@ ICPProcessor::BuildPeerList()
     // siblings are cluster members.  Note that in a cluster
     // configuration, "icp.config" is shared by all nodes.
     //
-    if (Pcfg->GetIP()->s_addr == _LocalPeer->GetIP()->s_addr)
+    if (Pcfg->GetIPAddr() == _LocalPeer->GetIP())
       continue;                 // ignore
 
     if ((type == PEER_PARENT) || (type == PEER_SIBLING)) {
 
       if (Pcfg->MultiCastMember()) {
-        mcP = FindPeer(Pcfg->GetMultiCastIP(), Pcfg->GetICPPort());
+        mcP = FindPeer(Pcfg->GetMultiCastIPAddr(), Pcfg->GetICPPort());
         if (!mcP) {
           //*********************************
           // Create multicast peer structure
           //*********************************
-          mcP = NEW(new MultiCastPeer(Pcfg->GetMultiCastIP(), Pcfg->GetICPPort(), Pcfg->GetMultiCastTTL(), this));
+          mcP = NEW(new MultiCastPeer(Pcfg->GetMultiCastIPAddr(), Pcfg->GetICPPort(), Pcfg->GetMultiCastTTL(), this));
           status = AddPeer(mcP);
           ink_assert(status);
           status = AddPeerToSendList(mcP);
@@ -2190,44 +2195,37 @@ ICPProcessor::SetupListenSockets()
   int status;
   int index;
   for (index = 0; index < (_nPeerList + 1); ++index) {
+    ip_port_text_buffer ipb, ipb2;
+
     if ((P = _PeerList[index])) {
 
       if ((P->GetType() == PEER_PARENT)
           || (P->GetType() == PEER_SIBLING)) {
         ParentSiblingPeer *pPS = (ParentSiblingPeer *) P;
 
-	pPS->GetChan()->setRemote(pPS->GetIP()->s_addr, pPS->GetPort());
+	pPS->GetChan()->setRemote(pPS->GetIP());
 
       } else if (P->GetType() == PEER_MULTICAST) {
         MultiCastPeer *pMC = (MultiCastPeer *) P;
         ink_assert(_mcastCB_handler != NULL);
-        status = pMC->GetSendChan()->setup_mc_send(pMC->GetIP()->s_addr, pMC->GetPort(), _LocalPeer->GetIP()->s_addr,
-#ifdef _WIN32
-                                                   _LocalPeer->GetPort(),
-#else
-                                                   0,
-#endif
-                                                   NON_BLOCKING, pMC->GetTTL(), DISABLE_MC_LOOPBACK, _mcastCB_handler);
+        status = pMC->GetSendChan()->setup_mc_send(pMC->GetIP(), _LocalPeer->GetIP(), NON_BLOCKING, pMC->GetTTL(), DISABLE_MC_LOOPBACK, _mcastCB_handler);
         if (status) {
-          unsigned char x[4], y[4];
-          *(uint32_t *) & x = (uint32_t) pMC->GetIP()->s_addr;
-          *(uint32_t *) & y = (uint32_t) _LocalPeer->GetIP()->s_addr;
           // coverity[uninit_use_in_call]
-          Warning("ICP MC send setup failed, res=%d, ip=%d.%d.%d.%d:%d bind_ip=%d.%d.%d.%d:%d",
-                  status, x[0], x[1], x[2], x[3], pMC->GetPort(), y[0], y[1], y[2], y[3], 0);
+          Warning("ICP MC send setup failed, res=%d, ip=%s bind_ip=%s",
+            status,
+            ink_inet_nptop(pMC->GetIP(), ipb, sizeof(ipb)),
+            ink_inet_nptop(_LocalPeer->GetIP(), ipb2, sizeof(ipb2))
+          );
           REC_SignalWarning(REC_SIGNAL_CONFIG_ERROR, "ICP MC send setup failed");
           return 1;             // Failed
         }
 
-        status = pMC->GetRecvChan()->setup_mc_receive(pMC->GetIP()->s_addr,
-                                                      pMC->GetPort(),
+        status = pMC->GetRecvChan()->setup_mc_receive(pMC->GetIP(),
                                                       NON_BLOCKING, pMC->GetSendChan(), _mcastCB_handler);
         if (status) {
-          unsigned char x[4];
-          *(uint32_t *) & x = (uint32_t) pMC->GetIP()->s_addr;
           // coverity[uninit_use_in_call]
-          Warning("ICP MC recv setup failed, res=%d, ip=%d.%d.%d.%d:%d",
-                  status, x[0], x[1], x[2], x[3], pMC->GetPort());
+          Warning("ICP MC recv setup failed, res=%d, ip=%s",
+            status, ink_inet_nptop(pMC->GetIP(), ipb, sizeof(ipb)));
           REC_SignalWarning(REC_SIGNAL_CONFIG_ERROR, "ICP MC recv setup failed");
           return 1;             // Failed
         }
@@ -2241,7 +2239,7 @@ ICPProcessor::SetupListenSockets()
   //
   ParentSiblingPeer *pPS = (ParentSiblingPeer *) ((Peer *) _LocalPeer);
 
-  pPS->GetChan()->setRemote(pPS->GetIP()->s_addr, pPS->GetPort());
+  pPS->GetChan()->setRemote(pPS->GetIP());
   return 0;                     // Success
 }
 
@@ -2405,28 +2403,29 @@ ICPProcessor::CancelPendingReads()
 }
 
 Peer *
-ICPProcessor::GenericFindListPeer(struct in_addr *ip, int port, int validListItems, Ptr<Peer> *List)
+ICPProcessor::GenericFindListPeer(InkInetAddr const& ip, uint16_t port, int validListItems, Ptr<Peer> *List)
 {
   Peer *P;
+  port = htons(port);
   for (int n = 0; n < validListItems; ++n) {
     if ((P = List[n])) {
-      if ((P->GetIP()->s_addr == ip->s_addr)
-          && ((port == -1) || (P->GetPort() == port)))
+      if ((P->GetIP() == ip)
+        && ((port == 0) || (ink_inet_port_cast(P->GetIP()) == port)))
         return P;
     }
   }
-  return (Peer *) 0;
+  return NULL;
 }
 
 Peer *
-ICPProcessor::FindPeer(struct in_addr * ip, int port)
+ICPProcessor::FindPeer(InkInetAddr const& ip, uint16_t port)
 {
   // Find (Peer *) with the given (ip,port) on the global list (PeerList)
   return GenericFindListPeer(ip, port, (_nPeerList + 1), _PeerList);
 }
 
 Peer *
-ICPProcessor::FindSendListPeer(struct in_addr * ip, int port)
+ICPProcessor::FindSendListPeer(InkInetAddr const& ip, uint16_t port)
 {
   // Find (Peer *) with the given (ip,port) on the
   //  scheduler list (SendPeerList)
@@ -2434,7 +2433,7 @@ ICPProcessor::FindSendListPeer(struct in
 }
 
 Peer *
-ICPProcessor::FindRecvListPeer(struct in_addr * ip, int port)
+ICPProcessor::FindRecvListPeer(InkInetAddr const& ip, uint16_t port)
 {
   // Find (Peer *) with the given (ip,port) on the
   //  receive list (RecvPeerList)
@@ -2451,11 +2450,10 @@ ICPProcessor::AddPeer(Peer * P)
   //
   // Make sure no duplicate exists
   //
-  if (FindPeer(P->GetIP(), P->GetPort())) {
-    unsigned char x[4];
-    *(uint32_t *) & x = (uint32_t) P->GetIP()->s_addr;
+  if (FindPeer(P->GetIP())) {
+    ip_port_text_buffer x;
     // coverity[uninit_use_in_call]
-    Warning("bad icp.config, multiple peer definitions for ip=%d.%d.%d.%d", x[0], x[1], x[2], x[3]);
+    Warning("bad icp.config, multiple peer definitions for ip=%s", ink_inet_nptop(P->GetIP(), x, sizeof(x)));
     REC_SignalWarning(REC_SIGNAL_CONFIG_ERROR, "bad icp.config, multiple peer definitions");
 
     return 0;                   // Not added
@@ -2480,7 +2478,7 @@ ICPProcessor::AddPeerToRecvList(Peer * P
   // Returns 1 - added; 0 - Not added
 
   // Assert that no duplicate exists
-  ink_assert(FindRecvListPeer(P->GetIP(), P->GetPort()) == 0);
+  ink_assert(FindRecvListPeer(InkInetAddr(P->GetIP()), ink_inet_get_port(P->GetIP())) == 0);
 
   if (_nRecvPeerList + 1 < RECV_PEER_LIST_SIZE) {
     _nRecvPeerList++;
@@ -2499,7 +2497,7 @@ ICPProcessor::AddPeerToSendList(Peer * P
   // Returns 1 - added; 0 - Not added
 
   // Assert that no duplicate exists
-  ink_assert(FindSendListPeer(P->GetIP(), P->GetPort()) == 0);
+  ink_assert(FindSendListPeer(InkInetAddr(P->GetIP()), ink_inet_get_port(P->GetIP())) == 0);
 
   if (_nSendPeerList + 1 < SEND_PEER_LIST_SIZE) {
     _nSendPeerList++;

Modified: trafficserver/traffic/trunk/proxy/ICP.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/ICP.h?rev=1187650&r1=1187649&r2=1187650&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/ICP.h (original)
+++ trafficserver/traffic/trunk/proxy/ICP.h Sat Oct 22 04:47:26 2011
@@ -315,12 +315,12 @@ class PeerConfigData
 
 public:
     PeerConfigData();
-    PeerConfigData(int ctype, struct in_addr *ip_addr, int proxy_port, int icp_port)
-  : _ctype(ctype), _ip_addr(*ip_addr),
-    _proxy_port(proxy_port), _icp_port(icp_port), _mc_member(0), _mc_ttl(0), _my_ip_addr(*ip_addr)
+    PeerConfigData(int ctype, InkInetAddr const& ip_addr, int proxy_port, int icp_port)
+      : _ctype(ctype), _ip_addr(ip_addr),
+      _proxy_port(proxy_port), _icp_port(icp_port), _mc_member(0), _mc_ttl(0),
+      _my_ip_addr(ip_addr)
   {
     _hostname[0] = 0;
-    _mc_ip_addr.s_addr = 0;
   }
    ~PeerConfigData()
   {
@@ -334,9 +334,9 @@ public:
   {
     return _ctype;
   }
-  inline struct in_addr *GetIP()
+  inline InkInetAddr const& GetIPAddr()
   {
-    return &_my_ip_addr;
+    return _my_ip_addr;
   }
   inline int GetProxyPort()
   {
@@ -350,9 +350,9 @@ public:
   {
     return _mc_member;
   }
-  inline struct in_addr *GetMultiCastIP()
+  inline InkInetAddr const& GetMultiCastIPAddr()
   {
-    return &_mc_ip_addr;
+    return _mc_ip_addr;
   }
   inline int GetMultiCastTTL()
   {
@@ -361,7 +361,7 @@ public:
 
   // Static member functions
   static PeerType_t CTypeToPeerType_t(int);
-  static int GetHostIPByName(char *, struct in_addr *);
+  static int GetHostIPByName(char *, InkInetAddr&);
 
   enum
   { HOSTNAME_SIZE = 256 };
@@ -378,20 +378,20 @@ private:
   //---------------------------------------------------------
   char _hostname[HOSTNAME_SIZE];
   int _ctype;
-  struct in_addr _ip_addr;
+  InkInetAddr _ip_addr;
   int _proxy_port;
   int _icp_port;
   //-------------------
   // MultiCast data
   //-------------------
   int _mc_member;
-  struct in_addr _mc_ip_addr;
+  InkInetAddr _mc_ip_addr;
   int _mc_ttl;
 
   //----------------------------------------------
   // Computed data not subject to "==" test
   //----------------------------------------------
-  struct in_addr _my_ip_addr;
+  InkInetAddr _my_ip_addr;
 };
 
 //---------------------------------------------------------------
@@ -508,19 +508,18 @@ public:
   void LogRecvMsg(ICPMsg_t *, int);
 
   // Pure virtual functions
-  virtual struct in_addr *GetIP() = 0;
-  virtual int GetPort() = 0;
-  virtual Action *SendMsg_re(Continuation *, void *, struct msghdr *, struct sockaddr_in *to) = 0;
+  virtual sockaddr* GetIP() = 0;
+  virtual Action *SendMsg_re(Continuation *, void *, struct msghdr *, struct sockaddr const* to) = 0;
   virtual Action *RecvFrom_re(Continuation *, void *, IOBufferBlock *, int, struct sockaddr *, socklen_t *) = 0;
   virtual int GetRecvFD() = 0;
   virtual int GetSendFD() = 0;
   virtual int ExpectedReplies(BitMap *) = 0;
-  virtual int ValidSender(struct sockaddr_in *) = 0;
-  virtual void LogSendMsg(ICPMsg_t *, struct sockaddr_in *) = 0;
+  virtual int ValidSender(sockaddr *) = 0;
+  virtual void LogSendMsg(ICPMsg_t *, sockaddr const*) = 0;
   virtual int IsOnline() = 0;
   virtual Connection *GetSendChan() = 0;
   virtual Connection *GetRecvChan() = 0;
-  virtual int ExtToIntRecvSockAddr(struct sockaddr_in *, struct sockaddr_in *) = 0;
+  virtual int ExtToIntRecvSockAddr(sockaddr const*, sockaddr *) = 0;
 
   enum
   { OFFLINE_THRESHOLD = 20 };
@@ -569,7 +568,7 @@ public:
   // these shouldn't be public
   // this is for delayed I/O
   Ptr<IOBufferBlock> buf;
-  struct sockaddr_in fromaddr;
+  ts_ip_endpoint fromaddr;
   socklen_t fromaddrlen;
   int notFirstRead;             // priming the reads
   Action *readAction;           // outstanding read
@@ -614,16 +613,15 @@ public:
       delete _pconfig;
   }
   int GetProxyPort();
-  virtual struct in_addr *GetIP();
-  virtual int GetPort();
-  virtual Action *SendMsg_re(Continuation *, void *, struct msghdr *, struct sockaddr_in *to);
+  virtual sockaddr* GetIP();
+  virtual Action *SendMsg_re(Continuation *, void *, struct msghdr *, struct sockaddr const* to);
   virtual Action *RecvFrom_re(Continuation *, void *, IOBufferBlock *, int, struct sockaddr *, socklen_t *);
   virtual int GetRecvFD();
   virtual int GetSendFD();
   virtual int ExpectedReplies(BitMap *);
-  virtual int ValidSender(struct sockaddr_in *);
-  virtual void LogSendMsg(ICPMsg_t *, struct sockaddr_in *);
-  virtual int ExtToIntRecvSockAddr(struct sockaddr_in *in, struct sockaddr_in *out);
+  virtual int ValidSender(struct sockaddr*);
+  virtual void LogSendMsg(ICPMsg_t *, sockaddr const*);
+  virtual int ExtToIntRecvSockAddr(sockaddr const* in, sockaddr* out);
   inline virtual int IsOnline()
   {
     return 1;
@@ -648,6 +646,7 @@ public:
 private:
   // Class data declarations
   PeerConfigData * _pconfig;    // associated config data
+  ts_ip_endpoint _ip; ///< Cache for GetIP().
   Connection _chan;
 };
 
@@ -657,23 +656,28 @@ private:
 class MultiCastPeer:public Peer
 {
 public:
-  MultiCastPeer(struct in_addr *, int, int, ICPProcessor *);
+  MultiCastPeer(InkInetAddr const&, uint16_t, int, ICPProcessor *);
   ~MultiCastPeer()
   {
   }
   int GetTTL();
   int AddMultiCastChild(Peer * P);
-  Peer *FindMultiCastChild(struct in_addr *ip, int port);
+  /** Find the multicast child peer with IP address @a ip on @a port.
+      If @a port is 0 the port is not checked.
+  */
+  Peer *FindMultiCastChild(
+    InkInetAddr const& ip, ///< IP address.
+    uint16_t port = 0 ///< Port (host order).
+  );
 
-  virtual struct in_addr *GetIP();
-  virtual int GetPort();
-  virtual Action *SendMsg_re(Continuation *, void *, struct msghdr *, struct sockaddr_in *to);
+  virtual sockaddr* GetIP();
+  virtual Action *SendMsg_re(Continuation *, void *, struct msghdr *, struct sockaddr const* to);
   virtual Action *RecvFrom_re(Continuation *, void *, IOBufferBlock *, int, struct sockaddr *, socklen_t *);
   virtual int GetRecvFD();
   virtual int GetSendFD();
   virtual int ExpectedReplies(BitMap *);
-  virtual int ValidSender(struct sockaddr_in *);
-  virtual void LogSendMsg(ICPMsg_t *, struct sockaddr_in *);
+  virtual int ValidSender(struct sockaddr*);
+  virtual void LogSendMsg(ICPMsg_t *, sockaddr const*);
   virtual int IsOnline();
   inline virtual Connection *GetRecvChan()
   {
@@ -683,12 +687,12 @@ public:
   {
     return &_send_chan;
   }
-  inline virtual int ExtToIntRecvSockAddr(struct sockaddr_in *in, struct sockaddr_in *out)
+  inline virtual int ExtToIntRecvSockAddr(sockaddr const* in, sockaddr* out)
   {
-    Peer *P = FindMultiCastChild(&in->sin_addr, 0);
+    Peer *P = FindMultiCastChild(InkInetAddr(in));
     if (P) {
-      out->sin_addr = in->sin_addr;
-      out->sin_port = htons(P->GetPort());
+      ink_inet_copy(out, in);
+      ink_inet_port_cast(out) = ink_inet_port_cast(P->GetIP());
       return 1;
     } else {
       return 0;
@@ -702,7 +706,7 @@ private:
   //---------------------------
   // Multicast specific data
   //---------------------------
-  struct sockaddr_in _mc_addr;
+  ts_ip_endpoint _mc_ip;
   int _mc_ttl;
   struct multicast_data
   {
@@ -763,7 +767,14 @@ public:
   } ReconfigState_t;
   ReconfigState_t ReconfigureStateMachine(ReconfigState_t, int, int);
 
-  Peer *FindPeer(struct in_addr *, int);
+  Peer *FindPeer(InkInetAddr const& ip, uint16_t port = 0);
+  Peer *FindPeer(ts_ip_endpoint const& ip) {
+    return this->FindPeer(InkInetAddr(&ip), ink_inet_get_port(&ip));
+  }
+  Peer *FindPeer(sockaddr const* ip) {
+    return this->FindPeer(InkInetAddr(ip), ink_inet_get_port(ip));
+  }
+
   inline Peer *GetLocalPeer()
   {
     return _LocalPeer;
@@ -836,9 +847,9 @@ private:
     _PendingIcpQueries--;
   }
 
-  Peer *GenericFindListPeer(struct in_addr *, int, int, Ptr<Peer> *);
-  Peer *FindSendListPeer(struct in_addr *, int);
-  Peer *FindRecvListPeer(struct in_addr *, int);
+  Peer *GenericFindListPeer(InkInetAddr const&, uint16_t, int, Ptr<Peer> *);
+  Peer *FindSendListPeer(InkInetAddr const&, uint16_t);
+  Peer *FindRecvListPeer(InkInetAddr const&, uint16_t);
   int AddPeer(Peer *);
   int AddPeerToSendList(Peer *);
   int AddPeerToRecvList(Peer *);
@@ -1066,7 +1077,7 @@ public:
       Ptr<IOBufferBlock> _buf;       // the buffer with the ICP message in it
     ICPMsg_t *_rICPmsg;
     int _rICPmsg_len;
-    struct sockaddr_in _sender; // sender of rICPmsg
+    ts_ip_endpoint _sender; // sender of rICPmsg
     URL _cachelookupURL;
     int _queryResult;
     ICPRequestCont *_ICPReqCont;
@@ -1188,7 +1199,7 @@ private:
   URL *_url;
 
   // Return data
-  struct sockaddr_in _ret_sockaddr;
+  ts_ip_endpoint _ret_sockaddr;
   ICPreturn_t _ret_status;
   class Action _act;
 

Modified: trafficserver/traffic/trunk/proxy/ICPConfig.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/ICPConfig.cc?rev=1187650&r1=1187649&r2=1187650&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/ICPConfig.cc (original)
+++ trafficserver/traffic/trunk/proxy/ICPConfig.cc Sat Oct 22 04:47:26 2011
@@ -282,9 +282,6 @@ ICPConfigData::operator==(ICPConfigData 
 PeerConfigData::PeerConfigData():_ctype(CTYPE_NONE), _proxy_port(0), _icp_port(0), _mc_member(0), _mc_ttl(0)
 {
   memset(_hostname, 0, HOSTNAME_SIZE);
-  _ip_addr.s_addr = 0;
-  _mc_ip_addr.s_addr = 0;
-  _my_ip_addr.s_addr = 0;
 }
 
 PeerType_t PeerConfigData::CTypeToPeerType_t(int ctype)
@@ -305,34 +302,33 @@ PeerType_t PeerConfigData::CTypeToPeerTy
 }
 
 int
-PeerConfigData::GetHostIPByName(char *hostname, struct in_addr *rip)
+PeerConfigData::GetHostIPByName(char *hostname, InkInetAddr& rip)
 {
-  // Returns 0 on success.
-  ink_gethostbyname_r_data d;
-  struct hostent *h = 0;
-
   // Short circuit NULL hostname case
-  if (hostname && (hostname[0] == 0))
-    return 1;                   // Unable to map to IP address
-  h = ink_gethostbyname_r(hostname, &d);
-  if (!h)
+  if (0 == hostname || 0 == *hostname)
     return 1;                   // Unable to map to IP address
 
-  // If multiple IP addresses, select lowest IP address
-  unsigned int curIP;
-  unsigned int IP;
-  curIP = (unsigned int) -1;    // 0xFFFFFFFF
-
-  for (int i = 0; h->h_addr_list[i]; i++) {
-    IP = ntohl(*((unsigned int *) h->h_addr_list[i]));
-    if (curIP > IP)
-      curIP = IP;
+  addrinfo hints;
+  addrinfo *ai;
+  sockaddr const* best = 0;
+
+  ink_zero(hints);
+  hints.ai_family = AF_UNSPEC;
+  hints.ai_flags = AI_ADDRCONFIG;
+  if (0 == getaddrinfo(hostname, 0, &hints, &ai)) {
+    for ( addrinfo *spot = ai ; spot ; spot = spot->ai_next) {
+      // If current address is valid, and either we don't have one yet
+      // or this address is less than our current, set it as current.
+      if (ink_inet_is_ip(spot->ai_addr) &&
+        (!best || -1 == ink_inet_cmp(spot->ai_addr, best))
+      ) {
+        best = spot->ai_addr;
+      }
+    }
+    if (best) rip.assign(best);
+    freeaddrinfo(ai);
   }
-  if (curIP == (unsigned int) -1)
-    rip->s_addr = 0;
-  else
-    rip->s_addr = htonl(curIP);
-  return 0;
+  return best ? 0 : 1;
 }
 
 bool PeerConfigData::operator==(PeerConfigData & PeerData)
@@ -341,7 +337,7 @@ bool PeerConfigData::operator==(PeerConf
     return false;
   if (PeerData._ctype != _ctype)
     return false;
-  if (PeerData._ip_addr.s_addr != _ip_addr.s_addr)
+  if (PeerData._ip_addr != _ip_addr)
     return false;
   if (PeerData._proxy_port != _proxy_port)
     return false;
@@ -349,7 +345,7 @@ bool PeerConfigData::operator==(PeerConf
     return false;
   if (PeerData._mc_member != _mc_member)
     return false;
-  if (PeerData._mc_ip_addr.s_addr != _mc_ip_addr.s_addr)
+  if (PeerData._mc_ip_addr != _mc_ip_addr)
     return false;
   if (PeerData._mc_ttl != _mc_ttl)
     return false;
@@ -478,12 +474,12 @@ ICPConfiguration::UpdatePeerConfig()
     //
     memcpy(_peer_cdata[i], _peer_cdata_current[i], sizeof(*_peer_cdata[i]));
     // Setup IP address
-    if ((_peer_cdata[i]->_ip_addr.s_addr == 0) && _peer_cdata[i]->_hostname) {
+    if ((_peer_cdata[i]->_ip_addr.isValid()) && _peer_cdata[i]->_hostname) {
       // IP address not specified, lookup using hostname.
-      (void) PeerConfigData::GetHostIPByName(_peer_cdata[i]->_hostname, &_peer_cdata[i]->_my_ip_addr);
+      (void) PeerConfigData::GetHostIPByName(_peer_cdata[i]->_hostname, _peer_cdata[i]->_my_ip_addr);
     } else {
       // IP address specified by user, lookup on hostname not required.
-      _peer_cdata[i]->_my_ip_addr.s_addr = _peer_cdata[i]->_ip_addr.s_addr;
+      _peer_cdata[i]->_my_ip_addr = _peer_cdata[i]->_ip_addr;
     }
   }
 }
@@ -506,6 +502,15 @@ ICPConfiguration::mgr_icp_config_change_
   return EVENT_DONE;
 }
 
+namespace {
+  inline char* next_field(char* text, char fs) {
+    text = strchr(text, fs);
+    // Compress contiguous whitespace by leaving zret pointing at the last space.
+    if (text && *text == fs)
+      while (text[1] == fs) ++text;
+    return text;
+  }
+}
 
 void *
 ICPConfiguration::icp_config_change_callback(void *data, void *value, int startup)
@@ -575,10 +580,12 @@ ICPConfiguration::icp_config_change_call
   int error = 0;
   int ln = 0;
   int n_colons;
-  char line[256];
+  char line[512];
   char *cur;
   char *next;
   char *p;
+  char fs = ':'; // field separator.
+  int len; // length of current input line (original).
 
   int n = 1;                    // Note: Entry zero reserved for "localhost" data
 
@@ -587,11 +594,11 @@ ICPConfiguration::icp_config_change_call
   //
   // Note: ink_file_fd_readline() null terminates returned buffer
   //////////////////////////////////////////////////////////////////////
-  while (ink_file_fd_readline(fd, sizeof(line) - 1, line) > 0) {
+  while ((len = ink_file_fd_readline(fd, sizeof(line) - 1, line)) > 0) {
     ln++;
-    if (*line == '#')
-      continue;
-    if (*line == '\n' || *line == '\r')
+    cur = line;
+    while (isspace(*cur)) ++cur, --len; // skip leading space.
+    if (!*cur || *cur == '#')
       continue;
 
     if (n >= MAX_DEFINED_PEERS) {
@@ -600,26 +607,40 @@ ICPConfiguration::icp_config_change_call
       error = 1;
       break;
     }
-    cur = line;
     //***********************************
     // Verify general syntax of entry
     //***********************************
+    /* Ugly. The original field separator was colon, but we can't have that
+       if we want to support IPv6. So - since each line is required to have a
+       separator at the end of the line, we look there and require it to be
+       consistent. It still must be an acceptable character.
+    */
+    char* last = cur + len -1; // last character.
+    if ('\n' == *last) --last; // back over trailing LF.
+    if (NULL == strchr(" ;:|,", *last)) {
+      Warning("read icp.config, invalid separator [value %d]", *last);
+      REC_SignalWarning(REC_SIGNAL_CONFIG_ERROR, "read icp.config, invalid separator");
+      error = 1;
+      break;
+    }
+    fs = *last;
+
     n_colons = 0;
     p = cur;
-    while ((p = strchr(p, ':'))) {
+    while (0 != (p = next_field(p, fs))) {
       ++p;
       ++n_colons;
     }
     if (n_colons != colons_per_entry) {
-      Warning("read icp.config, invalid syntax, line %d", ln);
-      REC_SignalWarning(REC_SIGNAL_CONFIG_ERROR, "read icp.config, invalid syntax");
+      Warning("read icp.config, invalid syntax, line %d: expected %d fields, found %d", ln, colons_per_entry, n_colons);
+      REC_SignalWarning(REC_SIGNAL_CONFIG_ERROR, "read icp.config, invalid syntax: wrong number of fields");
       error = 1;
       break;
     }
     //*******************
     // Extract hostname
     //*******************
-    next = strchr(cur, ':');
+    next = next_field(cur, fs);
     *next++ = 0;
     if (cur != (next - 1)) {
       ink_strlcpy(P[n]._hostname, cur, PeerConfigData::HOSTNAME_SIZE);
@@ -630,20 +651,20 @@ ICPConfiguration::icp_config_change_call
     // Extract host_ip_str
     //*********************
     cur = next;
-    next = strchr(cur, ':');
+    next = next_field(next, fs);
     *next++ = 0;
     if (cur != (next - 1)) {
-      if ((P[n]._ip_addr.s_addr = inet_addr(cur)) == 0xffffffff) {
+      if (0 != P[n]._ip_addr.load(cur)) {
         Warning("read icp.config, bad host ip_addr, line %d", ln);
         REC_SignalWarning(REC_SIGNAL_CONFIG_ERROR, "read icp.config, bad host ip_addr");
         error = 1;
         break;
       }
     } else {
-      P[n]._ip_addr.s_addr = 0;
+      P[n]._ip_addr.invalidate();
     }
 
-    if (!P[n]._hostname[0] && !P[n]._ip_addr.s_addr) {
+    if (!P[n]._hostname[0] && !P[n]._ip_addr.isValid()) {
       Warning("read icp.config, bad hostname, line %d", ln);
       REC_SignalWarning(REC_SIGNAL_CONFIG_ERROR, "read icp.config, bad hostname");
       error = 1;
@@ -653,7 +674,7 @@ ICPConfiguration::icp_config_change_call
     // Extract ctype
     //******************
     cur = next;
-    next = strchr(cur, ':');
+    next = next_field(next, fs);
     *next++ = 0;
     if (cur != (next - 1)) {
       P[n]._ctype = atoi(cur);
@@ -673,7 +694,7 @@ ICPConfiguration::icp_config_change_call
     // Extract proxy_port
     //*********************
     cur = next;
-    next = strchr(cur, ':');
+    next = next_field(next, fs);
     *next++ = 0;
     if (cur != (next - 1)) {
       if ((P[n]._proxy_port = atoi(cur)) <= 0) {
@@ -692,7 +713,7 @@ ICPConfiguration::icp_config_change_call
     // Extract icp_port
     //*********************
     cur = next;
-    next = strchr(cur, ':');
+    next = next_field(next, fs);
     *next++ = 0;
     if (cur != (next - 1)) {
       if ((P[n]._icp_port = atoi(cur)) <= 0) {
@@ -711,7 +732,7 @@ ICPConfiguration::icp_config_change_call
     // Extract multicast_member
     //****************************
     cur = next;
-    next = strchr(cur, ':');
+    next = next_field(next, fs);
     *next++ = 0;
     if (cur != (next - 1)) {
       if ((P[n]._mc_member = atoi(cur)) < 0) {
@@ -736,28 +757,26 @@ ICPConfiguration::icp_config_change_call
     // Extract multicast_ip_str
     //****************************
     cur = next;
-    next = strchr(cur, ':');
+    next = next_field(next, fs);
     *next++ = 0;
     if (cur != (next - 1)) {
-      P[n]._mc_ip_addr.s_addr = inet_addr(cur);
+      P[n]._mc_ip_addr.load(cur);
       // Validate only if "multicast_member" is set.
-      if ((P[n]._mc_member != 0) &&
-          ((P[n]._mc_ip_addr.s_addr == 0xffffffff) ||
-           (P[n]._mc_ip_addr.s_addr<mc_min_ip_addr.s_addr) || (P[n]._mc_ip_addr.s_addr> mc_max_ip_addr.s_addr))) {
+      if (P[n]._mc_member != 0 && !P[n]._mc_ip_addr.isMulticast()) {
         Warning("read icp.config, bad multicast ip_addr, line %d", ln);
         REC_SignalWarning(REC_SIGNAL_CONFIG_ERROR, "read icp.config, bad multicast ip_addr");
         error = 1;
         break;
       }
     } else {
-      P[n]._mc_ip_addr.s_addr = 0;
+      P[n]._mc_ip_addr.invalidate();
     }
     //************************
     // Extract multicast_ttl
     //************************
     // Note: last entry is always terminated with a ":"
     cur = next;
-    next = strchr(cur, ':');
+    next = next_field(next, fs);
     *next++ = 0;
     if (cur != (next - 1)) {
       P[n]._mc_ttl = atoi(cur);
@@ -798,7 +817,7 @@ buf(NULL), notFirstRead(0), readAction(N
     _state |= PEER_DYNAMIC;
   }
   memset((void *) &this->_stats, 0, sizeof(this->_stats));
-  memset((void *) &fromaddr, 0, sizeof(fromaddr));
+  ink_zero(fromaddr);
   fromaddrlen = sizeof(fromaddr);
   _id = 0;
 }
@@ -822,12 +841,13 @@ Peer::LogRecvMsg(ICPMsg_t * m, int valid
     _stats.dropped_replies++;
   }
   if ((_state & PEER_UP) == 0) {
+    ip_port_text_buffer ipb;
     // Currently marked down so we still send but do not expect reply.
     // Now mark up so we will wait for reply.
     _state |= PEER_UP;
     _stats.total_received = _stats.total_sent;  // restart timeout count
 
-    Debug("icp", "Peer [%s:%d] now back online", inet_ntoa(*GetIP()), GetPort());
+    Debug("icp", "Peer [%s] now back online", ink_inet_nptop(this->GetIP(), ipb, sizeof(ipb)));
   }
 }
 
@@ -838,6 +858,7 @@ Peer::LogRecvMsg(ICPMsg_t * m, int valid
 ParentSiblingPeer::ParentSiblingPeer(PeerType_t t, PeerConfigData * p, ICPProcessor * icpPr, bool dynamic_peer)
 :Peer(t, icpPr, dynamic_peer), _pconfig(p)
 {
+  ink_inet_ip_set(&_ip.sa, _pconfig->GetIPAddr(), htons(_pconfig->GetICPPort()));
 }
 
 int
@@ -846,20 +867,16 @@ ParentSiblingPeer::GetProxyPort()
   return _pconfig->GetProxyPort();
 }
 
-struct in_addr *
+sockaddr*
 ParentSiblingPeer::GetIP()
 {
-  return _pconfig->GetIP();
-}
-
-int
-ParentSiblingPeer::GetPort()
-{
-  return _pconfig->GetICPPort();
+  // The real data is in _pconfig, but I don't think ever changes so
+  // it should be OK to have set this in the constructor.
+  return &_ip.sa;
 }
 
 Action *
-ParentSiblingPeer::SendMsg_re(Continuation * cont, void *token, struct msghdr * msg, struct sockaddr_in * to)
+ParentSiblingPeer::SendMsg_re(Continuation * cont, void *token, struct msghdr * msg, sockaddr const* to)
 {
   // Note: All sends are funneled through the local peer UDP socket.
 
@@ -867,17 +884,17 @@ ParentSiblingPeer::SendMsg_re(Continuati
 
   if (to) {
     // Send to specified host
-    Peer *p = _ICPpr->FindPeer(&to->sin_addr, ntohs(to->sin_port));
+    Peer *p = _ICPpr->FindPeer(InkInetAddr(to), ntohs(ink_inet_port_cast(to)));
     ink_assert(p);
 
-    msg->msg_name = (caddr_t) & (p->GetSendChan())->addr;
-    msg->msg_namelen = sizeof((p->GetSendChan())->addr);
+    msg->msg_name = &p->GetSendChan()->addr;
+    msg->msg_namelen = ink_inet_ip_size(&p->GetSendChan()->addr);
     Action *a = udpNet.sendmsg_re(cont, token, lp->GetSendFD(), msg);
     return a;
   } else {
     // Send to default host
-    msg->msg_name = (caddr_t) & _chan.addr;
-    msg->msg_namelen = sizeof(_chan.addr);
+    msg->msg_name = & _chan.addr;
+    msg->msg_namelen = ink_inet_ip_size(&_chan.addr.sa);
     Action *a = udpNet.sendmsg_re(cont, token, lp->GetSendFD(), msg);
     return a;
   }
@@ -913,8 +930,9 @@ ParentSiblingPeer::ExpectedReplies(BitMa
 {
   if (((_state & PEER_UP) == 0) || ((_stats.total_sent - _stats.total_received) > Peer::OFFLINE_THRESHOLD)) {
     if (_state & PEER_UP) {
+      ip_port_text_buffer ipb;
       _state &= ~PEER_UP;
-      Debug("icp", "Peer [%s:%d] marked offline", inet_ntoa(*GetIP()), GetPort());
+      Debug("icp", "Peer [%s] marked offline", ink_inet_nptop(this->GetIP(), ipb, sizeof(ipb)));
     }
     //
     // We will continue to send messages, but will not wait for a reply
@@ -928,7 +946,7 @@ ParentSiblingPeer::ExpectedReplies(BitMa
 }
 
 int
-ParentSiblingPeer::ValidSender(struct sockaddr_in *fr)
+ParentSiblingPeer::ValidSender(sockaddr* fr)
 {
   if (_type == PEER_LOCAL) {
     //
@@ -937,7 +955,7 @@ ParentSiblingPeer::ValidSender(struct so
     // the sender is known within the ICP configuration,
     // consider it valid.
     //
-    Peer *p = _ICPpr->FindPeer(&fr->sin_addr, ntohs(fr->sin_port));
+    Peer *p = _ICPpr->FindPeer(fr);
     if (p) {
       return 1;                 // Valid sender
     } else {
@@ -946,8 +964,11 @@ ParentSiblingPeer::ValidSender(struct so
 
   } else {
     // Make sure the sockaddr_in corresponds to this peer
-    if ((GetIP()->s_addr == fr->sin_addr.s_addr)
-        && (GetPort() == (int)ntohs(fr->sin_port))) {
+    // Need to update once we have support for comparing address
+    // and port in a socakddr.
+    if (ink_inet_eq(this->GetIP(), fr) &&
+      (ink_inet_port_cast(this->GetIP()) == ink_inet_port_cast(fr))
+    ) {
       return 1;                 // Sender is this peer
     } else {
       return 0;                 // Sender is not this peer
@@ -956,7 +977,7 @@ ParentSiblingPeer::ValidSender(struct so
 }
 
 void
-ParentSiblingPeer::LogSendMsg(ICPMsg_t * m, struct sockaddr_in *sa)
+ParentSiblingPeer::LogSendMsg(ICPMsg_t * m, sockaddr const* sa)
 {
   NOWARN_UNUSED(sa);
   // Note: ICPMsg_t (m) is in network byte order
@@ -968,16 +989,12 @@ ParentSiblingPeer::LogSendMsg(ICPMsg_t *
 }
 
 int
-ParentSiblingPeer::ExtToIntRecvSockAddr(struct sockaddr_in *in, struct sockaddr_in *out)
+ParentSiblingPeer::ExtToIntRecvSockAddr(sockaddr const* in, sockaddr *out)
 {
-  Peer *p = _ICPpr->FindPeer(&in->sin_addr, -1);        // ignore port
+  Peer *p = _ICPpr->FindPeer(InkInetAddr(in));
   if (p && (p->GetType() != PEER_LOCAL)) {
     // Map from received (ip, port) to defined (ip, port).
-    struct sockaddr_in s;
-    memset((void *) &s, 0, sizeof(s));
-    s.sin_port = htons(p->GetPort());
-    s.sin_addr = *p->GetIP();
-    *out = s;
+    ink_inet_copy(out, p->GetIP());
     return 1;
   } else {
     return 0;
@@ -988,14 +1005,11 @@ ParentSiblingPeer::ExtToIntRecvSockAddr(
 // Class MultiCastPeer (derived from Peer) member functions
 //      ICP object describing MultiCast Peers.
 //-----------------------------------------------------------
-MultiCastPeer::MultiCastPeer(struct in_addr * ip, int mc_port, int ttl, ICPProcessor * icpPr)
+MultiCastPeer::MultiCastPeer(InkInetAddr const& addr, uint16_t mc_port, int ttl, ICPProcessor * icpPr)
 :Peer(PEER_MULTICAST, icpPr), _mc_ttl(ttl)
 {
-  memset((void *) &_mc_addr, 0, sizeof(_mc_addr));
-  _mc_addr.sin_family = AF_INET;
-  _mc_addr.sin_addr = *ip;
-  _mc_addr.sin_port = htons(mc_port);
-  memset((void *) &this->_mc, 0, sizeof(this->_mc));
+  ink_inet_ip_set(&_mc_ip.sa, addr, htons(mc_port));
+  memset(&this->_mc, 0, sizeof(this->_mc));
 }
 
 int
@@ -1004,26 +1018,20 @@ MultiCastPeer::GetTTL()
   return _mc_ttl;
 }
 
-struct in_addr *
+sockaddr *
 MultiCastPeer::GetIP()
 {
-  return &_mc_addr.sin_addr;
-}
-
-int
-MultiCastPeer::GetPort()
-{
-  return ntohs(_mc_addr.sin_port);
+  return &_mc_ip.sa;
 }
 
 Action *
-MultiCastPeer::SendMsg_re(Continuation * cont, void *token, struct msghdr * msg, struct sockaddr_in * to)
+MultiCastPeer::SendMsg_re(Continuation * cont, void *token, struct msghdr * msg, sockaddr const* to)
 {
   Action *a;
 
   if (to) {
     // Send to MultiCast group member (UniCast)
-    Peer *p = FindMultiCastChild(&to->sin_addr, ntohs(to->sin_port));
+    Peer *p = FindMultiCastChild(InkInetAddr(to), ink_inet_get_port(to));
     ink_assert(p);
     a = ((ParentSiblingPeer *) p)->SendMsg_re(cont, token, msg, 0);
   } else {
@@ -1074,15 +1082,16 @@ MultiCastPeer::ExpectedReplies(BitMap * 
 }
 
 int
-MultiCastPeer::ValidSender(struct sockaddr_in *sa)
+MultiCastPeer::ValidSender(sockaddr* sa)
 {
   // TBD: Use hash function
   // Make sure sockaddr_in corresponds to a defined peer in the
   //  MultiCast group.
   Peer *P = _next;
   while (P) {
-    if ((P->GetIP()->s_addr == sa->sin_addr.s_addr)
-        && (P->GetPort() == (int)ntohs(sa->sin_port))) {
+    if (ink_inet_eq(P->GetIP(), sa) &&
+      (ink_inet_port_cast(P->GetIP()) == ink_inet_port_cast(sa))
+    ) {
       return 1;
     } else {
       P = P->GetNext();
@@ -1092,7 +1101,7 @@ MultiCastPeer::ValidSender(struct sockad
 }
 
 void
-MultiCastPeer::LogSendMsg(ICPMsg_t * m, struct sockaddr_in *sa)
+MultiCastPeer::LogSendMsg(ICPMsg_t * m, sockaddr const* sa)
 {
   // Note: ICPMsg_t (m) is in network byte order
   if (sa) {
@@ -1100,7 +1109,7 @@ MultiCastPeer::LogSendMsg(ICPMsg_t * m, 
     //  target Peer.
     //
     Peer *p;
-    p = FindMultiCastChild(&sa->sin_addr, ntohs(sa->sin_port));
+    p = FindMultiCastChild(InkInetAddr(sa), ink_inet_get_port(sa));
     if (p)
       ((ParentSiblingPeer *) p)->LogSendMsg(m, sa);
 
@@ -1129,33 +1138,37 @@ MultiCastPeer::AddMultiCastChild(Peer * 
 {
   // Add (Peer *) to the given MultiCast structure.
   // Make sure child (ip,port) is unique.
-  if (FindMultiCastChild(P->GetIP(), P->GetPort())) {
-    unsigned char x[4] = { 0, 0, 0, 0 };
-    *(uint32_t *) & x = (uint32_t) P->GetIP()->s_addr;
-    Warning("bad icp.config, multiple multicast child definitions for ip=%d.%d.%d.%d", x[0], x[1], x[2], x[3]);
+  sockaddr const* ip = P->GetIP();
+  if (FindMultiCastChild(InkInetAddr(ip), ink_inet_get_port(ip))) {
+    ip_text_buffer x;
+    Warning("bad icp.config, multiple multicast child definitions for ip=%s", ink_inet_ntop(ip, x, sizeof(x)));
     return 0;                   // Not added, already exists
   } else {
     P->SetNext(this->_next);
     this->_next = P;
-    _mc.defined_members++;
+    ++_mc.defined_members;
     return 1;                   // Added
   }
 }
 
 Peer *
-MultiCastPeer::FindMultiCastChild(struct in_addr * ip, int port)
+MultiCastPeer::FindMultiCastChild(InkInetAddr const& addr, uint16_t port)
 {
-  // Locate child (Peer *) with the given (ip,port).
+  // Locate child (Peer *) with the given (ip,port). This is split out
+  // rather than using a sockaddr so we can indicate the port is to not
+  // be checked (@a port == 0).
   Peer *curP = this->_next;
   while (curP) {
-    if ((curP->GetIP()->s_addr == ip->s_addr)
-        && (!port || (curP->GetPort() == port))) {
+    sockaddr const* peer_ip = curP->GetIP();
+    if (addr == peer_ip &&
+      (!port || port == ink_inet_get_port(peer_ip))
+    ) {
       return curP;
     } else {
       curP = curP->GetNext();
     }
   }
-  return (Peer *) 0;
+  return NULL;
 }
 
 //-------------------------------------------------------------------------
@@ -1297,10 +1310,10 @@ ink_hrtime ICPlog::GetElapsedTime()
   return (ink_get_hrtime() - _s->_start_time);
 }
 
-struct in_addr *
+sockaddr const*
 ICPlog::GetClientIP()
 {
-  return &_s->_sender.sin_addr;
+  return &_s->_sender.sa;
 }
 
 SquidLogCode ICPlog::GetAction()
@@ -1436,8 +1449,7 @@ ICPProcessor::DumpICPConfig()
   Peer *P;
   PeerType_t type;
   int id;
-  unsigned char ip[4] = { 0, 0, 0, 0 };
-  int icp_port;
+  ip_port_text_buffer ipb;
 
   Debug("icp", "On=%d, MultiCast=%d, Timeout=%d LocalCacheLookup=%d",
         GetConfig()->globalConfig()->ICPconfigured(),
@@ -1451,8 +1463,6 @@ ICPProcessor::DumpICPConfig()
     P = _PeerList[i];
     id = P->GetPeerID();
     type = P->GetType();
-    *(uint32_t *) & ip = (uint32_t) (P->GetIP())->s_addr;
-    icp_port = P->GetPort();
     const char *str_type;
 
     switch (type) {
@@ -1484,19 +1494,19 @@ ICPProcessor::DumpICPConfig()
     }                           // End of switch
 
     if (*str_type == 'M') {
-      Debug("icp", "[%d]: Type=%s IP=%d.%d.%d.%d ICP_Port=%d", id, str_type, ip[0], ip[1], ip[2], ip[3], icp_port);
+      Debug("icp", "[%d]: Type=%s IP=%s", id, str_type, ink_inet_nptop(P->GetIP(), ipb, sizeof(ipb)));
     } else {
-      ParentSiblingPeer *Pps = (ParentSiblingPeer *) P;
+      ParentSiblingPeer *Pps = static_cast<ParentSiblingPeer *>(P);
       Debug("icp",
-            "[%d]: Type=%s IP=%d.%d.%d.%d Port=%d PPort=%d Host=%s",
-            id, str_type, ip[0], ip[1], ip[2], ip[3], icp_port,
-            Pps->GetConfig()->GetProxyPort(), Pps->GetConfig()->GetHostname());
-
-      *(uint32_t *) & ip = (uint32_t) (Pps->GetConfig()->GetMultiCastIP())->s_addr;
+            "[%d]: Type=%s IP=%s PPort=%d Host=%s",
+        id, str_type, ink_inet_nptop(P->GetIP(), ipb, sizeof(ipb)),
+        Pps->GetConfig()->GetProxyPort(), Pps->GetConfig()->GetHostname());
 
       Debug("icp",
-            "[%d]: MC ON=%d MC_IP=%d.%d.%d.%d MC_TTL=%d",
-            id, Pps->GetConfig()->MultiCastMember(), ip[0], ip[1], ip[2], ip[3], Pps->GetConfig()->GetMultiCastTTL());
+            "[%d]: MC ON=%d MC_IP=%s MC_TTL=%d",
+            id, Pps->GetConfig()->MultiCastMember(),
+        Pps->GetConfig()->GetMultiCastIPAddr().toString(ipb, sizeof(ipb)),
+        Pps->GetConfig()->GetMultiCastTTL());
     }
   }
 }

Modified: trafficserver/traffic/trunk/proxy/ICPlog.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/ICPlog.h?rev=1187650&r1=1187649&r2=1187650&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/ICPlog.h (original)
+++ trafficserver/traffic/trunk/proxy/ICPlog.h Sat Oct 22 04:47:26 2011
@@ -51,7 +51,7 @@ public:
   {
   }
   ink_hrtime GetElapsedTime();
-  struct in_addr *GetClientIP();
+  sockaddr const* GetClientIP();
   SquidLogCode GetAction();
   const char *GetCode();
   int GetSize();

Modified: trafficserver/traffic/trunk/proxy/config/icp.config.default
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/config/icp.config.default?rev=1187650&r1=1187649&r2=1187650&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/config/icp.config.default (original)
+++ trafficserver/traffic/trunk/proxy/config/icp.config.default Sat Oct 22 04:47:26 2011
@@ -2,28 +2,38 @@
 #
 # ICP Configuration -- Defines ICP parent/sibling configuration
 #
-#  Each line is formatted as follows with ":" separator for each field.
+#  Each line is formatted with a separator between fields. This can be
+#  a space, ':', ';', ',', or '|' but must be consistent for the
+#  entire line. There must be a terminating separator as the last
+#  character. The separator for the line is determined by this
+#  character. Note: if you use an IPv6 address, you must *not* use
+#  colon as a field separator.
+#
 #    - hostname (string)           -- Identifier for entry
 #    - host_ip_str (string)        -- decimal dot notation
 #    - ctype (int)                 -- 1=Parent, 2=Sibling
 #    - proxy_port (int)            -- TCP Port #
 #    - icp_port (int)              -- UDP Port #
 #    - multicast_member            -- 0=No 1=Yes
-#    - multicast_ip_str (string)   -- decimal dot notation
+#    - multicast_ip_str (string)   -- decimal dot notation for IPv4
 #				      224.0.0.0 - 239.255.255.255
+#				      colon notation for IPv6
+#				      FF05::2
 #    - multicast_ttl (int)         -- (1 - 2; default 1)
 #
 # <host>:<host IP>:<ctype>:<proxy port>:<icp port>:<MC on>:<mc IP>:<MC ttl>:
 #
-# Example #1 (1 parent and 1 sibling):
+# Example #1 (1 parent and 2 siblings):
 # ==============================================================
 #     host1:209.1.33.10:1:8080:3130:0:0.0.0.0:1:
-#     host2:209.1.33.11:2:8080:3130:0:0.0.0.0:1:
+#     host2;209.1.33.11;2;8080;3130;0;0.0.0.0;1;
+#     host3|fe80::208:54ff:fe47:d94d|2|8080|3130|0|::|1|
 #
 #
 # Example #2 (1 parent and 1 sibling using MultiCast):
 # ============================================================================
-#     host1:209.1.33.10:1:8080:3130:1:239.128.16.128:1:
-#     host2:209.1.33.11:2:8080:3130:1:239.128.16.128:1:
+#     host1 209.1.33.10 1 8080 3130 1 239.128.16.128 1 
+#     host2 209.1.33.11 2:8080:3130 1 239.128.16.128 1 
+# Note: trailing space in previous lines.
 #
 ###############################################################################

Modified: trafficserver/traffic/trunk/proxy/logging/LogAccessICP.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogAccessICP.cc?rev=1187650&r1=1187649&r2=1187650&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogAccessICP.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogAccessICP.cc Sat Oct 22 04:47:26 2011
@@ -69,7 +69,7 @@ int
 LogAccessICP::marshal_client_host_ip(char *buf)
 {
   if (buf) {
-    int64_t ip = m_icp_log->GetClientIP()->s_addr;
+    int64_t ip = ink_inet_ip4_addr_cast(m_icp_log->GetClientIP());
     // ip is already in network order
     marshal_int(buf, (int64_t)ntohl(ip));
   }



Mime
View raw message