TT#157801 explicitly handle v4/v6 also for libwebsockets

Analogous to 12f23b311

Prerequisite for #1432

Change-Id: I204692cbaea6b5339ed392dcbd13689087391669
pull/1439/head
Richard Fuchs 4 years ago
parent 8d99ef0686
commit 6d0eba931a

@ -939,24 +939,34 @@ int websocket_init(void) {
for (char **ifp = rtpe_config.http_ifs; ifp && *ifp; ifp++) { for (char **ifp = rtpe_config.http_ifs; ifp && *ifp; ifp++) {
char *ifa = *ifp; char *ifa = *ifp;
ilogs(http, LOG_DEBUG, "Starting HTTP/WS '%s'", ifa); ilogs(http, LOG_DEBUG, "Starting HTTP/WS '%s'", ifa);
endpoint_t ep; endpoint_t eps[2];
err = "Failed to parse address/port"; err = "Failed to parse address/port";
if (endpoint_parse_any_getaddrinfo(&ep, ifa)) if (endpoint_parse_any_getaddrinfo_alt(&eps[0], &eps[1], ifa))
goto err; goto err;
struct lws_context_creation_info *vhost = g_slice_alloc(sizeof(*vhost)); bool success = false;
g_queue_push_tail(&websocket_vhost_configs, vhost); for (int i = 0; i < G_N_ELEMENTS(eps); i++) {
endpoint_t *ep = &eps[i];
*vhost = (struct lws_context_creation_info) { if (!ep->port)
.port = ep.port, continue;
.iface = g_strdup(sockaddr_print_buf(&ep.address)), struct lws_context_creation_info *vhost = g_slice_alloc(sizeof(*vhost));
.protocols = websocket_protocols, g_queue_push_tail(&websocket_vhost_configs, vhost);
};
vhost->vhost_name = vhost->iface; *vhost = (struct lws_context_creation_info) {
if (ep.address.family->af == AF_INET) .port = ep->port,
vhost->options |= LWS_SERVER_OPTION_DISABLE_IPV6; .iface = g_strdup(sockaddr_print_buf(&ep->address)),
err = "LWS failed to create vhost"; .protocols = websocket_protocols,
if (!lws_create_vhost(websocket_context, vhost)) };
vhost->vhost_name = vhost->iface;
if (ep->address.family->af == AF_INET)
vhost->options |= LWS_SERVER_OPTION_DISABLE_IPV6;
err = "LWS failed to create vhost";
if (!lws_create_vhost(websocket_context, vhost))
goto err;
success = true;
}
err = "Failed to create any LWS vhost from given config";
if (!success)
goto err; goto err;
} }
@ -967,28 +977,38 @@ int websocket_init(void) {
char *ifa = *ifp; char *ifa = *ifp;
ilogs(http, LOG_DEBUG, "Starting HTTPS/WSS '%s'", ifa); ilogs(http, LOG_DEBUG, "Starting HTTPS/WSS '%s'", ifa);
endpoint_t ep; endpoint_t eps[2];
err = "Failed to parse address/port"; err = "Failed to parse address/port";
if (endpoint_parse_any_getaddrinfo(&ep, ifa)) if (endpoint_parse_any_getaddrinfo_alt(&eps[0], &eps[1], ifa))
goto err; goto err;
struct lws_context_creation_info *vhost = g_slice_alloc(sizeof(*vhost)); bool success = false;
g_queue_push_tail(&websocket_vhost_configs, vhost); for (int i = 0; i < G_N_ELEMENTS(eps); i++) {
endpoint_t *ep = &eps[i];
*vhost = (struct lws_context_creation_info) { if (!ep->port)
.port = ep.port, continue;
.iface = g_strdup(sockaddr_print_buf(&ep.address)), struct lws_context_creation_info *vhost = g_slice_alloc(sizeof(*vhost));
.protocols = websocket_protocols, g_queue_push_tail(&websocket_vhost_configs, vhost);
.ssl_cert_filepath = rtpe_config.https_cert,
.ssl_private_key_filepath = rtpe_config.https_key ? : rtpe_config.https_cert, *vhost = (struct lws_context_creation_info) {
.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT, .port = ep->port,
// XXX cipher list, key password .iface = g_strdup(sockaddr_print_buf(&ep->address)),
}; .protocols = websocket_protocols,
vhost->vhost_name = vhost->iface; .ssl_cert_filepath = rtpe_config.https_cert,
if (ep.address.family->af == AF_INET) .ssl_private_key_filepath = rtpe_config.https_key ? : rtpe_config.https_cert,
vhost->options |= LWS_SERVER_OPTION_DISABLE_IPV6; .options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT,
err = "LWS failed to create vhost"; // XXX cipher list, key password
if (!lws_create_vhost(websocket_context, vhost)) };
vhost->vhost_name = vhost->iface;
if (ep->address.family->af == AF_INET)
vhost->options |= LWS_SERVER_OPTION_DISABLE_IPV6;
err = "LWS failed to create vhost";
if (!lws_create_vhost(websocket_context, vhost))
goto err;
success = true;
}
err = "Failed to create any LWS vhost from given config";
if (!success)
goto err; goto err;
} }

Loading…
Cancel
Save