TT#157801 explicitly handle v4/v6 also for libwebsockets

Analogous to 12f23b311

Prerequisite for #1432

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

@ -939,25 +939,35 @@ 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;
bool success = false;
for (int i = 0; i < G_N_ELEMENTS(eps); i++) {
endpoint_t *ep = &eps[i];
if (!ep->port)
continue;
struct lws_context_creation_info *vhost = g_slice_alloc(sizeof(*vhost)); struct lws_context_creation_info *vhost = g_slice_alloc(sizeof(*vhost));
g_queue_push_tail(&websocket_vhost_configs, vhost); g_queue_push_tail(&websocket_vhost_configs, vhost);
*vhost = (struct lws_context_creation_info) { *vhost = (struct lws_context_creation_info) {
.port = ep.port, .port = ep->port,
.iface = g_strdup(sockaddr_print_buf(&ep.address)), .iface = g_strdup(sockaddr_print_buf(&ep->address)),
.protocols = websocket_protocols, .protocols = websocket_protocols,
}; };
vhost->vhost_name = vhost->iface; vhost->vhost_name = vhost->iface;
if (ep.address.family->af == AF_INET) if (ep->address.family->af == AF_INET)
vhost->options |= LWS_SERVER_OPTION_DISABLE_IPV6; vhost->options |= LWS_SERVER_OPTION_DISABLE_IPV6;
err = "LWS failed to create vhost"; err = "LWS failed to create vhost";
if (!lws_create_vhost(websocket_context, vhost)) if (!lws_create_vhost(websocket_context, vhost))
goto err; goto err;
success = true;
}
err = "Failed to create any LWS vhost from given config";
if (!success)
goto err;
} }
for (char **ifp = rtpe_config.https_ifs; ifp && *ifp; ifp++) { for (char **ifp = rtpe_config.https_ifs; ifp && *ifp; ifp++) {
@ -967,17 +977,22 @@ 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;
bool success = false;
for (int i = 0; i < G_N_ELEMENTS(eps); i++) {
endpoint_t *ep = &eps[i];
if (!ep->port)
continue;
struct lws_context_creation_info *vhost = g_slice_alloc(sizeof(*vhost)); struct lws_context_creation_info *vhost = g_slice_alloc(sizeof(*vhost));
g_queue_push_tail(&websocket_vhost_configs, vhost); g_queue_push_tail(&websocket_vhost_configs, vhost);
*vhost = (struct lws_context_creation_info) { *vhost = (struct lws_context_creation_info) {
.port = ep.port, .port = ep->port,
.iface = g_strdup(sockaddr_print_buf(&ep.address)), .iface = g_strdup(sockaddr_print_buf(&ep->address)),
.protocols = websocket_protocols, .protocols = websocket_protocols,
.ssl_cert_filepath = rtpe_config.https_cert, .ssl_cert_filepath = rtpe_config.https_cert,
.ssl_private_key_filepath = rtpe_config.https_key ? : rtpe_config.https_cert, .ssl_private_key_filepath = rtpe_config.https_key ? : rtpe_config.https_cert,
@ -985,11 +1000,16 @@ int websocket_init(void) {
// XXX cipher list, key password // XXX cipher list, key password
}; };
vhost->vhost_name = vhost->iface; vhost->vhost_name = vhost->iface;
if (ep.address.family->af == AF_INET) if (ep->address.family->af == AF_INET)
vhost->options |= LWS_SERVER_OPTION_DISABLE_IPV6; vhost->options |= LWS_SERVER_OPTION_DISABLE_IPV6;
err = "LWS failed to create vhost"; err = "LWS failed to create vhost";
if (!lws_create_vhost(websocket_context, vhost)) if (!lws_create_vhost(websocket_context, vhost))
goto err; goto err;
success = true;
}
err = "Failed to create any LWS vhost from given config";
if (!success)
goto err;
} }
int num_threads = rtpe_config.http_threads ? : rtpe_config.num_threads; int num_threads = rtpe_config.http_threads ? : rtpe_config.num_threads;

Loading…
Cancel
Save