From: Amos Jeffries Date: Mon, 14 Jul 2014 09:48:47 +0000 (-0700) Subject: Converts the PortCfgPointer to reference counted X-Git-Tag: SQUID_3_5_0_1~148 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fa720bfbffea58f40958d0f6dc67fca6a53e8862;p=thirdparty%2Fsquid.git Converts the PortCfgPointer to reference counted This allows long-lived connections to retain access to their original receiving port configuration even after squid has been reconfigured. Reference counting prevents some leaking of these port configuration details and associated state by removing locking uncertainties. Also, fixes all parsing errors resulting from the change. Most of the issues were due to use of raw-pointers and explicit cbdataReference*() API. --- diff --git a/src/AccessLogEntry.cc b/src/AccessLogEntry.cc index 003eb29703..1231391352 100644 --- a/src/AccessLogEntry.cc +++ b/src/AccessLogEntry.cc @@ -60,5 +60,4 @@ AccessLogEntry::~AccessLogEntry() HTTPMSGUNLOCK(icap.reply); HTTPMSGUNLOCK(icap.request); #endif - cbdataReferenceDone(cache.port); } diff --git a/src/AccessLogEntry.h b/src/AccessLogEntry.h index 648ffac198..27c34cd23f 100644 --- a/src/AccessLogEntry.h +++ b/src/AccessLogEntry.h @@ -185,7 +185,7 @@ public: const char *ssluser; Ssl::X509_Pointer sslClientCert; ///< cert received from the client #endif - AnyP::PortCfg *port; + AnyP::PortCfgPointer port; } cache; diff --git a/src/CommCalls.cc b/src/CommCalls.cc index 36d91b196e..2593c3fd7c 100644 --- a/src/CommCalls.cc +++ b/src/CommCalls.cc @@ -1,4 +1,5 @@ #include "squid.h" +#include "anyp/PortCfg.h" #include "comm/Connection.h" #include "CommCalls.h" #include "fde.h" diff --git a/src/Makefile.am b/src/Makefile.am index 6f8fcd0709..14ddc49bd9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1179,6 +1179,7 @@ tests_testHttpReply_SOURCES=\ tests/stub_HelperChildConfig.cc \ tests/stub_libformat.cc \ tests/stub_libauth.cc \ + tests/stub_libcomm.cc \ StatCounters.h \ StatCounters.cc \ StatHist.h \ @@ -1786,7 +1787,6 @@ tests_testDiskIO_LDADD = \ acl/libstate.la \ libsquid.la \ comm/libcomm.la \ - anyp/libanyp.la \ ip/libip.la \ fs/libfs.la \ ipc/libipc.la \ @@ -1794,6 +1794,7 @@ tests_testDiskIO_LDADD = \ $(DISK_LIBS) \ $(DISK_OS_LIBS) \ acl/libapi.la \ + anyp/libanyp.la \ mgr/libmgr.la \ $(SSL_LIBS) \ ipc/libipc.la \ @@ -3413,7 +3414,6 @@ tests_testRock_LDADD = \ http/libsquid-http.la \ libsquid.la \ comm/libcomm.la \ - anyp/libanyp.la \ ip/libip.la \ fs/libfs.la \ $(COMMON_LIBS) \ @@ -3423,6 +3423,7 @@ tests_testRock_LDADD = \ acl/libacls.la \ acl/libapi.la \ acl/libstate.la \ + anyp/libanyp.la \ eui/libeui.la \ $(SSL_LIBS) \ ipc/libipc.la \ diff --git a/src/MasterXaction.h b/src/MasterXaction.h index 164a9d9f96..e89f1e138f 100644 --- a/src/MasterXaction.h +++ b/src/MasterXaction.h @@ -2,7 +2,6 @@ #define SQUID_SRC_MASTERXACTION_H #include "anyp/forward.h" -#include "base/CbcPointer.h" #include "base/InstanceId.h" #include "base/Lock.h" #include "comm/forward.h" diff --git a/src/SquidConfig.h b/src/SquidConfig.h index 97d09a3100..8cae4ee27e 100644 --- a/src/SquidConfig.h +++ b/src/SquidConfig.h @@ -136,12 +136,6 @@ public: #endif } Port; - struct { - AnyP::PortCfg *http; -#if USE_OPENSSL - AnyP::PortCfg *https; -#endif - } Sockaddr; #if SQUID_SNMP struct { diff --git a/src/acl/Acl.cc b/src/acl/Acl.cc index 574d66a9ed..52d1d9390e 100644 --- a/src/acl/Acl.cc +++ b/src/acl/Acl.cc @@ -225,8 +225,8 @@ ACL::ParseAclLine(ConfigParser &parser, ACL ** head) // Is this ACL going to work? if (strcmp(theType, "myip") == 0) { - AnyP::PortCfg *p = Config.Sockaddr.http; - while (p) { + AnyP::PortCfgPointer p = HttpPortList; + while (p != NULL) { // Bug 3239: not reliable when there is interception traffic coming if (p->flags.natIntercept) debugs(28, DBG_CRITICAL, "WARNING: 'myip' ACL is not reliable for interception proxies. Please use 'myportname' instead."); @@ -235,8 +235,8 @@ ACL::ParseAclLine(ConfigParser &parser, ACL ** head) debugs(28, DBG_IMPORTANT, "UPGRADE: ACL 'myip' type is has been renamed to 'localip' and matches the IP the client connected to."); theType = "localip"; } else if (strcmp(theType, "myport") == 0) { - AnyP::PortCfg *p = Config.Sockaddr.http; - while (p) { + AnyP::PortCfgPointer p = HttpPortList; + while (p != NULL) { // Bug 3239: not reliable when there is interception traffic coming // Bug 3239: myport - not reliable (yet) when there is interception traffic coming if (p->flags.natIntercept) diff --git a/src/anyp/PortCfg.cc b/src/anyp/PortCfg.cc index 693ce6a36a..c1d357ef8e 100644 --- a/src/anyp/PortCfg.cc +++ b/src/anyp/PortCfg.cc @@ -9,13 +9,16 @@ #include #include -CBDATA_NAMESPACED_CLASS_INIT(AnyP, PortCfg); +AnyP::PortCfgPointer HttpPortList; +#if USE_OPENSSL +AnyP::PortCfgPointer HttpsPortList; +#endif int NHttpSockets = 0; int HttpSockets[MAXTCPLISTENPORTS]; AnyP::PortCfg::PortCfg() : - next(NULL), + next(), s(), transport(AnyP::PROTO_HTTP,1,1), // "Squid is an HTTP proxy", etc. name(NULL), @@ -84,10 +87,10 @@ AnyP::PortCfg::~PortCfg() #endif } -AnyP::PortCfg * +AnyP::PortCfgPointer AnyP::PortCfg::clone() const { - AnyP::PortCfg *b = new AnyP::PortCfg(); + AnyP::PortCfgPointer b = new AnyP::PortCfg(); b->s = s; if (name) b->name = xstrdup(name); diff --git a/src/anyp/PortCfg.h b/src/anyp/PortCfg.h index 594196026e..50366523ed 100644 --- a/src/anyp/PortCfg.h +++ b/src/anyp/PortCfg.h @@ -13,12 +13,12 @@ namespace AnyP { -class PortCfg +class PortCfg : public RefCountable { public: PortCfg(); ~PortCfg(); - AnyP::PortCfg *clone() const; + AnyP::PortCfgPointer clone() const; #if USE_OPENSSL /// creates, configures, and validates SSL context and related port options void configureSslServerContext(); @@ -31,7 +31,7 @@ public: */ void setTransport(const char *aProtocol); - PortCfg *next; + PortCfgPointer next; Ip::Address s; AnyP::ProtocolVersion transport; ///< transport protocol and version received by this port @@ -94,12 +94,18 @@ public: long sslContextFlags; ///< flags modifying the use of SSL long sslOptions; ///< SSL engine options #endif - - CBDATA_CLASS2(PortCfg); // namespaced }; } // namespace AnyP +/// list of Squid http_port configured +extern AnyP::PortCfgPointer HttpPortList; + +#if USE_OPENSSL +/// list of Squid https_port configured +extern AnyP::PortCfgPointer HttpsPortList; +#endif + // Max number of TCP listening ports #define MAXTCPLISTENPORTS 128 diff --git a/src/anyp/forward.h b/src/anyp/forward.h index bc9a52ef36..6e5063a8b3 100644 --- a/src/anyp/forward.h +++ b/src/anyp/forward.h @@ -1,13 +1,13 @@ #ifndef _SQUID_SRC_ANYP_FORWARD_H #define _SQUID_SRC_ANYP_FORWARD_H -#include "base/CbcPointer.h" +#include "base/RefCount.h" namespace AnyP { class PortCfg; -typedef CbcPointer PortCfgPointer; +typedef RefCount PortCfgPointer; class UriScheme; diff --git a/src/cache_cf.cc b/src/cache_cf.cc index b65b4e94a3..8ac2e8468b 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -228,10 +228,10 @@ static int check_null_IpAddress_list(const Ip::Address_list *); #endif /* CURRENTLY_UNUSED */ #endif /* USE_WCCPv2 */ -static void parsePortCfg(AnyP::PortCfg **, const char *protocol); +static void parsePortCfg(AnyP::PortCfgPointer *, const char *protocol); #define parse_PortCfg(l) parsePortCfg((l), token) -static void dump_PortCfg(StoreEntry *, const char *, const AnyP::PortCfg *); -static void free_PortCfg(AnyP::PortCfg **); +static void dump_PortCfg(StoreEntry *, const char *, const AnyP::PortCfgPointer &); +#define free_PortCfg(h) *(h)=NULL #if USE_OPENSSL static void parse_sslproxy_cert_sign(sslproxy_cert_sign **cert_sign); @@ -911,7 +911,7 @@ configDoConfigure(void) } } - for (AnyP::PortCfg *s = Config.Sockaddr.http; s != NULL; s = s->next) { + for (AnyP::PortCfgPointer s = HttpPortList; s != NULL; s = s->next) { if (!s->flags.tunnelSslBumping) continue; @@ -919,7 +919,7 @@ configDoConfigure(void) s->configureSslServerContext(); } - for (AnyP::PortCfg *s = Config.Sockaddr.https; s != NULL; s = s->next) { + for (AnyP::PortCfgPointer s = HttpsPortList; s != NULL; s = s->next) { debugs(3, DBG_IMPORTANT, "Initializing https_port " << s->s << " SSL context"); s->configureSslServerContext(); } @@ -3484,7 +3484,7 @@ check_null_IpAddress_list(const Ip::Address_list * s) #endif /* USE_WCCPv2 */ static void -parsePortSpecification(AnyP::PortCfg * s, char *token) +parsePortSpecification(const AnyP::PortCfgPointer &s, char *token) { char *host = NULL; unsigned short port = 0; @@ -3561,7 +3561,7 @@ parsePortSpecification(AnyP::PortCfg * s, char *token) } static void -parse_port_option(AnyP::PortCfg * s, char *token) +parse_port_option(AnyP::PortCfgPointer &s, char *token) { /* modes first */ @@ -3755,18 +3755,17 @@ parse_port_option(AnyP::PortCfg * s, char *token) void add_http_port(char *portspec) { - AnyP::PortCfg *s = new AnyP::PortCfg(); + AnyP::PortCfgPointer s = new AnyP::PortCfg(); s->setTransport("HTTP"); parsePortSpecification(s, portspec); // we may need to merge better if the above returns a list with clones assert(s->next == NULL); - s->next = cbdataReference(Config.Sockaddr.http); - cbdataReferenceDone(Config.Sockaddr.http); - Config.Sockaddr.http = cbdataReference(s); + s->next = HttpPortList; + HttpPortList = s; } static void -parsePortCfg(AnyP::PortCfg ** head, const char *optionName) +parsePortCfg(AnyP::PortCfgPointer *head, const char *optionName) { const char *protocol = NULL; if (strcmp(optionName, "http_port") == 0 || @@ -3786,7 +3785,7 @@ parsePortCfg(AnyP::PortCfg ** head, const char *optionName) return; } - AnyP::PortCfg *s = new AnyP::PortCfg(); + AnyP::PortCfgPointer s = new AnyP::PortCfg(); s->setTransport(protocol); parsePortSpecification(s, token); @@ -3812,19 +3811,19 @@ parsePortCfg(AnyP::PortCfg ** head, const char *optionName) if (Ip::EnableIpv6&IPV6_SPECIAL_SPLITSTACK && s->s.isAnyAddr()) { // clone the port options from *s to *(s->next) - s->next = cbdataReference(s->clone()); + s->next = s->clone(); s->next->s.setIPv4(); debugs(3, 3, AnyP::UriScheme(s->transport.protocol).c_str() << "_port: clone wildcard address for split-stack: " << s->s << " and " << s->next->s); } - while (*head) - head = &(*head)->next; + while (*head != NULL) + head = &((*head)->next); - *head = cbdataReference(s); + *head = s; } static void -dump_generic_port(StoreEntry * e, const char *n, const AnyP::PortCfg * s) +dump_generic_port(StoreEntry * e, const char *n, const AnyP::PortCfgPointer &s) { char buf[MAX_IPSTRLEN]; @@ -3948,23 +3947,11 @@ dump_generic_port(StoreEntry * e, const char *n, const AnyP::PortCfg * s) } static void -dump_PortCfg(StoreEntry * e, const char *n, const AnyP::PortCfg * s) +dump_PortCfg(StoreEntry * e, const char *n, const AnyP::PortCfgPointer &s) { - while (s) { - dump_generic_port(e, n, s); + for (AnyP::PortCfgPointer p = s; p != NULL; p = p->next) { + dump_generic_port(e, n, p); storeAppendPrintf(e, "\n"); - s = s->next; - } -} - -static void -free_PortCfg(AnyP::PortCfg ** head) -{ - AnyP::PortCfg *s; - - while ((s = *head) != NULL) { - *head = s->next; - cbdataReferenceDone(s); } } diff --git a/src/cf.data.pre b/src/cf.data.pre index 102d954baa..317cf453ac 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -1500,7 +1500,7 @@ COMMENT_END NAME: http_port ascii_port TYPE: PortCfg DEFAULT: none -LOC: Config.Sockaddr.http +LOC: HttpPortList DOC_START Usage: port [mode] [options] hostname:port [mode] [options] @@ -1737,7 +1737,7 @@ NAME: https_port IFDEF: USE_OPENSSL TYPE: PortCfg DEFAULT: none -LOC: Config.Sockaddr.https +LOC: HttpsPortList DOC_START Usage: [ip:]port cert=certificate.pem [key=key.pem] [mode] [options...] diff --git a/src/client_side.cc b/src/client_side.cc index f54ba1e194..0db586e552 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -161,13 +161,13 @@ class ListeningStartedDialer: public CallDialer, public Ipc::StartListeningCb { public: - typedef void (*Handler)(AnyP::PortCfg *portCfg, const Ipc::FdNoteId note, const Subscription::Pointer &sub); - ListeningStartedDialer(Handler aHandler, AnyP::PortCfg *aPortCfg, const Ipc::FdNoteId note, const Subscription::Pointer &aSub): + typedef void (*Handler)(AnyP::PortCfgPointer &portCfg, const Ipc::FdNoteId note, const Subscription::Pointer &sub); + ListeningStartedDialer(Handler aHandler, AnyP::PortCfgPointer &aPortCfg, const Ipc::FdNoteId note, const Subscription::Pointer &aSub): handler(aHandler), portCfg(aPortCfg), portTypeNote(note), sub(aSub) {} virtual void print(std::ostream &os) const { startPrint(os) << - ", " << FdNote(portTypeNote) << " port=" << (void*)portCfg << ')'; + ", " << FdNote(portTypeNote) << " port=" << (void*)&portCfg << ')'; } virtual bool canDial(AsyncCall &) const { return true; } @@ -177,12 +177,12 @@ public: Handler handler; private: - AnyP::PortCfg *portCfg; ///< from Config.Sockaddr.http + AnyP::PortCfgPointer portCfg; ///< from HttpPortList Ipc::FdNoteId portTypeNote; ///< Type of IPC socket being opened Subscription::Pointer sub; ///< The handler to be subscribed for this connetion listener }; -static void clientListenerConnectionOpened(AnyP::PortCfg *s, const Ipc::FdNoteId portTypeNote, const Subscription::Pointer &sub); +static void clientListenerConnectionOpened(AnyP::PortCfgPointer &s, const Ipc::FdNoteId portTypeNote, const Subscription::Pointer &sub); /* our socket-related context */ @@ -878,8 +878,6 @@ ConnStateData::~ConnStateData() if (!flags.swanSang) debugs(33, DBG_IMPORTANT, "BUG: ConnStateData was not destroyed properly; " << clientConnection); - cbdataReferenceDone(port); - if (bodyPipe != NULL) stopProducingFor(bodyPipe, false); @@ -2263,7 +2261,7 @@ parseHttpRequest(ConnStateData *csd, HttpParser *hp, HttpRequestMethod * method_ *method_p = HttpRequestMethod(&hp->buf[hp->req.m_start], &hp->buf[hp->req.m_end]+1); /* deny CONNECT via accelerated ports */ - if (*method_p == Http::METHOD_CONNECT && csd->port && csd->port->flags.accelSurrogate) { + if (*method_p == Http::METHOD_CONNECT && csd->port != NULL && csd->port->flags.accelSurrogate) { debugs(33, DBG_IMPORTANT, "WARNING: CONNECT method received on " << csd->port->transport.protocol << " Accelerator port " << csd->port->s.port()); /* XXX need a way to say "this many character length string" */ debugs(33, DBG_IMPORTANT, "WARNING: for request: " << hp->buf); @@ -3278,7 +3276,7 @@ ConnStateData::ConnStateData(const MasterXaction::Pointer &xact) : // store the details required for creating more MasterXaction objects as new requests come in clientConnection = xact->tcpClient; - port = cbdataReference(xact->squidPort.get()); + port = xact->squidPort; log_addr = xact->tcpClient->remote; log_addr.applyMask(Config.Addrs.client_netmask); @@ -3330,7 +3328,7 @@ httpAccept(const CommAcceptCbParams ¶ms) MasterXaction::Pointer xact = params.xaction; AnyP::PortCfgPointer s = xact->squidPort; - if (!s.valid()) { + if (!s) { // it is possible the call or accept() was still queued when the port was reconfigured debugs(33, 2, "HTTP accept failure: port reconfigured."); return; @@ -4038,9 +4036,7 @@ AddOpenedHttpSocket(const Comm::ConnectionPointer &conn) static void clientHttpConnectionsOpen(void) { - AnyP::PortCfg *s = NULL; - - for (s = Config.Sockaddr.http; s; s = s->next) { + for (AnyP::PortCfgPointer s = HttpPortList; s != NULL; s = s->next) { if (MAXTCPLISTENPORTS == NHttpSockets) { debugs(1, DBG_IMPORTANT, "WARNING: You have too many 'http_port' lines."); debugs(1, DBG_IMPORTANT, " The limit is " << MAXTCPLISTENPORTS << " HTTP ports."); @@ -4073,7 +4069,7 @@ clientHttpConnectionsOpen(void) // setup the subscriptions such that new connections accepted by listenConn are handled by HTTP typedef CommCbFunPtrCallT AcceptCall; - RefCount subCall = commCbCall(5, 5, "httpAccept", CommAcceptCbPtrFun(httpAccept, s)); + RefCount subCall = commCbCall(5, 5, "httpAccept", CommAcceptCbPtrFun(httpAccept, CommAcceptCbParams(NULL))); Subscription::Pointer sub = new CallSubscription(subCall); AsyncCall::Pointer listenCall = asyncCall(33,2, "clientListenerConnectionOpened", @@ -4089,9 +4085,7 @@ clientHttpConnectionsOpen(void) static void clientHttpsConnectionsOpen(void) { - AnyP::PortCfg *s; - - for (s = Config.Sockaddr.https; s; s = s->next) { + for (AnyP::PortCfgPointer s = HttpsPortList; s != NULL; s = s->next) { if (MAXTCPLISTENPORTS == NHttpSockets) { debugs(1, DBG_IMPORTANT, "Ignoring 'https_port' lines exceeding the limit."); debugs(1, DBG_IMPORTANT, "The limit is " << MAXTCPLISTENPORTS << " HTTPS ports."); @@ -4128,7 +4122,7 @@ clientHttpsConnectionsOpen(void) // setup the subscriptions such that new connections accepted by listenConn are handled by HTTPS typedef CommCbFunPtrCallT AcceptCall; - RefCount subCall = commCbCall(5, 5, "httpsAccept", CommAcceptCbPtrFun(httpsAccept, s)); + RefCount subCall = commCbCall(5, 5, "httpsAccept", CommAcceptCbPtrFun(httpsAccept, CommAcceptCbParams(NULL))); Subscription::Pointer sub = new CallSubscription(subCall); AsyncCall::Pointer listenCall = asyncCall(33, 2, "clientListenerConnectionOpened", @@ -4143,16 +4137,17 @@ clientHttpsConnectionsOpen(void) /// process clientHttpConnectionsOpen result static void -clientListenerConnectionOpened(AnyP::PortCfg *s, const Ipc::FdNoteId portTypeNote, const Subscription::Pointer &sub) +clientListenerConnectionOpened(AnyP::PortCfgPointer &s, const Ipc::FdNoteId portTypeNote, const Subscription::Pointer &sub) { + Must(s != NULL); + if (!OpenedHttpSocket(s->listenConn, portTypeNote)) return; - Must(s); Must(Comm::IsConnOpen(s->listenConn)); // TCP: setup a job to handle accept() with subscribed handler - AsyncJob::Start(new Comm::TcpAcceptor(s->listenConn, FdNote(portTypeNote), sub)); + AsyncJob::Start(new Comm::TcpAcceptor(s, FdNote(portTypeNote), sub)); debugs(1, DBG_IMPORTANT, "Accepting " << (s->flags.natIntercept ? "NAT intercepted " : "") << @@ -4180,7 +4175,7 @@ clientOpenListenSockets(void) void clientHttpConnectionsClose(void) { - for (AnyP::PortCfg *s = Config.Sockaddr.http; s; s = s->next) { + for (AnyP::PortCfgPointer s = HttpPortList; s != NULL; s = s->next) { if (s->listenConn != NULL) { debugs(1, DBG_IMPORTANT, "Closing HTTP port " << s->listenConn->local); s->listenConn->close(); @@ -4189,7 +4184,7 @@ clientHttpConnectionsClose(void) } #if USE_OPENSSL - for (AnyP::PortCfg *s = Config.Sockaddr.https; s; s = s->next) { + for (AnyP::PortCfgPointer s = HttpsPortList; s != NULL; s = s->next) { if (s->listenConn != NULL) { debugs(1, DBG_IMPORTANT, "Closing HTTPS port " << s->listenConn->local); s->listenConn->close(); diff --git a/src/client_side.h b/src/client_side.h index 91139dac8f..5d8359372a 100644 --- a/src/client_side.h +++ b/src/client_side.h @@ -275,7 +275,7 @@ public: } pinning; /// Squid listening port details where this connection arrived. - AnyP::PortCfg *port; + AnyP::PortCfgPointer port; bool transparent() const; bool reading() const; diff --git a/src/client_side_request.cc b/src/client_side_request.cc index ea434ecc0f..9487435849 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -164,7 +164,7 @@ ClientHttpRequest::ClientHttpRequest(ConnStateData * aConn) : al = new AccessLogEntry; al->cache.start_time = current_time; al->tcpClient = clientConnection = aConn->clientConnection; - al->cache.port = cbdataReference(aConn->port); + al->cache.port = aConn->port; al->cache.caddr = aConn->log_addr; #if USE_OPENSSL diff --git a/src/comm/ModPoll.cc b/src/comm/ModPoll.cc index 2367634c04..9e0a67b5e1 100644 --- a/src/comm/ModPoll.cc +++ b/src/comm/ModPoll.cc @@ -196,7 +196,7 @@ fdIsDns(int fd) static int fdIsTcpListen(int fd) { - for (const AnyP::PortCfg *s = Config.Sockaddr.http; s; s = s->next) { + for (const AnyP::PortCfgPointer s = HttpPortList; s != NULL; s = s->next) { if (s->listenConn != NULL && s->listenConn->fd == fd) return 1; } diff --git a/src/comm/ModSelect.cc b/src/comm/ModSelect.cc index e704b367c8..18ccbb0806 100644 --- a/src/comm/ModSelect.cc +++ b/src/comm/ModSelect.cc @@ -197,7 +197,7 @@ fdIsDns(int fd) static int fdIsTcpListener(int fd) { - for (const AnyP::PortCfg *s = Config.Sockaddr.http; s; s = s->next) { + for (const AnyP::PortCfgPointer s = HttpPortList; s != NULL; s = s->next) { if (s->listenConn != NULL && s->listenConn->fd == fd) return 1; } @@ -320,7 +320,7 @@ comm_select_tcp_incoming(void) // XXX: only poll sockets that won't be deferred. But how do we identify them? - for (const AnyP::PortCfg *s = Config.Sockaddr.http; s; s = s->next) { + for (const AnyP::PortCfgPointer s = HttpPortList; s != NULL; s = s->next) { if (Comm::IsConnOpen(s->listenConn)) { fds[nfds] = s->listenConn->fd; ++nfds; diff --git a/src/comm/ModSelectWin32.cc b/src/comm/ModSelectWin32.cc index 373a7b7521..023f5a21aa 100644 --- a/src/comm/ModSelectWin32.cc +++ b/src/comm/ModSelectWin32.cc @@ -191,7 +191,7 @@ fdIsDns(int fd) static int fdIsTcpListener(int fd) { - for (const AnyP::PortCfg *s = Config.Sockaddr.http; s; s = s->next) { + for (const AnyP::PortCfgPointer s = HttpPortList; s != NULL; s = s->next) { if (s->listenConn != NULL && s->listenConn->fd == fd) return 1; } @@ -317,7 +317,7 @@ comm_select_tcp_incoming(void) // XXX: only poll sockets that won't be deferred. But how do we identify them? - for (const AnyP::PortCfg *s = Config.Sockaddr.http; s; s = s->next) { + for (const AnyP::PortCfgPointer s = HttpPortList; s != NULL; s = s->next) { if (Comm::IsConnOpen(s->listenConn)) { fds[nfds] = s->listenConn->fd; ++nfds; diff --git a/src/comm/TcpAcceptor.cc b/src/comm/TcpAcceptor.cc index f4b6c66f6b..244afb2484 100644 --- a/src/comm/TcpAcceptor.cc +++ b/src/comm/TcpAcceptor.cc @@ -66,7 +66,17 @@ Comm::TcpAcceptor::TcpAcceptor(const Comm::ConnectionPointer &newConn, const cha errcode(0), isLimited(0), theCallSub(aSub), - conn(newConn) + conn(newConn), + listenPort_() +{} + +Comm::TcpAcceptor::TcpAcceptor(const AnyP::PortCfgPointer &p, const char *note, const Subscription::Pointer &aSub) : + AsyncJob("Comm::TcpAcceptor"), + errcode(0), + isLimited(0), + theCallSub(aSub), + conn(p->listenConn), + listenPort_(p) {} void @@ -309,7 +319,7 @@ Comm::TcpAcceptor::notify(const Comm::Flag flag, const Comm::ConnectionPointer & AsyncCall::Pointer call = theCallSub->callback(); CommAcceptCbParams ¶ms = GetCommParams(call); params.xaction = new MasterXaction; - params.xaction->squidPort = static_cast(params.data); + params.xaction->squidPort = listenPort_; params.fd = conn->fd; params.conn = params.xaction->tcpClient = newConnDetails; params.flag = flag; diff --git a/src/comm/TcpAcceptor.h b/src/comm/TcpAcceptor.h index abffacb7f0..49a1fa947f 100644 --- a/src/comm/TcpAcceptor.h +++ b/src/comm/TcpAcceptor.h @@ -1,6 +1,7 @@ #ifndef SQUID_COMM_TCPACCEPTOR_H #define SQUID_COMM_TCPACCEPTOR_H +#include "anyp/forward.h" #include "base/AsyncJob.h" #include "base/CbcPointer.h" #include "base/Subscription.h" @@ -41,6 +42,7 @@ private: public: TcpAcceptor(const Comm::ConnectionPointer &conn, const char *note, const Subscription::Pointer &aSub); + TcpAcceptor(const AnyP::PortCfgPointer &listenPort, const char *note, const Subscription::Pointer &aSub); /** Subscribe a handler to receive calls back about new connections. * Unsubscribes any existing subscribed handler. @@ -75,6 +77,9 @@ private: /// Reserved for read-only use. ConnectionPointer conn; + /// configuration details of the listening port (if provided) + AnyP::PortCfgPointer listenPort_; + /// listen socket closure handler AsyncCall::Pointer closer_; diff --git a/src/format/Format.cc b/src/format/Format.cc index 7f61bc0b4a..b58a47ce0e 100644 --- a/src/format/Format.cc +++ b/src/format/Format.cc @@ -384,7 +384,7 @@ Format::Format::assemble(MemBuf &mb, const AccessLogEntry::Pointer &al, int logS // avoid logging a dash if we have reliable info const bool interceptedAtKnownPort = al->request ? (al->request->flags.interceptTproxy || - al->request->flags.intercepted) && al->cache.port : + al->request->flags.intercepted) && al->cache.port != NULL : false; if (interceptedAtKnownPort) { const bool portAddressConfigured = !al->cache.port->s.isAnyAddr(); @@ -416,7 +416,7 @@ Format::Format::assemble(MemBuf &mb, const AccessLogEntry::Pointer &al, int logS break; case LFT_LOCAL_LISTENING_PORT: - if (al->cache.port) { + if (al->cache.port != NULL) { outint = al->cache.port->s.port(); doint = 1; } diff --git a/src/neighbors.cc b/src/neighbors.cc index e7c5f98d5a..c480e5cdc1 100644 --- a/src/neighbors.cc +++ b/src/neighbors.cc @@ -583,7 +583,7 @@ neighbors_init(void) if (0 != strcmp(thisPeer->host, me)) continue; - for (AnyP::PortCfg *s = Config.Sockaddr.http; s; s = s->next) { + for (AnyP::PortCfgPointer s = HttpPortList; s != NULL; s = s->next) { if (thisPeer->http_port != s->s.port()) continue; diff --git a/src/send-announce.cc b/src/send-announce.cc index 68f66b2c5d..50845e62ae 100644 --- a/src/send-announce.cc +++ b/src/send-announce.cc @@ -31,6 +31,7 @@ */ #include "squid.h" +#include "anyp/PortCfg.h" #include "comm/Connection.h" #include "disk.h" #include "event.h" @@ -81,7 +82,7 @@ send_announce(const ipcache_addrs *ia, const DnsLookupDetails &, void *junk) sndbuf[0] = '\0'; snprintf(tbuf, 256, "cache_version SQUID/%s\n", version_string); strcat(sndbuf, tbuf); - assert(Config.Sockaddr.http); + assert(HttpPortList != NULL); snprintf(tbuf, 256, "Running on %s %d %d\n", getMyHostname(), getMyPort(), diff --git a/src/ssl/helper.cc b/src/ssl/helper.cc index 3e3099c360..4ed0f796c3 100644 --- a/src/ssl/helper.cc +++ b/src/ssl/helper.cc @@ -33,9 +33,9 @@ void Ssl::Helper::Init() // we need to start ssl_crtd only if some port(s) need to bump SSL bool found = false; - for (AnyP::PortCfg *s = ::Config.Sockaddr.http; !found && s; s = s->next) + for (AnyP::PortCfgPointer s = HttpPortList; !found && s != NULL; s = s->next) found = s->flags.tunnelSslBumping; - for (AnyP::PortCfg *s = ::Config.Sockaddr.https; !found && s; s = s->next) + for (AnyP::PortCfgPointer s = HttpsPortList; !found && s != NULL; s = s->next) found = s->flags.tunnelSslBumping; if (!found) return; @@ -134,9 +134,9 @@ void Ssl::CertValidationHelper::Init() // we need to start ssl_crtd only if some port(s) need to bump SSL bool found = false; - for (AnyP::PortCfg *s = ::Config.Sockaddr.http; !found && s; s = s->next) + for (AnyP::PortCfgPointer s = HttpPortList; !found && s != NULL; s = s->next) found = s->flags.tunnelSslBumping; - for (AnyP::PortCfg *s = ::Config.Sockaddr.https; !found && s; s = s->next) + for (AnyP::PortCfgPointer s = HttpsPortList; !found && s != NULL; s = s->next) found = s->flags.tunnelSslBumping; if (!found) return; diff --git a/src/ssl/support.cc b/src/ssl/support.cc index fad05b9b0c..b3493f168c 100644 --- a/src/ssl/support.cc +++ b/src/ssl/support.cc @@ -1774,10 +1774,10 @@ setSessionCallbacks(SSL_CTX *ctx) static bool isSslServer() { - if (Config.Sockaddr.https) + if (HttpsPortList.valid()) return true; - for (AnyP::PortCfg *s = Config.Sockaddr.http; s; s = s->next) { + for (AnyP::PortCfgPointer s = HttpPortList; s != NULL; s = s->next) { if (s->flags.tunnelSslBumping) return true; } @@ -1808,12 +1808,12 @@ Ssl::initialize_session_cache() return; } - for (AnyP::PortCfg *s = ::Config.Sockaddr.https; s; s = s->next) { + for (AnyP::PortCfgPointer s = HttpsPortList; s != NULL; s = s->next) { if (s->staticSslContext.get() != NULL) setSessionCallbacks(s->staticSslContext.get()); } - for (AnyP::PortCfg *s = ::Config.Sockaddr.http; s; s = s->next) { + for (AnyP::PortCfgPointer s = HttpPortList; s != NULL; s = s->next) { if (s->staticSslContext.get() != NULL) setSessionCallbacks(s->staticSslContext.get()); } diff --git a/src/tools.cc b/src/tools.cc index 4d275a6b29..466e284f24 100644 --- a/src/tools.cc +++ b/src/tools.cc @@ -477,13 +477,13 @@ getMyHostname(void) host[0] = '\0'; - if (Config.Sockaddr.http && sa.isAnyAddr()) - sa = Config.Sockaddr.http->s; + if (HttpPortList != NULL && sa.isAnyAddr()) + sa = HttpPortList->s; #if USE_OPENSSL - if (Config.Sockaddr.https && sa.isAnyAddr()) - sa = Config.Sockaddr.https->s; + if (HttpsPortList != NULL && sa.isAnyAddr()) + sa = HttpsPortList->s; #endif @@ -1131,21 +1131,21 @@ parseEtcHosts(void) int getMyPort(void) { - AnyP::PortCfg *p = NULL; - if ((p = Config.Sockaddr.http)) { + AnyP::PortCfgPointer p; + if ((p = HttpPortList) != NULL) { // skip any special interception ports - while (p && p->flags.isIntercepted()) + while (p != NULL && p->flags.isIntercepted()) p = p->next; - if (p) + if (p != NULL) return p->s.port(); } #if USE_OPENSSL - if ((p = Config.Sockaddr.https)) { + if ((p = HttpsPortList) != NULL) { // skip any special interception ports - while (p && p->flags.isIntercepted()) + while (p != NULL && p->flags.isIntercepted()) p = p->next; - if (p) + if (p != NULL) return p->s.port(); } #endif