From b0865b5366e9cda605bdbf17320a238b864bb159 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Thu, 24 Jun 2021 15:16:48 +0200 Subject: [PATCH] BUG/MINOR: resolvers: Always attach server on matching record on resolution On A/AAAA resolution, for a given server, if a record is matching, we must always attach the server to this record. Before it was only done if the server IP was not the same than the record one. However, it is a problem if the server IP was not set for a previous resolution. From the libc during startup for instance. In this case, the server IP is not updated and the server is not attached to any record. It remains in this state while a matching record is found in the DNS response. It is especially a problem when the resolution is used for server-templates. This bug was introduced by the commit bd78c912f ("MEDIUM: resolvers: add a ref on server to the used A/AAAA answer item"). This patch should solve the issue #1305. It must be backported to all versions containing the above commit. (cherry picked from commit d7bb23490c1a71542c7e98b7c44d92df081c7e52) Signed-off-by: Christopher Faulet (cherry picked from commit 2558d5aac1147b6e5c028152fc5382492dc6807c) [cf: Changes applied in src/dns.c instead of src/resolvers.c] Signed-off-by: Christopher Faulet --- src/dns.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/dns.c b/src/dns.c index d00288d..947674f 100644 --- a/src/dns.c +++ b/src/dns.c @@ -1640,8 +1640,6 @@ int dns_get_ip_from_response(struct dns_response_packet *dns_p, *newip = newip6; *newip_sin_family = AF_INET6; } - if (!currentip_found) - goto not_found; } /* Case when the caller looks first for an IPv6 address */ else if (family_priority == AF_INET6) { @@ -1653,8 +1651,6 @@ int dns_get_ip_from_response(struct dns_response_packet *dns_p, *newip = newip4; *newip_sin_family = AF_INET; } - if (!currentip_found) - goto not_found; } /* Case when the caller have no preference (we prefer IPv6) */ else if (family_priority == AF_UNSPEC) { @@ -1666,17 +1662,11 @@ int dns_get_ip_from_response(struct dns_response_packet *dns_p, *newip = newip4; *newip_sin_family = AF_INET; } - if (!currentip_found) - goto not_found; } - /* No reason why we should change the server's IP address */ - return DNS_UPD_NO; - - not_found: - /* the ip of this record was chosen for the server */ if (owner && found_record) { + LIST_DEL_INIT(&owner->ip_rec_item); LIST_ADDQ(&found_record->attached_servers, &owner->ip_rec_item); } @@ -1687,7 +1677,8 @@ int dns_get_ip_from_response(struct dns_response_packet *dns_p, LIST_ADDQ(&dns_p->answer_list, &record->list); break; } - return DNS_UPD_SRVIP_NOT_FOUND; + + return (currentip_found ? DNS_UPD_NO : DNS_UPD_SRVIP_NOT_FOUND); } /* Turns a domain name label into a string. -- 1.7.10.4