From: Willy Tarreau Date: Sun, 10 Mar 2013 17:37:42 +0000 (+0100) Subject: MEDIUM: config: add complete support for str2sa_range() in 'peer' X-Git-Tag: v1.5-dev18~63 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b36487e1062c04124cadff3b6ca4b2fe242d2020;p=thirdparty%2Fhaproxy.git MEDIUM: config: add complete support for str2sa_range() in 'peer' The peer addresses are now completely parsed using str2sa_range() and the resulting protocol is checked for support for connect(). --- diff --git a/src/cfgparse.c b/src/cfgparse.c index cc1ae426b8..60270da7c3 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -1465,6 +1465,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) struct sockaddr_storage *sk; int port1, port2; char *err_msg = NULL; + struct protocol *proto; if (!*args[2]) { Alert("parsing [%s:%d] : '%s' expects and [:] as arguments.\n", @@ -1498,9 +1499,19 @@ 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, NULL, NULL); + sk = str2sa_range(args[2], &port1, &port2, &err_msg, NULL); if (!sk) { - Alert("parsing [%s:%d] : '%s %s' : unknown host in '%s'\n", file, linenum, args[0], args[1], args[2]); + Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err_msg); + err_code |= ERR_ALERT | ERR_FATAL; + free(err_msg); + goto out; + } + free(err_msg); + + proto = protocol_by_family(sk->ss_family); + if (!proto || !proto->connect) { + Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", + file, linenum, args[0], args[1]); err_code |= ERR_ALERT | ERR_FATAL; goto out; } @@ -1520,17 +1531,10 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) } newpeer->addr = *sk; - newpeer->proto = protocol_by_family(newpeer->addr.ss_family); + newpeer->proto = proto; newpeer->xprt = &raw_sock; newpeer->sock_init_arg = NULL; - if (!newpeer->proto) { - Alert("parsing [%s:%d] : Unknown protocol family %d '%s'\n", - file, linenum, newpeer->addr.ss_family, args[2]); - err_code |= ERR_ALERT | ERR_FATAL; - goto out; - } - if (strcmp(newpeer->id, localpeer) == 0) { /* Current is local peer, it define a frontend */ newpeer->local = 1;