1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00
Commit graph

571 commits

Author SHA1 Message Date
Andy Green
6bc5c0ffac reduce debug logging 2020-11-09 07:40:35 +00:00
Andy Green
22e6d5212b spawn: in discrete env setting case do it readonly
OSX changed to blow a segfault on write to .rodata, exposing that
we're dropping a NUL in what can be .rodata to set the environment
manually.  We don't do this on Linux typically because we take the
code path where execvpe() is available to do the env for us.

Adapt the code to treat it as const, and underscore it by changing
its type to be const char ** in the info struct.
2020-10-19 16:35:03 +01:00
Andy Green
643a001ed8 roles: netlink
This creates a role for RFC3549 Netlink monitoring.

If the OS supports it (currently, linux) then each pt creates a wsi
with the netlink role and dumps the current routing table at pt init.
It then maintains a cache of the routing table in each pt.

Upon routing table changes an SMD message is issued as an event, and
Captive Portal Detection is triggered.

All of the pt's current connections are reassessed for routability under
the changed routing table, those that no longer have a valid route or
gateway are closed.
2020-10-19 16:35:03 +01:00
Andy Green
21719898e8 wsi: store peer lws_sockaddr46
If we connect out to an IP address, or we adopt a connected socket,
from now on we want to hold the peer sockaddr in the wsi.

Adapt ACCESS_LOG to use this new copy rather than keep the
stringified version.
2020-10-19 16:35:03 +01:00
Andy Green
67d24d7c00 cleaning 2020-10-19 16:35:03 +01:00
Andy Green
44e860642b docs: switch to use main 2020-10-19 16:35:03 +01:00
Andy Green
657cadf7c6 http: bind PUT and friends to mounts 2020-10-10 06:52:42 +01:00
Andy Green
27964ddaf2 ws: reporting PONG with pmd enabled
Add a return code NOTHING_WE_SHOULD_DO indicating that the
extension determined by ext-specific means its operation was
disabled on this frame.

https://github.com/warmcat/libwebsockets/issues/2076
2020-10-09 08:00:44 +01:00
Andy Green
8c88b857a9 h1: explicitly close when post txn completes
https://github.com/warmcat/libwebsockets/issues/2072
2020-10-06 13:56:45 +01:00
Sakthi Kannan
4e9f433b7e mqtt: fix extra byte on SUBSCRIBE 2020-09-21 17:04:42 +01:00
Andy Green
62e566b9de client: move staged connect pieces into core-net
They have been in lib/roles/http for historical reasons, and all
ended up in client-handshake.c that doesn't describe what they
actually do any more.  Separate out the staged client connect
related stage functions into

  lib/core-net/client/client2.c: lws_client_connect_2_dnsreq()
  lib/core-net/client/client3.c: lws_client_connect_3_connect()
  lib/core-net/client/client4.c: lws_client_connect_4_established()

Move a couple of other functions from there that don't belong out to
tls-client.c and client-http.c, which is related to http and remains
in the http role dir.
2020-09-21 12:47:11 +01:00
Andy Green
21546e511d h2: mark :protocol as an h2 psuedoheader 2020-09-20 09:17:09 +01:00
Andy Green
49e92ba089 http: add RFC7231 date and time helpers and retry-after handling
Teach lws how to deal with date: and retry-after:

Add quick selftest into apt-test-lws_tokenize

Expand lws_retry_sul_schedule_retry_wsi() to check for retry_after and
increase the backoff if a larger one found.

Finally, change SS h1 protocol to handle 503 + retry-after: as a
failure, and apply any increased backoff from retry-after
automatically.
2020-09-19 14:11:56 +01:00
Andy Green
101b474217 ss: rx metadata
At the moment you can define and set per-stream metadata at the client,
which will be string-substituted and if configured in the policy, set in
related outgoing protocol specific content like h1 headers.

This patch extends the metadata concept to also check incoming protocol-
specific content like h1 headers and where it matches the binding in the
streamtype's metadata entry, make it available to the client by name, via
a new lws_ss_get_metadata() api.

Currently warmcat.com has additional headers for

server: lwsws                (well-known header name)
test-custom-header: hello    (custom header name)

minimal-secure-streams test is updated to try to recover these both
in direct and -client (via proxy) versions.  The corresponding metadata
part of the "mintest" stream policy from warmcat.com is

                        {
                                "srv": "server:"
                        }, {
                                "test": "test-custom-header:"
                        },

If built direct, or at the proxy, the stream has access to the static
policy metadata definitions and can store the rx metadata in the stream
metadata allocation, with heap-allocated a value.  For client side that
talks to a proxy, only the proxy knows the policy, and it returns rx
metadata inside the serialized link to the client, which stores it on
the heap attached to the stream.

In addition an optimization for mapping static policy metadata definitions
to individual stream handle metadata is changed to match by name.
2020-09-16 13:10:26 +01:00
Andy Green
5c7b5af92a cmake: disable export visibility when building lws static
This is complicated by the fact extern on a function declaration implies
visibility... we have to make LWS_EXTERN empty when building static.

And, setting target_compile_definitions() doesn't work inside macros,
so it has to be set explicitly for the plugins.

Checking the symbol status needs nm -C -D as per

https://stackoverflow.com/questions/37934388/symbol-visibility-not-working-as-expected

after this patch, libwebsockets.a shows no symbols when checked like that and
the static-linked minimal examples only show -U for their other dynamic
imports.

In a handful of cases we use LWS_EXTERN on extern data declarations,
those then need to change to explicit extern.
2020-09-06 11:46:25 +01:00
Andy Green
4ae3ef51c1 ss: improve callback return consistency
Formalize the LWSSSSRET_ enums into a type "lws_ss_state_return_t"
returned by the rx, tx and state callbacks, and some private helpers
lws_ss_backoff() and lws_ss_event_helper().

Remove LWSSSSRET_SS_HANDLE_DESTROYED concept... the two helpers that could
have destroyed the ss and returned that, now return LWSSSSRET_DESTROY_ME
to the caller to perform or pass up to their caller instead.

Handle helper returns in all the ss protocols and update the rx / tx
calls to have their returns from rx / tx / event helper and ss backoff
all handled by unified code.
2020-08-31 16:51:37 +01:00
Andy Green
e3e177a7d6 smp: add pt lock on client connect path 2020-08-31 16:51:37 +01:00
Andy Green
095b76853e smp: lws_mutex_refcount: add assert held helper
also additional pt locks shown as needed by that
2020-08-31 16:51:37 +01:00
Andy Green
c6c7ab2b44 event libs: default to building as dynamically loaded plugins
Event lib support as it has been isn't scaling well, at the low level
libevent and libev headers have a namespace conflict so they can't
both be built into the same image, and at the distro level, binding
all the event libs to libwebsockets.so makes a bloaty situation for
packaging, lws will drag in all the event libs every time.

This patch implements the plan discussed here

https://github.com/warmcat/libwebsockets/issues/1980

and refactors the event lib support so they are built into isolated
plugins and bound at runtime according to what the application says
it wants to use.  The event lib plugins can be packaged individually
so that only the needed sets of support are installed (perhaps none
of them if the user code is OK with the default poll() loop).  And
dependent user code can mark the specific event loop plugin package
as required so pieces are added as needed.

The eventlib-foreign example is also refactored to build the selected
lib support isolated.

A readme is added detailing the changes and how to use them.

https://libwebsockets.org/git/libwebsockets/tree/READMEs/README.event-libs.md
2020-08-31 16:51:37 +01:00
Andy Green
d98101d1e3 plugins: generalize and provide public api
Move the common plugin scanning dir stuff to be based on lws_dir, which
already builds for windows.  Previously this was done via dirent for unix
and libuv for windows.

Reduce the dl plat stuff to just wrap instantiation and destruction of
dynlibs, establish common code in lib/misc/dir.c for plugin scanning
itself.

Migrate the libuv windows dl stuff to windows-plugins.c, so that he's
available even if later libuv loop support becomes and event lib plugin.

Remove the existing api exports scheme for plugins, just export a const struct
now which has a fixed header type but then whatever you want afterwards depending
on the class / purpose of the plugin.  Place a "class" string in the header so
there can be different kinds of plugins implying different types exported.

Make the plugin apis public and add support for filter by class string, and
per instantation / destruction callbacks so the subclassed header type can
do its thing for the plugin class.  The user provides a linked-list base
for his class of plugins, so he can manage them completely separately and
in user code / user export types.

Rip out some last hangers-on from generic sessions / tables.

This is all aimed at making the plugins support general enough so it can
provide event lib plugins later.
2020-08-31 16:51:37 +01:00
Andy Green
c54a35e1a9 h2: allow empty SETTINGS
https://libwebsockets.org/pipermail/libwebsockets/2020-August/008676.html
2020-08-31 16:51:37 +01:00
Andy Green
fa78129f73 ws: LCCSCF_PRIORITIZE_READS 2020-08-31 16:51:37 +01:00
Andy Green
72b245ea38 h2: fix breakage with LWS_WITH_HTTP2=0 2020-08-31 16:51:37 +01:00
Andy Green
28f4aae555 listen: network filter: provide a struct with client info to the FILTER cb
For backwards compatibility, keep the cast fd on in and pass an info struct
to the callback by overloading user_data.
2020-08-31 16:51:37 +01:00
Andy Green
258ee1886f coverity: 37468: confirm gethostname worked 2020-08-19 07:19:48 +01:00
Andy Green
d69b91d2d9 coverity: 62123: explicitly check things to guide coverity
Coverity sees we sometimes check if header length is 0 and extrapolates
from that not checking header length return is a violation.  But often
we are OK if the header length is 0 and there is no error return to
check from that.

It also doesn't understand that if we saw a nonzero length for a header,
then we are going to get a non-null simple_ptr() return for sure.  Just
give up and explicitly, unneccessarily check everything so coverity can
stop telling us about it.
2020-08-19 07:11:59 +01:00
Andy Green
a8315807e7 coverity: 10417: move goto inside preprocessor conditional that needs it
Otherwise coverity sees it with !defined(LWS_ROLE_WS) sitting there doing nothing
2020-08-19 06:46:19 +01:00
Andy Green
7ff64b3c42 coverity: 10117: help coverity understand simple_ptr cannot be NULL 2020-08-19 06:40:13 +01:00
Andy Green
9679222070 coverity: 62147: setting retcode var is cruft 2020-08-18 14:00:54 +01:00
Andy Green
ad6dfd3df6 coverity: 21071: no need to init accept_fd 2020-08-18 14:00:54 +01:00
Andy Green
d5497d5f55 coverity: 62535: another simple_ptr NULL check after confirmed by other means 2020-08-18 14:00:54 +01:00
Andy Green
398a9e1bad coverity: 62134: protect debug-only statement with preprocessor conditional
Compiler has no problem with it but coverity complains nobody uses p in release build
2020-08-18 14:00:54 +01:00
Andy Green
598a82ca1d coverity: 62512: remove unused assignment 2020-08-18 14:00:54 +01:00
Andy Green
5ef6c548d8 coverity: 62488 62253: comment NOP left in for extensibility 2020-08-18 14:00:54 +01:00
Andy Green
1892af1ce3 coverity: 40529: add needless check on NULL simple_ptr after confirmed it has nonzero length 2020-08-18 14:00:54 +01:00
Andy Green
630391e0fb coverity: 50320: show coverity protocol can always be found by name 2020-08-18 14:00:54 +01:00
Andy Green
b1281f1f3a coverity: 50773: no need to set m any more when transitioning and exiting 2020-08-18 14:00:54 +01:00
Andy Green
cdbf86fe4a coverity: 51248: convince coverity we have an ah attached before dereference during parse 2020-08-18 14:00:54 +01:00
Andy Green
b63c7f1e8e coverity: 62131: check when logging role name for NULL 2020-08-18 14:00:54 +01:00
Andy Green
06005d14b4 coverity: 62154: calculation needed if WITH_FILE_OPS 2020-08-18 09:34:50 +01:00
Andy Green
048604751c coverity: 62584: init m only inside preprocessor conditional that needs it 2020-08-18 09:28:40 +01:00
Andy Green
60e2c65208 coverity: 62333; no need to init cce as set on all paths that use it 2020-08-18 09:19:34 +01:00
Andy Green
400355fdc3 coverity: 62458: coverity doesnt understand nonzero header length means simple_ptr cannot be NULL 2020-08-18 09:19:33 +01:00
Andy Green
9745c5cca8 coverity: 62477: explicitly check wsi->protocol even though client creation sets it 2020-08-18 09:11:45 +01:00
Andy Green
192b76c89b coverity: 62540: explicitly check for NULL even though cannot be 2020-08-18 09:08:03 +01:00
Andy Green
0f173e0bbe coverity: 62622: remove unused line 2020-08-18 09:00:39 +01:00
Andy Green
7692d920a8 coverity: 244441: strerror broken on some platforms
Some platforms have strerror but it's broken according to Coverity.
Let's avoid it
2020-08-14 09:14:24 +01:00
Andy Green
491f0f6068 coverity: 324943: confirm get_random worked
In normal systems this doesn't have a way to fail.  But check it for
consistency.
2020-08-14 09:07:27 +01:00
Andy Green
aec2bdec2f coverity: 324897: mqtt: check unsub var for NULL 2020-08-14 09:02:29 +01:00
Andy Green
795d20081e coverity: 232068: hpack 6-bit index may be garbage
It's possible an attacker may send an illegal dynamic index
we can't succeed to look up
2020-08-14 08:56:19 +01:00