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