From 655e7fcacc07dd4f2df3a2afe11b2ca0c751a82c Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Mon, 4 Jan 2021 14:38:35 -0800 Subject: [PATCH] Move isc_socket_getsockname() calls into dispatch We now use dns_dispentry_getlocaladdress(). (this API is likely to be cleaned up further later.) --- lib/dns/dispatch.c | 17 +++++++++++++++++ lib/dns/include/dns/dispatch.h | 16 +++++++++++++++- lib/dns/resolver.c | 15 ++++++--------- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/lib/dns/dispatch.c b/lib/dns/dispatch.c index 2f65f7d4c7..24cb01fe6a 100644 --- a/lib/dns/dispatch.c +++ b/lib/dns/dispatch.c @@ -2678,6 +2678,23 @@ dns_dispatch_getlocaladdress(dns_dispatch_t *disp, isc_sockaddr_t *addrp) { return (ISC_R_NOTIMPLEMENTED); } +isc_result_t +dns_dispentry_getlocaladdress(dns_dispentry_t *resp, isc_sockaddr_t *addrp) { + REQUIRE(VALID_RESPONSE(resp)); + REQUIRE(addrp != NULL); + + if (resp->disp->socktype == isc_sockettype_tcp) { + return (isc_socket_getsockname(resp->disp->socket, addrp)); + } + + if (resp->dispsocket != NULL) { + return (isc_socket_getsockname(resp->dispsocket->socket, + addrp)); + } + + return (ISC_R_NOTIMPLEMENTED); +} + unsigned int dns_dispatch_getattributes(dns_dispatch_t *disp) { REQUIRE(VALID_DISPATCH(disp)); diff --git a/lib/dns/include/dns/dispatch.h b/lib/dns/include/dns/dispatch.h index 2854a7bcb6..7ce569111b 100644 --- a/lib/dns/include/dns/dispatch.h +++ b/lib/dns/include/dns/dispatch.h @@ -374,7 +374,21 @@ dns_dispatch_getlocaladdress(dns_dispatch_t *disp, isc_sockaddr_t *addrp); * * Requires: *\li disp is valid. - *\li addrp to be non null. + *\li addrp to be non NULL. + * + * Returns: + *\li ISC_R_SUCCESS + *\li ISC_R_NOTIMPLEMENTED + */ + +isc_result_t +dns_dispentry_getlocaladdress(dns_dispentry_t *resp, isc_sockaddr_t *addrp); +/*%< + * Return the local address for this dispatch entry. + * + * Requires: + *\li resp is valid. + *\li addrp to be non NULL. * * Returns: *\li ISC_R_SUCCESS diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c index 59079b0c5f..c011dabae7 100644 --- a/lib/dns/resolver.c +++ b/lib/dns/resolver.c @@ -2370,7 +2370,7 @@ resquery_send(resquery_t *query) { isc_region_t r; dns_resolver_t *res = NULL; isc_task_t *task; - isc_socket_t *sock; + isc_socket_t *sock = NULL; isc_buffer_t tcpbuffer; isc_sockaddr_t *address = NULL; isc_buffer_t *buffer = NULL; @@ -2849,7 +2849,7 @@ resquery_send(resquery_t *query) { dtmsgtype = DNS_DTTYPE_RQ; } - result = isc_socket_getsockname(sock, &localaddr); + result = dns_dispentry_getlocaladdress(query->dispentry, &localaddr); if (result == ISC_R_SUCCESS) { la = &localaddr; } @@ -9801,7 +9801,6 @@ rctx_logpacket(respctx_t *rctx) { #ifdef HAVE_DNSTAP isc_result_t result; fetchctx_t *fctx = rctx->fctx; - isc_socket_t *sock = NULL; isc_sockaddr_t localaddr, *la = NULL; unsigned char zone[DNS_NAME_MAXWIRE]; dns_dtmsgtype_t dtmsgtype; @@ -9838,12 +9837,10 @@ rctx_logpacket(respctx_t *rctx) { dtmsgtype = DNS_DTTYPE_RR; } - sock = dns_dispatch_getentrysocket(rctx->query); - if (sock != NULL) { - result = isc_socket_getsockname(sock, &localaddr); - if (result == ISC_R_SUCCESS) { - la = &localaddr; - } + result = dns_dispentry_getlocaladdress(rctx->query->dispentry, + &localaddr); + if (result == ISC_R_SUCCESS) { + la = &localaddr; } dns_dt_send(fctx->res->view, dtmsgtype, la,