]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: config: use str2sa_range() to parse log addresses
authorWilly Tarreau <w@1wt.eu>
Wed, 6 Mar 2013 14:02:49 +0000 (15:02 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 8 Mar 2013 13:04:54 +0000 (14:04 +0100)
str2sa_range() is now used to parse log addresses, both INET and
UNIX. str2sun() is not used anymore.

src/cfgparse.c

index 800f162049be6b635df88078676e1787943ca96e..0c08e3b09e0d9b14a56492ed4d0024ae475c2ffe 100644 (file)
@@ -1080,6 +1080,9 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
                }
        }
        else if (!strcmp(args[0], "log")) {  /* syslog server address */
+               struct sockaddr_storage *sk;
+               int port1, port2;
+               char *err_msg = NULL;
                struct logsrv *logsrv;
 
                if (*(args[1]) == 0 || *(args[2]) == 0) {
@@ -1117,28 +1120,18 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
                        }
                }
 
-               if (args[1][0] == '/') {
-                       struct sockaddr_storage *sk = (struct sockaddr_storage *)str2sun(args[1]);
-                       if (!sk) {
-                               Alert("parsing [%s:%d] : Socket path '%s' too long (max %d)\n", file, linenum,
-                                     args[1], (int)sizeof(((struct sockaddr_un *)&sk)->sun_path) - 1);
-                               err_code |= ERR_ALERT | ERR_FATAL;
-                               free(logsrv);
-                               goto out;
-                       }
-                       logsrv->addr = *sk;
-               } else {
-                       struct sockaddr_storage *sk;
-                       int port1, port2;
-
-                       sk = str2sa_range(args[1], &port1, &port2, NULL, NULL);
-                       if (!sk) {
-                               Alert("parsing [%s:%d] : '%s' : unknown host in '%s'\n", file, linenum, args[0], args[1]);
-                               err_code |= ERR_ALERT | ERR_FATAL;
-                               free(logsrv);
-                               goto out;
-                       }
+               sk = str2sa_range(args[1], &port1, &port2, &err_msg, NULL);
+               if (!sk) {
+                       Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], err_msg);
+                       err_code |= ERR_ALERT | ERR_FATAL;
+                       free(err_msg);
+                       free(logsrv);
+                       goto out;
+               }
+               logsrv->addr = *sk;
+               free(err_msg);
 
+               if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) {
                        if (port1 != port2) {
                                Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n",
                                      file, linenum, args[0], args[1]);
@@ -4816,6 +4809,9 @@ stats_error_parsing:
                        }
                }
                else if (*(args[1]) && *(args[2])) {
+                       struct sockaddr_storage *sk;
+                       int port1, port2;
+                       char *err_msg = NULL;
 
                        logsrv = calloc(1, sizeof(struct logsrv));
 
@@ -4849,27 +4845,18 @@ stats_error_parsing:
                                }
                        }
 
-                       if (args[1][0] == '/') {
-                               struct sockaddr_storage *sk = (struct sockaddr_storage *)str2sun(args[1]);
-                               if (!sk) {
-                                       Alert("parsing [%s:%d] : Socket path '%s' too long (max %d)\n", file, linenum,
-                                             args[1], (int)sizeof(((struct sockaddr_un *)sk)->sun_path) - 1);
-                                       err_code |= ERR_ALERT | ERR_FATAL;
-                                       goto out;
-                               }
-                               logsrv->addr = *sk;
-                       } else {
-                               struct sockaddr_storage *sk;
-                               int port1, port2;
+                       sk = str2sa_range(args[1], &port1, &port2, &err_msg, NULL);
+                       if (!sk) {
+                               Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], err_msg);
+                               err_code |= ERR_ALERT | ERR_FATAL;
+                               free(err_msg);
+                               goto out;
+                       }
 
-                               sk = str2sa_range(args[1], &port1, &port2, NULL, NULL);
-                               if (!sk) {
-                                       Alert("parsing [%s:%d] : '%s' : unknown host in '%s'\n",
-                                             file, linenum, args[0], args[1]);
-                                       err_code |= ERR_ALERT | ERR_FATAL;
-                                       goto out;
-                               }
+                       logsrv->addr = *sk;
+                       free(err_msg);
 
+                       if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) {
                                if (port1 != port2) {
                                        Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n",
                                              file, linenum, args[0], args[1]);
@@ -4877,7 +4864,6 @@ stats_error_parsing:
                                        goto out;
                                }
 
-                               logsrv->addr = *sk;
                                if (!port1)
                                        set_host_port(&logsrv->addr, SYSLOG_PORT);
                        }