trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r1126862 [2/4] - in /trafficserver/traffic/branches/ssc: iocore/aio/ iocore/cache/ iocore/cluster/ iocore/dns/ iocore/eventsystem/ iocore/hostdb/ iocore/hostdb/include/ iocore/net/ iocore/utils/ lib/records/ lib/ts/ lib/wccp/ mgmt/ mgmt/api...
Date Tue, 24 May 2011 04:11:39 GMT
Modified: trafficserver/traffic/branches/ssc/iocore/net/Makefile.am
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/ssc/iocore/net/Makefile.am?rev=1126862&r1=1126861&r2=1126862&view=diff
==============================================================================
--- trafficserver/traffic/branches/ssc/iocore/net/Makefile.am (original)
+++ trafficserver/traffic/branches/ssc/iocore/net/Makefile.am Tue May 24 04:11:36 2011
@@ -23,7 +23,7 @@ AM_CPPFLAGS = \
 else
 AM_CPPFLAGS = \
   $(iocore_include_dirs) \
-  -I$(top_srcdir)/lib/records \
+  -I$(top_srcdir)/lib \
   -I$(top_srcdir)/proxy \
   -I$(top_srcdir)/proxy/hdrs \
   -I$(top_srcdir)/mgmt \

Modified: trafficserver/traffic/branches/ssc/iocore/net/P_Connection.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/ssc/iocore/net/P_Connection.h?rev=1126862&r1=1126861&r2=1126862&view=diff
==============================================================================
--- trafficserver/traffic/branches/ssc/iocore/net/P_Connection.h (original)
+++ trafficserver/traffic/branches/ssc/iocore/net/P_Connection.h Tue May 24 04:11:36 2011
@@ -81,7 +81,7 @@ struct NetVCOptions;
 struct Connection
 {
   SOCKET fd; ///< Socket for connection.
-  struct sockaddr_storage sa; ///< Remote address.
+  sockaddr_storage addr; ///< Associated address.
   bool is_bound; ///< Flag for already bound to a local address.
   bool is_connected; ///< Flag for already connected.
 
@@ -111,31 +111,25 @@ struct Connection
       @see open
   */
   int connect(
-	   uint32_t addr, ///< Remote address.
-	   uint16_t port, ///< Remote port.
-	   NetVCOptions const& opt = DEFAULT_OPTIONS ///< Socket options
-	   );
+    sockaddr_storage const* to, ///< Remote address and port.
+    NetVCOptions const& opt = DEFAULT_OPTIONS ///< Socket options
+  );
 
 
   /// Set the internal socket address struct.
   /// @internal Used only by ICP.
   void setRemote(
-		 uint32_t addr, ///< Remote IP address.
-		 uint16_t port ///< Remote port.
-	     ) {
-    sockaddr_in* sa_in = reinterpret_cast<sockaddr_in*>(&sa);
-    sa.ss_family = AF_INET;
-    sa_in->sin_port = htons(port);
-    sa_in->sin_addr.s_addr = addr;
-    memset(&(sa_in->sin_zero), 0, 8);
+    sockaddr_storage const* remote_addr ///< Address and port.
+  ) {
+    ink_inet_copy(&addr, remote_addr);
   }
     
-  int setup_mc_send(unsigned int mc_ip, int mc_port,
-                    unsigned int my_ip, int my_port,
+  int setup_mc_send(sockaddr_storage const* mc_addr,
+                    sockaddr_storage const* my_addr,
                     bool non_blocking = NON_BLOCKING,
                     unsigned char mc_ttl = 1, bool mc_loopback = DISABLE_MC_LOOPBACK, Continuation * c = NULL);
 
-  int setup_mc_receive(unsigned int mc_ip, int port,
+  int setup_mc_receive(sockaddr_storage const* from,
                        bool non_blocking = NON_BLOCKING, Connection * sendchan = NULL, Continuation * c = NULL);
 
   int close();                  // 0 on success, -errno on failure
@@ -160,8 +154,8 @@ struct Server: public Connection
   //
   // IP address in network byte order
   //
-  unsigned int accept_ip;
-  char *accept_ip_str;
+  sockaddr_storage accept_addr;
+//  char *accept_ip_str;
 
   /// If set, transparently connect to origin server for requests.
   bool f_outbound_transparent;
@@ -176,20 +170,21 @@ struct Server: public Connection
   int accept(Connection * c);
 
   //
-  // Listen on a socket. We assume the port is in host by orderr, but
-  // that the IP address (specified by accept_ip) has already been
+  // Listen on a socket. We assume the port is in host by order, but
+  // that the IP address (specified by accept_addr) has already been
   // converted into network byte order
   //
 
-  int listen(int port, int domain = AF_INET, bool non_blocking = false, int recv_bufsize = 0, int send_bufsize = 0);
+  int listen(bool non_blocking = false, int recv_bufsize = 0, int send_bufsize = 0);
   int setup_fd_for_listen(bool non_blocking = false, int recv_bufsize = 0, int send_bufsize = 0);
 
   Server()
     : Connection()
-    , accept_ip(INADDR_ANY)
-    , accept_ip_str(NULL)
+//    , accept_ip_str(NULL)
     , f_outbound_transparent(false)
-  { }
+  {
+    ink_inet_invalidate(accept_addr);
+  }
 };
 
 #endif /*_Connection_h*/

Modified: trafficserver/traffic/branches/ssc/iocore/net/P_NetVConnection.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/ssc/iocore/net/P_NetVConnection.h?rev=1126862&r1=1126861&r2=1126862&view=diff
==============================================================================
--- trafficserver/traffic/branches/ssc/iocore/net/P_NetVConnection.h (original)
+++ trafficserver/traffic/branches/ssc/iocore/net/P_NetVConnection.h Tue May 24 04:11:36 2011
@@ -23,81 +23,32 @@
 
 #include "I_NetVConnection.h"
 
-TS_INLINE const struct sockaddr_storage &
+TS_INLINE sockaddr_storage const*
 NetVConnection::get_remote_addr()
 {
   if (!got_remote_addr) {
     set_remote_addr();
-    got_remote_addr = 1;
+    got_remote_addr = true;
   }
-  return remote_addr;
+  return &remote_addr;
 }
 
-TS_INLINE unsigned int
-NetVConnection::get_remote_ip()
-{
-  switch (get_remote_addr().ss_family) {
-  case AF_INET:
-    return (unsigned int)((struct sockaddr_in *)&(get_remote_addr()))->sin_addr.s_addr;
-  default:
-    return 0;
-  }
-}
-
-
-TS_INLINE int
-NetVConnection::get_remote_port()
-{
-  switch (get_remote_addr().ss_family) {
-  case AF_INET:
-    return ntohs(((struct sockaddr_in *)&(get_remote_addr()))->sin_port);
-  case AF_INET6:
-    return ntohs(((struct sockaddr_in6 *)&(get_remote_addr()))->sin6_port);
-  default:
-    return 0;
-  }
+TS_INLINE uint16_t
+NetVConnection::get_remote_port() {
+  return ink_inet_get_port(this->get_remote_addr());
 }
 
-TS_INLINE const struct sockaddr_storage &
+TS_INLINE sockaddr_storage const*
 NetVConnection::get_local_addr()
 {
   if (!got_local_addr) {
     set_local_addr();
-    switch (local_addr.ss_family) {
-    case AF_INET:
-      if (((struct sockaddr_in *)&(local_addr))->sin_addr.s_addr || ((struct sockaddr_in *)&(local_addr))->sin_port) {
-        got_local_addr = 1;
-      }
-      break;
-    case AF_INET6:
-      if (((struct sockaddr_in6 *)&(local_addr))->sin6_addr.s6_addr || ((struct sockaddr_in6 *)&(local_addr))->sin6_port) {
-        got_local_addr = 1;
-      }
-    }
+    got_local_addr = ink_inet_is_ip(local_addr);
   }
-  return local_addr;
+  return &local_addr;
 }
 
-TS_INLINE unsigned int
-NetVConnection::get_local_ip()
-{
-  switch (get_local_addr().ss_family) {
-  case AF_INET:
-    return (unsigned int)((struct sockaddr_in *)&(get_local_addr()))->sin_addr.s_addr;
-  default:
-    return 0;
-  }
-}
-
-TS_INLINE int
-NetVConnection::get_local_port()
-{
-  switch (get_local_addr().ss_family) {
-  case AF_INET:
-    return ntohs(((struct sockaddr_in *)&(get_local_addr()))->sin_port);
-  case AF_INET6:
-    return ntohs(((struct sockaddr_in6 *)&(get_local_addr()))->sin6_port);
-  default:
-    return 0;
-  }
+TS_INLINE uint16_t
+NetVConnection::get_local_port() {
+  return ink_inet_get_port(this->get_local_addr());
 }

Modified: trafficserver/traffic/branches/ssc/iocore/net/P_Socks.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/ssc/iocore/net/P_Socks.h?rev=1126862&r1=1126861&r2=1126862&view=diff
==============================================================================
--- trafficserver/traffic/branches/ssc/iocore/net/P_Socks.h (original)
+++ trafficserver/traffic/branches/ssc/iocore/net/P_Socks.h Tue May 24 04:11:36 2011
@@ -28,7 +28,7 @@
 
 #ifdef SOCKS_WITH_TS
 #include "ParentSelection.h"
-#include "IPRange.h"
+#include <ts/IpMap.h>
 #endif
 
 enum
@@ -59,18 +59,22 @@ struct socks_conf_struct
   unsigned short http_port;
 
 #ifdef SOCKS_WITH_TS
-  IPRange ip_range;
+  IpMap ip_map;
 #endif
 
 #ifndef SOCKS_WITH_TS
-  unsigned int socks_server;
-  int socks_server_port;
+  sockaddr_storage server_addr;
+//  unsigned int socks_server;
+//  int socks_server_port;
 #endif
 
     socks_conf_struct():socks_needed(0), server_connect_timeout(0), socks_timeout(100), default_version(5),
     user_name_n_passwd(NULL), user_name_n_passwd_len(0),
     per_server_connection_attempts(1), connection_attempts(0), accept_enabled(0), accept_port(0), http_port(1080)
   {
+# if !defined(SOCKS_WITH_TS)
+    ink_inet_invalidate(server_addr);
+# endif
   }
 };
 
@@ -113,11 +117,11 @@ struct SocksEntry:public Continuation
 
   SocksNetVC *netVConnection;
 
-  unsigned int ip;              // ip address in the original request
-  int port;                     // port number in the original request
+  // Changed from @a ip and @a port.
+  sockaddr_storage target_addr; ///< Original target address.
+  // Changed from @a server_ip, @a server_port.
+  sockaddr_storage server_addr; ///< Origin server address.
 
-  unsigned int server_ip;
-  int server_port;
   int nattempts;
 
   Action action_;
@@ -144,9 +148,11 @@ struct SocksEntry:public Continuation
   void free();
 
     SocksEntry():Continuation(NULL), netVConnection(0),
-    ip(0), port(0), server_ip(0), server_port(0), nattempts(0),
+    nattempts(0),
     lerrno(0), timeout(0), version(5), write_done(false), auth_handler(NULL), socks_cmd(NORMAL_SOCKS)
   {
+    ink_inet_invalidate(target_addr);
+    ink_inet_invalidate(server_addr);
   }
 };
 
@@ -154,15 +160,4 @@ typedef int (SocksEntry::*SocksEntryHand
 
 extern ClassAllocator<SocksEntry> socksAllocator;
 
-TS_INLINE void
-SocksAddrType::reset()
-{
-  if (type != SOCKS_ATYPE_IPV4 && addr.buf) {
-    xfree(addr.buf);
-  }
-
-  addr.buf = 0;
-  type = SOCKS_ATYPE_NONE;
-}
-
 #endif

Modified: trafficserver/traffic/branches/ssc/iocore/net/P_UDPConnection.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/ssc/iocore/net/P_UDPConnection.h?rev=1126862&r1=1126861&r2=1126862&view=diff
==============================================================================
--- trafficserver/traffic/branches/ssc/iocore/net/P_UDPConnection.h (original)
+++ trafficserver/traffic/branches/ssc/iocore/net/P_UDPConnection.h Tue May 24 04:11:36 2011
@@ -46,7 +46,7 @@ public:
   int refcount;               // public for assertion
 
   SOCKET fd;
-  struct sockaddr_in binding;
+  sockaddr_storage binding;
   int binding_valid;
   int tobedestroyed;
   int sendGenerationNum;
@@ -110,7 +110,7 @@ UDPConnection::getFd()
 }
 
 TS_INLINE void
-UDPConnection::setBinding(struct sockaddr_in *s)
+UDPConnection::setBinding(sockaddr_storage *s)
 {
   UDPConnectionInternal *p = (UDPConnectionInternal *) this;
   memcpy(&p->binding, s, sizeof(p->binding));
@@ -118,7 +118,7 @@ UDPConnection::setBinding(struct sockadd
 }
 
 TS_INLINE int
-UDPConnection::getBinding(struct sockaddr_in *s)
+UDPConnection::getBinding(sockaddr_storage *s)
 {
   UDPConnectionInternal *p = (UDPConnectionInternal *) this;
   memcpy(s, &p->binding, sizeof(*s));
@@ -165,7 +165,7 @@ UDPConnection::GetSendGenerationNumber()
 TS_INLINE int
 UDPConnection::getPortNum(void)
 {
-  return ((UDPConnectionInternal *) this)->binding.sin_port;
+  return ink_inet_get_port(static_cast<UDPConnectionInternal *>(this)->binding);
 }
 
 TS_INLINE int64_t

Modified: trafficserver/traffic/branches/ssc/iocore/net/P_UDPNet.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/ssc/iocore/net/P_UDPNet.h?rev=1126862&r1=1126861&r2=1126862&view=diff
==============================================================================
--- trafficserver/traffic/branches/ssc/iocore/net/P_UDPNet.h (original)
+++ trafficserver/traffic/branches/ssc/iocore/net/P_UDPNet.h Tue May 24 04:11:36 2011
@@ -399,7 +399,6 @@ struct InkSinglePipeInfo
   {
     wt = 0.0;
     bwLimit = 0;
-    destIP = 0;
     count = 0;
     bytesSent = pktsSent = 0;
     bwAlloc = 0;
@@ -417,7 +416,7 @@ struct InkSinglePipeInfo
   int64_t bwAlloc;
   // this is in Mbps
   double bwUsed;
-  int32_t destIP;
+  InkInetAddr destIP;
   uint32_t count;
   uint64_t bytesSent;
   uint64_t pktsSent;
@@ -437,13 +436,18 @@ extern InkPipeInfo G_inkPipeInfo;
 class UDPWorkContinuation:public Continuation
 {
 public:
-  UDPWorkContinuation():cont(NULL), numPairs(0), myIP(0), destIP(0),
-    sendbufsize(0), recvbufsize(0), udpConns(NULL), resultCode(NET_EVENT_DATAGRAM_OPEN)
+  UDPWorkContinuation():cont(NULL), numPairs(0), sendbufsize(0), recvbufsize(0), udpConns(NULL), resultCode(NET_EVENT_DATAGRAM_OPEN)
   {
+    ink_inet_init(local_ip);
+    ink_inet_init(remote_ip);
   };
   ~UDPWorkContinuation() {
   };
-  void init(Continuation * c, int num_pairs, unsigned int my_ip, unsigned int dest_ip, int s_bufsize, int r_bufsize);
+  void init(Continuation * c, int num_pairs,
+    sockaddr_storage const* local_ip,
+    sockaddr_storage const* remote_ip,
+//    unsigned int my_ip, unsigned int dest_ip,
+    int s_bufsize, int r_bufsize);
   int StateCreatePortPairs(int event, void *data);
   int StateDoCallback(int event, void *data);
 
@@ -452,7 +456,9 @@ public:
 private:
   Continuation * cont;
   int numPairs;
-  unsigned int myIP, destIP;
+//  unsigned int myIP, destIP;
+  sockaddr_storage local_ip; ///< replaces myIP.
+  sockaddr_storage remote_ip; ///< replaces destIP.
   int sendbufsize, recvbufsize;
   UnixUDPConnection **udpConns;
   int resultCode;

Modified: trafficserver/traffic/branches/ssc/iocore/net/P_UDPPacket.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/ssc/iocore/net/P_UDPPacket.h?rev=1126862&r1=1126861&r2=1126862&view=diff
==============================================================================
--- trafficserver/traffic/branches/ssc/iocore/net/P_UDPPacket.h (original)
+++ trafficserver/traffic/branches/ssc/iocore/net/P_UDPPacket.h Tue May 24 04:11:36 2011
@@ -210,7 +210,7 @@ UDPPacket::setArrivalTime(ink_hrtime t)
 }
 
 TS_INLINE UDPPacket *
-new_UDPPacket(struct sockaddr_in *to, ink_hrtime when, char *buf, int len)
+new_UDPPacket(sockaddr_storage *to, ink_hrtime when, char *buf, int len)
 {
   UDPPacketInternal *p = udpPacketAllocator.alloc();
 
@@ -233,7 +233,7 @@ new_UDPPacket(struct sockaddr_in *to, in
 }
 
 TS_INLINE UDPPacket *
-new_UDPPacket(struct sockaddr_in * to, ink_hrtime when, IOBufferBlock * buf, int len)
+new_UDPPacket(sockaddr_storage * to, ink_hrtime when, IOBufferBlock * buf, int len)
 {
   (void) len;
   UDPPacketInternal *p = udpPacketAllocator.alloc();
@@ -255,7 +255,7 @@ new_UDPPacket(struct sockaddr_in * to, i
 }
 
 TS_INLINE UDPPacket *
-new_UDPPacket(struct sockaddr_in * to, ink_hrtime when, Ptr<IOBufferBlock> buf)
+new_UDPPacket(sockaddr_storage * to, ink_hrtime when, Ptr<IOBufferBlock> buf)
 {
   UDPPacketInternal *p = udpPacketAllocator.alloc();
 
@@ -277,7 +277,7 @@ new_UDPPacket(ink_hrtime when, Ptr<IOBuf
 }
 
 TS_INLINE UDPPacket *
-new_incoming_UDPPacket(struct sockaddr_in * from, char *buf, int len)
+new_incoming_UDPPacket(sockaddr_storage * from, char *buf, int len)
 {
   UDPPacketInternal *p = udpPacketAllocator.alloc();
 

Modified: trafficserver/traffic/branches/ssc/iocore/net/P_UnixNetProcessor.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/ssc/iocore/net/P_UnixNetProcessor.h?rev=1126862&r1=1126861&r2=1126862&view=diff
==============================================================================
--- trafficserver/traffic/branches/ssc/iocore/net/P_UnixNetProcessor.h (original)
+++ trafficserver/traffic/branches/ssc/iocore/net/P_UnixNetProcessor.h Tue May 24 04:11:36 2011
@@ -36,18 +36,30 @@ class UnixNetVConnection;
 struct UnixNetProcessor:public NetProcessor
 {
 public:
-virtual Action *accept_internal (Continuation * cont,
-				 int fd,
-				 sockaddr * bound_sockaddr = NULL,
-				 int *bound_sockaddr_size = NULL,
-				 bool frequent_accept = true,
-				 AcceptFunctionPtr fn = net_accept,
-				 unsigned int accept_ip = INADDR_ANY,
-				 char *accept_ip_str = NULL,
-				 AcceptOptions const &opt = DEFAULT_ACCEPT_OPTIONS);
-
-  Action *connect_re_internal(Continuation * cont, unsigned int ip, int port, NetVCOptions * options = NULL);
-  Action *connect(Continuation * cont, UnixNetVConnection ** vc, unsigned int ip, int port, NetVCOptions * opt = NULL);
+  virtual Action *accept_internal (
+    Continuation * cont,
+    int fd,
+    sockaddr_storage const* accept_addr, ///< Address on which to listen.
+//  sockaddr_storage const* bound_sockaddr = NULL,
+//  int *bound_sockaddr_size = NULL,
+//    bool frequent_accept = true,
+//    AcceptFunctionPtr fn = net_accept,
+//  unsigned int accept_ip = INADDR_ANY,
+//  char *accept_ip_str = NULL,
+    AcceptOptions const &opt
+  );
+
+  Action *connect_re_internal(
+    Continuation * cont,
+    sockaddr_storage const* target,
+    NetVCOptions * options = NULL
+  );
+  Action *connect(
+    Continuation * cont,
+    UnixNetVConnection ** vc,
+    sockaddr_storage const* target,
+    NetVCOptions * opt = NULL
+  );
 
   // Virtual function allows etype to be upgraded to ET_SSL for SSLNetProcessor.  Does
   // nothing for NetProcessor
@@ -74,14 +86,17 @@ virtual Action *accept_internal (Continu
   EThread **netthreads;
 
   char *incoming_ip_to_bind;
-  int incoming_ip_to_bind_saddr;
+  sockaddr_storage incoming_ip_to_bind_saddr;
 };
 
 
 TS_INLINE Action *
-NetProcessor::connect_re(Continuation * cont, unsigned int ip, int port, NetVCOptions * opts)
-{
-  return static_cast<UnixNetProcessor *>(this)->connect_re_internal(cont, ip, port, opts);
+NetProcessor::connect_re(
+  Continuation * cont,
+  sockaddr_storage const* addr,
+  NetVCOptions * opts
+) {
+  return static_cast<UnixNetProcessor *>(this)->connect_re_internal(cont, addr, opts);
 }
 
 

Modified: trafficserver/traffic/branches/ssc/iocore/net/P_UnixNetVConnection.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/ssc/iocore/net/P_UnixNetVConnection.h?rev=1126862&r1=1126861&r2=1126862&view=diff
==============================================================================
--- trafficserver/traffic/branches/ssc/iocore/net/P_UnixNetVConnection.h (original)
+++ trafficserver/traffic/branches/ssc/iocore/net/P_UnixNetVConnection.h Tue May 24 04:11:36 2011
@@ -45,9 +45,7 @@ TS_INLINE void
 NetVCOptions::reset()
 {
   ip_proto = USE_TCP;
-  local_port = 0;
-  port_binding = ANY_PORT;
-  local_addr = 0;
+  ink_inet_invalidate(local_addr);
   addr_binding = ANY_ADDR;
   f_blocking = false;
   f_blocking_connect = false;
@@ -204,10 +202,12 @@ public:
   EventIO ep;
   NetHandler *nh;
   unsigned int id;
-  unsigned int ip;
+//  unsigned int ip;
   //  unsigned int _interface; // 'interface' conflicts with the C++ keyword
   int accept_port;
-  int port;
+//  int port;
+  // replaces @a ip and @a port.
+  sockaddr_storage server_addr; /// Server address and port.
 
   union
   {
@@ -216,11 +216,12 @@ public:
 #define NET_VC_SHUTDOWN_WRITE 2
     struct
     {
-      unsigned int got_local_sa:1;
+      unsigned int got_local_addr:1;
       unsigned int shutdown:2;
     } f;
   };
-  struct sockaddr_in local_sa;
+  /// Local address of connection.
+  sockaddr_storage local_addr;
 
   Connection con;
   int recursion;
@@ -249,14 +250,14 @@ typedef int (UnixNetVConnection::*NetVCo
 TS_INLINE void
 UnixNetVConnection::set_remote_addr()
 {
-  remote_addr = con.sa;
+  ink_inet_copy(remote_addr, con.addr);
 }
 
 TS_INLINE void
 UnixNetVConnection::set_local_addr()
 {
   int local_sa_size = sizeof(local_addr);
-  safe_getsockname(con.fd, (sockaddr *) & local_addr, &local_sa_size);
+  safe_getsockname(con.fd, &local_addr, &local_sa_size);
 }
 
 TS_INLINE ink_hrtime

Modified: trafficserver/traffic/branches/ssc/iocore/net/SSLNetVConnection.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/ssc/iocore/net/SSLNetVConnection.cc?rev=1126862&r1=1126861&r2=1126862&view=diff
==============================================================================
--- trafficserver/traffic/branches/ssc/iocore/net/SSLNetVConnection.cc (original)
+++ trafficserver/traffic/branches/ssc/iocore/net/SSLNetVConnection.cc Tue May 24 04:11:36 2011
@@ -451,18 +451,16 @@ int
 SSLNetVConnection::sslStartHandShake(int event, int &err)
 {
   SSL_CTX *ctx = NULL;
-  struct sockaddr_in sa;
-  struct in_addr ia;
+  sockaddr_storage sa;
   int namelen = sizeof(sa);
-  char *strAddr;
 
   if (event == SSL_EVENT_SERVER) {
     if (ssl == NULL) {
       if (sslCertLookup.multipleCerts) {
-        safe_getsockname(get_socket(), (struct sockaddr *) &sa, &namelen);
-        ia.s_addr = sa.sin_addr.s_addr;
-        strAddr = inet_ntoa(ia);
-        ctx = sslCertLookup.findInfoInHash(strAddr);
+        char buff[INET6_ADDRSTRLEN];
+        safe_getsockname(get_socket(), &sa, &namelen);
+        ink_inet_ntop(&sa, buff, sizeof(buff));
+        ctx = sslCertLookup.findInfoInHash(buff);
         if (ctx == NULL)
           ctx = ssl_NetProcessor.ctx;
       } else {

Modified: trafficserver/traffic/branches/ssc/iocore/net/Socks.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/ssc/iocore/net/Socks.cc?rev=1126862&r1=1126861&r2=1126862&view=diff
==============================================================================
--- trafficserver/traffic/branches/ssc/iocore/net/Socks.cc (original)
+++ trafficserver/traffic/branches/ssc/iocore/net/Socks.cc Tue May 24 04:11:36 2011
@@ -32,6 +32,7 @@
 
 #include "P_Net.h"
 #include "I_Layout.h"
+#include <ts/IpMapConf.h>
 
 socks_conf_struct *g_socks_conf_stuff = 0;
 
@@ -53,19 +54,17 @@ SocksEntry::init(ProxyMutex * m, SocksNe
 
   SET_HANDLER(&SocksEntry::startEvent);
 
-  ip = vc->ip;
-  port = vc->port;
+  ink_inet_copy(target_addr, vc->local_addr);
 
 #ifdef SOCKS_WITH_TS
   req_data.hdr = 0;
   req_data.hostname_str = 0;
   req_data.api_info = 0;
   req_data.xact_start = time(0);
-  req_data.dest_ip = ip;
+  ink_inet_copy(req_data.dest_ip, target_addr);
 
   //we dont have information about the source. set to destination's
-  req_data.src_ip = ip;
-  req_data.incoming_port = port;
+  ink_inet_copy(req_data.src_ip, target_addr);
 
   server_params = SocksServerConfig::acquire();
 #endif
@@ -102,23 +101,33 @@ SocksEntry::findServer()
 
   switch (server_result.r) {
   case PARENT_SPECIFIED:
-    server_ip = inet_addr(server_result.hostname);
-    server_port = server_result.port;
+    // Original was inet_addr, but should hostnames work?
+    // ink_inet_pton only supports numeric (because other clients
+    // explicitly want to avoid hostname lookups).
+    if (0 == ink_inet_pton(server_result.hostname, &server_addr)) {
+      ink_inet_port_cast(server_addr) = server_result.port;
+    } else {
+      Debug("SocksParent", "Invalid parent server specified %s", server_result.hostname);
+    }
     break;
 
   default:
     ink_debug_assert(!"Unexpected event");
   case PARENT_DIRECT:
   case PARENT_FAIL:
-    server_ip = (unsigned int) -1;
+    ink_inet_invalidate(server_addr);
   }
 #else
-  server_ip = (nattempts > netProcessor.socks_conf_stuff->connection_attempts)
-    ? (unsigned int) -1 : g_socks_conf_stuff->socks_server;
-  server_port = g_socks_conf_stuff->socks_server_port;
+  if (nattempts > netProcessor.socks_conf_stuff->connection_attempts)
+    ink_inet_invalidate(server_addr);
+  else ink_inet_copy(server_addr, g_socks_conf_stuff->socks_server);
 #endif // SOCKS_WITH_TS
 
-  Debug("SocksParents", "findServer result: %u.%u.%u.%u:%d", PRINT_IP(server_ip), server_port);
+  char buff[INET6_ADDRSTRLEN];
+  Debug("SocksParents", "findServer result: %s:%d",
+    ink_inet_ntop(&server_addr, buff, sizeof(buff)),
+    ink_inet_get_port(&server_addr)
+  );
 }
 
 void
@@ -152,8 +161,7 @@ SocksEntry::free()
       netVConnection->do_io_read(this, 0, 0);
       netVConnection->do_io_write(this, 0, 0);
       netVConnection->action_ = action_;        //assign the original continuation
-      netVConnection->ip = ip;
-      netVConnection->port = port;      // we already have the lock for the continuation
+      ink_inet_copy(netVConnection->server_addr, server_addr);
       Debug("Socks", "Sent success to HTTP");
       NET_INCREMENT_DYN_STAT(socks_connections_successful_stat);
       action_.continuation->handleEvent(NET_EVENT_OPEN, netVConnection);
@@ -186,11 +194,12 @@ SocksEntry::startEvent(int event, void *
       timeout = NULL;
     }
 
-    Debug("Socks", "Failed to connect to %u.%u.%u.%u:%d", PRINT_IP(server_ip), server_port);
+    char buff[INET6_ADDRPORTSTRLEN];
+    Debug("Socks", "Failed to connect to %s", ink_inet_nptop(&server_addr, buff, sizeof(buff)));
 
     findServer();
 
-    if (server_ip == (uint32_t) - 1) {
+    if (!ink_inet_is_valid(server_addr)) {
       Debug("Socks", "Unable to open connection to the SOCKS server");
       lerrno = ESOCK_NO_SOCK_SERVER_CONN;
       free();
@@ -213,7 +222,7 @@ SocksEntry::startEvent(int event, void *
 
     NetVCOptions options;
     options.socks_support = NO_SOCKS;
-    netProcessor.connect_re(this, server_ip, server_port, &options);
+    netProcessor.connect_re(this, &server_addr, &options);
   }
 
   return EVENT_CONT;
@@ -242,28 +251,45 @@ SocksEntry::mainEvent(int event, void *d
 
       p[n_bytes++] = version;
       p[n_bytes++] = (socks_cmd == NORMAL_SOCKS) ? SOCKS_CONNECT : socks_cmd;
-      ts = (unsigned short) htons(port);
+      ts = ink_inet_port_cast(server_addr);
 
       if (version == SOCKS5_VERSION) {
         p[n_bytes++] = 0;       //Reserved
-        p[n_bytes++] = 1;       //IPv4 addr
-        p[n_bytes++] = ((unsigned char *) &ip)[0];
-        p[n_bytes++] = ((unsigned char *) &ip)[1];
-        p[n_bytes++] = ((unsigned char *) &ip)[2];
-        p[n_bytes++] = ((unsigned char *) &ip)[3];
+        if (ink_inet_is_ip4(server_addr)) {
+          p[n_bytes++] = 1;       //IPv4 addr
+          memcpy(p + n_bytes,
+            &ink_inet_ip4_cast(server_addr).sin_addr,
+            4
+          );
+          n_bytes += 4;
+        } else if (ink_inet_is_ip6(server_addr)) {
+          p[n_bytes++] = 4;       //IPv6 addr
+          memcpy(p + n_bytes,
+            &ink_inet_ip6_cast(server_addr).sin6_addr,
+            INK_IP6_SIZE
+          );
+          n_bytes += INK_IP6_SIZE;
+        } else {
+          Debug("Socks", "SOCKS supports only IP addresses.");
+        }
       }
 
-      p[n_bytes++] = ((unsigned char *) &ts)[0];
-      p[n_bytes++] = ((unsigned char *) &ts)[1];
+      memcpy(p + n_bytes, &ts, 2);
+      n_bytes += 2;
 
       if (version == SOCKS4_VERSION) {
-        //for socks4, ip addr is after the port
-        p[n_bytes++] = ((unsigned char *) &ip)[0];
-        p[n_bytes++] = ((unsigned char *) &ip)[1];
-        p[n_bytes++] = ((unsigned char *) &ip)[2];
-        p[n_bytes++] = ((unsigned char *) &ip)[3];
-
-        p[n_bytes++] = 0;       // NULL
+        if (ink_inet_is_ip4(server_addr)) {
+          //for socks4, ip addr is after the port
+          memcpy(p + n_bytes,
+            &ink_inet_ip4_cast(server_addr).sin_addr,
+            4
+          );
+          n_bytes += 4;
+
+          p[n_bytes++] = 0;       // NULL
+        } else {
+          Debug("Socks", "SOCKS v4 supports only IPv4 addresses.");
+        }
       }
 
     }
@@ -500,7 +526,7 @@ loadSocksConfiguration(socks_conf_struct
     goto error;
   }
 #ifdef SOCKS_WITH_TS
-  tmp = socks_conf_stuff->ip_range.read_table_from_file(socks_config_fd, "no_socks");
+  tmp = Load_IpMap_From_File(&socks_conf_stuff->ip_map, socks_config_fd, "no_socks");
 
   if (tmp) {
     Error("SOCKS Config: Error while reading ip_range: %s.", tmp);

Modified: trafficserver/traffic/branches/ssc/iocore/net/UnixConnection.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/ssc/iocore/net/UnixConnection.cc?rev=1126862&r1=1126861&r2=1126862&view=diff
==============================================================================
--- trafficserver/traffic/branches/ssc/iocore/net/UnixConnection.cc (original)
+++ trafficserver/traffic/branches/ssc/iocore/net/UnixConnection.cc Tue May 24 04:11:36 2011
@@ -45,16 +45,17 @@ unsigned int const IP_TRANSPARENT = 19;
 // Functions
 //
 int
-Connection::setup_mc_send(unsigned int mc_ip, int mc_port,
-                          unsigned int my_ip, int my_port,
-                          bool non_blocking, unsigned char mc_ttl, bool mc_loopback, Continuation * c)
-{
+Connection::setup_mc_send(
+  sockaddr_storage const* mc_addr,
+  sockaddr_storage const* my_addr,
+  bool non_blocking, unsigned char mc_ttl, bool mc_loopback, Continuation * c
+) {
   (void) c;
   ink_assert(fd == NO_FD);
   int res = 0;
   int enable_reuseaddr = 1;
 
-  if ((res = socketManager.mc_socket(AF_INET, SOCK_DGRAM, 0, non_blocking)) < 0)
+  if ((res = socketManager.mc_socket(my_addr->ss_family, SOCK_DGRAM, 0, non_blocking)) < 0)
     goto Lerror;
 
   fd = res;
@@ -63,19 +64,11 @@ Connection::setup_mc_send(unsigned int m
     goto Lerror;
   }
 
-  struct sockaddr_in bind_sa;
-  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) {
+  if ((res = socketManager.ink_bind(fd, my_addr, sizeof(*my_addr), IPPROTO_UDP)) < 0) {
     goto Lerror;
   }
 
-  sa.ss_family = AF_INET;
-  ((struct sockaddr_in *)(&sa))->sin_port = htons(mc_port);
-  ((struct sockaddr_in *)(&sa))->sin_addr.s_addr = mc_ip;
-  memset(&(((struct sockaddr_in *)(&sa))->sin_zero), 0, 8);
+  ink_inet_copy(&addr, mc_addr);
 
 #ifdef SET_CLOSE_ON_EXEC
   if ((res = safe_fcntl(fd, F_SETFD, 1)) < 0)
@@ -108,16 +101,17 @@ Lerror:
 
 
 int
-Connection::setup_mc_receive(unsigned int mc_ip, int mc_port,
-                             bool non_blocking, Connection * sendChan, Continuation * c)
-{
+Connection::setup_mc_receive(
+  sockaddr_storage const* mc_addr,
+  bool non_blocking, Connection * sendChan, Continuation * c
+) {
   ink_assert(fd == NO_FD);
   (void) sendChan;
   (void) c;
   int res = 0;
   int enable_reuseaddr = 1;
 
-  if ((res = socketManager.socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+  if ((res = socketManager.socket(mc_addr->ss_family, SOCK_DGRAM, 0)) < 0)
     goto Lerror;
 
   fd = res;
@@ -130,25 +124,24 @@ Connection::setup_mc_receive(unsigned in
   if ((res = safe_setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &enable_reuseaddr, sizeof(enable_reuseaddr)) < 0))
     goto Lerror;
 
-  memset(&sa, 0, sizeof(sa));
-  sa.ss_family = AF_INET;
-  ((struct sockaddr_in *)(&sa))->sin_addr.s_addr = mc_ip;
-  ((struct sockaddr_in *)(&sa))->sin_port = htons(mc_port);
+  ink_inet_copy(&addr, mc_addr);
 
-  if ((res = socketManager.ink_bind(fd, (struct sockaddr *) &sa, sizeof(sa), IPPROTO_TCP)) < 0)
+  if ((res = socketManager.ink_bind(fd, &addr, sizeof(addr), IPPROTO_TCP)) < 0)
     goto Lerror;
 
   if (non_blocking)
     if ((res = safe_nonblocking(fd)) < 0)
       goto Lerror;
 
-  struct ip_mreq mc_request;
-  // Add ourselves to the MultiCast group
-  mc_request.imr_multiaddr.s_addr = mc_ip;
-  mc_request.imr_interface.s_addr = htonl(INADDR_ANY);
+  if (ink_inet_is_ip4(addr)) {
+    struct ip_mreq mc_request;
+    // Add ourselves to the MultiCast group
+    mc_request.imr_multiaddr.s_addr = ink_inet_ip4_cast(mc_addr)->sin_addr.s_addr;
+    mc_request.imr_interface.s_addr = htonl(INADDR_ANY);
 
-  if ((res = safe_setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &mc_request, sizeof(mc_request)) < 0))
-    goto Lerror;
+    if ((res = safe_setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &mc_request, sizeof(mc_request)) < 0))
+      goto Lerror;
+  }
   return 0;
 
 Lerror:
@@ -220,17 +213,26 @@ Connection::open(NetVCOptions const& opt
   ink_assert(fd == NO_FD);
   int enable_reuseaddr = 1; // used for sockopt setting
   int res = 0; // temp result
-  uint32_t local_addr = NetVCOptions::ANY_ADDR == opt.addr_binding
-    ? INADDR_ANY
-    : opt.local_addr;
-  uint16_t local_port = NetVCOptions::ANY_PORT == opt.port_binding
-    ? 0
-    : opt.local_port;
+  sockaddr_storage local_addr;
   int sock_type = NetVCOptions::USE_UDP == opt.ip_proto
     ? SOCK_DGRAM
     : SOCK_STREAM;
+  int protocol = AF_INET;
 
-  res = socketManager.socket(AF_INET, sock_type, 0);
+  // copy it local so we can (potentially) modify it.
+  ink_inet_copy(local_addr, opt.local_addr);
+
+  if (ink_inet_is_ip6(opt.local_addr)) {
+    protocol = opt.local_addr.ss_family;
+    if (NetVCOptions::ANY_ADDR == opt.addr_binding)
+      ink_inet_ip6_cast(local_addr).sin6_addr = in6addr_any;
+      ;
+  } else {
+    if (NetVCOptions::ANY_ADDR == opt.addr_binding)
+      ink_inet_ip4_cast(local_addr).sin_addr.s_addr = INADDR_ANY;
+  }
+
+  res = socketManager.socket(protocol, sock_type, 0);
   if (-1 == res) return -errno;
 
   fd = res;
@@ -279,7 +281,9 @@ Connection::open(NetVCOptions const& opt
     }
   }
 
-  if (NetVCOptions::FOREIGN_ADDR == opt.addr_binding && local_addr) {
+  if (NetVCOptions::FOREIGN_ADDR == opt.addr_binding
+    && ink_inet_is_valid(local_addr)
+  ) {
     static char const * const DEBUG_TEXT = "::open setsockopt() IP_TRANSPARENT";
 #if TS_USE_TPROXY
     int value = 1;
@@ -296,15 +300,7 @@ Connection::open(NetVCOptions const& opt
 #endif
   }
 
-  // Local address/port.
-  struct sockaddr_in bind_sa;
-  memset(&bind_sa, 0, sizeof(bind_sa));
-  bind_sa.sin_family = AF_INET;
-  bind_sa.sin_port = htons(local_port);
-  bind_sa.sin_addr.s_addr = local_addr;
-  if (-1 == socketManager.ink_bind(fd,
-				   reinterpret_cast<struct sockaddr *>(&bind_sa),
-				   sizeof(bind_sa)))
+  if (-1 == socketManager.ink_bind(fd, &local_addr, sizeof(local_addr)))
     return -errno;
 
   cleanup.reset();
@@ -313,20 +309,19 @@ Connection::open(NetVCOptions const& opt
 }
 
 int
-Connection::connect(uint32_t addr, uint16_t port, NetVCOptions const& opt) {
+Connection::connect(sockaddr_storage const* target, NetVCOptions const& opt) {
   ink_assert(fd != NO_FD);
   ink_assert(is_bound);
   ink_assert(!is_connected);
 
   int res;
 
-  this->setRemote(addr, port);
+  this->setRemote(target);
 
   cleaner<Connection> cleanup(this, &Connection::_cleanup); // mark for close until we succeed.
 
-  res = ::connect(fd,
-		  reinterpret_cast<struct sockaddr *>(&sa),
-		  sizeof(struct sockaddr_in));
+  res = ::connect(fd, ink_inet_sa_cast(target), sizeof(*target));
+
   // It's only really an error if either the connect was blocking
   // or it wasn't blocking and the error was other than EINPROGRESS.
   // (Is EWOULDBLOCK ok? Does that start the connect?)

Modified: trafficserver/traffic/branches/ssc/iocore/net/UnixNetAccept.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/ssc/iocore/net/UnixNetAccept.cc?rev=1126862&r1=1126861&r2=1126862&view=diff
==============================================================================
--- trafficserver/traffic/branches/ssc/iocore/net/UnixNetAccept.cc (original)
+++ trafficserver/traffic/branches/ssc/iocore/net/UnixNetAccept.cc Tue May 24 04:11:36 2011
@@ -118,9 +118,11 @@ net_accept(NetAccept * na, void *ep, boo
     na->alloc_cache = NULL;
 
     vc->submit_time = ink_get_hrtime();
-    vc->ip = ((struct sockaddr_in *)(&(vc->con.sa)))->sin_addr.s_addr;
-    vc->port = ntohs(((struct sockaddr_in *)(&(vc->con.sa)))->sin_port);
-    vc->accept_port = ntohs(((struct sockaddr_in *)(&(na->server.sa)))->sin_port);
+    ink_inet_copy(vc->server_addr, vc->con.addr);
+//    vc->ip = ((sockaddr_storage *)(&(vc->con.sa)))->sin_addr.s_addr;
+//    vc->port = ntohs(((sockaddr_storage *)(&(vc->con.sa)))->sin_port);
+    vc->accept_port = ink_inet_get_port(na->server.addr);
+//    vc->accept_port = ntohs(((sockaddr_storage *)(&(na->server.sa)))->sin_port);
     vc->mutex = new_ProxyMutex();
     vc->action_ = *na->action_;
     vc->set_is_transparent(na->server.f_inbound_transparent);
@@ -276,7 +278,7 @@ NetAccept::do_listen(bool non_blocking)
     }
   } else {
   Lretry:
-    if ((res = server.listen(port, domain, non_blocking, recv_bufsize, send_bufsize)))
+    if ((res = server.listen(non_blocking, recv_bufsize, send_bufsize)))
       Warning("unable to listen on port %d: %d %d, %s", port, res, errno, strerror(errno));
   }
   if (callback_on_open && !action_->cancelled) {
@@ -342,9 +344,11 @@ NetAccept::do_blocking_accept(NetAccept 
 
     NET_SUM_GLOBAL_DYN_STAT(net_connections_currently_open_stat, 1);
     vc->submit_time = now;
-    vc->ip = ((struct sockaddr_in *)(&(vc->con.sa)))->sin_addr.s_addr;
-    vc->port = ntohs(((struct sockaddr_in *)(&(vc->con.sa)))->sin_port);
-    vc->accept_port = ntohs(((struct sockaddr_in *)(&(server.sa)))->sin_port);
+    ink_inet_copy(vc->server_addr, vc->con.addr);
+//    vc->ip = ((sockaddr_storage *)(&(vc->con.sa)))->sin_addr.s_addr;
+//    vc->port = ntohs(((sockaddr_storage *)(&(vc->con.sa)))->sin_port);
+    vc->accept_port = ink_inet_get_port(server.addr);
+//    vc->accept_port = ntohs(((sockaddr_storage *)(&(server.sa)))->sin_port);
     vc->set_is_transparent(master_na->server.f_inbound_transparent);
     vc->set_is_other_side_transparent(master_na->server.f_outbound_transparent);
     Debug("http_tproxy", "Marking accepted %sconnect on %x as%s outbound transparent.\n",
@@ -390,8 +394,12 @@ NetAccept::acceptEvent(int event, void *
       if ((res = accept_fn(this, e, false)) < 0) {
         NET_DECREMENT_DYN_STAT(net_accepts_currently_open_stat);
         /* INKqa11179 */
-        Warning("Accept on port %d failed with error no %d", ntohs(((struct sockaddr_in *)(&(server.sa)))->sin_port), res);
-        Warning("Traffic Server may be unable to accept more network" "connections on %d", ntohs(((struct sockaddr_in *)(&(server.sa)))->sin_port));
+        Warning("Accept on port %d failed with error no %d",
+          ink_inet_get_port(server.addr), res
+        );
+        Warning("Traffic Server may be unable to accept more network" "connections on %d",
+          ink_inet_get_port(server.addr)
+        );
         e->cancel();
         delete this;
         return EVENT_DONE;
@@ -421,8 +429,8 @@ NetAccept::acceptFastEvent(int event, vo
     }
     vc = allocateThread(e->ethread);
 
-    socklen_t sz = sizeof(vc->con.sa);
-    int fd = socketManager.accept(server.fd, (struct sockaddr *) &vc->con.sa, &sz);
+    socklen_t sz = sizeof(vc->con.addr);
+    int fd = socketManager.accept(server.fd, &vc->con.addr, &sz);
 
     if (likely(fd >= 0)) {
       Debug("iocore_net", "accepted a new socket: %d", fd);
@@ -486,9 +494,11 @@ NetAccept::acceptFastEvent(int event, vo
     vc->id = net_next_connection_number();
 
     vc->submit_time = ink_get_hrtime();
-    vc->ip = ((struct sockaddr_in *)(&(vc->con.sa)))->sin_addr.s_addr;
-    vc->port = ntohs(((struct sockaddr_in *)(&(vc->con.sa)))->sin_port);
-    vc->accept_port = ntohs(((struct sockaddr_in *)(&(server.sa)))->sin_port);
+    ink_inet_copy(vc->server_addr, vc->con.addr);
+//    vc->ip = ((sockaddr_storage *)(&(vc->con.sa)))->sin_addr.s_addr;
+//    vc->port = ntohs(((sockaddr_storage *)(&(vc->con.sa)))->sin_port);
+    vc->accept_port = ink_inet_get_port(server.addr);
+//    vc->accept_port = ntohs(((sockaddr_storage *)(&(server.sa)))->sin_port);
     vc->set_is_transparent(server.f_inbound_transparent);
     vc->set_is_other_side_transparent(server.f_outbound_transparent);
     Debug("http_tproxy", "Marking fast accepted %sconnection on as%s outbound transparent.\n",

Modified: trafficserver/traffic/branches/ssc/iocore/net/UnixNetPages.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/ssc/iocore/net/UnixNetPages.cc?rev=1126862&r1=1126861&r2=1126862&view=diff
==============================================================================
--- trafficserver/traffic/branches/ssc/iocore/net/UnixNetPages.cc (original)
+++ trafficserver/traffic/branches/ssc/iocore/net/UnixNetPages.cc Tue May 24 04:11:36 2011
@@ -34,8 +34,7 @@ typedef int (ShowNet::*ShowNetEventHandl
 struct ShowNet: public ShowCont
 {
   int ithread;
-  int port;
-  unsigned int ip;
+  sockaddr_storage addr;
 
   int showMain(int event, Event * e)
   {
@@ -64,14 +63,19 @@ struct ShowNet: public ShowCont
 
     ink_hrtime now = ink_get_hrtime();
     forl_LL(UnixNetVConnection, vc, nh->open_list) {
-      if (ip && ip != vc->ip)
+      uint16_t port = ink_inet_port_cast(addr);
+      if (ink_inet_is_ip(addr) && addr != vc->server_addr)
         continue;
-      if (port && port != vc->port && port != vc->accept_port)
+      if (port && port != ink_inet_port_cast(vc->server_addr) && port != vc->accept_port)
         continue;
-      char ipbuf[80];
-      snprintf(ipbuf, sizeof(ipbuf), "%hhu.%hhu.%hhu.%hhu", PRINT_IP(vc->ip));
+      char ipbuf[INET6_ADDRSTRLEN];
+      ink_inet_ntop(&vc->server_addr, ipbuf, sizeof(ipbuf));
+      char opt_ipbuf[INET6_ADDRSTRLEN];
       char interbuf[80];
-      snprintf(interbuf, sizeof(interbuf), "[%s] %hhu.%hhu.%hhu.%hhu", vc->options.toString(vc->options.addr_binding), PRINT_IP(vc->options.local_addr));
+      snprintf(interbuf, sizeof(interbuf), "[%s] %s",
+        vc->options.toString(vc->options.addr_binding),
+        ink_inet_ntop(&vc->options.local_addr, opt_ipbuf, sizeof(opt_ipbuf))
+      );
       CHECK_SHOW(show("<tr>"
                       // "<td><a href=\"/connection/%d\">%d</a></td>"
                       "<td>%d</td>"     // ID
@@ -95,7 +99,7 @@ struct ShowNet: public ShowCont
                       "</tr>\n",
                       vc->id,
                       ipbuf,
-                      vc->port,
+                      ink_inet_get_port(vc->server_addr),
                       vc->con.fd,
                       interbuf,
                       vc->accept_port,
@@ -200,7 +204,8 @@ struct ShowNet: public ShowCont
   }
 
 ShowNet(Continuation * c, HTTPHdr * h):
-  ShowCont(c, h), ithread(0), port(0), ip(0) {
+  ShowCont(c, h), ithread(0) {
+    ink_inet_invalidate(addr);
     SET_HANDLER(&ShowNet::showMain);
   }
 };
@@ -227,7 +232,7 @@ register_ShowNet(Continuation * c, HTTPH
     if (s->sarg)
       gn = (char *)memchr(s->sarg, '=', strlen(s->sarg));
     if (gn)
-      s->ip = ink_inet_addr(gn + 1);
+      ink_inet_pton(gn + 1, &s->addr);
     SET_CONTINUATION_HANDLER(s, &ShowNet::showConnections);
   } else if (STREQ_PREFIX(path, path_len, "ports")) {
     int query_len;
@@ -237,7 +242,7 @@ register_ShowNet(Continuation * c, HTTPH
     if (s->sarg)
       gn = (char *)memchr(s->sarg, '=', strlen(s->sarg));
     if (gn)
-      s->port = atoi(gn + 1);
+      ink_inet_port_cast(s->addr) = htons(atoi(gn+1));
     SET_CONTINUATION_HANDLER(s, &ShowNet::showConnections);
   }
   eventProcessor.schedule_imm(s, ET_TASK);

Modified: trafficserver/traffic/branches/ssc/iocore/net/UnixNetProcessor.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/ssc/iocore/net/UnixNetProcessor.cc?rev=1126862&r1=1126861&r2=1126862&view=diff
==============================================================================
--- trafficserver/traffic/branches/ssc/iocore/net/UnixNetProcessor.cc (original)
+++ trafficserver/traffic/branches/ssc/iocore/net/UnixNetProcessor.cc Tue May 24 04:11:36 2011
@@ -31,13 +31,13 @@
 NetProcessor::AcceptOptions const NetProcessor::DEFAULT_ACCEPT_OPTIONS;
 
 NetProcessor::AcceptOptions&
-NetProcessor::AcceptOptions::reset()
-{
-  port = 0;
+NetProcessor::AcceptOptions::reset() {
   accept_threads = 0;
   domain = AF_INET;
   etype = ET_NET;
   f_callback_on_open = false;
+  localhost_only = false;
+  frequent_accept = false;
   recv_bufsize = 0;
   send_bufsize = 0;
   sockopt_flags = 0;
@@ -61,93 +61,102 @@ net_next_connection_number()
 
 Action *
 NetProcessor::accept(Continuation * cont,
-                     int port,
-                     int domain,
-                     int accept_threads,
-                     bool frequent_accept,
-                     unsigned int accept_ip,
-                     char *accept_ip_str,
-                     bool callback_on_open,
-                     SOCKET listen_socket_in,
-                     int accept_pool_size,
-                     bool accept_only,
-                     sockaddr * bound_sockaddr,
-                     int *bound_sockaddr_size,
-                     int recv_bufsize, int send_bufsize, uint32_t sockopt_flags, EventType etype)
-{
-  (void) listen_socket_in;      // NT only
-  (void) accept_pool_size;      // NT only
-  (void) accept_only;           // NT only
-  (void) bound_sockaddr;        // NT only
-  (void) bound_sockaddr_size;   // NT only
+  sockaddr_storage const* accept_addr,
+//                     int port,
+//                     int domain,
+//                     int accept_threads,
+//                     bool frequent_accept,
+//                     unsigned int accept_ip,
+//                     char *accept_ip_str,
+//                     bool callback_on_open,
+//                     int accept_pool_size,
+//                     bool accept_only,
+//                     sockaddr * bound_sockaddr,
+//                     int *bound_sockaddr_size,
+//                     int recv_bufsize, int send_bufsize, uint32_t sockopt_flags, EventType etype
+  AcceptOptions const& opt
+) {
+//  (void) accept_pool_size;      // NT only
+//  (void) accept_only;           // NT only
+//  (void) bound_sockaddr;        // NT only
+//  (void) bound_sockaddr_size;   // NT only
   Debug("iocore_net_processor",
         "NetProcessor::accept - port %d,recv_bufsize %d, send_bufsize %d, sockopt 0x%0lX",
-        port, recv_bufsize, send_bufsize, sockopt_flags);
+    ink_inet_get_port(accept_addr), opt.recv_bufsize, opt.send_bufsize, opt.sockopt_flags);
 
-  AcceptOptions opt;
-
-  opt.port = port;
-  opt.domain = domain;
-  opt.etype = etype;
-  opt.f_callback_on_open = callback_on_open;
-  opt.recv_bufsize = recv_bufsize;
-  opt.send_bufsize = send_bufsize;
-  opt.sockopt_flags = opt.sockopt_flags;
-  opt.accept_threads = accept_threads;
-
-  return ((UnixNetProcessor *) this)->accept_internal(cont, NO_FD,
-                                                      bound_sockaddr,
-                                                      bound_sockaddr_size,
-                                                      frequent_accept,
-                                                      net_accept,
-                                                      accept_ip,
-                                                      accept_ip_str,
+  return static_cast<UnixNetProcessor *>(this)->accept_internal(cont, NO_FD,
+    accept_addr,
+//                                                      bound_sockaddr,
+//                                                      bound_sockaddr_size,
+//                                                      frequent_accept,
+//                                                      net_accept,
+//                                                      accept_ip,
+//                                                      accept_ip_str,
                                                       opt);
 }
 
 Action *
-NetProcessor::main_accept(Continuation * cont, SOCKET fd, sockaddr * bound_sockaddr, int *bound_sockaddr_size,
-                          bool accept_only, bool localhost_only, AcceptOptions const& opt)
-{
-  (void) accept_only;           // NT only
+NetProcessor::main_accept(
+  Continuation * cont,
+  SOCKET fd,
+  uint16_t port,
+//  sockaddr_storage const* bound_sockaddr,
+//  int *bound_sockaddr_size,
+//  bool accept_only,
+//  bool localhost_only,
+  AcceptOptions const& opt
+) {
+  UnixNetProcessor* this_unp = static_cast<UnixNetProcessor*>(this);
+
+  sockaddr_storage addr;
+//  (void) accept_only;           // NT only
   Debug("iocore_net_processor", "NetProcessor::main_accept - port %d,recv_bufsize %d, send_bufsize %d, sockopt 0x%0lX",
-        opt.port, opt.recv_bufsize, opt.send_bufsize, opt.sockopt_flags);
-  if (localhost_only) {
-    static char localhost[] = "127.0.0.1";
-
-    return ((UnixNetProcessor *) this)->accept_internal(cont, fd,
-                                                        bound_sockaddr,
-                                                        bound_sockaddr_size,
-                                                        true,
-                                                        net_accept,
-                                                        inet_addr(localhost),
-                                                        localhost,
-                                                        opt);
+        port, opt.recv_bufsize, opt.send_bufsize, opt.sockopt_flags);
+  if (opt.localhost_only) {
+    ink_inet_ip4_set(&addr, INADDR_LOOPBACK, port);
+
+//    return ((UnixNetProcessor *) this)->accept_internal(
+//      cont, fd, &addr,
+//      bound_sockaddr,
+//      bound_sockaddr_size,
+//      true,
+//      net_accept,
+//      inet_addr(localhost),
+//      localhost,
+//      opt
+//    );
   } else {
-    return ((UnixNetProcessor *) this)->accept_internal(cont, fd,
-                                                        bound_sockaddr,
-                                                        bound_sockaddr_size,
-                                                        true,
-                                                        net_accept,
-                                                        ((UnixNetProcessor *) this)->incoming_ip_to_bind_saddr,
-                                                        ((UnixNetProcessor *) this)->incoming_ip_to_bind,
-                                                        opt);
+    ink_inet_copy(addr, this_unp->incoming_ip_to_bind_saddr);
+    ink_inet_port_cast(addr) = port;
+//    return ((UnixNetProcessor *) this)->accept_internal(
+//      cont, fd,
+//      bound_sockaddr,
+//      bound_sockaddr_size,
+//      true,
+//      net_accept,
+//    ((UnixNetProcessor *) this)->incoming_ip_to_bind_saddr,
+//    ((UnixNetProcessor *) this)->incoming_ip_to_bind,
+//      opt
+//    );
   }
+    return this_unp->accept_internal(cont, fd, &addr, opt);
 }
 
 
 
 Action *
-UnixNetProcessor::accept_internal(Continuation * cont,
-                                  int fd,
-                                  struct sockaddr * bound_sockaddr,
-                                  int *bound_sockaddr_size,
-                                  bool frequent_accept,
-                                  AcceptFunction fn,
-                                  unsigned int accept_ip,
-                                  char *accept_ip_str,
-                                  AcceptOptions const& opt)
-{
+UnixNetProcessor::accept_internal(
+  Continuation * cont,
+  int fd,
+  sockaddr_storage const* accept_addr,
+//                                  sockaddr_storage const* bound_sockaddr,
+//                                  int *bound_sockaddr_size,
+//                                  bool frequent_accept,
+//                                  AcceptFunction fn,
+//                                  unsigned int accept_ip,
+//                                  char *accept_ip_str,
+  AcceptOptions const& opt
+) {
   EventType et = opt.etype; // setEtype requires non-const ref.
   NetAccept *na = createNetAccept();
   EThread *thread = this_ethread();
@@ -162,15 +171,16 @@ UnixNetProcessor::accept_internal(Contin
     IOCORE_ReadConfigInteger(accept_threads, "proxy.config.accept_threads");
 
   NET_INCREMENT_DYN_STAT(net_accepts_currently_open_stat);
-  na->port = opt.port;
-  na->domain = opt.domain;
-  na->accept_fn = fn;
+//  na->port = opt.port;
+//  na->domain = opt.domain;
+  na->accept_fn = net_accept; // All callers used this.
   na->server.fd = fd;
-  na->server.accept_ip = accept_ip;
-  na->server.accept_ip_str = accept_ip_str;
+  ink_inet_copy(&na->server.accept_addr, accept_addr);
+//  na->server.accept_ip = accept_ip;
+//  na->server.accept_ip_str = accept_ip_str;
   na->server.f_outbound_transparent = opt.f_outbound_transparent;
   na->server.f_inbound_transparent = opt.f_inbound_transparent;
-  if (opt.f_outbound_transparent) Debug("http_tproxy", "Marking accept server %x on port %d as outbound transparent.\n", na, opt.port);
+  if (opt.f_outbound_transparent) Debug("http_tproxy", "Marking accept server %x on port %d as outbound transparent.\n", na, ink_inet_get_port(accept_addr));
   na->action_ = NEW(new NetAcceptAction());
   *na->action_ = cont;
   na->action_->server = &na->server;
@@ -181,7 +191,7 @@ UnixNetProcessor::accept_internal(Contin
   na->etype = opt.etype;
   if (na->callback_on_open)
     na->mutex = cont->mutex;
-  if (frequent_accept) { // true
+  if (opt.frequent_accept) {
     if (accept_threads > 0)  {
       if (0 == na->do_listen(BLOCKING)) {
         NetAccept *a;
@@ -190,10 +200,10 @@ UnixNetProcessor::accept_internal(Contin
           a = createNetAccept();
           *a = *na;
           a->init_accept_loop();
-          Debug("iocore_net_accept", "Created accept thread #%d for port %d", i, opt.port);
+          Debug("iocore_net_accept", "Created accept thread #%d for port %d", i, ink_inet_get_port(accept_addr));
         }
         // Start the "template" accept thread last.
-        Debug("iocore_net_accept", "Created accept thread #%d for port %d", accept_threads, opt.port);
+        Debug("iocore_net_accept", "Created accept thread #%d for port %d", accept_threads, ink_inet_get_port(accept_addr));
         na->init_accept_loop();
       }
     } else {
@@ -201,8 +211,8 @@ UnixNetProcessor::accept_internal(Contin
     }
   } else
     na->init_accept();
-  if (bound_sockaddr && bound_sockaddr_size)
-    safe_getsockname(na->server.fd, bound_sockaddr, bound_sockaddr_size);
+//  if (bound_sockaddr && bound_sockaddr_size)
+//    safe_getsockname(na->server.fd, bound_sockaddr, bound_sockaddr_size);
 
 #ifdef TCP_DEFER_ACCEPT
   // set tcp defer accept timeout if it is configured, this will not trigger an accept until there is
@@ -217,9 +227,11 @@ UnixNetProcessor::accept_internal(Contin
 }
 
 Action *
-UnixNetProcessor::connect_re_internal(Continuation * cont,
-                                      unsigned int ip, int port,  NetVCOptions * opt)
-{
+UnixNetProcessor::connect_re_internal(
+  Continuation * cont,
+  sockaddr_storage const* target,
+  NetVCOptions * opt
+) {
   ProxyMutex *mutex = cont->mutex;
   EThread *t = mutex->thread_holding;
   UnixNetVConnection *vc = allocateThread(t);
@@ -240,7 +252,7 @@ UnixNetProcessor::connect_re_internal(Co
                            * we need to connect using socks server even
                            * if this ip is in no_socks list.
                            */
-                          !socks_conf_stuff->ip_range.match(ip))
+                          !socks_conf_stuff->ip_map.contains(target))
 #endif
     );
   SocksEntry *socksEntry = NULL;
@@ -249,24 +261,27 @@ UnixNetProcessor::connect_re_internal(Co
   vc->id = net_next_connection_number();
   vc->submit_time = ink_get_hrtime();
   vc->setSSLClientConnection(true);
-  vc->ip = ip;
-  vc->port = port;
+  ink_inet_copy(&vc->server_addr, target);
+//  vc->ip = ip;
+//  vc->port = port;
   vc->mutex = cont->mutex;
   Action *result = &vc->action_;
 #ifndef INK_NO_SOCKS
   if (using_socks) {
-    Debug("Socks", "Using Socks ip: %u.%u.%u.%u:%d\n", PRINT_IP(ip), port);
+    char buff[INET6_ADDRPORTSTRLEN];
+    Debug("Socks", "Using Socks ip: %s\n", ink_inet_nptop(target, buff, sizeof(buff)));
     socksEntry = socksAllocator.alloc();
     socksEntry->init(cont->mutex, vc, opt->socks_support, opt->socks_version);        /*XXXX remove last two args */
     socksEntry->action_ = cont;
     cont = socksEntry;
-    if (socksEntry->server_ip == (uint32_t) - 1) {
+    if (!ink_inet_is_valid(socksEntry->server_addr)) {
       socksEntry->lerrno = ESOCK_NO_SOCK_SERVER_CONN;
       socksEntry->free();
       return ACTION_RESULT_DONE;
     }
-    vc->ip = socksEntry->server_ip;
-    vc->port = socksEntry->server_port;
+    ink_inet_copy(vc->server_addr, socksEntry->server_addr);
+//    vc->ip = socksEntry->server_ip;
+//    vc->port = socksEntry->server_port;
     result = &socksEntry->action_;
     vc->action_ = socksEntry;
   } else {
@@ -305,10 +320,11 @@ UnixNetProcessor::connect_re_internal(Co
 Action *
 UnixNetProcessor::connect(Continuation * cont,
                           UnixNetVConnection ** avc,
-                          unsigned int ip, int port, NetVCOptions * opt)
+                          sockaddr_storage const* target,
+                          NetVCOptions * opt)
 {
   NOWARN_UNUSED(avc);
-  return connect_re(cont, ip, port, opt);
+  return connect_re(cont, target, opt);
 }
 
 struct CheckConnect:public Continuation
@@ -386,13 +402,13 @@ struct CheckConnect:public Continuation
     return EVENT_DONE;
   }
 
-  Action *connect_s(Continuation * cont, unsigned int ip, int port,
+  Action *connect_s(Continuation * cont, sockaddr_storage const* target,
                     int _timeout, NetVCOptions * opt)
   {
     action_ = cont;
     timeout = HRTIME_MSECONDS(_timeout);
     recursion++;
-    netProcessor.connect_re(this, ip, port, opt);
+    netProcessor.connect_re(this, target, opt);
     recursion--;
     if (connect_status != NET_EVENT_OPEN_FAILED)
       return &action_;
@@ -416,12 +432,12 @@ struct CheckConnect:public Continuation
 };
 
 Action *
-NetProcessor::connect_s(Continuation * cont, unsigned int ip,
-                        int port, int timeout, NetVCOptions * opt)
+NetProcessor::connect_s(Continuation * cont, sockaddr_storage const* target,
+                        int timeout, NetVCOptions * opt)
 {
   Debug("iocore_net_connect", "NetProcessor::connect_s called");
   CheckConnect *c = NEW(new CheckConnect(cont->mutex));
-  return c->connect_s(cont, ip, port, timeout, opt);
+  return c->connect_s(cont, target, timeout, opt);
 }
 
 
@@ -446,10 +462,11 @@ UnixNetProcessor::start(int)
     initialize_thread_for_net(netthreads[i], i);
   }
 
-  if ((incoming_ip_to_bind = IOCORE_ConfigReadString("proxy.local.incoming_ip_to_bind")) != 0)
-    incoming_ip_to_bind_saddr = inet_addr(incoming_ip_to_bind);
-  else
-    incoming_ip_to_bind_saddr = 0;
+  if (
+    0 == (incoming_ip_to_bind = IOCORE_ConfigReadString("proxy.local.incoming_ip_to_bind"))
+    || 0 != ink_inet_pton(incoming_ip_to_bind, &incoming_ip_to_bind_saddr)
+  )
+    ink_inet_invalidate(incoming_ip_to_bind_saddr);
 
   RecData d;
   d.rec_int = 0;

Modified: trafficserver/traffic/branches/ssc/iocore/net/UnixNetVConnection.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/ssc/iocore/net/UnixNetVConnection.cc?rev=1126862&r1=1126861&r2=1126862&view=diff
==============================================================================
--- trafficserver/traffic/branches/ssc/iocore/net/UnixNetVConnection.cc (original)
+++ trafficserver/traffic/branches/ssc/iocore/net/UnixNetVConnection.cc Tue May 24 04:11:36 2011
@@ -761,10 +761,11 @@ UnixNetVConnection::UnixNetVConnection()
     next_inactivity_timeout_at(0),
 #endif
     active_timeout(NULL), nh(NULL),
-    id(0), ip(0), accept_port(0), port(0), flags(0), recursion(0), submit_time(0), oob_ptr(0),
+    id(0), accept_port(0), flags(0), recursion(0), submit_time(0), oob_ptr(0),
     from_accept_thread(false)
 {
-  memset(&local_sa, 0, sizeof local_sa);
+  memset(&local_addr, 0, sizeof local_addr);
+  memset(&server_addr, 0, sizeof server_addr);
   SET_HANDLER((NetVConnHandler) & UnixNetVConnection::startEvent);
 }
 
@@ -1059,7 +1060,7 @@ UnixNetVConnection::connectUp(EThread *t
       free(t);
       return CONNECT_FAILURE;
     }
-    res = con.connect(ip, port, options);
+    res = con.connect(&server_addr, options);
   }
 
   if (res) {

Modified: trafficserver/traffic/branches/ssc/iocore/net/UnixUDPNet.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/ssc/iocore/net/UnixUDPNet.cc?rev=1126862&r1=1126861&r2=1126862&view=diff
==============================================================================
--- trafficserver/traffic/branches/ssc/iocore/net/UnixUDPNet.cc (original)
+++ trafficserver/traffic/branches/ssc/iocore/net/UnixUDPNet.cc Tue May 24 04:11:36 2011
@@ -66,7 +66,7 @@ void *G_bulkIOState = NULL;
 InkPipeInfo G_inkPipeInfo;
 
 int G_bwGrapherFd;
-struct sockaddr_in G_bwGrapherLoc;
+sockaddr_storage G_bwGrapherLoc;
 
 void
 initialize_thread_for_udp_net(EThread * thread)
@@ -132,14 +132,14 @@ UDPNetProcessorInternal::udp_read_from_n
   int r;
   int iters = 0;
   do {
-    struct sockaddr_in fromaddr;
+    sockaddr_storage fromaddr;
     socklen_t fromlen = sizeof(fromaddr);
     // XXX: want to be 0 copy.
     // XXX: really should read into next contiguous region of an IOBufferData
     // which gets referenced by IOBufferBlock.
     char buf[65536];
     int buflen = sizeof(buf);
-    r = socketManager.recvfrom(uc->getFd(), buf, buflen, 0, (struct sockaddr *) &fromaddr, &fromlen);
+    r = socketManager.recvfrom(uc->getFd(), buf, buflen, 0, (sockaddr_storage *) &fromaddr, &fromlen);
     if (r <= 0) {
       // error
       break;
@@ -201,7 +201,7 @@ public:
   inline void free(void);
   inline void init_token(Event * completionToken);
 
-  inline void init_read(int fd, IOBufferBlock * buf, int len, struct sockaddr *fromaddr, socklen_t *fromaddrlen);     // start up polling
+  inline void init_read(int fd, IOBufferBlock * buf, int len, sockaddr_storage *fromaddr, socklen_t *fromaddrlen);     // start up polling
   void set_timer(int seconds)
   {
     timeout_interval = HRTIME_SECONDS(seconds);
@@ -219,7 +219,7 @@ private:
   // on behalf of the client
   Ptr<IOBufferBlock> readbuf;
   int readlen;
-  struct sockaddr *fromaddr;
+  sockaddr_storage *fromaddr;
   socklen_t *fromaddrlen;
   int fd;                       // fd we are reading from
   int ifd;                      // poll fd index
@@ -276,7 +276,7 @@ UDPReadContinuation::init_token(Event * 
 }
 
 inline void
-UDPReadContinuation::init_read(int rfd, IOBufferBlock * buf, int len, struct sockaddr *fromaddr_, socklen_t *fromaddrlen_)
+UDPReadContinuation::init_read(int rfd, IOBufferBlock * buf, int len, sockaddr_storage *fromaddr_, socklen_t *fromaddrlen_)
 {
   ink_assert(rfd >= 0 && buf != NULL && fromaddr_ != NULL && fromaddrlen_ != NULL);
   fd = rfd;
@@ -416,7 +416,7 @@ Action *
 UDPNetProcessor::recvfrom_re(Continuation * cont,
                              void *token,
                              int fd,
-                             struct sockaddr * fromaddr, socklen_t *fromaddrlen,
+                             sockaddr_storage * fromaddr, socklen_t *fromaddrlen,
                              IOBufferBlock * buf, int len, bool useReadCont, int timeout)
 {
   (void) useReadCont;
@@ -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, sockaddr_storage * toaddr, int toaddrlen, IOBufferBlock * buf, int len)
 {
   (void) token;
   ink_assert(buf->read_avail() >= len);
@@ -514,43 +514,46 @@ 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,
+//  unsigned int myIP, unsigned int destIP,
+  sockaddr_storage const* local_addr,
+  sockaddr_storage 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_storage const* remote_addr,
+  sockaddr_storage* local_addr,
+  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);
+  int local_addr_len = sizeof(*local_addr);
+
+  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->ss_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, sizeof(*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 +565,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 +596,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 +612,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 +629,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_storage 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;
+  sockaddr_storage myaddr;
   int myaddr_len = sizeof(myaddr);
 
-  if ((res = socketManager.socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+  if ((res = socketManager.socket(addr->ss_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_get_ip4_addr(addr) & 0xf0000000) == 0xe0000000) {
     int enable_reuseaddr = 1;
 
     if ((res = safe_setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &enable_reuseaddr, sizeof(enable_reuseaddr)) < 0)) {
@@ -652,11 +652,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, sizeof(*addr))) < 0) {
     goto Lerror;
   }
 
@@ -668,10 +664,10 @@ 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, &myaddr_len)) < 0) {
     goto Lerror;
   }
-  if (!myaddr.sin_addr.s_addr) {
+  if (!ink_inet_get_ip4_addr(&myaddr)) {
     // set to default IP address for machine
     /** netfixme this_machine is in proxy/
     if (this_machine()) {
@@ -1261,14 +1257,19 @@ 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_storage const* local_addr,
+  sockaddr_storage const* remote_addr,
+//  unsigned int my_ip, unsigned int dest_ip,
+  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);
+//  myIP = my_ip;
+//  destIP = dest_ip;
   sendbufsize = s_bufsize;
   recvbufsize = r_bufsize;
   udpConns = NULL;
@@ -1283,8 +1284,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;
+  sockaddr_storage target;
+  sockaddr_storage myaddr1, myaddr2;
   int portNum, i;
 //  int myaddr_len = sizeof(myaddr1);
   static int lastAllocPort = 10000;
@@ -1304,6 +1305,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,8 +1318,10 @@ 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)) {
+    ink_inet_port_cast(target) = htons(portNum);
+    if (udpNet.CreateUDPSocket(&fd1, &target, &myaddr1, &status, sendbufsize, recvbufsize)) {
+      ink_inet_port_cast(target) = htons(portNum + 1);
+      if (udpNet.CreateUDPSocket(&fd2, &target, &myaddr2, &status, sendbufsize, recvbufsize)) {
         udpConns[i] = NEW(new UnixUDPConnection(fd1));        // new_UnixUDPConnection(fd1);
         udpConns[i]->setBinding(&myaddr1);
         i++;
@@ -1351,7 +1355,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/branches/ssc/iocore/utils/Makefile.am
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/ssc/iocore/utils/Makefile.am?rev=1126862&r1=1126861&r2=1126862&view=diff
==============================================================================
--- trafficserver/traffic/branches/ssc/iocore/utils/Makefile.am (original)
+++ trafficserver/traffic/branches/ssc/iocore/utils/Makefile.am Tue May 24 04:11:36 2011
@@ -17,7 +17,7 @@
 #  limitations under the License.
 
 AM_CPPFLAGS = \
-  -I$(top_srcdir)/lib/records \
+  -I$(top_srcdir)/lib \
   -I$(top_srcdir)/iocore/eventsystem
 
 DEFS += @IOCORE_MODULARIZED_DEFS@

Modified: trafficserver/traffic/branches/ssc/lib/records/RecCompatibility.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/ssc/lib/records/RecCompatibility.cc?rev=1126862&r1=1126861&r2=1126862&view=diff
==============================================================================
--- trafficserver/traffic/branches/ssc/lib/records/RecCompatibility.cc (original)
+++ trafficserver/traffic/branches/ssc/lib/records/RecCompatibility.cc Tue May 24 04:11:36 2011
@@ -161,8 +161,8 @@ RecPipeCreate(const char *base_path, con
 
   RecHandle listenfd;
   RecHandle acceptfd;
-  struct sockaddr_un servaddr;
-  struct sockaddr_un cliaddr;
+  sockaddr_storage_un servaddr;
+  sockaddr_storage_un cliaddr;
   int servaddr_len;
   socklen_t cliaddr_len;
 
@@ -207,7 +207,7 @@ RecPipeCreate(const char *base_path, con
   }
 
   servaddr_len = sizeof(servaddr.sun_family) + strlen(servaddr.sun_path);
-  if ((bind(listenfd, (struct sockaddr *) &servaddr, servaddr_len)) < 0) {
+  if ((bind(listenfd, (sockaddr_storage *) &servaddr, servaddr_len)) < 0) {
     RecLog(DL_Warning, "[RecPipeCreate] bind error\n");
     return REC_HANDLE_INVALID;
   }
@@ -218,7 +218,7 @@ RecPipeCreate(const char *base_path, con
   }
   // block until we get a connection from the other side
   cliaddr_len = sizeof(cliaddr);
-  if ((acceptfd = accept(listenfd, (struct sockaddr *) &cliaddr,
+  if ((acceptfd = accept(listenfd, (sockaddr_storage *) &cliaddr,
                          &cliaddr_len)) < 0) {
     return REC_HANDLE_INVALID;
   }
@@ -237,7 +237,7 @@ RecPipeConnect(const char *base_path, co
 {
 
   RecHandle sockfd;
-  struct sockaddr_un servaddr;
+  sockaddr_storage_un servaddr;
   int servaddr_len;
 
   // construct a path/filename for the pipe
@@ -265,7 +265,7 @@ RecPipeConnect(const char *base_path, co
     return REC_HANDLE_INVALID;
   }
   // blocking connect
-  if ((connect(sockfd, (struct sockaddr *) &servaddr, servaddr_len)) < 0) {
+  if ((connect(sockfd, (sockaddr_storage *) &servaddr, servaddr_len)) < 0) {
     RecLog(DL_Warning, "[RecPipeConnect] connect error\n");
     return REC_HANDLE_INVALID;
   }



Mime
View raw message