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