From 6e5e0d8f9edcc963dda0ea5980ea58e908f5dfb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20L=C3=A9caille?= Date: Mon, 20 Mar 2017 16:30:18 +0100 Subject: [PATCH] MINOR: server: Make 'default-server' support 'addr' keyword. This patch makes 'default-server' support 'addr' setting. The code which was responsible of parsing 'server' 'addr' setting has moved from parse_server() to implement a new parser callable both as 'default-server' and 'server' 'addr' setting parser. Should not break anything. --- src/server.c | 82 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 33 deletions(-) diff --git a/src/server.c b/src/server.c index 602a7c9ba..198a68749 100644 --- a/src/server.c +++ b/src/server.c @@ -215,6 +215,53 @@ void srv_dump_kws(char **out) } } +/* Parse the "addr" server keyword */ +static int srv_parse_addr(char **args, int *cur_arg, + struct proxy *curproxy, struct server *newsrv, char **err) +{ + char *errmsg, *arg; + struct sockaddr_storage *sk; + int port1, port2; + struct protocol *proto; + + errmsg = NULL; + arg = args[*cur_arg + 1]; + + if (!*arg) { + memprintf(err, "'%s' expects as argument.\n", args[*cur_arg]); + goto err; + } + + sk = str2sa_range(arg, NULL, &port1, &port2, &errmsg, NULL, NULL, 1); + if (!sk) { + memprintf(err, "'%s' : %s", args[*cur_arg], errmsg); + goto err; + } + + proto = protocol_by_family(sk->ss_family); + if (!proto || !proto->connect) { + memprintf(err, "'%s %s' : connect() not supported for this address family.\n", + args[*cur_arg], arg); + goto err; + } + + if (port1 != port2) { + memprintf(err, "'%s' : port ranges and offsets are not allowed in '%s'\n", + args[*cur_arg], arg); + goto err; + } + + newsrv->check.addr = newsrv->agent.addr = *sk; + newsrv->flags |= SRV_F_CHECKADDR; + newsrv->flags |= SRV_F_AGENTADDR; + + return 0; + + err: + free(errmsg); + return ERR_ALERT | ERR_FATAL; +} + /* Parse the "backup" server keyword */ static int srv_parse_backup(char **args, int *cur_arg, struct proxy *curproxy, struct server *newsrv, char **err) @@ -1271,6 +1318,7 @@ void srv_compute_all_admin_states(struct proxy *px) * not enabled. */ static struct srv_kw_list srv_kws = { "ALL", { }, { + { "addr", srv_parse_addr, 1, 1 }, /* IP address to send health to or to probe from agent-check */ { "backup", srv_parse_backup, 0, 1 }, /* Flag as backup server */ { "check", srv_parse_check, 0, 1 }, /* enable health checks */ { "check-send-proxy", srv_parse_check_send_proxy, 0, 1 }, /* enable PROXY protocol for health checks */ @@ -1668,6 +1716,7 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr newsrv->cklen = curproxy->defsrv.cklen; } newsrv->use_ssl = curproxy->defsrv.use_ssl; + newsrv->check.addr = newsrv->agent.addr = curproxy->defsrv.check.addr; newsrv->check.use_ssl = curproxy->defsrv.check.use_ssl; newsrv->check.port = curproxy->defsrv.check.port; /* Note: 'flags' field has potentially been already initialized. */ @@ -2006,39 +2055,6 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr newsrv->check.downinter = val; cur_arg += 2; } - else if (!defsrv && !strcmp(args[cur_arg], "addr")) { - struct sockaddr_storage *sk; - int port1, port2; - struct protocol *proto; - - 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); - err_code |= ERR_ALERT | ERR_FATAL; - goto out; - } - - 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[cur_arg], args[cur_arg + 1]); - err_code |= ERR_ALERT | ERR_FATAL; - goto out; - } - - if (port1 != port2) { - Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", - file, linenum, args[cur_arg], args[cur_arg + 1]); - err_code |= ERR_ALERT | ERR_FATAL; - goto out; - } - - newsrv->check.addr = newsrv->agent.addr = *sk; - newsrv->flags |= SRV_F_CHECKADDR; - newsrv->flags |= SRV_F_AGENTADDR; - cur_arg += 2; - } else if (!strcmp(args[cur_arg], "port")) { newsrv->check.port = atol(args[cur_arg + 1]); newsrv->flags |= SRV_F_CHECKPORT;