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