]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: resolvers: new function find_srvrq_answer_record()
authorBaptiste Assmann <bedis9@gmail.com>
Wed, 10 Mar 2021 11:22:18 +0000 (12:22 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 12 Mar 2021 16:41:28 +0000 (17:41 +0100)
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.

include/haproxy/resolvers.h
src/resolvers.c

index 342c1f199d9f055c1d404489ceada52eaad52415..7dc8819cabdb731381b9729ed995ffdaeaf1b3ce 100644 (file)
@@ -31,6 +31,7 @@ extern unsigned int resolv_failed_resolutions;
 struct resolvers *find_resolvers_by_id(const char *id);
 struct resolv_srvrq *find_srvrq_by_name(const char *name, struct proxy *px);
 struct resolv_srvrq *new_resolv_srvrq(struct server *srv, char *fqdn);
+struct resolv_answer_item *find_srvrq_answer_record(const struct resolv_requester *requester);
 
 int resolv_str_to_dn_label(const char *str, int str_len, char *dn, int dn_len);
 int resolv_dn_label_to_str(const char *dn, int dn_len, char *str, int str_len);
index 4d960b7be613828bd25de840f73c2c51b992f32d..66712dd98a6411a22d52e0dc7d4f62613dfd650a 100644 (file)
@@ -224,6 +224,37 @@ struct resolv_srvrq *new_resolv_srvrq(struct server *srv, char *fqdn)
 }
 
 
+/* 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 resolv_answer_item *find_srvrq_answer_record(const struct resolv_requester *requester)
+{
+       struct resolv_resolution *res;
+       struct resolv_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->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 (resolv_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 resolv_rnd16(void)
 {