From 611c4acdddab9d702d235c2bcfe3b69002e93569 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 19 Oct 2025 10:40:26 -0700 Subject: Add support for OpenSSL v3.5 and newer. We are *only* supporting 3.5 (or newer 3.x releases) as its the newest LTS version of OpenSSL. This supports the full set of TLS features with NNG, including DTLS, PSK, TLS 1.3, etc. Future work will explore making using of the QUIC support in OpenSSL. Note that this OpenSSL work sits on top of NNG's TCP streams, so it cannot benefit from Linux in-kernel TLS or other features such as TCP fast open at this time. --- src/core/defs.h | 7 +++++++ src/core/sockaddr.c | 25 ++++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) (limited to 'src/core') diff --git a/src/core/defs.h b/src/core/defs.h index c94d9bd3..0ca885b3 100644 --- a/src/core/defs.h +++ b/src/core/defs.h @@ -261,4 +261,11 @@ extern void *nni_zalloc(size_t); // Most implementations can just call free() here. extern void nni_free(void *, size_t); +// nni_inet_ntop is like inet_ntop, but for NNG_AF_INET and NNG_AF_INET6. The +// output buffer must be able to contain at least 46 bytes. Note that +// NNG_AF_UNSPEC is explicitly unsupported, as we do not pass the address +// length. +extern char *nni_inet_ntop( + enum nng_sockaddr_family af, const uint8_t *addr, char *buf); + #endif // CORE_DEFS_H diff --git a/src/core/sockaddr.c b/src/core/sockaddr.c index 9dcfa3bc..39e527da 100644 --- a/src/core/sockaddr.c +++ b/src/core/sockaddr.c @@ -24,17 +24,27 @@ str_sa_inet(const nng_sockaddr_in *sa, char *buf, size_t bufsz) { uint8_t *a_bytes = (uint8_t *) &sa->sa_addr; uint8_t *p_bytes = (uint8_t *) &sa->sa_port; + char ipbuf[46]; - snprintf(buf, bufsz, "%u.%u.%u.%u:%u", a_bytes[0], a_bytes[1], - a_bytes[2], a_bytes[3], + snprintf(buf, bufsz, "%s:%u", + nni_inet_ntop(NNG_AF_INET, a_bytes, ipbuf), (((uint16_t) p_bytes[0]) << 8) + p_bytes[1]); return (buf); } -// emit an IPv6 address in "short form" -static char * -nni_inet_ntop(const uint8_t addr[16], char buf[46]) +// emit an IP address, only NNG_AF_INET and NNG_AF_INET6 explicitly are +// supported. (NO support for NNG_AF_UNSPEC.) +char * +nni_inet_ntop(enum nng_sockaddr_family af, const uint8_t *addr, char *buf) { + if (af == NNG_AF_INET) { + snprintf(buf, 46, "%u.%u.%u.%u", addr[0], addr[1], addr[2], + addr[3]); + return (buf); + } + if (af != NNG_AF_INET6) { + return (NULL); + } const uint8_t v4map[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff }; @@ -106,11 +116,12 @@ str_sa_inet6(const nng_sockaddr_in6 *sa, char *buf, size_t bufsz) if (sa->sa_scope) { snprintf(buf, bufsz, "[%s%%%u]:%u", - nni_inet_ntop(sa->sa_addr, istr), sa->sa_scope, + nni_inet_ntop(NNG_AF_INET6, sa->sa_addr, istr), + sa->sa_scope, (((uint16_t) (p_bytes[0])) << 8) + p_bytes[1]); } else { snprintf(buf, bufsz, "[%s]:%u", - nni_inet_ntop(sa->sa_addr, istr), + nni_inet_ntop(NNG_AF_INET6, sa->sa_addr, istr), (((uint16_t) (p_bytes[0])) << 8) + p_bytes[1]); } return (buf); -- cgit v1.2.3-70-g09d2