------------------------------------------------------------ revno: 13497 revision-id: squid3@treenet.co.nz-20140714094847-w3ojd24bzmv00tl3 parent: squidadm@squid-cache.org-20140714001444-iek3r36pru5cl1t9 committer: Amos Jeffries branch nick: trunk timestamp: Mon 2014-07-14 02:48:47 -0700 message: 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. ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20140714094847-w3ojd24bzmv00tl3 # target_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # testament_sha1: 267148e9d3099d3f5be4d313ce279c605badf0e5 # timestamp: 2014-07-14 10:02:41 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # base_revision_id: squidadm@squid-cache.org-20140714001444-\ # iek3r36pru5cl1t9 # # Begin patch === modified file 'src/AccessLogEntry.cc' --- src/AccessLogEntry.cc 2014-03-30 12:00:34 +0000 +++ src/AccessLogEntry.cc 2014-07-14 09:48:47 +0000 @@ -60,5 +60,4 @@ HTTPMSGUNLOCK(icap.reply); HTTPMSGUNLOCK(icap.request); #endif - cbdataReferenceDone(cache.port); } === modified file 'src/AccessLogEntry.h' --- src/AccessLogEntry.h 2014-04-22 02:47:09 +0000 +++ src/AccessLogEntry.h 2014-07-14 09:48:47 +0000 @@ -185,7 +185,7 @@ const char *ssluser; Ssl::X509_Pointer sslClientCert; ///< cert received from the client #endif - AnyP::PortCfg *port; + AnyP::PortCfgPointer port; } cache; === modified file 'src/CommCalls.cc' --- src/CommCalls.cc 2014-06-05 14:57:58 +0000 +++ src/CommCalls.cc 2014-07-14 09:48:47 +0000 @@ -1,4 +1,5 @@ #include "squid.h" +#include "anyp/PortCfg.h" #include "comm/Connection.h" #include "CommCalls.h" #include "fde.h" === modified file 'src/Makefile.am' --- src/Makefile.am 2014-06-24 22:52:53 +0000 +++ src/Makefile.am 2014-07-14 09:48:47 +0000 @@ -1179,6 +1179,7 @@ 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 @@ acl/libstate.la \ libsquid.la \ comm/libcomm.la \ - anyp/libanyp.la \ ip/libip.la \ fs/libfs.la \ ipc/libipc.la \ @@ -1794,6 +1794,7 @@ $(DISK_LIBS) \ $(DISK_OS_LIBS) \ acl/libapi.la \ + anyp/libanyp.la \ mgr/libmgr.la \ $(SSL_LIBS) \ ipc/libipc.la \ @@ -3413,7 +3414,6 @@ http/libsquid-http.la \ libsquid.la \ comm/libcomm.la \ - anyp/libanyp.la \ ip/libip.la \ fs/libfs.la \ $(COMMON_LIBS) \ @@ -3423,6 +3423,7 @@ acl/libacls.la \ acl/libapi.la \ acl/libstate.la \ + anyp/libanyp.la \ eui/libeui.la \ $(SSL_LIBS) \ ipc/libipc.la \ === modified file 'src/MasterXaction.h' --- src/MasterXaction.h 2013-06-18 23:26:17 +0000 +++ src/MasterXaction.h 2014-07-14 09:48:47 +0000 @@ -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" === modified file 'src/SquidConfig.h' --- src/SquidConfig.h 2014-04-04 16:36:47 +0000 +++ src/SquidConfig.h 2014-07-14 09:48:47 +0000 @@ -136,12 +136,6 @@ #endif } Port; - struct { - AnyP::PortCfg *http; -#if USE_OPENSSL - AnyP::PortCfg *https; -#endif - } Sockaddr; #if SQUID_SNMP struct { === modified file 'src/acl/Acl.cc' --- src/acl/Acl.cc 2014-06-24 22:21:48 +0000 +++ src/acl/Acl.cc 2014-07-14 09:48:47 +0000 @@ -225,8 +225,8 @@ // 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 @@ 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) === modified file 'src/anyp/PortCfg.cc' --- src/anyp/PortCfg.cc 2014-04-16 21:58:08 +0000 +++ src/anyp/PortCfg.cc 2014-07-14 09:48:47 +0000 @@ -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 @@ #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); === modified file 'src/anyp/PortCfg.h' --- src/anyp/PortCfg.h 2014-03-30 12:00:34 +0000 +++ src/anyp/PortCfg.h 2014-07-14 09:48:47 +0000 @@ -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 @@ */ 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 @@ 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 === modified file 'src/anyp/forward.h' --- src/anyp/forward.h 2014-02-07 13:45:20 +0000 +++ src/anyp/forward.h 2014-07-14 09:48:47 +0000 @@ -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; === modified file 'src/cache_cf.cc' --- src/cache_cf.cc 2014-06-24 22:52:53 +0000 +++ src/cache_cf.cc 2014-07-14 09:48:47 +0000 @@ -228,10 +228,10 @@ #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 @@ } } - 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 @@ 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 @@ #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 @@ } static void -parse_port_option(AnyP::PortCfg * s, char *token) +parse_port_option(AnyP::PortCfgPointer &s, char *token) { /* modes first */ @@ -3755,18 +3755,17 @@ 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 @@ return; } - AnyP::PortCfg *s = new AnyP::PortCfg(); + AnyP::PortCfgPointer s = new AnyP::PortCfg(); s->setTransport(protocol); parsePortSpecification(s, token); @@ -3812,19 +3811,19 @@ 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 @@ } 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); } } === modified file 'src/cf.data.pre' --- src/cf.data.pre 2014-07-12 09:34:43 +0000 +++ src/cf.data.pre 2014-07-14 09:48:47 +0000 @@ -1500,7 +1500,7 @@ 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 @@ 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...] === modified file 'src/client_side.cc' --- src/client_side.cc 2014-06-24 22:52:53 +0000 +++ src/client_side.cc 2014-07-14 09:48:47 +0000 @@ -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 @@ 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 @@ 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 @@ *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 @@ // 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 @@ 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 @@ 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 @@ // 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 @@ 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 @@ // 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 @@ /// 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 @@ 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 @@ } #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(); === modified file 'src/client_side.h' --- src/client_side.h 2014-07-12 09:34:43 +0000 +++ src/client_side.h 2014-07-14 09:48:47 +0000 @@ -275,7 +275,7 @@ } pinning; /// Squid listening port details where this connection arrived. - AnyP::PortCfg *port; + AnyP::PortCfgPointer port; bool transparent() const; bool reading() const; === modified file 'src/client_side_request.cc' --- src/client_side_request.cc 2014-07-12 09:34:43 +0000 +++ src/client_side_request.cc 2014-07-14 09:48:47 +0000 @@ -164,7 +164,7 @@ 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 === modified file 'src/comm/ModPoll.cc' --- src/comm/ModPoll.cc 2014-06-09 13:18:48 +0000 +++ src/comm/ModPoll.cc 2014-07-14 09:48:47 +0000 @@ -196,7 +196,7 @@ 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; } === modified file 'src/comm/ModSelect.cc' --- src/comm/ModSelect.cc 2014-06-09 13:18:48 +0000 +++ src/comm/ModSelect.cc 2014-07-14 09:48:47 +0000 @@ -197,7 +197,7 @@ 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 @@ // 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; === modified file 'src/comm/ModSelectWin32.cc' --- src/comm/ModSelectWin32.cc 2014-06-09 13:18:48 +0000 +++ src/comm/ModSelectWin32.cc 2014-07-14 09:48:47 +0000 @@ -191,7 +191,7 @@ 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 @@ // 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; === modified file 'src/comm/TcpAcceptor.cc' --- src/comm/TcpAcceptor.cc 2014-07-10 14:47:53 +0000 +++ src/comm/TcpAcceptor.cc 2014-07-14 09:48:47 +0000 @@ -66,7 +66,17 @@ 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 @@ 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; === modified file 'src/comm/TcpAcceptor.h' --- src/comm/TcpAcceptor.h 2014-06-05 14:57:58 +0000 +++ src/comm/TcpAcceptor.h 2014-07-14 09:48:47 +0000 @@ -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 @@ 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 @@ /// 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_; === modified file 'src/format/Format.cc' --- src/format/Format.cc 2014-05-13 10:27:18 +0000 +++ src/format/Format.cc 2014-07-14 09:48:47 +0000 @@ -384,7 +384,7 @@ // 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 @@ break; case LFT_LOCAL_LISTENING_PORT: - if (al->cache.port) { + if (al->cache.port != NULL) { outint = al->cache.port->s.port(); doint = 1; } === modified file 'src/neighbors.cc' --- src/neighbors.cc 2014-06-05 14:57:58 +0000 +++ src/neighbors.cc 2014-07-14 09:48:47 +0000 @@ -583,7 +583,7 @@ 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; === modified file 'src/send-announce.cc' --- src/send-announce.cc 2013-06-03 14:05:16 +0000 +++ src/send-announce.cc 2014-07-14 09:48:47 +0000 @@ -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 @@ 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(), === modified file 'src/ssl/helper.cc' --- src/ssl/helper.cc 2013-10-25 00:13:46 +0000 +++ src/ssl/helper.cc 2014-07-14 09:48:47 +0000 @@ -33,9 +33,9 @@ // 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 @@ // 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; === modified file 'src/ssl/support.cc' --- src/ssl/support.cc 2014-06-02 07:19:35 +0000 +++ src/ssl/support.cc 2014-07-14 09:48:47 +0000 @@ -1774,10 +1774,10 @@ 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 @@ 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()); } === modified file 'src/tools.cc' --- src/tools.cc 2014-06-02 07:19:35 +0000 +++ src/tools.cc 2014-07-14 09:48:47 +0000 @@ -477,13 +477,13 @@ 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 @@ 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