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