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