-
-
Notifications
You must be signed in to change notification settings - Fork 497
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
17 changed files
with
344 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// | ||
// Copyright 2023 Staysail Systems, Inc. <[email protected]> | ||
// Copyright 2024 Staysail Systems, Inc. <[email protected]> | ||
// | ||
// 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, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// | ||
// Copyright 2020 Staysail Systems, Inc. <[email protected]> | ||
// Copyright 2024 Staysail Systems, Inc. <[email protected]> | ||
// Copyright 2018 Capitar IT Group BV <[email protected]> | ||
// | ||
// 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)); | ||
|
Oops, something went wrong.