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