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