]> git.ipfire.org Git - thirdparty/squid.git/log
thirdparty/squid.git
19 months agoRun cache_peer probes without transaction context (#1256)
Eduard Bagdasaryan [Fri, 10 Feb 2023 15:44:18 +0000 (15:44 +0000)] 
Run cache_peer probes without transaction context (#1256)

Even when triggered by a master transaction, these background probes
should not be associated with it. That transaction just wants to know
whether the neighbor is "up" right now. The transaction does not wait
(and is not aware of) the background probe its question may or may not
have triggered.

19 months agoCleanup: remove xusleep() hacks (#613)
Amos Jeffries [Fri, 10 Feb 2023 12:25:07 +0000 (12:25 +0000)] 
Cleanup: remove xusleep() hacks (#613)

usleep() has been obsolete for a long time. C++11 provides better and
portable waiting mechanism we can use easily instead of these hacks
trying to replicate and extend usleep().

19 months agoMaintenance: Add ACL key change tests (#1269)
Eduard Bagdasaryan [Tue, 7 Feb 2023 20:22:54 +0000 (20:22 +0000)] 
Maintenance: Add ACL key change tests (#1269)

Squid bans key changes in req_header/rep_header and note ACLs
since 4a3b853.

19 months agoPrep for 6.0.1 (#1263)
Amos Jeffries [Mon, 6 Feb 2023 23:06:48 +0000 (23:06 +0000)] 
Prep for 6.0.1 (#1263)

19 months agoDocumentation: Polish "refresh_pattern percent" description (#1260)
Amos Jeffries [Sun, 5 Feb 2023 21:00:38 +0000 (21:00 +0000)] 
Documentation: Polish "refresh_pattern percent" description (#1260)

The original text contained a "last modification age" typo and was
misinterpreted by some admins as if Squid applied the configured percent
to the current object age.

The text also did not make it clear that the percent-based heuristic is
effectively only applied to responses with a Last-Modified header (in
addition to the usual "without an explicit expiry time" precondition).

19 months agoAdd memFreeRigid to mem/libminimal.la (#1258)
gkinkie@gmail.com [Sun, 5 Feb 2023 10:08:41 +0000 (10:08 +0000)] 
Add memFreeRigid to mem/libminimal.la (#1258)

Complement the already-included memAllocRigid,
to better support unit tests

19 months agoUpdate ChangeLog for latest merges (#1257)
Amos Jeffries [Sat, 4 Feb 2023 08:43:30 +0000 (08:43 +0000)] 
Update ChangeLog for latest merges (#1257)

19 months agoFix stub for ip/libip.la (#1254)
Amos Jeffries [Fri, 3 Feb 2023 14:07:53 +0000 (14:07 +0000)] 
Fix stub for ip/libip.la (#1254)

Use to build disk I/O tests which do not need IP address
operations. This also ensures bitrot does not reappear.

19 months agocachemgr.cgi: Drop cache_object protocol support (#1252)
Eduard Bagdasaryan [Thu, 2 Feb 2023 22:42:48 +0000 (22:42 +0000)] 
cachemgr.cgi: Drop cache_object protocol support (#1252)

19 months agoV6 release prep (#1245)
Amos Jeffries [Thu, 2 Feb 2023 19:47:05 +0000 (19:47 +0000)] 
V6 release prep (#1245)

19 months agosquidclient: Drop cache_object protocol support (#1251)
Eduard Bagdasaryan [Thu, 2 Feb 2023 12:25:10 +0000 (12:25 +0000)] 
squidclient: Drop cache_object protocol support (#1251)

Use `http` URL scheme for `mgr:command` cache manager requests instead.

Also fixed a bug: When `mgr:command` was used together with a `-w X`
command-line option, squidclient sent that proxy authentication password
`X` in the `cache_object` URL instead of sending the `Y` password from
the `-W Y` option (or no password at all if no `-W` option was given).
If no Authorization header had been sent, Squid's cachemgr_passwd
honored the `-w X` password sent in the cache_object URL.  If
Authorization header had been sent, Squid's cachemgr_passwd honored the
corresponding `-W Y` password, ignoring any password sent in the
cache_object URL.

Now, squidclient uses Authorization HTTP header for sending cache
manager authentication credentials with `mgr:command` requests. Those
credentials are taken either from the `-U` and `-W` command-line options
(if `mgr:command` parameter lacks an embedded password) or from the `-U`
command line option and from the `mgr:command@password` parameter
(otherwise).

squidclient now sends Proxy authentication credentials if and only if
`-u` and `-w` command line options are given. These credentials may be
required to authenticate with the proxy, but they do not affect cache
manager authentication driven by the cachemgr_passwd directive.

Also prohibit specifying a command-line option with a password (`-w` or
`-W`) without specifying the corresponding user name (`-u` or `-U`).
Prior to this change, squidclient did not send the Proxy-Authorization
or Authorization header if the corresponding user name was missing but
did not complain about the problem.

19 months agoRemove broken -sha1 option from server_cert_fingerprint (#1249)
Eduard Bagdasaryan [Wed, 1 Feb 2023 19:25:10 +0000 (19:25 +0000)] 
Remove broken -sha1 option from server_cert_fingerprint (#1249)

server_cert_fingerprint support for the sha1 parameter has been broken
for years, probably since its inception (2012 commit 42d3334). The bug
was known since at least 2018 when it was mentioned in Bug 4847
discussion.  The single-dash syntax violates the double-dash pattern
used for other --long ACL options. If fixed, using the option would not
change Squid behavior because SHA1 is the default (and the only
supported) fingerprinting algorithm.

The option was meant to allow admins to be explicit about that default
in case it changes in the future, but implementation bugs derailed that
plan. The fix is not straightforward, and we should be focusing on more
important things.

19 months agoImprove error message storage in Dns::LookupDetails (#1241)
Francesco Chemolli [Sun, 29 Jan 2023 21:59:41 +0000 (21:59 +0000)] 
Improve error message storage in Dns::LookupDetails (#1241)

Removed one more deprecated String usage and optimized handling of a
common "no error, no lookup" case as well as portions of the "no-error
lookup" code paths. Further optimizations need similar ipcache_entry and
fqdncache_entry error storage changes (at least).

Co-authored-by: Alex Rousskov <rousskov@measurement-factory.com>
19 months agoFix logging of responses truncated by premature EOF (#1244)
Eduard Bagdasaryan [Sat, 28 Jan 2023 09:36:56 +0000 (09:36 +0000)] 
Fix logging of responses truncated by premature EOF (#1244)

When a transaction failed due to a premature EOF while receiving an HTTP
response, %Ss logformat code was missing the ABORTED suffix (e.g.,
logging TCP_MISS instead of TCP_MISS_ABORTED). When premature EOF
truncated the header, the default "squid" access log format contained a
502 sent status code (%>Hs), hinting at the problem. When the body was
truncated, even that weak hint was usually absent because the actual
status code returned by the server (usually 200) was usually logged.

Similarly, %err_code/%err_detail logformat codes for HTTP responses with
truncated by a premature EOF bodies carried no information. Now they
expand to ERR_READ_ERROR/SRV_PREMATURE_EOF in those cases.

No changes to requests truncated by Squid-server read timeouts. They
were and are still logged with TIMEDOUT %Ss suffix and
ERR_READ_TIMEOUT/WITH_SERVER %err_code/%err_detail.

Also adjusted WHOIS to mark zero-length responses with
ERR_ZERO_SIZE_OBJECT instead of default ERR_READ_ERROR. This affects
forwarded WHOIS transactions and AS number queries generated during
(re)configuration.

19 months agoReduce code duplication in ACLCertificateData::parse() (#1242)
Eduard Bagdasaryan [Sat, 28 Jan 2023 05:34:27 +0000 (05:34 +0000)] 
Reduce code duplication in ACLCertificateData::parse() (#1242)

ACLs ca_cert and user_cert already prohibit key changes. And
server_cert_fingerprint ACL only supports one option name spelling, so,
while "-sha1" is not, technically, a "key", it still cannot be
"changed". Adjust SetAclKey() (added in recent commit 4a3b853) and reuse
it to implement those existing "key change" checks.

20 months agoMerge MemImplementingAllocator and Mem::Allocator (#1211)
Amos Jeffries [Sat, 28 Jan 2023 01:40:22 +0000 (01:40 +0000)] 
Merge MemImplementingAllocator and Mem::Allocator (#1211)

20 months agoConvert MimeEntry to use RegexPattern API (#1233)
Amos Jeffries [Fri, 27 Jan 2023 20:04:05 +0000 (20:04 +0000)] 
Convert MimeEntry to use RegexPattern API (#1233)

Restore 318f2c8d3418a73946ae947d84f7696a381628b1
with modifications for current RegexPattern API.

20 months agoFix build with clang v15.0.6 [-Wunused-but-set-variable] (#1247)
gkinkie@gmail.com [Fri, 27 Jan 2023 14:43:41 +0000 (14:43 +0000)] 
Fix build with clang v15.0.6 [-Wunused-but-set-variable] (#1247)

clang v15.0.6 distributed with Fedora Rawhide complains about a variable
that is updated but never used:

    net_db.cc:230:9: error: variable 'removed' set but not used
    [-Werror,-Wunused-but-set-variable]`

20 months agoFix build with clang v15.0.6 [-Wdeprecated-non-prototype] (#1246)
gkinkie@gmail.com [Wed, 25 Jan 2023 15:00:42 +0000 (15:00 +0000)] 
Fix build with clang v15.0.6 [-Wdeprecated-non-prototype] (#1246)

clang v15.0.6 distributed with Fedora Rawhide complains about function
definitions using K&R style:

    lib/snmplib/mib.c:229:1: error: a function definition without a
    prototype is deprecated in all versions of C and is not supported in
    C2x [-Werror,-Wdeprecated-non-prototype]

20 months agoSource Format Enforcement (#1234)
squidadm [Sun, 22 Jan 2023 02:14:40 +0000 (02:14 +0000)] 
Source Format Enforcement (#1234)

20 months agoRemoved tcp-banger* and pconn-banger tools (#1236)
Amos Jeffries [Tue, 17 Jan 2023 02:19:01 +0000 (02:19 +0000)] 
Removed tcp-banger* and pconn-banger tools (#1236)

We do not have enough resources/demand for maintaining these tools, they
do require maintenance, and there are better tools available.

* tcp-banger2 is not built by default and probably could not be built at
  all since at least 2006 commit 5679212.

* tcp-banger3 lacked build rules since inception (1998 commit 2742510)
  and probably could not be built manually (by mimicking tcp-banger2
  build commands) without warnings since 2002 commit 88d8a2a.

* pconn-banger lacked build rules since inception (1997 commit eb5f55b)
  and probably could not be built manually since at least 2007 commit
  cc192b5.

* tcp-banger.pl has portability and code quality issues; its basic
  functionality is supported by squidclient, wget, curl, and others.

Co-authored-by: Alex Rousskov <rousskov@measurement-factory.com>
20 months agoMaintenance: Check for expected squid-conf-tests notifications (#1231)
Alex Rousskov [Mon, 16 Jan 2023 23:24:41 +0000 (23:24 +0000)] 
Maintenance: Check for expected squid-conf-tests notifications (#1231)

Sometimes, Squid must accept a configuration file while also logging a
WARNING or even an ERROR message. The new "expect-message" test case
instruction tells test-suite/test-squid-conf.sh to check for a given
expected message while still expecting configuration acceptance.

Two test cases (mgr_passwd.conf and time_units.conf) were enhanced. We
plan to use this feature in future tests already under development.

20 months agoMaintenance: Do not hide squid-conf-tests errors (#1227)
Alex Rousskov [Mon, 16 Jan 2023 20:28:49 +0000 (20:28 +0000)] 
Maintenance: Do not hide squid-conf-tests errors (#1227)

These "make installcheck" failures were ignored since commit 5992004.

20 months agoMove Namespace::Foo printing operators to Namespace (#1218)
Alex Rousskov [Sat, 14 Jan 2023 18:29:18 +0000 (18:29 +0000)] 
Move Namespace::Foo printing operators to Namespace (#1218)

... where C++ Argument-Dependent Lookup (ADL) can find them.

These specific printing operators did not encounter build problems yet,
but they were misplaced. See commit XXX for rationale and details.

Also removed unimplemented Mgr::ActionParams printing operator.

Also removed excessive "Namespace::" prefixes inside Namespace in
several printing operators declarations that were already properly
placed in their argument's namespaces (e.g., Ipc::ReadWriteLock).

No functionality changes expected.

20 months agoBug 5256: Intercepting port fails to accept (#1238)
Alex Rousskov [Fri, 13 Jan 2023 22:33:35 +0000 (22:33 +0000)] 
Bug 5256: Intercepting port fails to accept (#1238)

    ERROR: NF getsockopt(ORIGINAL_DST) failed on ... Bad file descriptor
    ERROR: NAT lookup failed to locate original IPs on ...

Ip::Interceptor.LookupNat() needs an open Connection, but commit 7185c9e
supplied a half-baked details object, resulting in ERRORs (showing a
closed connection -- no FD... field) for every otherwise successful
accept(2) attempt on an intercepting port.

Refactored oldAccept() to use exceptions for error handling and false
return result for no-error-but-no-connection cases (Comm::NOMESSAGE).
This refactoring allows us to centralize connection closing code instead
of chasing individual COMM_ERROR and NOMESSAGE cases while still missing
connection closure (if a function called by oldAccept() throws). With
connection closure handled, we can now open the details Connection
earlier, as we have done before commit 7185c9e, meeting current
LookupNat() and other/future code expectations.

Positive side effects of this fix include elimination of the following
old error reporting problems that left admins puzzled why Squid is not
handling new connections with no error messages in non-debugging
cache.log (and with the socket listening queue growing).

* Silent lack of accept() after an ENFILE or EMFILE failure.
* Silent lack of accept() if some function used by oldAccept() throws.
* Silent at level-0 lack of accept() after logging a level-1 ERROR. This
  problem was specific to ALL,0 and similar (rare) configurations.

20 months agoMaintenance: Consistent use of C++11 "override" specifier (#1224)
Alex Rousskov [Mon, 9 Jan 2023 21:12:02 +0000 (21:12 +0000)] 
Maintenance: Consistent use of C++11 "override" specifier (#1224)

Start following CppCoreGuidelines recommendation C.128: Virtual
functions should specify exactly one of virtual, override, or final.

Used clang-tidy modernize-use-override check to mark overridden methods.
Clang-tidy uses clang AST, so we can only modernize code that clang can
see, but we can enable enough ./configure options for clang to reach
most (possibly all) relevant classes in a single build.

Manual gradual conversion of modified (for other reasons) method
declarations is impractical because some compilers complain when a class
uses an inconsistent _mix_ of virtual and override declarations:

    warning: 'toCbdata' overrides a member function but is not marked
    'override' [-Winconsistent-missing-override]

### cbdata changes

The following manual changes avoid -Winconsistent-missing-override
warnings. Doing these separately, either before or after applying
modernize-use-override, would trigger those warnings.

* Replaced CbdataParent-CBDATA_CLASS with CbdataParent-CBDATA_CHILD
  class inheritance sequences. This fix does not really change anything
  except for making toCbdata() specifiers consistent.

* Replaced CbdataParent-CBDATA_CLASS-CBDATA_CHILD with
  CbdataParent-CBDATA_INTERMEDIATE-CBDATA_CHILD class inheritance
  sequences. This fix removes unused new/delete operators in
  intermediate classes (and associated unused static memory pools) and
  makes toCbdata() specifiers consistent. This fix was difficult to get
  right because of the old design problem discussed below.

While working on the second bullet changes, we first tried to simply
drop the intermediate CBDATA_CLASS sequence element because it should
never be needed/used in class hierarchies ending with CBDATA_CHILD.
Fortunately, CI tests discovered that dropping CBDATA_CLASS converts an
old design problem into runtime bugs: Those intermediate class
constructors (e.g., Mgr::StoreToCommWriter) actually call toCbdata()
when creating connection closure callbacks and such!

During intermediate constructor execution, the class virtual table does
not yet point to toCbdata() defined by CBDATA_CHILD. If we simply remove
CBDATA_CLASS, then, during that intermediate constructor execution, the
virtual table would still point to pure CbdataParent::toCbdata(). Those
intermediate constructors would then crash Squid:

    FATAL: Dying from an exception handling failure;
    exception: [no active exception]

    in OnTerminate () at main.cc:1310
    in std::terminate() () from libstdc++.so.6
    in __cxa_pure_virtual () from libstdc++.so.6
    in CbcPointer<Mgr::StoreToCommWriter>::CbcPointer at CbcPointer.h:94
    in Mgr::StoreToCommWriter::StoreToCommWriter at ...oCommWriter.cc:29

We now use lighter CBDATA_INTERMEDIATE() instead of intermediate
CBDATA_CLASS. The resulting code is as risky as it used to be, but at
least we are marking this (old) design problem (in some cases).

We rejected the idea of defining CbdataParent::toCbdata() instead. It
would work fine for linear class inheritance where "this" does not
change -- in those simple class hierarchies, we do not need toCbdata()!
However, such a change would make any constructor-time bugs in multiple
inheritance hierarchies much more difficult to find because the faulty
constructor will work instead of triggering the above FATAL error. The
crashes would happen later, when wrong cbdata pointer is used. While
CBDATA_INTERMEDIATE() cannot fix this design problem, it does not make
it _worse_, so we prefer that solution.

20 months agoWarn about some bad from-helper annotations (#1221)
Alex Rousskov [Sun, 8 Jan 2023 12:43:48 +0000 (12:43 +0000)] 
Warn about some bad from-helper annotations (#1221)

From-helper annotations may belong to one or more of the following
(partially overlapping) categories:

* A1: Annotations with a name ending with an underscore. Those
  annotations are reserved for admin use. Example: "category_".

* A2: Annotations that this Squid version knows about and treats
  specially. Example: "clt_conn_tag".

* B1: Annotations that this Squid version does not know about at all.
  Future Squids may start using them specially. Example: "detail".

* B2: Annotations unused by this Squid build. Example: Squid
  ./configured with --disable-auth does not use "user" and "password"
  annotations received from an external ACL helper.

* B3: Annotations incompatible with the current helper response
  type/kind. Example: Digest authentication code does not use "ha1"
  annotation in ERR responses received from digest authentication
  helpers.

* B4: Annotations with repeated names (the first of them will be used).
  Example: "user" in OK replies from negotiate authentication helpers.

Warn about received helper annotations in the B1 category.

It is possible to also warn about B2 and B3 annotations, but several
draft implementations imply that such an improvement requires complex
code changes that may also increase Squid code maintenance overheads.

Warning about B4 annotations is not that difficult, but we must decide:

* Whether custom repeated annotation are actually bad (and should be
  reported or even ignored).

* Whether Squid-recognized repeated annotations are bad enough to
  warrant the decreased performance and increased code complexity that
  reporting them would require. In other words, do we want to penalize
  good helpers that do _not_ send any repeated Squid-recognized
  annotations (except, perhaps, "message") to warn about bad helpers
  that do?

20 months agoRemove bundled GnuRegex library (#1229)
gkinkie@gmail.com [Sun, 8 Jan 2023 00:10:31 +0000 (00:10 +0000)] 
Remove bundled GnuRegex library (#1229)

Modern operating systems provide a functioning regex
library, so we don't need to carry one anymore.

20 months agoFix ./configure --enable-poll and --disable-poll (#1228)
Alex Rousskov [Sat, 7 Jan 2023 00:27:12 +0000 (00:27 +0000)] 
Fix ./configure --enable-poll and --disable-poll (#1228)

    ./configure: line 42685: xyes: command not found
    ./configure: line 42685: xno: command not found

Since commit a1c2236, these options triggered errors messages above, and
--enable-poll did not affect syscall selection for the I/O loop:

    ./configure --enable-poll
    configure: Using epoll for the IO loop.

20 months agoLog the number of request sending attempts (#541)
Eduard Bagdasaryan [Fri, 6 Jan 2023 20:32:17 +0000 (20:32 +0000)] 
Log the number of request sending attempts (#541)

Squid retries certain request forwarding failures. When the problem is
persistent, and there are many peers (or the origin server has many
IPs), many retries are possible. Absence of Squid-server transaction log
hides these retries from admins. The new logformat code helps discover
and triage problems, especially when Squid retries many times.

20 months agoMaintenance: Updated CONTRIBUTORS (#1225)
Alex Rousskov [Wed, 4 Jan 2023 18:53:30 +0000 (18:53 +0000)] 
Maintenance: Updated CONTRIBUTORS (#1225)

This change is a reference point for automated CONTRIBUTORS updates.

20 months ago%busy_time: Time spent in transaction-related code (#1216)
Alex Rousskov [Tue, 3 Jan 2023 12:20:27 +0000 (12:20 +0000)] 
%busy_time: Time spent in transaction-related code (#1216)

Configuration tuning, problems triage, and performance optimization
often benefit from knowing how much time Squid spent on a particular
transaction (or a typical transaction in a category like "cache hits").

We already log total transaction response time (%tr), but that time
includes transaction queuing time (i.e. the time when Squid could
advance our transaction but was advancing other transactions) and
various waiting periods (e.g., waiting for a helper response). The new
measurement focuses on time periods when Squid was actively working on
(as in "was blocked on") our transaction.

CodeContext coverage problems do affect this measurement, but the
existing coverage is already good enough for usable measurements in some
cases, and it is getting better. It will take us a long time to cover
all cases; we should not wait for that to happen (as long as we warn
admins about these problems).

20 months agoMaintenance: source maintenance script improvements (#1220)
gkinkie@gmail.com [Fri, 30 Dec 2022 18:07:12 +0000 (18:07 +0000)] 
Maintenance: source maintenance script improvements (#1220)

- Allow passing astyle program name via ASTYLE environment variable.
- By default, use "astyle-3.1" if present or "astyle" otherwise.
- Add an option to format changed source files only.

No changes to the default behavior except for environments where a
program named "astyle-3.1" is present but a program named "astyle" was
previously used.

20 months agoFix errorpage.cc build on MacOS (#1219)
gkinkie@gmail.com [Wed, 28 Dec 2022 13:38:35 +0000 (13:38 +0000)] 
Fix errorpage.cc build on MacOS (#1219)

    errorpage.cc:153:44: error: implicit instantiation of undefined
    template std::array<HardCodedError, 7> HardCodedErrors

21 months agoFix ./configure --with-filedescriptors=NUMBER (#1217)
Alex Rousskov [Sat, 24 Dec 2022 17:00:32 +0000 (17:00 +0000)] 
Fix ./configure --with-filedescriptors=NUMBER (#1217)

Commit a1c2236 forgot to quote AS_CASE argument of AC_ARG_WITH(),
resulting in the following ./configure-time errors:

    error: --with-filedescriptors expects a numeric argument

We now quote AS_CASE argument of AC_ARG_WITH(), as recommended by
Autoconf and for consistency sake. More (hopefully automated) work is
needed to quote all function call arguments (that should be quoted).

Also use m4 quadrigraphs for quoting safety sake and to attract readers
attention to a risky (from writing in m4 point of view) expression. This
particular improvement is not required to fix the bug.

The other two AC_ARG_WITH() are modified for consistency sake but they
were not broken and their compiled versions have not changed.

21 months agoFix GCC v12 build errors related to ADL in "printing" code (#1215)
Alex Rousskov [Thu, 22 Dec 2022 02:12:12 +0000 (02:12 +0000)] 
Fix GCC v12 build errors related to ADL in "printing" code (#1215)

This change contains three fixes/adjustments described below.

### Fix Store::SwapMetaView printing

    src/sbuf/Stream.h:66:20: error: no match for 'operator<<' (operand
    types are 'std::basic_ostream<char>' and 'const
    Store::SwapMetaView'): (out << ... << args);

Disclaimer: This explanation omits many details that become important in
some other contexts. Most Argument-Dependent Lookup details are
documented at https://en.cppreference.com/w/cpp/language/adl

    // In some printer.h, we define a printing function for any type A.
    // This is similar to an ToSBuf() declaration in sbuf/Stream.h.
    template <typename A>
    void print(ostream &os, const A &argument) { os << argument; }

    // In some n/t.h, we define how to print objects of type N::T.
    // This is similar to store/SwapMetaView.h.
    operator <<(ostream &os, const N::T &argument);

    // In some caller1.cc, we include both headers and call print():
    #include "printer.h"
    #include "n/t.h"
    void caller1(const N::T &argument) { print(std::cout, argument); }

    // In some caller2.cc, we do the same but change #include order:
    #include "n/t.h"
    #include "printer.h"
    void caller2(const N::T &argument) { print(std::cout, argument); }

When looking at "os << argument", the compiler considers two sets of
argument printing operators, formed by the following two sources:

* The usual unqualified name lookup. This set includes N::T printing
  operator if that operator is declared in global namespace somewhere
  above the print() _template declaration_. In the example above, only
  caller2() will have that printing operator in this set, provided that
  operator is declared in global namespace (as it used to be). None of
  the callers will have that printing operator in this set otherwise.

* ADL. This set is computed from the caller point of view. It includes
  N::T printing operator if that operator is declared inside namespace N
  somewhere above the print() _caller_. In the example above, both
  caller1() and caller2() will have that printing operator in this set,
  provided that operator is declared in namespace N (as it is now). None
  of the callers will have that printing operator in this set otherwise.

For code to compile, one of the sets must contain the printing operator.
Given the above outcomes, there is only one sane solution that allows
any caller to instantiate print() with an N::T argument: The argument
printing operator must be declared inside namaspace N! Declaring in
global namespace would require maintaining certain #include order (that
will cause headaches and, eventually, circular dependencies).

In other words, we must rely on ADL, and that means declaring operators
in the namespace of one of their argument types.

### Fix std::optional<Ip::Address> printing (in src/icap/Xaction.cc)

    src/base/AsyncJobCalls.h:115:61: error: no match for 'operator<<'
    (operand types are 'std::basic_ostream<char>' and 'const
    std::optional<Ip::Address>'):
    void print(std::ostream &os) const { os << '(' << arg1 << ')'; }

In this context, both printing operator argument types are in std, but
ADL also looks at template parameters of argument types (if an argument
type is a template). That recursion adds the Ip namespace to the search.

This is a minimal fix. We should move both Ip::Address printers into
ip/print.h or similar, away from Ip::Address users that print nothing.

### Do not declare an overly general std::optional printer

The removed declaration:

* evidently became unused (after the other changes described above);
* places std::optional<N::T> printers in the wrong namespace (global
  instead of N), where ADL cannot find them;
* exposes all I/O manipulators to a, technically, unrelated
  std::optional interface.

Co-authored-by: Amos Jeffries <squid3@treenet.co.nz>
21 months agoSupport "negative" squid-conf-tests (#1214)
Alex Rousskov [Tue, 20 Dec 2022 15:41:40 +0000 (15:41 +0000)] 
Support "negative" squid-conf-tests (#1214)

The test suite can now check that Squid rejects a given malformed
configuration file and that the rejection reason matches the expected
one. The latter reduces the probability that a successful "negative"
test outcome would hide a bug (because Squid has rejected a malformed
file but for a reason unrelated to what the test was trying to verify).

For now, enable just one acl regex test case, addressing an old TODO.

To improve "negative" test coverage, we would need to generate test
configurations using a configuration template and a list of problematic
expressions (with corresponding failure messages), but this hard-coded
approach is already better than nothing.

21 months agoRequire C++17 (#1212)
Alex Rousskov [Tue, 13 Dec 2022 23:17:48 +0000 (23:17 +0000)] 
Require C++17 (#1212)

Modern environments support C++17 well. We are wasting significant
amounts of time on emulating such basic C++17 features as std::optional.
We are writing worse code than we can because we lack access to such
C++14 and C++17 features like std::make_unique and std::byte.

The following language-standard-dependent TODOs were completed:

* Switched to [[fallthrough]] attributes.
* Replaced Optional with std::optional.
* Replaced EnableIfType with std::enable_if_t.
* Removed old C++11 type replacements (e.g., xuniform_int_distribution).
* Removed std::allocator declarations deprecated in C++17.
* Made ToSBuf() readable using a fold expression.
* Simplified compile-time "natural type" assertions.
* Used std::container::emplace*() return value where warranted.

Moved BUILDCXX-setting code after AX_CXX_COMPILE_STDCXX adds -std=c++17
to CXX (rather than CXXFLAGS!). Our cf_gen was built with compiler's
default C++ standard version! Ideally, BUILDCXX block should be lowered
further -- other macros might alter CXX -- but its CXXFLAGS adjustment
may affect subsequent code, warranting a careful/dedicated change.

21 months agoBan acl key changes in req_header, rep_header, and note ACLs (#1210)
Alex Rousskov [Mon, 12 Dec 2022 13:34:12 +0000 (13:34 +0000)] 
Ban acl key changes in req_header, rep_header, and note ACLs (#1210)

* req_header and rep_header ACLs; the key is the header-name argument:

    acl barred req_header X-1 bar
    acl barred req_header X-2 bar # never matches since commit a0b240c
    http_access deny barred

* the "note" ACL; the key is the annotation name argument:

    acl banned note color green  # never matches since commit 39baccc
    acl banned note weight heavy
    http_access deny banned

Squid did write a cache.log ERROR for req_header/rep_header key changes
but was silent about the preceding "note" ACL rules being ineffective
after a key change (e.g., Squid was not denying "green" requests above).

Now, Squid rejects configurations containing such ACL key changes.

Also significantly reduced the corresponding parsing code duplication.

21 months agoFix ACL type typo in req_header, rep_header key-changing ERRORs (#1208)
Alex Rousskov [Sat, 10 Dec 2022 14:18:18 +0000 (14:18 +0000)] 
Fix ACL type typo in req_header, rep_header key-changing ERRORs (#1208)

21 months agoext_kerberos_ldap_group_acl: Support -b with -D (#1207)
Alexander Bokovoy [Sat, 10 Dec 2022 11:50:27 +0000 (11:50 +0000)] 
ext_kerberos_ldap_group_acl: Support -b with -D (#1207)

When both '-b' (i.e. bind DN) and '-D' (i.e. Kerberos domain) options
are specified, '-b' is ignored completely. This breaks the helper when a
search subtree has to be limited (e.g., when using FreeIPA).

Fix it to take '-b' into account if it was specified with '-D'.

21 months agoUpdate LruNode to MEMPROXY_CLASS (#1206)
Amos Jeffries [Fri, 9 Dec 2022 21:54:31 +0000 (21:54 +0000)] 
Update LruNode to MEMPROXY_CLASS (#1206)

21 months agosquid-conf-tests should test installed Squid (#1204)
Alex Rousskov [Fri, 9 Dec 2022 11:51:39 +0000 (11:51 +0000)] 
squid-conf-tests should test installed Squid (#1204)

    FATAL: ..._inst/etc/mime.conf: (2) No such file or directory
    FATAL: ..._inst/share/icons: (2) No such file or directory

Our squid-conf-tests are running "squid -k parse" that requires icons
and other supplementary files to be _installed_. Thus, squid-conf-tests
must run during "make installcheck" rather than during "make check".

With this change, "make distcheck" triggers squid-conf-tests at the
right time, after "all", "check", and "install" targets are built.
Also, we are now testing installed Squid binaries, as we should.

21 months agoUpdate Host, Via, and other headers in-place when possible (#1203)
Eric Walters [Fri, 9 Dec 2022 05:58:43 +0000 (05:58 +0000)] 
Update Host, Via, and other headers in-place when possible (#1203)

This change optimizes Host header synchronization code that usually does
not need to change the Host header field but was always deleting the old
field and generating/appending a new one. Appending Host also violated
an RFC 9110 section 7.2 rule (on behalf of the user agent whose Host we
were rewriting): "A user agent that sends Host SHOULD send it as the
first field in the header section".

Also, removing old header fields and appending new ones introduced HTTP
header changes that broke otherwise working peers. For example, some
origins denied Squid-proxied messages exclusively due to an unusual
(from those origins point of view) Host header position. This change
reduces (but does not eliminate) such unnecessary and risky changes.

21 months agoFix helper module auto-detection algorithm (#1194)
Amos Jeffries [Fri, 9 Dec 2022 01:08:03 +0000 (01:08 +0000)] 
Fix helper module auto-detection algorithm (#1194)

Two issues here causing no helpers to be detected as buildable when
./configure parameters are missing entirely (eg "./configure ").
These were not detected by our build farm because missing helpers
is not an error, they are optional, and we lack tests validating
optional helpers.

1) Over-escaping of "$" variable prefix (M4 "$$" expands to "$")
   prevented the path string being expanded to correct value for
   the helper directory test. Causing it to always fail.

2) The $ac_top_srcdir variable internal to autoconf may not be set
   at the time AC_DEFUN macros are expanded. Making it unreliable.
   The $top_srcdir variable which should be used instead has the
   same problem with "top" not yet being determined. As such we
   use $srcdir instead and hope it expands correctly at ./configure
   run time.

21 months agoDo not overwrite caching bans (#1189)
Alex Rousskov [Thu, 8 Dec 2022 08:25:44 +0000 (08:25 +0000)] 
Do not overwrite caching bans (#1189)

To ban caching, Squid made RequestFlags::cachable false in several
places (e.g., when a "cache deny" rule matched). To permit caching,
Squid also made the flag true in several places (e.g., when
maybeCacheable() was true). That combination worked as intended only
when the cachable=false veto always came after all the cachable=true
support votes. The code did not (and should not) enforce such a
complicated/fragile timing invariant.

Squid now correctly honors caching bans regardless of the updates order.

This change addresses an old XXX, but we are not aware of any specific
bugs fixed by this change. The primary purpose of this change is to make
the existing baseline ban-honoring functionality easy to maintain.

Also reduced code duplication across cachable=false,noCache=true code.

21 months agoSource Format Enforcement (#1201)
squidadm [Thu, 8 Dec 2022 02:50:15 +0000 (02:50 +0000)] 
Source Format Enforcement (#1201)

21 months agoFix regression test configuration (#1198)
Eduard Bagdasaryan [Wed, 7 Dec 2022 20:15:17 +0000 (20:15 +0000)] 
Fix regression test configuration (#1198)

The regressions-3.4.0.1 configuration produces an error message:

    ERROR: Can not open file empty for reading

Broken since commit 6c9a5e8 that renamed "empty" to "empty.conf".

21 months agoOptimize RefCount comparison with raw pointers (#1200)
sameer-here [Wed, 7 Dec 2022 17:27:47 +0000 (17:27 +0000)] 
Optimize RefCount comparison with raw pointers (#1200)

GCC v12 and Clang v12 tests show that compilers cannot avoid creating
temporaries when comparing RefCount objects with arbitrary pointers.

Also fixes (not yet supported) C++20 build. C++20 automatically reverses
equality comparisons, triggering an ambiguity:

    src/esi/Esi.cc:1920:26: error: ambiguous overload for 'operator=='
        (operand types are 'ESISegment::Pointer' {aka
        'RefCount<ESISegment>'} and std::nullptr_t)
        assert (output->next == nullptr);

    src/esi/Esi.cc:77:6: note: candidate: 'bool operator==(const
        ESIElement*, const Pointer&)' (reversed)

    src/base/RefCount.h:82:10: note: candidate: 'bool
        RefCount<C>::operator==(const RefCount<C>&) const [with C =
        ESISegment]'

21 months agoDrop CBDATA debugging (#1199)
Amos Jeffries [Mon, 5 Dec 2022 15:52:26 +0000 (15:52 +0000)] 
Drop CBDATA debugging (#1199)

This was occasionally (but still rare) useful when CBDATA was the
only method of passing callback parameters. Much of that has now
been replaced with AsyncJob/AsyncCall logic. Making this debug
much less useful.

Remove the --enable-debug-cbdata build option and two cache manager
reports only enabled when that option is built. Greatly reducing
the cbdata logic complexity and removing one of its five APIs
permutations entirely.

21 months agoAvoid level-3 "failed to find or read error text file" WARNINGs (#1176)
Eduard Bagdasaryan [Sun, 4 Dec 2022 22:00:20 +0000 (22:00 +0000)] 
Avoid level-3 "failed to find or read error text file" WARNINGs (#1176)

... when (re)configuring ERR_REQUEST_PARSE_TIMEOUT and ERR_RELAY_REMOTE
error templates. These errors cannot be customized externally and should
have been listed as such in commits 9ce4a1e and f5e1794, respectively.

Also polished hard-coded error storage code.

21 months agobasic_ncsa_auth: Fix missing libnettle dependency (#1193)
Amos Jeffries [Fri, 2 Dec 2022 14:11:22 +0000 (14:11 +0000)] 
basic_ncsa_auth: Fix missing libnettle dependency (#1193)

Broken since b12b66cdd75835c6fb92bf25c2f68272f55d21cd

21 months agokerberos_ldap_group: fix unused variable warnings (#1192)
Amos Jeffries [Fri, 2 Dec 2022 09:11:39 +0000 (09:11 +0000)] 
kerberos_ldap_group: fix unused variable warnings (#1192)

When built with disabled LDAP support.

21 months agoRefactor memory pools statistics gathering (#1186)
Amos Jeffries [Fri, 2 Dec 2022 05:02:44 +0000 (05:02 +0000)] 
Refactor memory pools statistics gathering (#1186)

21 months agoBug 5162: mgr:index URL do not produce MGR_INDEX template (#1191)
Eduard Bagdasaryan [Thu, 1 Dec 2022 18:50:37 +0000 (18:50 +0000)] 
Bug 5162: mgr:index URL do not produce MGR_INDEX template (#1191)

Satisfy mgr:index requests using

* a 200 OK response with a body derived from the MGR_INDEX template (if
  that template file was found during (re)configuration) or
* a 404 (Not Found) error response (otherwise).

Broken in 2019 commit 7e6eabb, when Squid started replying using a 200
OK response with a hard-coded "mgr_index" text as a body, ignoring any
configured MGR_INDEX template.

21 months agoMake Optional<bool> trivially copyable (#1188)
Alex Rousskov [Thu, 1 Dec 2022 05:49:57 +0000 (05:49 +0000)] 
Make Optional<bool> trivially copyable (#1188)

    ipc/TypedMsgHdr.h: static assertion failed: putPod() used for a POD
    ActionParams.cc:44: required from here [with Pod = RequestFlags]

The known XXX in Optional destructor has started to bite us because
pending changes expose memcpy(3)-based IPC serialization code to
Optional<bool> flags. It is possible to mimic standard std::optional
implementations, avoiding that XXX, but that requires rather
sophisticated C++ tricks with placement new() and such. Specializing the
whole Optional is a better alternative for this _temporary_ class IMO.

21 months agoMaintenance: Missing squid.h include (#1190)
Alex Rousskov [Wed, 30 Nov 2022 18:09:02 +0000 (18:09 +0000)] 
Maintenance: Missing squid.h include (#1190)

Broken since inception (i.e. master/v6 commit 4a28fc5).
Detected by scripts/source-maintenance.sh.

21 months agoCI: Test handling of truncated responses (#1187)
Alex Rousskov [Tue, 29 Nov 2022 02:57:15 +0000 (02:57 +0000)] 
CI: Test handling of truncated responses (#1187)

Use Daft truncated-responses test to monitor for bugs like those fixed
by master/v6 commit ba3fe8d.

21 months agoShuffle MemAllocator to Mem namespace (#1181)
Amos Jeffries [Mon, 28 Nov 2022 14:46:51 +0000 (14:46 +0000)] 
Shuffle MemAllocator to Mem namespace (#1181)

Update and add missing documentation for class members.

Update syntax to latest standard compliance and Squid
coding guideline style.

22 months agoMove MemPoolMeter into Mem namespace (#1183)
Amos Jeffries [Thu, 24 Nov 2022 00:17:11 +0000 (00:17 +0000)] 
Move MemPoolMeter into Mem namespace (#1183)

Simplified PoolMeter::flush() implementation
and inlined it for performance.

Convert mgb_t type to a sub-struct and inline
C++11 initialization for performance.

Also update Mem::Meter initialization.

22 months agoRemove Mem::Report() and polish memory_pools_limit storage (#1184)
Amos Jeffries [Mon, 21 Nov 2022 05:20:32 +0000 (05:20 +0000)] 
Remove Mem::Report() and polish memory_pools_limit storage (#1184)

The official code should not call Mem::Report(). There is no
justification for main.cc treating memory module in such a
special way. The reporting code itself has problems.
Removing all this code is better than leaving or polishing it.

22 months agoDo not blame cache_peer for 4xx CONNECT responses (#1166)
Eduard Bagdasaryan [Sun, 13 Nov 2022 16:00:21 +0000 (16:00 +0000)] 
Do not blame cache_peer for 4xx CONNECT responses (#1166)

To avoid using a problematic cache_peer, Squid penalizes cache_peers for
a variety of problems. However, a problem like an HTTP 403 Forbidden
response may be caused by the client or other factors unrelated to the
cache_peer that sent the response to Squid. In those cases, the
cache_peer is not at fault and should not be marked dead, even after
many such responses.

This change stops blaming cache_peers for HTTP 4xx outcomes of Squid
CONNECT requests. Currently, such outcomes only happen when a cache_peer
responds with a 4xx reply, but the new code also treats Squid-generated
4xx error responses (while trying to establish a connection to the
cache_peer) the same way.

This hard-coded logic covers known use cases. If different use cases
surface, we can make Squid behavior configurable.

Co-authored-by: Amos Jeffries <squid3@treenet.co.nz>
22 months agoRemove --enable-kill-parent-hack (#1178)
Amos Jeffries [Thu, 10 Nov 2022 05:56:30 +0000 (05:56 +0000)] 
Remove --enable-kill-parent-hack (#1178)

This feature has been deprecated for some time.

The useful functionality can more safely be implemented in the parent
script by using the --foreground command line option and waiting for
the Squid process to exit.

It has always been labeled dangerous as the parent process can be
PID 1 or some other vital system process than the intended
RunCache script. Currently it breaks SMP support for manually
killing a single worker or disker process.

22 months agoSort CA certificates in tls-cert=bundle (#1177)
Alex Rousskov [Thu, 10 Nov 2022 02:01:29 +0000 (02:01 +0000)] 
Sort CA certificates in tls-cert=bundle (#1177)

... as opposed to requiring the bundle to contain CA certificates in the
correct on-the-wire/issuing order and warning about (and then ignoring)
out-of-order bundled certificates.

This enhancement makes it easier to configure Squid to send the right
intermediate certificates, especially during certificate upgrades when
intermediate certificates (which may be obtained from a source not
tightly coordinated with the signing certificate source) is likely to
contain a mix of old and new intermediate certificates.

Squid has to (and did) check the certificate issuing order anyway. The
new code uses very similar checks to sort intermediate certificates.

No on-the-wire changes expected for Squid configurations that have
correctly ordered certificate bundles. Other configurations may start
sending the previously missing intermediate certificates.

22 months agoImprove cache_peer reporting and NetDB cache_peer search (#1174)
Alex Rousskov [Wed, 9 Nov 2022 21:29:33 +0000 (21:29 +0000)] 
Improve cache_peer reporting and NetDB cache_peer search (#1174)

Squid used several cache_peer configuration components and CachePeer
fields to identify cache peers in code and cache.log messages: (the
lowercase version of) cache_peer hostname, cache_peer (hostname,
http_port) tuple, and cache_peer name=value (which uses cache_peer
hostname by default).

Inconsistent identification led to admin confusion (e.g., a message
about cache_peer A was misinterpreted as being about cache_peer B) and
bugs (e.g., indexing storage by component X, but searching using
component Y). This change cements a single component as a unique
cache_peer identifier: CachePeer::name.

Also reject configurations with cache_peer naming errors in
cache_peer_access and neighbor_type_domain directives (instead of
reporting but otherwise ignoring the problematic configuration lines).

The following CachePeer reporting principles were used:

* To identify a specific cache_peer p (among all the configured ones) in
  a cache.log message, print that peer (i.e. use `os << *p` or
  equivalent). CachePeer printing code will print that peer name, which
  is guaranteed to be unique across all configured cache_peers.

* After identifying a cache_peer, do not dump its various details like
  ICP port numbers, especially when they are not relevant to the message
  (i.e. provide no useful context-related information going beyond that
  cache_peer identification).

The following bugs were fixed:

* NetDB code is storing cache_peer hostname[1] but was searching for a
  cache_peer with a matching name[2] and, hence, usually failing to find
  explicitly named cache_peers. Probably broken since 2003 commit
  be75332 that added name=value support and updated peerFindByName() to
  use CachePeer::name but left storage code[1] unchanged.

    [1] netdbPeerAdd(): p->peername = netdbPeerName(e->host);
    [2] netdbClosestParent(): p = peerFindByName(h->peername);

* netdbClosestParent() could not find the closest cache_peer in certain
  cases involving multiple cache_peers with the same hostname because
  the code incorrectly stopped looking for eligible same-hostname
  cache_peers after correctly discarding the first one.

  The above NetDB problems may imply that NetDB code needs to be
  refactored to store CachePeer pointers instead of CachePeer hostnames,
  but that serious change deserves more analysis (and a dedicated PR).

* cache_peer name=value configurations with empty/missing name value
  could dereference a null name pointer while misleading developers into
  thinking that a previously set name could be erased/forgotten. Squid
  now rejects such configurations.

* neighborIgnoreNonPeer() was allocating CachePeer::host using new() but
  ~CachePeer is freeing its host data member using xfree().

Also removed peerFindByNameAndPort() unused since inception at db1cd23.

22 months agoCI: Assume recent CI fixes make busy-restart test stable (#1172)
Alex Rousskov [Sat, 29 Oct 2022 20:09:53 +0000 (20:09 +0000)] 
CI: Assume recent CI fixes make busy-restart test stable (#1172)

22 months agoCI: Fix support for running a subset of GitHub Actions tests (#1171)
Alex Rousskov [Mon, 24 Oct 2022 03:18:06 +0000 (03:18 +0000)] 
CI: Fix support for running a subset of GitHub Actions tests (#1171)

The scripts were always running all/default tests instead of those named
on the command line (if any). Broken since inception in commit 2ed8cc4.

23 months agoMimic GET reforwarding decisions when our CONNECT fails (#1168)
Eduard Bagdasaryan [Sat, 22 Oct 2022 19:44:50 +0000 (19:44 +0000)] 
Mimic GET reforwarding decisions when our CONNECT fails (#1168)

Use FwdState::reforwardableStatus() logic when deciding whether to
reforward our CONNECT request after a failed tunneling attempt.

Also honor forward_max_tries limit when retrying tunneling attempts.

These TunnelStateData fixes deal with ordinary CONNECT traffic (no
SslBump). FwdState also handles CONNECT requests (with SslBump). We make
that CONNECT handling more consistent across these classes (in addition
to making it more consistent across CONNECT and GET/etc. methods).

Co-authored-by: Alex Rousskov <rousskov@measurement-factory.com>
23 months agoMaintenance: Drop an unused, misleading condition (#1169)
Alex Rousskov [Fri, 21 Oct 2022 15:57:49 +0000 (15:57 +0000)] 
Maintenance: Drop an unused, misleading condition (#1169)

According to Autoconf NEWS, AC_USE_SYSTEM_EXTENSIONS is defined with
AC_DEFUN_ONCE since Autoconf v2.63b: "This means a subtle change in
semantics; previously, an AC_DEFUN macro could expand [this macro]
multiple times or surround the macro inside shell conditional text to
bypass [its] effects, but now the macro will expand exactly once, and
prior to the start of any enclosing AC_DEFUN macro".

In the generated ./configure script, the if statement no longer had any
code inside it, and AC_USE_SYSTEM_EXTENSIONS was unconditionally
expanded above the if statement.

23 months agoFix milliseconds in certain cache.log messages (#1167)
Eduard Bagdasaryan [Wed, 19 Oct 2022 12:52:47 +0000 (12:52 +0000)] 
Fix milliseconds in certain cache.log messages (#1167)

This change fixes two bugs:

1. The milliseconds part of an early message time was wrong because
   debugLogTime() got it from the current_time global instead of the
   saved message timestamp. This problem probably affected only early
   saved messages in rare situations where current_time was updated
   between message creation and message writing. This fix adjusts
   DebugMessageHeader::timestamp to store message time with microsecond
   precision.

2. Level-0/1 messages that followed same-second level-2+ messages were
   logged with an unwanted (and stale) milliseconds value. This fix
   forces a reset of the message line format buffer in relevant cases.

23 months agoCI: Install all known dependencies for test-builds.sh on GitHub (#1162)
Amos Jeffries [Mon, 17 Oct 2022 17:27:07 +0000 (17:27 +0000)] 
CI: Install all known dependencies for test-builds.sh on GitHub (#1162)

The apt-get build-dep trick makes us dependent on Ubuntu decisions, but
it saves us work, and we can always add more dependencies manually if we
discover holes in the Ubuntu-maintained list.

Co-authored-by: Alex Rousskov <rousskov@measurement-factory.com>
23 months agoBug 5241: Block all non-localhost requests by default (#1164)
Alex Rousskov [Mon, 17 Oct 2022 13:22:34 +0000 (13:22 +0000)] 
Bug 5241: Block all non-localhost requests by default (#1164)

This change goes one step further than commit 6d2f8ed in satisfying the
same "by default, introduce no new attack vectors" principle.

Commit 6d2f8ed blocked access to localhost and to-link-local services
but still allowed access to potentially vulnerable popular cloud
instance metadata services running on site-local IPv6 addresses. It also
still allowed external access to localnet services that could be
completely unprepared for such dangers! This change closes those holes.

This default configuration has two extra deny rules. These rules become
necessary only when the admin adds an "http_access allow" rule below
them. We enabled these rules despite their overheads, including more DNS
queries in some environments, so that the admin does not have to
remember to enable them when following our "INSERT...HERE" instructions.

23 months agoFix ./configure detection of various LDAP functions (#1163)
Alex Rousskov [Sun, 16 Oct 2022 21:59:28 +0000 (21:59 +0000)] 
Fix ./configure detection of various LDAP functions (#1163)

Commit 0d57ed2 started using $LIBLDAP_LIBS as AC_CHECK_LIB() argument,
but that does not work because AC_CHECK_LIB() expects a library name (X)
rather than a linker option (-lX). The macro adds a "-l" prefix itself:

    checking for ldap_url_desc2str in -l-lldap -llber... no
    checking for ldap_url_parse in -l-lldap -llber... no
    checking for ldap_start_tls_s in -l-lldap -llber... no

23 months agoAvoid negative test-builds.sh results due to lack of LDAP (#1158)
Alex Rousskov [Tue, 11 Oct 2022 15:29:42 +0000 (15:29 +0000)] 
Avoid negative test-builds.sh results due to lack of LDAP (#1158)

    TESTING: layer-02-maximus
    BUILD: test-suite/buildtests/layer-02-maximus.opts
    configure: error: Required library ldap not found

Broken by commit 0d57ed2.

23 months agoBug 5241: Block to-localhost, to-link-local requests by default (#1161)
Alex Rousskov [Mon, 10 Oct 2022 23:07:02 +0000 (23:07 +0000)] 
Bug 5241: Block to-localhost, to-link-local requests by default (#1161)

Squid suggested blocking to-localhost access since 2001 commit 4cc6eb1.
At that time, the default was not adjusted because some use cases were
known to require to-localhost access. However, the existence of special
cases should not affect defaults! The _default_ configuration should
either block all traffic or only allow traffic that is unlikely to
introduce new attack vectors into the network.

Also block to-link-local traffic (by default), for very similar reasons:
Popular cloud services use well-known IPv4 link-local (i.e. RFC 3927)
addresses (a.k.a. APIPA), to provide sensitive instance metadata
information, via HTTP, to instance users and scripts. Given cloud
popularity, those special addresses become nearly as ubiquitous as
127.0.0.1. Cloud provider networks shield metadata services from
external accesses, but proxies like Squid that forward external HTTP
requests may circumvent that protection.

23 months agoStart using Github Actions for CI tests (#1160)
Alex Rousskov [Mon, 10 Oct 2022 04:24:22 +0000 (04:24 +0000)] 
Start using Github Actions for CI tests (#1160)

This change imports existing Sempaphore CI functionality test harness
and migrates it to Github Actions. Using a stand-alone harness offered
many advantages, but that approach goes against the current custom of
importing CI configurations into being-tested repositories. Semaphore CI
itself switched to such invasive configurations since v2. We have to
start using invasive CI configurations to be able to evolve Squid CI and
solve known CI problems.

While importing the test harness, we made basic CI functionality tests
available from the command line so that developers can run them even
before submitting a PR and while addressing reviewer concerns. They do
require internet access because the tests are downloaded from GitHub,
but they avoid permanent service installations in developer environment.
The tests do create/overwrite logs and start services like Squid. A lot
more work is still required to make these tests user friendly.

The new test configuration/harness consists of two primary parts:

* Github Actions "workflow" configuration, including embedded scripts.
* Various test scripts used by the "workflow" configuration above.

There are many ways to split the test harness among those two parts.
This particular split is based on these split-specific principles/ideas:

1. When running tests locally, developers do not want to risk
   disruptive, permanent, potentially dangerous actions such as globally
   installing new packages or overwriting checked out Squid sources.
   These actions belong to the workflow configuration file that is only
   interpreted by Github Actions, on Github virtual machines. The test
   scripts have only one sudo command (to start a Squid manipulating
   agent as nobody) which is bypassed of the agent is already running.

2. Developers should be able to repeat basic tests from the command
   line, against their version of Squid sources, their Squid builds, and
   without learning the ever-changing testing details. If their PR has
   failed a CI test, they may simple want to run the corresponding
   script locally to reproduce the issue. This means that nearly all
   testing logic belongs to the test scripts, not the Actions
   configuration file (that developers cannot easily interpret/apply).

We also thought that some developers would want to separate
functionality from code quality tests (because those are often applied
at different development stages) and to repeat (many times) just the
failed test case (because that often helps when triaging and fixing
bugs). These considerations resulted in the creation of two scripts,
each accepting individual test case names as optional parameters:

* test-suite/test-functionality.sh
* test-suite/test-sources.sh

23 months agoFix GCC build on macos-11: -Wunused-parameter (#1159)
Alex Rousskov [Tue, 4 Oct 2022 13:26:08 +0000 (13:26 +0000)] 
Fix GCC build on macos-11: -Wunused-parameter (#1159)

23 months agoReport (problems with) DEAD-at-start cache_peers (#1155)
Alex Rousskov [Thu, 29 Sep 2022 21:03:06 +0000 (21:03 +0000)] 
Report (problems with) DEAD-at-start cache_peers (#1155)

When a cache_peer is (re)configured, Squid probes its address using a
throw-away TCP connection. If and only if that TCP probe succeeds, peer
selection algorithms may pick the peer. Until then, the cache_peer is
treated as if it was DEAD.

This change preserves the logic summarized above but starts _reporting_
the initial probe failure and the fact that it marks the cache_peer
DEAD. Without these reports, admins often naturally assume that the
cache_peer is alive, especially if traffic can be served without it.

23 months agoFix 'warning: stray \ before white space' (#1150)
Amos Jeffries [Wed, 28 Sep 2022 18:17:35 +0000 (18:17 +0000)] 
Fix 'warning: stray \ before white space' (#1150)

grep 3.8 started detecting overly-escaped regex patterns

23 months agoRedux broken krb5.h handling (#1156)
Amos Jeffries [Tue, 27 Sep 2022 21:05:14 +0000 (21:05 +0000)] 
Redux broken krb5.h handling (#1156)

De-duplicate the #include sequence into a libcompat header to
ensure all uses of the hack(s) including autoconf test macros
are using the same logic. This fixes some macros which were
using inconsistent logic for Solaris.

Simplify the if-elif use of __cplusplus detection. All the
extern C hacks apply only when C++ is used.

Wrapping the entire file peer_proxy_negotiate_auth.cc with
'extern C {...}' is unnecessary (it is a .cc) and breaks the
Solaris workaround.

2 years agoImprove LDAP library detection (#1148)
Amos Jeffries [Sat, 24 Sep 2022 11:52:35 +0000 (11:52 +0000)] 
Improve LDAP library detection (#1148)

Add --with-ldap and pkg-config support to speed up Squid builds
where LDAP is not to be used. This also adds support for custom
LDAP library locations like other --with-foo options.

'pkg-config --libs ldap' finds both -lldap and -llber. Stop using
different variables for them in Makefile.am.

Extract LDAP API tests into simpler dedicated macros and stop
polluting LIBS when running LDAP tests.

2 years agoRename ./configure option --with-libcap to --with-cap (#1140)
Amos Jeffries [Fri, 23 Sep 2022 13:26:23 +0000 (13:26 +0000)] 
Rename ./configure option --with-libcap to --with-cap (#1140)

The 'lib' prefix is supposed to be omitted from --with/--without
names but libcap was not correctly named.

Also, add support for pkg-config library auto-detection.

2 years agoFix ./configure detection of libxml2 headers (#1153)
Alex Rousskov [Thu, 22 Sep 2022 03:41:10 +0000 (03:41 +0000)] 
Fix ./configure detection of libxml2 headers (#1153)

    checking for LIBXML2... yes
    checking libxml/parser.h usability... yes
    checking libxml/parser.h presence... no
    configure: WARNING: libxml/parser.h: accepted by the compiler,
               rejected by the preprocessor!
    configure: WARNING: libxml/parser.h: proceeding with the compiler's
               result

PKG_CHECK_MODULES() documentation warns that it uses a "misleading" name
for the foo_CFLAGS variable it sets: "the variable provides the flags to
pass to the preprocessor, rather than the compiler". Lots of Squid code
has been mislead by that macro, but this fix is specific to a recent
regression introduced in commit 866a092. TODO: Fix all others.

2 years agoFix ./configure tests (#1151)
Alex Rousskov [Wed, 21 Sep 2022 23:53:12 +0000 (23:53 +0000)] 
Fix ./configure tests (#1151)

Many tests broken by recent commit a1c2236 supplying empty input to
AC_LINK_IFELSE() macro in SQUID_CC_CHECK_ARGUMENT. Empty input results
in no test file created by the macro (and, presumably, a failed linking
test). Observable symptoms (in some environments) include many repeated
errors on ./configure stderr:

    sed: can't read conftest.cpp: No such file or directory

Also fixed a similar SQUID_SEARCH_LIBS() bug. That macro was broken
since inception (commit 391f0ba). It is currently only used for the
mingw-specific SQUID_CHECK_WINSOCK_LIB check. This change is untested.

2 years agoFix escaping leading regex dashes in ./configure sources (#1152)
Alex Rousskov [Wed, 21 Sep 2022 13:53:22 +0000 (13:53 +0000)] 
Fix escaping leading regex dashes in ./configure sources (#1152)

    grep: invalid option -- 't'
    Usage: grep [OPTION]... PATTERNS [FILE]...
    Try 'grep --help' for more information.

    Usage: grep [OPTION]... PATTERNS [FILE]...
    Try 'grep --help' for more information.
    ./configure: line 27524: test: too many arguments

    Usage: grep [OPTION]... PATTERNS [FILE]...
    Try 'grep --help' for more information.
    ./configure: line 27698: test: too many arguments

Configure scripts are written in m4, not shell. M4 treats [square
brackets] specially. We could use quadrigraphs instead (as documented in
autoconf manual) but `(-)` looks a lot simpler than `@<:@-@:>@`!

2 years agoFixed comm.cc:644: "address.port() != 0" assertion (#1149)
Alex Rousskov [Mon, 19 Sep 2022 14:07:47 +0000 (14:07 +0000)] 
Fixed comm.cc:644: "address.port() != 0" assertion (#1149)

IPC code creating a TCP socket pair for communication with helpers used
comm_open() to create a _listening_ socket, misleading Comm into
applying IP_BIND_ADDRESS_NO_PORT optimization that delays port
assignment until connect(2) (which is never called for listening
sockets). Listening sockets must be opened using comm_open_listener(),
but the IPC use case was missed in 2009 commit 31be869 that introduced
comm_open_listener(). IP_BIND_ADDRESS_NO_PORT changes in recent commit
74d7d19 hit that bug.

Disclaimer: Windows-specific code adjusted without testing.

2 years agoCleanup libsystemd variables (#1147)
Amos Jeffries [Mon, 19 Sep 2022 12:14:39 +0000 (12:14 +0000)] 
Cleanup libsystemd variables (#1147)

Rename SYSTEMD_LIBS and related `*_CFLAGS` / `*_PATH` variables to
`LIBSYSTEMD_*` prefix in line with other libraries naming style.

Polish detection log outputs in line with other libraries.

Fix pollution of global LDFLAGS variable.

Also, expand possible -lsystemd builds beyond Linux. Some OS provide a
library for compatibility. Cross-builds can also need to link against
systemd.

2 years agoDo not check unused RECV_ARG_TYPE (#1146)
gkinkie@gmail.com [Sun, 18 Sep 2022 23:58:37 +0000 (23:58 +0000)] 
Do not check unused RECV_ARG_TYPE (#1146)

The check and corresponding defined preprocessor value
are not used anywhere in the code; remove the check

2 years agoCleanup libexpat variables (#1143)
Amos Jeffries [Sun, 18 Sep 2022 19:19:21 +0000 (19:19 +0000)] 
Cleanup libexpat variables (#1143)

... to use pkg-config compatible naming and take advantage of
squid provided macros better.

Also, add support for pkg-config library auto-detection.

2 years agoCleanup libxml2 variables (#1145)
Amos Jeffries [Sun, 18 Sep 2022 05:40:09 +0000 (05:40 +0000)] 
Cleanup libxml2 variables (#1145)

... to use pkg-config compatible naming and take advantage of
squid provided macros better.

Remove unnecessary path detection of /usr vs /usr/local
locations. Admin can use --with-foo=PATH to provide any needed
customization of those from whichever is standard for the build
environment.

2 years agoCleanup libnettle detection (#1144)
Amos Jeffries [Sat, 17 Sep 2022 11:01:26 +0000 (11:01 +0000)] 
Cleanup libnettle detection (#1144)

... to use pkg-config compatible variable naming and break out
the code test to a dedicated macro per the style used by other
libraries.

Also, add support for pkg-config library auto-detection.

Also, our libcompat provides local replacement for Base64 on
builds with older libnettle. Fix the library link order to
ensure our functions get linked properly.

2 years agoDo not lock an SMP hit twice for the same transaction (#1134)
Alex Rousskov [Thu, 15 Sep 2022 07:16:50 +0000 (07:16 +0000)] 
Do not lock an SMP hit twice for the same transaction (#1134)

Before commit 4310f8b, anchorToCache() (known then as anchorCollapsed())
was only called for not-yet-anchored entries. For anchored entries, we
called updateCollapsed(). In that commit, a new anchorToCache() caller
(i.e. allowSharing() after peek()) started calling anchorToCache() for
all entries, but anchorToCache() code was not updated to skip anchoring
of anchored entries, leading to an extra read lock placed on a peek()ed
hit entry. The extra lock prevented the entry slot from being reused for
other entries when the entry was later purged (i.e. marked for removal),
drastically decreasing hit ratio in some environments.

Fixed anchorToCache() no longer anchors anchored entries. To make sure
we covered all callers/cases, especially in patches, we changed the call
parameters, addressing an old code simplification TODO.

2 years agoFix 'warning: stray \ before -' (#1141)
Amos Jeffries [Thu, 15 Sep 2022 01:14:17 +0000 (01:14 +0000)] 
Fix 'warning: stray \ before -' (#1141)

grep 3.8 started detecting overly-escaped regex patterns

2 years agoBug 5232: Fix GCC v12 build [-Wuse-after-free] (#1136)
Eduard Bagdasaryan [Wed, 14 Sep 2022 06:47:52 +0000 (06:47 +0000)] 
Bug 5232: Fix GCC v12 build [-Wuse-after-free] (#1136)

This warning is a false positive. Introduced in GCC v12, use-after-free
checks have attracted dozens of bug reports, with several reports still
open as of GCC v12.2, including one that looks very similar to our case:
https://gcc.gnu.org/bugzilla//show_bug.cgi?id=106776

Removing (excessive) "inline" works around this GCC bug. We do not have
a better workaround right now. If we see more false positives like this,
we may disable -Wuse-after-free until its support matures.

2 years agoFix cppunit version detection (#1142)
Amos Jeffries [Tue, 13 Sep 2022 12:19:16 +0000 (12:19 +0000)] 
Fix cppunit version detection (#1142)

2 years agoFix 'AC_LINK_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS' (#1139)
Amos Jeffries [Tue, 13 Sep 2022 07:25:36 +0000 (07:25 +0000)] 
Fix 'AC_LINK_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS' (#1139)

... produced during bootstrap.sh by autoconf 2.71

AC_USE_SYSTEM_EXTENSIONS needs to be placed after detecting
which OS and compiler are being used. But before any of the
checks detecting capabilities of those OS and compilers.

AC_CANONICAL_HOST is a prerequisite of the simple_host_os logic.
Attach it to that code block instead of the compiler detection
block.

Replace deprecated '$GCC' variable with autoconf cached
'$ac_cv_c_compiler_gnu' variable used as the real source for the
yes/no value of GCC usability after AC_PROG_CC.

2 years agoImprove SQUID_YESNO error messages (#1137)
Amos Jeffries [Sun, 11 Sep 2022 23:27:18 +0000 (23:27 +0000)] 
Improve SQUID_YESNO error messages (#1137)

This macro performs a very specific validation check but was
passed a mix of different error messages to display on failure.
Many of which were unclear or wrong.

Move the text of the error inside the macro to enforce
consistency and accuracy about what failed. It actually only
needs to be passed the name of the ./configure options which
was configured badly.

Also, the options configured can only take the positive form
when they fail '--with-foo=X' or 'enable-foo=X' so update the
second argment to always show that form regardless of whether
the configure.ac logic has it default enabled or disabled.

Also, fixed a bug in --with-nat-devpf validation which was
testing the wrong variable (enableval). This bug only affects
the errors displayed so no builds were significantly affected.

2 years agoReplaced FDECB callback with a basic async call (#1135)
Eduard Bagdasaryan [Sun, 11 Sep 2022 17:24:48 +0000 (17:24 +0000)] 
Replaced FDECB callback with a basic async call (#1135)

The "FD passing callback" was misleading because it was not used as a
callback. We just need an async call with a known-to-the-caller
parameter instead. Simplifying CommCalls (by removing this "special
callback") helps improve that API.

2 years agoRename ./configure option --with-libxml2 to --with-xml2 (#1138)
Amos Jeffries [Fri, 9 Sep 2022 11:41:21 +0000 (11:41 +0000)] 
Rename ./configure option --with-libxml2 to --with-xml2 (#1138)

The 'lib' prefix is supposed to be omitted from
--with/--without names but libxml2 was not
correctly implemented from inception.

2 years agoUpdate configure.ac scripts (#937)
Amos Jeffries [Wed, 7 Sep 2022 19:02:11 +0000 (19:02 +0000)] 
Update configure.ac scripts (#937)

Various cleanup changes to reduce the size of autoconf scripts and
remove deprecated macros causing build warnings with autoconf v2.71.