trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zw...@apache.org
Subject svn commit: r955421 - in /trafficserver/traffic/trunk: iocore/cluster/ iocore/net/ proxy/ proxy/http2/ proxy/mgmt2/cluster/
Date Wed, 16 Jun 2010 23:00:41 GMT
Author: zwoop
Date: Wed Jun 16 23:00:40 2010
New Revision: 955421

URL: http://svn.apache.org/viewvc?rev=955421&view=rev
Log:
TS-320: Do some cleanup on Connection::fast_connect and Connection::bind_connect

Tested: FC-13 64-bit
Author: Alan M. Carroll
Review and comments: John Plevyak

Modified:
    trafficserver/traffic/trunk/iocore/cluster/ClusterHandlerBase.cc
    trafficserver/traffic/trunk/iocore/net/Connection.cc
    trafficserver/traffic/trunk/iocore/net/I_NetProcessor.h
    trafficserver/traffic/trunk/iocore/net/I_NetVConnection.h
    trafficserver/traffic/trunk/iocore/net/P_Connection.h
    trafficserver/traffic/trunk/iocore/net/P_UnixNetProcessor.h
    trafficserver/traffic/trunk/iocore/net/P_UnixNetVConnection.h
    trafficserver/traffic/trunk/iocore/net/Socks.cc
    trafficserver/traffic/trunk/iocore/net/UnixConnection.cc
    trafficserver/traffic/trunk/iocore/net/UnixNetPages.cc
    trafficserver/traffic/trunk/iocore/net/UnixNetProcessor.cc
    trafficserver/traffic/trunk/iocore/net/UnixNetVConnection.cc
    trafficserver/traffic/trunk/proxy/ICP.cc
    trafficserver/traffic/trunk/proxy/SocksProxy.cc
    trafficserver/traffic/trunk/proxy/http2/HttpSM.cc
    trafficserver/traffic/trunk/proxy/mgmt2/cluster/ClusterCom.cc

Modified: trafficserver/traffic/trunk/iocore/cluster/ClusterHandlerBase.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/cluster/ClusterHandlerBase.cc?rev=955421&r1=955420&r2=955421&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/cluster/ClusterHandlerBase.cc (original)
+++ trafficserver/traffic/trunk/iocore/cluster/ClusterHandlerBase.cc Wed Jun 16 23:00:40 2010
@@ -852,10 +852,14 @@ ClusterHandler::connectClusterEvent(int 
     opt.socket_recv_bufsize = cluster_receive_buffer_size;
     opt.sockopt_flags = cluster_sockopt_flags;
     opt.etype = ET_CLUSTER;
+    opt.addr_binding = NetVCOptions::INTF_ADDR;
+    opt.local_addr = this_cluster_machine()->ip;
 
     Action *act = netProcessor.connect_re(this, machine->ip,
-                                          machine->cluster_port ? machine->cluster_port : cluster_port,
-                                          this_cluster_machine()->ip, &opt);
+                                          machine->cluster_port
+					      ? machine->cluster_port
+					      : cluster_port,
+					  &opt);
 
     NOWARN_UNUSED(act);
 

Modified: trafficserver/traffic/trunk/iocore/net/Connection.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/net/Connection.cc?rev=955421&r1=955420&r2=955421&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/net/Connection.cc (original)
+++ trafficserver/traffic/trunk/iocore/net/Connection.cc Wed Jun 16 23:00:40 2010
@@ -56,10 +56,20 @@ get_listen_backlog(void)
 //
 // Functions
 //
+char const*
+NetVCOptions::toString(addr_bind_style s) {
+  return ANY_ADDR == s ? "any"
+    : INTF_ADDR == s ? "interface"
+    : "foreign"
+    ;
+}
+
 Connection::Connection()
+  : fd(NO_FD)
+  , is_bound(false)
+  , is_connected(false)
 {
   memset(&sa, 0, sizeof(struct sockaddr_storage));
-  fd = NO_FD;
 }
 
 
@@ -105,6 +115,8 @@ Lerror:
 int
 Connection::close()
 {
+  is_connected = false;
+  is_bound = false;
   // don't close any of the standards
   if (fd >= 2) {
     int fd_save = fd;
@@ -116,178 +128,6 @@ Connection::close()
   }
 }
 
-
-int
-Connection::fast_connect(const unsigned int ip, const int port, NetVCOptions * opt, const int sock)
-{
-  uint32 *z;
-  int res = 0;
-
-  if (sock < 0) {
-    ink_assert(fd == NO_FD);
-    if ((res = socketManager.socket(AF_INET, SOCK_STREAM, 0)) < 0)
-      goto Lerror;
-  } else
-    res = sock;
-
-  fd = res;
-
-  sa.ss_family = AF_INET;
-  ((struct sockaddr_in *)(&sa))->sin_port = htons(port);
-  ((struct sockaddr_in *)(&sa))->sin_addr.s_addr = ip;
-  z = (uint32 *)(&(((struct sockaddr_in *)(&sa))->sin_zero));
-  z[0] = 0;
-  z[1] = 0;
-
-  do {
-    res = safe_nonblocking(fd);
-  } while (res < 0 && (errno == EAGAIN || errno == EINTR));
-
-  // cannot do this after connection on non-blocking connect
-#ifdef SET_TCP_NO_DELAY
-  NetDebug("socket", "setting TCP_NODELAY in fast_connect");
-  if ((res = safe_setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, ON, sizeof(int))) < 0)
-    goto Lerror;
-#endif
-#ifdef RECV_BUF_SIZE
-  socketManager.set_rcvbuf_size(fd, RECV_BUF_SIZE);
-#endif
-#ifdef SET_SO_KEEPALIVE
-  // enables 2 hour inactivity probes, also may fix IRIX FIN_WAIT_2 leak
-  if ((res = safe_setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, ON, sizeof(int))) < 0)
-    goto Lerror;
-#endif
-
-  if (opt) {
-    if (opt->socket_recv_bufsize > 0) {
-      if (socketManager.set_rcvbuf_size(fd, opt->socket_recv_bufsize)) {
-        int rbufsz = ROUNDUP(opt->socket_recv_bufsize, 1024);   // Round down until success
-        while (rbufsz) {
-          if (!socketManager.set_rcvbuf_size(fd, rbufsz))
-            break;
-          rbufsz -= 1024;
-        }
-      }
-    }
-    if (opt->socket_send_bufsize > 0) {
-      if (socketManager.set_sndbuf_size(fd, opt->socket_send_bufsize)) {
-        int sbufsz = ROUNDUP(opt->socket_send_bufsize, 1024);   // Round down until success
-        while (sbufsz) {
-          if (!socketManager.set_sndbuf_size(fd, sbufsz))
-            break;
-          sbufsz -= 1024;
-        }
-      }
-    }
-    if (opt->sockopt_flags & 1) {
-      safe_setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, ON, sizeof(int));
-      NetDebug("socket", "::fast_connect: setsockopt() TCP_NODELAY on socket");
-    }
-    if (opt->sockopt_flags & 2) {
-      safe_setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, ON, sizeof(int));
-      NetDebug("socket", "::fast_connect: setsockopt() SO_KEEPALIVE on socket");
-    }
-  }
-  res = ::connect(fd, (struct sockaddr *) &sa, sizeof(struct sockaddr_in));
-
-  if (res < 0 && errno != EINPROGRESS)
-    goto Lerror;
-
-  return 0;
-
-Lerror:
-  if (fd != NO_FD)
-    close();
-  return res;
-}
-
-
-int
-Connection::connect(unsigned int ip, int port,
-                    bool non_blocking_connect, bool use_tcp, bool non_blocking, bool bind_random_port)
-{
-  ink_assert(fd == NO_FD);
-  int res = 0;
-  ink_hrtime t;
-  short Proto;
-
-  if (use_tcp) {
-    Proto = IPPROTO_TCP;
-    if ((res = socketManager.socket(AF_INET, SOCK_STREAM, 0)) < 0)
-      goto Lerror;
-  } else {
-    Proto = IPPROTO_UDP;
-    if ((res = socketManager.socket(AF_INET, SOCK_DGRAM, 0)) < 0)
-      goto Lerror;
-  }
-
-  fd = res;
-
-  if (bind_random_port) {
-    int retries = 0;
-    int offset = 0;
-    while (retries++ < 10000) {
-      struct sockaddr_storage bind_sa;
-      memset(&sa, 0, sizeof(bind_sa));
-      bind_sa.ss_family = AF_INET;
-      ((struct sockaddr_in *)(&bind_sa))->sin_addr.s_addr = INADDR_ANY;
-      int p = time(NULL) + offset;
-      p = (p % (LAST_RANDOM_PORT - FIRST_RANDOM_PORT)) + FIRST_RANDOM_PORT;
-      ((struct sockaddr_in *)(&bind_sa))->sin_port = htons(p);
-      NetDebug("dns", "random port = %d\n", p);
-      if ((res = socketManager.ink_bind(fd, (struct sockaddr *) &bind_sa, sizeof(bind_sa), Proto)) < 0) {
-        offset += 101;
-        continue;
-      }
-      goto Lok;
-    }
-    Warning("unable to bind random DNS port");
-  Lok:;
-  }
-
-  sa.ss_family = AF_INET;
-  ((struct sockaddr_in *)(&sa))->sin_port = htons(port);
-  ((struct sockaddr_in *)(&sa))->sin_addr.s_addr = ip;
-  memset(&(((struct sockaddr_in *)(&sa))->sin_zero), 0, 8);
-
-  if (non_blocking_connect)
-    if ((res = safe_nonblocking(fd)) < 0)
-      goto Lerror;
-
-  // cannot do this after connection on non-blocking connect
-#ifdef SET_TCP_NO_DELAY
-  if (use_tcp)
-    if ((res = safe_setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, ON, sizeof(int))) < 0)
-      goto Lerror;
-#endif
-#ifdef RECV_BUF_SIZE
-  socketManager.set_rcvbuf_size(fd, RECV_BUF_SIZE);
-#endif
-#ifdef SET_SO_KEEPALIVE
-  // enables 2 hour inactivity probes, also may fix IRIX FIN_WAIT_2 leak
-  if ((res = safe_setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, ON, sizeof(int))) < 0)
-    goto Lerror;
-#endif
-
-  t = ink_get_hrtime();
-  res =::connect(fd, (struct sockaddr *) &sa, sizeof(struct sockaddr_in));
-
-  if (!res || ((res < 0) && (errno == EINPROGRESS || errno == EWOULDBLOCK))) {
-    if (!non_blocking_connect && non_blocking)
-      if ((res = safe_nonblocking(fd)) < 0)
-        goto Lerror;
-  } else
-    goto Lerror;
-
-  return 0;
-
-Lerror:
-  if (fd != NO_FD)
-    close();
-  return res;
-}
-
-
 int
 Server::setup_fd_for_listen(bool non_blocking, int recv_bufsize, int send_bufsize)
 {

Modified: trafficserver/traffic/trunk/iocore/net/I_NetProcessor.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/net/I_NetProcessor.h?rev=955421&r1=955420&r2=955421&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/net/I_NetProcessor.h (original)
+++ trafficserver/traffic/trunk/iocore/net/I_NetProcessor.h Wed Jun 16 23:00:40 2010
@@ -157,13 +157,12 @@ public:
     @param cont Continuation to be called back with events.
     @param ip machine to connect to.
     @param port port to connect to.
-    @param _interface network interface to use for connect.
     @param options @see NetVCOptions.
 
   */
 
   inkcoreapi Action *connect_re(Continuation * cont,
-                                unsigned int ip, int port, unsigned int _interface = 0, NetVCOptions * options = NULL);
+                                unsigned int ip, int port, NetVCOptions * options = NULL);
 
   /**
     Open a NetVConnection for connection oriented I/O. This call
@@ -177,7 +176,6 @@ public:
     @param cont Continuation to be called back with events.
     @param ip machine to connect to.
     @param port port to connect to.
-    @param _interface local interaface to bind to for the new connection.
     @param timeout for connect, the cont will get NET_EVENT_OPEN_FAILED
       if connection could not be established for timeout msecs. The
       default is 30 secs.
@@ -189,7 +187,7 @@ public:
   Action *connect_s(Continuation * cont,
                     unsigned int ip,
                     int port,
-                    unsigned int _interface = 0, int timeout = NET_CONNECT_TIMEOUT, NetVCOptions * opts = NULL);
+                    int timeout = NET_CONNECT_TIMEOUT, NetVCOptions * opts = NULL);
 
   /**
     Starts the Netprocessor. This has to be called before doing any

Modified: trafficserver/traffic/trunk/iocore/net/I_NetVConnection.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/net/I_NetVConnection.h?rev=955421&r1=955420&r2=955421&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/net/I_NetVConnection.h (original)
+++ trafficserver/traffic/trunk/iocore/net/I_NetVConnection.h Wed Jun 16 23:00:40 2010
@@ -49,68 +49,107 @@ enum NetDataType
   NET_DATA_ATTRIBUTES = VCONNECTION_NET_DATA_BASE
 };
 
-/**
-  Holds user options for NetVConnection. This class holds various
-  options a user can specify for NetVConnection. Right now this
-  passed when we invoke NetProcessor::connect_re().
-
-  Currently defined fields:
-
-  <table>
-    <tr><td><b>Field</b></td><td><b>Description</b></td></tr>
-    <tr>
-      <td><i>local_port</i></td>
-      <td>Specifies local port to bind to before connecting</td>
-    </tr>
-    <tr>
-      <td><i>spoof_ip</i></td>
-      <td>IP address to spoof instead of our local address If
-        <i>spoof_src_ip</i> is set, <i>spoof_src_port</i> should be
-        set as well. Spcified in network byte order</td>
-    </tr>
-    <tr>
-      <td><i>spoof_port</i></td>
-      <td>Same as <i>spoof_src_ip</i>. Specified in host byte order</td>
-    </tr>
-    <tr>
-      <td><i>socks_version</i></td>
-      <td>Set explicit version for Socks</td>
-    </tr>
-    <tr>
-      <td><i>socks_support</i></td>
-      <td>Explicitly set to NO_SOCKS to disable SOCKS for the
-        connection. Default is to use SOCKS if configiration enables
-        SOCKS.</td>
-    </tr>
-  </table>
+/** Holds client options for NetVConnection.
 
-  User only needs to set only the option she is interested in--the
-  rest get sensible default values.
+    This class holds various options a user can specify for
+    NetVConnection. Various clients need many slightly different
+    features. This is an attempt to prevent out of control growth of
+    the connection method signatures.
 
+    Only options of interest need to be explicitly set --
+    the rest get sensible default values.
 */
 struct NetVCOptions {
-  int local_port;
+  typedef NetVCOptions self; ///< Self reference type.
 
-  uint32 spoof_ip;
-  int spoof_port;
+  /// Values for valid IP protocols.
+  enum ip_protocol_t {
+    USE_TCP, ///< TCP protocol.
+    USE_UDP, ///< UDP protocol.
+  };
+
+  /// IP protocol to use on socket.
+  ip_protocol_t ip_proto;
+
+  /** The set of ways in which the local address should be bound.
+
+      @note The difference between @c INTF_ADDR and @c FOREIGN_ADDR is
+      whether transparency is enabled on the socket. It is the
+      client's responsibility to set this correct based on whether the
+      address in @a local_addr is associated with an interface on the
+      local system, or is owned by a foreign system.  A binding style
+      of @c ANY_ADDR causes the value in @a local_addr to be ignored.
 
+      @see local_addr
+   */
+  enum addr_bind_style {
+    ANY_ADDR, ///< Bind to any available local address (don't care, default).
+    INTF_ADDR, ///< Bind to the interface address in @a local_addr.
+    FOREIGN_ADDR, ///< Bind to foreign address in @a local_addr.
+  };
+
+  /// The set of ways in which the local port should be bound.
+  enum port_bind_style {
+    ANY_PORT, ///< Bind to any available local port (dont' care, default).
+    FIXED_PORT, ///< Bind to the port in @a local_port.
+  };
+
+  /// Port to use for local side of connection.
+  /// @note Ignored if @a port_binding is @c ANY_PORT.
+  /// @see port_binding
+  uint16 local_port;
+  /// How to bind local port.
+  /// @note Default is @c ANY_PORT.
+  port_bind_style port_binding;
+  /// Address to use for local side of connection.
+  /// @note Ignored if @a addr_binding is @c ANY_ADDR.
+  /// @see addr_binding
+  uint32 local_addr;
+  /// How to bind the local address.
+  /// @note Default is @c ANY_ADDR.
+  addr_bind_style addr_binding;
+
+  /// Make the socket blocking on I/O (default: @c false)
+  bool f_blocking;
+  /// Make socket block on connect (default: @c false)
+  bool f_blocking_connect;
+
+  /// Control use of SOCKS.
+  /// Set to @c NO_SOCKS to disable use of SOCKS. Otherwise SOCKS is
+  /// used if available.
   unsigned char socks_support;
+  /// Version of SOCKS to use.
   unsigned char socks_version;
 
   int socket_recv_bufsize;
   int socket_send_bufsize;
+
+  /// Configuration options for sockets.
+  /// @note These are not identical to internal socket options but
+  /// specifically defined for configuration. These are mask values
+  /// and so must be powers of 2.
   unsigned long sockopt_flags;
+  /// Value for TCP no delay for @c sockopt_flags.
+  static unsigned long const SOCK_OPT_NO_DELAY = 1;
+  /// Value for keep alive for @c sockopt_flags.
+  static unsigned long const SOCK_OPT_KEEP_ALIVE = 2;
 
   EventType etype;
 
+  /// Reset all values to defaults.
   void reset();
-  void set_sock_param(int _recv_bufsize, int _send_bufsize, unsigned long _opt_flags);
 
+  void set_sock_param(int _recv_bufsize, int _send_bufsize, unsigned long _opt_flags);
 
   NetVCOptions() {
     reset();
   }
-  /* Add more options here instead of adding them to connect_re() args etc */
+
+  /// @name Debugging
+  //@{
+  /// Convert @a s to its string equivalent.
+  static char const* toString(addr_bind_style s);
+  //@}
 };
 
 /**

Modified: trafficserver/traffic/trunk/iocore/net/P_Connection.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/net/P_Connection.h?rev=955421&r1=955420&r2=955421&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/net/P_Connection.h (original)
+++ trafficserver/traffic/trunk/iocore/net/P_Connection.h Wed Jun 16 23:00:40 2010
@@ -80,22 +80,56 @@ struct NetVCOptions;
 ///////////////////////////////////////////////////////////////////////
 struct Connection
 {
-  SOCKET fd;
-  struct sockaddr_storage sa;
-
-  int connect(unsigned int ip, int port,
-              bool non_blocking_connect = NON_BLOCKING_CONNECT,
-              bool use_tcp = CONNECT_WITH_TCP, bool non_blocking = NON_BLOCKING, bool bind_random_port = BIND_ANY_PORT);
-
-  int fast_connect(const unsigned int ip, const int port, NetVCOptions * opt = NULL, const int sock = -1);
-
-  int bind_connect(unsigned int target_ip, int target_port,
-                   unsigned int my_ip,
-                   NetVCOptions * opt = NULL, int sock = -1,
-                   bool non_blocking_connect = NON_BLOCKING_CONNECT,
-                   bool use_tcp = CONNECT_WITH_TCP,
-                   bool non_blocking = NON_BLOCKING, bool bc_no_connect = BC_CONNECT, bool bc_no_bind = BC_BIND);
-
+  SOCKET fd; ///< Socket for connection.
+  struct sockaddr_storage sa; ///< Remote address.
+  bool is_bound; ///< Flag for already bound to a local address.
+  bool is_connected; ///< Flag for already connected.
+
+  /** Create and initialize the socket for this connection.
+
+      A socket is created and the options specified by @a opt are
+      set. The socket is @b not connected.
+
+      @note It is important to pass the same @a opt to this method and
+      @c connect.
+
+      @return 0 on success, -ERRNO on failure.
+      @see connect
+  */
+  int open(
+	   NetVCOptions const& opt = DEFAULT_OPTIONS ///< Socket options.
+	   );
+
+  /** Connect the socket.
+
+      The socket is connected to the remote @a addr and @a port. The
+      @a opt structure is used to control blocking on the socket. All
+      other options are set via @c open. It is important to pass the
+      same @a opt to this method as was passed to @c open.
+
+      @return 0 on success, -ERRNO on failure.
+      @see open
+  */
+  int connect(
+	   uint32 addr, ///< Remote address.
+	   uint16 port, ///< Remote port.
+	   NetVCOptions const& opt = DEFAULT_OPTIONS ///< Socket options
+	   );
+
+
+  /// Set the internal socket address struct.
+  /// @internal Used only by ICP.
+  void setRemote(
+		 uint32 addr, ///< Remote IP address.
+		 uint16 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);
+  }
+    
   int setup_mc_send(unsigned int mc_ip, int mc_port,
                     unsigned int my_ip, int my_port,
                     bool non_blocking = NON_BLOCKING,
@@ -108,6 +142,12 @@ struct Connection
 
   virtual ~ Connection();
   Connection();
+
+  /// Default options.
+  static NetVCOptions const DEFAULT_OPTIONS;
+
+protected:
+  void _cleanup();
 };
 
 ///////////////////////////////////////////////////////////////////////

Modified: trafficserver/traffic/trunk/iocore/net/P_UnixNetProcessor.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/net/P_UnixNetProcessor.h?rev=955421&r1=955420&r2=955421&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/net/P_UnixNetProcessor.h (original)
+++ trafficserver/traffic/trunk/iocore/net/P_UnixNetProcessor.h Wed Jun 16 23:00:40 2010
@@ -54,11 +54,11 @@ public:
 
 
   Action *connect_re_internal(Continuation * cont,
-                              unsigned int ip, int port, unsigned int _interface = 0, NetVCOptions * options = NULL);
+                              unsigned int ip, int port, NetVCOptions * options = NULL);
 
   Action *connect(Continuation * cont,
                   UnixNetVConnection ** vc,
-                  unsigned int ip, int port, unsigned int _interface, NetVCOptions * opt = NULL);
+                  unsigned int ip, int port, NetVCOptions * opt = NULL);
 
   // Virtual function allows etype
   // to be set to ET_SSL for SSLNetProcessor.  Does
@@ -96,9 +96,9 @@ public:
 
 
 TS_INLINE Action *
-NetProcessor::connect_re(Continuation * cont, unsigned int ip, int port, unsigned int _interface, NetVCOptions * opts)
+NetProcessor::connect_re(Continuation * cont, unsigned int ip, int port, NetVCOptions * opts)
 {
-  return ((UnixNetProcessor *) this)->connect_re_internal(cont, ip, port, _interface, opts);
+  return static_cast<UnixNetProcessor *>(this)->connect_re_internal(cont, ip, port, opts);
 }
 
 

Modified: trafficserver/traffic/trunk/iocore/net/P_UnixNetVConnection.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/net/P_UnixNetVConnection.h?rev=955421&r1=955420&r2=955421&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/net/P_UnixNetVConnection.h (original)
+++ trafficserver/traffic/trunk/iocore/net/P_UnixNetVConnection.h Wed Jun 16 23:00:40 2010
@@ -44,13 +44,21 @@ class PollDescriptor;
 TS_INLINE void
 NetVCOptions::reset()
 {
+  ip_proto = USE_TCP;
   local_port = 0;
-  spoof_ip = 0;
-  spoof_port = 0;
+  port_binding = ANY_PORT;
+  local_addr = 0;
+  addr_binding = ANY_ADDR;
+  f_blocking = false;
+  f_blocking_connect = true;
   socks_support = NORMAL_SOCKS;
   socks_version = SOCKS_DEFAULT_VERSION;
-  //_interface = 0;
-  socket_recv_bufsize = 0;
+  socket_recv_bufsize = 
+#if defined(RECV_BUF_SIZE)
+    RECV_BUF_SIZE;
+#else
+    0;
+#endif
   socket_send_bufsize = 0;
   sockopt_flags = 0;
   etype = ET_NET;
@@ -205,7 +213,7 @@ public:
   NetHandler *nh;
   unsigned int id;
   unsigned int ip;
-  unsigned int _interface; // 'interface' conflicts with the C++ keyword
+  //  unsigned int _interface; // 'interface' conflicts with the C++ keyword
   int accept_port;
   int port;
 

Modified: trafficserver/traffic/trunk/iocore/net/Socks.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/net/Socks.cc?rev=955421&r1=955420&r2=955421&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/net/Socks.cc (original)
+++ trafficserver/traffic/trunk/iocore/net/Socks.cc Wed Jun 16 23:00:40 2010
@@ -213,7 +213,7 @@ SocksEntry::startEvent(int event, void *
 
     NetVCOptions options;
     options.socks_support = NO_SOCKS;
-    netProcessor.connect_re(this, server_ip, server_port, 0, &options);
+    netProcessor.connect_re(this, server_ip, server_port, &options);
   }
 
   return EVENT_CONT;

Modified: trafficserver/traffic/trunk/iocore/net/UnixConnection.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/net/UnixConnection.cc?rev=955421&r1=955420&r2=955421&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/net/UnixConnection.cc (original)
+++ trafficserver/traffic/trunk/iocore/net/UnixConnection.cc Wed Jun 16 23:00:40 2010
@@ -28,7 +28,6 @@
 #include "ink_unused.h"       /* MAGIC_EDITING_TAG */
 #include "P_Net.h"
 
-#define SET_TCP_NO_DELAY
 #define SET_NO_LINGER
 // set in the OS
 // #define RECV_BUF_SIZE            (1024*64)
@@ -38,6 +37,10 @@
 
 #define ROUNDUP(x, y) ((((x)+((y)-1))/(y))*(y))
 
+#if !defined(IP_TRANSPARENT)
+unsigned int const IP_TRANSPARENT = 19;
+#endif
+
 //
 // Functions
 //
@@ -154,122 +157,187 @@ Lerror:
   return res;
 }
 
+namespace {
+  /** Struct to make cleaning up resources easier.
+
+      By default, the @a method is invoked on the @a object when
+      this object is destructed. This can be prevented by calling
+      the @c reset method.
+
+      This is not overly useful in the allocate, check, return case
+      but very handy if there are
+      - multiple resources (each can have its own cleaner)
+      - multiple checks against the resource
+      In such cases, rather than trying to track all the resources
+      that might need cleaned up, you can set up a cleaner at allocation
+      and only have to deal with them on success, which is generally
+      singular.
+
+      @code
+      self::some_method (...) {
+        /// allocate resource
+        cleaner<self> clean_up(this, &self::cleanup);
+	// modify or check the resource
+        if (fail) return FAILURE; // cleanup() is called
+        /// success!
+        clean_up.reset(); // cleanup() not called after this
+        return SUCCESS;
+      @endcode
+   */
+  template <typename T> struct cleaner {
+    T* obj; ///< Object instance.
+    typedef void (T::*method)(); ///< Method signature.
+    method m;
+
+    cleaner(T* _obj, method  _method) : obj(_obj), m(_method) {}
+    ~cleaner() { if (obj) (obj->*m)(); }
+    void reset() { obj = 0; }
+  };
+}
+
+/** Default options.
+
+    @internal This structure is used to reduce the number of places in
+    which the defaults are set. Originally the argument defaulted to
+    @c NULL which meant that the defaults had to be encoded in any
+    methods that used it as well as the @c NetVCOptions
+    constructor. Now they are controlled only in the latter and not in
+    any of the methods. This makes handling global default values
+    (such as @c RECV_BUF_SIZE) more robust. It doesn't have to be
+    checked in the method, only in the @c NetVCOptions constructor.
+
+    The methods are simpler because they never have to check for the
+    presence of the options, yet the clients aren't inconvenienced
+    because a default value for the argument is provided. Further,
+    clients can pass temporaries and not have to declare a variable in
+    order to tweak options.
+ */
+NetVCOptions const Connection::DEFAULT_OPTIONS;
 
 int
-Connection::bind_connect(unsigned int target_ip, int target_port, unsigned int my_ip,
-                         NetVCOptions *opt, int sock, bool non_blocking_connect, bool use_tcp,
-                         bool non_blocking, bool bc_no_connect, bool bc_no_bind)
+Connection::open(NetVCOptions const& opt)
 {
   ink_assert(fd == NO_FD);
-  int res = 0;
-  ink_hrtime t;
-  int enable_reuseaddr = 1;
-  int my_port = (opt) ? opt->local_port : 0;
-
-  if (!bc_no_bind) {
-    if (sock < 0) {
-      if (use_tcp) {
-        if ((res = socketManager.socket(AF_INET, SOCK_STREAM, 0)) < 0)
-          goto Lerror;
-      } else {
-        if ((res = socketManager.socket(AF_INET, SOCK_DGRAM, 0)) < 0)
-          goto Lerror;
-      }
-    } else
-      res = sock;
+  int enable_reuseaddr = 1; // used for sockopt setting
+  int res = 0; // temp result
+  uint32 local_addr = NetVCOptions::ANY_ADDR == opt.addr_binding
+    ? INADDR_ANY
+    : opt.local_addr;
+  uint16 local_port = NetVCOptions::ANY_PORT == opt.port_binding
+    ? 0
+    : opt.local_port;
+  int sock_type = NetVCOptions::USE_UDP == opt.ip_proto
+    ? SOCK_DGRAM
+    : SOCK_STREAM;
 
-    fd = res;
+  res = socketManager.socket(AF_INET, sock_type, 0);
+  if (-1 == res) return -errno;
 
-    if ((res = safe_setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &enable_reuseaddr, sizeof(enable_reuseaddr)) < 0))
-      goto Lerror;
+  fd = res;
+  // mark fd for close until we succeed.
+  cleaner<Connection> cleanup(this, &Connection::_cleanup);
 
-    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))) < 0)
-      goto Lerror;
+  // Try setting the various socket options, if requested.
 
-    NetDebug("arm_spoofing", "Passed in options opt=%x client_ip=%x and client_port=%d",
-          opt, opt ? opt->spoof_ip : 0, opt ? opt->spoof_port : 0);
+  if (-1 == safe_setsockopt(fd,
+			    SOL_SOCKET,
+			    SO_REUSEADDR,
+			    reinterpret_cast<char *>(&enable_reuseaddr),
+			    sizeof(enable_reuseaddr)))
+    return -errno;
+
+  if (!opt.f_blocking_connect && -1 == safe_nonblocking(fd))
+    return -errno;
+
+  if (opt.socket_recv_bufsize > 0) {
+    if (socketManager.set_rcvbuf_size(fd, opt.socket_recv_bufsize)) {
+      // Round down until success
+      int rbufsz = ROUNDUP(opt.socket_recv_bufsize, 1024);
+      while (rbufsz && !socketManager.set_rcvbuf_size(fd, rbufsz))
+	rbufsz -= 1024;
+      NetDebug("socket", "::open: recv_bufsize = %d of %d\n", rbufsz, opt.socket_recv_bufsize);
+    }
   }
-
-  sa.ss_family = AF_INET;
-  ((struct sockaddr_in *)(&sa))->sin_port = htons(target_port);
-  ((struct sockaddr_in *)(&sa))->sin_addr.s_addr = target_ip;
-  memset(&(((struct sockaddr_in *)(&sa))->sin_zero), 0, 8);
-
-  if (bc_no_bind)               // no socket
-    return 0;
-
-  if (non_blocking_connect)
-    if ((res = safe_nonblocking(fd)) < 0)
-      goto Lerror;
-
-  // cannot do this after connection on non-blocking connect
-#ifdef SET_TCP_NO_DELAY
-  if (use_tcp)
-    if ((res = safe_setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, ON, sizeof(int))) < 0)
-      goto Lerror;
-#endif
-#ifdef RECV_BUF_SIZE
-  socketManager.set_rcvbuf_size(fd, RECV_BUF_SIZE);
-#endif
-#ifdef SET_SO_KEEPALIVE
-  // enables 2 hour inactivity probes, also may fix IRIX FIN_WAIT_2 leak
-  if ((res = safe_setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, ON, sizeof(int))) < 0)
-    goto Lerror;
-#endif
-
-  if (opt) {
-    if (opt->socket_recv_bufsize > 0) {
-      if (socketManager.set_rcvbuf_size(fd, opt->socket_recv_bufsize)) {
-        int rbufsz = ROUNDUP(opt->socket_recv_bufsize, 1024);   // Round down until success
-        while (rbufsz) {
-          if (!socketManager.set_rcvbuf_size(fd, rbufsz))
-            break;
-          rbufsz -= 1024;
-        }
-      }
+  if (opt.socket_send_bufsize > 0) {
+    if (socketManager.set_sndbuf_size(fd, opt.socket_send_bufsize)) {
+      // Round down until success
+      int sbufsz = ROUNDUP(opt.socket_send_bufsize, 1024);
+      while (sbufsz && !socketManager.set_sndbuf_size(fd, sbufsz))
+	sbufsz -= 1024;
+      NetDebug("socket", "::open: send_bufsize = %d of %d\n", sbufsz, opt.socket_send_bufsize);
     }
-    if (opt->socket_send_bufsize > 0) {
-      if (socketManager.set_sndbuf_size(fd, opt->socket_send_bufsize)) {
-        int sbufsz = ROUNDUP(opt->socket_send_bufsize, 1024);   // Round down until success
-        while (sbufsz) {
-          if (!socketManager.set_sndbuf_size(fd, sbufsz))
-            break;
-          sbufsz -= 1024;
-        }
-      }
+  }
+
+  if (SOCK_STREAM == sock_type) {
+    if (opt.sockopt_flags & NetVCOptions::SOCK_OPT_NO_DELAY) {
+      safe_setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, ON, sizeof(int));
+      NetDebug("socket", "::open: setsockopt() TCP_NODELAY on socket");
     }
-    if (use_tcp) {
-      if (opt->sockopt_flags & 1) {
-        safe_setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, ON, sizeof(int));
-        NetDebug("socket", "::bind_connect: setsockopt() TCP_NODELAY on socket");
-      }
-      if (opt->sockopt_flags & 2) {
-        safe_setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, ON, sizeof(int));
-        NetDebug("socket", "::bind_connect: setsockopt() SO_KEEPALIVE on socket");
-      }
+    if (opt.sockopt_flags & NetVCOptions::SOCK_OPT_KEEP_ALIVE) {
+      safe_setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, ON, sizeof(int));
+      NetDebug("socket", "::open: setsockopt() SO_KEEPALIVE on socket");
     }
   }
 
-  if (!bc_no_connect) {
-    t = ink_get_hrtime();
-    res =::connect(fd, (struct sockaddr *) &sa, sizeof(struct sockaddr_in));
-    if (!res || ((res < 0) && errno == EINPROGRESS)) {
-      if (!non_blocking_connect && non_blocking)
-        if ((res = safe_nonblocking(fd)) < 0)
-          goto Lerror;
-    } else
-      goto Lerror;
+  if (NetVCOptions::FOREIGN_ADDR == opt.addr_binding && local_addr) {
+    int value = 1;
+    res = safe_setsockopt(fd, SOL_SOCKET, IP_TRANSPARENT, reinterpret_cast<char*>(&value), sizeof(value));
+    if (-1 == res) return -errno;
   }
 
+  // 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)))
+    return -errno;
+
+  cleanup.reset();
+  is_bound = true;
   return 0;
+}
 
-Lerror:
-  if (fd != NO_FD)
-    close();
-  return res;
+int
+Connection::connect(uint32 addr, uint16 port, NetVCOptions const& opt) {
+  ink_assert(fd != NO_FD);
+  ink_assert(is_bound);
+  ink_assert(!is_connected);
+
+  int res;
+
+  this->setRemote(addr, port);
+
+  cleaner<Connection> cleanup(this, &Connection::_cleanup); // mark for close until we succeed.
+
+  res = ::connect(fd,
+		  reinterpret_cast<struct sockaddr *>(&sa),
+		  sizeof(struct sockaddr_in));
+  // 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?)
+  // We also want to handle the cases where the connect blocking
+  // and IO blocking differ, by turning it on or off as needed.
+  if (-1 == res 
+      && (opt.f_blocking_connect
+	  || ! (EINPROGRESS == errno || EWOULDBLOCK == errno))) {
+    return -errno;
+  } else if (opt.f_blocking_connect && !opt.f_blocking) {
+    if (-1 == safe_nonblocking(fd)) return -errno;
+  } else if (!opt.f_blocking_connect && opt.f_blocking) {
+    if (-1 == safe_blocking(fd)) return -errno;
+  }
+
+  cleanup.reset();
+  is_connected = true;
+  return 0;
+}
+
+void
+Connection::_cleanup()
+{
+  this->close();
 }

Modified: trafficserver/traffic/trunk/iocore/net/UnixNetPages.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/net/UnixNetPages.cc?rev=955421&r1=955420&r2=955421&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/net/UnixNetPages.cc (original)
+++ trafficserver/traffic/trunk/iocore/net/UnixNetPages.cc Wed Jun 16 23:00:40 2010
@@ -70,7 +70,7 @@ struct ShowNet:ShowCont
       char ipbuf[80];
       snprintf(ipbuf, sizeof(ipbuf), "%u.%u.%u.%u", PRINT_IP(vc->ip));
       char interbuf[80];
-      snprintf(interbuf, sizeof(interbuf), "%u.%u.%u.%u", PRINT_IP(vc->_interface));
+      snprintf(interbuf, sizeof(interbuf), "[%s] %u.%u.%u.%u", vc->options.toString(vc->options.addr_binding), PRINT_IP(vc->options.local_addr));
       CHECK_SHOW(show("<tr>"
                       // "<td><a href=\"/connection/%d\">%d</a></td>"
                       "<td>%d</td>" "<td>%s</td>"       // ipbuf

Modified: trafficserver/traffic/trunk/iocore/net/UnixNetProcessor.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/net/UnixNetProcessor.cc?rev=955421&r1=955420&r2=955421&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/net/UnixNetProcessor.cc (original)
+++ trafficserver/traffic/trunk/iocore/net/UnixNetProcessor.cc Wed Jun 16 23:00:40 2010
@@ -160,7 +160,7 @@ UnixNetProcessor::accept_internal(Contin
 
 Action *
 UnixNetProcessor::connect_re_internal(Continuation * cont,
-                                      unsigned int ip, int port, unsigned int _interface, NetVCOptions * opt)
+                                      unsigned int ip, int port,  NetVCOptions * opt)
 {
 
   ProxyMutex *mutex = cont->mutex;
@@ -171,7 +171,6 @@ UnixNetProcessor::connect_re_internal(Co
   else
     opt = &vc->options;
 
-  vc->_interface = _interface;
   // virtual function used to set etype to ET_SSL
   // for SSLNetProcessor.  Does nothing if not overwritten.
   setEtype(opt->etype);
@@ -249,9 +248,9 @@ UnixNetProcessor::connect_re_internal(Co
 Action *
 UnixNetProcessor::connect(Continuation * cont,
                           UnixNetVConnection ** avc,
-                          unsigned int ip, int port, unsigned int _interface, NetVCOptions * opt)
+                          unsigned int ip, int port, NetVCOptions * opt)
 {
-  return connect_re(cont, ip, port, _interface, opt);
+  return connect_re(cont, ip, port, opt);
 }
 
 struct CheckConnect:public Continuation
@@ -330,12 +329,12 @@ struct CheckConnect:public Continuation
   }
 
   Action *connect_s(Continuation * cont, unsigned int ip, int port,
-                    unsigned int _interface, int _timeout, NetVCOptions * opt)
+                    int _timeout, NetVCOptions * opt)
   {
     action_ = cont;
     timeout = HRTIME_MSECONDS(_timeout);
     recursion++;
-    netProcessor.connect_re(this, ip, port, _interface, opt);
+    netProcessor.connect_re(this, ip, port, opt);
     recursion--;
     if (connect_status != NET_EVENT_OPEN_FAILED)
       return &action_;
@@ -360,11 +359,11 @@ struct CheckConnect:public Continuation
 
 Action *
 NetProcessor::connect_s(Continuation * cont, unsigned int ip,
-                        int port, unsigned int _interface, int timeout, NetVCOptions * opt)
+                        int port, int timeout, NetVCOptions * opt)
 {
   NetDebug("iocore_net_connect", "NetProcessor::connect_s called");
   CheckConnect *c = NEW(new CheckConnect(cont->mutex));
-  return c->connect_s(cont, ip, port, _interface, timeout, opt);
+  return c->connect_s(cont, ip, port, timeout, opt);
 }
 
 

Modified: trafficserver/traffic/trunk/iocore/net/UnixNetVConnection.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/net/UnixNetVConnection.cc?rev=955421&r1=955420&r2=955421&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/net/UnixNetVConnection.cc (original)
+++ trafficserver/traffic/trunk/iocore/net/UnixNetVConnection.cc Wed Jun 16 23:00:40 2010
@@ -788,7 +788,7 @@ closed(0), inactivity_timeout_in(0), act
   next_inactivity_timeout_at(0),
 #endif
   active_timeout(NULL), nh(NULL),
-  id(0), ip(0), _interface(0), accept_port(0), port(0), flags(0), recursion(0), submit_time(0), oob_ptr(0)
+  id(0), ip(0), accept_port(0), port(0), flags(0), recursion(0), submit_time(0), oob_ptr(0)
 {
   memset(&local_sa, 0, sizeof local_sa);
   SET_HANDLER((NetVConnHandler) & UnixNetVConnection::startEvent);
@@ -1070,37 +1070,28 @@ UnixNetVConnection::connectUp(EThread *t
   // Initialize this UnixNetVConnection
   //
   int res = 0;
-  NetDebug("arm_spoofing", "connectUp:: interface=%x and options.spoofip=%x\n", _interface, options.spoof_ip);
+  NetDebug("iocore_net", "connectUp:: local_addr=%u.%u.%u.%u [%s]\n",
+	   PRINT_IP(options.local_addr),
+	   NetVCOptions::toString(options.addr_binding)
+	   );
+
+
   nh = get_NetHandler(t);
-#ifndef USE_EDGE_TRIGGER
-  if (_interface || options.local_port || options.spoof_ip)
-    res = con.bind_connect(ip, port, _interface, &options);
-  else
-    res = con.fast_connect(ip, port, &options);
-#else
-  int sock = -1;
-  if ((sock = socketManager.socket(AF_INET, SOCK_STREAM, 0)) < 0)
-    goto Lfailure;
-  con.fd = sock;
-#endif
-  if (ep.start(get_PollDescriptor(t), this, EVENTIO_READ|EVENTIO_WRITE) < 0) {
-    lerrno = errno;
-    NetDebug("iocore_net", "connectUp : Failed to add to epoll list\n");
-    action_.continuation->handleEvent(NET_EVENT_OPEN_FAILED, (void *) res);
-    free(t);
-    return CONNECT_FAILURE;
+  res = con.open(options);
+  if (0 == res) {
+    // Must connect after EventIO::Start() to avoid a race condition
+    // when edge triggering is used.
+    if (ep.start(get_PollDescriptor(t), this, EVENTIO_READ|EVENTIO_WRITE) < 0) {
+      lerrno = errno;
+      NetDebug("iocore_net", "connectUp : Failed to add to epoll list\n");
+      action_.continuation->handleEvent(NET_EVENT_OPEN_FAILED, (void *) res);
+      free(t);
+      return CONNECT_FAILURE;
+    }
+    res = con.connect(ip, port, options);
   }
-#ifdef USE_EDGE_TRIGGER
-  // must be called after EventIO::start() to avoid race with edge triggering
-  if (_interface || options.local_port || options.spoof_ip)
-    res = con.bind_connect(ip, port, _interface, &options, sock);
-  else
-    res = con.fast_connect(ip, port, &options, sock);
-#endif
+
   if (res) {
-#ifdef USE_EDGE_TRIGGER
-  Lfailure:
-#endif
     lerrno = errno;
     action_.continuation->handleEvent(NET_EVENT_OPEN_FAILED, (void *)(intptr_t)res);
     free(t);
@@ -1116,18 +1107,6 @@ UnixNetVConnection::connectUp(EThread *t
   // function code not to be duplicated in the inherited SSL class.
   //  sslStartHandShake (SSL_EVENT_CLIENT, err);
 
-  if (_interface || options.local_port || options.spoof_ip) {
-    nh = get_NetHandler(t);
-    PollDescriptor *pd = get_PollDescriptor(t);
-    if (ep.start(pd, this, EVENTIO_READ|EVENTIO_WRITE) < 0) {
-      NetDebug("iocore_net", "connectUp : Failed to add to epoll list\n");
-      lerrno = errno;
-      action_.continuation->handleEvent(NET_EVENT_OPEN_FAILED, (void *)(intptr_t)res);
-      free(t);
-      return CONNECT_FAILURE;
-    }
-  }
-
   nh->open_list.enqueue(this);
 
   ink_assert(!inactivity_timeout_in);

Modified: trafficserver/traffic/trunk/proxy/ICP.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/ICP.cc?rev=955421&r1=955420&r2=955421&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/ICP.cc (original)
+++ trafficserver/traffic/trunk/proxy/ICP.cc Wed Jun 16 23:00:40 2010
@@ -730,24 +730,10 @@ ICPPeerReadCont::PeerReadStateMachine(Pe
             status = _ICPpr->AddPeerToSendList(P);
             ink_assert(status);
 
-            NetVCOptions options;
-            options.local_port = P->GetPort();
-            status = P->GetChan()->bind_connect(P->GetIP()->s_addr,
-                                                P->GetPort(),
-                                                P->GetIP()->s_addr,
-                                                &options,
-                                                NON_BLOCKING_CONNECT,
-                                                CONNECT_WITH_UDP, NON_BLOCKING, BC_NO_CONNECT, BC_NO_BIND);
-            _ICPpr->GetConfig()->Unlock();
+	    P->GetChan()->setRemote(P->GetIP()->s_addr, P->GetPort());
 
-            unsigned char x[4];
-            *(uint32 *) & x = (uint32) P->GetIP()->s_addr;
-            if (status) {
-              Warning("ICP bind_connect(2) failed, res=%d, ip=%d.%d.%d.%d", status, x[0], x[1], x[2], x[3]);
-              REC_SignalWarning(REC_SIGNAL_CONFIG_ERROR, "ICP bind_connect(2) failed");
-            }
             // coverity[uninit_use_in_call]
-            Note("ICP Peer added ip=%d.%d.%d.%d port=%d", x[0], x[1], x[2], x[3], P->GetPort());
+            Note("ICP Peer added ip=%u.%u.%u.%u port=%d", PRINT_IP(P->GetIP()->s_addr), P->GetPort());
             from = s->_peer->fromaddr;
           } else {
           invalid_message:
@@ -2212,21 +2198,7 @@ ICPProcessor::SetupListenSockets()
           || (P->GetType() == PEER_SIBLING)) {
         ParentSiblingPeer *pPS = (ParentSiblingPeer *) P;
 
-        NetVCOptions options;
-        options.local_port = pPS->GetPort();
-        status = pPS->GetChan()->bind_connect(pPS->GetIP()->s_addr,
-                                              pPS->GetPort(),
-                                              pPS->GetIP()->s_addr,
-                                              &options,
-                                              NON_BLOCKING_CONNECT,
-                                              CONNECT_WITH_UDP, NON_BLOCKING, BC_NO_CONNECT, BC_NO_BIND);
-        if (status) {
-          unsigned char x[4];
-          *(uint32 *) & x = (uint32) pPS->GetIP()->s_addr;
-          Warning("ICP bind_connect failed, res=%d, ip=%d.%d.%d.%d", status, x[0], x[1], x[2], x[3]);
-          REC_SignalWarning(REC_SIGNAL_CONFIG_ERROR, "ICP bind_connect failed");
-          return 1;             // Failed
-        }
+	pPS->GetChan()->setRemote(pPS->GetIP()->s_addr, pPS->GetPort());
 
       } else if (P->GetType() == PEER_MULTICAST) {
         MultiCastPeer *pMC = (MultiCastPeer *) P;
@@ -2271,22 +2243,7 @@ ICPProcessor::SetupListenSockets()
   //
   ParentSiblingPeer *pPS = (ParentSiblingPeer *) ((Peer *) _LocalPeer);
 
-  NetVCOptions options;
-  options.local_port = pPS->GetPort();
-
-  status = pPS->GetChan()->bind_connect(pPS->GetIP()->s_addr,
-                                        pPS->GetPort(),
-                                        pPS->GetIP()->s_addr,
-                                        &options,
-                                        NON_BLOCKING_CONNECT, CONNECT_WITH_UDP, NON_BLOCKING, BC_NO_CONNECT, BC_BIND);
-  if (status) {
-    unsigned char x[4];
-    *(uint32 *) & x = (uint32) pPS->GetIP()->s_addr;
-    // coverity[uninit_use_in_call]
-    Warning("ICP bind_connect failed, res=%d, ip=%d.%d.%d.%d", status, x[0], x[1], x[2], x[3]);
-    REC_SignalWarning(REC_SIGNAL_CONFIG_ERROR, "ICP bind_connect for localhost failed");
-    return 1;                   // Failed
-  }
+  pPS->GetChan()->setRemote(pPS->GetIP()->s_addr, pPS->GetPort());
   return 0;                     // Success
 }
 

Modified: trafficserver/traffic/trunk/proxy/SocksProxy.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/SocksProxy.cc?rev=955421&r1=955420&r2=955421&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/SocksProxy.cc (original)
+++ trafficserver/traffic/trunk/proxy/SocksProxy.cc Wed Jun 16 23:00:40 2010
@@ -321,8 +321,7 @@ SocksProxy::mainEvent(int event, void *d
             vc_options.socks_support = p[1];
             vc_options.socks_version = version;
 
-            Action *action = netProcessor.connect_re(this, ip, port, 0,
-                                                     &vc_options);
+            Action *action = netProcessor.connect_re(this, ip, port, &vc_options);
             if (action != ACTION_RESULT_DONE) {
               ink_assert(pending_action == NULL);
               pending_action = action;

Modified: trafficserver/traffic/trunk/proxy/http2/HttpSM.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http2/HttpSM.cc?rev=955421&r1=955420&r2=955421&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http2/HttpSM.cc (original)
+++ trafficserver/traffic/trunk/proxy/http2/HttpSM.cc Wed Jun 16 23:00:40 2010
@@ -4270,12 +4270,15 @@ HttpSM::do_http_server_open(bool raw)
   opt.set_sock_param(t_state.http_config_param->sock_recv_buffer_size_out,
                      t_state.http_config_param->sock_send_buffer_size_out,
                      t_state.http_config_param->sock_option_flag_out);
+  // TBD: Check for transparency here and set opt accordingly.
+  if (t_state.http_config_param->outgoing_ip_to_bind_saddr) {
+    opt.addr_binding = NetVCOptions::INTF_ADDR;
+    opt.local_addr = t_state.http_config_param->outgoing_ip_to_bind_saddr;
+  }
+
 
   Debug("http", "[%lld] open connection to %s: %u.%u.%u.%u",
-        sm_id, t_state.current.server->name,
-        ((unsigned char *) &t_state.current.server->ip)[0],
-        ((unsigned char *) &t_state.current.server->ip)[1],
-        ((unsigned char *) &t_state.current.server->ip)[2], ((unsigned char *) &t_state.current.server->ip)[3]);
+        sm_id, t_state.current.server->name, PRINT_IP(t_state.current.server->ip));
 
   if (plugin_tunnel) {
     PluginVCCore *t = plugin_tunnel;
@@ -4423,14 +4426,14 @@ HttpSM::do_http_server_open(bool raw)
     connect_action_handle = sslNetProcessor.connect_re(this,    // state machine
                                                        srv_ip,  // host_op
                                                        srv_port,        // host_port
-                                                       t_state.http_config_param->outgoing_ip_to_bind_saddr, &opt);
+                                                       &opt);
   } else {
     if (t_state.method != HTTP_WKSIDX_CONNECT) {
       Debug("http", "calling netProcessor.connect_re");
       connect_action_handle = netProcessor.connect_re(this,     // state machine
                                                       srv_ip,   // host_op
                                                       srv_port, // host_port
-                                                      t_state.http_config_param->outgoing_ip_to_bind_saddr, &opt);
+                                                      &opt);
     } else {
       // Setup the timeouts
       // Set the inactivity timeout to the connect timeout so that we
@@ -4453,7 +4456,6 @@ HttpSM::do_http_server_open(bool raw)
       connect_action_handle = netProcessor.connect_s(this,      // state machine
                                                      srv_ip,    // host_op
                                                      srv_port,  // host_port
-                                                     t_state.http_config_param->outgoing_ip_to_bind_saddr,
                                                      connect_timeout, &opt);
     }
   }
@@ -4465,7 +4467,6 @@ HttpSM::do_http_server_open(bool raw)
     connect_action_handle = netProcessor.connect_re(this,       // state machine
                                                     srv_ip,     // host_op
                                                     srv_port,   // host_port
-                                                    t_state.http_config_param->outgoing_ip_to_bind_saddr, &opt);
   } else {
     // Setup the timeouts
     // Set the inactivity timeout to the connect timeout so that we

Modified: trafficserver/traffic/trunk/proxy/mgmt2/cluster/ClusterCom.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt2/cluster/ClusterCom.cc?rev=955421&r1=955420&r2=955421&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt2/cluster/ClusterCom.cc (original)
+++ trafficserver/traffic/trunk/proxy/mgmt2/cluster/ClusterCom.cc Wed Jun 16 23:00:40 2010
@@ -1668,7 +1668,7 @@ ClusterCom::establishChannels()
   serv_addr.sin_port = htons(reliable_server_port);
 
   if ((bind(reliable_server_fd, (struct sockaddr *) &serv_addr, sizeof(serv_addr))) < 0) {
-    mgmt_fatal("[ClusterCom::establishChannels] Unable to bind socket\n");
+    mgmt_fatal("[ClusterCom::establishChannels] Unable to bind socket (port:%d)\n", reliable_server_port);
   }
 
   if ((listen(reliable_server_fd, 10)) < 0) {



Mime
View raw message