MINOR: resolvers: Add function to change the srv status based on SRV resolution
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 11 Mar 2021 17:03:21 +0000 (18:03 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 9 Apr 2021 14:02:30 +0000 (16:02 +0200)
srvrq_update_srv_status() update the server status based on result of SRV
resolution. For now, it is only used from snr_update_srv_status() when
appropriate.

(cherry picked from commit 5efdef24c1753d7a68d1f6c8dc8cb6b4b84a3361)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 6d70368ab146925a9b2eae3963c5d92c00abe05d)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit d938bd528e3fa172f984cec4b8d7ae92dbb908a6)
[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/server.h
src/server.c

index eaf4907..4e0c242 100644 (file)
@@ -60,6 +60,7 @@ struct server *cli_find_server(struct appctx *appctx, char *arg);
 struct server *new_server(struct proxy *proxy);
 
 /* functions related to server name resolution */
+int srvrq_update_srv_status(struct server *s, int has_no_ip);
 int snr_update_srv_status(struct server *s, int has_no_ip);
 const char *update_server_fqdn(struct server *server, const char *fqdn, const char *updater, int dns_locked);
 int snr_resolution_cb(struct dns_requester *requester, struct dns_nameserver *nameserver);
index 44d29ed..771dcbc 100644 (file)
@@ -3968,6 +3968,31 @@ out:
        return msg->area;
 }
 
+/*
+ * update server status based on result of SRV resolution
+ * returns:
+ *  0 if server status is updated
+ *  1 if server status has not changed
+ *
+ * Must be called with the server lock held.
+ */
+int srvrq_update_srv_status(struct server *s, int has_no_ip)
+{
+       if (!s->srvrq)
+               return 1;
+
+       /* since this server has an IP, it can go back in production */
+       if (has_no_ip == 0) {
+               srv_clr_admin_flag(s, SRV_ADMF_RMAINT);
+               return 1;
+       }
+
+       if (s->next_admin & SRV_ADMF_RMAINT)
+               return 1;
+
+       srv_set_admin_flag(s, SRV_ADMF_RMAINT, "entry removed from SRV record");
+       return 0;
+}
 
 /*
  * update server status based on result of name resolution
@@ -3984,19 +4009,8 @@ int snr_update_srv_status(struct server *s, int has_no_ip)
        int exp;
 
        /* If resolution is NULL we're dealing with SRV records Additional records */
-       if (resolution == NULL) {
-               /* since this server has an IP, it can go back in production */
-               if (has_no_ip == 0) {
-                       srv_clr_admin_flag(s, SRV_ADMF_RMAINT);
-                       return 1;
-               }
-
-               if (s->next_admin & SRV_ADMF_RMAINT)
-                       return 1;
-
-               srv_set_admin_flag(s, SRV_ADMF_RMAINT, "entry removed from SRV record");
-               return 0;
-       }
+       if (resolution == NULL)
+               return srvrq_update_srv_status(s, has_no_ip);
 
        switch (resolution->status) {
                case RSLV_STATUS_NONE: