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