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