aboutsummaryrefslogtreecommitdiffstats
path: root/net
Commit message (Collapse)AuthorAgeFilesLines
* net.httpserver: Remove obsolete APIMatthew Wild2 days1-17/+0
|
* net.adns: Collect DNS lookup timing metricsKim Alvefur9 days2-5/+20
| | | | Nice to have this in OpenMetricts instead of debug logs
* net.server_epoll: Call :shutdown() on TLS sockets when supportedMartijn van Duren10 days1-0/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Comment from Matthew: This fixes a potential issue where the Prosody process gets blocked on sockets waiting for them to close. Unlike non-TLS sockets, closing a TLS socket sends layer 7 data, and this can cause problems for sockets which are in the process of being cleaned up. This depends on LuaSec changes which are not yet upstream. From Martijn's original email: So first my analysis of luasec. in ssl.c the socket is put into blocking mode right before calling SSL_shutdown() inside meth_destroy(). My best guess to why this is is because meth_destroy is linked to the __close and __gc methods, which can't exactly be called multiple times and luasec does want to make sure that a tls session is shutdown as clean as possible. I can't say I disagree with this reasoning and don't want to change this behaviour. My solution to this without changing the current behaviour is to introduce a shutdown() method. I am aware that this overlaps in a conflicting way with tcp's shutdown method, but it stays close to the OpenSSL name. This method calls SSL_shutdown() in the current (non)blocking mode of the underlying socket and returns a boolean whether or not the shutdown is completed (matching SSL_shutdown()'s 0 or 1 return values), and returns the familiar ssl_ioerror() strings on error with a false for completion. This error can then be used to determine if we have wantread/wantwrite to finalize things. Once meth_shutdown() has been called once a shutdown flag will be set, which indicates to meth_destroy() that the SSL_shutdown() has been handled by the application and it shouldn't be needed to set the socket to blocking mode. I've left the SSL_shutdown() call in the LSEC_STATE_CONNECTED to prevent TOCTOU if the application reaches a timeout for the shutdown code, which might allow SSL_shutdown() to clean up anyway at the last possible moment. Another thing I've changed to luasec is the call to socket_setblocking() right before calling close(2) in socket_destroy() in usocket.c. According to the latest POSIX[0]: Note that the requirement for close() on a socket to block for up to the current linger interval is not conditional on the O_NONBLOCK setting. Which I read to mean that removing O_NONBLOCK on the socket before close doesn't impact the behaviour and only causes noise in system call tracers. I didn't touch the windows bits of this, since I don't do windows. For the prosody side of things I've made the TLS shutdown bits resemble interface:onwritable(), and put it under a combined guard of self._tls and self.conn.shutdown. The self._tls bit is there to prevent getting stuck on this condition, and self.conn.shutdown is there to prevent the code being called by instances where the patched luasec isn't deployed. The destroy() method can be called from various places and is read by me as the "we give up" error path. To accommodate for these unexpected entrypoints I've added a single call to self.conn:shutdown() to prevent the socket being put into blocking mode. I have no expectations that there is any other use here. Same as previous, the self.conn.shutdown check is there to make sure it's not called on unpatched luasec deployments and self._tls is there to make sure we don't call shutdown() on tcp sockets. I wouldn't recommend logging of the conn:shutdown() error inside close(), since a lot of clients simply close the connection before SSL_shutdown() is done.
* net.server_epoll: Don't try to flush buffer on closed connectionsKim Alvefur2024-11-191-1/+2
| | | | | | | | | Attempt to fix a bug where connections are somehow closed twice, leading to bad things happening elsewhere. With LuaSec, closed connections are generally already too closed to write anything to anyway since it does not support unidirectional shutdown.
* net.server_epoll: Revert opportunistic_writes tweakKim Alvefur2024-11-191-3/+0
| | | | Added in f0b2c026e542 and not sure why
* net.server_epoll: Make running out of buffer space a fatal errorKim Alvefur2024-11-091-0/+6
| | | | | | | Prevent Bad Things from happening when the buffer gets full. This of course opens up the possibility of intentionally killing connections by sending much stuff, which need to be mitigated with rate limits elsewhere.
* net.server_epoll: Improve efficiency of sending much buffered dataKim Alvefur2024-11-091-34/+68
| | | | | | | | | | | | | | Problem: The string slice operations when a lot of data gets buffered ends up being expensive and memory-consuming. We have util.dbuffer for precisely this kind of thing. I want to keep the behavior of writebuffer being upgraded from nil to a string to full buffer since the last step involves three table allocations, where the previous buffer method only used one. Avoiding those allocations for simple writes like white space keep alive feels like it would keep memory churn down. This work was started in 2020
* util.error: Use is_error() instead of is_err() everywhereKim Alvefur2024-10-291-1/+1
| | | | Continuation of 4b39691a274e
* Merge 0.12->trunkKim Alvefur2024-08-161-0/+3
|\
| * net.http: Throw error if missing TLS context for HTTPS requestKim Alvefur2024-08-081-0/+3
| | | | | | | | | | | | | | Prevents the mistake of creating a http context without any TLS context and then trying to use HTTPS, which doesn't work right. Thanks nils
* | util.sslconfig: Support DH parameters as literal stringKim Alvefur2024-07-121-1/+4
| | | | | | | | Simplifies shipping well-known DH parameters in the config
* | Merge 0.12->trunkKim Alvefur2024-07-071-1/+16
|\|
| * net.server_event: Add 'wrapserver' APIKim Alvefur2024-07-071-1/+16
| | | | | | | | | | | | | | | | | | This enables accepting admin stream socket (UNIX) connections trough the same procedures as any other (TCP) socket, which avoids problems caused by using the wrapclient API, which ends up discarding early data due to only expecting early connection failure. Fixes #1867
* | net.server_epoll: Add support for systemd socket activationKim Alvefur2024-05-141-0/+40
| | | | | | | | | | | | | | | | | | | | Allows creating listening sockets and accepting client connections before Prosody starts. This is unlike normal Prosody dynamic resource management, where ports may added and removed at any time, and the ports defined by the config. Weird things happen if these are closed (e.g. due to reload) so here we prevent closing and ensure sockets are reused when opened again.
* | net.unbound: Show canonical name in textual format (e.g. in shell)Kim Alvefur2024-04-141-1/+5
| | | | | | | | | | | | | | libunbound does not tell us the whole chain of CNAMEs, only the final canonical name. This is to aid in debugging since it will only be shown in the shell.
* | net.server: Restore epoll signalfd handlingKim Alvefur2024-03-021-5/+0
| | | | | | | | Reverts 4a9a69659727
* | net.server: Disable epoll signalfd handling by default until problems resolvedKim Alvefur2024-03-011-0/+5
| |
* | net.server_epoll: Log creation of signalfd handles at noise levelKim Alvefur2024-03-011-0/+1
| | | | | | | | To aid in tracking down signalfd-related problems
* | net.server_epoll: Log failure to hook signalsKim Alvefur2024-02-281-1/+6
| | | | | | | | To make any such failures noticeable
* | Merge 0.12->trunkKim Alvefur2024-02-271-1/+1
|\|
| * net.http.files: Validate argument to setup functionKim Alvefur2024-02-271-1/+1
| | | | | | | | Fixes error in #1765 by throwing an error earlier
* | util.signal: Wrap signalfd in an userdatum for gc handling etcKim Alvefur2024-02-241-1/+2
| |
* | net.server_epoll: Support hooking signals via signalfdKim Alvefur2024-02-241-0/+15
| | | | | | | | | | | | Handling signal events the same way as all other events makes sense and seems safer than the signal handling just jumping around in C and messing with Lua states.
* | net.server_epoll: Prevent traceback when checking TLS after connection goneKim Alvefur2024-01-211-0/+5
| | | | | | | | Unclear why this would be done, but an error is not great.
* | net.http.server: Fix whitespace-ignoring syntaxKim Alvefur2023-12-011-2/+2
| |
* | Merge 0.12->trunkKim Alvefur2023-12-011-1/+7
|\|
| * net.http.parser: Reject overlarge header section earlierKim Alvefur2023-08-231-1/+7
| | | | | | | | This case would eventually be rejected by the buffer size limit.
* | net.http.server: Complete async waiter for non-persistent connectionsKim Alvefur2023-11-241-3/+2
| | | | | | | | | | | | | | | | | | Otherwise requests with Connection: close would be stuck in the async wait that starts after the handle_request() call. Together with the new async debugging, this makes the async thread stay in the set of waiting runners forever, where previously it would simply be garbage collected.
* | net.server_epoll: Avoid call to update socket watch flags when nothing changedKim Alvefur2023-11-211-0/+3
| | | | | | | | Should skip a syscall for each write when using epoll.
* | net.http: Set Connection header based on connection pool usageKim Alvefur2023-11-111-1/+8
| | | | | | | | Connection: keep-alive is implicit in HTTP/1.1 but explicit > implicit
* | net.http: Add simple connection poolingKim Alvefur2023-11-111-1/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This should speed up repeated requests to the same site by keeping their connections around and sending more requests on them. Sending multiple requests at the same time is not supported, instead a request started while another to the same authority is in progress would open a new one and the first one to complete would go back in the pool. This could be investigated in the future. Some http servers limit the number of requests per connection and this is not tested and could cause one request to fail, but hopefully it will close the connection and prevent it from being reused.
* | net.http.server: Fix typo in previous commitKim Alvefur2023-09-231-1/+1
| |
* | net.http.server: Support setting Content-Type of uncaught HTTP errorsKim Alvefur2023-09-221-1/+6
| | | | | | | | | | | | | | | | mod_http_errors normally sets the Content-Type header via the response object, which isn't available when handling these uncaught errors. Without a Content-Type header the browser is forced to guess, which may or may not result in something sensible.
* | net.websocket.frames: Remove completed TODOKim Alvefur2023-07-291-1/+0
| | | | | | | | The XOR is done in C since 4e5a2af9dd19
* | net.server: Handle loading from outside Prosody (e.g. Verse)Kim Alvefur2023-05-201-15/+20
| | | | | | | | | | server_select only depending on LuaSocket generally makes it more portable, so fall back to that if util.poll can't be found.
* | net.http.server: Return request ID in header to aid debuggingKim Alvefur2023-05-291-1/+1
| | | | | | | | Eases locating the request in logs
* | net.tls_luasec: Expose method for loading a certificateKim Alvefur2023-05-271-0/+1
| | | | | | | | | | Further isolates LuaSec from Prosody core, with the ultimate goal of allowing LuaSec to be replaced more easily.
* | net.certmanager: Move LuaSec feature detection to net.tls_luasecKim Alvefur2023-05-271-0/+24
| | | | | | | | | | Further isolates LuaSec from Prosody core, with the ultimate goal of allowing LuaSec to be replaced more easily.
* | net.http.server: Remove "Firing event" logs, use event logging insteadKim Alvefur2023-05-141-4/+0
| | | | | | | | | | | | | | | | Since these are noisy and we have the thing in util.helpers to log events fired. The new status line events are meant to replace these as they include more useful info.
* | net.http.server: Log request and response status linesKim Alvefur2023-05-141-0/+3
| | | | | | | | Points out the beginning and end of a request.
* | net.http.server: Assign each request its own log sourceKim Alvefur2023-05-141-5/+8
| |
* | net.http.server: Assign an ID to each request, shared with responseKim Alvefur2023-05-141-0/+3
| | | | | | | | | | Goal is improve tracking of individual HTTP requests throughout its life-cycle. Having a single ID to use in logging should help here.
* | net: Prefix module imports with prosody namespaceKim Alvefur2023-03-1720-108/+108
| |
* | Merge 0.12->trunkMatthew Wild2023-02-171-2/+3
|\|
| * net.http.parser: Fix off-by-one error in chunk parserMatthew Wild2023-02-171-2/+3
| |
* | Merge 0.12->trunkMatthew Wild2023-02-161-0/+4
|\|
| * net.http.server: Add new API to get HTTP request from a connectionMatthew Wild2023-02-161-0/+4
| | | | | | | | | | | | | | | | | | | | | | This information is sometimes necessary in the context where we have a connection that we know (or believe to be) associated with an incoming HTTP request. For example, it can be used to retrieve the IP address of a request (which may differ from the IP address of the connection, due to X-Forwarded-For and co). Thanks to the Jitsi team for highlighting this gap in the API.
* | Merge 0.12->trunkMatthew Wild2023-02-092-7/+12
|\|
| * net.http.parser: Improve handling of responses without content-lengthMatthew Wild2023-02-091-6/+11
| | | | | | | | | | | | This ensures that we support responses without a content-length header, and allow streaming them through the streaming handler interface. An example of such a response would be Server-Sent Events streams.
| * net.http: Add missing log parameterMatthew Wild2023-02-091-1/+1
| |