diff options
| author | Garrett D'Amore <garrett@damore.org> | 2025-04-27 18:40:40 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2025-06-01 22:49:00 -0700 |
| commit | 8bcb82d245a5fce1bd519e2f99250dedf11e763d (patch) | |
| tree | 4d663bedbb043b9d599f061d7f2b5f9509c8f390 /src/core | |
| parent | 08400bd437149c4fb31af9b2abece2ae44041283 (diff) | |
| download | nng-8bcb82d245a5fce1bd519e2f99250dedf11e763d.tar.gz nng-8bcb82d245a5fce1bd519e2f99250dedf11e763d.tar.bz2 nng-8bcb82d245a5fce1bd519e2f99250dedf11e763d.zip | |
Introduce DTLS transport for NNG.
This introduces a new experimental transport for DTLS, that
provides encryption over UDP. It has a simpler protocol than
the current UDP SP protocol (but we intend to fix that by making
the UDP transport simpler in a follow up!)
There are a few other fixes in the TLS layer itself, and in
the build, that were needed to accomplish this work.
Also there was an endianness bug in the UDP protocol handling, which
is fixed here.
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/aio.c | 2 | ||||
| -rw-r--r-- | src/core/defs.h | 38 | ||||
| -rw-r--r-- | src/core/pipe.c | 2 | ||||
| -rw-r--r-- | src/core/platform.h | 4 | ||||
| -rw-r--r-- | src/core/url.c | 3 |
5 files changed, 28 insertions, 21 deletions
diff --git a/src/core/aio.c b/src/core/aio.c index 4c4c78b6..76ca7726 100644 --- a/src/core/aio.c +++ b/src/core/aio.c @@ -499,7 +499,7 @@ nni_aio_finish_sync(nni_aio *aio, nng_err result, size_t count) void nni_aio_finish_error(nni_aio *aio, nng_err result) { - nni_aio_finish_impl(aio, result, NNG_OK, NULL, false); + nni_aio_finish_impl(aio, result, 0, NULL, false); } void diff --git a/src/core/defs.h b/src/core/defs.h index 419f5ba7..432c0be7 100644 --- a/src/core/defs.h +++ b/src/core/defs.h @@ -151,25 +151,25 @@ typedef void (*nni_cb)(void *); (ptr)[0] = (uint8_t) ((uint64_t) (u)); \ } while (0) -#define NNI_GET16LE(ptr, v) \ - v = (((uint16_t) ((uint8_t) (ptr)[1])) << 8u) + \ - (((uint16_t) (uint8_t) (ptr)[0])) - -#define NNI_GET32LE(ptr, v) \ - v = (((uint32_t) ((uint8_t) (ptr)[3])) << 24u) + \ - (((uint32_t) ((uint8_t) (ptr)[2])) << 16u) + \ - (((uint32_t) ((uint8_t) (ptr)[1])) << 8u) + \ - (((uint32_t) (uint8_t) (ptr)[0])) - -#define NNI_GET64LE(ptr, v) \ - v = (((uint64_t) ((uint8_t) (ptr)[7])) << 56u) + \ - (((uint64_t) ((uint8_t) (ptr)[6])) << 48u) + \ - (((uint64_t) ((uint8_t) (ptr)[5])) << 40u) + \ - (((uint64_t) ((uint8_t) (ptr)[4])) << 32u) + \ - (((uint64_t) ((uint8_t) (ptr)[3])) << 24u) + \ - (((uint64_t) ((uint8_t) (ptr)[2])) << 16u) + \ - (((uint64_t) ((uint8_t) (ptr)[1])) << 8u) + \ - (((uint64_t) (uint8_t) (ptr)[0])) +#define NNI_GET16LE(ptr, v) \ + v = (((uint16_t) (((uint8_t *) (ptr))[1])) << 8u) + \ + ((uint16_t) ((uint8_t *) (ptr))[0]) + +#define NNI_GET32LE(ptr, v) \ + v = (((uint32_t) (((uint8_t *) (ptr))[3])) << 24u) + \ + (((uint32_t) (((uint8_t *) (ptr))[2])) << 16u) + \ + (((uint32_t) (((uint8_t *) (ptr))[1])) << 8u) + \ + (((uint32_t) ((uint8_t *) (ptr))[0])) + +#define NNI_GET64LE(ptr, v) \ + v = (((uint64_t) (((uint8_t *) (ptr))[7])) << 56u) + \ + (((uint64_t) (((uint8_t *) (ptr))[6])) << 48u) + \ + (((uint64_t) (((uint8_t *) (ptr))[5])) << 40u) + \ + (((uint64_t) (((uint8_t *) (ptr))[4])) << 32u) + \ + (((uint64_t) (((uint8_t *) (ptr))[3])) << 24u) + \ + (((uint64_t) (((uint8_t *) (ptr))[2])) << 16u) + \ + (((uint64_t) (((uint8_t *) (ptr))[1])) << 8u) + \ + (((uint64_t) ((uint8_t *) (ptr))[0])) // This increments a pointer a fixed number of byte cells. #define NNI_INCPTR(ptr, n) ((ptr) = (void *) ((char *) (ptr) + (n))) diff --git a/src/core/pipe.c b/src/core/pipe.c index c57a8d43..5ce85420 100644 --- a/src/core/pipe.c +++ b/src/core/pipe.c @@ -250,7 +250,7 @@ pipe_create(nni_pipe **pp, nni_sock *sock, nni_sp_tran *tran, nni_dialer *d, size_t sz; sz = NNI_ALIGN_UP(sizeof(*p)) + NNI_ALIGN_UP(pops->pipe_size) + - NNI_ALIGN_UP(tops->p_size); + NNI_ALIGN_UP(tops->p_size()); if ((p = nni_zalloc(sz)) == NULL) { return (NNG_ENOMEM); diff --git a/src/core/platform.h b/src/core/platform.h index a13ae9f2..cdb0d887 100644 --- a/src/core/platform.h +++ b/src/core/platform.h @@ -359,6 +359,10 @@ typedef struct nni_plat_udp nni_plat_udp; // aio's a_pipe. extern int nni_plat_udp_open(nni_plat_udp **, const nni_sockaddr *); +// nni_plat_udp_stop stops I/O on the socket, but does not close it +// or free the underlying data. May block for callbacks to complete. +extern void nni_plat_udp_stop(nni_plat_udp *); + // nni_plat_udp_close closes the underlying UDP socket. extern void nni_plat_udp_close(nni_plat_udp *); diff --git a/src/core/url.c b/src/core/url.c index 9db92992..fb13ee59 100644 --- a/src/core/url.c +++ b/src/core/url.c @@ -273,6 +273,9 @@ static const char *nni_schemes[] = { "udp", "udp4", "udp6", + "dtls", + "dtls4", + "dtls6", // we don't support these "file", "mailto", |
