[MAJOR] add a connection error state to the stream_interface
Tracking connection status changes was hard, and some code was
redundant. A new SI_ST_CER state was added to the stream interface
to indicate a past connection error, and an SI_FL_ERR flag was
added to report past I/O error. The stream_sock code does not set
the connection to SI_ST_CLO anymore in case of I/O error, it's
the upper layer which does it. This makes it possible to know
exactly when the file descriptors are allocated.
The new SI_ST_CER state permitted to split tcp_connection_status()
in two parts, one processing SI_ST_CON and the other one SI_ST_CER.
Synchronous connection errors now make use of this last state, hence
eliminating duplicate code.
Some ib<->ob copy paste errors were found and fixed, and all entities
setting SI_ST_CLO also shut the buffers down.
Some of these stream_interface specific functions and structures
have migrated to a new stream_interface.c file.
Some types of errors are still not detected by the buffers. For
instance, let's assume the following scenario in one single pass
of process_session: a connection sits in SI_ST_TAR state during
a retry. At TAR expiration, a new connection attempt is made, the
connection is obtained and srv->cur_sess is increased. Then the
buffer timeout is fires and everything is cleared, the new state
becomes SI_ST_CLO. The cleaning code checks that previous state
was either SI_ST_CON or SI_ST_EST to release the connection. But
that's wrong because last state is still SI_ST_TAR. So the
server's connection count does not get decreased.
This means that prev_state must not be used, and must be replaced
by some transition detection instead of level detection.
The following debugging line was useful to track state changes :
fprintf(stderr, "%s:%d: cs=%d ss=%d(%d) rqf=0x%08x rpf=0x%08x\n", __FUNCTION__, __LINE__,
s->si[0].state, s->si[1].state, s->si[1].err_type, s->req->flags, s-> rep->flags);
2008-11-03 05:26:53 +00:00
|
|
|
/*
|
2009-10-18 21:56:35 +00:00
|
|
|
* include/proto/stream_interface.h
|
|
|
|
* This file contains stream_interface function prototypes
|
|
|
|
*
|
2012-05-11 15:47:17 +00:00
|
|
|
* Copyright (C) 2000-2012 Willy Tarreau - w@1wt.eu
|
2009-10-18 21:56:35 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
[MAJOR] add a connection error state to the stream_interface
Tracking connection status changes was hard, and some code was
redundant. A new SI_ST_CER state was added to the stream interface
to indicate a past connection error, and an SI_FL_ERR flag was
added to report past I/O error. The stream_sock code does not set
the connection to SI_ST_CLO anymore in case of I/O error, it's
the upper layer which does it. This makes it possible to know
exactly when the file descriptors are allocated.
The new SI_ST_CER state permitted to split tcp_connection_status()
in two parts, one processing SI_ST_CON and the other one SI_ST_CER.
Synchronous connection errors now make use of this last state, hence
eliminating duplicate code.
Some ib<->ob copy paste errors were found and fixed, and all entities
setting SI_ST_CLO also shut the buffers down.
Some of these stream_interface specific functions and structures
have migrated to a new stream_interface.c file.
Some types of errors are still not detected by the buffers. For
instance, let's assume the following scenario in one single pass
of process_session: a connection sits in SI_ST_TAR state during
a retry. At TAR expiration, a new connection attempt is made, the
connection is obtained and srv->cur_sess is increased. Then the
buffer timeout is fires and everything is cleared, the new state
becomes SI_ST_CLO. The cleaning code checks that previous state
was either SI_ST_CON or SI_ST_EST to release the connection. But
that's wrong because last state is still SI_ST_TAR. So the
server's connection count does not get decreased.
This means that prev_state must not be used, and must be replaced
by some transition detection instead of level detection.
The following debugging line was useful to track state changes :
fprintf(stderr, "%s:%d: cs=%d ss=%d(%d) rqf=0x%08x rpf=0x%08x\n", __FUNCTION__, __LINE__,
s->si[0].state, s->si[1].state, s->si[1].err_type, s->req->flags, s-> rep->flags);
2008-11-03 05:26:53 +00:00
|
|
|
|
|
|
|
#ifndef _PROTO_STREAM_INTERFACE_H
|
|
|
|
#define _PROTO_STREAM_INTERFACE_H
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <common/config.h>
|
2012-07-06 15:12:34 +00:00
|
|
|
#include <types/session.h>
|
[MAJOR] add a connection error state to the stream_interface
Tracking connection status changes was hard, and some code was
redundant. A new SI_ST_CER state was added to the stream interface
to indicate a past connection error, and an SI_FL_ERR flag was
added to report past I/O error. The stream_sock code does not set
the connection to SI_ST_CLO anymore in case of I/O error, it's
the upper layer which does it. This makes it possible to know
exactly when the file descriptors are allocated.
The new SI_ST_CER state permitted to split tcp_connection_status()
in two parts, one processing SI_ST_CON and the other one SI_ST_CER.
Synchronous connection errors now make use of this last state, hence
eliminating duplicate code.
Some ib<->ob copy paste errors were found and fixed, and all entities
setting SI_ST_CLO also shut the buffers down.
Some of these stream_interface specific functions and structures
have migrated to a new stream_interface.c file.
Some types of errors are still not detected by the buffers. For
instance, let's assume the following scenario in one single pass
of process_session: a connection sits in SI_ST_TAR state during
a retry. At TAR expiration, a new connection attempt is made, the
connection is obtained and srv->cur_sess is increased. Then the
buffer timeout is fires and everything is cleared, the new state
becomes SI_ST_CLO. The cleaning code checks that previous state
was either SI_ST_CON or SI_ST_EST to release the connection. But
that's wrong because last state is still SI_ST_TAR. So the
server's connection count does not get decreased.
This means that prev_state must not be used, and must be replaced
by some transition detection instead of level detection.
The following debugging line was useful to track state changes :
fprintf(stderr, "%s:%d: cs=%d ss=%d(%d) rqf=0x%08x rpf=0x%08x\n", __FUNCTION__, __LINE__,
s->si[0].state, s->si[1].state, s->si[1].err_type, s->req->flags, s-> rep->flags);
2008-11-03 05:26:53 +00:00
|
|
|
#include <types/stream_interface.h>
|
2012-08-30 20:23:13 +00:00
|
|
|
#include <proto/channel.h>
|
2012-08-17 15:33:53 +00:00
|
|
|
#include <proto/connection.h>
|
[MAJOR] add a connection error state to the stream_interface
Tracking connection status changes was hard, and some code was
redundant. A new SI_ST_CER state was added to the stream interface
to indicate a past connection error, and an SI_FL_ERR flag was
added to report past I/O error. The stream_sock code does not set
the connection to SI_ST_CLO anymore in case of I/O error, it's
the upper layer which does it. This makes it possible to know
exactly when the file descriptors are allocated.
The new SI_ST_CER state permitted to split tcp_connection_status()
in two parts, one processing SI_ST_CON and the other one SI_ST_CER.
Synchronous connection errors now make use of this last state, hence
eliminating duplicate code.
Some ib<->ob copy paste errors were found and fixed, and all entities
setting SI_ST_CLO also shut the buffers down.
Some of these stream_interface specific functions and structures
have migrated to a new stream_interface.c file.
Some types of errors are still not detected by the buffers. For
instance, let's assume the following scenario in one single pass
of process_session: a connection sits in SI_ST_TAR state during
a retry. At TAR expiration, a new connection attempt is made, the
connection is obtained and srv->cur_sess is increased. Then the
buffer timeout is fires and everything is cleared, the new state
becomes SI_ST_CLO. The cleaning code checks that previous state
was either SI_ST_CON or SI_ST_EST to release the connection. But
that's wrong because last state is still SI_ST_TAR. So the
server's connection count does not get decreased.
This means that prev_state must not be used, and must be replaced
by some transition detection instead of level detection.
The following debugging line was useful to track state changes :
fprintf(stderr, "%s:%d: cs=%d ss=%d(%d) rqf=0x%08x rpf=0x%08x\n", __FUNCTION__, __LINE__,
s->si[0].state, s->si[1].state, s->si[1].err_type, s->req->flags, s-> rep->flags);
2008-11-03 05:26:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* main event functions used to move data between sockets and buffers */
|
2009-09-20 18:14:49 +00:00
|
|
|
int stream_int_check_timeouts(struct stream_interface *si);
|
[MAJOR] add a connection error state to the stream_interface
Tracking connection status changes was hard, and some code was
redundant. A new SI_ST_CER state was added to the stream interface
to indicate a past connection error, and an SI_FL_ERR flag was
added to report past I/O error. The stream_sock code does not set
the connection to SI_ST_CLO anymore in case of I/O error, it's
the upper layer which does it. This makes it possible to know
exactly when the file descriptors are allocated.
The new SI_ST_CER state permitted to split tcp_connection_status()
in two parts, one processing SI_ST_CON and the other one SI_ST_CER.
Synchronous connection errors now make use of this last state, hence
eliminating duplicate code.
Some ib<->ob copy paste errors were found and fixed, and all entities
setting SI_ST_CLO also shut the buffers down.
Some of these stream_interface specific functions and structures
have migrated to a new stream_interface.c file.
Some types of errors are still not detected by the buffers. For
instance, let's assume the following scenario in one single pass
of process_session: a connection sits in SI_ST_TAR state during
a retry. At TAR expiration, a new connection attempt is made, the
connection is obtained and srv->cur_sess is increased. Then the
buffer timeout is fires and everything is cleared, the new state
becomes SI_ST_CLO. The cleaning code checks that previous state
was either SI_ST_CON or SI_ST_EST to release the connection. But
that's wrong because last state is still SI_ST_TAR. So the
server's connection count does not get decreased.
This means that prev_state must not be used, and must be replaced
by some transition detection instead of level detection.
The following debugging line was useful to track state changes :
fprintf(stderr, "%s:%d: cs=%d ss=%d(%d) rqf=0x%08x rpf=0x%08x\n", __FUNCTION__, __LINE__,
s->si[0].state, s->si[1].state, s->si[1].err_type, s->req->flags, s-> rep->flags);
2008-11-03 05:26:53 +00:00
|
|
|
void stream_int_report_error(struct stream_interface *si);
|
2008-11-30 18:48:07 +00:00
|
|
|
void stream_int_retnclose(struct stream_interface *si, const struct chunk *msg);
|
2012-07-06 15:12:34 +00:00
|
|
|
int conn_si_send_proxy(struct connection *conn, unsigned int flag);
|
2012-08-20 13:38:41 +00:00
|
|
|
void stream_sock_read0(struct stream_interface *si);
|
[MAJOR] add a connection error state to the stream_interface
Tracking connection status changes was hard, and some code was
redundant. A new SI_ST_CER state was added to the stream interface
to indicate a past connection error, and an SI_FL_ERR flag was
added to report past I/O error. The stream_sock code does not set
the connection to SI_ST_CLO anymore in case of I/O error, it's
the upper layer which does it. This makes it possible to know
exactly when the file descriptors are allocated.
The new SI_ST_CER state permitted to split tcp_connection_status()
in two parts, one processing SI_ST_CON and the other one SI_ST_CER.
Synchronous connection errors now make use of this last state, hence
eliminating duplicate code.
Some ib<->ob copy paste errors were found and fixed, and all entities
setting SI_ST_CLO also shut the buffers down.
Some of these stream_interface specific functions and structures
have migrated to a new stream_interface.c file.
Some types of errors are still not detected by the buffers. For
instance, let's assume the following scenario in one single pass
of process_session: a connection sits in SI_ST_TAR state during
a retry. At TAR expiration, a new connection attempt is made, the
connection is obtained and srv->cur_sess is increased. Then the
buffer timeout is fires and everything is cleared, the new state
becomes SI_ST_CLO. The cleaning code checks that previous state
was either SI_ST_CON or SI_ST_EST to release the connection. But
that's wrong because last state is still SI_ST_TAR. So the
server's connection count does not get decreased.
This means that prev_state must not be used, and must be replaced
by some transition detection instead of level detection.
The following debugging line was useful to track state changes :
fprintf(stderr, "%s:%d: cs=%d ss=%d(%d) rqf=0x%08x rpf=0x%08x\n", __FUNCTION__, __LINE__,
s->si[0].state, s->si[1].state, s->si[1].err_type, s->req->flags, s-> rep->flags);
2008-11-03 05:26:53 +00:00
|
|
|
|
2012-08-24 16:12:41 +00:00
|
|
|
extern struct si_ops si_embedded_ops;
|
|
|
|
extern struct si_ops si_conn_ops;
|
2012-10-02 22:41:04 +00:00
|
|
|
extern struct data_cb si_conn_cb;
|
2012-05-07 15:15:39 +00:00
|
|
|
|
2009-09-05 18:57:35 +00:00
|
|
|
struct task *stream_int_register_handler(struct stream_interface *si,
|
2011-02-13 12:16:36 +00:00
|
|
|
struct si_applet *app);
|
2009-09-05 18:57:35 +00:00
|
|
|
void stream_int_unregister_handler(struct stream_interface *si);
|
|
|
|
|
2012-05-21 14:31:45 +00:00
|
|
|
static inline const struct protocol *si_ctrl(struct stream_interface *si)
|
|
|
|
{
|
2012-10-26 18:10:28 +00:00
|
|
|
return si->conn->ctrl;
|
2012-05-21 14:31:45 +00:00
|
|
|
}
|
|
|
|
|
2013-09-29 15:19:56 +00:00
|
|
|
static inline void si_prepare_none(struct stream_interface *si)
|
|
|
|
{
|
|
|
|
si->ops = &si_embedded_ops;
|
|
|
|
conn_prepare(si->conn, NULL, NULL, NULL, si);
|
|
|
|
si->conn->target = NULL;
|
|
|
|
}
|
|
|
|
|
REORG: connection: rename the data layer the "transport layer"
While working on the changes required to make the health checks use the
new connections, it started to become obvious that some naming was not
logical at all in the connections. Specifically, it is not logical to
call the "data layer" the layer which is in charge for all the handshake
and which does not yet provide a data layer once established until a
session has allocated all the required buffers.
In fact, it's more a transport layer, which makes much more sense. The
transport layer offers a medium on which data can transit, and it offers
the functions to move these data when the upper layer requests this. And
it is the upper layer which iterates over the transport layer's functions
to move data which should be called the data layer.
The use case where it's obvious is with embryonic sessions : an incoming
SSL connection is accepted. Only the connection is allocated, not the
buffers nor stream interface, etc... The connection handles the SSL
handshake by itself. Once this handshake is complete, we can't use the
data functions because the buffers and stream interface are not there
yet. Hence we have to first call a specific function to complete the
session initialization, after which we'll be able to use the data
functions. This clearly proves that SSL here is only a transport layer
and that the stream interface constitutes the data layer.
A similar change will be performed to rename app_cb => data, but the
two could not be in the same commit for obvious reasons.
2012-10-02 22:19:48 +00:00
|
|
|
static inline void si_prepare_conn(struct stream_interface *si, const struct protocol *ctrl, const struct xprt_ops *xprt)
|
2012-05-07 15:15:39 +00:00
|
|
|
{
|
2012-08-24 16:12:41 +00:00
|
|
|
si->ops = &si_conn_ops;
|
2012-10-26 18:10:28 +00:00
|
|
|
conn_prepare(si->conn, &si_conn_cb, ctrl, xprt, si);
|
2012-05-07 15:15:39 +00:00
|
|
|
}
|
|
|
|
|
2012-10-02 18:57:19 +00:00
|
|
|
static inline void si_takeover_conn(struct stream_interface *si, const struct protocol *ctrl, const struct xprt_ops *xprt)
|
|
|
|
{
|
|
|
|
si->ops = &si_conn_ops;
|
2012-10-26 18:10:28 +00:00
|
|
|
conn_assign(si->conn, &si_conn_cb, ctrl, xprt, si);
|
2012-10-02 18:57:19 +00:00
|
|
|
}
|
|
|
|
|
2013-09-29 15:19:56 +00:00
|
|
|
static inline void si_prepare_applet(struct stream_interface *si, struct si_applet *applet)
|
2012-08-24 16:12:41 +00:00
|
|
|
{
|
|
|
|
si->ops = &si_embedded_ops;
|
2012-10-26 18:10:28 +00:00
|
|
|
conn_prepare(si->conn, NULL, NULL, NULL, si);
|
2013-09-29 15:19:56 +00:00
|
|
|
si->conn->target = &applet->obj_type;
|
2012-08-24 16:12:41 +00:00
|
|
|
}
|
|
|
|
|
2012-05-21 14:31:45 +00:00
|
|
|
/* Sends a shutr to the connection using the data layer */
|
|
|
|
static inline void si_shutr(struct stream_interface *si)
|
|
|
|
{
|
2013-09-29 13:16:03 +00:00
|
|
|
si->ops->shutr(si);
|
2012-05-21 14:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Sends a shutw to the connection using the data layer */
|
|
|
|
static inline void si_shutw(struct stream_interface *si)
|
|
|
|
{
|
2013-09-29 13:16:03 +00:00
|
|
|
si->ops->shutw(si);
|
2012-05-21 14:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Calls the data state update on the stream interfaace */
|
|
|
|
static inline void si_update(struct stream_interface *si)
|
|
|
|
{
|
2012-08-24 16:12:41 +00:00
|
|
|
si->ops->update(si);
|
2012-05-21 14:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Calls chk_rcv on the connection using the data layer */
|
|
|
|
static inline void si_chk_rcv(struct stream_interface *si)
|
|
|
|
{
|
2012-08-24 16:12:41 +00:00
|
|
|
si->ops->chk_rcv(si);
|
2012-05-21 14:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Calls chk_snd on the connection using the data layer */
|
|
|
|
static inline void si_chk_snd(struct stream_interface *si)
|
|
|
|
{
|
2012-08-24 16:12:41 +00:00
|
|
|
si->ops->chk_snd(si);
|
2012-05-21 14:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Calls chk_snd on the connection using the ctrl layer */
|
|
|
|
static inline int si_connect(struct stream_interface *si)
|
|
|
|
{
|
2012-08-30 20:23:13 +00:00
|
|
|
int ret;
|
|
|
|
|
2012-05-21 14:31:45 +00:00
|
|
|
if (unlikely(!si_ctrl(si) || !si_ctrl(si)->connect))
|
|
|
|
return SN_ERR_INTERNAL;
|
2012-08-30 20:23:13 +00:00
|
|
|
|
2012-11-24 09:24:27 +00:00
|
|
|
ret = si_ctrl(si)->connect(si->conn, !channel_is_empty(si->ob), !!si->send_proxy_ofs);
|
2012-08-30 20:23:13 +00:00
|
|
|
if (ret != SN_ERR_NONE)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* needs src ip/port for logging */
|
|
|
|
if (si->flags & SI_FL_SRC_ADDR)
|
2012-10-26 18:10:28 +00:00
|
|
|
conn_get_from_addr(si->conn);
|
2012-08-30 20:23:13 +00:00
|
|
|
|
|
|
|
/* Prepare to send a few handshakes related to the on-wire protocol. */
|
|
|
|
if (si->send_proxy_ofs)
|
2012-10-26 18:10:28 +00:00
|
|
|
si->conn->flags |= CO_FL_SI_SEND_PROXY;
|
2012-08-30 20:23:13 +00:00
|
|
|
|
|
|
|
/* we need to be notified about connection establishment */
|
2012-10-26 18:10:28 +00:00
|
|
|
si->conn->flags |= CO_FL_WAKE_DATA;
|
2012-08-30 20:23:13 +00:00
|
|
|
|
|
|
|
/* we're in the process of establishing a connection */
|
|
|
|
si->state = SI_ST_CON;
|
|
|
|
|
|
|
|
return ret;
|
2012-05-21 14:31:45 +00:00
|
|
|
}
|
2012-05-11 14:16:40 +00:00
|
|
|
|
2012-12-08 16:48:47 +00:00
|
|
|
/* for debugging, reports the stream interface state name */
|
|
|
|
static inline const char *si_state_str(int state)
|
|
|
|
{
|
|
|
|
switch (state) {
|
|
|
|
case SI_ST_INI: return "INI";
|
|
|
|
case SI_ST_REQ: return "REQ";
|
|
|
|
case SI_ST_QUE: return "QUE";
|
|
|
|
case SI_ST_TAR: return "TAR";
|
|
|
|
case SI_ST_ASS: return "ASS";
|
|
|
|
case SI_ST_CON: return "CON";
|
|
|
|
case SI_ST_CER: return "CER";
|
|
|
|
case SI_ST_EST: return "EST";
|
|
|
|
case SI_ST_DIS: return "DIS";
|
|
|
|
case SI_ST_CLO: return "CLO";
|
|
|
|
default: return "???";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[MAJOR] add a connection error state to the stream_interface
Tracking connection status changes was hard, and some code was
redundant. A new SI_ST_CER state was added to the stream interface
to indicate a past connection error, and an SI_FL_ERR flag was
added to report past I/O error. The stream_sock code does not set
the connection to SI_ST_CLO anymore in case of I/O error, it's
the upper layer which does it. This makes it possible to know
exactly when the file descriptors are allocated.
The new SI_ST_CER state permitted to split tcp_connection_status()
in two parts, one processing SI_ST_CON and the other one SI_ST_CER.
Synchronous connection errors now make use of this last state, hence
eliminating duplicate code.
Some ib<->ob copy paste errors were found and fixed, and all entities
setting SI_ST_CLO also shut the buffers down.
Some of these stream_interface specific functions and structures
have migrated to a new stream_interface.c file.
Some types of errors are still not detected by the buffers. For
instance, let's assume the following scenario in one single pass
of process_session: a connection sits in SI_ST_TAR state during
a retry. At TAR expiration, a new connection attempt is made, the
connection is obtained and srv->cur_sess is increased. Then the
buffer timeout is fires and everything is cleared, the new state
becomes SI_ST_CLO. The cleaning code checks that previous state
was either SI_ST_CON or SI_ST_EST to release the connection. But
that's wrong because last state is still SI_ST_TAR. So the
server's connection count does not get decreased.
This means that prev_state must not be used, and must be replaced
by some transition detection instead of level detection.
The following debugging line was useful to track state changes :
fprintf(stderr, "%s:%d: cs=%d ss=%d(%d) rqf=0x%08x rpf=0x%08x\n", __FUNCTION__, __LINE__,
s->si[0].state, s->si[1].state, s->si[1].err_type, s->req->flags, s-> rep->flags);
2008-11-03 05:26:53 +00:00
|
|
|
#endif /* _PROTO_STREAM_INTERFACE_H */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* c-indent-level: 8
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* End:
|
|
|
|
*/
|