From 72d3bf8e4ed9c9ad189141e191ce1bcb2d3b9190 Mon Sep 17 00:00:00 2001 From: Matthijs Mekking Date: Wed, 26 Oct 2022 09:55:55 +0200 Subject: [PATCH] Fix config bug related to port setting There are three levels there for the port value, with increasing priority: 1. The default ports, defined by 'port' and 'tls-port' config options. 2. The primaries-level default port: primaries port { ... }; 3. The primaries element-level port: primaries {
port ; ... };" In 'named_config_getipandkeylist()', the 'def_port' and 'def_tlsport' variables are extracted from level 1. The 'port' variable is extracted from the level 2. Currently if that is unset, it defaults to the default port ('def_port' or 'def_tlsport' depending on the transport used), but overrides the level 2 port setting for the next primaries in the list. Update the code such that we inherit the port only if the level 3 port is not set, and inherit from the default ports if the level 2 port is also not set. --- bin/named/config.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/bin/named/config.c b/bin/named/config.c index 4837a1e19b..347b078498 100644 --- a/bin/named/config.c +++ b/bin/named/config.c @@ -866,18 +866,22 @@ resume: goto cleanup; } - /* Set the default port or tls-port */ - if (port == 0) { - if (tlss[i] != NULL) { - port = def_tlsport; - } else { - port = def_port; + /* If the port is unset, take it from one of the upper levels */ + if (isc_sockaddr_getport(&addrs[i]) == 0) { + in_port_t addr_port = port; + + /* If unset, use the default port or tls-port */ + if (addr_port == 0) { + if (tlss[i] != NULL) { + addr_port = def_tlsport; + } else { + addr_port = def_port; + } } + + isc_sockaddr_setport(&addrs[i], addr_port); } - if (isc_sockaddr_getport(&addrs[i]) == 0) { - isc_sockaddr_setport(&addrs[i], port); - } i++; } if (pushed != 0) {