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