MINOR: resolvers: Use a function to remove answers attached to a resolution
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 10 Mar 2021 13:40:39 +0000 (14:40 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 9 Apr 2021 14:02:18 +0000 (16:02 +0200)
resolv_purge_resolution_answer_records() must be used to removed all answers
attached to a resolution. For now, it is only used when a resolution is
released.

(cherry picked from commit 1dec5c793474027ddffbfca3849e5ca4e9e51083)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 656b42714a05e578c0480f1751a065d8e96f8f3a)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 67cc9a6dc2d6cdf0686c36178440a6c4236ac5f3)
[cf: Must be backported as far as 2.0 because of recent changes on resolvers]
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

include/proto/dns.h
src/dns.c

index 7ce5a09..19159d6 100644 (file)
@@ -42,6 +42,7 @@ int dns_get_ip_from_response(struct dns_response_packet *dns_p,
                              void **newip, short *newip_sin_family,
                              void *owner);
 
+void dns_purge_resolution_answer_records(struct dns_resolution *resolution);
 int dns_link_resolution(void *requester, int requester_type, int requester_locked);
 void dns_unlink_resolution(struct dns_requester *requester);
 void dns_trigger_resolution(struct dns_requester *requester);
index a04e137..6ec246c 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
@@ -1350,11 +1350,20 @@ static struct dns_resolution *dns_pick_resolution(struct dns_resolvers *resolver
        return res;
 }
 
+void dns_purge_resolution_answer_records(struct dns_resolution *resolution)
+{
+       struct dns_answer_item *item, *itemback;
+
+       list_for_each_entry_safe(item, itemback, &resolution->response.answer_list, list) {
+               LIST_DEL(&item->list);
+               pool_free(dns_answer_item_pool, item);
+       }
+}
+
 /* Releases a resolution from its requester(s) and move it back to the pool */
 static void dns_free_resolution(struct dns_resolution *resolution)
 {
        struct dns_requester *req, *reqback;
-       struct dns_answer_item *item, *itemback;
 
        /* clean up configuration */
        dns_reset_resolution(resolution);
@@ -1366,11 +1375,7 @@ static void dns_free_resolution(struct dns_resolution *resolution)
                req->resolution = NULL;
        }
 
-       list_for_each_entry_safe(item, itemback, &resolution->response.answer_list, list) {
-               LIST_DEL(&item->list);
-               pool_free(dns_answer_item_pool, item);
-       }
-
+       dns_purge_resolution_answer_records(resolution);
        LIST_DEL(&resolution->list);
        pool_free(dns_resolution_pool, resolution);
 }