From c8e8ccd0262283bede1340451be71a353dafd693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Wed, 5 Apr 2023 15:28:32 +0200 Subject: [PATCH 1/2] Honour the source-port when retrying in dns_dispatch When retrying in the DNS dispatch, the local port would be forgotten on ISC_R_ADDRINUSE, keep the configured source-port even when retrying. Additionally, treat ISC_R_NOPERM same as ISC_R_ADDRINUSE. Closes: #3986 --- lib/dns/dispatch.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/dns/dispatch.c b/lib/dns/dispatch.c index 9e98e10afa..c3006b6501 100644 --- a/lib/dns/dispatch.c +++ b/lib/dns/dispatch.c @@ -1440,7 +1440,7 @@ dns_dispatch_add(dns_dispatch_t *disp, unsigned int options, dns_dispentry_t **respp) { dns_dispentry_t *resp = NULL; dns_qid_t *qid = NULL; - in_port_t dispport, localport = 0; + in_port_t localport; dns_messageid_t id; unsigned int bucket; bool ok = false; @@ -1465,10 +1465,7 @@ dns_dispatch_add(dns_dispatch_t *disp, unsigned int options, qid = disp->mgr->qid; - dispport = isc_sockaddr_getport(&disp->local); - if (dispport != 0) { - localport = dispport; - } + localport = isc_sockaddr_getport(&disp->local); resp = isc_mem_get(disp->mgr->mctx, sizeof(*resp)); *resp = (dns_dispentry_t){ @@ -1943,8 +1940,9 @@ udp_connected(isc_nmhandle_t *handle, isc_result_t eresult, void *arg) { resp->state = DNS_DISPATCHSTATE_CONNECTED; udp_startrecv(handle, resp); break; + case ISC_R_NOPERM: case ISC_R_ADDRINUSE: { - in_port_t localport = 0; + in_port_t localport = isc_sockaddr_getport(&disp->local); isc_result_t result; /* probably a port collision; try a different one */ From 3d36e0bb89521d8bfad017ce4b415aa4cec47b52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Wed, 5 Apr 2023 15:42:05 +0200 Subject: [PATCH 2/2] Add CHANGES note for [GL #3986] --- CHANGES | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGES b/CHANGES index aa518f8a15..1f5d67be2f 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,10 @@ +6152. [bug] In dispatch, honour the configured source-port + selection when UDP connection fails with address + in use error. + + Also treat ISC_R_NOPERM same as ISC_R_ADDRINUSE. + [GL #3986] + 6151. [bug] When the same ``notify-source`` address and port number was configured for multiple destinations and zones, an unresponsive server could tie up the socket until it