From: Amos Jeffries Date: Sun, 19 Jan 2014 05:20:17 +0000 (-0800) Subject: Merge from trunk X-Git-Tag: SQUID_3_5_0_1~392 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6832236ff45da0325fa7d163a598f8ff1f482e0b;p=thirdparty%2Fsquid.git Merge from trunk --- diff --git a/src/comm.cc b/src/comm.cc index 9f19f1dbb4..c5dba5ae37 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -426,22 +426,28 @@ comm_open(int sock_type, int flags, const char *note) { - return comm_openex(sock_type, proto, addr, flags, 0, 0, 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; } void comm_open_listener(int sock_type, int proto, - Comm::ConnectionPointer &conn, + const 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->local, conn->flags, 0, 0, note); + conn->fd = comm_openex(sock_type, proto, conn, conn->flags, 0, 0, note); + // XXX: remove the flags parameter to comm_openex() } +// XXX: remove this wrapper int comm_open_listener(int sock_type, int proto, @@ -449,14 +455,13 @@ comm_open_listener(int sock_type, int flags, const char *note) { - int sock = -1; - /* all listener sockets require bind() */ flags |= COMM_DOBIND; - /* attempt native enabled port. */ - sock = comm_openex(sock_type, proto, addr, flags, 0, 0, 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; } @@ -528,13 +533,12 @@ comm_set_transparent(int fd) int comm_openex(int sock_type, int proto, - Ip::Address &addr, + const Comm::ConnectionPointer &conn, int flags, tos_t tos, nfmark_t nfmark, const char *note) { - int new_socket; struct addrinfo *AI = NULL; PROF_start(comm_open); @@ -542,29 +546,28 @@ comm_openex(int sock_type, ++ statCounter.syscalls.sock.sockets; /* Setup the socket addrinfo details for use */ - addr.getAddrInfo(AI); + conn->local.getAddrInfo(AI); AI->ai_socktype = sock_type; AI->ai_protocol = proto; - debugs(50, 3, "comm_openex: Attempt open socket for: " << addr ); + debugs(50, 3, "Attempt open " << note << " socket for: " << conn); - new_socket = socket(AI->ai_family, AI->ai_socktype, AI->ai_protocol); + conn->fd = 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 ( new_socket < 0 && Ip::EnableIpv6 && addr.isIPv6() && addr.setIPv4() ) { + if (conn->fd < 0 && Ip::EnableIpv6 && conn->local.isIPv6() && conn->local.setIPv4()) { /* attempt to open this IPv4-only. */ Ip::Address::FreeAddrInfo(AI); /* Setup the socket addrinfo details for use */ - addr.getAddrInfo(AI); + conn->local.getAddrInfo(AI); AI->ai_socktype = sock_type; AI->ai_protocol = proto; - 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); + debugs(50, 3, "Attempt fallback open " << note << " socket for: " << conn); + conn->fd = socket(AI->ai_family, AI->ai_socktype, AI->ai_protocol); } - if (new_socket < 0) { + if (conn->fd < 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 */ @@ -582,12 +585,7 @@ comm_openex(int sock_type, return -1; } - // 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 ); + debugs(50, 3, "Opened socket " << conn << " : family=" << AI->ai_family << ", type=" << AI->ai_socktype << ", protocol=" << AI->ai_protocol); /* set TOS if needed */ if (tos) @@ -597,24 +595,26 @@ comm_openex(int sock_type, if (nfmark) Ip::Qos::setSockNfmark(conn, nfmark); - if ( Ip::EnableIpv6&IPV6_SPECIAL_SPLITSTACK && addr.isIPv6() ) + if (Ip::EnableIpv6&IPV6_SPECIAL_SPLITSTACK && conn->local.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 && addr.isIPv6() ) + if (Ip::EnableIpv6&IPV6_SPECIAL_V4MAPPING && conn->local.isIPv6()) comm_set_v6only(conn->fd, 0); comm_init_opened(conn, tos, nfmark, note, AI); - new_socket = comm_apply_flags(conn->fd, addr, flags, 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); Ip::Address::FreeAddrInfo(AI); PROF_stop(comm_open); - // XXX transition only. prevent conn from closing the new FD on function exit. - conn->fd = -1; - return new_socket; + return conn->fd; } /// update FD tables after a local or remote (IPC) comm_openex(); diff --git a/src/comm.h b/src/comm.h index 8c5b04ea91..0658df5ede 100644 --- a/src/comm.h +++ b/src/comm.h @@ -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, Comm::ConnectionPointer &conn, const char *note); +void comm_open_listener(int sock_type, int proto, const Comm::ConnectionPointer &conn, const char *note); -int comm_openex(int, int, Ip::Address &, int, tos_t tos, nfmark_t nfmark, const char *); +int comm_openex(int, int, const Comm::ConnectionPointer &, 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); diff --git a/src/comm/ConnOpener.cc b/src/comm/ConnOpener.cc index c2913dbc55..c115875e75 100644 --- a/src/comm/ConnOpener.cc +++ b/src/comm/ConnOpener.cc @@ -255,7 +255,7 @@ Comm::ConnOpener::createFd() if (callback_ == NULL || callback_->canceled()) return false; - temporaryFd_ = comm_openex(SOCK_STREAM, IPPROTO_TCP, conn_->local, conn_->flags, conn_->tos, conn_->nfmark, host_); + temporaryFd_ = comm_openex(SOCK_STREAM, IPPROTO_TCP, conn_, conn_->flags, conn_->tos, conn_->nfmark, host_); if (temporaryFd_ < 0) { sendAnswer(COMM_ERR_CONNECT, 0, "Comm::ConnOpener::createFd"); return false; diff --git a/src/ftp.cc b/src/ftp.cc index 05275efaa8..9a3ed5e8c3 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -636,11 +636,13 @@ FtpStateData::listenForDataChannel(const Comm::ConnectionPointer &conn, const ch /* open the conn if its not already open */ if (!Comm::IsConnOpen(conn)) { - conn->fd = comm_open_listener(SOCK_STREAM, IPPROTO_TCP, conn->local, conn->flags, note); + comm_open_listener(SOCK_STREAM, IPPROTO_TCP, conn, 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); }