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