* It is illegal to call this function with a session in a queue.
*
* It may return :
- * SRV_STATUS_OK if everything is OK. Session assigned to ->srv
+ * SRV_STATUS_OK if everything is OK. ->srv and ->target are assigned.
* SRV_STATUS_NOSRV if no server is available. Session is not ASSIGNED
* SRV_STATUS_FULL if all servers are saturated. Session is not ASSIGNED
* SRV_STATUS_INTERNAL for other unrecoverable errors.
*/
s->srv = NULL;
+ s->target.type = TARG_TYPE_NONE;
+ s->target.ptr.v = NULL;
+
if (s->be->lbprm.algo & BE_LB_KIND) {
int len;
/* we must check if we have at least one server available */
s->be->counters.cum_lbconn++;
s->srv->counters.cum_lbconn++;
}
+
+ s->target.type = TARG_TYPE_SERVER;
+ s->target.ptr.s = s->srv;
}
- else if (s->be->options & PR_O_HTTP_PROXY) {
- if (!s->req->cons->addr.s.to.sin_addr.s_addr) {
- err = SRV_STATUS_NOSRV;
- goto out;
- }
+ else if ((s->be->options2 & PR_O2_DISPATCH) || (s->be->options & PR_O_TRANSP)) {
+ s->target.type = TARG_TYPE_PROXY;
+ s->target.ptr.p = s->be;
+ }
+ else if ((s->be->options & PR_O_HTTP_PROXY) && s->req->cons->addr.s.to.sin_addr.s_addr) {
+ /* in proxy mode, we need a valid destination address */
+ s->target.type = TARG_TYPE_PROXY;
+ s->target.ptr.p = s->be;
}
- else if (!(s->be->options2 & PR_O2_DISPATCH) && !(s->be->options & PR_O_TRANSP)) {
+ else {
err = SRV_STATUS_NOSRV;
goto out;
}
/*
* This function initiates a connection to the server assigned to this session
- * (s->srv, s->req->cons->addr.s.to). It will assign a server if none is assigned yet.
+ * (s->srv, s->target, s->req->cons->addr.s.to). It will assign a server if none
+ * is assigned yet.
* It can return one of :
* - SN_ERR_NONE if everything's OK
* - SN_ERR_SRVTO if there are no more servers
/* Prepare the stream interface for a TCP connection. Later
* we may assign a protocol-specific connect() function.
+ * NOTE: when we later support HTTP keep-alive, we'll have to
+ * decide here if we can reuse the connection by comparing the
+ * session's freshly assigned target with the stream interface's.
*/
stream_sock_prepare_interface(s->req->cons);
s->req->cons->connect = tcpv4_connect_server;
- if (s->srv) {
- s->req->cons->target.type = TARG_TYPE_SERVER;
- s->req->cons->target.ptr.s = s->srv;
- } else {
- s->req->cons->target.type = TARG_TYPE_PROXY;
- s->req->cons->target.ptr.p = s->be;
- }
+ s->req->cons->target = s->target;
assign_tproxy_address(s);
if (*p != '.')
goto no_cookie;
+ s->target.type = TARG_TYPE_NONE;
+ s->target.ptr.v = NULL;
while (srv) {
if (memcmp(&addr, &(srv->addr), sizeof(addr)) == 0) {
if ((srv->state & SRV_RUNNING) || (px->options & PR_O_PERSIST)) {
/* we found the server and it is usable */
s->flags |= SN_DIRECT | SN_ASSIGNED;
s->srv = srv;
+ s->target.type = TARG_TYPE_SERVER;
+ s->target.ptr.s = s->srv;
break;
}
}
if (unlikely(s->srv_conn))
sess_change_server(s, NULL);
s->srv = NULL;
+ s->target.type = TARG_TYPE_NONE;
+ s->target.ptr.v = NULL;
s->req->cons->state = s->req->cons->prev_state = SI_ST_INI;
s->req->cons->fd = -1; /* just to help with debugging */
txn->flags |= (srv->state & SRV_RUNNING) ? TX_CK_VALID : TX_CK_DOWN;
t->flags |= SN_DIRECT | SN_ASSIGNED;
t->srv = srv;
+ t->target.type = TARG_TYPE_SERVER;
+ t->target.ptr.s = srv;
+
break;
} else {
txn->flags &= ~TX_CK_MASK;
txn->flags |= (srv->state & SRV_RUNNING) ? TX_CK_VALID : TX_CK_DOWN;
t->flags |= SN_DIRECT | SN_ASSIGNED;
t->srv = srv;
+ t->target.type = TARG_TYPE_SERVER;
+ t->target.ptr.s = srv;
break;
} else {
/* we found a server, but it's down,
s->be = s->fe;
s->logs.logwait = s->fe->to_log;
s->srv = s->prev_srv = s->srv_conn = NULL;
+ s->target.type = TARG_TYPE_NONE;
+ s->target.ptr.v = NULL;
/* re-init store persistence */
s->store_count = 0;