Amaury Denoyelle | fc6ac53 | 2021-04-27 10:46:36 +0200 | [diff] [blame] | 1 | #define _GNU_SOURCE /* for cpu_set_t from haproxy/cpuset.h */ |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 2 | #include <stdio.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <string.h> |
| 5 | #include <netdb.h> |
| 6 | #include <ctype.h> |
| 7 | #include <pwd.h> |
| 8 | #include <grp.h> |
| 9 | #include <errno.h> |
| 10 | #include <sys/types.h> |
| 11 | #include <sys/stat.h> |
| 12 | #include <fcntl.h> |
| 13 | #include <unistd.h> |
| 14 | |
Eric Salama | 7cea606 | 2020-10-02 11:58:19 +0200 | [diff] [blame] | 15 | #include <haproxy/buf.h> |
Willy Tarreau | 6be7849 | 2020-06-05 00:00:29 +0200 | [diff] [blame] | 16 | #include <haproxy/cfgparse.h> |
Amaury Denoyelle | a6f9c5d | 2021-04-23 16:58:08 +0200 | [diff] [blame] | 17 | #ifdef USE_CPU_AFFINITY |
Amaury Denoyelle | c90932b | 2021-04-14 16:16:03 +0200 | [diff] [blame] | 18 | #include <haproxy/cpuset.h> |
Amaury Denoyelle | a6f9c5d | 2021-04-23 16:58:08 +0200 | [diff] [blame] | 19 | #endif |
Willy Tarreau | 0a3bd39 | 2020-06-04 08:52:38 +0200 | [diff] [blame] | 20 | #include <haproxy/compression.h> |
Willy Tarreau | dfd3de8 | 2020-06-04 23:46:14 +0200 | [diff] [blame] | 21 | #include <haproxy/global.h> |
Willy Tarreau | 36979d9 | 2020-06-05 17:27:29 +0200 | [diff] [blame] | 22 | #include <haproxy/log.h> |
Dragan Dosen | 13cd54c | 2020-06-18 18:24:05 +0200 | [diff] [blame] | 23 | #include <haproxy/peers.h> |
Willy Tarreau | 36979d9 | 2020-06-05 17:27:29 +0200 | [diff] [blame] | 24 | #include <haproxy/tools.h> |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 25 | |
Willy Tarreau | a0e8eb8 | 2021-03-12 09:30:14 +0100 | [diff] [blame] | 26 | /* some keywords that are still being parsed using strcmp() and are not |
| 27 | * registered anywhere. They are used as suggestions for mistyped words. |
| 28 | */ |
| 29 | static const char *common_kw_list[] = { |
| 30 | "global", "daemon", "master-worker", "noepoll", "nokqueue", |
| 31 | "noevports", "nopoll", "busy-polling", "set-dumpable", |
| 32 | "insecure-fork-wanted", "insecure-setuid-wanted", "nosplice", |
| 33 | "nogetaddrinfo", "noreuseport", "quiet", "zero-warning", |
| 34 | "tune.runqueue-depth", "tune.maxpollevents", "tune.maxaccept", |
Willy Tarreau | eb9d90a | 2021-06-11 15:29:31 +0200 | [diff] [blame] | 35 | "tune.recv_enough", "tune.buffers.limit", |
Willy Tarreau | a0e8eb8 | 2021-03-12 09:30:14 +0100 | [diff] [blame] | 36 | "tune.buffers.reserve", "tune.bufsize", "tune.maxrewrite", |
| 37 | "tune.idletimer", "tune.rcvbuf.client", "tune.rcvbuf.server", |
| 38 | "tune.sndbuf.client", "tune.sndbuf.server", "tune.pipesize", |
| 39 | "tune.http.cookielen", "tune.http.logurilen", "tune.http.maxhdr", |
| 40 | "tune.comp.maxlevel", "tune.pattern.cache-size", "uid", "gid", |
| 41 | "external-check", "user", "group", "nbproc", "nbthread", "maxconn", |
| 42 | "ssl-server-verify", "maxconnrate", "maxsessrate", "maxsslrate", |
| 43 | "maxcomprate", "maxpipes", "maxzlibmem", "maxcompcpuusage", "ulimit-n", |
| 44 | "chroot", "description", "node", "pidfile", "unix-bind", "log", |
| 45 | "log-send-hostname", "server-state-base", "server-state-file", |
| 46 | "log-tag", "spread-checks", "max-spread-checks", "cpu-map", "setenv", |
| 47 | "presetenv", "unsetenv", "resetenv", "strict-limits", "localpeer", |
Amaury Denoyelle | 0f50cb9 | 2021-03-26 18:50:33 +0100 | [diff] [blame] | 48 | "numa-cpu-mapping", "defaults", "listen", "frontend", "backend", |
| 49 | "peers", "resolvers", |
Willy Tarreau | a0e8eb8 | 2021-03-12 09:30:14 +0100 | [diff] [blame] | 50 | NULL /* must be last */ |
| 51 | }; |
| 52 | |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 53 | /* |
| 54 | * parse a line in a <global> section. Returns the error code, 0 if OK, or |
| 55 | * any combination of : |
| 56 | * - ERR_ABORT: must abort ASAP |
| 57 | * - ERR_FATAL: we can continue parsing but not start the service |
| 58 | * - ERR_WARN: a warning has been emitted |
| 59 | * - ERR_ALERT: an alert has been emitted |
| 60 | * Only the two first ones can stop processing, the two others are just |
| 61 | * indicators. |
| 62 | */ |
| 63 | int cfg_parse_global(const char *file, int linenum, char **args, int kwm) |
| 64 | { |
| 65 | int err_code = 0; |
| 66 | char *errmsg = NULL; |
| 67 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 68 | if (strcmp(args[0], "global") == 0) { /* new section */ |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 69 | /* no option, nothing special to do */ |
| 70 | alertif_too_many_args(0, file, linenum, args, &err_code); |
| 71 | goto out; |
| 72 | } |
Amaury Denoyelle | d2e53cd | 2021-05-06 16:21:39 +0200 | [diff] [blame] | 73 | else if (strcmp(args[0], "expose-experimental-directives") == 0) { |
| 74 | experimental_directives_allowed = 1; |
| 75 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 76 | else if (strcmp(args[0], "daemon") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 77 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 78 | goto out; |
| 79 | global.mode |= MODE_DAEMON; |
| 80 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 81 | else if (strcmp(args[0], "master-worker") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 82 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 83 | goto out; |
| 84 | if (*args[1]) { |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 85 | if (strcmp(args[1], "no-exit-on-failure") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 86 | global.tune.options |= GTUNE_NOEXIT_ONFAILURE; |
| 87 | } else { |
| 88 | ha_alert("parsing [%s:%d] : '%s' only supports 'no-exit-on-failure' option.\n", file, linenum, args[0]); |
| 89 | err_code |= ERR_ALERT | ERR_FATAL; |
| 90 | goto out; |
| 91 | } |
| 92 | } |
| 93 | global.mode |= MODE_MWORKER; |
| 94 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 95 | else if (strcmp(args[0], "noepoll") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 96 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 97 | goto out; |
| 98 | global.tune.options &= ~GTUNE_USE_EPOLL; |
| 99 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 100 | else if (strcmp(args[0], "nokqueue") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 101 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 102 | goto out; |
| 103 | global.tune.options &= ~GTUNE_USE_KQUEUE; |
| 104 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 105 | else if (strcmp(args[0], "noevports") == 0) { |
Emmanuel Hocdet | 0ba4f48 | 2019-04-08 16:53:32 +0000 | [diff] [blame] | 106 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 107 | goto out; |
| 108 | global.tune.options &= ~GTUNE_USE_EVPORTS; |
| 109 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 110 | else if (strcmp(args[0], "nopoll") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 111 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 112 | goto out; |
| 113 | global.tune.options &= ~GTUNE_USE_POLL; |
| 114 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 115 | else if (strcmp(args[0], "busy-polling") == 0) { /* "no busy-polling" or "busy-polling" */ |
Willy Tarreau | beb859a | 2018-11-22 18:07:59 +0100 | [diff] [blame] | 116 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 117 | goto out; |
| 118 | if (kwm == KWM_NO) |
| 119 | global.tune.options &= ~GTUNE_BUSY_POLLING; |
| 120 | else |
| 121 | global.tune.options |= GTUNE_BUSY_POLLING; |
| 122 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 123 | else if (strcmp(args[0], "set-dumpable") == 0) { /* "no set-dumpable" or "set-dumpable" */ |
Willy Tarreau | 636848a | 2019-04-15 19:38:50 +0200 | [diff] [blame] | 124 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 125 | goto out; |
| 126 | if (kwm == KWM_NO) |
| 127 | global.tune.options &= ~GTUNE_SET_DUMPABLE; |
| 128 | else |
| 129 | global.tune.options |= GTUNE_SET_DUMPABLE; |
| 130 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 131 | else if (strcmp(args[0], "insecure-fork-wanted") == 0) { /* "no insecure-fork-wanted" or "insecure-fork-wanted" */ |
Willy Tarreau | d96f112 | 2019-12-03 07:07:36 +0100 | [diff] [blame] | 132 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 133 | goto out; |
| 134 | if (kwm == KWM_NO) |
| 135 | global.tune.options &= ~GTUNE_INSECURE_FORK; |
| 136 | else |
| 137 | global.tune.options |= GTUNE_INSECURE_FORK; |
| 138 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 139 | else if (strcmp(args[0], "insecure-setuid-wanted") == 0) { /* "no insecure-setuid-wanted" or "insecure-setuid-wanted" */ |
Willy Tarreau | a45a8b5 | 2019-12-06 16:31:45 +0100 | [diff] [blame] | 140 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 141 | goto out; |
| 142 | if (kwm == KWM_NO) |
| 143 | global.tune.options &= ~GTUNE_INSECURE_SETUID; |
| 144 | else |
| 145 | global.tune.options |= GTUNE_INSECURE_SETUID; |
| 146 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 147 | else if (strcmp(args[0], "nosplice") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 148 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 149 | goto out; |
| 150 | global.tune.options &= ~GTUNE_USE_SPLICE; |
| 151 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 152 | else if (strcmp(args[0], "nogetaddrinfo") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 153 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 154 | goto out; |
| 155 | global.tune.options &= ~GTUNE_USE_GAI; |
| 156 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 157 | else if (strcmp(args[0], "noreuseport") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 158 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 159 | goto out; |
| 160 | global.tune.options &= ~GTUNE_USE_REUSEPORT; |
| 161 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 162 | else if (strcmp(args[0], "quiet") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 163 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 164 | goto out; |
| 165 | global.mode |= MODE_QUIET; |
| 166 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 167 | else if (strcmp(args[0], "zero-warning") == 0) { |
Willy Tarreau | 3eb10b8 | 2020-04-15 16:42:39 +0200 | [diff] [blame] | 168 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 169 | goto out; |
| 170 | global.mode |= MODE_ZERO_WARNING; |
| 171 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 172 | else if (strcmp(args[0], "tune.runqueue-depth") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 173 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 174 | goto out; |
| 175 | if (global.tune.runqueue_depth != 0) { |
| 176 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 177 | err_code |= ERR_ALERT; |
| 178 | goto out; |
| 179 | } |
| 180 | if (*(args[1]) == 0) { |
| 181 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 182 | err_code |= ERR_ALERT | ERR_FATAL; |
| 183 | goto out; |
| 184 | } |
| 185 | global.tune.runqueue_depth = atol(args[1]); |
| 186 | |
| 187 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 188 | else if (strcmp(args[0], "tune.maxpollevents") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 189 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 190 | goto out; |
| 191 | if (global.tune.maxpollevents != 0) { |
| 192 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 193 | err_code |= ERR_ALERT; |
| 194 | goto out; |
| 195 | } |
| 196 | if (*(args[1]) == 0) { |
| 197 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 198 | err_code |= ERR_ALERT | ERR_FATAL; |
| 199 | goto out; |
| 200 | } |
| 201 | global.tune.maxpollevents = atol(args[1]); |
| 202 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 203 | else if (strcmp(args[0], "tune.maxaccept") == 0) { |
Christopher Faulet | 6b02ab8 | 2019-04-30 14:03:56 +0200 | [diff] [blame] | 204 | long max; |
| 205 | |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 206 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 207 | goto out; |
| 208 | if (global.tune.maxaccept != 0) { |
| 209 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 210 | err_code |= ERR_ALERT; |
| 211 | goto out; |
| 212 | } |
| 213 | if (*(args[1]) == 0) { |
| 214 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 215 | err_code |= ERR_ALERT | ERR_FATAL; |
| 216 | goto out; |
| 217 | } |
Christopher Faulet | 6b02ab8 | 2019-04-30 14:03:56 +0200 | [diff] [blame] | 218 | max = atol(args[1]); |
| 219 | if (/*max < -1 || */max > INT_MAX) { |
| 220 | ha_alert("parsing [%s:%d] : '%s' expects -1 or an integer from 0 to INT_MAX.\n", file, linenum, args[0]); |
| 221 | err_code |= ERR_ALERT | ERR_FATAL; |
| 222 | goto out; |
| 223 | } |
| 224 | global.tune.maxaccept = max; |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 225 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 226 | else if (strcmp(args[0], "tune.chksize") == 0) { |
Willy Tarreau | eb9d90a | 2021-06-11 15:29:31 +0200 | [diff] [blame] | 227 | ha_alert("parsing [%s:%d]: option '%s' is not supported any more (tune.bufsize is used instead).\n", file, linenum, args[0]); |
| 228 | err_code |= ERR_ALERT | ERR_FATAL; |
| 229 | goto out; |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 230 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 231 | else if (strcmp(args[0], "tune.recv_enough") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 232 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 233 | goto out; |
| 234 | if (*(args[1]) == 0) { |
| 235 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 236 | err_code |= ERR_ALERT | ERR_FATAL; |
| 237 | goto out; |
| 238 | } |
| 239 | global.tune.recv_enough = atol(args[1]); |
| 240 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 241 | else if (strcmp(args[0], "tune.buffers.limit") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 242 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 243 | goto out; |
| 244 | if (*(args[1]) == 0) { |
| 245 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 246 | err_code |= ERR_ALERT | ERR_FATAL; |
| 247 | goto out; |
| 248 | } |
| 249 | global.tune.buf_limit = atol(args[1]); |
| 250 | if (global.tune.buf_limit) { |
| 251 | if (global.tune.buf_limit < 3) |
| 252 | global.tune.buf_limit = 3; |
| 253 | if (global.tune.buf_limit <= global.tune.reserved_bufs) |
| 254 | global.tune.buf_limit = global.tune.reserved_bufs + 1; |
| 255 | } |
| 256 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 257 | else if (strcmp(args[0], "tune.buffers.reserve") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 258 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 259 | goto out; |
| 260 | if (*(args[1]) == 0) { |
| 261 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 262 | err_code |= ERR_ALERT | ERR_FATAL; |
| 263 | goto out; |
| 264 | } |
| 265 | global.tune.reserved_bufs = atol(args[1]); |
| 266 | if (global.tune.reserved_bufs < 2) |
| 267 | global.tune.reserved_bufs = 2; |
| 268 | if (global.tune.buf_limit && global.tune.buf_limit <= global.tune.reserved_bufs) |
| 269 | global.tune.buf_limit = global.tune.reserved_bufs + 1; |
| 270 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 271 | else if (strcmp(args[0], "tune.bufsize") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 272 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 273 | goto out; |
| 274 | if (*(args[1]) == 0) { |
| 275 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 276 | err_code |= ERR_ALERT | ERR_FATAL; |
| 277 | goto out; |
| 278 | } |
| 279 | global.tune.bufsize = atol(args[1]); |
Willy Tarreau | c77d364 | 2018-12-12 06:19:42 +0100 | [diff] [blame] | 280 | /* round it up to support a two-pointer alignment at the end */ |
| 281 | global.tune.bufsize = (global.tune.bufsize + 2 * sizeof(void *) - 1) & -(2 * sizeof(void *)); |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 282 | if (global.tune.bufsize <= 0) { |
| 283 | ha_alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]); |
| 284 | err_code |= ERR_ALERT | ERR_FATAL; |
| 285 | goto out; |
| 286 | } |
| 287 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 288 | else if (strcmp(args[0], "tune.maxrewrite") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 289 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 290 | goto out; |
| 291 | if (*(args[1]) == 0) { |
| 292 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 293 | err_code |= ERR_ALERT | ERR_FATAL; |
| 294 | goto out; |
| 295 | } |
| 296 | global.tune.maxrewrite = atol(args[1]); |
| 297 | if (global.tune.maxrewrite < 0) { |
| 298 | ha_alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]); |
| 299 | err_code |= ERR_ALERT | ERR_FATAL; |
| 300 | goto out; |
| 301 | } |
| 302 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 303 | else if (strcmp(args[0], "tune.idletimer") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 304 | unsigned int idle; |
| 305 | const char *res; |
| 306 | |
| 307 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 308 | goto out; |
| 309 | if (*(args[1]) == 0) { |
| 310 | ha_alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 311 | err_code |= ERR_ALERT | ERR_FATAL; |
| 312 | goto out; |
| 313 | } |
| 314 | |
| 315 | res = parse_time_err(args[1], &idle, TIME_UNIT_MS); |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 316 | if (res == PARSE_TIME_OVER) { |
| 317 | ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 65535 ms.\n", |
| 318 | file, linenum, args[1], args[0]); |
| 319 | err_code |= ERR_ALERT | ERR_FATAL; |
| 320 | goto out; |
| 321 | } |
| 322 | else if (res == PARSE_TIME_UNDER) { |
| 323 | ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n", |
| 324 | file, linenum, args[1], args[0]); |
| 325 | err_code |= ERR_ALERT | ERR_FATAL; |
| 326 | goto out; |
| 327 | } |
| 328 | else if (res) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 329 | ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 330 | file, linenum, *res, args[0]); |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 331 | err_code |= ERR_ALERT | ERR_FATAL; |
| 332 | goto out; |
| 333 | } |
| 334 | |
| 335 | if (idle > 65535) { |
| 336 | ha_alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 337 | err_code |= ERR_ALERT | ERR_FATAL; |
| 338 | goto out; |
| 339 | } |
| 340 | global.tune.idle_timer = idle; |
| 341 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 342 | else if (strcmp(args[0], "tune.rcvbuf.client") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 343 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 344 | goto out; |
| 345 | if (global.tune.client_rcvbuf != 0) { |
| 346 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 347 | err_code |= ERR_ALERT; |
| 348 | goto out; |
| 349 | } |
| 350 | if (*(args[1]) == 0) { |
| 351 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 352 | err_code |= ERR_ALERT | ERR_FATAL; |
| 353 | goto out; |
| 354 | } |
| 355 | global.tune.client_rcvbuf = atol(args[1]); |
| 356 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 357 | else if (strcmp(args[0], "tune.rcvbuf.server") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 358 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 359 | goto out; |
| 360 | if (global.tune.server_rcvbuf != 0) { |
| 361 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 362 | err_code |= ERR_ALERT; |
| 363 | goto out; |
| 364 | } |
| 365 | if (*(args[1]) == 0) { |
| 366 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 367 | err_code |= ERR_ALERT | ERR_FATAL; |
| 368 | goto out; |
| 369 | } |
| 370 | global.tune.server_rcvbuf = atol(args[1]); |
| 371 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 372 | else if (strcmp(args[0], "tune.sndbuf.client") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 373 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 374 | goto out; |
| 375 | if (global.tune.client_sndbuf != 0) { |
| 376 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 377 | err_code |= ERR_ALERT; |
| 378 | goto out; |
| 379 | } |
| 380 | if (*(args[1]) == 0) { |
| 381 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 382 | err_code |= ERR_ALERT | ERR_FATAL; |
| 383 | goto out; |
| 384 | } |
| 385 | global.tune.client_sndbuf = atol(args[1]); |
| 386 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 387 | else if (strcmp(args[0], "tune.sndbuf.server") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 388 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 389 | goto out; |
| 390 | if (global.tune.server_sndbuf != 0) { |
| 391 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 392 | err_code |= ERR_ALERT; |
| 393 | goto out; |
| 394 | } |
| 395 | if (*(args[1]) == 0) { |
| 396 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 397 | err_code |= ERR_ALERT | ERR_FATAL; |
| 398 | goto out; |
| 399 | } |
| 400 | global.tune.server_sndbuf = atol(args[1]); |
| 401 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 402 | else if (strcmp(args[0], "tune.pipesize") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 403 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 404 | goto out; |
| 405 | if (*(args[1]) == 0) { |
| 406 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 407 | err_code |= ERR_ALERT | ERR_FATAL; |
| 408 | goto out; |
| 409 | } |
| 410 | global.tune.pipesize = atol(args[1]); |
| 411 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 412 | else if (strcmp(args[0], "tune.http.cookielen") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 413 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 414 | goto out; |
| 415 | if (*(args[1]) == 0) { |
| 416 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 417 | err_code |= ERR_ALERT | ERR_FATAL; |
| 418 | goto out; |
| 419 | } |
| 420 | global.tune.cookie_len = atol(args[1]) + 1; |
| 421 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 422 | else if (strcmp(args[0], "tune.http.logurilen") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 423 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 424 | goto out; |
| 425 | if (*(args[1]) == 0) { |
| 426 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 427 | err_code |= ERR_ALERT | ERR_FATAL; |
| 428 | goto out; |
| 429 | } |
| 430 | global.tune.requri_len = atol(args[1]) + 1; |
| 431 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 432 | else if (strcmp(args[0], "tune.http.maxhdr") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 433 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 434 | goto out; |
| 435 | if (*(args[1]) == 0) { |
| 436 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 437 | err_code |= ERR_ALERT | ERR_FATAL; |
| 438 | goto out; |
| 439 | } |
| 440 | global.tune.max_http_hdr = atoi(args[1]); |
| 441 | if (global.tune.max_http_hdr < 1 || global.tune.max_http_hdr > 32767) { |
| 442 | ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 32767\n", |
| 443 | file, linenum, args[0]); |
| 444 | err_code |= ERR_ALERT | ERR_FATAL; |
| 445 | goto out; |
| 446 | } |
| 447 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 448 | else if (strcmp(args[0], "tune.comp.maxlevel") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 449 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 450 | goto out; |
| 451 | if (*args[1]) { |
| 452 | global.tune.comp_maxlevel = atoi(args[1]); |
| 453 | if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) { |
| 454 | ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 455 | file, linenum, args[0]); |
| 456 | err_code |= ERR_ALERT | ERR_FATAL; |
| 457 | goto out; |
| 458 | } |
| 459 | } else { |
| 460 | ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 461 | file, linenum, args[0]); |
| 462 | err_code |= ERR_ALERT | ERR_FATAL; |
| 463 | goto out; |
| 464 | } |
| 465 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 466 | else if (strcmp(args[0], "tune.pattern.cache-size") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 467 | if (*args[1]) { |
| 468 | global.tune.pattern_cache = atoi(args[1]); |
| 469 | if (global.tune.pattern_cache < 0) { |
| 470 | ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 471 | file, linenum, args[0]); |
| 472 | err_code |= ERR_ALERT | ERR_FATAL; |
| 473 | goto out; |
| 474 | } |
| 475 | } else { |
| 476 | ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 477 | file, linenum, args[0]); |
| 478 | err_code |= ERR_ALERT | ERR_FATAL; |
| 479 | goto out; |
| 480 | } |
| 481 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 482 | else if (strcmp(args[0], "uid") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 483 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 484 | goto out; |
| 485 | if (global.uid != 0) { |
| 486 | ha_alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
| 487 | err_code |= ERR_ALERT; |
| 488 | goto out; |
| 489 | } |
| 490 | if (*(args[1]) == 0) { |
| 491 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 492 | err_code |= ERR_ALERT | ERR_FATAL; |
| 493 | goto out; |
| 494 | } |
| 495 | if (strl2irc(args[1], strlen(args[1]), &global.uid) != 0) { |
| 496 | ha_warning("parsing [%s:%d] : uid: string '%s' is not a number.\n | You might want to use the 'user' parameter to use a system user name.\n", file, linenum, args[1]); |
| 497 | err_code |= ERR_WARN; |
| 498 | goto out; |
| 499 | } |
| 500 | |
| 501 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 502 | else if (strcmp(args[0], "gid") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 503 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 504 | goto out; |
| 505 | if (global.gid != 0) { |
| 506 | ha_alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
| 507 | err_code |= ERR_ALERT; |
| 508 | goto out; |
| 509 | } |
| 510 | if (*(args[1]) == 0) { |
| 511 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 512 | err_code |= ERR_ALERT | ERR_FATAL; |
| 513 | goto out; |
| 514 | } |
| 515 | if (strl2irc(args[1], strlen(args[1]), &global.gid) != 0) { |
| 516 | ha_warning("parsing [%s:%d] : gid: string '%s' is not a number.\n | You might want to use the 'group' parameter to use a system group name.\n", file, linenum, args[1]); |
| 517 | err_code |= ERR_WARN; |
| 518 | goto out; |
| 519 | } |
| 520 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 521 | else if (strcmp(args[0], "external-check") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 522 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 523 | goto out; |
| 524 | global.external_check = 1; |
| 525 | } |
| 526 | /* user/group name handling */ |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 527 | else if (strcmp(args[0], "user") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 528 | struct passwd *ha_user; |
| 529 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 530 | goto out; |
| 531 | if (global.uid != 0) { |
| 532 | ha_alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
| 533 | err_code |= ERR_ALERT; |
| 534 | goto out; |
| 535 | } |
| 536 | errno = 0; |
| 537 | ha_user = getpwnam(args[1]); |
| 538 | if (ha_user != NULL) { |
| 539 | global.uid = (int)ha_user->pw_uid; |
| 540 | } |
| 541 | else { |
| 542 | ha_alert("parsing [%s:%d] : cannot find user id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno)); |
| 543 | err_code |= ERR_ALERT | ERR_FATAL; |
| 544 | } |
| 545 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 546 | else if (strcmp(args[0], "group") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 547 | struct group *ha_group; |
| 548 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 549 | goto out; |
| 550 | if (global.gid != 0) { |
| 551 | ha_alert("parsing [%s:%d] : gid/group was already specified. Continuing.\n", file, linenum); |
| 552 | err_code |= ERR_ALERT; |
| 553 | goto out; |
| 554 | } |
| 555 | errno = 0; |
| 556 | ha_group = getgrnam(args[1]); |
| 557 | if (ha_group != NULL) { |
| 558 | global.gid = (int)ha_group->gr_gid; |
| 559 | } |
| 560 | else { |
| 561 | ha_alert("parsing [%s:%d] : cannot find group id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno)); |
| 562 | err_code |= ERR_ALERT | ERR_FATAL; |
| 563 | } |
| 564 | } |
| 565 | /* end of user/group name handling*/ |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 566 | else if (strcmp(args[0], "nbproc") == 0) { |
Willy Tarreau | b63dbb7 | 2021-06-11 16:50:29 +0200 | [diff] [blame] | 567 | ha_alert("parsing [%s:%d] : nbproc is not supported any more since HAProxy 2.5. Threads will automatically be used on multi-processor machines if available.\n", file, linenum); |
| 568 | err_code |= ERR_ALERT | ERR_FATAL; |
| 569 | goto out; |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 570 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 571 | else if (strcmp(args[0], "nbthread") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 572 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 573 | goto out; |
| 574 | if (*(args[1]) == 0) { |
| 575 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 576 | err_code |= ERR_ALERT | ERR_FATAL; |
| 577 | goto out; |
| 578 | } |
Amaury Denoyelle | c4d47d6 | 2021-03-29 10:41:15 +0200 | [diff] [blame] | 579 | |
| 580 | HA_DIAG_WARNING_COND(global.nbthread, |
| 581 | "parsing [%s:%d] : nbthread is already defined and will be overridden.\n", |
| 582 | file, linenum); |
| 583 | |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 584 | global.nbthread = parse_nbthread(args[1], &errmsg); |
| 585 | if (!global.nbthread) { |
| 586 | ha_alert("parsing [%s:%d] : '%s' %s.\n", |
| 587 | file, linenum, args[0], errmsg); |
| 588 | err_code |= ERR_ALERT | ERR_FATAL; |
| 589 | goto out; |
| 590 | } |
| 591 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 592 | else if (strcmp(args[0], "maxconn") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 593 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 594 | goto out; |
| 595 | if (global.maxconn != 0) { |
| 596 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 597 | err_code |= ERR_ALERT; |
| 598 | goto out; |
| 599 | } |
| 600 | if (*(args[1]) == 0) { |
| 601 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 602 | err_code |= ERR_ALERT | ERR_FATAL; |
| 603 | goto out; |
| 604 | } |
| 605 | global.maxconn = atol(args[1]); |
| 606 | #ifdef SYSTEM_MAXCONN |
Willy Tarreau | ca783d4 | 2019-03-13 10:03:07 +0100 | [diff] [blame] | 607 | if (global.maxconn > SYSTEM_MAXCONN && cfg_maxconn <= SYSTEM_MAXCONN) { |
| 608 | ha_alert("parsing [%s:%d] : maxconn value %d too high for this system.\nLimiting to %d. Please use '-n' to force the value.\n", file, linenum, global.maxconn, SYSTEM_MAXCONN); |
| 609 | global.maxconn = SYSTEM_MAXCONN; |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 610 | err_code |= ERR_ALERT; |
| 611 | } |
| 612 | #endif /* SYSTEM_MAXCONN */ |
| 613 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 614 | else if (strcmp(args[0], "ssl-server-verify") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 615 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 616 | goto out; |
| 617 | if (*(args[1]) == 0) { |
| 618 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 619 | err_code |= ERR_ALERT | ERR_FATAL; |
| 620 | goto out; |
| 621 | } |
| 622 | if (strcmp(args[1],"none") == 0) |
| 623 | global.ssl_server_verify = SSL_SERVER_VERIFY_NONE; |
| 624 | else if (strcmp(args[1],"required") == 0) |
| 625 | global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED; |
| 626 | else { |
| 627 | ha_alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]); |
| 628 | err_code |= ERR_ALERT | ERR_FATAL; |
| 629 | goto out; |
| 630 | } |
| 631 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 632 | else if (strcmp(args[0], "maxconnrate") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 633 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 634 | goto out; |
| 635 | if (global.cps_lim != 0) { |
| 636 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 637 | err_code |= ERR_ALERT; |
| 638 | goto out; |
| 639 | } |
| 640 | if (*(args[1]) == 0) { |
| 641 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 642 | err_code |= ERR_ALERT | ERR_FATAL; |
| 643 | goto out; |
| 644 | } |
| 645 | global.cps_lim = atol(args[1]); |
| 646 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 647 | else if (strcmp(args[0], "maxsessrate") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 648 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 649 | goto out; |
| 650 | if (global.sps_lim != 0) { |
| 651 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 652 | err_code |= ERR_ALERT; |
| 653 | goto out; |
| 654 | } |
| 655 | if (*(args[1]) == 0) { |
| 656 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 657 | err_code |= ERR_ALERT | ERR_FATAL; |
| 658 | goto out; |
| 659 | } |
| 660 | global.sps_lim = atol(args[1]); |
| 661 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 662 | else if (strcmp(args[0], "maxsslrate") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 663 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 664 | goto out; |
| 665 | if (global.ssl_lim != 0) { |
| 666 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 667 | err_code |= ERR_ALERT; |
| 668 | goto out; |
| 669 | } |
| 670 | if (*(args[1]) == 0) { |
| 671 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 672 | err_code |= ERR_ALERT | ERR_FATAL; |
| 673 | goto out; |
| 674 | } |
| 675 | global.ssl_lim = atol(args[1]); |
| 676 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 677 | else if (strcmp(args[0], "maxcomprate") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 678 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 679 | goto out; |
| 680 | if (*(args[1]) == 0) { |
| 681 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]); |
| 682 | err_code |= ERR_ALERT | ERR_FATAL; |
| 683 | goto out; |
| 684 | } |
| 685 | global.comp_rate_lim = atoi(args[1]) * 1024; |
| 686 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 687 | else if (strcmp(args[0], "maxpipes") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 688 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 689 | goto out; |
| 690 | if (global.maxpipes != 0) { |
| 691 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 692 | err_code |= ERR_ALERT; |
| 693 | goto out; |
| 694 | } |
| 695 | if (*(args[1]) == 0) { |
| 696 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 697 | err_code |= ERR_ALERT | ERR_FATAL; |
| 698 | goto out; |
| 699 | } |
| 700 | global.maxpipes = atol(args[1]); |
| 701 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 702 | else if (strcmp(args[0], "maxzlibmem") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 703 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 704 | goto out; |
| 705 | if (*(args[1]) == 0) { |
| 706 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 707 | err_code |= ERR_ALERT | ERR_FATAL; |
| 708 | goto out; |
| 709 | } |
| 710 | global.maxzlibmem = atol(args[1]) * 1024L * 1024L; |
| 711 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 712 | else if (strcmp(args[0], "maxcompcpuusage") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 713 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 714 | goto out; |
| 715 | if (*(args[1]) == 0) { |
| 716 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 717 | err_code |= ERR_ALERT | ERR_FATAL; |
| 718 | goto out; |
| 719 | } |
| 720 | compress_min_idle = 100 - atoi(args[1]); |
| 721 | if (compress_min_idle > 100) { |
| 722 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 723 | err_code |= ERR_ALERT | ERR_FATAL; |
| 724 | goto out; |
| 725 | } |
| 726 | } |
| 727 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 728 | else if (strcmp(args[0], "ulimit-n") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 729 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 730 | goto out; |
| 731 | if (global.rlimit_nofile != 0) { |
| 732 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 733 | err_code |= ERR_ALERT; |
| 734 | goto out; |
| 735 | } |
| 736 | if (*(args[1]) == 0) { |
| 737 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 738 | err_code |= ERR_ALERT | ERR_FATAL; |
| 739 | goto out; |
| 740 | } |
| 741 | global.rlimit_nofile = atol(args[1]); |
| 742 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 743 | else if (strcmp(args[0], "chroot") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 744 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 745 | goto out; |
| 746 | if (global.chroot != NULL) { |
| 747 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 748 | err_code |= ERR_ALERT; |
| 749 | goto out; |
| 750 | } |
| 751 | if (*(args[1]) == 0) { |
| 752 | ha_alert("parsing [%s:%d] : '%s' expects a directory as an argument.\n", file, linenum, args[0]); |
| 753 | err_code |= ERR_ALERT | ERR_FATAL; |
| 754 | goto out; |
| 755 | } |
| 756 | global.chroot = strdup(args[1]); |
| 757 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 758 | else if (strcmp(args[0], "description") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 759 | int i, len=0; |
| 760 | char *d; |
| 761 | |
| 762 | if (!*args[1]) { |
| 763 | ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 764 | file, linenum, args[0]); |
| 765 | err_code |= ERR_ALERT | ERR_FATAL; |
| 766 | goto out; |
| 767 | } |
| 768 | |
| 769 | for (i = 1; *args[i]; i++) |
| 770 | len += strlen(args[i]) + 1; |
| 771 | |
| 772 | if (global.desc) |
| 773 | free(global.desc); |
| 774 | |
| 775 | global.desc = d = calloc(1, len); |
| 776 | |
| 777 | d += snprintf(d, global.desc + len - d, "%s", args[1]); |
| 778 | for (i = 2; *args[i]; i++) |
| 779 | d += snprintf(d, global.desc + len - d, " %s", args[i]); |
| 780 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 781 | else if (strcmp(args[0], "node") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 782 | int i; |
| 783 | char c; |
| 784 | |
| 785 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 786 | goto out; |
| 787 | |
| 788 | for (i=0; args[1][i]; i++) { |
| 789 | c = args[1][i]; |
| 790 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 791 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
| 792 | break; |
| 793 | } |
| 794 | |
| 795 | if (!i || args[1][i]) { |
| 796 | ha_alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 797 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 798 | file, linenum, args[0]); |
| 799 | err_code |= ERR_ALERT | ERR_FATAL; |
| 800 | goto out; |
| 801 | } |
| 802 | |
| 803 | if (global.node) |
| 804 | free(global.node); |
| 805 | |
| 806 | global.node = strdup(args[1]); |
| 807 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 808 | else if (strcmp(args[0], "pidfile") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 809 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 810 | goto out; |
| 811 | if (global.pidfile != NULL) { |
| 812 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 813 | err_code |= ERR_ALERT; |
| 814 | goto out; |
| 815 | } |
| 816 | if (*(args[1]) == 0) { |
| 817 | ha_alert("parsing [%s:%d] : '%s' expects a file name as an argument.\n", file, linenum, args[0]); |
| 818 | err_code |= ERR_ALERT | ERR_FATAL; |
| 819 | goto out; |
| 820 | } |
| 821 | global.pidfile = strdup(args[1]); |
| 822 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 823 | else if (strcmp(args[0], "unix-bind") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 824 | int cur_arg = 1; |
| 825 | while (*(args[cur_arg])) { |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 826 | if (strcmp(args[cur_arg], "prefix") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 827 | if (global.unix_bind.prefix != NULL) { |
| 828 | ha_alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]); |
| 829 | err_code |= ERR_ALERT; |
| 830 | cur_arg += 2; |
| 831 | continue; |
| 832 | } |
| 833 | |
| 834 | if (*(args[cur_arg+1]) == 0) { |
| 835 | ha_alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]); |
| 836 | err_code |= ERR_ALERT | ERR_FATAL; |
| 837 | goto out; |
| 838 | } |
| 839 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 840 | cur_arg += 2; |
| 841 | continue; |
| 842 | } |
| 843 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 844 | if (strcmp(args[cur_arg], "mode") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 845 | |
| 846 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 847 | cur_arg += 2; |
| 848 | continue; |
| 849 | } |
| 850 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 851 | if (strcmp(args[cur_arg], "uid") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 852 | |
| 853 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 854 | cur_arg += 2; |
| 855 | continue; |
| 856 | } |
| 857 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 858 | if (strcmp(args[cur_arg], "gid") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 859 | |
| 860 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 861 | cur_arg += 2; |
| 862 | continue; |
| 863 | } |
| 864 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 865 | if (strcmp(args[cur_arg], "user") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 866 | struct passwd *user; |
| 867 | |
| 868 | user = getpwnam(args[cur_arg + 1]); |
| 869 | if (!user) { |
| 870 | ha_alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 871 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 872 | err_code |= ERR_ALERT | ERR_FATAL; |
| 873 | goto out; |
| 874 | } |
| 875 | |
| 876 | global.unix_bind.ux.uid = user->pw_uid; |
| 877 | cur_arg += 2; |
| 878 | continue; |
| 879 | } |
| 880 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 881 | if (strcmp(args[cur_arg], "group") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 882 | struct group *group; |
| 883 | |
| 884 | group = getgrnam(args[cur_arg + 1]); |
| 885 | if (!group) { |
| 886 | ha_alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 887 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 888 | err_code |= ERR_ALERT | ERR_FATAL; |
| 889 | goto out; |
| 890 | } |
| 891 | |
| 892 | global.unix_bind.ux.gid = group->gr_gid; |
| 893 | cur_arg += 2; |
| 894 | continue; |
| 895 | } |
| 896 | |
| 897 | ha_alert("parsing [%s:%d] : '%s' only supports the 'prefix', 'mode', 'uid', 'gid', 'user' and 'group' options.\n", |
| 898 | file, linenum, args[0]); |
| 899 | err_code |= ERR_ALERT | ERR_FATAL; |
| 900 | goto out; |
| 901 | } |
| 902 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 903 | else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */ |
Emeric Brun | 9533a70 | 2021-04-02 10:13:43 +0200 | [diff] [blame] | 904 | if (!parse_logsrv(args, &global.logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 905 | ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg); |
| 906 | err_code |= ERR_ALERT | ERR_FATAL; |
| 907 | goto out; |
| 908 | } |
| 909 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 910 | else if (strcmp(args[0], "log-send-hostname") == 0) { /* set the hostname in syslog header */ |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 911 | char *name; |
| 912 | |
| 913 | if (global.log_send_hostname != NULL) { |
| 914 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 915 | err_code |= ERR_ALERT; |
| 916 | goto out; |
| 917 | } |
| 918 | |
| 919 | if (*(args[1])) |
| 920 | name = args[1]; |
| 921 | else |
| 922 | name = hostname; |
| 923 | |
| 924 | free(global.log_send_hostname); |
| 925 | global.log_send_hostname = strdup(name); |
| 926 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 927 | else if (strcmp(args[0], "server-state-base") == 0) { /* path base where HAProxy can find server state files */ |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 928 | if (global.server_state_base != NULL) { |
| 929 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 930 | err_code |= ERR_ALERT; |
| 931 | goto out; |
| 932 | } |
| 933 | |
| 934 | if (!*(args[1])) { |
| 935 | ha_alert("parsing [%s:%d] : '%s' expects one argument: a directory path.\n", file, linenum, args[0]); |
| 936 | err_code |= ERR_FATAL; |
| 937 | goto out; |
| 938 | } |
| 939 | |
| 940 | global.server_state_base = strdup(args[1]); |
| 941 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 942 | else if (strcmp(args[0], "server-state-file") == 0) { /* path to the file where HAProxy can load the server states */ |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 943 | if (global.server_state_file != NULL) { |
| 944 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 945 | err_code |= ERR_ALERT; |
| 946 | goto out; |
| 947 | } |
| 948 | |
| 949 | if (!*(args[1])) { |
| 950 | ha_alert("parsing [%s:%d] : '%s' expect one argument: a file path.\n", file, linenum, args[0]); |
| 951 | err_code |= ERR_FATAL; |
| 952 | goto out; |
| 953 | } |
| 954 | |
| 955 | global.server_state_file = strdup(args[1]); |
| 956 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 957 | else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */ |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 958 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 959 | goto out; |
| 960 | if (*(args[1]) == 0) { |
| 961 | ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 962 | err_code |= ERR_ALERT | ERR_FATAL; |
| 963 | goto out; |
| 964 | } |
| 965 | chunk_destroy(&global.log_tag); |
Eric Salama | 7cea606 | 2020-10-02 11:58:19 +0200 | [diff] [blame] | 966 | chunk_initlen(&global.log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1])); |
| 967 | if (b_orig(&global.log_tag) == NULL) { |
| 968 | chunk_destroy(&global.log_tag); |
| 969 | ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]); |
| 970 | err_code |= ERR_ALERT | ERR_FATAL; |
| 971 | goto out; |
| 972 | } |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 973 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 974 | else if (strcmp(args[0], "spread-checks") == 0) { /* random time between checks (0-50) */ |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 975 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 976 | goto out; |
| 977 | if (global.spread_checks != 0) { |
| 978 | ha_alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
| 979 | err_code |= ERR_ALERT; |
| 980 | goto out; |
| 981 | } |
| 982 | if (*(args[1]) == 0) { |
| 983 | ha_alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]); |
| 984 | err_code |= ERR_ALERT | ERR_FATAL; |
| 985 | goto out; |
| 986 | } |
| 987 | global.spread_checks = atol(args[1]); |
| 988 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 989 | ha_alert("parsing [%s:%d]: 'spread-checks' needs a positive value in range 0..50.\n", file, linenum); |
| 990 | err_code |= ERR_ALERT | ERR_FATAL; |
| 991 | } |
| 992 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 993 | else if (strcmp(args[0], "max-spread-checks") == 0) { /* maximum time between first and last check */ |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 994 | const char *err; |
| 995 | unsigned int val; |
| 996 | |
| 997 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 998 | goto out; |
| 999 | if (*(args[1]) == 0) { |
| 1000 | ha_alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]); |
| 1001 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1002 | goto out; |
| 1003 | } |
| 1004 | |
| 1005 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 1006 | if (err == PARSE_TIME_OVER) { |
| 1007 | ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 ms (~24.8 days).\n", |
| 1008 | file, linenum, args[1], args[0]); |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1009 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1010 | } |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 1011 | else if (err == PARSE_TIME_UNDER) { |
| 1012 | ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n", |
| 1013 | file, linenum, args[1], args[0]); |
| 1014 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1015 | } |
| 1016 | else if (err) { |
| 1017 | ha_alert("parsing [%s:%d]: unsupported character '%c' in '%s' (wants an integer delay).\n", file, linenum, *err, args[0]); |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1018 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1019 | } |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 1020 | global.max_spread_checks = val; |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1021 | } |
| 1022 | else if (strcmp(args[0], "cpu-map") == 0) { |
| 1023 | /* map a process list to a CPU set */ |
| 1024 | #ifdef USE_CPU_AFFINITY |
| 1025 | char *slash; |
Amaury Denoyelle | 982fb53 | 2021-04-21 18:39:58 +0200 | [diff] [blame] | 1026 | unsigned long proc = 0, thread = 0; |
Willy Tarreau | bda7c1d | 2021-06-15 08:49:05 +0200 | [diff] [blame] | 1027 | int j, n, autoinc; |
Amaury Denoyelle | 982fb53 | 2021-04-21 18:39:58 +0200 | [diff] [blame] | 1028 | struct hap_cpuset cpus, cpus_copy; |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1029 | |
| 1030 | if (!*args[1] || !*args[2]) { |
| 1031 | ha_alert("parsing [%s:%d] : %s expects a process number " |
| 1032 | " ('all', 'odd', 'even', a number from 1 to %d or a range), " |
| 1033 | " followed by a list of CPU ranges with numbers from 0 to %d.\n", |
Willy Tarreau | 5799e9c | 2019-03-05 18:14:03 +0100 | [diff] [blame] | 1034 | file, linenum, args[0], LONGBITS, LONGBITS - 1); |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1035 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1036 | goto out; |
| 1037 | } |
| 1038 | |
| 1039 | if ((slash = strchr(args[1], '/')) != NULL) |
| 1040 | *slash = 0; |
| 1041 | |
Willy Tarreau | 5799e9c | 2019-03-05 18:14:03 +0100 | [diff] [blame] | 1042 | /* note: we silently ignore processes over MAX_PROCS and |
| 1043 | * threads over MAX_THREADS so as not to make configurations a |
| 1044 | * pain to maintain. |
| 1045 | */ |
| 1046 | if (parse_process_number(args[1], &proc, LONGBITS, &autoinc, &errmsg)) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1047 | ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg); |
| 1048 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1049 | goto out; |
| 1050 | } |
| 1051 | |
| 1052 | if (slash) { |
Willy Tarreau | 5799e9c | 2019-03-05 18:14:03 +0100 | [diff] [blame] | 1053 | if (parse_process_number(slash+1, &thread, LONGBITS, NULL, &errmsg)) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1054 | ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg); |
| 1055 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1056 | goto out; |
| 1057 | } |
| 1058 | *slash = '/'; |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1059 | } |
| 1060 | |
Amaury Denoyelle | a808235 | 2021-04-06 16:46:15 +0200 | [diff] [blame] | 1061 | if (parse_cpu_set((const char **)args+2, &cpus, 0, &errmsg)) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1062 | ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg); |
| 1063 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1064 | goto out; |
| 1065 | } |
Amaury Denoyelle | 982fb53 | 2021-04-21 18:39:58 +0200 | [diff] [blame] | 1066 | |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1067 | if (autoinc && |
Amaury Denoyelle | 982fb53 | 2021-04-21 18:39:58 +0200 | [diff] [blame] | 1068 | my_popcountl(proc) != ha_cpuset_count(&cpus) && |
| 1069 | my_popcountl(thread) != ha_cpuset_count(&cpus)) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1070 | ha_alert("parsing [%s:%d] : %s : PROC/THREAD range and CPU sets " |
| 1071 | "must have the same size to be automatically bound\n", |
| 1072 | file, linenum, args[0]); |
| 1073 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1074 | goto out; |
| 1075 | } |
| 1076 | |
Willy Tarreau | 7764a57 | 2019-07-16 15:10:34 +0200 | [diff] [blame] | 1077 | /* we now have to deal with 3 real cases : |
| 1078 | * cpu-map P-Q => mapping for whole processes, numbers P to Q |
| 1079 | * cpu-map P-Q/1 => mapping of first thread of processes P to Q |
| 1080 | * cpu-map 1/T-U => mapping of threads T to U of process 1 |
Willy Tarreau | bda7c1d | 2021-06-15 08:49:05 +0200 | [diff] [blame] | 1081 | * (note: P=Q=1 since 2.5). |
Willy Tarreau | 7764a57 | 2019-07-16 15:10:34 +0200 | [diff] [blame] | 1082 | * Otherwise other combinations are silently ignored since nbthread |
| 1083 | * and nbproc cannot both be >1 : |
| 1084 | * cpu-map P-Q/T => mapping for thread T for processes P to Q. |
| 1085 | * Only one of T,Q may be > 1, others ignored. |
| 1086 | * cpu-map P/T-U => mapping for threads T to U of process P. Only |
| 1087 | * one of P,U may be > 1, others ignored. |
| 1088 | */ |
Willy Tarreau | bda7c1d | 2021-06-15 08:49:05 +0200 | [diff] [blame] | 1089 | if (!thread || thread == 0x1) { |
| 1090 | /* mapping for whole process. E.g. cpu-map 1 0-3 or cpu-map 1/1 0-3 */ |
| 1091 | ha_cpuset_assign(&cpus_copy, &cpus); |
| 1092 | |
| 1093 | if (!autoinc) |
Willy Tarreau | 44ea631 | 2021-06-15 08:57:56 +0200 | [diff] [blame] | 1094 | ha_cpuset_assign(&cpu_map.proc, &cpus); |
Willy Tarreau | bda7c1d | 2021-06-15 08:49:05 +0200 | [diff] [blame] | 1095 | else { |
Willy Tarreau | 44ea631 | 2021-06-15 08:57:56 +0200 | [diff] [blame] | 1096 | ha_cpuset_zero(&cpu_map.proc); |
Willy Tarreau | bda7c1d | 2021-06-15 08:49:05 +0200 | [diff] [blame] | 1097 | n = ha_cpuset_ffs(&cpus_copy) - 1; |
| 1098 | ha_cpuset_clr(&cpus_copy, n); |
Willy Tarreau | 44ea631 | 2021-06-15 08:57:56 +0200 | [diff] [blame] | 1099 | ha_cpuset_set(&cpu_map.proc, n); |
Willy Tarreau | bda7c1d | 2021-06-15 08:49:05 +0200 | [diff] [blame] | 1100 | } |
| 1101 | } else { |
| 1102 | /* first process, iterate on threads. E.g. cpu-map 1/1-4 0-3 */ |
Amaury Denoyelle | 982fb53 | 2021-04-21 18:39:58 +0200 | [diff] [blame] | 1103 | ha_cpuset_assign(&cpus_copy, &cpus); |
Willy Tarreau | bda7c1d | 2021-06-15 08:49:05 +0200 | [diff] [blame] | 1104 | for (j = n = 0; j < MAX_THREADS; j++) { |
| 1105 | /* No mapping for this thread */ |
| 1106 | if (!(thread & (1UL << j))) |
Willy Tarreau | 81492c9 | 2019-05-03 09:41:23 +0200 | [diff] [blame] | 1107 | continue; |
| 1108 | |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1109 | if (!autoinc) |
Willy Tarreau | bda7c1d | 2021-06-15 08:49:05 +0200 | [diff] [blame] | 1110 | ha_cpuset_assign(&cpu_map.thread[j], &cpus); |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1111 | else { |
Willy Tarreau | bda7c1d | 2021-06-15 08:49:05 +0200 | [diff] [blame] | 1112 | ha_cpuset_zero(&cpu_map.thread[j]); |
Amaury Denoyelle | 982fb53 | 2021-04-21 18:39:58 +0200 | [diff] [blame] | 1113 | n = ha_cpuset_ffs(&cpus_copy) - 1; |
| 1114 | ha_cpuset_clr(&cpus_copy, n); |
Willy Tarreau | bda7c1d | 2021-06-15 08:49:05 +0200 | [diff] [blame] | 1115 | ha_cpuset_set(&cpu_map.thread[j], n); |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1116 | } |
| 1117 | } |
Amaury Denoyelle | a2944ec | 2021-04-15 18:07:07 +0200 | [diff] [blame] | 1118 | |
| 1119 | HA_DIAG_WARNING_COND(proc != 0x1 && thread != 0x1, |
| 1120 | "parsing [%s:%d] : cpu-map statement is considered invalid and thus ignored as it addresses multiple processes and threads at the same time. At least one of them should be 1 and only 1.", file, linenum); |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1121 | } |
| 1122 | #else |
| 1123 | ha_alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n", |
| 1124 | file, linenum, args[0]); |
| 1125 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1126 | goto out; |
| 1127 | #endif /* ! USE_CPU_AFFINITY */ |
| 1128 | } |
| 1129 | else if (strcmp(args[0], "setenv") == 0 || strcmp(args[0], "presetenv") == 0) { |
| 1130 | if (alertif_too_many_args(3, file, linenum, args, &err_code)) |
| 1131 | goto out; |
| 1132 | |
| 1133 | if (*(args[2]) == 0) { |
| 1134 | ha_alert("parsing [%s:%d]: '%s' expects a name and a value.\n", file, linenum, args[0]); |
| 1135 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1136 | goto out; |
| 1137 | } |
| 1138 | |
| 1139 | /* "setenv" overwrites, "presetenv" only sets if not yet set */ |
| 1140 | if (setenv(args[1], args[2], (args[0][0] == 's')) != 0) { |
| 1141 | ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[1], strerror(errno)); |
| 1142 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1143 | goto out; |
| 1144 | } |
| 1145 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1146 | else if (strcmp(args[0], "unsetenv") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1147 | int arg; |
| 1148 | |
| 1149 | if (*(args[1]) == 0) { |
| 1150 | ha_alert("parsing [%s:%d]: '%s' expects at least one variable name.\n", file, linenum, args[0]); |
| 1151 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1152 | goto out; |
| 1153 | } |
| 1154 | |
| 1155 | for (arg = 1; *args[arg]; arg++) { |
| 1156 | if (unsetenv(args[arg]) != 0) { |
| 1157 | ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[arg], strerror(errno)); |
| 1158 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1159 | goto out; |
| 1160 | } |
| 1161 | } |
| 1162 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1163 | else if (strcmp(args[0], "resetenv") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1164 | extern char **environ; |
| 1165 | char **env = environ; |
| 1166 | |
| 1167 | /* args contain variable names to keep, one per argument */ |
| 1168 | while (*env) { |
| 1169 | int arg; |
| 1170 | |
| 1171 | /* look for current variable in among all those we want to keep */ |
| 1172 | for (arg = 1; *args[arg]; arg++) { |
| 1173 | if (strncmp(*env, args[arg], strlen(args[arg])) == 0 && |
| 1174 | (*env)[strlen(args[arg])] == '=') |
| 1175 | break; |
| 1176 | } |
| 1177 | |
| 1178 | /* delete this variable */ |
| 1179 | if (!*args[arg]) { |
| 1180 | char *delim = strchr(*env, '='); |
| 1181 | |
| 1182 | if (!delim || delim - *env >= trash.size) { |
| 1183 | ha_alert("parsing [%s:%d]: '%s' failed to unset invalid variable '%s'.\n", file, linenum, args[0], *env); |
| 1184 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1185 | goto out; |
| 1186 | } |
| 1187 | |
| 1188 | memcpy(trash.area, *env, delim - *env); |
| 1189 | trash.area[delim - *env] = 0; |
| 1190 | |
| 1191 | if (unsetenv(trash.area) != 0) { |
| 1192 | ha_alert("parsing [%s:%d]: '%s' failed to unset variable '%s' : %s.\n", file, linenum, args[0], *env, strerror(errno)); |
| 1193 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1194 | goto out; |
| 1195 | } |
| 1196 | } |
| 1197 | else |
| 1198 | env++; |
| 1199 | } |
| 1200 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1201 | else if (strcmp(args[0], "strict-limits") == 0) { /* "no strict-limits" or "strict-limits" */ |
William Dauchy | 0fec3ab | 2019-10-27 20:08:11 +0100 | [diff] [blame] | 1202 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 1203 | goto out; |
| 1204 | if (kwm == KWM_NO) |
| 1205 | global.tune.options &= ~GTUNE_STRICT_LIMITS; |
William Dauchy | 0fec3ab | 2019-10-27 20:08:11 +0100 | [diff] [blame] | 1206 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1207 | else if (strcmp(args[0], "localpeer") == 0) { |
Dragan Dosen | 13cd54c | 2020-06-18 18:24:05 +0200 | [diff] [blame] | 1208 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1209 | goto out; |
| 1210 | |
| 1211 | if (*(args[1]) == 0) { |
| 1212 | ha_alert("parsing [%s:%d] : '%s' expects a name as an argument.\n", |
| 1213 | file, linenum, args[0]); |
| 1214 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1215 | goto out; |
| 1216 | } |
| 1217 | |
| 1218 | if (global.localpeer_cmdline != 0) { |
| 1219 | ha_warning("parsing [%s:%d] : '%s' ignored since it is already set by using the '-L' " |
| 1220 | "command line argument.\n", file, linenum, args[0]); |
| 1221 | err_code |= ERR_WARN; |
| 1222 | goto out; |
| 1223 | } |
| 1224 | |
| 1225 | if (cfg_peers) { |
| 1226 | ha_warning("parsing [%s:%d] : '%s' ignored since it is used after 'peers' section.\n", |
| 1227 | file, linenum, args[0]); |
| 1228 | err_code |= ERR_WARN; |
| 1229 | goto out; |
| 1230 | } |
| 1231 | |
| 1232 | free(localpeer); |
| 1233 | if ((localpeer = strdup(args[1])) == NULL) { |
| 1234 | ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", |
| 1235 | file, linenum, args[0]); |
| 1236 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1237 | goto out; |
| 1238 | } |
| 1239 | setenv("HAPROXY_LOCALPEER", localpeer, 1); |
| 1240 | } |
Amaury Denoyelle | 0f50cb9 | 2021-03-26 18:50:33 +0100 | [diff] [blame] | 1241 | else if (strcmp(args[0], "numa-cpu-mapping") == 0) { |
| 1242 | global.numa_cpu_mapping = (kwm == KWM_NO) ? 0 : 1; |
| 1243 | } |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1244 | else { |
| 1245 | struct cfg_kw_list *kwl; |
Willy Tarreau | a0e8eb8 | 2021-03-12 09:30:14 +0100 | [diff] [blame] | 1246 | const char *best; |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1247 | int index; |
| 1248 | int rc; |
| 1249 | |
| 1250 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1251 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1252 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1253 | continue; |
| 1254 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
Amaury Denoyelle | d2e53cd | 2021-05-06 16:21:39 +0200 | [diff] [blame] | 1255 | if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) { |
Amaury Denoyelle | 86c1d0f | 2021-05-07 15:07:21 +0200 | [diff] [blame] | 1256 | ha_alert("%s\n", errmsg); |
Amaury Denoyelle | d2e53cd | 2021-05-06 16:21:39 +0200 | [diff] [blame] | 1257 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1258 | goto out; |
| 1259 | } |
| 1260 | |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1261 | rc = kwl->kw[index].parse(args, CFG_GLOBAL, NULL, NULL, file, linenum, &errmsg); |
| 1262 | if (rc < 0) { |
| 1263 | ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
| 1264 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1265 | } |
| 1266 | else if (rc > 0) { |
| 1267 | ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
| 1268 | err_code |= ERR_WARN; |
| 1269 | goto out; |
| 1270 | } |
| 1271 | goto out; |
| 1272 | } |
| 1273 | } |
| 1274 | } |
| 1275 | |
Willy Tarreau | 101df31 | 2021-03-15 09:12:41 +0100 | [diff] [blame] | 1276 | best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_GLOBAL, common_kw_list); |
Willy Tarreau | a0e8eb8 | 2021-03-12 09:30:14 +0100 | [diff] [blame] | 1277 | if (best) |
| 1278 | ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best); |
| 1279 | else |
| 1280 | ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "global"); |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1281 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1282 | } |
| 1283 | |
| 1284 | out: |
| 1285 | free(errmsg); |
| 1286 | return err_code; |
| 1287 | } |
| 1288 | |