diff options
| -rw-r--r-- | docs/man/nng_ws.7.adoc | 16 | ||||
| -rw-r--r-- | src/core/stream.c | 16 | ||||
| -rw-r--r-- | src/supplemental/http/http_server.c | 8 | ||||
| -rw-r--r-- | src/transport/ws/websocket.c | 32 | ||||
| -rw-r--r-- | tests/tcp.c | 2 | ||||
| -rw-r--r-- | tests/udp.c | 6 | ||||
| -rw-r--r-- | tests/ws.c | 10 |
7 files changed, 77 insertions, 13 deletions
diff --git a/docs/man/nng_ws.7.adoc b/docs/man/nng_ws.7.adoc index 5dedbeb8..18baedfa 100644 --- a/docs/man/nng_ws.7.adoc +++ b/docs/man/nng_ws.7.adoc @@ -1,6 +1,6 @@ = nng_ws(7) // -// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This document is supplied under the terms of the MIT License, a @@ -58,6 +58,20 @@ Secure WebSockets (((WebSockets, Secure)))(((URI, `wss://`))) (if enabled) use the scheme `wss://`, and the default TCP port number of 443. Otherwise the format is the same as for regular WebSockets. +A URI may be restricted to IPv6 using the scheme `ws6://` or `wss6://`, and may +be restricted to IPv4 using the scheme `ws4://` or `wss4://`. + +NOTE: Specifying `ws6://` or `wss6://` may not prevent IPv4 hosts from being used with +IPv4-in-IPv6 addresses, particularly when using a wildcard hostname with +listeners. +The details of this varies across operating systems. + +NOTE: The `ws4://` , `ws6://`, `wss4://` and `wss6://` schemes are specific to _NNG_, +and might not be understood by other implementations. + +TIP: We recommend using either numeric IP addresses, or names that are +specific to either IPv4 or IPv6 to prevent confusion and surprises. + When specifying IPv6 addresses, the address must be enclosed in square brackets (`[]`) to avoid confusion with the final colon separating the port. diff --git a/src/core/stream.c b/src/core/stream.c index e7ebc4e0..2112f5ef 100644 --- a/src/core/stream.c +++ b/src/core/stream.c @@ -1,5 +1,5 @@ // -// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech> // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -74,7 +74,19 @@ static struct { .listener_alloc = nni_ws_listener_alloc, .checkopt = nni_ws_checkopt, }, - { + { + .scheme = "ws4", + .dialer_alloc = nni_ws_dialer_alloc, + .listener_alloc = nni_ws_listener_alloc, + .checkopt = nni_ws_checkopt, + }, + { + .scheme = "ws6", + .dialer_alloc = nni_ws_dialer_alloc, + .listener_alloc = nni_ws_listener_alloc, + .checkopt = nni_ws_checkopt, + }, + { .scheme = "wss", .dialer_alloc = nni_ws_dialer_alloc, .listener_alloc = nni_ws_listener_alloc, diff --git a/src/supplemental/http/http_server.c b/src/supplemental/http/http_server.c index e711c2a2..caa06b3d 100644 --- a/src/supplemental/http/http_server.c +++ b/src/supplemental/http/http_server.c @@ -937,6 +937,14 @@ http_server_init(nni_http_server **serverp, const nni_url *url) } else if ((strcmp(url->u_scheme, "https") == 0) || (strcmp(url->u_scheme, "wss") == 0)) { myurl.u_scheme = "tls+tcp"; + } else if (strcmp(url->u_scheme, "ws4") == 0) { + myurl.u_scheme = "tcp4"; + } else if (strcmp(url->u_scheme, "ws6") == 0) { + myurl.u_scheme = "tcp6"; + } else if (strcmp(url->u_scheme, "wss4") == 0) { + myurl.u_scheme = "tls+tcp4"; + } else if (strcmp(url->u_scheme, "wss6") == 0) { + myurl.u_scheme = "tls+tcp6"; } else { return (NNG_EADDRINVAL); } diff --git a/src/transport/ws/websocket.c b/src/transport/ws/websocket.c index e2578f32..545a519d 100644 --- a/src/transport/ws/websocket.c +++ b/src/transport/ws/websocket.c @@ -670,10 +670,40 @@ static nni_tran ws_tran = { .tran_checkopt = wstran_checkopt, }; +static nni_tran ws4_tran = { + .tran_version = NNI_TRANSPORT_VERSION, + .tran_scheme = "ws4", + .tran_dialer = &ws_dialer_ops, + .tran_listener = &ws_listener_ops, + .tran_pipe = &ws_pipe_ops, + .tran_init = wstran_init, + .tran_fini = wstran_fini, + .tran_checkopt = wstran_checkopt, +}; + +static nni_tran ws6_tran = { + .tran_version = NNI_TRANSPORT_VERSION, + .tran_scheme = "ws6", + .tran_dialer = &ws_dialer_ops, + .tran_listener = &ws_listener_ops, + .tran_pipe = &ws_pipe_ops, + .tran_init = wstran_init, + .tran_fini = wstran_fini, + .tran_checkopt = wstran_checkopt, +}; + + int nng_ws_register(void) { - return (nni_tran_register(&ws_tran)); + int rv; + if (((rv = nni_tran_register(&ws_tran)) != 0) || + ((rv = nni_tran_register(&ws4_tran)) != 0) || + ((rv = nni_tran_register(&ws6_tran)) != 0)) { + return (rv); + } + + return (0); } #ifdef NNG_TRANSPORT_WSS diff --git a/tests/tcp.c b/tests/tcp.c index 8975da33..1288af01 100644 --- a/tests/tcp.c +++ b/tests/tcp.c @@ -84,7 +84,7 @@ TestMain("TCP Transport", { nng_close(s2); nng_close(s1); }); - trantest_next_address(addr, "tcp://*:%u"); + trantest_next_address(addr, "tcp4://*:%u"); So(nng_listen(s1, addr, NULL, 0) == 0); // reset port back one trantest_prev_address(addr, "tcp://127.0.0.1:%u"); diff --git a/tests/udp.c b/tests/udp.c index d5f20c26..af7b2807 100644 --- a/tests/udp.c +++ b/tests/udp.c @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -229,7 +229,7 @@ TestMain("UDP support", { nng_aio_wait(aio1); So((rv = nng_aio_result(aio1)) != 0); So(rv == NNG_EADDRINVAL || rv == NNG_ENOTSUP || - rv == NNG_EUNREACHABLE); + rv == NNG_EUNREACHABLE || rv == NNG_EINVAL); nng_aio_free(aio1); }); @@ -255,7 +255,7 @@ TestMain("UDP support", { nng_aio_wait(aio1); So((rv = nng_aio_result(aio1)) != 0); So(rv == NNG_EADDRINVAL || rv == NNG_ENOTSUP || - rv == NNG_EUNREACHABLE); + rv == NNG_EUNREACHABLE || rv == NNG_EINVAL); nng_aio_free(aio1); }); }); @@ -1,5 +1,5 @@ // -// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -95,7 +95,7 @@ TestMain("WebSocket Transport", { nng_close(s2); nng_close(s1); }); - trantest_next_address(addr, "ws://:%u/test"); + trantest_next_address(addr, "ws4://:%u/test"); So(nng_listen(s1, addr, NULL, 0) == 0); nng_msleep(100); // reset port back one @@ -114,7 +114,7 @@ TestMain("WebSocket Transport", { nng_close(s2); nng_close(s1); }); - trantest_next_address(addr, "ws://*:%u/test"); + trantest_next_address(addr, "ws4://*:%u/test"); So(nng_listen(s1, addr, NULL, 0) == 0); nng_msleep(100); // reset port back one @@ -150,8 +150,8 @@ TestMain("WebSocket Transport", { nng_close(s1); nng_close(s2); }); - So(nng_listen(s1, "ws://*:5599/one", NULL, 0) == 0); - So(nng_listen(s1, "ws://*:5599/two", NULL, 0) == 0); + So(nng_listen(s1, "ws4://*:5599/one", NULL, 0) == 0); + So(nng_listen(s1, "ws4://*:5599/two", NULL, 0) == 0); So(nng_dial(s2, "ws://127.0.0.1:5599/one", NULL, 0) == 0); }); |
