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