]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: standard: avoid DNS resolution from the function str2sa_range()
authorThierry FOURNIER <tfournier@arpalert.org>
Sat, 26 Sep 2015 18:03:36 +0000 (20:03 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 27 Sep 2015 13:04:32 +0000 (15:04 +0200)
This patch blocks the DNS resolution in the function str2sa_range(),
this is useful if the function is used during the HAProxy runtime.

include/common/standard.h
src/cfgparse.c
src/server.c
src/standard.c

index a8e1b995276a6708ec39f63d0c17796b16b61968..d28ab79c8ff912b9ec53c1255601549f114ac69c 100644 (file)
@@ -275,9 +275,10 @@ extern const char *invalid_domainchar(const char *name);
  * The IPv6 '::' address is IN6ADDR_ANY, so in order to bind to a given port on
  * IPv6, use ":::port". NULL is returned if the host part cannot be resolved.
  * If <pfx> is non-null, it is used as a string prefix before any path-based
- * address (typically the path to a unix socket).
+ * address (typically the path to a unix socket). If use_dns is not true,
+ * the funtion cannot accept the DNS resolution.
  */
-struct sockaddr_storage *str2sa_range(const char *str, int *low, int *high, char **err, const char *pfx, char **fqdn);
+struct sockaddr_storage *str2sa_range(const char *str, int *low, int *high, char **err, const char *pfx, char **fqdn, int use_dns);
 
 /* converts <str> to a struct in_addr containing a network mask. It can be
  * passed in dotted form (255.255.255.0) or in CIDR form (24). It returns 1
index 3b7b390858491dc66f8b881fc689801aa5c17e3d..06a2e0da156a2b63d6495393f5a27eb72f79a289 100644 (file)
@@ -240,7 +240,7 @@ int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf,
 
                ss2 = str2sa_range(str, &port, &end, err,
                                   curproxy == global.stats_fe ? NULL : global.unix_bind.prefix,
-                                  NULL);
+                                  NULL, 1);
                if (!ss2)
                        goto fail;
 
@@ -1598,7 +1598,7 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
                        }
                }
 
-               sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL);
+               sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL, 1);
                if (!sk) {
                        Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
                        err_code |= ERR_ALERT | ERR_FATAL;
@@ -2059,7 +2059,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
                newpeer->last_change = now.tv_sec;
                newpeer->id = strdup(args[1]);
 
-               sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL, NULL);
+               sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL, NULL, 1);
                if (!sk) {
                        Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
                        err_code |= ERR_ALERT | ERR_FATAL;
@@ -2259,7 +2259,7 @@ int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm)
                newnameserver->conf.line = linenum;
                newnameserver->id = strdup(args[1]);
 
-               sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL, NULL);
+               sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL, NULL, 1);
                if (!sk) {
                        Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
                        err_code |= ERR_ALERT | ERR_FATAL;
@@ -2443,7 +2443,7 @@ int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm)
 
                newmailer->id = strdup(args[1]);
 
-               sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL, NULL);
+               sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL, NULL, 1);
                if (!sk) {
                        Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
                        err_code |= ERR_ALERT | ERR_FATAL;
@@ -5611,7 +5611,7 @@ stats_error_parsing:
                else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
                        err_code |= ERR_WARN;
 
-               sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL);
+               sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL, 1);
                if (!sk) {
                        Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
                        err_code |= ERR_ALERT | ERR_FATAL;
@@ -5883,7 +5883,7 @@ stats_error_parsing:
                                }
                        }
 
-                       sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL);
+                       sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL, 1);
                        if (!sk) {
                                Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
                                err_code |= ERR_ALERT | ERR_FATAL;
@@ -5935,7 +5935,7 @@ stats_error_parsing:
                curproxy->conn_src.iface_name = NULL;
                curproxy->conn_src.iface_len = 0;
 
-               sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL);
+               sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL, 1);
                if (!sk) {
                        Alert("parsing [%s:%d] : '%s %s' : %s\n",
                              file, linenum, args[0], args[1], errmsg);
@@ -6020,7 +6020,7 @@ stats_error_parsing:
                                } else {
                                        struct sockaddr_storage *sk;
 
-                                       sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL, NULL);
+                                       sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL, NULL, 1);
                                        if (!sk) {
                                                Alert("parsing [%s:%d] : '%s %s' : %s\n",
                                                      file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
index a34b850b6d04f6f5072ad95875414432b9281629..bc92c3cb0f324921ffb8113552e73b0d928b3b75 100644 (file)
@@ -907,7 +907,7 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
                         *  - IP:+N => port=+N, relative
                         *  - IP:-N => port=-N, relative
                         */
-                       sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL, &fqdn);
+                       sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL, &fqdn, 1);
                        if (!sk) {
                                Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
                                err_code |= ERR_ALERT | ERR_FATAL;
@@ -1174,7 +1174,7 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
                                int port1, port2;
                                struct protocol *proto;
 
-                               sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL, NULL);
+                               sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL, NULL, 1);
                                if (!sk) {
                                        Alert("parsing [%s:%d] : '%s' : %s\n",
                                              file, linenum, args[cur_arg], errmsg);
@@ -1383,7 +1383,7 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
                                }
 
                                newsrv->conn_src.opts |= CO_SRC_BIND;
-                               sk = str2sa_range(args[cur_arg + 1], &port_low, &port_high, &errmsg, NULL, NULL);
+                               sk = str2sa_range(args[cur_arg + 1], &port_low, &port_high, &errmsg, NULL, NULL, 1);
                                if (!sk) {
                                        Alert("parsing [%s:%d] : '%s %s' : %s\n",
                                              file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
@@ -1483,7 +1483,7 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
                                                        struct sockaddr_storage *sk;
                                                        int port1, port2;
 
-                                                       sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL, NULL);
+                                                       sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL, NULL, 1);
                                                        if (!sk) {
                                                                Alert("parsing [%s:%d] : '%s %s' : %s\n",
                                                                      file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
index 7964b88ddb46aadd98a0319326205064a3de4a40..a468700b1973fc4e4d30112efef4709d74545b1b 100644 (file)
@@ -760,10 +760,12 @@ struct sockaddr_storage *str2ip2(const char *str, struct sockaddr_storage *sa, i
  *     that the caller will have to free(),
  *   - NULL if there was an explicit address that doesn't require resolution.
  *
+ * Hostnames are only resolved if <resolve> is non-null.
+ *
  * When a file descriptor is passed, its value is put into the s_addr part of
  * the address when cast to sockaddr_in and the address family is AF_UNSPEC.
  */
-struct sockaddr_storage *str2sa_range(const char *str, int *low, int *high, char **err, const char *pfx, char **fqdn)
+struct sockaddr_storage *str2sa_range(const char *str, int *low, int *high, char **err, const char *pfx, char **fqdn, int resolve)
 {
        static struct sockaddr_storage ss;
        struct sockaddr_storage *ret = NULL;
@@ -862,7 +864,7 @@ struct sockaddr_storage *str2sa_range(const char *str, int *low, int *high, char
 
                if (str2ip2(str2, &ss, 0) == NULL) {
                        use_fqdn = 1;
-                       if (str2ip(str2, &ss) == NULL) {
+                       if (!resolve || str2ip2(str2, &ss, 1) == NULL) {
                                memprintf(err, "invalid address: '%s' in '%s'\n", str2, str);
                                goto out;
                        }