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