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