]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: config: use a single str2sa_range() call to parse bind addresses
authorWilly Tarreau <w@1wt.eu>
Wed, 6 Mar 2013 14:45:03 +0000 (15:45 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 8 Mar 2013 13:04:54 +0000 (14:04 +0100)
str2listener() now doesn't check the address syntax, it only relies on
str2sa_range() to retrieve the address and family.

src/cfgparse.c

index 61b78a56d51681da572443fc1a601eef6bc1afc1..800f162049be6b635df88078676e1787943ca96e 100644 (file)
@@ -206,7 +206,7 @@ int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf,
        next = dupstr = strdup(str);
 
        while (next && *next) {
-               struct sockaddr_storage ss;
+               struct sockaddr_storage ss, *ss2;
 
                str = next;
                /* 1) look for the end of the first address */
@@ -214,25 +214,12 @@ int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf,
                        *next++ = 0;
                }
 
-               if (*str == '/') {
-                       struct sockaddr_storage *ss2;
-
-                       ss2 = str2sa_range(str, &port, &end, err,
-                                          curproxy == global.stats_fe ? NULL : global.unix_bind.prefix);
-                       if (!ss2)
-                               goto fail;
-                       ss = *ss2;
-                       port = end = 0;
-               }
-               else {
-                       struct sockaddr_storage *ss2;
-
-                       ss2 = str2sa_range(str, &port, &end, NULL, NULL);
-                       if (!ss2) {
-                               memprintf(err, "invalid listening address: '%s'\n", str);
-                               goto fail;
-                       }
+               ss2 = str2sa_range(str, &port, &end, err,
+                                  curproxy == global.stats_fe ? NULL : global.unix_bind.prefix);
+               if (!ss2)
+                       goto fail;
 
+               if (ss2->ss_family == AF_INET || ss2->ss_family == AF_INET6) {
                        if (!port && !end) {
                                memprintf(err, "missing port number: '%s'\n", str);
                                goto fail;
@@ -243,9 +230,6 @@ int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf,
                                goto fail;
                        }
 
-                       /* OK the address looks correct */
-                       ss = *ss2;
-
                        if (port < 1 || port > 65535) {
                                memprintf(err, "invalid port '%d' specified for address '%s'.\n", port, str);
                                goto fail;
@@ -257,6 +241,9 @@ int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf,
                        }
                }
 
+               /* OK the address looks correct */
+               ss = *ss2;
+
                for (; port <= end; port++) {
                        l = (struct listener *)calloc(1, sizeof(struct listener));
                        l->obj_type = OBJ_TYPE_LISTENER;