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; |
Willy Tarreau | c3914d4 | 2020-09-24 08:39:22 +0200 | [diff] [blame] | 596 | curproxy->disabled = 1; |
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 | |
| 2027 | if (kwm != KWM_STD) { |
| 2028 | ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n", |
| 2029 | file, linenum, args[1]); |
| 2030 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2031 | goto out; |
| 2032 | } |
| 2033 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2034 | if (strcmp(args[1], "httplog") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2035 | char *logformat; |
| 2036 | /* generate a complete HTTP log */ |
| 2037 | logformat = default_http_log_format; |
| 2038 | if (*(args[2]) != '\0') { |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2039 | if (strcmp(args[2], "clf") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2040 | curproxy->options2 |= PR_O2_CLFLOG; |
| 2041 | logformat = clf_http_log_format; |
| 2042 | } else { |
| 2043 | ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]); |
| 2044 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2045 | goto out; |
| 2046 | } |
| 2047 | if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code)) |
| 2048 | goto out; |
| 2049 | } |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 2050 | if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2051 | char *oldlogformat = "log-format"; |
| 2052 | char *clflogformat = ""; |
| 2053 | |
| 2054 | if (curproxy->conf.logformat_string == default_http_log_format) |
| 2055 | oldlogformat = "option httplog"; |
| 2056 | else if (curproxy->conf.logformat_string == default_tcp_log_format) |
| 2057 | oldlogformat = "option tcplog"; |
| 2058 | else if (curproxy->conf.logformat_string == clf_http_log_format) |
| 2059 | oldlogformat = "option httplog clf"; |
| 2060 | if (logformat == clf_http_log_format) |
| 2061 | clflogformat = " clf"; |
| 2062 | ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n", |
| 2063 | file, linenum, clflogformat, oldlogformat); |
| 2064 | } |
| 2065 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 2066 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2067 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2068 | free(curproxy->conf.logformat_string); |
| 2069 | curproxy->conf.logformat_string = logformat; |
| 2070 | |
| 2071 | free(curproxy->conf.lfs_file); |
| 2072 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 2073 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
| 2074 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 2075 | if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2076 | ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n", |
| 2077 | file, linenum, curproxy->id); |
| 2078 | err_code |= ERR_WARN; |
| 2079 | } |
| 2080 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2081 | else if (strcmp(args[1], "tcplog") == 0) { |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 2082 | if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2083 | char *oldlogformat = "log-format"; |
| 2084 | |
| 2085 | if (curproxy->conf.logformat_string == default_http_log_format) |
| 2086 | oldlogformat = "option httplog"; |
| 2087 | else if (curproxy->conf.logformat_string == default_tcp_log_format) |
| 2088 | oldlogformat = "option tcplog"; |
| 2089 | else if (curproxy->conf.logformat_string == clf_http_log_format) |
| 2090 | oldlogformat = "option httplog clf"; |
| 2091 | ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n", |
| 2092 | file, linenum, oldlogformat); |
| 2093 | } |
| 2094 | /* generate a detailed TCP log */ |
| 2095 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 2096 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2097 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2098 | free(curproxy->conf.logformat_string); |
| 2099 | curproxy->conf.logformat_string = default_tcp_log_format; |
| 2100 | |
| 2101 | free(curproxy->conf.lfs_file); |
| 2102 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 2103 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
| 2104 | |
| 2105 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2106 | goto out; |
| 2107 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 2108 | if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2109 | ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n", |
| 2110 | file, linenum, curproxy->id); |
| 2111 | err_code |= ERR_WARN; |
| 2112 | } |
| 2113 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2114 | else if (strcmp(args[1], "tcpka") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2115 | /* enable TCP keep-alives on client and server streams */ |
| 2116 | if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL)) |
| 2117 | err_code |= ERR_WARN; |
| 2118 | |
| 2119 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2120 | goto out; |
| 2121 | |
| 2122 | if (curproxy->cap & PR_CAP_FE) |
| 2123 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 2124 | if (curproxy->cap & PR_CAP_BE) |
| 2125 | curproxy->options |= PR_O_TCP_SRV_KA; |
| 2126 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2127 | else if (strcmp(args[1], "httpchk") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame] | 2128 | 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] | 2129 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2130 | goto out; |
| 2131 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2132 | else if (strcmp(args[1], "ssl-hello-chk") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame] | 2133 | 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] | 2134 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2135 | goto out; |
| 2136 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2137 | else if (strcmp(args[1], "smtpchk") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame] | 2138 | 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] | 2139 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2140 | goto out; |
| 2141 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2142 | else if (strcmp(args[1], "pgsql-check") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame] | 2143 | 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] | 2144 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2145 | goto out; |
| 2146 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2147 | else if (strcmp(args[1], "redis-check") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame] | 2148 | 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] | 2149 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2150 | goto out; |
| 2151 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2152 | else if (strcmp(args[1], "mysql-check") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame] | 2153 | 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] | 2154 | if (err_code & ERR_FATAL) |
| 2155 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2156 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2157 | else if (strcmp(args[1], "ldap-check") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame] | 2158 | 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] | 2159 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2160 | goto out; |
| 2161 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2162 | else if (strcmp(args[1], "spop-check") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame] | 2163 | 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] | 2164 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2165 | goto out; |
| 2166 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2167 | else if (strcmp(args[1], "tcp-check") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame] | 2168 | 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] | 2169 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2170 | goto out; |
| 2171 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2172 | else if (strcmp(args[1], "external-check") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame] | 2173 | 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] | 2174 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2175 | goto out; |
| 2176 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2177 | else if (strcmp(args[1], "forwardfor") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2178 | int cur_arg; |
| 2179 | |
| 2180 | /* 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] | 2181 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2182 | */ |
| 2183 | |
| 2184 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
| 2185 | |
| 2186 | free(curproxy->fwdfor_hdr_name); |
| 2187 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
Christopher Faulet | b15625a | 2021-04-12 21:31:45 +0200 | [diff] [blame] | 2188 | if (!curproxy->fwdfor_hdr_name) |
| 2189 | goto alloc_error; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2190 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
Christopher Faulet | 5d1def6 | 2021-02-26 09:19:15 +0100 | [diff] [blame] | 2191 | curproxy->except_xff_net.family = AF_UNSPEC; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2192 | |
| 2193 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 2194 | cur_arg = 2; |
| 2195 | while (*(args[cur_arg])) { |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2196 | if (strcmp(args[cur_arg], "except") == 0) { |
Christopher Faulet | 5d1def6 | 2021-02-26 09:19:15 +0100 | [diff] [blame] | 2197 | unsigned char mask; |
| 2198 | int i; |
| 2199 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2200 | /* suboption except - needs additional argument for it */ |
Christopher Faulet | 5d1def6 | 2021-02-26 09:19:15 +0100 | [diff] [blame] | 2201 | if (*(args[cur_arg+1]) && |
| 2202 | str2net(args[cur_arg+1], 1, &curproxy->except_xff_net.addr.v4.ip, &curproxy->except_xff_net.addr.v4.mask)) { |
| 2203 | curproxy->except_xff_net.family = AF_INET; |
| 2204 | curproxy->except_xff_net.addr.v4.ip.s_addr &= curproxy->except_xff_net.addr.v4.mask.s_addr; |
| 2205 | } |
| 2206 | else if (*(args[cur_arg+1]) && |
| 2207 | str62net(args[cur_arg+1], &curproxy->except_xff_net.addr.v6.ip, &mask)) { |
| 2208 | curproxy->except_xff_net.family = AF_INET6; |
| 2209 | len2mask6(mask, &curproxy->except_xff_net.addr.v6.mask); |
| 2210 | for (i = 0; i < 16; i++) |
| 2211 | curproxy->except_xff_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xff_net.addr.v6.mask.s6_addr[i]; |
| 2212 | } |
| 2213 | else { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2214 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 2215 | file, linenum, args[0], args[1], args[cur_arg]); |
| 2216 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2217 | goto out; |
| 2218 | } |
| 2219 | /* flush useless bits */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2220 | cur_arg += 2; |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2221 | } else if (strcmp(args[cur_arg], "header") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2222 | /* suboption header - needs additional argument for it */ |
| 2223 | if (*(args[cur_arg+1]) == 0) { |
| 2224 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 2225 | file, linenum, args[0], args[1], args[cur_arg]); |
| 2226 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2227 | goto out; |
| 2228 | } |
| 2229 | free(curproxy->fwdfor_hdr_name); |
| 2230 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
Christopher Faulet | b15625a | 2021-04-12 21:31:45 +0200 | [diff] [blame] | 2231 | if (!curproxy->fwdfor_hdr_name) |
| 2232 | goto alloc_error; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2233 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 2234 | cur_arg += 2; |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2235 | } else if (strcmp(args[cur_arg], "if-none") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2236 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 2237 | cur_arg += 1; |
| 2238 | } else { |
| 2239 | /* unknown suboption - catchall */ |
| 2240 | ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n", |
| 2241 | file, linenum, args[0], args[1]); |
| 2242 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2243 | goto out; |
| 2244 | } |
| 2245 | } /* end while loop */ |
| 2246 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2247 | else if (strcmp(args[1], "originalto") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2248 | int cur_arg; |
| 2249 | |
| 2250 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 2251 | * set default options (ie: bitfield, header name, etc) |
| 2252 | */ |
| 2253 | |
| 2254 | curproxy->options |= PR_O_ORGTO; |
| 2255 | |
| 2256 | free(curproxy->orgto_hdr_name); |
| 2257 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
Christopher Faulet | b15625a | 2021-04-12 21:31:45 +0200 | [diff] [blame] | 2258 | if (!curproxy->orgto_hdr_name) |
| 2259 | goto alloc_error; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2260 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
Christopher Faulet | 5d1def6 | 2021-02-26 09:19:15 +0100 | [diff] [blame] | 2261 | curproxy->except_xot_net.family = AF_UNSPEC; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2262 | |
| 2263 | /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */ |
| 2264 | cur_arg = 2; |
| 2265 | while (*(args[cur_arg])) { |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2266 | if (strcmp(args[cur_arg], "except") == 0) { |
Christopher Faulet | 5d1def6 | 2021-02-26 09:19:15 +0100 | [diff] [blame] | 2267 | unsigned char mask; |
| 2268 | int i; |
| 2269 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2270 | /* suboption except - needs additional argument for it */ |
Christopher Faulet | 5d1def6 | 2021-02-26 09:19:15 +0100 | [diff] [blame] | 2271 | if (*(args[cur_arg+1]) && |
| 2272 | str2net(args[cur_arg+1], 1, &curproxy->except_xot_net.addr.v4.ip, &curproxy->except_xot_net.addr.v4.mask)) { |
| 2273 | curproxy->except_xot_net.family = AF_INET; |
| 2274 | curproxy->except_xot_net.addr.v4.ip.s_addr &= curproxy->except_xot_net.addr.v4.mask.s_addr; |
| 2275 | } |
| 2276 | else if (*(args[cur_arg+1]) && |
| 2277 | str62net(args[cur_arg+1], &curproxy->except_xot_net.addr.v6.ip, &mask)) { |
| 2278 | curproxy->except_xot_net.family = AF_INET6; |
| 2279 | len2mask6(mask, &curproxy->except_xot_net.addr.v6.mask); |
| 2280 | for (i = 0; i < 16; i++) |
| 2281 | curproxy->except_xot_net.addr.v6.ip.s6_addr[i] &= curproxy->except_xot_net.addr.v6.mask.s6_addr[i]; |
| 2282 | } |
| 2283 | else { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2284 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 2285 | file, linenum, args[0], args[1], args[cur_arg]); |
| 2286 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2287 | goto out; |
| 2288 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2289 | cur_arg += 2; |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2290 | } else if (strcmp(args[cur_arg], "header") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2291 | /* suboption header - needs additional argument for it */ |
| 2292 | if (*(args[cur_arg+1]) == 0) { |
| 2293 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 2294 | file, linenum, args[0], args[1], args[cur_arg]); |
| 2295 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2296 | goto out; |
| 2297 | } |
| 2298 | free(curproxy->orgto_hdr_name); |
| 2299 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
Christopher Faulet | b15625a | 2021-04-12 21:31:45 +0200 | [diff] [blame] | 2300 | if (!curproxy->orgto_hdr_name) |
| 2301 | goto alloc_error; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2302 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 2303 | cur_arg += 2; |
| 2304 | } else { |
| 2305 | /* unknown suboption - catchall */ |
| 2306 | ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 2307 | file, linenum, args[0], args[1]); |
| 2308 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2309 | goto out; |
| 2310 | } |
| 2311 | } /* end while loop */ |
| 2312 | } |
| 2313 | else { |
Willy Tarreau | 31a3cea | 2021-03-15 11:11:55 +0100 | [diff] [blame] | 2314 | const char *best = proxy_find_best_option(args[1], common_options); |
| 2315 | |
| 2316 | if (best) |
| 2317 | ha_alert("parsing [%s:%d] : unknown option '%s'; did you mean '%s' maybe ?\n", file, linenum, args[1], best); |
| 2318 | else |
| 2319 | ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
| 2320 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2321 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2322 | goto out; |
| 2323 | } |
| 2324 | goto out; |
| 2325 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2326 | else if (strcmp(args[0], "default_backend") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2327 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
| 2328 | err_code |= ERR_WARN; |
| 2329 | |
| 2330 | if (*(args[1]) == 0) { |
| 2331 | ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]); |
| 2332 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2333 | goto out; |
| 2334 | } |
| 2335 | free(curproxy->defbe.name); |
| 2336 | curproxy->defbe.name = strdup(args[1]); |
Christopher Faulet | b15625a | 2021-04-12 21:31:45 +0200 | [diff] [blame] | 2337 | if (!curproxy->defbe.name) |
| 2338 | goto alloc_error; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2339 | |
| 2340 | if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code)) |
| 2341 | goto out; |
| 2342 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2343 | else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) { |
Tim Duesterhus | dac168b | 2019-05-14 20:57:58 +0200 | [diff] [blame] | 2344 | 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] | 2345 | |
Tim Duesterhus | dac168b | 2019-05-14 20:57:58 +0200 | [diff] [blame] | 2346 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2347 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2348 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2349 | else if (strcmp(args[0], "http-reuse") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2350 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2351 | err_code |= ERR_WARN; |
| 2352 | |
| 2353 | if (strcmp(args[1], "never") == 0) { |
| 2354 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 2355 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 2356 | curproxy->options |= PR_O_REUSE_NEVR; |
| 2357 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2358 | goto out; |
| 2359 | } |
| 2360 | else if (strcmp(args[1], "safe") == 0) { |
| 2361 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 2362 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 2363 | curproxy->options |= PR_O_REUSE_SAFE; |
| 2364 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2365 | goto out; |
| 2366 | } |
| 2367 | else if (strcmp(args[1], "aggressive") == 0) { |
| 2368 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 2369 | curproxy->options |= PR_O_REUSE_AGGR; |
| 2370 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2371 | goto out; |
| 2372 | } |
| 2373 | else if (strcmp(args[1], "always") == 0) { |
| 2374 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 2375 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 2376 | curproxy->options |= PR_O_REUSE_ALWS; |
| 2377 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2378 | goto out; |
| 2379 | } |
| 2380 | else { |
| 2381 | ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]); |
| 2382 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2383 | goto out; |
| 2384 | } |
| 2385 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2386 | else if (strcmp(args[0], "monitor") == 0) { |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 2387 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2388 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2389 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2390 | goto out; |
| 2391 | } |
| 2392 | |
| 2393 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
| 2394 | err_code |= ERR_WARN; |
| 2395 | |
| 2396 | if (strcmp(args[1], "fail") == 0) { |
| 2397 | /* add a condition to fail monitor requests */ |
| 2398 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 2399 | ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2400 | file, linenum, args[0], args[1]); |
| 2401 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2402 | goto out; |
| 2403 | } |
| 2404 | |
| 2405 | err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail"); |
| 2406 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 2407 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 2408 | file, linenum, args[0], args[1], errmsg); |
| 2409 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2410 | goto out; |
| 2411 | } |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 2412 | LIST_APPEND(&curproxy->mon_fail_cond, &cond->list); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2413 | } |
| 2414 | else { |
| 2415 | ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]); |
| 2416 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2417 | goto out; |
| 2418 | } |
| 2419 | } |
Willy Tarreau | e573323 | 2019-05-22 19:24:06 +0200 | [diff] [blame] | 2420 | #ifdef USE_TPROXY |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2421 | else if (strcmp(args[0], "transparent") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2422 | /* enable transparent proxy connections */ |
| 2423 | curproxy->options |= PR_O_TRANSP; |
| 2424 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 2425 | goto out; |
| 2426 | } |
| 2427 | #endif |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2428 | else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2429 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?")) |
| 2430 | err_code |= ERR_WARN; |
| 2431 | |
| 2432 | if (*(args[1]) == 0) { |
| 2433 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 2434 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2435 | goto out; |
| 2436 | } |
| 2437 | curproxy->maxconn = atol(args[1]); |
| 2438 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 2439 | goto out; |
| 2440 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2441 | else if (strcmp(args[0], "backlog") == 0) { /* backlog */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2442 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
| 2443 | err_code |= ERR_WARN; |
| 2444 | |
| 2445 | if (*(args[1]) == 0) { |
| 2446 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 2447 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2448 | goto out; |
| 2449 | } |
| 2450 | curproxy->backlog = atol(args[1]); |
| 2451 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 2452 | goto out; |
| 2453 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2454 | else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2455 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?")) |
| 2456 | err_code |= ERR_WARN; |
| 2457 | |
| 2458 | if (*(args[1]) == 0) { |
| 2459 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 2460 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2461 | goto out; |
| 2462 | } |
| 2463 | curproxy->fullconn = atol(args[1]); |
| 2464 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 2465 | goto out; |
| 2466 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2467 | else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */ |
Willy Tarreau | eb77824 | 2021-06-11 16:27:10 +0200 | [diff] [blame] | 2468 | 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] | 2469 | file, linenum, args[0]); |
Willy Tarreau | eb77824 | 2021-06-11 16:27:10 +0200 | [diff] [blame] | 2470 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2471 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2472 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2473 | else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2474 | struct sockaddr_storage *sk; |
| 2475 | int port1, port2; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2476 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 2477 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2478 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2479 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2480 | goto out; |
| 2481 | } |
| 2482 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2483 | err_code |= ERR_WARN; |
| 2484 | |
Willy Tarreau | 65ec4e3 | 2020-09-16 19:17:08 +0200 | [diff] [blame] | 2485 | sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL, |
| 2486 | &errmsg, NULL, NULL, |
| 2487 | 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] | 2488 | if (!sk) { |
| 2489 | ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
| 2490 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2491 | goto out; |
| 2492 | } |
| 2493 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2494 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 2495 | goto out; |
| 2496 | |
| 2497 | curproxy->dispatch_addr = *sk; |
| 2498 | curproxy->options |= PR_O_DISPATCH; |
| 2499 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2500 | else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2501 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2502 | err_code |= ERR_WARN; |
| 2503 | |
| 2504 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 2505 | ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
| 2506 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2507 | goto out; |
| 2508 | } |
| 2509 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2510 | else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2511 | /** |
| 2512 | * The syntax for hash-type config element is |
| 2513 | * hash-type {map-based|consistent} [[<algo>] avalanche] |
| 2514 | * |
| 2515 | * The default hash function is sdbm for map-based and sdbm+avalanche for consistent. |
| 2516 | */ |
| 2517 | curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD); |
| 2518 | |
| 2519 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2520 | err_code |= ERR_WARN; |
| 2521 | |
| 2522 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
| 2523 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 2524 | } |
| 2525 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
| 2526 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 2527 | } |
| 2528 | else if (strcmp(args[1], "avalanche") == 0) { |
| 2529 | 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]); |
| 2530 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2531 | goto out; |
| 2532 | } |
| 2533 | else { |
| 2534 | ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]); |
| 2535 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2536 | goto out; |
| 2537 | } |
| 2538 | |
| 2539 | /* set the hash function to use */ |
| 2540 | if (!*args[2]) { |
| 2541 | /* the default algo is sdbm */ |
| 2542 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 2543 | |
| 2544 | /* if consistent with no argument, then avalanche modifier is also applied */ |
| 2545 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) |
| 2546 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 2547 | } else { |
| 2548 | /* set the hash function */ |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2549 | if (strcmp(args[2], "sdbm") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2550 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 2551 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2552 | else if (strcmp(args[2], "djb2") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2553 | curproxy->lbprm.algo |= BE_LB_HFCN_DJB2; |
| 2554 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2555 | else if (strcmp(args[2], "wt6") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2556 | curproxy->lbprm.algo |= BE_LB_HFCN_WT6; |
| 2557 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2558 | else if (strcmp(args[2], "crc32") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2559 | curproxy->lbprm.algo |= BE_LB_HFCN_CRC32; |
| 2560 | } |
| 2561 | else { |
| 2562 | ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]); |
| 2563 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2564 | goto out; |
| 2565 | } |
| 2566 | |
| 2567 | /* set the hash modifier */ |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2568 | if (strcmp(args[3], "avalanche") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2569 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 2570 | } |
| 2571 | else if (*args[3]) { |
| 2572 | ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]); |
| 2573 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2574 | goto out; |
| 2575 | } |
| 2576 | } |
| 2577 | } |
| 2578 | else if (strcmp(args[0], "hash-balance-factor") == 0) { |
| 2579 | if (*(args[1]) == 0) { |
| 2580 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 2581 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2582 | goto out; |
| 2583 | } |
Willy Tarreau | 76e84f5 | 2019-01-14 16:50:58 +0100 | [diff] [blame] | 2584 | curproxy->lbprm.hash_balance_factor = atol(args[1]); |
| 2585 | 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] | 2586 | ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]); |
| 2587 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2588 | goto out; |
| 2589 | } |
| 2590 | } |
| 2591 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 2592 | if (!*(args[1])) { |
| 2593 | ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 2594 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2595 | goto out; |
| 2596 | } |
| 2597 | if (*(args[2])) { |
| 2598 | ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 2599 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2600 | goto out; |
| 2601 | } |
| 2602 | free(curproxy->conf.uniqueid_format_string); |
| 2603 | curproxy->conf.uniqueid_format_string = strdup(args[1]); |
Christopher Faulet | b15625a | 2021-04-12 21:31:45 +0200 | [diff] [blame] | 2604 | if (!curproxy->conf.uniqueid_format_string) |
| 2605 | goto alloc_error; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2606 | |
| 2607 | free(curproxy->conf.uif_file); |
| 2608 | curproxy->conf.uif_file = strdup(curproxy->conf.args.file); |
| 2609 | curproxy->conf.uif_line = curproxy->conf.args.line; |
| 2610 | } |
| 2611 | |
| 2612 | else if (strcmp(args[0], "unique-id-header") == 0) { |
Tim Duesterhus | 0643b0e | 2020-03-05 17:56:35 +0100 | [diff] [blame] | 2613 | char *copy; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2614 | if (!*(args[1])) { |
| 2615 | ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 2616 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2617 | goto out; |
| 2618 | } |
Tim Duesterhus | 0643b0e | 2020-03-05 17:56:35 +0100 | [diff] [blame] | 2619 | copy = strdup(args[1]); |
| 2620 | if (copy == NULL) { |
| 2621 | ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum); |
| 2622 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2623 | goto out; |
| 2624 | } |
| 2625 | |
| 2626 | istfree(&curproxy->header_unique_id); |
| 2627 | curproxy->header_unique_id = ist(copy); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2628 | } |
| 2629 | |
| 2630 | else if (strcmp(args[0], "log-format") == 0) { |
| 2631 | if (!*(args[1])) { |
| 2632 | ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 2633 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2634 | goto out; |
| 2635 | } |
| 2636 | if (*(args[2])) { |
| 2637 | ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 2638 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2639 | goto out; |
| 2640 | } |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 2641 | if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2642 | char *oldlogformat = "log-format"; |
| 2643 | |
| 2644 | if (curproxy->conf.logformat_string == default_http_log_format) |
| 2645 | oldlogformat = "option httplog"; |
| 2646 | else if (curproxy->conf.logformat_string == default_tcp_log_format) |
| 2647 | oldlogformat = "option tcplog"; |
| 2648 | else if (curproxy->conf.logformat_string == clf_http_log_format) |
| 2649 | oldlogformat = "option httplog clf"; |
| 2650 | ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n", |
| 2651 | file, linenum, oldlogformat); |
| 2652 | } |
| 2653 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 2654 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2655 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2656 | free(curproxy->conf.logformat_string); |
| 2657 | curproxy->conf.logformat_string = strdup(args[1]); |
Christopher Faulet | b15625a | 2021-04-12 21:31:45 +0200 | [diff] [blame] | 2658 | if (!curproxy->conf.logformat_string) |
| 2659 | goto alloc_error; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2660 | |
| 2661 | free(curproxy->conf.lfs_file); |
| 2662 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 2663 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
| 2664 | |
| 2665 | /* get a chance to improve log-format error reporting by |
| 2666 | * reporting the correct line-number when possible. |
| 2667 | */ |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 2668 | if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2669 | ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n", |
| 2670 | file, linenum, curproxy->id); |
| 2671 | err_code |= ERR_WARN; |
| 2672 | } |
| 2673 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2674 | else if (strcmp(args[0], "log-format-sd") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2675 | if (!*(args[1])) { |
| 2676 | ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 2677 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2678 | goto out; |
| 2679 | } |
| 2680 | if (*(args[2])) { |
| 2681 | ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 2682 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2683 | goto out; |
| 2684 | } |
| 2685 | |
| 2686 | if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 2687 | free(curproxy->conf.logformat_sd_string); |
| 2688 | curproxy->conf.logformat_sd_string = strdup(args[1]); |
Christopher Faulet | b15625a | 2021-04-12 21:31:45 +0200 | [diff] [blame] | 2689 | if (!curproxy->conf.logformat_sd_string) |
| 2690 | goto alloc_error; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2691 | |
| 2692 | free(curproxy->conf.lfsd_file); |
| 2693 | curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file); |
| 2694 | curproxy->conf.lfsd_line = curproxy->conf.args.line; |
| 2695 | |
| 2696 | /* get a chance to improve log-format-sd error reporting by |
| 2697 | * reporting the correct line-number when possible. |
| 2698 | */ |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 2699 | if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2700 | ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n", |
| 2701 | file, linenum, curproxy->id); |
| 2702 | err_code |= ERR_WARN; |
| 2703 | } |
| 2704 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2705 | 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] | 2706 | if (*(args[1]) == 0) { |
| 2707 | ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 2708 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2709 | goto out; |
| 2710 | } |
| 2711 | chunk_destroy(&curproxy->log_tag); |
Eric Salama | 7cea606 | 2020-10-02 11:58:19 +0200 | [diff] [blame] | 2712 | chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1])); |
| 2713 | if (b_orig(&curproxy->log_tag) == NULL) { |
| 2714 | chunk_destroy(&curproxy->log_tag); |
| 2715 | ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]); |
| 2716 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2717 | goto out; |
| 2718 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2719 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2720 | else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */ |
Emeric Brun | 9533a70 | 2021-04-02 10:13:43 +0200 | [diff] [blame] | 2721 | if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2722 | ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg); |
| 2723 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2724 | goto out; |
| 2725 | } |
| 2726 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2727 | 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] | 2728 | int cur_arg; |
| 2729 | int port1, port2; |
| 2730 | struct sockaddr_storage *sk; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2731 | |
| 2732 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2733 | err_code |= ERR_WARN; |
| 2734 | |
| 2735 | if (!*args[1]) { |
| 2736 | ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 2737 | file, linenum, "source", "usesrc", "interface"); |
| 2738 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2739 | goto out; |
| 2740 | } |
| 2741 | |
Christopher Faulet | 3193037 | 2019-07-15 10:16:58 +0200 | [diff] [blame] | 2742 | /* we must first clear any optional default setting */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2743 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
Willy Tarreau | 61cfdf4 | 2021-02-20 10:46:51 +0100 | [diff] [blame] | 2744 | ha_free(&curproxy->conn_src.iface_name); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2745 | curproxy->conn_src.iface_len = 0; |
| 2746 | |
Willy Tarreau | 65ec4e3 | 2020-09-16 19:17:08 +0200 | [diff] [blame] | 2747 | sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL, |
| 2748 | &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] | 2749 | if (!sk) { |
| 2750 | ha_alert("parsing [%s:%d] : '%s %s' : %s\n", |
| 2751 | file, linenum, args[0], args[1], errmsg); |
| 2752 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2753 | goto out; |
| 2754 | } |
| 2755 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2756 | curproxy->conn_src.source_addr = *sk; |
| 2757 | curproxy->conn_src.opts |= CO_SRC_BIND; |
| 2758 | |
| 2759 | cur_arg = 2; |
| 2760 | while (*(args[cur_arg])) { |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2761 | if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2762 | #if defined(CONFIG_HAP_TRANSPARENT) |
| 2763 | if (!*args[cur_arg + 1]) { |
| 2764 | ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 2765 | file, linenum, "usesrc"); |
| 2766 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2767 | goto out; |
| 2768 | } |
| 2769 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2770 | if (strcmp(args[cur_arg + 1], "client") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2771 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 2772 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2773 | } else if (strcmp(args[cur_arg + 1], "clientip") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2774 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 2775 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP; |
| 2776 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 2777 | char *name, *end; |
| 2778 | |
| 2779 | name = args[cur_arg+1] + 7; |
Willy Tarreau | 9080711 | 2020-02-25 08:16:33 +0100 | [diff] [blame] | 2780 | while (isspace((unsigned char)*name)) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2781 | name++; |
| 2782 | |
| 2783 | end = name; |
Willy Tarreau | 9080711 | 2020-02-25 08:16:33 +0100 | [diff] [blame] | 2784 | while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')') |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2785 | end++; |
| 2786 | |
| 2787 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 2788 | curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN; |
Amaury Denoyelle | 69c5c3a | 2021-01-26 14:35:22 +0100 | [diff] [blame] | 2789 | free(curproxy->conn_src.bind_hdr_name); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2790 | curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
Christopher Faulet | b15625a | 2021-04-12 21:31:45 +0200 | [diff] [blame] | 2791 | if (!curproxy->conn_src.bind_hdr_name) |
| 2792 | goto alloc_error; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2793 | curproxy->conn_src.bind_hdr_len = end - name; |
| 2794 | memcpy(curproxy->conn_src.bind_hdr_name, name, end - name); |
| 2795 | curproxy->conn_src.bind_hdr_name[end-name] = '\0'; |
| 2796 | curproxy->conn_src.bind_hdr_occ = -1; |
| 2797 | |
| 2798 | /* now look for an occurrence number */ |
Willy Tarreau | 9080711 | 2020-02-25 08:16:33 +0100 | [diff] [blame] | 2799 | while (isspace((unsigned char)*end)) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2800 | end++; |
| 2801 | if (*end == ',') { |
| 2802 | end++; |
| 2803 | name = end; |
| 2804 | if (*end == '-') |
| 2805 | end++; |
Willy Tarreau | 9080711 | 2020-02-25 08:16:33 +0100 | [diff] [blame] | 2806 | while (isdigit((unsigned char)*end)) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2807 | end++; |
| 2808 | curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
| 2809 | } |
| 2810 | |
| 2811 | if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
| 2812 | ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 2813 | " occurrences values smaller than %d.\n", |
| 2814 | file, linenum, MAX_HDR_HISTORY); |
| 2815 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2816 | goto out; |
| 2817 | } |
| 2818 | } else { |
| 2819 | struct sockaddr_storage *sk; |
| 2820 | |
Willy Tarreau | 65ec4e3 | 2020-09-16 19:17:08 +0200 | [diff] [blame] | 2821 | sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL, |
| 2822 | &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] | 2823 | if (!sk) { |
| 2824 | ha_alert("parsing [%s:%d] : '%s %s' : %s\n", |
| 2825 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
| 2826 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2827 | goto out; |
| 2828 | } |
| 2829 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2830 | curproxy->conn_src.tproxy_addr = *sk; |
| 2831 | curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
| 2832 | } |
| 2833 | global.last_checks |= LSTCHK_NETADM; |
| 2834 | #else /* no TPROXY support */ |
| 2835 | ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n", |
| 2836 | file, linenum, "usesrc"); |
| 2837 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2838 | goto out; |
| 2839 | #endif |
| 2840 | cur_arg += 2; |
| 2841 | continue; |
| 2842 | } |
| 2843 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2844 | if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2845 | #ifdef SO_BINDTODEVICE |
| 2846 | if (!*args[cur_arg + 1]) { |
| 2847 | ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 2848 | file, linenum, args[0]); |
| 2849 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2850 | goto out; |
| 2851 | } |
| 2852 | free(curproxy->conn_src.iface_name); |
| 2853 | curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]); |
Christopher Faulet | b15625a | 2021-04-12 21:31:45 +0200 | [diff] [blame] | 2854 | if (!curproxy->conn_src.iface_name) |
| 2855 | goto alloc_error; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2856 | curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name); |
| 2857 | global.last_checks |= LSTCHK_NETADM; |
| 2858 | #else |
| 2859 | ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 2860 | file, linenum, args[0], args[cur_arg]); |
| 2861 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2862 | goto out; |
| 2863 | #endif |
| 2864 | cur_arg += 2; |
| 2865 | continue; |
| 2866 | } |
| 2867 | ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n", |
| 2868 | file, linenum, args[0], "interface", "usesrc"); |
| 2869 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2870 | goto out; |
| 2871 | } |
| 2872 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2873 | 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] | 2874 | ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 2875 | file, linenum, "usesrc", "source"); |
| 2876 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2877 | goto out; |
| 2878 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2879 | 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] | 2880 | 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] | 2881 | "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] | 2882 | file, linenum, args[0]); |
| 2883 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2884 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2885 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2886 | 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] | 2887 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2888 | "Use 'http-request del-header' instead.\n", file, linenum, args[0]); |
| 2889 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2890 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2891 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2892 | 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] | 2893 | ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. " |
| 2894 | "Use 'http-request deny' instead.\n", file, linenum, args[0]); |
| 2895 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2896 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2897 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2898 | 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] | 2899 | ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]); |
| 2900 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2901 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2902 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2903 | 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] | 2904 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2905 | "Use 'http-request allow' instead.\n", file, linenum, args[0]); |
| 2906 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2907 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2908 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2909 | else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2910 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2911 | "Use 'http-request tarpit' instead.\n", file, linenum, args[0]); |
| 2912 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2913 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2914 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2915 | else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2916 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2917 | "Use 'http-request replace-header' instead.\n", file, linenum, args[0]); |
| 2918 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2919 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2920 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2921 | else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2922 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2923 | "Use 'http-request del-header' instead.\n", file, linenum, args[0]); |
| 2924 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2925 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2926 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2927 | 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] | 2928 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2929 | "Use 'http-request deny' instead.\n", file, linenum, args[0]); |
| 2930 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2931 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2932 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2933 | 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] | 2934 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]); |
| 2935 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2936 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2937 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2938 | else if (strcmp(args[0], "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] | 2939 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2940 | "Use 'http-request allow' instead.\n", file, linenum, args[0]); |
| 2941 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2942 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2943 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2944 | else if (strcmp(args[0], "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] | 2945 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2946 | "Use 'http-request tarpit' instead.\n", file, linenum, args[0]); |
| 2947 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2948 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2949 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2950 | else if (strcmp(args[0], "reqadd") == 0) { /* add request header */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2951 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2952 | "Use 'http-request add-header' instead.\n", file, linenum, args[0]); |
| 2953 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2954 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2955 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2956 | else if (strcmp(args[0], "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] | 2957 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2958 | "Use 'http-response replace-header' instead.\n", file, linenum, args[0]); |
| 2959 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2960 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2961 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2962 | 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] | 2963 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2964 | "Use 'http-response del-header' .\n", file, linenum, args[0]); |
| 2965 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2966 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2967 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2968 | 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] | 2969 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2970 | "Use 'http-response deny' instead.\n", file, linenum, args[0]); |
| 2971 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2972 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2973 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2974 | 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] | 2975 | 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] | 2976 | "Use 'http-response replace-header' instead.\n", file, linenum, args[0]); |
| 2977 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2978 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2979 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2980 | 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] | 2981 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2982 | "Use 'http-response del-header' instead.\n", file, linenum, args[0]); |
| 2983 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2984 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2985 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2986 | 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] | 2987 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2988 | "Use 'http-response deny' instead.\n", file, linenum, args[0]); |
| 2989 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2990 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2991 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2992 | else if (strcmp(args[0], "rspadd") == 0) { /* add response header */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2993 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2994 | "Use 'http-response add-header' instead.\n", file, linenum, args[0]); |
| 2995 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2996 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2997 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2998 | else { |
| 2999 | struct cfg_kw_list *kwl; |
Willy Tarreau | c0ff679 | 2021-03-12 09:14:19 +0100 | [diff] [blame] | 3000 | const char *best; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 3001 | int index; |
| 3002 | |
| 3003 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 3004 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 3005 | if (kwl->kw[index].section != CFG_LISTEN) |
| 3006 | continue; |
| 3007 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
Amaury Denoyelle | d2e53cd | 2021-05-06 16:21:39 +0200 | [diff] [blame] | 3008 | if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) { |
Amaury Denoyelle | 86c1d0f | 2021-05-07 15:07:21 +0200 | [diff] [blame] | 3009 | ha_alert("%s\n", errmsg); |
Amaury Denoyelle | d2e53cd | 2021-05-06 16:21:39 +0200 | [diff] [blame] | 3010 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3011 | goto out; |
| 3012 | } |
| 3013 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 3014 | /* prepare error message just in case */ |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame] | 3015 | 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] | 3016 | if (rc < 0) { |
| 3017 | ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
| 3018 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3019 | goto out; |
| 3020 | } |
| 3021 | else if (rc > 0) { |
| 3022 | ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
| 3023 | err_code |= ERR_WARN; |
| 3024 | goto out; |
| 3025 | } |
| 3026 | goto out; |
| 3027 | } |
| 3028 | } |
| 3029 | } |
| 3030 | |
Willy Tarreau | c0ff679 | 2021-03-12 09:14:19 +0100 | [diff] [blame] | 3031 | best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_LISTEN, common_kw_list); |
| 3032 | if (best) |
| 3033 | ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best); |
| 3034 | else |
| 3035 | 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] | 3036 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3037 | goto out; |
| 3038 | } |
| 3039 | out: |
| 3040 | free(errmsg); |
| 3041 | return err_code; |
Christopher Faulet | b15625a | 2021-04-12 21:31:45 +0200 | [diff] [blame] | 3042 | |
| 3043 | alloc_error: |
| 3044 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 3045 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3046 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 3047 | } |