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