--- ./haproxy.c~ Sat Nov 27 13:57:54 2004 +++ ./haproxy.c Sat Nov 27 14:46:27 2004 @@ -2924,24 +2924,32 @@ /* Cool... it's the right one */ struct server *srv = t->proxy->srv; - while (srv && - ((srv->cklen != p4 - p3) || memcmp(p3, srv->cookie, p4 - p3))) { + /* Here, we'll look for the first running server which supports the cookie. + * This allows to share a same cookie between several servers, for example + * to dedicate backup servers to specific servers only. + */ + while (srv) { + if ((srv->cklen == p4 - p3) && !memcmp(p3, srv->cookie, p4 - p3)) { + if (srv->state & SRV_RUNNING || t->proxy->options & PR_O_PERSIST) { + /* we found the server and it's usable */ + t->flags &= ~SN_CK_MASK; + t->flags |= SN_CK_VALID | SN_DIRECT; + t->srv = srv; + break; + } + else { + /* we found a server, but it's down */ + t->flags &= ~SN_CK_MASK; + t->flags |= SN_CK_DOWN; + } + } srv = srv->next; } - if (!srv) { + if (!srv && !(t->flags & SN_CK_DOWN)) { + /* no server matched this cookie */ t->flags &= ~SN_CK_MASK; t->flags |= SN_CK_INVALID; - } - else if (srv->state & SRV_RUNNING || t->proxy->options & PR_O_PERSIST) { - /* we found the server and it's usable */ - t->flags &= ~SN_CK_MASK; - t->flags |= SN_CK_VALID | SN_DIRECT; - t->srv = srv; - } - else { - t->flags &= ~SN_CK_MASK; - t->flags |= SN_CK_DOWN; } /* if this cookie was set in insert+indirect mode, then it's better that the