diff --git a/include/types/server.h b/include/types/server.h index cfc4d7d83..c93236cb4 100644 --- a/include/types/server.h +++ b/include/types/server.h @@ -2,7 +2,7 @@ include/types/server.h This file defines everything related to servers. - Copyright (C) 2000-2007 Willy Tarreau - w@1wt.eu + Copyright (C) 2000-2008 Willy Tarreau - w@1wt.eu This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -73,7 +73,9 @@ struct server { int state; /* server state (SRV_*) */ int prev_state; /* server state before last change (SRV_*) */ int cklen; /* the len of the cookie, to speed up checks */ + int rdr_len; /* the length of the redirection prefix */ char *cookie; /* the id set in the cookie */ + char *rdr_pfx; /* the redirection prefix */ struct proxy *proxy; /* the proxy this server belongs to */ int cur_sess, cur_sess_max; /* number of currently active sessions (including syn_sent) */ diff --git a/src/cfgparse.c b/src/cfgparse.c index 1815ed487..9329df3eb 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -1547,6 +1547,11 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int inv) newsrv->cklen = strlen(args[cur_arg + 1]); cur_arg += 2; } + else if (!strcmp(args[cur_arg], "redir")) { + newsrv->rdr_pfx = strdup(args[cur_arg + 1]); + newsrv->rdr_len = strlen(args[cur_arg + 1]); + cur_arg += 2; + } else if (!strcmp(args[cur_arg], "rise")) { newsrv->rise = atol(args[cur_arg + 1]); newsrv->health = newsrv->rise; @@ -1691,7 +1696,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int inv) return -1; } else { - Alert("parsing [%s:%d] : server %s only supports options 'backup', 'cookie', 'check', 'inter', 'fastinter', 'downinter', 'rise', 'fall', 'addr', 'port', 'source', 'minconn', 'maxconn', 'maxqueue', 'slowstart' and 'weight'.\n", + Alert("parsing [%s:%d] : server %s only supports options 'backup', 'cookie', 'redir', 'check', 'inter', 'fastinter', 'downinter', 'rise', 'fall', 'addr', 'port', 'source', 'minconn', 'maxconn', 'maxqueue', 'slowstart' and 'weight'.\n", file, linenum, newsrv->id); return -1; } @@ -2904,6 +2909,19 @@ int readcfgfile(const char *file) if (curproxy->options & PR_O_LOGASAP) curproxy->to_log &= ~LW_BYTES; + /* + * ensure that we're not cross-dressing a TCP server into HTTP. + */ + newsrv = curproxy->srv; + while (newsrv != NULL) { + if ((curproxy->mode != PR_MODE_HTTP) && (newsrv->rdr_len || newsrv->cklen)) { + Alert("parsing %s, %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", + file, proxy_type_str(curproxy), curproxy->id, linenum); + goto err; + } + newsrv = newsrv->next; + } + /* * If this server supports a maxconn parameter, it needs a dedicated * tasks to fill the emptied slots when a connection leaves.