From db0dbd3666412c3d952bdc79551c95abdf549609 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 25 Jan 2022 15:07:43 -0500 Subject: [PATCH] TT#157801 skip libwebsockets IPv6 bindings if not available Add an explicit test to see if libwebsockets has been compiled with support for IPv6. If it hasn't then we don't try to create v6 bindings. Closes #1432 Change-Id: I6902f5b4203aa09cb28a8edb46f97b339677ed75 --- daemon/websocket.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/daemon/websocket.c b/daemon/websocket.c index 58f3e442d..3f53f6111 100644 --- a/daemon/websocket.c +++ b/daemon/websocket.c @@ -920,6 +920,10 @@ int websocket_init(void) { (!rtpe_config.https_ifs || !*rtpe_config.https_ifs)) return 0; + struct sockaddr_storage sa; + int ret = lws_interface_to_sa(1, "::1", (void *) &sa, sizeof(sa)); + bool have_lws_ipv6 = (ret == 0); + const char *err = NULL; lws_set_log_level(LLL_ERR | LLL_WARN, websocket_log); @@ -945,10 +949,15 @@ int websocket_init(void) { goto err; bool success = false; + bool ipv6_fail = false; for (int i = 0; i < G_N_ELEMENTS(eps); i++) { endpoint_t *ep = &eps[i]; if (!ep->port) continue; + if (ep->address.family->af == AF_INET6 && !have_lws_ipv6) { + ipv6_fail = true; + continue; + } struct lws_context_creation_info *vhost = g_slice_alloc(sizeof(*vhost)); g_queue_push_tail(&websocket_vhost_configs, vhost); @@ -966,6 +975,9 @@ int websocket_init(void) { success = true; } err = "Failed to create any LWS vhost from given config"; + if (ipv6_fail) + err = "Failed to create any LWS vhost from given config. Hint: LWS IPv6 support is not " + "available and config lists at least one IPv6 vhost"; if (!success) goto err; } @@ -983,10 +995,15 @@ int websocket_init(void) { goto err; bool success = false; + bool ipv6_fail = false; for (int i = 0; i < G_N_ELEMENTS(eps); i++) { endpoint_t *ep = &eps[i]; if (!ep->port) continue; + if (ep->address.family->af == AF_INET6 && !have_lws_ipv6) { + ipv6_fail = true; + continue; + } struct lws_context_creation_info *vhost = g_slice_alloc(sizeof(*vhost)); g_queue_push_tail(&websocket_vhost_configs, vhost); @@ -1008,6 +1025,9 @@ int websocket_init(void) { success = true; } err = "Failed to create any LWS vhost from given config"; + if (ipv6_fail) + err = "Failed to create any LWS vhost from given config. Hint: LWS IPv6 support is not " + "available and config lists at least one IPv6 vhost"; if (!success) goto err; }