]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: standard: Disable ip resolution during the runtime
authorThierry FOURNIER <tfournier@exceliance.fr>
Tue, 11 Feb 2014 14:23:04 +0000 (15:23 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 17 Mar 2014 17:06:08 +0000 (18:06 +0100)
The function str2net runs DNS resolution if valid ip cannot be parsed.
The DNS function used is the standard function of the libc and it
performs asynchronous request.

The asynchronous request is not compatible with the haproxy
archictecture.

str2net() is used during the runtime throught the "socket".

This patch remove the DNS resolution during the runtime.

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

index 9ed06688f771db2755d4cb620bfe3932fb4b11da..1a3020dc5c1a5e908906ce401c4e7a999fdb8eb7 100644 (file)
@@ -248,7 +248,7 @@ int cidr2dotted(int cidr, struct in_addr *mask);
  * is optionnal and either in the dotted or CIDR notation.
  * Note: "addr" can also be a hostname. Returns 1 if OK, 0 if error.
  */
-int str2net(const char *str, struct in_addr *addr, struct in_addr *mask);
+int str2net(const char *str, int resolve, struct in_addr *addr, struct in_addr *mask);
 
 /*
  * converts <str> to two struct in6_addr* which must be pre-allocated.
index 6611d6cfc169289a9248a9fc9222dee2dfa0c581..5635c5716af3efa25317750e41bc8cc955e1c0b4 100644 (file)
@@ -2198,7 +2198,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                goto out;
        }
        else if (!strcmp(args[0], "monitor-net")) {  /* set the range of IPs to ignore */
-               if (!*args[1] || !str2net(args[1], &curproxy->mon_net, &curproxy->mon_mask)) {
+               if (!*args[1] || !str2net(args[1], 1, &curproxy->mon_net, &curproxy->mon_mask)) {
                        Alert("parsing [%s:%d] : '%s' expects address[/mask].\n",
                              file, linenum, args[0]);
                        err_code |= ERR_ALERT | ERR_FATAL;
@@ -3928,7 +3928,7 @@ stats_error_parsing:
                        while (*(args[cur_arg])) {
                                if (!strcmp(args[cur_arg], "except")) {
                                        /* suboption except - needs additional argument for it */
-                                       if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_net, &curproxy->except_mask)) {
+                                       if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_net, &curproxy->except_mask)) {
                                                Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
                                                      file, linenum, args[0], args[1], args[cur_arg]);
                                                err_code |= ERR_ALERT | ERR_FATAL;
@@ -3979,7 +3979,7 @@ stats_error_parsing:
                        while (*(args[cur_arg])) {
                                if (!strcmp(args[cur_arg], "except")) {
                                        /* suboption except - needs additional argument for it */
-                                       if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], &curproxy->except_to, &curproxy->except_mask_to)) {
+                                       if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_to, &curproxy->except_mask_to)) {
                                                Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
                                                      file, linenum, args[0], args[1], args[cur_arg]);
                                                err_code |= ERR_ALERT | ERR_FATAL;
index dad2472de1d7036cf715511926afe2202d1a64ec..22aa9d4b7165352c7a86bf30f716fe600b8977bc 100644 (file)
@@ -405,7 +405,8 @@ int pat_parse_dotted_ver(const char *text, struct pattern *pattern, char **err)
  */
 int pat_parse_ip(const char *text, struct pattern *pattern, char **err)
 {
-       if (str2net(text, &pattern->val.ipv4.addr, &pattern->val.ipv4.mask)) {
+       if (str2net(text, global.mode & MODE_STARTING,
+                   &pattern->val.ipv4.addr, &pattern->val.ipv4.mask)) {
                pattern->type = SMP_T_IPV4;
                return 1;
        }
index 89af08f72a013e3d3d351b4ee6bb694c66a94c23..d435c3c5b35617f852919994695cb081df2fa4d4 100644 (file)
@@ -809,7 +809,7 @@ int cidr2dotted(int cidr, struct in_addr *mask) {
  * is optionnal and either in the dotted or CIDR notation.
  * Note: "addr" can also be a hostname. Returns 1 if OK, 0 if error.
  */
-int str2net(const char *str, struct in_addr *addr, struct in_addr *mask)
+int str2net(const char *str, int resolve, struct in_addr *addr, struct in_addr *mask)
 {
        __label__ out_free, out_err;
        char *c, *s;
@@ -834,6 +834,9 @@ int str2net(const char *str, struct in_addr *addr, struct in_addr *mask)
        if (!inet_pton(AF_INET, s, addr)) {
                struct hostent *he;
 
+               if (!resolve)
+                       goto out_err;
+
                if ((he = gethostbyname(s)) == NULL) {
                        goto out_err;
                }