MINOR: dns: dns_requester structures are now in a memory pool

dns_requester structure can be allocated at run time when servers get
associated to DNS resolution (this happens when SRV records are used in
conjunction with service discovery).
Well, this memory allocation is safer if managed in an HAProxy pool,
furthermore with upcoming HTTP action which can perform DNS resolution
at runtime.

This patch moves the memory management of the dns_requester structure
into its own pool.
This commit is contained in:
Baptiste Assmann 2019-01-21 08:18:09 +01:00 committed by Willy Tarreau
parent cd9b9bd3e4
commit dfd35fd71a
2 changed files with 7 additions and 4 deletions

View File

@ -34,6 +34,8 @@
#include <types/server.h>
#include <types/task.h>
extern struct pool_head *dns_requester_pool;
/*DNS maximum values */
/*
* Maximum issued from RFC:

View File

@ -51,6 +51,7 @@ static THREAD_LOCAL int64_t dns_query_id_seed = 0; /* random seed */
DECLARE_STATIC_POOL(dns_answer_item_pool, "dns_answer_item", sizeof(struct dns_answer_item));
DECLARE_STATIC_POOL(dns_resolution_pool, "dns_resolution", sizeof(struct dns_resolution));
DECLARE_POOL(dns_requester_pool, "dns_requester", sizeof(struct dns_requester));
static unsigned int resolution_uuid = 1;
@ -1384,7 +1385,7 @@ int dns_link_resolution(void *requester, int requester_type, int requester_locke
if (!requester_locked)
HA_SPIN_LOCK(SERVER_LOCK, &srv->lock);
if (srv->dns_requester == NULL) {
if ((req = calloc(1, sizeof(*req))) == NULL) {
if ((req = pool_alloc(dns_requester_pool)) == NULL) {
if (!requester_locked)
HA_SPIN_UNLOCK(SERVER_LOCK, &srv->lock);
goto err;
@ -1399,7 +1400,7 @@ int dns_link_resolution(void *requester, int requester_type, int requester_locke
}
else if (srvrq) {
if (srvrq->dns_requester == NULL) {
if ((req = calloc(1, sizeof(*req))) == NULL)
if ((req = pool_alloc(dns_requester_pool)) == NULL)
goto err;
req->owner = &srvrq->obj_type;
srvrq->dns_requester = req;
@ -1826,7 +1827,7 @@ static void dns_deinit(void)
list_for_each_entry_safe(res, resback, &resolvers->resolutions.curr, list) {
list_for_each_entry_safe(req, reqback, &res->requesters, list) {
LIST_DEL(&req->list);
free(req);
pool_free(dns_requester_pool, req);
}
dns_free_resolution(res);
}
@ -1834,7 +1835,7 @@ static void dns_deinit(void)
list_for_each_entry_safe(res, resback, &resolvers->resolutions.wait, list) {
list_for_each_entry_safe(req, reqback, &res->requesters, list) {
LIST_DEL(&req->list);
free(req);
pool_free(dns_requester_pool, req);
}
dns_free_resolution(res);
}