blob: 5ac5e373dc1817e67ffbda410e98712ed1b3e764 [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")) {
615 newsrv->state |= SRV_SEND_PROXY;
616 cur_arg ++;
617 }
618 else if (!defsrv && !strcmp(args[cur_arg], "check-send-proxy")) {
619 newsrv->check.send_proxy = 1;
620 cur_arg ++;
621 }
622 else if (!strcmp(args[cur_arg], "weight")) {
623 int w;
624 w = atol(args[cur_arg + 1]);
625 if (w < 0 || w > SRV_UWGHT_MAX) {
626 Alert("parsing [%s:%d] : weight of server %s is not within 0 and %d (%d).\n",
627 file, linenum, newsrv->id, SRV_UWGHT_MAX, w);
628 err_code |= ERR_ALERT | ERR_FATAL;
629 goto out;
630 }
631 newsrv->uweight = newsrv->iweight = w;
632 cur_arg += 2;
633 }
634 else if (!strcmp(args[cur_arg], "minconn")) {
635 newsrv->minconn = atol(args[cur_arg + 1]);
636 cur_arg += 2;
637 }
638 else if (!strcmp(args[cur_arg], "maxconn")) {
639 newsrv->maxconn = atol(args[cur_arg + 1]);
640 cur_arg += 2;
641 }
642 else if (!strcmp(args[cur_arg], "maxqueue")) {
643 newsrv->maxqueue = atol(args[cur_arg + 1]);
644 cur_arg += 2;
645 }
646 else if (!strcmp(args[cur_arg], "slowstart")) {
647 /* slowstart is stored in seconds */
648 const char *err = parse_time_err(args[cur_arg + 1], &val, TIME_UNIT_MS);
649 if (err) {
650 Alert("parsing [%s:%d] : unexpected character '%c' in 'slowstart' argument of server %s.\n",
651 file, linenum, *err, newsrv->id);
652 err_code |= ERR_ALERT | ERR_FATAL;
653 goto out;
654 }
655 newsrv->slowstart = (val + 999) / 1000;
656 cur_arg += 2;
657 }
658 else if (!defsrv && !strcmp(args[cur_arg], "track")) {
659
660 if (!*args[cur_arg + 1]) {
661 Alert("parsing [%s:%d]: 'track' expects [<proxy>/]<server> as argument.\n",
662 file, linenum);
663 err_code |= ERR_ALERT | ERR_FATAL;
664 goto out;
665 }
666
667 newsrv->trackit = strdup(args[cur_arg + 1]);
668
669 cur_arg += 2;
670 }
671 else if (!defsrv && !strcmp(args[cur_arg], "check")) {
672 global.maxsock++;
673 do_check = 1;
674 cur_arg += 1;
675 }
676 else if (!defsrv && !strcmp(args[cur_arg], "disabled")) {
677 newsrv->state |= SRV_MAINTAIN;
678 newsrv->state &= ~SRV_RUNNING;
679 newsrv->check.state |= CHK_ST_PAUSED;
680 newsrv->check.health = 0;
681 newsrv->agent.health = 0;
682 cur_arg += 1;
683 }
684 else if (!defsrv && !strcmp(args[cur_arg], "observe")) {
685 if (!strcmp(args[cur_arg + 1], "none"))
686 newsrv->observe = HANA_OBS_NONE;
687 else if (!strcmp(args[cur_arg + 1], "layer4"))
688 newsrv->observe = HANA_OBS_LAYER4;
689 else if (!strcmp(args[cur_arg + 1], "layer7")) {
690 if (curproxy->mode != PR_MODE_HTTP) {
691 Alert("parsing [%s:%d]: '%s' can only be used in http proxies.\n",
692 file, linenum, args[cur_arg + 1]);
693 err_code |= ERR_ALERT;
694 }
695 newsrv->observe = HANA_OBS_LAYER7;
696 }
697 else {
698 Alert("parsing [%s:%d]: '%s' expects one of 'none', "
699 "'layer4', 'layer7' but got '%s'\n",
700 file, linenum, args[cur_arg], args[cur_arg + 1]);
701 err_code |= ERR_ALERT | ERR_FATAL;
702 goto out;
703 }
704
705 cur_arg += 2;
706 }
707 else if (!strcmp(args[cur_arg], "on-error")) {
708 if (!strcmp(args[cur_arg + 1], "fastinter"))
709 newsrv->onerror = HANA_ONERR_FASTINTER;
710 else if (!strcmp(args[cur_arg + 1], "fail-check"))
711 newsrv->onerror = HANA_ONERR_FAILCHK;
712 else if (!strcmp(args[cur_arg + 1], "sudden-death"))
713 newsrv->onerror = HANA_ONERR_SUDDTH;
714 else if (!strcmp(args[cur_arg + 1], "mark-down"))
715 newsrv->onerror = HANA_ONERR_MARKDWN;
716 else {
717 Alert("parsing [%s:%d]: '%s' expects one of 'fastinter', "
718 "'fail-check', 'sudden-death' or 'mark-down' but got '%s'\n",
719 file, linenum, args[cur_arg], args[cur_arg + 1]);
720 err_code |= ERR_ALERT | ERR_FATAL;
721 goto out;
722 }
723
724 cur_arg += 2;
725 }
726 else if (!strcmp(args[cur_arg], "on-marked-down")) {
727 if (!strcmp(args[cur_arg + 1], "shutdown-sessions"))
728 newsrv->onmarkeddown = HANA_ONMARKEDDOWN_SHUTDOWNSESSIONS;
729 else {
730 Alert("parsing [%s:%d]: '%s' expects 'shutdown-sessions' but got '%s'\n",
731 file, linenum, args[cur_arg], args[cur_arg + 1]);
732 err_code |= ERR_ALERT | ERR_FATAL;
733 goto out;
734 }
735
736 cur_arg += 2;
737 }
738 else if (!strcmp(args[cur_arg], "on-marked-up")) {
739 if (!strcmp(args[cur_arg + 1], "shutdown-backup-sessions"))
740 newsrv->onmarkedup = HANA_ONMARKEDUP_SHUTDOWNBACKUPSESSIONS;
741 else {
742 Alert("parsing [%s:%d]: '%s' expects 'shutdown-backup-sessions' but got '%s'\n",
743 file, linenum, args[cur_arg], args[cur_arg + 1]);
744 err_code |= ERR_ALERT | ERR_FATAL;
745 goto out;
746 }
747
748 cur_arg += 2;
749 }
750 else if (!strcmp(args[cur_arg], "error-limit")) {
751 if (!*args[cur_arg + 1]) {
752 Alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
753 file, linenum, args[cur_arg]);
754 err_code |= ERR_ALERT | ERR_FATAL;
755 goto out;
756 }
757
758 newsrv->consecutive_errors_limit = atoi(args[cur_arg + 1]);
759
760 if (newsrv->consecutive_errors_limit <= 0) {
761 Alert("parsing [%s:%d]: %s has to be > 0.\n",
762 file, linenum, args[cur_arg]);
763 err_code |= ERR_ALERT | ERR_FATAL;
764 goto out;
765 }
766 cur_arg += 2;
767 }
768 else if (!defsrv && !strcmp(args[cur_arg], "source")) { /* address to which we bind when connecting */
769 int port_low, port_high;
770 struct sockaddr_storage *sk;
771 struct protocol *proto;
772
773 if (!*args[cur_arg + 1]) {
774 Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>[-<port>]], and optionally '%s' <addr>, and '%s' <name> as argument.\n",
775 file, linenum, "source", "usesrc", "interface");
776 err_code |= ERR_ALERT | ERR_FATAL;
777 goto out;
778 }
779
780 newsrv->conn_src.opts |= CO_SRC_BIND;
781 sk = str2sa_range(args[cur_arg + 1], &port_low, &port_high, &errmsg, NULL);
782 if (!sk) {
783 Alert("parsing [%s:%d] : '%s %s' : %s\n",
784 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
785 err_code |= ERR_ALERT | ERR_FATAL;
786 goto out;
787 }
788
789 proto = protocol_by_family(sk->ss_family);
790 if (!proto || !proto->connect) {
791 Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
792 file, linenum, args[cur_arg], args[cur_arg+1]);
793 err_code |= ERR_ALERT | ERR_FATAL;
794 goto out;
795 }
796
797 newsrv->conn_src.source_addr = *sk;
798
799 if (port_low != port_high) {
800 int i;
801
802 if (!port_low || !port_high) {
803 Alert("parsing [%s:%d] : %s does not support port offsets (found '%s').\n",
804 file, linenum, args[cur_arg], args[cur_arg + 1]);
805 err_code |= ERR_ALERT | ERR_FATAL;
806 goto out;
807 }
808
809 if (port_low <= 0 || port_low > 65535 ||
810 port_high <= 0 || port_high > 65535 ||
811 port_low > port_high) {
812 Alert("parsing [%s:%d] : invalid source port range %d-%d.\n",
813 file, linenum, port_low, port_high);
814 err_code |= ERR_ALERT | ERR_FATAL;
815 goto out;
816 }
817 newsrv->conn_src.sport_range = port_range_alloc_range(port_high - port_low + 1);
818 for (i = 0; i < newsrv->conn_src.sport_range->size; i++)
819 newsrv->conn_src.sport_range->ports[i] = port_low + i;
820 }
821
822 cur_arg += 2;
823 while (*(args[cur_arg])) {
824 if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */
825#if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT)
826#if !defined(CONFIG_HAP_TRANSPARENT)
827 if (!is_addr(&newsrv->conn_src.source_addr)) {
828 Alert("parsing [%s:%d] : '%s' requires an explicit '%s' address.\n",
829 file, linenum, "usesrc", "source");
830 err_code |= ERR_ALERT | ERR_FATAL;
831 goto out;
832 }
833#endif
834 if (!*args[cur_arg + 1]) {
835 Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', 'clientip', or 'hdr_ip(name,#)' as argument.\n",
836 file, linenum, "usesrc");
837 err_code |= ERR_ALERT | ERR_FATAL;
838 goto out;
839 }
840 if (!strcmp(args[cur_arg + 1], "client")) {
841 newsrv->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
842 newsrv->conn_src.opts |= CO_SRC_TPROXY_CLI;
843 } else if (!strcmp(args[cur_arg + 1], "clientip")) {
844 newsrv->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
845 newsrv->conn_src.opts |= CO_SRC_TPROXY_CIP;
846 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
847 char *name, *end;
848
849 name = args[cur_arg+1] + 7;
850 while (isspace(*name))
851 name++;
852
853 end = name;
854 while (*end && !isspace(*end) && *end != ',' && *end != ')')
855 end++;
856
857 newsrv->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
858 newsrv->conn_src.opts |= CO_SRC_TPROXY_DYN;
859 newsrv->conn_src.bind_hdr_name = calloc(1, end - name + 1);
860 newsrv->conn_src.bind_hdr_len = end - name;
861 memcpy(newsrv->conn_src.bind_hdr_name, name, end - name);
862 newsrv->conn_src.bind_hdr_name[end-name] = '\0';
863 newsrv->conn_src.bind_hdr_occ = -1;
864
865 /* now look for an occurrence number */
866 while (isspace(*end))
867 end++;
868 if (*end == ',') {
869 end++;
870 name = end;
871 if (*end == '-')
872 end++;
873 while (isdigit((int)*end))
874 end++;
875 newsrv->conn_src.bind_hdr_occ = strl2ic(name, end-name);
876 }
877
878 if (newsrv->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
879 Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
880 " occurrences values smaller than %d.\n",
881 file, linenum, MAX_HDR_HISTORY);
882 err_code |= ERR_ALERT | ERR_FATAL;
883 goto out;
884 }
885 } else {
886 struct sockaddr_storage *sk;
887 int port1, port2;
888
889 sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL);
890 if (!sk) {
891 Alert("parsing [%s:%d] : '%s %s' : %s\n",
892 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
893 err_code |= ERR_ALERT | ERR_FATAL;
894 goto out;
895 }
896
897 proto = protocol_by_family(sk->ss_family);
898 if (!proto || !proto->connect) {
899 Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
900 file, linenum, args[cur_arg], args[cur_arg+1]);
901 err_code |= ERR_ALERT | ERR_FATAL;
902 goto out;
903 }
904
905 if (port1 != port2) {
906 Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n",
907 file, linenum, args[cur_arg], args[cur_arg + 1]);
908 err_code |= ERR_ALERT | ERR_FATAL;
909 goto out;
910 }
911 newsrv->conn_src.tproxy_addr = *sk;
912 newsrv->conn_src.opts |= CO_SRC_TPROXY_ADDR;
913 }
914 global.last_checks |= LSTCHK_NETADM;
915#if !defined(CONFIG_HAP_TRANSPARENT)
916 global.last_checks |= LSTCHK_CTTPROXY;
917#endif
918 cur_arg += 2;
919 continue;
920#else /* no TPROXY support */
921 Alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
922 file, linenum, "usesrc");
923 err_code |= ERR_ALERT | ERR_FATAL;
924 goto out;
925#endif /* defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) */
926 } /* "usesrc" */
927
928 if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */
929#ifdef SO_BINDTODEVICE
930 if (!*args[cur_arg + 1]) {
931 Alert("parsing [%s:%d] : '%s' : missing interface name.\n",
932 file, linenum, args[0]);
933 err_code |= ERR_ALERT | ERR_FATAL;
934 goto out;
935 }
936 free(newsrv->conn_src.iface_name);
937 newsrv->conn_src.iface_name = strdup(args[cur_arg + 1]);
938 newsrv->conn_src.iface_len = strlen(newsrv->conn_src.iface_name);
939 global.last_checks |= LSTCHK_NETADM;
940#else
941 Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
942 file, linenum, args[0], args[cur_arg]);
943 err_code |= ERR_ALERT | ERR_FATAL;
944 goto out;
945#endif
946 cur_arg += 2;
947 continue;
948 }
949 /* this keyword in not an option of "source" */
950 break;
951 } /* while */
952 }
953 else if (!defsrv && !strcmp(args[cur_arg], "usesrc")) { /* address to use outside: needs "source" first */
954 Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
955 file, linenum, "usesrc", "source");
956 err_code |= ERR_ALERT | ERR_FATAL;
957 goto out;
958 }
959 else {
960 static int srv_dumped;
961 struct srv_kw *kw;
962 char *err;
963
964 kw = srv_find_kw(args[cur_arg]);
965 if (kw) {
966 char *err = NULL;
967 int code;
968
969 if (!kw->parse) {
970 Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n",
971 file, linenum, args[0], args[1], args[cur_arg]);
972 cur_arg += 1 + kw->skip ;
973 err_code |= ERR_ALERT | ERR_FATAL;
974 goto out;
975 }
976
977 if (defsrv && !kw->default_ok) {
978 Alert("parsing [%s:%d] : '%s %s' : '%s' option is not accepted in default-server sections.\n",
979 file, linenum, args[0], args[1], args[cur_arg]);
980 cur_arg += 1 + kw->skip ;
981 err_code |= ERR_ALERT;
982 continue;
983 }
984
985 code = kw->parse(args, &cur_arg, curproxy, newsrv, &err);
986 err_code |= code;
987
988 if (code) {
989 if (err && *err) {
990 indent_msg(&err, 2);
991 Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
992 }
993 else
994 Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n",
995 file, linenum, args[0], args[1], args[cur_arg]);
996 if (code & ERR_FATAL) {
997 free(err);
998 cur_arg += 1 + kw->skip;
999 goto out;
1000 }
1001 }
1002 free(err);
1003 cur_arg += 1 + kw->skip;
1004 continue;
1005 }
1006
1007 err = NULL;
1008 if (!srv_dumped) {
1009 srv_dump_kws(&err);
1010 indent_msg(&err, 4);
1011 srv_dumped = 1;
1012 }
1013
1014 Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n",
1015 file, linenum, args[0], args[1], args[cur_arg],
1016 err ? " Registered keywords :" : "", err ? err : "");
1017 free(err);
1018
1019 err_code |= ERR_ALERT | ERR_FATAL;
1020 goto out;
1021 }
1022 }
1023
1024 /* Set initial drain state using now-configured weight */
1025 set_server_drain_state(newsrv);
1026
1027 if (do_check) {
1028 int ret;
1029
1030 if (newsrv->trackit) {
1031 Alert("parsing [%s:%d]: unable to enable checks and tracking at the same time!\n",
1032 file, linenum);
1033 err_code |= ERR_ALERT | ERR_FATAL;
1034 goto out;
1035 }
1036
1037 /* If neither a port nor an addr was specified and no check transport
1038 * layer is forced, then the transport layer used by the checks is the
1039 * same as for the production traffic. Otherwise we use raw_sock by
1040 * default, unless one is specified.
1041 */
1042 if (!newsrv->check.port && !is_addr(&newsrv->check_common.addr)) {
1043#ifdef USE_OPENSSL
1044 newsrv->check.use_ssl |= (newsrv->use_ssl || (newsrv->proxy->options & PR_O_TCPCHK_SSL));
1045#endif
1046 newsrv->check.send_proxy |= (newsrv->state & SRV_SEND_PROXY);
1047 }
1048 /* try to get the port from check_core.addr if check.port not set */
1049 if (!newsrv->check.port)
1050 newsrv->check.port = get_host_port(&newsrv->check_common.addr);
1051
1052 if (!newsrv->check.port)
1053 newsrv->check.port = realport; /* by default */
1054
1055 if (!newsrv->check.port) {
1056 /* not yet valid, because no port was set on
1057 * the server either. We'll check if we have
1058 * a known port on the first listener.
1059 */
1060 struct listener *l;
1061
1062 list_for_each_entry(l, &curproxy->conf.listeners, by_fe) {
1063 newsrv->check.port = get_host_port(&l->addr);
1064 if (newsrv->check.port)
1065 break;
1066 }
1067 }
1068 /*
1069 * We need at least a service port, a check port or the first tcp-check rule must
1070 * be a 'connect' one
1071 */
1072 if (!newsrv->check.port) {
1073 struct tcpcheck_rule *n = NULL, *r = NULL;
1074 struct list *l;
1075
1076 r = (struct tcpcheck_rule *)newsrv->proxy->tcpcheck_rules.n;
1077 if (!r) {
1078 Alert("parsing [%s:%d] : server %s has neither service port nor check port. Check has been disabled.\n",
1079 file, linenum, newsrv->id);
1080 err_code |= ERR_ALERT | ERR_FATAL;
1081 goto out;
1082 }
1083 if ((r->action != TCPCHK_ACT_CONNECT) || !r->port) {
1084 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",
1085 file, linenum, newsrv->id);
1086 err_code |= ERR_ALERT | ERR_FATAL;
1087 goto out;
1088 }
1089 else {
1090 /* scan the tcp-check ruleset to ensure a port has been configured */
1091 l = &newsrv->proxy->tcpcheck_rules;
1092 list_for_each_entry(n, l, list) {
1093 r = (struct tcpcheck_rule *)n->list.p;
1094 if ((r->action == TCPCHK_ACT_CONNECT) && (!r->port)) {
1095 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",
1096 file, linenum, newsrv->id);
1097 err_code |= ERR_ALERT | ERR_FATAL;
1098 goto out;
1099 }
1100 }
1101 }
1102 }
1103
1104 /* note: check type will be set during the config review phase */
1105 ret = init_check(&newsrv->check, 0, file, linenum);
1106 if (ret) {
1107 err_code |= ret;
1108 goto out;
1109 }
1110
1111 newsrv->check.state |= CHK_ST_CONFIGURED | CHK_ST_ENABLED;
1112 }
1113
1114 if (do_agent) {
1115 int ret;
1116
1117 if (!newsrv->agent.port) {
1118 Alert("parsing [%s:%d] : server %s does not have agent port. Agent check has been disabled.\n",
1119 file, linenum, newsrv->id);
1120 err_code |= ERR_ALERT | ERR_FATAL;
1121 goto out;
1122 }
1123
1124 if (!newsrv->agent.inter)
1125 newsrv->agent.inter = newsrv->check.inter;
1126
1127 ret = init_check(&newsrv->agent, PR_O2_LB_AGENT_CHK, file, linenum);
1128 if (ret) {
1129 err_code |= ret;
1130 goto out;
1131 }
1132
1133 newsrv->agent.state |= CHK_ST_CONFIGURED | CHK_ST_ENABLED | CHK_ST_AGENT;
1134 }
1135
1136 if (!defsrv) {
1137 if (newsrv->state & SRV_BACKUP)
1138 curproxy->srv_bck++;
1139 else
1140 curproxy->srv_act++;
1141
1142 newsrv->prev_state = newsrv->state;
1143 }
1144 }
1145 return 0;
1146
1147 out:
1148 free(errmsg);
1149 return err_code;
1150}
1151
Simon Horman7d09b9a2013-02-12 10:45:51 +09001152/*
Willy Tarreaubaaee002006-06-26 02:48:02 +02001153 * Local variables:
1154 * c-indent-level: 8
1155 * c-basic-offset: 8
1156 * End:
1157 */