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