>From 6ab43989ab00ceef2b681bac8ac919f3fd25311f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20L=C3=A9caille?= <[email protected]>
Date: Wed, 15 Mar 2017 09:13:33 +0100
Subject: [PATCH 22/31] MINOR: server: Make 'default-server' support 'cookie'
keyword.
X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4
Before this patch, 'cookie' setting was only supported by 'server' directives.
This patch makes 'default-server' directive also support 'cookie' setting.
Should not break anything.
---
src/server.c | 30 ++++++++++++++++++++++++------
1 file changed, 24 insertions(+), 6 deletions(-)
diff --git a/src/server.c b/src/server.c
index b855b1b..79dcca7 100644
--- a/src/server.c
+++ b/src/server.c
@@ -237,6 +237,25 @@ static int srv_parse_check_send_proxy(char **args, int *cur_arg,
return 0;
}
+/* Parse the "cookie" server keyword */
+static int srv_parse_cookie(char **args, int *cur_arg,
+ struct proxy *curproxy, struct server *newsrv, char **err)
+{
+ char *arg;
+
+ arg = args[*cur_arg + 1];
+ if (!*arg) {
+ memprintf(err, "'%s' expects <value> as argument.\n", args[*cur_arg]);
+ return ERR_ALERT | ERR_FATAL;
+ }
+
+ free(newsrv->cookie);
+ newsrv->cookie = strdup(arg);
+ newsrv->cklen = strlen(arg);
+ newsrv->flags |= SRV_F_COOKIESET;
+ return 0;
+}
+
/* parse the "id" server keyword */
static int srv_parse_id(char **args, int *cur_arg, struct proxy *curproxy, struct server *newsrv, char **err)
{
@@ -1036,6 +1055,7 @@ static struct srv_kw_list srv_kws = { "ALL", { }, {
{ "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 */
+ { "cookie", srv_parse_cookie, 1, 1 }, /* Assign a cookie to the server */
{ "id", srv_parse_id, 1, 0 }, /* set id# of server */
{ "no-backup", srv_parse_no_backup, 0, 1 }, /* Flag as non-backup server */
{ "no-check", srv_parse_no_check, 0, 1 }, /* disable health checks */
@@ -1340,6 +1360,10 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
newsrv->rdr_pfx = strdup(curproxy->defsrv.rdr_pfx);
newsrv->rdr_len = curproxy->defsrv.rdr_len;
}
+ if (curproxy->defsrv.cookie != NULL) {
+ newsrv->cookie = strdup(curproxy->defsrv.cookie);
+ newsrv->cklen = curproxy->defsrv.cklen;
+ }
newsrv->use_ssl = curproxy->defsrv.use_ssl;
newsrv->check.use_ssl = curproxy->defsrv.check.use_ssl;
newsrv->check.port = curproxy->defsrv.check.port;
@@ -1459,12 +1483,6 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
memcpy(newsrv->agent.send_string, args[cur_arg + 1], newsrv->agent.send_string_len);
cur_arg += 2;
}
- else if (!defsrv && !strcmp(args[cur_arg], "cookie")) {
- newsrv->cookie = strdup(args[cur_arg + 1]);
- newsrv->cklen = strlen(args[cur_arg + 1]);
- newsrv->flags |= SRV_F_COOKIESET;
- cur_arg += 2;
- }
else if (!strcmp(args[cur_arg], "init-addr")) {
char *p, *end;
int done;
--
2.1.4