trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r1159471 [2/2] - in /trafficserver/traffic/trunk: ./ iocore/cluster/ iocore/dns/ iocore/eventsystem/ iocore/hostdb/ iocore/net/ lib/ts/ proxy/ proxy/http/
Date Fri, 19 Aug 2011 01:30:38 GMT
Modified: trafficserver/traffic/trunk/iocore/net/UnixUDPNet.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/net/UnixUDPNet.cc?rev=1159471&r1=1159470&r2=1159471&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/net/UnixUDPNet.cc (original)
+++ trafficserver/traffic/trunk/iocore/net/UnixUDPNet.cc Fri Aug 19 01:30:36 2011
@@ -66,7 +66,7 @@ void *G_bulkIOState = NULL;
 InkPipeInfo G_inkPipeInfo;
 
 int G_bwGrapherFd;
-struct sockaddr_in G_bwGrapherLoc;
+sockaddr_in6 G_bwGrapherLoc;
 
 void
 initialize_thread_for_udp_net(EThread * thread)
@@ -132,7 +132,7 @@ UDPNetProcessorInternal::udp_read_from_n
   int r;
   int iters = 0;
   do {
-    struct sockaddr_in fromaddr;
+    sockaddr_in6 fromaddr;
     socklen_t fromlen = sizeof(fromaddr);
     // XXX: want to be 0 copy.
     // XXX: really should read into next contiguous region of an IOBufferData
@@ -145,7 +145,7 @@ UDPNetProcessorInternal::udp_read_from_n
       break;
     }
     // create packet
-    UDPPacket *p = new_incoming_UDPPacket(&fromaddr, buf, r);
+    UDPPacket *p = new_incoming_UDPPacket(ink_inet_sa_cast(&fromaddr), buf, r);
     p->setConnection(uc);
     // XXX: is this expensive?  I] really want to know this information
     p->setArrivalTime(ink_get_hrtime_internal());
@@ -219,7 +219,7 @@ private:
   // on behalf of the client
   Ptr<IOBufferBlock> readbuf;
   int readlen;
-  struct sockaddr *fromaddr;
+  struct sockaddr_in6 *fromaddr;
   socklen_t *fromaddrlen;
   int fd;                       // fd we are reading from
   int ifd;                      // poll fd index
@@ -282,7 +282,7 @@ UDPReadContinuation::init_read(int rfd, 
   fd = rfd;
   readbuf = buf;
   readlen = len;
-  fromaddr = fromaddr_;
+  fromaddr = ink_inet_ip6_cast(fromaddr_);
   fromaddrlen = fromaddrlen_;
   SET_HANDLER(&UDPReadContinuation::readPollEvent);
   period = NET_PERIOD;
@@ -356,7 +356,7 @@ UDPReadContinuation::readPollEvent(int e
     socklen_t tmp_fromlen = *fromaddrlen;
     int rlen = socketManager.recvfrom(fd, readbuf->end(), readlen,
                                       0,        // default flags
-                                      fromaddr, &tmp_fromlen);
+                                      ink_inet_sa_cast(fromaddr), &tmp_fromlen);
     completionUtil::setThread(event, e->ethread);
     // call back user with their event
     if (rlen > 0) {
@@ -496,7 +496,7 @@ UDPNetProcessor::sendmsg_re(Continuation
  */
 Action *
 UDPNetProcessor::sendto_re(Continuation * cont,
-                           void *token, int fd, struct sockaddr * toaddr, int toaddrlen, IOBufferBlock * buf, int len)
+                           void *token, int fd, struct sockaddr const* toaddr, int toaddrlen, IOBufferBlock * buf, int len)
 {
   (void) token;
   ink_assert(buf->read_avail() >= len);
@@ -514,43 +514,45 @@ UDPNetProcessor::sendto_re(Continuation 
 }
 
 Action *
-UDPNetProcessor::UDPCreatePortPairs(Continuation * cont,
-                                    int nPairs,
-                                    unsigned int myIP, unsigned int destIP, int send_bufsize, int recv_bufsize)
-{
+UDPNetProcessor::UDPCreatePortPairs(
+  Continuation * cont,
+  int nPairs,
+  sockaddr const* local_addr,
+  sockaddr const* remote_addr,
+  int send_bufsize, int recv_bufsize
+) {
 
   UDPWorkContinuation *worker = udpWorkContinuationAllocator.alloc();
   // UDPWorkContinuation *worker = NEW(new UDPWorkContinuation);
 
-  worker->init(cont, nPairs, myIP, destIP, send_bufsize, recv_bufsize);
+  worker->init(cont, nPairs, local_addr, remote_addr, send_bufsize, recv_bufsize);
   eventProcessor.schedule_imm(worker, ET_UDP);
   return &(worker->action);
 }
 
 
 bool
-UDPNetProcessor::CreateUDPSocket(int *resfd,
-                                 struct sockaddr_in * addr,
-                                 Action ** status, int my_port, unsigned int my_ip, int send_bufsize, int recv_bufsize)
-{
+UDPNetProcessor::CreateUDPSocket(
+  int *resfd,
+  sockaddr const* remote_addr,
+  sockaddr* local_addr,
+  int *local_addr_len,
+  Action ** status, 
+  int send_bufsize, int recv_bufsize
+) {
   int res = 0, fd = -1;
-  struct sockaddr_in bind_sa;
-  struct sockaddr_in myaddr;
-  int myaddr_len = sizeof(myaddr);
+
+  ink_assert(ink_inet_are_compatible(remote_addr, local_addr));
 
   *resfd = -1;
-  if ((res = socketManager.socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+  if ((res = socketManager.socket(remote_addr->sa_family, SOCK_DGRAM, 0)) < 0)
     goto HardError;
   fd = res;
   if ((res = safe_fcntl(fd, F_SETFL, O_NONBLOCK)) < 0)
     goto HardError;
-  memset(&bind_sa, 0, sizeof(bind_sa));
-  bind_sa.sin_family = AF_INET;
-  bind_sa.sin_port = htons(my_port);
-  bind_sa.sin_addr.s_addr = my_ip;
-  if ((res = socketManager.ink_bind(fd, (struct sockaddr *) &bind_sa, sizeof(bind_sa), IPPROTO_UDP)) < 0) {
-    unsigned char *pt = (unsigned char *) &my_ip;
-    Debug("udpnet", "ink bind failed --- my_ip = %d.%d.%d.%d", pt[0], pt[1], pt[2], pt[3]);
+  if ((res = socketManager.ink_bind(fd, remote_addr, ink_inet_ip_size(remote_addr), IPPROTO_UDP)) < 0) {
+    char buff[INET6_ADDRPORTSTRLEN];
+    Debug("udpnet", "ink bind failed on %s", ink_inet_nptop(remote_addr, buff, sizeof(buff)));
     goto SoftError;
   }
 
@@ -562,34 +564,29 @@ UDPNetProcessor::CreateUDPSocket(int *re
     if (unlikely(socketManager.set_sndbuf_size(fd, send_bufsize)))
       Debug("udpnet", "set_dnsbuf_size(%d) failed", send_bufsize);
   }
-  if ((res = safe_getsockname(fd, (struct sockaddr *) &myaddr, &myaddr_len)) < 0) {
+  if ((res = safe_getsockname(fd, local_addr, local_addr_len)) < 0) {
     Debug("udpnet", "CreateUdpsocket: getsockname didnt' work");
     goto HardError;
   }
-  if (!myaddr.sin_addr.s_addr) {
-    // set to default IP address for machine
-    /** netfixme ... this_machine() is in proxy.
-    if (this_machine()) {
-      myaddr.sin_addr.s_addr = this_machine()->ip;
-    } else {
-      Debug("udpnet","CreateUdpSocket -- machine not initialized");
-    }
-    */
-  }
   *resfd = fd;
-  memcpy(addr, &myaddr, myaddr_len);
   *status = NULL;
-  Debug("udpnet", "creating a udp socket port = %d, %d---success", my_port, addr->sin_port);
+  Debug("udpnet", "creating a udp socket port = %d, %d---success",
+    ink_inet_get_port(remote_addr), ink_inet_get_port(local_addr)
+  );
   return true;
 SoftError:
-  Debug("udpnet", "creating a udp socket port = %d---soft failure", my_port);
+  Debug("udpnet", "creating a udp socket port = %d---soft failure",
+    ink_inet_get_port(local_addr)
+  );
   if (fd != -1)
     socketManager.close(fd);
   *resfd = -1;
   *status = NULL;
   return false;
 HardError:
-  Debug("udpnet", "creating a udp socket port = %d---hard failure", my_port);
+  Debug("udpnet", "creating a udp socket port = %d---hard failure",
+    ink_inet_get_port(local_addr)
+  );
   if (fd != -1)
     socketManager.close(fd);
   *resfd = -1;
@@ -598,10 +595,12 @@ HardError:
 }
 
 void
-UDPNetProcessor::UDPClassifyConnection(Continuation * udpConn, int destIP)
-{
+UDPNetProcessor::UDPClassifyConnection(
+  Continuation * udpConn,
+  InkInetAddr const& destIP
+) {
   int i;
-  UDPConnectionInternal *p = (UDPConnectionInternal *) udpConn;
+  UDPConnectionInternal *p = static_cast<UDPConnectionInternal *>(udpConn);
 
   if (G_inkPipeInfo.numPipes == 0) {
     p->pipe_class = 0;
@@ -612,10 +611,11 @@ UDPNetProcessor::UDPClassifyConnection(C
   for (i = 0; i < G_inkPipeInfo.numPipes + 1; i++)
     if (G_inkPipeInfo.perPipeInfo[i].destIP == destIP)
       p->pipe_class = i;
-  // no match; set it to the destIP=0 class
+  // no match; set it to the null class
   if (p->pipe_class == -1) {
-    for (i = 0; i < G_inkPipeInfo.numPipes + 1; i++)
-      if (G_inkPipeInfo.perPipeInfo[i].destIP == 0) {
+    InkInetAddr null; // default constructed -> invalid value.
+    for (i = 0; i < G_inkPipeInfo.numPipes + 1; ++i)
+      if (G_inkPipeInfo.perPipeInfo[i].destIP == null) {
         p->pipe_class = i;
         break;
       }
@@ -628,23 +628,22 @@ UDPNetProcessor::UDPClassifyConnection(C
 }
 
 Action *
-UDPNetProcessor::UDPBind(Continuation * cont, int my_port, int my_ip, int send_bufsize, int recv_bufsize)
+UDPNetProcessor::UDPBind(Continuation * cont, sockaddr const* addr, int send_bufsize, int recv_bufsize)
 {
   int res = 0;
   int fd = -1;
   UnixUDPConnection *n = NULL;
-  struct sockaddr_in bind_sa;
-  struct sockaddr_in myaddr;
+  ts_ip_endpoint myaddr;
   int myaddr_len = sizeof(myaddr);
 
-  if ((res = socketManager.socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+  if ((res = socketManager.socket(addr->sa_family, SOCK_DGRAM, 0)) < 0)
     goto Lerror;
   fd = res;
   if ((res = fcntl(fd, F_SETFL, O_NONBLOCK) < 0))
     goto Lerror;
 
   // If this is a class D address (i.e. multicast address), use REUSEADDR.
-  if ((((unsigned int) (ntohl(my_ip))) & 0xf0000000) == 0xe0000000) {
+  if (ink_inet_is_multicast(addr)) {
     int enable_reuseaddr = 1;
 
     if ((res = safe_setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &enable_reuseaddr, sizeof(enable_reuseaddr)) < 0)) {
@@ -652,11 +651,7 @@ UDPNetProcessor::UDPBind(Continuation * 
     }
   }
 
-  memset(&bind_sa, 0, sizeof(bind_sa));
-  bind_sa.sin_family = AF_INET;
-  bind_sa.sin_port = htons(my_port);
-  bind_sa.sin_addr.s_addr = my_ip;
-  if ((res = socketManager.ink_bind(fd, (struct sockaddr *) &bind_sa, sizeof(bind_sa))) < 0) {
+  if ((res = socketManager.ink_bind(fd, addr, ink_inet_ip_size(addr))) < 0) {
     goto Lerror;
   }
 
@@ -668,23 +663,13 @@ UDPNetProcessor::UDPBind(Continuation * 
     if (unlikely(socketManager.set_sndbuf_size(fd, send_bufsize)))
       Debug("udpnet", "set_dnsbuf_size(%d) failed", send_bufsize);
   }
-  if ((res = safe_getsockname(fd, (struct sockaddr *) &myaddr, &myaddr_len)) < 0) {
+  if ((res = safe_getsockname(fd, &myaddr.sa, &myaddr_len)) < 0) {
     goto Lerror;
   }
-  if (!myaddr.sin_addr.s_addr) {
-    // set to default IP address for machine
-    /** netfixme this_machine is in proxy/
-    if (this_machine()) {
-      myaddr.sin_addr.s_addr = this_machine()->ip;
-    } else {
-      Debug("udpnet","UDPNetProcessor::UDPBind -- machine not initialized");
-    }
-    */
-  }
   n = NEW(new UnixUDPConnection(fd));
 
   Debug("udpnet", "UDPNetProcessor::UDPBind: %x fd=%d", n, fd);
-  n->setBinding(&myaddr);
+  n->setBinding(&myaddr.sa);
   n->bindToThread(cont);
 
   cont->handleEvent(NET_EVENT_DATAGRAM_OPEN, n);
@@ -1261,14 +1246,16 @@ UDPNetHandler::mainNetEvent(int event, E
 
 void
 UDPWorkContinuation::init(Continuation * c, int num_pairs,
-                          unsigned int my_ip, unsigned int dest_ip, int s_bufsize, int r_bufsize)
-{
+  sockaddr const* local_addr,
+  sockaddr const* remote_addr,
+  int s_bufsize, int r_bufsize
+) {
   mutex = c->mutex;
   cont = c;
   action = c;
   numPairs = num_pairs;
-  myIP = my_ip;
-  destIP = dest_ip;
+  ink_inet_copy(&local_ip, local_addr);
+  ink_inet_copy(&remote_ip, remote_addr);
   sendbufsize = s_bufsize;
   recvbufsize = r_bufsize;
   udpConns = NULL;
@@ -1283,8 +1270,8 @@ UDPWorkContinuation::StateCreatePortPair
 //  int res = 0;
   int numUdpPorts = 2 * numPairs;
   int fd1 = -1, fd2 = -1;
-//  struct sockaddr_in bind_sa;
-  struct sockaddr_in myaddr1, myaddr2;
+  ts_ip_endpoint target;
+  ts_ip_endpoint myaddr1, myaddr2;
   int portNum, i;
 //  int myaddr_len = sizeof(myaddr1);
   static int lastAllocPort = 10000;
@@ -1304,6 +1291,7 @@ UDPWorkContinuation::StateCreatePortPair
   }
 
   startTime = ink_get_hrtime_internal();
+  ink_inet_copy(&target, &remote_ip);
 
   udpConns = NEW(new UnixUDPConnection *[numUdpPorts]);
   for (i = 0; i < numUdpPorts; i++)
@@ -1316,13 +1304,25 @@ UDPWorkContinuation::StateCreatePortPair
   i = 0;
   while (i < numUdpPorts) {
 
-    if (udpNet.CreateUDPSocket(&fd1, &myaddr1, &status, portNum, myIP, sendbufsize, recvbufsize)) {
-      if (udpNet.CreateUDPSocket(&fd2, &myaddr2, &status, portNum + 1, myIP, sendbufsize, recvbufsize)) {
+    int myaddr1_len = sizeof(myaddr1);
+    int myaddr2_len = sizeof(myaddr2);
+    ink_inet_port_cast(&target) = htons(portNum);
+    if (udpNet.CreateUDPSocket(&fd1, 
+        &target.sa, 
+        &myaddr1.sa,
+        &myaddr1_len,
+        &status, sendbufsize, recvbufsize)) {
+      ink_inet_port_cast(&target) = htons(portNum + 1);
+      if (udpNet.CreateUDPSocket(&fd2, 
+        &target.sa, 
+        &myaddr2.sa,
+        &myaddr2_len,
+        &status, sendbufsize, recvbufsize)) {
         udpConns[i] = NEW(new UnixUDPConnection(fd1));        // new_UnixUDPConnection(fd1);
-        udpConns[i]->setBinding(&myaddr1);
+        udpConns[i]->setBinding(&myaddr1.sa);
         i++;
         udpConns[i] = NEW(new UnixUDPConnection(fd2));        // new_UnixUDPConnection(fd2);
-        udpConns[i]->setBinding(&myaddr2);
+        udpConns[i]->setBinding(&myaddr2.sa);
         i++;
         // remember the last alloc'ed port
         ink_atomic_swap(&lastAllocPort, portNum + 2);
@@ -1351,7 +1351,7 @@ UDPWorkContinuation::StateCreatePortPair
   }
 
   for (i = 0; i < numUdpPorts; i++) {
-    udpNet.UDPClassifyConnection(udpConns[i], destIP);
+    udpNet.UDPClassifyConnection(udpConns[i], InkInetAddr(target));
     Debug("udpnet-pipe", "Adding (port = %d) to Pipe class: %d",
           udpConns[i]->getPortNum(), udpConns[i]->pipe_class);
   }

Modified: trafficserver/traffic/trunk/lib/ts/MatcherUtils.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/lib/ts/MatcherUtils.cc?rev=1159471&r1=1159470&r2=1159471&view=diff
==============================================================================
--- trafficserver/traffic/trunk/lib/ts/MatcherUtils.cc (original)
+++ trafficserver/traffic/trunk/lib/ts/MatcherUtils.cc Fri Aug 19 01:30:36 2011
@@ -141,12 +141,12 @@ unescapifyStr(char *buffer)
 
 char const*
 ExtractIpRange(char* match_str, in_addr_t* min, in_addr_t* max) {
-  sockaddr_in6 min6, max6;
-  char const* zret = ExtractIpRange(match_str, ink_inet_sa_cast(&min6), ink_inet_sa_cast(&max6));
+  ts_ip_endpoint ip_min, ip_max;
+  char const* zret = ExtractIpRange(match_str, &ip_min.sa, &ip_max.sa);
   if (0 == zret) { // success
-    if (ink_inet_is_ip4(&min6) && ink_inet_is_ip4(&max6)) {
-      if (min) *min = ntohl(ink_inet_ip4_addr_cast(&min6));
-      if (max) *max = ntohl(ink_inet_ip4_addr_cast(&max6));
+    if (ink_inet_is_ip4(&ip_min) && ink_inet_is_ip4(&ip_max)) {
+      if (min) *min = ntohl(ink_inet_ip4_addr_cast(&ip_min));
+      if (max) *max = ntohl(ink_inet_ip4_addr_cast(&ip_max));
     } else {
       zret = "The addresses were not IPv4 addresses.";
     }
@@ -176,7 +176,7 @@ ExtractIpRange(char *match_str, sockaddr
   int mask_bits;
   int mask_val;
   int numToks;
-  sockaddr_in6 la1, la2;
+  ts_ip_endpoint la1, la2;
 
   // Extract the IP addresses from match data
   numToks = rangeTok.Initialize(match_str, SHARE_TOKS);
@@ -187,7 +187,7 @@ ExtractIpRange(char *match_str, sockaddr
     return "malformed IP range";
   }
 
-  if (0 != ink_inet_pton(rangeTok[0], &la1)) {
+  if (0 != ink_inet_pton(rangeTok[0], &la1.sa)) {
     return "malformed IP address";
   }
 
@@ -222,16 +222,16 @@ ExtractIpRange(char *match_str, sockaddr
       }
     }
 
-    if (1 == ink_inet_cmp(&la1, &la2)) {
+    if (1 == ink_inet_cmp(&la1.sa, &la2.sa)) {
       return "range start greater than range end";
     }
 
-    ink_inet_copy(addr2, ink_inet_sa_cast(&la2));
+    ink_inet_copy(addr2, &la2);
   } else {
-    ink_inet_copy(addr2, ink_inet_sa_cast(&la1));
+    ink_inet_copy(addr2, &la1);
   }
 
-  ink_inet_copy(addr1, ink_inet_sa_cast(&la1));
+  ink_inet_copy(addr1, &la1);
   return NULL;
 }
 

Modified: trafficserver/traffic/trunk/lib/ts/ink_inet.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/lib/ts/ink_inet.h?rev=1159471&r1=1159470&r2=1159471&view=diff
==============================================================================
--- trafficserver/traffic/trunk/lib/ts/ink_inet.h (original)
+++ trafficserver/traffic/trunk/lib/ts/ink_inet.h Fri Aug 19 01:30:36 2011
@@ -130,7 +130,13 @@ inline void ink_inet_invalidate(ts_ip_en
 /// Test for IP protocol.
 /// @return @c true if the address is IP, @c false otherwise.
 inline bool ink_inet_is_ip(sockaddr const* addr) {
-  return addr && (AF_INET == addr->sa_family || AF_INET6 == addr->sa_family);
+  return addr
+    && (AF_INET == addr->sa_family || AF_INET6 == addr->sa_family);
+}
+/// @return @c true if the address is IP, @c false otherwise.
+inline bool ink_inet_is_ip(ts_ip_endpoint const* addr) {
+  return addr
+    && (AF_INET == addr->sa.sa_family || AF_INET6 == addr->sa.sa_family);
 }
 /// Test for IPv4 protocol.
 /// @return @c true if the address is IPv4, @c false otherwise.
@@ -140,14 +146,21 @@ inline bool ink_inet_is_ip4(sockaddr con
 /// Test for IPv4 protocol.
 /// @note Convenience overload.
 /// @return @c true if the address is IPv4, @c false otherwise.
-inline bool ink_inet_is_ip4(sockaddr_in6 const* addr) {
-  return addr && AF_INET == addr->sin6_family;
+inline bool ink_inet_is_ip4(ts_ip_endpoint const* addr) {
+  return addr && AF_INET == addr->sa.sa_family;
 }
 /// Test for IPv6 protocol.
 /// @return @c true if the address is IPv6, @c false otherwise.
 inline bool ink_inet_is_ip6(sockaddr const* addr) {
   return addr && AF_INET6 == addr->sa_family;
 }
+/// Test for IPv6 protocol.
+/// @note Convenience overload.
+/// @return @c true if the address is IPv6, @c false otherwise.
+inline bool ink_inet_is_ip6(ts_ip_endpoint const* addr) {
+  return addr && AF_INET6 == addr->sa.sa_family;
+}
+
 /// @return @c true if the address families are compatible.
 inline bool ink_inet_are_compatible(
   sockaddr const* lhs, ///< Address to test.
@@ -156,16 +169,6 @@ inline bool ink_inet_are_compatible(
   return lhs->sa_family == rhs->sa_family;
 }
 
-/// @return An appropriate size based on the address family.
-inline size_t ink_inet_ip_size(
-  sockaddr const* addr ///< Address object.
-) {
-  return AF_INET == addr->sa_family ? sizeof(sockaddr_in)
-    : AF_INET6 == addr->sa_family ? sizeof(sockaddr_in6)
-    : 0
-    ;
-}
-
 // IP address casting.
 // sa_cast to cast to sockaddr*.
 // ss_cast to cast to sockaddr_storage*.
@@ -221,6 +224,13 @@ inline sockaddr_in const* ink_inet_ip4_c
   return static_cast<sockaddr_in const*>(static_cast<void const*>(a));
 }
 
+inline sockaddr_in& ink_inet_ip4_cast(sockaddr_in6& a) {
+  return *static_cast<sockaddr_in*>(static_cast<void*>(&a));
+}
+inline sockaddr_in const& ink_inet_ip4_cast(sockaddr_in6 const& a) {
+  return *static_cast<sockaddr_in const*>(static_cast<void const*>(&a));
+}
+
 inline sockaddr_in6* ink_inet_ip6_cast(sockaddr* a) {
   return static_cast<sockaddr_in6*>(static_cast<void*>(a));
 }
@@ -233,6 +243,32 @@ inline sockaddr_in6& ink_inet_ip6_cast(s
 inline sockaddr_in6 const& ink_inet_ip6_cast(sockaddr const& a) {
   return *static_cast<sockaddr_in6 const*>(static_cast<void const*>(&a));
 }
+
+/// @return An appropriate size based on the address family.
+inline size_t ink_inet_ip_size(
+  sockaddr const* addr ///< Address object.
+) {
+  return AF_INET == addr->sa_family ? sizeof(sockaddr_in)
+    : AF_INET6 == addr->sa_family ? sizeof(sockaddr_in6)
+    : 0
+    ;
+}
+inline size_t ink_inet_ip_size(
+  ts_ip_endpoint const* addr ///< Address object.
+) {
+  return AF_INET == addr->sa.sa_family ? sizeof(sockaddr_in)
+    : AF_INET6 == addr->sa.sa_family ? sizeof(sockaddr_in6)
+    : 0
+    ;
+}
+
+/// @return An appropriate size based on the address family.
+inline size_t ink_inet_ip_size(
+  sockaddr_in6 const* addr ///< Address object.
+) {
+  return ink_inet_ip_size(ink_inet_sa_cast(addr));
+}
+
 /** Get a reference to the port in an address.
     @note Because this is direct access, the port value is in network order.
     @see ink_inet_get_port.
@@ -249,16 +285,15 @@ inline uint16_t& ink_inet_port_cast(sock
       : (dummy = 0)
     ;
 }
-/** Get a reference to the port in an address.
-    @note Because this is direct access, the port value is in network order.
-    @see ink_inet_get_port.
-    @return A reference to the port value in an IPv4 or IPv6 address.
-    @internal This is primarily for internal use but it might be handy for
-    clients so it is exposed.
-*/
 inline uint16_t const& ink_inet_port_cast(sockaddr const* sa) {
   return ink_inet_port_cast(const_cast<sockaddr*>(sa));
 }
+inline uint16_t const& ink_inet_port_cast(ts_ip_endpoint const* ip) {
+  return ink_inet_port_cast(const_cast<sockaddr*>(&ip->sa));
+}
+inline uint16_t& ink_inet_port_cast(ts_ip_endpoint* ip) {
+  return ink_inet_port_cast(&ip->sa);
+}
 
 /** Access the IPv4 address.
 
@@ -301,8 +336,8 @@ inline in_addr_t const& ink_inet_ip4_add
 
     @return A reference to the IPv4 address in @a addr.
 */
-inline in_addr_t& ink_inet_ip4_addr_cast(sockaddr_in6* addr) {
-  return ink_inet_ip4_addr_cast(ink_inet_sa_cast(addr));
+inline in_addr_t& ink_inet_ip4_addr_cast(ts_ip_endpoint* ip) {
+  return ink_inet_ip4_addr_cast(&ip->sa);
 }
 
 /** Access the IPv4 address.
@@ -314,8 +349,8 @@ inline in_addr_t& ink_inet_ip4_addr_cast
 
     @return A reference to the IPv4 address in @a addr.
 */
-inline in_addr_t const& ink_inet_ip4_addr_cast(sockaddr_in6 const* addr) {
-  return ink_inet_ip4_addr_cast(ink_inet_sa_cast(addr));
+inline in_addr_t const& ink_inet_ip4_addr_cast(ts_ip_endpoint const* ip) {
+  return ink_inet_ip4_addr_cast(&ip->sa);
 }
 
 /** Access the IPv6 address.
@@ -332,6 +367,12 @@ inline in6_addr& ink_inet_ip6_addr_cast(
 inline in6_addr const& ink_inet_ip6_addr_cast(sockaddr const* addr) {
   return ink_inet_ip6_cast(addr)->sin6_addr;
 }
+inline in6_addr& ink_inet_ip6_addr_cast(ts_ip_endpoint* ip) {
+  return ip->sin6.sin6_addr;
+}
+inline in6_addr const& ink_inet_ip6_addr_cast(ts_ip_endpoint const* ip) {
+  return ip->sin6.sin6_addr;
+}
 
 /** Cast an IP address to an array of @c uint32_t.
     @note The size of the array is dependent on the address type which
@@ -339,7 +380,7 @@ inline in6_addr const& ink_inet_ip6_addr
     @return A pointer to the address information in @a addr or @c NULL
     if @a addr is not an IP address.
 */
-inline uint32_t* ink_inet_ip_addr32_cast(sockaddr* addr) {
+inline uint32_t* ink_inet_addr32_cast(sockaddr* addr) {
   uint32_t* zret = 0;
   switch(addr->sa_family) {
   case AF_INET: zret = reinterpret_cast<uint32_t*>(&ink_inet_ip4_addr_cast(addr)); break;
@@ -347,10 +388,59 @@ inline uint32_t* ink_inet_ip_addr32_cast
   }
   return zret;
 }
-inline uint32_t const* ink_inet_ip_addr32_cast(sockaddr const* addr) {
-  return ink_inet_ip_addr32_cast(const_cast<sockaddr*>(addr));
+inline uint32_t const* ink_inet_addr32_cast(sockaddr const* addr) {
+  return ink_inet_addr32_cast(const_cast<sockaddr*>(addr));
 }
 
+/** Cast an IP address to an array of @c uint8_t.
+    @note The size of the array is dependent on the address type which
+    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.
+*/
+inline uint8_t* ink_inet_addr8_cast(sockaddr* addr) {
+  uint8_t* zret = 0;
+  switch(addr->sa_family) {
+  case AF_INET: zret = reinterpret_cast<uint8_t*>(&ink_inet_ip4_addr_cast(addr)); break;
+  case AF_INET6: zret = reinterpret_cast<uint8_t*>(&ink_inet_ip6_addr_cast(addr)); break;
+  }
+  return zret;
+}
+inline uint8_t const* ink_inet_addr8_cast(sockaddr const* addr) {
+  return ink_inet_addr8_cast(const_cast<sockaddr*>(addr));
+}
+inline uint8_t* ink_inet_addr8_cast(ts_ip_endpoint* ip) {
+  return ink_inet_addr8_cast(&ip->sa);
+}
+inline uint8_t const* ink_inet_addr8_cast(ts_ip_endpoint const* ip) {
+  return ink_inet_addr8_cast(&ip->sa);
+}
+
+/// @return @c true if this is an IP loopback address, @c false otherwise.
+inline bool ink_inet_is_loopback(sockaddr const* ip) {
+  return ip
+    && (
+      (AF_INET == ip->sa_family && htonl(INADDR_LOOPBACK) == ink_inet_ip4_addr_cast(ip))
+      ||
+      (AF_INET6 == ip->sa_family && IN6_IS_ADDR_LOOPBACK(&ink_inet_ip6_addr_cast(ip)))
+    );
+}
+
+inline bool ink_inet_is_loopback(ts_ip_endpoint const* ip) {
+  return ink_inet_is_loopback(&ip->sa);
+}
+
+inline bool ink_inet_is_multicast(sockaddr const* ip) {
+  return ip
+    && (
+      (AF_INET == ip->sa_family && 0xe == *ink_inet_addr8_cast(ip))
+      ||
+      (AF_INET6 == ip->sa_family && IN6_IS_ADDR_MULTICAST(&ink_inet_ip6_addr_cast(ip)))
+    );
+}
+inline bool ink_inet_is_multicast(ts_ip_endpoint const* ip) {
+  return ink_inet_is_multicast(&ip->sa);
+}
   
 /// @name Address operators
 //@{
@@ -378,16 +468,16 @@ inline bool ink_inet_copy(
 }
 
 inline bool ink_inet_copy(
-  sockaddr_in6* dst, ///< Destination object.
+  ts_ip_endpoint* dst, ///< Destination object.
   sockaddr const* src ///< Source object.
 ) {
-  return ink_inet_copy(ink_inet_sa_cast(dst), src);
+  return ink_inet_copy(&dst->sa, src);
 }
 inline bool ink_inet_copy(
-  ts_ip_endpoint* dst,
-  sockaddr const* src
+  ts_ip_endpoint* dst, ///< Destination object.
+  ts_ip_endpoint const* src ///< Source object.
 ) {
-  return ink_inet_copy(&dst->sa, src);
+  return ink_inet_copy(&dst->sa, &src->sa);
 }
 inline bool ink_inet_copy(
   sockaddr* dst,
@@ -473,13 +563,16 @@ inline int ink_inet_cmp(sockaddr_in6 con
 inline bool ink_inet_eq(sockaddr const* lhs, sockaddr const* rhs) {
   return 0 == ink_inet_cmp(lhs, rhs);
 }
-inline bool ink_inet_eq(ts_ip_endpoint const& lhs, ts_ip_endpoint const& rhs) {
-  return 0 == ink_inet_cmp(&lhs.sa, &rhs.sa);
+inline bool ink_inet_eq(ts_ip_endpoint const* lhs, ts_ip_endpoint const* rhs) {
+  return 0 == ink_inet_cmp(&lhs->sa, &rhs->sa);
 }
 
 inline bool operator == (ts_ip_endpoint const& lhs, ts_ip_endpoint const& rhs) {
   return 0 == ink_inet_cmp(&lhs.sa, &rhs.sa);
 }
+inline bool operator != (ts_ip_endpoint const& lhs, ts_ip_endpoint const& rhs) {
+  return 0 != ink_inet_cmp(&lhs.sa, &rhs.sa);
+}
 
 //@}
 
@@ -494,6 +587,18 @@ inline uint16_t ink_inet_get_port(
   return ntohs(ink_inet_port_cast(const_cast<sockaddr*>(addr)));
 }
 
+/// Get IP TCP/UDP port.
+/// @return The port in host order for an IPv4 or IPv6 address,
+/// or zero if neither.
+inline uint16_t ink_inet_get_port(
+  ts_ip_endpoint const* ip ///< Address with port.
+) {
+  // We can discard the const because this function returns
+  // by value.
+  return ntohs(ink_inet_port_cast(const_cast<sockaddr*>(&ip->sa)));
+}
+
+
 /** Extract the IPv4 address.
     @return Host order IPv4 address.
 */
@@ -520,11 +625,11 @@ inline sockaddr* ink_inet_ip4_set(
     @note Convenience overload.
 */
 inline sockaddr* ink_inet_ip4_set(
-  sockaddr_in6* dst, ///< Destination storage.
+  ts_ip_endpoint* dst, ///< Destination storage.
   in_addr_t ip4, ///< address, IPv4 network order.
   uint16_t port = 0 ///< port, network order.
 ) {
-  return ink_inet_ip4_set(ink_inet_ip4_cast(dst), ip4, port);
+  return ink_inet_ip4_set(&dst->sin, ip4, port);
 }
 
 /** Write IPv4 data to storage @a dst.
@@ -539,10 +644,10 @@ inline sockaddr* ink_inet_ip4_set(
 ) {
   return ink_inet_ip4_set(ink_inet_ip4_cast(dst), ip4, port);
 }
-
-/// Write IPv6 address to storage @a dst.
-/// @note convenience overload.
-inline void ink_inet_ip6_set(
+/** Write IPv6 data to storage @a dst.
+    @return @a dst cast to @c sockaddr*.
+ */
+inline sockaddr* ink_inet_ip6_set(
   sockaddr_in6* dst, ///< Destination storage.
   in6_addr const& addr, ///< address in network order.
   uint16_t port = 0 ///< Port, network order.
@@ -551,15 +656,27 @@ inline void ink_inet_ip6_set(
   dst->sin6_family = AF_INET6;
   memcpy(&dst->sin6_addr, &addr, sizeof addr);
   dst->sin6_port = port;
+  return ink_inet_sa_cast(dst);
 }
-
-/// Write IPv6 address to storage @a dst.
-inline void ink_inet_ip6_set(
+/** Write IPv6 data to storage @a dst.
+    @return @a dst cast to @c sockaddr*.
+ */
+inline sockaddr* ink_inet_ip6_set(
   sockaddr* dst, ///< Destination storage.
   in6_addr const& addr, ///< address in network order.
   uint16_t port = 0 ///< Port, network order.
 ) {
-  ink_inet_ip6_set(ink_inet_ip6_cast(dst), addr, port);
+  return ink_inet_ip6_set(ink_inet_ip6_cast(dst), addr, port);
+}
+/** Write IPv6 data to storage @a dst.
+    @return @a dst cast to @c sockaddr*.
+ */
+inline sockaddr* ink_inet_ip6_set(
+  ts_ip_endpoint* dst, ///< Destination storage.
+  in6_addr const& addr, ///< address in network order.
+  uint16_t port = 0 ///< Port, network order.
+) {
+  return ink_inet_ip6_set(&dst->sin6, addr, port);
 }
 
 /** Write a null terminated string for @a addr to @a dst.
@@ -571,6 +688,17 @@ char const* ink_inet_ntop(
   size_t size ///< Length of buffer.
 );
 
+/** Write a null terminated string for @a addr to @a dst.
+    A buffer of size INET6_ADDRSTRLEN suffices, including a terminating nul.
+ */
+inline char const* ink_inet_ntop(
+  const sockaddr_in6 *addr, ///< Address.
+  char *dst, ///< Output buffer.
+  size_t size ///< Length of buffer.
+) {
+  return ink_inet_ntop(ink_inet_sa_cast(addr), dst, size);
+}
+
 /// Buffer size sufficient for IPv6 address and port.
 static size_t const INET6_ADDRPORTSTRLEN = INET6_ADDRSTRLEN + 6;
 /// Convenience type for address formatting.
@@ -587,6 +715,18 @@ char const* ink_inet_nptop(
   size_t size ///< Length of buffer.
 );
 
+/** Write a null terminated string for @a addr to @a dst with port.
+    A buffer of size INET6_ADDRPORTSTRLEN suffices, including a terminating nul.
+ */
+inline char const* ink_inet_nptop(
+  const sockaddr_in6 *addr, ///< Address.
+  char *dst, ///< Output buffer.
+  size_t size ///< Length of buffer.
+) {
+  return ink_inet_nptop(ink_inet_sa_cast(addr), dst, size);
+}
+
+
 /** Convert @a text to an IP address and write it to @a addr.
 
     @a text is expected to be an explicit address, not a hostname.  No
@@ -634,21 +774,25 @@ inline int ink_inet_pton(
     makes sense.
     @note This is not easily used as an address for system calls.
 */
-struct InkIpAddr {
-  typedef InkIpAddr self; ///< Self reference type.
+struct InkInetAddr {
+  typedef InkInetAddr self; ///< Self reference type.
 
   /// Default construct (invalid address).
-  InkIpAddr() : _family(AF_UNSPEC) {}
+  InkInetAddr() : _family(AF_UNSPEC) {}
   /// Construct as IPv4 @a addr.
-  explicit InkIpAddr(
-    in_addr_t addr ///< Address to assign.
+  explicit InkInetAddr(
+    uint32_t addr ///< Address to assign.
   ) : _family(AF_INET) {
     _addr._ip4 = addr;
   }
-  /// Construct from @c sockaddr_storage.
-  explicit InkIpAddr(sockaddr const& addr) { this->assign(&addr); }
-  /// Construct from @c sockaddr_storage.
-  explicit InkIpAddr(sockaddr const* addr) { this->assign(addr); }
+  /// Construct from @c sockaddr.
+  explicit InkInetAddr(sockaddr const* addr) { this->assign(addr); }
+  /// Construct from @c sockaddr_in6.
+  explicit InkInetAddr(sockaddr_in6 const& addr) { this->assign(ink_inet_sa_cast(&addr)); }
+  /// Construct from @c sockaddr_in6.
+  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); }
 
   /// Assign sockaddr storage.
   self& assign(sockaddr const* addr) {
@@ -692,6 +836,4 @@ struct InkIpAddr {
   } _addr;
 };
 
-// --
-
 #endif // _ink_inet.h

Modified: trafficserver/traffic/trunk/lib/ts/ink_sock.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/lib/ts/ink_sock.cc?rev=1159471&r1=1159470&r2=1159471&view=diff
==============================================================================
--- trafficserver/traffic/trunk/lib/ts/ink_sock.cc (original)
+++ trafficserver/traffic/trunk/lib/ts/ink_sock.cc Fri Aug 19 01:30:36 2011
@@ -164,7 +164,7 @@ safe_ioctl(int fd, int request, char *ar
 }
 
 int
-safe_bind(int s, struct sockaddr *name, int namelen)
+safe_bind(int s, struct sockaddr const* name, int namelen)
 {
   int r;
   CHECK_PLAUSIBLE_SOCKADDR(name, __FILE__, __LINE__);

Modified: trafficserver/traffic/trunk/lib/ts/ink_sock.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/lib/ts/ink_sock.h?rev=1159471&r1=1159470&r2=1159471&view=diff
==============================================================================
--- trafficserver/traffic/trunk/lib/ts/ink_sock.h (original)
+++ trafficserver/traffic/trunk/lib/ts/ink_sock.h Fri Aug 19 01:30:36 2011
@@ -37,7 +37,7 @@
 
 int safe_setsockopt(int s, int level, int optname, char *optval, int optlevel);
 int safe_getsockopt(int s, int level, int optname, char *optval, int *optlevel);
-int safe_bind(int s, struct sockaddr *name, int namelen);
+int safe_bind(int s, struct sockaddr const* name, int namelen);
 int safe_listen(int s, int backlog);
 int safe_getsockname(int s, struct sockaddr *name, int *namelen);
 

Modified: trafficserver/traffic/trunk/proxy/CoreUtils.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/CoreUtils.cc?rev=1159471&r1=1159470&r2=1159471&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/CoreUtils.cc (original)
+++ trafficserver/traffic/trunk/proxy/CoreUtils.cc Fri Aug 19 01:30:36 2011
@@ -1007,13 +1007,13 @@ CoreUtils::process_NetVC(UnixNetVConnect
 
   if (read_from_core((intptr_t) nvc_test, sizeof(UnixNetVConnection), buf) != -1) {
     UnixNetVConnection *loaded_nvc = (UnixNetVConnection *) buf;
-
+    
     // Probably not 64-bit safe. /leif
+    char addrbuf[INET6_ADDRSTRLEN];
     printf("----------- UnixNetVConnection @ 0x%p ----------\n", nvc_test);
-    printf("     ip: %hhu.%hhu.%hhu.%hhu    port: %d\n",
-           ((unsigned char *) &loaded_nvc->ip)[0],
-           ((unsigned char *) &loaded_nvc->ip)[1],
-           ((unsigned char *) &loaded_nvc->ip)[2], ((unsigned char *) &loaded_nvc->ip)[3], loaded_nvc->port);
+    printf("     ip: %s    port: %d\n",
+        ink_inet_ntop(&loaded_nvc->server_addr.sa, addrbuf, sizeof(addrbuf)), 
+        ink_inet_get_port(&loaded_nvc->server_addr));
     printf("     closed: %d\n\n", loaded_nvc->closed);
     printf("     read state: \n");
     print_netstate(&loaded_nvc->read);

Modified: trafficserver/traffic/trunk/proxy/ICP.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/ICP.cc?rev=1159471&r1=1159470&r2=1159471&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/ICP.cc (original)
+++ trafficserver/traffic/trunk/proxy/ICP.cc Fri Aug 19 01:30:36 2011
@@ -2399,8 +2399,8 @@ ICPProcessor::CancelPendingReads()
   r->_ICPmsg.h.version = ~r->_ICPmsg.h.version; // bogus message
 
   Peer *lp = GetLocalPeer();
-  r->_sendMsgHdr.msg_name = (caddr_t) & (lp->GetSendChan())->sa;
-  r->_sendMsgHdr.msg_namelen = sizeof((lp->GetSendChan())->sa);
+  r->_sendMsgHdr.msg_name = (caddr_t) & (lp->GetSendChan())->addr;
+  r->_sendMsgHdr.msg_namelen = sizeof((lp->GetSendChan())->addr);
   udpNet.sendmsg_re(r, r, lp->GetSendFD(), &r->_sendMsgHdr);
 }
 

Modified: trafficserver/traffic/trunk/proxy/ICPConfig.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/ICPConfig.cc?rev=1159471&r1=1159470&r2=1159471&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/ICPConfig.cc (original)
+++ trafficserver/traffic/trunk/proxy/ICPConfig.cc Fri Aug 19 01:30:36 2011
@@ -871,14 +871,14 @@ ParentSiblingPeer::SendMsg_re(Continuati
     Peer *p = _ICPpr->FindPeer(&to->sin_addr, ntohs(to->sin_port));
     ink_assert(p);
 
-    msg->msg_name = (caddr_t) & (p->GetSendChan())->sa;
-    msg->msg_namelen = sizeof((p->GetSendChan())->sa);
+    msg->msg_name = (caddr_t) & (p->GetSendChan())->addr;
+    msg->msg_namelen = sizeof((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.sa;
-    msg->msg_namelen = sizeof(_chan.sa);
+    msg->msg_name = (caddr_t) & _chan.addr;
+    msg->msg_namelen = sizeof(_chan.addr);
     Action *a = udpNet.sendmsg_re(cont, token, lp->GetSendFD(), msg);
     return a;
   }
@@ -1029,8 +1029,8 @@ MultiCastPeer::SendMsg_re(Continuation *
     a = ((ParentSiblingPeer *) p)->SendMsg_re(cont, token, msg, 0);
   } else {
     // Send to MultiCast group
-    msg->msg_name = (caddr_t) & _send_chan.sa;
-    msg->msg_namelen = sizeof(_send_chan.sa);
+    msg->msg_name = (caddr_t) & _send_chan.addr;
+    msg->msg_namelen = sizeof(_send_chan.addr);
     a = udpNet.sendmsg_re(cont, token, _send_chan.fd, msg);
   }
   return a;

Modified: trafficserver/traffic/trunk/proxy/InkAPI.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/InkAPI.cc?rev=1159471&r1=1159470&r2=1159471&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/InkAPI.cc (original)
+++ trafficserver/traffic/trunk/proxy/InkAPI.cc Fri Aug 19 01:30:36 2011
@@ -5156,7 +5156,7 @@ TSHttpTxnServerAddrGet(TSHttpTxn txnp)
   ink_inet_ip4_set(
     ink_inet_sa_cast(&sm->t_state.server_info.addr),
     sm->t_state.server_info.ip,
-    sm->t_state.server_info.port
+    htons(sm->t_state.server_info.port)
   );
   return ink_inet_sa_cast(&sm->t_state.server_info.addr);
 }
@@ -5841,7 +5841,7 @@ TSHttpConnect(sockaddr const* addr)
   sdk_assert(addr);
 
   in_addr_t ip = ink_inet_ip4_addr_cast(addr);
-  uint16_t port = ink_inet_port_cast(addr);
+  uint16_t port = ink_inet_get_port(addr);
 
   sdk_assert(ip);
   sdk_assert(port);
@@ -6186,7 +6186,7 @@ TSNetConnect(TSCont contp, sockaddr cons
   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_port_cast(addr);
+  uint16_t port = ink_inet_get_port(addr);
   sdk_assert(ip != 0 && port != 0);
 
   FORCE_PLUGIN_MUTEX(contp);
@@ -7079,7 +7079,7 @@ TSFetchPages(TSFetchUrlParams_t *params)
     FetchSM *fetch_sm =  FetchSMAllocator.alloc();
     sockaddr* addr = ink_inet_sa_cast(&myparams->ip);
     in_addr_t ip = ink_inet_ip4_addr_cast(addr);
-    uint16_t port = ink_inet_port_cast(addr);
+    uint16_t port = ink_inet_get_port(addr);
 
     fetch_sm->init((Continuation*)myparams->contp, myparams->options,myparams->events, myparams->request, myparams->request_len, ip, port);
     fetch_sm->httpConnect();

Modified: trafficserver/traffic/trunk/proxy/InkAPITest.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/InkAPITest.cc?rev=1159471&r1=1159470&r2=1159471&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/InkAPITest.cc (original)
+++ trafficserver/traffic/trunk/proxy/InkAPITest.cc Fri Aug 19 01:30:36 2011
@@ -46,12 +46,8 @@
 
 #define UTDBG_TAG "sdk_ut"
 
-static in_addr_t const LOCAL_IP = INADDR_LOOPBACK;//  0x7f000001    // 127.0.0.1
-
 /******************************************************************************/
 
-
-
 /* Use SDK_RPRINT to report failure or success for each test case */
 int
 SDK_RPRINT(RegressionTest * t, const char *api_name, const char *testcase_name, int status, const char *err_details_format, ...)
@@ -285,15 +281,16 @@ client_handler(TSCont contp, TSEvent eve
     SDK_RPRINT(SDK_NetVConn_test, "TSNetConnect", "TestCase1", TC_PASS, "ok");
 
     sockaddr const* addr = TSNetVConnRemoteAddrGet(static_cast<TSVConn>(data));
-    in_addr_t input_server_ip = ink_inet_ip4_addr_cast(addr);
-    uint16_t input_server_port = ntohs(ink_inet_port_cast(addr));
+    uint16_t input_server_port = ink_inet_get_port(addr);
 
-    if (input_server_ip != LOCAL_IP) {
-      char s[INET6_ADDRSTRLEN];
-      inet_ntop(addr->sa_family, addr, s, sizeof s);
-      in_addr a;
-      a.s_addr = LOCAL_IP;
-      SDK_RPRINT(SDK_NetVConn_test, "TSNetVConnRemoteIPGet", "TestCase1", TC_FAIL, "server ip [%s] is incorrect - expected [%x]", s, inet_ntoa(a));
+    if (!ink_inet_is_loopback(addr)) {
+      ip_text_buffer s, ipb;
+      ts_ip_endpoint loopback;
+      ink_inet_ip4_set(&loopback, htonl(INADDR_LOOPBACK));
+      SDK_RPRINT(SDK_NetVConn_test, "TSNetVConnRemoteIPGet", "TestCase1", TC_FAIL, "server ip [%s] is incorrect - expected [%s]",
+        ink_inet_ntop(addr, s, sizeof s),
+        ink_inet_ntop(&loopback.sa, ipb, sizeof ipb)
+      );
 
       TSContDestroy(contp);
       // Fix me: how to deal with server side cont?
@@ -336,9 +333,9 @@ REGRESSION_TEST(SDK_API_TSNetVConn) (Reg
 
   TSNetAccept(server_cont, server_port, -1, 0);
 
-  sockaddr_in addr;
-  ink_inet_ip4_set(&addr, INADDR_LOOPBACK, server_port);
-  TSNetConnect(client_cont, ink_inet_sa_cast(&addr));
+  ts_ip_endpoint addr;
+  ink_inet_ip4_set(&addr, htonl(INADDR_LOOPBACK), htons(server_port));
+  TSNetConnect(client_cont, &addr.sa);
 }
 
 /* TSCache, TSVConn, TSVIO */
@@ -2164,21 +2161,21 @@ checkHttpTxnClientIPGet(SocketTest * tes
   sockaddr const* ptr;
   in_addr_t ip;
   TSHttpTxn txnp = (TSHttpTxn) data;
-  in_addr_t actual_ip = LOCAL_IP;     /* 127.0.0.1 is expected because the client is on the same machine */
+  in_addr_t actual_ip = htonl(INADDR_LOOPBACK);     /* 127.0.0.1 is expected because the client is on the same machine */
 
   ptr = TSHttpTxnClientAddrGet(txnp);
-  if (ptr == 0 || (ip = ink_inet_ip4_addr_cast(ptr)) == 0) {
+  if (ptr == 0 || INADDR_ANY == (ip = ink_inet_ip4_addr_cast(ptr))) {
     test->test_client_ip_get = false;
     SDK_RPRINT(test->regtest, "TSHttpTxnClientIPGet", "TestCase1", TC_FAIL, "TSHttpTxnClientIPGet returns 0 %s", ptr ? "address" : "pointer");
     return TS_EVENT_CONTINUE;
   }
 
-  if (ntohl(ip) == actual_ip) {
+  if (ip == actual_ip) {
     test->test_client_ip_get = true;
     SDK_RPRINT(test->regtest, "TSHttpTxnClientIPGet", "TestCase1", TC_PASS, "ok [%0.8x]", ip);
   } else {
     test->test_client_ip_get = false;
-    SDK_RPRINT(test->regtest, "TSHttpTxnClientIPGet", "TestCase1", TC_FAIL, "Value's Mismatch [expected %0.8x got %0.8x]", actual_ip, ip);
+    SDK_RPRINT(test->regtest, "TSHttpTxnClientIPGet", "TestCase1", TC_FAIL, "Value's Mismatch [expected %.8x got %.8x]", actual_ip, ip);
   }
   return TS_EVENT_CONTINUE;
 
@@ -2189,7 +2186,7 @@ static int
 checkHttpTxnNextHopIPGet(SocketTest * test, void *data)
 {
   TSHttpTxn txnp = (TSHttpTxn) data;
-  in_addr_t actual_ip = LOCAL_IP;     /* 127.0.0.1 is expected because the client is on the same machine */
+  in_addr_t actual_ip = htonl(INADDR_LOOPBACK);     /* 127.0.0.1 is expected because the client is on the same machine */
   sockaddr const* ptr;
   in_addr_t nexthopip;
 
@@ -2200,7 +2197,7 @@ checkHttpTxnNextHopIPGet(SocketTest * te
     return TS_EVENT_CONTINUE;
   }
 
-  if (ntohl(nexthopip) == actual_ip) {
+  if (nexthopip == actual_ip) {
     test->test_next_hop_ip_get = true;
     SDK_RPRINT(test->regtest, "TSHttpTxnNextHopIPGet", "TestCase1", TC_PASS, "ok");
   } else {
@@ -2220,7 +2217,7 @@ checkHttpTxnServerIPGet(SocketTest * tes
   sockaddr const* ptr;
   in_addr_t ip;
   TSHttpTxn txnp = (TSHttpTxn) data;
-  in_addr_t actual_ip = ntohl(LOCAL_IP);      /* 127.0.0.1 is expected because the client is on the same machine */
+  in_addr_t actual_ip = htonl(INADDR_LOOPBACK);      /* 127.0.0.1 is expected because the client is on the same machine */
 
   ptr = TSHttpTxnServerAddrGet(txnp);
   if (0 == ptr || 0 == (ip = ink_inet_ip4_addr_cast(ptr))) {
@@ -2257,7 +2254,7 @@ checkHttpTxnClientIncomingPortGet(Socket
     test->test_client_incoming_port_get = false;
     return TS_EVENT_CONTINUE;
   }
-  port = ntohs(ink_inet_port_cast(ptr));
+  port = ink_inet_get_port(ptr);
 
   if (TSMgmtIntGet("proxy.config.http.server_port", &port_from_config_file) != TS_SUCCESS) {
     port_from_config_file = 8080;
@@ -2295,7 +2292,7 @@ checkHttpTxnClientRemotePortGet(SocketTe
     return TS_EVENT_CONTINUE;
   }
 
-  port = ntohs(ink_inet_port_cast(ptr));
+  port = ink_inet_get_port(ptr);
   TSDebug(UTDBG_TAG, "Browser port = %x, Txn remote port = %x", browser_port, port);
 
   if (port == browser_port) {
@@ -7406,6 +7403,7 @@ done:
 EXCLUSIVE_REGRESSION_TEST(SDK_API_TSHttpConnectIntercept) (RegressionTest * test, int atype, int *pstatus)
 {
   NOWARN_UNUSED(atype);
+
   *pstatus = REGRESSION_TEST_INPROGRESS;
 
   TSDebug(UTDBG_TAG, "Starting test TSHttpConnectIntercept");
@@ -7447,6 +7445,7 @@ EXCLUSIVE_REGRESSION_TEST(SDK_API_TSHttp
 EXCLUSIVE_REGRESSION_TEST(SDK_API_TSHttpConnectServerIntercept) (RegressionTest * test, int atype, int *pstatus)
 {
   NOWARN_UNUSED(atype);
+
   *pstatus = REGRESSION_TEST_INPROGRESS;
 
   TSDebug(UTDBG_TAG, "Starting test TSHttpConnectServerintercept");

Modified: trafficserver/traffic/trunk/proxy/InkAPITestTool.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/InkAPITestTool.cc?rev=1159471&r1=1159470&r2=1159471&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/InkAPITestTool.cc (original)
+++ trafficserver/traffic/trunk/proxy/InkAPITestTool.cc Fri Aug 19 01:30:36 2011
@@ -502,7 +502,7 @@ synclient_txn_send_request(ClientTxn * t
   cont = TSContCreate(synclient_txn_main_handler, TSMutexCreate());
   TSContDataSet(cont, txn);
   
-  ink_inet_ip4_set(&addr, txn->connect_ip, txn->connect_port);
+  ink_inet_ip4_set(&addr, txn->connect_ip, htons(txn->connect_port));
   TSNetConnect(cont, ink_inet_sa_cast(&addr));
   return 1;
 }

Modified: trafficserver/traffic/trunk/proxy/InkIOCoreAPI.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/InkIOCoreAPI.cc?rev=1159471&r1=1159470&r2=1159471&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/InkIOCoreAPI.cc (original)
+++ trafficserver/traffic/trunk/proxy/InkIOCoreAPI.cc Fri Aug 19 01:30:36 2011
@@ -358,11 +358,15 @@ INKBasedTimeGet()
 
 TSAction
 INKUDPBind(TSCont contp, unsigned int ip, int port)
-{
+{  
   sdk_assert(sdk_sanity_check_continuation(contp) == TS_SUCCESS);
-
+    
   FORCE_PLUGIN_MUTEX(contp);
-  return reinterpret_cast<TSAction>(udpNet.UDPBind((Continuation *)contp, port, ip, INK_ETHERNET_MTU_SIZE, INK_ETHERNET_MTU_SIZE));
+
+  struct sockaddr_in addr;
+  ink_inet_ip4_set(&addr, ip, htons(port));
+  
+  return reinterpret_cast<TSAction>(udpNet.UDPBind((Continuation *)contp, ink_inet_sa_cast(&addr), INK_ETHERNET_MTU_SIZE, INK_ETHERNET_MTU_SIZE));
 }
 
 TSAction
@@ -374,9 +378,7 @@ INKUDPSendTo(TSCont contp, INKUDPConn ud
   UDPPacket *packet = new_UDPPacket();
   UDPConnection *conn = (UDPConnection *)udp;
 
-  packet->to.sin_family = PF_INET;
-  packet->to.sin_port = htons(port);
-  packet->to.sin_addr.s_addr = ip;
+  ink_inet_ip4_set(&packet->to, ip, htons(port));
 
   IOBufferBlock *blockp = new_IOBufferBlock();
   blockp->alloc(BUFFER_SIZE_INDEX_32K);
@@ -438,7 +440,7 @@ INKUDPPacketFromAddressGet(INKUDPPacket 
   sdk_assert(sdk_sanity_check_null_ptr((void*)packet) == TS_SUCCESS);
 
   UDPPacket *p = (UDPPacket *)packet;
-  return (p->from.sin_addr.s_addr);
+  return ink_inet_ip4_addr_cast(&p->from);
 }
 
 int
@@ -447,7 +449,7 @@ INKUDPPacketFromPortGet(INKUDPPacket pac
   sdk_assert(sdk_sanity_check_null_ptr((void*)packet) == TS_SUCCESS);
 
   UDPPacket *p = (UDPPacket *)packet;
-  return (ntohs(p->from.sin_port));
+  return ink_inet_get_port(&p->from);
 }
 
 INKUDPConn

Modified: trafficserver/traffic/trunk/proxy/PluginVC.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/PluginVC.cc?rev=1159471&r1=1159470&r2=1159471&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/PluginVC.cc (original)
+++ trafficserver/traffic/trunk/proxy/PluginVC.cc Fri Aug 19 01:30:36 2011
@@ -879,16 +879,10 @@ void
 PluginVC::set_local_addr()
 {
   if (vc_type == PLUGIN_VC_ACTIVE) {
-    ink_inet_copy(
-      ink_inet_sa_cast(&local_addr),
-      ink_inet_sa_cast(&core_obj->active_addr_struct)
-    );
+    ink_inet_copy(&local_addr, &core_obj->active_addr_struct);
 //    local_addr = core_obj->active_addr_struct;
   } else {
-    ink_inet_copy(
-      ink_inet_sa_cast(&local_addr),
-      ink_inet_sa_cast(&core_obj->passive_addr_struct)
-    );
+    ink_inet_copy(&local_addr, &core_obj->passive_addr_struct);
 //    local_addr = core_obj->passive_addr_struct;
   }
 }
@@ -897,17 +891,9 @@ void
 PluginVC::set_remote_addr()
 {
   if (vc_type == PLUGIN_VC_ACTIVE) {
-    ink_inet_copy(
-      ink_inet_sa_cast(&remote_addr),
-      ink_inet_sa_cast(&core_obj->passive_addr_struct)
-    );
-//    remote_addr = core_obj->passive_addr_struct;
+    ink_inet_copy(&remote_addr, &core_obj->passive_addr_struct);
   } else {
-    ink_inet_copy(
-      ink_inet_sa_cast(&remote_addr),
-      ink_inet_sa_cast(&core_obj->active_addr_struct)
-    );
-//    remote_addr = core_obj->active_addr_struct;
+    ink_inet_copy(&remote_addr, &core_obj->active_addr_struct);
   }
 }
 

Modified: trafficserver/traffic/trunk/proxy/PluginVC.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/PluginVC.h?rev=1159471&r1=1159470&r2=1159471&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/PluginVC.h (original)
+++ trafficserver/traffic/trunk/proxy/PluginVC.h Fri Aug 19 01:30:36 2011
@@ -200,8 +200,8 @@ private:
   MIOBuffer *a_to_p_buffer;
   IOBufferReader *a_to_p_reader;
 
-  struct sockaddr_storage passive_addr_struct;
-  struct sockaddr_storage active_addr_struct;
+  ts_ip_endpoint passive_addr_struct;
+  ts_ip_endpoint active_addr_struct;
 
   void *passive_data;
   void *active_data;
@@ -224,8 +224,8 @@ passive_data(NULL),
 active_data(NULL),
 id(0)
 {
-  memset(&active_addr_struct, 0, sizeof(struct sockaddr_storage));
-  memset(&passive_addr_struct, 0, sizeof(struct sockaddr_storage));
+  memset(&active_addr_struct, 0, sizeof active_addr_struct);
+  memset(&passive_addr_struct, 0, sizeof passive_addr_struct);
 
   id = ink_atomic_increment(&nextid, 1);
 }

Modified: trafficserver/traffic/trunk/proxy/UglyLogStubs.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/UglyLogStubs.cc?rev=1159471&r1=1159470&r2=1159471&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/UglyLogStubs.cc (original)
+++ trafficserver/traffic/trunk/proxy/UglyLogStubs.cc Fri Aug 19 01:30:36 2011
@@ -62,11 +62,10 @@ UDPNetProcessor::FreeBandwidth(Continuat
 NetProcessor& netProcessor; //  = unix_netProcessor;
 
 Action *
-UnixNetProcessor::connect_re_internal(Continuation * cont, unsigned int ip, int port,  NetVCOptions * opt)
+UnixNetProcessor::connect_re_internal(Continuation * cont, sockaddr const* target,  NetVCOptions * opt)
 {
   NOWARN_UNUSED(cont);
-  NOWARN_UNUSED(ip);
-  NOWARN_UNUSED(port);
+  NOWARN_UNUSED(target);
   NOWARN_UNUSED(opt);
   ink_release_assert(false);
   return NULL;

Modified: trafficserver/traffic/trunk/proxy/http/HttpProxyServerMain.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/HttpProxyServerMain.cc?rev=1159471&r1=1159470&r2=1159471&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/HttpProxyServerMain.cc (original)
+++ trafficserver/traffic/trunk/proxy/http/HttpProxyServerMain.cc Fri Aug 19 01:30:36 2011
@@ -333,6 +333,7 @@ start_HttpProxyServerBackDoor(int port, 
 
   opt.port = port;
   opt.accept_threads = accept_threads;
+  
   // The backdoor only binds the loopback interface
   netProcessor.main_accept(NEW(new HttpAccept(SERVER_PORT_DEFAULT, true)), NO_FD, 0, 0, false, true, opt);
 }

Modified: trafficserver/traffic/trunk/proxy/http/HttpSM.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/HttpSM.cc?rev=1159471&r1=1159470&r2=1159471&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/HttpSM.cc (original)
+++ trafficserver/traffic/trunk/proxy/http/HttpSM.cc Fri Aug 19 01:30:36 2011
@@ -3842,7 +3842,7 @@ HttpSM::do_hostdb_update_if_necessary()
     ts_ip_endpoint ip;
     hostDBProcessor.setby(t_state.current.server->name,
       strlen(t_state.current.server->name),
-      ink_inet_ip4_set(&ip.sa, t_state.current.server->ip, t_state.current.server->port),
+      ink_inet_ip4_set(&ip.sa, t_state.current.server->ip, htons(t_state.current.server->port)),
       &t_state.host_db_info.app
     );
   }
@@ -4089,10 +4089,10 @@ HttpSM::do_http_server_open(bool raw)
 
   if (t_state.txn_conf->outgoing_ip_to_bind_saddr) {
     opt.addr_binding = NetVCOptions::INTF_ADDR;
-    opt.local_addr = t_state.txn_conf->outgoing_ip_to_bind_saddr;
+    ink_inet_ip4_set(&opt.local_addr, t_state.txn_conf->outgoing_ip_to_bind_saddr);
   } else if (t_state.server_info.is_transparent) {
     opt.addr_binding = NetVCOptions::FOREIGN_ADDR;
-    opt.local_addr = t_state.client_info.ip;
+    ink_inet_ip4_set(&opt.local_addr, t_state.client_info.ip);
   }
 
   Debug("http", "[%" PRId64 "] open connection to %s: %u.%u.%u.%u",



Mime
View raw message