Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <string.h> |
| 4 | #include <netdb.h> |
| 5 | #include <ctype.h> |
| 6 | #include <pwd.h> |
| 7 | #include <grp.h> |
| 8 | #include <errno.h> |
| 9 | #include <sys/types.h> |
| 10 | #include <sys/stat.h> |
| 11 | #include <fcntl.h> |
| 12 | #include <unistd.h> |
| 13 | |
Willy Tarreau | dcc048a | 2020-06-04 19:11:43 +0200 | [diff] [blame] | 14 | #include <haproxy/acl.h> |
Eric Salama | 7cea606 | 2020-10-02 11:58:19 +0200 | [diff] [blame] | 15 | #include <haproxy/buf.h> |
Willy Tarreau | 278161c | 2020-06-04 11:18:28 +0200 | [diff] [blame] | 16 | #include <haproxy/capture-t.h> |
Willy Tarreau | 6be7849 | 2020-06-05 00:00:29 +0200 | [diff] [blame] | 17 | #include <haproxy/cfgparse.h> |
Willy Tarreau | 4aa573d | 2020-06-04 18:21:56 +0200 | [diff] [blame] | 18 | #include <haproxy/check.h> |
Willy Tarreau | 0a3bd39 | 2020-06-04 08:52:38 +0200 | [diff] [blame] | 19 | #include <haproxy/compression-t.h> |
Willy Tarreau | 7ea393d | 2020-06-04 18:02:10 +0200 | [diff] [blame] | 20 | #include <haproxy/connection.h> |
Willy Tarreau | bcc6733 | 2020-06-05 15:31:31 +0200 | [diff] [blame] | 21 | #include <haproxy/extcheck.h> |
Willy Tarreau | 8773533 | 2020-06-04 09:08:41 +0200 | [diff] [blame] | 22 | #include <haproxy/http_htx.h> |
Willy Tarreau | c761f84 | 2020-06-04 11:40:28 +0200 | [diff] [blame] | 23 | #include <haproxy/http_rules.h> |
Willy Tarreau | 213e990 | 2020-06-04 14:58:24 +0200 | [diff] [blame] | 24 | #include <haproxy/listener.h> |
Willy Tarreau | 36979d9 | 2020-06-05 17:27:29 +0200 | [diff] [blame] | 25 | #include <haproxy/log.h> |
Willy Tarreau | 872f2ea | 2020-06-04 18:46:44 +0200 | [diff] [blame] | 26 | #include <haproxy/peers.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 27 | #include <haproxy/protocol.h> |
Willy Tarreau | a264d96 | 2020-06-04 22:29:18 +0200 | [diff] [blame] | 28 | #include <haproxy/proxy.h> |
Willy Tarreau | e6ce10b | 2020-06-04 15:33:47 +0200 | [diff] [blame] | 29 | #include <haproxy/sample.h> |
Willy Tarreau | 1e56f92 | 2020-06-04 23:20:13 +0200 | [diff] [blame] | 30 | #include <haproxy/server.h> |
Willy Tarreau | 2eec9b5 | 2020-06-04 19:58:55 +0200 | [diff] [blame] | 31 | #include <haproxy/stats-t.h> |
Willy Tarreau | 872f2ea | 2020-06-04 18:46:44 +0200 | [diff] [blame] | 32 | #include <haproxy/stick_table.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 33 | #include <haproxy/tcpcheck.h> |
| 34 | #include <haproxy/uri_auth.h> |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 35 | |
Willy Tarreau | 7d0c143 | 2021-02-12 12:29:28 +0100 | [diff] [blame] | 36 | |
| 37 | static struct proxy defproxy; /* fake proxy used to assign default values on all instances */ |
| 38 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 39 | /* Report a warning if a rule is placed after a 'tcp-request session' rule. |
| 40 | * Return 1 if the warning has been emitted, otherwise 0. |
| 41 | */ |
| 42 | int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg) |
| 43 | { |
| 44 | if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) { |
| 45 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n", |
| 46 | file, line, arg); |
| 47 | return 1; |
| 48 | } |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | /* Report a warning if a rule is placed after a 'tcp-request content' rule. |
| 53 | * Return 1 if the warning has been emitted, otherwise 0. |
| 54 | */ |
| 55 | int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) |
| 56 | { |
| 57 | if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) { |
| 58 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n", |
| 59 | file, line, arg); |
| 60 | return 1; |
| 61 | } |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | /* Report a warning if a rule is placed after a 'monitor fail' rule. |
| 66 | * Return 1 if the warning has been emitted, otherwise 0. |
| 67 | */ |
| 68 | int warnif_rule_after_monitor(struct proxy *proxy, const char *file, int line, const char *arg) |
| 69 | { |
| 70 | if (!LIST_ISEMPTY(&proxy->mon_fail_cond)) { |
| 71 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'monitor fail' rule will still be processed before.\n", |
| 72 | file, line, arg); |
| 73 | return 1; |
| 74 | } |
| 75 | return 0; |
| 76 | } |
| 77 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 78 | /* Report a warning if a rule is placed after an 'http_request' rule. |
| 79 | * Return 1 if the warning has been emitted, otherwise 0. |
| 80 | */ |
| 81 | int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 82 | { |
| 83 | if (!LIST_ISEMPTY(&proxy->http_req_rules)) { |
| 84 | ha_warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n", |
| 85 | file, line, arg); |
| 86 | return 1; |
| 87 | } |
| 88 | return 0; |
| 89 | } |
| 90 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 91 | /* Report a warning if a rule is placed after a redirect rule. |
| 92 | * Return 1 if the warning has been emitted, otherwise 0. |
| 93 | */ |
| 94 | int warnif_rule_after_redirect(struct proxy *proxy, const char *file, int line, const char *arg) |
| 95 | { |
| 96 | if (!LIST_ISEMPTY(&proxy->redirect_rules)) { |
| 97 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n", |
| 98 | file, line, arg); |
| 99 | return 1; |
| 100 | } |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | /* Report a warning if a rule is placed after a 'use_backend' rule. |
| 105 | * Return 1 if the warning has been emitted, otherwise 0. |
| 106 | */ |
| 107 | int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int line, const char *arg) |
| 108 | { |
| 109 | if (!LIST_ISEMPTY(&proxy->switching_rules)) { |
| 110 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n", |
| 111 | file, line, arg); |
| 112 | return 1; |
| 113 | } |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | /* Report a warning if a rule is placed after a 'use-server' rule. |
| 118 | * Return 1 if the warning has been emitted, otherwise 0. |
| 119 | */ |
| 120 | int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg) |
| 121 | { |
| 122 | if (!LIST_ISEMPTY(&proxy->server_rules)) { |
| 123 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n", |
| 124 | file, line, arg); |
| 125 | return 1; |
| 126 | } |
| 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | /* report a warning if a redirect rule is dangerously placed */ |
| 131 | int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg) |
| 132 | { |
| 133 | return warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 134 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 135 | } |
| 136 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 137 | /* report a warning if an http-request rule is dangerously placed */ |
| 138 | int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 139 | { |
Christopher Faulet | 1b6adb4 | 2019-07-17 15:33:14 +0200 | [diff] [blame] | 140 | return warnif_rule_after_redirect(proxy, file, line, arg) || |
| 141 | warnif_misplaced_redirect(proxy, file, line, arg); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | /* report a warning if a block rule is dangerously placed */ |
Christopher Faulet | 8c3b63a | 2019-07-17 15:19:51 +0200 | [diff] [blame] | 145 | int warnif_misplaced_monitor(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 146 | { |
| 147 | return warnif_rule_after_http_req(proxy, file, line, arg) || |
| 148 | warnif_misplaced_http_req(proxy, file, line, arg); |
| 149 | } |
| 150 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 151 | /* report a warning if a "tcp request content" rule is dangerously placed */ |
| 152 | int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) |
| 153 | { |
| 154 | return warnif_rule_after_monitor(proxy, file, line, arg) || |
| 155 | warnif_misplaced_monitor(proxy, file, line, arg); |
| 156 | } |
| 157 | |
| 158 | /* report a warning if a "tcp request session" rule is dangerously placed */ |
| 159 | int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg) |
| 160 | { |
| 161 | return warnif_rule_after_tcp_cont(proxy, file, line, arg) || |
| 162 | warnif_misplaced_tcp_cont(proxy, file, line, arg); |
| 163 | } |
| 164 | |
| 165 | /* report a warning if a "tcp request connection" rule is dangerously placed */ |
| 166 | int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg) |
| 167 | { |
| 168 | return warnif_rule_after_tcp_sess(proxy, file, line, arg) || |
| 169 | warnif_misplaced_tcp_sess(proxy, file, line, arg); |
| 170 | } |
| 171 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 172 | int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) |
| 173 | { |
| 174 | static struct proxy *curproxy = NULL; |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame^] | 175 | static struct proxy *curr_defproxy = NULL; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 176 | const char *err; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 177 | int rc; |
| 178 | unsigned val; |
| 179 | int err_code = 0; |
| 180 | struct acl_cond *cond = NULL; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 181 | char *errmsg = NULL; |
| 182 | struct bind_conf *bind_conf; |
| 183 | |
Willy Tarreau | 7d0c143 | 2021-02-12 12:29:28 +0100 | [diff] [blame] | 184 | if (defproxy.obj_type != OBJ_TYPE_PROXY) { |
| 185 | /* defproxy not initialized yet */ |
| 186 | init_new_proxy(&defproxy); |
| 187 | proxy_preset_defaults(&defproxy); |
| 188 | } |
| 189 | |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame^] | 190 | if (!curr_defproxy) |
| 191 | curr_defproxy = &defproxy; |
| 192 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 193 | if (strcmp(args[0], "listen") == 0) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 194 | rc = PR_CAP_LISTEN; |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 195 | else if (strcmp(args[0], "frontend") == 0) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 196 | rc = PR_CAP_FE; |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 197 | else if (strcmp(args[0], "backend") == 0) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 198 | rc = PR_CAP_BE; |
Willy Tarreau | 80dc6fe | 2021-02-12 09:43:33 +0100 | [diff] [blame] | 199 | else if (strcmp(args[0], "defaults") == 0) |
| 200 | rc = PR_CAP_DEF; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 201 | else |
| 202 | rc = PR_CAP_NONE; |
| 203 | |
Willy Tarreau | 80dc6fe | 2021-02-12 09:43:33 +0100 | [diff] [blame] | 204 | if (rc & PR_CAP_LISTEN) { /* new proxy */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 205 | if (!*args[1]) { |
Willy Tarreau | b2ec994 | 2021-02-12 13:28:22 +0100 | [diff] [blame] | 206 | ha_alert("parsing [%s:%d] : '%s' expects an <id> argument\n", |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 207 | file, linenum, args[0]); |
| 208 | err_code |= ERR_ALERT | ERR_ABORT; |
| 209 | goto out; |
| 210 | } |
| 211 | |
| 212 | err = invalid_char(args[1]); |
| 213 | if (err) { |
| 214 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 215 | file, linenum, *err, args[0], args[1]); |
| 216 | err_code |= ERR_ALERT | ERR_FATAL; |
| 217 | } |
| 218 | |
| 219 | curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]); |
| 220 | if (curproxy) { |
| 221 | ha_alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n", |
| 222 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 223 | curproxy->id, curproxy->conf.file, curproxy->conf.line); |
| 224 | err_code |= ERR_ALERT | ERR_FATAL; |
| 225 | } |
| 226 | |
Emeric Brun | b0c331f | 2020-10-07 17:05:59 +0200 | [diff] [blame] | 227 | curproxy = log_forward_by_name(args[1]); |
| 228 | if (curproxy) { |
| 229 | ha_alert("Parsing [%s:%d]: %s '%s' has the same name as log forward section '%s' declared at %s:%d.\n", |
| 230 | file, linenum, proxy_cap_str(rc), args[1], |
| 231 | curproxy->id, curproxy->conf.file, curproxy->conf.line); |
| 232 | err_code |= ERR_ALERT | ERR_FATAL; |
| 233 | } |
| 234 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 235 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) { |
Willy Tarreau | 7683893 | 2021-02-12 08:49:47 +0100 | [diff] [blame] | 236 | if (rc & PR_CAP_FE) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 237 | ha_alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum); |
| 238 | goto out; |
| 239 | } |
| 240 | |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame^] | 241 | curproxy = alloc_new_proxy(args[1], rc, file, linenum, curr_defproxy, &errmsg); |
Willy Tarreau | 7683893 | 2021-02-12 08:49:47 +0100 | [diff] [blame] | 242 | if (!curproxy) { |
| 243 | /* message already printed by alloc_new_proxy() */ |
| 244 | ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
| 245 | err_code |= ERR_ALERT | ERR_ABORT; |
Christopher Faulet | 76edc0f | 2020-01-13 15:52:01 +0100 | [diff] [blame] | 246 | goto out; |
| 247 | } |
Willy Tarreau | 7683893 | 2021-02-12 08:49:47 +0100 | [diff] [blame] | 248 | curproxy->next = proxies_list; |
| 249 | proxies_list = curproxy; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 250 | |
| 251 | goto out; |
| 252 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 253 | else if (strcmp(args[0], "defaults") == 0) { /* use this one to assign default values */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 254 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) { |
| 255 | err_code |= ERR_ABORT; |
| 256 | goto out; |
| 257 | } |
| 258 | |
Willy Tarreau | a3320a0 | 2021-02-12 10:38:49 +0100 | [diff] [blame] | 259 | /* let's first free previous defaults */ |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame^] | 260 | proxy_free_defaults(curr_defproxy); |
| 261 | init_new_proxy(curr_defproxy); |
| 262 | proxy_preset_defaults(curr_defproxy); |
| 263 | curproxy = curr_defproxy; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 264 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 265 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Willy Tarreau | 80dc6fe | 2021-02-12 09:43:33 +0100 | [diff] [blame] | 266 | defproxy.cap = PR_CAP_DEF | PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 267 | goto out; |
| 268 | } |
| 269 | else if (curproxy == NULL) { |
| 270 | ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
| 271 | err_code |= ERR_ALERT | ERR_FATAL; |
| 272 | goto out; |
| 273 | } |
| 274 | |
| 275 | /* update the current file and line being parsed */ |
| 276 | curproxy->conf.args.file = curproxy->conf.file; |
| 277 | curproxy->conf.args.line = linenum; |
| 278 | |
| 279 | /* Now let's parse the proxy-specific keywords */ |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 280 | if (strcmp(args[0], "server") == 0 || |
| 281 | strcmp(args[0], "default-server") == 0 || |
| 282 | strcmp(args[0], "server-template") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame^] | 283 | err_code |= parse_server(file, linenum, args, curproxy, curr_defproxy, 1, 0, 0); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 284 | if (err_code & ERR_FATAL) |
| 285 | goto out; |
| 286 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 287 | else if (strcmp(args[0], "bind") == 0) { /* new listen addresses */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 288 | struct listener *l; |
| 289 | int cur_arg; |
| 290 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 291 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 292 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 293 | err_code |= ERR_ALERT | ERR_FATAL; |
| 294 | goto out; |
| 295 | } |
| 296 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
| 297 | err_code |= ERR_WARN; |
| 298 | |
| 299 | if (!*(args[1])) { |
| 300 | ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n", |
| 301 | file, linenum, args[0]); |
| 302 | err_code |= ERR_ALERT | ERR_FATAL; |
| 303 | goto out; |
| 304 | } |
| 305 | |
| 306 | bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW)); |
| 307 | |
| 308 | /* use default settings for unix sockets */ |
Willy Tarreau | 6e459d7 | 2020-09-03 07:09:09 +0200 | [diff] [blame] | 309 | bind_conf->settings.ux.uid = global.unix_bind.ux.uid; |
| 310 | bind_conf->settings.ux.gid = global.unix_bind.ux.gid; |
| 311 | bind_conf->settings.ux.mode = global.unix_bind.ux.mode; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 312 | |
| 313 | /* NOTE: the following line might create several listeners if there |
| 314 | * are comma-separated IPs or port ranges. So all further processing |
| 315 | * will have to be applied to all listeners created after last_listen. |
| 316 | */ |
| 317 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 318 | if (errmsg && *errmsg) { |
| 319 | indent_msg(&errmsg, 2); |
| 320 | ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
| 321 | } |
| 322 | else |
| 323 | ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 324 | file, linenum, args[0], args[1]); |
| 325 | err_code |= ERR_ALERT | ERR_FATAL; |
| 326 | goto out; |
| 327 | } |
| 328 | |
| 329 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 330 | /* Set default global rights and owner for unix bind */ |
| 331 | global.maxsock++; |
| 332 | } |
| 333 | |
| 334 | cur_arg = 2; |
| 335 | while (*(args[cur_arg])) { |
| 336 | static int bind_dumped; |
| 337 | struct bind_kw *kw; |
| 338 | char *err; |
| 339 | |
| 340 | kw = bind_find_kw(args[cur_arg]); |
| 341 | if (kw) { |
| 342 | char *err = NULL; |
| 343 | int code; |
| 344 | |
| 345 | if (!kw->parse) { |
| 346 | ha_alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 347 | file, linenum, args[0], args[1], args[cur_arg]); |
| 348 | cur_arg += 1 + kw->skip ; |
| 349 | err_code |= ERR_ALERT | ERR_FATAL; |
| 350 | goto out; |
| 351 | } |
| 352 | |
| 353 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
| 354 | err_code |= code; |
| 355 | |
| 356 | if (code) { |
| 357 | if (err && *err) { |
| 358 | indent_msg(&err, 2); |
Emeric Brun | 0655c9b | 2019-10-17 16:45:56 +0200 | [diff] [blame] | 359 | if (((code & (ERR_WARN|ERR_ALERT)) == ERR_WARN)) |
| 360 | ha_warning("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err); |
| 361 | else |
| 362 | ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 363 | } |
| 364 | else |
| 365 | ha_alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 366 | file, linenum, args[0], args[1], args[cur_arg]); |
| 367 | if (code & ERR_FATAL) { |
| 368 | free(err); |
| 369 | cur_arg += 1 + kw->skip; |
| 370 | goto out; |
| 371 | } |
| 372 | } |
| 373 | free(err); |
| 374 | cur_arg += 1 + kw->skip; |
| 375 | continue; |
| 376 | } |
| 377 | |
| 378 | err = NULL; |
| 379 | if (!bind_dumped) { |
| 380 | bind_dump_kws(&err); |
| 381 | indent_msg(&err, 4); |
| 382 | bind_dumped = 1; |
| 383 | } |
| 384 | |
| 385 | ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 386 | file, linenum, args[0], args[1], args[cur_arg], |
| 387 | err ? " Registered keywords :" : "", err ? err : ""); |
| 388 | free(err); |
| 389 | |
| 390 | err_code |= ERR_ALERT | ERR_FATAL; |
| 391 | goto out; |
| 392 | } |
| 393 | goto out; |
| 394 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 395 | else if (strcmp(args[0], "monitor-net") == 0) { /* set the range of IPs to ignore */ |
Willy Tarreau | 9e9919d | 2020-10-14 15:55:23 +0200 | [diff] [blame] | 396 | ha_alert("parsing [%s:%d] : 'monitor-net' doesn't exist anymore. Please use 'http-request return status 200 if { src %s }' instead.\n", file, linenum, args[1]); |
| 397 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 398 | goto out; |
| 399 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 400 | else if (strcmp(args[0], "monitor-uri") == 0) { /* set the URI to intercept */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 401 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
| 402 | err_code |= ERR_WARN; |
| 403 | |
| 404 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 405 | goto out; |
| 406 | |
| 407 | if (!*args[1]) { |
| 408 | ha_alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 409 | file, linenum, args[0]); |
| 410 | err_code |= ERR_ALERT | ERR_FATAL; |
| 411 | goto out; |
| 412 | } |
| 413 | |
| 414 | free(curproxy->monitor_uri); |
| 415 | curproxy->monitor_uri_len = strlen(args[1]); |
| 416 | curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1); |
| 417 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
| 418 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 419 | |
| 420 | goto out; |
| 421 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 422 | else if (strcmp(args[0], "mode") == 0) { /* sets the proxy mode */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 423 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 424 | goto out; |
| 425 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 426 | if (strcmp(args[1], "http") == 0) curproxy->mode = PR_MODE_HTTP; |
| 427 | else if (strcmp(args[1], "tcp") == 0) curproxy->mode = PR_MODE_TCP; |
| 428 | else if (strcmp(args[1], "health") == 0) { |
Willy Tarreau | 77e0dae | 2020-10-14 15:44:27 +0200 | [diff] [blame] | 429 | ha_alert("parsing [%s:%d] : 'mode health' doesn't exist anymore. Please use 'http-request return status 200' instead.\n", file, linenum); |
| 430 | err_code |= ERR_ALERT | ERR_FATAL; |
| 431 | goto out; |
| 432 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 433 | else { |
| 434 | ha_alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]); |
| 435 | err_code |= ERR_ALERT | ERR_FATAL; |
| 436 | goto out; |
| 437 | } |
| 438 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 439 | else if (strcmp(args[0], "id") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 440 | struct eb32_node *node; |
| 441 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 442 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 443 | ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 444 | file, linenum, args[0]); |
| 445 | err_code |= ERR_ALERT | ERR_FATAL; |
| 446 | goto out; |
| 447 | } |
| 448 | |
| 449 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 450 | goto out; |
| 451 | |
| 452 | if (!*args[1]) { |
| 453 | ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 454 | file, linenum, args[0]); |
| 455 | err_code |= ERR_ALERT | ERR_FATAL; |
| 456 | goto out; |
| 457 | } |
| 458 | |
| 459 | curproxy->uuid = atol(args[1]); |
| 460 | curproxy->conf.id.key = curproxy->uuid; |
| 461 | curproxy->options |= PR_O_FORCED_ID; |
| 462 | |
| 463 | if (curproxy->uuid <= 0) { |
| 464 | ha_alert("parsing [%s:%d]: custom id has to be > 0.\n", |
| 465 | file, linenum); |
| 466 | err_code |= ERR_ALERT | ERR_FATAL; |
| 467 | goto out; |
| 468 | } |
| 469 | |
| 470 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 471 | if (node) { |
| 472 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 473 | ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 474 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 475 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 476 | err_code |= ERR_ALERT | ERR_FATAL; |
| 477 | goto out; |
| 478 | } |
| 479 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
| 480 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 481 | else if (strcmp(args[0], "description") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 482 | int i, len=0; |
| 483 | char *d; |
| 484 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 485 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 486 | ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 487 | file, linenum, args[0]); |
| 488 | err_code |= ERR_ALERT | ERR_FATAL; |
| 489 | goto out; |
| 490 | } |
| 491 | |
| 492 | if (!*args[1]) { |
| 493 | ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 494 | file, linenum, args[0]); |
| 495 | return -1; |
| 496 | } |
| 497 | |
| 498 | for (i = 1; *args[i]; i++) |
| 499 | len += strlen(args[i]) + 1; |
| 500 | |
| 501 | d = calloc(1, len); |
| 502 | curproxy->desc = d; |
| 503 | |
| 504 | d += snprintf(d, curproxy->desc + len - d, "%s", args[1]); |
| 505 | for (i = 2; *args[i]; i++) |
| 506 | d += snprintf(d, curproxy->desc + len - d, " %s", args[i]); |
| 507 | |
| 508 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 509 | else if (strcmp(args[0], "disabled") == 0) { /* disables this proxy */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 510 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 511 | goto out; |
Willy Tarreau | c3914d4 | 2020-09-24 08:39:22 +0200 | [diff] [blame] | 512 | curproxy->disabled = 1; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 513 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 514 | else if (strcmp(args[0], "enabled") == 0) { /* enables this proxy (used to revert a disabled default) */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 515 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 516 | goto out; |
Willy Tarreau | c3914d4 | 2020-09-24 08:39:22 +0200 | [diff] [blame] | 517 | curproxy->disabled = 0; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 518 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 519 | else if (strcmp(args[0], "bind-process") == 0) { /* enable this proxy only on some processes */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 520 | int cur_arg = 1; |
| 521 | unsigned long set = 0; |
| 522 | |
| 523 | while (*args[cur_arg]) { |
| 524 | if (strcmp(args[cur_arg], "all") == 0) { |
| 525 | set = 0; |
| 526 | break; |
| 527 | } |
Willy Tarreau | ff9c914 | 2019-02-07 10:39:36 +0100 | [diff] [blame] | 528 | if (parse_process_number(args[cur_arg], &set, MAX_PROCS, NULL, &errmsg)) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 529 | ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg); |
| 530 | err_code |= ERR_ALERT | ERR_FATAL; |
| 531 | goto out; |
| 532 | } |
| 533 | cur_arg++; |
| 534 | } |
| 535 | curproxy->bind_proc = set; |
| 536 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 537 | else if (strcmp(args[0], "acl") == 0) { /* add an ACL */ |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 538 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 539 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 540 | err_code |= ERR_ALERT | ERR_FATAL; |
| 541 | goto out; |
| 542 | } |
| 543 | |
| 544 | err = invalid_char(args[1]); |
| 545 | if (err) { |
| 546 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 547 | file, linenum, *err, args[1]); |
| 548 | err_code |= ERR_ALERT | ERR_FATAL; |
| 549 | goto out; |
| 550 | } |
| 551 | |
Tim Duesterhus | 0cf811a | 2020-02-05 21:00:50 +0100 | [diff] [blame] | 552 | if (strcasecmp(args[1], "or") == 0) { |
Tim Duesterhus | f1bc24c | 2020-02-06 22:04:03 +0100 | [diff] [blame] | 553 | ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a " |
Tim Duesterhus | 0cf811a | 2020-02-05 21:00:50 +0100 | [diff] [blame] | 554 | "logical disjunction within a condition.\n", |
| 555 | file, linenum, args[1]); |
| 556 | err_code |= ERR_ALERT | ERR_FATAL; |
| 557 | goto out; |
| 558 | } |
| 559 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 560 | if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) { |
| 561 | ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 562 | file, linenum, args[1], errmsg); |
| 563 | err_code |= ERR_ALERT | ERR_FATAL; |
| 564 | goto out; |
| 565 | } |
| 566 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 567 | else if (strcmp(args[0], "dynamic-cookie-key") == 0) { /* Dynamic cookies secret key */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 568 | |
| 569 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 570 | err_code |= ERR_WARN; |
| 571 | |
| 572 | if (*(args[1]) == 0) { |
| 573 | ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n", |
| 574 | file, linenum, args[0]); |
| 575 | err_code |= ERR_ALERT | ERR_FATAL; |
| 576 | goto out; |
| 577 | } |
| 578 | free(curproxy->dyncookie_key); |
| 579 | curproxy->dyncookie_key = strdup(args[1]); |
| 580 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 581 | else if (strcmp(args[0], "cookie") == 0) { /* cookie name */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 582 | int cur_arg; |
| 583 | |
| 584 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 585 | err_code |= ERR_WARN; |
| 586 | |
| 587 | if (*(args[1]) == 0) { |
| 588 | ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 589 | file, linenum, args[0]); |
| 590 | err_code |= ERR_ALERT | ERR_FATAL; |
| 591 | goto out; |
| 592 | } |
| 593 | |
| 594 | curproxy->ck_opts = 0; |
| 595 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
| 596 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
| 597 | free(curproxy->cookie_name); |
| 598 | curproxy->cookie_name = strdup(args[1]); |
| 599 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
| 600 | |
| 601 | cur_arg = 2; |
| 602 | while (*(args[cur_arg])) { |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 603 | if (strcmp(args[cur_arg], "rewrite") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 604 | curproxy->ck_opts |= PR_CK_RW; |
| 605 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 606 | else if (strcmp(args[cur_arg], "indirect") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 607 | curproxy->ck_opts |= PR_CK_IND; |
| 608 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 609 | else if (strcmp(args[cur_arg], "insert") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 610 | curproxy->ck_opts |= PR_CK_INS; |
| 611 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 612 | else if (strcmp(args[cur_arg], "nocache") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 613 | curproxy->ck_opts |= PR_CK_NOC; |
| 614 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 615 | else if (strcmp(args[cur_arg], "postonly") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 616 | curproxy->ck_opts |= PR_CK_POST; |
| 617 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 618 | else if (strcmp(args[cur_arg], "preserve") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 619 | curproxy->ck_opts |= PR_CK_PSV; |
| 620 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 621 | else if (strcmp(args[cur_arg], "prefix") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 622 | curproxy->ck_opts |= PR_CK_PFX; |
| 623 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 624 | else if (strcmp(args[cur_arg], "httponly") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 625 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 626 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 627 | else if (strcmp(args[cur_arg], "secure") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 628 | curproxy->ck_opts |= PR_CK_SECURE; |
| 629 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 630 | else if (strcmp(args[cur_arg], "domain") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 631 | if (!*args[cur_arg + 1]) { |
| 632 | ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 633 | file, linenum, args[cur_arg]); |
| 634 | err_code |= ERR_ALERT | ERR_FATAL; |
| 635 | goto out; |
| 636 | } |
| 637 | |
Joao Morais | e158375 | 2019-10-30 21:04:00 -0300 | [diff] [blame] | 638 | if (!strchr(args[cur_arg + 1], '.')) { |
| 639 | /* rfc6265, 5.2.3 The Domain Attribute */ |
| 640 | ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot," |
| 641 | " this configuration may not work properly (see RFC6265#5.2.3).\n", |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 642 | file, linenum, args[cur_arg + 1]); |
| 643 | err_code |= ERR_WARN; |
| 644 | } |
| 645 | |
| 646 | err = invalid_domainchar(args[cur_arg + 1]); |
| 647 | if (err) { |
| 648 | ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 649 | file, linenum, *err, args[cur_arg + 1]); |
| 650 | err_code |= ERR_ALERT | ERR_FATAL; |
| 651 | goto out; |
| 652 | } |
| 653 | |
| 654 | if (!curproxy->cookie_domain) { |
| 655 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 656 | } else { |
| 657 | /* one domain was already specified, add another one by |
| 658 | * building the string which will be returned along with |
| 659 | * the cookie. |
| 660 | */ |
| 661 | char *new_ptr; |
| 662 | int new_len = strlen(curproxy->cookie_domain) + |
| 663 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 664 | new_ptr = malloc(new_len); |
| 665 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 666 | free(curproxy->cookie_domain); |
| 667 | curproxy->cookie_domain = new_ptr; |
| 668 | } |
| 669 | cur_arg++; |
| 670 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 671 | else if (strcmp(args[cur_arg], "maxidle") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 672 | unsigned int maxidle; |
| 673 | const char *res; |
| 674 | |
| 675 | if (!*args[cur_arg + 1]) { |
| 676 | ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 677 | file, linenum, args[cur_arg]); |
| 678 | err_code |= ERR_ALERT | ERR_FATAL; |
| 679 | goto out; |
| 680 | } |
| 681 | |
| 682 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 683 | if (res == PARSE_TIME_OVER) { |
| 684 | ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n", |
| 685 | file, linenum, args[cur_arg+1], args[cur_arg]); |
| 686 | err_code |= ERR_ALERT | ERR_FATAL; |
| 687 | goto out; |
| 688 | } |
| 689 | else if (res == PARSE_TIME_UNDER) { |
| 690 | ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n", |
| 691 | file, linenum, args[cur_arg+1], args[cur_arg]); |
| 692 | err_code |= ERR_ALERT | ERR_FATAL; |
| 693 | goto out; |
| 694 | } |
| 695 | else if (res) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 696 | ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 697 | file, linenum, *res, args[cur_arg]); |
| 698 | err_code |= ERR_ALERT | ERR_FATAL; |
| 699 | goto out; |
| 700 | } |
| 701 | curproxy->cookie_maxidle = maxidle; |
| 702 | cur_arg++; |
| 703 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 704 | else if (strcmp(args[cur_arg], "maxlife") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 705 | unsigned int maxlife; |
| 706 | const char *res; |
| 707 | |
| 708 | if (!*args[cur_arg + 1]) { |
| 709 | ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 710 | file, linenum, args[cur_arg]); |
| 711 | err_code |= ERR_ALERT | ERR_FATAL; |
| 712 | goto out; |
| 713 | } |
| 714 | |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 715 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 716 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 717 | if (res == PARSE_TIME_OVER) { |
| 718 | ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n", |
| 719 | file, linenum, args[cur_arg+1], args[cur_arg]); |
| 720 | err_code |= ERR_ALERT | ERR_FATAL; |
| 721 | goto out; |
| 722 | } |
| 723 | else if (res == PARSE_TIME_UNDER) { |
| 724 | ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n", |
| 725 | file, linenum, args[cur_arg+1], args[cur_arg]); |
| 726 | err_code |= ERR_ALERT | ERR_FATAL; |
| 727 | goto out; |
| 728 | } |
| 729 | else if (res) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 730 | ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 731 | file, linenum, *res, args[cur_arg]); |
| 732 | err_code |= ERR_ALERT | ERR_FATAL; |
| 733 | goto out; |
| 734 | } |
| 735 | curproxy->cookie_maxlife = maxlife; |
| 736 | cur_arg++; |
| 737 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 738 | else if (strcmp(args[cur_arg], "dynamic") == 0) { /* Dynamic persistent cookies secret key */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 739 | |
| 740 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL)) |
| 741 | err_code |= ERR_WARN; |
| 742 | curproxy->ck_opts |= PR_CK_DYNAMIC; |
| 743 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 744 | else if (strcmp(args[cur_arg], "attr") == 0) { |
Christopher Faulet | 2f53390 | 2020-01-21 11:06:48 +0100 | [diff] [blame] | 745 | char *val; |
| 746 | if (!*args[cur_arg + 1]) { |
| 747 | ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n", |
| 748 | file, linenum, args[cur_arg]); |
| 749 | err_code |= ERR_ALERT | ERR_FATAL; |
| 750 | goto out; |
| 751 | } |
| 752 | val = args[cur_arg + 1]; |
| 753 | while (*val) { |
Willy Tarreau | 9080711 | 2020-02-25 08:16:33 +0100 | [diff] [blame] | 754 | if (iscntrl((unsigned char)*val) || *val == ';') { |
Christopher Faulet | 2f53390 | 2020-01-21 11:06:48 +0100 | [diff] [blame] | 755 | ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n", |
| 756 | file, linenum, *val); |
| 757 | err_code |= ERR_ALERT | ERR_FATAL; |
| 758 | goto out; |
| 759 | } |
| 760 | val++; |
| 761 | } |
| 762 | /* don't add ';' for the first attribute */ |
| 763 | if (!curproxy->cookie_attrs) |
| 764 | curproxy->cookie_attrs = strdup(args[cur_arg + 1]); |
| 765 | else |
| 766 | memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]); |
| 767 | cur_arg++; |
| 768 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 769 | |
| 770 | else { |
Christopher Faulet | 2f53390 | 2020-01-21 11:06:48 +0100 | [diff] [blame] | 771 | ha_alert("parsing [%s:%d] : '%s' supports 'rewrite', 'insert', 'prefix', 'indirect', 'nocache', 'postonly', 'domain', 'maxidle', 'dynamic', 'maxlife' and 'attr' options.\n", |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 772 | file, linenum, args[0]); |
| 773 | err_code |= ERR_ALERT | ERR_FATAL; |
| 774 | goto out; |
| 775 | } |
| 776 | cur_arg++; |
| 777 | } |
| 778 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
| 779 | ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 780 | file, linenum); |
| 781 | err_code |= ERR_ALERT | ERR_FATAL; |
| 782 | } |
| 783 | |
| 784 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) { |
| 785 | ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 786 | file, linenum); |
| 787 | err_code |= ERR_ALERT | ERR_FATAL; |
| 788 | } |
| 789 | |
| 790 | if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) { |
| 791 | ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 792 | file, linenum); |
| 793 | err_code |= ERR_ALERT | ERR_FATAL; |
| 794 | } |
| 795 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 796 | else if (strcmp(args[0], "email-alert") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 797 | if (*(args[1]) == 0) { |
| 798 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 799 | file, linenum, args[0]); |
| 800 | err_code |= ERR_ALERT | ERR_FATAL; |
| 801 | goto out; |
| 802 | } |
| 803 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 804 | if (strcmp(args[1], "from") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 805 | if (*(args[1]) == 0) { |
| 806 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 807 | file, linenum, args[1]); |
| 808 | err_code |= ERR_ALERT | ERR_FATAL; |
| 809 | goto out; |
| 810 | } |
| 811 | free(curproxy->email_alert.from); |
| 812 | curproxy->email_alert.from = strdup(args[2]); |
| 813 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 814 | else if (strcmp(args[1], "mailers") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 815 | if (*(args[1]) == 0) { |
| 816 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 817 | file, linenum, args[1]); |
| 818 | err_code |= ERR_ALERT | ERR_FATAL; |
| 819 | goto out; |
| 820 | } |
| 821 | free(curproxy->email_alert.mailers.name); |
| 822 | curproxy->email_alert.mailers.name = strdup(args[2]); |
| 823 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 824 | else if (strcmp(args[1], "myhostname") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 825 | if (*(args[1]) == 0) { |
| 826 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 827 | file, linenum, args[1]); |
| 828 | err_code |= ERR_ALERT | ERR_FATAL; |
| 829 | goto out; |
| 830 | } |
| 831 | free(curproxy->email_alert.myhostname); |
| 832 | curproxy->email_alert.myhostname = strdup(args[2]); |
| 833 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 834 | else if (strcmp(args[1], "level") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 835 | curproxy->email_alert.level = get_log_level(args[2]); |
| 836 | if (curproxy->email_alert.level < 0) { |
| 837 | ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n", |
| 838 | file, linenum, args[1], args[2]); |
| 839 | err_code |= ERR_ALERT | ERR_FATAL; |
| 840 | goto out; |
| 841 | } |
| 842 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 843 | else if (strcmp(args[1], "to") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 844 | if (*(args[1]) == 0) { |
| 845 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 846 | file, linenum, args[1]); |
| 847 | err_code |= ERR_ALERT | ERR_FATAL; |
| 848 | goto out; |
| 849 | } |
| 850 | free(curproxy->email_alert.to); |
| 851 | curproxy->email_alert.to = strdup(args[2]); |
| 852 | } |
| 853 | else { |
| 854 | ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n", |
| 855 | file, linenum, args[1]); |
| 856 | err_code |= ERR_ALERT | ERR_FATAL; |
| 857 | goto out; |
| 858 | } |
| 859 | /* Indicate that the email_alert is at least partially configured */ |
| 860 | curproxy->email_alert.set = 1; |
| 861 | }/* end else if (!strcmp(args[0], "email-alert")) */ |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 862 | else if (strcmp(args[0], "persist") == 0) { /* persist */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 863 | if (*(args[1]) == 0) { |
| 864 | ha_alert("parsing [%s:%d] : missing persist method.\n", |
| 865 | file, linenum); |
| 866 | err_code |= ERR_ALERT | ERR_FATAL; |
| 867 | goto out; |
| 868 | } |
| 869 | |
| 870 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 871 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 872 | |
| 873 | if (*(args[1] + 10) == '(') { /* cookie name */ |
| 874 | const char *beg, *end; |
| 875 | |
| 876 | beg = args[1] + 11; |
| 877 | end = strchr(beg, ')'); |
| 878 | |
| 879 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 880 | goto out; |
| 881 | |
| 882 | if (!end || end == beg) { |
| 883 | ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 884 | file, linenum); |
| 885 | err_code |= ERR_ALERT | ERR_FATAL; |
| 886 | goto out; |
| 887 | } |
| 888 | |
| 889 | free(curproxy->rdp_cookie_name); |
| 890 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 891 | curproxy->rdp_cookie_len = end-beg; |
| 892 | } |
| 893 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
| 894 | free(curproxy->rdp_cookie_name); |
| 895 | curproxy->rdp_cookie_name = strdup("msts"); |
| 896 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 897 | } |
| 898 | else { /* syntax */ |
| 899 | ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 900 | file, linenum); |
| 901 | err_code |= ERR_ALERT | ERR_FATAL; |
| 902 | goto out; |
| 903 | } |
| 904 | } |
| 905 | else { |
| 906 | ha_alert("parsing [%s:%d] : unknown persist method.\n", |
| 907 | file, linenum); |
| 908 | err_code |= ERR_ALERT | ERR_FATAL; |
| 909 | goto out; |
| 910 | } |
| 911 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 912 | else if (strcmp(args[0], "appsession") == 0) { /* cookie name */ |
Tim Duesterhus | 473c283 | 2019-05-06 01:19:52 +0200 | [diff] [blame] | 913 | ha_alert("parsing [%s:%d] : '%s' is not supported anymore since HAProxy 1.6.\n", file, linenum, args[0]); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 914 | err_code |= ERR_ALERT | ERR_FATAL; |
| 915 | goto out; |
| 916 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 917 | else if (strcmp(args[0], "load-server-state-from-file") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 918 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 919 | err_code |= ERR_WARN; |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 920 | if (strcmp(args[1], "global") == 0) { /* use the file pointed to by global server-state-file directive */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 921 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL; |
| 922 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 923 | else if (strcmp(args[1], "local") == 0) { /* use the server-state-file-name variable to locate the server-state file */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 924 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL; |
| 925 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 926 | else if (strcmp(args[1], "none") == 0) { /* don't use server-state-file directive for this backend */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 927 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE; |
| 928 | } |
| 929 | else { |
| 930 | ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n", |
| 931 | file, linenum, args[0], args[1]); |
| 932 | err_code |= ERR_ALERT | ERR_FATAL; |
| 933 | goto out; |
| 934 | } |
| 935 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 936 | else if (strcmp(args[0], "server-state-file-name") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 937 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 938 | err_code |= ERR_WARN; |
Christopher Faulet | 583b6de | 2021-02-12 09:27:10 +0100 | [diff] [blame] | 939 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 940 | goto out; |
Christopher Faulet | 583b6de | 2021-02-12 09:27:10 +0100 | [diff] [blame] | 941 | |
| 942 | free(curproxy->server_state_file_name); |
| 943 | curproxy->server_state_file_name = NULL; |
| 944 | |
| 945 | if (*(args[1]) == 0 || strcmp(args[1], "use-backend-name") == 0) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 946 | curproxy->server_state_file_name = strdup(curproxy->id); |
| 947 | else |
| 948 | curproxy->server_state_file_name = strdup(args[1]); |
| 949 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 950 | else if (strcmp(args[0], "max-session-srv-conns") == 0) { |
Olivier Houchard | a4d4fdf | 2018-12-14 19:27:06 +0100 | [diff] [blame] | 951 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
| 952 | err_code |= ERR_WARN; |
| 953 | if (*(args[1]) == 0) { |
| 954 | ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n", |
| 955 | file, linenum, args[0]); |
| 956 | err_code |= ERR_ALERT | ERR_FATAL; |
| 957 | goto out; |
| 958 | } |
| 959 | curproxy->max_out_conns = atoi(args[1]); |
| 960 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 961 | else if (strcmp(args[0], "capture") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 962 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
| 963 | err_code |= ERR_WARN; |
| 964 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 965 | if (strcmp(args[1], "cookie") == 0) { /* name of a cookie to capture */ |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 966 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 967 | ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 968 | err_code |= ERR_ALERT | ERR_FATAL; |
| 969 | goto out; |
| 970 | } |
| 971 | |
| 972 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 973 | goto out; |
| 974 | |
| 975 | if (*(args[4]) == 0) { |
| 976 | ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 977 | file, linenum, args[0]); |
| 978 | err_code |= ERR_ALERT | ERR_FATAL; |
| 979 | goto out; |
| 980 | } |
| 981 | free(curproxy->capture_name); |
| 982 | curproxy->capture_name = strdup(args[2]); |
| 983 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 984 | curproxy->capture_len = atol(args[4]); |
| 985 | curproxy->to_log |= LW_COOKIE; |
| 986 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 987 | else if (strcmp(args[1], "request") == 0 && strcmp(args[2], "header") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 988 | struct cap_hdr *hdr; |
| 989 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 990 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 991 | ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 992 | err_code |= ERR_ALERT | ERR_FATAL; |
| 993 | goto out; |
| 994 | } |
| 995 | |
| 996 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 997 | goto out; |
| 998 | |
| 999 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 1000 | ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 1001 | file, linenum, args[0], args[1]); |
| 1002 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1003 | goto out; |
| 1004 | } |
| 1005 | |
| 1006 | hdr = calloc(1, sizeof(*hdr)); |
| 1007 | hdr->next = curproxy->req_cap; |
| 1008 | hdr->name = strdup(args[3]); |
| 1009 | hdr->namelen = strlen(args[3]); |
| 1010 | hdr->len = atol(args[5]); |
| 1011 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
| 1012 | hdr->index = curproxy->nb_req_cap++; |
| 1013 | curproxy->req_cap = hdr; |
| 1014 | curproxy->to_log |= LW_REQHDR; |
| 1015 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1016 | else if (strcmp(args[1], "response") == 0 && strcmp(args[2], "header") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1017 | struct cap_hdr *hdr; |
| 1018 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1019 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1020 | ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 1021 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1022 | goto out; |
| 1023 | } |
| 1024 | |
| 1025 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 1026 | goto out; |
| 1027 | |
| 1028 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 1029 | ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 1030 | file, linenum, args[0], args[1]); |
| 1031 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1032 | goto out; |
| 1033 | } |
| 1034 | hdr = calloc(1, sizeof(*hdr)); |
| 1035 | hdr->next = curproxy->rsp_cap; |
| 1036 | hdr->name = strdup(args[3]); |
| 1037 | hdr->namelen = strlen(args[3]); |
| 1038 | hdr->len = atol(args[5]); |
| 1039 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
| 1040 | hdr->index = curproxy->nb_rsp_cap++; |
| 1041 | curproxy->rsp_cap = hdr; |
| 1042 | curproxy->to_log |= LW_RSPHDR; |
| 1043 | } |
| 1044 | else { |
| 1045 | ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 1046 | file, linenum, args[0]); |
| 1047 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1048 | goto out; |
| 1049 | } |
| 1050 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1051 | else if (strcmp(args[0], "retries") == 0) { /* connection retries */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1052 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 1053 | err_code |= ERR_WARN; |
| 1054 | |
| 1055 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1056 | goto out; |
| 1057 | |
| 1058 | if (*(args[1]) == 0) { |
| 1059 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 1060 | file, linenum, args[0]); |
| 1061 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1062 | goto out; |
| 1063 | } |
| 1064 | curproxy->conn_retries = atol(args[1]); |
| 1065 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1066 | else if (strcmp(args[0], "http-request") == 0) { /* request access control: allow/deny/auth */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1067 | struct act_rule *rule; |
| 1068 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1069 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1070 | ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1071 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1072 | goto out; |
| 1073 | } |
| 1074 | |
| 1075 | if (!LIST_ISEMPTY(&curproxy->http_req_rules) && |
| 1076 | !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond && |
Christopher Faulet | 245cf79 | 2019-12-18 14:58:12 +0100 | [diff] [blame] | 1077 | (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1078 | ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 1079 | file, linenum, args[0]); |
| 1080 | err_code |= ERR_WARN; |
| 1081 | } |
| 1082 | |
| 1083 | rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy); |
| 1084 | |
| 1085 | if (!rule) { |
| 1086 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1087 | goto out; |
| 1088 | } |
| 1089 | |
| 1090 | err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]); |
| 1091 | err_code |= warnif_cond_conflicts(rule->cond, |
| 1092 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 1093 | file, linenum); |
| 1094 | |
| 1095 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
| 1096 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1097 | else if (strcmp(args[0], "http-response") == 0) { /* response access control */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1098 | struct act_rule *rule; |
| 1099 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1100 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1101 | ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1102 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1103 | goto out; |
| 1104 | } |
| 1105 | |
| 1106 | if (!LIST_ISEMPTY(&curproxy->http_res_rules) && |
| 1107 | !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond && |
Christopher Faulet | 245cf79 | 2019-12-18 14:58:12 +0100 | [diff] [blame] | 1108 | (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1109 | ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 1110 | file, linenum, args[0]); |
| 1111 | err_code |= ERR_WARN; |
| 1112 | } |
| 1113 | |
| 1114 | rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy); |
| 1115 | |
| 1116 | if (!rule) { |
| 1117 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1118 | goto out; |
| 1119 | } |
| 1120 | |
| 1121 | err_code |= warnif_cond_conflicts(rule->cond, |
| 1122 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 1123 | file, linenum); |
| 1124 | |
| 1125 | LIST_ADDQ(&curproxy->http_res_rules, &rule->list); |
| 1126 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1127 | else if (strcmp(args[0], "http-after-response") == 0) { |
Christopher Faulet | 6d0c3df | 2020-01-22 09:26:35 +0100 | [diff] [blame] | 1128 | struct act_rule *rule; |
| 1129 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1130 | if (curproxy->cap & PR_CAP_DEF) { |
Christopher Faulet | 6d0c3df | 2020-01-22 09:26:35 +0100 | [diff] [blame] | 1131 | ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1132 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1133 | goto out; |
| 1134 | } |
| 1135 | |
| 1136 | if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) && |
| 1137 | !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond && |
| 1138 | (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) { |
| 1139 | ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 1140 | file, linenum, args[0]); |
| 1141 | err_code |= ERR_WARN; |
| 1142 | } |
| 1143 | |
| 1144 | rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy); |
| 1145 | |
| 1146 | if (!rule) { |
| 1147 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1148 | goto out; |
| 1149 | } |
| 1150 | |
| 1151 | err_code |= warnif_cond_conflicts(rule->cond, |
| 1152 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 1153 | file, linenum); |
| 1154 | |
| 1155 | LIST_ADDQ(&curproxy->http_after_res_rules, &rule->list); |
| 1156 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1157 | else if (strcmp(args[0], "http-send-name-header") == 0) { /* send server name in request header */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1158 | /* set the header name and length into the proxy structure */ |
| 1159 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 1160 | err_code |= ERR_WARN; |
| 1161 | |
| 1162 | if (!*args[1]) { |
| 1163 | ha_alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 1164 | file, linenum, args[0]); |
| 1165 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1166 | goto out; |
| 1167 | } |
| 1168 | |
Christopher Faulet | dabcc8e | 2019-10-02 10:45:55 +0200 | [diff] [blame] | 1169 | /* set the desired header name, in lower case */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1170 | free(curproxy->server_id_hdr_name); |
| 1171 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 1172 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
Christopher Faulet | dabcc8e | 2019-10-02 10:45:55 +0200 | [diff] [blame] | 1173 | ist2bin_lc(curproxy->server_id_hdr_name, ist2(curproxy->server_id_hdr_name, curproxy->server_id_hdr_len)); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1174 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1175 | else if (strcmp(args[0], "block") == 0) { |
Tim Duesterhus | 7b7c47f | 2019-05-14 20:57:57 +0200 | [diff] [blame] | 1176 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. Use 'http-request deny' which uses the exact same syntax.\n", file, linenum, args[0]); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1177 | |
Tim Duesterhus | 7b7c47f | 2019-05-14 20:57:57 +0200 | [diff] [blame] | 1178 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1179 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1180 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1181 | else if (strcmp(args[0], "redirect") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1182 | struct redirect_rule *rule; |
| 1183 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1184 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1185 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1186 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1187 | goto out; |
| 1188 | } |
| 1189 | |
| 1190 | if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) { |
| 1191 | ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n", |
| 1192 | file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg); |
| 1193 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1194 | goto out; |
| 1195 | } |
| 1196 | |
| 1197 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
| 1198 | err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]); |
| 1199 | err_code |= warnif_cond_conflicts(rule->cond, |
| 1200 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 1201 | file, linenum); |
| 1202 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1203 | else if (strcmp(args[0], "use_backend") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1204 | struct switching_rule *rule; |
| 1205 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1206 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1207 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1208 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1209 | goto out; |
| 1210 | } |
| 1211 | |
| 1212 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
| 1213 | err_code |= ERR_WARN; |
| 1214 | |
| 1215 | if (*(args[1]) == 0) { |
| 1216 | ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]); |
| 1217 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1218 | goto out; |
| 1219 | } |
| 1220 | |
| 1221 | if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) { |
| 1222 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 1223 | ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 1224 | file, linenum, errmsg); |
| 1225 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1226 | goto out; |
| 1227 | } |
| 1228 | |
| 1229 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum); |
| 1230 | } |
| 1231 | else if (*args[2]) { |
| 1232 | ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n", |
| 1233 | file, linenum, args[2]); |
| 1234 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1235 | goto out; |
| 1236 | } |
| 1237 | |
| 1238 | rule = calloc(1, sizeof(*rule)); |
| 1239 | if (!rule) { |
| 1240 | ha_alert("Out of memory error.\n"); |
| 1241 | goto out; |
| 1242 | } |
| 1243 | rule->cond = cond; |
| 1244 | rule->be.name = strdup(args[1]); |
Tim Duesterhus | 5ce5a15 | 2021-01-03 22:54:43 +0100 | [diff] [blame] | 1245 | if (!rule->be.name) { |
| 1246 | ha_alert("Out of memory error.\n"); |
| 1247 | goto out; |
| 1248 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1249 | rule->line = linenum; |
| 1250 | rule->file = strdup(file); |
| 1251 | if (!rule->file) { |
| 1252 | ha_alert("Out of memory error.\n"); |
| 1253 | goto out; |
| 1254 | } |
| 1255 | LIST_INIT(&rule->list); |
| 1256 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 1257 | } |
| 1258 | else if (strcmp(args[0], "use-server") == 0) { |
| 1259 | struct server_rule *rule; |
| 1260 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1261 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1262 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1263 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1264 | goto out; |
| 1265 | } |
| 1266 | |
| 1267 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 1268 | err_code |= ERR_WARN; |
| 1269 | |
| 1270 | if (*(args[1]) == 0) { |
| 1271 | ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 1272 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1273 | goto out; |
| 1274 | } |
| 1275 | |
| 1276 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 1277 | ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 1278 | file, linenum, args[0]); |
| 1279 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1280 | goto out; |
| 1281 | } |
| 1282 | |
| 1283 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 1284 | ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 1285 | file, linenum, errmsg); |
| 1286 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1287 | goto out; |
| 1288 | } |
| 1289 | |
| 1290 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum); |
| 1291 | |
| 1292 | rule = calloc(1, sizeof(*rule)); |
| 1293 | rule->cond = cond; |
| 1294 | rule->srv.name = strdup(args[1]); |
Jerome Magnin | 824186b | 2020-03-29 09:37:12 +0200 | [diff] [blame] | 1295 | rule->line = linenum; |
| 1296 | rule->file = strdup(file); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1297 | LIST_INIT(&rule->list); |
| 1298 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 1299 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 1300 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1301 | else if ((strcmp(args[0], "force-persist") == 0) || |
| 1302 | (strcmp(args[0], "ignore-persist") == 0)) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1303 | struct persist_rule *rule; |
| 1304 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1305 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1306 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1307 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1308 | goto out; |
| 1309 | } |
| 1310 | |
| 1311 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 1312 | err_code |= ERR_WARN; |
| 1313 | |
| 1314 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
| 1315 | ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 1316 | file, linenum, args[0]); |
| 1317 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1318 | goto out; |
| 1319 | } |
| 1320 | |
| 1321 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 1322 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 1323 | file, linenum, args[0], errmsg); |
| 1324 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1325 | goto out; |
| 1326 | } |
| 1327 | |
| 1328 | /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is |
| 1329 | * where force-persist is applied. |
| 1330 | */ |
| 1331 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum); |
| 1332 | |
| 1333 | rule = calloc(1, sizeof(*rule)); |
| 1334 | rule->cond = cond; |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1335 | if (strcmp(args[0], "force-persist") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1336 | rule->type = PERSIST_TYPE_FORCE; |
| 1337 | } else { |
| 1338 | rule->type = PERSIST_TYPE_IGNORE; |
| 1339 | } |
| 1340 | LIST_INIT(&rule->list); |
| 1341 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
| 1342 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1343 | else if (strcmp(args[0], "stick-table") == 0) { |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1344 | struct stktable *other; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1345 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1346 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1347 | ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n", |
| 1348 | file, linenum); |
| 1349 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1350 | goto out; |
| 1351 | } |
| 1352 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1353 | other = stktable_find_by_name(curproxy->id); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1354 | if (other) { |
| 1355 | ha_alert("parsing [%s:%d] : stick-table name '%s' conflicts with table declared in %s '%s' at %s:%d.\n", |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1356 | file, linenum, curproxy->id, |
| 1357 | other->proxy ? proxy_cap_str(other->proxy->cap) : "peers", |
| 1358 | other->proxy ? other->id : other->peers.p->id, |
| 1359 | other->conf.file, other->conf.line); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1360 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1361 | goto out; |
| 1362 | } |
| 1363 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1364 | curproxy->table = calloc(1, sizeof *curproxy->table); |
| 1365 | if (!curproxy->table) { |
| 1366 | ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n", |
| 1367 | file, linenum, args[0], args[1]); |
| 1368 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1369 | goto out; |
| 1370 | } |
| 1371 | |
Frédéric Lécaille | c02766a | 2019-03-20 15:06:55 +0100 | [diff] [blame] | 1372 | err_code |= parse_stick_table(file, linenum, args, curproxy->table, |
| 1373 | curproxy->id, curproxy->id, NULL); |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 1374 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1375 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1376 | |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 1377 | /* Store the proxy in the stick-table. */ |
| 1378 | curproxy->table->proxy = curproxy; |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1379 | |
| 1380 | stktable_store_name(curproxy->table); |
| 1381 | curproxy->table->next = stktables_list; |
| 1382 | stktables_list = curproxy->table; |
Frédéric Lécaille | 015e4d7 | 2019-03-19 14:55:01 +0100 | [diff] [blame] | 1383 | |
| 1384 | /* Add this proxy to the list of proxies which refer to its stick-table. */ |
| 1385 | if (curproxy->table->proxies_list != curproxy) { |
| 1386 | curproxy->next_stkt_ref = curproxy->table->proxies_list; |
| 1387 | curproxy->table->proxies_list = curproxy; |
| 1388 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1389 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1390 | else if (strcmp(args[0], "stick") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1391 | struct sticking_rule *rule; |
| 1392 | struct sample_expr *expr; |
| 1393 | int myidx = 0; |
| 1394 | const char *name = NULL; |
| 1395 | int flags; |
| 1396 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1397 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1398 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1399 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1400 | goto out; |
| 1401 | } |
| 1402 | |
| 1403 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 1404 | err_code |= ERR_WARN; |
| 1405 | goto out; |
| 1406 | } |
| 1407 | |
| 1408 | myidx++; |
| 1409 | if ((strcmp(args[myidx], "store") == 0) || |
| 1410 | (strcmp(args[myidx], "store-request") == 0)) { |
| 1411 | myidx++; |
| 1412 | flags = STK_IS_STORE; |
| 1413 | } |
| 1414 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 1415 | myidx++; |
| 1416 | flags = STK_IS_STORE | STK_ON_RSP; |
| 1417 | } |
| 1418 | else if (strcmp(args[myidx], "match") == 0) { |
| 1419 | myidx++; |
| 1420 | flags = STK_IS_MATCH; |
| 1421 | } |
| 1422 | else if (strcmp(args[myidx], "on") == 0) { |
| 1423 | myidx++; |
| 1424 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 1425 | } |
| 1426 | else { |
| 1427 | ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 1428 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1429 | goto out; |
| 1430 | } |
| 1431 | |
| 1432 | if (*(args[myidx]) == 0) { |
| 1433 | ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 1434 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1435 | goto out; |
| 1436 | } |
| 1437 | |
| 1438 | curproxy->conf.args.ctx = ARGC_STK; |
Willy Tarreau | e3b57bf | 2020-02-14 16:50:14 +0100 | [diff] [blame] | 1439 | expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1440 | if (!expr) { |
| 1441 | ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
| 1442 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1443 | goto out; |
| 1444 | } |
| 1445 | |
| 1446 | if (flags & STK_ON_RSP) { |
| 1447 | if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) { |
| 1448 | ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n", |
| 1449 | file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use)); |
| 1450 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1451 | free(expr); |
| 1452 | goto out; |
| 1453 | } |
| 1454 | } else { |
| 1455 | if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) { |
| 1456 | ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n", |
| 1457 | file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use)); |
| 1458 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1459 | free(expr); |
| 1460 | goto out; |
| 1461 | } |
| 1462 | } |
| 1463 | |
Christopher Faulet | 711ed6a | 2019-07-16 14:16:10 +0200 | [diff] [blame] | 1464 | /* check if we need to allocate an http_txn struct for HTTP parsing */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1465 | curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
| 1466 | |
| 1467 | if (strcmp(args[myidx], "table") == 0) { |
| 1468 | myidx++; |
| 1469 | name = args[myidx++]; |
| 1470 | } |
| 1471 | |
| 1472 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
| 1473 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 1474 | ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 1475 | file, linenum, args[0], errmsg); |
| 1476 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1477 | free(expr); |
| 1478 | goto out; |
| 1479 | } |
| 1480 | } |
| 1481 | else if (*(args[myidx])) { |
| 1482 | ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 1483 | file, linenum, args[0], args[myidx]); |
| 1484 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1485 | free(expr); |
| 1486 | goto out; |
| 1487 | } |
| 1488 | if (flags & STK_ON_RSP) |
| 1489 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum); |
| 1490 | else |
| 1491 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum); |
| 1492 | |
| 1493 | rule = calloc(1, sizeof(*rule)); |
| 1494 | rule->cond = cond; |
| 1495 | rule->expr = expr; |
| 1496 | rule->flags = flags; |
| 1497 | rule->table.name = name ? strdup(name) : NULL; |
| 1498 | LIST_INIT(&rule->list); |
| 1499 | if (flags & STK_ON_RSP) |
| 1500 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 1501 | else |
| 1502 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 1503 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1504 | else if (strcmp(args[0], "stats") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame^] | 1505 | if (!(curproxy->cap & PR_CAP_DEF) && curproxy->uri_auth == curr_defproxy->uri_auth) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1506 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 1507 | |
| 1508 | if (!*args[1]) { |
| 1509 | goto stats_error_parsing; |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1510 | } else if (strcmp(args[1], "admin") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1511 | struct stats_admin_rule *rule; |
| 1512 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1513 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1514 | ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 1515 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1516 | goto out; |
| 1517 | } |
| 1518 | |
| 1519 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 1520 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 1521 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1522 | goto out; |
| 1523 | } |
| 1524 | |
| 1525 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 1526 | ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 1527 | file, linenum, args[0], args[1]); |
| 1528 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1529 | goto out; |
| 1530 | } |
| 1531 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 1532 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 1533 | file, linenum, args[0], args[1], errmsg); |
| 1534 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1535 | goto out; |
| 1536 | } |
| 1537 | |
| 1538 | err_code |= warnif_cond_conflicts(cond, |
| 1539 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 1540 | file, linenum); |
| 1541 | |
| 1542 | rule = calloc(1, sizeof(*rule)); |
| 1543 | rule->cond = cond; |
| 1544 | LIST_INIT(&rule->list); |
| 1545 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1546 | } else if (strcmp(args[1], "uri") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1547 | if (*(args[2]) == 0) { |
| 1548 | ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
| 1549 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1550 | goto out; |
| 1551 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 1552 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1553 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1554 | goto out; |
| 1555 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1556 | } else if (strcmp(args[1], "realm") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1557 | if (*(args[2]) == 0) { |
| 1558 | ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
| 1559 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1560 | goto out; |
| 1561 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 1562 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1563 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1564 | goto out; |
| 1565 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1566 | } else if (strcmp(args[1], "refresh") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1567 | unsigned interval; |
| 1568 | |
| 1569 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 1570 | if (err == PARSE_TIME_OVER) { |
| 1571 | ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n", |
| 1572 | file, linenum, args[2]); |
| 1573 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1574 | goto out; |
| 1575 | } |
| 1576 | else if (err == PARSE_TIME_UNDER) { |
| 1577 | ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n", |
| 1578 | file, linenum, args[2]); |
| 1579 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1580 | goto out; |
| 1581 | } |
| 1582 | else if (err) { |
| 1583 | ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n", |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1584 | file, linenum, *err); |
| 1585 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1586 | goto out; |
| 1587 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 1588 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1589 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1590 | goto out; |
| 1591 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1592 | } else if (strcmp(args[1], "http-request") == 0) { /* request access control: allow/deny/auth */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1593 | struct act_rule *rule; |
| 1594 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1595 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1596 | ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1597 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1598 | goto out; |
| 1599 | } |
| 1600 | |
| 1601 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 1602 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 1603 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1604 | goto out; |
| 1605 | } |
| 1606 | |
| 1607 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
| 1608 | !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) { |
| 1609 | ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 1610 | file, linenum, args[0]); |
| 1611 | err_code |= ERR_WARN; |
| 1612 | } |
| 1613 | |
| 1614 | rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy); |
| 1615 | |
| 1616 | if (!rule) { |
| 1617 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1618 | goto out; |
| 1619 | } |
| 1620 | |
| 1621 | err_code |= warnif_cond_conflicts(rule->cond, |
| 1622 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 1623 | file, linenum); |
| 1624 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
| 1625 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1626 | } else if (strcmp(args[1], "auth") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1627 | if (*(args[2]) == 0) { |
| 1628 | ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum); |
| 1629 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1630 | goto out; |
| 1631 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 1632 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1633 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1634 | goto out; |
| 1635 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1636 | } else if (strcmp(args[1], "scope") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1637 | if (*(args[2]) == 0) { |
| 1638 | ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
| 1639 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1640 | goto out; |
| 1641 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 1642 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1643 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1644 | goto out; |
| 1645 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1646 | } else if (strcmp(args[1], "enable") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1647 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 1648 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1649 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1650 | goto out; |
| 1651 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1652 | } else if (strcmp(args[1], "hide-version") == 0) { |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1653 | if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER)) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1654 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1655 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1656 | goto out; |
| 1657 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1658 | } else if (strcmp(args[1], "show-legends") == 0) { |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1659 | if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS)) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1660 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 1661 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1662 | goto out; |
| 1663 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1664 | } else if (strcmp(args[1], "show-modules") == 0) { |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1665 | if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES)) { |
| 1666 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 1667 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1668 | goto out; |
| 1669 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1670 | } else if (strcmp(args[1], "show-node") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1671 | |
| 1672 | if (*args[2]) { |
| 1673 | int i; |
| 1674 | char c; |
| 1675 | |
| 1676 | for (i=0; args[2][i]; i++) { |
| 1677 | c = args[2][i]; |
| 1678 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 1679 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
| 1680 | break; |
| 1681 | } |
| 1682 | |
| 1683 | if (!i || args[2][i]) { |
| 1684 | ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 1685 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 1686 | file, linenum, args[0], args[1]); |
| 1687 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1688 | goto out; |
| 1689 | } |
| 1690 | } |
| 1691 | |
| 1692 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 1693 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 1694 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1695 | goto out; |
| 1696 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1697 | } else if (strcmp(args[1], "show-desc") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1698 | char *desc = NULL; |
| 1699 | |
| 1700 | if (*args[2]) { |
| 1701 | int i, len=0; |
| 1702 | char *d; |
| 1703 | |
| 1704 | for (i = 2; *args[i]; i++) |
| 1705 | len += strlen(args[i]) + 1; |
| 1706 | |
| 1707 | desc = d = calloc(1, len); |
| 1708 | |
| 1709 | d += snprintf(d, desc + len - d, "%s", args[2]); |
| 1710 | for (i = 3; *args[i]; i++) |
| 1711 | d += snprintf(d, desc + len - d, " %s", args[i]); |
| 1712 | } |
| 1713 | |
| 1714 | if (!*args[2] && !global.desc) |
| 1715 | ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 1716 | file, linenum, args[1]); |
| 1717 | else { |
| 1718 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 1719 | free(desc); |
| 1720 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 1721 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1722 | goto out; |
| 1723 | } |
| 1724 | free(desc); |
| 1725 | } |
| 1726 | } else { |
| 1727 | stats_error_parsing: |
| 1728 | ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n", |
| 1729 | file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]); |
| 1730 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1731 | goto out; |
| 1732 | } |
| 1733 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1734 | else if (strcmp(args[0], "option") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1735 | int optnum; |
| 1736 | |
| 1737 | if (*(args[1]) == '\0') { |
| 1738 | ha_alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 1739 | file, linenum, args[0]); |
| 1740 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1741 | goto out; |
| 1742 | } |
| 1743 | |
| 1744 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1745 | if (strcmp(args[1], cfg_opts[optnum].name) == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1746 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 1747 | ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 1748 | file, linenum, cfg_opts[optnum].name); |
| 1749 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1750 | goto out; |
| 1751 | } |
| 1752 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 1753 | goto out; |
| 1754 | |
| 1755 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 1756 | err_code |= ERR_WARN; |
| 1757 | goto out; |
| 1758 | } |
| 1759 | |
| 1760 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 1761 | curproxy->options &= ~cfg_opts[optnum].val; |
| 1762 | |
| 1763 | switch (kwm) { |
| 1764 | case KWM_STD: |
| 1765 | curproxy->options |= cfg_opts[optnum].val; |
| 1766 | break; |
| 1767 | case KWM_NO: |
| 1768 | curproxy->no_options |= cfg_opts[optnum].val; |
| 1769 | break; |
| 1770 | case KWM_DEF: /* already cleared */ |
| 1771 | break; |
| 1772 | } |
| 1773 | |
| 1774 | goto out; |
| 1775 | } |
| 1776 | } |
| 1777 | |
| 1778 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1779 | if (strcmp(args[1], cfg_opts2[optnum].name) == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1780 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 1781 | ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 1782 | file, linenum, cfg_opts2[optnum].name); |
| 1783 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1784 | goto out; |
| 1785 | } |
| 1786 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 1787 | goto out; |
| 1788 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 1789 | err_code |= ERR_WARN; |
| 1790 | goto out; |
| 1791 | } |
| 1792 | |
Christopher Faulet | 3193037 | 2019-07-15 10:16:58 +0200 | [diff] [blame] | 1793 | /* "[no] option http-use-htx" is deprecated */ |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1794 | if (strcmp(cfg_opts2[optnum].name, "http-use-htx") == 0) { |
Christopher Faulet | f89f099 | 2019-07-19 11:17:38 +0200 | [diff] [blame] | 1795 | if (kwm ==KWM_NO) { |
| 1796 | ha_warning("parsing [%s:%d]: option '%s' is deprecated and ignored." |
| 1797 | " The HTX mode is now the only supported mode.\n", |
| 1798 | file, linenum, cfg_opts2[optnum].name); |
| 1799 | err_code |= ERR_WARN; |
| 1800 | } |
Christopher Faulet | 3193037 | 2019-07-15 10:16:58 +0200 | [diff] [blame] | 1801 | goto out; |
| 1802 | } |
| 1803 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1804 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 1805 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 1806 | |
| 1807 | switch (kwm) { |
| 1808 | case KWM_STD: |
| 1809 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 1810 | break; |
| 1811 | case KWM_NO: |
| 1812 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 1813 | break; |
| 1814 | case KWM_DEF: /* already cleared */ |
| 1815 | break; |
| 1816 | } |
| 1817 | goto out; |
| 1818 | } |
| 1819 | } |
| 1820 | |
| 1821 | /* HTTP options override each other. They can be cancelled using |
| 1822 | * "no option xxx" which only switches to default mode if the mode |
| 1823 | * was this one (useful for cancelling options set in defaults |
| 1824 | * sections). |
| 1825 | */ |
| 1826 | if (strcmp(args[1], "httpclose") == 0 || strcmp(args[1], "forceclose") == 0) { |
Tim Duesterhus | 10c6c16 | 2019-05-14 20:58:00 +0200 | [diff] [blame] | 1827 | if (strcmp(args[1], "forceclose") == 0) { |
| 1828 | if (!already_warned(WARN_FORCECLOSE_DEPRECATED)) |
| 1829 | ha_warning("parsing [%s:%d]: keyword '%s' is deprecated in favor of 'httpclose', and will not be supported by future versions.\n", |
| 1830 | file, linenum, args[1]); |
| 1831 | err_code |= ERR_WARN; |
| 1832 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1833 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 1834 | goto out; |
| 1835 | if (kwm == KWM_STD) { |
| 1836 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 1837 | curproxy->options |= PR_O_HTTP_CLO; |
| 1838 | goto out; |
| 1839 | } |
| 1840 | else if (kwm == KWM_NO) { |
| 1841 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO) |
| 1842 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 1843 | goto out; |
| 1844 | } |
| 1845 | } |
| 1846 | else if (strcmp(args[1], "http-server-close") == 0) { |
| 1847 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 1848 | goto out; |
| 1849 | if (kwm == KWM_STD) { |
| 1850 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 1851 | curproxy->options |= PR_O_HTTP_SCL; |
| 1852 | goto out; |
| 1853 | } |
| 1854 | else if (kwm == KWM_NO) { |
| 1855 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL) |
| 1856 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 1857 | goto out; |
| 1858 | } |
| 1859 | } |
| 1860 | else if (strcmp(args[1], "http-keep-alive") == 0) { |
| 1861 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 1862 | goto out; |
| 1863 | if (kwm == KWM_STD) { |
| 1864 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 1865 | curproxy->options |= PR_O_HTTP_KAL; |
| 1866 | goto out; |
| 1867 | } |
| 1868 | else if (kwm == KWM_NO) { |
| 1869 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL) |
| 1870 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 1871 | goto out; |
| 1872 | } |
| 1873 | } |
| 1874 | else if (strcmp(args[1], "http-tunnel") == 0) { |
Christopher Faulet | 73e8ede | 2019-07-16 15:04:46 +0200 | [diff] [blame] | 1875 | ha_warning("parsing [%s:%d]: the option '%s' is deprecated and will be removed in next version.\n", |
| 1876 | file, linenum, args[1]); |
| 1877 | err_code |= ERR_WARN; |
| 1878 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1879 | } |
| 1880 | |
| 1881 | /* Redispatch can take an integer argument that control when the |
| 1882 | * resispatch occurs. All values are relative to the retries option. |
| 1883 | * This can be cancelled using "no option xxx". |
| 1884 | */ |
| 1885 | if (strcmp(args[1], "redispatch") == 0) { |
| 1886 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) { |
| 1887 | err_code |= ERR_WARN; |
| 1888 | goto out; |
| 1889 | } |
| 1890 | |
| 1891 | curproxy->no_options &= ~PR_O_REDISP; |
| 1892 | curproxy->options &= ~PR_O_REDISP; |
| 1893 | |
| 1894 | switch (kwm) { |
| 1895 | case KWM_STD: |
| 1896 | curproxy->options |= PR_O_REDISP; |
| 1897 | curproxy->redispatch_after = -1; |
| 1898 | if(*args[2]) { |
| 1899 | curproxy->redispatch_after = atol(args[2]); |
| 1900 | } |
| 1901 | break; |
| 1902 | case KWM_NO: |
| 1903 | curproxy->no_options |= PR_O_REDISP; |
| 1904 | curproxy->redispatch_after = 0; |
| 1905 | break; |
| 1906 | case KWM_DEF: /* already cleared */ |
| 1907 | break; |
| 1908 | } |
| 1909 | goto out; |
| 1910 | } |
| 1911 | |
| 1912 | if (kwm != KWM_STD) { |
| 1913 | ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n", |
| 1914 | file, linenum, args[1]); |
| 1915 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1916 | goto out; |
| 1917 | } |
| 1918 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1919 | if (strcmp(args[1], "httplog") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1920 | char *logformat; |
| 1921 | /* generate a complete HTTP log */ |
| 1922 | logformat = default_http_log_format; |
| 1923 | if (*(args[2]) != '\0') { |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1924 | if (strcmp(args[2], "clf") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1925 | curproxy->options2 |= PR_O2_CLFLOG; |
| 1926 | logformat = clf_http_log_format; |
| 1927 | } else { |
| 1928 | ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]); |
| 1929 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1930 | goto out; |
| 1931 | } |
| 1932 | if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code)) |
| 1933 | goto out; |
| 1934 | } |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1935 | if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1936 | char *oldlogformat = "log-format"; |
| 1937 | char *clflogformat = ""; |
| 1938 | |
| 1939 | if (curproxy->conf.logformat_string == default_http_log_format) |
| 1940 | oldlogformat = "option httplog"; |
| 1941 | else if (curproxy->conf.logformat_string == default_tcp_log_format) |
| 1942 | oldlogformat = "option tcplog"; |
| 1943 | else if (curproxy->conf.logformat_string == clf_http_log_format) |
| 1944 | oldlogformat = "option httplog clf"; |
| 1945 | if (logformat == clf_http_log_format) |
| 1946 | clflogformat = " clf"; |
| 1947 | ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n", |
| 1948 | file, linenum, clflogformat, oldlogformat); |
| 1949 | } |
| 1950 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 1951 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 1952 | curproxy->conf.logformat_string != clf_http_log_format) |
| 1953 | free(curproxy->conf.logformat_string); |
| 1954 | curproxy->conf.logformat_string = logformat; |
| 1955 | |
| 1956 | free(curproxy->conf.lfs_file); |
| 1957 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 1958 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
| 1959 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1960 | if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1961 | ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n", |
| 1962 | file, linenum, curproxy->id); |
| 1963 | err_code |= ERR_WARN; |
| 1964 | } |
| 1965 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1966 | else if (strcmp(args[1], "tcplog") == 0) { |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1967 | if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1968 | char *oldlogformat = "log-format"; |
| 1969 | |
| 1970 | if (curproxy->conf.logformat_string == default_http_log_format) |
| 1971 | oldlogformat = "option httplog"; |
| 1972 | else if (curproxy->conf.logformat_string == default_tcp_log_format) |
| 1973 | oldlogformat = "option tcplog"; |
| 1974 | else if (curproxy->conf.logformat_string == clf_http_log_format) |
| 1975 | oldlogformat = "option httplog clf"; |
| 1976 | ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n", |
| 1977 | file, linenum, oldlogformat); |
| 1978 | } |
| 1979 | /* generate a detailed TCP log */ |
| 1980 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 1981 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 1982 | curproxy->conf.logformat_string != clf_http_log_format) |
| 1983 | free(curproxy->conf.logformat_string); |
| 1984 | curproxy->conf.logformat_string = default_tcp_log_format; |
| 1985 | |
| 1986 | free(curproxy->conf.lfs_file); |
| 1987 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 1988 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
| 1989 | |
| 1990 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 1991 | goto out; |
| 1992 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1993 | if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1994 | ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n", |
| 1995 | file, linenum, curproxy->id); |
| 1996 | err_code |= ERR_WARN; |
| 1997 | } |
| 1998 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1999 | else if (strcmp(args[1], "tcpka") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2000 | /* enable TCP keep-alives on client and server streams */ |
| 2001 | if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL)) |
| 2002 | err_code |= ERR_WARN; |
| 2003 | |
| 2004 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2005 | goto out; |
| 2006 | |
| 2007 | if (curproxy->cap & PR_CAP_FE) |
| 2008 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 2009 | if (curproxy->cap & PR_CAP_BE) |
| 2010 | curproxy->options |= PR_O_TCP_SRV_KA; |
| 2011 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2012 | else if (strcmp(args[1], "httpchk") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame^] | 2013 | err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum); |
Christopher Faulet | 6c2a743 | 2020-04-09 14:48:48 +0200 | [diff] [blame] | 2014 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2015 | goto out; |
| 2016 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2017 | else if (strcmp(args[1], "ssl-hello-chk") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame^] | 2018 | err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, curr_defproxy, file, linenum); |
Christopher Faulet | 811f78c | 2020-04-01 11:10:27 +0200 | [diff] [blame] | 2019 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2020 | goto out; |
| 2021 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2022 | else if (strcmp(args[1], "smtpchk") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame^] | 2023 | err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum); |
Christopher Faulet | fbcc77c | 2020-04-01 20:54:05 +0200 | [diff] [blame] | 2024 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2025 | goto out; |
| 2026 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2027 | else if (strcmp(args[1], "pgsql-check") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame^] | 2028 | err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum); |
Christopher Faulet | ce35507 | 2020-04-02 11:44:39 +0200 | [diff] [blame] | 2029 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2030 | goto out; |
| 2031 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2032 | else if (strcmp(args[1], "redis-check") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame^] | 2033 | err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, curr_defproxy, file, linenum); |
Christopher Faulet | 33f05df | 2020-04-01 11:08:50 +0200 | [diff] [blame] | 2034 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2035 | goto out; |
| 2036 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2037 | else if (strcmp(args[1], "mysql-check") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame^] | 2038 | err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum); |
Christopher Faulet | f2b3be5 | 2020-04-02 18:07:37 +0200 | [diff] [blame] | 2039 | if (err_code & ERR_FATAL) |
| 2040 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2041 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2042 | else if (strcmp(args[1], "ldap-check") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame^] | 2043 | err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, curr_defproxy, file, linenum); |
Christopher Faulet | 1997eca | 2020-04-03 23:13:50 +0200 | [diff] [blame] | 2044 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2045 | goto out; |
| 2046 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2047 | else if (strcmp(args[1], "spop-check") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame^] | 2048 | err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, curr_defproxy, file, linenum); |
Christopher Faulet | 267b01b | 2020-04-04 10:27:09 +0200 | [diff] [blame] | 2049 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2050 | goto out; |
| 2051 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2052 | else if (strcmp(args[1], "tcp-check") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame^] | 2053 | err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, curr_defproxy, file, linenum); |
Christopher Faulet | 430e480 | 2020-04-09 15:28:16 +0200 | [diff] [blame] | 2054 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2055 | goto out; |
| 2056 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2057 | else if (strcmp(args[1], "external-check") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame^] | 2058 | err_code |= proxy_parse_external_check_opt(args, 0, curproxy, curr_defproxy, file, linenum); |
Christopher Faulet | 6f55791 | 2020-04-09 15:58:50 +0200 | [diff] [blame] | 2059 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2060 | goto out; |
| 2061 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2062 | else if (strcmp(args[1], "forwardfor") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2063 | int cur_arg; |
| 2064 | |
| 2065 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
Christopher Faulet | 3193037 | 2019-07-15 10:16:58 +0200 | [diff] [blame] | 2066 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2067 | */ |
| 2068 | |
| 2069 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
| 2070 | |
| 2071 | free(curproxy->fwdfor_hdr_name); |
| 2072 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 2073 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 2074 | |
| 2075 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 2076 | cur_arg = 2; |
| 2077 | while (*(args[cur_arg])) { |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2078 | if (strcmp(args[cur_arg], "except") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2079 | /* suboption except - needs additional argument for it */ |
| 2080 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_net, &curproxy->except_mask)) { |
| 2081 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 2082 | file, linenum, args[0], args[1], args[cur_arg]); |
| 2083 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2084 | goto out; |
| 2085 | } |
| 2086 | /* flush useless bits */ |
| 2087 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
| 2088 | cur_arg += 2; |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2089 | } else if (strcmp(args[cur_arg], "header") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2090 | /* suboption header - needs additional argument for it */ |
| 2091 | if (*(args[cur_arg+1]) == 0) { |
| 2092 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 2093 | file, linenum, args[0], args[1], args[cur_arg]); |
| 2094 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2095 | goto out; |
| 2096 | } |
| 2097 | free(curproxy->fwdfor_hdr_name); |
| 2098 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 2099 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 2100 | cur_arg += 2; |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2101 | } else if (strcmp(args[cur_arg], "if-none") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2102 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 2103 | cur_arg += 1; |
| 2104 | } else { |
| 2105 | /* unknown suboption - catchall */ |
| 2106 | ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n", |
| 2107 | file, linenum, args[0], args[1]); |
| 2108 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2109 | goto out; |
| 2110 | } |
| 2111 | } /* end while loop */ |
| 2112 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2113 | else if (strcmp(args[1], "originalto") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2114 | int cur_arg; |
| 2115 | |
| 2116 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 2117 | * set default options (ie: bitfield, header name, etc) |
| 2118 | */ |
| 2119 | |
| 2120 | curproxy->options |= PR_O_ORGTO; |
| 2121 | |
| 2122 | free(curproxy->orgto_hdr_name); |
| 2123 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 2124 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 2125 | |
| 2126 | /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */ |
| 2127 | cur_arg = 2; |
| 2128 | while (*(args[cur_arg])) { |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2129 | if (strcmp(args[cur_arg], "except") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2130 | /* suboption except - needs additional argument for it */ |
| 2131 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_to, &curproxy->except_mask_to)) { |
| 2132 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 2133 | file, linenum, args[0], args[1], args[cur_arg]); |
| 2134 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2135 | goto out; |
| 2136 | } |
| 2137 | /* flush useless bits */ |
| 2138 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 2139 | cur_arg += 2; |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2140 | } else if (strcmp(args[cur_arg], "header") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2141 | /* suboption header - needs additional argument for it */ |
| 2142 | if (*(args[cur_arg+1]) == 0) { |
| 2143 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 2144 | file, linenum, args[0], args[1], args[cur_arg]); |
| 2145 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2146 | goto out; |
| 2147 | } |
| 2148 | free(curproxy->orgto_hdr_name); |
| 2149 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 2150 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 2151 | cur_arg += 2; |
| 2152 | } else { |
| 2153 | /* unknown suboption - catchall */ |
| 2154 | ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 2155 | file, linenum, args[0], args[1]); |
| 2156 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2157 | goto out; |
| 2158 | } |
| 2159 | } /* end while loop */ |
| 2160 | } |
| 2161 | else { |
| 2162 | ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
| 2163 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2164 | goto out; |
| 2165 | } |
| 2166 | goto out; |
| 2167 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2168 | else if (strcmp(args[0], "default_backend") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2169 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
| 2170 | err_code |= ERR_WARN; |
| 2171 | |
| 2172 | if (*(args[1]) == 0) { |
| 2173 | ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]); |
| 2174 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2175 | goto out; |
| 2176 | } |
| 2177 | free(curproxy->defbe.name); |
| 2178 | curproxy->defbe.name = strdup(args[1]); |
| 2179 | |
| 2180 | if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code)) |
| 2181 | goto out; |
| 2182 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2183 | else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) { |
Tim Duesterhus | dac168b | 2019-05-14 20:57:58 +0200 | [diff] [blame] | 2184 | ha_alert("parsing [%s:%d] : keyword '%s' directive is not supported anymore since HAProxy 2.1. Use 'option redispatch'.\n", file, linenum, args[0]); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2185 | |
Tim Duesterhus | dac168b | 2019-05-14 20:57:58 +0200 | [diff] [blame] | 2186 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2187 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2188 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2189 | else if (strcmp(args[0], "http-reuse") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2190 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2191 | err_code |= ERR_WARN; |
| 2192 | |
| 2193 | if (strcmp(args[1], "never") == 0) { |
| 2194 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 2195 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 2196 | curproxy->options |= PR_O_REUSE_NEVR; |
| 2197 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2198 | goto out; |
| 2199 | } |
| 2200 | else if (strcmp(args[1], "safe") == 0) { |
| 2201 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 2202 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 2203 | curproxy->options |= PR_O_REUSE_SAFE; |
| 2204 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2205 | goto out; |
| 2206 | } |
| 2207 | else if (strcmp(args[1], "aggressive") == 0) { |
| 2208 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 2209 | curproxy->options |= PR_O_REUSE_AGGR; |
| 2210 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2211 | goto out; |
| 2212 | } |
| 2213 | else if (strcmp(args[1], "always") == 0) { |
| 2214 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 2215 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 2216 | curproxy->options |= PR_O_REUSE_ALWS; |
| 2217 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2218 | goto out; |
| 2219 | } |
| 2220 | else { |
| 2221 | ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]); |
| 2222 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2223 | goto out; |
| 2224 | } |
| 2225 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2226 | else if (strcmp(args[0], "monitor") == 0) { |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 2227 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2228 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2229 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2230 | goto out; |
| 2231 | } |
| 2232 | |
| 2233 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
| 2234 | err_code |= ERR_WARN; |
| 2235 | |
| 2236 | if (strcmp(args[1], "fail") == 0) { |
| 2237 | /* add a condition to fail monitor requests */ |
| 2238 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 2239 | ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2240 | file, linenum, args[0], args[1]); |
| 2241 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2242 | goto out; |
| 2243 | } |
| 2244 | |
| 2245 | err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail"); |
| 2246 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 2247 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 2248 | file, linenum, args[0], args[1], errmsg); |
| 2249 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2250 | goto out; |
| 2251 | } |
| 2252 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 2253 | } |
| 2254 | else { |
| 2255 | ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]); |
| 2256 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2257 | goto out; |
| 2258 | } |
| 2259 | } |
Willy Tarreau | e573323 | 2019-05-22 19:24:06 +0200 | [diff] [blame] | 2260 | #ifdef USE_TPROXY |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2261 | else if (strcmp(args[0], "transparent") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2262 | /* enable transparent proxy connections */ |
| 2263 | curproxy->options |= PR_O_TRANSP; |
| 2264 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 2265 | goto out; |
| 2266 | } |
| 2267 | #endif |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2268 | else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2269 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?")) |
| 2270 | err_code |= ERR_WARN; |
| 2271 | |
| 2272 | if (*(args[1]) == 0) { |
| 2273 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 2274 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2275 | goto out; |
| 2276 | } |
| 2277 | curproxy->maxconn = atol(args[1]); |
| 2278 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 2279 | goto out; |
| 2280 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2281 | else if (strcmp(args[0], "backlog") == 0) { /* backlog */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2282 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
| 2283 | err_code |= ERR_WARN; |
| 2284 | |
| 2285 | if (*(args[1]) == 0) { |
| 2286 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 2287 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2288 | goto out; |
| 2289 | } |
| 2290 | curproxy->backlog = atol(args[1]); |
| 2291 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 2292 | goto out; |
| 2293 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2294 | else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2295 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?")) |
| 2296 | err_code |= ERR_WARN; |
| 2297 | |
| 2298 | if (*(args[1]) == 0) { |
| 2299 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 2300 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2301 | goto out; |
| 2302 | } |
| 2303 | curproxy->fullconn = atol(args[1]); |
| 2304 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 2305 | goto out; |
| 2306 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2307 | else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2308 | if (*(args[1]) == 0) { |
| 2309 | ha_alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]); |
| 2310 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2311 | goto out; |
| 2312 | } |
| 2313 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 2314 | if (err == PARSE_TIME_OVER) { |
| 2315 | ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to grace time, maximum value is 2147483647 ms (~24.8 days).\n", |
| 2316 | file, linenum, args[1]); |
| 2317 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2318 | goto out; |
| 2319 | } |
| 2320 | else if (err == PARSE_TIME_UNDER) { |
| 2321 | ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to grace time, minimum non-null value is 1 ms.\n", |
| 2322 | file, linenum, args[1]); |
| 2323 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2324 | goto out; |
| 2325 | } |
| 2326 | else if (err) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2327 | ha_alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 2328 | file, linenum, *err); |
| 2329 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2330 | goto out; |
| 2331 | } |
| 2332 | curproxy->grace = val; |
| 2333 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 2334 | goto out; |
Willy Tarreau | ab0a519 | 2020-10-09 19:07:01 +0200 | [diff] [blame] | 2335 | |
| 2336 | ha_warning("parsing [%s:%d]: the '%s' is deprecated and will be removed in a future version.\n", |
| 2337 | file, linenum, args[0]); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2338 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2339 | else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2340 | struct sockaddr_storage *sk; |
| 2341 | int port1, port2; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2342 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 2343 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2344 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2345 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2346 | goto out; |
| 2347 | } |
| 2348 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2349 | err_code |= ERR_WARN; |
| 2350 | |
Willy Tarreau | 65ec4e3 | 2020-09-16 19:17:08 +0200 | [diff] [blame] | 2351 | sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL, |
| 2352 | &errmsg, NULL, NULL, |
| 2353 | PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_STREAM | PA_O_XPRT | PA_O_CONNECT); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2354 | if (!sk) { |
| 2355 | ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
| 2356 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2357 | goto out; |
| 2358 | } |
| 2359 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2360 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 2361 | goto out; |
| 2362 | |
| 2363 | curproxy->dispatch_addr = *sk; |
| 2364 | curproxy->options |= PR_O_DISPATCH; |
| 2365 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2366 | else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2367 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2368 | err_code |= ERR_WARN; |
| 2369 | |
| 2370 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 2371 | ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
| 2372 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2373 | goto out; |
| 2374 | } |
| 2375 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2376 | else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2377 | /** |
| 2378 | * The syntax for hash-type config element is |
| 2379 | * hash-type {map-based|consistent} [[<algo>] avalanche] |
| 2380 | * |
| 2381 | * The default hash function is sdbm for map-based and sdbm+avalanche for consistent. |
| 2382 | */ |
| 2383 | curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD); |
| 2384 | |
| 2385 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2386 | err_code |= ERR_WARN; |
| 2387 | |
| 2388 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
| 2389 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 2390 | } |
| 2391 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
| 2392 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 2393 | } |
| 2394 | else if (strcmp(args[1], "avalanche") == 0) { |
| 2395 | ha_alert("parsing [%s:%d] : experimental feature '%s %s' is not supported anymore, please use '%s map-based sdbm avalanche' instead.\n", file, linenum, args[0], args[1], args[0]); |
| 2396 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2397 | goto out; |
| 2398 | } |
| 2399 | else { |
| 2400 | ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]); |
| 2401 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2402 | goto out; |
| 2403 | } |
| 2404 | |
| 2405 | /* set the hash function to use */ |
| 2406 | if (!*args[2]) { |
| 2407 | /* the default algo is sdbm */ |
| 2408 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 2409 | |
| 2410 | /* if consistent with no argument, then avalanche modifier is also applied */ |
| 2411 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) |
| 2412 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 2413 | } else { |
| 2414 | /* set the hash function */ |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2415 | if (strcmp(args[2], "sdbm") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2416 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 2417 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2418 | else if (strcmp(args[2], "djb2") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2419 | curproxy->lbprm.algo |= BE_LB_HFCN_DJB2; |
| 2420 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2421 | else if (strcmp(args[2], "wt6") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2422 | curproxy->lbprm.algo |= BE_LB_HFCN_WT6; |
| 2423 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2424 | else if (strcmp(args[2], "crc32") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2425 | curproxy->lbprm.algo |= BE_LB_HFCN_CRC32; |
| 2426 | } |
| 2427 | else { |
| 2428 | ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]); |
| 2429 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2430 | goto out; |
| 2431 | } |
| 2432 | |
| 2433 | /* set the hash modifier */ |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2434 | if (strcmp(args[3], "avalanche") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2435 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 2436 | } |
| 2437 | else if (*args[3]) { |
| 2438 | ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]); |
| 2439 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2440 | goto out; |
| 2441 | } |
| 2442 | } |
| 2443 | } |
| 2444 | else if (strcmp(args[0], "hash-balance-factor") == 0) { |
| 2445 | if (*(args[1]) == 0) { |
| 2446 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 2447 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2448 | goto out; |
| 2449 | } |
Willy Tarreau | 76e84f5 | 2019-01-14 16:50:58 +0100 | [diff] [blame] | 2450 | curproxy->lbprm.hash_balance_factor = atol(args[1]); |
| 2451 | if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2452 | ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]); |
| 2453 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2454 | goto out; |
| 2455 | } |
| 2456 | } |
| 2457 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 2458 | if (!*(args[1])) { |
| 2459 | ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 2460 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2461 | goto out; |
| 2462 | } |
| 2463 | if (*(args[2])) { |
| 2464 | ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 2465 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2466 | goto out; |
| 2467 | } |
| 2468 | free(curproxy->conf.uniqueid_format_string); |
| 2469 | curproxy->conf.uniqueid_format_string = strdup(args[1]); |
| 2470 | |
| 2471 | free(curproxy->conf.uif_file); |
| 2472 | curproxy->conf.uif_file = strdup(curproxy->conf.args.file); |
| 2473 | curproxy->conf.uif_line = curproxy->conf.args.line; |
| 2474 | } |
| 2475 | |
| 2476 | else if (strcmp(args[0], "unique-id-header") == 0) { |
Tim Duesterhus | 0643b0e | 2020-03-05 17:56:35 +0100 | [diff] [blame] | 2477 | char *copy; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2478 | if (!*(args[1])) { |
| 2479 | ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 2480 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2481 | goto out; |
| 2482 | } |
Tim Duesterhus | 0643b0e | 2020-03-05 17:56:35 +0100 | [diff] [blame] | 2483 | copy = strdup(args[1]); |
| 2484 | if (copy == NULL) { |
| 2485 | ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum); |
| 2486 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2487 | goto out; |
| 2488 | } |
| 2489 | |
| 2490 | istfree(&curproxy->header_unique_id); |
| 2491 | curproxy->header_unique_id = ist(copy); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2492 | } |
| 2493 | |
| 2494 | else if (strcmp(args[0], "log-format") == 0) { |
| 2495 | if (!*(args[1])) { |
| 2496 | ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 2497 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2498 | goto out; |
| 2499 | } |
| 2500 | if (*(args[2])) { |
| 2501 | ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 2502 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2503 | goto out; |
| 2504 | } |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 2505 | if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2506 | char *oldlogformat = "log-format"; |
| 2507 | |
| 2508 | if (curproxy->conf.logformat_string == default_http_log_format) |
| 2509 | oldlogformat = "option httplog"; |
| 2510 | else if (curproxy->conf.logformat_string == default_tcp_log_format) |
| 2511 | oldlogformat = "option tcplog"; |
| 2512 | else if (curproxy->conf.logformat_string == clf_http_log_format) |
| 2513 | oldlogformat = "option httplog clf"; |
| 2514 | ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n", |
| 2515 | file, linenum, oldlogformat); |
| 2516 | } |
| 2517 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 2518 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2519 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2520 | free(curproxy->conf.logformat_string); |
| 2521 | curproxy->conf.logformat_string = strdup(args[1]); |
| 2522 | |
| 2523 | free(curproxy->conf.lfs_file); |
| 2524 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 2525 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
| 2526 | |
| 2527 | /* get a chance to improve log-format error reporting by |
| 2528 | * reporting the correct line-number when possible. |
| 2529 | */ |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 2530 | if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2531 | ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n", |
| 2532 | file, linenum, curproxy->id); |
| 2533 | err_code |= ERR_WARN; |
| 2534 | } |
| 2535 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2536 | else if (strcmp(args[0], "log-format-sd") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2537 | if (!*(args[1])) { |
| 2538 | ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 2539 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2540 | goto out; |
| 2541 | } |
| 2542 | if (*(args[2])) { |
| 2543 | ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 2544 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2545 | goto out; |
| 2546 | } |
| 2547 | |
| 2548 | if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 2549 | free(curproxy->conf.logformat_sd_string); |
| 2550 | curproxy->conf.logformat_sd_string = strdup(args[1]); |
| 2551 | |
| 2552 | free(curproxy->conf.lfsd_file); |
| 2553 | curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file); |
| 2554 | curproxy->conf.lfsd_line = curproxy->conf.args.line; |
| 2555 | |
| 2556 | /* get a chance to improve log-format-sd error reporting by |
| 2557 | * reporting the correct line-number when possible. |
| 2558 | */ |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 2559 | if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2560 | ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n", |
| 2561 | file, linenum, curproxy->id); |
| 2562 | err_code |= ERR_WARN; |
| 2563 | } |
| 2564 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2565 | else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2566 | if (*(args[1]) == 0) { |
| 2567 | ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 2568 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2569 | goto out; |
| 2570 | } |
| 2571 | chunk_destroy(&curproxy->log_tag); |
Eric Salama | 7cea606 | 2020-10-02 11:58:19 +0200 | [diff] [blame] | 2572 | chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1])); |
| 2573 | if (b_orig(&curproxy->log_tag) == NULL) { |
| 2574 | chunk_destroy(&curproxy->log_tag); |
| 2575 | ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]); |
| 2576 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2577 | goto out; |
| 2578 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2579 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2580 | else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2581 | if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), &errmsg)) { |
| 2582 | ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg); |
| 2583 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2584 | goto out; |
| 2585 | } |
| 2586 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2587 | else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2588 | int cur_arg; |
| 2589 | int port1, port2; |
| 2590 | struct sockaddr_storage *sk; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2591 | |
| 2592 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2593 | err_code |= ERR_WARN; |
| 2594 | |
| 2595 | if (!*args[1]) { |
| 2596 | ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 2597 | file, linenum, "source", "usesrc", "interface"); |
| 2598 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2599 | goto out; |
| 2600 | } |
| 2601 | |
Christopher Faulet | 3193037 | 2019-07-15 10:16:58 +0200 | [diff] [blame] | 2602 | /* we must first clear any optional default setting */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2603 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 2604 | free(curproxy->conn_src.iface_name); |
| 2605 | curproxy->conn_src.iface_name = NULL; |
| 2606 | curproxy->conn_src.iface_len = 0; |
| 2607 | |
Willy Tarreau | 65ec4e3 | 2020-09-16 19:17:08 +0200 | [diff] [blame] | 2608 | sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL, |
| 2609 | &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2610 | if (!sk) { |
| 2611 | ha_alert("parsing [%s:%d] : '%s %s' : %s\n", |
| 2612 | file, linenum, args[0], args[1], errmsg); |
| 2613 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2614 | goto out; |
| 2615 | } |
| 2616 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2617 | curproxy->conn_src.source_addr = *sk; |
| 2618 | curproxy->conn_src.opts |= CO_SRC_BIND; |
| 2619 | |
| 2620 | cur_arg = 2; |
| 2621 | while (*(args[cur_arg])) { |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2622 | if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2623 | #if defined(CONFIG_HAP_TRANSPARENT) |
| 2624 | if (!*args[cur_arg + 1]) { |
| 2625 | ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 2626 | file, linenum, "usesrc"); |
| 2627 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2628 | goto out; |
| 2629 | } |
| 2630 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2631 | if (strcmp(args[cur_arg + 1], "client") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2632 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 2633 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2634 | } else if (strcmp(args[cur_arg + 1], "clientip") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2635 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 2636 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP; |
| 2637 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 2638 | char *name, *end; |
| 2639 | |
| 2640 | name = args[cur_arg+1] + 7; |
Willy Tarreau | 9080711 | 2020-02-25 08:16:33 +0100 | [diff] [blame] | 2641 | while (isspace((unsigned char)*name)) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2642 | name++; |
| 2643 | |
| 2644 | end = name; |
Willy Tarreau | 9080711 | 2020-02-25 08:16:33 +0100 | [diff] [blame] | 2645 | while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')') |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2646 | end++; |
| 2647 | |
| 2648 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 2649 | curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN; |
Amaury Denoyelle | 69c5c3a | 2021-01-26 14:35:22 +0100 | [diff] [blame] | 2650 | free(curproxy->conn_src.bind_hdr_name); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2651 | curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 2652 | curproxy->conn_src.bind_hdr_len = end - name; |
| 2653 | memcpy(curproxy->conn_src.bind_hdr_name, name, end - name); |
| 2654 | curproxy->conn_src.bind_hdr_name[end-name] = '\0'; |
| 2655 | curproxy->conn_src.bind_hdr_occ = -1; |
| 2656 | |
| 2657 | /* now look for an occurrence number */ |
Willy Tarreau | 9080711 | 2020-02-25 08:16:33 +0100 | [diff] [blame] | 2658 | while (isspace((unsigned char)*end)) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2659 | end++; |
| 2660 | if (*end == ',') { |
| 2661 | end++; |
| 2662 | name = end; |
| 2663 | if (*end == '-') |
| 2664 | end++; |
Willy Tarreau | 9080711 | 2020-02-25 08:16:33 +0100 | [diff] [blame] | 2665 | while (isdigit((unsigned char)*end)) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2666 | end++; |
| 2667 | curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
| 2668 | } |
| 2669 | |
| 2670 | if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
| 2671 | ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 2672 | " occurrences values smaller than %d.\n", |
| 2673 | file, linenum, MAX_HDR_HISTORY); |
| 2674 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2675 | goto out; |
| 2676 | } |
| 2677 | } else { |
| 2678 | struct sockaddr_storage *sk; |
| 2679 | |
Willy Tarreau | 65ec4e3 | 2020-09-16 19:17:08 +0200 | [diff] [blame] | 2680 | sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL, |
| 2681 | &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2682 | if (!sk) { |
| 2683 | ha_alert("parsing [%s:%d] : '%s %s' : %s\n", |
| 2684 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
| 2685 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2686 | goto out; |
| 2687 | } |
| 2688 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2689 | curproxy->conn_src.tproxy_addr = *sk; |
| 2690 | curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
| 2691 | } |
| 2692 | global.last_checks |= LSTCHK_NETADM; |
| 2693 | #else /* no TPROXY support */ |
| 2694 | ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n", |
| 2695 | file, linenum, "usesrc"); |
| 2696 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2697 | goto out; |
| 2698 | #endif |
| 2699 | cur_arg += 2; |
| 2700 | continue; |
| 2701 | } |
| 2702 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2703 | if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2704 | #ifdef SO_BINDTODEVICE |
| 2705 | if (!*args[cur_arg + 1]) { |
| 2706 | ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 2707 | file, linenum, args[0]); |
| 2708 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2709 | goto out; |
| 2710 | } |
| 2711 | free(curproxy->conn_src.iface_name); |
| 2712 | curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 2713 | curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name); |
| 2714 | global.last_checks |= LSTCHK_NETADM; |
| 2715 | #else |
| 2716 | ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 2717 | file, linenum, args[0], args[cur_arg]); |
| 2718 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2719 | goto out; |
| 2720 | #endif |
| 2721 | cur_arg += 2; |
| 2722 | continue; |
| 2723 | } |
| 2724 | ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n", |
| 2725 | file, linenum, args[0], "interface", "usesrc"); |
| 2726 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2727 | goto out; |
| 2728 | } |
| 2729 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2730 | else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2731 | ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 2732 | file, linenum, "usesrc", "source"); |
| 2733 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2734 | goto out; |
| 2735 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2736 | else if (strcmp(args[0], "cliexp") == 0 || strcmp(args[0], "reqrep") == 0) { /* replace request header from a regex */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2737 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
Willy Tarreau | 262c3f1 | 2019-12-17 06:52:51 +0100 | [diff] [blame] | 2738 | "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n", |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2739 | file, linenum, args[0]); |
| 2740 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2741 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2742 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2743 | else if (strcmp(args[0], "reqdel") == 0) { /* delete request header from a regex */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2744 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2745 | "Use 'http-request del-header' instead.\n", file, linenum, args[0]); |
| 2746 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2747 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2748 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2749 | else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2750 | ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. " |
| 2751 | "Use 'http-request deny' instead.\n", file, linenum, args[0]); |
| 2752 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2753 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2754 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2755 | else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2756 | ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]); |
| 2757 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2758 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2759 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2760 | else if (strcmp(args[0], "reqallow") == 0) { /* allow a request if a header matches this regex */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2761 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2762 | "Use 'http-request allow' instead.\n", file, linenum, args[0]); |
| 2763 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2764 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2765 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2766 | else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2767 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2768 | "Use 'http-request tarpit' instead.\n", file, linenum, args[0]); |
| 2769 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2770 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2771 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2772 | else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2773 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2774 | "Use 'http-request replace-header' instead.\n", file, linenum, args[0]); |
| 2775 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2776 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2777 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2778 | else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2779 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2780 | "Use 'http-request del-header' instead.\n", file, linenum, args[0]); |
| 2781 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2782 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2783 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2784 | else if (strcmp(args[0], "reqideny") == 0) { /* deny a request if a header matches this regex ignoring case */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2785 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2786 | "Use 'http-request deny' instead.\n", file, linenum, args[0]); |
| 2787 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2788 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2789 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2790 | else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2791 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]); |
| 2792 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2793 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2794 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2795 | else if (strcmp(args[0], "reqiallow") == 0) { /* allow a request if a header matches this regex ignoring case */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2796 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2797 | "Use 'http-request allow' instead.\n", file, linenum, args[0]); |
| 2798 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2799 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2800 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2801 | else if (strcmp(args[0], "reqitarpit") == 0) { /* tarpit a request if a header matches this regex ignoring case */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2802 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2803 | "Use 'http-request tarpit' instead.\n", file, linenum, args[0]); |
| 2804 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2805 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2806 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2807 | else if (strcmp(args[0], "reqadd") == 0) { /* add request header */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2808 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2809 | "Use 'http-request add-header' instead.\n", file, linenum, args[0]); |
| 2810 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2811 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2812 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2813 | else if (strcmp(args[0], "srvexp") == 0 || strcmp(args[0], "rsprep") == 0) { /* replace response header from a regex */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2814 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2815 | "Use 'http-response replace-header' instead.\n", file, linenum, args[0]); |
| 2816 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2817 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2818 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2819 | else if (strcmp(args[0], "rspdel") == 0) { /* delete response header from a regex */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2820 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2821 | "Use 'http-response del-header' .\n", file, linenum, args[0]); |
| 2822 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2823 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2824 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2825 | else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2826 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2827 | "Use 'http-response deny' instead.\n", file, linenum, args[0]); |
| 2828 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2829 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2830 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2831 | else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */ |
Balvinder Singh Rawat | def595e | 2020-03-14 12:11:50 +0530 | [diff] [blame] | 2832 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2833 | "Use 'http-response replace-header' instead.\n", file, linenum, args[0]); |
| 2834 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2835 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2836 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2837 | else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2838 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2839 | "Use 'http-response del-header' instead.\n", file, linenum, args[0]); |
| 2840 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2841 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2842 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2843 | else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2844 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2845 | "Use 'http-response deny' instead.\n", file, linenum, args[0]); |
| 2846 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2847 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2848 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2849 | else if (strcmp(args[0], "rspadd") == 0) { /* add response header */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2850 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2851 | "Use 'http-response add-header' instead.\n", file, linenum, args[0]); |
| 2852 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2853 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2854 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2855 | else { |
| 2856 | struct cfg_kw_list *kwl; |
| 2857 | int index; |
| 2858 | |
| 2859 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 2860 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 2861 | if (kwl->kw[index].section != CFG_LISTEN) |
| 2862 | continue; |
| 2863 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 2864 | /* prepare error message just in case */ |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame^] | 2865 | rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2866 | if (rc < 0) { |
| 2867 | ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
| 2868 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2869 | goto out; |
| 2870 | } |
| 2871 | else if (rc > 0) { |
| 2872 | ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
| 2873 | err_code |= ERR_WARN; |
| 2874 | goto out; |
| 2875 | } |
| 2876 | goto out; |
| 2877 | } |
| 2878 | } |
| 2879 | } |
| 2880 | |
| 2881 | ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 2882 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2883 | goto out; |
| 2884 | } |
| 2885 | out: |
| 2886 | free(errmsg); |
| 2887 | return err_code; |
| 2888 | } |