haproxy/include/proto
Willy Tarreau f79c8171b2 MAJOR: connection: add two new flags to indicate readiness of control/transport
Currently the control and transport layers of a connection are supposed
to be initialized when their respective pointers are not NULL. This will
not work anymore when we plan to reuse connections, because there is an
asymmetry between the accept() side and the connect() side :

  - on accept() side, the fd is set first, then the ctrl layer then the
    transport layer ; upon error, they must be undone in the reverse order,
    then the FD must be closed. The FD must not be deleted if the control
    layer was not yet initialized ;

  - on the connect() side, the fd is set last and there is no reliable way
    to know if it has been initialized or not. In practice it's initialized
    to -1 first but this is hackish and supposes that local FDs only will
    be used forever. Also, there are even less solutions for keeping trace
    of the transport layer's state.

Also it is possible to support delayed close() when something (eg: logs)
tracks some information requiring the transport and/or control layers,
making it even more difficult to clean them.

So the proposed solution is to add two flags to the connection :

  - CO_FL_CTRL_READY is set when the control layer is initialized (fd_insert)
    and cleared after it's released (fd_delete).

  - CO_FL_XPRT_READY is set when the control layer is initialized (xprt->init)
    and cleared after it's released (xprt->close).

The functions have been adapted to rely on this and not on the pointers
anymore. conn_xprt_close() was unused and dangerous : it did not close
the control layer (eg: the socket itself) but still marks the transport
layer as closed, preventing any future call to conn_full_close() from
finishing the job.

The problem comes from conn_full_close() in fact. It needs to close the
xprt and ctrl layers independantly. After that we're still having an issue :
we don't know based on ->ctrl alone whether the fd was registered or not.
For this we use the two new flags CO_FL_XPRT_READY and CO_FL_CTRL_READY. We
now rely on this and not on conn->xprt nor conn->ctrl anymore to decide what
remains to be done on the connection.

In order not to miss some flag assignments, we introduce conn_ctrl_init()
to initialize the control layer, register the fd using fd_insert() and set
the flag, and conn_ctrl_close() which unregisters the fd and removes the
flag, but only if the transport layer was closed.

Similarly, at the transport layer, conn_xprt_init() calls ->init and sets
the flag, while conn_xprt_close() checks the flag, calls ->close and clears
the flag, regardless xprt_ctx or xprt_st. This also ensures that the ->init
and the ->close functions are called only once each and in the correct order.
Note that conn_xprt_close() does nothing if the transport layer is still
tracked.

conn_full_close() now simply calls conn_xprt_close() then conn_full_close()
in turn, which do nothing if CO_FL_XPRT_TRACKED is set.

In order to handle the error path, we also provide conn_force_close() which
ignores CO_FL_XPRT_TRACKED and closes the transport and the control layers
in turns. All relevant instances of fd_delete() have been replaced with
conn_force_close(). Now we always know what state the connection is in and
we can expect to split its initialization.
2013-12-09 15:40:23 +01:00
..
acl.h MINOR: acl/pattern: use types different from int to clarify who does what. 2013-12-02 23:31:33 +01:00
arg.h MAJOR: sample: maintain a per-proxy list of the fetch args to resolve 2013-04-03 02:13:02 +02:00
auth.h MINOR: acl/pattern: use types different from int to clarify who does what. 2013-12-02 23:31:33 +01:00
backend.h REORG/MAJOR: use "struct channel" instead of "struct buffer" 2012-09-02 21:54:55 +02:00
channel.h BUG/MAJOR: http: always ensure response buffer has some room for a response 2013-06-08 13:14:17 +02:00
checks.h MEDIUM: Paramatise functions over the check of a server 2013-11-19 09:35:54 +01:00
compression.h MINOR: compression: CPU usage limit 2012-11-21 02:15:16 +01:00
connection.h MAJOR: connection: add two new flags to indicate readiness of control/transport 2013-12-09 15:40:23 +01:00
cttproxy.h
dumpstats.h MAJOR: stats: move the HTTP stats handling to its applet 2013-12-09 15:40:22 +01:00
fd.h OPTIM: poll: optimize fd management functions for low register count CPUs 2012-12-13 23:34:18 +01:00
freq_ctr.h
frontend.h REORG: connection: move the PROXY protocol management to connection.c 2012-10-05 00:32:33 +02:00
hdr_idx.h OPTIM/MINOR: move the hdr_idx pools out of the proxy struct 2011-10-24 18:15:04 +02:00
lb_chash.h
lb_fas.h MEDIUM: backend: add the 'first' balancing algorithm 2012-02-21 22:27:27 +01:00
lb_fwlc.h
lb_fwrr.h
lb_map.h
listener.h CLEANUP: fix missing include <string.h> in proto/listener.h 2013-06-14 19:52:17 +02:00
log.h MINOR: log: indicate it when some unreliable sample fetches are logged 2013-04-03 02:12:56 +02:00
obj_type.h MINOR: obj: introduce a new type appctx 2013-12-09 15:40:22 +01:00
pattern.h MINOR: pattern: import acl_find_match_name() into pattern.h 2013-12-02 23:31:33 +01:00
payload.h MINOR: payload: split smp_fetch_rdp_cookie() 2013-08-01 21:17:13 +02:00
peers.h [CLEANUP] peers.h: fix declarations 2011-06-18 20:27:19 +02:00
pipe.h
port_range.h
proto_http.h MEDIUM: http: The redirect strings follows the log format rules. 2013-12-02 23:31:33 +01:00
proto_tcp.h BUG/MINOR: config: report the correct track-sc number in tcp-rules 2013-12-02 23:31:32 +01:00
proto_uxst.h BUG/MEDIUM: stream_interface: restore get_src/get_dst 2012-05-11 16:48:10 +02:00
protocol.h REORG: split "protocols" files into protocol and listener 2012-09-15 22:29:32 +02:00
proxy.h REORG: split "protocols" files into protocol and listener 2012-09-15 22:29:32 +02:00
queue.h BUG/MEDIUM: zero-weight servers must not dequeue requests from the backend 2012-01-20 16:18:53 +01:00
raw_sock.h REORG: connection: rename the data layer the "transport layer" 2012-10-04 22:26:09 +02:00
sample.h MEDIUM: acl: use the fetch syntax 'fetch(args),conv(),conv()' into the ACL keyword 2013-12-02 23:31:32 +01:00
server.h MEDIUM: Add DRAIN state and report it on the stats page 2013-11-25 07:31:16 +01:00
session.h MINOR: session: add a simple function to retrieve a session from a task 2013-12-09 15:40:21 +01:00
shctx.h MINOR: ssl: Setting global tune.ssl.cachesize value to 0 disables SSL session cache. 2012-12-28 14:48:13 +01:00
signal.h CLEANUP: includes: fix includes for a number of users of fd.h 2012-09-03 20:49:14 +02:00
ssl_sock.h MEDIUM: log: report SSL ciphers and version in logs using logformat %sslc/%sslv 2012-10-12 20:48:51 +02:00
stick_table.h MEDIUM: stick-tables: flush old entries upon soft-stop 2013-09-04 17:54:01 +02:00
stream_interface.h MINOR: get rid of si_takeover_conn() 2013-12-09 15:40:23 +01:00
task.h [MAJOR] proxy: finally get rid of maintain_proxies() 2011-07-25 16:33:49 +02:00
template.h