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