2020-03-28 16:20:50 +00:00
|
|
|
/*
|
|
|
|
* libwebsockets - small server side websockets and web server implementation
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 - 2020 Andy Green <andy@warmcat.com>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to
|
|
|
|
* deal in the Software without restriction, including without limitation the
|
|
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
* sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* This is the glue that wires up raw-socket to Secure Streams.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <private-lib-core.h>
|
|
|
|
|
|
|
|
int
|
|
|
|
secstream_raw(struct lws *wsi, enum lws_callback_reasons reason, void *user,
|
|
|
|
void *in, size_t len)
|
|
|
|
{
|
2020-11-10 11:27:28 +00:00
|
|
|
#if defined(LWS_WITH_SERVER)
|
|
|
|
struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi];
|
|
|
|
#endif
|
2020-03-28 16:20:50 +00:00
|
|
|
lws_ss_handle_t *h = (lws_ss_handle_t *)lws_get_opaque_user_data(wsi);
|
|
|
|
uint8_t buf[LWS_PRE + 1520], *p = &buf[LWS_PRE],
|
|
|
|
*end = &buf[sizeof(buf) - 1];
|
2020-08-26 11:05:41 +01:00
|
|
|
lws_ss_state_return_t r;
|
2020-03-28 16:20:50 +00:00
|
|
|
size_t buflen;
|
2020-06-01 07:33:37 +01:00
|
|
|
int f = 0;
|
2020-03-28 16:20:50 +00:00
|
|
|
|
|
|
|
switch (reason) {
|
|
|
|
|
|
|
|
case LWS_CALLBACK_CLIENT_CONNECTION_ERROR:
|
|
|
|
assert(h);
|
|
|
|
assert(h->policy);
|
2020-12-25 05:54:19 +00:00
|
|
|
lwsl_info("%s: %s, %s CLIENT_CONNECTION_ERROR: %s\n", __func__,
|
|
|
|
lws_ss_tag(h), h->policy->streamtype, in ? (char *)in : "(null)");
|
ss: sspc: add conmon performance telemetry
This provides a way to get ahold of LWS_WITH_CONMON telemetry from Secure
Streams, it works the same with direct onward connections or via the proxy.
You can mark streamtypes with a "perf": true policy attribute... this
causes the onward connections on those streamtypes to collect information
about the connection performance, and the unsorted DNS results.
Streams with that policy attribute receive extra data in their rx callback,
with the LWSSS_FLAG_PERF_JSON flag set on it, containing JSON describing the
performance of the onward connection taken from CONMON data, in a JSON
representation. Streams without the "perf" attribute set never receive
this extra rx.
The received JSON is based on the CONMON struct info and looks like
{"peer":"46.105.127.147","dns_us":596,"sockconn_us":31382,"tls_us":28180,"txn_resp_us:23015,"dns":["2001:41d0:2:ee93::1","46.105.127.147"]}
A new minimal example minimal-secure-streams-perf is added that collects
this data on an HTTP GET from warmcat.com, and is built with a -client
version as well if LWS_WITH_SECURE_STREAMS_PROXY_API is set, that operates
via the ss proxy and produces the same result at the client.
2021-03-31 13:20:34 +01:00
|
|
|
|
2021-08-03 15:25:39 +08:00
|
|
|
#if defined(LWS_WITH_CONMON)
|
ss: sspc: add conmon performance telemetry
This provides a way to get ahold of LWS_WITH_CONMON telemetry from Secure
Streams, it works the same with direct onward connections or via the proxy.
You can mark streamtypes with a "perf": true policy attribute... this
causes the onward connections on those streamtypes to collect information
about the connection performance, and the unsorted DNS results.
Streams with that policy attribute receive extra data in their rx callback,
with the LWSSS_FLAG_PERF_JSON flag set on it, containing JSON describing the
performance of the onward connection taken from CONMON data, in a JSON
representation. Streams without the "perf" attribute set never receive
this extra rx.
The received JSON is based on the CONMON struct info and looks like
{"peer":"46.105.127.147","dns_us":596,"sockconn_us":31382,"tls_us":28180,"txn_resp_us:23015,"dns":["2001:41d0:2:ee93::1","46.105.127.147"]}
A new minimal example minimal-secure-streams-perf is added that collects
this data on an HTTP GET from warmcat.com, and is built with a -client
version as well if LWS_WITH_SECURE_STREAMS_PROXY_API is set, that operates
via the ss proxy and produces the same result at the client.
2021-03-31 13:20:34 +01:00
|
|
|
lws_conmon_ss_json(h);
|
2021-08-03 15:25:39 +08:00
|
|
|
#endif
|
ss: sspc: add conmon performance telemetry
This provides a way to get ahold of LWS_WITH_CONMON telemetry from Secure
Streams, it works the same with direct onward connections or via the proxy.
You can mark streamtypes with a "perf": true policy attribute... this
causes the onward connections on those streamtypes to collect information
about the connection performance, and the unsorted DNS results.
Streams with that policy attribute receive extra data in their rx callback,
with the LWSSS_FLAG_PERF_JSON flag set on it, containing JSON describing the
performance of the onward connection taken from CONMON data, in a JSON
representation. Streams without the "perf" attribute set never receive
this extra rx.
The received JSON is based on the CONMON struct info and looks like
{"peer":"46.105.127.147","dns_us":596,"sockconn_us":31382,"tls_us":28180,"txn_resp_us:23015,"dns":["2001:41d0:2:ee93::1","46.105.127.147"]}
A new minimal example minimal-secure-streams-perf is added that collects
this data on an HTTP GET from warmcat.com, and is built with a -client
version as well if LWS_WITH_SECURE_STREAMS_PROXY_API is set, that operates
via the ss proxy and produces the same result at the client.
2021-03-31 13:20:34 +01:00
|
|
|
|
2020-08-26 11:05:41 +01:00
|
|
|
r = lws_ss_event_helper(h, LWSSSCS_UNREACHABLE);
|
|
|
|
if (r == LWSSSSRET_DESTROY_ME)
|
2020-12-22 15:56:41 +00:00
|
|
|
return _lws_ss_handle_state_ret_CAN_DESTROY_HANDLE(r, wsi, &h);
|
2020-03-28 16:20:50 +00:00
|
|
|
h->wsi = NULL;
|
2020-08-26 11:05:41 +01:00
|
|
|
r = lws_ss_backoff(h);
|
|
|
|
if (r != LWSSSSRET_OK)
|
2020-12-22 15:56:41 +00:00
|
|
|
return _lws_ss_handle_state_ret_CAN_DESTROY_HANDLE(r, wsi, &h);
|
2020-03-28 16:20:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LWS_CALLBACK_RAW_CLOSE:
|
|
|
|
if (!h)
|
|
|
|
break;
|
2020-06-30 16:42:37 +01:00
|
|
|
lws_sul_cancel(&h->sul_timeout);
|
ss: sspc: add conmon performance telemetry
This provides a way to get ahold of LWS_WITH_CONMON telemetry from Secure
Streams, it works the same with direct onward connections or via the proxy.
You can mark streamtypes with a "perf": true policy attribute... this
causes the onward connections on those streamtypes to collect information
about the connection performance, and the unsorted DNS results.
Streams with that policy attribute receive extra data in their rx callback,
with the LWSSS_FLAG_PERF_JSON flag set on it, containing JSON describing the
performance of the onward connection taken from CONMON data, in a JSON
representation. Streams without the "perf" attribute set never receive
this extra rx.
The received JSON is based on the CONMON struct info and looks like
{"peer":"46.105.127.147","dns_us":596,"sockconn_us":31382,"tls_us":28180,"txn_resp_us:23015,"dns":["2001:41d0:2:ee93::1","46.105.127.147"]}
A new minimal example minimal-secure-streams-perf is added that collects
this data on an HTTP GET from warmcat.com, and is built with a -client
version as well if LWS_WITH_SECURE_STREAMS_PROXY_API is set, that operates
via the ss proxy and produces the same result at the client.
2021-03-31 13:20:34 +01:00
|
|
|
|
2021-08-03 15:25:39 +08:00
|
|
|
#if defined(LWS_WITH_CONMON)
|
ss: sspc: add conmon performance telemetry
This provides a way to get ahold of LWS_WITH_CONMON telemetry from Secure
Streams, it works the same with direct onward connections or via the proxy.
You can mark streamtypes with a "perf": true policy attribute... this
causes the onward connections on those streamtypes to collect information
about the connection performance, and the unsorted DNS results.
Streams with that policy attribute receive extra data in their rx callback,
with the LWSSS_FLAG_PERF_JSON flag set on it, containing JSON describing the
performance of the onward connection taken from CONMON data, in a JSON
representation. Streams without the "perf" attribute set never receive
this extra rx.
The received JSON is based on the CONMON struct info and looks like
{"peer":"46.105.127.147","dns_us":596,"sockconn_us":31382,"tls_us":28180,"txn_resp_us:23015,"dns":["2001:41d0:2:ee93::1","46.105.127.147"]}
A new minimal example minimal-secure-streams-perf is added that collects
this data on an HTTP GET from warmcat.com, and is built with a -client
version as well if LWS_WITH_SECURE_STREAMS_PROXY_API is set, that operates
via the ss proxy and produces the same result at the client.
2021-03-31 13:20:34 +01:00
|
|
|
lws_conmon_ss_json(h);
|
2021-08-03 15:25:39 +08:00
|
|
|
#endif
|
ss: sspc: add conmon performance telemetry
This provides a way to get ahold of LWS_WITH_CONMON telemetry from Secure
Streams, it works the same with direct onward connections or via the proxy.
You can mark streamtypes with a "perf": true policy attribute... this
causes the onward connections on those streamtypes to collect information
about the connection performance, and the unsorted DNS results.
Streams with that policy attribute receive extra data in their rx callback,
with the LWSSS_FLAG_PERF_JSON flag set on it, containing JSON describing the
performance of the onward connection taken from CONMON data, in a JSON
representation. Streams without the "perf" attribute set never receive
this extra rx.
The received JSON is based on the CONMON struct info and looks like
{"peer":"46.105.127.147","dns_us":596,"sockconn_us":31382,"tls_us":28180,"txn_resp_us:23015,"dns":["2001:41d0:2:ee93::1","46.105.127.147"]}
A new minimal example minimal-secure-streams-perf is added that collects
this data on an HTTP GET from warmcat.com, and is built with a -client
version as well if LWS_WITH_SECURE_STREAMS_PROXY_API is set, that operates
via the ss proxy and produces the same result at the client.
2021-03-31 13:20:34 +01:00
|
|
|
|
2021-01-06 15:08:22 +00:00
|
|
|
lwsl_info("%s: %s, %s RAW_CLOSE\n", __func__, lws_ss_tag(h),
|
2020-03-28 16:20:50 +00:00
|
|
|
h->policy ? h->policy->streamtype : "no policy");
|
|
|
|
h->wsi = NULL;
|
2020-11-10 11:27:28 +00:00
|
|
|
#if defined(LWS_WITH_SERVER)
|
|
|
|
lws_pt_lock(pt, __func__);
|
|
|
|
lws_dll2_remove(&h->cli_list);
|
|
|
|
lws_pt_unlock(pt);
|
|
|
|
#endif
|
2021-01-06 15:08:22 +00:00
|
|
|
|
|
|
|
/* wsi is going down anyway */
|
|
|
|
r = lws_ss_event_helper(h, LWSSSCS_DISCONNECTED);
|
|
|
|
if (r == LWSSSSRET_DESTROY_ME)
|
|
|
|
return _lws_ss_handle_state_ret_CAN_DESTROY_HANDLE(r, wsi, &h);
|
|
|
|
|
2020-03-28 16:20:50 +00:00
|
|
|
if (h->policy && !(h->policy->flags & LWSSSPOLF_OPPORTUNISTIC) &&
|
2020-07-28 09:21:45 +01:00
|
|
|
#if defined(LWS_WITH_SERVER)
|
|
|
|
!(h->info.flags & LWSSSINFLAGS_ACCEPTED) && /* not server */
|
|
|
|
#endif
|
2020-08-26 11:05:41 +01:00
|
|
|
!h->txn_ok && !wsi->a.context->being_destroyed) {
|
|
|
|
r = lws_ss_backoff(h);
|
|
|
|
if (r != LWSSSSRET_OK)
|
2020-12-22 15:56:41 +00:00
|
|
|
return _lws_ss_handle_state_ret_CAN_DESTROY_HANDLE(r, wsi, &h);
|
2020-08-26 11:05:41 +01:00
|
|
|
break;
|
|
|
|
}
|
2021-01-06 15:08:22 +00:00
|
|
|
|
2020-03-28 16:20:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LWS_CALLBACK_RAW_CONNECTED:
|
|
|
|
lwsl_info("%s: RAW_CONNECTED\n", __func__);
|
|
|
|
|
|
|
|
h->retry = 0;
|
|
|
|
h->seqstate = SSSEQ_CONNECTED;
|
2020-05-28 12:48:17 +01:00
|
|
|
lws_sul_cancel(&h->sul);
|
2021-01-06 15:08:22 +00:00
|
|
|
#if defined(LWS_WITH_SYS_METRICS)
|
|
|
|
/*
|
|
|
|
* If any hanging caliper measurement, dump it, and free any tags
|
|
|
|
*/
|
|
|
|
lws_metrics_caliper_report_hist(h->cal_txn, (struct lws *)NULL);
|
|
|
|
#endif
|
2020-08-26 11:05:41 +01:00
|
|
|
r = lws_ss_event_helper(h, LWSSSCS_CONNECTED);
|
|
|
|
if (r != LWSSSSRET_OK)
|
2020-12-22 15:56:41 +00:00
|
|
|
return _lws_ss_handle_state_ret_CAN_DESTROY_HANDLE(r, wsi, &h);
|
2020-03-28 16:20:50 +00:00
|
|
|
|
|
|
|
lws_validity_confirmed(wsi);
|
|
|
|
break;
|
|
|
|
|
2020-07-28 09:21:45 +01:00
|
|
|
case LWS_CALLBACK_RAW_ADOPT:
|
|
|
|
lwsl_info("%s: RAW_ADOPT\n", __func__);
|
|
|
|
break;
|
|
|
|
|
2020-03-28 16:20:50 +00:00
|
|
|
/* chunks of chunked content, with header removed */
|
|
|
|
case LWS_CALLBACK_RAW_RX:
|
2020-06-01 07:17:48 +01:00
|
|
|
if (!h || !h->info.rx)
|
2020-03-28 16:20:50 +00:00
|
|
|
return 0;
|
|
|
|
|
2020-08-26 11:05:41 +01:00
|
|
|
r = h->info.rx(ss_to_userobj(h), (const uint8_t *)in, len, 0);
|
|
|
|
if (r != LWSSSSRET_OK)
|
2020-12-22 15:56:41 +00:00
|
|
|
return _lws_ss_handle_state_ret_CAN_DESTROY_HANDLE(r, wsi, &h);
|
2020-03-28 16:20:50 +00:00
|
|
|
|
|
|
|
return 0; /* don't passthru */
|
|
|
|
|
|
|
|
case LWS_CALLBACK_RAW_WRITEABLE:
|
|
|
|
lwsl_info("%s: RAW_WRITEABLE\n", __func__);
|
2020-06-01 07:17:48 +01:00
|
|
|
if (!h || !h->info.tx)
|
2020-03-28 16:20:50 +00:00
|
|
|
return 0;
|
|
|
|
|
2020-12-12 06:21:40 +00:00
|
|
|
buflen = lws_ptr_diff_size_t(end, p);
|
2020-08-26 11:05:41 +01:00
|
|
|
r = h->info.tx(ss_to_userobj(h), h->txord++, p, &buflen, &f);
|
|
|
|
if (r == LWSSSSRET_TX_DONT_SEND)
|
2020-03-28 16:20:50 +00:00
|
|
|
return 0;
|
2020-08-26 11:05:41 +01:00
|
|
|
if (r < 0)
|
2020-12-22 15:56:41 +00:00
|
|
|
return _lws_ss_handle_state_ret_CAN_DESTROY_HANDLE(r, wsi, &h);
|
2020-03-28 16:20:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* flags are ignored with raw, there are no protocol payload
|
|
|
|
* boundaries, just an arbitrarily-fragmented bytestream
|
|
|
|
*/
|
|
|
|
|
|
|
|
p += buflen;
|
2020-12-12 06:21:40 +00:00
|
|
|
if (lws_write(wsi, buf + LWS_PRE, lws_ptr_diff_size_t(p, buf + LWS_PRE),
|
|
|
|
LWS_WRITE_HTTP) != lws_ptr_diff(p, buf + LWS_PRE)) {
|
2020-03-28 16:20:50 +00:00
|
|
|
lwsl_err("%s: write failed\n", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
lws_set_timeout(wsi, 0, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-07-28 09:21:45 +01:00
|
|
|
return 0;
|
2020-03-28 16:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
secstream_connect_munge_raw(lws_ss_handle_t *h, char *buf, size_t len,
|
|
|
|
struct lws_client_connect_info *i,
|
|
|
|
union lws_ss_contemp *ct)
|
|
|
|
{
|
|
|
|
i->method = "RAW";
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const struct lws_protocols protocol_secstream_raw = {
|
|
|
|
"lws-secstream-raw",
|
|
|
|
secstream_raw,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct ss_pcols ss_pcol_raw = {
|
|
|
|
"raw",
|
|
|
|
"",
|
2020-07-27 10:03:12 +01:00
|
|
|
&protocol_secstream_raw,
|
2020-03-28 16:20:50 +00:00
|
|
|
secstream_connect_munge_raw,
|
|
|
|
NULL
|
|
|
|
};
|