Amos Jeffries [Fri, 22 Feb 2013 13:26:12 +0000 (02:26 +1300)]
SourceLayout: shuffle BasicAuthQueueNode to Auth:: namespace
... and document what it is used for by authentication.
There is only one logic change in this patch. The QueueNode destructor
is added to clear the queued CBDATA entries when the queue is deleted.
Previously the pointer was just erased in hopes that the queue was
notified prior to deletion.
Amos Jeffries [Mon, 18 Feb 2013 13:02:42 +0000 (02:02 +1300)]
Removes the domain from the cache_peer server pconn key
Under the squid-3.2 pconn model the IP:port specifying the destination
are part of the key and can be used to strictly filter selection when
locating pconn. This means the domain is no longer a necessary part
of the key.
Squid using cache_peer can see a large number of wasted idle connections
to their peers due to the key domain value if the peer hostname is not
substituted properly. There is also a similar affect when contacting
servers with virtual hosted domains.
Also a bug was located with peer host and name= values being used
inconsistently as the domain marker. Resulting in failed pop() operations
and extra FD usage.
This has been tested for several months now with only socket usage
benefits seen in several production networks.
NOTE: previous experience some years back with pconn has demonstrated
several broken web servers which assume all requests on a persistent
connection are for the same virtual host. For now this change avoids
altering the behaviour on DIRECT traffic for this reason.
Since debugs() is a macro, it should not change static Debugs::level
before putting the debug message to the internal stream. Otherwise we
encounter problems when debug message itself containg calls to debugs().
Amos Jeffries [Tue, 12 Feb 2013 11:34:35 +0000 (00:34 +1300)]
Polish: Drop redundant HttpMsgPointerT template
Despite the object and API changes being rather extensive
there are no logic changes in this patch.
The HttpMsgPointerT template was used to ref-count HttpMsg
objects and its children. It provided an API identical to
the RefCount API plus a few extensions for handling
polymorphism cast operations in the background.
This patch:
* update HttpMsg class hierarchy to use Lock API directly
removing the _lock() and _unlock() virtual functions.
* update HttpControlMsg to use a HttpReply::Pointer directly
since this type is available to that class a re-definition
using HttpMsg* casting was not needed.
* update HTTPMSGLOCK() macro not to return a HttpMsg*
The API polymorphism extensions provided by
HttpMsgPointerT<> were only necessary to handle the
HttpMsg* object casting this macro made a requirement.
Once that assignment casting is removed the entire
API extensions are no longer used.
Amos Jeffries [Mon, 11 Feb 2013 23:11:12 +0000 (16:11 -0700)]
SourceLayout: Shuffle and collate the log result codes symbols
This collates all the small definitions spread around Squid for defining
and handling the TCP_* and UDP_* result code tags logged by Squid.
* log_type enumeration shuffled from enums.h
* log_type increment operator shuffled from client_db
* log_type strings shuffled from Format:: and built automatically
* is-HIT lookup test shuffled from ICP
Due to LogTags.cc being automatically built from the enum list we define
the shuffled functions as inline. This is not a problem due to their small
size. When the LogTags type is converted to a class thay can be de-inlined.
Amos Jeffries [Sat, 9 Feb 2013 10:45:25 +0000 (03:45 -0700)]
Attempt alternative method of snapshot cleanup.
Something in the sed regex patterns is not matching the snapshots detected
by the ls pattern. We can skip the sed and use the full file path ls
found to remove the snapshot.
Amos Jeffries [Sat, 9 Feb 2013 05:16:04 +0000 (22:16 -0700)]
Polish: call maxObjectSze virtual in SwapDir.
Say "virtual" explicitly in this
case to remind us that maxObjectSize() is a part of the [semi-broken]
Store API and not some SwapDir "own" method. This will help us when we
polish the API to remove the common Store root.
Amos Jeffries [Sat, 9 Feb 2013 00:44:07 +0000 (17:44 -0700)]
Bug 3686: cache_dir max-size default fails
If some cache_dir are configured with max-size and some not the default
maximum_object_size limit fails.
This refactors the max-size management code such that each SwapDir always
has a value maxObjectSize(). This value is calculated from the SwapDir
local setting or global limit as appropriate.
The global maximum_object_size directive is migrated to simply be a default
for cache_dir max-size= option.
The global store_maxobjsize variable is altered to be the overall global
limit on how big an object may be cache by this proxy. It now takes into
account the max-size for all cache_dir and cache_mem limitation.
NP: The slow accumulation of these and earlier changes means Squid no
longer immediately caches unknown-length objects. The unit-tests are
therefore changed to test using explicit 0-length objects to ensure the
test is on a cached object not bypassing the apparently ested logic.
They are also provided with a large global store_maxobjsize limit in order
to do a weak test of the SwapDir types max-size in the presence of other
larger cache_dir or maximum_object_size settings.
Alex Rousskov [Fri, 8 Feb 2013 04:14:50 +0000 (21:14 -0700)]
Make squid -z for cache_dir rock work like UFS instead of like COSS.
Polish -z documentation and cache.log reporting.
When a startup script runs squid -z by mistake against a cache_dir that is
already initialized and full of cached entries, some admins prefer that
nothing happens. Rock store now skips reinitialization if both the cache_dir
directory and the db file in that directory exist. If one or both are missing,
the missing pieces are created.
UFS does something similar because it creates missing L1 and L2 directories
but does not erase any entries already present in the cache_dir path. COSS,
OTOH, re-initializes the existing db. Rock behavior will now be closer to UFS.
To clean a corrupted cache_dir, the admin must remove its top-level directory
before running squid -z.
Squid now logs "Creating missing swap directories" instead of "Creating Swap
Directories", and our documentation now reflects the "if missing" part of the
-z algorithm.
Also documented that recent Squid versions run -z in daemon mode (so that SMP
configuration macros continue to work).
Amos Jeffries [Tue, 5 Feb 2013 07:47:28 +0000 (20:47 +1300)]
Migrate HttpMsg to Lock refcounting
First stage of the conversion to RefCount<>. This replaces the custom
attempt at ref-count locking in HttpMsg with the locking mechanism
presented by class Lock.
Alex Rousskov [Mon, 4 Feb 2013 17:39:23 +0000 (10:39 -0700)]
Bug 3752: objects that cannot be cached in memory are not cached on disk
if cache_dir max-size is used.
This fix contains four related changes:
1) When fixing "trimMemory for unswappable objects" (trunk r11969), we
replaced swapoutPossible() with swappingOut()||mayStartSwapOut() but missed
the fact that swapoutPossible() had "possible now" semantics while
mayStartSwapOut() has "may start now or in the future" semantics. When all
cache_dirs had max-size set, mayStartSwapOut() returned false for objects of
unknown size and even for smaller-than-maximum but not-yet-received objects,
despite the fact that those objects could be swapped out later.
That false mayStartSwapOut() result allowed maybeTrimMemory() to trim those
objects memory and mark the objects for release, preventing their subsequent
disk caching.
2) To fix (1) above, mayStartSwapOut() had to return true for not-yet-received
objects of unknown size. However, returning true is correct only if no
subsequent check can return false. Thus, we had to move all lower/later checks
that could return false up, placing them before the maximum-of-all-max-sizes
check.
3) Once (2) was done, the end of mayStartSwapOut() had (a) a loop that could
return true while setting decision to MemObject::SwapOut::swPossible and (b)
an unconditional code that did ... the same thing. Thus, the loop could no
longer change the method outcome. The loop also had a lot of doubts and XXXs
attached to it. We removed it. If that loop is needed, it is needed and must
be resurrected elsewhere.
4) Since mayStartSwapOut() returns true if swapout is possible in the future
(but not necessarily now), we cannot rely on its return value to initiate
swapout code. We need to test whether swapout.decision is swPossible instead.
Amos Jeffries [Sun, 3 Feb 2013 08:49:00 +0000 (01:49 -0700)]
Fix lots of SNMP alignment, sizeof(), and memory uninitialized erorrs
They all stem from a few uses of "sizeof(name)" where name is a pointer
to an OID object rather than the object itself. This code is present as
far back as squid-2.6 and probably a lot further.
It appears to not have been causing obvious problems due to the
sizeof(oid*) [4 or 8 octets] on a pointer being larger than the
sizeof(oid) [1 or 2 octets] on the object stored into the allocated
memory.
Amos Jeffries [Fri, 1 Feb 2013 06:49:25 +0000 (23:49 -0700)]
Bug 3515: crash in FtpStateData::ftpTimeout
Since revision squid-3.2-11174 restructured teh TCO connection handling
in FTP the data connection has had separate 'opener' connection.
Meaning the conn->fd state is always NULL when the setup times out.
This cleans up the data connection opener state and allows the error
message generation to take place.
Alex Rousskov [Fri, 1 Feb 2013 00:28:16 +0000 (17:28 -0700)]
Fixed several ConnOpener problems
by relying on AsyncJob protections and comm_close(), while maintaining a
tighter grip on various I/O and sleep states.
Problems addressed:
* Connection descriptor was not closed when attempting to reconnect after
failures. We now properly close on failures, sleep with descriptor closed,
and then reopen.
* Timeout handler was not cleaned up properly in some cases, causing memory
leaks (for the handler Pointer) and possibly timeouts that were fired (for
then-active handler) after the connection was passed to the initiator.
* Comm close handler was not cleaned up properly.
* statCounter.syscalls.sock.closes counter was not updated on FD closure.
* Waiting pending accepts were not kicked on FD closure.
* Connection timeout was enforced for each connection attempt instead of
applying to all attempts taken together.
and possibly other problems. The full extent of all side-effects of mishandled
race conditions and state conflicts is probably unknown.
There are cases where the generated certificates do not mimic enough properties
and secure connection with the client fails. For example, Squid does not mimic
Key Usage extensions. Clients using GnuTLS (or similar libraries that validate
server certificate using those extensions) fail to secure the connection with
Squid.
This patch add mimicking for the following extensions, which are considered
as safe to mimic:
* X509v3 Key Usage
* X509v3 Extended Key Usage,
* X509v3 Basic Constraints CA.
We would be happy to add more "safe to mimic" extensions if users request (and
vouch for) them.
Currently, dst, dstdom, dstdom_regex (and other?) DNS-related ACLs do DNS
lookups if such a lookup is needed to convert an IP address into a domain name
or vice versa. This creates two kinds of problems:
- It is difficult to identify requests that use raw IP addresses in Request-URI
or Host headers. One would have to use something like url_regex and possibly
req_header to identify those before using dst ACLs to match the request
destination against a known IP subnet. IPv6 would only make this harder.
- It is difficult to use dst* ACLs in options that support fast ACLs only.
If an async lookup is required, the answer will be unpredictable (now)
or DUNNO (when the ACL bugs are fixed), possibly with warnings and other
complications.
This patch adds a -n option to dst, dstdom, dstdom_regex and other DNS-related
ACLs. The option disable lookups and address type conversions. If lookup or
conversion is required because the parameter type (IP or domain name) does not
match the message address type (domain name or IP), then the ACL with a -n
option would immediately declare a mismatch without any warnings or lookups.
The "--" option can be used to stop processing all options, in the case the
first acl value has '-' character as first character (for example the '-' is
a valid domain name)
For example:
# Matches requests with full URI host set to localhost
# but not requests with full URI host set to 127.0.0.1
acl toLocalRawName dstdom -n localhost
http_access allow toLocalRawName
# Use -- option to stop processing flags
acl AnACL dst_domain -n -- -cream-and-sugar.tumblr.com
# Matches requests with full URI host set to 127.0.0.1
# but not requests with full URI host set to localhost
acl toLocalRawIp dst -n 127.0.0.1/32
cache_peer_access peer1 allow toLocalRawIp
Please note that -n prohibits lookups in Squid's DNS caches as well.