blob: 565a108be8043b84b5ef747eba4a159b13470a55 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
2 * Server management functions.
3 *
Willy Tarreau21faa912012-10-10 08:27:36 +02004 * Copyright 2000-2012 Willy Tarreau <w@1wt.eu>
Krzysztof Piotr Oledzki5259dfe2008-01-21 01:54:06 +01005 * Copyright 2007-2008 Krzysztof Piotr Oledzki <ole@ans.pl>
Willy Tarreaubaaee002006-06-26 02:48:02 +02006 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 *
12 */
13
Willy Tarreau272adea2014-03-31 10:39:59 +020014#include <ctype.h>
15
16#include <common/cfgparse.h>
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020017#include <common/config.h>
Willy Tarreaudff55432012-10-10 17:51:05 +020018#include <common/errors.h>
Krzysztof Oledzki85130942007-10-22 16:21:10 +020019#include <common/time.h>
20
Willy Tarreau272adea2014-03-31 10:39:59 +020021#include <types/global.h>
22
23#include <proto/port_range.h>
24#include <proto/protocol.h>
25#include <proto/raw_sock.h>
Willy Tarreauec6c5df2008-07-15 00:22:45 +020026#include <proto/server.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020027
Willy Tarreau21faa912012-10-10 08:27:36 +020028/* List head of all known server keywords */
29static struct srv_kw_list srv_keywords = {
30 .list = LIST_HEAD_INIT(srv_keywords.list)
31};
Krzysztof Oledzki85130942007-10-22 16:21:10 +020032
Simon Hormana3608442013-11-01 16:46:15 +090033int srv_downtime(const struct server *s)
Willy Tarreau21faa912012-10-10 08:27:36 +020034{
Krzysztof Oledzki85130942007-10-22 16:21:10 +020035 if ((s->state & SRV_RUNNING) && s->last_change < now.tv_sec) // ignore negative time
36 return s->down_time;
37
38 return now.tv_sec - s->last_change + s->down_time;
39}
Willy Tarreaubaaee002006-06-26 02:48:02 +020040
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -050041int srv_lastsession(const struct server *s)
42{
43 if (s->counters.last_sess)
44 return now.tv_sec - s->counters.last_sess;
45
46 return -1;
47}
48
Simon Horman4a741432013-02-23 15:35:38 +090049int srv_getinter(const struct check *check)
Willy Tarreau21faa912012-10-10 08:27:36 +020050{
Simon Horman4a741432013-02-23 15:35:38 +090051 const struct server *s = check->server;
52
Willy Tarreauff5ae352013-12-11 20:36:34 +010053 if ((check->state & CHK_ST_CONFIGURED) && (check->health == check->rise + check->fall - 1))
Simon Horman4a741432013-02-23 15:35:38 +090054 return check->inter;
Krzysztof Piotr Oledzki5259dfe2008-01-21 01:54:06 +010055
Simon Horman125d0992013-02-24 17:23:38 +090056 if (!(s->state & SRV_RUNNING) && check->health == 0)
Simon Horman4a741432013-02-23 15:35:38 +090057 return (check->downinter)?(check->downinter):(check->inter);
Krzysztof Piotr Oledzki5259dfe2008-01-21 01:54:06 +010058
Simon Horman4a741432013-02-23 15:35:38 +090059 return (check->fastinter)?(check->fastinter):(check->inter);
Krzysztof Piotr Oledzki5259dfe2008-01-21 01:54:06 +010060}
61
Willy Tarreau21faa912012-10-10 08:27:36 +020062/*
63 * Registers the server keyword list <kwl> as a list of valid keywords for next
64 * parsing sessions.
65 */
66void srv_register_keywords(struct srv_kw_list *kwl)
67{
68 LIST_ADDQ(&srv_keywords.list, &kwl->list);
69}
70
71/* Return a pointer to the server keyword <kw>, or NULL if not found. If the
72 * keyword is found with a NULL ->parse() function, then an attempt is made to
73 * find one with a valid ->parse() function. This way it is possible to declare
74 * platform-dependant, known keywords as NULL, then only declare them as valid
75 * if some options are met. Note that if the requested keyword contains an
76 * opening parenthesis, everything from this point is ignored.
77 */
78struct srv_kw *srv_find_kw(const char *kw)
79{
80 int index;
81 const char *kwend;
82 struct srv_kw_list *kwl;
83 struct srv_kw *ret = NULL;
84
85 kwend = strchr(kw, '(');
86 if (!kwend)
87 kwend = kw + strlen(kw);
88
89 list_for_each_entry(kwl, &srv_keywords.list, list) {
90 for (index = 0; kwl->kw[index].kw != NULL; index++) {
91 if ((strncmp(kwl->kw[index].kw, kw, kwend - kw) == 0) &&
92 kwl->kw[index].kw[kwend-kw] == 0) {
93 if (kwl->kw[index].parse)
94 return &kwl->kw[index]; /* found it !*/
95 else
96 ret = &kwl->kw[index]; /* may be OK */
97 }
98 }
99 }
100 return ret;
101}
102
103/* Dumps all registered "server" keywords to the <out> string pointer. The
104 * unsupported keywords are only dumped if their supported form was not
105 * found.
106 */
107void srv_dump_kws(char **out)
108{
109 struct srv_kw_list *kwl;
110 int index;
111
112 *out = NULL;
113 list_for_each_entry(kwl, &srv_keywords.list, list) {
114 for (index = 0; kwl->kw[index].kw != NULL; index++) {
115 if (kwl->kw[index].parse ||
116 srv_find_kw(kwl->kw[index].kw) == &kwl->kw[index]) {
117 memprintf(out, "%s[%4s] %s%s%s%s\n", *out ? *out : "",
118 kwl->scope,
119 kwl->kw[index].kw,
120 kwl->kw[index].skip ? " <arg>" : "",
121 kwl->kw[index].default_ok ? " [dflt_ok]" : "",
122 kwl->kw[index].parse ? "" : " (not supported)");
123 }
124 }
125 }
126}
Krzysztof Piotr Oledzki5259dfe2008-01-21 01:54:06 +0100127
Willy Tarreaudff55432012-10-10 17:51:05 +0200128/* parse the "id" server keyword */
129static int srv_parse_id(char **args, int *cur_arg, struct proxy *curproxy, struct server *newsrv, char **err)
130{
131 struct eb32_node *node;
132
133 if (!*args[*cur_arg + 1]) {
134 memprintf(err, "'%s' : expects an integer argument", args[*cur_arg]);
135 return ERR_ALERT | ERR_FATAL;
136 }
137
138 newsrv->puid = atol(args[*cur_arg + 1]);
139 newsrv->conf.id.key = newsrv->puid;
140
141 if (newsrv->puid <= 0) {
142 memprintf(err, "'%s' : custom id has to be > 0", args[*cur_arg]);
143 return ERR_ALERT | ERR_FATAL;
144 }
145
146 node = eb32_lookup(&curproxy->conf.used_server_id, newsrv->puid);
147 if (node) {
148 struct server *target = container_of(node, struct server, conf.id);
149 memprintf(err, "'%s' : custom id %d already used at %s:%d ('server %s')",
150 args[*cur_arg], newsrv->puid, target->conf.file, target->conf.line,
151 target->id);
152 return ERR_ALERT | ERR_FATAL;
153 }
154
155 eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id);
156 return 0;
157}
158
159/* Note: must not be declared <const> as its list will be overwritten.
160 * Please take care of keeping this list alphabetically sorted, doing so helps
161 * all code contributors.
162 * Optional keywords are also declared with a NULL ->parse() function so that
163 * the config parser can report an appropriate error when a known keyword was
164 * not enabled.
165 */
166static struct srv_kw_list srv_kws = { "ALL", { }, {
167 { "id", srv_parse_id, 1, 0 }, /* set id# of server */
168 { NULL, NULL, 0 },
169}};
170
171__attribute__((constructor))
172static void __listener_init(void)
173{
174 srv_register_keywords(&srv_kws);
175}
176
Willy Tarreau004e0452013-11-21 11:22:01 +0100177/* Recomputes the server's eweight based on its state, uweight, the current time,
178 * and the proxy's algorihtm. To be used after updating sv->uweight. The warmup
179 * state is automatically disabled if the time is elapsed.
180 */
181void server_recalc_eweight(struct server *sv)
182{
183 struct proxy *px = sv->proxy;
184 unsigned w;
185
186 if (now.tv_sec < sv->last_change || now.tv_sec >= sv->last_change + sv->slowstart) {
187 /* go to full throttle if the slowstart interval is reached */
188 sv->state &= ~SRV_WARMINGUP;
189 }
190
191 /* We must take care of not pushing the server to full throttle during slow starts.
192 * It must also start immediately, at least at the minimal step when leaving maintenance.
193 */
194 if ((sv->state & SRV_WARMINGUP) && (px->lbprm.algo & BE_LB_PROP_DYN))
195 w = (px->lbprm.wdiv * (now.tv_sec - sv->last_change) + sv->slowstart) / sv->slowstart;
196 else
197 w = px->lbprm.wdiv;
198
199 sv->eweight = (sv->uweight * w + px->lbprm.wmult - 1) / px->lbprm.wmult;
200
201 /* now propagate the status change to any LB algorithms */
202 if (px->lbprm.update_server_eweight)
203 px->lbprm.update_server_eweight(sv);
204 else if (sv->eweight) {
205 if (px->lbprm.set_server_status_up)
206 px->lbprm.set_server_status_up(sv);
207 }
208 else {
209 if (px->lbprm.set_server_status_down)
210 px->lbprm.set_server_status_down(sv);
211 }
212}
213
Willy Tarreaubaaee002006-06-26 02:48:02 +0200214/*
Simon Horman7d09b9a2013-02-12 10:45:51 +0900215 * Parses weight_str and configures sv accordingly.
216 * Returns NULL on success, error message string otherwise.
217 */
218const char *server_parse_weight_change_request(struct server *sv,
219 const char *weight_str)
220{
221 struct proxy *px;
Simon Hormanb796afa2013-02-12 10:45:53 +0900222 long int w;
223 char *end;
Simon Horman7d09b9a2013-02-12 10:45:51 +0900224
225 px = sv->proxy;
226
227 /* if the weight is terminated with '%', it is set relative to
228 * the initial weight, otherwise it is absolute.
229 */
230 if (!*weight_str)
231 return "Require <weight> or <weight%>.\n";
232
Simon Hormanb796afa2013-02-12 10:45:53 +0900233 w = strtol(weight_str, &end, 10);
234 if (end == weight_str)
235 return "Empty weight string empty or preceded by garbage";
236 else if (end[0] == '%' && end[1] == '\0') {
Simon Horman58b5d292013-02-12 10:45:52 +0900237 if (w < 0)
Simon Horman7d09b9a2013-02-12 10:45:51 +0900238 return "Relative weight must be positive.\n";
Simon Horman58b5d292013-02-12 10:45:52 +0900239 /* Avoid integer overflow */
240 if (w > 25600)
241 w = 25600;
Simon Horman7d09b9a2013-02-12 10:45:51 +0900242 w = sv->iweight * w / 100;
Simon Horman58b5d292013-02-12 10:45:52 +0900243 if (w > 256)
244 w = 256;
Simon Horman7d09b9a2013-02-12 10:45:51 +0900245 }
246 else if (w < 0 || w > 256)
247 return "Absolute weight can only be between 0 and 256 inclusive.\n";
Simon Hormanb796afa2013-02-12 10:45:53 +0900248 else if (end[0] != '\0')
249 return "Trailing garbage in weight string";
Simon Horman7d09b9a2013-02-12 10:45:51 +0900250
251 if (w && w != sv->iweight && !(px->lbprm.algo & BE_LB_PROP_DYN))
252 return "Backend is using a static LB algorithm and only accepts weights '0%' and '100%'.\n";
253
254 sv->uweight = w;
Willy Tarreau004e0452013-11-21 11:22:01 +0100255 server_recalc_eweight(sv);
Simon Horman7d09b9a2013-02-12 10:45:51 +0900256
257 return NULL;
258}
259
Willy Tarreau272adea2014-03-31 10:39:59 +0200260static int init_check(struct check *check, int type, const char * file, int linenum)
261{
262 check->type = type;
263
264 /* Allocate buffer for requests... */
265 if ((check->bi = calloc(sizeof(struct buffer) + global.tune.chksize, sizeof(char))) == NULL) {
266 Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum);
267 return ERR_ALERT | ERR_ABORT;
268 }
269 check->bi->size = global.tune.chksize;
270
271 /* Allocate buffer for responses... */
272 if ((check->bo = calloc(sizeof(struct buffer) + global.tune.chksize, sizeof(char))) == NULL) {
273 Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum);
274 return ERR_ALERT | ERR_ABORT;
275 }
276 check->bo->size = global.tune.chksize;
277
278 /* Allocate buffer for partial results... */
279 if ((check->conn = calloc(1, sizeof(struct connection))) == NULL) {
280 Alert("parsing [%s:%d] : out of memory while allocating check connection.\n", file, linenum);
281 return ERR_ALERT | ERR_ABORT;
282 }
283
284 check->conn->t.sock.fd = -1; /* no agent in progress yet */
285
286 return 0;
287}
288
289int parse_server(const char *file, int linenum, char **args, struct proxy *curproxy, struct proxy *defproxy)
290{
291 struct server *newsrv = NULL;
292 const char *err;
293 char *errmsg = NULL;
294 int err_code = 0;
295 unsigned val;
296
297 if (!strcmp(args[0], "server") || !strcmp(args[0], "default-server")) { /* server address */
298 int cur_arg;
299 short realport = 0;
300 int do_agent = 0, do_check = 0, defsrv = (*args[0] == 'd');
301
302 if (!defsrv && curproxy == defproxy) {
303 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
304 err_code |= ERR_ALERT | ERR_FATAL;
305 goto out;
306 }
307 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
308 err_code |= ERR_ALERT | ERR_FATAL;
309
310 if (!*args[2]) {
311 Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n",
312 file, linenum, args[0]);
313 err_code |= ERR_ALERT | ERR_FATAL;
314 goto out;
315 }
316
317 err = invalid_char(args[1]);
318 if (err && !defsrv) {
319 Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n",
320 file, linenum, *err, args[1]);
321 err_code |= ERR_ALERT | ERR_FATAL;
322 goto out;
323 }
324
325 if (!defsrv) {
326 struct sockaddr_storage *sk;
327 int port1, port2;
328 struct protocol *proto;
329
330 if ((newsrv = (struct server *)calloc(1, sizeof(struct server))) == NULL) {
331 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
332 err_code |= ERR_ALERT | ERR_ABORT;
333 goto out;
334 }
335
336 /* the servers are linked backwards first */
337 newsrv->next = curproxy->srv;
338 curproxy->srv = newsrv;
339 newsrv->proxy = curproxy;
340 newsrv->conf.file = strdup(file);
341 newsrv->conf.line = linenum;
342
343 newsrv->obj_type = OBJ_TYPE_SERVER;
344 LIST_INIT(&newsrv->actconns);
345 LIST_INIT(&newsrv->pendconns);
346 do_check = 0;
347 do_agent = 0;
348 newsrv->state = SRV_RUNNING; /* early server setup */
349 newsrv->last_change = now.tv_sec;
350 newsrv->id = strdup(args[1]);
351
352 /* several ways to check the port component :
353 * - IP => port=+0, relative (IPv4 only)
354 * - IP: => port=+0, relative
355 * - IP:N => port=N, absolute
356 * - IP:+N => port=+N, relative
357 * - IP:-N => port=-N, relative
358 */
359 sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL);
360 if (!sk) {
361 Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
362 err_code |= ERR_ALERT | ERR_FATAL;
363 goto out;
364 }
365
366 proto = protocol_by_family(sk->ss_family);
367 if (!proto || !proto->connect) {
368 Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
369 file, linenum, args[0], args[1]);
370 err_code |= ERR_ALERT | ERR_FATAL;
371 goto out;
372 }
373
374 if (!port1 || !port2) {
375 /* no port specified, +offset, -offset */
376 newsrv->state |= SRV_MAPPORTS;
377 }
378 else if (port1 != port2) {
379 /* port range */
380 Alert("parsing [%s:%d] : '%s %s' : port ranges are not allowed in '%s'\n",
381 file, linenum, args[0], args[1], args[2]);
382 err_code |= ERR_ALERT | ERR_FATAL;
383 goto out;
384 }
385 else {
386 /* used by checks */
387 realport = port1;
388 }
389
390 newsrv->addr = *sk;
391 newsrv->proto = newsrv->check_common.proto = protocol_by_family(newsrv->addr.ss_family);
392 newsrv->xprt = newsrv->check_common.xprt = &raw_sock;
393
394 if (!newsrv->proto) {
395 Alert("parsing [%s:%d] : Unknown protocol family %d '%s'\n",
396 file, linenum, newsrv->addr.ss_family, args[2]);
397 err_code |= ERR_ALERT | ERR_FATAL;
398 goto out;
399 }
400
401 newsrv->check.use_ssl = curproxy->defsrv.check.use_ssl;
402 newsrv->check.port = curproxy->defsrv.check.port;
403 newsrv->check.inter = curproxy->defsrv.check.inter;
404 newsrv->check.fastinter = curproxy->defsrv.check.fastinter;
405 newsrv->check.downinter = curproxy->defsrv.check.downinter;
406 newsrv->agent.use_ssl = curproxy->defsrv.agent.use_ssl;
407 newsrv->agent.port = curproxy->defsrv.agent.port;
408 newsrv->agent.inter = curproxy->defsrv.agent.inter;
409 newsrv->agent.fastinter = curproxy->defsrv.agent.fastinter;
410 newsrv->agent.downinter = curproxy->defsrv.agent.downinter;
411 newsrv->maxqueue = curproxy->defsrv.maxqueue;
412 newsrv->minconn = curproxy->defsrv.minconn;
413 newsrv->maxconn = curproxy->defsrv.maxconn;
414 newsrv->slowstart = curproxy->defsrv.slowstart;
415 newsrv->onerror = curproxy->defsrv.onerror;
416 newsrv->onmarkeddown = curproxy->defsrv.onmarkeddown;
417 newsrv->onmarkedup = curproxy->defsrv.onmarkedup;
418 newsrv->consecutive_errors_limit
419 = curproxy->defsrv.consecutive_errors_limit;
420#ifdef OPENSSL
421 newsrv->use_ssl = curproxy->defsrv.use_ssl;
422#endif
423 newsrv->uweight = newsrv->iweight
424 = curproxy->defsrv.iweight;
425
426 newsrv->check.status = HCHK_STATUS_INI;
427 newsrv->check.rise = curproxy->defsrv.check.rise;
428 newsrv->check.fall = curproxy->defsrv.check.fall;
429 newsrv->check.health = newsrv->check.rise; /* up, but will fall down at first failure */
430 newsrv->check.server = newsrv;
431
432 newsrv->agent.status = HCHK_STATUS_INI;
433 newsrv->agent.rise = curproxy->defsrv.agent.rise;
434 newsrv->agent.fall = curproxy->defsrv.agent.fall;
435 newsrv->agent.health = newsrv->agent.rise; /* up, but will fall down at first failure */
436 newsrv->agent.server = newsrv;
437
438 cur_arg = 3;
439 } else {
440 newsrv = &curproxy->defsrv;
441 cur_arg = 1;
442 }
443
444 while (*args[cur_arg]) {
445 if (!strcmp(args[cur_arg], "agent-check")) {
446 global.maxsock++;
447 do_agent = 1;
448 cur_arg += 1;
449 } else if (!strcmp(args[cur_arg], "agent-inter")) {
450 const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS);
451 if (err) {
452 Alert("parsing [%s:%d] : unexpected character '%c' in 'agent-inter' argument of server %s.\n",
453 file, linenum, *err, newsrv->id);
454 err_code |= ERR_ALERT | ERR_FATAL;
455 goto out;
456 }
457 if (val <= 0) {
458 Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n",
459 file, linenum, val, args[cur_arg], newsrv->id);
460 err_code |= ERR_ALERT | ERR_FATAL;
461 goto out;
462 }
463 newsrv->agent.inter = val;
464 cur_arg += 2;
465 }
466 else if (!strcmp(args[cur_arg], "agent-port")) {
467 global.maxsock++;
468 newsrv->agent.port = atol(args[cur_arg + 1]);
469 cur_arg += 2;
470 }
471 else if (!defsrv && !strcmp(args[cur_arg], "cookie")) {
472 newsrv->cookie = strdup(args[cur_arg + 1]);
473 newsrv->cklen = strlen(args[cur_arg + 1]);
474 cur_arg += 2;
475 }
476 else if (!defsrv && !strcmp(args[cur_arg], "redir")) {
477 newsrv->rdr_pfx = strdup(args[cur_arg + 1]);
478 newsrv->rdr_len = strlen(args[cur_arg + 1]);
479 cur_arg += 2;
480 }
481 else if (!strcmp(args[cur_arg], "rise")) {
482 if (!*args[cur_arg + 1]) {
483 Alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
484 file, linenum, args[cur_arg]);
485 err_code |= ERR_ALERT | ERR_FATAL;
486 goto out;
487 }
488
489 newsrv->check.rise = atol(args[cur_arg + 1]);
490 if (newsrv->check.rise <= 0) {
491 Alert("parsing [%s:%d]: '%s' has to be > 0.\n",
492 file, linenum, args[cur_arg]);
493 err_code |= ERR_ALERT | ERR_FATAL;
494 goto out;
495 }
496
497 if (newsrv->check.health)
498 newsrv->check.health = newsrv->check.rise;
499 cur_arg += 2;
500 }
501 else if (!strcmp(args[cur_arg], "fall")) {
502 newsrv->check.fall = atol(args[cur_arg + 1]);
503
504 if (!*args[cur_arg + 1]) {
505 Alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
506 file, linenum, args[cur_arg]);
507 err_code |= ERR_ALERT | ERR_FATAL;
508 goto out;
509 }
510
511 if (newsrv->check.fall <= 0) {
512 Alert("parsing [%s:%d]: '%s' has to be > 0.\n",
513 file, linenum, args[cur_arg]);
514 err_code |= ERR_ALERT | ERR_FATAL;
515 goto out;
516 }
517
518 cur_arg += 2;
519 }
520 else if (!strcmp(args[cur_arg], "inter")) {
521 const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS);
522 if (err) {
523 Alert("parsing [%s:%d] : unexpected character '%c' in 'inter' argument of server %s.\n",
524 file, linenum, *err, newsrv->id);
525 err_code |= ERR_ALERT | ERR_FATAL;
526 goto out;
527 }
528 if (val <= 0) {
529 Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n",
530 file, linenum, val, args[cur_arg], newsrv->id);
531 err_code |= ERR_ALERT | ERR_FATAL;
532 goto out;
533 }
534 newsrv->check.inter = val;
535 cur_arg += 2;
536 }
537 else if (!strcmp(args[cur_arg], "fastinter")) {
538 const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS);
539 if (err) {
540 Alert("parsing [%s:%d]: unexpected character '%c' in 'fastinter' argument of server %s.\n",
541 file, linenum, *err, newsrv->id);
542 err_code |= ERR_ALERT | ERR_FATAL;
543 goto out;
544 }
545 if (val <= 0) {
546 Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n",
547 file, linenum, val, args[cur_arg], newsrv->id);
548 err_code |= ERR_ALERT | ERR_FATAL;
549 goto out;
550 }
551 newsrv->check.fastinter = val;
552 cur_arg += 2;
553 }
554 else if (!strcmp(args[cur_arg], "downinter")) {
555 const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS);
556 if (err) {
557 Alert("parsing [%s:%d]: unexpected character '%c' in 'downinter' argument of server %s.\n",
558 file, linenum, *err, newsrv->id);
559 err_code |= ERR_ALERT | ERR_FATAL;
560 goto out;
561 }
562 if (val <= 0) {
563 Alert("parsing [%s:%d]: invalid value %d for argument '%s' of server %s.\n",
564 file, linenum, val, args[cur_arg], newsrv->id);
565 err_code |= ERR_ALERT | ERR_FATAL;
566 goto out;
567 }
568 newsrv->check.downinter = val;
569 cur_arg += 2;
570 }
571 else if (!defsrv && !strcmp(args[cur_arg], "addr")) {
572 struct sockaddr_storage *sk;
573 int port1, port2;
574 struct protocol *proto;
575
576 sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL);
577 if (!sk) {
578 Alert("parsing [%s:%d] : '%s' : %s\n",
579 file, linenum, args[cur_arg], errmsg);
580 err_code |= ERR_ALERT | ERR_FATAL;
581 goto out;
582 }
583
584 proto = protocol_by_family(sk->ss_family);
585 if (!proto || !proto->connect) {
586 Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
587 file, linenum, args[cur_arg], args[cur_arg + 1]);
588 err_code |= ERR_ALERT | ERR_FATAL;
589 goto out;
590 }
591
592 if (port1 != port2) {
593 Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n",
594 file, linenum, args[cur_arg], args[cur_arg + 1]);
595 err_code |= ERR_ALERT | ERR_FATAL;
596 goto out;
597 }
598
599 newsrv->check_common.addr = *sk;
600 cur_arg += 2;
601 }
602 else if (!strcmp(args[cur_arg], "port")) {
603 newsrv->check.port = atol(args[cur_arg + 1]);
604 cur_arg += 2;
605 }
606 else if (!defsrv && !strcmp(args[cur_arg], "backup")) {
607 newsrv->state |= SRV_BACKUP;
608 cur_arg ++;
609 }
610 else if (!defsrv && !strcmp(args[cur_arg], "non-stick")) {
611 newsrv->state |= SRV_NON_STICK;
612 cur_arg ++;
613 }
614 else if (!defsrv && !strcmp(args[cur_arg], "send-proxy")) {
David Safb76832014-05-08 23:42:08 -0400615 newsrv->pp_opts |= SRV_PP_V1;
Willy Tarreau272adea2014-03-31 10:39:59 +0200616 cur_arg ++;
617 }
David Safb76832014-05-08 23:42:08 -0400618 else if (!defsrv && !strcmp(args[cur_arg], "send-proxy-v2")) {
619 newsrv->pp_opts |= SRV_PP_V2;
620 cur_arg ++;
621 }
Willy Tarreau272adea2014-03-31 10:39:59 +0200622 else if (!defsrv && !strcmp(args[cur_arg], "check-send-proxy")) {
623 newsrv->check.send_proxy = 1;
624 cur_arg ++;
625 }
626 else if (!strcmp(args[cur_arg], "weight")) {
627 int w;
628 w = atol(args[cur_arg + 1]);
629 if (w < 0 || w > SRV_UWGHT_MAX) {
630 Alert("parsing [%s:%d] : weight of server %s is not within 0 and %d (%d).\n",
631 file, linenum, newsrv->id, SRV_UWGHT_MAX, w);
632 err_code |= ERR_ALERT | ERR_FATAL;
633 goto out;
634 }
635 newsrv->uweight = newsrv->iweight = w;
636 cur_arg += 2;
637 }
638 else if (!strcmp(args[cur_arg], "minconn")) {
639 newsrv->minconn = atol(args[cur_arg + 1]);
640 cur_arg += 2;
641 }
642 else if (!strcmp(args[cur_arg], "maxconn")) {
643 newsrv->maxconn = atol(args[cur_arg + 1]);
644 cur_arg += 2;
645 }
646 else if (!strcmp(args[cur_arg], "maxqueue")) {
647 newsrv->maxqueue = atol(args[cur_arg + 1]);
648 cur_arg += 2;
649 }
650 else if (!strcmp(args[cur_arg], "slowstart")) {
651 /* slowstart is stored in seconds */
652 const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS);
653 if (err) {
654 Alert("parsing [%s:%d] : unexpected character '%c' in 'slowstart' argument of server %s.\n",
655 file, linenum, *err, newsrv->id);
656 err_code |= ERR_ALERT | ERR_FATAL;
657 goto out;
658 }
659 newsrv->slowstart = (val + 999) / 1000;
660 cur_arg += 2;
661 }
662 else if (!defsrv && !strcmp(args[cur_arg], "track")) {
663
664 if (!*args[cur_arg + 1]) {
665 Alert("parsing [%s:%d]: 'track' expects [<proxy>/]<server> as argument.\n",
666 file, linenum);
667 err_code |= ERR_ALERT | ERR_FATAL;
668 goto out;
669 }
670
671 newsrv->trackit = strdup(args[cur_arg + 1]);
672
673 cur_arg += 2;
674 }
675 else if (!defsrv && !strcmp(args[cur_arg], "check")) {
676 global.maxsock++;
677 do_check = 1;
678 cur_arg += 1;
679 }
680 else if (!defsrv && !strcmp(args[cur_arg], "disabled")) {
681 newsrv->state |= SRV_MAINTAIN;
682 newsrv->state &= ~SRV_RUNNING;
683 newsrv->check.state |= CHK_ST_PAUSED;
684 newsrv->check.health = 0;
685 newsrv->agent.health = 0;
686 cur_arg += 1;
687 }
688 else if (!defsrv && !strcmp(args[cur_arg], "observe")) {
689 if (!strcmp(args[cur_arg + 1], "none"))
690 newsrv->observe = HANA_OBS_NONE;
691 else if (!strcmp(args[cur_arg + 1], "layer4"))
692 newsrv->observe = HANA_OBS_LAYER4;
693 else if (!strcmp(args[cur_arg + 1], "layer7")) {
694 if (curproxy->mode != PR_MODE_HTTP) {
695 Alert("parsing [%s:%d]: '%s' can only be used in http proxies.\n",
696 file, linenum, args[cur_arg + 1]);
697 err_code |= ERR_ALERT;
698 }
699 newsrv->observe = HANA_OBS_LAYER7;
700 }
701 else {
702 Alert("parsing [%s:%d]: '%s' expects one of 'none', "
703 "'layer4', 'layer7' but got '%s'\n",
704 file, linenum, args[cur_arg], args[cur_arg + 1]);
705 err_code |= ERR_ALERT | ERR_FATAL;
706 goto out;
707 }
708
709 cur_arg += 2;
710 }
711 else if (!strcmp(args[cur_arg], "on-error")) {
712 if (!strcmp(args[cur_arg + 1], "fastinter"))
713 newsrv->onerror = HANA_ONERR_FASTINTER;
714 else if (!strcmp(args[cur_arg + 1], "fail-check"))
715 newsrv->onerror = HANA_ONERR_FAILCHK;
716 else if (!strcmp(args[cur_arg + 1], "sudden-death"))
717 newsrv->onerror = HANA_ONERR_SUDDTH;
718 else if (!strcmp(args[cur_arg + 1], "mark-down"))
719 newsrv->onerror = HANA_ONERR_MARKDWN;
720 else {
721 Alert("parsing [%s:%d]: '%s' expects one of 'fastinter', "
722 "'fail-check', 'sudden-death' or 'mark-down' but got '%s'\n",
723 file, linenum, args[cur_arg], args[cur_arg + 1]);
724 err_code |= ERR_ALERT | ERR_FATAL;
725 goto out;
726 }
727
728 cur_arg += 2;
729 }
730 else if (!strcmp(args[cur_arg], "on-marked-down")) {
731 if (!strcmp(args[cur_arg + 1], "shutdown-sessions"))
732 newsrv->onmarkeddown = HANA_ONMARKEDDOWN_SHUTDOWNSESSIONS;
733 else {
734 Alert("parsing [%s:%d]: '%s' expects 'shutdown-sessions' but got '%s'\n",
735 file, linenum, args[cur_arg], args[cur_arg + 1]);
736 err_code |= ERR_ALERT | ERR_FATAL;
737 goto out;
738 }
739
740 cur_arg += 2;
741 }
742 else if (!strcmp(args[cur_arg], "on-marked-up")) {
743 if (!strcmp(args[cur_arg + 1], "shutdown-backup-sessions"))
744 newsrv->onmarkedup = HANA_ONMARKEDUP_SHUTDOWNBACKUPSESSIONS;
745 else {
746 Alert("parsing [%s:%d]: '%s' expects 'shutdown-backup-sessions' but got '%s'\n",
747 file, linenum, args[cur_arg], args[cur_arg + 1]);
748 err_code |= ERR_ALERT | ERR_FATAL;
749 goto out;
750 }
751
752 cur_arg += 2;
753 }
754 else if (!strcmp(args[cur_arg], "error-limit")) {
755 if (!*args[cur_arg + 1]) {
756 Alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
757 file, linenum, args[cur_arg]);
758 err_code |= ERR_ALERT | ERR_FATAL;
759 goto out;
760 }
761
762 newsrv->consecutive_errors_limit = atoi(args[cur_arg + 1]);
763
764 if (newsrv->consecutive_errors_limit <= 0) {
765 Alert("parsing [%s:%d]: %s has to be > 0.\n",
766 file, linenum, args[cur_arg]);
767 err_code |= ERR_ALERT | ERR_FATAL;
768 goto out;
769 }
770 cur_arg += 2;
771 }
772 else if (!defsrv && !strcmp(args[cur_arg], "source")) { /* address to which we bind when connecting */
773 int port_low, port_high;
774 struct sockaddr_storage *sk;
775 struct protocol *proto;
776
777 if (!*args[cur_arg + 1]) {
778 Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>[-<port>]], and optionally '%s' <addr>, and '%s' <name> as argument.\n",
779 file, linenum, "source", "usesrc", "interface");
780 err_code |= ERR_ALERT | ERR_FATAL;
781 goto out;
782 }
783
784 newsrv->conn_src.opts |= CO_SRC_BIND;
785 sk = str2sa_range(args[cur_arg + 1], &port_low, &port_high, &errmsg, NULL);
786 if (!sk) {
787 Alert("parsing [%s:%d] : '%s %s' : %s\n",
788 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
789 err_code |= ERR_ALERT | ERR_FATAL;
790 goto out;
791 }
792
793 proto = protocol_by_family(sk->ss_family);
794 if (!proto || !proto->connect) {
795 Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
796 file, linenum, args[cur_arg], args[cur_arg+1]);
797 err_code |= ERR_ALERT | ERR_FATAL;
798 goto out;
799 }
800
801 newsrv->conn_src.source_addr = *sk;
802
803 if (port_low != port_high) {
804 int i;
805
806 if (!port_low || !port_high) {
807 Alert("parsing [%s:%d] : %s does not support port offsets (found '%s').\n",
808 file, linenum, args[cur_arg], args[cur_arg + 1]);
809 err_code |= ERR_ALERT | ERR_FATAL;
810 goto out;
811 }
812
813 if (port_low <= 0 || port_low > 65535 ||
814 port_high <= 0 || port_high > 65535 ||
815 port_low > port_high) {
816 Alert("parsing [%s:%d] : invalid source port range %d-%d.\n",
817 file, linenum, port_low, port_high);
818 err_code |= ERR_ALERT | ERR_FATAL;
819 goto out;
820 }
821 newsrv->conn_src.sport_range = port_range_alloc_range(port_high - port_low + 1);
822 for (i = 0; i < newsrv->conn_src.sport_range->size; i++)
823 newsrv->conn_src.sport_range->ports[i] = port_low + i;
824 }
825
826 cur_arg += 2;
827 while (*(args[cur_arg])) {
828 if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */
829#if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT)
830#if !defined(CONFIG_HAP_TRANSPARENT)
831 if (!is_addr(&newsrv->conn_src.source_addr)) {
832 Alert("parsing [%s:%d] : '%s' requires an explicit '%s' address.\n",
833 file, linenum, "usesrc", "source");
834 err_code |= ERR_ALERT | ERR_FATAL;
835 goto out;
836 }
837#endif
838 if (!*args[cur_arg + 1]) {
839 Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', 'clientip', or 'hdr_ip(name,#)' as argument.\n",
840 file, linenum, "usesrc");
841 err_code |= ERR_ALERT | ERR_FATAL;
842 goto out;
843 }
844 if (!strcmp(args[cur_arg + 1], "client")) {
845 newsrv->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
846 newsrv->conn_src.opts |= CO_SRC_TPROXY_CLI;
847 } else if (!strcmp(args[cur_arg + 1], "clientip")) {
848 newsrv->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
849 newsrv->conn_src.opts |= CO_SRC_TPROXY_CIP;
850 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
851 char *name, *end;
852
853 name = args[cur_arg+1] + 7;
854 while (isspace(*name))
855 name++;
856
857 end = name;
858 while (*end && !isspace(*end) && *end != ',' && *end != ')')
859 end++;
860
861 newsrv->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
862 newsrv->conn_src.opts |= CO_SRC_TPROXY_DYN;
863 newsrv->conn_src.bind_hdr_name = calloc(1, end - name + 1);
864 newsrv->conn_src.bind_hdr_len = end - name;
865 memcpy(newsrv->conn_src.bind_hdr_name, name, end - name);
866 newsrv->conn_src.bind_hdr_name[end-name] = '\0';
867 newsrv->conn_src.bind_hdr_occ = -1;
868
869 /* now look for an occurrence number */
870 while (isspace(*end))
871 end++;
872 if (*end == ',') {
873 end++;
874 name = end;
875 if (*end == '-')
876 end++;
877 while (isdigit((int)*end))
878 end++;
879 newsrv->conn_src.bind_hdr_occ = strl2ic(name, end-name);
880 }
881
882 if (newsrv->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
883 Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
884 " occurrences values smaller than %d.\n",
885 file, linenum, MAX_HDR_HISTORY);
886 err_code |= ERR_ALERT | ERR_FATAL;
887 goto out;
888 }
889 } else {
890 struct sockaddr_storage *sk;
891 int port1, port2;
892
893 sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL);
894 if (!sk) {
895 Alert("parsing [%s:%d] : '%s %s' : %s\n",
896 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
897 err_code |= ERR_ALERT | ERR_FATAL;
898 goto out;
899 }
900
901 proto = protocol_by_family(sk->ss_family);
902 if (!proto || !proto->connect) {
903 Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
904 file, linenum, args[cur_arg], args[cur_arg+1]);
905 err_code |= ERR_ALERT | ERR_FATAL;
906 goto out;
907 }
908
909 if (port1 != port2) {
910 Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n",
911 file, linenum, args[cur_arg], args[cur_arg + 1]);
912 err_code |= ERR_ALERT | ERR_FATAL;
913 goto out;
914 }
915 newsrv->conn_src.tproxy_addr = *sk;
916 newsrv->conn_src.opts |= CO_SRC_TPROXY_ADDR;
917 }
918 global.last_checks |= LSTCHK_NETADM;
919#if !defined(CONFIG_HAP_TRANSPARENT)
920 global.last_checks |= LSTCHK_CTTPROXY;
921#endif
922 cur_arg += 2;
923 continue;
924#else /* no TPROXY support */
925 Alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
926 file, linenum, "usesrc");
927 err_code |= ERR_ALERT | ERR_FATAL;
928 goto out;
929#endif /* defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) */
930 } /* "usesrc" */
931
932 if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */
933#ifdef SO_BINDTODEVICE
934 if (!*args[cur_arg + 1]) {
935 Alert("parsing [%s:%d] : '%s' : missing interface name.\n",
936 file, linenum, args[0]);
937 err_code |= ERR_ALERT | ERR_FATAL;
938 goto out;
939 }
940 free(newsrv->conn_src.iface_name);
941 newsrv->conn_src.iface_name = strdup(args[cur_arg + 1]);
942 newsrv->conn_src.iface_len = strlen(newsrv->conn_src.iface_name);
943 global.last_checks |= LSTCHK_NETADM;
944#else
945 Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
946 file, linenum, args[0], args[cur_arg]);
947 err_code |= ERR_ALERT | ERR_FATAL;
948 goto out;
949#endif
950 cur_arg += 2;
951 continue;
952 }
953 /* this keyword in not an option of "source" */
954 break;
955 } /* while */
956 }
957 else if (!defsrv && !strcmp(args[cur_arg], "usesrc")) { /* address to use outside: needs "source" first */
958 Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
959 file, linenum, "usesrc", "source");
960 err_code |= ERR_ALERT | ERR_FATAL;
961 goto out;
962 }
963 else {
964 static int srv_dumped;
965 struct srv_kw *kw;
966 char *err;
967
968 kw = srv_find_kw(args[cur_arg]);
969 if (kw) {
970 char *err = NULL;
971 int code;
972
973 if (!kw->parse) {
974 Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n",
975 file, linenum, args[0], args[1], args[cur_arg]);
976 cur_arg += 1 + kw->skip ;
977 err_code |= ERR_ALERT | ERR_FATAL;
978 goto out;
979 }
980
981 if (defsrv && !kw->default_ok) {
982 Alert("parsing [%s:%d] : '%s %s' : '%s' option is not accepted in default-server sections.\n",
983 file, linenum, args[0], args[1], args[cur_arg]);
984 cur_arg += 1 + kw->skip ;
985 err_code |= ERR_ALERT;
986 continue;
987 }
988
989 code = kw->parse(args, &cur_arg, curproxy, newsrv, &err);
990 err_code |= code;
991
992 if (code) {
993 if (err && *err) {
994 indent_msg(&err, 2);
995 Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
996 }
997 else
998 Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n",
999 file, linenum, args[0], args[1], args[cur_arg]);
1000 if (code & ERR_FATAL) {
1001 free(err);
1002 cur_arg += 1 + kw->skip;
1003 goto out;
1004 }
1005 }
1006 free(err);
1007 cur_arg += 1 + kw->skip;
1008 continue;
1009 }
1010
1011 err = NULL;
1012 if (!srv_dumped) {
1013 srv_dump_kws(&err);
1014 indent_msg(&err, 4);
1015 srv_dumped = 1;
1016 }
1017
1018 Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n",
1019 file, linenum, args[0], args[1], args[cur_arg],
1020 err ? " Registered keywords :" : "", err ? err : "");
1021 free(err);
1022
1023 err_code |= ERR_ALERT | ERR_FATAL;
1024 goto out;
1025 }
1026 }
1027
1028 /* Set initial drain state using now-configured weight */
1029 set_server_drain_state(newsrv);
1030
1031 if (do_check) {
1032 int ret;
1033
1034 if (newsrv->trackit) {
1035 Alert("parsing [%s:%d]: unable to enable checks and tracking at the same time!\n",
1036 file, linenum);
1037 err_code |= ERR_ALERT | ERR_FATAL;
1038 goto out;
1039 }
1040
1041 /* If neither a port nor an addr was specified and no check transport
1042 * layer is forced, then the transport layer used by the checks is the
1043 * same as for the production traffic. Otherwise we use raw_sock by
1044 * default, unless one is specified.
1045 */
1046 if (!newsrv->check.port && !is_addr(&newsrv->check_common.addr)) {
1047#ifdef USE_OPENSSL
1048 newsrv->check.use_ssl |= (newsrv->use_ssl || (newsrv->proxy->options & PR_O_TCPCHK_SSL));
1049#endif
David Safb76832014-05-08 23:42:08 -04001050 newsrv->check.send_proxy |= (newsrv->pp_opts);
Willy Tarreau272adea2014-03-31 10:39:59 +02001051 }
1052 /* try to get the port from check_core.addr if check.port not set */
1053 if (!newsrv->check.port)
1054 newsrv->check.port = get_host_port(&newsrv->check_common.addr);
1055
1056 if (!newsrv->check.port)
1057 newsrv->check.port = realport; /* by default */
1058
1059 if (!newsrv->check.port) {
1060 /* not yet valid, because no port was set on
1061 * the server either. We'll check if we have
1062 * a known port on the first listener.
1063 */
1064 struct listener *l;
1065
1066 list_for_each_entry(l, &curproxy->conf.listeners, by_fe) {
1067 newsrv->check.port = get_host_port(&l->addr);
1068 if (newsrv->check.port)
1069 break;
1070 }
1071 }
1072 /*
1073 * We need at least a service port, a check port or the first tcp-check rule must
1074 * be a 'connect' one
1075 */
1076 if (!newsrv->check.port) {
1077 struct tcpcheck_rule *n = NULL, *r = NULL;
1078 struct list *l;
1079
1080 r = (struct tcpcheck_rule *)newsrv->proxy->tcpcheck_rules.n;
1081 if (!r) {
1082 Alert("parsing [%s:%d] : server %s has neither service port nor check port. Check has been disabled.\n",
1083 file, linenum, newsrv->id);
1084 err_code |= ERR_ALERT | ERR_FATAL;
1085 goto out;
1086 }
1087 if ((r->action != TCPCHK_ACT_CONNECT) || !r->port) {
1088 Alert("parsing [%s:%d] : server %s has neither service port nor check port nor tcp_check rule 'connect' with port information. Check has been disabled.\n",
1089 file, linenum, newsrv->id);
1090 err_code |= ERR_ALERT | ERR_FATAL;
1091 goto out;
1092 }
1093 else {
1094 /* scan the tcp-check ruleset to ensure a port has been configured */
1095 l = &newsrv->proxy->tcpcheck_rules;
1096 list_for_each_entry(n, l, list) {
1097 r = (struct tcpcheck_rule *)n->list.p;
1098 if ((r->action == TCPCHK_ACT_CONNECT) && (!r->port)) {
1099 Alert("parsing [%s:%d] : server %s has neither service port nor check port, and a tcp_check rule 'connect' with no port information. Check has been disabled.\n",
1100 file, linenum, newsrv->id);
1101 err_code |= ERR_ALERT | ERR_FATAL;
1102 goto out;
1103 }
1104 }
1105 }
1106 }
1107
1108 /* note: check type will be set during the config review phase */
1109 ret = init_check(&newsrv->check, 0, file, linenum);
1110 if (ret) {
1111 err_code |= ret;
1112 goto out;
1113 }
1114
1115 newsrv->check.state |= CHK_ST_CONFIGURED | CHK_ST_ENABLED;
1116 }
1117
1118 if (do_agent) {
1119 int ret;
1120
1121 if (!newsrv->agent.port) {
1122 Alert("parsing [%s:%d] : server %s does not have agent port. Agent check has been disabled.\n",
1123 file, linenum, newsrv->id);
1124 err_code |= ERR_ALERT | ERR_FATAL;
1125 goto out;
1126 }
1127
1128 if (!newsrv->agent.inter)
1129 newsrv->agent.inter = newsrv->check.inter;
1130
1131 ret = init_check(&newsrv->agent, PR_O2_LB_AGENT_CHK, file, linenum);
1132 if (ret) {
1133 err_code |= ret;
1134 goto out;
1135 }
1136
1137 newsrv->agent.state |= CHK_ST_CONFIGURED | CHK_ST_ENABLED | CHK_ST_AGENT;
1138 }
1139
1140 if (!defsrv) {
1141 if (newsrv->state & SRV_BACKUP)
1142 curproxy->srv_bck++;
1143 else
1144 curproxy->srv_act++;
1145
1146 newsrv->prev_state = newsrv->state;
1147 }
1148 }
1149 return 0;
1150
1151 out:
1152 free(errmsg);
1153 return err_code;
1154}
1155
Simon Horman7d09b9a2013-02-12 10:45:51 +09001156/*
Willy Tarreaubaaee002006-06-26 02:48:02 +02001157 * Local variables:
1158 * c-indent-level: 8
1159 * c-basic-offset: 8
1160 * End:
1161 */