Alex Rousskov [Mon, 26 Aug 2013 19:15:21 +0000 (13:15 -0600)]
Log %<sS (reply content length) as zero when object size is unknown.
For %<sS purposes, Squid computes reply content length as the difference
between "object size" and response headers. When headers were received but the
"object size" is not known (e.g., the promissed response body was never
received), that computation results in misleading negative numbers. We no
longer log them.
Alex Rousskov [Mon, 26 Aug 2013 19:09:40 +0000 (13:09 -0600)]
Support %<st and %<sh logformat codes for FTP gateway responses.
For logging purposes, treat all non-data FTP responses (i.e., bytes written on
the client control connection) as "HTTP headers" because they are similar
"matadata".
Alex Rousskov [Mon, 26 Aug 2013 18:24:02 +0000 (12:24 -0600)]
Added ftp_client_idle_timeout directive to squid.conf.
Many FTP clients do not deal with control connection closures. They cannot
retry pconn races without asking the user for credentials, for example. Thus,
the existing client_idle_pconn_timeout default (2 minutes) does not work well
for FTP clients. One the other hand, increasing that may create too many idle
HTTP connections for Squid to maintain.
The new timeout is specific to ftp_port traffic. It does not affect ftp://...
requests sent to an http[s]_port.
Alex Rousskov [Mon, 26 Aug 2013 17:46:48 +0000 (11:46 -0600)]
Do not close FTP gw server control connection on more server-unrelated errors.
FtpGatewayServer now forgets about its control connection to the server once
it is done communicating with that server. This allows us to preserve that
connection on FTP transaction errors (e.g., forbidden responses or broken
ICAP servers) that are not related to the server communication and can be
ignored as far as the next FTP gatewayed transaction is concerned.
Removed special DONE state because it is now identical to doneWithServer().
Fixed ServerChannel::forget() to prevent subsequent forgotten connection
closure.
Alex Rousskov [Sun, 25 Aug 2013 19:50:44 +0000 (13:50 -0600)]
Avoid some unnecessary FTP control connection closures; polished FTP failure
code.
Do not close FTP server control connection just because FTP response
adaptation is done. We still close FTP connections if we are receiving the
virgin response (because we have no place to store it), but if we are done
receiving, there is no need to terminate FTP server connections. The former
happens when an ICAP service responds before receiving the entire virgin FTP
response. The latter, when the ICAP service responds after the FTP data
connection is closed but before the control 226 response comes in.
Do not close FTP client control connection just because we served a non-OK
control response. The client may still send us commands if our ClientStream is
still in a good state. This may happen when an FTP download is prohibited by
an adaptation service via an HTTP 403 Forbidden response, for example.
Avoid STORE_PENDING assertion in FwdState::reforward() due to double
forwarding completion by FtpGatewayServer. Similar code exists in regular FTP
server and is needed for gatewaying as well because FTP may keep open (and
expect a control response on) the control connection after adaptation is
completed, creating two avenues for a FwdState::complete() call.
Ftp::ServerStateData::failed() should always call FwdState::fail(), to supply
forwarding code with ErrorState details. And we should not create the error
HttpReply in the FTP code. FwdState code does that, probably because it may
reforward the request and, hence, bypass some errors. For now, FTP gateway
code still creates an HttpReply (in addition to calling FwdState::fail) to be
able to supply custom gatewaying error information. Eventually, that should be
done via custom ErrorState object (that will later create an appropriate
HttpReply when/if needed).
Amos Jeffries [Sun, 25 Aug 2013 04:44:20 +0000 (22:44 -0600)]
Doce: make doc/Programming-Guide/doxygen.footer.dyn non-empty
Experiment to see if the .dyn file footer output by doxygen is still
placed if this file contains whitespace. Just having it empty no longer
seems to work with the newer doxygen version.
Amos Jeffries [Sat, 24 Aug 2013 13:12:26 +0000 (01:12 +1200)]
Docs: define use of footer for output DYN files.
doc/Programming-Guide/doxygen.footer.dyn is an empty file because we do
not need anythign as a footer. But we do need to use it because doing so
will suppress teh default "</body></html>" string being appended to the
output file, which breaks out static site generation since .dyn files
have our own squid-cache.org footers automatically appended.
Alex Rousskov [Fri, 23 Aug 2013 22:19:46 +0000 (16:19 -0600)]
Render adaptation X-Response-Info and X-Response-Desc meta values in FTP errors
caused by adaptation (e.g., an ICAP service blocking an FTP command)
Requires adaptation history to be enabled, which can be achieved by logging
adaptation meta headers to access log (%adapt::<last_h) or setting
adaptation_masterx_shared_names in squid.conf
Long term, the contents of the error message should be configurable via
error message templates (which may include these semi-standard meta headers).
Alex Rousskov [Fri, 23 Aug 2013 20:29:04 +0000 (14:29 -0600)]
Provide user with more details on forwarding/adaptation errors.
In addition to "421 Service Unavailable", print %c and %E errorpage info.
Needs more work to make FTP error messages configurable, just like they are
for HTTP.
Alex Rousskov [Fri, 23 Aug 2013 01:20:21 +0000 (19:20 -0600)]
Initial support for active FTP downloads via the FTP PORT command.
Squid accepts PORT command on the client side, but still uses passive transfer
on the server side. The PORT command response is not sent to the client until
the server-side PASV command succeeds. The data connection to the client is
not opened until Squid receives the RETR command from the client.
Squid requires either PORT or PASV command before data transfers. RFC 959 says
PORT is optional because default ports can be used.
RFC 959 also seems to imply that Squid should originate active connections to
client from port 20. The code to do that is commented out for now because it
would prevent support for concurrent data connections. The code configuring
this outgoing (but to-client) connection may need more work as we do a lot
more for outgoing to-server connections.
Alex Rousskov [Thu, 22 Aug 2013 18:39:41 +0000 (12:39 -0600)]
Close idle client connections associated with closed idle pinned connections.
Squid was not monitoring idle persistent connections pinned to servers. Squid
would discover that the pinned server connection is closed only after
receiving a new request on the idle client connection and trying to write that
request to the server. In such cases, Squid propagates the pinned connection
closure to the client (as it should).
Chrome and, to a lesser extent, Firefox handle such races by opening a new
connection and resending the failed [idempotent] request transparently to the
user. However, IE usually displays an error page to the user.
While some pconn races cannot be avoided, without monitoring idle pconns,
Squid virtually guaranteed such a race in environments where origin server
idle connection timeout is smaller than client/Squid timeouts and users
are revisiting pages in the window between those two timeouts.
Squid now monitors idle pinned connections similar to idle connections in the
pconn pool and closes the corresponding idle client connection to keep the two
sides in sync (to the extent possible).
It is theoretically possible that this change will break servers that send
whitespace on an idle persistent connection or perhaps send some SSL keepalive
traffic. No such cases are known to exist though.
Amos Jeffries [Wed, 21 Aug 2013 08:43:27 +0000 (02:43 -0600)]
Update forward_max_tries to permit 25 server paths
With cloud sites becoming more popular more CDN servers are producing
long lists of IPv6 and IPv4 addresses. If there are not enough paths
selected the IPv4 ones may never be reached.
Alex Rousskov [Thu, 15 Aug 2013 22:26:40 +0000 (16:26 -0600)]
Fixed swap_file_sz calculation when loading rock entries. Polished debugging.
Supply storeRebuildParseEntry() with known "swap file size" so that it can
adjust swap_file_sz after loading store entry meta info. Entries are often
stored with swap_file_sz in the meta header missing the swap_hdr_len
component. storeRebuildParseEntry() adds swap_hdr_len when needed, using known
entry size to detect that need.
Alex Rousskov [Thu, 15 Aug 2013 22:21:16 +0000 (16:21 -0600)]
Do not use StoreEntry::swap_file_sz to write DbCellHeader::entrySize,
even during the last write.
StoreEntry::swap_file_sz is often set by storeSwapOutFileClosed, which is
called after the last write.
Also, I am not sure whether partial StoreEntry::swap_file_sz info might later
confuse store rebuild code into thinking that the whole entry is malformed.
That would be [different] bug.
Jan Sievers [Thu, 15 Aug 2013 21:28:14 +0000 (15:28 -0600)]
Regression Bug 3077: off-by-one error in Digest header decoding
This is a regression in the 3.2 and later version of the original bug
fix patch.
The effect is that all attributes are treated as quoted-string values
with unescaping performed. This ends with credentials wrongly being
rejected as invalid.
Amos Jeffries [Sat, 3 Aug 2013 07:57:44 +0000 (19:57 +1200)]
Fix configure parsing IP/domain directives
Squid would semi-silently accept invalid IP address or hostname in some
directives which required them (eg wccp_router) and use the magic
IP_ANYADDR value. This change makes configure halt with a FATAL error
instead.
Amos Jeffries [Thu, 1 Aug 2013 20:45:56 +0000 (08:45 +1200)]
Add dns_multicast_local to control mDNS operation
Enable admin control over whether mDNS operates or not. Set the default
to OFF due to .arpa reverse-DNS requests causing a rise in traffic from
this feature even on networks without mDNS responders setup.
Also, polish cachemgr idns report to show for queued queries which
resolver type and query the entry is involving. mDNS can cause a queue
to exist as some lookups timeout on the mDNS resolvers.
Alex Rousskov [Tue, 30 Jul 2013 17:10:57 +0000 (11:10 -0600)]
Prevented STORE_DISK_CLIENT assertions for aborted entries. Polished code.
To prevent store_client.cc:445: "STORE_DISK_CLIENT == getType()" assertions,
rewrote the storeClientNoMoreToSend() function so that it does not send a
STORE_MEM_CLIENT to read from disk. Used this opportunity to polish this
negative function code and convert it into a positive method.
Documented known (and mostly old) StoreEntry::storeClientType() problems.
Specialize SBuf::reserveSpace and reserveCapacity functions to provide guarantee of single store ownership.
Tune SBuf::rawSpace() to take over from reserve* for the optimization role preveiously played by reserve*.
Adjust documentation and callers.
Fix debugs when refresh_pattern is missing the regex pattern
This is a very rare situation and may not be completely required. But it
did hinder debugging of refresh_pattern when the regex field token was
broken by parser updates.
Alex Rousskov [Mon, 29 Jul 2013 00:46:55 +0000 (18:46 -0600)]
Better support for things with shared locks that can be opened many times,
such as Ipc::StoreMap entries. Maintain a lock counter instead of boolean
opened flag.
Better support for things with multipart IDs
such as Ipc::StoreMap entries that have an anchor/inode ID and map name.
Alex Rousskov [Mon, 29 Jul 2013 00:43:55 +0000 (18:43 -0600)]
Re-enabled on-disk collapsing of entries after fixing related code.
Since we started writing partial entries, we cannot rely on negative sidNext
marking the end of the slice/write sequence. Added a WriteRequest::eof field
to signal that end explicitly.
Do not leak db slices when write fails or IoState is closed before the write
succeeds.
Handle store client requesting an offset we have not stored yet. This might
happen for collapsed hits (and also if the client is buggy). May need more
work to slow the reader down.
Do not update various shared stats until the corresponding slot is written.
Alex Rousskov [Mon, 29 Jul 2013 00:27:23 +0000 (18:27 -0600)]
Improved STORE_MEM_CLIENT detection.
IN_MEMORY mem_status does not guarantee that the entore object is in the
memory cache. We may be just loading it from a shared memrory cache, and
loading may fail. We may have nibbled at the entry already (although that may
not be possible, not sure). The whole memory/disk store_client designation
probably needs more work, but the now-removed condition was causing
store_client.cc:445: "STORE_DISK_CLIENT == getType()" assertions.
Alex Rousskov [Sat, 27 Jul 2013 17:19:29 +0000 (11:19 -0600)]
Keep anchor.basics.swap_file_sz in sync with slice sizes.
The old code updated anchor.basics.swap_file_sz _after_ copying all of the
available data into shared memory. An exception in the copying loop (e.g., the
map is out of available slots) could prevent that update. For another worker,
the entry would then appear to be fully completed (no writer, last slice size
stable, and last slice poiner is -1) and that worker would assert due to
anchor.basics.swap_file_sz mismatching the sum of slice sizes.
Handle infinite certificate validation loops caused by OpenSSL bug #3090.
If OpenSSL is stuck in a validation loop, Squid breaks the loop and triggers a
new custom SQUID_X509_V_ERR_INFINITE_VALIDATION SSL validation error. That
error cannot be bypassed using sslproxy_cert_error because to break the loop
Squid has to tell OpenSSL that the certificate is invalid, which terminates
the SSL connection.
Validation loops exceeding SQUID_CERT_VALIDATION_ITERATION_MAX iterations
are deemed infinite. That macro is defined to be 16384, but that default can
be overwritten using CPPFLAGS.
Tied more closely SBuf and MemBlob size_type
Better compliance with standards
Improved SBuf documentation
Improved adherence to std::string method signatures
Improved \0-cleanliness
Removed some methods taking std::string arguments to avoid double data copies,
documented alternate patterns
Implemented cmp and caseCmp shortcuts
Cleaned-up some methods' implementations after Alex Rousskov's suggestions
Improved unit tests' cleanliness by making more effective use of cppunit macros
Implemented more unit tests, better coverage for \0-cleanliness
Update the http(s)_port directives protocol= parameter
... to use AnyP::ProtocolVersion for internal storage instead of opaque
string text.
This both limits the possible parameter values to one of HTTP, HTTP/1.1,
HTTPS or HTTPS/1.1 and ensures that URLs generated from that protocol
parameter value are http:// and https:// URL.
Other values will cause Squid to abort.
Invalid casting seems to confuse the ABI generator and results in
illegal instruction faults when the unit tests is run.
The class API is already const-correct so there is no need for the cast
to occur, and it should not be done on a non-pointer type anyway.
Also, fixes a missing "struct" type identifier found along the way.
Alex Rousskov [Wed, 24 Jul 2013 21:48:45 +0000 (15:48 -0600)]
Disconnect StoreEntries before deleting their memory objects.
The new cleanup order helps identify the write Rock entry state (reading or
writing) and avoid assertions related to state identification bugs (such
as unlocking a writing entry for reading).
Similar to the memory cache code, we should not disconnect disk entries during
shutdown because Store::Root() may be missing by then.
Alex Rousskov [Wed, 24 Jul 2013 21:45:02 +0000 (15:45 -0600)]
Avoid !writeableAnchor_ assertions when Squid shuts down.
A shutting down Squid deletes locked StoreEntry objects, which may trigger
deletion of Rock::IoState that is still writing to disk. We should fix the
shutdown sequence. Meanwhile, the Rock::IoState code does not need to mislead
admins with an assert.
Alex Rousskov [Mon, 22 Jul 2013 17:04:00 +0000 (11:04 -0600)]
Fixed StoreEntry::mayStartSwapOut() logic to handle terminated swapouts.
StoreEntry::mayStartSwapOut() should return true if a swapout can start. If
swapout was started earlier but then terminated for some reason (setting sio
to nil), the method should not return true. Checking swap_status ==
SWAPOUT_DONE does not work reliably because the status may be reset to
SWAPOUT_NONE in some cases (and the check was too late anyway). Checking
decision == swPossible does not work at all because while swapout start was
possible at some point, it is no longer possible after we started swapping
out.
Added MemObject::SwapOut::swStarted to detect started swapouts reliably.
This patch :
- adds support for quoted values in the entire squid.conf
- warn about or prohibit values that can no longer be interpreted as
either quoted strings or simple tokens
- support parameters("/path/to/file.name") syntax to load external
configuration files
- Checks if macros allowed in "double quoted" values.
- replaces the strtok() calls with calls to the new ConfigParser::NextToken()
- modify strtokFile to use new ConfigParser::NextToken()
- Add the new configuration_includes_quoted_values configuration option, to
control the squid parser behaviour. If set to on Squid will recognize each
"quoted string" after a configuration directive as a single parameter
This patch add new logformat codes to log TOS/DSCP values and netfilter marks
for client and server connections. If multiple outgoing connections were used,
the last used connection value logged.
The values printed in hexadecimal form.
The logformat codes are:
%>tos Client connection tos mark set by Squid
%<tos Server connection tos mark set by Squid
%>nfmark Client connection netfilter mark set by Squid
%<nfmark Server connection netfilter mark set by Squid
This patch also modify qos related code to set Comm::Connection::nfmark and
Comm::Connection::tos members in Ip::Qos::setSockNfmark and Ip::Qos::setSockTos
methods. The Comm::Connection members are now set only if the tos and nfmark
set successfuly.
This patch sends an If-None-Match request, when we need to re-validate
if a cached object which has a strong ETag is still valid.
This is also done in the cases an HTTP client request contains HTTP
headers prohibiting a from-cache response (i.e., a "reload" request).
The use of If-None-Match request in this context violates RFC 2616 and
requires using reload-into-ims option within refresh_pattern squid.conf
directive.
The exact definition of a "reload request" and the adjustment/removal of
"reload" headers is the same as currently used for reload-into-ims
option support. This patch is not modifying that code/logic, just adding
an If-None-Match header in addition to the IMS header that Squid already
adds.
Fix external ACL user:pass detail logging after adaptation
When a request is successfully adapted, the external ACL username and
password are now inherited with this patch. This means the
LFT_USER_NAME log token can display the username from an external ACL
if available, for adapted requests.
The HttpRequest will inherit the password for good measure as well -
while none too useful, it seems strange to inherit the username but
not the password.
We can do better than just producing errors about invalid port details
and treatign it as port-0.
We can instead undo the port separation and pass it through as part of
the host name to be verified with the default port number properly
assumed.