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