]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Revert rev.13253 - fuba
authorAmos Jeffries <squid3@treenet.co.nz>
Sun, 19 Jan 2014 05:39:55 +0000 (21:39 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 19 Jan 2014 05:39:55 +0000 (21:39 -0800)
src/comm.cc
src/comm.h
src/comm/ConnOpener.cc
src/ftp.cc

index c5dba5ae3723ed8cc8854db48db5be3b0ec3ad48..9f19f1dbb4d5e8ad12a59517b27dd611b517ed78 100644 (file)
@@ -426,28 +426,22 @@ comm_open(int sock_type,
           int flags,
           const char *note)
 {
-    // XXX: temporary for the transition to Comm::Pointer
-    Comm::ConnectionPointer conn = new Comm::Connection();
-    const int sock = comm_openex(sock_type, proto, conn, flags, 0, 0, note);
-    conn->fd = -1; // prevent Comm::Connection closing the FD on destruct
-    return sock;
+    return comm_openex(sock_type, proto, addr, flags, 0, 0, note);
 }
 
 void
 comm_open_listener(int sock_type,
                    int proto,
-                   const Comm::ConnectionPointer &conn,
+                   Comm::ConnectionPointer &conn,
                    const char *note)
 {
     /* all listener sockets require bind() */
     conn->flags |= COMM_DOBIND;
 
     /* attempt native enabled port. */
-    conn->fd = comm_openex(sock_type, proto, conn, conn->flags, 0, 0, note);
-    // XXX: remove the flags parameter to comm_openex()
+    conn->fd = comm_openex(sock_type, proto, conn->local, conn->flags, 0, 0, note);
 }
 
-// XXX: remove this wrapper
 int
 comm_open_listener(int sock_type,
                    int proto,
@@ -455,13 +449,14 @@ comm_open_listener(int sock_type,
                    int flags,
                    const char *note)
 {
+    int sock = -1;
+
     /* all listener sockets require bind() */
     flags |= COMM_DOBIND;
 
-    // XXX: temporary for the transition to Comm::Pointer
-    Comm::ConnectionPointer conn = new Comm::Connection();
-    const int sock = comm_openex(sock_type, proto, conn, flags, 0, 0, note);
-    conn->fd = -1; // prevent Comm::Connection closing the FD on destruct
+    /* attempt native enabled port. */
+    sock = comm_openex(sock_type, proto, addr, flags, 0, 0, note);
+
     return sock;
 }
 
@@ -533,12 +528,13 @@ comm_set_transparent(int fd)
 int
 comm_openex(int sock_type,
             int proto,
-            const Comm::ConnectionPointer &conn,
+            Ip::Address &addr,
             int flags,
             tos_t tos,
             nfmark_t nfmark,
             const char *note)
 {
+    int new_socket;
     struct addrinfo *AI = NULL;
 
     PROF_start(comm_open);
@@ -546,28 +542,29 @@ comm_openex(int sock_type,
     ++ statCounter.syscalls.sock.sockets;
 
     /* Setup the socket addrinfo details for use */
-    conn->local.getAddrInfo(AI);
+    addr.getAddrInfo(AI);
     AI->ai_socktype = sock_type;
     AI->ai_protocol = proto;
 
-    debugs(50, 3, "Attempt open " << note << " socket for: " << conn);
+    debugs(50, 3, "comm_openex: Attempt open socket for: " << addr );
 
-    conn->fd = socket(AI->ai_family, AI->ai_socktype, AI->ai_protocol);
+    new_socket = socket(AI->ai_family, AI->ai_socktype, AI->ai_protocol);
 
     /* under IPv6 there is the possibility IPv6 is present but disabled. */
     /* try again as IPv4-native if possible */
-    if (conn->fd < 0 && Ip::EnableIpv6 && conn->local.isIPv6() && conn->local.setIPv4()) {
+    if ( new_socket < 0 && Ip::EnableIpv6 && addr.isIPv6() && addr.setIPv4() ) {
         /* attempt to open this IPv4-only. */
         Ip::Address::FreeAddrInfo(AI);
         /* Setup the socket addrinfo details for use */
-        conn->local.getAddrInfo(AI);
+        addr.getAddrInfo(AI);
         AI->ai_socktype = sock_type;
         AI->ai_protocol = proto;
-        debugs(50, 3, "Attempt fallback open " << note << " socket for: " << conn);
-        conn->fd = socket(AI->ai_family, AI->ai_socktype, AI->ai_protocol);
+        debugs(50, 3, "comm_openex: Attempt fallback open socket for: " << addr );
+        new_socket = socket(AI->ai_family, AI->ai_socktype, AI->ai_protocol);
+        debugs(50, 2, HERE << "attempt open " << note << " socket on: " << addr);
     }
 
-    if (conn->fd < 0) {
+    if (new_socket < 0) {
         /* Increase the number of reserved fd's if calls to socket()
          * are failing because the open file table is full.  This
          * limits the number of simultaneous clients */
@@ -585,7 +582,12 @@ comm_openex(int sock_type,
         return -1;
     }
 
-    debugs(50, 3, "Opened socket " << conn << " : family=" << AI->ai_family << ", type=" << AI->ai_socktype << ", protocol=" << AI->ai_protocol);
+    // XXX: temporary for the transition. comm_openex will eventually have a conn to play with.
+    Comm::ConnectionPointer conn = new Comm::Connection;
+    conn->local = addr;
+    conn->fd = new_socket;
+
+    debugs(50, 3, "comm_openex: Opened socket " << conn << " : family=" << AI->ai_family << ", type=" << AI->ai_socktype << ", protocol=" << AI->ai_protocol );
 
     /* set TOS if needed */
     if (tos)
@@ -595,26 +597,24 @@ comm_openex(int sock_type,
     if (nfmark)
         Ip::Qos::setSockNfmark(conn, nfmark);
 
-    if (Ip::EnableIpv6&IPV6_SPECIAL_SPLITSTACK && conn->local.isIPv6())
+    if ( Ip::EnableIpv6&IPV6_SPECIAL_SPLITSTACK && addr.isIPv6() )
         comm_set_v6only(conn->fd, 1);
 
     /* Windows Vista supports Dual-Sockets. BUT defaults them to V6ONLY. Turn it OFF. */
     /* Other OS may have this administratively disabled for general use. Same deal. */
-    if (Ip::EnableIpv6&IPV6_SPECIAL_V4MAPPING && conn->local.isIPv6())
+    if ( Ip::EnableIpv6&IPV6_SPECIAL_V4MAPPING && addr.isIPv6() )
         comm_set_v6only(conn->fd, 0);
 
     comm_init_opened(conn, tos, nfmark, note, AI);
-    conn->fd = comm_apply_flags(conn->fd, conn->local, flags, AI);
-
-    // XXX: does AI contain the new local port number ??
-    conn->local = *AI;
-    debugs(50, 3, "New Socket details: " << conn);
+    new_socket = comm_apply_flags(conn->fd, addr, flags, AI);
 
     Ip::Address::FreeAddrInfo(AI);
 
     PROF_stop(comm_open);
 
-    return conn->fd;
+    // XXX transition only. prevent conn from closing the new FD on function exit.
+    conn->fd = -1;
+    return new_socket;
 }
 
 /// update FD tables after a local or remote (IPC) comm_openex();
index 0658df5edeb6a694effe15789948a028e28c679f..8c5b04ea91af5a30721dccb39d55cacaddf4c2f5 100644 (file)
@@ -49,9 +49,9 @@ void comm_import_opened(const Comm::ConnectionPointer &, const char *note, struc
  * A reconfigure is needed to reset the stored IP in most cases and attempt a port re-open.
  */
 int comm_open_listener(int sock_type, int proto, Ip::Address &addr, int flags, const char *note);
-void comm_open_listener(int sock_type, int proto, const Comm::ConnectionPointer &conn, const char *note);
+void comm_open_listener(int sock_type, int proto, Comm::ConnectionPointer &conn, const char *note);
 
-int comm_openex(int, int, const Comm::ConnectionPointer &, int, tos_t tos, nfmark_t nfmark, const char *);
+int comm_openex(int, int, Ip::Address &, int, tos_t tos, nfmark_t nfmark, const char *);
 unsigned short comm_local_port(int fd);
 
 int comm_udp_sendto(int sock, const Ip::Address &to, const void *buf, int buflen);
index c115875e756e98501849ba8a96a118921ef439a1..c2913dbc55496aa456ffb59b16028f157f00921c 100644 (file)
@@ -255,7 +255,7 @@ Comm::ConnOpener::createFd()
     if (callback_ == NULL || callback_->canceled())
         return false;
 
-    temporaryFd_ = comm_openex(SOCK_STREAM, IPPROTO_TCP, conn_, conn_->flags, conn_->tos, conn_->nfmark, host_);
+    temporaryFd_ = comm_openex(SOCK_STREAM, IPPROTO_TCP, conn_->local, conn_->flags, conn_->tos, conn_->nfmark, host_);
     if (temporaryFd_ < 0) {
         sendAnswer(COMM_ERR_CONNECT, 0, "Comm::ConnOpener::createFd");
         return false;
index 9a3ed5e8c3604457a66640d15d2ce5adac94370a..05275efaa8916a780f6439f2632c4de0e816e7ac 100644 (file)
@@ -636,13 +636,11 @@ FtpStateData::listenForDataChannel(const Comm::ConnectionPointer &conn, const ch
 
     /* open the conn if its not already open */
     if (!Comm::IsConnOpen(conn)) {
-        comm_open_listener(SOCK_STREAM, IPPROTO_TCP, conn, note);
+        conn->fd = comm_open_listener(SOCK_STREAM, IPPROTO_TCP, conn->local, conn->flags, note);
         if (!Comm::IsConnOpen(conn)) {
             debugs(5, DBG_CRITICAL, HERE << "comm_open_listener failed:" << conn->local << " error: " << errno);
             return;
         }
-// XXX: for the 3.3 workaround try grabbing the IP:port from fd_table where comm should have put it.
-        assert(conn->local.port() != 0);
         debugs(9, 3, HERE << "Unconnected data socket created on " << conn);
     }