]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: resolve: fix init resolving for ring and peers section.
authorEmeric Brun <ebrun@haproxy.com>
Tue, 21 Jul 2020 14:54:36 +0000 (16:54 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 21 Jul 2020 15:59:20 +0000 (17:59 +0200)
Reported github issue #759 shows there is no name resolving
on server lines for ring and peers sections.

This patch introduce the resolving for those lines.

This patch adds  boolean a parameter to parse_server function to specify
if we want the function to perform an initial name resolving using libc.

This boolean is forced to true in case of peers or ring section.

The boolean is kept to false in case of classic servers (from
backend/listen)

This patch should be backported in branches where peers sections
support 'server' lines.

include/haproxy/server.h
src/cfgparse-listen.c
src/cfgparse.c
src/server.c
src/sink.c

index 0686ab14ce2cf157c1ec6c0e263d6a8123b34cea..269216d30a6b0c11b26b996e9fda83112006f34e 100644 (file)
@@ -43,7 +43,7 @@ extern struct dict server_name_dict;
 int srv_downtime(const struct server *s);
 int srv_lastsession(const struct server *s);
 int srv_getinter(const struct check *check);
-int parse_server(const char *file, int linenum, char **args, struct proxy *curproxy, struct proxy *defproxy, int parse_addr, int in_peers_section);
+int parse_server(const char *file, int linenum, char **args, struct proxy *curproxy, struct proxy *defproxy, int parse_addr, int in_peers_section, int initial_resolve);
 int update_server_addr(struct server *s, void *ip, int ip_sin_family, const char *updater);
 const char *update_server_addr_port(struct server *s, const char *addr, const char *port, char *updater);
 struct server *server_find_by_id(struct proxy *bk, int id);
index df4021d236e6955c9240a3f96a6fbdc744c59739..089c177a9fb7af9a521c8a40558a649b11711c27 100644 (file)
@@ -539,7 +539,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
        if (!strcmp(args[0], "server")         ||
            !strcmp(args[0], "default-server") ||
            !strcmp(args[0], "server-template")) {
-               err_code |= parse_server(file, linenum, args, curproxy, &defproxy, 1, 0);
+               err_code |= parse_server(file, linenum, args, curproxy, &defproxy, 1, 0, 0);
                if (err_code & ERR_FATAL)
                        goto out;
        }
index be36571cd127b9daf22040cb9974d712a2aa1ead..de82a9fd3eb4be0c7326f4ea7321210435c956d3 100644 (file)
@@ -679,7 +679,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
                        err_code |= ERR_ALERT | ERR_ABORT;
                        goto out;
                }
-               err_code |= parse_server(file, linenum, args, curpeers->peers_fe, NULL, 0, 1);
+               err_code |= parse_server(file, linenum, args, curpeers->peers_fe, NULL, 0, 1, 1);
        }
        else if (strcmp(args[0], "log") == 0) {
                if (init_peers_frontend(file, linenum, NULL, curpeers) != 0) {
@@ -788,7 +788,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
                 * The server address is parsed only if we are parsing a "peer" line,
                 * or if we are parsing a "server" line and the current peer is not the local one.
                 */
-               err_code |= parse_server(file, linenum, args, curpeers->peers_fe, NULL, peer || !local_peer, 1);
+               err_code |= parse_server(file, linenum, args, curpeers->peers_fe, NULL, peer || !local_peer, 1, 1);
                if (!curpeers->peers_fe->srv) {
                        /* Remove the newly allocated peer. */
                        if (newpeer != curpeers->local) {
index e682855edb3e7f2095b424d49258cb7e93b8297d..a622e22bda0811d4784cb6a6ebdc1393024217d0 100644 (file)
@@ -1937,7 +1937,8 @@ static int server_template_init(struct server *srv, struct proxy *px)
        return i - srv->tmpl_info.nb_low;
 }
 
-int parse_server(const char *file, int linenum, char **args, struct proxy *curproxy, struct proxy *defproxy, int parse_addr, int in_peers_section)
+int parse_server(const char *file, int linenum, char **args, struct proxy *curproxy,
+                 struct proxy *defproxy, int parse_addr, int in_peers_section, int initial_resolve)
 {
        struct server *newsrv = NULL;
        const char *err = NULL;
@@ -2053,7 +2054,7 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
                        if (!parse_addr)
                                goto skip_addr;
 
-                       sk = str2sa_range(args[cur_arg], &port, &port1, &port2, &errmsg, NULL, &fqdn, 0);
+                       sk = str2sa_range(args[cur_arg], &port, &port1, &port2, &errmsg, NULL, &fqdn, initial_resolve);
                        if (!sk) {
                                ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
                                err_code |= ERR_ALERT | ERR_FATAL;
index 4b5dd5b6e0b75703c02ecb7c1c7644d93f8ba9f1..64bac61743746c2ba9ee926c37cf2fa42620148f 100644 (file)
@@ -802,7 +802,7 @@ int cfg_parse_ring(const char *file, int linenum, char **args, int kwm)
                }
        }
        else if (strcmp(args[0],"server") == 0) {
-               err_code |= parse_server(file, linenum, args, cfg_sink->forward_px, NULL, 1, 0);
+               err_code |= parse_server(file, linenum, args, cfg_sink->forward_px, NULL, 1, 0, 1);
        }
        else if (strcmp(args[0],"timeout") == 0) {
                if (!cfg_sink || !cfg_sink->forward_px) {