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