Mercurial > hg > batmud > maputils
changeset 2293:e2f6c11a26c0
Implement disabling of IPv6 or IPv4 for each listener/vhost in mapsearch.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 30 Jun 2020 13:43:01 +0300 |
parents | 1084423b7246 |
children | a285e768e4ae |
files | mapsearch.c |
diffstat | 1 files changed, 48 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/mapsearch.c Thu Jun 11 13:11:05 2020 +0300 +++ b/mapsearch.c Tue Jun 30 13:43:01 2020 +0300 @@ -51,6 +51,8 @@ char *vhostname; // Vhost name int port; // Port number + int ipvMode; // Enable/disable IPv4/6 support for this listener + BOOL useSSL; // Use SSL/TLS? char *sslCertFile, // Certificate file *sslKeyFile, // Key file @@ -129,16 +131,18 @@ fprintf(stdout, "\n" "Listening interface(s) are specified with following syntax:\n" - "-l \"<interface/IP/host>:<port>[=<SSL/TLS spec>]\"\n" + "-l \"<interface/IP/host>:<port>[:no-ipv(4|6)][=<SSL/TLS spec>]\"\n" "\n" "IPv6 addresses should be specified with the square bracket notation [].\n" "To listen to all interfaces, you can specify an asterisk (*) as host:\n" "\n" "-l *:3491 -l *:3492=<vhostname for SNI>:<ssl_cert_file.crt>:<ssl_key_file.key>:<ca_file.crt>\n" "\n" - "Would listen for normal WebSocket (ws://) connections on port 3491 and for\n" + "This would listen for normal WebSocket (ws://) connections on port 3491 and for\n" "secure SSL/TLS WebSocket (wss://) connections on port 3492 of all interfaces.\n" "\n" + "To disable listening on IPv4/6 addresses, specify :no-ipv4 or :no-ipv6\n" + "\n" "Maps and location files for each map are specified as follows:\n" "<filename.map>:<locfilename.loc>:<map/continent name>[:<world x-offset>:<world y-offset>]\n" "World offsets are optional and default to 0, 0 if not specified.\n" @@ -346,7 +350,19 @@ *end++ = 0; start = end; - // Check for '=flags' at the end + // Check for ':no-ipv4' or ':no-ipv6' flag + if ((end = strstr(start, ":no-ipv")) != NULL && + (end[7] == '4' || end[7] == '6')) + { + *end = 0; + + if (end[7] == '4') + ctx->ipvMode = 6; + else + ctx->ipvMode = 4; + } + + // Check for '=<SSL/TLS spec>' at the end if ((flags = strchr(start, '=')) != NULL) *flags++ = 0; @@ -1866,14 +1882,37 @@ // Create listener LWS vhosts .. for (int n = 0; n < optNListenTo; n++) { + char *ipvMode = ""; ctx = optListenTo[n]; + info.port = ctx->port; + info.iface = ctx->interface; + info.options = 0; + + switch (ctx->ipvMode) + { + case 0: + ipvMode = " [IPv4 + IPv6]"; + break; + + case 4: + ipvMode = " [IPv4 only]"; + info.options |= LWS_SERVER_OPTION_DISABLE_IPV6; + break; + + case 6: + ipvMode = " [IPv6 only]"; + info.options |= LWS_SERVER_OPTION_IPV6_V6ONLY_MODIFY | LWS_SERVER_OPTION_IPV6_V6ONLY_VALUE; + break; + } + if (ctx->useSSL) { - mapMSG(1, "Listen to %s:%d (wss) [vhost='%s', cert='%s', key='%s', ca='%s']\n", + mapMSG(1, "Listen to %s:%d (wss) [vhost='%s', cert='%s', key='%s', ca='%s']%s\n", ctx->interface != NULL ? ctx->interface : "*", ctx->port, ctx->vhostname, - ctx->sslCertFile, ctx->sslKeyFile, ctx->sslCAFile); + ctx->sslCertFile, ctx->sslKeyFile, ctx->sslCAFile, + ipvMode); info.vhost_name = ctx->vhostname; info.ssl_cert_filepath = ctx->sslCertFile; @@ -1882,8 +1921,10 @@ } else { - mapMSG(1, "Listen to %s:%d (ws)\n", - ctx->interface != NULL ? ctx->interface : "*", ctx->port); + mapMSG(1, "Listen to %s:%d (ws)%s\n", + ctx->interface != NULL ? ctx->interface : "*", + ctx->port, + ipvMode); info.vhost_name = NULL; info.ssl_cert_filepath = NULL; @@ -1891,9 +1932,6 @@ info.ssl_ca_filepath = NULL; } - info.port = ctx->port; - info.iface = ctx->interface; - if ((ctx->vhost = lws_create_vhost(setLWSContext, &info)) == NULL) { mapERR("LWS vhost creation failed!\n");