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]); |
Tim Duesterhus | f46d9cd | 2021-01-03 22:54:43 +0100 | [diff] [blame] | 1512 | if (!rule->be.name) { |
| 1513 | ha_alert("Out of memory error.\n"); |
| 1514 | goto out; |
| 1515 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1516 | rule->line = linenum; |
| 1517 | rule->file = strdup(file); |
| 1518 | if (!rule->file) { |
| 1519 | ha_alert("Out of memory error.\n"); |
| 1520 | goto out; |
| 1521 | } |
| 1522 | LIST_INIT(&rule->list); |
| 1523 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 1524 | } |
| 1525 | else if (strcmp(args[0], "use-server") == 0) { |
| 1526 | struct server_rule *rule; |
| 1527 | |
| 1528 | if (curproxy == &defproxy) { |
| 1529 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1530 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1531 | goto out; |
| 1532 | } |
| 1533 | |
| 1534 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 1535 | err_code |= ERR_WARN; |
| 1536 | |
| 1537 | if (*(args[1]) == 0) { |
| 1538 | ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 1539 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1540 | goto out; |
| 1541 | } |
| 1542 | |
| 1543 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 1544 | ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 1545 | file, linenum, args[0]); |
| 1546 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1547 | goto out; |
| 1548 | } |
| 1549 | |
| 1550 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 1551 | ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 1552 | file, linenum, errmsg); |
| 1553 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1554 | goto out; |
| 1555 | } |
| 1556 | |
| 1557 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum); |
| 1558 | |
| 1559 | rule = calloc(1, sizeof(*rule)); |
| 1560 | rule->cond = cond; |
| 1561 | rule->srv.name = strdup(args[1]); |
Jerome Magnin | 824186b | 2020-03-29 09:37:12 +0200 | [diff] [blame] | 1562 | rule->line = linenum; |
| 1563 | rule->file = strdup(file); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1564 | LIST_INIT(&rule->list); |
| 1565 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 1566 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 1567 | } |
| 1568 | else if ((!strcmp(args[0], "force-persist")) || |
| 1569 | (!strcmp(args[0], "ignore-persist"))) { |
| 1570 | struct persist_rule *rule; |
| 1571 | |
| 1572 | if (curproxy == &defproxy) { |
| 1573 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1574 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1575 | goto out; |
| 1576 | } |
| 1577 | |
| 1578 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 1579 | err_code |= ERR_WARN; |
| 1580 | |
| 1581 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
| 1582 | ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 1583 | file, linenum, args[0]); |
| 1584 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1585 | goto out; |
| 1586 | } |
| 1587 | |
| 1588 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 1589 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 1590 | file, linenum, args[0], errmsg); |
| 1591 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1592 | goto out; |
| 1593 | } |
| 1594 | |
| 1595 | /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is |
| 1596 | * where force-persist is applied. |
| 1597 | */ |
| 1598 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum); |
| 1599 | |
| 1600 | rule = calloc(1, sizeof(*rule)); |
| 1601 | rule->cond = cond; |
| 1602 | if (!strcmp(args[0], "force-persist")) { |
| 1603 | rule->type = PERSIST_TYPE_FORCE; |
| 1604 | } else { |
| 1605 | rule->type = PERSIST_TYPE_IGNORE; |
| 1606 | } |
| 1607 | LIST_INIT(&rule->list); |
| 1608 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
| 1609 | } |
| 1610 | else if (!strcmp(args[0], "stick-table")) { |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1611 | struct stktable *other; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1612 | |
| 1613 | if (curproxy == &defproxy) { |
| 1614 | ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n", |
| 1615 | file, linenum); |
| 1616 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1617 | goto out; |
| 1618 | } |
| 1619 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1620 | other = stktable_find_by_name(curproxy->id); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1621 | if (other) { |
| 1622 | 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] | 1623 | file, linenum, curproxy->id, |
| 1624 | other->proxy ? proxy_cap_str(other->proxy->cap) : "peers", |
| 1625 | other->proxy ? other->id : other->peers.p->id, |
| 1626 | other->conf.file, other->conf.line); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1627 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1628 | goto out; |
| 1629 | } |
| 1630 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1631 | curproxy->table = calloc(1, sizeof *curproxy->table); |
| 1632 | if (!curproxy->table) { |
| 1633 | ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n", |
| 1634 | file, linenum, args[0], args[1]); |
| 1635 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1636 | goto out; |
| 1637 | } |
| 1638 | |
Frédéric Lécaille | c02766a | 2019-03-20 15:06:55 +0100 | [diff] [blame] | 1639 | err_code |= parse_stick_table(file, linenum, args, curproxy->table, |
| 1640 | curproxy->id, curproxy->id, NULL); |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 1641 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1642 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1643 | |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 1644 | /* Store the proxy in the stick-table. */ |
| 1645 | curproxy->table->proxy = curproxy; |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1646 | |
| 1647 | stktable_store_name(curproxy->table); |
| 1648 | curproxy->table->next = stktables_list; |
| 1649 | stktables_list = curproxy->table; |
Frédéric Lécaille | 015e4d7 | 2019-03-19 14:55:01 +0100 | [diff] [blame] | 1650 | |
| 1651 | /* Add this proxy to the list of proxies which refer to its stick-table. */ |
| 1652 | if (curproxy->table->proxies_list != curproxy) { |
| 1653 | curproxy->next_stkt_ref = curproxy->table->proxies_list; |
| 1654 | curproxy->table->proxies_list = curproxy; |
| 1655 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1656 | } |
| 1657 | else if (!strcmp(args[0], "stick")) { |
| 1658 | struct sticking_rule *rule; |
| 1659 | struct sample_expr *expr; |
| 1660 | int myidx = 0; |
| 1661 | const char *name = NULL; |
| 1662 | int flags; |
| 1663 | |
| 1664 | if (curproxy == &defproxy) { |
| 1665 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1666 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1667 | goto out; |
| 1668 | } |
| 1669 | |
| 1670 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 1671 | err_code |= ERR_WARN; |
| 1672 | goto out; |
| 1673 | } |
| 1674 | |
| 1675 | myidx++; |
| 1676 | if ((strcmp(args[myidx], "store") == 0) || |
| 1677 | (strcmp(args[myidx], "store-request") == 0)) { |
| 1678 | myidx++; |
| 1679 | flags = STK_IS_STORE; |
| 1680 | } |
| 1681 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 1682 | myidx++; |
| 1683 | flags = STK_IS_STORE | STK_ON_RSP; |
| 1684 | } |
| 1685 | else if (strcmp(args[myidx], "match") == 0) { |
| 1686 | myidx++; |
| 1687 | flags = STK_IS_MATCH; |
| 1688 | } |
| 1689 | else if (strcmp(args[myidx], "on") == 0) { |
| 1690 | myidx++; |
| 1691 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 1692 | } |
| 1693 | else { |
| 1694 | ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 1695 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1696 | goto out; |
| 1697 | } |
| 1698 | |
| 1699 | if (*(args[myidx]) == 0) { |
| 1700 | ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 1701 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1702 | goto out; |
| 1703 | } |
| 1704 | |
| 1705 | curproxy->conf.args.ctx = ARGC_STK; |
Willy Tarreau | e3b57bf | 2020-02-14 16:50:14 +0100 | [diff] [blame] | 1706 | 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] | 1707 | if (!expr) { |
| 1708 | ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
| 1709 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1710 | goto out; |
| 1711 | } |
| 1712 | |
| 1713 | if (flags & STK_ON_RSP) { |
| 1714 | if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) { |
| 1715 | ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n", |
| 1716 | file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use)); |
| 1717 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1718 | free(expr); |
| 1719 | goto out; |
| 1720 | } |
| 1721 | } else { |
| 1722 | if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) { |
| 1723 | ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n", |
| 1724 | file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use)); |
| 1725 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1726 | free(expr); |
| 1727 | goto out; |
| 1728 | } |
| 1729 | } |
| 1730 | |
Christopher Faulet | 711ed6a | 2019-07-16 14:16:10 +0200 | [diff] [blame] | 1731 | /* 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] | 1732 | curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
| 1733 | |
| 1734 | if (strcmp(args[myidx], "table") == 0) { |
| 1735 | myidx++; |
| 1736 | name = args[myidx++]; |
| 1737 | } |
| 1738 | |
| 1739 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
| 1740 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 1741 | ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 1742 | file, linenum, args[0], errmsg); |
| 1743 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1744 | free(expr); |
| 1745 | goto out; |
| 1746 | } |
| 1747 | } |
| 1748 | else if (*(args[myidx])) { |
| 1749 | ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 1750 | file, linenum, args[0], args[myidx]); |
| 1751 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1752 | free(expr); |
| 1753 | goto out; |
| 1754 | } |
| 1755 | if (flags & STK_ON_RSP) |
| 1756 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum); |
| 1757 | else |
| 1758 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum); |
| 1759 | |
| 1760 | rule = calloc(1, sizeof(*rule)); |
| 1761 | rule->cond = cond; |
| 1762 | rule->expr = expr; |
| 1763 | rule->flags = flags; |
| 1764 | rule->table.name = name ? strdup(name) : NULL; |
| 1765 | LIST_INIT(&rule->list); |
| 1766 | if (flags & STK_ON_RSP) |
| 1767 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 1768 | else |
| 1769 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 1770 | } |
| 1771 | else if (!strcmp(args[0], "stats")) { |
| 1772 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 1773 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 1774 | |
| 1775 | if (!*args[1]) { |
| 1776 | goto stats_error_parsing; |
| 1777 | } else if (!strcmp(args[1], "admin")) { |
| 1778 | struct stats_admin_rule *rule; |
| 1779 | |
| 1780 | if (curproxy == &defproxy) { |
| 1781 | ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 1782 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1783 | goto out; |
| 1784 | } |
| 1785 | |
| 1786 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 1787 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 1788 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1789 | goto out; |
| 1790 | } |
| 1791 | |
| 1792 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 1793 | ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 1794 | file, linenum, args[0], args[1]); |
| 1795 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1796 | goto out; |
| 1797 | } |
| 1798 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 1799 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 1800 | file, linenum, args[0], args[1], errmsg); |
| 1801 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1802 | goto out; |
| 1803 | } |
| 1804 | |
| 1805 | err_code |= warnif_cond_conflicts(cond, |
| 1806 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 1807 | file, linenum); |
| 1808 | |
| 1809 | rule = calloc(1, sizeof(*rule)); |
| 1810 | rule->cond = cond; |
| 1811 | LIST_INIT(&rule->list); |
| 1812 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
| 1813 | } else if (!strcmp(args[1], "uri")) { |
| 1814 | if (*(args[2]) == 0) { |
| 1815 | ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
| 1816 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1817 | goto out; |
| 1818 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 1819 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1820 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1821 | goto out; |
| 1822 | } |
| 1823 | } else if (!strcmp(args[1], "realm")) { |
| 1824 | if (*(args[2]) == 0) { |
| 1825 | ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
| 1826 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1827 | goto out; |
| 1828 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 1829 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1830 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1831 | goto out; |
| 1832 | } |
| 1833 | } else if (!strcmp(args[1], "refresh")) { |
| 1834 | unsigned interval; |
| 1835 | |
| 1836 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 1837 | if (err == PARSE_TIME_OVER) { |
| 1838 | ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n", |
| 1839 | file, linenum, args[2]); |
| 1840 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1841 | goto out; |
| 1842 | } |
| 1843 | else if (err == PARSE_TIME_UNDER) { |
| 1844 | ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n", |
| 1845 | file, linenum, args[2]); |
| 1846 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1847 | goto out; |
| 1848 | } |
| 1849 | else if (err) { |
| 1850 | 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] | 1851 | file, linenum, *err); |
| 1852 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1853 | goto out; |
| 1854 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 1855 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1856 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1857 | goto out; |
| 1858 | } |
| 1859 | } else if (!strcmp(args[1], "http-request")) { /* request access control: allow/deny/auth */ |
| 1860 | struct act_rule *rule; |
| 1861 | |
| 1862 | if (curproxy == &defproxy) { |
| 1863 | ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1864 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1865 | goto out; |
| 1866 | } |
| 1867 | |
| 1868 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 1869 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 1870 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1871 | goto out; |
| 1872 | } |
| 1873 | |
| 1874 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
| 1875 | !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) { |
| 1876 | ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 1877 | file, linenum, args[0]); |
| 1878 | err_code |= ERR_WARN; |
| 1879 | } |
| 1880 | |
| 1881 | rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy); |
| 1882 | |
| 1883 | if (!rule) { |
| 1884 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1885 | goto out; |
| 1886 | } |
| 1887 | |
| 1888 | err_code |= warnif_cond_conflicts(rule->cond, |
| 1889 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 1890 | file, linenum); |
| 1891 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
| 1892 | |
| 1893 | } else if (!strcmp(args[1], "auth")) { |
| 1894 | if (*(args[2]) == 0) { |
| 1895 | ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum); |
| 1896 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1897 | goto out; |
| 1898 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 1899 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1900 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1901 | goto out; |
| 1902 | } |
| 1903 | } else if (!strcmp(args[1], "scope")) { |
| 1904 | if (*(args[2]) == 0) { |
| 1905 | ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
| 1906 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1907 | goto out; |
| 1908 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 1909 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1910 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1911 | goto out; |
| 1912 | } |
| 1913 | } else if (!strcmp(args[1], "enable")) { |
| 1914 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 1915 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1916 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1917 | goto out; |
| 1918 | } |
| 1919 | } else if (!strcmp(args[1], "hide-version")) { |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1920 | if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER)) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1921 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1922 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1923 | goto out; |
| 1924 | } |
| 1925 | } else if (!strcmp(args[1], "show-legends")) { |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1926 | if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS)) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1927 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 1928 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1929 | goto out; |
| 1930 | } |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1931 | } else if (!strcmp(args[1], "show-modules")) { |
| 1932 | if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES)) { |
| 1933 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 1934 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1935 | goto out; |
| 1936 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1937 | } else if (!strcmp(args[1], "show-node")) { |
| 1938 | |
| 1939 | if (*args[2]) { |
| 1940 | int i; |
| 1941 | char c; |
| 1942 | |
| 1943 | for (i=0; args[2][i]; i++) { |
| 1944 | c = args[2][i]; |
| 1945 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 1946 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
| 1947 | break; |
| 1948 | } |
| 1949 | |
| 1950 | if (!i || args[2][i]) { |
| 1951 | ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 1952 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 1953 | file, linenum, args[0], args[1]); |
| 1954 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1955 | goto out; |
| 1956 | } |
| 1957 | } |
| 1958 | |
| 1959 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 1960 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 1961 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1962 | goto out; |
| 1963 | } |
| 1964 | } else if (!strcmp(args[1], "show-desc")) { |
| 1965 | char *desc = NULL; |
| 1966 | |
| 1967 | if (*args[2]) { |
| 1968 | int i, len=0; |
| 1969 | char *d; |
| 1970 | |
| 1971 | for (i = 2; *args[i]; i++) |
| 1972 | len += strlen(args[i]) + 1; |
| 1973 | |
| 1974 | desc = d = calloc(1, len); |
| 1975 | |
| 1976 | d += snprintf(d, desc + len - d, "%s", args[2]); |
| 1977 | for (i = 3; *args[i]; i++) |
| 1978 | d += snprintf(d, desc + len - d, " %s", args[i]); |
| 1979 | } |
| 1980 | |
| 1981 | if (!*args[2] && !global.desc) |
| 1982 | ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 1983 | file, linenum, args[1]); |
| 1984 | else { |
| 1985 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 1986 | free(desc); |
| 1987 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 1988 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1989 | goto out; |
| 1990 | } |
| 1991 | free(desc); |
| 1992 | } |
| 1993 | } else { |
| 1994 | stats_error_parsing: |
| 1995 | ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n", |
| 1996 | file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]); |
| 1997 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1998 | goto out; |
| 1999 | } |
| 2000 | } |
| 2001 | else if (!strcmp(args[0], "option")) { |
| 2002 | int optnum; |
| 2003 | |
| 2004 | if (*(args[1]) == '\0') { |
| 2005 | ha_alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 2006 | file, linenum, args[0]); |
| 2007 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2008 | goto out; |
| 2009 | } |
| 2010 | |
| 2011 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 2012 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
| 2013 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 2014 | ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 2015 | file, linenum, cfg_opts[optnum].name); |
| 2016 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2017 | goto out; |
| 2018 | } |
| 2019 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2020 | goto out; |
| 2021 | |
| 2022 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 2023 | err_code |= ERR_WARN; |
| 2024 | goto out; |
| 2025 | } |
| 2026 | |
| 2027 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 2028 | curproxy->options &= ~cfg_opts[optnum].val; |
| 2029 | |
| 2030 | switch (kwm) { |
| 2031 | case KWM_STD: |
| 2032 | curproxy->options |= cfg_opts[optnum].val; |
| 2033 | break; |
| 2034 | case KWM_NO: |
| 2035 | curproxy->no_options |= cfg_opts[optnum].val; |
| 2036 | break; |
| 2037 | case KWM_DEF: /* already cleared */ |
| 2038 | break; |
| 2039 | } |
| 2040 | |
| 2041 | goto out; |
| 2042 | } |
| 2043 | } |
| 2044 | |
| 2045 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 2046 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
| 2047 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 2048 | ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 2049 | file, linenum, cfg_opts2[optnum].name); |
| 2050 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2051 | goto out; |
| 2052 | } |
| 2053 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2054 | goto out; |
| 2055 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 2056 | err_code |= ERR_WARN; |
| 2057 | goto out; |
| 2058 | } |
| 2059 | |
Christopher Faulet | 3193037 | 2019-07-15 10:16:58 +0200 | [diff] [blame] | 2060 | /* "[no] option http-use-htx" is deprecated */ |
| 2061 | if (!strcmp(cfg_opts2[optnum].name, "http-use-htx")) { |
Christopher Faulet | f89f099 | 2019-07-19 11:17:38 +0200 | [diff] [blame] | 2062 | if (kwm ==KWM_NO) { |
| 2063 | ha_warning("parsing [%s:%d]: option '%s' is deprecated and ignored." |
| 2064 | " The HTX mode is now the only supported mode.\n", |
| 2065 | file, linenum, cfg_opts2[optnum].name); |
| 2066 | err_code |= ERR_WARN; |
| 2067 | } |
Christopher Faulet | 3193037 | 2019-07-15 10:16:58 +0200 | [diff] [blame] | 2068 | goto out; |
| 2069 | } |
| 2070 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2071 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 2072 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 2073 | |
| 2074 | switch (kwm) { |
| 2075 | case KWM_STD: |
| 2076 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 2077 | break; |
| 2078 | case KWM_NO: |
| 2079 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 2080 | break; |
| 2081 | case KWM_DEF: /* already cleared */ |
| 2082 | break; |
| 2083 | } |
| 2084 | goto out; |
| 2085 | } |
| 2086 | } |
| 2087 | |
| 2088 | /* HTTP options override each other. They can be cancelled using |
| 2089 | * "no option xxx" which only switches to default mode if the mode |
| 2090 | * was this one (useful for cancelling options set in defaults |
| 2091 | * sections). |
| 2092 | */ |
| 2093 | if (strcmp(args[1], "httpclose") == 0 || strcmp(args[1], "forceclose") == 0) { |
Tim Duesterhus | 10c6c16 | 2019-05-14 20:58:00 +0200 | [diff] [blame] | 2094 | if (strcmp(args[1], "forceclose") == 0) { |
| 2095 | if (!already_warned(WARN_FORCECLOSE_DEPRECATED)) |
| 2096 | ha_warning("parsing [%s:%d]: keyword '%s' is deprecated in favor of 'httpclose', and will not be supported by future versions.\n", |
| 2097 | file, linenum, args[1]); |
| 2098 | err_code |= ERR_WARN; |
| 2099 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2100 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2101 | goto out; |
| 2102 | if (kwm == KWM_STD) { |
| 2103 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 2104 | curproxy->options |= PR_O_HTTP_CLO; |
| 2105 | goto out; |
| 2106 | } |
| 2107 | else if (kwm == KWM_NO) { |
| 2108 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO) |
| 2109 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 2110 | goto out; |
| 2111 | } |
| 2112 | } |
| 2113 | else if (strcmp(args[1], "http-server-close") == 0) { |
| 2114 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2115 | goto out; |
| 2116 | if (kwm == KWM_STD) { |
| 2117 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 2118 | curproxy->options |= PR_O_HTTP_SCL; |
| 2119 | goto out; |
| 2120 | } |
| 2121 | else if (kwm == KWM_NO) { |
| 2122 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL) |
| 2123 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 2124 | goto out; |
| 2125 | } |
| 2126 | } |
| 2127 | else if (strcmp(args[1], "http-keep-alive") == 0) { |
| 2128 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2129 | goto out; |
| 2130 | if (kwm == KWM_STD) { |
| 2131 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 2132 | curproxy->options |= PR_O_HTTP_KAL; |
| 2133 | goto out; |
| 2134 | } |
| 2135 | else if (kwm == KWM_NO) { |
| 2136 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL) |
| 2137 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 2138 | goto out; |
| 2139 | } |
| 2140 | } |
| 2141 | else if (strcmp(args[1], "http-tunnel") == 0) { |
Christopher Faulet | 73e8ede | 2019-07-16 15:04:46 +0200 | [diff] [blame] | 2142 | ha_warning("parsing [%s:%d]: the option '%s' is deprecated and will be removed in next version.\n", |
| 2143 | file, linenum, args[1]); |
| 2144 | err_code |= ERR_WARN; |
| 2145 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2146 | } |
| 2147 | |
| 2148 | /* Redispatch can take an integer argument that control when the |
| 2149 | * resispatch occurs. All values are relative to the retries option. |
| 2150 | * This can be cancelled using "no option xxx". |
| 2151 | */ |
| 2152 | if (strcmp(args[1], "redispatch") == 0) { |
| 2153 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) { |
| 2154 | err_code |= ERR_WARN; |
| 2155 | goto out; |
| 2156 | } |
| 2157 | |
| 2158 | curproxy->no_options &= ~PR_O_REDISP; |
| 2159 | curproxy->options &= ~PR_O_REDISP; |
| 2160 | |
| 2161 | switch (kwm) { |
| 2162 | case KWM_STD: |
| 2163 | curproxy->options |= PR_O_REDISP; |
| 2164 | curproxy->redispatch_after = -1; |
| 2165 | if(*args[2]) { |
| 2166 | curproxy->redispatch_after = atol(args[2]); |
| 2167 | } |
| 2168 | break; |
| 2169 | case KWM_NO: |
| 2170 | curproxy->no_options |= PR_O_REDISP; |
| 2171 | curproxy->redispatch_after = 0; |
| 2172 | break; |
| 2173 | case KWM_DEF: /* already cleared */ |
| 2174 | break; |
| 2175 | } |
| 2176 | goto out; |
| 2177 | } |
| 2178 | |
| 2179 | if (kwm != KWM_STD) { |
| 2180 | ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n", |
| 2181 | file, linenum, args[1]); |
| 2182 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2183 | goto out; |
| 2184 | } |
| 2185 | |
| 2186 | if (!strcmp(args[1], "httplog")) { |
| 2187 | char *logformat; |
| 2188 | /* generate a complete HTTP log */ |
| 2189 | logformat = default_http_log_format; |
| 2190 | if (*(args[2]) != '\0') { |
| 2191 | if (!strcmp(args[2], "clf")) { |
| 2192 | curproxy->options2 |= PR_O2_CLFLOG; |
| 2193 | logformat = clf_http_log_format; |
| 2194 | } else { |
| 2195 | ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]); |
| 2196 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2197 | goto out; |
| 2198 | } |
| 2199 | if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code)) |
| 2200 | goto out; |
| 2201 | } |
| 2202 | if (curproxy->conf.logformat_string && curproxy == &defproxy) { |
| 2203 | char *oldlogformat = "log-format"; |
| 2204 | char *clflogformat = ""; |
| 2205 | |
| 2206 | if (curproxy->conf.logformat_string == default_http_log_format) |
| 2207 | oldlogformat = "option httplog"; |
| 2208 | else if (curproxy->conf.logformat_string == default_tcp_log_format) |
| 2209 | oldlogformat = "option tcplog"; |
| 2210 | else if (curproxy->conf.logformat_string == clf_http_log_format) |
| 2211 | oldlogformat = "option httplog clf"; |
| 2212 | if (logformat == clf_http_log_format) |
| 2213 | clflogformat = " clf"; |
| 2214 | ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n", |
| 2215 | file, linenum, clflogformat, oldlogformat); |
| 2216 | } |
| 2217 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 2218 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2219 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2220 | free(curproxy->conf.logformat_string); |
| 2221 | curproxy->conf.logformat_string = logformat; |
| 2222 | |
| 2223 | free(curproxy->conf.lfs_file); |
| 2224 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 2225 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
| 2226 | |
| 2227 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 2228 | ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n", |
| 2229 | file, linenum, curproxy->id); |
| 2230 | err_code |= ERR_WARN; |
| 2231 | } |
| 2232 | } |
| 2233 | else if (!strcmp(args[1], "tcplog")) { |
| 2234 | if (curproxy->conf.logformat_string && curproxy == &defproxy) { |
| 2235 | char *oldlogformat = "log-format"; |
| 2236 | |
| 2237 | if (curproxy->conf.logformat_string == default_http_log_format) |
| 2238 | oldlogformat = "option httplog"; |
| 2239 | else if (curproxy->conf.logformat_string == default_tcp_log_format) |
| 2240 | oldlogformat = "option tcplog"; |
| 2241 | else if (curproxy->conf.logformat_string == clf_http_log_format) |
| 2242 | oldlogformat = "option httplog clf"; |
| 2243 | ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n", |
| 2244 | file, linenum, oldlogformat); |
| 2245 | } |
| 2246 | /* generate a detailed TCP log */ |
| 2247 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 2248 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2249 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2250 | free(curproxy->conf.logformat_string); |
| 2251 | curproxy->conf.logformat_string = default_tcp_log_format; |
| 2252 | |
| 2253 | free(curproxy->conf.lfs_file); |
| 2254 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 2255 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
| 2256 | |
| 2257 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2258 | goto out; |
| 2259 | |
| 2260 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 2261 | ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n", |
| 2262 | file, linenum, curproxy->id); |
| 2263 | err_code |= ERR_WARN; |
| 2264 | } |
| 2265 | } |
| 2266 | else if (!strcmp(args[1], "tcpka")) { |
| 2267 | /* enable TCP keep-alives on client and server streams */ |
| 2268 | if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL)) |
| 2269 | err_code |= ERR_WARN; |
| 2270 | |
| 2271 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2272 | goto out; |
| 2273 | |
| 2274 | if (curproxy->cap & PR_CAP_FE) |
| 2275 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 2276 | if (curproxy->cap & PR_CAP_BE) |
| 2277 | curproxy->options |= PR_O_TCP_SRV_KA; |
| 2278 | } |
| 2279 | else if (!strcmp(args[1], "httpchk")) { |
Christopher Faulet | 6c2a743 | 2020-04-09 14:48:48 +0200 | [diff] [blame] | 2280 | err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, &defproxy, file, linenum); |
| 2281 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2282 | goto out; |
| 2283 | } |
| 2284 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
Christopher Faulet | 811f78c | 2020-04-01 11:10:27 +0200 | [diff] [blame] | 2285 | err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, &defproxy, file, linenum); |
| 2286 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2287 | goto out; |
| 2288 | } |
| 2289 | else if (!strcmp(args[1], "smtpchk")) { |
Christopher Faulet | fbcc77c | 2020-04-01 20:54:05 +0200 | [diff] [blame] | 2290 | err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, &defproxy, file, linenum); |
| 2291 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2292 | goto out; |
| 2293 | } |
| 2294 | else if (!strcmp(args[1], "pgsql-check")) { |
Christopher Faulet | ce35507 | 2020-04-02 11:44:39 +0200 | [diff] [blame] | 2295 | err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, &defproxy, file, linenum); |
| 2296 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2297 | goto out; |
| 2298 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2299 | else if (!strcmp(args[1], "redis-check")) { |
Christopher Faulet | 33f05df | 2020-04-01 11:08:50 +0200 | [diff] [blame] | 2300 | err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, &defproxy, file, linenum); |
| 2301 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2302 | goto out; |
| 2303 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2304 | else if (!strcmp(args[1], "mysql-check")) { |
Christopher Faulet | f2b3be5 | 2020-04-02 18:07:37 +0200 | [diff] [blame] | 2305 | err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, &defproxy, file, linenum); |
| 2306 | if (err_code & ERR_FATAL) |
| 2307 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2308 | } |
| 2309 | else if (!strcmp(args[1], "ldap-check")) { |
Christopher Faulet | 1997eca | 2020-04-03 23:13:50 +0200 | [diff] [blame] | 2310 | err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, &defproxy, file, linenum); |
| 2311 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2312 | goto out; |
| 2313 | } |
| 2314 | else if (!strcmp(args[1], "spop-check")) { |
Christopher Faulet | 267b01b | 2020-04-04 10:27:09 +0200 | [diff] [blame] | 2315 | err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, &defproxy, file, linenum); |
| 2316 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2317 | goto out; |
| 2318 | } |
| 2319 | else if (!strcmp(args[1], "tcp-check")) { |
Christopher Faulet | 430e480 | 2020-04-09 15:28:16 +0200 | [diff] [blame] | 2320 | err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, &defproxy, file, linenum); |
| 2321 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2322 | goto out; |
| 2323 | } |
| 2324 | else if (!strcmp(args[1], "external-check")) { |
Christopher Faulet | 6f55791 | 2020-04-09 15:58:50 +0200 | [diff] [blame] | 2325 | err_code |= proxy_parse_external_check_opt(args, 0, curproxy, &defproxy, file, linenum); |
| 2326 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2327 | goto out; |
| 2328 | } |
| 2329 | else if (!strcmp(args[1], "forwardfor")) { |
| 2330 | int cur_arg; |
| 2331 | |
| 2332 | /* 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] | 2333 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2334 | */ |
| 2335 | |
| 2336 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
| 2337 | |
| 2338 | free(curproxy->fwdfor_hdr_name); |
| 2339 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 2340 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 2341 | |
| 2342 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 2343 | cur_arg = 2; |
| 2344 | while (*(args[cur_arg])) { |
| 2345 | if (!strcmp(args[cur_arg], "except")) { |
| 2346 | /* suboption except - needs additional argument for it */ |
| 2347 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_net, &curproxy->except_mask)) { |
| 2348 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 2349 | file, linenum, args[0], args[1], args[cur_arg]); |
| 2350 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2351 | goto out; |
| 2352 | } |
| 2353 | /* flush useless bits */ |
| 2354 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
| 2355 | cur_arg += 2; |
| 2356 | } else if (!strcmp(args[cur_arg], "header")) { |
| 2357 | /* suboption header - needs additional argument for it */ |
| 2358 | if (*(args[cur_arg+1]) == 0) { |
| 2359 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 2360 | file, linenum, args[0], args[1], args[cur_arg]); |
| 2361 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2362 | goto out; |
| 2363 | } |
| 2364 | free(curproxy->fwdfor_hdr_name); |
| 2365 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 2366 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 2367 | cur_arg += 2; |
| 2368 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 2369 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 2370 | cur_arg += 1; |
| 2371 | } else { |
| 2372 | /* unknown suboption - catchall */ |
| 2373 | ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n", |
| 2374 | file, linenum, args[0], args[1]); |
| 2375 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2376 | goto out; |
| 2377 | } |
| 2378 | } /* end while loop */ |
| 2379 | } |
| 2380 | else if (!strcmp(args[1], "originalto")) { |
| 2381 | int cur_arg; |
| 2382 | |
| 2383 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 2384 | * set default options (ie: bitfield, header name, etc) |
| 2385 | */ |
| 2386 | |
| 2387 | curproxy->options |= PR_O_ORGTO; |
| 2388 | |
| 2389 | free(curproxy->orgto_hdr_name); |
| 2390 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 2391 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 2392 | |
| 2393 | /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */ |
| 2394 | cur_arg = 2; |
| 2395 | while (*(args[cur_arg])) { |
| 2396 | if (!strcmp(args[cur_arg], "except")) { |
| 2397 | /* suboption except - needs additional argument for it */ |
| 2398 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_to, &curproxy->except_mask_to)) { |
| 2399 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 2400 | file, linenum, args[0], args[1], args[cur_arg]); |
| 2401 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2402 | goto out; |
| 2403 | } |
| 2404 | /* flush useless bits */ |
| 2405 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 2406 | cur_arg += 2; |
| 2407 | } else if (!strcmp(args[cur_arg], "header")) { |
| 2408 | /* suboption header - needs additional argument for it */ |
| 2409 | if (*(args[cur_arg+1]) == 0) { |
| 2410 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 2411 | file, linenum, args[0], args[1], args[cur_arg]); |
| 2412 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2413 | goto out; |
| 2414 | } |
| 2415 | free(curproxy->orgto_hdr_name); |
| 2416 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 2417 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 2418 | cur_arg += 2; |
| 2419 | } else { |
| 2420 | /* unknown suboption - catchall */ |
| 2421 | ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 2422 | file, linenum, args[0], args[1]); |
| 2423 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2424 | goto out; |
| 2425 | } |
| 2426 | } /* end while loop */ |
| 2427 | } |
| 2428 | else { |
| 2429 | ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
| 2430 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2431 | goto out; |
| 2432 | } |
| 2433 | goto out; |
| 2434 | } |
| 2435 | else if (!strcmp(args[0], "default_backend")) { |
| 2436 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
| 2437 | err_code |= ERR_WARN; |
| 2438 | |
| 2439 | if (*(args[1]) == 0) { |
| 2440 | ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]); |
| 2441 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2442 | goto out; |
| 2443 | } |
| 2444 | free(curproxy->defbe.name); |
| 2445 | curproxy->defbe.name = strdup(args[1]); |
| 2446 | |
| 2447 | if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code)) |
| 2448 | goto out; |
| 2449 | } |
| 2450 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Tim Duesterhus | dac168b | 2019-05-14 20:57:58 +0200 | [diff] [blame] | 2451 | 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] | 2452 | |
Tim Duesterhus | dac168b | 2019-05-14 20:57:58 +0200 | [diff] [blame] | 2453 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2454 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2455 | } |
| 2456 | else if (!strcmp(args[0], "http-reuse")) { |
| 2457 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2458 | err_code |= ERR_WARN; |
| 2459 | |
| 2460 | if (strcmp(args[1], "never") == 0) { |
| 2461 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 2462 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 2463 | curproxy->options |= PR_O_REUSE_NEVR; |
| 2464 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2465 | goto out; |
| 2466 | } |
| 2467 | else if (strcmp(args[1], "safe") == 0) { |
| 2468 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 2469 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 2470 | curproxy->options |= PR_O_REUSE_SAFE; |
| 2471 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2472 | goto out; |
| 2473 | } |
| 2474 | else if (strcmp(args[1], "aggressive") == 0) { |
| 2475 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 2476 | curproxy->options |= PR_O_REUSE_AGGR; |
| 2477 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2478 | goto out; |
| 2479 | } |
| 2480 | else if (strcmp(args[1], "always") == 0) { |
| 2481 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 2482 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 2483 | curproxy->options |= PR_O_REUSE_ALWS; |
| 2484 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2485 | goto out; |
| 2486 | } |
| 2487 | else { |
| 2488 | ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]); |
| 2489 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2490 | goto out; |
| 2491 | } |
| 2492 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2493 | else if (!strcmp(args[0], "monitor")) { |
| 2494 | if (curproxy == &defproxy) { |
| 2495 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2496 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2497 | goto out; |
| 2498 | } |
| 2499 | |
| 2500 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
| 2501 | err_code |= ERR_WARN; |
| 2502 | |
| 2503 | if (strcmp(args[1], "fail") == 0) { |
| 2504 | /* add a condition to fail monitor requests */ |
| 2505 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 2506 | ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2507 | file, linenum, args[0], args[1]); |
| 2508 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2509 | goto out; |
| 2510 | } |
| 2511 | |
| 2512 | err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail"); |
| 2513 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 2514 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 2515 | file, linenum, args[0], args[1], errmsg); |
| 2516 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2517 | goto out; |
| 2518 | } |
| 2519 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 2520 | } |
| 2521 | else { |
| 2522 | ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]); |
| 2523 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2524 | goto out; |
| 2525 | } |
| 2526 | } |
Willy Tarreau | e573323 | 2019-05-22 19:24:06 +0200 | [diff] [blame] | 2527 | #ifdef USE_TPROXY |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2528 | else if (!strcmp(args[0], "transparent")) { |
| 2529 | /* enable transparent proxy connections */ |
| 2530 | curproxy->options |= PR_O_TRANSP; |
| 2531 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 2532 | goto out; |
| 2533 | } |
| 2534 | #endif |
| 2535 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
| 2536 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?")) |
| 2537 | err_code |= ERR_WARN; |
| 2538 | |
| 2539 | if (*(args[1]) == 0) { |
| 2540 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 2541 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2542 | goto out; |
| 2543 | } |
| 2544 | curproxy->maxconn = atol(args[1]); |
| 2545 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 2546 | goto out; |
| 2547 | } |
| 2548 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 2549 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
| 2550 | err_code |= ERR_WARN; |
| 2551 | |
| 2552 | if (*(args[1]) == 0) { |
| 2553 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 2554 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2555 | goto out; |
| 2556 | } |
| 2557 | curproxy->backlog = atol(args[1]); |
| 2558 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 2559 | goto out; |
| 2560 | } |
| 2561 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
| 2562 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?")) |
| 2563 | err_code |= ERR_WARN; |
| 2564 | |
| 2565 | if (*(args[1]) == 0) { |
| 2566 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 2567 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2568 | goto out; |
| 2569 | } |
| 2570 | curproxy->fullconn = atol(args[1]); |
| 2571 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 2572 | goto out; |
| 2573 | } |
| 2574 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 2575 | if (*(args[1]) == 0) { |
| 2576 | ha_alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]); |
| 2577 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2578 | goto out; |
| 2579 | } |
| 2580 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 2581 | if (err == PARSE_TIME_OVER) { |
| 2582 | ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to grace time, maximum value is 2147483647 ms (~24.8 days).\n", |
| 2583 | file, linenum, args[1]); |
| 2584 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2585 | goto out; |
| 2586 | } |
| 2587 | else if (err == PARSE_TIME_UNDER) { |
| 2588 | ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to grace time, minimum non-null value is 1 ms.\n", |
| 2589 | file, linenum, args[1]); |
| 2590 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2591 | goto out; |
| 2592 | } |
| 2593 | else if (err) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2594 | ha_alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 2595 | file, linenum, *err); |
| 2596 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2597 | goto out; |
| 2598 | } |
| 2599 | curproxy->grace = val; |
| 2600 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 2601 | goto out; |
Willy Tarreau | ab0a519 | 2020-10-09 19:07:01 +0200 | [diff] [blame] | 2602 | |
| 2603 | ha_warning("parsing [%s:%d]: the '%s' is deprecated and will be removed in a future version.\n", |
| 2604 | file, linenum, args[0]); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2605 | } |
| 2606 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
| 2607 | struct sockaddr_storage *sk; |
| 2608 | int port1, port2; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2609 | |
| 2610 | if (curproxy == &defproxy) { |
| 2611 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2612 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2613 | goto out; |
| 2614 | } |
| 2615 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2616 | err_code |= ERR_WARN; |
| 2617 | |
Willy Tarreau | 65ec4e3 | 2020-09-16 19:17:08 +0200 | [diff] [blame] | 2618 | sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL, |
| 2619 | &errmsg, NULL, NULL, |
| 2620 | 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] | 2621 | if (!sk) { |
| 2622 | ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
| 2623 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2624 | goto out; |
| 2625 | } |
| 2626 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2627 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 2628 | goto out; |
| 2629 | |
| 2630 | curproxy->dispatch_addr = *sk; |
| 2631 | curproxy->options |= PR_O_DISPATCH; |
| 2632 | } |
| 2633 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
| 2634 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2635 | err_code |= ERR_WARN; |
| 2636 | |
| 2637 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 2638 | ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
| 2639 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2640 | goto out; |
| 2641 | } |
| 2642 | } |
| 2643 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
| 2644 | /** |
| 2645 | * The syntax for hash-type config element is |
| 2646 | * hash-type {map-based|consistent} [[<algo>] avalanche] |
| 2647 | * |
| 2648 | * The default hash function is sdbm for map-based and sdbm+avalanche for consistent. |
| 2649 | */ |
| 2650 | curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD); |
| 2651 | |
| 2652 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2653 | err_code |= ERR_WARN; |
| 2654 | |
| 2655 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
| 2656 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 2657 | } |
| 2658 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
| 2659 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 2660 | } |
| 2661 | else if (strcmp(args[1], "avalanche") == 0) { |
| 2662 | 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]); |
| 2663 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2664 | goto out; |
| 2665 | } |
| 2666 | else { |
| 2667 | ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]); |
| 2668 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2669 | goto out; |
| 2670 | } |
| 2671 | |
| 2672 | /* set the hash function to use */ |
| 2673 | if (!*args[2]) { |
| 2674 | /* the default algo is sdbm */ |
| 2675 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 2676 | |
| 2677 | /* if consistent with no argument, then avalanche modifier is also applied */ |
| 2678 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) |
| 2679 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 2680 | } else { |
| 2681 | /* set the hash function */ |
| 2682 | if (!strcmp(args[2], "sdbm")) { |
| 2683 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 2684 | } |
| 2685 | else if (!strcmp(args[2], "djb2")) { |
| 2686 | curproxy->lbprm.algo |= BE_LB_HFCN_DJB2; |
| 2687 | } |
| 2688 | else if (!strcmp(args[2], "wt6")) { |
| 2689 | curproxy->lbprm.algo |= BE_LB_HFCN_WT6; |
| 2690 | } |
| 2691 | else if (!strcmp(args[2], "crc32")) { |
| 2692 | curproxy->lbprm.algo |= BE_LB_HFCN_CRC32; |
| 2693 | } |
| 2694 | else { |
| 2695 | ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]); |
| 2696 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2697 | goto out; |
| 2698 | } |
| 2699 | |
| 2700 | /* set the hash modifier */ |
| 2701 | if (!strcmp(args[3], "avalanche")) { |
| 2702 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 2703 | } |
| 2704 | else if (*args[3]) { |
| 2705 | ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]); |
| 2706 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2707 | goto out; |
| 2708 | } |
| 2709 | } |
| 2710 | } |
| 2711 | else if (strcmp(args[0], "hash-balance-factor") == 0) { |
| 2712 | if (*(args[1]) == 0) { |
| 2713 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 2714 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2715 | goto out; |
| 2716 | } |
Willy Tarreau | 76e84f5 | 2019-01-14 16:50:58 +0100 | [diff] [blame] | 2717 | curproxy->lbprm.hash_balance_factor = atol(args[1]); |
| 2718 | 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] | 2719 | ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]); |
| 2720 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2721 | goto out; |
| 2722 | } |
| 2723 | } |
| 2724 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 2725 | if (!*(args[1])) { |
| 2726 | ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 2727 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2728 | goto out; |
| 2729 | } |
| 2730 | if (*(args[2])) { |
| 2731 | ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 2732 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2733 | goto out; |
| 2734 | } |
| 2735 | free(curproxy->conf.uniqueid_format_string); |
| 2736 | curproxy->conf.uniqueid_format_string = strdup(args[1]); |
| 2737 | |
| 2738 | free(curproxy->conf.uif_file); |
| 2739 | curproxy->conf.uif_file = strdup(curproxy->conf.args.file); |
| 2740 | curproxy->conf.uif_line = curproxy->conf.args.line; |
| 2741 | } |
| 2742 | |
| 2743 | else if (strcmp(args[0], "unique-id-header") == 0) { |
Tim Duesterhus | 0643b0e | 2020-03-05 17:56:35 +0100 | [diff] [blame] | 2744 | char *copy; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2745 | if (!*(args[1])) { |
| 2746 | ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 2747 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2748 | goto out; |
| 2749 | } |
Tim Duesterhus | 0643b0e | 2020-03-05 17:56:35 +0100 | [diff] [blame] | 2750 | copy = strdup(args[1]); |
| 2751 | if (copy == NULL) { |
| 2752 | ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum); |
| 2753 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2754 | goto out; |
| 2755 | } |
| 2756 | |
| 2757 | istfree(&curproxy->header_unique_id); |
| 2758 | curproxy->header_unique_id = ist(copy); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2759 | } |
| 2760 | |
| 2761 | else if (strcmp(args[0], "log-format") == 0) { |
| 2762 | if (!*(args[1])) { |
| 2763 | ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 2764 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2765 | goto out; |
| 2766 | } |
| 2767 | if (*(args[2])) { |
| 2768 | ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 2769 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2770 | goto out; |
| 2771 | } |
| 2772 | if (curproxy->conf.logformat_string && curproxy == &defproxy) { |
| 2773 | char *oldlogformat = "log-format"; |
| 2774 | |
| 2775 | if (curproxy->conf.logformat_string == default_http_log_format) |
| 2776 | oldlogformat = "option httplog"; |
| 2777 | else if (curproxy->conf.logformat_string == default_tcp_log_format) |
| 2778 | oldlogformat = "option tcplog"; |
| 2779 | else if (curproxy->conf.logformat_string == clf_http_log_format) |
| 2780 | oldlogformat = "option httplog clf"; |
| 2781 | ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n", |
| 2782 | file, linenum, oldlogformat); |
| 2783 | } |
| 2784 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 2785 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2786 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2787 | free(curproxy->conf.logformat_string); |
| 2788 | curproxy->conf.logformat_string = strdup(args[1]); |
| 2789 | |
| 2790 | free(curproxy->conf.lfs_file); |
| 2791 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 2792 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
| 2793 | |
| 2794 | /* get a chance to improve log-format error reporting by |
| 2795 | * reporting the correct line-number when possible. |
| 2796 | */ |
| 2797 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 2798 | ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n", |
| 2799 | file, linenum, curproxy->id); |
| 2800 | err_code |= ERR_WARN; |
| 2801 | } |
| 2802 | } |
| 2803 | else if (!strcmp(args[0], "log-format-sd")) { |
| 2804 | if (!*(args[1])) { |
| 2805 | ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 2806 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2807 | goto out; |
| 2808 | } |
| 2809 | if (*(args[2])) { |
| 2810 | ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 2811 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2812 | goto out; |
| 2813 | } |
| 2814 | |
| 2815 | if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 2816 | free(curproxy->conf.logformat_sd_string); |
| 2817 | curproxy->conf.logformat_sd_string = strdup(args[1]); |
| 2818 | |
| 2819 | free(curproxy->conf.lfsd_file); |
| 2820 | curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file); |
| 2821 | curproxy->conf.lfsd_line = curproxy->conf.args.line; |
| 2822 | |
| 2823 | /* get a chance to improve log-format-sd error reporting by |
| 2824 | * reporting the correct line-number when possible. |
| 2825 | */ |
| 2826 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 2827 | ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n", |
| 2828 | file, linenum, curproxy->id); |
| 2829 | err_code |= ERR_WARN; |
| 2830 | } |
| 2831 | } |
| 2832 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 2833 | if (*(args[1]) == 0) { |
| 2834 | ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 2835 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2836 | goto out; |
| 2837 | } |
| 2838 | chunk_destroy(&curproxy->log_tag); |
Eric Salama | 7cea606 | 2020-10-02 11:58:19 +0200 | [diff] [blame] | 2839 | chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1])); |
| 2840 | if (b_orig(&curproxy->log_tag) == NULL) { |
| 2841 | chunk_destroy(&curproxy->log_tag); |
| 2842 | ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]); |
| 2843 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2844 | goto out; |
| 2845 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2846 | } |
| 2847 | else if (!strcmp(args[0], "log")) { /* "no log" or "log ..." */ |
| 2848 | if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), &errmsg)) { |
| 2849 | ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg); |
| 2850 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2851 | goto out; |
| 2852 | } |
| 2853 | } |
| 2854 | else if (!strcmp(args[0], "source")) { /* address to which we bind when connecting */ |
| 2855 | int cur_arg; |
| 2856 | int port1, port2; |
| 2857 | struct sockaddr_storage *sk; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2858 | |
| 2859 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2860 | err_code |= ERR_WARN; |
| 2861 | |
| 2862 | if (!*args[1]) { |
| 2863 | ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 2864 | file, linenum, "source", "usesrc", "interface"); |
| 2865 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2866 | goto out; |
| 2867 | } |
| 2868 | |
Christopher Faulet | 3193037 | 2019-07-15 10:16:58 +0200 | [diff] [blame] | 2869 | /* we must first clear any optional default setting */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2870 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 2871 | free(curproxy->conn_src.iface_name); |
| 2872 | curproxy->conn_src.iface_name = NULL; |
| 2873 | curproxy->conn_src.iface_len = 0; |
| 2874 | |
Willy Tarreau | 65ec4e3 | 2020-09-16 19:17:08 +0200 | [diff] [blame] | 2875 | sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL, |
| 2876 | &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] | 2877 | if (!sk) { |
| 2878 | ha_alert("parsing [%s:%d] : '%s %s' : %s\n", |
| 2879 | file, linenum, args[0], args[1], errmsg); |
| 2880 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2881 | goto out; |
| 2882 | } |
| 2883 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2884 | curproxy->conn_src.source_addr = *sk; |
| 2885 | curproxy->conn_src.opts |= CO_SRC_BIND; |
| 2886 | |
| 2887 | cur_arg = 2; |
| 2888 | while (*(args[cur_arg])) { |
| 2889 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
| 2890 | #if defined(CONFIG_HAP_TRANSPARENT) |
| 2891 | if (!*args[cur_arg + 1]) { |
| 2892 | ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 2893 | file, linenum, "usesrc"); |
| 2894 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2895 | goto out; |
| 2896 | } |
| 2897 | |
| 2898 | if (!strcmp(args[cur_arg + 1], "client")) { |
| 2899 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 2900 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI; |
| 2901 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
| 2902 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 2903 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP; |
| 2904 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 2905 | char *name, *end; |
| 2906 | |
| 2907 | name = args[cur_arg+1] + 7; |
Willy Tarreau | 9080711 | 2020-02-25 08:16:33 +0100 | [diff] [blame] | 2908 | while (isspace((unsigned char)*name)) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2909 | name++; |
| 2910 | |
| 2911 | end = name; |
Willy Tarreau | 9080711 | 2020-02-25 08:16:33 +0100 | [diff] [blame] | 2912 | while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')') |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2913 | end++; |
| 2914 | |
| 2915 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 2916 | curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 2917 | curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 2918 | curproxy->conn_src.bind_hdr_len = end - name; |
| 2919 | memcpy(curproxy->conn_src.bind_hdr_name, name, end - name); |
| 2920 | curproxy->conn_src.bind_hdr_name[end-name] = '\0'; |
| 2921 | curproxy->conn_src.bind_hdr_occ = -1; |
| 2922 | |
| 2923 | /* now look for an occurrence number */ |
Willy Tarreau | 9080711 | 2020-02-25 08:16:33 +0100 | [diff] [blame] | 2924 | while (isspace((unsigned char)*end)) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2925 | end++; |
| 2926 | if (*end == ',') { |
| 2927 | end++; |
| 2928 | name = end; |
| 2929 | if (*end == '-') |
| 2930 | end++; |
Willy Tarreau | 9080711 | 2020-02-25 08:16:33 +0100 | [diff] [blame] | 2931 | while (isdigit((unsigned char)*end)) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2932 | end++; |
| 2933 | curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
| 2934 | } |
| 2935 | |
| 2936 | if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
| 2937 | ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 2938 | " occurrences values smaller than %d.\n", |
| 2939 | file, linenum, MAX_HDR_HISTORY); |
| 2940 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2941 | goto out; |
| 2942 | } |
| 2943 | } else { |
| 2944 | struct sockaddr_storage *sk; |
| 2945 | |
Willy Tarreau | 65ec4e3 | 2020-09-16 19:17:08 +0200 | [diff] [blame] | 2946 | sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL, |
| 2947 | &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] | 2948 | if (!sk) { |
| 2949 | ha_alert("parsing [%s:%d] : '%s %s' : %s\n", |
| 2950 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
| 2951 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2952 | goto out; |
| 2953 | } |
| 2954 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2955 | curproxy->conn_src.tproxy_addr = *sk; |
| 2956 | curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
| 2957 | } |
| 2958 | global.last_checks |= LSTCHK_NETADM; |
| 2959 | #else /* no TPROXY support */ |
| 2960 | ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n", |
| 2961 | file, linenum, "usesrc"); |
| 2962 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2963 | goto out; |
| 2964 | #endif |
| 2965 | cur_arg += 2; |
| 2966 | continue; |
| 2967 | } |
| 2968 | |
| 2969 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 2970 | #ifdef SO_BINDTODEVICE |
| 2971 | if (!*args[cur_arg + 1]) { |
| 2972 | ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 2973 | file, linenum, args[0]); |
| 2974 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2975 | goto out; |
| 2976 | } |
| 2977 | free(curproxy->conn_src.iface_name); |
| 2978 | curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 2979 | curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name); |
| 2980 | global.last_checks |= LSTCHK_NETADM; |
| 2981 | #else |
| 2982 | ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 2983 | file, linenum, args[0], args[cur_arg]); |
| 2984 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2985 | goto out; |
| 2986 | #endif |
| 2987 | cur_arg += 2; |
| 2988 | continue; |
| 2989 | } |
| 2990 | ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n", |
| 2991 | file, linenum, args[0], "interface", "usesrc"); |
| 2992 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2993 | goto out; |
| 2994 | } |
| 2995 | } |
| 2996 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 2997 | ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 2998 | file, linenum, "usesrc", "source"); |
| 2999 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3000 | goto out; |
| 3001 | } |
| 3002 | 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] | 3003 | 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] | 3004 | "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] | 3005 | file, linenum, args[0]); |
| 3006 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3007 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 3008 | } |
| 3009 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 3010 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 3011 | "Use 'http-request del-header' instead.\n", file, linenum, args[0]); |
| 3012 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3013 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 3014 | } |
| 3015 | 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] | 3016 | ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. " |
| 3017 | "Use 'http-request deny' instead.\n", file, linenum, args[0]); |
| 3018 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3019 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 3020 | } |
| 3021 | 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] | 3022 | ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]); |
| 3023 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3024 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 3025 | } |
| 3026 | 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] | 3027 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 3028 | "Use 'http-request allow' instead.\n", file, linenum, args[0]); |
| 3029 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3030 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 3031 | } |
| 3032 | 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] | 3033 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 3034 | "Use 'http-request tarpit' instead.\n", file, linenum, args[0]); |
| 3035 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3036 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 3037 | } |
| 3038 | 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] | 3039 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 3040 | "Use 'http-request replace-header' instead.\n", file, linenum, args[0]); |
| 3041 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3042 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 3043 | } |
| 3044 | 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] | 3045 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 3046 | "Use 'http-request del-header' instead.\n", file, linenum, args[0]); |
| 3047 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3048 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 3049 | } |
| 3050 | 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] | 3051 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 3052 | "Use 'http-request deny' instead.\n", file, linenum, args[0]); |
| 3053 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3054 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 3055 | } |
| 3056 | 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] | 3057 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]); |
| 3058 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3059 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 3060 | } |
| 3061 | 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] | 3062 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 3063 | "Use 'http-request allow' instead.\n", file, linenum, args[0]); |
| 3064 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3065 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 3066 | } |
| 3067 | 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] | 3068 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 3069 | "Use 'http-request tarpit' instead.\n", file, linenum, args[0]); |
| 3070 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3071 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 3072 | } |
| 3073 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 3074 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 3075 | "Use 'http-request add-header' instead.\n", file, linenum, args[0]); |
| 3076 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3077 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 3078 | } |
| 3079 | 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] | 3080 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 3081 | "Use 'http-response replace-header' instead.\n", file, linenum, args[0]); |
| 3082 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3083 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 3084 | } |
| 3085 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 3086 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 3087 | "Use 'http-response del-header' .\n", file, linenum, args[0]); |
| 3088 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3089 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 3090 | } |
| 3091 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 3092 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 3093 | "Use 'http-response deny' instead.\n", file, linenum, args[0]); |
| 3094 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3095 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 3096 | } |
| 3097 | 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] | 3098 | 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] | 3099 | "Use 'http-response replace-header' instead.\n", file, linenum, args[0]); |
| 3100 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3101 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 3102 | } |
| 3103 | 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] | 3104 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 3105 | "Use 'http-response del-header' instead.\n", file, linenum, args[0]); |
| 3106 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3107 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 3108 | } |
| 3109 | 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] | 3110 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 3111 | "Use 'http-response deny' instead.\n", file, linenum, args[0]); |
| 3112 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3113 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 3114 | } |
| 3115 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 3116 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 3117 | "Use 'http-response add-header' instead.\n", file, linenum, args[0]); |
| 3118 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3119 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 3120 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 3121 | else { |
| 3122 | struct cfg_kw_list *kwl; |
| 3123 | int index; |
| 3124 | |
| 3125 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 3126 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 3127 | if (kwl->kw[index].section != CFG_LISTEN) |
| 3128 | continue; |
| 3129 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 3130 | /* prepare error message just in case */ |
| 3131 | rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, &defproxy, file, linenum, &errmsg); |
| 3132 | if (rc < 0) { |
| 3133 | ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
| 3134 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3135 | goto out; |
| 3136 | } |
| 3137 | else if (rc > 0) { |
| 3138 | ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
| 3139 | err_code |= ERR_WARN; |
| 3140 | goto out; |
| 3141 | } |
| 3142 | goto out; |
| 3143 | } |
| 3144 | } |
| 3145 | } |
| 3146 | |
| 3147 | ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 3148 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3149 | goto out; |
| 3150 | } |
| 3151 | out: |
| 3152 | free(errmsg); |
| 3153 | return err_code; |
| 3154 | } |