diff options
| author | Garrett D'Amore <garrett@damore.org> | 2024-11-17 13:34:58 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2024-11-17 13:34:58 -0800 |
| commit | ff66ec5f43547abc78b22ebcdfad32e2775bc9cb (patch) | |
| tree | f92d0ad15cbb1ee8470226a436ef0403c9d49b2e /src/sp/transport/tcp/tcp.c | |
| parent | 48d0c0340f16b580443b3aba53c8bf618572fa6a (diff) | |
| download | nng-ff66ec5f43547abc78b22ebcdfad32e2775bc9cb.tar.gz nng-ff66ec5f43547abc78b22ebcdfad32e2775bc9cb.tar.bz2 nng-ff66ec5f43547abc78b22ebcdfad32e2775bc9cb.zip | |
tcp/tls: Remove support for local interface address in dialer URLs
This was an undocumented capability provided for libnanomsg. The
correct way to obtain the same functionality is to use `NNG_OPT_LOCADDR`.
Diffstat (limited to 'src/sp/transport/tcp/tcp.c')
| -rw-r--r-- | src/sp/transport/tcp/tcp.c | 79 |
1 files changed, 4 insertions, 75 deletions
diff --git a/src/sp/transport/tcp/tcp.c b/src/sp/transport/tcp/tcp.c index 437001f6..54d31726 100644 --- a/src/sp/transport/tcp/tcp.c +++ b/src/sp/transport/tcp/tcp.c @@ -724,65 +724,6 @@ tcptran_ep_close(void *arg) nni_mtx_unlock(&ep->mtx); } -// This parses off the optional source address that this transport uses. -// The special handling of this URL format is quite honestly an historical -// mistake, which we would remove if we could. -static int -tcptran_url_parse_source(nng_url *url, nng_sockaddr *sa, const nng_url *surl) -{ - int af; - char *semi; - char *src; - size_t len; - int rv; - nni_aio *aio; - - // We modify the URL. This relies on the fact that the underlying - // transport does not free this, so we can just use references. - - url->u_scheme = surl->u_scheme; - url->u_port = surl->u_port; - url->u_hostname = surl->u_hostname; - - if ((semi = strchr(url->u_hostname, ';')) == NULL) { - memset(sa, 0, sizeof(*sa)); - return (0); - } - - len = (size_t) (semi - url->u_hostname); - url->u_hostname = semi + 1; - - if (strcmp(surl->u_scheme, "tcp") == 0) { - af = NNG_AF_UNSPEC; - } else if (strcmp(surl->u_scheme, "tcp4") == 0) { - af = NNG_AF_INET; -#ifdef NNG_ENABLE_IPV6 - } else if (strcmp(surl->u_scheme, "tcp6") == 0) { - af = NNG_AF_INET6; -#endif - } else { - return (NNG_EADDRINVAL); - } - - if ((src = nni_alloc(len + 1)) == NULL) { - return (NNG_ENOMEM); - } - memcpy(src, surl->u_hostname, len); - src[len] = '\0'; - - if ((rv = nni_aio_alloc(&aio, NULL, NULL)) != 0) { - nni_free(src, len + 1); - return (rv); - } - - nni_resolv_ip(src, "0", af, true, sa, aio); - nni_aio_wait(aio); - rv = nni_aio_result(aio); - nni_aio_free(aio); - nni_free(src, len + 1); - return (rv); -} - static void tcptran_timer_cb(void *arg) { @@ -923,11 +864,9 @@ tcptran_ep_init(tcptran_ep **epp, nng_url *url, nni_sock *sock) static int tcptran_dialer_init(void **dp, nng_url *url, nni_dialer *ndialer) { - tcptran_ep *ep; - int rv; - nng_sockaddr srcsa; - nni_sock *sock = nni_dialer_sock(ndialer); - nng_url myurl; + tcptran_ep *ep; + int rv; + nni_sock *sock = nni_dialer_sock(ndialer); // Check for invalid URL components. if ((strlen(url->u_path) != 0) && (strcmp(url->u_path, "/") != 0)) { @@ -939,23 +878,13 @@ tcptran_dialer_init(void **dp, nng_url *url, nni_dialer *ndialer) return (NNG_EADDRINVAL); } - if ((rv = tcptran_url_parse_source(&myurl, &srcsa, url)) != 0) { - return (rv); - } - if ((rv = tcptran_ep_init(&ep, url, sock)) != 0) { return (rv); } if ((rv != 0) || ((rv = nni_aio_alloc(&ep->connaio, tcptran_dial_cb, ep)) != 0) || - ((rv = nng_stream_dialer_alloc_url(&ep->dialer, &myurl)) != 0)) { - tcptran_ep_fini(ep); - return (rv); - } - if ((srcsa.s_family != NNG_AF_UNSPEC) && - ((rv = nni_stream_dialer_set(ep->dialer, NNG_OPT_LOCADDR, &srcsa, - sizeof(srcsa), NNI_TYPE_SOCKADDR)) != 0)) { + ((rv = nng_stream_dialer_alloc_url(&ep->dialer, url)) != 0)) { tcptran_ep_fini(ep); return (rv); } |
