diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-06-12 20:05:34 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-06-13 18:01:52 -0700 |
| commit | da2aac4a6eb10af88e3938068e24c58aea1832b1 (patch) | |
| tree | fb0676be5426ed1510945b7e7fe3d09eb45333a7 /src/transport | |
| parent | 61ffae5e3649897776c26799ccaaa35d578ba816 (diff) | |
| download | nng-da2aac4a6eb10af88e3938068e24c58aea1832b1.tar.gz nng-da2aac4a6eb10af88e3938068e24c58aea1832b1.tar.bz2 nng-da2aac4a6eb10af88e3938068e24c58aea1832b1.zip | |
fixes #540 nni_ep_opttype serves no purpose
fixes #538 setopt should have an explicit chkopt routine
fixes #537 Internal TCP API needs better name separation
fixes #524 Option types should be "typed"
This is a rework of the option management code, to make it both clearer
and to prepare for further work to break up endpoints. This reduces
a certain amount of dead or redundant code, and actually saves cycles
when setting options, as some loops were not terminated that should have
been.
Diffstat (limited to 'src/transport')
| -rw-r--r-- | src/transport/inproc/inproc.c | 24 | ||||
| -rw-r--r-- | src/transport/ipc/ipc.c | 451 | ||||
| -rw-r--r-- | src/transport/tcp/tcp.c | 451 | ||||
| -rw-r--r-- | src/transport/tls/tls.c | 606 | ||||
| -rw-r--r-- | src/transport/ws/websocket.c | 318 | ||||
| -rw-r--r-- | src/transport/zerotier/zerotier.c | 341 |
6 files changed, 1140 insertions, 1051 deletions
diff --git a/src/transport/inproc/inproc.c b/src/transport/inproc/inproc.c index bc51d971..7a52d89f 100644 --- a/src/transport/inproc/inproc.c +++ b/src/transport/inproc/inproc.c @@ -177,7 +177,7 @@ nni_inproc_pipe_peer(void *arg) } static int -nni_inproc_pipe_get_addr(void *arg, void *buf, size_t *szp, int typ) +nni_inproc_pipe_get_addr(void *arg, void *buf, size_t *szp, nni_opt_type t) { nni_inproc_pipe *p = arg; nni_sockaddr sa; @@ -185,7 +185,7 @@ nni_inproc_pipe_get_addr(void *arg, void *buf, size_t *szp, int typ) memset(&sa, 0, sizeof(sa)); sa.s_inproc.sa_family = NNG_AF_INPROC; nni_strlcpy(sa.s_inproc.sa_name, p->addr, sizeof(sa.s_inproc.sa_name)); - return (nni_copyout_sockaddr(&sa, buf, szp, typ)); + return (nni_copyout_sockaddr(&sa, buf, szp, t)); } static int @@ -435,20 +435,20 @@ nni_inproc_ep_accept(void *arg, nni_aio *aio) nni_mtx_unlock(&nni_inproc.mx); } -static nni_tran_pipe_option nni_inproc_pipe_options[] = { +static nni_tran_option nni_inproc_pipe_options[] = { { - .po_name = NNG_OPT_LOCADDR, - .po_type = NNI_TYPE_SOCKADDR, - .po_getopt = nni_inproc_pipe_get_addr, + .o_name = NNG_OPT_LOCADDR, + .o_type = NNI_TYPE_SOCKADDR, + .o_get = nni_inproc_pipe_get_addr, }, { - .po_name = NNG_OPT_REMADDR, - .po_type = NNI_TYPE_SOCKADDR, - .po_getopt = nni_inproc_pipe_get_addr, + .o_name = NNG_OPT_REMADDR, + .o_type = NNI_TYPE_SOCKADDR, + .o_get = nni_inproc_pipe_get_addr, }, // terminate list { - .po_name = NULL, + .o_name = NULL, }, }; @@ -461,10 +461,10 @@ static nni_tran_pipe_ops nni_inproc_pipe_ops = { .p_options = nni_inproc_pipe_options, }; -static nni_tran_ep_option nni_inproc_ep_options[] = { +static nni_tran_option nni_inproc_ep_options[] = { // terminate list { - .eo_name = NULL, + .o_name = NULL, }, }; diff --git a/src/transport/ipc/ipc.c b/src/transport/ipc/ipc.c index 6191dea6..c5c7032a 100644 --- a/src/transport/ipc/ipc.c +++ b/src/transport/ipc/ipc.c @@ -20,11 +20,11 @@ // Windows named pipes. Other platforms could use other mechanisms, // but all implementations on the platform must use the same mechanism. -typedef struct nni_ipc_pipe nni_ipc_pipe; -typedef struct nni_ipc_ep nni_ipc_ep; +typedef struct ipc_pipe ipc_pipe; +typedef struct ipc_ep ipc_ep; -// nni_ipc_pipe is one end of an IPC connection. -struct nni_ipc_pipe { +// ipc_pipe is one end of an IPC connection. +struct ipc_pipe { nni_plat_ipc_pipe *ipp; uint16_t peer; uint16_t proto; @@ -48,7 +48,7 @@ struct nni_ipc_pipe { nni_mtx mtx; }; -struct nni_ipc_ep { +struct ipc_ep { nni_sockaddr sa; nni_plat_ipc_ep *iep; uint16_t proto; @@ -58,28 +58,28 @@ struct nni_ipc_ep { nni_mtx mtx; }; -static void nni_ipc_pipe_dosend(nni_ipc_pipe *, nni_aio *); -static void nni_ipc_pipe_dorecv(nni_ipc_pipe *); -static void nni_ipc_pipe_send_cb(void *); -static void nni_ipc_pipe_recv_cb(void *); -static void nni_ipc_pipe_nego_cb(void *); -static void nni_ipc_ep_cb(void *); +static void ipc_pipe_dosend(ipc_pipe *, nni_aio *); +static void ipc_pipe_dorecv(ipc_pipe *); +static void ipc_pipe_send_cb(void *); +static void ipc_pipe_recv_cb(void *); +static void ipc_pipe_nego_cb(void *); +static void ipc_ep_cb(void *); static int -nni_ipc_tran_init(void) +ipc_tran_init(void) { return (0); } static void -nni_ipc_tran_fini(void) +ipc_tran_fini(void) { } static void -nni_ipc_pipe_close(void *arg) +ipc_pipe_close(void *arg) { - nni_ipc_pipe *pipe = arg; + ipc_pipe *pipe = arg; nni_aio_close(pipe->rxaio); nni_aio_close(pipe->txaio); @@ -89,9 +89,9 @@ nni_ipc_pipe_close(void *arg) } static void -nni_ipc_pipe_stop(void *arg) +ipc_pipe_stop(void *arg) { - nni_ipc_pipe *pipe = arg; + ipc_pipe *pipe = arg; nni_aio_stop(pipe->rxaio); nni_aio_stop(pipe->txaio); @@ -99,9 +99,9 @@ nni_ipc_pipe_stop(void *arg) } static void -nni_ipc_pipe_fini(void *arg) +ipc_pipe_fini(void *arg) { - nni_ipc_pipe *pipe = arg; + ipc_pipe *pipe = arg; nni_aio_fini(pipe->rxaio); nni_aio_fini(pipe->txaio); @@ -117,19 +117,19 @@ nni_ipc_pipe_fini(void *arg) } static int -nni_ipc_pipe_init(nni_ipc_pipe **pipep, nni_ipc_ep *ep, void *ipp) +ipc_pipe_init(ipc_pipe **pipep, ipc_ep *ep, void *ipp) { - nni_ipc_pipe *p; - int rv; + ipc_pipe *p; + int rv; if ((p = NNI_ALLOC_STRUCT(p)) == NULL) { return (NNG_ENOMEM); } nni_mtx_init(&p->mtx); - if (((rv = nni_aio_init(&p->txaio, nni_ipc_pipe_send_cb, p)) != 0) || - ((rv = nni_aio_init(&p->rxaio, nni_ipc_pipe_recv_cb, p)) != 0) || - ((rv = nni_aio_init(&p->negaio, nni_ipc_pipe_nego_cb, p)) != 0)) { - nni_ipc_pipe_fini(p); + if (((rv = nni_aio_init(&p->txaio, ipc_pipe_send_cb, p)) != 0) || + ((rv = nni_aio_init(&p->rxaio, ipc_pipe_recv_cb, p)) != 0) || + ((rv = nni_aio_init(&p->negaio, ipc_pipe_nego_cb, p)) != 0)) { + ipc_pipe_fini(p); return (rv); } nni_aio_list_init(&p->sendq); @@ -146,9 +146,9 @@ nni_ipc_pipe_init(nni_ipc_pipe **pipep, nni_ipc_ep *ep, void *ipp) } static void -nni_ipc_cancel_start(nni_aio *aio, int rv) +ipc_cancel_start(nni_aio *aio, int rv) { - nni_ipc_pipe *pipe = nni_aio_get_prov_data(aio); + ipc_pipe *pipe = nni_aio_get_prov_data(aio); nni_mtx_lock(&pipe->mtx); if (pipe->user_negaio != aio) { @@ -163,11 +163,11 @@ nni_ipc_cancel_start(nni_aio *aio, int rv) } static void -nni_ipc_pipe_nego_cb(void *arg) +ipc_pipe_nego_cb(void *arg) { - nni_ipc_pipe *pipe = arg; - nni_aio * aio = pipe->negaio; - int rv; + ipc_pipe *pipe = arg; + nni_aio * aio = pipe->negaio; + int rv; nni_mtx_lock(&pipe->mtx); if ((rv = nni_aio_result(aio)) != 0) { @@ -220,14 +220,14 @@ done: } static void -nni_ipc_pipe_send_cb(void *arg) +ipc_pipe_send_cb(void *arg) { - nni_ipc_pipe *pipe = arg; - nni_aio * aio; - nni_aio * txaio = pipe->txaio; - nni_msg * msg; - int rv; - size_t n; + ipc_pipe *pipe = arg; + nni_aio * aio; + nni_aio * txaio = pipe->txaio; + nni_msg * msg; + int rv; + size_t n; nni_mtx_lock(&pipe->mtx); aio = nni_list_first(&pipe->sendq); @@ -255,7 +255,7 @@ nni_ipc_pipe_send_cb(void *arg) nni_aio_list_remove(aio); if (!nni_list_empty(&pipe->sendq)) { // schedule next send - nni_ipc_pipe_dosend(pipe, nni_list_first(&pipe->sendq)); + ipc_pipe_dosend(pipe, nni_list_first(&pipe->sendq)); } nni_mtx_unlock(&pipe->mtx); @@ -267,14 +267,14 @@ nni_ipc_pipe_send_cb(void *arg) } static void -nni_ipc_pipe_recv_cb(void *arg) +ipc_pipe_recv_cb(void *arg) { - nni_ipc_pipe *pipe = arg; - nni_aio * aio; - int rv; - size_t n; - nni_msg * msg; - nni_aio * rxaio = pipe->rxaio; + ipc_pipe *pipe = arg; + nni_aio * aio; + int rv; + size_t n; + nni_msg * msg; + nni_aio * rxaio = pipe->rxaio; nni_mtx_lock(&pipe->mtx); aio = nni_list_first(&pipe->recvq); @@ -346,7 +346,7 @@ nni_ipc_pipe_recv_cb(void *arg) msg = pipe->rxmsg; pipe->rxmsg = NULL; if (!nni_list_empty(&pipe->recvq)) { - nni_ipc_pipe_dorecv(pipe); + ipc_pipe_dorecv(pipe); } nni_mtx_unlock(&pipe->mtx); @@ -367,9 +367,9 @@ recv_error: } static void -nni_ipc_cancel_tx(nni_aio *aio, int rv) +ipc_cancel_tx(nni_aio *aio, int rv) { - nni_ipc_pipe *pipe = nni_aio_get_prov_data(aio); + ipc_pipe *pipe = nni_aio_get_prov_data(aio); nni_mtx_lock(&pipe->mtx); if (!nni_aio_list_active(aio)) { @@ -390,7 +390,7 @@ nni_ipc_cancel_tx(nni_aio *aio, int rv) } static void -nni_ipc_pipe_dosend(nni_ipc_pipe *pipe, nni_aio *aio) +ipc_pipe_dosend(ipc_pipe *pipe, nni_aio *aio) { nni_aio *txaio; nni_msg *msg; @@ -425,31 +425,31 @@ nni_ipc_pipe_dosend(nni_ipc_pipe *pipe, nni_aio *aio) } static void -nni_ipc_pipe_send(void *arg, nni_aio *aio) +ipc_pipe_send(void *arg, nni_aio *aio) { - nni_ipc_pipe *pipe = arg; - int rv; + ipc_pipe *pipe = arg; + int rv; if (nni_aio_begin(aio) != 0) { return; } nni_mtx_lock(&pipe->mtx); - if ((rv = nni_aio_schedule(aio, nni_ipc_cancel_tx, pipe)) != 0) { + if ((rv = nni_aio_schedule(aio, ipc_cancel_tx, pipe)) != 0) { nni_mtx_unlock(&pipe->mtx); nni_aio_finish_error(aio, rv); return; } nni_list_append(&pipe->sendq, aio); if (nni_list_first(&pipe->sendq) == aio) { - nni_ipc_pipe_dosend(pipe, aio); + ipc_pipe_dosend(pipe, aio); } nni_mtx_unlock(&pipe->mtx); } static void -nni_ipc_cancel_rx(nni_aio *aio, int rv) +ipc_cancel_rx(nni_aio *aio, int rv) { - nni_ipc_pipe *pipe = nni_aio_get_prov_data(aio); + ipc_pipe *pipe = nni_aio_get_prov_data(aio); nni_mtx_lock(&pipe->mtx); if (!nni_aio_list_active(aio)) { @@ -470,7 +470,7 @@ nni_ipc_cancel_rx(nni_aio *aio, int rv) } static void -nni_ipc_pipe_dorecv(nni_ipc_pipe *pipe) +ipc_pipe_dorecv(ipc_pipe *pipe) { nni_aio *rxaio; nni_iov iov; @@ -486,17 +486,17 @@ nni_ipc_pipe_dorecv(nni_ipc_pipe *pipe) } static void -nni_ipc_pipe_recv(void *arg, nni_aio *aio) +ipc_pipe_recv(void *arg, nni_aio *aio) { - nni_ipc_pipe *pipe = arg; - int rv; + ipc_pipe *pipe = arg; + int rv; if (nni_aio_begin(aio) != 0) { return; } nni_mtx_lock(&pipe->mtx); - if ((rv = nni_aio_schedule(aio, nni_ipc_cancel_rx, pipe)) != 0) { + if ((rv = nni_aio_schedule(aio, ipc_cancel_rx, pipe)) != 0) { nni_mtx_unlock(&pipe->mtx); nni_aio_finish_error(aio, rv); return; @@ -504,24 +504,24 @@ nni_ipc_pipe_recv(void *arg, nni_aio *aio) nni_list_append(&pipe->recvq, aio); if (nni_list_first(&pipe->recvq) == aio) { - nni_ipc_pipe_dorecv(pipe); + ipc_pipe_dorecv(pipe); } nni_mtx_unlock(&pipe->mtx); } static void -nni_ipc_pipe_start(void *arg, nni_aio *aio) +ipc_pipe_start(void *arg, nni_aio *aio) { - nni_ipc_pipe *pipe = arg; - nni_aio * negaio; - nni_iov iov; - int rv; + ipc_pipe *pipe = arg; + nni_aio * negaio; + nni_iov iov; + int rv; if (nni_aio_begin(aio) != 0) { return; } nni_mtx_lock(&pipe->mtx); - if ((rv = nni_aio_schedule(aio, nni_ipc_cancel_start, pipe)) != 0) { + if ((rv = nni_aio_schedule(aio, ipc_cancel_start, pipe)) != 0) { nni_mtx_unlock(&pipe->mtx); nni_aio_finish_error(aio, rv); return; @@ -547,72 +547,72 @@ nni_ipc_pipe_start(void *arg, nni_aio *aio) } static uint16_t -nni_ipc_pipe_peer(void *arg) +ipc_pipe_peer(void *arg) { - nni_ipc_pipe *pipe = arg; + ipc_pipe *pipe = arg; return (pipe->peer); } static int -nni_ipc_pipe_get_addr(void *arg, void *buf, size_t *szp, int typ) +ipc_pipe_get_addr(void *arg, void *buf, size_t *szp, nni_opt_type t) { - nni_ipc_pipe *p = arg; - return (nni_copyout_sockaddr(&p->sa, buf, szp, typ)); + ipc_pipe *p = arg; + return (nni_copyout_sockaddr(&p->sa, buf, szp, t)); } static int -nni_ipc_pipe_get_peer_uid(void *arg, void *buf, size_t *szp, int typ) +ipc_pipe_get_peer_uid(void *arg, void *buf, size_t *szp, nni_opt_type t) { - nni_ipc_pipe *p = arg; - uint64_t id; - int rv; + ipc_pipe *p = arg; + uint64_t id; + int rv; if ((rv = nni_plat_ipc_pipe_get_peer_uid(p->ipp, &id)) != 0) { return (rv); } - return (nni_copyout_u64(id, buf, szp, typ)); + return (nni_copyout_u64(id, buf, szp, t)); } static int -nni_ipc_pipe_get_peer_gid(void *arg, void *buf, size_t *szp, int typ) +ipc_pipe_get_peer_gid(void *arg, void *buf, size_t *szp, nni_opt_type t) { - nni_ipc_pipe *p = arg; - uint64_t id; - int rv; + ipc_pipe *p = arg; + uint64_t id; + int rv; if ((rv = nni_plat_ipc_pipe_get_peer_gid(p->ipp, &id)) != 0) { return (rv); } - return (nni_copyout_u64(id, buf, szp, typ)); + return (nni_copyout_u64(id, buf, szp, t)); } static int -nni_ipc_pipe_get_peer_pid(void *arg, void *buf, size_t *szp, int typ) +ipc_pipe_get_peer_pid(void *arg, void *buf, size_t *szp, nni_opt_type t) { - nni_ipc_pipe *p = arg; - uint64_t id; - int rv; + ipc_pipe *p = arg; + uint64_t id; + int rv; if ((rv = nni_plat_ipc_pipe_get_peer_pid(p->ipp, &id)) != 0) { return (rv); } - return (nni_copyout_u64(id, buf, szp, typ)); + return (nni_copyout_u64(id, buf, szp, t)); } static int -nni_ipc_pipe_get_peer_zoneid(void *arg, void *buf, size_t *szp, int typ) +ipc_pipe_get_peer_zoneid(void *arg, void *buf, size_t *szp, nni_opt_type t) { - nni_ipc_pipe *p = arg; - uint64_t id; - int rv; + ipc_pipe *p = arg; + uint64_t id; + int rv; if ((rv = nni_plat_ipc_pipe_get_peer_zoneid(p->ipp, &id)) != 0) { return (rv); } - return (nni_copyout_u64(id, buf, szp, typ)); + return (nni_copyout_u64(id, buf, szp, t)); } static void -nni_ipc_ep_fini(void *arg) +ipc_ep_fini(void *arg) { - nni_ipc_ep *ep = arg; + ipc_ep *ep = arg; nni_aio_stop(ep->aio); nni_plat_ipc_ep_fini(ep->iep); @@ -622,11 +622,11 @@ nni_ipc_ep_fini(void *arg) } static int -nni_ipc_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) +ipc_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) { - nni_ipc_ep *ep; - int rv; - size_t sz; + ipc_ep *ep; + int rv; + size_t sz; if ((ep = NNI_ALLOC_STRUCT(ep)) == NULL) { return (NNG_ENOMEM); @@ -637,17 +637,17 @@ nni_ipc_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) ep->sa.s_ipc.sa_family = NNG_AF_IPC; if (nni_strlcpy(ep->sa.s_ipc.sa_path, url->u_path, sz) >= sz) { - nni_ipc_ep_fini(ep); + ipc_ep_fini(ep); return (NNG_EADDRINVAL); } if ((rv = nni_plat_ipc_ep_init(&ep->iep, &ep->sa, mode)) != 0) { - nni_ipc_ep_fini(ep); + ipc_ep_fini(ep); return (rv); } - if ((rv = nni_aio_init(&ep->aio, nni_ipc_ep_cb, ep)) != 0) { - nni_ipc_ep_fini(ep); + if ((rv = nni_aio_init(&ep->aio, ipc_ep_cb, ep)) != 0) { + ipc_ep_fini(ep); return (rv); } ep->proto = nni_sock_proto_id(sock); @@ -657,9 +657,9 @@ nni_ipc_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) } static void -nni_ipc_ep_close(void *arg) +ipc_ep_close(void *arg) { - nni_ipc_ep *ep = arg; + ipc_ep *ep = arg; nni_aio_close(ep->aio); @@ -669,10 +669,10 @@ nni_ipc_ep_close(void *arg) } static int -nni_ipc_ep_bind(void *arg) +ipc_ep_bind(void *arg) { - nni_ipc_ep *ep = arg; - int rv; + ipc_ep *ep = arg; + int rv; nni_mtx_lock(&ep->mtx); rv = nni_plat_ipc_ep_listen(ep->iep); @@ -681,11 +681,11 @@ nni_ipc_ep_bind(void *arg) } static void -nni_ipc_ep_finish(nni_ipc_ep *ep) +ipc_ep_finish(ipc_ep *ep) { - nni_aio * aio; - int rv; - nni_ipc_pipe *pipe = NULL; + nni_aio * aio; + int rv; + ipc_pipe *pipe = NULL; if ((rv = nni_aio_result(ep->aio)) != 0) { goto done; @@ -694,7 +694,7 @@ nni_ipc_ep_finish(nni_ipc_ep *ep) // Attempt to allocate the parent pipe. If this fails we'll // drop the connection (ENOMEM probably). - rv = nni_ipc_pipe_init(&pipe, ep, nni_aio_get_output(ep->aio, 0)); + rv = ipc_pipe_init(&pipe, ep, nni_aio_get_output(ep->aio, 0)); done: aio = ep->user_aio; @@ -708,7 +708,7 @@ done: } if (pipe != NULL) { - nni_ipc_pipe_fini(pipe); + ipc_pipe_fini(pipe); } if (aio != NULL) { NNI_ASSERT(rv != 0); @@ -717,19 +717,19 @@ done: } static void -nni_ipc_ep_cb(void *arg) +ipc_ep_cb(void *arg) { - nni_ipc_ep *ep = arg; + ipc_ep *ep = arg; nni_mtx_lock(&ep->mtx); - nni_ipc_ep_finish(ep); + ipc_ep_finish(ep); nni_mtx_unlock(&ep->mtx); } static void -nni_ipc_cancel_ep(nni_aio *aio, int rv) +ipc_cancel_ep(nni_aio *aio, int rv) { - nni_ipc_ep *ep = nni_aio_get_prov_data(aio); + ipc_ep *ep = nni_aio_get_prov_data(aio); NNI_ASSERT(rv != 0); nni_mtx_lock(&ep->mtx); @@ -745,10 +745,10 @@ nni_ipc_cancel_ep(nni_aio *aio, int rv) } static void -nni_ipc_ep_accept(void *arg, nni_aio *aio) +ipc_ep_accept(void *arg, nni_aio *aio) { - nni_ipc_ep *ep = arg; - int rv; + ipc_ep *ep = arg; + int rv; if (nni_aio_begin(aio) != 0) { return; @@ -756,7 +756,7 @@ nni_ipc_ep_accept(void *arg, nni_aio *aio) nni_mtx_lock(&ep->mtx); NNI_ASSERT(ep->user_aio == NULL); - if ((rv = nni_aio_schedule(aio, nni_ipc_cancel_ep, ep)) != 0) { + if ((rv = nni_aio_schedule(aio, ipc_cancel_ep, ep)) != 0) { nni_mtx_unlock(&ep->mtx); nni_aio_finish_error(aio, rv); return; @@ -768,10 +768,10 @@ nni_ipc_ep_accept(void *arg, nni_aio *aio) } static void -nni_ipc_ep_connect(void *arg, nni_aio *aio) +ipc_ep_connect(void *arg, nni_aio *aio) { - nni_ipc_ep *ep = arg; - int rv; + ipc_ep *ep = arg; + int rv; if (nni_aio_begin(aio) != 0) { return; @@ -779,7 +779,7 @@ nni_ipc_ep_connect(void *arg, nni_aio *aio) nni_mtx_lock(&ep->mtx); NNI_ASSERT(ep->user_aio == NULL); - if ((rv = nni_aio_schedule(aio, nni_ipc_cancel_ep, ep)) != 0) { + if ((rv = nni_aio_schedule(aio, ipc_cancel_ep, ep)) != 0) { nni_mtx_unlock(&ep->mtx); nni_aio_finish_error(aio, rv); return; @@ -791,14 +791,13 @@ nni_ipc_ep_connect(void *arg, nni_aio *aio) } static int -nni_ipc_ep_setopt_recvmaxsz(void *arg, const void *data, size_t sz, int typ) +ipc_ep_set_recvmaxsz(void *arg, const void *data, size_t sz, nni_opt_type t) { - nni_ipc_ep *ep = arg; - size_t val; - int rv; + ipc_ep *ep = arg; + size_t val; + int rv; - rv = nni_copyin_size(&val, data, sz, 0, NNI_MAXSZ, typ); - if ((rv == 0) && (ep != NULL)) { + if ((rv = nni_copyin_size(&val, data, sz, 0, NNI_MAXSZ, t)) == 0) { nni_mtx_lock(&ep->mtx); ep->rcvmax = val; nni_mtx_unlock(&ep->mtx); @@ -807,30 +806,35 @@ nni_ipc_ep_setopt_recvmaxsz(void *arg, const void *data, size_t sz, int typ) } static int -nni_ipc_ep_getopt_recvmaxsz(void *arg, void *data, size_t *szp, int typ) +ipc_ep_chk_recvmaxsz(const void *data, size_t sz, nni_opt_type t) { - nni_ipc_ep *ep = arg; - return (nni_copyout_size(ep->rcvmax, data, szp, typ)); + return (nni_copyin_size(NULL, data, sz, 0, NNI_MAXSZ, t)); } static int -nni_ipc_ep_get_addr(void *arg, void *data, size_t *szp, int typ) +ipc_ep_get_recvmaxsz(void *arg, void *data, size_t *szp, nni_opt_type t) { - nni_ipc_ep *ep = arg; - return (nni_copyout_sockaddr(&ep->sa, data, szp, typ)); + ipc_ep *ep = arg; + return (nni_copyout_size(ep->rcvmax, data, szp, t)); } static int -nni_ipc_ep_setopt_permissions(void *arg, const void *data, size_t sz, int typ) +ipc_ep_get_addr(void *arg, void *data, size_t *szp, nni_opt_type t) { - nni_ipc_ep *ep = arg; - int val; - int rv; + ipc_ep *ep = arg; + return (nni_copyout_sockaddr(&ep->sa, data, szp, t)); +} + +static int +ipc_ep_set_perms(void *arg, const void *data, size_t sz, nni_opt_type t) +{ + ipc_ep *ep = arg; + int val; + int rv; // Probably we could further limit this -- most systems don't have // meaningful chmod beyond the lower 9 bits. - rv = nni_copyin_int(&val, data, sz, 0, 0x7FFFFFFF, typ); - if ((rv == 0) && (ep != NULL)) { + if ((rv = nni_copyin_int(&val, data, sz, 0, 0x7FFFFFFF, t)) == 0) { nni_mtx_lock(&ep->mtx); rv = nni_plat_ipc_ep_set_permissions(ep->iep, val); nni_mtx_unlock(&ep->mtx); @@ -839,123 +843,132 @@ nni_ipc_ep_setopt_permissions(void *arg, const void *data, size_t sz, int typ) } static int -nni_ipc_ep_setopt_security_desc( - void *arg, const void *data, size_t sz, int typ) +ipc_ep_chk_perms(const void *data, size_t sz, nni_opt_type t) { - nni_ipc_ep *ep = arg; - void * ptr; - int rv; + return (nni_copyin_int(NULL, data, sz, 0, 0x7FFFFFFF, t)); +} - if ((rv = nni_copyin_ptr((void **) &ptr, data, sz, typ)) != 0) { - return (rv); - } +static int +ipc_ep_set_sec_desc(void *arg, const void *data, size_t sz, nni_opt_type t) +{ + ipc_ep *ep = arg; + void * ptr; + int rv; - if (ep == NULL) { - return (0); + if ((rv = nni_copyin_ptr(&ptr, data, sz, t)) == 0) { + rv = nni_plat_ipc_ep_set_security_descriptor(ep->iep, ptr); } - return (nni_plat_ipc_ep_set_security_descriptor(ep->iep, ptr)); + return (rv); +} + +static int +ipc_ep_chk_sec_desc(const void *data, size_t sz, nni_opt_type t) +{ + return (nni_copyin_ptr(NULL, data, sz, t)); } -static nni_tran_pipe_option nni_ipc_pipe_options[] = { +static nni_tran_option ipc_pipe_options[] = { { - .po_name = NNG_OPT_REMADDR, - .po_type = NNI_TYPE_SOCKADDR, - .po_getopt = nni_ipc_pipe_get_addr, + .o_name = NNG_OPT_REMADDR, + .o_type = NNI_TYPE_SOCKADDR, + .o_get = ipc_pipe_get_addr, }, { - .po_name = NNG_OPT_LOCADDR, - .po_type = NNI_TYPE_SOCKADDR, - .po_getopt = nni_ipc_pipe_get_addr, + .o_name = NNG_OPT_LOCADDR, + .o_type = NNI_TYPE_SOCKADDR, + .o_get = ipc_pipe_get_addr, }, { - .po_name = NNG_OPT_IPC_PEER_UID, - .po_type = NNI_TYPE_UINT64, - .po_getopt = nni_ipc_pipe_get_peer_uid, + .o_name = NNG_OPT_IPC_PEER_UID, + .o_type = NNI_TYPE_UINT64, + .o_get = ipc_pipe_get_peer_uid, }, { - .po_name = NNG_OPT_IPC_PEER_GID, - .po_type = NNI_TYPE_UINT64, - .po_getopt = nni_ipc_pipe_get_peer_gid, + .o_name = NNG_OPT_IPC_PEER_GID, + .o_type = NNI_TYPE_UINT64, + .o_get = ipc_pipe_get_peer_gid, }, { - .po_name = NNG_OPT_IPC_PEER_PID, - .po_type = NNI_TYPE_UINT64, - .po_getopt = nni_ipc_pipe_get_peer_pid, + .o_name = NNG_OPT_IPC_PEER_PID, + .o_type = NNI_TYPE_UINT64, + .o_get = ipc_pipe_get_peer_pid, }, { - .po_name = NNG_OPT_IPC_PEER_ZONEID, - .po_type = NNI_TYPE_UINT64, - .po_getopt = nni_ipc_pipe_get_peer_zoneid, + .o_name = NNG_OPT_IPC_PEER_ZONEID, + .o_type = NNI_TYPE_UINT64, + .o_get = ipc_pipe_get_peer_zoneid, }, // terminate list { - .po_name = NULL, + .o_name = NULL, }, }; -static nni_tran_pipe_ops nni_ipc_pipe_ops = { - .p_fini = nni_ipc_pipe_fini, - .p_start = nni_ipc_pipe_start, - .p_stop = nni_ipc_pipe_stop, - .p_send = nni_ipc_pipe_send, - .p_recv = nni_ipc_pipe_recv, - .p_close = nni_ipc_pipe_close, - .p_peer = nni_ipc_pipe_peer, - .p_options = nni_ipc_pipe_options, +static nni_tran_pipe_ops ipc_pipe_ops = { + .p_fini = ipc_pipe_fini, + .p_start = ipc_pipe_start, + .p_stop = ipc_pipe_stop, + .p_send = ipc_pipe_send, + .p_recv = ipc_pipe_recv, + .p_close = ipc_pipe_close, + .p_peer = ipc_pipe_peer, + .p_options = ipc_pipe_options, }; -static nni_tran_ep_option nni_ipc_ep_options[] = { +static nni_tran_option ipc_ep_options[] = { { - .eo_name = NNG_OPT_RECVMAXSZ, - .eo_type = NNI_TYPE_SIZE, - .eo_getopt = nni_ipc_ep_getopt_recvmaxsz, - .eo_setopt = nni_ipc_ep_setopt_recvmaxsz, + .o_name = NNG_OPT_RECVMAXSZ, + .o_type = NNI_TYPE_SIZE, + .o_get = ipc_ep_get_recvmaxsz, + .o_set = ipc_ep_set_recvmaxsz, + .o_chk = ipc_ep_chk_recvmaxsz, }, { - .eo_name = NNG_OPT_LOCADDR, - .eo_type = NNI_TYPE_SOCKADDR, - .eo_getopt = nni_ipc_ep_get_addr, - .eo_setopt = NULL, + .o_name = NNG_OPT_LOCADDR, + .o_type = NNI_TYPE_SOCKADDR, + .o_get = ipc_ep_get_addr, }, { - .eo_name = NNG_OPT_IPC_SECURITY_DESCRIPTOR, - .eo_type = NNI_TYPE_POINTER, - .eo_getopt = NULL, - .eo_setopt = nni_ipc_ep_setopt_security_desc, + .o_name = NNG_OPT_IPC_SECURITY_DESCRIPTOR, + .o_type = NNI_TYPE_POINTER, + .o_get = NULL, + .o_set = ipc_ep_set_sec_desc, + .o_chk = ipc_ep_chk_sec_desc, }, { - .eo_name = NNG_OPT_IPC_PERMISSIONS, - .eo_type = NNI_TYPE_INT32, - .eo_getopt = NULL, - .eo_setopt = nni_ipc_ep_setopt_permissions, + .o_name = NNG_OPT_IPC_PERMISSIONS, + .o_type = NNI_TYPE_INT32, + .o_get = NULL, + .o_set = ipc_ep_set_perms, + .o_chk = ipc_ep_chk_perms, }, // terminate list { - .eo_name = NULL, + .o_name = NULL, }, }; -static nni_tran_ep_ops nni_ipc_ep_ops = { - .ep_init = nni_ipc_ep_init, - .ep_fini = nni_ipc_ep_fini, - .ep_connect = nni_ipc_ep_connect, - .ep_bind = nni_ipc_ep_bind, - .ep_accept = nni_ipc_ep_accept, - .ep_close = nni_ipc_ep_close, - .ep_options = nni_ipc_ep_options, +static nni_tran_ep_ops ipc_ep_ops = { + .ep_init = ipc_ep_init, + .ep_fini = ipc_ep_fini, + .ep_connect = ipc_ep_connect, + .ep_bind = ipc_ep_bind, + .ep_accept = ipc_ep_accept, + .ep_close = ipc_ep_close, + .ep_options = ipc_ep_options, }; -static nni_tran nni_ipc_tran = { +static nni_tran ipc_tran = { .tran_version = NNI_TRANSPORT_VERSION, .tran_scheme = "ipc", - .tran_ep = &nni_ipc_ep_ops, - .tran_pipe = &nni_ipc_pipe_ops, - .tran_init = nni_ipc_tran_init, - .tran_fini = nni_ipc_tran_fini, + .tran_ep = &ipc_ep_ops, + .tran_pipe = &ipc_pipe_ops, + .tran_init = ipc_tran_init, + .tran_fini = ipc_tran_fini, }; int nng_ipc_register(void) { - return (nni_tran_register(&nni_ipc_tran)); + return (nni_tran_register(&ipc_tran)); } diff --git a/src/transport/tcp/tcp.c b/src/transport/tcp/tcp.c index be0dd2b5..f23d5b3a 100644 --- a/src/transport/tcp/tcp.c +++ b/src/transport/tcp/tcp.c @@ -17,11 +17,11 @@ // TCP transport. Platform specific TCP operations must be // supplied as well. -typedef struct nni_tcp_pipe nni_tcp_pipe; -typedef struct nni_tcp_ep nni_tcp_ep; +typedef struct tcp_pipe tcp_pipe; +typedef struct tcp_ep tcp_ep; -// nni_tcp_pipe is one end of a TCP connection. -struct nni_tcp_pipe { +// tcp_pipe is one end of a TCP connection. +struct tcp_pipe { nni_plat_tcp_pipe *tpp; uint16_t peer; uint16_t proto; @@ -46,7 +46,7 @@ struct nni_tcp_pipe { nni_mtx mtx; }; -struct nni_tcp_ep { +struct tcp_ep { nni_plat_tcp_ep *tep; uint16_t proto; size_t rcvmax; @@ -60,28 +60,28 @@ struct nni_tcp_ep { nni_mtx mtx; }; -static void nni_tcp_pipe_dosend(nni_tcp_pipe *, nni_aio *); -static void nni_tcp_pipe_dorecv(nni_tcp_pipe *); -static void nni_tcp_pipe_send_cb(void *); -static void nni_tcp_pipe_recv_cb(void *); -static void nni_tcp_pipe_nego_cb(void *); -static void nni_tcp_ep_cb(void *arg); +static void tcp_pipe_dosend(tcp_pipe *, nni_aio *); +static void tcp_pipe_dorecv(tcp_pipe *); +static void tcp_pipe_send_cb(void *); +static void tcp_pipe_recv_cb(void *); +static void tcp_pipe_nego_cb(void *); +static void tcp_ep_cb(void *arg); static int -nni_tcp_tran_init(void) +tcp_tran_init(void) { return (0); } static void -nni_tcp_tran_fini(void) +tcp_tran_fini(void) { } static void -nni_tcp_pipe_close(void *arg) +tcp_pipe_close(void *arg) { - nni_tcp_pipe *p = arg; + tcp_pipe *p = arg; nni_aio_close(p->rxaio); nni_aio_close(p->txaio); @@ -91,9 +91,9 @@ nni_tcp_pipe_close(void *arg) } static void -nni_tcp_pipe_stop(void *arg) +tcp_pipe_stop(void *arg) { - nni_tcp_pipe *p = arg; + tcp_pipe *p = arg; nni_aio_stop(p->rxaio); nni_aio_stop(p->txaio); @@ -101,9 +101,9 @@ nni_tcp_pipe_stop(void *arg) } static void -nni_tcp_pipe_fini(void *arg) +tcp_pipe_fini(void *arg) { - nni_tcp_pipe *p = arg; + tcp_pipe *p = arg; nni_aio_fini(p->rxaio); nni_aio_fini(p->txaio); @@ -119,19 +119,19 @@ nni_tcp_pipe_fini(void *arg) } static int -nni_tcp_pipe_init(nni_tcp_pipe **pipep, nni_tcp_ep *ep, void *tpp) +tcp_pipe_init(tcp_pipe **pipep, tcp_ep *ep, void *tpp) { - nni_tcp_pipe *p; - int rv; + tcp_pipe *p; + int rv; if ((p = NNI_ALLOC_STRUCT(p)) == NULL) { return (NNG_ENOMEM); } nni_mtx_init(&p->mtx); - if (((rv = nni_aio_init(&p->txaio, nni_tcp_pipe_send_cb, p)) != 0) || - ((rv = nni_aio_init(&p->rxaio, nni_tcp_pipe_recv_cb, p)) != 0) || - ((rv = nni_aio_init(&p->negaio, nni_tcp_pipe_nego_cb, p)) != 0)) { - nni_tcp_pipe_fini(p); + if (((rv = nni_aio_init(&p->txaio, tcp_pipe_send_cb, p)) != 0) || + ((rv = nni_aio_init(&p->rxaio, tcp_pipe_recv_cb, p)) != 0) || + ((rv = nni_aio_init(&p->negaio, tcp_pipe_nego_cb, p)) != 0)) { + tcp_pipe_fini(p); return (rv); } nni_aio_list_init(&p->recvq); @@ -154,9 +154,9 @@ nni_tcp_pipe_init(nni_tcp_pipe **pipep, nni_tcp_ep *ep, void *tpp) } static void -nni_tcp_cancel_nego(nni_aio *aio, int rv) +tcp_cancel_nego(nni_aio *aio, int rv) { - nni_tcp_pipe *p = nni_aio_get_prov_data(aio); + tcp_pipe *p = nni_aio_get_prov_data(aio); nni_mtx_lock(&p->mtx); if (p->user_negaio != aio) { @@ -171,11 +171,11 @@ nni_tcp_cancel_nego(nni_aio *aio, int rv) } static void -nni_tcp_pipe_nego_cb(void *arg) +tcp_pipe_nego_cb(void *arg) { - nni_tcp_pipe *p = arg; - nni_aio * aio = p->negaio; - int rv; + tcp_pipe *p = arg; + nni_aio * aio = p->negaio; + int rv; nni_mtx_lock(&p->mtx); if ((rv = nni_aio_result(aio)) != 0) { @@ -228,14 +228,14 @@ done: } static void -nni_tcp_pipe_send_cb(void *arg) +tcp_pipe_send_cb(void *arg) { - nni_tcp_pipe *p = arg; - int rv; - nni_aio * aio; - size_t n; - nni_msg * msg; - nni_aio * txaio = p->txaio; + tcp_pipe *p = arg; + int rv; + nni_aio * aio; + size_t n; + nni_msg * msg; + nni_aio * txaio = p->txaio; nni_mtx_lock(&p->mtx); aio = nni_list_first(&p->sendq); @@ -263,7 +263,7 @@ nni_tcp_pipe_send_cb(void *arg) nni_aio_list_remove(aio); if (!nni_list_empty(&p->sendq)) { // schedule next send - nni_tcp_pipe_dosend(p, nni_list_first(&p->sendq)); + tcp_pipe_dosend(p, nni_list_first(&p->sendq)); } nni_mtx_unlock(&p->mtx); @@ -275,14 +275,14 @@ nni_tcp_pipe_send_cb(void *arg) } static void -nni_tcp_pipe_recv_cb(void *arg) +tcp_pipe_recv_cb(void *arg) { - nni_tcp_pipe *p = arg; - nni_aio * aio; - int rv; - size_t n; - nni_msg * msg; - nni_aio * rxaio = p->rxaio; + tcp_pipe *p = arg; + nni_aio * aio; + int rv; + size_t n; + nni_msg * msg; + nni_aio * rxaio = p->rxaio; nni_mtx_lock(&p->mtx); aio = nni_list_first(&p->recvq); @@ -337,7 +337,7 @@ nni_tcp_pipe_recv_cb(void *arg) msg = p->rxmsg; p->rxmsg = NULL; if (!nni_list_empty(&p->recvq)) { - nni_tcp_pipe_dorecv(p); + tcp_pipe_dorecv(p); } nni_mtx_unlock(&p->mtx); @@ -358,9 +358,9 @@ recv_error: } static void -nni_tcp_cancel_tx(nni_aio *aio, int rv) +tcp_cancel_tx(nni_aio *aio, int rv) { - nni_tcp_pipe *p = nni_aio_get_prov_data(aio); + tcp_pipe *p = nni_aio_get_prov_data(aio); nni_mtx_lock(&p->mtx); if (!nni_aio_list_active(aio)) { @@ -382,7 +382,7 @@ nni_tcp_cancel_tx(nni_aio *aio, int rv) } static void -nni_tcp_pipe_dosend(nni_tcp_pipe *p, nni_aio *aio) +tcp_pipe_dosend(tcp_pipe *p, nni_aio *aio) { nni_aio *txaio; nni_msg *msg; @@ -416,31 +416,31 @@ nni_tcp_pipe_dosend(nni_tcp_pipe *p, nni_aio *aio) } static void -nni_tcp_pipe_send(void *arg, nni_aio *aio) +tcp_pipe_send(void *arg, nni_aio *aio) { - nni_tcp_pipe *p = arg; - int rv; + tcp_pipe *p = arg; + int rv; if (nni_aio_begin(aio) != 0) { return; } nni_mtx_lock(&p->mtx); - if ((rv = nni_aio_schedule(aio, nni_tcp_cancel_tx, p)) != 0) { + if ((rv = nni_aio_schedule(aio, tcp_cancel_tx, p)) != 0) { nni_mtx_unlock(&p->mtx); nni_aio_finish_error(aio, rv); return; } nni_list_append(&p->sendq, aio); if (nni_list_first(&p->sendq) == aio) { - nni_tcp_pipe_dosend(p, aio); + tcp_pipe_dosend(p, aio); } nni_mtx_unlock(&p->mtx); } static void -nni_tcp_cancel_rx(nni_aio *aio, int rv) +tcp_cancel_rx(nni_aio *aio, int rv) { - nni_tcp_pipe *p = nni_aio_get_prov_data(aio); + tcp_pipe *p = nni_aio_get_prov_data(aio); nni_mtx_lock(&p->mtx); if (!nni_aio_list_active(aio)) { @@ -461,7 +461,7 @@ nni_tcp_cancel_rx(nni_aio *aio, int rv) } static void -nni_tcp_pipe_dorecv(nni_tcp_pipe *p) +tcp_pipe_dorecv(tcp_pipe *p) { nni_aio *rxaio; nni_iov iov; @@ -477,16 +477,16 @@ nni_tcp_pipe_dorecv(nni_tcp_pipe *p) } static void -nni_tcp_pipe_recv(void *arg, nni_aio *aio) +tcp_pipe_recv(void *arg, nni_aio *aio) { - nni_tcp_pipe *p = arg; - int rv; + tcp_pipe *p = arg; + int rv; if (nni_aio_begin(aio) != 0) { return; } nni_mtx_lock(&p->mtx); - if ((rv = nni_aio_schedule(aio, nni_tcp_cancel_rx, p)) != 0) { + if ((rv = nni_aio_schedule(aio, tcp_cancel_rx, p)) != 0) { nni_mtx_unlock(&p->mtx); nni_aio_finish_error(aio, rv); return; @@ -494,75 +494,75 @@ nni_tcp_pipe_recv(void *arg, nni_aio *aio) nni_list_append(&p->recvq, aio); if (nni_list_first(&p->recvq) == aio) { - nni_tcp_pipe_dorecv(p); + tcp_pipe_dorecv(p); } nni_mtx_unlock(&p->mtx); } static uint16_t -nni_tcp_pipe_peer(void *arg) +tcp_pipe_peer(void *arg) { - nni_tcp_pipe *p = arg; + tcp_pipe *p = arg; return (p->peer); } static int -nni_tcp_pipe_getopt_locaddr(void *arg, void *v, size_t *szp, int typ) +tcp_pipe_get_locaddr(void *arg, void *v, size_t *szp, nni_opt_type t) { - nni_tcp_pipe *p = arg; - int rv; - nni_sockaddr sa; + tcp_pipe * p = arg; + int rv; + nni_sockaddr sa; memset(&sa, 0, sizeof(sa)); if ((rv = nni_plat_tcp_pipe_sockname(p->tpp, &sa)) == 0) { - rv = nni_copyout_sockaddr(&sa, v, szp, typ); + rv = nni_copyout_sockaddr(&sa, v, szp, t); } return (rv); } static int -nni_tcp_pipe_getopt_remaddr(void *arg, void *v, size_t *szp, int typ) +tcp_pipe_get_remaddr(void *arg, void *v, size_t *szp, nni_opt_type t) { - nni_tcp_pipe *p = arg; - int rv; - nni_sockaddr sa; + tcp_pipe * p = arg; + int rv; + nni_sockaddr sa; memset(&sa, 0, sizeof(sa)); if ((rv = nni_plat_tcp_pipe_peername(p->tpp, &sa)) == 0) { - rv = nni_copyout_sockaddr(&sa, v, szp, typ); + rv = nni_copyout_sockaddr(&sa, v, szp, t); } return (rv); } static int -nni_tcp_pipe_getopt_keepalive(void *arg, void *v, size_t *szp, int typ) +tcp_pipe_get_keepalive(void *arg, void *v, size_t *szp, nni_opt_type t) { - nni_tcp_pipe *p = arg; - return (nni_copyout_bool(p->keepalive, v, szp, typ)); + tcp_pipe *p = arg; + return (nni_copyout_bool(p->keepalive, v, szp, t)); } static int -nni_tcp_pipe_getopt_nodelay(void *arg, void *v, size_t *szp, int typ) +tcp_pipe_get_nodelay(void *arg, void *v, size_t *szp, nni_opt_type t) { - nni_tcp_pipe *p = arg; - return (nni_copyout_bool(p->nodelay, v, szp, typ)); + tcp_pipe *p = arg; + return (nni_copyout_bool(p->nodelay, v, szp, t)); } // Note that the url *must* be in a modifiable buffer. static void -nni_tcp_pipe_start(void *arg, nni_aio *aio) +tcp_pipe_start(void *arg, nni_aio *aio) { - nni_tcp_pipe *p = arg; - nni_aio * negaio; - nni_iov iov; - int rv; + tcp_pipe *p = arg; + nni_aio * negaio; + nni_iov iov; + int rv; if (nni_aio_begin(aio) != 0) { return; } nni_mtx_lock(&p->mtx); - if ((rv = nni_aio_schedule(aio, nni_tcp_cancel_nego, p)) != 0) { + if ((rv = nni_aio_schedule(aio, tcp_cancel_nego, p)) != 0) { nni_mtx_unlock(&p->mtx); nni_aio_finish_error(aio, rv); return; @@ -588,9 +588,9 @@ nni_tcp_pipe_start(void *arg, nni_aio *aio) } static void -nni_tcp_ep_fini(void *arg) +tcp_ep_fini(void *arg) { - nni_tcp_ep *ep = arg; + tcp_ep *ep = arg; nni_aio_stop(ep->aio); if (ep->tep != NULL) { @@ -602,9 +602,9 @@ nni_tcp_ep_fini(void *arg) } static int -nni_tcp_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) +tcp_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) { - nni_tcp_ep * ep; + tcp_ep * ep; int rv; char * host; char * serv; @@ -679,12 +679,12 @@ nni_tcp_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) ep->url = url; if ((rv = nni_plat_tcp_ep_init(&ep->tep, &lsa, &rsa, mode)) != 0) { - nni_tcp_ep_fini(ep); + tcp_ep_fini(ep); return (rv); } - if ((rv = nni_aio_init(&ep->aio, nni_tcp_ep_cb, ep)) != 0) { - nni_tcp_ep_fini(ep); + if ((rv = nni_aio_init(&ep->aio, tcp_ep_cb, ep)) != 0) { + tcp_ep_fini(ep); return (rv); } ep->proto = nni_sock_proto_id(sock); @@ -697,9 +697,9 @@ nni_tcp_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) } static void -nni_tcp_ep_close(void *arg) +tcp_ep_close(void *arg) { - nni_tcp_ep *ep = arg; + tcp_ep *ep = arg; nni_aio_close(ep->aio); @@ -709,10 +709,10 @@ nni_tcp_ep_close(void *arg) } static int -nni_tcp_ep_bind(void *arg) +tcp_ep_bind(void *arg) { - nni_tcp_ep *ep = arg; - int rv; + tcp_ep *ep = arg; + int rv; nni_mtx_lock(&ep->mtx); rv = nni_plat_tcp_ep_listen(ep->tep, &ep->bsa); @@ -722,11 +722,11 @@ nni_tcp_ep_bind(void *arg) } static void -nni_tcp_ep_finish(nni_tcp_ep *ep) +tcp_ep_finish(tcp_ep *ep) { - nni_aio * aio; - int rv; - nni_tcp_pipe *pipe = NULL; + nni_aio * aio; + int rv; + tcp_pipe *pipe = NULL; if ((rv = nni_aio_result(ep->aio)) != 0) { goto done; @@ -735,7 +735,7 @@ nni_tcp_ep_finish(nni_tcp_ep *ep) // Attempt to allocate the parent pipe. If this fails we'll // drop the connection (ENOMEM probably). - rv = nni_tcp_pipe_init(&pipe, ep, nni_aio_get_output(ep->aio, 0)); + rv = tcp_pipe_init(&pipe, ep, nni_aio_get_output(ep->aio, 0)); done: aio = ep->user_aio; @@ -747,7 +747,7 @@ done: return; } if (pipe != NULL) { - nni_tcp_pipe_fini(pipe); + tcp_pipe_fini(pipe); } if (aio != NULL) { NNI_ASSERT(rv != 0); @@ -756,19 +756,19 @@ done: } static void -nni_tcp_ep_cb(void *arg) +tcp_ep_cb(void *arg) { - nni_tcp_ep *ep = arg; + tcp_ep *ep = arg; nni_mtx_lock(&ep->mtx); - nni_tcp_ep_finish(ep); + tcp_ep_finish(ep); nni_mtx_unlock(&ep->mtx); } static void -nni_tcp_cancel_ep(nni_aio *aio, int rv) +tcp_cancel_ep(nni_aio *aio, int rv) { - nni_tcp_ep *ep = nni_aio_get_prov_data(aio); + tcp_ep *ep = nni_aio_get_prov_data(aio); nni_mtx_lock(&ep->mtx); if (ep->user_aio != aio) { @@ -783,10 +783,10 @@ nni_tcp_cancel_ep(nni_aio *aio, int rv) } static void -nni_tcp_ep_accept(void *arg, nni_aio *aio) +tcp_ep_accept(void *arg, nni_aio *aio) { - nni_tcp_ep *ep = arg; - int rv; + tcp_ep *ep = arg; + int rv; if (nni_aio_begin(aio) != 0) { return; @@ -794,7 +794,7 @@ nni_tcp_ep_accept(void *arg, nni_aio *aio) nni_mtx_lock(&ep->mtx); NNI_ASSERT(ep->user_aio == NULL); - if ((rv = nni_aio_schedule(aio, nni_tcp_cancel_ep, ep)) != 0) { + if ((rv = nni_aio_schedule(aio, tcp_cancel_ep, ep)) != 0) { nni_mtx_unlock(&ep->mtx); nni_aio_finish_error(aio, rv); return; @@ -806,10 +806,10 @@ nni_tcp_ep_accept(void *arg, nni_aio *aio) } static void -nni_tcp_ep_connect(void *arg, nni_aio *aio) +tcp_ep_connect(void *arg, nni_aio *aio) { - nni_tcp_ep *ep = arg; - int rv; + tcp_ep *ep = arg; + int rv; if (nni_aio_begin(aio) != 0) { return; @@ -817,7 +817,7 @@ nni_tcp_ep_connect(void *arg, nni_aio *aio) nni_mtx_lock(&ep->mtx); NNI_ASSERT(ep->user_aio == NULL); - if ((rv = nni_aio_schedule(aio, nni_tcp_cancel_ep, ep)) != 0) { + if ((rv = nni_aio_schedule(aio, tcp_cancel_ep, ep)) != 0) { nni_mtx_unlock(&ep->mtx); nni_aio_finish_error(aio, rv); return; @@ -829,13 +829,12 @@ nni_tcp_ep_connect(void *arg, nni_aio *aio) } static int -nni_tcp_ep_setopt_recvmaxsz(void *arg, const void *v, size_t sz, int typ) +tcp_ep_set_recvmaxsz(void *arg, const void *v, size_t sz, nni_opt_type t) { - nni_tcp_ep *ep = arg; - size_t val; - int rv; - rv = nni_copyin_size(&val, v, sz, 0, NNI_MAXSZ, typ); - if ((rv == 0) && (ep != NULL)) { + tcp_ep *ep = arg; + size_t val; + int rv; + if ((rv = nni_copyin_size(&val, v, sz, 0, NNI_MAXSZ, t)) == 0) { nni_mtx_lock(&ep->mtx); ep->rcvmax = val; nni_mtx_unlock(&ep->mtx); @@ -844,13 +843,18 @@ nni_tcp_ep_setopt_recvmaxsz(void *arg, const void *v, size_t sz, int typ) } static int -nni_tcp_ep_setopt_nodelay(void *arg, const void *v, size_t sz, int typ) +tcp_ep_chk_recvmaxsz(const void *v, size_t sz, nni_opt_type t) +{ + return (nni_copyin_size(NULL, v, sz, 0, NNI_MAXSZ, t)); +} + +static int +tcp_ep_set_nodelay(void *arg, const void *v, size_t sz, nni_opt_type t) { - nni_tcp_ep *ep = arg; - bool val; - int rv; - rv = nni_copyin_bool(&val, v, sz, typ); - if ((rv == 0) && (ep != NULL)) { + tcp_ep *ep = arg; + bool val; + int rv; + if ((rv = nni_copyin_bool(&val, v, sz, t)) == 0) { nni_mtx_lock(&ep->mtx); ep->nodelay = val; nni_mtx_unlock(&ep->mtx); @@ -859,20 +863,25 @@ nni_tcp_ep_setopt_nodelay(void *arg, const void *v, size_t sz, int typ) } static int -nni_tcp_ep_getopt_nodelay(void *arg, void *v, size_t *szp, int typ) +tcp_ep_chk_bool(const void *v, size_t sz, nni_opt_type t) +{ + return (nni_copyin_bool(NULL, v, sz, t)); +} + +static int +tcp_ep_get_nodelay(void *arg, void *v, size_t *szp, nni_opt_type t) { - nni_tcp_ep *ep = arg; - return (nni_copyout_bool(ep->nodelay, v, szp, typ)); + tcp_ep *ep = arg; + return (nni_copyout_bool(ep->nodelay, v, szp, t)); } static int -nni_tcp_ep_setopt_keepalive(void *arg, const void *v, size_t sz, int typ) +tcp_ep_set_keepalive(void *arg, const void *v, size_t sz, nni_opt_type t) { - nni_tcp_ep *ep = arg; - bool val; - int rv; - rv = nni_copyin_bool(&val, v, sz, typ); - if ((rv == 0) && (ep != NULL)) { + tcp_ep *ep = arg; + bool val; + int rv; + if ((rv = nni_copyin_bool(&val, v, sz, t)) == 0) { nni_mtx_lock(&ep->mtx); ep->keepalive = val; nni_mtx_unlock(&ep->mtx); @@ -881,148 +890,150 @@ nni_tcp_ep_setopt_keepalive(void *arg, const void *v, size_t sz, int typ) } static int -nni_tcp_ep_getopt_keepalive(void *arg, void *v, size_t *szp, int typ) +tcp_ep_get_keepalive(void *arg, void *v, size_t *szp, nni_opt_type t) { - nni_tcp_ep *ep = arg; - return (nni_copyout_bool(ep->keepalive, v, szp, typ)); + tcp_ep *ep = arg; + return (nni_copyout_bool(ep->keepalive, v, szp, t)); } static int -nni_tcp_ep_getopt_url(void *arg, void *v, size_t *szp, int typ) +tcp_ep_get_url(void *arg, void *v, size_t *szp, nni_opt_type t) { - nni_tcp_ep *ep = arg; - char ustr[128]; - char ipstr[48]; // max for IPv6 addresses including [] - char portstr[6]; // max for 16-bit port + tcp_ep *ep = arg; + char ustr[128]; + char ipstr[48]; // max for IPv6 addresses including [] + char portstr[6]; // max for 16-bit port if (ep->mode == NNI_EP_MODE_DIAL) { - return (nni_copyout_str(ep->url->u_rawurl, v, szp, typ)); + return (nni_copyout_str(ep->url->u_rawurl, v, szp, t)); } nni_plat_tcp_ntop(&ep->bsa, ipstr, portstr); snprintf(ustr, sizeof(ustr), "tcp://%s:%s", ipstr, portstr); - return (nni_copyout_str(ustr, v, szp, typ)); + return (nni_copyout_str(ustr, v, szp, t)); } static int -nni_tcp_ep_getopt_recvmaxsz(void *arg, void *v, size_t *szp, int typ) +tcp_ep_get_recvmaxsz(void *arg, void *v, size_t *szp, nni_opt_type t) { - nni_tcp_ep *ep = arg; - return (nni_copyout_size(ep->rcvmax, v, szp, typ)); + tcp_ep *ep = arg; + return (nni_copyout_size(ep->rcvmax, v, szp, t)); } -static nni_tran_pipe_option nni_tcp_pipe_options[] = { +static nni_tran_option tcp_pipe_options[] = { { - .po_name = NNG_OPT_LOCADDR, - .po_type = NNI_TYPE_SOCKADDR, - .po_getopt = nni_tcp_pipe_getopt_locaddr, + .o_name = NNG_OPT_LOCADDR, + .o_type = NNI_TYPE_SOCKADDR, + .o_get = tcp_pipe_get_locaddr, }, { - .po_name = NNG_OPT_REMADDR, - .po_type = NNI_TYPE_SOCKADDR, - .po_getopt = nni_tcp_pipe_getopt_remaddr, + .o_name = NNG_OPT_REMADDR, + .o_type = NNI_TYPE_SOCKADDR, + .o_get = tcp_pipe_get_remaddr, }, { - .po_name = NNG_OPT_TCP_KEEPALIVE, - .po_type = NNI_TYPE_BOOL, - .po_getopt = nni_tcp_pipe_getopt_keepalive, + .o_name = NNG_OPT_TCP_KEEPALIVE, + .o_type = NNI_TYPE_BOOL, + .o_get = tcp_pipe_get_keepalive, }, { - .po_name = NNG_OPT_TCP_NODELAY, - .po_type = NNI_TYPE_BOOL, - .po_getopt = nni_tcp_pipe_getopt_nodelay, + .o_name = NNG_OPT_TCP_NODELAY, + .o_type = NNI_TYPE_BOOL, + .o_get = tcp_pipe_get_nodelay, }, // terminate list { - .po_name = NULL, + .o_name = NULL, }, }; -static nni_tran_pipe_ops nni_tcp_pipe_ops = { - .p_fini = nni_tcp_pipe_fini, - .p_start = nni_tcp_pipe_start, - .p_stop = nni_tcp_pipe_stop, - .p_send = nni_tcp_pipe_send, - .p_recv = nni_tcp_pipe_recv, - .p_close = nni_tcp_pipe_close, - .p_peer = nni_tcp_pipe_peer, - .p_options = nni_tcp_pipe_options, +static nni_tran_pipe_ops tcp_pipe_ops = { + .p_fini = tcp_pipe_fini, + .p_start = tcp_pipe_start, + .p_stop = tcp_pipe_stop, + .p_send = tcp_pipe_send, + .p_recv = tcp_pipe_recv, + .p_close = tcp_pipe_close, + .p_peer = tcp_pipe_peer, + .p_options = tcp_pipe_options, }; -static nni_tran_ep_option nni_tcp_ep_options[] = { +static nni_tran_option tcp_ep_options[] = { { - .eo_name = NNG_OPT_RECVMAXSZ, - .eo_type = NNI_TYPE_SIZE, - .eo_getopt = nni_tcp_ep_getopt_recvmaxsz, - .eo_setopt = nni_tcp_ep_setopt_recvmaxsz, + .o_name = NNG_OPT_RECVMAXSZ, + .o_type = NNI_TYPE_SIZE, + .o_get = tcp_ep_get_recvmaxsz, + .o_set = tcp_ep_set_recvmaxsz, + .o_chk = tcp_ep_chk_recvmaxsz, }, { - .eo_name = NNG_OPT_URL, - .eo_type = NNI_TYPE_STRING, - .eo_getopt = nni_tcp_ep_getopt_url, - .eo_setopt = NULL, + .o_name = NNG_OPT_URL, + .o_type = NNI_TYPE_STRING, + .o_get = tcp_ep_get_url, }, { - .eo_name = NNG_OPT_TCP_NODELAY, - .eo_type = NNI_TYPE_BOOL, - .eo_getopt = nni_tcp_ep_getopt_nodelay, - .eo_setopt = nni_tcp_ep_setopt_nodelay, + .o_name = NNG_OPT_TCP_NODELAY, + .o_type = NNI_TYPE_BOOL, + .o_get = tcp_ep_get_nodelay, + .o_set = tcp_ep_set_nodelay, + .o_chk = tcp_ep_chk_bool, }, { - .eo_name = NNG_OPT_TCP_KEEPALIVE, - .eo_type = NNI_TYPE_BOOL, - .eo_getopt = nni_tcp_ep_getopt_keepalive, - .eo_setopt = nni_tcp_ep_setopt_keepalive, + .o_name = NNG_OPT_TCP_KEEPALIVE, + .o_type = NNI_TYPE_BOOL, + .o_get = tcp_ep_get_keepalive, + .o_set = tcp_ep_set_keepalive, + .o_chk = tcp_ep_chk_bool, }, // terminate list { - .eo_name = NULL, + .o_name = NULL, }, }; -static nni_tran_ep_ops nni_tcp_ep_ops = { - .ep_init = nni_tcp_ep_init, - .ep_fini = nni_tcp_ep_fini, - .ep_connect = nni_tcp_ep_connect, - .ep_bind = nni_tcp_ep_bind, - .ep_accept = nni_tcp_ep_accept, - .ep_close = nni_tcp_ep_close, - .ep_options = nni_tcp_ep_options, +static nni_tran_ep_ops tcp_ep_ops = { + .ep_init = tcp_ep_init, + .ep_fini = tcp_ep_fini, + .ep_connect = tcp_ep_connect, + .ep_bind = tcp_ep_bind, + .ep_accept = tcp_ep_accept, + .ep_close = tcp_ep_close, + .ep_options = tcp_ep_options, }; -static nni_tran nni_tcp_tran = { +static nni_tran tcp_tran = { .tran_version = NNI_TRANSPORT_VERSION, .tran_scheme = "tcp", - .tran_ep = &nni_tcp_ep_ops, - .tran_pipe = &nni_tcp_pipe_ops, - .tran_init = nni_tcp_tran_init, - .tran_fini = nni_tcp_tran_fini, + .tran_ep = &tcp_ep_ops, + .tran_pipe = &tcp_pipe_ops, + .tran_init = tcp_tran_init, + .tran_fini = tcp_tran_fini, }; -static nni_tran nni_tcp4_tran = { +static nni_tran tcp4_tran = { .tran_version = NNI_TRANSPORT_VERSION, .tran_scheme = "tcp4", - .tran_ep = &nni_tcp_ep_ops, - .tran_pipe = &nni_tcp_pipe_ops, - .tran_init = nni_tcp_tran_init, - .tran_fini = nni_tcp_tran_fini, + .tran_ep = &tcp_ep_ops, + .tran_pipe = &tcp_pipe_ops, + .tran_init = tcp_tran_init, + .tran_fini = tcp_tran_fini, }; -static nni_tran nni_tcp6_tran = { +static nni_tran tcp6_tran = { .tran_version = NNI_TRANSPORT_VERSION, .tran_scheme = "tcp6", - .tran_ep = &nni_tcp_ep_ops, - .tran_pipe = &nni_tcp_pipe_ops, - .tran_init = nni_tcp_tran_init, - .tran_fini = nni_tcp_tran_fini, + .tran_ep = &tcp_ep_ops, + .tran_pipe = &tcp_pipe_ops, + .tran_init = tcp_tran_init, + .tran_fini = tcp_tran_fini, }; int nng_tcp_register(void) { int rv; - if (((rv = nni_tran_register(&nni_tcp_tran)) != 0) || - ((rv = nni_tran_register(&nni_tcp4_tran)) != 0) || - ((rv = nni_tran_register(&nni_tcp6_tran)) != 0)) { + if (((rv = nni_tran_register(&tcp_tran)) != 0) || + ((rv = nni_tran_register(&tcp4_tran)) != 0) || + ((rv = nni_tran_register(&tcp6_tran)) != 0)) { return (rv); } return (0); diff --git a/src/transport/tls/tls.c b/src/transport/tls/tls.c index d1d21f6d..35f88e25 100644 --- a/src/transport/tls/tls.c +++ b/src/transport/tls/tls.c @@ -22,11 +22,11 @@ // supplied as well, and uses the supplemental TLS v1.2 code. It is not // an accident that this very closely resembles the TCP transport itself. -typedef struct nni_tls_pipe nni_tls_pipe; -typedef struct nni_tls_ep nni_tls_ep; +typedef struct tls_pipe tls_pipe; +typedef struct tls_ep tls_ep; -// nni_tls_pipe is one end of a TLS connection. -struct nni_tls_pipe { +// tls_pipe is one end of a TLS connection. +struct tls_pipe { nni_plat_tcp_pipe *tcp; uint16_t peer; uint16_t proto; @@ -52,7 +52,7 @@ struct nni_tls_pipe { nni_tls *tls; }; -struct nni_tls_ep { +struct tls_ep { nni_plat_tcp_ep *tep; uint16_t proto; size_t rcvmax; @@ -68,28 +68,28 @@ struct nni_tls_ep { bool keepalive; }; -static void nni_tls_pipe_dorecv(nni_tls_pipe *); -static void nni_tls_pipe_dosend(nni_tls_pipe *, nni_aio *); -static void nni_tls_pipe_send_cb(void *); -static void nni_tls_pipe_recv_cb(void *); -static void nni_tls_pipe_nego_cb(void *); -static void nni_tls_ep_cb(void *arg); +static void tls_pipe_dorecv(tls_pipe *); +static void tls_pipe_dosend(tls_pipe *, nni_aio *); +static void tls_pipe_send_cb(void *); +static void tls_pipe_recv_cb(void *); +static void tls_pipe_nego_cb(void *); +static void tls_ep_cb(void *arg); static int -nni_tls_tran_init(void) +tls_tran_init(void) { return (0); } static void -nni_tls_tran_fini(void) +tls_tran_fini(void) { } static void -nni_tls_pipe_close(void *arg) +tls_pipe_close(void *arg) { - nni_tls_pipe *p = arg; + tls_pipe *p = arg; nni_aio_close(p->rxaio); nni_aio_close(p->txaio); @@ -99,9 +99,9 @@ nni_tls_pipe_close(void *arg) } static void -nni_tls_pipe_stop(void *arg) +tls_pipe_stop(void *arg) { - nni_tls_pipe *p = arg; + tls_pipe *p = arg; nni_aio_stop(p->rxaio); nni_aio_stop(p->txaio); @@ -109,9 +109,9 @@ nni_tls_pipe_stop(void *arg) } static void -nni_tls_pipe_fini(void *arg) +tls_pipe_fini(void *arg) { - nni_tls_pipe *p = arg; + tls_pipe *p = arg; nni_aio_fini(p->rxaio); nni_aio_fini(p->txaio); @@ -125,9 +125,9 @@ nni_tls_pipe_fini(void *arg) } static int -nni_tls_pipe_init(nni_tls_pipe **pipep, nni_tls_ep *ep, void *tpp) +tls_pipe_init(tls_pipe **pipep, tls_ep *ep, void *tpp) { - nni_tls_pipe * p; + tls_pipe * p; nni_plat_tcp_pipe *tcp = tpp; int rv; @@ -137,10 +137,10 @@ nni_tls_pipe_init(nni_tls_pipe **pipep, nni_tls_ep *ep, void *tpp) nni_mtx_init(&p->mtx); if (((rv = nni_tls_init(&p->tls, ep->cfg, tcp)) != 0) || - ((rv = nni_aio_init(&p->txaio, nni_tls_pipe_send_cb, p)) != 0) || - ((rv = nni_aio_init(&p->rxaio, nni_tls_pipe_recv_cb, p)) != 0) || - ((rv = nni_aio_init(&p->negaio, nni_tls_pipe_nego_cb, p)) != 0)) { - nni_tls_pipe_fini(p); + ((rv = nni_aio_init(&p->txaio, tls_pipe_send_cb, p)) != 0) || + ((rv = nni_aio_init(&p->rxaio, tls_pipe_recv_cb, p)) != 0) || + ((rv = nni_aio_init(&p->negaio, tls_pipe_nego_cb, p)) != 0)) { + tls_pipe_fini(p); return (rv); } nni_aio_list_init(&p->recvq); @@ -157,9 +157,9 @@ nni_tls_pipe_init(nni_tls_pipe **pipep, nni_tls_ep *ep, void *tpp) } static void -nni_tls_cancel_nego(nni_aio *aio, int rv) +tls_cancel_nego(nni_aio *aio, int rv) { - nni_tls_pipe *p = nni_aio_get_prov_data(aio); + tls_pipe *p = nni_aio_get_prov_data(aio); nni_mtx_lock(&p->mtx); if (p->user_negaio != aio) { @@ -174,11 +174,11 @@ nni_tls_cancel_nego(nni_aio *aio, int rv) } static void -nni_tls_pipe_nego_cb(void *arg) +tls_pipe_nego_cb(void *arg) { - nni_tls_pipe *p = arg; - nni_aio * aio = p->negaio; - int rv; + tls_pipe *p = arg; + nni_aio * aio = p->negaio; + int rv; nni_mtx_lock(&p->mtx); if ((rv = nni_aio_result(aio)) != 0) { @@ -237,14 +237,14 @@ done: } static void -nni_tls_pipe_send_cb(void *arg) +tls_pipe_send_cb(void *arg) { - nni_tls_pipe *p = arg; - int rv; - nni_aio * aio; - size_t n; - nni_msg * msg; - nni_aio * txaio = p->txaio; + tls_pipe *p = arg; + int rv; + nni_aio * aio; + size_t n; + nni_msg * msg; + nni_aio * txaio = p->txaio; nni_mtx_lock(&p->mtx); aio = nni_list_first(&p->sendq); @@ -270,7 +270,7 @@ nni_tls_pipe_send_cb(void *arg) } nni_aio_list_remove(aio); if (!nni_list_empty(&p->sendq)) { - nni_tls_pipe_dosend(p, nni_list_first(&p->sendq)); + tls_pipe_dosend(p, nni_list_first(&p->sendq)); } nni_mtx_unlock(&p->mtx); @@ -282,14 +282,14 @@ nni_tls_pipe_send_cb(void *arg) } static void -nni_tls_pipe_recv_cb(void *arg) +tls_pipe_recv_cb(void *arg) { - nni_tls_pipe *p = arg; - nni_aio * aio; - int rv; - size_t n; - nni_msg * msg; - nni_aio * rxaio = p->rxaio; + tls_pipe *p = arg; + nni_aio * aio; + int rv; + size_t n; + nni_msg * msg; + nni_aio * rxaio = p->rxaio; nni_mtx_lock(&p->mtx); aio = nni_list_first(&p->recvq); @@ -345,7 +345,7 @@ nni_tls_pipe_recv_cb(void *arg) msg = p->rxmsg; p->rxmsg = NULL; if (!nni_list_empty(&p->recvq)) { - nni_tls_pipe_dorecv(p); + tls_pipe_dorecv(p); } nni_mtx_unlock(&p->mtx); @@ -365,9 +365,9 @@ recv_error: } static void -nni_tls_cancel_tx(nni_aio *aio, int rv) +tls_cancel_tx(nni_aio *aio, int rv) { - nni_tls_pipe *p = nni_aio_get_prov_data(aio); + tls_pipe *p = nni_aio_get_prov_data(aio); nni_mtx_lock(&p->mtx); if (!nni_aio_list_active(aio)) { @@ -389,7 +389,7 @@ nni_tls_cancel_tx(nni_aio *aio, int rv) } static void -nni_tls_pipe_dosend(nni_tls_pipe *p, nni_aio *aio) +tls_pipe_dosend(tls_pipe *p, nni_aio *aio) { nni_aio *txaio; nni_msg *msg; @@ -423,31 +423,31 @@ nni_tls_pipe_dosend(nni_tls_pipe *p, nni_aio *aio) } static void -nni_tls_pipe_send(void *arg, nni_aio *aio) +tls_pipe_send(void *arg, nni_aio *aio) { - nni_tls_pipe *p = arg; - int rv; + tls_pipe *p = arg; + int rv; if (nni_aio_begin(aio) != 0) { return; } nni_mtx_lock(&p->mtx); - if ((rv = nni_aio_schedule(aio, nni_tls_cancel_tx, p)) != 0) { + if ((rv = nni_aio_schedule(aio, tls_cancel_tx, p)) != 0) { nni_mtx_unlock(&p->mtx); nni_aio_finish_error(aio, rv); return; } nni_list_append(&p->sendq, aio); if (nni_list_first(&p->sendq) == aio) { - nni_tls_pipe_dosend(p, aio); + tls_pipe_dosend(p, aio); } nni_mtx_unlock(&p->mtx); } static void -nni_tls_cancel_rx(nni_aio *aio, int rv) +tls_cancel_rx(nni_aio *aio, int rv) { - nni_tls_pipe *p = nni_aio_get_prov_data(aio); + tls_pipe *p = nni_aio_get_prov_data(aio); nni_mtx_lock(&p->mtx); if (!nni_aio_list_active(aio)) { @@ -468,7 +468,7 @@ nni_tls_cancel_rx(nni_aio *aio, int rv) } static void -nni_tls_pipe_dorecv(nni_tls_pipe *p) +tls_pipe_dorecv(tls_pipe *p) { nni_aio *rxaio; nni_iov iov; @@ -484,16 +484,16 @@ nni_tls_pipe_dorecv(nni_tls_pipe *p) } static void -nni_tls_pipe_recv(void *arg, nni_aio *aio) +tls_pipe_recv(void *arg, nni_aio *aio) { - nni_tls_pipe *p = arg; - int rv; + tls_pipe *p = arg; + int rv; if (nni_aio_begin(aio) != 0) { return; } nni_mtx_lock(&p->mtx); - if ((rv = nni_aio_schedule(aio, nni_tls_cancel_rx, p)) != 0) { + if ((rv = nni_aio_schedule(aio, tls_cancel_rx, p)) != 0) { nni_mtx_unlock(&p->mtx); nni_aio_finish_error(aio, rv); return; @@ -501,74 +501,74 @@ nni_tls_pipe_recv(void *arg, nni_aio *aio) nni_aio_list_append(&p->recvq, aio); if (nni_list_first(&p->recvq) == aio) { - nni_tls_pipe_dorecv(p); + tls_pipe_dorecv(p); } nni_mtx_unlock(&p->mtx); } static uint16_t -nni_tls_pipe_peer(void *arg) +tls_pipe_peer(void *arg) { - nni_tls_pipe *p = arg; + tls_pipe *p = arg; return (p->peer); } static int -nni_tls_pipe_getopt_locaddr(void *arg, void *v, size_t *szp, int typ) +tls_pipe_get_locaddr(void *arg, void *v, size_t *szp, nni_opt_type t) { - nni_tls_pipe *p = arg; - int rv; - nni_sockaddr sa; + tls_pipe * p = arg; + int rv; + nni_sockaddr sa; memset(&sa, 0, sizeof(sa)); if ((rv = nni_tls_sockname(p->tls, &sa)) == 0) { - rv = nni_copyout_sockaddr(&sa, v, szp, typ); + rv = nni_copyout_sockaddr(&sa, v, szp, t); } return (rv); } static int -nni_tls_pipe_getopt_remaddr(void *arg, void *v, size_t *szp, int typ) +tls_pipe_get_remaddr(void *arg, void *v, size_t *szp, nni_opt_type t) { - nni_tls_pipe *p = arg; - int rv; - nni_sockaddr sa; + tls_pipe * p = arg; + int rv; + nni_sockaddr sa; memset(&sa, 0, sizeof(sa)); if ((rv = nni_tls_peername(p->tls, &sa)) == 0) { - rv = nni_copyout_sockaddr(&sa, v, szp, typ); + rv = nni_copyout_sockaddr(&sa, v, szp, t); } return (rv); } static int -nni_tls_pipe_getopt_keepalive(void *arg, void *v, size_t *szp, int typ) +tls_pipe_get_keepalive(void *arg, void *v, size_t *szp, nni_opt_type t) { - nni_tls_pipe *p = arg; - return (nni_copyout_bool(p->keepalive, v, szp, typ)); + tls_pipe *p = arg; + return (nni_copyout_bool(p->keepalive, v, szp, t)); } static int -nni_tls_pipe_getopt_nodelay(void *arg, void *v, size_t *szp, int typ) +tls_pipe_get_nodelay(void *arg, void *v, size_t *szp, nni_opt_type t) { - nni_tls_pipe *p = arg; - return (nni_copyout_bool(p->nodelay, v, szp, typ)); + tls_pipe *p = arg; + return (nni_copyout_bool(p->nodelay, v, szp, t)); } static void -nni_tls_pipe_start(void *arg, nni_aio *aio) +tls_pipe_start(void *arg, nni_aio *aio) { - nni_tls_pipe *p = arg; - nni_aio * negaio; - nni_iov iov; - int rv; + tls_pipe *p = arg; + nni_aio * negaio; + nni_iov iov; + int rv; if (nni_aio_begin(aio) != 0) { return; } nni_mtx_lock(&p->mtx); - if ((rv = nni_aio_schedule(aio, nni_tls_cancel_nego, p)) != 0) { + if ((rv = nni_aio_schedule(aio, tls_cancel_nego, p)) != 0) { nni_mtx_unlock(&p->mtx); nni_aio_finish_error(aio, rv); return; @@ -594,9 +594,9 @@ nni_tls_pipe_start(void *arg, nni_aio *aio) } static void -nni_tls_ep_fini(void *arg) +tls_ep_fini(void *arg) { - nni_tls_ep *ep = arg; + tls_ep *ep = arg; nni_aio_stop(ep->aio); if (ep->tep != NULL) { @@ -611,9 +611,9 @@ nni_tls_ep_fini(void *arg) } static int -nni_tls_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) +tls_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) { - nni_tls_ep * ep; + tls_ep * ep; int rv; char * host; char * serv; @@ -698,13 +698,13 @@ nni_tls_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) if (((rv = nni_plat_tcp_ep_init(&ep->tep, &lsa, &rsa, mode)) != 0) || ((rv = nni_tls_config_init(&ep->cfg, tlsmode)) != 0) || ((rv = nng_tls_config_auth_mode(ep->cfg, authmode)) != 0) || - ((rv = nni_aio_init(&ep->aio, nni_tls_ep_cb, ep)) != 0)) { - nni_tls_ep_fini(ep); + ((rv = nni_aio_init(&ep->aio, tls_ep_cb, ep)) != 0)) { + tls_ep_fini(ep); return (rv); } if ((tlsmode == NNG_TLS_MODE_CLIENT) && (host != NULL)) { if ((rv = nng_tls_config_server_name(ep->cfg, host)) != 0) { - nni_tls_ep_fini(ep); + tls_ep_fini(ep); return (rv); } } @@ -716,9 +716,9 @@ nni_tls_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) } static void -nni_tls_ep_close(void *arg) +tls_ep_close(void *arg) { - nni_tls_ep *ep = arg; + tls_ep *ep = arg; nni_aio_close(ep->aio); @@ -728,10 +728,10 @@ nni_tls_ep_close(void *arg) } static int -nni_tls_ep_bind(void *arg) +tls_ep_bind(void *arg) { - nni_tls_ep *ep = arg; - int rv; + tls_ep *ep = arg; + int rv; nni_mtx_lock(&ep->mtx); rv = nni_plat_tcp_ep_listen(ep->tep, &ep->bsa); @@ -741,11 +741,11 @@ nni_tls_ep_bind(void *arg) } static void -nni_tls_ep_finish(nni_tls_ep *ep) +tls_ep_finish(tls_ep *ep) { - nni_aio * aio; - int rv; - nni_tls_pipe *pipe = NULL; + nni_aio * aio; + int rv; + tls_pipe *pipe = NULL; if ((rv = nni_aio_result(ep->aio)) != 0) { goto done; @@ -754,7 +754,7 @@ nni_tls_ep_finish(nni_tls_ep *ep) // Attempt to allocate the parent pipe. If this fails we'll // drop the connection (ENOMEM probably). - rv = nni_tls_pipe_init(&pipe, ep, nni_aio_get_output(ep->aio, 0)); + rv = tls_pipe_init(&pipe, ep, nni_aio_get_output(ep->aio, 0)); done: aio = ep->user_aio; @@ -766,7 +766,7 @@ done: return; } if (pipe != NULL) { - nni_tls_pipe_fini(pipe); + tls_pipe_fini(pipe); } if (aio != NULL) { NNI_ASSERT(rv != 0); @@ -775,19 +775,19 @@ done: } static void -nni_tls_ep_cb(void *arg) +tls_ep_cb(void *arg) { - nni_tls_ep *ep = arg; + tls_ep *ep = arg; nni_mtx_lock(&ep->mtx); - nni_tls_ep_finish(ep); + tls_ep_finish(ep); nni_mtx_unlock(&ep->mtx); } static void -nni_tls_cancel_ep(nni_aio *aio, int rv) +tls_cancel_ep(nni_aio *aio, int rv) { - nni_tls_ep *ep = nni_aio_get_prov_data(aio); + tls_ep *ep = nni_aio_get_prov_data(aio); nni_mtx_lock(&ep->mtx); if (ep->user_aio != aio) { @@ -802,17 +802,17 @@ nni_tls_cancel_ep(nni_aio *aio, int rv) } static void -nni_tls_ep_accept(void *arg, nni_aio *aio) +tls_ep_accept(void *arg, nni_aio *aio) { - nni_tls_ep *ep = arg; - int rv; + tls_ep *ep = arg; + int rv; if (nni_aio_begin(aio) != 0) { return; } nni_mtx_lock(&ep->mtx); NNI_ASSERT(ep->user_aio == NULL); - if ((rv = nni_aio_schedule(aio, nni_tls_cancel_ep, ep)) != 0) { + if ((rv = nni_aio_schedule(aio, tls_cancel_ep, ep)) != 0) { nni_mtx_unlock(&ep->mtx); nni_aio_finish_error(aio, rv); return; @@ -823,17 +823,17 @@ nni_tls_ep_accept(void *arg, nni_aio *aio) } static void -nni_tls_ep_connect(void *arg, nni_aio *aio) +tls_ep_connect(void *arg, nni_aio *aio) { - nni_tls_ep *ep = arg; - int rv; + tls_ep *ep = arg; + int rv; if (nni_aio_begin(aio) != 0) { return; } nni_mtx_lock(&ep->mtx); NNI_ASSERT(ep->user_aio == NULL); - if ((rv = nni_aio_schedule(aio, nni_tls_cancel_ep, ep)) != 0) { + if ((rv = nni_aio_schedule(aio, tls_cancel_ep, ep)) != 0) { nni_mtx_unlock(&ep->mtx); nni_aio_finish_error(aio, rv); } @@ -843,13 +843,18 @@ nni_tls_ep_connect(void *arg, nni_aio *aio) } static int -nni_tls_ep_setopt_nodelay(void *arg, const void *v, size_t sz, int typ) +tls_ep_chk_bool(const void *v, size_t sz, nni_opt_type t) { - nni_tls_ep *ep = arg; - bool val; - int rv; - rv = nni_copyin_bool(&val, v, sz, typ); - if ((rv == 0) && (ep != NULL)) { + return (nni_copyin_bool(NULL, v, sz, t)); +} + +static int +tls_ep_set_nodelay(void *arg, const void *v, size_t sz, nni_opt_type t) +{ + tls_ep *ep = arg; + bool val; + int rv; + if ((rv = nni_copyin_bool(&val, v, sz, t)) == 0) { nni_mtx_lock(&ep->mtx); ep->nodelay = val; nni_mtx_unlock(&ep->mtx); @@ -858,20 +863,19 @@ nni_tls_ep_setopt_nodelay(void *arg, const void *v, size_t sz, int typ) } static int -nni_tls_ep_getopt_nodelay(void *arg, void *v, size_t *szp, int typ) +tls_ep_get_nodelay(void *arg, void *v, size_t *szp, nni_opt_type t) { - nni_tls_ep *ep = arg; - return (nni_copyout_bool(ep->nodelay, v, szp, typ)); + tls_ep *ep = arg; + return (nni_copyout_bool(ep->nodelay, v, szp, t)); } static int -nni_tls_ep_setopt_keepalive(void *arg, const void *v, size_t sz, int typ) +tls_ep_set_keepalive(void *arg, const void *v, size_t sz, nni_opt_type t) { - nni_tls_ep *ep = arg; - bool val; - int rv; - rv = nni_copyin_bool(&val, v, sz, typ); - if ((rv == 0) && (ep != NULL)) { + tls_ep *ep = arg; + bool val; + int rv; + if ((rv = nni_copyin_bool(&val, v, sz, t)) == 0) { nni_mtx_lock(&ep->mtx); ep->keepalive = val; nni_mtx_unlock(&ep->mtx); @@ -880,37 +884,36 @@ nni_tls_ep_setopt_keepalive(void *arg, const void *v, size_t sz, int typ) } static int -nni_tls_ep_getopt_keepalive(void *arg, void *v, size_t *szp, int typ) +tls_ep_get_keepalive(void *arg, void *v, size_t *szp, nni_opt_type t) { - nni_tls_ep *ep = arg; - return (nni_copyout_bool(ep->keepalive, v, szp, typ)); + tls_ep *ep = arg; + return (nni_copyout_bool(ep->keepalive, v, szp, t)); } static int -nni_tls_ep_getopt_url(void *arg, void *v, size_t *szp, int typ) +tls_ep_get_url(void *arg, void *v, size_t *szp, nni_opt_type t) { - nni_tls_ep *ep = arg; - char ustr[128]; - char ipstr[48]; // max for IPv6 addresses including [] - char portstr[6]; // max for 16-bit port + tls_ep *ep = arg; + char ustr[128]; + char ipstr[48]; // max for IPv6 addresses including [] + char portstr[6]; // max for 16-bit port if (ep->mode == NNI_EP_MODE_DIAL) { - return (nni_copyout_str(ep->url->u_rawurl, v, szp, typ)); + return (nni_copyout_str(ep->url->u_rawurl, v, szp, t)); } nni_plat_tcp_ntop(&ep->bsa, ipstr, portstr); snprintf(ustr, sizeof(ustr), "tls+tcp://%s:%s", ipstr, portstr); - return (nni_copyout_str(ustr, v, szp, typ)); + return (nni_copyout_str(ustr, v, szp, t)); } static int -nni_tls_ep_setopt_recvmaxsz(void *arg, const void *v, size_t sz, int typ) +tls_ep_set_recvmaxsz(void *arg, const void *v, size_t sz, nni_opt_type t) { - nni_tls_ep *ep = arg; - size_t val; - int rv; + tls_ep *ep = arg; + size_t val; + int rv; - rv = nni_copyin_size(&val, v, sz, 0, NNI_MAXSZ, typ); - if ((rv == 0) && (ep != NULL)) { + if ((rv = nni_copyin_size(&val, v, sz, 0, NNI_MAXSZ, t)) == 0) { nni_mtx_lock(&ep->mtx); ep->rcvmax = val; nni_mtx_unlock(&ep->mtx); @@ -919,28 +922,42 @@ nni_tls_ep_setopt_recvmaxsz(void *arg, const void *v, size_t sz, int typ) } static int -nni_tls_ep_getopt_recvmaxsz(void *arg, void *v, size_t *szp, int typ) +tls_ep_chk_recvmaxsz(const void *v, size_t sz, nni_opt_type t) { - nni_tls_ep *ep = arg; - return (nni_copyout_size(ep->rcvmax, v, szp, typ)); + return (nni_copyin_size(NULL, v, sz, 0, NNI_MAXSZ, t)); } static int -tls_setopt_config(void *arg, const void *data, size_t sz, int typ) +tls_ep_get_recvmaxsz(void *arg, void *v, size_t *szp, nni_opt_type t) { - nni_tls_ep * ep = arg; + tls_ep *ep = arg; + return (nni_copyout_size(ep->rcvmax, v, szp, t)); +} + +static int +tls_ep_chk_config(const void *data, size_t sz, nni_opt_type t) +{ + void *v; + int rv; + if (((rv = nni_copyin_ptr(&v, data, sz, t)) == 0) && (v == NULL)) { + rv = NNG_EINVAL; + } + return (rv); +} + +static int +tls_ep_set_config(void *arg, const void *data, size_t sz, nni_opt_type t) +{ + tls_ep * ep = arg; nng_tls_config *cfg, *old; int rv; - if ((rv = nni_copyin_ptr((void **) &cfg, data, sz, typ)) != 0) { + if ((rv = nni_copyin_ptr((void **) &cfg, data, sz, t)) != 0) { return (rv); } if (cfg == NULL) { return (NNG_EINVAL); } - if (ep == NULL) { - return (0); - } old = ep->cfg; nni_tls_config_hold(cfg); ep->cfg = cfg; @@ -951,234 +968,241 @@ tls_setopt_config(void *arg, const void *data, size_t sz, int typ) } static int -tls_getopt_config(void *arg, void *v, size_t *szp, int typ) +tls_ep_get_config(void *arg, void *v, size_t *szp, nni_opt_type t) { - nni_tls_ep *ep = arg; - return (nni_copyout_ptr(ep->cfg, v, szp, typ)); + tls_ep *ep = arg; + return (nni_copyout_ptr(ep->cfg, v, szp, t)); } static int -tls_setopt_ca_file(void *arg, const void *v, size_t sz, int typ) +tls_ep_chk_string(const void *v, size_t sz, nni_opt_type t) { - nni_tls_ep *ep = arg; - - if ((typ != NNI_TYPE_OPAQUE) && (typ != NNI_TYPE_STRING)) { + if ((t != NNI_TYPE_OPAQUE) && (t != NNI_TYPE_STRING)) { return (NNG_EBADTYPE); } if (nni_strnlen(v, sz) >= sz) { return (NNG_EINVAL); } - if (ep == NULL) { - return (0); + return (0); +} + +static int +tls_ep_set_ca_file(void *arg, const void *v, size_t sz, nni_opt_type t) +{ + tls_ep *ep = arg; + int rv; + + if ((rv = tls_ep_chk_string(v, sz, t)) == 0) { + rv = nng_tls_config_ca_file(ep->cfg, v); } - return (nng_tls_config_ca_file(ep->cfg, v)); + return (rv); +} + +static int +tls_ep_chk_auth_mode(const void *v, size_t sz, nni_opt_type t) +{ + return (nni_copyin_int(NULL, v, sz, NNG_TLS_AUTH_MODE_NONE, + NNG_TLS_AUTH_MODE_REQUIRED, t)); } static int -tls_setopt_auth_mode(void *arg, const void *v, size_t sz, int typ) +tls_ep_set_auth_mode(void *arg, const void *v, size_t sz, nni_opt_type t) { - nni_tls_ep *ep = arg; - int mode; - int rv; + tls_ep *ep = arg; + int mode; + int rv; rv = nni_copyin_int(&mode, v, sz, NNG_TLS_AUTH_MODE_NONE, - NNG_TLS_AUTH_MODE_REQUIRED, typ); - if ((rv != 0) || (ep == NULL)) { - return (rv); + NNG_TLS_AUTH_MODE_REQUIRED, t); + if (rv == 0) { + rv = nng_tls_config_auth_mode(ep->cfg, mode); } - return (nng_tls_config_auth_mode(ep->cfg, mode)); + return (rv); } static int -tls_setopt_server_name(void *arg, const void *v, size_t sz, int typ) +tls_ep_set_server_name(void *arg, const void *v, size_t sz, nni_opt_type t) { - nni_tls_ep *ep = arg; + tls_ep *ep = arg; + int rv; - if ((typ != NNI_TYPE_OPAQUE) && (typ != NNI_TYPE_STRING)) { - return (NNG_EBADTYPE); + if ((rv = tls_ep_chk_string(v, sz, t)) == 0) { + rv = nng_tls_config_server_name(ep->cfg, v); } - if (nni_strnlen(v, sz) >= sz) { - return (NNG_EINVAL); - } - if (ep == NULL) { - return (0); - } - return (nng_tls_config_server_name(ep->cfg, v)); + return (rv); } static int -tls_setopt_cert_key_file(void *arg, const void *v, size_t sz, int typ) +tls_ep_set_cert_key_file(void *arg, const void *v, size_t sz, nni_opt_type t) { - nni_tls_ep *ep = arg; + tls_ep *ep = arg; + int rv; - if ((typ != NNI_TYPE_OPAQUE) && (typ != NNI_TYPE_STRING)) { - return (NNG_EBADTYPE); + if ((rv = tls_ep_chk_string(v, sz, t)) == 0) { + rv = nng_tls_config_cert_key_file(ep->cfg, v, NULL); } - if (nni_strnlen(v, sz) >= sz) { - return (NNG_EINVAL); - } - if (ep == NULL) { - return (0); - } - return (nng_tls_config_cert_key_file(ep->cfg, v, NULL)); + return (rv); } static int -tls_getopt_verified(void *arg, void *v, size_t *szp, int typ) +tls_pipe_get_verified(void *arg, void *v, size_t *szp, nni_opt_type t) { - nni_tls_pipe *p = arg; + tls_pipe *p = arg; - return (nni_copyout_bool(nni_tls_verified(p->tls), v, szp, typ)); + return (nni_copyout_bool(nni_tls_verified(p->tls), v, szp, t)); } -static nni_tran_pipe_option nni_tls_pipe_options[] = { +static nni_tran_option tls_pipe_options[] = { { - .po_name = NNG_OPT_LOCADDR, - .po_type = NNI_TYPE_SOCKADDR, - .po_getopt = nni_tls_pipe_getopt_locaddr, + .o_name = NNG_OPT_LOCADDR, + .o_type = NNI_TYPE_SOCKADDR, + .o_get = tls_pipe_get_locaddr, }, { - .po_name = NNG_OPT_REMADDR, - .po_type = NNI_TYPE_SOCKADDR, - .po_getopt = nni_tls_pipe_getopt_remaddr, + .o_name = NNG_OPT_REMADDR, + .o_type = NNI_TYPE_SOCKADDR, + .o_get = tls_pipe_get_remaddr, }, { - .po_name = NNG_OPT_TLS_VERIFIED, - .po_type = NNI_TYPE_BOOL, - .po_getopt = tls_getopt_verified, + .o_name = NNG_OPT_TLS_VERIFIED, + .o_type = NNI_TYPE_BOOL, + .o_get = tls_pipe_get_verified, }, { - .po_name = NNG_OPT_TCP_KEEPALIVE, - .po_type = NNI_TYPE_BOOL, - .po_getopt = nni_tls_pipe_getopt_keepalive, + .o_name = NNG_OPT_TCP_KEEPALIVE, + .o_type = NNI_TYPE_BOOL, + .o_get = tls_pipe_get_keepalive, }, { - .po_name = NNG_OPT_TCP_NODELAY, - .po_type = NNI_TYPE_BOOL, - .po_getopt = nni_tls_pipe_getopt_nodelay, + .o_name = NNG_OPT_TCP_NODELAY, + .o_type = NNI_TYPE_BOOL, + .o_get = tls_pipe_get_nodelay, }, // terminate list { - .po_name = NULL, + .o_name = NULL, }, }; -static nni_tran_pipe_ops nni_tls_pipe_ops = { - .p_fini = nni_tls_pipe_fini, - .p_start = nni_tls_pipe_start, - .p_stop = nni_tls_pipe_stop, - .p_send = nni_tls_pipe_send, - .p_recv = nni_tls_pipe_recv, - .p_close = nni_tls_pipe_close, - .p_peer = nni_tls_pipe_peer, - .p_options = nni_tls_pipe_options, +static nni_tran_pipe_ops tls_pipe_ops = { + .p_fini = tls_pipe_fini, + .p_start = tls_pipe_start, + .p_stop = tls_pipe_stop, + .p_send = tls_pipe_send, + .p_recv = tls_pipe_recv, + .p_close = tls_pipe_close, + .p_peer = tls_pipe_peer, + .p_options = tls_pipe_options, }; -static nni_tran_ep_option nni_tls_ep_options[] = { +static nni_tran_option tls_ep_options[] = { { - .eo_name = NNG_OPT_RECVMAXSZ, - .eo_type = NNI_TYPE_SIZE, - .eo_getopt = nni_tls_ep_getopt_recvmaxsz, - .eo_setopt = nni_tls_ep_setopt_recvmaxsz, + .o_name = NNG_OPT_RECVMAXSZ, + .o_type = NNI_TYPE_SIZE, + .o_get = tls_ep_get_recvmaxsz, + .o_set = tls_ep_set_recvmaxsz, + .o_chk = tls_ep_chk_recvmaxsz, }, { - .eo_name = NNG_OPT_URL, - .eo_type = NNI_TYPE_STRING, - .eo_getopt = nni_tls_ep_getopt_url, - .eo_setopt = NULL, + .o_name = NNG_OPT_URL, + .o_type = NNI_TYPE_STRING, + .o_get = tls_ep_get_url, }, { - .eo_name = NNG_OPT_TLS_CONFIG, - .eo_type = NNI_TYPE_POINTER, - .eo_getopt = tls_getopt_config, - .eo_setopt = tls_setopt_config, + .o_name = NNG_OPT_TLS_CONFIG, + .o_type = NNI_TYPE_POINTER, + .o_get = tls_ep_get_config, + .o_set = tls_ep_set_config, + .o_chk = tls_ep_chk_config, }, { - .eo_name = NNG_OPT_TLS_CERT_KEY_FILE, - .eo_type = NNI_TYPE_STRING, - .eo_getopt = NULL, - .eo_setopt = tls_setopt_cert_key_file, + .o_name = NNG_OPT_TLS_CERT_KEY_FILE, + .o_type = NNI_TYPE_STRING, + .o_set = tls_ep_set_cert_key_file, + .o_chk = tls_ep_chk_string, }, { - .eo_name = NNG_OPT_TLS_CA_FILE, - .eo_type = NNI_TYPE_STRING, - .eo_getopt = NULL, - .eo_setopt = tls_setopt_ca_file, + .o_name = NNG_OPT_TLS_CA_FILE, + .o_type = NNI_TYPE_STRING, + .o_set = tls_ep_set_ca_file, + .o_chk = tls_ep_chk_string, }, { - .eo_name = NNG_OPT_TLS_AUTH_MODE, - .eo_type = NNI_TYPE_INT32, // enum really - .eo_getopt = NULL, - .eo_setopt = tls_setopt_auth_mode, + .o_name = NNG_OPT_TLS_AUTH_MODE, + .o_type = NNI_TYPE_INT32, // enum really + .o_set = tls_ep_set_auth_mode, + .o_chk = tls_ep_chk_auth_mode, }, { - .eo_name = NNG_OPT_TLS_SERVER_NAME, - .eo_type = NNI_TYPE_STRING, - .eo_getopt = NULL, - .eo_setopt = tls_setopt_server_name, + .o_name = NNG_OPT_TLS_SERVER_NAME, + .o_type = NNI_TYPE_STRING, + .o_set = tls_ep_set_server_name, + .o_chk = tls_ep_chk_string, }, { - .eo_name = NNG_OPT_TCP_NODELAY, - .eo_type = NNI_TYPE_BOOL, - .eo_getopt = nni_tls_ep_getopt_nodelay, - .eo_setopt = nni_tls_ep_setopt_nodelay, + .o_name = NNG_OPT_TCP_NODELAY, + .o_type = NNI_TYPE_BOOL, + .o_get = tls_ep_get_nodelay, + .o_set = tls_ep_set_nodelay, + .o_chk = tls_ep_chk_bool, }, { - .eo_name = NNG_OPT_TCP_KEEPALIVE, - .eo_type = NNI_TYPE_BOOL, - .eo_getopt = nni_tls_ep_getopt_keepalive, - .eo_setopt = nni_tls_ep_setopt_keepalive, + .o_name = NNG_OPT_TCP_KEEPALIVE, + .o_type = NNI_TYPE_BOOL, + .o_get = tls_ep_get_keepalive, + .o_set = tls_ep_set_keepalive, + .o_chk = tls_ep_chk_bool, }, // terminate list { - .eo_name = NULL, + .o_name = NULL, }, }; -static nni_tran_ep_ops nni_tls_ep_ops = { - .ep_init = nni_tls_ep_init, - .ep_fini = nni_tls_ep_fini, - .ep_connect = nni_tls_ep_connect, - .ep_bind = nni_tls_ep_bind, - .ep_accept = nni_tls_ep_accept, - .ep_close = nni_tls_ep_close, - .ep_options = nni_tls_ep_options, +static nni_tran_ep_ops tls_ep_ops = { + .ep_init = tls_ep_init, + .ep_fini = tls_ep_fini, + .ep_connect = tls_ep_connect, + .ep_bind = tls_ep_bind, + .ep_accept = tls_ep_accept, + .ep_close = tls_ep_close, + .ep_options = tls_ep_options, }; -static nni_tran nni_tls_tran = { +static nni_tran tls_tran = { .tran_version = NNI_TRANSPORT_VERSION, .tran_scheme = "tls+tcp", - .tran_ep = &nni_tls_ep_ops, - .tran_pipe = &nni_tls_pipe_ops, - .tran_init = nni_tls_tran_init, - .tran_fini = nni_tls_tran_fini, + .tran_ep = &tls_ep_ops, + .tran_pipe = &tls_pipe_ops, + .tran_init = tls_tran_init, + .tran_fini = tls_tran_fini, }; -static nni_tran nni_tls4_tran = { +static nni_tran tls4_tran = { .tran_version = NNI_TRANSPORT_VERSION, .tran_scheme = "tls+tcp4", - .tran_ep = &nni_tls_ep_ops, - .tran_pipe = &nni_tls_pipe_ops, - .tran_init = nni_tls_tran_init, - .tran_fini = nni_tls_tran_fini, + .tran_ep = &tls_ep_ops, + .tran_pipe = &tls_pipe_ops, + .tran_init = tls_tran_init, + .tran_fini = tls_tran_fini, }; -static nni_tran nni_tls6_tran = { +static nni_tran tls6_tran = { .tran_version = NNI_TRANSPORT_VERSION, .tran_scheme = "tls+tcp6", - .tran_ep = &nni_tls_ep_ops, - .tran_pipe = &nni_tls_pipe_ops, - .tran_init = nni_tls_tran_init, - .tran_fini = nni_tls_tran_fini, + .tran_ep = &tls_ep_ops, + .tran_pipe = &tls_pipe_ops, + .tran_init = tls_tran_init, + .tran_fini = tls_tran_fini, }; int nng_tls_register(void) { int rv; - if (((rv = nni_tran_register(&nni_tls_tran)) != 0) || - ((rv = nni_tran_register(&nni_tls4_tran)) != 0) || - ((rv = nni_tran_register(&nni_tls6_tran)) != 0)) { + if (((rv = nni_tran_register(&tls_tran)) != 0) || + ((rv = nni_tran_register(&tls4_tran)) != 0) || + ((rv = nni_tran_register(&tls6_tran)) != 0)) { return (rv); } return (0); diff --git a/src/transport/ws/websocket.c b/src/transport/ws/websocket.c index 62f43fd0..7dbf6903 100644 --- a/src/transport/ws/websocket.c +++ b/src/transport/ws/websocket.c @@ -367,14 +367,25 @@ ws_ep_connect(void *arg, nni_aio *aio) } static int -ws_ep_setopt_recvmaxsz(void *arg, const void *v, size_t sz, int typ) +ws_ep_chk_string(const void *v, size_t sz, nni_opt_type t) +{ + if ((t != NNI_TYPE_OPAQUE) && (t != NNI_TYPE_STRING)) { + return (NNG_EBADTYPE); + } + if (nni_strnlen(v, sz) >= sz) { + return (NNG_EINVAL); + } + return (0); +} + +static int +ws_ep_set_recvmaxsz(void *arg, const void *v, size_t sz, nni_opt_type t) { ws_ep *ep = arg; size_t val; int rv; - rv = nni_copyin_size(&val, v, sz, 0, NNI_MAXSZ, typ); - if ((rv == 0) && (ep != NULL)) { + if ((rv = nni_copyin_size(&val, v, sz, 0, NNI_MAXSZ, t)) == 0) { nni_mtx_lock(&ep->mtx); ep->rcvmax = val; nni_mtx_unlock(&ep->mtx); @@ -388,7 +399,20 @@ ws_ep_setopt_recvmaxsz(void *arg, const void *v, size_t sz, int typ) } static int -ws_ep_setopt_headers(ws_ep *ep, const char *v) +ws_ep_chk_recvmaxsz(const void *v, size_t sz, nni_opt_type t) +{ + return (nni_copyin_size(NULL, v, sz, 0, NNI_MAXSZ, t)); +} + +static int +ws_ep_get_recvmaxsz(void *arg, void *v, size_t *szp, nni_opt_type t) +{ + ws_ep *ep = arg; + return (nni_copyout_size(ep->rcvmax, v, szp, t)); +} + +static int +ws_ep_set_headers(ws_ep *ep, const char *v) { char * dupstr; size_t duplen; @@ -471,52 +495,39 @@ done: } static int -ws_ep_setopt_reqhdrs(void *arg, const void *v, size_t sz, int typ) +ws_ep_set_reqhdrs(void *arg, const void *v, size_t sz, nni_opt_type t) { ws_ep *ep = arg; + int rv; - if ((typ != NNI_TYPE_STRING) && (typ != NNI_TYPE_OPAQUE)) { - return (NNG_EBADTYPE); - } - - if (nni_strnlen(v, sz) >= sz) { - return (NNG_EINVAL); - } - - if ((ep != NULL) && (ep->mode == NNI_EP_MODE_LISTEN)) { - return (NNG_EREADONLY); + if ((rv = ws_ep_chk_string(v, sz, t)) == 0) { + if (ep->mode == NNI_EP_MODE_LISTEN) { + rv = NNG_EREADONLY; + } else { + rv = ws_ep_set_headers(ep, v); + } } - return (ws_ep_setopt_headers(ep, v)); + return (rv); } static int -ws_ep_setopt_reshdrs(void *arg, const void *v, size_t sz, int typ) +ws_ep_set_reshdrs(void *arg, const void *v, size_t sz, nni_opt_type t) { ws_ep *ep = arg; + int rv; - if ((typ != NNI_TYPE_STRING) && (typ != NNI_TYPE_OPAQUE)) { - return (NNG_EBADTYPE); - } - - if (nni_strnlen(v, sz) >= sz) { - return (NNG_EINVAL); - } - - if ((ep != NULL) && (ep->mode == NNI_EP_MODE_DIAL)) { - return (NNG_EREADONLY); + if ((rv = ws_ep_chk_string(v, sz, t)) == 0) { + if (ep->mode == NNI_EP_MODE_DIAL) { + rv = NNG_EREADONLY; + } else { + rv = ws_ep_set_headers(ep, v); + } } - return (ws_ep_setopt_headers(ep, v)); -} - -static int -ws_ep_getopt_recvmaxsz(void *arg, void *v, size_t *szp, int typ) -{ - ws_ep *ep = arg; - return (nni_copyout_size(ep->rcvmax, v, szp, typ)); + return (rv); } static int -ws_pipe_getopt_locaddr(void *arg, void *v, size_t *szp, int typ) +ws_pipe_get_locaddr(void *arg, void *v, size_t *szp, nni_opt_type t) { ws_pipe * p = arg; int rv; @@ -524,13 +535,13 @@ ws_pipe_getopt_locaddr(void *arg, void *v, size_t *szp, int typ) memset(&sa, 0, sizeof(sa)); if ((rv = nni_ws_sock_addr(p->ws, &sa)) == 0) { - rv = nni_copyout_sockaddr(&sa, v, szp, typ); + rv = nni_copyout_sockaddr(&sa, v, szp, t); } return (rv); } static int -ws_pipe_getopt_remaddr(void *arg, void *v, size_t *szp, int typ) +ws_pipe_get_remaddr(void *arg, void *v, size_t *szp, nni_opt_type t) { ws_pipe * p = arg; int rv; @@ -538,13 +549,13 @@ ws_pipe_getopt_remaddr(void *arg, void *v, size_t *szp, int typ) memset(&sa, 0, sizeof(sa)); if ((rv = nni_ws_peer_addr(p->ws, &sa)) == 0) { - rv = nni_copyout_sockaddr(&sa, v, szp, typ); + rv = nni_copyout_sockaddr(&sa, v, szp, t); } return (rv); } static int -ws_pipe_getopt_reshdrs(void *arg, void *v, size_t *szp, int typ) +ws_pipe_get_reshdrs(void *arg, void *v, size_t *szp, nni_opt_type t) { ws_pipe * p = arg; const char *s; @@ -552,11 +563,11 @@ ws_pipe_getopt_reshdrs(void *arg, void *v, size_t *szp, int typ) if ((s = nni_ws_response_headers(p->ws)) == NULL) { return (NNG_ENOMEM); } - return (nni_copyout_str(s, v, szp, typ)); + return (nni_copyout_str(s, v, szp, t)); } static int -ws_pipe_getopt_reqhdrs(void *arg, void *v, size_t *szp, int typ) +ws_pipe_get_reqhdrs(void *arg, void *v, size_t *szp, nni_opt_type t) { ws_pipe * p = arg; const char *s; @@ -564,46 +575,46 @@ ws_pipe_getopt_reqhdrs(void *arg, void *v, size_t *szp, int typ) if ((s = nni_ws_request_headers(p->ws)) == NULL) { return (NNG_ENOMEM); } - return (nni_copyout_str(s, v, szp, typ)); + return (nni_copyout_str(s, v, szp, t)); } static int -ws_pipe_getopt_tls_verified(void *arg, void *v, size_t *szp, int typ) +ws_pipe_get_tls_verified(void *arg, void *v, size_t *szp, nni_opt_type t) { ws_pipe *p = arg; - return (nni_copyout_bool(nni_ws_tls_verified(p->ws), v, szp, typ)); + return (nni_copyout_bool(nni_ws_tls_verified(p->ws), v, szp, t)); } -static nni_tran_pipe_option ws_pipe_options[] = { +static nni_tran_option ws_pipe_options[] = { { - .po_name = NNG_OPT_LOCADDR, - .po_type = NNI_TYPE_SOCKADDR, - .po_getopt = ws_pipe_getopt_locaddr, + .o_name = NNG_OPT_LOCADDR, + .o_type = NNI_TYPE_SOCKADDR, + .o_get = ws_pipe_get_locaddr, }, { - .po_name = NNG_OPT_REMADDR, - .po_type = NNI_TYPE_SOCKADDR, - .po_getopt = ws_pipe_getopt_remaddr, + .o_name = NNG_OPT_REMADDR, + .o_type = NNI_TYPE_SOCKADDR, + .o_get = ws_pipe_get_remaddr, }, { - .po_name = NNG_OPT_WS_REQUEST_HEADERS, - .po_type = NNI_TYPE_STRING, - .po_getopt = ws_pipe_getopt_reqhdrs, + .o_name = NNG_OPT_WS_REQUEST_HEADERS, + .o_type = NNI_TYPE_STRING, + .o_get = ws_pipe_get_reqhdrs, }, { - .po_name = NNG_OPT_WS_RESPONSE_HEADERS, - .po_type = NNI_TYPE_STRING, - .po_getopt = ws_pipe_getopt_reshdrs, + .o_name = NNG_OPT_WS_RESPONSE_HEADERS, + .o_type = NNI_TYPE_STRING, + .o_get = ws_pipe_get_reshdrs, }, { - .po_name = NNG_OPT_TLS_VERIFIED, - .po_type = NNI_TYPE_BOOL, - .po_getopt = ws_pipe_getopt_tls_verified, + .o_name = NNG_OPT_TLS_VERIFIED, + .o_type = NNI_TYPE_BOOL, + .o_get = ws_pipe_get_tls_verified, }, // terminate list { - .po_name = NULL, + .o_name = NULL, } }; @@ -617,28 +628,29 @@ static nni_tran_pipe_ops ws_pipe_ops = { .p_options = ws_pipe_options, }; -static nni_tran_ep_option ws_ep_options[] = { +static nni_tran_option ws_ep_options[] = { { - .eo_name = NNG_OPT_RECVMAXSZ, - .eo_type = NNI_TYPE_SIZE, - .eo_getopt = ws_ep_getopt_recvmaxsz, - .eo_setopt = ws_ep_setopt_recvmaxsz, + .o_name = NNG_OPT_RECVMAXSZ, + .o_type = NNI_TYPE_SIZE, + .o_get = ws_ep_get_recvmaxsz, + .o_set = ws_ep_set_recvmaxsz, + .o_chk = ws_ep_chk_recvmaxsz, }, { - .eo_name = NNG_OPT_WS_REQUEST_HEADERS, - .eo_type = NNI_TYPE_STRING, - .eo_getopt = NULL, - .eo_setopt = ws_ep_setopt_reqhdrs, + .o_name = NNG_OPT_WS_REQUEST_HEADERS, + .o_type = NNI_TYPE_STRING, + .o_set = ws_ep_set_reqhdrs, + .o_chk = ws_ep_chk_string, }, { - .eo_name = NNG_OPT_WS_RESPONSE_HEADERS, - .eo_type = NNI_TYPE_STRING, - .eo_getopt = NULL, - .eo_setopt = ws_ep_setopt_reshdrs, + .o_name = NNG_OPT_WS_RESPONSE_HEADERS, + .o_type = NNI_TYPE_STRING, + .o_set = ws_ep_set_reshdrs, + .o_chk = ws_ep_chk_string, }, // terminate list { - .eo_name = NULL, + .o_name = NULL, }, }; @@ -858,36 +870,44 @@ wss_get_tls(ws_ep *ep, nng_tls_config **tlsp) } static int -wss_ep_getopt_tlsconfig(void *arg, void *v, size_t *szp, int typ) +wss_ep_get_tlsconfig(void *arg, void *v, size_t *szp, nni_opt_type t) { ws_ep * ep = arg; nng_tls_config *tls; int rv; if (((rv = wss_get_tls(ep, &tls)) != 0) || - ((rv = nni_copyout_ptr(tls, v, szp, typ)) != 0)) { + ((rv = nni_copyout_ptr(tls, v, szp, t)) != 0)) { return (rv); } return (0); } static int -wss_ep_setopt_tlsconfig(void *arg, const void *v, size_t sz, int typ) +wss_ep_chk_tlsconfig(const void *v, size_t sz, nni_opt_type t) +{ + void *p; + int rv; + if (((rv = nni_copyin_ptr(&p, v, sz, t)) == 0) && (p == NULL)) { + rv = NNG_EINVAL; + } + return (rv); +} + +static int +wss_ep_set_tlsconfig(void *arg, const void *v, size_t sz, nni_opt_type t) { ws_ep * ep = arg; nng_tls_config *cfg; int rv; - if ((rv = nni_copyin_ptr((void **) &cfg, v, sz, typ)) != 0) { + if ((rv = nni_copyin_ptr((void **) &cfg, v, sz, t)) != 0) { return (rv); } if (cfg == NULL) { // NULL is clearly invalid. return (NNG_EINVAL); } - if (ep == NULL) { - return (0); - } if (ep->mode == NNI_EP_MODE_LISTEN) { rv = nni_ws_listener_set_tls(ep->listener, cfg); } else { @@ -897,52 +917,42 @@ wss_ep_setopt_tlsconfig(void *arg, const void *v, size_t sz, int typ) } static int -wss_ep_setopt_tls_cert_key_file(void *arg, const void *v, size_t sz, int typ) +wss_ep_set_cert_key_file(void *arg, const void *v, size_t sz, nni_opt_type t) { ws_ep * ep = arg; int rv; nng_tls_config *tls; - if ((typ != NNI_TYPE_OPAQUE) && (typ != NNI_TYPE_STRING)) { - return (NNG_EBADTYPE); - } - if (nni_strnlen(v, sz) >= sz) { - return (NNG_EINVAL); - } - if (ep == NULL) { - return (0); - } - if ((rv = wss_get_tls(ep, &tls)) != 0) { + if (((rv = ws_ep_chk_string(v, sz, t)) != 0) || + ((rv = wss_get_tls(ep, &tls)) != 0)) { return (rv); } return (nng_tls_config_cert_key_file(tls, v, NULL)); } static int -wss_ep_setopt_tls_ca_file(void *arg, const void *v, size_t sz, int typ) +wss_ep_set_ca_file(void *arg, const void *v, size_t sz, nni_opt_type t) { ws_ep * ep = arg; int rv; nng_tls_config *tls; - if ((typ != NNI_TYPE_OPAQUE) && (typ != NNI_TYPE_STRING)) { - return (NNG_EBADTYPE); - } - - if (nni_strnlen(v, sz) >= sz) { - return (NNG_EINVAL); - } - if (ep == NULL) { - return (0); - } - if ((rv = wss_get_tls(ep, &tls)) != 0) { + if (((rv = ws_ep_chk_string(v, sz, t)) != 0) || + ((rv = wss_get_tls(ep, &tls)) != 0)) { return (rv); } return (nng_tls_config_ca_file(tls, v)); } static int -wss_ep_setopt_tls_auth_mode(void *arg, const void *v, size_t sz, int typ) +wss_ep_chk_auth_mode(const void *v, size_t sz, nni_opt_type t) +{ + return (nni_copyin_int(NULL, v, sz, NNG_TLS_AUTH_MODE_NONE, + NNG_TLS_AUTH_MODE_REQUIRED, t)); +} + +static int +wss_ep_set_auth_mode(void *arg, const void *v, size_t sz, nni_opt_type t) { ws_ep * ep = arg; int rv; @@ -950,91 +960,83 @@ wss_ep_setopt_tls_auth_mode(void *arg, const void *v, size_t sz, int typ) int mode; rv = nni_copyin_int(&mode, v, sz, NNG_TLS_AUTH_MODE_NONE, - NNG_TLS_AUTH_MODE_REQUIRED, typ); - if ((rv != 0) || (ep == NULL)) { - return (rv); - } - if ((rv = wss_get_tls(ep, &tls)) != 0) { + NNG_TLS_AUTH_MODE_REQUIRED, t); + + if ((rv != 0) || ((rv = wss_get_tls(ep, &tls)) != 0)) { return (rv); } return (nng_tls_config_auth_mode(tls, mode)); } static int -wss_ep_setopt_tls_server_name(void *arg, const void *v, size_t sz, int typ) +wss_ep_set_tls_server_name(void *arg, const void *v, size_t sz, nni_opt_type t) { ws_ep * ep = arg; int rv; nng_tls_config *tls; - if ((typ != NNI_TYPE_OPAQUE) && (typ != NNI_TYPE_STRING)) { - return (NNG_EBADTYPE); - } - - if (nni_strnlen(v, sz) >= sz) { - return (NNG_EINVAL); - } - if (ep == NULL) { - return (0); - } - if ((rv = wss_get_tls(ep, &tls)) != 0) { + if (((rv = ws_ep_chk_string(v, sz, t)) != 0) || + ((rv = wss_get_tls(ep, &tls)) != 0)) { return (rv); } + return (nng_tls_config_server_name(tls, v)); } -static nni_tran_ep_option wss_ep_options[] = { +static nni_tran_option wss_ep_options[] = { { - .eo_name = NNG_OPT_RECVMAXSZ, - .eo_type = NNI_TYPE_SIZE, - .eo_getopt = ws_ep_getopt_recvmaxsz, - .eo_setopt = ws_ep_setopt_recvmaxsz, + .o_name = NNG_OPT_RECVMAXSZ, + .o_type = NNI_TYPE_SIZE, + .o_get = ws_ep_get_recvmaxsz, + .o_set = ws_ep_set_recvmaxsz, + .o_chk = ws_ep_chk_recvmaxsz, }, { - .eo_name = NNG_OPT_WS_REQUEST_HEADERS, - .eo_type = NNI_TYPE_STRING, - .eo_getopt = NULL, - .eo_setopt = ws_ep_setopt_reqhdrs, + .o_name = NNG_OPT_WS_REQUEST_HEADERS, + .o_type = NNI_TYPE_STRING, + .o_set = ws_ep_set_reqhdrs, + .o_chk = ws_ep_chk_string, }, { - .eo_name = NNG_OPT_WS_RESPONSE_HEADERS, - .eo_type = NNI_TYPE_STRING, - .eo_getopt = NULL, - .eo_setopt = ws_ep_setopt_reshdrs, + .o_name = NNG_OPT_WS_RESPONSE_HEADERS, + .o_type = NNI_TYPE_STRING, + .o_set = ws_ep_set_reshdrs, + .o_chk = ws_ep_chk_string, }, { - .eo_name = NNG_OPT_TLS_CONFIG, - .eo_type = NNI_TYPE_POINTER, - .eo_getopt = wss_ep_getopt_tlsconfig, - .eo_setopt = wss_ep_setopt_tlsconfig, + .o_name = NNG_OPT_TLS_CONFIG, + .o_type = NNI_TYPE_POINTER, + .o_get = wss_ep_get_tlsconfig, + .o_set = wss_ep_set_tlsconfig, + .o_chk = wss_ep_chk_tlsconfig, }, { - .eo_name = NNG_OPT_TLS_CERT_KEY_FILE, - .eo_type = NNI_TYPE_STRING, - .eo_getopt = NULL, - .eo_setopt = wss_ep_setopt_tls_cert_key_file, + .o_name = NNG_OPT_TLS_CERT_KEY_FILE, + .o_type = NNI_TYPE_STRING, + .o_set = wss_ep_set_cert_key_file, + .o_chk = ws_ep_chk_string, }, { - .eo_name = NNG_OPT_TLS_CA_FILE, - .eo_type = NNI_TYPE_STRING, - .eo_getopt = NULL, - .eo_setopt = wss_ep_setopt_tls_ca_file, + .o_name = NNG_OPT_TLS_CA_FILE, + .o_type = NNI_TYPE_STRING, + .o_set = wss_ep_set_ca_file, + .o_chk = ws_ep_chk_string, }, { - .eo_name = NNG_OPT_TLS_AUTH_MODE, - .eo_type = NNI_TYPE_INT32, - .eo_getopt = NULL, - .eo_setopt = wss_ep_setopt_tls_auth_mode, + .o_name = NNG_OPT_TLS_AUTH_MODE, + .o_type = NNI_TYPE_INT32, + .o_set = wss_ep_set_auth_mode, + .o_chk = wss_ep_chk_auth_mode, }, { - .eo_name = NNG_OPT_TLS_SERVER_NAME, - .eo_type = NNI_TYPE_STRING, - .eo_getopt = NULL, - .eo_setopt = wss_ep_setopt_tls_server_name, + .o_name = NNG_OPT_TLS_SERVER_NAME, + .o_type = NNI_TYPE_STRING, + .o_set = wss_ep_set_tls_server_name, + .o_chk = ws_ep_chk_string, }, // terminate list { - .eo_name = NULL, + .o_name = NULL, }, }; diff --git a/src/transport/zerotier/zerotier.c b/src/transport/zerotier/zerotier.c index 46fe476e..fa8458c1 100644 --- a/src/transport/zerotier/zerotier.c +++ b/src/transport/zerotier/zerotier.c @@ -1932,8 +1932,8 @@ zt_pipe_peer(void *arg) } static int -zt_getopt_nw_status( - zt_node *ztn, uint64_t nwid, void *buf, size_t *szp, int typ) +zt_get_nw_status( + zt_node *ztn, uint64_t nwid, void *buf, size_t *szp, nni_opt_type t) { ZT_VirtualNetworkConfig *vcfg; int status; @@ -1970,11 +1970,12 @@ zt_getopt_nw_status( ZT_Node_freeQueryResult(ztn->zn_znode, vcfg); nni_mtx_unlock(&zt_lk); - return (nni_copyout_int(status, buf, szp, typ)); + return (nni_copyout_int(status, buf, szp, t)); } static int -zt_getopt_nw_name(zt_node *ztn, uint64_t nwid, void *buf, size_t *szp, int typ) +zt_get_nw_name( + zt_node *ztn, uint64_t nwid, void *buf, size_t *szp, nni_opt_type t) { ZT_VirtualNetworkConfig *vcfg; int rv; @@ -1986,7 +1987,7 @@ zt_getopt_nw_name(zt_node *ztn, uint64_t nwid, void *buf, size_t *szp, int typ) return (NNG_ECLOSED); } - rv = nni_copyout_str(vcfg->name, buf, szp, typ); + rv = nni_copyout_str(vcfg->name, buf, szp, t); ZT_Node_freeQueryResult(ztn->zn_znode, vcfg); nni_mtx_unlock(&zt_lk); @@ -1994,24 +1995,24 @@ zt_getopt_nw_name(zt_node *ztn, uint64_t nwid, void *buf, size_t *szp, int typ) } static int -zt_pipe_get_recvmaxsz(void *arg, void *buf, size_t *szp, int typ) +zt_pipe_get_recvmaxsz(void *arg, void *buf, size_t *szp, nni_opt_type t) { zt_pipe *p = arg; - return (nni_copyout_size(p->zp_rcvmax, buf, szp, typ)); + return (nni_copyout_size(p->zp_rcvmax, buf, szp, t)); } static int -zt_pipe_get_nwid(void *arg, void *buf, size_t *szp, int typ) +zt_pipe_get_nwid(void *arg, void *buf, size_t *szp, nni_opt_type t) { zt_pipe *p = arg; - return (nni_copyout_u64(p->zp_nwid, buf, szp, typ)); + return (nni_copyout_u64(p->zp_nwid, buf, szp, t)); } static int -zt_pipe_get_node(void *arg, void *buf, size_t *szp, int typ) +zt_pipe_get_node(void *arg, void *buf, size_t *szp, nni_opt_type t) { zt_pipe *p = arg; - return (nni_copyout_u64(p->zp_laddr >> 24, buf, szp, typ)); + return (nni_copyout_u64(p->zp_laddr >> 24, buf, szp, t)); } static void @@ -2574,66 +2575,77 @@ zt_ep_connect(void *arg, nni_aio *aio) } static int -zt_ep_setopt_recvmaxsz(void *arg, const void *data, size_t sz, int typ) +zt_ep_chk_recvmaxsz(const void *v, size_t sz, nni_opt_type t) +{ + return (nni_copyin_size(NULL, v, sz, 0, NNI_MAXSZ, t)); +} + +static int +zt_ep_set_recvmaxsz(void *arg, const void *data, size_t sz, nni_opt_type t) { zt_ep *ep = arg; size_t val; int rv; - rv = nni_copyin_size(&val, data, sz, 0, 0xffffffffu, typ); - if ((rv == 0) && (ep != NULL)) { + if ((rv = nni_copyin_size(&val, data, sz, 0, NNI_MAXSZ, t)) == 0) { ep->ze_rcvmax = val; } return (rv); } static int -zt_ep_getopt_recvmaxsz(void *arg, void *data, size_t *szp, int typ) +zt_ep_get_recvmaxsz(void *arg, void *data, size_t *szp, nni_opt_type t) { zt_ep *ep = arg; - return (nni_copyout_size(ep->ze_rcvmax, data, szp, typ)); + return (nni_copyout_size(ep->ze_rcvmax, data, szp, t)); } static int -zt_ep_setopt_home(void *arg, const void *data, size_t sz, int typ) +zt_ep_chk_string(const void *data, size_t sz, nni_opt_type t) { size_t len; - int rv; - zt_ep *ep = arg; - if ((typ != NNI_TYPE_OPAQUE) && (typ != NNI_TYPE_STRING)) { + if ((t != NNI_TYPE_OPAQUE) && (t != NNI_TYPE_STRING)) { return (NNG_EBADTYPE); } - len = nni_strnlen(data, sz); if ((len >= sz) || (len >= NNG_MAXADDRLEN)) { return (NNG_EINVAL); } - if (ep != NULL) { + return (0); +} + +static int +zt_ep_set_home(void *arg, const void *data, size_t sz, nni_opt_type t) +{ + int rv; + zt_ep *ep = arg; + + if ((rv = zt_ep_chk_string(data, sz, t)) == 0) { if (ep->ze_running) { - return (NNG_ESTATE); - } - nni_mtx_lock(&zt_lk); - nni_strlcpy(ep->ze_home, data, sizeof(ep->ze_home)); - if ((rv = zt_node_find(ep)) != 0) { - ep->ze_ztn = NULL; + rv = NNG_ESTATE; + } else { + nni_mtx_lock(&zt_lk); + nni_strlcpy(ep->ze_home, data, sizeof(ep->ze_home)); + if ((rv = zt_node_find(ep)) != 0) { + ep->ze_ztn = NULL; + } + nni_mtx_unlock(&zt_lk); } - nni_mtx_unlock(&zt_lk); - } else { - rv = 0; } + return (rv); } static int -zt_ep_getopt_home(void *arg, void *data, size_t *szp, int typ) +zt_ep_get_home(void *arg, void *data, size_t *szp, nni_opt_type t) { zt_ep *ep = arg; - return (nni_copyout_str(ep->ze_home, data, szp, typ)); + return (nni_copyout_str(ep->ze_home, data, szp, t)); } static int -zt_ep_getopt_url(void *arg, void *data, size_t *szp, int typ) +zt_ep_get_url(void *arg, void *data, size_t *szp, nni_opt_type t) { char ustr[64]; // more than plenty zt_ep * ep = arg; @@ -2644,18 +2656,14 @@ zt_ep_getopt_url(void *arg, void *data, size_t *szp, int typ) (unsigned long long) addr >> zt_port_shift, (unsigned long long) ep->ze_nwid, (unsigned) (addr & zt_port_mask)); - return (nni_copyout_str(ustr, data, szp, typ)); + return (nni_copyout_str(ustr, data, szp, t)); } static int -zt_ep_setopt_orbit(void *arg, const void *data, size_t sz, int typ) +zt_ep_chk_orbit(const void *data, size_t sz, nni_opt_type t) { - uint64_t moonid; - uint64_t peerid; - zt_ep * ep = arg; - enum ZT_ResultCode zrv; - - switch (typ) { + NNI_ARG_UNUSED(data); + switch (t) { case NNI_TYPE_UINT64: NNI_ASSERT(sz == sizeof(uint64_t)); break; @@ -2668,6 +2676,21 @@ zt_ep_setopt_orbit(void *arg, const void *data, size_t sz, int typ) default: return (NNG_EBADTYPE); } + return (0); +} + +static int +zt_ep_set_orbit(void *arg, const void *data, size_t sz, nni_opt_type t) +{ + uint64_t moonid; + uint64_t peerid; + zt_ep * ep = arg; + int rv; + enum ZT_ResultCode zrv; + + if ((rv = zt_ep_chk_orbit(data, sz, t)) != 0) { + return (rv); + } if (sz == sizeof(uint64_t)) { memcpy(&moonid, data, sizeof(moonid)); @@ -2687,15 +2710,20 @@ zt_ep_setopt_orbit(void *arg, const void *data, size_t sz, int typ) } static int -zt_ep_setopt_deorbit(void *arg, const void *data, size_t sz, int typ) +zt_ep_chk_deorbit(const void *data, size_t sz, nni_opt_type t) +{ + return (nni_copyin_u64(NULL, data, sz, t)); +} + +static int +zt_ep_set_deorbit(void *arg, const void *data, size_t sz, nni_opt_type t) { uint64_t moonid; zt_ep * ep = arg; enum ZT_ResultCode zrv; int rv; - rv = nni_copyin_u64(&moonid, data, sz, typ); - if ((rv == 0) && (ep != NULL)) { + if ((rv = nni_copyin_u64(&moonid, data, sz, t)) == 0) { nni_mtx_lock(&zt_lk); zrv = ZT_Node_deorbit(ep->ze_ztn->zn_znode, NULL, moonid); @@ -2707,117 +2735,127 @@ zt_ep_setopt_deorbit(void *arg, const void *data, size_t sz, int typ) } static int -zt_ep_getopt_node(void *arg, void *data, size_t *szp, int typ) +zt_ep_get_node(void *arg, void *data, size_t *szp, nni_opt_type t) { zt_ep *ep = arg; - return (nni_copyout_u64(ep->ze_ztn->zn_self, data, szp, typ)); + return (nni_copyout_u64(ep->ze_ztn->zn_self, data, szp, t)); } static int -zt_ep_getopt_nwid(void *arg, void *data, size_t *szp, int typ) +zt_ep_get_nwid(void *arg, void *data, size_t *szp, nni_opt_type t) { zt_ep *ep = arg; - return (nni_copyout_u64(ep->ze_nwid, data, szp, typ)); + return (nni_copyout_u64(ep->ze_nwid, data, szp, t)); } static int -zt_ep_getopt_nw_name(void *arg, void *buf, size_t *szp, int typ) +zt_ep_get_nw_name(void *arg, void *buf, size_t *szp, nni_opt_type t) { zt_ep *ep = arg; - return (zt_getopt_nw_name(ep->ze_ztn, ep->ze_nwid, buf, szp, typ)); + return (zt_get_nw_name(ep->ze_ztn, ep->ze_nwid, buf, szp, t)); } static int -zt_ep_getopt_nw_status(void *arg, void *buf, size_t *szp, int typ) +zt_ep_get_nw_status(void *arg, void *buf, size_t *szp, nni_opt_type t) { zt_ep *ep = arg; - return (zt_getopt_nw_status(ep->ze_ztn, ep->ze_nwid, buf, szp, typ)); + return (zt_get_nw_status(ep->ze_ztn, ep->ze_nwid, buf, szp, t)); } static int -zt_ep_setopt_ping_time(void *arg, const void *data, size_t sz, int typ) +zt_ep_chk_time(const void *data, size_t sz, nni_opt_type t) +{ + return (nni_copyin_ms(NULL, data, sz, t)); +} + +static int +zt_ep_set_ping_time(void *arg, const void *data, size_t sz, nni_opt_type t) { zt_ep * ep = arg; nng_duration val; int rv; - if (((rv = nni_copyin_ms(&val, data, sz, typ)) == 0) && (ep != NULL)) { + if ((rv = nni_copyin_ms(&val, data, sz, t)) == 0) { ep->ze_ping_time = val; } return (rv); } static int -zt_ep_getopt_ping_time(void *arg, void *data, size_t *szp, int typ) +zt_ep_get_ping_time(void *arg, void *data, size_t *szp, nni_opt_type t) { zt_ep *ep = arg; - return (nni_copyout_ms(ep->ze_ping_time, data, szp, typ)); + return (nni_copyout_ms(ep->ze_ping_time, data, szp, t)); +} + +static int +zt_ep_chk_tries(const void *data, size_t sz, nni_opt_type t) +{ + return (nni_copyin_int(NULL, data, sz, 0, 1000000, t)); } static int -zt_ep_setopt_ping_tries(void *arg, const void *data, size_t sz, int typ) +zt_ep_set_ping_tries(void *arg, const void *data, size_t sz, nni_opt_type t) { zt_ep *ep = arg; int val; int rv; - if (((rv = nni_copyin_int(&val, data, sz, 0, 1000000, typ)) == 0) && - (ep != NULL)) { + if ((rv = nni_copyin_int(&val, data, sz, 0, 1000000, t)) == 0) { ep->ze_ping_tries = val; } return (rv); } static int -zt_ep_getopt_ping_tries(void *arg, void *data, size_t *szp, int typ) +zt_ep_get_ping_tries(void *arg, void *data, size_t *szp, nni_opt_type t) { zt_ep *ep = arg; - return (nni_copyout_int(ep->ze_ping_tries, data, szp, typ)); + return (nni_copyout_int(ep->ze_ping_tries, data, szp, t)); } static int -zt_ep_setopt_conn_time(void *arg, const void *data, size_t sz, int typ) +zt_ep_set_conn_time(void *arg, const void *data, size_t sz, nni_opt_type t) { zt_ep * ep = arg; nng_duration val; int rv; - if (((rv = nni_copyin_ms(&val, data, sz, typ)) == 0) && (ep != NULL)) { + if ((rv = nni_copyin_ms(&val, data, sz, t)) == 0) { ep->ze_conn_time = val; } return (rv); } static int -zt_ep_getopt_conn_time(void *arg, void *data, size_t *szp, int typ) +zt_ep_get_conn_time(void *arg, void *data, size_t *szp, nni_opt_type t) { zt_ep *ep = arg; - return (nni_copyout_ms(ep->ze_conn_time, data, szp, typ)); + return (nni_copyout_ms(ep->ze_conn_time, data, szp, t)); } static int -zt_ep_setopt_conn_tries(void *arg, const void *data, size_t sz, int typ) +zt_ep_set_conn_tries(void *arg, const void *data, size_t sz, nni_opt_type t) { zt_ep *ep = arg; int val; int rv; - if (((rv = nni_copyin_int(&val, data, sz, 0, 1000000, typ)) == 0) && - (ep != NULL)) { + if ((rv = nni_copyin_int(&val, data, sz, 0, 1000000, t)) == 0) { ep->ze_conn_tries = val; } return (rv); } static int -zt_ep_getopt_conn_tries(void *arg, void *data, size_t *szp, int typ) +zt_ep_get_conn_tries(void *arg, void *data, size_t *szp, nni_opt_type t) { zt_ep *ep = arg; - return (nni_copyout_int(ep->ze_conn_tries, data, szp, typ)); + return (nni_copyout_int(ep->ze_conn_tries, data, szp, t)); } static int -zt_pipe_getopt_locaddr(void *arg, void *data, size_t *szp, int typ) +zt_pipe_get_locaddr(void *arg, void *data, size_t *szp, nni_opt_type t) { zt_pipe * p = arg; nng_sockaddr sa; @@ -2827,11 +2865,11 @@ zt_pipe_getopt_locaddr(void *arg, void *data, size_t *szp, int typ) sa.s_zt.sa_nwid = p->zp_nwid; sa.s_zt.sa_nodeid = p->zp_laddr >> zt_port_shift; sa.s_zt.sa_port = p->zp_laddr & zt_port_mask; - return (nni_copyout_sockaddr(&sa, data, szp, typ)); + return (nni_copyout_sockaddr(&sa, data, szp, t)); } static int -zt_pipe_getopt_remaddr(void *arg, void *data, size_t *szp, int typ) +zt_pipe_get_remaddr(void *arg, void *data, size_t *szp, nni_opt_type t) { zt_pipe * p = arg; nng_sockaddr sa; @@ -2841,50 +2879,50 @@ zt_pipe_getopt_remaddr(void *arg, void *data, size_t *szp, int typ) sa.s_zt.sa_nwid = p->zp_nwid; sa.s_zt.sa_nodeid = p->zp_raddr >> zt_port_shift; sa.s_zt.sa_port = p->zp_raddr & zt_port_mask; - return (nni_copyout_sockaddr(&sa, data, szp, typ)); + return (nni_copyout_sockaddr(&sa, data, szp, t)); } static int -zt_pipe_getopt_mtu(void *arg, void *data, size_t *szp, int typ) +zt_pipe_get_mtu(void *arg, void *data, size_t *szp, nni_opt_type t) { zt_pipe *p = arg; - return (nni_copyout_size(p->zp_mtu, data, szp, typ)); + return (nni_copyout_size(p->zp_mtu, data, szp, t)); } -static nni_tran_pipe_option zt_pipe_options[] = { +static nni_tran_option zt_pipe_options[] = { { - .po_name = NNG_OPT_LOCADDR, - .po_type = NNI_TYPE_SOCKADDR, - .po_getopt = zt_pipe_getopt_locaddr, + .o_name = NNG_OPT_LOCADDR, + .o_type = NNI_TYPE_SOCKADDR, + .o_get = zt_pipe_get_locaddr, }, { - .po_name = NNG_OPT_REMADDR, - .po_type = NNI_TYPE_SOCKADDR, - .po_getopt = zt_pipe_getopt_remaddr, + .o_name = NNG_OPT_REMADDR, + .o_type = NNI_TYPE_SOCKADDR, + .o_get = zt_pipe_get_remaddr, }, { - .po_name = NNG_OPT_ZT_MTU, - .po_type = NNI_TYPE_SIZE, - .po_getopt = zt_pipe_getopt_mtu, + .o_name = NNG_OPT_ZT_MTU, + .o_type = NNI_TYPE_SIZE, + .o_get = zt_pipe_get_mtu, }, { - .po_name = NNG_OPT_ZT_NWID, - .po_type = NNI_TYPE_UINT64, - .po_getopt = zt_pipe_get_nwid, + .o_name = NNG_OPT_ZT_NWID, + .o_type = NNI_TYPE_UINT64, + .o_get = zt_pipe_get_nwid, }, { - .po_name = NNG_OPT_ZT_NODE, - .po_type = NNI_TYPE_UINT64, - .po_getopt = zt_pipe_get_node, + .o_name = NNG_OPT_ZT_NODE, + .o_type = NNI_TYPE_UINT64, + .o_get = zt_pipe_get_node, }, { - .po_name = NNG_OPT_RECVMAXSZ, - .po_type = NNI_TYPE_SIZE, - .po_getopt = zt_pipe_get_recvmaxsz, + .o_name = NNG_OPT_RECVMAXSZ, + .o_type = NNI_TYPE_SIZE, + .o_get = zt_pipe_get_recvmaxsz, }, // terminate list { - .po_name = NULL, + .o_name = NULL, }, }; @@ -2898,88 +2936,89 @@ static nni_tran_pipe_ops zt_pipe_ops = { .p_options = zt_pipe_options, }; -static nni_tran_ep_option zt_ep_options[] = { +static nni_tran_option zt_ep_options[] = { { - .eo_name = NNG_OPT_RECVMAXSZ, - .eo_type = NNI_TYPE_SIZE, - .eo_getopt = zt_ep_getopt_recvmaxsz, - .eo_setopt = zt_ep_setopt_recvmaxsz, + .o_name = NNG_OPT_RECVMAXSZ, + .o_type = NNI_TYPE_SIZE, + .o_get = zt_ep_get_recvmaxsz, + .o_set = zt_ep_set_recvmaxsz, + .o_chk = zt_ep_chk_recvmaxsz, }, { - .eo_name = NNG_OPT_URL, - .eo_type = NNI_TYPE_STRING, - .eo_getopt = zt_ep_getopt_url, - .eo_setopt = NULL, + .o_name = NNG_OPT_URL, + .o_type = NNI_TYPE_STRING, + .o_get = zt_ep_get_url, }, { - .eo_name = NNG_OPT_ZT_HOME, - .eo_type = NNI_TYPE_STRING, - .eo_getopt = zt_ep_getopt_home, - .eo_setopt = zt_ep_setopt_home, + .o_name = NNG_OPT_ZT_HOME, + .o_type = NNI_TYPE_STRING, + .o_get = zt_ep_get_home, + .o_set = zt_ep_set_home, + .o_chk = zt_ep_chk_string, }, { - .eo_name = NNG_OPT_ZT_NODE, - .eo_type = NNI_TYPE_UINT64, - .eo_getopt = zt_ep_getopt_node, - .eo_setopt = NULL, + .o_name = NNG_OPT_ZT_NODE, + .o_type = NNI_TYPE_UINT64, + .o_get = zt_ep_get_node, }, { - .eo_name = NNG_OPT_ZT_NWID, - .eo_type = NNI_TYPE_UINT64, - .eo_getopt = zt_ep_getopt_nwid, - .eo_setopt = NULL, + .o_name = NNG_OPT_ZT_NWID, + .o_type = NNI_TYPE_UINT64, + .o_get = zt_ep_get_nwid, }, { - .eo_name = NNG_OPT_ZT_NETWORK_STATUS, - .eo_type = NNI_TYPE_INT32, // enumeration really - .eo_getopt = zt_ep_getopt_nw_status, - .eo_setopt = NULL, + .o_name = NNG_OPT_ZT_NETWORK_STATUS, + .o_type = NNI_TYPE_INT32, // enumeration really + .o_get = zt_ep_get_nw_status, }, { - .eo_name = NNG_OPT_ZT_NETWORK_NAME, - .eo_type = NNI_TYPE_STRING, - .eo_getopt = zt_ep_getopt_nw_name, - .eo_setopt = NULL, + .o_name = NNG_OPT_ZT_NETWORK_NAME, + .o_type = NNI_TYPE_STRING, + .o_get = zt_ep_get_nw_name, }, { - .eo_name = NNG_OPT_ZT_PING_TIME, - .eo_type = NNI_TYPE_DURATION, - .eo_getopt = zt_ep_getopt_ping_time, - .eo_setopt = zt_ep_setopt_ping_time, + .o_name = NNG_OPT_ZT_PING_TIME, + .o_type = NNI_TYPE_DURATION, + .o_get = zt_ep_get_ping_time, + .o_set = zt_ep_set_ping_time, + .o_chk = zt_ep_chk_time, }, { - .eo_name = NNG_OPT_ZT_PING_TRIES, - .eo_type = NNI_TYPE_INT32, - .eo_getopt = zt_ep_getopt_ping_tries, - .eo_setopt = zt_ep_setopt_ping_tries, + .o_name = NNG_OPT_ZT_PING_TRIES, + .o_type = NNI_TYPE_INT32, + .o_get = zt_ep_get_ping_tries, + .o_set = zt_ep_set_ping_tries, + .o_chk = zt_ep_chk_tries, }, { - .eo_name = NNG_OPT_ZT_CONN_TIME, - .eo_type = NNI_TYPE_DURATION, - .eo_getopt = zt_ep_getopt_conn_time, - .eo_setopt = zt_ep_setopt_conn_time, + .o_name = NNG_OPT_ZT_CONN_TIME, + .o_type = NNI_TYPE_DURATION, + .o_get = zt_ep_get_conn_time, + .o_set = zt_ep_set_conn_time, + .o_chk = zt_ep_chk_time, }, { - .eo_name = NNG_OPT_ZT_CONN_TRIES, - .eo_type = NNI_TYPE_INT32, - .eo_getopt = zt_ep_getopt_conn_tries, - .eo_setopt = zt_ep_setopt_conn_tries, + .o_name = NNG_OPT_ZT_CONN_TRIES, + .o_type = NNI_TYPE_INT32, + .o_get = zt_ep_get_conn_tries, + .o_set = zt_ep_set_conn_tries, + .o_chk = zt_ep_chk_tries, }, { - .eo_name = NNG_OPT_ZT_ORBIT, - .eo_type = NNI_TYPE_UINT64, // use opaque for two - .eo_getopt = NULL, - .eo_setopt = zt_ep_setopt_orbit, + .o_name = NNG_OPT_ZT_ORBIT, + .o_type = NNI_TYPE_UINT64, // use opaque for two + .o_set = zt_ep_set_orbit, + .o_chk = zt_ep_chk_orbit, }, { - .eo_name = NNG_OPT_ZT_DEORBIT, - .eo_type = NNI_TYPE_UINT64, - .eo_getopt = NULL, - .eo_setopt = zt_ep_setopt_deorbit, + .o_name = NNG_OPT_ZT_DEORBIT, + .o_type = NNI_TYPE_UINT64, + .o_set = zt_ep_set_deorbit, + .o_chk = zt_ep_chk_deorbit, }, // terminate list { - .eo_name = NULL, + .o_name = NULL, }, }; |
