From: Willy Tarreau Date: Fri, 30 Nov 2012 16:33:05 +0000 (+0100) Subject: MEDIUM: connection: add an error code in connections X-Git-Tag: v1.5-dev15~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=14cba4b0b1240e207ac8df3d876d71da60ccb42d;p=thirdparty%2Fhaproxy.git MEDIUM: connection: add an error code in connections This will be needed to improve error reporting, especially for SSL. --- diff --git a/include/types/connection.h b/include/types/connection.h index 6149dd598a..6f8a59f2db 100644 --- a/include/types/connection.h +++ b/include/types/connection.h @@ -142,6 +142,12 @@ enum { CO_FL_XPRT_TRACKED = 0x80000000, }; + +/* possible connection error codes */ +enum { + CO_ER_NONE, /* no error */ +}; + /* xprt_ops describes transport-layer operations for a connection. They * 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_*) @@ -186,7 +192,7 @@ struct connection { const struct protocol *ctrl; /* operations at the socket layer */ const struct xprt_ops *xprt; /* operations at the transport layer */ const struct data_cb *data; /* data layer callbacks */ - unsigned int flags; /* CO_F_* */ + unsigned int flags; /* CO_FL_* */ int xprt_st; /* transport layer state, initialized to zero */ void *xprt_ctx; /* general purpose pointer, initialized to NULL */ void *owner; /* pointer to upper layer's entity (eg: stream interface) */ @@ -195,6 +201,7 @@ struct connection { int fd; /* file descriptor for a stream driver when known */ } sock; } t; + unsigned int err_code; /* CO_ER_* */ enum obj_type *target; /* the target to connect to (server, proxy, applet, ...) */ struct { struct sockaddr_storage from; /* client address, or address to spoof when connecting to the server */ diff --git a/src/checks.c b/src/checks.c index a0637c29df..394d29ef75 100644 --- a/src/checks.c +++ b/src/checks.c @@ -1298,6 +1298,7 @@ static struct task *process_chk(struct task *t) /* prepare a new connection */ conn->flags = CO_FL_NONE; + conn->err_code = CO_ER_NONE; conn->target = &s->obj_type; conn_prepare(conn, &check_conn_cb, s->check.proto, s->check.xprt, s); diff --git a/src/peers.c b/src/peers.c index 6870f8f86f..688d64cf9f 100644 --- a/src/peers.c +++ b/src/peers.c @@ -1156,6 +1156,7 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio s->si[0].conn->t.sock.fd = -1; s->si[0].conn->flags = CO_FL_NONE; + s->si[0].conn->err_code = CO_ER_NONE; s->si[0].owner = t; s->si[0].state = s->si[0].prev_state = SI_ST_EST; s->si[0].err_type = SI_ET_NONE; @@ -1174,6 +1175,7 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio s->si[1].conn->t.sock.fd = -1; /* just to help with debugging */ s->si[1].conn->flags = CO_FL_NONE; + s->si[1].conn->err_code = CO_ER_NONE; s->si[1].owner = t; s->si[1].state = s->si[1].prev_state = SI_ST_ASS; s->si[1].conn_retries = p->conn_retries; diff --git a/src/proto_http.c b/src/proto_http.c index c01dfd288f..0e51c089f4 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -4093,6 +4093,7 @@ void http_end_txn_clean_session(struct session *s) 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->flags = CO_FL_NONE; + s->req->cons->conn->err_code = CO_ER_NONE; s->req->cons->err_type = SI_ET_NONE; s->req->cons->conn_retries = 0; /* used for logging too */ s->req->cons->err_loc = NULL; diff --git a/src/session.c b/src/session.c index 330d7228f8..f7c802b8dd 100644 --- a/src/session.c +++ b/src/session.c @@ -109,6 +109,7 @@ int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr) s->si[0].conn->t.sock.fd = cfd; s->si[0].conn->ctrl = l->proto; s->si[0].conn->flags = CO_FL_NONE; + s->si[0].conn->err_code = CO_ER_NONE; s->si[0].conn->addr.from = *addr; s->si[0].conn->target = &l->obj_type; @@ -403,6 +404,7 @@ int session_complete(struct session *s) */ s->si[1].conn->t.sock.fd = -1; /* just to help with debugging */ s->si[1].conn->flags = CO_FL_NONE; + s->si[1].conn->err_code = CO_ER_NONE; s->si[1].owner = t; s->si[1].state = s->si[1].prev_state = SI_ST_INI; s->si[1].err_type = SI_ET_NONE;