diff options
| author | Garrett D'Amore <garrett@damore.org> | 2020-11-01 22:05:35 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2020-11-08 17:50:24 -0800 |
| commit | fc6882305f0b5e06e58a0a25740f422d133015b5 (patch) | |
| tree | 714b1fa4656253c8731a8f3f0861c24715440f95 /src/platform/posix/posix_ipcdial.c | |
| parent | 4bf06d03f6ebead7f4e0603a2da3b1b891887878 (diff) | |
| download | nng-fc6882305f0b5e06e58a0a25740f422d133015b5.tar.gz nng-fc6882305f0b5e06e58a0a25740f422d133015b5.tar.bz2 nng-fc6882305f0b5e06e58a0a25740f422d133015b5.zip | |
fixes #1041 Abstract socket address for IPC
fixes #1326 Linux IPC could use fchmod
fixes #1327 getsockname on ipc may not work
This introduces an abstract:// style transport, which on Linux
results in using the abstract socket with the given name (not
including the leading NULL byte). A new NNG_AF_ABSTRACT is
provided. Auto bind abstract sockets are also supported.
While here we have inlined the aios for the POSIX ipc pipe
objects, eliminating at least one set of failure paths, and
have also performed various other cleanups.
A unix:// alias is available on POSIX systems, which acts just
like ipc:// (and is fact just an alias). This is supplied so
that in the future we can add support for AF_UNIX on Windows.
We've also absorbed the ipcperms test into the new ipc_test suite.
Finally we are now enforcing that IPC path names on Windows are
not over the maximum size, rather than just silently truncating
them.
Diffstat (limited to 'src/platform/posix/posix_ipcdial.c')
| -rw-r--r-- | src/platform/posix/posix_ipcdial.c | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/src/platform/posix/posix_ipcdial.c b/src/platform/posix/posix_ipcdial.c index 65061767..b25f7340 100644 --- a/src/platform/posix/posix_ipcdial.c +++ b/src/platform/posix/posix_ipcdial.c @@ -178,7 +178,7 @@ ipc_dialer_dial(void *arg, nni_aio *aio) nni_atomic_inc64(&d->ref); - if ((rv = nni_posix_ipc_alloc(&c, d)) != 0) { + if ((rv = nni_posix_ipc_alloc(&c, &d->sa, d)) != 0) { (void) close(fd); nni_posix_ipc_dialer_rele(d); nni_aio_finish_error(aio, rv); @@ -263,20 +263,46 @@ int nni_ipc_dialer_alloc(nng_stream_dialer **dp, const nng_url *url) { ipc_dialer *d; + size_t len; - if ((strcmp(url->u_scheme, "ipc") != 0) || (url->u_path == NULL) || - (strlen(url->u_path) == 0) || - (strlen(url->u_path) >= NNG_MAXADDRLEN)) { - return (NNG_EADDRINVAL); - } if ((d = NNI_ALLOC_STRUCT(d)) == NULL) { return (NNG_ENOMEM); } + + if ((strcmp(url->u_scheme, "ipc") == 0) || + (strcmp(url->u_scheme, "unix") == 0)) { + if ((url->u_path == NULL) || + ((len = strlen(url->u_path)) == 0) || + (len > NNG_MAXADDRLEN)) { + NNI_FREE_STRUCT(d); + return (NNG_EADDRINVAL); + } + d->sa.s_ipc.sa_family = NNG_AF_IPC; + nni_strlcpy(d->sa.s_ipc.sa_path, url->u_path, NNG_MAXADDRLEN); + +#ifdef NNG_HAVE_ABSTRACT_SOCKETS + } else if (strcmp(url->u_scheme, "abstract") == 0) { + + // path is url encoded. + len = nni_url_decode(d->sa.s_abstract.sa_name, url->u_path, + sizeof(d->sa.s_abstract.sa_name)); + if (len == (size_t) -1) { + NNI_FREE_STRUCT(d); + return (NNG_EADDRINVAL); + } + + d->sa.s_abstract.sa_family = NNG_AF_ABSTRACT; + d->sa.s_abstract.sa_len = len; +#endif + + } else { + NNI_FREE_STRUCT(d); + return (NNG_EADDRINVAL); + } + nni_mtx_init(&d->mtx); nni_aio_list_init(&d->connq); - d->closed = false; - d->sa.s_ipc.sa_family = NNG_AF_IPC; - strcpy(d->sa.s_ipc.sa_path, url->u_path); + d->closed = false; d->sd.sd_free = ipc_dialer_free; d->sd.sd_close = ipc_dialer_close; d->sd.sd_dial = ipc_dialer_dial; |
