]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
7 years agoMINOR: connection: adjust CO_FL_NOTIFY_DATA after removal of flags
Willy Tarreau [Wed, 20 Sep 2017 15:46:46 +0000 (17:46 +0200)] 
MINOR: connection: adjust CO_FL_NOTIFY_DATA after removal of flags

After the removal of CO_FL_DATA_RD_SH and CO_FL_DATA_WR_SH, the
aggregate mask CO_FL_NOTIFY_DATA was not updated. It happens that
now CO_FL_NOTIFY_DATA and CO_FL_NOTIFY_DONE are similar, which may
reveal some overlap between the ->wake and ->xprt_done callbacks.
We'll see after the mux changes if both are still required.

7 years agoMINOR: net_helper: add 64-bit read/write functions
Willy Tarreau [Wed, 20 Sep 2017 06:14:52 +0000 (08:14 +0200)] 
MINOR: net_helper: add 64-bit read/write functions

These ones are the same as the previous ones but for 64 bit values.
We're using my_ntohll() and my_htonll() from standard.h for the byte
order conversion.

7 years agoMINOR: net_helper: add write functions
Willy Tarreau [Tue, 19 Sep 2017 15:27:05 +0000 (17:27 +0200)] 
MINOR: net_helper: add write functions

These ones are the equivalent of the read_* functions. They support
writing unaligned words, possibly wrapping, in host and network order.
The write_i*() functions were not implemented since the caller can
already use the unsigned version.

7 years agoMINOR: net_helper: add functions to read from vectors
Willy Tarreau [Tue, 19 Sep 2017 12:59:52 +0000 (14:59 +0200)] 
MINOR: net_helper: add functions to read from vectors

This patch adds the ability to read from a wrapping memory area (ie:
buffers). The new functions are called "readv_<type>". The original
ones were renamed to start with "read_" to make the difference more
obvious between the read method and the returned type.

It's worth noting that the memory barrier in readv_bytes() is critical,
as otherwise gcc decides that it doesn't need the resulting data, but
even worse, removes the length checks in readv_u64() and happily
performs an out-of-bounds unaligned read using read_u64()! Such
"optimizations" are a bit borderline, especially when they impact
security like this...

7 years agoMINOR: buffer: add b_end() and b_to_end()
Willy Tarreau [Tue, 19 Sep 2017 19:14:08 +0000 (21:14 +0200)] 
MINOR: buffer: add b_end() and b_to_end()

These ones return respectively the pointer to the end of the buffer and
the distance between b->p and the end. These will simplify a bit some
new code needed to parse directly from a wrapping buffer.

7 years agoMINOR: buffer: add b_del() to delete a number of characters
Willy Tarreau [Tue, 19 Sep 2017 12:18:46 +0000 (14:18 +0200)] 
MINOR: buffer: add b_del() to delete a number of characters

This will be used by code which directly parses buffers with no channel
in the middle (eg: h2, might be used by checks as well).

7 years agoMINOR: tools: make my_htonll() more efficient on x86_64
Willy Tarreau [Wed, 20 Sep 2017 06:18:49 +0000 (08:18 +0200)] 
MINOR: tools: make my_htonll() more efficient on x86_64

The current construct was made when developing on a 32-bit machine.
Having a simple bswap operation replaced with 2 bswap, 2 shift and
2 or is quite of a waste of precious cycles... Let's provide a trivial
asm-based implementation for x86_64.

7 years agoBUG/MINOR: contrib/modsecurity: close the va_list ap before return
Dragan Dosen [Mon, 18 Sep 2017 07:20:43 +0000 (09:20 +0200)] 
BUG/MINOR: contrib/modsecurity: close the va_list ap before return

Make sure the va_list ap is closed before return in case the function
vsnprintf() returned an error.

7 years agoBUG/MINOR: contrib/mod_defender: close the va_list argp before return
Dragan Dosen [Mon, 18 Sep 2017 06:20:33 +0000 (08:20 +0200)] 
BUG/MINOR: contrib/mod_defender: close the va_list argp before return

Fix the case when the va_list argp could be left open if the function
vsnprintf() returned a negative value.

7 years agoMINOR: ssl: Remove useless checks on bind_conf or bind_conf->is_ssl
Christopher Faulet [Fri, 15 Sep 2017 07:52:49 +0000 (09:52 +0200)] 
MINOR: ssl: Remove useless checks on bind_conf or bind_conf->is_ssl

bind_conf always exists at these steps and it is always for SSL listeners.

7 years agoBUG/MINOR: dns: Fix check on nameserver in snr_resolution_cb
Christopher Faulet [Fri, 15 Sep 2017 09:55:45 +0000 (11:55 +0200)] 
BUG/MINOR: dns: Fix check on nameserver in snr_resolution_cb

snr_resolution_cb can be called with <nameserver> parameter set to NULL. So we
must check it before using it. This is done most of time, except when we deal
with invalid DNS response.

7 years agoBUG/MINOR: spoe: Don't rely on SPOE ctx in debug message when its creation failed
Christopher Faulet [Fri, 15 Sep 2017 09:51:18 +0000 (11:51 +0200)] 
BUG/MINOR: spoe: Don't rely on SPOE ctx in debug message when its creation failed

If the SPOE context creation failed, we must not try to use it in the debug
message used to notice the error.

This patch must be backported in 1.7.

7 years agoBUG/MINOR: compression: Check response headers before http-response rules eval
Christopher Faulet [Fri, 15 Sep 2017 09:39:36 +0000 (11:39 +0200)] 
BUG/MINOR: compression: Check response headers before http-response rules eval

This is required if we want to use res.comp or res.comp_algo sample fetches in
http-response rules.

This patch must be backported in 1.7.

7 years agoBUG/MEDIUM: compression: Fix check on txn in smp_fetch_res_comp_algo
Christopher Faulet [Fri, 15 Sep 2017 08:14:43 +0000 (10:14 +0200)] 
BUG/MEDIUM: compression: Fix check on txn in smp_fetch_res_comp_algo

The check was totally messed up. In the worse case, it led to a crash, when
res.comp_algo sample fetch was retrieved on uncompressed response (with the
compression enabled).

This patch must be backported in 1.7.

7 years agoMEDIUM: session: count the frontend's connections at a single place
Willy Tarreau [Fri, 15 Sep 2017 08:25:14 +0000 (10:25 +0200)] 
MEDIUM: session: count the frontend's connections at a single place

There are several places where we see feconn++, feconn--, totalconn++ and
an increment on the frontend's number of connections and connection rate.
This is done exactly once per session in each direction, so better take
care of this counter in the session and simplify the callers. At least it
ensures a better symmetry. It also ensures consistency as till now the
lua/spoe/peers frontend didn't have these counters properly set, which can
be useful at least for troubleshooting.

7 years agoMEDIUM: session: factor out duplicated code for conn_complete_session
Willy Tarreau [Fri, 15 Sep 2017 08:06:28 +0000 (10:06 +0200)] 
MEDIUM: session: factor out duplicated code for conn_complete_session

session_accept_fd() may either successfully complete a session creation,
or defer it to conn_complete_session() depending of whether a handshake
remains to be performed or not. The problem is that all the code after
the handshake was duplicated between the two functions.

This patch make session_accept_fd() synchronously call
conn_complete_session() to finish the session creation. It is only needed
to check if the session's task has to be released or not at the end, which
is fairly minimal. This way there is now a single place where the sessions
are created.

7 years agoMINOR: session: small cleanup of conn_complete_session()
Willy Tarreau [Fri, 15 Sep 2017 07:49:59 +0000 (09:49 +0200)] 
MINOR: session: small cleanup of conn_complete_session()

Commit 8e3c6ce ("MEDIUM: connection: get rid of data->init() which was
not for data") simplified conn_complete_session() but introduced a
confusing check which cannot happen on CO_FL_HANDSHAKE. Make it clear
that this call is final and will either succeed and complete the
session or fail.

7 years agoMINOR: listener: new function listener_release
Willy Tarreau [Fri, 15 Sep 2017 07:19:58 +0000 (09:19 +0200)] 
MINOR: listener: new function listener_release

Instead of duplicating some sensitive listener-specific code in the
session and in the stream code, let's call listener_release() when
releasing a connection attached to a listener.

7 years agoMEDIUM: session: take care of incrementing/decrementing jobs
Willy Tarreau [Fri, 15 Sep 2017 07:07:56 +0000 (09:07 +0200)] 
MEDIUM: session: take care of incrementing/decrementing jobs

Each user of a session increments/decrements the jobs variable at its
own place, resulting in a real mess and inconsistencies between them.
Let's have session_new() increment jobs and session_free() decrement
it.

7 years agoMINOR: listeners: make listeners count consistent with reality
Willy Tarreau [Fri, 15 Sep 2017 06:18:11 +0000 (08:18 +0200)] 
MINOR: listeners: make listeners count consistent with reality

Some places call delete_listener() then decrement the number of
listeners and jobs. At least one other place calls delete_listener()
without doing so, but since it's in deinit(), it's harmless and cannot
risk to cause zombie processes to survive. Given that the number of
listeners and jobs is incremented when creating the listeners, it's
much more logical to symmetrically decrement them when deleting such
listeners.

7 years agoMINOR: listeners: new function create_listeners
Willy Tarreau [Fri, 15 Sep 2017 06:10:44 +0000 (08:10 +0200)] 
MINOR: listeners: new function create_listeners

This function is used to create a series of listeners for a specific
address and a port range. It automatically calls the matching protocol
handlers to add them to the relevant lists. This way cfgparse doesn't
need to manipulate listeners anymore. As an added bonus, the memory
allocation is checked.

7 years agoMINOR: unix: remove the now unused proto_uxst.h file
Willy Tarreau [Fri, 15 Sep 2017 05:59:31 +0000 (07:59 +0200)] 
MINOR: unix: remove the now unused proto_uxst.h file

Since everything is self contained in proto_uxst.c there's no need to
export anything. The same should be done for proto_tcp.c but the file
contains other stuff that's not related to the TCP protocol itself
and which should first be moved somewhere else.

7 years agoMINOR: protocols: register the ->add function and stop calling them directly
Willy Tarreau [Fri, 15 Sep 2017 05:55:51 +0000 (07:55 +0200)] 
MINOR: protocols: register the ->add function and stop calling them directly

cfgparse has no business directly calling each individual protocol's 'add'
function to create a listener. Now that they're all registered, better
perform a protocol lookup on the family and have a standard ->add method
for all of them.

7 years agoMINOR: protocols: always pass a "port" argument to the listener creation
Willy Tarreau [Fri, 15 Sep 2017 05:44:44 +0000 (07:44 +0200)] 
MINOR: protocols: always pass a "port" argument to the listener creation

It's a shame that cfgparse() has to make special cases of each protocol
just to cast the port to the target address family. Let's pass the port
in argument to the function. The unix listener simply ignores it.

7 years agoMINOR: frontend: don't retrieve ALPN on the critical path
Willy Tarreau [Fri, 15 Sep 2017 09:43:32 +0000 (11:43 +0200)] 
MINOR: frontend: don't retrieve ALPN on the critical path

It's pointless to read it on each and every accept(), as we only need
it for reporting in debugging mode a few lines later. Let's move this
part to the relevant block.

7 years agoMINOR: peers: don't reference the incoming listener on outgoing connections
Willy Tarreau [Fri, 15 Sep 2017 09:01:04 +0000 (11:01 +0200)] 
MINOR: peers: don't reference the incoming listener on outgoing connections

Since v1.7 it's pointless to reference a listener when greating a session
for an outgoing connection, it only complicates the code. SPOE and Lua were
cleaned up in 1.8-dev1 but the peers code was forgotten. This patch fixes
this by not assigning such a listener for outgoing connections. It also has
the extra benefit of not discounting the outgoing connections from the number
of allowed incoming connections (the code currently adds a safety marging of
3 extra connections to take care of this).

7 years agoBUILD: Makefile: improve detection of support for compiler warnings
Willy Tarreau [Thu, 14 Sep 2017 17:05:45 +0000 (19:05 +0200)] 
BUILD: Makefile: improve detection of support for compiler warnings

Some compiler versions don't emit an error when facing an unknown
no-warning unless another error is reported, resulting in all -Wno-*
options being enabled by default and being reported as wrong with
build errors. Let's create a new "cc-nowarn" function to disable
warnings only after checking that the positive one is supported.

7 years agoBUILD: Makefile: shut certain gcc/clang stupid warnings
Willy Tarreau [Wed, 13 Sep 2017 14:58:27 +0000 (16:58 +0200)] 
BUILD: Makefile: shut certain gcc/clang stupid warnings

The recent gcc and clang are utterly broken and apparently written by
people who don't use them anymore, because they emit warnings that are
impossible to disable in the code, which is the opposite of what a
warning should do. It is however possible to disable these warnings on
the command line.

This patch adds when supported :
   -Wno-format-truncation: bogus warning which is triggered on each
    snprintf() call based on the input type instead of the variables
    ranges, resulting in the impossibility to use "%02d" and similar.

   -Wno-address-of-packed-member: emitted for each and every line in
    ebtree.h by recent clang. Probably that the warning's author has
    never understood the use cases of packed structs and should be
    taught the use cases of the language he writes the compiler for.

   -Wno-null-dereference: emitted by clang on *(int *)0 = 0. The code
    will be updated to use a volatile instead but this recent change
    of behaviour will certainly cause quite some bugs in decades of
    existing code.

Feel free to report new such stupid warnings and to propose patches
to complete this list.

7 years agoBUILD: Makefile: add a function to detect support by the compiler of certain options
Willy Tarreau [Wed, 13 Sep 2017 14:54:28 +0000 (16:54 +0200)] 
BUILD: Makefile: add a function to detect support by the compiler of certain options

The recent gcc and clang are utterly broken and apparently written by
people who don't use them anymore, because they emit warnings that are
impossible to disable in the code, which is the opposite of what a
warning should do. It is however possible to disable these warnings on
the command line, but not in a backwards-compatible way.

Thus here we create a new function which detect if the compiler supports
certain options, and which adds them if supported.

7 years agoMINOR: add severity information to cli feedback messages
Andjelko Iharos [Thu, 20 Jul 2017 14:49:14 +0000 (16:49 +0200)] 
MINOR: add severity information to cli feedback messages

7 years agoMINOR: cli: add socket commands and config to prepend informational messages with...
Andjelko Iharos [Thu, 20 Jul 2017 09:59:48 +0000 (11:59 +0200)] 
MINOR: cli: add socket commands and config to prepend informational messages with severity

Adds cli commands to change at runtime whether informational messages
are prepended with severity level or not, with support for numeric and
worded severity in line with syslog severity level.

Adds stats socket config keyword severity-output to set default behavior
per socket on startup.

7 years agoMINOR: net_helper: Inline functions meant to be inlined.
Olivier Houchard [Wed, 13 Sep 2017 09:49:22 +0000 (11:49 +0200)] 
MINOR: net_helper: Inline functions meant to be inlined.

7 years agoMINOR: tasks: Move Lua notification from Lua to tasks
Thierry FOURNIER [Wed, 12 Jul 2017 12:31:10 +0000 (14:31 +0200)] 
MINOR: tasks: Move Lua notification from Lua to tasks

These notification management function and structs are generic and
it will be better to move in common parts.

The notification management functions and structs have names
containing some "lua" references because it was written for
the Lua. This patch removes also these references.

7 years agoMEDIUM: xref/lua: Use xref for referencing cosocket relation between stream and lua
Thierry FOURNIER [Mon, 11 Sep 2017 16:37:23 +0000 (18:37 +0200)] 
MEDIUM: xref/lua: Use xref for referencing cosocket relation between stream and lua

This relation will ensure that each was informed about death of another one.

7 years agoMINOR: xref: Add a new xref system
Thierry FOURNIER [Thu, 31 Aug 2017 18:35:18 +0000 (20:35 +0200)] 
MINOR: xref: Add a new xref system

xref is used to create a relation between two elements.
Once an element is released, it breaks the relation. If the
relation is already broken, it frees the xref struct.
The pointer between two elements is a sort of refcount with
max value 1. The relation is only between two elements.
The pointer and the type of element a and b are conventional.

Note that xref is initialised from Lua files because Lua is
the only one user.

7 years agoBUG/MINOR: Lua: The socket may be destroyed when we try to access.
Thierry FOURNIER [Tue, 11 Jul 2017 16:38:39 +0000 (18:38 +0200)] 
BUG/MINOR: Lua: The socket may be destroyed when we try to access.

When we try to access to other proxy context, we must check
its existence because haproxy can kill it between the creation
and the usage.

This patch should be backported in 1.6 and 1.7

7 years agoBUG/MEDIUM: http: Close streams for connections closed before a redirect
Christopher Faulet [Mon, 11 Sep 2017 07:27:29 +0000 (09:27 +0200)] 
BUG/MEDIUM: http: Close streams for connections closed before a redirect

A previous fix was made to prevent the connection to a server if a redirect was
performed during the request processing when we wait to keep the client
connection alive. This fix introduced a pernicious bug. If a client closes its
connection immediately after sending a request, it is possible to keep stream
alive infinitely. This happens when the connection closure is caught when the
request is received, before the request parsing.

To be more specific, this happens because the close event is not "forwarded",
first because of the call to "channel_dont_connect" in the function
"http_apply_redirect_rule", then because we want to keep the client connection
alive, we explicitly call "channel_dont_close" in the function
"http_request_forward_body".

So, to fix the bug, instead of blocking the server connection, we force its
shutdown. This will force the stream to re-evaluate all connexions states. So it
will detect the client has closed its connection.

This patch must be backported in 1.7.

7 years agoMINOR: ssl: rework smp_fetch_ssl_fc_cl_str without internal ssl use
Emmanuel Hocdet [Fri, 1 Sep 2017 15:32:08 +0000 (17:32 +0200)] 
MINOR: ssl: rework smp_fetch_ssl_fc_cl_str without internal ssl use

smp_fetch_ssl_fc_cl_str as very limited usage (only work with openssl == 1.0.2
compiled with the option enable-ssl-trace). It use internal cipher.algorithm_ssl
attribut and SSL_CIPHER_standard_name (available with ssl-trace).
This patch implement this (debug) function in a standard way. It used common
SSL_CIPHER_get_name to display cipher name. It work with openssl >= 1.0.2
and boringssl.

7 years agoRevert "BUG/MINOR: server: Remove FQDN requirement for using init-addr and state...
Willy Tarreau [Wed, 6 Sep 2017 12:22:45 +0000 (14:22 +0200)] 
Revert "BUG/MINOR: server: Remove FQDN requirement for using init-addr and state file"

This reverts commit 19e8aa58f7c42e602a95b4ceb4b254c424aed11c.

It causes some trouble reported by Manu :
   listen tls
     [...]
     server bla 127.0.0.1:8080

   [ALERT] 248/130258 (21960) : parsing [/etc/haproxy/test.cfg:53] : 'server bla' : no method found to resolve address '(null)'
   [ALERT] 248/130258 (21960) : Failed to initialize server(s) addr.

According to Nenad :
  "It's not a good way to fix the issue we were experiencing
   before. It will need a bigger rewrite, because the logic in
   srv_iterate_initaddr needs to be changed."

7 years agoBUG/MINOR: server: Remove FQDN requirement for using init-addr and state file
Nenad Merdanovic [Tue, 5 Sep 2017 13:32:47 +0000 (15:32 +0200)] 
BUG/MINOR: server: Remove FQDN requirement for using init-addr and state file

Historically the DNS was the only way of updating the server IP dynamically
and the init-addr processing and state file load required the server to have
an FQDN defined. Given that we can now update the IP through the socket as
well and also can have different init-addr values (like IP and 'none') - this
requirement needs to be removed.

This patch should be backported to 1.7.

7 years agoMINOR: polling: Use fd_update_events to update events seen for a fd
Christopher Faulet [Wed, 30 Aug 2017 08:34:36 +0000 (10:34 +0200)] 
MINOR: polling: Use fd_update_events to update events seen for a fd

Now, the same function is used by all pollers to update events seen for a
fd. This will ease the threads support integration.

7 years agoMINOR: fd: Add fd_update_events function
Christopher Faulet [Wed, 30 Aug 2017 08:30:04 +0000 (10:30 +0200)] 
MINOR: fd: Add fd_update_events function

This function should be called by the poller to set FD_POLL_* flags on an FD and
update its state if needed. This function has been added to ease threads support
integration.

7 years agoBUG/MEDIUM: epoll: ensure we always consider HUP and ERR
Willy Tarreau [Tue, 5 Sep 2017 13:32:56 +0000 (15:32 +0200)] 
BUG/MEDIUM: epoll: ensure we always consider HUP and ERR

Since commit 5be2f35 ("MAJOR: polling: centralize calls to I/O callbacks")
that came into 1.6-dev1, each poller deals with its own events and decides
to signal ability to receive or send on a file descriptor based on the
active events on the file descriptor.

The commit above was incorrectly done for the epoll code. Instead of
checking the active events on the fd, it checks for the new events. In
general these ones are the same for POLL_IN and POLL_OUT since they
are always cleared prior to being computed, but it is possible that
POLL_HUP and POLL_ERR were initially reported and are not reported
again (especially for HUP). This could happen for example if POLL_HUP
and POLL_IN were received together, the pending data exactly correspond
to a full buffer which is read at once, preventing the POLL_HUP from
being dealt with in the same call, and on the next call only POLL_OUT
is reported (eg: to emit some response or peers protocol ACKs). In this
case fd_may_recv() will not be enabled anymore and the close event will
be missed.

It seems quite hard to trigger this case, though it might explain some
of the rare missed close events that were detected in the past on the
peers.

This fix needs to be backported to 1.6 and 1.7.

7 years agoMEDIUM: check: server states and weight propagation re-work
Emeric Brun [Thu, 31 Aug 2017 12:41:55 +0000 (14:41 +0200)] 
MEDIUM: check: server states and weight propagation re-work

The server state and weight was reworked to handle
"pending" values updated by checks/CLI/LUA/agent.
These values are commited to be propagated to the
LB stack.

In further dev related to multi-thread, the commit
will be handled into a sync point.

Pending values are named using the prefix 'next_'
Current values used by the LB stack are named 'cur_'

7 years agoMINOR: freq_ctr: Return the new value after an update
Christopher Faulet [Fri, 1 Sep 2017 10:18:36 +0000 (12:18 +0200)] 
MINOR: freq_ctr: Return the new value after an update

This will ease threads support integration.

7 years agoMINOR: fd: Move (de)allocation of fdtab and fdinfo in (de)init_pollers
Christopher Faulet [Thu, 31 Aug 2017 15:52:09 +0000 (17:52 +0200)] 
MINOR: fd: Move (de)allocation of fdtab and fdinfo in (de)init_pollers

This will be useful for the threads support integration.

7 years agoMINOR: fd: Use inlined functions to check fd state in fd_*_send/recv functions
Christopher Faulet [Wed, 30 Aug 2017 08:07:47 +0000 (10:07 +0200)] 
MINOR: fd: Use inlined functions to check fd state in fd_*_send/recv functions

It these functions, the test is inverted and we rely on fd_recv/send_* function
to check the fd state. This will ease threads support integration.

7 years agoMINOR: fd: Add fd_active function
Christopher Faulet [Wed, 30 Aug 2017 07:59:38 +0000 (09:59 +0200)] 
MINOR: fd: Add fd_active function

This inlined function is used to check if a fd is active for receive or send. It
will ease threads support integration.

7 years agoMINOR: http: Use a trash chunk to store decoded string of the HTTP auth header
Christopher Faulet [Thu, 27 Jul 2017 13:18:52 +0000 (15:18 +0200)] 
MINOR: http: Use a trash chunk to store decoded string of the HTTP auth header

This string is used in sample fetches so it is safe to use a preallocated trash
chunk instead of a buffer dynamically allocated during HAProxy startup.

7 years agoMINOR: stick-tables: Make static_table_key a struct variable instead of a pointer
Christopher Faulet [Tue, 29 Aug 2017 13:30:31 +0000 (15:30 +0200)] 
MINOR: stick-tables: Make static_table_key a struct variable instead of a pointer

First, this variable does not need to be publicly exposed because it is only
used by stick_table functions. So we declare it as a global static in
stick_table.c file. Then, it is useless to use a pointer. Using a plain struct
variable avoids any dynamic allocation.

7 years agoMINOR: buffers: Move swap_buffer into buffer.c and add deinit_buffer function
Christopher Faulet [Tue, 29 Aug 2017 13:30:11 +0000 (15:30 +0200)] 
MINOR: buffers: Move swap_buffer into buffer.c and add deinit_buffer function

swap_buffer is a global variable only used by buffer_slow_realign. So it has
been moved from global.h to buffer.c and it is allocated by init_buffer
function. deinit_buffer function has been added to release it. It is also used
to destroy the buffers' pool.

7 years agoMINOR: logs: Realloc log buffers only after the config is parsed and checked
Christopher Faulet [Tue, 29 Aug 2017 14:54:41 +0000 (16:54 +0200)] 
MINOR: logs: Realloc log buffers only after the config is parsed and checked

During the configuration parsing, log buffers are reallocated when
global.max_syslog_len is updated. This can be done serveral time. So, instead of
doing it serveral time, we do it only once after the configuration parsing.

7 years agoMINOR: logs: Use dedicated function to init/deinit log buffers
Christopher Faulet [Wed, 26 Jul 2017 13:33:35 +0000 (15:33 +0200)] 
MINOR: logs: Use dedicated function to init/deinit log buffers

Now, we use init_log_buffers and deinit_log_buffers to, respectively, initialize
and deinitialize log buffers used for syslog messages.

These functions have been introduced to be used by threads, to deal with
thread-local log buffers.

7 years agoMEDIUM: chunks: Realloc trash buffers only after the config is parsed and checked
Christopher Faulet [Tue, 29 Aug 2017 14:46:57 +0000 (16:46 +0200)] 
MEDIUM: chunks: Realloc trash buffers only after the config is parsed and checked

Trash buffers are reallocated when "tune.bufsize" parameter is changed. Here, we
just move the realloc after the configuration parsing.

Given that the config parser doesn't rely on the trash size, it should be
harmless.

7 years agoMINOR: chunks: Use dedicated function to init/deinit trash buffers
Christopher Faulet [Wed, 26 Jul 2017 12:59:46 +0000 (14:59 +0200)] 
MINOR: chunks: Use dedicated function to init/deinit trash buffers

Now, we use init_trash_buffers and deinit_trash_buffers to, respectively,
initialize and deinitialize trash buffers (trash, trash_buf1 and trash_buf2).

These functions have been introduced to be used by threads, to deal with
thread-local trash buffers.

7 years agoMINOR: applet: Check applets_active_queue before processing applets queue
Christopher Faulet [Tue, 27 Jun 2017 14:07:01 +0000 (16:07 +0200)] 
MINOR: applet: Check applets_active_queue before processing applets queue

This is useless for now, but it will allow a huge improvement when the
multithreading will be merged.

7 years agoMINOR: backends: Make get_server_* functions explicitly static
Christopher Faulet [Fri, 9 Jun 2017 12:23:09 +0000 (14:23 +0200)] 
MINOR: backends: Make get_server_* functions explicitly static

Not used outside.

7 years agoMINOR: fd: Set owner and iocb field before inserting a new fd in the fdtab
Christopher Faulet [Tue, 5 Sep 2017 07:51:57 +0000 (09:51 +0200)] 
MINOR: fd: Set owner and iocb field before inserting a new fd in the fdtab

This will be needed for concurrent accesses.

7 years agoMINOR: fd: Don't forget to reset fdtab[fd].update when a fd is added/removed
Christopher Faulet [Thu, 1 Jun 2017 14:55:03 +0000 (16:55 +0200)] 
MINOR: fd: Don't forget to reset fdtab[fd].update when a fd is added/removed

It used to be guaranteed by the polling functions on a later call but
with concurrent accesses it cannot be granted anymore.

7 years agoMINOR: listeners: Change enable_listener and disable_listener into private functions
Christopher Faulet [Fri, 2 Jun 2017 08:00:35 +0000 (10:00 +0200)] 
MINOR: listeners: Change enable_listener and disable_listener into private functions

These functions are only used in listener.c.

7 years agoMINOR: listeners: Change listener_full and limit_listener into private functions
Christopher Faulet [Mon, 28 Aug 2017 13:29:20 +0000 (15:29 +0200)] 
MINOR: listeners: Change listener_full and limit_listener into private functions

These functions are only used in listener_accept. So there is no need to export
them.

7 years agoCLEANUP: memory: Remove unused function pool_destroy
Christopher Faulet [Mon, 28 Aug 2017 12:28:44 +0000 (14:28 +0200)] 
CLEANUP: memory: Remove unused function pool_destroy

This one was never used.

7 years agoDOC: Add note about "* " prefix in CSV stats
Daniel Schneller [Fri, 1 Sep 2017 17:13:55 +0000 (19:13 +0200)] 
DOC: Add note about "* " prefix in CSV stats

The check_status field in the CSV stats output is conditionally prefixed
with "* " if a check is currently underway. This can trip tools that
parse the CSV output and compare against a well known list of values.

This commit just adds this bit to the documentation.

7 years agoBUG/MEDIUM: http: Fix a regression bug when a HTTP response is in TUNNEL mode
Christopher Faulet [Tue, 29 Aug 2017 14:06:38 +0000 (16:06 +0200)] 
BUG/MEDIUM: http: Fix a regression bug when a HTTP response is in TUNNEL mode

Unfortunatly, a regression bug was introduced in the commit 1486b0ab
("BUG/MEDIUM: http: Switch HTTP responses in TUNNEL mode when body length is
undefined"). HTTP responses with undefined body length are blocked until timeout
when the compression is enabled. This bug was fixed in commit 69744d92
("BUG/MEDIUM: http: Fix blocked HTTP/1.0 responses when compression is
enabled").

The bug is still the same. We do not forward response data because we are
waiting for the synchronization between the HTTP request and the response.

To fix the bug, conditions to infinitly forward channel data has been slightly
relaxed. Now, it is done if there is no more analyzer registered on the channel
or if _FLT_END analyzer is still there but without the flag CF_FLT_ANALYZE. This
last condition is only possible when a channel is waiting the end of the other
side. So, fundamentally, it means that no one is analyzing the channel
anymore. This is a transitional state during a sync phase.

This patch must be backported in 1.7.

7 years agoMINOR: ssl: remove duplicate ssl_methods in struct bind_conf
Emmanuel Hocdet [Wed, 9 Aug 2017 16:26:20 +0000 (18:26 +0200)] 
MINOR: ssl: remove duplicate ssl_methods in struct bind_conf

Patch "MINOR: ssl: support ssl-min-ver and ssl-max-ver with crt-list"
introduce ssl_methods in struct ssl_bind_conf. struct bind_conf have now
ssl_methods and ssl_conf.ssl_methods (unused). It's error-prone. This patch
remove the duplicate structure to avoid any confusion.

7 years agoDOC: Refer to Mozilla TLS info / config generator
Daniel Schneller [Fri, 1 Sep 2017 17:29:57 +0000 (19:29 +0200)] 
DOC: Refer to Mozilla TLS info / config generator

As per a recent mailing list discussion, suggesting specific cipher
settings is not too helpful, because they depend on a lot of factors,
ranging from client capabilities, available TLS libraries, new
security research, and others.
To avoid the documentation from become stale -- and potentially
wrong/dangerous, this commit adds links to Mozilla's well-reknowned
TLS blog, as well as to their configuration generator.

7 years agoDOC: add CLI info on privilege levels
Olivier Doucet [Thu, 31 Aug 2017 09:05:10 +0000 (11:05 +0200)] 
DOC: add CLI info on privilege levels

7 years agoMEDIUM: connection: remove useless flag CO_FL_DATA_WR_SH
Willy Tarreau [Wed, 30 Aug 2017 07:59:52 +0000 (09:59 +0200)] 
MEDIUM: connection: remove useless flag CO_FL_DATA_WR_SH

After careful inspection, this flag is set at exactly two places :
  - once in the health-check receive callback after receipt of a
    response
  - once in the stream interface's shutw() code where CF_SHUTW is
    always set on chn->flags

The flag was checked in the checks before deciding to send data, but
when it is set, the wake() callback immediately closes the connection
so the CO_FL_SOCK_WR_SH flag is also set.

The flag was also checked in si_conn_send(), but checking the channel's
flag instead is enough and even reveals that one check involving it
could never match.

So it's time to remove this flag and replace its check with a check of
CF_SHUTW in the stream interface. This way each layer is responsible
for its shutdown, this will ease insertion of the mux layer.

7 years agoCLEANUP: connection: remove the unused conn_sock_shutw_pending()
Willy Tarreau [Wed, 30 Aug 2017 05:44:03 +0000 (07:44 +0200)] 
CLEANUP: connection: remove the unused conn_sock_shutw_pending()

This has never been used anywhere.

7 years agoMEDIUM: connection: remove useless flag CO_FL_DATA_RD_SH
Willy Tarreau [Wed, 30 Aug 2017 05:35:35 +0000 (07:35 +0200)] 
MEDIUM: connection: remove useless flag CO_FL_DATA_RD_SH

This flag is both confusing and wrong. It is supposed to report the
fact that the data layer has received a shutdown, but in fact this is
reported by CO_FL_SOCK_RD_SH which is set by the transport layer after
this condition is detected. The only case where the flag above is set
is in the stream interface where CF_SHUTR is also set on the receiving
channel.

In addition, it was checked in the health checks code (while never set)
and was always test jointly with CO_FL_SOCK_RD_SH everywhere, except in
conn_data_read0_pending() which incorrectly doesn't match the second
time it's called and is fortunately protected by an extra check on
(ic->flags & CF_SHUTR).

This patch gets rid of the flag completely. Now conn_data_read0_pending()
accurately reports the fact that the transport layer has detected the end
of the stream, regardless of the fact that this state was already consumed,
and the stream interface watches ic->flags&CF_SHUTR to know if the channel
was already closed by the upper layer (which it already used to do).

The now unused conn_data_read0() function was removed.

7 years agoMINOR: stream: provide a new stream creation function for connections
Willy Tarreau [Mon, 28 Aug 2017 15:18:36 +0000 (17:18 +0200)] 
MINOR: stream: provide a new stream creation function for connections

The purpose will be to create new streams for a given connection so
that we can later abstract this from a mux.

7 years agoMEDIUM: session: add a pointer to a struct task in the session
Willy Tarreau [Mon, 28 Aug 2017 17:02:51 +0000 (19:02 +0200)] 
MEDIUM: session: add a pointer to a struct task in the session

The session may need to enforce a timeout when waiting for a handshake.
Till now we used a trick to avoid allocating a pointer, we used to set
the connection's owner to the task and set the task's context to the
session, so that it was possible to circle between all of them. The
problem is that we'll really need to pass the pointer to the session
to the upper layers during initialization and that the only place to
store it is conn->owner, which is squatted for this trick.

So this patch moves the struct task* into the session where it should
always have been and ensures conn->owner points to the session until
the data layer is properly initialized.

7 years agoCLEANUP: listener: remove the unused handler field
Willy Tarreau [Mon, 28 Aug 2017 14:28:47 +0000 (16:28 +0200)] 
CLEANUP: listener: remove the unused handler field

Historically listeners used to have a handler depending on the upper
layer. But now it's exclusively process_stream() and nothing uses it
anymore so it can safely be removed.

7 years agoMEDIUM: stream: make stream_new() allocate its own task
Willy Tarreau [Mon, 28 Aug 2017 14:22:54 +0000 (16:22 +0200)] 
MEDIUM: stream: make stream_new() allocate its own task

Currently a task is allocated in session_new() and serves two purposes :
  - either the handshake is complete and it is offered to the stream via
    the second arg of stream_new()

  - or the handshake is not complete and it's diverted to be used as a
    timeout handler for the embryonic session and repurposed once we land
    into conn_complete_session()

Furthermore, the task's process() function was taken from the listener's
handler in conn_complete_session() prior to being replaced by a call to
stream_new(). This will become a serious mess with the mux.

Since it's impossible to have a stream without a task, this patch removes
the second arg from stream_new() and make this function allocate its own
task. In session_accept_fd(), we now only allocate the task if needed for
the embryonic session and delete it later.

7 years agoMEDIUM: connection: get rid of data->init() which was not for data
Willy Tarreau [Mon, 28 Aug 2017 13:46:01 +0000 (15:46 +0200)] 
MEDIUM: connection: get rid of data->init() which was not for data

The ->init() callback of the connection's data layer was only used to
complete the session's initialisation since sessions and streams were
split apart in 1.6. The problem is that it creates a big confusion in
the layers' roles as the session has to register a dummy data layer
when waiting for a handshake to complete, then hand it off to the
stream which will replace it.

The real need is to notify that the transport has finished initializing.
This should enable a better splitting between these layers.

This patch thus introduces a connection-specific callback called
xprt_done_cb() which informs about handshake successes or failures. With
this, data->init() can disappear, CO_FL_INIT_DATA as well, and we don't
need to register a dummy data->wake() callback to be notified of errors.

7 years agoBUG/MINOR: stream-int: don't check the CO_FL_CURR_WR_ENA flag
Willy Tarreau [Tue, 29 Aug 2017 14:40:59 +0000 (16:40 +0200)] 
BUG/MINOR: stream-int: don't check the CO_FL_CURR_WR_ENA flag

The stream interface chk_snd() code checks if the connection has already
subscribed to write events in order to avoid attempting a useless write()
which will fail. But it used to check both the CO_FL_CURR_WR_ENA and the
CO_FL_DATA_WR_ENA flags, while the former may only be present without the
latterif either the other side just disabled writing did not synchronize
yet (which is harmless) or if it's currently performing a handshake, which
is being checked by the next condition and will be better dealt with by
properly subscribing to the data events.

This code was added back in 1.5-dev20 to limit the number of useless calls
to splice() but both flags were checked at once while only CO_FL_DATA_WR_ENA
was needed. This bug seems to have no impact other than making code changes
more painful. This fix may be backported down to 1.5 though is unlikely to
be needed there.

7 years agoREORG/MEDIUM: connection: introduce the notion of connection handle
Willy Tarreau [Thu, 24 Aug 2017 12:31:19 +0000 (14:31 +0200)] 
REORG/MEDIUM: connection: introduce the notion of connection handle

Till now connections used to rely exclusively on file descriptors. It
was planned in the past that alternative solutions would be implemented,
leading to member "union t" presenting sock.fd only for now.

With QUIC, the connection will need to continue to exist but will not
rely on a file descriptor but a connection ID.

So this patch introduces a "connection handle" which is either a file
descriptor or a connection ID, to replace the existing "union t". We've
now removed the intermediate "struct sock" which was never used. There
is no functional change at all, though the struct connection was inflated
by 32 bits on 64-bit platforms due to alignment.

7 years agoOPTIM: lua: don't add "Connection: close" on the response
Willy Tarreau [Wed, 23 Aug 2017 09:37:48 +0000 (11:37 +0200)] 
OPTIM: lua: don't add "Connection: close" on the response

Haproxy doesn't need this anymore, we're wasting cycles checking for
a Connection header in order to add "Connection: close" only in the
1.1 case so that haproxy sees it and removes it. All tests were run
in 1.0 and 1.1, with/without the request header, and in the various
keep-alive/close modes, with/without compression, and everything works
fine. It's worth noting that this header was inherited from the stats
applet and that the same cleanup probably ought to be done there as
well.

7 years agoOPTIM: lua: don't use expensive functions to parse headers in the HTTP applet
Willy Tarreau [Wed, 23 Aug 2017 09:24:47 +0000 (11:24 +0200)] 
OPTIM: lua: don't use expensive functions to parse headers in the HTTP applet

In the HTTP applet, we have to parse the response headers provided by
the application and to produce a response. strcasecmp() is expensive,
and chunk_append() even more as it uses a format string.

Here we check the string length before calling strcasecmp(), which
results in strcasecmp() being called only on the relevant header in
practise due to very few collisions on the name lengths, effectively
dividing the number of calls by 3, and we replace chunk_appendf()
with memcpy() as we already know the string lengths.

Doing just this makes the "hello-world" applet 5% faster, reaching
41400 requests/s on a core i5-3320M.

7 years agoBUG/MEDIUM: stream: properly set the required HTTP analysers on use-service
Willy Tarreau [Wed, 23 Aug 2017 08:52:20 +0000 (10:52 +0200)] 
BUG/MEDIUM: stream: properly set the required HTTP analysers on use-service

Commit 4850e51 ("BUG/MAJOR: lua: Do not force the HTTP analysers in
use-services") fixed a bug in how services are used in Lua, but this
fix broke the ability for Lua services to support keep-alive.

The cause is that we branch to a service while we have not yet set the
body analysers on the request nor the response, and when we start to
deal with the response we don't have any request analyser anymore. This
leads the response forward engine to detect an error and abort. It's
very likely that this also causes some random truncation of responses
though this has not been observed during the tests.

The root cause is not the Lua part in fact, the commit above was correct,
the problem is the implementation of the "use-service" action. When done
in an HTTP request, it bypasses the load balancing decisions and the
connect() phase. These ones are normally the ones preparing the request
analysers to parse the body when keep-alive is set. This should be dealt
with in the main process_use_service() function in fact.

That's what this patch does. If process_use_service() is called from the
http-request rule set, it enables the XFER_BODY analyser on the request
(since the same is always set on the response). Note that it's exactly
what is being done on the stats page which properly supports keep-alive
and compression.

This fix must be backported to 1.7 and 1.6 as the breakage appeared in 1.6.3.

7 years agoMINOR: lua: properly process the contents of the content-length field
Willy Tarreau [Wed, 23 Aug 2017 07:32:06 +0000 (09:32 +0200)] 
MINOR: lua: properly process the contents of the content-length field

The header's value was parsed with atoi() then compared against -1,
meaning that all the unparsable stuff returning zero was not considered
and that all multiples of 2^32 + 0xFFFFFFFF would continue to emit a
chunk.

Now instead we parse the value using a long long, only accept positive
values and consider all unparsable values as incorrect and switch to
either close or chunked encoding. This is more in line with what a
client (including haproxy's parser) would expect.

This may be backported as a cleanup to stable versions, though it's
really unlikely that Lua applications are facing side effects of this.

7 years agoBUG/MEDIUM: lua: HTTP services must take care of body-less status codes
Willy Tarreau [Wed, 23 Aug 2017 07:10:38 +0000 (09:10 +0200)] 
BUG/MEDIUM: lua: HTTP services must take care of body-less status codes

The following Lua code causes emission of a final chunk after the body,
which is wrong :

core.register_service("send204", "http", function(applet)
   applet:set_status(204)
   applet:start_response()
end)

Indeed, responses with status codes 1xx, 204 and 304 do not contain any
body and the message ends immediately after the empty header (cf RFC7230)
so by emitting a 0<CR><LF> we're disturbing keep-alive responses. There's
a workaround against this for now which consists in always emitting
"Content-length: 0" but it may not be cool with 304 when clients use
the headers to update their cache.

This fix must be backported to stable versions back to 1.6.

7 years agoBUG/MAJOR: lua: fix the impact of the scheduler changes again
Willy Tarreau [Wed, 23 Aug 2017 14:07:33 +0000 (16:07 +0200)] 
BUG/MAJOR: lua: fix the impact of the scheduler changes again

Commit d1aa41f ("BUG/MAJOR: lua: properly dequeue hlua_applet_wakeup()
for new scheduler") tried to address the side effects of the scheduler
changes on Lua, but it was not enough. Having some Lua code send data
in chunks separated by one second each clearly shows busy polling being
done.

The issue was tracked down to hlua_applet_wakeup() being woken up on
timer expiration, and returning itself without clearing the timeout,
causing the task to be re-inserted with an expiration date in the past,
thus firing again. In the past it was not a problem, as returning NULL
was enough to clear the timer. Now we can't rely on this anymore so
it's important to clear this timeout.

No backport is needed, this issue is specific to 1.8-dev and results
from an incomplete fix in the commit above.

7 years agoBUG/MEDIUM: dns: fix accepted_payload_size parser to avoid integer overflow
Willy Tarreau [Tue, 22 Aug 2017 10:01:26 +0000 (12:01 +0200)] 
BUG/MEDIUM: dns: fix accepted_payload_size parser to avoid integer overflow

Since commit 9d8dbbc ("MINOR: dns: Maximum DNS udp payload set to 8192") it's
possible to specify a packet size, but passing too large a size or a negative
size is not detected and results in memset() being performed over a 2GB+ area
upon receipt of the first DNS response, causing runtime crashes.

We now check that the size is not smaller than the smallest packet which is
the DNS header size (12 bytes).

No backport is needed.

7 years agoBUG/MINOR: dns: wrong resolution interval lead to 100% CPU
Baptiste Assmann [Mon, 21 Aug 2017 11:21:48 +0000 (13:21 +0200)] 
BUG/MINOR: dns: wrong resolution interval lead to 100% CPU

Since the DNS layer split and the use of obj_type structure, we did not
updated propoerly the code used to compute the interval between 2
resolutions.
A nasty loop was then created when:
- resolver's hold.valid is shorter than servers' check.inter
- a valid response is available in the DNS cache

A task was woken up for a server's resolution. The servers pick up the IP
in the cache and returns without updating the 'last update' timestamp of
the resolution (which is normal...). Then the task is woken up again for
the same server.
The fix simply computes now properly the interval between 2 resolutions
and the cache is used properly while a new resolution is triggered if
the data is not fresh enough.

7 years agoCLEANUP: dns: remove duplicated code in dns_validate_dns_response()
Baptiste Assmann [Mon, 21 Aug 2017 14:11:32 +0000 (16:11 +0200)] 
CLEANUP: dns: remove duplicated code in dns_validate_dns_response()

a reader pointer comparison to the end of the buffer was performed twice
while once is obviously enough.

backport status: this patch can be backported into HAProxy 1.6 (with some
modification. Please contact me)

7 years agoCLEANUP: dns: remove duplicated code in dns_resolve_recv()
Baptiste Assmann [Mon, 21 Aug 2017 14:09:59 +0000 (16:09 +0200)] 
CLEANUP: dns: remove duplicated code in dns_resolve_recv()

by mistake, I duplicated a block when introductiing the list_for_each loop
on a resolution's requester list.

7 years agoMINOR: dns: make SRV record processing more verbose
Baptiste Assmann [Fri, 18 Aug 2017 21:36:07 +0000 (23:36 +0200)] 
MINOR: dns: make SRV record processing more verbose

For troubleshooting purpose, it may be important to know when a server
got its fqdn updated by a SRV record.
This patch makes HAProxy to report such events through stderr and logs.

7 years agoMINOR: dns: automatic reduction of DNS accpeted payload size
Baptiste Assmann [Mon, 21 Aug 2017 14:51:09 +0000 (16:51 +0200)] 
MINOR: dns: automatic reduction of DNS accpeted payload size

RFC 6891 states that if a DNS client announces "big" payload size and
doesn't receive a response (because some equipments on the path may
block/drop UDP fragmented packets), then it should try asking for
smaller responses.

7 years agoMINOR: dns: Maximum DNS udp payload set to 8192
Baptiste Assmann [Fri, 18 Aug 2017 21:35:08 +0000 (23:35 +0200)] 
MINOR: dns: Maximum DNS udp payload set to 8192

Following up DNS extension introduction, this patch aims at making the
computation of the maximum number of records in DNS response dynamic.
This computation is based on the announced payload size accepted by
HAProxy.

7 years agoBUG/MINOR: dns: server set by SRV records stay in "no resolution" status
Baptiste Assmann [Mon, 14 Aug 2017 08:37:46 +0000 (10:37 +0200)] 
BUG/MINOR: dns: server set by SRV records stay in "no resolution" status

This patch fixes a bug where some servers managed by SRV record query
types never ever recover from a "no resolution" status.
The problem is due to a wrong function called when breaking the
server/resolution (A/AAAA) relationship: this is performed when a server's SRV
record disappear from the SRV response.

7 years agoBUG/MINOR: Wrong type used as argument for spoe_decode_buffer().
Frédéric Lécaille [Tue, 22 Aug 2017 08:33:14 +0000 (10:33 +0200)] 
BUG/MINOR: Wrong type used as argument for spoe_decode_buffer().

Contrary to 64-bits libCs where size_t type size is 8, on systems with 32-bits
size of size_t is 4 (the size of a long) which does not equal to size of uint64_t type.
This was revealed by such GCC warnings on 32bits systems:

src/flt_spoe.c:2259:40: warning: passing argument 4 of spoe_decode_buffer from
incompatible pointer type
  if (spoe_decode_buffer(&p, end, &str, &sz) == -1)
                                         ^
As the already existing code using spoe_decode_buffer() already use such pointers to
uint64_t, in place of pointer to size_t ;), most of this code is in contrib directory,
this simple patch modifies the prototype of spoe_decode_buffer() so that to use a
pointer to uint64_t in place of a pointer to size_t, uint64_t type being the type
finally required for decode_varint().

7 years agoMINOR: http: export some of the HTTP parser macros
Willy Tarreau [Wed, 26 Jul 2017 06:07:15 +0000 (08:07 +0200)] 
MINOR: http: export some of the HTTP parser macros

The two macros EXPECT_LF_HERE and EAT_AND_JUMP_OR_RETURN were exported
for use outside the HTTP parser. They now take extra arguments to avoid
implicit pointers and jump labels. These will be used to reimplement a
minimalist HTTP/1 parser in the H1->H2 gateway.

7 years agoTESTS: ist: add a test file for the functions
Willy Tarreau [Wed, 9 Aug 2017 21:36:48 +0000 (23:36 +0200)] 
TESTS: ist: add a test file for the functions

This test file covers the various functions provided by ist.h. It allows
both to test them for absence of regression, and to observe the code
emitted at different optimization levels.

7 years agoMINOR: ist: implement very simple indirect strings
Willy Tarreau [Tue, 30 May 2017 15:49:36 +0000 (17:49 +0200)] 
MINOR: ist: implement very simple indirect strings

For HPACK we'll need to perform a lot of string manipulation between the
dynamic headers table and the output stream, and we need an efficient way
to deal with that, considering that the zero character is not an end of
string marker here. It turns out that gcc supports returning structs from
functions and is able to place up to two words directly in registers when
-freg-struct is used, which is the case by default on x86 and armv8. On
other architectures the caller reserves some stack space where the callee
can write, which is equivalent to passing a pointer to the return value.

So let's implement a few functions to deal with this as the resulting code
will be optimized on certain architectures where retrieving the length of
a string will simply consist in reading one of the two returned registers.

Extreme care was taken to ensure that the compiler gets maximum opportunities
to optimize out every bit of unused code. This is also the reason why no
call to regular string functions (such as strlen(), memcmp(), memcpy() etc)
were used. The code involving them is often larger than when they are open
coded. Given that strings are usually very small, especially when manipulating
headers, the time spent calling a function optimized for large vectors often
ends up being higher than the few cycles needed to count a few bytes.

An issue was met with __builtin_strlen() which can automatically convert
a constant string to its constant length. It doesn't accept NULLs and there
is no way to hide them using expressions as the check is made before the
optimizer is called. On gcc 4 and above, using an intermediary variable
is enough to hide it. On older versions, calls to ist() with an explicit
NULL argument will issue a warning. There is normally no reason to do this
but taking care of it the best possible still seems important.

7 years agoMEDIUM: session: do not free a session until no stream references it
Willy Tarreau [Tue, 27 Jun 2017 13:25:14 +0000 (15:25 +0200)] 
MEDIUM: session: do not free a session until no stream references it

We now refrain from clearing a session's variables, counters, and from
releasing it as long as at least one stream references it. For now it
never happens but with H2 this will be mandatory to avoid double frees.

7 years agoMINOR: stream: link the stream to its session
Willy Tarreau [Tue, 27 Jun 2017 13:20:05 +0000 (15:20 +0200)] 
MINOR: stream: link the stream to its session

Now each stream is added to the session's list of streams, so that it
will be possible to know all the streams belonging to a session, and
to know if any stream is still attached to a sessoin.

7 years agoMINOR: session: add a streams field to the session struct
Willy Tarreau [Tue, 27 Jun 2017 13:13:43 +0000 (15:13 +0200)] 
MINOR: session: add a streams field to the session struct

This will be used to hold the list of streams belonging to a given session.

7 years agoMINOR: chunks: add chunk_memcpy() and chunk_memcat()
Willy Tarreau [Thu, 27 Jul 2017 11:35:34 +0000 (13:35 +0200)] 
MINOR: chunks: add chunk_memcpy() and chunk_memcat()

These two functions respectively copy a memory area onto the chunk, and
append the contents of a memory area over a chunk. They are convenient
to prepare binary output data to be sent and will be used for HTTP/2.

7 years agoMINOR: dns: default "hold obsolete" timeout set to 0
Baptiste Assmann [Fri, 18 Aug 2017 08:15:42 +0000 (10:15 +0200)] 
MINOR: dns: default "hold obsolete" timeout set to 0

The "hold obsolete" timer is used to prevent HAProxy from moving a server to
an other IP or from considering the server as DOWN if the IP currently
affected to this server has not been seen for this period of time in DNS
responses.

That said, historically, HAProxy used to update servers as soon as the IP
has disappeared from the response. Current default timeout break this
historical behavior and may change HAProxy's behavior when people will
upgrade to 1.8.

This patch changes the default value to 0 to keep backward compatibility.