MAJOR: connection: replace struct target with a pointer to an enum

Instead of storing a couple of (int, ptr) in the struct connection
and the struct session, we use a different method : we only store a
pointer to an integer which is stored inside the target object and
which contains a unique type identifier. That way, the pointer allows
us to retrieve the object type (by dereferencing it) and the object's
address (by computing the displacement in the target structure). The
NULL pointer always corresponds to OBJ_TYPE_NONE.

This reduces the size of the connection and session structs. It also
simplifies target assignment and compare.

In order to improve the generated code, we try to put the obj_type
element at the beginning of all the structs (listener, server, proxy,
si_applet), so that the original and target pointers are always equal.

A lot of code was touched by massive replaces, but the changes are not
that important.
This commit is contained in:
Willy Tarreau 2012-11-12 00:42:33 +01:00
parent 128b03c9ab
commit 3fdb366885
22 changed files with 332 additions and 266 deletions

View File

@ -26,6 +26,7 @@
#include <common/memory.h> #include <common/memory.h>
#include <types/connection.h> #include <types/connection.h>
#include <types/listener.h> #include <types/listener.h>
#include <proto/obj_type.h>
extern struct pool_head *pool2_connection; extern struct pool_head *pool2_connection;
@ -375,61 +376,6 @@ static inline int conn_sock_shutw_pending(struct connection *c)
return (c->flags & (CO_FL_DATA_WR_SH | CO_FL_SOCK_WR_SH)) == CO_FL_DATA_WR_SH; return (c->flags & (CO_FL_DATA_WR_SH | CO_FL_SOCK_WR_SH)) == CO_FL_DATA_WR_SH;
} }
static inline void clear_target(struct target *dest)
{
dest->type = TARG_TYPE_NONE;
dest->ptr.v = NULL;
}
static inline void set_target_client(struct target *dest, struct listener *l)
{
dest->type = TARG_TYPE_CLIENT;
dest->ptr.l = l;
}
static inline void set_target_server(struct target *dest, struct server *s)
{
dest->type = TARG_TYPE_SERVER;
dest->ptr.s = s;
}
static inline void set_target_proxy(struct target *dest, struct proxy *p)
{
dest->type = TARG_TYPE_PROXY;
dest->ptr.p = p;
}
static inline void set_target_applet(struct target *dest, struct si_applet *a)
{
dest->type = TARG_TYPE_APPLET;
dest->ptr.a = a;
}
static inline struct target *copy_target(struct target *dest, struct target *src)
{
*dest = *src;
return dest;
}
static inline int target_match(struct target *a, struct target *b)
{
return a->type == b->type && a->ptr.v == b->ptr.v;
}
static inline struct server *target_srv(struct target *t)
{
if (!t || t->type != TARG_TYPE_SERVER)
return NULL;
return t->ptr.s;
}
static inline struct listener *target_client(struct target *t)
{
if (!t || t->type != TARG_TYPE_CLIENT)
return NULL;
return t->ptr.l;
}
/* Retrieves the connection's source address */ /* Retrieves the connection's source address */
static inline void conn_get_from_addr(struct connection *conn) static inline void conn_get_from_addr(struct connection *conn)
{ {
@ -441,7 +387,7 @@ static inline void conn_get_from_addr(struct connection *conn)
if (conn->ctrl->get_src(conn->t.sock.fd, (struct sockaddr *)&conn->addr.from, if (conn->ctrl->get_src(conn->t.sock.fd, (struct sockaddr *)&conn->addr.from,
sizeof(conn->addr.from), sizeof(conn->addr.from),
conn->target.type != TARG_TYPE_CLIENT) == -1) obj_type(conn->target) != OBJ_TYPE_LISTENER) == -1)
return; return;
conn->flags |= CO_FL_ADDR_FROM_SET; conn->flags |= CO_FL_ADDR_FROM_SET;
} }
@ -457,7 +403,7 @@ static inline void conn_get_to_addr(struct connection *conn)
if (conn->ctrl->get_dst(conn->t.sock.fd, (struct sockaddr *)&conn->addr.to, if (conn->ctrl->get_dst(conn->t.sock.fd, (struct sockaddr *)&conn->addr.to,
sizeof(conn->addr.to), sizeof(conn->addr.to),
conn->target.type != TARG_TYPE_CLIENT) == -1) obj_type(conn->target) != OBJ_TYPE_LISTENER) == -1)
return; return;
conn->flags |= CO_FL_ADDR_TO_SET; conn->flags |= CO_FL_ADDR_TO_SET;
} }

75
include/proto/obj_type.h Normal file
View File

@ -0,0 +1,75 @@
/*
* include/proto/obj_type.h
* This file contains function prototypes to manipulate object types
*
* Copyright (C) 2000-2012 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
* License as published by the Free Software Foundation, version 2.1
* exclusively.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _PROTO_OBJ_TYPE_H
#define _PROTO_OBJ_TYPE_H
#include <common/config.h>
#include <common/memory.h>
#include <types/listener.h>
#include <types/obj_type.h>
#include <types/proxy.h>
#include <types/server.h>
#include <types/stream_interface.h>
static inline enum obj_type obj_type(enum obj_type *t)
{
if (!t || *t > OBJ_TYPE_APPLET)
return OBJ_TYPE_NONE;
return *t;
}
static inline struct listener *objt_listener(enum obj_type *t)
{
if (!t || *t != OBJ_TYPE_LISTENER)
return NULL;
return container_of(t, struct listener, obj_type);
}
static inline struct proxy *objt_proxy(enum obj_type *t)
{
if (!t || *t != OBJ_TYPE_PROXY)
return NULL;
return container_of(t, struct proxy, obj_type);
}
static inline struct server *objt_server(enum obj_type *t)
{
if (!t || *t != OBJ_TYPE_SERVER)
return NULL;
return container_of(t, struct server, obj_type);
}
static inline struct si_applet *objt_applet(enum obj_type *t)
{
if (!t || *t != OBJ_TYPE_APPLET)
return NULL;
return container_of(t, struct si_applet, obj_type);
}
#endif /* _PROTO_OBJ_TYPE_H */
/*
* Local variables:
* c-indent-level: 8
* c-basic-offset: 8
* End:
*/

View File

@ -28,6 +28,7 @@
#include <common/config.h> #include <common/config.h>
#include <types/listener.h> #include <types/listener.h>
#include <types/obj_type.h>
#include <types/protocol.h> #include <types/protocol.h>
/* referenced below */ /* referenced below */
@ -141,16 +142,6 @@ enum {
CO_FL_XPRT_TRACKED = 0x80000000, CO_FL_XPRT_TRACKED = 0x80000000,
}; };
/* target types */
enum {
TARG_TYPE_NONE = 0, /* no target set, pointer is NULL by definition */
TARG_TYPE_CLIENT, /* target is a client, pointer is NULL by definition */
TARG_TYPE_PROXY, /* target is a proxy ; use address with the proxy's settings */
TARG_TYPE_SERVER, /* target is a server ; use address with server's and its proxy's settings */
TARG_TYPE_APPLET, /* target is an applet ; use only the applet */
};
/* xprt_ops describes transport-layer operations for a connection. They /* xprt_ops describes transport-layer operations for a connection. They
* generally run over a socket-based control layer, but not always. Some * generally run over a socket-based control layer, but not always. Some
* of them are used for data transfer with the upper layer (rcv_*, snd_*) * of them are used for data transfer with the upper layer (rcv_*, snd_*)
@ -184,18 +175,6 @@ struct data_cb {
int (*init)(struct connection *conn); /* data-layer initialization */ int (*init)(struct connection *conn); /* data-layer initialization */
}; };
/* a target describes what is on the remote side of the connection. */
struct target {
int type;
union {
void *v; /* pointer value, for any type */
struct proxy *p; /* when type is TARG_TYPE_PROXY */
struct server *s; /* when type is TARG_TYPE_SERVER */
struct si_applet *a; /* when type is TARG_TYPE_APPLET */
struct listener *l; /* when type is TARG_TYPE_CLIENT */
} ptr;
} __attribute__((packed));
/* This structure describes a connection with its methods and data. /* This structure describes a connection with its methods and data.
* A connection may be performed to proxy or server via a local or remote * A connection may be performed to proxy or server via a local or remote
* socket, and can also be made to an internal applet. It can support * socket, and can also be made to an internal applet. It can support
@ -216,7 +195,7 @@ struct connection {
int fd; /* file descriptor for a stream driver when known */ int fd; /* file descriptor for a stream driver when known */
} sock; } sock;
} t; } t;
struct target target; /* the target to connect to (server, proxy, applet, ...) */ enum obj_type *target; /* the target to connect to (server, proxy, applet, ...) */
struct { struct {
struct sockaddr_storage from; /* client address, or address to spoof when connecting to the server */ struct sockaddr_storage from; /* client address, or address to spoof when connecting to the server */
struct sockaddr_storage to; /* address reached by the client, or address to connect to */ struct sockaddr_storage to; /* address reached by the client, or address to connect to */

View File

@ -31,6 +31,7 @@
#include <common/config.h> #include <common/config.h>
#include <common/mini-clist.h> #include <common/mini-clist.h>
#include <types/obj_type.h>
#include <eb32tree.h> #include <eb32tree.h>
/* Some pointer types reference below */ /* Some pointer types reference below */
@ -146,6 +147,7 @@ struct bind_conf {
* the fdtab. * the fdtab.
*/ */
struct listener { struct listener {
enum obj_type obj_type; /* object type = OBJ_TYPE_LISTENER */
int fd; /* the listen socket */ int fd; /* the listen socket */
char *name; /* */ char *name; /* */
int luid; /* listener universally unique ID, used for SNMP */ int luid; /* listener universally unique ID, used for SNMP */

49
include/types/obj_type.h Normal file
View File

@ -0,0 +1,49 @@
/*
* include/types/obj_type.h
* This file declares some object types for use in various structures.
*
* Copyright (C) 2000-2012 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
* License as published by the Free Software Foundation, version 2.1
* exclusively.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _TYPES_OBJ_TYPE_H
#define _TYPES_OBJ_TYPE_H
/* The principle is to be able to change the type of a pointer by pointing
* it directly to an object type. The object type indicates the format of the
* structure holing the type, and this is used to retrieve the pointer to the
* beginning of the structure. Doing so saves us from having to maintain both
* a pointer and a type for elements such as connections which can point to
* various types of objects.
*/
/* object types */
enum obj_type {
OBJ_TYPE_NONE = 0, /* pointer is NULL by definition */
OBJ_TYPE_LISTENER, /* object is a struct listener */
OBJ_TYPE_PROXY, /* object is a struct proxy */
OBJ_TYPE_SERVER, /* object is a struct server */
OBJ_TYPE_APPLET, /* object is a struct si_applet */
};
#endif /* _TYPES_OBJ_TYPE_H */
/*
* Local variables:
* c-indent-level: 8
* c-basic-offset: 8
* End:
*/

View File

@ -42,6 +42,7 @@
#include <types/freq_ctr.h> #include <types/freq_ctr.h>
#include <types/listener.h> #include <types/listener.h>
#include <types/log.h> #include <types/log.h>
#include <types/obj_type.h>
#include <types/proto_http.h> #include <types/proto_http.h>
#include <types/sample.h> #include <types/sample.h>
#include <types/session.h> #include <types/session.h>
@ -200,10 +201,11 @@ struct error_snapshot {
}; };
struct proxy { struct proxy {
struct in_addr mon_net, mon_mask; /* don't forward connections from this net (network order) FIXME: should support IPv6 */ enum obj_type obj_type; /* object type == OBJ_TYPE_PROXY */
int state; /* proxy state */ int state; /* proxy state */
int options; /* PR_O_REDISP, PR_O_TRANSP, ... */ int options; /* PR_O_REDISP, PR_O_TRANSP, ... */
int options2; /* PR_O2_* */ int options2; /* PR_O2_* */
struct in_addr mon_net, mon_mask; /* don't forward connections from this net (network order) FIXME: should support IPv6 */
unsigned int ck_opts; /* PR_CK_* (cookie options) */ unsigned int ck_opts; /* PR_CK_* (cookie options) */
unsigned int fe_req_ana, be_req_ana; /* bitmap of common request protocol analysers for the frontend and backend */ unsigned int fe_req_ana, be_req_ana; /* bitmap of common request protocol analysers for the frontend and backend */
unsigned int fe_rsp_ana, be_rsp_ana; /* bitmap of common response protocol analysers for the frontend and backend */ unsigned int fe_rsp_ana, be_rsp_ana; /* bitmap of common response protocol analysers for the frontend and backend */

View File

@ -36,6 +36,7 @@
#include <types/connection.h> #include <types/connection.h>
#include <types/counters.h> #include <types/counters.h>
#include <types/freq_ctr.h> #include <types/freq_ctr.h>
#include <types/obj_type.h>
#include <types/port_range.h> #include <types/port_range.h>
#include <types/proxy.h> #include <types/proxy.h>
#include <types/queue.h> #include <types/queue.h>
@ -107,6 +108,7 @@ struct tree_occ {
}; };
struct server { struct server {
enum obj_type obj_type; /* object type == OBJ_TYPE_SERVER */
struct server *next; struct server *next;
int state; /* server state (SRV_*) */ int state; /* server state (SRV_*) */
int prev_state; /* server state before last change (SRV_*) */ int prev_state; /* server state before last change (SRV_*) */

View File

@ -34,6 +34,7 @@
#include <types/channel.h> #include <types/channel.h>
#include <types/compression.h> #include <types/compression.h>
#include <types/obj_type.h>
#include <types/proto_http.h> #include <types/proto_http.h>
#include <types/proxy.h> #include <types/proxy.h>
#include <types/queue.h> #include <types/queue.h>
@ -99,15 +100,14 @@
* immediately assigned when SN_DIRECT is determined. Both must be cleared * immediately assigned when SN_DIRECT is determined. Both must be cleared
* when clearing SN_DIRECT (eg: redispatch). * when clearing SN_DIRECT (eg: redispatch).
* - ->srv has no meaning without SN_ASSIGNED and must not be checked without * - ->srv has no meaning without SN_ASSIGNED and must not be checked without
* it. ->target and ->target_type may be used to check previous ->srv after * it. ->target may be used to check previous ->srv after a failed connection attempt.
* a failed connection attempt.
* - a session being processed has srv_conn set. * - a session being processed has srv_conn set.
* - srv_conn might remain after SN_DIRECT has been reset, but the assigned * - srv_conn might remain after SN_DIRECT has been reset, but the assigned
* server should eventually be released. * server should eventually be released.
*/ */
struct session { struct session {
int flags; /* some flags describing the session */ int flags; /* some flags describing the session */
struct target target; /* target to use for this session */ enum obj_type *target; /* target to use for this session */
struct channel *req; /* request buffer */ struct channel *req; /* request buffer */
struct channel *rep; /* response buffer */ struct channel *rep; /* response buffer */

View File

@ -27,6 +27,7 @@
#include <types/channel.h> #include <types/channel.h>
#include <types/connection.h> #include <types/connection.h>
#include <types/obj_type.h>
#include <common/config.h> #include <common/config.h>
/* A stream interface must have its own errors independently of the buffer's, /* A stream interface must have its own errors independently of the buffer's,
@ -160,6 +161,7 @@ struct stream_interface {
/* An applet designed to run in a stream interface */ /* An applet designed to run in a stream interface */
struct si_applet { struct si_applet {
enum obj_type obj_type; /* object type = OBJ_TYPE_APPLET */
char *name; /* applet's name to report in logs */ char *name; /* applet's name to report in logs */
void (*fct)(struct stream_interface *); /* internal I/O handler, may never be NULL */ void (*fct)(struct stream_interface *); /* internal I/O handler, may never be NULL */
void (*release)(struct stream_interface *); /* callback to release resources, may be NULL */ void (*release)(struct stream_interface *); /* callback to release resources, may be NULL */

View File

@ -38,6 +38,7 @@
#include <proto/lb_fwlc.h> #include <proto/lb_fwlc.h>
#include <proto/lb_fwrr.h> #include <proto/lb_fwrr.h>
#include <proto/lb_map.h> #include <proto/lb_map.h>
#include <proto/obj_type.h>
#include <proto/protocol.h> #include <proto/protocol.h>
#include <proto/proto_http.h> #include <proto/proto_http.h>
#include <proto/proto_tcp.h> #include <proto/proto_tcp.h>
@ -489,7 +490,7 @@ int assign_server(struct session *s)
if (unlikely(s->pend_pos || s->flags & SN_ASSIGNED)) if (unlikely(s->pend_pos || s->flags & SN_ASSIGNED))
goto out_err; goto out_err;
prev_srv = target_srv(&s->target); prev_srv = objt_server(s->target);
conn_slot = s->srv_conn; conn_slot = s->srv_conn;
/* We have to release any connection slot before applying any LB algo, /* We have to release any connection slot before applying any LB algo,
@ -498,13 +499,13 @@ int assign_server(struct session *s)
if (conn_slot) if (conn_slot)
sess_change_server(s, NULL); sess_change_server(s, NULL);
/* We will now try to find the good server and store it into <target_srv(&s->target)>. /* We will now try to find the good server and store it into <objt_server(s->target)>.
* Note that <target_srv(&s->target)> may be NULL in case of dispatch or proxy mode, * Note that <objt_server(s->target)> may be NULL in case of dispatch or proxy mode,
* as well as if no server is available (check error code). * as well as if no server is available (check error code).
*/ */
srv = NULL; srv = NULL;
clear_target(&s->target); s->target = NULL;
if (s->be->lbprm.algo & BE_LB_KIND) { if (s->be->lbprm.algo & BE_LB_KIND) {
/* we must check if we have at least one server available */ /* we must check if we have at least one server available */
@ -631,15 +632,15 @@ int assign_server(struct session *s)
s->be->be_counters.cum_lbconn++; s->be->be_counters.cum_lbconn++;
srv->counters.cum_lbconn++; srv->counters.cum_lbconn++;
} }
set_target_server(&s->target, srv); s->target = &srv->obj_type;
} }
else if (s->be->options & (PR_O_DISPATCH | PR_O_TRANSP)) { else if (s->be->options & (PR_O_DISPATCH | PR_O_TRANSP)) {
set_target_proxy(&s->target, s->be); s->target = &s->be->obj_type;
} }
else if ((s->be->options & PR_O_HTTP_PROXY) && else if ((s->be->options & PR_O_HTTP_PROXY) &&
is_addr(&s->req->cons->conn->addr.to)) { is_addr(&s->req->cons->conn->addr.to)) {
/* in proxy mode, we need a valid destination address */ /* in proxy mode, we need a valid destination address */
set_target_proxy(&s->target, s->be); s->target = &s->be->obj_type;
} }
else { else {
err = SRV_STATUS_NOSRV; err = SRV_STATUS_NOSRV;
@ -691,7 +692,7 @@ int assign_server_address(struct session *s)
if (!(s->flags & SN_ASSIGNED)) if (!(s->flags & SN_ASSIGNED))
return SRV_STATUS_INTERNAL; return SRV_STATUS_INTERNAL;
s->req->cons->conn->addr.to = target_srv(&s->target)->addr; s->req->cons->conn->addr.to = objt_server(s->target)->addr;
if (!is_addr(&s->req->cons->conn->addr.to)) { if (!is_addr(&s->req->cons->conn->addr.to)) {
/* if the server has no address, we use the same address /* if the server has no address, we use the same address
@ -710,7 +711,7 @@ int assign_server_address(struct session *s)
/* if this server remaps proxied ports, we'll use /* if this server remaps proxied ports, we'll use
* the port the client connected to with an offset. */ * the port the client connected to with an offset. */
if (target_srv(&s->target)->state & SRV_MAPPORTS) { if (objt_server(s->target)->state & SRV_MAPPORTS) {
int base_port; int base_port;
if (!(s->be->options & PR_O_TRANSP)) if (!(s->be->options & PR_O_TRANSP))
@ -764,7 +765,7 @@ int assign_server_address(struct session *s)
* Returns : * Returns :
* *
* SRV_STATUS_OK if everything is OK. * SRV_STATUS_OK if everything is OK.
* SRV_STATUS_NOSRV if no server is available. target_srv(&s->target) = NULL. * SRV_STATUS_NOSRV if no server is available. objt_server(s->target) = NULL.
* SRV_STATUS_QUEUED if the connection has been queued. * SRV_STATUS_QUEUED if the connection has been queued.
* SRV_STATUS_FULL if the server(s) is/are saturated and the * SRV_STATUS_FULL if the server(s) is/are saturated and the
* connection could not be queued at the server's, * connection could not be queued at the server's,
@ -783,7 +784,7 @@ int assign_server_and_queue(struct session *s)
err = SRV_STATUS_OK; err = SRV_STATUS_OK;
if (!(s->flags & SN_ASSIGNED)) { if (!(s->flags & SN_ASSIGNED)) {
struct server *prev_srv = target_srv(&s->target); struct server *prev_srv = objt_server(s->target);
err = assign_server(s); err = assign_server(s);
if (prev_srv) { if (prev_srv) {
@ -796,7 +797,7 @@ int assign_server_and_queue(struct session *s)
* - if the server remained the same : update retries. * - if the server remained the same : update retries.
*/ */
if (prev_srv != target_srv(&s->target)) { if (prev_srv != objt_server(s->target)) {
if ((s->txn.flags & TX_CK_MASK) == TX_CK_VALID) { if ((s->txn.flags & TX_CK_MASK) == TX_CK_VALID) {
s->txn.flags &= ~TX_CK_MASK; s->txn.flags &= ~TX_CK_MASK;
s->txn.flags |= TX_CK_DOWN; s->txn.flags |= TX_CK_DOWN;
@ -814,7 +815,7 @@ int assign_server_and_queue(struct session *s)
switch (err) { switch (err) {
case SRV_STATUS_OK: case SRV_STATUS_OK:
/* we have SN_ASSIGNED set */ /* we have SN_ASSIGNED set */
srv = target_srv(&s->target); srv = objt_server(s->target);
if (!srv) if (!srv)
return SRV_STATUS_OK; /* dispatch or proxy mode */ return SRV_STATUS_OK; /* dispatch or proxy mode */
@ -882,7 +883,7 @@ int assign_server_and_queue(struct session *s)
static void assign_tproxy_address(struct session *s) static void assign_tproxy_address(struct session *s)
{ {
#if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY)
struct server *srv = target_srv(&s->target); struct server *srv = objt_server(s->target);
if (srv && srv->state & SRV_BIND_SRC) { if (srv && srv->state & SRV_BIND_SRC) {
switch (srv->state & SRV_TPROXY_MASK) { switch (srv->state & SRV_TPROXY_MASK) {
@ -981,13 +982,13 @@ int connect_server(struct session *s)
} }
/* the target was only on the session, assign it to the SI now */ /* the target was only on the session, assign it to the SI now */
copy_target(&s->req->cons->conn->target, &s->target); s->req->cons->conn->target = s->target;
/* set the correct protocol on the output stream interface */ /* set the correct protocol on the output stream interface */
if (s->target.type == TARG_TYPE_SERVER) { if (objt_server(s->target)) {
si_prepare_conn(s->req->cons, target_srv(&s->target)->proto, target_srv(&s->target)->xprt); si_prepare_conn(s->req->cons, objt_server(s->target)->proto, objt_server(s->target)->xprt);
} }
else if (s->target.type == TARG_TYPE_PROXY) { else if (obj_type(s->target) == OBJ_TYPE_PROXY) {
/* proxies exclusively run on raw_sock right now */ /* proxies exclusively run on raw_sock right now */
si_prepare_conn(s->req->cons, protocol_by_family(s->req->cons->conn->addr.to.ss_family), &raw_sock); si_prepare_conn(s->req->cons, protocol_by_family(s->req->cons->conn->addr.to.ss_family), &raw_sock);
if (!si_ctrl(s->req->cons)) if (!si_ctrl(s->req->cons))
@ -998,7 +999,7 @@ int connect_server(struct session *s)
/* process the case where the server requires the PROXY protocol to be sent */ /* process the case where the server requires the PROXY protocol to be sent */
s->req->cons->send_proxy_ofs = 0; s->req->cons->send_proxy_ofs = 0;
if (s->target.type == TARG_TYPE_SERVER && (s->target.ptr.s->state & SRV_SEND_PROXY)) { if (objt_server(s->target) && (objt_server(s->target)->state & SRV_SEND_PROXY)) {
s->req->cons->send_proxy_ofs = 1; /* must compute size */ s->req->cons->send_proxy_ofs = 1; /* must compute size */
conn_get_to_addr(s->req->prod->conn); conn_get_to_addr(s->req->prod->conn);
} }
@ -1021,7 +1022,7 @@ int connect_server(struct session *s)
/* set connect timeout */ /* set connect timeout */
s->req->cons->exp = tick_add_ifset(now_ms, s->be->timeout.connect); s->req->cons->exp = tick_add_ifset(now_ms, s->be->timeout.connect);
srv = target_srv(&s->target); srv = objt_server(s->target);
if (srv) { if (srv) {
s->flags |= SN_CURR_SESS; s->flags |= SN_CURR_SESS;
srv->cur_sess++; srv->cur_sess++;
@ -1053,7 +1054,7 @@ int srv_redispatch_connect(struct session *t)
*/ */
redispatch: redispatch:
conn_err = assign_server_and_queue(t); conn_err = assign_server_and_queue(t);
srv = target_srv(&t->target); srv = objt_server(t->target);
switch (conn_err) { switch (conn_err) {
case SRV_STATUS_OK: case SRV_STATUS_OK:
@ -1173,13 +1174,13 @@ int tcp_persist_rdp_cookie(struct session *s, struct channel *req, int an_bit)
if (*p != '.') if (*p != '.')
goto no_cookie; goto no_cookie;
clear_target(&s->target); s->target = NULL;
while (srv) { while (srv) {
if (memcmp(&addr, &(srv->addr), sizeof(addr)) == 0) { if (memcmp(&addr, &(srv->addr), sizeof(addr)) == 0) {
if ((srv->state & SRV_RUNNING) || (px->options & PR_O_PERSIST)) { if ((srv->state & SRV_RUNNING) || (px->options & PR_O_PERSIST)) {
/* we found the server and it is usable */ /* we found the server and it is usable */
s->flags |= SN_DIRECT | SN_ASSIGNED; s->flags |= SN_DIRECT | SN_ASSIGNED;
set_target_server(&s->target, srv); s->target = &srv->obj_type;
break; break;
} }
} }
@ -1488,11 +1489,11 @@ static int
acl_fetch_srv_id(struct proxy *px, struct session *l4, void *l7, unsigned int opt, acl_fetch_srv_id(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
const struct arg *args, struct sample *smp) const struct arg *args, struct sample *smp)
{ {
if (!target_srv(&l4->target)) if (!objt_server(l4->target))
return 0; return 0;
smp->type = SMP_T_UINT; smp->type = SMP_T_UINT;
smp->data.uint = target_srv(&l4->target)->puid; smp->data.uint = objt_server(l4->target)->puid;
return 1; return 1;
} }

View File

@ -35,6 +35,7 @@
#include <types/capture.h> #include <types/capture.h>
#include <types/compression.h> #include <types/compression.h>
#include <types/global.h> #include <types/global.h>
#include <types/obj_type.h>
#include <types/peers.h> #include <types/peers.h>
#include <proto/acl.h> #include <proto/acl.h>
@ -265,6 +266,7 @@ int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf,
for (; port <= end; port++) { for (; port <= end; port++) {
l = (struct listener *)calloc(1, sizeof(struct listener)); l = (struct listener *)calloc(1, sizeof(struct listener));
l->obj_type = OBJ_TYPE_LISTENER;
LIST_ADDQ(&curproxy->conf.listeners, &l->by_fe); LIST_ADDQ(&curproxy->conf.listeners, &l->by_fe);
LIST_ADDQ(&bind_conf->listeners, &l->by_bind); LIST_ADDQ(&bind_conf->listeners, &l->by_bind);
l->frontend = curproxy; l->frontend = curproxy;
@ -4034,6 +4036,7 @@ stats_error_parsing:
newsrv->conf.file = strdup(file); newsrv->conf.file = strdup(file);
newsrv->conf.line = linenum; newsrv->conf.line = linenum;
newsrv->obj_type = OBJ_TYPE_SERVER;
LIST_INIT(&newsrv->actconns); LIST_INIT(&newsrv->actconns);
LIST_INIT(&newsrv->pendconns); LIST_INIT(&newsrv->pendconns);
do_check = 0; do_check = 0;

View File

@ -349,7 +349,7 @@ static int check_for_pending(struct server *s)
p = pendconn_from_px(s->proxy); p = pendconn_from_px(s->proxy);
if (!p) if (!p)
break; break;
set_target_server(&p->sess->target, s); p->sess->target = &s->obj_type;
sess = p->sess; sess = p->sess;
pendconn_free(p); pendconn_free(p);
task_wakeup(sess->task, TASK_WOKEN_RES); task_wakeup(sess->task, TASK_WOKEN_RES);
@ -1299,7 +1299,7 @@ static struct task *process_chk(struct task *t)
} }
/* prepare a new connection */ /* prepare a new connection */
set_target_server(&conn->target, s); conn->target = &s->obj_type;
conn_prepare(conn, &check_conn_cb, s->check.proto, s->check.xprt, s); conn_prepare(conn, &check_conn_cb, s->check.proto, s->check.xprt, s);
/* no client address */ /* no client address */

View File

@ -125,7 +125,7 @@ static int stats_accept(struct session *s)
{ {
/* we have a dedicated I/O handler for the stats */ /* we have a dedicated I/O handler for the stats */
stream_int_register_handler(&s->si[1], &cli_applet); stream_int_register_handler(&s->si[1], &cli_applet);
copy_target(&s->target, &s->si[1].conn->target); // for logging only s->target = s->si[1].conn->target; // for logging only
s->si[1].conn->xprt_ctx = s; s->si[1].conn->xprt_ctx = s;
s->si[1].applet.st1 = 0; s->si[1].applet.st1 = 0;
s->si[1].applet.st0 = STAT_CLI_INIT; s->si[1].applet.st0 = STAT_CLI_INIT;
@ -3419,8 +3419,8 @@ static int stats_dump_full_sess_to_buffer(struct stream_interface *si)
if (sess->be->cap & PR_CAP_BE) if (sess->be->cap & PR_CAP_BE)
chunk_appendf(&trash, chunk_appendf(&trash,
" server=%s (id=%u)", " server=%s (id=%u)",
target_srv(&sess->target) ? target_srv(&sess->target)->id : "<none>", objt_server(sess->target) ? objt_server(sess->target)->id : "<none>",
target_srv(&sess->target) ? target_srv(&sess->target)->puid : 0); objt_server(sess->target) ? objt_server(sess->target)->puid : 0);
else else
chunk_appendf(&trash, " server=<NONE> (id=-1)"); chunk_appendf(&trash, " server=<NONE> (id=-1)");
@ -3638,7 +3638,7 @@ static int stats_dump_sess_to_buffer(struct stream_interface *si)
get_host_port(&curr_sess->si[0].conn->addr.from), get_host_port(&curr_sess->si[0].conn->addr.from),
curr_sess->fe->id, curr_sess->fe->id,
(curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>",
target_srv(&curr_sess->target) ? target_srv(&curr_sess->target)->id : "<none>" objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>"
); );
break; break;
case AF_UNIX: case AF_UNIX:
@ -3647,7 +3647,7 @@ static int stats_dump_sess_to_buffer(struct stream_interface *si)
curr_sess->listener->luid, curr_sess->listener->luid,
curr_sess->fe->id, curr_sess->fe->id,
(curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>",
target_srv(&curr_sess->target) ? target_srv(&curr_sess->target)->id : "<none>" objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>"
); );
break; break;
} }
@ -4161,12 +4161,14 @@ static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct b
} }
struct si_applet http_stats_applet = { struct si_applet http_stats_applet = {
.obj_type = OBJ_TYPE_APPLET,
.name = "<STATS>", /* used for logging */ .name = "<STATS>", /* used for logging */
.fct = http_stats_io_handler, .fct = http_stats_io_handler,
.release = NULL, .release = NULL,
}; };
static struct si_applet cli_applet = { static struct si_applet cli_applet = {
.obj_type = OBJ_TYPE_APPLET,
.name = "<CLI>", /* used for logging */ .name = "<CLI>", /* used for logging */
.fct = cli_io_handler, .fct = cli_io_handler,
.release = NULL, .release = NULL,

View File

@ -800,12 +800,12 @@ int build_logline(struct session *s, char *dst, size_t maxsize, struct list *lis
if (!(tolog & LW_SVID)) if (!(tolog & LW_SVID))
svid = "-"; svid = "-";
else switch (s->target.type) { else switch (obj_type(s->target)) {
case TARG_TYPE_SERVER: case OBJ_TYPE_SERVER:
svid = s->target.ptr.s->id; svid = objt_server(s->target)->id;
break; break;
case TARG_TYPE_APPLET: case OBJ_TYPE_APPLET:
svid = s->target.ptr.a->name; svid = objt_applet(s->target)->name;
break; break;
default: default:
svid = "<NOSRV>"; svid = "<NOSRV>";
@ -1175,8 +1175,8 @@ int build_logline(struct session *s, char *dst, size_t maxsize, struct list *lis
break; break;
case LOG_FMT_SRVCONN: // %sc case LOG_FMT_SRVCONN: // %sc
ret = ultoa_o(target_srv(&s->target) ? ret = ultoa_o(obj_type(s->target) ?
target_srv(&s->target)->cur_sess : objt_server(s->target)->cur_sess :
0, tmplog, dst + maxsize - tmplog); 0, tmplog, dst + maxsize - tmplog);
if (ret == NULL) if (ret == NULL)
goto out; goto out;

View File

@ -25,7 +25,8 @@
#include <common/time.h> #include <common/time.h>
#include <types/global.h> #include <types/global.h>
#include <proto/listener.h> #include <types/listener.h>
#include <types/obj_type.h>
#include <types/peers.h> #include <types/peers.h>
#include <proto/acl.h> #include <proto/acl.h>
@ -1040,6 +1041,7 @@ quit:
} }
static struct si_applet peer_applet = { static struct si_applet peer_applet = {
.obj_type = OBJ_TYPE_APPLET,
.name = "<PEER>", /* used for logging */ .name = "<PEER>", /* used for logging */
.fct = peer_io_handler, .fct = peer_io_handler,
.release = peer_session_release, .release = peer_session_release,
@ -1052,8 +1054,7 @@ static void peer_session_forceshutdown(struct session * session)
{ {
struct stream_interface *oldsi; struct stream_interface *oldsi;
if (session->si[0].conn->target.type == TARG_TYPE_APPLET && if (objt_applet(session->si[0].conn->target) == &peer_applet) {
session->si[0].conn->target.ptr.a == &peer_applet) {
oldsi = &session->si[0]; oldsi = &session->si[0];
} }
else { else {
@ -1077,7 +1078,7 @@ int peer_accept(struct session *s)
{ {
/* we have a dedicated I/O handler for the stats */ /* we have a dedicated I/O handler for the stats */
stream_int_register_handler(&s->si[1], &peer_applet); stream_int_register_handler(&s->si[1], &peer_applet);
copy_target(&s->target, &s->si[1].conn->target); // for logging only s->target = s->si[1].conn->target; // for logging only
s->si[1].conn->xprt_ctx = s; s->si[1].conn->xprt_ctx = s;
s->si[1].applet.st0 = PEER_SESSION_ACCEPT; s->si[1].applet.st0 = PEER_SESSION_ACCEPT;
@ -1161,7 +1162,7 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio
s->si[0].err_loc = NULL; s->si[0].err_loc = NULL;
s->si[0].release = NULL; s->si[0].release = NULL;
s->si[0].send_proxy_ofs = 0; s->si[0].send_proxy_ofs = 0;
set_target_client(&s->si[0].conn->target, l); s->si[0].conn->target = &l->obj_type;
s->si[0].exp = TICK_ETERNITY; s->si[0].exp = TICK_ETERNITY;
s->si[0].flags = SI_FL_NONE; s->si[0].flags = SI_FL_NONE;
if (s->fe->options2 & PR_O2_INDEPSTR) if (s->fe->options2 & PR_O2_INDEPSTR)
@ -1180,7 +1181,7 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio
s->si[1].err_loc = NULL; s->si[1].err_loc = NULL;
s->si[1].release = NULL; s->si[1].release = NULL;
s->si[1].send_proxy_ofs = 0; s->si[1].send_proxy_ofs = 0;
set_target_proxy(&s->si[1].conn->target, s->be); s->si[1].conn->target = &s->be->obj_type;
si_prepare_conn(&s->si[1], peer->proto, peer->xprt); si_prepare_conn(&s->si[1], peer->proto, peer->xprt);
s->si[1].exp = TICK_ETERNITY; s->si[1].exp = TICK_ETERNITY;
s->si[1].flags = SI_FL_NONE; s->si[1].flags = SI_FL_NONE;
@ -1188,7 +1189,7 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio
s->si[1].flags |= SI_FL_INDEP_STR; s->si[1].flags |= SI_FL_INDEP_STR;
session_init_srv_conn(s); session_init_srv_conn(s);
set_target_proxy(&s->target, s->be); s->target = &s->be->obj_type;
s->pend_pos = NULL; s->pend_pos = NULL;
/* init store persistence */ /* init store persistence */

View File

@ -767,7 +767,7 @@ void perform_http_redirect(struct session *s, struct stream_interface *si)
trash.len = strlen(HTTP_302); trash.len = strlen(HTTP_302);
memcpy(trash.str, HTTP_302, trash.len); memcpy(trash.str, HTTP_302, trash.len);
srv = target_srv(&s->target); srv = objt_server(s->target);
/* 2: add the server's prefix */ /* 2: add the server's prefix */
if (trash.len + srv->rdr_len > trash.size) if (trash.len + srv->rdr_len > trash.size)
@ -3202,7 +3202,7 @@ int http_process_req_common(struct session *s, struct channel *req, int an_bit,
s->logs.tv_request = now; s->logs.tv_request = now;
s->task->nice = -32; /* small boost for HTTP statistics */ s->task->nice = -32; /* small boost for HTTP statistics */
stream_int_register_handler(s->rep->prod, &http_stats_applet); stream_int_register_handler(s->rep->prod, &http_stats_applet);
copy_target(&s->target, &s->rep->prod->conn->target); // for logging only s->target = s->rep->prod->conn->target; // for logging only
s->rep->prod->conn->xprt_ctx = s; s->rep->prod->conn->xprt_ctx = s;
s->rep->prod->applet.st0 = s->rep->prod->applet.st1 = 0; s->rep->prod->applet.st0 = s->rep->prod->applet.st1 = 0;
req->analysers = 0; req->analysers = 0;
@ -4056,16 +4056,16 @@ void http_end_txn_clean_session(struct session *s)
if (s->pend_pos) if (s->pend_pos)
pendconn_free(s->pend_pos); pendconn_free(s->pend_pos);
if (target_srv(&s->target)) { if (objt_server(s->target)) {
if (s->flags & SN_CURR_SESS) { if (s->flags & SN_CURR_SESS) {
s->flags &= ~SN_CURR_SESS; s->flags &= ~SN_CURR_SESS;
target_srv(&s->target)->cur_sess--; objt_server(s->target)->cur_sess--;
} }
if (may_dequeue_tasks(target_srv(&s->target), s->be)) if (may_dequeue_tasks(objt_server(s->target), s->be))
process_srv_queue(target_srv(&s->target)); process_srv_queue(objt_server(s->target));
} }
clear_target(&s->target); s->target = NULL;
s->req->cons->state = s->req->cons->prev_state = SI_ST_INI; s->req->cons->state = s->req->cons->prev_state = SI_ST_INI;
s->req->cons->conn->t.sock.fd = -1; /* just to help with debugging */ s->req->cons->conn->t.sock.fd = -1; /* just to help with debugging */
@ -4349,8 +4349,8 @@ int http_sync_res_state(struct session *s)
else if (chn->flags & CF_SHUTW) { else if (chn->flags & CF_SHUTW) {
txn->rsp.msg_state = HTTP_MSG_ERROR; txn->rsp.msg_state = HTTP_MSG_ERROR;
s->be->be_counters.cli_aborts++; s->be->be_counters.cli_aborts++;
if (target_srv(&s->target)) if (objt_server(s->target))
target_srv(&s->target)->counters.cli_aborts++; objt_server(s->target)->counters.cli_aborts++;
goto wait_other_side; goto wait_other_side;
} }
} }
@ -4628,8 +4628,8 @@ int http_request_forward_body(struct session *s, struct channel *req, int an_bit
s->fe->fe_counters.cli_aborts++; s->fe->fe_counters.cli_aborts++;
s->be->be_counters.cli_aborts++; s->be->be_counters.cli_aborts++;
if (target_srv(&s->target)) if (objt_server(s->target))
target_srv(&s->target)->counters.cli_aborts++; objt_server(s->target)->counters.cli_aborts++;
goto return_bad_req_stats_ok; goto return_bad_req_stats_ok;
} }
@ -4698,8 +4698,8 @@ int http_request_forward_body(struct session *s, struct channel *req, int an_bit
s->fe->fe_counters.srv_aborts++; s->fe->fe_counters.srv_aborts++;
s->be->be_counters.srv_aborts++; s->be->be_counters.srv_aborts++;
if (target_srv(&s->target)) if (objt_server(s->target))
target_srv(&s->target)->counters.srv_aborts++; objt_server(s->target)->counters.srv_aborts++;
if (!(s->flags & SN_ERR_MASK)) if (!(s->flags & SN_ERR_MASK))
s->flags |= SN_ERR_SRVCL; s->flags |= SN_ERR_SRVCL;
@ -4823,9 +4823,9 @@ int http_wait_for_response(struct session *s, struct channel *rep, int an_bit)
http_capture_bad_message(&s->be->invalid_rep, s, msg, msg->msg_state, s->fe); http_capture_bad_message(&s->be->invalid_rep, s, msg, msg->msg_state, s->fe);
s->be->be_counters.failed_resp++; s->be->be_counters.failed_resp++;
if (target_srv(&s->target)) { if (objt_server(s->target)) {
target_srv(&s->target)->counters.failed_resp++; objt_server(s->target)->counters.failed_resp++;
health_adjust(target_srv(&s->target), HANA_STATUS_HTTP_HDRRSP); health_adjust(objt_server(s->target), HANA_STATUS_HTTP_HDRRSP);
} }
abort_response: abort_response:
channel_auto_close(rep); channel_auto_close(rep);
@ -4856,9 +4856,9 @@ int http_wait_for_response(struct session *s, struct channel *rep, int an_bit)
http_capture_bad_message(&s->be->invalid_rep, s, msg, msg->msg_state, s->fe); http_capture_bad_message(&s->be->invalid_rep, s, msg, msg->msg_state, s->fe);
s->be->be_counters.failed_resp++; s->be->be_counters.failed_resp++;
if (target_srv(&s->target)) { if (objt_server(s->target)) {
target_srv(&s->target)->counters.failed_resp++; objt_server(s->target)->counters.failed_resp++;
health_adjust(target_srv(&s->target), HANA_STATUS_HTTP_READ_ERROR); health_adjust(objt_server(s->target), HANA_STATUS_HTTP_READ_ERROR);
} }
channel_auto_close(rep); channel_auto_close(rep);
@ -4881,9 +4881,9 @@ int http_wait_for_response(struct session *s, struct channel *rep, int an_bit)
http_capture_bad_message(&s->be->invalid_rep, s, msg, msg->msg_state, s->fe); http_capture_bad_message(&s->be->invalid_rep, s, msg, msg->msg_state, s->fe);
s->be->be_counters.failed_resp++; s->be->be_counters.failed_resp++;
if (target_srv(&s->target)) { if (objt_server(s->target)) {
target_srv(&s->target)->counters.failed_resp++; objt_server(s->target)->counters.failed_resp++;
health_adjust(target_srv(&s->target), HANA_STATUS_HTTP_READ_TIMEOUT); health_adjust(objt_server(s->target), HANA_STATUS_HTTP_READ_TIMEOUT);
} }
channel_auto_close(rep); channel_auto_close(rep);
@ -4906,9 +4906,9 @@ int http_wait_for_response(struct session *s, struct channel *rep, int an_bit)
http_capture_bad_message(&s->be->invalid_rep, s, msg, msg->msg_state, s->fe); http_capture_bad_message(&s->be->invalid_rep, s, msg, msg->msg_state, s->fe);
s->be->be_counters.failed_resp++; s->be->be_counters.failed_resp++;
if (target_srv(&s->target)) { if (objt_server(s->target)) {
target_srv(&s->target)->counters.failed_resp++; objt_server(s->target)->counters.failed_resp++;
health_adjust(target_srv(&s->target), HANA_STATUS_HTTP_BROKEN_PIPE); health_adjust(objt_server(s->target), HANA_STATUS_HTTP_BROKEN_PIPE);
} }
channel_auto_close(rep); channel_auto_close(rep);
@ -4969,8 +4969,8 @@ int http_wait_for_response(struct session *s, struct channel *rep, int an_bit)
if (n == 4) if (n == 4)
session_inc_http_err_ctr(s); session_inc_http_err_ctr(s);
if (target_srv(&s->target)) if (objt_server(s->target))
target_srv(&s->target)->counters.p.http.rsp[n]++; objt_server(s->target)->counters.p.http.rsp[n]++;
/* check if the response is HTTP/1.1 or above */ /* check if the response is HTTP/1.1 or above */
if ((msg->sl.st.v_l == 8) && if ((msg->sl.st.v_l == 8) &&
@ -4990,11 +4990,11 @@ int http_wait_for_response(struct session *s, struct channel *rep, int an_bit)
* and 505 are triggered on demand by client request, so we must not * and 505 are triggered on demand by client request, so we must not
* count them as server failures. * count them as server failures.
*/ */
if (target_srv(&s->target)) { if (objt_server(s->target)) {
if (txn->status >= 100 && (txn->status < 500 || txn->status == 501 || txn->status == 505)) if (txn->status >= 100 && (txn->status < 500 || txn->status == 501 || txn->status == 505))
health_adjust(target_srv(&s->target), HANA_STATUS_HTTP_OK); health_adjust(objt_server(s->target), HANA_STATUS_HTTP_OK);
else else
health_adjust(target_srv(&s->target), HANA_STATUS_HTTP_STS); health_adjust(objt_server(s->target), HANA_STATUS_HTTP_STS);
} }
/* /*
@ -5258,9 +5258,9 @@ int http_process_res_common(struct session *t, struct channel *rep, int an_bit,
if (rule_set->rsp_exp != NULL) { if (rule_set->rsp_exp != NULL) {
if (apply_filters_to_response(t, rep, rule_set) < 0) { if (apply_filters_to_response(t, rep, rule_set) < 0) {
return_bad_resp: return_bad_resp:
if (target_srv(&t->target)) { if (objt_server(t->target)) {
target_srv(&t->target)->counters.failed_resp++; objt_server(t->target)->counters.failed_resp++;
health_adjust(target_srv(&t->target), HANA_STATUS_HTTP_RSP); health_adjust(objt_server(t->target), HANA_STATUS_HTTP_RSP);
} }
t->be->be_counters.failed_resp++; t->be->be_counters.failed_resp++;
return_srv_prx_502: return_srv_prx_502:
@ -5279,8 +5279,8 @@ int http_process_res_common(struct session *t, struct channel *rep, int an_bit,
/* has the response been denied ? */ /* has the response been denied ? */
if (txn->flags & TX_SVDENY) { if (txn->flags & TX_SVDENY) {
if (target_srv(&t->target)) if (objt_server(t->target))
target_srv(&t->target)->counters.failed_secu++; objt_server(t->target)->counters.failed_secu++;
t->be->be_counters.denied_resp++; t->be->be_counters.denied_resp++;
t->fe->fe_counters.denied_resp++; t->fe->fe_counters.denied_resp++;
@ -5348,7 +5348,7 @@ int http_process_res_common(struct session *t, struct channel *rep, int an_bit,
/* /*
* 6: add server cookie in the response if needed * 6: add server cookie in the response if needed
*/ */
if (target_srv(&t->target) && (t->be->ck_opts & PR_CK_INS) && if (objt_server(t->target) && (t->be->ck_opts & PR_CK_INS) &&
!((txn->flags & TX_SCK_FOUND) && (t->be->ck_opts & PR_CK_PSV)) && !((txn->flags & TX_SCK_FOUND) && (t->be->ck_opts & PR_CK_PSV)) &&
(!(t->flags & SN_DIRECT) || (!(t->flags & SN_DIRECT) ||
((t->be->cookie_maxidle || txn->cookie_last_date) && ((t->be->cookie_maxidle || txn->cookie_last_date) &&
@ -5363,13 +5363,13 @@ int http_process_res_common(struct session *t, struct channel *rep, int an_bit,
* requests and this one isn't. Note that servers which don't have cookies * requests and this one isn't. Note that servers which don't have cookies
* (eg: some backup servers) will return a full cookie removal request. * (eg: some backup servers) will return a full cookie removal request.
*/ */
if (!target_srv(&t->target)->cookie) { if (!objt_server(t->target)->cookie) {
chunk_printf(&trash, chunk_printf(&trash,
"Set-Cookie: %s=; Expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/", "Set-Cookie: %s=; Expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/",
t->be->cookie_name); t->be->cookie_name);
} }
else { else {
chunk_printf(&trash, "Set-Cookie: %s=%s", t->be->cookie_name, target_srv(&t->target)->cookie); chunk_printf(&trash, "Set-Cookie: %s=%s", t->be->cookie_name, objt_server(t->target)->cookie);
if (t->be->cookie_maxidle || t->be->cookie_maxlife) { if (t->be->cookie_maxidle || t->be->cookie_maxlife) {
/* emit last_date, which is mandatory */ /* emit last_date, which is mandatory */
@ -5404,7 +5404,7 @@ int http_process_res_common(struct session *t, struct channel *rep, int an_bit,
goto return_bad_resp; goto return_bad_resp;
txn->flags &= ~TX_SCK_MASK; txn->flags &= ~TX_SCK_MASK;
if (target_srv(&t->target)->cookie && (t->flags & SN_DIRECT)) if (objt_server(t->target)->cookie && (t->flags & SN_DIRECT))
/* the server did not change, only the date was updated */ /* the server did not change, only the date was updated */
txn->flags |= TX_SCK_UPDATED; txn->flags |= TX_SCK_UPDATED;
else else
@ -5438,8 +5438,8 @@ int http_process_res_common(struct session *t, struct channel *rep, int an_bit,
* a set-cookie header. We'll block it as requested by * a set-cookie header. We'll block it as requested by
* the 'checkcache' option, and send an alert. * the 'checkcache' option, and send an alert.
*/ */
if (target_srv(&t->target)) if (objt_server(t->target))
target_srv(&t->target)->counters.failed_secu++; objt_server(t->target)->counters.failed_secu++;
t->be->be_counters.denied_resp++; t->be->be_counters.denied_resp++;
t->fe->fe_counters.denied_resp++; t->fe->fe_counters.denied_resp++;
@ -5447,10 +5447,10 @@ int http_process_res_common(struct session *t, struct channel *rep, int an_bit,
t->listener->counters->denied_resp++; t->listener->counters->denied_resp++;
Alert("Blocking cacheable cookie in response from instance %s, server %s.\n", Alert("Blocking cacheable cookie in response from instance %s, server %s.\n",
t->be->id, target_srv(&t->target) ? target_srv(&t->target)->id : "<dispatch>"); t->be->id, objt_server(t->target) ? objt_server(t->target)->id : "<dispatch>");
send_log(t->be, LOG_ALERT, send_log(t->be, LOG_ALERT,
"Blocking cacheable cookie in response from instance %s, server %s.\n", "Blocking cacheable cookie in response from instance %s, server %s.\n",
t->be->id, target_srv(&t->target) ? target_srv(&t->target)->id : "<dispatch>"); t->be->id, objt_server(t->target) ? objt_server(t->target)->id : "<dispatch>");
goto return_srv_prx_502; goto return_srv_prx_502;
} }
@ -5712,8 +5712,8 @@ int http_response_forward_body(struct session *s, struct channel *res, int an_bi
if (!(s->flags & SN_ERR_MASK)) if (!(s->flags & SN_ERR_MASK))
s->flags |= SN_ERR_SRVCL; s->flags |= SN_ERR_SRVCL;
s->be->be_counters.srv_aborts++; s->be->be_counters.srv_aborts++;
if (target_srv(&s->target)) if (objt_server(s->target))
target_srv(&s->target)->counters.srv_aborts++; objt_server(s->target)->counters.srv_aborts++;
goto return_bad_res_stats_ok; goto return_bad_res_stats_ok;
} }
@ -5762,8 +5762,8 @@ int http_response_forward_body(struct session *s, struct channel *res, int an_bi
return_bad_res: /* let's centralize all bad responses */ return_bad_res: /* let's centralize all bad responses */
s->be->be_counters.failed_resp++; s->be->be_counters.failed_resp++;
if (target_srv(&s->target)) if (objt_server(s->target))
target_srv(&s->target)->counters.failed_resp++; objt_server(s->target)->counters.failed_resp++;
return_bad_res_stats_ok: return_bad_res_stats_ok:
txn->rsp.msg_state = HTTP_MSG_ERROR; txn->rsp.msg_state = HTTP_MSG_ERROR;
@ -5771,8 +5771,8 @@ int http_response_forward_body(struct session *s, struct channel *res, int an_bi
stream_int_retnclose(res->cons, NULL); stream_int_retnclose(res->cons, NULL);
res->analysers = 0; res->analysers = 0;
s->req->analysers = 0; /* we're in data phase, we want to abort both directions */ s->req->analysers = 0; /* we're in data phase, we want to abort both directions */
if (target_srv(&s->target)) if (objt_server(s->target))
health_adjust(target_srv(&s->target), HANA_STATUS_HTTP_HDRRSP); health_adjust(objt_server(s->target), HANA_STATUS_HTTP_HDRRSP);
if (!(s->flags & SN_ERR_MASK)) if (!(s->flags & SN_ERR_MASK))
s->flags |= SN_ERR_PRXCOND; s->flags |= SN_ERR_PRXCOND;
@ -5789,8 +5789,8 @@ int http_response_forward_body(struct session *s, struct channel *res, int an_bi
s->fe->fe_counters.cli_aborts++; s->fe->fe_counters.cli_aborts++;
s->be->be_counters.cli_aborts++; s->be->be_counters.cli_aborts++;
if (target_srv(&s->target)) if (objt_server(s->target))
target_srv(&s->target)->counters.cli_aborts++; objt_server(s->target)->counters.cli_aborts++;
if (!(s->flags & SN_ERR_MASK)) if (!(s->flags & SN_ERR_MASK))
s->flags |= SN_ERR_CLICL; s->flags |= SN_ERR_CLICL;
@ -6166,7 +6166,7 @@ void manage_client_side_appsession(struct session *t, const char *buf, int len)
txn->flags &= ~TX_CK_MASK; txn->flags &= ~TX_CK_MASK;
txn->flags |= (srv->state & SRV_RUNNING) ? TX_CK_VALID : TX_CK_DOWN; txn->flags |= (srv->state & SRV_RUNNING) ? TX_CK_VALID : TX_CK_DOWN;
t->flags |= SN_DIRECT | SN_ASSIGNED; t->flags |= SN_DIRECT | SN_ASSIGNED;
set_target_server(&t->target, srv); t->target = &srv->obj_type;
break; break;
} else { } else {
@ -6576,7 +6576,7 @@ void manage_client_side_cookies(struct session *t, struct channel *req)
txn->flags &= ~TX_CK_MASK; txn->flags &= ~TX_CK_MASK;
txn->flags |= (srv->state & SRV_RUNNING) ? TX_CK_VALID : TX_CK_DOWN; txn->flags |= (srv->state & SRV_RUNNING) ? TX_CK_VALID : TX_CK_DOWN;
t->flags |= SN_DIRECT | SN_ASSIGNED; t->flags |= SN_DIRECT | SN_ASSIGNED;
set_target_server(&t->target, srv); t->target = &srv->obj_type;
break; break;
} else { } else {
/* we found a server, but it's down, /* we found a server, but it's down,
@ -7152,7 +7152,7 @@ void manage_server_side_cookies(struct session *t, struct channel *res)
} }
} }
srv = target_srv(&t->target); srv = objt_server(t->target);
/* now check if we need to process it for persistence */ /* now check if we need to process it for persistence */
if (!(t->flags & SN_IGNORE_PRST) && if (!(t->flags & SN_IGNORE_PRST) &&
(att_end - att_beg == t->be->cookie_len) && (t->be->cookie_name != NULL) && (att_end - att_beg == t->be->cookie_len) && (t->be->cookie_name != NULL) &&
@ -7289,7 +7289,7 @@ void manage_server_side_cookies(struct session *t, struct channel *res)
memcpy(asession->sessid, txn->sessid, t->be->appsession_len); memcpy(asession->sessid, txn->sessid, t->be->appsession_len);
asession->sessid[t->be->appsession_len] = 0; asession->sessid[t->be->appsession_len] = 0;
server_id_len = strlen(target_srv(&t->target)->id) + 1; server_id_len = strlen(objt_server(t->target)->id) + 1;
if ((asession->serverid = pool_alloc2(apools.serverid)) == NULL) { if ((asession->serverid = pool_alloc2(apools.serverid)) == NULL) {
Alert("Not enough Memory process_srv():asession->serverid:malloc().\n"); Alert("Not enough Memory process_srv():asession->serverid:malloc().\n");
send_log(t->be, LOG_ALERT, "Not enough Memory process_srv():asession->sessid:malloc().\n"); send_log(t->be, LOG_ALERT, "Not enough Memory process_srv():asession->sessid:malloc().\n");
@ -7297,7 +7297,7 @@ void manage_server_side_cookies(struct session *t, struct channel *res)
return; return;
} }
asession->serverid[0] = '\0'; asession->serverid[0] = '\0';
memcpy(asession->serverid, target_srv(&t->target)->id, server_id_len); memcpy(asession->serverid, objt_server(t->target)->id, server_id_len);
asession->request_count = 0; asession->request_count = 0;
appsession_hash_insert(&(t->be->htbl_proxy), asession); appsession_hash_insert(&(t->be->htbl_proxy), asession);
@ -7582,7 +7582,7 @@ void http_capture_bad_message(struct error_snapshot *es, struct session *s,
es->when = date; // user-visible date es->when = date; // user-visible date
es->sid = s->uniq_id; es->sid = s->uniq_id;
es->srv = target_srv(&s->target); es->srv = objt_server(s->target);
es->oe = other_end; es->oe = other_end;
es->src = s->req->prod->conn->addr.from; es->src = s->req->prod->conn->addr.from;
es->state = state; es->state = state;
@ -7775,7 +7775,7 @@ void http_reset_txn(struct session *s)
s->be = s->fe; s->be = s->fe;
s->logs.logwait = s->fe->to_log; s->logs.logwait = s->fe->to_log;
session_del_srv_conn(s); session_del_srv_conn(s);
clear_target(&s->target); s->target = NULL;
/* re-init store persistence */ /* re-init store persistence */
s->store_count = 0; s->store_count = 0;

View File

@ -220,7 +220,7 @@ int tcp_bind_socket(int fd, int flags, struct sockaddr_storage *local, struct so
* pointed to by conn->addr.from in case of transparent proxying. Normal source * pointed to by conn->addr.from in case of transparent proxying. Normal source
* bind addresses are still determined locally (due to the possible need of a * bind addresses are still determined locally (due to the possible need of a
* source port). conn->target may point either to a valid server or to a backend, * source port). conn->target may point either to a valid server or to a backend,
* depending on conn->target.type. Only TARG_TYPE_PROXY and TARG_TYPE_SERVER are * depending on conn->target. Only OBJ_TYPE_PROXY and OBJ_TYPE_SERVER are
* supported. The <data> parameter is a boolean indicating whether there are data * supported. The <data> parameter is a boolean indicating whether there are data
* waiting for being sent or not, in order to adjust data write polling and on * waiting for being sent or not, in order to adjust data write polling and on
* some platforms, the ability to avoid an empty initial ACK. * some platforms, the ability to avoid an empty initial ACK.
@ -241,13 +241,13 @@ int tcp_connect_server(struct connection *conn, int data)
struct server *srv; struct server *srv;
struct proxy *be; struct proxy *be;
switch (conn->target.type) { switch (obj_type(conn->target)) {
case TARG_TYPE_PROXY: case OBJ_TYPE_PROXY:
be = conn->target.ptr.p; be = objt_proxy(conn->target);
srv = NULL; srv = NULL;
break; break;
case TARG_TYPE_SERVER: case OBJ_TYPE_SERVER:
srv = conn->target.ptr.s; srv = objt_server(conn->target);
be = srv->proxy; be = srv->proxy;
break; break;
default: default:

View File

@ -26,6 +26,7 @@
#include <common/time.h> #include <common/time.h>
#include <types/global.h> #include <types/global.h>
#include <types/obj_type.h>
#include <types/peers.h> #include <types/peers.h>
#include <proto/backend.h> #include <proto/backend.h>
@ -425,6 +426,7 @@ int proxy_cfg_ensure_no_http(struct proxy *curproxy)
void init_new_proxy(struct proxy *p) void init_new_proxy(struct proxy *p)
{ {
memset(p, 0, sizeof(struct proxy)); memset(p, 0, sizeof(struct proxy));
p->obj_type = OBJ_TYPE_PROXY;
LIST_INIT(&p->pendconns); LIST_INIT(&p->pendconns);
LIST_INIT(&p->acl); LIST_INIT(&p->acl);
LIST_INIT(&p->http_req_rules); LIST_INIT(&p->http_req_rules);

View File

@ -122,7 +122,7 @@ struct session *pendconn_get_next_sess(struct server *srv, struct proxy *px)
/* we want to note that the session has now been assigned a server */ /* we want to note that the session has now been assigned a server */
sess->flags |= SN_ASSIGNED; sess->flags |= SN_ASSIGNED;
set_target_server(&sess->target, srv); sess->target = &srv->obj_type;
session_add_srv_conn(sess, srv); session_add_srv_conn(sess, srv);
srv->served++; srv->served++;
if (px->lbprm.server_take_conn) if (px->lbprm.server_take_conn)
@ -148,7 +148,7 @@ struct pendconn *pendconn_add(struct session *sess)
sess->pend_pos = p; sess->pend_pos = p;
p->sess = sess; p->sess = sess;
p->srv = srv = target_srv(&sess->target); p->srv = srv = objt_server(sess->target);
if (sess->flags & SN_ASSIGNED && srv) { if (sess->flags & SN_ASSIGNED && srv) {
LIST_ADDQ(&srv->pendconns, &p->list); LIST_ADDQ(&srv->pendconns, &p->list);

View File

@ -110,7 +110,7 @@ int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr)
s->si[0].conn->ctrl = l->proto; s->si[0].conn->ctrl = l->proto;
s->si[0].conn->flags = CO_FL_NONE; s->si[0].conn->flags = CO_FL_NONE;
s->si[0].conn->addr.from = *addr; s->si[0].conn->addr.from = *addr;
set_target_client(&s->si[0].conn->target, l); s->si[0].conn->target = &l->obj_type;
s->logs.accept_date = date; /* user-visible date for logging */ s->logs.accept_date = date; /* user-visible date for logging */
s->logs.tv_accept = now; /* corrected date for internal use */ s->logs.tv_accept = now; /* corrected date for internal use */
@ -415,7 +415,7 @@ int session_complete(struct session *s)
s->si[1].err_loc = NULL; s->si[1].err_loc = NULL;
s->si[1].release = NULL; s->si[1].release = NULL;
s->si[1].send_proxy_ofs = 0; s->si[1].send_proxy_ofs = 0;
clear_target(&s->si[1].conn->target); s->si[1].conn->target = NULL;
si_prepare_embedded(&s->si[1]); si_prepare_embedded(&s->si[1]);
s->si[1].exp = TICK_ETERNITY; s->si[1].exp = TICK_ETERNITY;
s->si[1].flags = SI_FL_NONE; s->si[1].flags = SI_FL_NONE;
@ -424,7 +424,7 @@ int session_complete(struct session *s)
s->si[1].flags |= SI_FL_INDEP_STR; s->si[1].flags |= SI_FL_INDEP_STR;
session_init_srv_conn(s); session_init_srv_conn(s);
clear_target(&s->target); s->target = NULL;
s->pend_pos = NULL; s->pend_pos = NULL;
/* init store persistence */ /* init store persistence */
@ -548,13 +548,13 @@ static void session_free(struct session *s)
if (s->pend_pos) if (s->pend_pos)
pendconn_free(s->pend_pos); pendconn_free(s->pend_pos);
if (target_srv(&s->target)) { /* there may be requests left pending in queue */ if (objt_server(s->target)) { /* there may be requests left pending in queue */
if (s->flags & SN_CURR_SESS) { if (s->flags & SN_CURR_SESS) {
s->flags &= ~SN_CURR_SESS; s->flags &= ~SN_CURR_SESS;
target_srv(&s->target)->cur_sess--; objt_server(s->target)->cur_sess--;
} }
if (may_dequeue_tasks(target_srv(&s->target), s->be)) if (may_dequeue_tasks(objt_server(s->target), s->be))
process_srv_queue(target_srv(&s->target)); process_srv_queue(objt_server(s->target));
} }
if (unlikely(s->srv_conn)) { if (unlikely(s->srv_conn)) {
@ -653,8 +653,8 @@ void session_process_counters(struct session *s)
s->be->be_counters.bytes_in += bytes; s->be->be_counters.bytes_in += bytes;
if (target_srv(&s->target)) if (objt_server(s->target))
target_srv(&s->target)->counters.bytes_in += bytes; objt_server(s->target)->counters.bytes_in += bytes;
if (s->listener->counters) if (s->listener->counters)
s->listener->counters->bytes_in += bytes; s->listener->counters->bytes_in += bytes;
@ -703,8 +703,8 @@ void session_process_counters(struct session *s)
s->be->be_counters.bytes_out += bytes; s->be->be_counters.bytes_out += bytes;
if (target_srv(&s->target)) if (objt_server(s->target))
target_srv(&s->target)->counters.bytes_out += bytes; objt_server(s->target)->counters.bytes_out += bytes;
if (s->listener->counters) if (s->listener->counters)
s->listener->counters->bytes_out += bytes; s->listener->counters->bytes_out += bytes;
@ -773,7 +773,7 @@ static int sess_update_st_con_tcp(struct session *s, struct stream_interface *si
si->state = SI_ST_EST; si->state = SI_ST_EST;
si->err_type = SI_ET_DATA_ERR; si->err_type = SI_ET_DATA_ERR;
si->ib->flags |= CF_READ_ERROR | CF_WRITE_ERROR; si->ib->flags |= CF_READ_ERROR | CF_WRITE_ERROR;
si->err_loc = target_srv(&s->target); si->err_loc = objt_server(s->target);
return 1; return 1;
} }
si->exp = TICK_ETERNITY; si->exp = TICK_ETERNITY;
@ -787,7 +787,7 @@ static int sess_update_st_con_tcp(struct session *s, struct stream_interface *si
if (si->err_type) if (si->err_type)
return 0; return 0;
si->err_loc = target_srv(&s->target); si->err_loc = objt_server(s->target);
if (si->flags & SI_FL_ERR) if (si->flags & SI_FL_ERR)
si->err_type = SI_ET_CONN_ERR; si->err_type = SI_ET_CONN_ERR;
else else
@ -803,7 +803,7 @@ static int sess_update_st_con_tcp(struct session *s, struct stream_interface *si
/* give up */ /* give up */
si_shutw(si); si_shutw(si);
si->err_type |= SI_ET_CONN_ABRT; si->err_type |= SI_ET_CONN_ABRT;
si->err_loc = target_srv(&s->target); si->err_loc = objt_server(s->target);
if (s->srv_error) if (s->srv_error)
s->srv_error(s, si); s->srv_error(s, si);
return 1; return 1;
@ -836,12 +836,12 @@ static int sess_update_st_con_tcp(struct session *s, struct stream_interface *si
static int sess_update_st_cer(struct session *s, struct stream_interface *si) static int sess_update_st_cer(struct session *s, struct stream_interface *si)
{ {
/* we probably have to release last session from the server */ /* we probably have to release last session from the server */
if (target_srv(&s->target)) { if (objt_server(s->target)) {
health_adjust(target_srv(&s->target), HANA_STATUS_L4_ERR); health_adjust(objt_server(s->target), HANA_STATUS_L4_ERR);
if (s->flags & SN_CURR_SESS) { if (s->flags & SN_CURR_SESS) {
s->flags &= ~SN_CURR_SESS; s->flags &= ~SN_CURR_SESS;
target_srv(&s->target)->cur_sess--; objt_server(s->target)->cur_sess--;
} }
} }
@ -850,15 +850,15 @@ static int sess_update_st_cer(struct session *s, struct stream_interface *si)
if (si->conn_retries < 0) { if (si->conn_retries < 0) {
if (!si->err_type) { if (!si->err_type) {
si->err_type = SI_ET_CONN_ERR; si->err_type = SI_ET_CONN_ERR;
si->err_loc = target_srv(&s->target); si->err_loc = objt_server(s->target);
} }
if (target_srv(&s->target)) if (objt_server(s->target))
target_srv(&s->target)->counters.failed_conns++; objt_server(s->target)->counters.failed_conns++;
s->be->be_counters.failed_conns++; s->be->be_counters.failed_conns++;
sess_change_server(s, NULL); sess_change_server(s, NULL);
if (may_dequeue_tasks(target_srv(&s->target), s->be)) if (may_dequeue_tasks(objt_server(s->target), s->be))
process_srv_queue(target_srv(&s->target)); process_srv_queue(objt_server(s->target));
/* shutw is enough so stop a connecting socket */ /* shutw is enough so stop a connecting socket */
si_shutw(si); si_shutw(si);
@ -877,17 +877,17 @@ static int sess_update_st_cer(struct session *s, struct stream_interface *si)
* bit to ignore any persistence cookie. We won't count a retry nor a * bit to ignore any persistence cookie. We won't count a retry nor a
* redispatch yet, because this will depend on what server is selected. * redispatch yet, because this will depend on what server is selected.
*/ */
if (target_srv(&s->target) && si->conn_retries == 0 && if (objt_server(s->target) && si->conn_retries == 0 &&
s->be->options & PR_O_REDISP && !(s->flags & SN_FORCE_PRST)) { s->be->options & PR_O_REDISP && !(s->flags & SN_FORCE_PRST)) {
sess_change_server(s, NULL); sess_change_server(s, NULL);
if (may_dequeue_tasks(target_srv(&s->target), s->be)) if (may_dequeue_tasks(objt_server(s->target), s->be))
process_srv_queue(target_srv(&s->target)); process_srv_queue(objt_server(s->target));
s->flags &= ~(SN_DIRECT | SN_ASSIGNED | SN_ADDR_SET); s->flags &= ~(SN_DIRECT | SN_ASSIGNED | SN_ADDR_SET);
si->state = SI_ST_REQ; si->state = SI_ST_REQ;
} else { } else {
if (target_srv(&s->target)) if (objt_server(s->target))
target_srv(&s->target)->counters.retries++; objt_server(s->target)->counters.retries++;
s->be->be_counters.retries++; s->be->be_counters.retries++;
si->state = SI_ST_ASS; si->state = SI_ST_ASS;
} }
@ -919,8 +919,8 @@ static void sess_establish(struct session *s, struct stream_interface *si)
struct channel *req = si->ob; struct channel *req = si->ob;
struct channel *rep = si->ib; struct channel *rep = si->ib;
if (target_srv(&s->target)) if (objt_server(s->target))
health_adjust(target_srv(&s->target), HANA_STATUS_L4_OK); health_adjust(objt_server(s->target), HANA_STATUS_L4_OK);
if (s->be->mode == PR_MODE_TCP) { /* let's allow immediate data connection in this case */ if (s->be->mode == PR_MODE_TCP) { /* let's allow immediate data connection in this case */
/* if the user wants to log as soon as possible, without counting /* if the user wants to log as soon as possible, without counting
@ -955,7 +955,7 @@ static void sess_establish(struct session *s, struct stream_interface *si)
*/ */
static void sess_update_stream_int(struct session *s, struct stream_interface *si) static void sess_update_stream_int(struct session *s, struct stream_interface *si)
{ {
struct server *srv = target_srv(&s->target); struct server *srv = objt_server(s->target);
DPRINTF(stderr,"[%u] %s: sess=%p rq=%p, rp=%p, exp(r,w)=%u,%u rqf=%08x rpf=%08x rqh=%d rqt=%d rph=%d rpt=%d cs=%d ss=%d\n", DPRINTF(stderr,"[%u] %s: sess=%p rq=%p, rp=%p, exp(r,w)=%u,%u rqf=%08x rpf=%08x rqh=%d rqt=%d rph=%d rpt=%d cs=%d ss=%d\n",
now_ms, __FUNCTION__, now_ms, __FUNCTION__,
@ -970,7 +970,7 @@ static void sess_update_stream_int(struct session *s, struct stream_interface *s
int conn_err; int conn_err;
conn_err = connect_server(s); conn_err = connect_server(s);
srv = target_srv(&s->target); srv = objt_server(s->target);
if (conn_err == SN_ERR_NONE) { if (conn_err == SN_ERR_NONE) {
/* state = SI_ST_CON now */ /* state = SI_ST_CON now */
@ -1314,7 +1314,7 @@ static int process_server_rules(struct session *s, struct channel *req, int an_b
(px->options & PR_O_PERSIST) || (px->options & PR_O_PERSIST) ||
(s->flags & SN_FORCE_PRST)) { (s->flags & SN_FORCE_PRST)) {
s->flags |= SN_DIRECT | SN_ASSIGNED; s->flags |= SN_DIRECT | SN_ASSIGNED;
set_target_server(&s->target, srv); s->target = &srv->obj_type;
break; break;
} }
/* if the server is not UP, let's go on with next rules /* if the server is not UP, let's go on with next rules
@ -1392,7 +1392,7 @@ static int process_sticking_rules(struct session *s, struct channel *req, int an
(px->options & PR_O_PERSIST) || (px->options & PR_O_PERSIST) ||
(s->flags & SN_FORCE_PRST)) { (s->flags & SN_FORCE_PRST)) {
s->flags |= SN_DIRECT | SN_ASSIGNED; s->flags |= SN_DIRECT | SN_ASSIGNED;
set_target_server(&s->target, srv); s->target = &srv->obj_type;
} }
} }
} }
@ -1488,7 +1488,7 @@ static int process_store_rules(struct session *s, struct channel *rep, int an_bi
struct stksess *ts; struct stksess *ts;
void *ptr; void *ptr;
if (target_srv(&s->target) && target_srv(&s->target)->state & SRV_NON_STICK) { if (objt_server(s->target) && objt_server(s->target)->state & SRV_NON_STICK) {
stksess_free(s->store[i].table, s->store[i].ts); stksess_free(s->store[i].table, s->store[i].ts);
s->store[i].ts = NULL; s->store[i].ts = NULL;
continue; continue;
@ -1505,7 +1505,7 @@ static int process_store_rules(struct session *s, struct channel *rep, int an_bi
s->store[i].ts = NULL; s->store[i].ts = NULL;
ptr = stktable_data_ptr(s->store[i].table, ts, STKTABLE_DT_SERVER_ID); ptr = stktable_data_ptr(s->store[i].table, ts, STKTABLE_DT_SERVER_ID);
stktable_data_cast(ptr, server_id) = target_srv(&s->target)->puid; stktable_data_cast(ptr, server_id) = objt_server(s->target)->puid;
} }
s->store_count = 0; /* everything is stored */ s->store_count = 0; /* everything is stored */
@ -1621,7 +1621,7 @@ struct task *process_session(struct task *t)
* the client cannot have connect (hence retryable) errors. Also, the * the client cannot have connect (hence retryable) errors. Also, the
* connection setup code must be able to deal with any type of abort. * connection setup code must be able to deal with any type of abort.
*/ */
srv = target_srv(&s->target); srv = objt_server(s->target);
if (unlikely(s->si[0].flags & SI_FL_ERR)) { if (unlikely(s->si[0].flags & SI_FL_ERR)) {
if (s->si[0].state == SI_ST_EST || s->si[0].state == SI_ST_DIS) { if (s->si[0].state == SI_ST_EST || s->si[0].state == SI_ST_DIS) {
si_shutr(&s->si[0]); si_shutr(&s->si[0]);
@ -1706,7 +1706,7 @@ struct task *process_session(struct task *t)
*/ */
if (unlikely(s->req->cons->state == SI_ST_DIS)) { if (unlikely(s->req->cons->state == SI_ST_DIS)) {
s->req->cons->state = SI_ST_CLO; s->req->cons->state = SI_ST_CLO;
srv = target_srv(&s->target); srv = objt_server(s->target);
if (srv) { if (srv) {
if (s->flags & SN_CURR_SESS) { if (s->flags & SN_CURR_SESS) {
s->flags &= ~SN_CURR_SESS; s->flags &= ~SN_CURR_SESS;
@ -1988,7 +1988,7 @@ struct task *process_session(struct task *t)
* we're just in a data phase here since it means we have not * we're just in a data phase here since it means we have not
* seen any analyser who could set an error status. * seen any analyser who could set an error status.
*/ */
srv = target_srv(&s->target); srv = objt_server(s->target);
if (unlikely(!(s->flags & SN_ERR_MASK))) { if (unlikely(!(s->flags & SN_ERR_MASK))) {
if (s->req->flags & (CF_READ_ERROR|CF_READ_TIMEOUT|CF_WRITE_ERROR|CF_WRITE_TIMEOUT)) { if (s->req->flags & (CF_READ_ERROR|CF_READ_TIMEOUT|CF_WRITE_ERROR|CF_WRITE_TIMEOUT)) {
/* Report it if the client got an error or a read timeout expired */ /* Report it if the client got an error or a read timeout expired */
@ -2148,7 +2148,7 @@ struct task *process_session(struct task *t)
*/ */
s->req->cons->state = SI_ST_REQ; /* new connection requested */ s->req->cons->state = SI_ST_REQ; /* new connection requested */
s->req->cons->conn_retries = s->be->conn_retries; s->req->cons->conn_retries = s->be->conn_retries;
if (unlikely(s->req->cons->conn->target.type == TARG_TYPE_APPLET && if (unlikely(obj_type(s->req->cons->conn->target) == OBJ_TYPE_APPLET &&
!(si_ctrl(s->req->cons) && si_ctrl(s->req->cons)->connect))) { !(si_ctrl(s->req->cons) && si_ctrl(s->req->cons)->connect))) {
s->req->cons->state = SI_ST_EST; /* connection established */ s->req->cons->state = SI_ST_EST; /* connection established */
s->rep->flags |= CF_READ_ATTACHED; /* producer is now attached */ s->rep->flags |= CF_READ_ATTACHED; /* producer is now attached */
@ -2177,7 +2177,7 @@ struct task *process_session(struct task *t)
if (s->si[1].state == SI_ST_REQ) if (s->si[1].state == SI_ST_REQ)
sess_prepare_conn_req(s, &s->si[1]); sess_prepare_conn_req(s, &s->si[1]);
srv = target_srv(&s->target); srv = objt_server(s->target);
if (s->si[1].state == SI_ST_ASS && srv && srv->rdr_len && (s->flags & SN_REDIRECTABLE)) if (s->si[1].state == SI_ST_ASS && srv && srv->rdr_len && (s->flags & SN_REDIRECTABLE))
perform_http_redirect(s, &s->si[1]); perform_http_redirect(s, &s->si[1]);
} while (s->si[1].state == SI_ST_ASS); } while (s->si[1].state == SI_ST_ASS);
@ -2187,7 +2187,7 @@ struct task *process_session(struct task *t)
if ((s->flags & SN_BE_ASSIGNED) && if ((s->flags & SN_BE_ASSIGNED) &&
(s->be->mode == PR_MODE_HTTP) && (s->be->mode == PR_MODE_HTTP) &&
(s->be->server_id_hdr_name != NULL)) { (s->be->server_id_hdr_name != NULL)) {
http_send_name_header(&s->txn, s->be, target_srv(&s->target)->id); http_send_name_header(&s->txn, s->be, objt_server(s->target)->id);
} }
} }
@ -2327,10 +2327,10 @@ struct task *process_session(struct task *t)
if ((s->fe->options & PR_O_CONTSTATS) && (s->flags & SN_BE_ASSIGNED)) if ((s->fe->options & PR_O_CONTSTATS) && (s->flags & SN_BE_ASSIGNED))
session_process_counters(s); session_process_counters(s);
if (s->rep->cons->state == SI_ST_EST && s->rep->cons->conn->target.type != TARG_TYPE_APPLET) if (s->rep->cons->state == SI_ST_EST && obj_type(s->rep->cons->conn->target) != OBJ_TYPE_APPLET)
si_update(s->rep->cons); si_update(s->rep->cons);
if (s->req->cons->state == SI_ST_EST && s->req->cons->conn->target.type != TARG_TYPE_APPLET) if (s->req->cons->state == SI_ST_EST && obj_type(s->req->cons->conn->target) != OBJ_TYPE_APPLET)
si_update(s->req->cons); si_update(s->req->cons);
s->req->flags &= ~(CF_READ_NULL|CF_READ_PARTIAL|CF_WRITE_NULL|CF_WRITE_PARTIAL|CF_READ_ATTACHED); s->req->flags &= ~(CF_READ_NULL|CF_READ_PARTIAL|CF_WRITE_NULL|CF_WRITE_PARTIAL|CF_READ_ATTACHED);
@ -2357,12 +2357,12 @@ struct task *process_session(struct task *t)
/* Call the stream interfaces' I/O handlers when embedded. /* Call the stream interfaces' I/O handlers when embedded.
* Note that this one may wake the task up again. * Note that this one may wake the task up again.
*/ */
if (s->req->cons->conn->target.type == TARG_TYPE_APPLET || if (obj_type(s->req->cons->conn->target) == OBJ_TYPE_APPLET ||
s->rep->cons->conn->target.type == TARG_TYPE_APPLET) { obj_type(s->rep->cons->conn->target) == OBJ_TYPE_APPLET) {
if (s->req->cons->conn->target.type == TARG_TYPE_APPLET) if (objt_applet(s->req->cons->conn->target))
s->req->cons->conn->target.ptr.a->fct(s->req->cons); objt_applet(s->req->cons->conn->target)->fct(s->req->cons);
if (s->rep->cons->conn->target.type == TARG_TYPE_APPLET) if (objt_applet(s->rep->cons->conn->target))
s->rep->cons->conn->target.ptr.a->fct(s->rep->cons); objt_applet(s->rep->cons->conn->target)->fct(s->rep->cons);
if (task_in_rq(t)) { if (task_in_rq(t)) {
/* If we woke up, we don't want to requeue the /* If we woke up, we don't want to requeue the
* task to the wait queue, but rather requeue * task to the wait queue, but rather requeue

View File

@ -125,7 +125,7 @@ int ssl_sock_verifycbk(int ok, X509_STORE_CTX *x_store)
conn->xprt_st |= SSL_SOCK_CAEDEPTH_TO_ST(depth); conn->xprt_st |= SSL_SOCK_CAEDEPTH_TO_ST(depth);
} }
if (target_client(&conn->target)->bind_conf->ca_ignerr & (1ULL << err)) if (objt_listener(conn->target)->bind_conf->ca_ignerr & (1ULL << err))
return 1; return 1;
return 0; return 0;
@ -135,7 +135,7 @@ int ssl_sock_verifycbk(int ok, X509_STORE_CTX *x_store)
conn->xprt_st |= SSL_SOCK_CRTERROR_TO_ST(err); conn->xprt_st |= SSL_SOCK_CRTERROR_TO_ST(err);
/* check if certificate error needs to be ignored */ /* check if certificate error needs to be ignored */
if (target_client(&conn->target)->bind_conf->crt_ignerr & (1ULL << err)) if (objt_listener(conn->target)->bind_conf->crt_ignerr & (1ULL << err))
return 1; return 1;
return 0; return 0;
@ -798,15 +798,15 @@ static int ssl_sock_init(struct connection *conn)
/* If it is in client mode initiate SSL session /* If it is in client mode initiate SSL session
in connect state otherwise accept state */ in connect state otherwise accept state */
if (target_srv(&conn->target)) { if (objt_server(conn->target)) {
/* Alloc a new SSL session ctx */ /* Alloc a new SSL session ctx */
conn->xprt_ctx = SSL_new(target_srv(&conn->target)->ssl_ctx.ctx); conn->xprt_ctx = SSL_new(objt_server(conn->target)->ssl_ctx.ctx);
if (!conn->xprt_ctx) if (!conn->xprt_ctx)
return -1; return -1;
SSL_set_connect_state(conn->xprt_ctx); SSL_set_connect_state(conn->xprt_ctx);
if (target_srv(&conn->target)->ssl_ctx.reused_sess) if (objt_server(conn->target)->ssl_ctx.reused_sess)
SSL_set_session(conn->xprt_ctx, target_srv(&conn->target)->ssl_ctx.reused_sess); SSL_set_session(conn->xprt_ctx, objt_server(conn->target)->ssl_ctx.reused_sess);
/* set fd on SSL session context */ /* set fd on SSL session context */
SSL_set_fd(conn->xprt_ctx, conn->t.sock.fd); SSL_set_fd(conn->xprt_ctx, conn->t.sock.fd);
@ -817,9 +817,9 @@ static int ssl_sock_init(struct connection *conn)
sslconns++; sslconns++;
return 0; return 0;
} }
else if (target_client(&conn->target)) { else if (objt_listener(conn->target)) {
/* Alloc a new SSL session ctx */ /* Alloc a new SSL session ctx */
conn->xprt_ctx = SSL_new(target_client(&conn->target)->bind_conf->default_ctx); conn->xprt_ctx = SSL_new(objt_listener(conn->target)->bind_conf->default_ctx);
if (!conn->xprt_ctx) if (!conn->xprt_ctx)
return -1; return -1;
@ -893,13 +893,13 @@ int ssl_sock_handshake(struct connection *conn, unsigned int flag)
} }
/* Handshake succeeded */ /* Handshake succeeded */
if (target_srv(&conn->target)) { if (objt_server(conn->target)) {
if (!SSL_session_reused(conn->xprt_ctx)) { if (!SSL_session_reused(conn->xprt_ctx)) {
/* check if session was reused, if not store current session on server for reuse */ /* check if session was reused, if not store current session on server for reuse */
if (target_srv(&conn->target)->ssl_ctx.reused_sess) if (objt_server(conn->target)->ssl_ctx.reused_sess)
SSL_SESSION_free(target_srv(&conn->target)->ssl_ctx.reused_sess); SSL_SESSION_free(objt_server(conn->target)->ssl_ctx.reused_sess);
target_srv(&conn->target)->ssl_ctx.reused_sess = SSL_get1_session(conn->xprt_ctx); objt_server(conn->target)->ssl_ctx.reused_sess = SSL_get1_session(conn->xprt_ctx);
} }
} }
@ -909,9 +909,9 @@ int ssl_sock_handshake(struct connection *conn, unsigned int flag)
out_error: out_error:
/* free resumed session if exists */ /* free resumed session if exists */
if (target_srv(&conn->target) && target_srv(&conn->target)->ssl_ctx.reused_sess) { if (objt_server(conn->target) && objt_server(conn->target)->ssl_ctx.reused_sess) {
SSL_SESSION_free(target_srv(&conn->target)->ssl_ctx.reused_sess); SSL_SESSION_free(objt_server(conn->target)->ssl_ctx.reused_sess);
target_srv(&conn->target)->ssl_ctx.reused_sess = NULL; objt_server(conn->target)->ssl_ctx.reused_sess = NULL;
} }
/* Fail on all other handshake errors */ /* Fail on all other handshake errors */

View File

@ -406,7 +406,7 @@ struct task *stream_int_register_handler(struct stream_interface *si, struct si_
DPRINTF(stderr, "registering handler %p for si %p (was %p)\n", app, si, si->owner); DPRINTF(stderr, "registering handler %p for si %p (was %p)\n", app, si, si->owner);
si_prepare_embedded(si); si_prepare_embedded(si);
set_target_applet(&si->conn->target, app); si->conn->target = &app->obj_type;
si->release = app->release; si->release = app->release;
si->flags |= SI_FL_WAIT_DATA; si->flags |= SI_FL_WAIT_DATA;
return si->owner; return si->owner;
@ -419,7 +419,7 @@ void stream_int_unregister_handler(struct stream_interface *si)
{ {
si->release = NULL; si->release = NULL;
si->owner = NULL; si->owner = NULL;
clear_target(&si->conn->target); si->conn->target = NULL;
} }
/* This callback is used to send a valid PROXY protocol line to a socket being /* This callback is used to send a valid PROXY protocol line to a socket being