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