*sap = NULL;
}
+/* returns 0 if the connection is valid and is a frontend connection, otherwise
+ * returns 1 indicating it's a backend connection. And uninitialized connection
+ * also returns 1 to better handle the usage in the middle of initialization.
+ */
+static inline int conn_is_back(const struct connection *conn)
+{
+ return !objt_listener(conn->target);
+}
+
/* Tries to allocate a new connection and initialized its main fields. The
* connection is returned on success, NULL on failure. The connection must
* be released using pool_free() or conn_free().
conn_init(conn, target);
- if (obj_type(target) == OBJ_TYPE_SERVER) {
- srv_use_conn(__objt_server(target), conn);
+ if (conn_is_back(conn)) {
+ if (obj_type(target) == OBJ_TYPE_SERVER)
+ srv_use_conn(__objt_server(target), conn);
hash_node = conn_alloc_hash_node(conn);
if (unlikely(!hash_node)) {
return item ? item->mux : NULL;
}
-/* returns 0 if the connection is valid and is a frontend connection, otherwise
- * returns 1 indicating it's a backend connection. And uninitialized connection
- * also returns 1 to better handle the usage in the middle of initialization.
- */
-static inline int conn_is_back(const struct connection *conn)
-{
- return !objt_listener(conn->target);
-}
-
/* returns a pointer to the proxy associated with this connection. For a front
* connection it returns a pointer to the frontend ; for a back connection, it
* returns a pointer to the backend.
int64_t hash = 0;
struct conn_hash_params hash_params;
+ /* in standard configuration, srv will be valid
+ * it can be NULL for dispatch mode or transparent backend */
+ srv = objt_server(s->target);
+
/* first, set unique connection parameters and then calculate hash */
memset(&hash_params, 0, sizeof(hash_params));
- srv = objt_server(s->target);
- hash_params.srv = srv;
+ /* 1. target */
+ hash_params.target = s->target;
#ifdef USE_OPENSSL
- /* 1. sni */
+ /* 2. sni */
if (srv && srv->ssl_ctx.sni) {
sni_smp = sample_fetch_as_type(s->be, s->sess, s,
SMP_OPT_DIR_REQ | SMP_OPT_FINAL,
}
#endif /* USE_OPENSSL */
- /* 2. destination address */
+ /* 3. destination address */
if (!(s->flags & SF_ADDR_SET)) {
err = alloc_dst_address(&s->target_addr, srv, s);
if (err != SRV_STATUS_OK)
if (srv && (!is_addr(&srv->addr) || srv->flags & SRV_F_MAPPORTS))
hash_params.dst_addr = s->target_addr;
- /* 3. source address */
+ /* 4. source address */
err = alloc_bind_address(&bind_addr, srv, s);
if (err != SRV_STATUS_OK)
return SF_ERR_INTERNAL;
hash_params.src_addr = bind_addr;
- /* 4. proxy protocol */
+ /* 5. proxy protocol */
if (srv && srv->pp_opts) {
proxy_line_ret = make_proxy_line(trash.area, trash.size, srv, cli_conn, s);
if (proxy_line_ret) {
}
}
- if (srv)
- hash = conn_calculate_hash(&hash_params);
+ hash = conn_calculate_hash(&hash_params);
/* This will catch some corner cases such as lying connections resulting from
* retries or connect timeouts but will rarely trigger.
if (srv_conn) {
srv_conn->owner = s->sess;
- if (reuse_mode == PR_O_REUSE_NEVR)
+
+ /* connection will be attached to the session if
+ * http-reuse mode is never or it is not targeted to a
+ * server */
+ if (reuse_mode == PR_O_REUSE_NEVR || !srv)
conn_set_private(srv_conn);
/* assign bind_addr to srv_conn */
}
}
- if (srv)
- srv_conn->hash_node->hash = hash;
+ srv_conn->hash_node->hash = hash;
return SF_ERR_NONE; /* connection is OK */
}
buf = trash.area;
- conn_hash_update(buf, &idx, ¶ms->srv, sizeof(params->srv), &hash_flags, 0);
+ conn_hash_update(buf, &idx, ¶ms->target, sizeof(params->target), &hash_flags, 0);
if (params->sni_prehash) {
conn_hash_update(buf, &idx,