Commit graph

153 commits

Author SHA1 Message Date
Tor Lillqvist
ed5569da30 Handle poll results in SocketPoll in a round-robin order
We don't want to always start with the most recently added socket.

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: Ic4b4bf6c19c5d119e6e6f9b398789a4c77b47a10
2021-08-21 15:30:18 +01:00
Gleb Popov
20c2ab5663 Remove non-abstract unix socket files on shutdown.
Signed-off-by: Gleb Popov <6yearold@gmail.com>
Change-Id: I54773de6d4f777f9188921d5aa99c052f0f79b34
2021-07-31 07:43:45 +03:00
Gleb Popov
950a5c4d1a Use more sensible value for #ifdef when checking for abstract unix sockets.
Signed-off-by: Gleb Popov <6yearold@gmail.com>
Change-Id: Icfd849424659c8949f8f3554aa75a8a7ceaf7ac2
2021-07-31 07:43:45 +03:00
Gopi Krishna Menon
b3d5a2563c Add profilezone around kitPoll function and SocketPoll constructor
Add profile zone around kitPoll function and SocketPoll constructor to
improve trace event generation

Signed-off-by: Gopi Krishna Menon <krishnagopi487.github@outlook.com>
Change-Id: Ia46e9add59a57935997649fe39861a8d851e1ff0
2021-07-21 15:00:31 +03:00
Ashod Nakashian
4c87cc36ff wsd: Close socket hard when necessary
Also clear its input buffer explicitly.

Change-Id: I8badbb96d98eaf10433a65fcfd13b0d6d5893594
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>

Ignore input in a somewhat gentler way.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: I758302dc3bb1aa87f9fbfa726f73f4b9339e08c2
2021-07-19 17:31:55 +01:00
Ashod Nakashian
0d59630b48 wsd: killpoco: cert verification
Change-Id: Ie9bc96183d1e416ef4b9b455eefb1f9249b2f695
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-07-18 21:14:48 -04:00
Ashod Nakashian
f63d077916 wsd: ssl certificate verification requirements
Change-Id: I72ffa586310296f1986276c3007672c41146c92b
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-07-18 21:14:48 -04:00
Ashod Nakashian
f702c4efab wsd: support certificate verification
Change-Id: I912595f104e24dc66da9cf06bc211cb0c50c9ff0
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-07-18 21:14:48 -04:00
Michael Meeks
7ed4b4f7e7 Use larger write buffer size for UDS from kit -> wsd.
We send lots of large tile data this way, this should help
accelerate tile data transfer marginally.

Change-Id: I1deab7845c09dc65b1f44e9f9fc762f70ce94cc3
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2021-06-04 14:58:36 +01:00
merttumer
5742acd87c android: Fix build fail and crash on doc load
Signed-off-by: merttumer <mert.tumer@collabora.com>
Change-Id: Id998e2bdf7051d54784543015c7d34c0bdd64543
2021-05-02 21:47:37 -07:00
Ashod Nakashian
0dbecddb3a wsd: http: simplify sending response and shutting down the socket
Change-Id: Id4e32c8eb79458d060767a7a5ac26476e2f84331
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-05-02 22:35:39 -04:00
Gleb Popov
742cda8b46 Don't try use abstract unix sockets on !Linux platforms.
Signed-off-by: Gleb Popov <6yearold@gmail.com>
Change-Id: Iaad2159ef2c5a45c52f0c7224d58a8160bb5f260
2021-04-30 20:30:56 +01:00
Gleb Popov
f11ca121a4 Use SOL_LOCAL value instead of 0 in getsockopt() calls.
Signed-off-by: Gleb Popov <6yearold@gmail.com>
Change-Id: I5a58a73541de2a32c5a03ebef5618b1541209d8d
2021-04-30 20:30:56 +01:00
Ashod Nakashian
3decba7eec wsd: specify the minimum bytes we can write to the socket
When writing to the socket, it's always more efficient
to fill the buffer up to the hardware limit for each
write. This is doubly important for efficiency with
SSL, due to the overhead of encrypting multiple
small buffers instead of one large one.

Currently we don't write more than one message
at a time, primarily due to limitations in
the Poco sockets in the unit-tests, which
have a hard time consuming multiple WS frames
with a single poll (subsequent calls to poll
doesn't enter signalled state until new data
arrives, possibly because the data is read and
buffered internally, making the whole scheme
of using poll unreliable and meaningless).

Change-Id: Ic2e2cf1babfb5ab4116efd93f392977ba234d92b
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-27 17:48:23 -04:00
Michael Meeks
e26fac4665 Use the accepted socket, not the listening one.
Change-Id: Iecaa90f4c3030b5b2e20bb0e33ef9b75717bb578
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2021-04-23 16:36:38 +01:00
Ashod Nakashian
4f05d69815 wsd: use http::Request for internal WS and simplify
Also, enable validation of WebSocket keys.

Change-Id: I226607b18a14d023bc9c55762580fd1cb47493f9
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
2e4524ad57 wsd: use WebSocketHandler instead of explicit WebSocket request
Now that the WebSocket functionality is available in
WebSocketHandler, we can cleanup Socket.

Change-Id: Ia3703ab5a2f00fb835eb80493bc400a91dabefad
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
f53e928530 wsd: http: support sending Request and Response in Socket
Improved handling of http::Request and http::Response
in Socket directly with better error handling and
automatic socket shutdown on error.

We shouldn't need to manually serialize into the
socket's buffer when sending a Request or Response.

Change-Id: I6dfcd2fe4f6b88cd2fa8c749045ce25a8c52fe9a
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-03 19:57:03 -04:00
Ashod Nakashian
88dbe155e4 wsd: http: support sending http::Response directly to the socket
The Socket now accepts http::Response and
serializes it before sending it.

Change-Id: Id36e2d91b21d168da72ccdbd7e509ec08021b78e
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-02 13:58:06 -04:00
Ashod Nakashian
54a10729f3 killpoco: replace Poco::icompare
Change-Id: I9b8154538c85593f054afd17bd588a593b803e98
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-02 13:18:41 -04:00
Ashod Nakashian
f494c27024 wsd: correct User-Agent usage in http headers
User-Agent is designed for client-side use only,
in http requests. For servers, the Server header
is designed to announce the server name and version.

This tries to normalize the use and documents
the proper intent and usage.

Change-Id: I42d68d65611cab64c45adf03fe74f9466798b093
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-22 10:09:22 -04:00
Ashod Nakashian
160f87bab0 wsd: encapsulate ServerSocket::_socketFactory
Change-Id: I3d880d06d5ea537cddb4c572f3439ea6061e51bf
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-16 08:27:46 -04:00
Ashod Nakashian
293d1c0a2a wsd: detect misuse of SocketPoll::startThread
There are scenarios where startThread is
called either when the thread is already
running or when it has long since finished.

Logs are added to catch them, and better
document the expected behavior in those
cases (they shouldn't happen).

Change-Id: I219a59b92c943445ec4520667a8ed6d9bd1c328d
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-13 19:34:02 -05:00
Ashod Nakashian
9ce552b5a5 wsd: better logging
Change-Id: I9c6bfcc22b1d80a27a4b4fa7229766d95fc62f9a
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-13 19:34:02 -05:00
Ashod Nakashian
e6fe7c0bd0 wsd: improved thread ownership management and logging
Change-Id: I00a7dc303a873cc249ec56db0611d104557bbf45
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-13 19:34:02 -05:00
Ashod Nakashian
0cd55fde61 wsd: better socket logging
Change-Id: If7d8411b40510d4942c6ef7a1c248f587b7dbdae
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-13 19:34:02 -05:00
Ashod Nakashian
5467a7f7ef wsd: simplify and document dumpHex
Change-Id: I636dd6548b0712a72dfc162eb7381e3e7ac18b5a
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-13 19:34:02 -05:00
Ashod Nakashian
6e7c5b6013 wsd: improved SocketPoll start-thread guard
Change-Id: I92e2bcf4efacd67fc336ab40194d8cc51da7e4f4
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-11 09:15:40 -05:00
Ashod Nakashian
0f9f7629b5 wsd: better logging of socket activity
Especially error reporting is now better.

Change-Id: I032f6e8403660c2ac24be2d80b53b63831ec1066
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-11 09:15:40 -05:00
Ashod Nakashian
5371715a52 wsd: logging improvements
Change-Id: Ic887c42f0ca844e54bfc054e9c0706bbec7ebb6f
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-01 21:50:18 -05:00
Ashod Nakashian
7a13fa0943 wsd: socket error simulation to maintain the ssl state
SSL signals whether it needs more data to read or write
so that we perform the appropriate polling and call
the respective API. Since during error simulation
we skip calling the SSL API altogether, we shouldn't
change the last desired operation it communicated to us.

This becomes clear when we consider that we always read,
unconditionally, in StreamSocket::handlePoll (but write
only when poll signals POLLOUT event). This means that
if we decide to simulate a socket error during such
uncoditional read, and SSL wants to write, we would
reset its last wantsTo flag from write to read!

Logically, since we aren't even invoking any SSL API
during a simulated error, we shouldn't change the
SSL state one way or the other.

Change-Id: Ie4ddbc959f8424ea4ac3bc52f30edbc7399b2c7a
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-01 21:48:43 -05:00
Ashod Nakashian
3982c7b34f wsd: set errno when simulating socket errors for SSL
The API is the same for both SSL and non-SSL sockets
(they are virtual functions), and the API relies on
errno to detect errors and decide to retry, log, or
break. As such, we must set the same EAGAIN when
simulating socket errors for both SSL and non-SSL
cases, so that the behavior would also be the same.

Change-Id: Ib1695cc94d93f5ecc53d7b22872f459ac8b11bbd
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-01 21:48:43 -05:00
Ashod Nakashian
ce3dd02ef3 wsd: new NetUtil file for network utilities
Move the connect function into the NetUtil
translation unit to aid using it for the
upcoming async socket logic.

The NetUtil should also come in handy for
the miscellaneous network helpers we have.

Change-Id: I2ee0c6e3e1769fd87572d7407d3b4979b59ffe6a
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-01-13 22:05:18 -05:00
Ashod Nakashian
417d19bce6 wsd: log when simulating socket error to help troubleshoot
When we simulate socket error it's hard to understand
what is going on, since there is no real errno to
explain the -1 return value. This is at least true
in the SSL case where we don't set errno (perhaps
we should?). At any rate, it's good form to log
that we are messing up with the return value and
that the real socket API hasn't been even invoked.

Change-Id: Ib76f0259dbdcfe0cfae97343c11ca45461079fa1
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-01-13 16:24:29 -05:00
Ashod Nakashian
06c5c90dd5 wsd: test: support SSL in classic tests
Add support for configuring the SSL certificates
when running the test binary as well as setting
up the SSL context.

Also adds the SSL socket headers with proper
compile-time guards for when SSL is disabled.

Change-Id: I99992639a66a64871f8ff8a2b2105279ead63ca1
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-01-13 08:07:06 -05:00
Ashod Nakashian
81d794bf9d wsd: chrono type-safe usage
Change-Id: I1e6bc4724672d3e86ad997d7b13ff9db87aade1e
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-01-10 11:13:08 -05:00
Ashod Nakashian
01138d7ae0 wsd: save errno before invoking any other functions
Most C and Posix API clobber errno. By failing to save
it immediately after invoking an API we risk simply
reporting the result of an arbitrary subsequent API call.

This adds LOG_SYS_ERRNO to take errno explicitly.
This is necessary because sometimes logging is not done
immediately after calling the function for which we
want to report errno. Similarly, log macros that log
errno need to save errno before calling any functions.
This is necessary as the argements might contain calls
that clobber errno.

This also converts some LOG_SYS entries to LOG_ERR
because there can be no relevant errno in that context
(f.e. in a catch clause).

A couple of LOG_ macros have been folded into others,
reducing redundancy.

Finally, both of these log macros append errno to the
log message, so there is little point in ending the
messages with a period.

Change-Id: Iecc656f67115fec78b65cad4e7c17a17623ecf43
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2020-12-29 11:40:17 +00:00
Ashod Nakashian
693a2e19e3 wsd: SocketPoll::poll accepts chrono duration
Cleans up some of the conversions and implicity
unit in integral types.

Change-Id: I79f35b92f8f631894e55bdb39851b050870fce96
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2020-12-22 11:24:13 -05:00
Tamás Zolnai
e0c1d4e96b Fix --disable-ssl build.
Signed-off-by: Tamás Zolnai <tamas.zolnai@collabora.com>
Change-Id: I6b38a68462c6c89a95ded5ac795702c18a7b762a
2020-12-14 11:59:59 +01:00
Michael Meeks
1cd41fd4e6 Simulate EAGAIN in debug mode, every seventh operation.
Hopefully reasonably simple; we perturb the count in the poll to
avoid starving a seventh socket in a poll.

Change-Id: I1a39cc36b9599ffe82186b896c6fd91d792c4127
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2020-12-10 11:53:02 +00:00
Michael Meeks
c069f72c4d Socket - re-work disposition to ensure we transfer sockets.
A number of call-sites, eg. clipboard, or admin-ws were
writing to sockets assuming they could return all the data
in a single series of writes, without needing to poll. As
such they failed to addSocketToPoll on the new poll - eg.
the docBroker. Unfortunately this meant that on EAGAIN
writes, the socket would be closed and the last parts
of a message lost.

Browsers would give net::ERR_CONTENT_LENGTH_MISMATCH 200 (OK)

The situation is/was intermittent, so painful to debug.
On under-loaded developer machines, socket buffers are larger,
so this was seldom seen.

The re-factor forces a transfer to another SocketPoll via
the disposition, except for a couple of corner cases.

Change-Id: I2f1b2f99f179c4fda84464c9241fe434fa527725
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2020-12-07 14:32:43 +00:00
Michael Meeks
0fc91ef31c Adapt Buffer class to avoid repeated compactions.
Avoid continually shuffling large output buffers down in memory,
it kills CPU caches, does nothing useful, and we can just advance
an offset instead. Of course, we do need to free memory - so do
that for lots of common cases.

Change-Id: I63240661ca87bdc0574acbce856771d9dde3fa94
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2020-11-29 19:27:23 -05:00
Michael Meeks
e00392647b pure re-factor, creating Buffer class to wrap vector.
For large transfers eg. image previews, particularly with SSL's
protocol limit of 16k byte blocks, we see lots of inefficiency
repeatedly copying a 20Mb image and shuffling it down a
std::vector as we write data out.

Change-Id: I620568cad2e6f41684c35289b0ee77cf7f59c077
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2020-11-29 19:27:23 -05:00
Ashod Nakashian
b47148ec16 wsd: log the socket id on websrv_poll
Otherwise, there is no way to know which connection
a given log belongs to, when websrv_poll handles
multiple simultaneous connections.

Also removed a duplicate log entry.

Change-Id: Id74e6e7b66062daf15a716b9fea8e7995fd75af0
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2020-11-16 23:46:08 -05:00
Gleb Popov
8c6cbedd58 Socket.cpp: Use LOCAL_PEERCRED flag on FreeBSD instead of SO_PEERCRED.
Change-Id: I3e53f3af102b11f0dd51b8c8d97c3367d83fd09e
Signed-off-by: Gleb Popov <6yearold@gmail.com>
2020-11-16 14:02:23 +00:00
Ashod Nakashian
0d031e19ef wsd: move HttpHelper namespace from Socket to its home
This is non-functional change to have all HttpHelper
members in a single place (HttpHelper.cpp).

Clang-format is applied and FileUtil::Stat is used
instead of a naked stat(2).

Change-Id: I663e2eb3070e873bd1f4477b60e45b0086d29f4e
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2020-11-02 07:56:03 -05:00
Ashod Nakashian
8f2ded18da wsd: misc minor cleanup
Change-Id: I39911e6a6b16661173ae69e39d353e517857f282
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2020-11-02 07:56:03 -05:00
Andras Timar
0002fdfd6c fix license headers
Change-Id: I8623770b32d278a45357dc7f757fabfadd2b4af7
2020-10-01 11:56:43 +02:00
Tor Lillqvist
980b7b04a6 Add a FIXME
Change-Id: I7d54f77c5661b04616c04d1807966b9e1ccea485
2020-07-08 17:34:20 +03:00
Ashod Nakashian
5c9988f2e3 wsd: faster jail setup via bind-mount
loolmount now works and supports mounting and
unmounting, plus numerous improvements,
refactoring, logging, etc..  When enabled,
binding improves the jail setup time by anywhere
from 2x to orders of magnitude (in docker, f.e.).

A new config entry mount_jail_tree controls
whether mounting is used or the old method of
linking/copying of jail contents. It is set to
true by default and falls back to linking/copying.
A test mount is done when the setting is enabled,
and if mounting fails, it's disabled to avoid noise.

Temporarily disabled for unit-tests until we can
cleanup lingering mounts after Jenkins aborts our
build job. In a future patch we will have mount/jail
cleanup as part of make.

The network/system files in /etc that need frequent
refreshing are now updated in systemplate to make
their most recent version available in the jails.
These files can change during the course of loolwsd
lifetime, and are unlikely to be updated in
systemplate after installation at all. We link to
them in the systemplate/etc directory, and if that
fails, we copy them before forking each kit
instance to have the latest.

This reworks the approach used to bind-mount the
jails and the templates such that the total is
now down to only three mounts: systemplate, lo, tmp.

As now systemplate and lotemplate are shared, they
must be mounted as readonly, this means that user/
must now be moved into tmp/user/ which is writable.

The mount-points must be recursive, because we mount
lo/ within the mount-point of systemplate (which is
the root of the jail). But because we (re)bind
recursively, and because both systemplate and
lotemplate are mounted for each jails, we need to
make them unbindable, so they wouldn't multiply the
mount-points for each jails (an explosive growth!)
Contrarywise, we don't want the mount-points to
be shared, because we don't expect to add/remove
mounts after a jail is created.

The random temp directory is now created and set
correctly, plus many logging and other improvements.

Change-Id: Iae3fda5e876cf47d2cae6669a87b5b826a8748df
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92829
Tested-by: Jenkins
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
2020-07-01 05:42:43 +02:00