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