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