aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-02-25 17:13:38 -0800
committerGarrett D'Amore <garrett@damore.org>2024-02-25 18:39:56 -0800
commit53a9740d1dcbad6be4b4c1a10a5f3fcbb97a5be9 (patch)
tree00c49f3cd56f5797ec0d3f31dab689c6573fc6e6 /src
parent8e62028a0db24364ea218007811e58ea11d0b64f (diff)
downloadnng-53a9740d1dcbad6be4b4c1a10a5f3fcbb97a5be9.tar.gz
nng-53a9740d1dcbad6be4b4c1a10a5f3fcbb97a5be9.tar.bz2
nng-53a9740d1dcbad6be4b4c1a10a5f3fcbb97a5be9.zip
fixes #1496 Provide NNG_ENABLE_IPV6 option (disabled by default)
This also checks if the build system has the definitions for AF_INET6, which might help in some embedded IPv4 only settings. The resolver test is enhanced to include a check for IPv6 enabled in the kernel. IPv6 support is enabled by default, of course.
Diffstat (limited to 'src')
-rw-r--r--src/core/stream.c12
-rw-r--r--src/platform/posix/CMakeLists.txt1
-rw-r--r--src/platform/posix/posix_resolv_gai.c49
-rw-r--r--src/platform/posix/posix_sockaddr.c48
-rw-r--r--src/platform/posix/posix_tcpdial.c28
-rw-r--r--src/platform/posix/posix_tcplisten.c15
-rw-r--r--src/platform/resolver_test.c56
-rw-r--r--src/platform/windows/win_resolv.c43
-rw-r--r--src/platform/windows/win_sockaddr.c14
-rw-r--r--src/platform/windows/win_tcpdial.c26
-rw-r--r--src/sp/protocol.c5
-rw-r--r--src/sp/transport/tcp/tcp.c82
-rw-r--r--src/sp/transport/tls/tls.c88
-rw-r--r--src/sp/transport/ws/websocket.c34
14 files changed, 329 insertions, 172 deletions
diff --git a/src/core/stream.c b/src/core/stream.c
index 99002fcd..95bc4123 100644
--- a/src/core/stream.c
+++ b/src/core/stream.c
@@ -1,5 +1,5 @@
//
-// Copyright 2023 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 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
@@ -22,8 +22,8 @@
static struct {
const char *scheme;
- int (*dialer_alloc)(nng_stream_dialer **, const nng_url *);
- int (*listener_alloc)(nng_stream_listener **, const nng_url *);
+ int (*dialer_alloc)(nng_stream_dialer **, const nng_url *);
+ int (*listener_alloc)(nng_stream_listener **, const nng_url *);
} stream_drivers[] = {
{
@@ -55,11 +55,13 @@ static struct {
.dialer_alloc = nni_tcp_dialer_alloc,
.listener_alloc = nni_tcp_listener_alloc,
},
+#ifdef NNG_ENABLE_IPV6
{
.scheme = "tcp6",
.dialer_alloc = nni_tcp_dialer_alloc,
.listener_alloc = nni_tcp_listener_alloc,
},
+#endif
{
.scheme = "tls+tcp",
.dialer_alloc = nni_tls_dialer_alloc,
@@ -70,11 +72,13 @@ static struct {
.dialer_alloc = nni_tls_dialer_alloc,
.listener_alloc = nni_tls_listener_alloc,
},
+#ifdef NNG_ENABLE_IPV6
{
.scheme = "tls+tcp6",
.dialer_alloc = nni_tls_dialer_alloc,
.listener_alloc = nni_tls_listener_alloc,
},
+#endif
{
.scheme = "ws",
.dialer_alloc = nni_ws_dialer_alloc,
@@ -85,11 +89,13 @@ static struct {
.dialer_alloc = nni_ws_dialer_alloc,
.listener_alloc = nni_ws_listener_alloc,
},
+#ifdef NNG_ENABLE_IPV6
{
.scheme = "ws6",
.dialer_alloc = nni_ws_dialer_alloc,
.listener_alloc = nni_ws_listener_alloc,
},
+#endif
{
.scheme = "wss",
.dialer_alloc = nni_ws_dialer_alloc,
diff --git a/src/platform/posix/CMakeLists.txt b/src/platform/posix/CMakeLists.txt
index b8e3782e..a00ffa50 100644
--- a/src/platform/posix/CMakeLists.txt
+++ b/src/platform/posix/CMakeLists.txt
@@ -62,6 +62,7 @@ if (NNG_PLATFORM_POSIX)
nng_check_sym(getpeerucred ucred.h NNG_HAVE_GETPEERUCRED)
nng_check_sym(atomic_flag_test_and_set stdatomic.h NNG_HAVE_STDATOMIC)
nng_check_sym(socketpair sys/socket.h NNG_HAVE_SOCKETPAIR)
+ nng_check_sym(AF_INET6 netinet/in.h NNG_HAVE_INET6)
nng_sources(
posix_impl.h
diff --git a/src/platform/posix/posix_resolv_gai.c b/src/platform/posix/posix_resolv_gai.c
index 8eaa29f2..f522499e 100644
--- a/src/platform/posix/posix_resolv_gai.c
+++ b/src/platform/posix/posix_resolv_gai.c
@@ -33,6 +33,10 @@
#define AI_NUMERICSERV 0
#endif
+#ifndef NNG_HAVE_INET6
+#undef NNG_ENABLE_IPV6
+#endif
+
static nni_mtx resolv_mtx = NNI_MTX_INITIALIZER;
static nni_cv resolv_cv = NNI_CV_INITIALIZER(&resolv_mtx);
static bool resolv_fini = false;
@@ -182,17 +186,23 @@ resolv_task(resolv_item *item)
rv = NNG_EADDRINVAL;
for (probe = results; probe != NULL; probe = probe->ai_next) {
- if ((probe->ai_addr->sa_family == AF_INET) ||
- (probe->ai_addr->sa_family == AF_INET6)) {
+ if (probe->ai_addr->sa_family == AF_INET) {
break;
}
+#ifdef NNG_ENABLE_IPV6
+ if (probe->ai_addr->sa_family == AF_INET6) {
+ break;
+ }
+#endif
}
nni_mtx_lock(&resolv_mtx);
if ((probe != NULL) && (item->aio != NULL)) {
- struct sockaddr_in *sin;
+ struct sockaddr_in *sin;
+#ifdef NNG_ENABLE_IPV6
struct sockaddr_in6 *sin6;
- nng_sockaddr *sa = item->sa;
+#endif
+ nng_sockaddr *sa = item->sa;
switch (probe->ai_addr->sa_family) {
case AF_INET:
@@ -202,6 +212,7 @@ resolv_task(resolv_item *item)
sa->s_in.sa_port = sin->sin_port;
sa->s_in.sa_addr = sin->sin_addr.s_addr;
break;
+#ifdef NNG_ENABLE_IPV6
case AF_INET6:
rv = 0;
sin6 = (void *) probe->ai_addr;
@@ -210,6 +221,7 @@ resolv_task(resolv_item *item)
sa->s_in6.sa_scope = sin6->sin6_scope_id;
memcpy(sa->s_in6.sa_addr, sin6->sin6_addr.s6_addr, 16);
break;
+#endif
}
}
nni_mtx_unlock(&resolv_mtx);
@@ -238,12 +250,20 @@ nni_resolv_ip(const char *host, const char *serv, int af, bool passive,
case NNG_AF_INET:
fam = AF_INET;
break;
+
+#ifdef NNG_ENABLE_IPV6
case NNG_AF_INET6:
fam = AF_INET6;
break;
case NNG_AF_UNSPEC:
fam = AF_UNSPEC;
break;
+#else
+ case NNG_AF_UNSPEC:
+ fam = AF_INET;
+ break;
+#endif
+
default:
nni_aio_finish_error(aio, NNG_ENOTSUP);
return;
@@ -342,13 +362,17 @@ parse_ip(const char *addr, nng_sockaddr *sa, bool want_port)
struct addrinfo hints;
struct addrinfo *results;
int rv;
- bool v6 = false;
- bool wrapped = false;
char *port;
char *host;
char *buf;
size_t buf_len;
+#ifdef NNG_ENABLE_IPV6
+ bool v6 = false;
+ bool wrapped = false;
+ char *s;
+#endif
+
if (addr == NULL) {
addr = "";
}
@@ -359,12 +383,12 @@ parse_ip(const char *addr, nng_sockaddr *sa, bool want_port)
}
memcpy(buf, addr, buf_len);
host = buf;
+#ifdef NNG_ENABLE_IPV6
if (*host == '[') {
v6 = true;
wrapped = true;
host++;
} else {
- char *s;
for (s = host; *s != '\0'; s++) {
if (*s == '.') {
break;
@@ -394,6 +418,13 @@ parse_ip(const char *addr, nng_sockaddr *sa, bool want_port)
rv = NNG_EADDRINVAL;
goto done;
}
+#else // NNG_ENABLE_IPV6
+ for (port = host; *port != '\0'; port++) {
+ if (*port == ':') {
+ break;
+ }
+ }
+#endif // NNG_ENABLE_IPV6
if ((!want_port) && (*port != '\0')) {
rv = NNG_EADDRINVAL;
@@ -408,9 +439,13 @@ parse_ip(const char *addr, nng_sockaddr *sa, bool want_port)
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_NUMERICSERV | AI_NUMERICHOST | AI_PASSIVE;
+#ifdef NNG_ENABLE_IPV6
if (v6) {
hints.ai_family = AF_INET6;
}
+#else
+ hints.ai_family = AF_INET;
+#endif
#ifdef AI_ADDRCONFIG
hints.ai_flags |= AI_ADDRCONFIG;
#endif
diff --git a/src/platform/posix/posix_sockaddr.c b/src/platform/posix/posix_sockaddr.c
index a569132c..63707310 100644
--- a/src/platform/posix/posix_sockaddr.c
+++ b/src/platform/posix/posix_sockaddr.c
@@ -1,5 +1,5 @@
//
-// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 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
@@ -22,17 +22,23 @@
#include <sys/types.h>
#include <sys/un.h>
+#ifndef NNG_HAVE_INET6
+#undef NNG_ENABLE_IPV6
+#endif
+
size_t
nni_posix_nn2sockaddr(void *sa, const nni_sockaddr *na)
{
- struct sockaddr_in * sin;
- struct sockaddr_in6 * sin6;
- struct sockaddr_un * spath;
- const nng_sockaddr_in * nsin;
- const nng_sockaddr_in6 * nsin6;
- const nng_sockaddr_path * nspath;
+ struct sockaddr_in *sin;
+ struct sockaddr_un *spath;
+ const nng_sockaddr_in *nsin;
+ const nng_sockaddr_path *nspath;
const nng_sockaddr_abstract *nsabs;
size_t sz;
+#ifdef NNG_ENABLE_IPV6
+ struct sockaddr_in6 *sin6;
+ const nng_sockaddr_in6 *nsin6;
+#endif
if ((sa == NULL) || (na == NULL)) {
return (0);
@@ -47,6 +53,7 @@ nni_posix_nn2sockaddr(void *sa, const nni_sockaddr *na)
sin->sin_addr.s_addr = nsin->sa_addr;
return (sizeof(*sin));
+#ifdef NNG_ENABLE_IPV6
case NNG_AF_INET6:
sin6 = (void *) sa;
nsin6 = &na->s_in6;
@@ -59,6 +66,7 @@ nni_posix_nn2sockaddr(void *sa, const nni_sockaddr *na)
sin6->sin6_scope_id = nsin6->sa_scope;
memcpy(sin6->sin6_addr.s6_addr, nsin6->sa_addr, 16);
return (sizeof(*sin6));
+#endif
case NNG_AF_IPC:
spath = (void *) sa;
@@ -75,18 +83,18 @@ nni_posix_nn2sockaddr(void *sa, const nni_sockaddr *na)
case NNG_AF_ABSTRACT:
spath = (void *) sa;
nsabs = &na->s_abstract;
- if (nsabs->sa_len >= sizeof (spath->sun_path)) {
+ if (nsabs->sa_len >= sizeof(spath->sun_path)) {
return (0);
}
memset(spath, 0, sizeof(*spath));
- spath->sun_family = PF_UNIX;
+ spath->sun_family = PF_UNIX;
spath->sun_path[0] = '\0'; // abstract starts with nul
// We support auto-bind with an empty string. There is
// a subtle caveat here, which is that we cannot bind to
// the *empty* name.
if (nsabs->sa_len == 0) {
- return (sizeof (sa_family_t)); // auto bind
+ return (sizeof(sa_family_t)); // auto bind
} else {
memcpy(&spath->sun_path[1], nsabs->sa_name,
nsabs->sa_len);
@@ -99,13 +107,15 @@ nni_posix_nn2sockaddr(void *sa, const nni_sockaddr *na)
int
nni_posix_sockaddr2nn(nni_sockaddr *na, const void *sa, size_t sz)
{
- const struct sockaddr_in * sin;
+ const struct sockaddr_in *sin;
+ const struct sockaddr_un *spath;
+ nng_sockaddr_in *nsin;
+ nng_sockaddr_path *nspath;
+ nng_sockaddr_abstract *nsabs;
+#ifdef NNG_ENABLE_IPV6
const struct sockaddr_in6 *sin6;
- const struct sockaddr_un * spath;
- nng_sockaddr_in * nsin;
- nng_sockaddr_in6 * nsin6;
- nng_sockaddr_path * nspath;
- nng_sockaddr_abstract * nsabs;
+ nng_sockaddr_in6 *nsin6;
+#endif
if ((na == NULL) || (sa == NULL)) {
return (-1);
@@ -121,6 +131,8 @@ nni_posix_sockaddr2nn(nni_sockaddr *na, const void *sa, size_t sz)
nsin->sa_port = sin->sin_port;
nsin->sa_addr = sin->sin_addr.s_addr;
break;
+
+#ifdef NNG_ENABLE_IPV6
case AF_INET6:
if (sz < sizeof(*sin6)) {
return (-1);
@@ -132,6 +144,8 @@ nni_posix_sockaddr2nn(nni_sockaddr *na, const void *sa, size_t sz)
nsin6->sa_scope = sin6->sin6_scope_id;
memcpy(nsin6->sa_addr, sin6->sin6_addr.s6_addr, 16);
break;
+#endif
+
case AF_UNIX:
// AF_UNIX can be NNG_AF_IPC, or NNG_AF_ABSTRACT.
spath = (void *) sa;
@@ -153,7 +167,7 @@ nni_posix_sockaddr2nn(nni_sockaddr *na, const void *sa, size_t sz)
nsabs->sa_len = sz - 1;
memcpy(nsabs->sa_name, &spath->sun_path[1], sz - 1);
} else {
- nspath = &na->s_ipc;
+ nspath = &na->s_ipc;
nspath->sa_family = NNG_AF_IPC;
nni_strlcpy(nspath->sa_path, spath->sun_path,
sizeof(nspath->sa_path));
diff --git a/src/platform/posix/posix_tcpdial.c b/src/platform/posix/posix_tcpdial.c
index 0af72cfa..cf3d9368 100644
--- a/src/platform/posix/posix_tcpdial.c
+++ b/src/platform/posix/posix_tcpdial.c
@@ -1,5 +1,5 @@
//
-// Copyright 2023 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2018 Devolutions <info@devolutions.net>
//
@@ -23,6 +23,10 @@
#include "posix_tcp.h"
+#ifndef NNG_HAVE_INET6
+#undef NNG_ENABLE_IPV6
+#endif
+
// Dialer stuff.
int
nni_tcp_dialer_init(nni_tcp_dialer **dp)
@@ -93,7 +97,7 @@ static void
tcp_dialer_cancel(nni_aio *aio, void *arg, int rv)
{
nni_tcp_dialer *d = arg;
- nni_tcp_conn * c;
+ nni_tcp_conn *c;
nni_mtx_lock(&d->mtx);
if ((!nni_aio_list_active(aio)) ||
@@ -113,9 +117,9 @@ tcp_dialer_cancel(nni_aio *aio, void *arg, int rv)
static void
tcp_dialer_cb(nni_posix_pfd *pfd, unsigned ev, void *arg)
{
- nni_tcp_conn * c = arg;
+ nni_tcp_conn *c = arg;
nni_tcp_dialer *d = c->dialer;
- nni_aio * aio;
+ nni_aio *aio;
int rv;
int ka;
int nd;
@@ -171,8 +175,8 @@ tcp_dialer_cb(nni_posix_pfd *pfd, unsigned ev, void *arg)
void
nni_tcp_dial(nni_tcp_dialer *d, const nni_sockaddr *sa, nni_aio *aio)
{
- nni_tcp_conn * c;
- nni_posix_pfd * pfd = NULL;
+ nni_tcp_conn *c;
+ nni_posix_pfd *pfd = NULL;
struct sockaddr_storage ss;
size_t sslen;
int fd;
@@ -333,13 +337,15 @@ tcp_dialer_get_locaddr(void *arg, void *buf, size_t *szp, nni_type t)
static int
tcp_dialer_set_locaddr(void *arg, const void *buf, size_t sz, nni_type t)
{
- nni_tcp_dialer * d = arg;
+ nni_tcp_dialer *d = arg;
nng_sockaddr sa;
struct sockaddr_storage ss;
- struct sockaddr_in * sin;
- struct sockaddr_in6 * sin6;
+ struct sockaddr_in *sin;
size_t len;
int rv;
+#ifdef NNG_ENABLE_IPV6
+ struct sockaddr_in6 *sin6;
+#endif
if ((rv = nni_copyin_sockaddr(&sa, buf, sz, t)) != 0) {
return (rv);
@@ -356,12 +362,16 @@ tcp_dialer_set_locaddr(void *arg, const void *buf, size_t sz, nni_type t)
return (NNG_EADDRINVAL);
}
break;
+
+#ifdef NNG_ENABLE_IPV6
case AF_INET6:
sin6 = (void *) &ss;
if (sin6->sin6_port != 0) {
return (NNG_EADDRINVAL);
}
break;
+#endif // __NG_INET6
+
default:
return (NNG_EADDRINVAL);
}
diff --git a/src/platform/posix/posix_tcplisten.c b/src/platform/posix/posix_tcplisten.c
index e1c0b90c..95be4beb 100644
--- a/src/platform/posix/posix_tcplisten.c
+++ b/src/platform/posix/posix_tcplisten.c
@@ -27,6 +27,10 @@
#define SOCK_CLOEXEC 0
#endif
+#ifndef NNG_HAVE_INET6
+#undef NNG_ENABLE_IPV6
+#endif
+
#include "posix_tcp.h"
struct nni_tcp_listener {
@@ -94,7 +98,7 @@ tcp_listener_doaccept(nni_tcp_listener *l)
int nd;
int ka;
nni_posix_pfd *pfd;
- nni_tcp_conn * c;
+ nni_tcp_conn *c;
fd = nni_posix_pfd_fd(l->pfd);
@@ -203,10 +207,15 @@ nni_tcp_listener_listen(nni_tcp_listener *l, const nni_sockaddr *sa)
struct sockaddr_storage ss;
int rv;
int fd;
- nni_posix_pfd * pfd;
+ nni_posix_pfd *pfd;
if (((len = nni_posix_nn2sockaddr(&ss, sa)) == 0) ||
- ((ss.ss_family != AF_INET) && (ss.ss_family != AF_INET6))) {
+#ifdef NNG_ENABLE_IPV6
+ ((ss.ss_family != AF_INET) && (ss.ss_family != AF_INET6))
+#else
+ (ss.ss_family != AF_INET)
+#endif
+ ) {
return (NNG_EADDRINVAL);
}
diff --git a/src/platform/resolver_test.c b/src/platform/resolver_test.c
index d4dd4465..ed88d09d 100644
--- a/src/platform/resolver_test.c
+++ b/src/platform/resolver_test.c
@@ -1,5 +1,5 @@
//
-// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 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
@@ -12,12 +12,33 @@
#include <nuts.h>
+#ifdef NNG_ENABLE_IPV6
uint8_t v6loop[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
+static bool
+has_v6(void)
+{
+ nng_sockaddr sa;
+ nni_plat_udp *u;
+ int rv;
+
+ nni_init(); // ensure that platform poller is up
+ sa.s_in6.sa_family = NNG_AF_INET6;
+ sa.s_in6.sa_port = 0;
+ memcpy(sa.s_in6.sa_addr, v6loop, 16);
+
+ rv = nni_plat_udp_open(&u, &sa);
+ if (rv == 0) {
+ nni_plat_udp_close(u);
+ }
+ return (rv == 0);
+}
+#endif
+
void
test_google_dns(void)
{
- nng_aio * aio;
+ nng_aio *aio;
nng_sockaddr sa;
NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL));
@@ -34,7 +55,7 @@ test_google_dns(void)
void
test_numeric_addr(void)
{
- nng_aio * aio;
+ nng_aio *aio;
nng_sockaddr sa;
NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL));
@@ -47,19 +68,17 @@ test_numeric_addr(void)
nng_aio_free(aio);
}
+#ifdef NNG_ENABLE_IPV6
void
test_numeric_v6(void)
{
- nng_aio * aio;
+ nng_aio *aio;
nng_sockaddr sa;
- // Travis CI has moved some of their services to host that
- // apparently don't support IPv6 at all. This is very sad.
- // CircleCI 2.0 is in the same boat. (Amazon to blame.)
- if ((getenv("TRAVIS") != NULL) || (getenv("CIRCLECI") != NULL)) {
- return; // skip this one.
+ if (!has_v6()) {
+ return;
}
-
+ NUTS_MSG("IPV6 support present");
NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL));
nni_resolv_ip("::1", "80", NNG_AF_INET6, true, &sa, aio);
nng_aio_wait(aio);
@@ -69,11 +88,12 @@ test_numeric_v6(void)
NUTS_TRUE(memcmp(sa.s_in6.sa_addr, v6loop, 16) == 0);
nng_aio_free(aio);
}
+#endif
void
test_service_names(void)
{
- nng_aio * aio;
+ nng_aio *aio;
nng_sockaddr sa;
NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL));
@@ -88,7 +108,7 @@ test_service_names(void)
void
test_localhost_v4(void)
{
- nng_aio * aio;
+ nng_aio *aio;
nng_sockaddr sa;
NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL));
@@ -104,7 +124,7 @@ test_localhost_v4(void)
void
test_localhost_unspecified(void)
{
- nng_aio * aio;
+ nng_aio *aio;
nng_sockaddr sa;
NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL));
@@ -118,10 +138,12 @@ test_localhost_unspecified(void)
NUTS_TRUE(sa.s_in.sa_port == nuts_be16(80));
NUTS_TRUE(sa.s_in.sa_addr == nuts_be32(0x7f000001));
break;
+#ifdef NNG_ENABLE_IPV6
case NNG_AF_INET6:
NUTS_TRUE(sa.s_in6.sa_port == nuts_be16(80));
NUTS_TRUE(memcmp(sa.s_in6.sa_addr, v6loop, 16) == 0);
break;
+#endif
}
nng_aio_free(aio);
}
@@ -129,7 +151,7 @@ test_localhost_unspecified(void)
void
test_null_passive(void)
{
- nng_aio * aio;
+ nng_aio *aio;
nng_sockaddr sa;
NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL));
@@ -145,7 +167,7 @@ test_null_passive(void)
void
test_null_not_passive(void)
{
- nng_aio * aio;
+ nng_aio *aio;
nng_sockaddr sa;
NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL));
@@ -166,7 +188,7 @@ test_null_not_passive(void)
void
test_bad_port_number(void)
{
- nng_aio * aio;
+ nng_aio *aio;
nng_sockaddr sa;
NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL));
@@ -179,7 +201,9 @@ test_bad_port_number(void)
NUTS_TESTS = {
{ "resolve google dns", test_google_dns },
{ "resolve numeric addr", test_numeric_addr },
+#ifdef NNG_ENABLE_IPV6
{ "resolve numeric v6", test_numeric_v6 },
+#endif
{ "resolve service names", test_service_names },
{ "resolve localhost v4", test_localhost_v4 },
{ "resolve localhost unspecified", test_localhost_unspecified },
diff --git a/src/platform/windows/win_resolv.c b/src/platform/windows/win_resolv.c
index 92c7461f..4f353e08 100644
--- a/src/platform/windows/win_resolv.c
+++ b/src/platform/windows/win_resolv.c
@@ -148,17 +148,23 @@ resolv_task(resolv_item *item)
rv = NNG_EADDRINVAL;
for (probe = results; probe != NULL; probe = probe->ai_next) {
- if ((probe->ai_addr->sa_family == AF_INET) ||
- (probe->ai_addr->sa_family == AF_INET6)) {
+ if (probe->ai_addr->sa_family == AF_INET) {
break;
}
+#if NNG_ENABLE_IPV6
+ if (probe->ai_addr->sa_family == AF_INET6) {
+ break;
+ }
+#endif
}
nni_mtx_lock(&resolv_mtx);
if ((probe != NULL) && (item->aio != NULL)) {
- struct sockaddr_in *sin;
+ struct sockaddr_in *sin;
+#ifdef NNG_ENABLE_IPV6
struct sockaddr_in6 *sin6;
- nni_sockaddr *sa;
+#endif
+ nni_sockaddr *sa;
sa = item->sa;
@@ -170,6 +176,7 @@ resolv_task(resolv_item *item)
sa->s_in.sa_port = sin->sin_port;
sa->s_in.sa_addr = sin->sin_addr.s_addr;
break;
+#ifdef NNG_ENABLE_IPV6
case AF_INET6:
rv = 0;
sin6 = (void *) probe->ai_addr;
@@ -178,6 +185,7 @@ resolv_task(resolv_item *item)
sa->s_in6.sa_scope = sin6->sin6_scope_id;
memcpy(sa->s_in6.sa_addr, sin6->sin6_addr.s6_addr, 16);
break;
+#endif
}
}
nni_mtx_unlock(&resolv_mtx);
@@ -205,12 +213,18 @@ nni_resolv_ip(const char *host, const char *serv, int family, bool passive,
case NNG_AF_INET:
fam = AF_INET;
break;
+#ifdef NNG_ENABLE_IPV6
case NNG_AF_INET6:
fam = AF_INET6;
break;
case NNG_AF_UNSPEC:
fam = AF_UNSPEC;
break;
+#else
+ case NNG_AF_UNSPEC:
+ fam = AF_INET;
+ break;
+#endif
default:
nni_aio_finish_error(aio, NNG_ENOTSUP);
return;
@@ -306,12 +320,15 @@ parse_ip(const char *addr, nng_sockaddr *sa, bool want_port)
struct addrinfo hints;
struct addrinfo *results;
int rv;
- bool v6 = false;
- bool wrapped = false;
char *port;
char *host;
char *buf;
size_t buf_len;
+#ifdef NNG_ENABLE_IPV6
+ bool v6 = false;
+ bool wrapped = false;
+ char *s;
+#endif
if (addr == NULL) {
addr = "";
@@ -323,12 +340,13 @@ parse_ip(const char *addr, nng_sockaddr *sa, bool want_port)
}
memcpy(buf, addr, buf_len);
host = buf;
+
+#ifdef NNG_ENABLE_IPV6
if (*host == '[') {
v6 = true;
wrapped = true;
host++;
} else {
- char *s;
for (s = host; *s != '\0'; s++) {
if (*s == '.') {
break;
@@ -358,6 +376,13 @@ parse_ip(const char *addr, nng_sockaddr *sa, bool want_port)
rv = NNG_EADDRINVAL;
goto done;
}
+#else // NNG_ENABLE_IPV6
+ for (port = host; *port != '\0'; port++) {
+ if (*port == ':') {
+ break;
+ }
+ }
+#endif
if ((!want_port) && (*port != '\0')) {
rv = NNG_EADDRINVAL;
@@ -373,9 +398,13 @@ parse_ip(const char *addr, nng_sockaddr *sa, bool want_port)
memset(&hints, 0, sizeof(hints));
hints.ai_flags =
AI_ADDRCONFIG | AI_NUMERICSERV | AI_NUMERICHOST | AI_PASSIVE;
+#ifdef NNG_ENABLE_IPV6
if (v6) {
hints.ai_family = AF_INET6;
}
+#else
+ hints.ai_family = AF_INET;
+#endif
rv = getaddrinfo(host, port, &hints, &results);
if ((rv != 0) || (results == NULL)) {
diff --git a/src/platform/windows/win_sockaddr.c b/src/platform/windows/win_sockaddr.c
index 818f670b..585096e9 100644
--- a/src/platform/windows/win_sockaddr.c
+++ b/src/platform/windows/win_sockaddr.c
@@ -1,5 +1,5 @@
//
-// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 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
@@ -15,8 +15,10 @@
int
nni_win_nn2sockaddr(SOCKADDR_STORAGE *ss, const nni_sockaddr *sa)
{
- SOCKADDR_IN * sin;
+ SOCKADDR_IN *sin;
+#ifdef NNG_ENABLE_IPV6
SOCKADDR_IN6 *sin6;
+#endif
if ((ss == NULL) || (sa == NULL)) {
return (-1);
@@ -30,6 +32,7 @@ nni_win_nn2sockaddr(SOCKADDR_STORAGE *ss, const nni_sockaddr *sa)
sin->sin_addr.s_addr = sa->s_in.sa_addr;
return (sizeof(*sin));
+#ifdef NNG_ENABLE_IPV6
case NNG_AF_INET6:
sin6 = (void *) ss;
memset(sin6, 0, sizeof(*sin6));
@@ -38,6 +41,7 @@ nni_win_nn2sockaddr(SOCKADDR_STORAGE *ss, const nni_sockaddr *sa)
sin6->sin6_scope_id = sa->s_in6.sa_scope;
memcpy(sin6->sin6_addr.s6_addr, sa->s_in6.sa_addr, 16);
return (sizeof(*sin6));
+#endif
}
return (-1);
}
@@ -45,8 +49,10 @@ nni_win_nn2sockaddr(SOCKADDR_STORAGE *ss, const nni_sockaddr *sa)
int
nni_win_sockaddr2nn(nni_sockaddr *sa, const SOCKADDR_STORAGE *ss)
{
- SOCKADDR_IN * sin;
+ SOCKADDR_IN *sin;
+#ifdef NNG_ENABLE_IPV6
SOCKADDR_IN6 *sin6;
+#endif
if ((ss == NULL) || (sa == NULL)) {
return (-1);
@@ -59,6 +65,7 @@ nni_win_sockaddr2nn(nni_sockaddr *sa, const SOCKADDR_STORAGE *ss)
sa->s_in.sa_addr = sin->sin_addr.s_addr;
return (0);
+#ifdef NNG_ENABLE_IPV6
case PF_INET6:
sin6 = (void *) ss;
sa->s_in6.sa_family = NNG_AF_INET6;
@@ -66,6 +73,7 @@ nni_win_sockaddr2nn(nni_sockaddr *sa, const SOCKADDR_STORAGE *ss)
sa->s_in6.sa_scope = sin6->sin6_scope_id;
memcpy(sa->s_in6.sa_addr, sin6->sin6_addr.s6_addr, 16);
return (0);
+#endif
}
return (-1);
}
diff --git a/src/platform/windows/win_tcpdial.c b/src/platform/windows/win_tcpdial.c
index 9463c241..b4a6d745 100644
--- a/src/platform/windows/win_tcpdial.c
+++ b/src/platform/windows/win_tcpdial.c
@@ -1,5 +1,5 @@
//
-// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2018 Devolutions <info@devolutions.net>
//
@@ -113,7 +113,7 @@ static void
tcp_dial_cancel(nni_aio *aio, void *arg, int rv)
{
nni_tcp_dialer *d = arg;
- nni_tcp_conn * c;
+ nni_tcp_conn *c;
nni_mtx_lock(&d->mtx);
if ((c = nni_aio_get_prov_data(aio)) != NULL) {
@@ -128,9 +128,9 @@ tcp_dial_cancel(nni_aio *aio, void *arg, int rv)
static void
tcp_dial_cb(nni_win_io *io, int rv, size_t cnt)
{
- nni_tcp_conn * c = io->ptr;
+ nni_tcp_conn *c = io->ptr;
nni_tcp_dialer *d = c->dialer;
- nni_aio * aio = c->conn_aio;
+ nni_aio *aio = c->conn_aio;
BOOL ka;
BOOL nd;
@@ -183,7 +183,7 @@ nni_tcp_dial(nni_tcp_dialer *d, const nni_sockaddr *sa, nni_aio *aio)
SOCKET s;
SOCKADDR_STORAGE ss;
int len;
- nni_tcp_conn * c;
+ nni_tcp_conn *c;
int rv;
if (nni_aio_begin(aio) != 0) {
@@ -335,13 +335,15 @@ tcp_dialer_get_locaddr(void *arg, void *buf, size_t *szp, nni_type t)
static int
tcp_dialer_set_locaddr(void *arg, const void *buf, size_t sz, nni_type t)
{
- nni_tcp_dialer * d = arg;
- nng_sockaddr sa;
- SOCKADDR_STORAGE ss;
- struct sockaddr_in * sin;
+ nni_tcp_dialer *d = arg;
+ nng_sockaddr sa;
+ SOCKADDR_STORAGE ss;
+ struct sockaddr_in *sin;
+ size_t sslen;
+ int rv;
+#ifdef NNG_ENABLE_IPV6
struct sockaddr_in6 *sin6;
- size_t sslen;
- int rv;
+#endif
if ((rv = nni_copyin_sockaddr(&sa, buf, sz, t)) != 0) {
return (rv);
@@ -358,12 +360,14 @@ tcp_dialer_set_locaddr(void *arg, const void *buf, size_t sz, nni_type t)
return (NNG_EADDRINVAL);
}
break;
+#ifdef NNG_ENABLE_IPV6
case AF_INET6:
sin6 = (void *) &ss;
if (sin6->sin6_port != 0) {
return (NNG_EADDRINVAL);
}
break;
+#endif
default:
return (NNG_EADDRINVAL);
}
diff --git a/src/sp/protocol.c b/src/sp/protocol.c
index 512b27cc..d64c85a3 100644
--- a/src/sp/protocol.c
+++ b/src/sp/protocol.c
@@ -12,7 +12,6 @@
#include "core/nng_impl.h"
-
int
nni_proto_open(nng_socket *sip, const nni_proto *proto)
{
@@ -21,8 +20,8 @@ nni_proto_open(nng_socket *sip, const nni_proto *proto)
if ((rv = nni_sock_open(&sock, proto)) == 0) {
nng_socket s;
- s.id = nni_sock_id(sock); // Keep socket held open.
- *sip = s;
+ s.id = nni_sock_id(sock); // Keep socket held open.
+ *sip = s;
}
return (rv);
}
diff --git a/src/sp/transport/tcp/tcp.c b/src/sp/transport/tcp/tcp.c
index 1b2a380c..a9075938 100644
--- a/src/sp/transport/tcp/tcp.c
+++ b/src/sp/transport/tcp/tcp.c
@@ -1,5 +1,5 @@
//
-// Copyright 2023 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2019 Devolutions <info@devolutions.net>
//
@@ -22,14 +22,14 @@ typedef struct tcptran_ep tcptran_ep;
// tcp_pipe is one end of a TCP connection.
struct tcptran_pipe {
- nng_stream * conn;
- nni_pipe * npipe;
+ nng_stream *conn;
+ nni_pipe *npipe;
uint16_t peer;
uint16_t proto;
size_t rcvmax;
bool closed;
nni_list_node node;
- tcptran_ep * ep;
+ tcptran_ep *ep;
nni_atomic_flag reaped;
nni_reap_node reap;
uint8_t txlen[sizeof(uint64_t)];
@@ -40,10 +40,10 @@ struct tcptran_pipe {
size_t wantrxhead;
nni_list recvq;
nni_list sendq;
- nni_aio * txaio;
- nni_aio * rxaio;
- nni_aio * negoaio;
- nni_msg * rxmsg;
+ nni_aio *txaio;
+ nni_aio *rxaio;
+ nni_aio *negoaio;
+ nni_msg *rxmsg;
nni_mtx mtx;
};
@@ -54,18 +54,18 @@ struct tcptran_ep {
bool fini;
bool started;
bool closed;
- nng_url * url;
- const char * host; // for dialers
+ nng_url *url;
+ const char *host; // for dialers
nng_sockaddr src;
int refcnt; // active pipes
- nni_aio * useraio;
- nni_aio * connaio;
- nni_aio * timeaio;
+ nni_aio *useraio;
+ nni_aio *connaio;
+ nni_aio *timeaio;
nni_list busypipes; // busy pipes -- ones passed to socket
nni_list waitpipes; // pipes waiting to match to socket
nni_list negopipes; // pipes busy negotiating
nni_reap_node reap;
- nng_stream_dialer * dialer;
+ nng_stream_dialer *dialer;
nng_stream_listener *listener;
#ifdef NNG_ENABLE_STATS
@@ -140,7 +140,7 @@ static void
tcptran_pipe_fini(void *arg)
{
tcptran_pipe *p = arg;
- tcptran_ep * ep;
+ tcptran_ep *ep;
tcptran_pipe_stop(p);
if ((ep = p->ep) != NULL) {
@@ -202,7 +202,7 @@ tcptran_pipe_alloc(tcptran_pipe **pipep)
static void
tcptran_ep_match(tcptran_ep *ep)
{
- nni_aio * aio;
+ nni_aio *aio;
tcptran_pipe *p;
if (((aio = ep->useraio) == NULL) ||
@@ -221,9 +221,9 @@ static void
tcptran_pipe_nego_cb(void *arg)
{
tcptran_pipe *p = arg;
- tcptran_ep * ep = p->ep;
- nni_aio * aio = p->negoaio;
- nni_aio * uaio;
+ tcptran_ep *ep = p->ep;
+ nni_aio *aio = p->negoaio;
+ nni_aio *uaio;
int rv;
nni_mtx_lock(&ep->mtx);
@@ -302,10 +302,10 @@ tcptran_pipe_send_cb(void *arg)
{
tcptran_pipe *p = arg;
int rv;
- nni_aio * aio;
+ nni_aio *aio;
size_t n;
- nni_msg * msg;
- nni_aio * txaio = p->txaio;
+ nni_msg *msg;
+ nni_aio *txaio = p->txaio;
nni_mtx_lock(&p->mtx);
aio = nni_list_first(&p->sendq);
@@ -348,11 +348,11 @@ static void
tcptran_pipe_recv_cb(void *arg)
{
tcptran_pipe *p = arg;
- nni_aio * aio;
+ nni_aio *aio;
int rv;
size_t n;
- nni_msg * msg;
- nni_aio * rxaio = p->rxaio;
+ nni_msg *msg;
+ nni_aio *rxaio = p->rxaio;
nni_mtx_lock(&p->mtx);
aio = nni_list_first(&p->recvq);
@@ -678,7 +678,7 @@ tcptran_ep_fini(void *arg)
static void
tcptran_ep_close(void *arg)
{
- tcptran_ep * ep = arg;
+ tcptran_ep *ep = arg;
tcptran_pipe *p;
nni_mtx_lock(&ep->mtx);
@@ -715,8 +715,8 @@ static int
tcptran_url_parse_source(nng_url *url, nng_sockaddr *sa, const nng_url *surl)
{
int af;
- char * semi;
- char * src;
+ char *semi;
+ char *src;
size_t len;
int rv;
nni_aio *aio;
@@ -740,8 +740,10 @@ tcptran_url_parse_source(nng_url *url, nng_sockaddr *sa, const nng_url *surl)
af = NNG_AF_UNSPEC;
} else if (strcmp(surl->u_scheme, "tcp4") == 0) {
af = NNG_AF_INET;
+#ifdef NNG_ENABLE_IPV6
} else if (strcmp(surl->u_scheme, "tcp6") == 0) {
af = NNG_AF_INET6;
+#endif
} else {
return (NNG_EADDRINVAL);
}
@@ -777,11 +779,11 @@ tcptran_timer_cb(void *arg)
static void
tcptran_accept_cb(void *arg)
{
- tcptran_ep * ep = arg;
- nni_aio * aio = ep->connaio;
+ tcptran_ep *ep = arg;
+ nni_aio *aio = ep->connaio;
tcptran_pipe *p;
int rv;
- nng_stream * conn;
+ nng_stream *conn;
nni_mtx_lock(&ep->mtx);
@@ -832,11 +834,11 @@ error:
static void
tcptran_dial_cb(void *arg)
{
- tcptran_ep * ep = arg;
- nni_aio * aio = ep->connaio;
+ tcptran_ep *ep = arg;
+ nni_aio *aio = ep->connaio;
tcptran_pipe *p;
int rv;
- nng_stream * conn;
+ nng_stream *conn;
if ((rv = nni_aio_result(aio)) != 0) {
goto error;
@@ -905,10 +907,10 @@ tcptran_ep_init(tcptran_ep **epp, nng_url *url, nni_sock *sock)
static int
tcptran_dialer_init(void **dp, nng_url *url, nni_dialer *ndialer)
{
- tcptran_ep * ep;
+ tcptran_ep *ep;
int rv;
nng_sockaddr srcsa;
- nni_sock * sock = nni_dialer_sock(ndialer);
+ nni_sock *sock = nni_dialer_sock(ndialer);
nng_url myurl;
// Check for invalid URL components.
@@ -954,7 +956,7 @@ tcptran_listener_init(void **lp, nng_url *url, nni_listener *nlistener)
{
tcptran_ep *ep;
int rv;
- nni_sock * sock = nni_listener_sock(nlistener);
+ nni_sock *sock = nni_listener_sock(nlistener);
// Check for invalid URL components.
if ((strlen(url->u_path) != 0) && (strcmp(url->u_path, "/") != 0)) {
@@ -1030,7 +1032,7 @@ static int
tcptran_ep_get_url(void *arg, void *v, size_t *szp, nni_opt_type t)
{
tcptran_ep *ep = arg;
- char * s;
+ char *s;
int rv;
int port = 0;
@@ -1243,6 +1245,7 @@ static nni_sp_tran tcp4_tran = {
.tran_fini = tcptran_fini,
};
+#ifdef NNG_ENABLE_IPV6
static nni_sp_tran tcp6_tran = {
.tran_scheme = "tcp6",
.tran_dialer = &tcptran_dialer_ops,
@@ -1251,6 +1254,7 @@ static nni_sp_tran tcp6_tran = {
.tran_init = tcptran_init,
.tran_fini = tcptran_fini,
};
+#endif
#ifndef NNG_ELIDE_DEPRECATED
int
@@ -1265,5 +1269,7 @@ nni_sp_tcp_register(void)
{
nni_sp_tran_register(&tcp_tran);
nni_sp_tran_register(&tcp4_tran);
+#ifdef NNG_ENABLE_IPV6
nni_sp_tran_register(&tcp6_tran);
+#endif
}
diff --git a/src/sp/transport/tls/tls.c b/src/sp/transport/tls/tls.c
index c6ef90de..c5e4e90d 100644
--- a/src/sp/transport/tls/tls.c
+++ b/src/sp/transport/tls/tls.c
@@ -1,5 +1,5 @@
//
-// Copyright 2023 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2019 Devolutions <info@devolutions.net>
//
@@ -28,8 +28,8 @@ typedef struct tlstran_pipe tlstran_pipe;
// tlstran_pipe is one end of a TLS connection.
struct tlstran_pipe {
- nng_stream * tls;
- nni_pipe * npipe;
+ nng_stream *tls;
+ nni_pipe *npipe;
uint16_t peer;
uint16_t proto;
size_t rcvmax;
@@ -37,7 +37,7 @@ struct tlstran_pipe {
nni_list_node node;
nni_list sendq;
nni_list recvq;
- tlstran_ep * ep;
+ tlstran_ep *ep;
nni_sockaddr sa;
nni_atomic_flag reaped;
nni_reap_node reap;
@@ -47,10 +47,10 @@ struct tlstran_pipe {
size_t gotrxhead;
size_t wanttxhead;
size_t wantrxhead;
- nni_aio * txaio;
- nni_aio * rxaio;
- nni_aio * negoaio;
- nni_msg * rxmsg;
+ nni_aio *txaio;
+ nni_aio *rxaio;
+ nni_aio *negoaio;
+ nni_msg *rxmsg;
nni_mtx mtx;
};
@@ -64,18 +64,18 @@ struct tlstran_ep {
bool fini;
int refcnt;
int authmode;
- nni_url * url;
+ nni_url *url;
nni_list pipes;
nni_reap_node reap;
- nng_stream_dialer * dialer;
+ nng_stream_dialer *dialer;
nng_stream_listener *listener;
- nni_aio * useraio;
- nni_aio * connaio;
- nni_aio * timeaio;
+ nni_aio *useraio;
+ nni_aio *connaio;
+ nni_aio *timeaio;
nni_list busypipes; // busy pipes -- ones passed to socket
nni_list waitpipes; // pipes waiting to match to socket
nni_list negopipes; // pipes busy negotiating
- const char * host;
+ const char *host;
nng_sockaddr src;
nng_sockaddr sa;
nni_stat_item st_rcv_max;
@@ -143,7 +143,7 @@ static void
tlstran_pipe_fini(void *arg)
{
tlstran_pipe *p = arg;
- tlstran_ep * ep;
+ tlstran_ep *ep;
tlstran_pipe_stop(p);
if ((ep = p->ep) != NULL) {
@@ -203,7 +203,7 @@ tlstran_pipe_reap(tlstran_pipe *p)
static void
tlstran_ep_match(tlstran_ep *ep)
{
- nni_aio * aio;
+ nni_aio *aio;
tlstran_pipe *p;
if (((aio = ep->useraio) == NULL) ||
@@ -222,9 +222,9 @@ static void
tlstran_pipe_nego_cb(void *arg)
{
tlstran_pipe *p = arg;
- tlstran_ep * ep = p->ep;
- nni_aio * aio = p->negoaio;
- nni_aio * uaio;
+ tlstran_ep *ep = p->ep;
+ nni_aio *aio = p->negoaio;
+ nni_aio *uaio;
int rv;
nni_mtx_lock(&ep->mtx);
@@ -302,10 +302,10 @@ tlstran_pipe_send_cb(void *arg)
{
tlstran_pipe *p = arg;
int rv;
- nni_aio * aio;
+ nni_aio *aio;
size_t n;
- nni_msg * msg;
- nni_aio * txaio = p->txaio;
+ nni_msg *msg;
+ nni_aio *txaio = p->txaio;
nni_mtx_lock(&p->mtx);
aio = nni_list_first(&p->sendq);
@@ -346,11 +346,11 @@ static void
tlstran_pipe_recv_cb(void *arg)
{
tlstran_pipe *p = arg;
- nni_aio * aio;
+ nni_aio *aio;
int rv;
size_t n;
- nni_msg * msg;
- nni_aio * rxaio = p->rxaio;
+ nni_msg *msg;
+ nni_aio *rxaio = p->rxaio;
nni_mtx_lock(&p->mtx);
aio = nni_list_first(&p->recvq);
@@ -644,7 +644,7 @@ tlstran_ep_fini(void *arg)
static void
tlstran_ep_close(void *arg)
{
- tlstran_ep * ep = arg;
+ tlstran_ep *ep = arg;
tlstran_pipe *p;
nni_mtx_lock(&ep->mtx);
@@ -680,8 +680,8 @@ static int
tlstran_url_parse_source(nni_url *url, nng_sockaddr *sa, const nni_url *surl)
{
int af;
- char * semi;
- char * src;
+ char *semi;
+ char *src;
size_t len;
int rv;
nni_aio *aio;
@@ -705,8 +705,10 @@ tlstran_url_parse_source(nni_url *url, nng_sockaddr *sa, const nni_url *surl)
af = NNG_AF_UNSPEC;
} else if (strcmp(surl->u_scheme, "tls+tcp4") == 0) {
af = NNG_AF_INET;
+#ifdef NNG_ENABLE_IPV6
} else if (strcmp(surl->u_scheme, "tls+tcp6") == 0) {
af = NNG_AF_INET6;
+#endif
} else {
return (NNG_EADDRINVAL);
}
@@ -742,11 +744,11 @@ tlstran_timer_cb(void *arg)
static void
tlstran_accept_cb(void *arg)
{
- tlstran_ep * ep = arg;
- nni_aio * aio = ep->connaio;
+ tlstran_ep *ep = arg;
+ nni_aio *aio = ep->connaio;
tlstran_pipe *p;
int rv;
- nng_stream * conn;
+ nng_stream *conn;
nni_mtx_lock(&ep->mtx);
@@ -801,11 +803,11 @@ error:
static void
tlstran_dial_cb(void *arg)
{
- tlstran_ep * ep = arg;
- nni_aio * aio = ep->connaio;
+ tlstran_ep *ep = arg;
+ nni_aio *aio = ep->connaio;
tlstran_pipe *p;
int rv;
- nng_stream * conn;
+ nng_stream *conn;
if ((rv = nni_aio_result(aio)) != 0) {
goto error;
@@ -873,10 +875,10 @@ tlstran_ep_init(tlstran_ep **epp, nng_url *url, nni_sock *sock)
static int
tlstran_ep_init_dialer(void **dp, nni_url *url, nni_dialer *ndialer)
{
- tlstran_ep * ep;
+ tlstran_ep *ep;
int rv;
nng_sockaddr srcsa;
- nni_sock * sock = nni_dialer_sock(ndialer);
+ nni_sock *sock = nni_dialer_sock(ndialer);
nni_url myurl;
// Check for invalid URL components.
@@ -923,16 +925,18 @@ tlstran_ep_init_listener(void **lp, nni_url *url, nni_listener *nlistener)
tlstran_ep *ep;
int rv;
uint16_t af;
- char * host = url->u_hostname;
- nni_aio * aio;
- nni_sock * sock = nni_listener_sock(nlistener);
+ char *host = url->u_hostname;
+ nni_aio *aio;
+ nni_sock *sock = nni_listener_sock(nlistener);
if (strcmp(url->u_scheme, "tls+tcp") == 0) {
af = NNG_AF_UNSPEC;
} else if (strcmp(url->u_scheme, "tls+tcp4") == 0) {
af = NNG_AF_INET;
+#ifdef NNG_ENABLE_IPV6
} else if (strcmp(url->u_scheme, "tls+tcp6") == 0) {
af = NNG_AF_INET6;
+#endif
} else {
return (NNG_EADDRINVAL);
}
@@ -1111,7 +1115,7 @@ static int
tlstran_ep_get_url(void *arg, void *v, size_t *szp, nni_type t)
{
tlstran_ep *ep = arg;
- char * s;
+ char *s;
int rv;
int port = 0;
@@ -1268,6 +1272,7 @@ static nni_sp_tran tls4_tran = {
.tran_fini = tlstran_fini,
};
+#ifdef NNG_ENABLE_IPV6
static nni_sp_tran tls6_tran = {
.tran_scheme = "tls+tcp6",
.tran_dialer = &tlstran_dialer_ops,
@@ -1276,6 +1281,7 @@ static nni_sp_tran tls6_tran = {
.tran_init = tlstran_init,
.tran_fini = tlstran_fini,
};
+#endif
int
nng_tls_register(void)
@@ -1288,5 +1294,7 @@ nni_sp_tls_register(void)
{
nni_sp_tran_register(&tls_tran);
nni_sp_tran_register(&tls4_tran);
+#ifdef NNG_ENABLE_IPV6
nni_sp_tran_register(&tls6_tran);
+#endif
}
diff --git a/src/sp/transport/ws/websocket.c b/src/sp/transport/ws/websocket.c
index a46ea58b..69509e84 100644
--- a/src/sp/transport/ws/websocket.c
+++ b/src/sp/transport/ws/websocket.c
@@ -1,5 +1,5 @@
//
-// Copyright 2023 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2019 Devolutions <info@devolutions.net>
//
@@ -27,7 +27,7 @@ struct ws_dialer {
uint16_t peer; // remote protocol
nni_list aios;
nni_mtx mtx;
- nni_aio * connaio;
+ nni_aio *connaio;
nng_stream_dialer *dialer;
bool started;
};
@@ -36,7 +36,7 @@ struct ws_listener {
uint16_t peer; // remote protocol
nni_list aios;
nni_mtx mtx;
- nni_aio * accaio;
+ nni_aio *accaio;
nng_stream_listener *listener;
bool started;
};
@@ -45,10 +45,10 @@ struct ws_pipe {
nni_mtx mtx;
bool closed;
uint16_t peer;
- nni_aio * user_txaio;
- nni_aio * user_rxaio;
- nni_aio * txaio;
- nni_aio * rxaio;
+ nni_aio *user_txaio;
+ nni_aio *user_rxaio;
+ nni_aio *txaio;
+ nni_aio *rxaio;
nng_stream *ws;
};
@@ -396,10 +396,10 @@ wstran_listener_fini(void *arg)
static void
wstran_connect_cb(void *arg)
{
- ws_dialer * d = arg;
- ws_pipe * p;
- nni_aio * caio = d->connaio;
- nni_aio * uaio;
+ ws_dialer *d = arg;
+ ws_pipe *p;
+ nni_aio *caio = d->connaio;
+ nni_aio *uaio;
int rv;
nng_stream *ws = NULL;
@@ -451,8 +451,8 @@ static void
wstran_accept_cb(void *arg)
{
ws_listener *l = arg;
- nni_aio * aaio = l->accaio;
- nni_aio * uaio;
+ nni_aio *aaio = l->accaio;
+ nni_aio *uaio;
int rv;
nni_mtx_lock(&l->mtx);
@@ -489,7 +489,7 @@ static int
wstran_dialer_init(void **dp, nng_url *url, nni_dialer *ndialer)
{
ws_dialer *d;
- nni_sock * s = nni_dialer_sock(ndialer);
+ nni_sock *s = nni_dialer_sock(ndialer);
int rv;
char name[64];
@@ -524,7 +524,7 @@ wstran_listener_init(void **lp, nng_url *url, nni_listener *listener)
{
ws_listener *l;
int rv;
- nni_sock * s = nni_listener_sock(listener);
+ nni_sock *s = nni_listener_sock(listener);
char name[64];
if ((l = NNI_ALLOC_STRUCT(l)) == NULL) {
@@ -713,6 +713,7 @@ static nni_sp_tran wss4_tran = {
.tran_fini = wstran_fini,
};
+#ifdef NNG_ENABLE_IPV6
static nni_sp_tran wss6_tran = {
.tran_scheme = "wss6",
.tran_dialer = &ws_dialer_ops,
@@ -721,13 +722,16 @@ static nni_sp_tran wss6_tran = {
.tran_init = wstran_init,
.tran_fini = wstran_fini,
};
+#endif
void
nni_sp_wss_register(void)
{
nni_sp_tran_register(&wss_tran);
nni_sp_tran_register(&wss4_tran);
+#ifdef NNG_ENABLE_IPV6
nni_sp_tran_register(&wss6_tran);
+#endif
}
#endif // NNG_TRANSPORT_WSS