]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
6 years agoBUILD: ssl_sock: remove build warnings on potential null-derefs
Willy Tarreau [Thu, 20 Sep 2018 08:57:52 +0000 (10:57 +0200)] 
BUILD: ssl_sock: remove build warnings on potential null-derefs

When building with -Wnull-dereferences, gcc sees some cases where a
pointer is dereferenced after a check may set it to null. While all of
these are already guarded by either a preliminary test or the code's
construction (eg: listeners code being called only on listeners), it
cannot be blamed for not "seeing" this, so better use the unguarded
calls everywhere this happens, particularly after checks. This is a
step towards building with -Wextra.

6 years agoMINOR: stream-int: make si_appctx() never fail
Willy Tarreau [Thu, 20 Sep 2018 09:08:47 +0000 (11:08 +0200)] 
MINOR: stream-int: make si_appctx() never fail

Callers of si_appctx() always use the result without checking it because
they know by construction that it's valid. This results in unchecked null
pointer warnings at -Wextra, so let's remove this test and make it clear
that it's up to the caller to check validity first.

6 years agoMINOR: stktable: provide an unchecked version of stktable_data_ptr()
Willy Tarreau [Thu, 20 Sep 2018 09:06:33 +0000 (11:06 +0200)] 
MINOR: stktable: provide an unchecked version of stktable_data_ptr()

stktable_data_ptr() currently performs null pointer checks but most
callers don't check the result since they know by construction that
it cannot be null. This causes valid warnings when building with
-Wextra which are worth addressing since it will result in better
code. Let's provide an unguarded version of this function for use
where the check is known to be useless and untested.

6 years agoBUG/MINOR: cli: make sure the "getsock" command is only called on connections
Willy Tarreau [Thu, 20 Sep 2018 09:22:29 +0000 (11:22 +0200)] 
BUG/MINOR: cli: make sure the "getsock" command is only called on connections

Theorically nothing would prevent a front applet form connecting to a stats
socket, and if a "getsock" command was issued, it would cause a crash. Right
now nothing in the code does this so in its current form there is no impact.

It may or may not be backported to 1.8.

6 years agoBUG/MINOR: tools: fix set_net_port() / set_host_port() on IPv4
Willy Tarreau [Thu, 20 Sep 2018 08:48:35 +0000 (10:48 +0200)] 
BUG/MINOR: tools: fix set_net_port() / set_host_port() on IPv4

These two functions were apparently written on the same model as their
parents when added by commit 11bcb6c4f ("[MEDIUM] IPv6 support for syslog")
except that they perform an assignment instead of a return, and as a
result fall through the next case where the assigned value may possibly
be partially overwritten. At least under Linux the port offset is the
same in both sockaddr_in and sockaddr_in6 so the value is written twice
without side effects.

This needs to be backported as far as 1.5.

6 years agoCLEANUP/CONTRIB: hpack: remove some h1 build warnings
Willy Tarreau [Mon, 17 Sep 2018 09:44:09 +0000 (11:44 +0200)] 
CLEANUP/CONTRIB: hpack: remove some h1 build warnings

These are inherited by recent reorganization to the H1 code.

6 years agoBUG/MEDIUM: h1: Really skip all updates when incomplete messages are parsed
Christopher Faulet [Wed, 19 Sep 2018 12:01:04 +0000 (14:01 +0200)] 
BUG/MEDIUM: h1: Really skip all updates when incomplete messages are parsed

In h1_headers_to_hdr_list, when an incomplete message is parsed, all updates
must be skipped until the end of the message is found. Then the parsing is
restarted from the beginning. But not all updates were skipped, leading to
invalid rewritting or segfault.

No backport is needed.

6 years agoBUG/MEDIUM: patterns: fix possible double free when reloading a pattern list
Dragan Dosen [Tue, 18 Sep 2018 18:18:09 +0000 (20:18 +0200)] 
BUG/MEDIUM: patterns: fix possible double free when reloading a pattern list

A null pointer assignment was missing after free() in function
pat_ref_reload() which can lead to segfault.

This bug was introduced in commit b5997f7 ("MAJOR: threads/map: Make
acls/maps thread safe").

Must be backported to 1.8.

6 years agoMEDIUM: h1: deduplicate the content-length header
Willy Tarreau [Fri, 14 Sep 2018 15:11:33 +0000 (17:11 +0200)] 
MEDIUM: h1: deduplicate the content-length header

Just like we used to do in proto_http, we now check that each and every
occurrence of the content-length header field and each of its values are
exactly identical, and we normalize the header to return the last value
of the first header with spaces trimmed.

6 years agoMEDIUM: h1: better handle transfer-encoding vs content-length
Willy Tarreau [Fri, 14 Sep 2018 14:34:47 +0000 (16:34 +0200)] 
MEDIUM: h1: better handle transfer-encoding vs content-length

The transfer-encoding header processing was a bit lenient in this part
because it was made to read messages already validated by haproxy. We
absolutely need to reinstate the strict processing defined in RFC7230
as is currently being done in proto_http.c. That is, transfer-encoding
presence alone is enough to cancel content-length, and must be
terminated by the "chunked" token, except in the response where we
can fall back to the close mode if it's not last.

For this we now use a specific parsing function which updates the
flags and we introduce a new flag H1_MF_XFER_ENC indicating that the
transfer-encoding header is present.

Last, if such a header is found, we delete all content-length header
fields found in the message.

6 years agoMINOR: h1: add headers to the list after controls, not before
Willy Tarreau [Fri, 14 Sep 2018 14:28:15 +0000 (16:28 +0200)] 
MINOR: h1: add headers to the list after controls, not before

This will ease removal/skipping of duplicates such as content-length.

6 years agoMINOR: http: add http_hdr_del() to remove a header from a list
Willy Tarreau [Fri, 14 Sep 2018 15:32:05 +0000 (17:32 +0200)] 
MINOR: http: add http_hdr_del() to remove a header from a list

This one removes all occurrences of the specified header field name from
a complete list and returns the new count.

6 years agoMINOR: h1: Add H1_MF_XFER_LEN flag
Christopher Faulet [Fri, 14 Sep 2018 09:15:52 +0000 (11:15 +0200)] 
MINOR: h1: Add H1_MF_XFER_LEN flag

This flag is usefull to handle cases where there is no body, regardless of CL or
TE headers (for instance, responses to HEAD requests). It will not be set by the
parser itself.

6 years agoDOC: Fix typos in lua documentation
Bertrand Jacquin [Mon, 10 Sep 2018 20:26:07 +0000 (21:26 +0100)] 
DOC: Fix typos in lua documentation

6 years agoMINOR: h1: parse the Connection header field
Willy Tarreau [Thu, 13 Sep 2018 12:15:58 +0000 (14:15 +0200)] 
MINOR: h1: parse the Connection header field

The new function h1_parse_connection_header() is called when facing a
connection header in the generic parser, and it will set up to 3 bits
in h1m->flags indicating if at least one "close", "keep-alive" or "upgrade"
tokens was seen.

6 years agoMINOR: h1: report in the h1m struct if the HTTP version is 1.1 or above
Willy Tarreau [Thu, 13 Sep 2018 09:32:51 +0000 (11:32 +0200)] 
MINOR: h1: report in the h1m struct if the HTTP version is 1.1 or above

This will be needed for the mux to know how to process the Connection
header, and will save it from having to re-parse the request line since
it's captured on the fly.

6 years agoBUG/MINOR: h1: don't consider the status for each header
Willy Tarreau [Thu, 13 Sep 2018 09:52:20 +0000 (11:52 +0200)] 
BUG/MINOR: h1: don't consider the status for each header

While it was possible to consider the status before parsing response
headers, it's wrong to do it for request headers and could lead to
random behaviours due to this status matching other fields instead.
Additionnally there is little to no value in doing this for each and
every new header field. It's much better to reset the content-length
at once in the callerwhen seeing such statuses (which currently is only
the H2 mux).

No backport is needed, this is purely 1.9.

6 years ago[RELEASE] Released version 1.9-dev2 v1.9-dev2
Willy Tarreau [Wed, 12 Sep 2018 16:59:48 +0000 (18:59 +0200)] 
[RELEASE] Released version 1.9-dev2

Released version 1.9-dev2 with the following main changes :
    - BUG/MINOR: buffers: Fix b_slow_realign when a buffer is realign without output
    - BUG/MEDIUM: threads: fix the no-thread case after the change to the sync point
    - BUG/MEDIUM: servers: check the queues once enabling a server
    - BUG/MEDIUM: queue: prevent a backup server from draining the proxy's connections
    - MEDIUM: mux: Remove const on the buffer in mux->snd_buf()
    - CLEANUP: backend: Move mux install to call it at only one place
    - MINOR: conn_stream: add an tx buffer to the conn_stream
    - MINOR: conn_stream: add cs_send() as a default snd_buf() function
    - MINOR: backend: Try to find the best mux for outgoing connections
    - MEDIUM: backend: don't rely on mux_pt_ops in connect_server()
    - MINOR: mux: Add info about the supported side in alpn_mux_list structure
    - MINOR: mux: Unlink ALPN and multiplexers to rather speak of mux protocols
    - MINOR: mux: Print the list of existing mux protocols during HA startup
    - MEDIUM: checks: use the new rendez-vous point to spread check result
    - MEDIUM: haproxy: don't use sync_poll_loop() anymore in the main loop
    - MINOR: threads: remove the previous synchronization point
    - MAJOR: server: make server state changes synchronous again
    - CLEANUP: server: remove the update list and the update lock
    - BUG/MINOR: threads: Remove the unexisting lock label "UPDATED_SERVERS_LOCK"
    - BUG/MEDIUM: stream_int: Don't check CO_FL_SOCK_RD_SH flag to trigger cs receive
    - MINOR: mux: Change get_mux_proto to get an ist as parameter
    - MINOR: mux: Improve the message with the list of existing mux protocols
    - MINOR: mux/frontend: Add 'proto' keyword to force the mux protocol
    - MINOR: mux/server: Add 'proto' keyword to force the multiplexer's protocol
    - MEDIUM: mux: Use the mux protocol specified on bind/server lines
    - BUG/MEDIUM: connection/mux: take care of serverless proxies
    - MINOR: queue: make sure the pendconn is released before logging
    - MINOR: stream: rename {srv,prx}_queue_size to *_queue_pos
    - MINOR: queue: store the queue index in the stream when enqueuing
    - MINOR: queue: replace the linked list with a tree
    - MEDIUM: add set-priority-class and set-priority-offset
    - MEDIUM: queue: adjust position based on priority-class and priority-offset
    - DOC: update the roadmap about priority queues
    - BUG/MINOR: ssl: empty connections reported as errors.
    - MINOR: connections: Make rcv_buf mandatory and nuke cs_recv().
    - MINOR: connections: Move rxbuf from the conn_stream to the h2s.
    - MINOR: connections: Get rid of txbuf.
    - MINOR: tasks: Allow tasklet_wakeup() to wakeup a task.
    - MINOR: connections/mux: Add the wait reason(s) to wait_list.
    - MINOR: stream_interface: Don't use si_cs_send() as a task handler.
    - MINOR: stream_interface: Give stream_interface its own wait_list.
    - MINOR: mux_h2: Don't use h2_send() as a callback.
    - MINOR: checks: Add event_srv_chk_io().
    - BUG/MEDIUM: tasks: Don't insert in the global rqueue if nbthread == 1
    - BUG/MEDIUM: sessions: Don't use t->state.
    - BUG/MEDIUM: ssl: fix missing error loading a keytype cert from a bundle.
    - BUG/MEDIUM: ssl: loading dh param from certifile causes unpredictable error.
    - BUG/MINOR: map: fix map_regm with backref
    - DOC: dns: explain set server ... fqdn requires resolver
    - DOC: add documentation for prio_class and prio_offset sample fetches.
    - DOC: ssl: Use consistent naming for TLS protocols
    - DOC: update the layering design notes
    - MINOR: tasks: Don't special-case when nbthreads == 1
    - MINOR: fd cache: And the thread_mask with all_threads_mask.
    - BUG/MEDIUM: lua: socket timeouts are not applied
    - BUG/MINOR: lua: fix extra 500ms added to socket timeouts
    - BUG/MEDIUM: server: update our local state before propagating changes
    - BUG/MEDIUM: cli/threads: protect all "proxy" commands against concurrent updates
    - DOC: server/threads: document which functions need to be called with/without locks
    - BUG/MEDIUM: cli/threads: protect some server commands against concurrent operations
    - BUG/MEDIUM: streams: Don't forget to remove the si from the wait list.
    - BUG/MEDIUM: tasklets: Add the thread as active when waking a tasklet.
    - BUG/MEDIUM: stream-int: Check if the conn_stream exist in si_cs_io_cb.
    - BUG/MEDIUM: H2: Activate polling after successful h2_snd_buf().
    - BUG/MEDIUM: stream_interface: Call the wake callback after sending.
    - BUG/MAJOR: queue/threads: make pendconn_redistribute not lock the server
    - BUG/MEDIUM: connection: don't forget to always delete the list's head
    - BUG/MEDIUM: lb/threads: always properly lock LB algorithms on maintenance operations
    - BUG/MEDIUM: check/threads: do not involve the rendez-vous point for status updates
    - BUG/MINOR: chunks: do not store -1 into chunk_printf() in case of error
    - BUG/MEDIUM: http: don't store exp_replace() result in the trash's length
    - BUG/MEDIUM: http: don't store url_decode() result in the samples's length
    - BUG/MEDIUM: dns: don't store dns_build_query() result in the trash's length
    - BUG/MEDIUM: map: don't store exp_replace() result in the trash's length
    - BUG/MEDIUM: connection: don't store recv() result into trash.data
    - BUG/MEDIUM: cli/ssl: don't store base64dec() result in the trash's length
    - MINOR: chunk: remove impossible tests on negative chunk->data
    - MINOR: sample: remove impossible tests on negative smp->data.u.str.data
    - DOC: Fix spelling error in configuration doc
    - REGTEST/MINOR: Missing mandatory "ignore_unknown_macro".
    - REGTEST/MINOR: Add a new class of regression testing files.
    - BUG/MEDIUM: unix: provide a ->drain() function
    - MINOR: connection: make conn_sock_drain() work for all socket families
    - BUG/MINOR: lua: Bad HTTP client request duration.
    - REGEST/MINOR: Add reg testing files.
    - BUG/MEDIUM: mux_pt: dereference the connection with care in mux_pt_wake()
    - REGTEST/MINOR: Add a reg testing file for b406b87 commit.
    - BUG/MEDIUM: lua: reset lua transaction between http requests
    - MINOR: add be_conn_free sample fetch
    - MINOR: Add srv_conn_free sample fetch
    - BUG/MEDIUM: hlua: Make sure we drain the output buffer when done.
    - MINOR: checks: Call wake_srv_chk() when we can finally send data.
    - BUG/MEDIUM: stream_interface: try to call si_cs_send() earlier.
    - BUG/MAJOR: thread: lua: Wrong SSL context initialization.
    - REGTEST/MINOR: Add a reg testing file for 3e60b11.
    - BUG/MEDIUM: hlua: Don't call RESET_SAFE_LJMP if SET_SAFE_LJMP returns 0.
    - REGTEST/MINOR: lua: Add reg testing files for 70d318c.
    - BUG/MEDIUM: dns/server: fix incomatibility between SRV resolution and server state file
    - BUG/MEDIUM: ECC cert should work with TLS < v1.2 and openssl >= 1.1.1
    - MINOR: tools: make date2str_log() take some consts
    - MINOR: thread: implement HA_ATOMIC_XADD()
    - BUG/MINOR: stream: use atomic increments for the request counter
    - BUG/MEDIUM: session: fix reporting of handshake processing time in the logs
    - BUG/MEDIUM: h2: fix risk of memory leak on malformated wrapped frames
    - BUG/MAJOR: buffer: fix incorrect check in __b_putblk()
    - MINOR: log: move the log code to sess_build_logline() to add extra arguments
    - MINOR: log: make the backend fall back to the frontend when there's no stream
    - MINOR: log: make sess_build_logline() not dereference a NULL stream for txn
    - MINOR: log: don't unconditionally pick log info from s->logs
    - CLEANUP: log: make the low_level lf_{ip,port,text,text_len} functions take consts
    - MINOR: log: keep a copy of the backend connection early in sess_build_logline()
    - MINOR: log: do not dereference a null stream to access captures
    - MINOR: log: be sure not to dereference a null stream for a target
    - MINOR: log: don't check the stream-int's conn_retries if the stream is NULL
    - MINOR: log: use NULL for the unique_id if there is no stream
    - MINOR: log: keep a copy of s->flags early to avoid a dereference
    - MINOR: log: use zero as the request counter if there is no stream
    - MEDIUM: log: make sess_build_logline() support being called with no stream
    - MINOR: log: provide a function to emit a log for a session
    - MEDIUM: h2: produce some logs on early errors that prevent streams from being created
    - BUG/MINOR: h1: fix buffer shift after realignment
    - MINOR: connection: make the initialization more consistent
    - MINOR: connection: add new function conn_get_proxy()
    - MINOR: connection: add new function conn_is_back()
    - MINOR: log: One const should be enough.
    - BUG/MINOR: dns: check and link servers' resolvers right after config parsing
    - BUG/MINOR: http/threads: atomically increment the error snapshot ID
    - MINOR: snapshot: restart on the event ID and not the stream ID
    - MINOR: snapshot: split the error snapshots into common and proto-specific parts
    - MEDIUM: snapshot: start to reorder the HTTP snapshot output a little bit
    - MEDIUM: snapshot: implement a show() callback and use it for HTTP
    - MINOR: proxy: add a new generic proxy_capture_error()
    - MINOR: http: make the HTTP error capture rely on the generic proxy code
    - MINOR: http: remove the pointer to the error snapshot in http_capture_bad_message()
    - REORG: cli: move the "show errors" handler from http to proxy
    - BUG/MEDIUM: snapshot: take the proxy's lock while dumping errors
    - MEDIUM: snapshots: dynamically allocate the snapshots
    - MEDIUM: snapshot: merge the captured data after the descriptor
    - MEDIUM: mworker: remove register/unregister signal functions
    - MEDIUM: mworker: use the haproxy poll loop
    - BUG/MINOR: mworker: no need to stop peers for each proxy
    - MINOR: mworker: mworker_cleanlisteners() delete the listeners
    - MEDIUM: mworker: block SIGCHLD until the master is ready
    - MEDIUM: mworker: never block SIG{TERM,INT} during reload
    - MEDIUM: startup: unify signal init between daemon and mworker mode
    - MINOR: mworker: don't deinit the poller fd when in wait mode
    - MEDIUM: mworker: master wait mode use its own initialization
    - MEDIUM: mworker: replace the master pipe by socketpairs
    - MINOR: mworker: keep and clean the listeners
    - MEDIUM: threads: close the thread-waker pipe during deinit
    - MEDIUM: mworker: call per_thread deinit in mworker_reload()
    - REORG: http: move the HTTP semantics definitions to http.h/http.c
    - REORG: http: move http_get_path() to http.c
    - REORG: http: move error codes production and processing to http.c
    - REORG: http: move the log encoding tables to log.c
    - REORG: http: move some header value processing functions to http.c
    - BUG/MAJOR: kqueue: Don't reset the changes number by accident.
    - MEDIUM: protocol: use a custom AF_MAX to help protocol parser
    - MEDIUM: protocol: sockpair protocol
    - TESTS: add a python wrapper for sockpair@
    - BUG/MINOR: server: Crash when setting FQDN via CLI.
    - BUG/MINOR: h2: report asynchronous end of stream on closed connections
    - BUILD: fix build without thread
    - BUG/MEDIUM: tasks: Don't forget to decrement task_list_size in tasklet_free().
    - MEDIUM: connections: Don't reset the polling flags in conn_fd_handler().
    - MEDIUM: connections/mux: Add a recv and a send+recv wait list.
    - MEDIUM: connections: Get rid of the recv() method.
    - MINOR: h2: Let user of h2_recv() and h2_send() know xfer has been done.
    - MEDIUM: h2: always subscribe to receive if allowed.
    - MEDIUM: h2: Don't use a wake() method anymore.
    - MEDIUM: stream_interface: Make recv() subscribe when more data is needed.
    - MINOR: connections: Add a "handle" field to wait_list.
    - MEDIUM: mux_h2: Revamp the send path when blocking.
    - MEDIUM: stream_interfaces: Starts receiving from the upper layers.
    - MINOR: checks: Give checks their own wait_list.
    - MINOR: conn_streams: Remove wait_list from conn_streams.
    - REORG: h1: create a new h1m_state
    - MINOR: h1: add the restart offsets into struct h1m
    - MINOR: h1: remove the unused states from h1m_state
    - MINOR: h1: provide a distinct init() function for request and response
    - MINOR: h1: add a message flag to indicate that a message carries a response
    - MINOR: h2: make sure h1m->err_pos field is correct on chunk error
    - MINOR: h1: properly pre-initialize err_pos to -2
    - MINOR: mux_h2: replace the req,res h1 messages with a single h1 message
    - MINOR: h2: pre-initialize h1m->err_pos to -1 on the output path
    - MEDIUM: h1: consider err_pos before deciding to accept a header name or not
    - MEDIUM: h1: make the parser support a pointer to a start line
    - MEDIUM: h1: let the caller pass the initial parser's state
    - MINOR: h1: make the message parser support a null <hdr> argument
    - MEDIUM: h1: support partial message parsing
    - MEDIUM: h1: remove the useless H1_MSG_BODY state
    - MINOR: h2: store the HTTP status into the H2S, not the H1M
    - MINOR: h1: remove the HTTP status from the H1M struct
    - MEDIUM: h1: implement the request parser as well
    - MINOR: h1: add H1_MF_TOLOWER to decide when to turn header names to lower case
    - MINOR: connection: pass the proxy when creating a connection
    - BUG/MEDIUM: h2: Don't forget to empty the wait lists on destroy.
    - BUG/MEDIUM: h2: Don't forget to set recv_wait_list to NULL in h2_detach.
    - BUG/MAJOR: h2: reset the parser's state on mux buffer full

6 years agoBUG/MAJOR: h2: reset the parser's state on mux buffer full
Willy Tarreau [Wed, 12 Sep 2018 16:51:18 +0000 (18:51 +0200)] 
BUG/MAJOR: h2: reset the parser's state on mux buffer full

The h2 parser has this specificity that if it cannot send the headers
frame resulting from the headers it just parsed, it needs to drop it
and parse it again later. Since commit 8852850 ("MEDIUM: h1: let the
caller pass the initial parser's state"), when this happens the parser
remains in the data state and the headers are not parsed again next
time, resulting in a parse error. Let's reset the parser on exit there.

No backport is needed.

6 years agoBUG/MEDIUM: h2: Don't forget to set recv_wait_list to NULL in h2_detach.
Olivier Houchard [Wed, 12 Sep 2018 15:56:08 +0000 (17:56 +0200)] 
BUG/MEDIUM: h2: Don't forget to set recv_wait_list to NULL in h2_detach.

If we're detaching the conn_stream, and it was subscribed to be waken up
when more data was available to receive, unsubscribe it.

No backport is needed.

6 years agoBUG/MEDIUM: h2: Don't forget to empty the wait lists on destroy.
Olivier Houchard [Wed, 12 Sep 2018 15:52:46 +0000 (17:52 +0200)] 
BUG/MEDIUM: h2: Don't forget to empty the wait lists on destroy.

Empty both send_list and fctl_list when destroying the h2 context, so that
if we're freeing the stream after, it doesn't try to remove itself from the
now-deleted list.

No backport is needed.

6 years agoMINOR: connection: pass the proxy when creating a connection
Willy Tarreau [Wed, 12 Sep 2018 10:02:05 +0000 (12:02 +0200)] 
MINOR: connection: pass the proxy when creating a connection

Till now it was very difficult for a mux to know what proxy it was
working for. Let's pass the proxy when the mux is instanciated at
init() time. It's not yet used but the H1 mux will definitely need
it, just like the H2 mux when dealing with backend connections.

6 years agoMINOR: h1: add H1_MF_TOLOWER to decide when to turn header names to lower case
Willy Tarreau [Wed, 12 Sep 2018 07:54:00 +0000 (09:54 +0200)] 
MINOR: h1: add H1_MF_TOLOWER to decide when to turn header names to lower case

The h1 parser used to systematically turn header field names to lower
case because it was designed for H2. Let's add a flag which is off by
default to condition this behaviour so that when using it from an H1
parser it will not affect the message.

6 years agoMEDIUM: h1: implement the request parser as well
Willy Tarreau [Tue, 11 Sep 2018 15:57:05 +0000 (17:57 +0200)] 
MEDIUM: h1: implement the request parser as well

The original H1 request parsing code was reintroduced into the generic
H1 parser so that it can be used regardless of the direction. If the
parser is interrupted and restarts, it makes use of the H1_MF_RESP
flag to decide whether to re-parse a request or a response. While
parsing the request, the method is decoded and set into the start line
structure.

6 years agoMINOR: h1: remove the HTTP status from the H1M struct
Willy Tarreau [Tue, 11 Sep 2018 17:23:04 +0000 (19:23 +0200)] 
MINOR: h1: remove the HTTP status from the H1M struct

It has nothing to do there and is not used from there anymore, let's
get rid of it.

6 years agoMINOR: h2: store the HTTP status into the H2S, not the H1M
Willy Tarreau [Tue, 11 Sep 2018 17:22:14 +0000 (19:22 +0200)] 
MINOR: h2: store the HTTP status into the H2S, not the H1M

The HTTP status is not relevant to the H1 message but to the H2 stream
itself. It used to be placed there by pure convenience but better move
it before it's too hard to remove.

6 years agoMEDIUM: h1: remove the useless H1_MSG_BODY state
Willy Tarreau [Wed, 12 Sep 2018 15:25:32 +0000 (17:25 +0200)] 
MEDIUM: h1: remove the useless H1_MSG_BODY state

This state was only a delimiter between headers and body but it now
causes more harm than good because it requires someone to change it.
Since the H1 parser knows if we're in DATA or CHUNK_SIZE, simply let
it set the right next state so that h1m->state constantly matches
what is expected afterwards.

6 years agoMEDIUM: h1: support partial message parsing
Willy Tarreau [Tue, 11 Sep 2018 14:20:30 +0000 (16:20 +0200)] 
MEDIUM: h1: support partial message parsing

While it was not needed in the H2 mux which was reading full H1 messages
from the channel, it is mandatory for the H1 mux reading contents from
outside to be able to restart on a message. The problem is that the
headers are indexed on the fly, and it's not fun to have to store
everything between calls.

The solution here is to complete the first pass doing a partial restart,
and only once the end of message was found, to start over it again at
once, filling entries. This way there is a bounded number of passes on
the contents and no need to store an intermediary result anymore. Later
this principle could even be used to decide to completely drop an output
buffer to save memory.

6 years agoMINOR: h1: make the message parser support a null <hdr> argument
Willy Tarreau [Tue, 11 Sep 2018 14:04:48 +0000 (16:04 +0200)] 
MINOR: h1: make the message parser support a null <hdr> argument

This will allow some iterative calls to be made on incomplete messages
without having to store all the headers.

6 years agoMEDIUM: h1: let the caller pass the initial parser's state
Willy Tarreau [Tue, 11 Sep 2018 13:33:32 +0000 (15:33 +0200)] 
MEDIUM: h1: let the caller pass the initial parser's state

This way the caller controls if it's the request or response which has
to be used, and it will allow to restart after an incomplete parsing.

6 years agoMEDIUM: h1: make the parser support a pointer to a start line
Willy Tarreau [Tue, 11 Sep 2018 13:34:50 +0000 (15:34 +0200)] 
MEDIUM: h1: make the parser support a pointer to a start line

This will allow the parser to fill some extra fields like the method or
status without having to store them permanently in the HTTP message. At
this point however the parser cannot restart from an interrupted read.

6 years agoMEDIUM: h1: consider err_pos before deciding to accept a header name or not
Willy Tarreau [Wed, 12 Sep 2018 07:20:40 +0000 (09:20 +0200)] 
MEDIUM: h1: consider err_pos before deciding to accept a header name or not

Till now the H1 parser made for H2 used to be lenient on invalid header
field names because they were supposed to be produced by haproxy. Now
instead we'll rely on err_pos to know how to act (ie: -2 == must block).

6 years agoMINOR: h2: pre-initialize h1m->err_pos to -1 on the output path
Willy Tarreau [Wed, 12 Sep 2018 07:24:38 +0000 (09:24 +0200)] 
MINOR: h2: pre-initialize h1m->err_pos to -1 on the output path

We don't want to trigger an error while parsing a response coming from
haproxy (it could be an errorfile for example), so let's set this to
-1.

6 years agoMINOR: mux_h2: replace the req,res h1 messages with a single h1 message
Willy Tarreau [Tue, 11 Sep 2018 11:52:04 +0000 (13:52 +0200)] 
MINOR: mux_h2: replace the req,res h1 messages with a single h1 message

There's no reason to have the two sides in H1 format since we only use
one at a time (the response at the moment). While completely removing
the request declaration, let's rename the response to "h1m" to clarify
that it's the unique h1 message there.

6 years agoMINOR: h1: properly pre-initialize err_pos to -2
Willy Tarreau [Wed, 12 Sep 2018 07:08:54 +0000 (09:08 +0200)] 
MINOR: h1: properly pre-initialize err_pos to -2

This way we maintain the old mechanism stating that -2 means we block
on errors, -1 means we only capture them, and a positive value indicates
the position of the first error.

6 years agoMINOR: h2: make sure h1m->err_pos field is correct on chunk error
Willy Tarreau [Wed, 12 Sep 2018 07:05:16 +0000 (09:05 +0200)] 
MINOR: h2: make sure h1m->err_pos field is correct on chunk error

This never happens but in case it would, it's better to report the
correct offset of the error instead of a negative value.

6 years agoMINOR: h1: add a message flag to indicate that a message carries a response
Willy Tarreau [Tue, 11 Sep 2018 14:47:23 +0000 (16:47 +0200)] 
MINOR: h1: add a message flag to indicate that a message carries a response

This flag is H1_MF_RESP. It will be used by the parser during restarts when
it supports requests.

6 years agoMINOR: h1: provide a distinct init() function for request and response
Willy Tarreau [Tue, 11 Sep 2018 11:51:19 +0000 (13:51 +0200)] 
MINOR: h1: provide a distinct init() function for request and response

h1m_init() used to handle response only since it was used by the H1
client code. Let's have one init per direction.

6 years agoMINOR: h1: remove the unused states from h1m_state
Willy Tarreau [Tue, 11 Sep 2018 10:01:48 +0000 (12:01 +0200)] 
MINOR: h1: remove the unused states from h1m_state

States ERROR, 100_SENT, ENDING, CLOSE, CLOSING are not used at all for
the parsers. It's possible that a few others may disappear as well.

6 years agoMINOR: h1: add the restart offsets into struct h1m
Willy Tarreau [Tue, 11 Sep 2018 09:51:31 +0000 (11:51 +0200)] 
MINOR: h1: add the restart offsets into struct h1m

Currently the only user of struct h1m is the h2 mux when it has to parse
an H1 message coming from the channel. Unfortunately this is not enough
to efficiently parse HTTP/1 messages like those coming from the network
as we don't want to restart from scratch at every byte received.

This patch reintroduces the "next" offset into the H1 message so that any
H1 parser can use it to restart when called with a state that is not the
initial state.

6 years agoREORG: h1: create a new h1m_state
Willy Tarreau [Tue, 11 Sep 2018 09:45:04 +0000 (11:45 +0200)] 
REORG: h1: create a new h1m_state

This is the *parsing* state of an HTTP/1 message. Currently the h1_state
is composite as it's made both of parsing and control (100SENT, BODY,
DONE, TUNNEL, ENDING etc). The purpose here is to have a purely H1 state
that can be used by H1 parsers. For now it's equivalent to h1_state.

6 years agoMINOR: conn_streams: Remove wait_list from conn_streams.
Olivier Houchard [Wed, 12 Sep 2018 13:21:03 +0000 (15:21 +0200)] 
MINOR: conn_streams: Remove wait_list from conn_streams.

The conn_streams won't be used for subscribing/waiting for I/O events, after
all, so just remove its wait_list, and send/recv/_wait_list.

6 years agoMINOR: checks: Give checks their own wait_list.
Olivier Houchard [Wed, 12 Sep 2018 13:15:12 +0000 (15:15 +0200)] 
MINOR: checks: Give checks their own wait_list.

Instead of (ab)using the conn_stream's wait_list, which should disappear,
give the checks their own wait_list.

6 years agoMEDIUM: stream_interfaces: Starts receiving from the upper layers.
Olivier Houchard [Tue, 11 Sep 2018 16:27:21 +0000 (18:27 +0200)] 
MEDIUM: stream_interfaces: Starts receiving from the upper layers.

Instead of waiting for the connection layer to let us know we can read,
attempt to receive as soon as process_stream() is called, and subscribe
to receive events if we can't receive yet.

Now, except for idle connections, the recv(), send() and wake() methods are
no more, all the lower layers do is waking tasklet for anybody waiting
for I/O events.

6 years agoMEDIUM: mux_h2: Revamp the send path when blocking.
Olivier Houchard [Tue, 11 Sep 2018 16:24:28 +0000 (18:24 +0200)] 
MEDIUM: mux_h2: Revamp the send path when blocking.

Change fctl_list and send_list to be lists of struct wait_list, and nuke
send_wait_list, as it's now redundant.
Make the code responsible for shutr/shutw subscribe to those lists.

6 years agoMINOR: connections: Add a "handle" field to wait_list.
Olivier Houchard [Fri, 31 Aug 2018 15:43:32 +0000 (17:43 +0200)] 
MINOR: connections: Add a "handle" field to wait_list.

Add a new field to struct wait_list, "handle", that can be used by the
entity in charge of subscribing.

6 years agoMEDIUM: stream_interface: Make recv() subscribe when more data is needed.
Olivier Houchard [Fri, 31 Aug 2018 15:29:12 +0000 (17:29 +0200)] 
MEDIUM: stream_interface: Make recv() subscribe when more data is needed.

Refactor the code so that si_cs_recv() subscribes to receive events.

6 years agoMEDIUM: h2: Don't use a wake() method anymore.
Olivier Houchard [Tue, 21 Aug 2018 16:10:44 +0000 (18:10 +0200)] 
MEDIUM: h2: Don't use a wake() method anymore.

Instead of having our wake() method called each time a fd event happens,
just subscribe to recv/send events, and get our tasklet called when that
happens. If any recv/send was possible, the equivalent of what h2_wake_cb()
will be done.

6 years agoMEDIUM: h2: always subscribe to receive if allowed.
Olivier Houchard [Fri, 17 Aug 2018 16:42:48 +0000 (18:42 +0200)] 
MEDIUM: h2: always subscribe to receive if allowed.

Let the connection layer know we're always interested in getting more data,
so that we get scheduled as soon as data is available, instead of relying
on the wake() method.

6 years agoMINOR: h2: Let user of h2_recv() and h2_send() know xfer has been done.
Olivier Houchard [Fri, 17 Aug 2018 16:39:46 +0000 (18:39 +0200)] 
MINOR: h2: Let user of h2_recv() and h2_send() know xfer has been done.

Make h2_recv() and h2_send() return 1 if data has been sent/received, or 0
if it did not. That way the caller will be able to know if more work may
have to be done.

6 years agoMEDIUM: connections: Get rid of the recv() method.
Olivier Houchard [Thu, 9 Aug 2018 11:06:55 +0000 (13:06 +0200)] 
MEDIUM: connections: Get rid of the recv() method.

Remove the recv() method from mux and conn_stream.
The goal is to always receive from the upper layers, instead of waiting
for the connection later. For now, recv() is still called from the wake()
method, but that should change soon.

6 years agoMEDIUM: connections/mux: Add a recv and a send+recv wait list.
Olivier Houchard [Thu, 2 Aug 2018 17:23:05 +0000 (19:23 +0200)] 
MEDIUM: connections/mux: Add a recv and a send+recv wait list.

For struct connection, struct conn_stream, and for the h2 mux, add 2 new
lists, one that handles waiters for recv, and one that handles waiters for
recv and send. That way we can ask to subscribe for either recv or send.

6 years agoMEDIUM: connections: Don't reset the polling flags in conn_fd_handler().
Olivier Houchard [Wed, 12 Sep 2018 15:12:53 +0000 (17:12 +0200)] 
MEDIUM: connections: Don't reset the polling flags in conn_fd_handler().

Resetting the polling flags at the end of conn_fd_handler() shouldn't be
needed anymore, and it will create problem when we won't handle send/recv
from conn_fd_handler() anymore.

6 years agoBUG/MEDIUM: tasks: Don't forget to decrement task_list_size in tasklet_free().
Olivier Houchard [Wed, 12 Sep 2018 12:55:03 +0000 (14:55 +0200)] 
BUG/MEDIUM: tasks: Don't forget to decrement task_list_size in tasklet_free().

In tasklet_free(), if we're currently in the runnable task list, don't
forget to decrement taks_list_size, or it'll end up being to big, and we may
not process tasks in the global runqueue.

6 years agoBUILD: fix build without thread
William Lallemand [Wed, 12 Sep 2018 09:57:19 +0000 (11:57 +0200)] 
BUILD: fix build without thread

Cyril Bonté reported that commit f9cc07c25b broke the build without
thread.

We don't need to initialise tid = 0 in mworker_loop, so we could
completely remove it.

6 years agoBUG/MINOR: h2: report asynchronous end of stream on closed connections
Willy Tarreau [Wed, 12 Sep 2018 07:45:54 +0000 (09:45 +0200)] 
BUG/MINOR: h2: report asynchronous end of stream on closed connections

Christopher noticed that the CS_FL_EOS to CS_FL_REOS conversion was
incomplete : when the connectionis closed, we mark the streams with EOS
instead of REOS, causing the loss of any possibly pending data. At the
moment it's not an issue since H2 is used only with a client, but with
servers it could be a real problem if servers close the connection right
after sending their response.

This patch should be backported to 1.8.

6 years agoBUG/MINOR: server: Crash when setting FQDN via CLI.
Frédéric Lécaille [Tue, 21 Aug 2018 13:04:23 +0000 (15:04 +0200)] 
BUG/MINOR: server: Crash when setting FQDN via CLI.

This patch ensures that a DNS resolution may be launched before
setting a server FQDN via the CLI. Especially, it checks that
resolvers was set.

A LEVEL 4 reg testing file is provided.

Thanks to Lukas Tribus for having reported this issue.

Must be backported to 1.8.

6 years agoTESTS: add a python wrapper for sockpair@
William Lallemand [Tue, 11 Sep 2018 14:51:30 +0000 (16:51 +0200)] 
TESTS: add a python wrapper for sockpair@

This is a python wrapper which creates a socketpair and passes it as two
environment variable to haproxy.

It's the easiest way to test the sockpair protocol in haproxy.

6 years agoMEDIUM: protocol: sockpair protocol
William Lallemand [Tue, 11 Sep 2018 14:51:29 +0000 (16:51 +0200)] 
MEDIUM: protocol: sockpair protocol

This protocol is based on the uxst one, but it uses socketpair and FD
passing insteads of a connect()/accept().

The "sockpair@" prefix has been implemented for both bind and server
keywords.

When HAProxy wants to connect through a sockpair@, it creates 2 new
sockets using the socketpair() syscall and pass one of the socket
through the FD specified on the server line.

On the bind side, haproxy will receive the FD, and will use it like it
was the FD of an accept() syscall.

This protocol was designed for internal communication within HAProxy
between the master and the workers, but it's possible to use it
externaly with a wrapper and pass the FD through environment variabls.

6 years agoMEDIUM: protocol: use a custom AF_MAX to help protocol parser
William Lallemand [Tue, 11 Sep 2018 14:51:28 +0000 (16:51 +0200)] 
MEDIUM: protocol: use a custom AF_MAX to help protocol parser

It's possible to have several protocols per family which is a problem
with the current way the protocols are stored.

This allows to register a new protocol in HAProxy which is not a
protocol in the strict socket definition. It will be used to register a
SOCK_STREAM protocol using socketpair().

6 years agoBUG/MAJOR: kqueue: Don't reset the changes number by accident.
Olivier Houchard [Tue, 11 Sep 2018 12:44:51 +0000 (14:44 +0200)] 
BUG/MAJOR: kqueue: Don't reset the changes number by accident.

In _update_fd(), if the fd wasn't polled, and we don't want it to be polled,
we just returned 0, however, we should return changes instead, or all previous
changes will be lost.

This should be backported to 1.8.

6 years agoREORG: http: move some header value processing functions to http.c
Willy Tarreau [Mon, 10 Sep 2018 16:41:28 +0000 (18:41 +0200)] 
REORG: http: move some header value processing functions to http.c

The following functions only deal with header field values and are agnostic
to the HTTP version so they were moved to http.c :

http_header_match2(), find_hdr_value_end(), find_cookie_value_end(),
extract_cookie_value(), parse_qvalue(), http_find_url_param_pos(),
http_find_next_url_param().

Those lacking the "http_" prefix were modified to have it.

6 years agoREORG: http: move the log encoding tables to log.c
Willy Tarreau [Mon, 10 Sep 2018 16:16:53 +0000 (18:16 +0200)] 
REORG: http: move the log encoding tables to log.c

There are 3 tables in proto_http which are used exclusively by logs :
hdr_encode_map[], url_encode_map[] and http_encode_map[]. They indicate
what characters are safe to be emitted in logs depending on the part of
the message where they are placed. Let's move this to log.c, as well as
its initialization. It's worth noting that the rfc5424 map was already
initialized there.

6 years agoREORG: http: move error codes production and processing to http.c
Willy Tarreau [Mon, 10 Sep 2018 16:04:24 +0000 (18:04 +0200)] 
REORG: http: move error codes production and processing to http.c

These error codes and messages are agnostic to the version, even if
they are represented as HTTP/1.0 messages. Ultimately they will have
to be transformed into internal HTTP messages to be used everywhere.

The HTTP/1.1 100 Continue message was turned to an IST and the local
copy in the Lua code was removed.

6 years agoREORG: http: move http_get_path() to http.c
Willy Tarreau [Mon, 10 Sep 2018 15:45:34 +0000 (17:45 +0200)] 
REORG: http: move http_get_path() to http.c

This function is purely HTTP once http_txn is put aside. So the original
one was renamed to http_txn_get_path() and it extracts the relevant offsets
from the txn to pass them to http_get_path(). One benefit of the new version
is that it returns the length at the same time so that allowed to slightly
simplify http_get_path_from_string() which had to look up the end pointer
previously and which is not needed anymore.

6 years agoREORG: http: move the HTTP semantics definitions to http.h/http.c
Willy Tarreau [Mon, 10 Sep 2018 13:38:55 +0000 (15:38 +0200)] 
REORG: http: move the HTTP semantics definitions to http.h/http.c

It's a bit painful to have to deal with HTTP semantics for each protocol
version (H1 and H2), and working on the version-agnostic code further
emphasizes the problem.

This patch creates http.h and http.c which are agnostic to the version
in use, and which borrow a few parts from proto_http and from h1. For
example the once thought h1-specific h1_char_classes array is in fact
dictated by RFC7231 and is used to parse HTTP headers. A few changes
were made to a few files which were including proto_http.h while they
only needed http.h.

Certain string definitions pre-dated the introduction of indirect
strings (ist) so some were used to simplify the definition of the known
HTTP methods. The current lookup code saves 2 kB of a heavily used table
and is faster than the previous table based lookup (typ. 14 ns vs 16
before).

6 years agoMEDIUM: mworker: call per_thread deinit in mworker_reload()
William Lallemand [Tue, 11 Sep 2018 08:06:29 +0000 (10:06 +0200)] 
MEDIUM: mworker: call per_thread deinit in mworker_reload()

We need to clean the FDs registered manually in the poller to avoid FD
leaking during a reload of the master.

This patch call the per thread deinit function which close the thread
waker pipe.

6 years agoMEDIUM: threads: close the thread-waker pipe during deinit
William Lallemand [Tue, 11 Sep 2018 08:06:28 +0000 (10:06 +0200)] 
MEDIUM: threads: close the thread-waker pipe during deinit

In order to avoid FD leaking, we close the pipe used to wake the threads
up during per thread deinit.

6 years agoMINOR: mworker: keep and clean the listeners
William Lallemand [Tue, 11 Sep 2018 08:06:27 +0000 (10:06 +0200)] 
MINOR: mworker: keep and clean the listeners

Keep the listeners that should be used in the master process and clean
them in the workers.

6 years agoMEDIUM: mworker: replace the master pipe by socketpairs
William Lallemand [Tue, 11 Sep 2018 08:06:26 +0000 (10:06 +0200)] 
MEDIUM: mworker: replace the master pipe by socketpairs

In order to communicate with the workers, the master pipe has been
replaced by a socketpair() per worker.

The goal is to use these sockets as stats sockets and be able to access
them from the master.

When reloading, the master serialize the information of the workers and
put them in a environment variable. Once the master has been reexecuted
it unserialize that information and it is capable of closing the FDs of
the leaving children.

6 years agoMEDIUM: mworker: master wait mode use its own initialization
William Lallemand [Tue, 11 Sep 2018 08:06:25 +0000 (10:06 +0200)] 
MEDIUM: mworker: master wait mode use its own initialization

The master now use a poll loop, which should be initialized even in wait
mode. We need to init some variables if we didn't success to load the
configuration file.

6 years agoMINOR: mworker: don't deinit the poller fd when in wait mode
William Lallemand [Tue, 11 Sep 2018 08:06:24 +0000 (10:06 +0200)] 
MINOR: mworker: don't deinit the poller fd when in wait mode

If haproxy failed to load its configuration, the process is reexecuted
and it did not init the poller. So we must not try to deinit the poller
before the exec().

6 years agoMEDIUM: startup: unify signal init between daemon and mworker mode
William Lallemand [Tue, 11 Sep 2018 08:06:23 +0000 (10:06 +0200)] 
MEDIUM: startup: unify signal init between daemon and mworker mode

The signals are now unblocked only once the configuration have been
parsed.

6 years agoMEDIUM: mworker: never block SIG{TERM,INT} during reload
William Lallemand [Tue, 11 Sep 2018 08:06:22 +0000 (10:06 +0200)] 
MEDIUM: mworker: never block SIG{TERM,INT} during reload

The master should be able to be killed even if the reload is not
finished.

6 years agoMEDIUM: mworker: block SIGCHLD until the master is ready
William Lallemand [Tue, 11 Sep 2018 08:06:21 +0000 (10:06 +0200)] 
MEDIUM: mworker: block SIGCHLD until the master is ready

With the new way of handling the signals in the master worker, we are
are not staying in a waitpid() loop. Which means that we need to catch the
SIGCHLD signals to call waitpid().

The problem is when the master is reloading, this signal is neither
registered nor blocked so we lost all signals between the restart and
the call to mworker_loop().

This patch blocks the SIGCHLD signals before the reloading and ensure
it's not unblocked before the master registered the SIGCHLD handler.

6 years agoMINOR: mworker: mworker_cleanlisteners() delete the listeners
William Lallemand [Tue, 11 Sep 2018 08:06:20 +0000 (10:06 +0200)] 
MINOR: mworker: mworker_cleanlisteners() delete the listeners

The mworker_cleanlisteners() function now remove the listeners, we don't
need them in the master for now.

6 years agoBUG/MINOR: mworker: no need to stop peers for each proxy
William Lallemand [Tue, 11 Sep 2018 08:06:19 +0000 (10:06 +0200)] 
BUG/MINOR: mworker: no need to stop peers for each proxy

The mworker_cleanlisteners() was cleaning the peers in the proxy loop,
which is useless since we need to stop the peers only once.

6 years agoMEDIUM: mworker: use the haproxy poll loop
William Lallemand [Tue, 11 Sep 2018 08:06:18 +0000 (10:06 +0200)] 
MEDIUM: mworker: use the haproxy poll loop

In order to reorganize the code of the master worker, the mworker_wait()
function which was the main function was split. This function was
handling a wait() loop, but it does not need it anymore since the code
will use the poll loop of haproxy instead.

The function was split in several functions:

- mworker_catch_sigterm() which is a signal handler for SIGTERM ans
SIGUSR1 that sends the signals to the workers
- mworker_catch_sigchld() which is the code handling the leaving of a
child
- mworker_catch_sighup which basically call the mworker_restart()
function
- mworker_loop() which is the function calling the main poll loop in the
master

6 years agoMEDIUM: mworker: remove register/unregister signal functions
William Lallemand [Tue, 11 Sep 2018 08:06:17 +0000 (10:06 +0200)] 
MEDIUM: mworker: remove register/unregister signal functions

Remove the register and unregister signal functions specifics to the
master worker, because that should be done with the generic ones.

6 years agoMEDIUM: snapshot: merge the captured data after the descriptor
Willy Tarreau [Fri, 7 Sep 2018 18:07:17 +0000 (20:07 +0200)] 
MEDIUM: snapshot: merge the captured data after the descriptor

Instead of having a separate area for the captured data, we now have a
contigous block made of the descriptor and the data. At the moment, since
the area is dynamically allocated, we can adjust its size to what is
needed, but the idea is to quickly switch to a pool and an LRU list.

6 years agoMEDIUM: snapshots: dynamically allocate the snapshots
Willy Tarreau [Fri, 7 Sep 2018 17:02:32 +0000 (19:02 +0200)] 
MEDIUM: snapshots: dynamically allocate the snapshots

Now upon error we dynamically allocate the snapshot instead of overwriting
it. This way there is no more memory wasted in the proxy to hold the two
error snapshot descriptors. Also an appreciable side effect of this is that
the proxy's lock is only taken during the pointer swap, no more while copying
the buffer's contents. This saves 480 bytes of memory per proxy.

6 years agoBUG/MEDIUM: snapshot: take the proxy's lock while dumping errors
Willy Tarreau [Fri, 7 Sep 2018 17:55:44 +0000 (19:55 +0200)] 
BUG/MEDIUM: snapshot: take the proxy's lock while dumping errors

The proxy's lock it held while filling the error but not while dumping
it, so it's possible to dereference pointers being replaced, typically
server pointers. The risk is very low and unlikely but not inexistent.

Since "show errors" is rarely used in parallel, let's simply grab the
proxy's lock while dumping. Ideally we should use an R/W lock here but
it will not make any difference.

This patch must be backported to 1.8, but the code is in proto_http.c
there, though mostly similar.

6 years agoREORG: cli: move the "show errors" handler from http to proxy
Willy Tarreau [Fri, 7 Sep 2018 16:34:24 +0000 (18:34 +0200)] 
REORG: cli: move the "show errors" handler from http to proxy

There's nothing HTTP-specific there anymore at all, let's move this
to the proxy where it belongs.

6 years agoMINOR: http: remove the pointer to the error snapshot in http_capture_bad_message()
Willy Tarreau [Fri, 7 Sep 2018 16:01:03 +0000 (18:01 +0200)] 
MINOR: http: remove the pointer to the error snapshot in http_capture_bad_message()

It's not needed anymore as we know the side thanks to the channel. This
will allow the proxy generic code to better manage the error snapshots.

6 years agoMINOR: http: make the HTTP error capture rely on the generic proxy code
Willy Tarreau [Fri, 7 Sep 2018 13:47:35 +0000 (15:47 +0200)] 
MINOR: http: make the HTTP error capture rely on the generic proxy code

Now that we have a generic error capture function, let's simplify
http_capture_bad_message() to make use of it. At this point the API
is not changed at all, but it could be further simplified.

6 years agoMINOR: proxy: add a new generic proxy_capture_error()
Willy Tarreau [Fri, 7 Sep 2018 15:43:26 +0000 (17:43 +0200)] 
MINOR: proxy: add a new generic proxy_capture_error()

This function now captures an error regardless of its side and protocol.
The caller must pass a number of elements and may pass a protocol-specific
structure and a callback to display it. Later this function may deal with
more advanced allocation techniques to avoid allocating as many buffers
as proxies.

6 years agoMEDIUM: snapshot: implement a show() callback and use it for HTTP
Willy Tarreau [Fri, 7 Sep 2018 12:01:39 +0000 (14:01 +0200)] 
MEDIUM: snapshot: implement a show() callback and use it for HTTP

The HTTP dumps are now configurable in the code : "show errors" now
calls a protocol-specific function to emit the decoded output. For
now only HTTP is implemented.

6 years agoMEDIUM: snapshot: start to reorder the HTTP snapshot output a little bit
Willy Tarreau [Fri, 7 Sep 2018 11:49:44 +0000 (13:49 +0200)] 
MEDIUM: snapshot: start to reorder the HTTP snapshot output a little bit

The output of "show errors" was slightly reordered to split the HTTP part
in a single chunk_appendf() call. The useless buffer total input was
replaced to report the buffer's start offset, which is the offset in the
stream of the first input byte (thus not counting output). Also it was
the opportunity to stop calling the stream "session".

6 years agoMINOR: snapshot: split the error snapshots into common and proto-specific parts
Willy Tarreau [Thu, 6 Sep 2018 17:41:22 +0000 (19:41 +0200)] 
MINOR: snapshot: split the error snapshots into common and proto-specific parts

The idea will be to make the error snapshot feature accessible to other
protocols than just HTTP. This patch only introduces an "http_snapshot"
structure and renames a few fields to make things more explicit. The
HTTP part was installed inside a union so that we can easily add more
protocols in the future.

6 years agoMINOR: snapshot: restart on the event ID and not the stream ID
Willy Tarreau [Fri, 7 Sep 2018 09:51:51 +0000 (11:51 +0200)] 
MINOR: snapshot: restart on the event ID and not the stream ID

The snapshots have the ability to restart a partial dump and they use
the stream ID as the restart point. Since it's purely HTTP, let's use
the event ID instead.

6 years agoBUG/MINOR: http/threads: atomically increment the error snapshot ID
Willy Tarreau [Fri, 7 Sep 2018 09:29:59 +0000 (11:29 +0200)] 
BUG/MINOR: http/threads: atomically increment the error snapshot ID

Let's use an atomic increment for the error snapshot, as we'd rather
not assign the same ID to two errors happening in parallel. It's very
unlikely that it will ever happen though.

This patch must be backported to 1.8 with the other one it relies on
("MINOR: thread: implement HA_ATOMIC_XADD()").

6 years agoBUG/MINOR: dns: check and link servers' resolvers right after config parsing
Baptiste Assmann [Fri, 10 Aug 2018 08:56:38 +0000 (10:56 +0200)] 
BUG/MINOR: dns: check and link servers' resolvers right after config parsing

On the Mailing list, Marcos Moreno reported that haproxy configuration
validation (through "haproxy -c cfgfile") does not detect when a
resolvers section does not exist for a server.
That said, this checking is done after HAProxy has started up.

The problem is that this can create production issue, since init
script can't detect the problem before starting / reloading HAProxy.

To fix this issue, this patch registers the function which validates DNS
configuration validity and run it right after configuration parsing is
finished (through cfg_register_postparser()).
Thanks to it, now "haproxy -c cfgfile" will fail when a server
points to a non-existing resolvers section (or any other validation made
by the function above).

Backport status: 1.8

6 years agoMINOR: log: One const should be enough.
Olivier Houchard [Thu, 6 Sep 2018 16:14:09 +0000 (18:14 +0200)] 
MINOR: log: One const should be enough.

"const const" doesn't bring much more constness, so only use one.

6 years agoMINOR: connection: add new function conn_is_back()
Willy Tarreau [Thu, 6 Sep 2018 12:52:21 +0000 (14:52 +0200)] 
MINOR: connection: add new function conn_is_back()

This function returns true if the connection is a backend connection
and false if it's a frontend connection.

6 years agoMINOR: connection: add new function conn_get_proxy()
Willy Tarreau [Thu, 6 Sep 2018 09:48:44 +0000 (11:48 +0200)] 
MINOR: connection: add new function conn_get_proxy()

This function returns the proxy associated to a connection. For front
connections it returns the frontend, and for back connections it
returns the backend. This will be used to retrieve some configuration
parameters from within a mux.

6 years agoMINOR: connection: make the initialization more consistent
Willy Tarreau [Thu, 6 Sep 2018 09:45:30 +0000 (11:45 +0200)] 
MINOR: connection: make the initialization more consistent

Sometimes a connection is prepared before the target is set, sometimes
after. There's no real rule since the few functions involved operate on
different and independent fields. Soon we'll benefit from knowing the
target at the connection layer, in order to figure the associated proxy
and retrieve the various parameters (timeouts etc). This patch slightly
reorders a few calls to conn_prepare() so that we can make sure that the
target is always known to the mux.

6 years agoBUG/MINOR: h1: fix buffer shift after realignment
Willy Tarreau [Thu, 6 Sep 2018 08:48:15 +0000 (10:48 +0200)] 
BUG/MINOR: h1: fix buffer shift after realignment

Commit 5e74b0b ("MEDIUM: h1: port to new buffer API.") introduced a
minor bug by which a buffer's head could stay shifted by the amount
of removed CRLF if it started with empty lines. This would cause the
second request (or response) not to work until it would receive a few
extra characters. This most only impacts requests sent by hand though.

This is purely 1.9, no backport is needed.

6 years agoMEDIUM: h2: produce some logs on early errors that prevent streams from being created
Willy Tarreau [Wed, 5 Sep 2018 17:55:58 +0000 (19:55 +0200)] 
MEDIUM: h2: produce some logs on early errors that prevent streams from being created

The h2 mux currently lacks some basic transparency. Some errors cause the
connection to be aborted but they couldn't be reported. With this patch,
almost all situations where an error will cause a stream or connection to
be aborted without the ability for an existing stream to report it will be
reported in the logs. This at least provides a solution to monitor the
activity and abnormal traffic.

6 years agoMINOR: log: provide a function to emit a log for a session
Willy Tarreau [Wed, 5 Sep 2018 17:51:10 +0000 (19:51 +0200)] 
MINOR: log: provide a function to emit a log for a session

The new function sess_log() only needs a session to emit a log. It will
ignore the parts that depend on the stream. It is usable to emit a log
to report early errors in muxes. These ones will typically mention
"<BADREQ>" for the request and 0 for the HTTP status code.

6 years agoMEDIUM: log: make sess_build_logline() support being called with no stream
Willy Tarreau [Wed, 5 Sep 2018 14:55:15 +0000 (16:55 +0200)] 
MEDIUM: log: make sess_build_logline() support being called with no stream

Till now it was impossible to emit logs from the lower layers only because
a stream was mandatory. From now on it will at least be possible to emit a
log to report a bad request or some timings for example. When the stream
is null, sess_build_logline() will use default values and will extract the
timing information from the session just like stream_new() does, so the
resulting log line is perfectly valid.

The termination state will indicate a proxy error during the request phase
since it is the only realistic use for such a call with no stream.