]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tools: make str2sa_range() return the port in a separate argument
authorWilly Tarreau <w@1wt.eu>
Fri, 6 Jan 2017 17:32:38 +0000 (18:32 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 6 Jan 2017 18:29:34 +0000 (19:29 +0100)
This will be needed so that we're don't have to extract it from the
returned address where it will not always be anymore (eg: for unresolved
servers).

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

index 68244dbe794602119183d26b09cf0fde79c3ff27..be719f71438b9d4b801dca7f6c88e60e811a9372 100644 (file)
@@ -280,7 +280,10 @@ extern const char *invalid_domainchar(const char *name);
  * 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, int use_dns);
+struct sockaddr_storage *str2sa_range(const char *str,
+                                      int *port, int *low, int *high,
+                                      char **err, const char *pfx,
+                                      char **fqdn, int resolve);
 
 /* 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 8e42163ce81e6e194f30b1479eac487571901d45..13f8983f343d46d53f80059c1016a221facd4dd1 100644 (file)
@@ -237,7 +237,7 @@ int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf,
                        *next++ = 0;
                }
 
-               ss2 = str2sa_range(str, &port, &end, err,
+               ss2 = str2sa_range(str, NULL, &port, &end, err,
                                   curproxy == global.stats_fe ? NULL : global.unix_bind.prefix,
                                   NULL, 1);
                if (!ss2)
@@ -1443,7 +1443,7 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
                        }
                }
 
-               sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL, 1);
+               sk = str2sa_range(args[1], NULL, &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;
@@ -1972,7 +1972,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, 1);
+               sk = str2sa_range(args[2], NULL, &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;
@@ -2186,7 +2186,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, 1);
+               sk = str2sa_range(args[2], NULL, &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;
@@ -2402,7 +2402,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, 1);
+               sk = str2sa_range(args[2], NULL, &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;
@@ -5666,7 +5666,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, 1);
+               sk = str2sa_range(args[1], NULL, &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;
@@ -5996,7 +5996,7 @@ stats_error_parsing:
                                }
                        }
 
-                       sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL, 1);
+                       sk = str2sa_range(args[1], NULL, &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;
@@ -6048,7 +6048,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, 1);
+               sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
                if (!sk) {
                        Alert("parsing [%s:%d] : '%s %s' : %s\n",
                              file, linenum, args[0], args[1], errmsg);
@@ -6133,7 +6133,7 @@ stats_error_parsing:
                                } else {
                                        struct sockaddr_storage *sk;
 
-                                       sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL, NULL, 1);
+                                       sk = str2sa_range(args[cur_arg + 1], NULL, &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 48fcf1af02cbfe44c83ec626784122680578ce01..35fb71789f9c8eb970346bc13344727c4f2d47f1 100644 (file)
@@ -2198,7 +2198,7 @@ __LJMP static int hlua_socket_connect(struct lua_State *L)
        conn->target = socket->s->target;
 
        /* Parse ip address. */
-       addr = str2sa_range(ip, &low, &high, NULL, NULL, NULL, 0);
+       addr = str2sa_range(ip, NULL, &low, &high, NULL, NULL, NULL, 0);
        if (!addr)
                WILL_LJMP(luaL_error(L, "connect: cannot parse destination address '%s'", ip));
        if (low != high)
index 8aaf2184233856987d50e04524784e187790671b..cc763177d4dab272d0fef68082e8ded94d195526 100644 (file)
@@ -1005,7 +1005,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, 0);
+                       sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, &fqdn, 0);
                        if (!sk) {
                                Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
                                err_code |= ERR_ALERT | ERR_FATAL;
@@ -1391,7 +1391,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, 1);
+                               sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
                                if (!sk) {
                                        Alert("parsing [%s:%d] : '%s' : %s\n",
                                              file, linenum, args[cur_arg], errmsg);
@@ -1603,7 +1603,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, 1);
+                               sk = str2sa_range(args[cur_arg + 1], NULL, &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);
@@ -1703,7 +1703,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, 1);
+                                                       sk = str2sa_range(args[cur_arg + 1], NULL, &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 02a183bfe1e16df996c60b797e7982a48bfc9fc1..468b15bce84426c43e9062008a1fc262866266bd 100644 (file)
@@ -816,7 +816,7 @@ struct sockaddr_storage *str2ip2(const char *str, struct sockaddr_storage *sa, i
  * 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, int resolve)
+struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int *high, char **err, const char *pfx, char **fqdn, int resolve)
 {
        static struct sockaddr_storage ss;
        struct sockaddr_storage *ret = NULL;
@@ -983,6 +983,8 @@ struct sockaddr_storage *str2sa_range(const char *str, int *low, int *high, char
 
        ret = &ss;
  out:
+       if (port)
+               *port = porta;
        if (low)
                *low = portl;
        if (high)