From 99348c3fdaa16980757b2b2afc00ec80c059b13d Mon Sep 17 00:00:00 2001 From: Baptiste Assmann Date: Wed, 10 Mar 2021 12:22:18 +0100 Subject: [PATCH] MINOR: resolvers: new function find_srvrq_answer_record() This function search for a SRV answer item associated to a requester whose type is server. This is mainly useful to "link" a server to its SRV record when no additional record were found to configure the IP address. This patch is required by a bug fix. (cherry picked from commit 6a8d11dc8051f4fc40c9ab1266cd58367ea1ca19) Signed-off-by: Christopher Faulet --- include/haproxy/dns.h | 1 + src/dns.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/haproxy/dns.h b/include/haproxy/dns.h index 4f2cb8b..2b232f8 100644 --- a/include/haproxy/dns.h +++ b/include/haproxy/dns.h @@ -31,6 +31,7 @@ extern unsigned int dns_failed_resolutions; struct dns_resolvers *find_resolvers_by_id(const char *id); struct dns_srvrq *find_srvrq_by_name(const char *name, struct proxy *px); struct dns_srvrq *new_dns_srvrq(struct server *srv, char *fqdn); +struct dns_answer_item *find_srvrq_answer_record(const struct dns_requester *requester); int dns_str_to_dn_label(const char *str, int str_len, char *dn, int dn_len); int dns_dn_label_to_str(const char *dn, int dn_len, char *str, int str_len); diff --git a/src/dns.c b/src/dns.c index 4a06c4a..b7f9519 100644 --- a/src/dns.c +++ b/src/dns.c @@ -214,6 +214,36 @@ struct dns_srvrq *new_dns_srvrq(struct server *srv, char *fqdn) return NULL; } +/* finds and return the SRV answer item associated to a requester (whose type is 'server'). + * + * returns NULL in case of error or not found. + */ +struct dns_answer_item *find_srvrq_answer_record(const struct dns_requester *requester) +{ + struct dns_resolution *res; + struct dns_answer_item *item; + struct server *srv; + + if (!requester) + return NULL; + + if ((srv = objt_server(requester->owner)) == NULL) + return NULL; + /* check if the server is managed by a SRV record */ + if (srv->srvrq == NULL) + return NULL; + + res = srv->srvrq->dns_requester->resolution; + /* search an ANSWER record whose target points to the server's hostname and whose port is + * the same as server's svc_port */ + list_for_each_entry(item, &res->response.answer_list, list) { + if (dns_hostname_cmp(srv->hostname_dn, item->target, srv->hostname_dn_len) == 0 && + (srv->svc_port == item->port)) + return item; + } + + return NULL; +} /* 2 bytes random generator to generate DNS query ID */ static inline uint16_t dns_rnd16(void) -- 1.7.10.4