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