]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
11 years agoMEDIUM: http: do not report connection errors for second and further requests
Willy Tarreau [Sun, 15 Dec 2013 18:31:37 +0000 (19:31 +0100)] 
MEDIUM: http: do not report connection errors for second and further requests

In HTTP keep-alive, if we face a connection error to the server while sending
the request, the error should not be reported, and the client-side connection
should simply be closed, so that client knows it can retry. This can happen if
the server has too short a keep-alive timeout and quits at the same moment the
new request comes in.

11 years agoMINOR: http: add option prefer-last-server
Willy Tarreau [Sun, 15 Dec 2013 17:58:25 +0000 (18:58 +0100)] 
MINOR: http: add option prefer-last-server

When the load balancing algorithm in use is not deterministic, and a previous
request was sent to a server to which haproxy still holds a connection, it is
sometimes desirable that subsequent requests on a same session go to the same
server as much as possible. Note that this is different from persistence, as
we only indicate a preference which haproxy tries to apply without any form
of warranty. The real use is for keep-alive connections sent to servers. When
this option is used, haproxy will try to reuse the same connection that is
attached to the server instead of rebalancing to another server, causing a
close of the connection. This can make sense for static file servers. It does
not make much sense to use this in combination with hashing algorithms.

11 years agoMAJOR: backend: enable connection reuse
Willy Tarreau [Sun, 15 Dec 2013 15:33:46 +0000 (16:33 +0100)] 
MAJOR: backend: enable connection reuse

This commit allows an existing server-side connection to be reused if
it matches the same target. Basic controls are performed ; right now
we do not allow to reuse a connection when dynamic source binding is
in use or when the destination address or port is dynamic (eg: proxy
mode). Later we'll have to also disable connection sharing when PROXY
protocol is being used or when non-idempotent requests are processed.

11 years agoMAJOR: http: add the keep-alive transition on the server side
Willy Tarreau [Sun, 15 Dec 2013 09:25:42 +0000 (10:25 +0100)] 
MAJOR: http: add the keep-alive transition on the server side

When a connection to the server is complete, if the transaction
requests keep-alive mode, we don't shut the connection and we just
reinitialize the stream interface in order to be able to reuse the
connection afterwards.

Note that the server connection count is decremented, just like the
backend's, and that we still try to wake up waiters. But that makes
sense considering that we'll eventually be able to immediately pass
idle connections to waiters.

11 years agoMAJOR: stream-int: handle the connection reuse in si_connect()
Willy Tarreau [Sun, 15 Dec 2013 15:20:50 +0000 (16:20 +0100)] 
MAJOR: stream-int: handle the connection reuse in si_connect()

This is the best place to reuse a connection. We centralize all
connection requests and we're at the best place to know exactly
what the current state of the underlying connection is. If the
connection is reused, we just enable polling for send() in order
to be able to emit the request.

11 years agoMEDIUM: connection: inform si_alloc_conn() whether existing conn is OK or not
Willy Tarreau [Sun, 15 Dec 2013 12:31:35 +0000 (13:31 +0100)] 
MEDIUM: connection: inform si_alloc_conn() whether existing conn is OK or not

When allocating a new connection, only the caller knows whether it's
acceptable to reuse the previous one or not. Let's pass this information
to si_alloc_conn() which will do the cleanup if the connection is not
acceptable.

11 years agoMINOR: config: add option http-keep-alive
Willy Tarreau [Sat, 16 Jan 2010 18:48:41 +0000 (19:48 +0100)] 
MINOR: config: add option http-keep-alive

This new option enables HTTP keep-alive processing on the connections.
It can be overwritten by http-server-close, httpclose and forceclose.
Right now full-chain keep-alive is not yet implemented, but we need
the option to work on it. The doc will come later.

11 years agoOPTIM: http: do not re-enable reading on client side while closing the server side
Willy Tarreau [Sun, 15 Dec 2013 14:32:10 +0000 (15:32 +0100)] 
OPTIM: http: do not re-enable reading on client side while closing the server side

It's common to observe a an recv() call on the client side just after
the connect() to has been issued to the server side when running in
server close mode. The reason is that the whole request has been sent
and the shutw() has been queued in the channel, so the request message
switches to the MSG_CLOSED state, which didn't disable reading. Let's
do it now. That way the reading will only be re-enabled after the
response is transferred to the client. However if abortonclose is set,
we still leave it enabled.

11 years agoOPTIM: http: set CF_READ_DONTWAIT on response message
Willy Tarreau [Sun, 15 Dec 2013 14:21:32 +0000 (15:21 +0100)] 
OPTIM: http: set CF_READ_DONTWAIT on response message

strace shows a lot of EAGAIN on small response messages. This
is caused by the fact that the READ_DONTWAIT flag is not set
on response message, it's only there when we want to flush
pending data.

For small responses, it's a waste of CPU cycles to call recv()
for nothing since most of the time, everything we'll need will
be in the first response. Also, this will offer more opportunities
for using splice() to transfer data.

11 years agoMEDIUM: connection: centralize handling of nolinger in fd management
Willy Tarreau [Sun, 15 Dec 2013 13:19:38 +0000 (14:19 +0100)] 
MEDIUM: connection: centralize handling of nolinger in fd management

Right now we see many places doing their own setsockopt(SO_LINGER).
Better only do it just before the close() in fd_delete(). For this
we add a new flag on the file descriptor, indicating if it's safe or
not to linger. If not (eg: after a connect()), then the setsockopt()
call is automatically performed before a close().

The flag automatically turns to safe when receiving a read0.

11 years agoMINOR: connection: add simple functions to report connection readiness
Willy Tarreau [Sun, 15 Dec 2013 09:23:20 +0000 (10:23 +0100)] 
MINOR: connection: add simple functions to report connection readiness

conn_xprt_ready() reports if the transport layer is ready.
conn_ctrl_ready() reports if the control layer is ready.

The stream interface uses si_conn_ready() to report that the
underlying connection is ready. This will be used for connection
reuse in keep-alive mode.

11 years agoDOC: move option tcp-check to the proper place
Willy Tarreau [Mon, 16 Dec 2013 00:07:00 +0000 (01:07 +0100)] 
DOC: move option tcp-check to the proper place

It was not alphabetically sorted.

11 years agoDOC: move option pgsql-check to the correct place
Willy Tarreau [Sun, 15 Dec 2013 17:49:01 +0000 (18:49 +0100)] 
DOC: move option pgsql-check to the correct place

This one was not alphabetically sorted.

11 years agoBUILD: dumpstats: fix build error on Solaris
Willy Tarreau [Mon, 16 Dec 2013 00:42:03 +0000 (01:42 +0100)] 
BUILD: dumpstats: fix build error on Solaris

Since the recent addition of map updates, haproxy does not build anymore
on Solaris because "s_addr" is a #define :

src/dumpstats.c: In function `stats_map_lookup':
src/dumpstats.c:4688: error: syntax error before '.' token
src/dumpstats.c:4781: error: `S_un' undeclared (first use in this function)
src/dumpstats.c:4781: error: (Each undeclared identifier is reported only once
src/dumpstats.c:4781: error: for each function it appears in.)
make: *** [src/dumpstats.o] Error 1

Simply rename the variable.

11 years agoBUILD: log: fix build warning on Solaris
Willy Tarreau [Mon, 16 Dec 2013 00:38:33 +0000 (01:38 +0100)] 
BUILD: log: fix build warning on Solaris

The is* macros must not use a char on Solaris. Unsigned char is OK.
Casting char to int is wrong as well since we get a negative value.

  src/log.c: In function `parse_logformat_string':
  src/log.c:454: warning: subscript has type `char'

11 years agoBUILD: pattern: silence a warning about uninitialized value
Willy Tarreau [Sun, 15 Dec 2013 15:42:26 +0000 (16:42 +0100)] 
BUILD: pattern: silence a warning about uninitialized value

Gcc 3.4 warns that mask may be used uninitialized in pattern.c. This
is wrong since it's used in the same condition as its assignment,
although it's not necessarily obvious for the compiler. Fix this by
initializing the value.

This was introduced by recent commit 01cdcd4a so no backport is needed.

11 years agoBUILD: fix SUBVERS extraction in the Makefile
Willy Tarreau [Mon, 16 Dec 2013 00:34:39 +0000 (01:34 +0100)] 
BUILD: fix SUBVERS extraction in the Makefile

We'd rather skip any line containing "$Format" and not just those
beginning with it because SUBVERS starts with a dash and caused a
bad format to be reported.

11 years agoBUG/MAJOR: session: repair tcp-request connection rules
Willy Tarreau [Mon, 16 Dec 2013 01:16:50 +0000 (02:16 +0100)] 
BUG/MAJOR: session: repair tcp-request connection rules

Since recent commit f79c817 (MAJOR: connection: add two new flags to
indicate readiness of control/transport) and the surrounding commits,
the session initialization has been slightly delayed and the control
layer of the connection is not yet initialized when processing the
rules.

We need to move that minimal initialization a bit above.

The bug was introduced with latest changes, no backport is needed.

11 years agoBUG/MEDIUM: checks: tracking servers must not inherit the MAINT flag
Willy Tarreau [Sat, 14 Dec 2013 15:16:01 +0000 (16:16 +0100)] 
BUG/MEDIUM: checks: tracking servers must not inherit the MAINT flag

If a server is disabled in configuration and another one tracks it,
this last one must not inherit the MAINT flag otherwise it needs to
be explicitly enabled afterwards. Just remove this to fix the issue.

11 years agoBUG/MEDIUM: checks: ensure we can enable a server after boot
Willy Tarreau [Sat, 14 Dec 2013 15:14:15 +0000 (16:14 +0100)] 
BUG/MEDIUM: checks: ensure we can enable a server after boot

Since commit 58c3297 (MEDIUM: Set rise and fall of agent checks to 1),
due to a bogus condition, it became impossible to re-enable a server
that was disabled in the configuration if no agent was enabled. The
reason is that in this case, the agent's health was zero while the
condition expected it to be at least one to consider the action.

Let's fix this by only considering the health of checks that are enabled.

11 years agoMEDIUM: checks: enable agent checks even if health checks are disabled
Willy Tarreau [Wed, 11 Dec 2013 20:26:24 +0000 (21:26 +0100)] 
MEDIUM: checks: enable agent checks even if health checks are disabled

The agent is able to retrieve some weight information from the server
and will eventually be able to force the server into maintenance mode.
It doesn't seem logical to have it depend on the health check being
configured, as for some servers it might very well make sense to only
fetch the weight from the server's load regardless of the health.

So let's stop disabling the agent checks when health checks are disabled.

11 years agoMINOR: checks: add a flag to indicate what check is an agent
Willy Tarreau [Wed, 11 Dec 2013 20:15:19 +0000 (21:15 +0100)] 
MINOR: checks: add a flag to indicate what check is an agent

Currently to know if a check is an agent, we compare its pointer to its
servers' agent pointer. Better have a flag in its state to indicate this.

11 years agoMINOR: checks: create the agent tasks even when no check is configured
Willy Tarreau [Wed, 11 Dec 2013 20:10:14 +0000 (21:10 +0100)] 
MINOR: checks: create the agent tasks even when no check is configured

Till now, a configuration required at least one health check in the
whole config file to create the agent tasks. Now we start them even
if no health check is enabled.

11 years agoMINOR: checks: add a PAUSED state for the checks
Willy Tarreau [Wed, 11 Dec 2013 20:03:31 +0000 (21:03 +0100)] 
MINOR: checks: add a PAUSED state for the checks

Health checks can now be paused. This is the status they get when the
server is put into maintenance mode, which is more logical than relying
on the server's state at some places. It will be needed to allow agent
checks to run when health checks are disabled (currently not possible).

11 years agoMINOR: checks: fix agent check interval computation
Willy Tarreau [Wed, 11 Dec 2013 19:41:18 +0000 (20:41 +0100)] 
MINOR: checks: fix agent check interval computation

start_checks() only used to consider the health checks intervals to
compute the start interval, so if an agent had a faster check than
all health checks, it would be significantly delayed.

11 years agoMINOR: checks: use check->state instead of srv->state & SRV_CHECKED
Willy Tarreau [Wed, 11 Dec 2013 19:36:34 +0000 (20:36 +0100)] 
MINOR: checks: use check->state instead of srv->state & SRV_CHECKED

Having the check state partially stored in the server doesn't help.
Some functions such as srv_getinter() rely on the server being checked
to decide what check frequency to use, instead of relying on the check
being configured. So let's get rid of SRV_CHECKED and SRV_AGENT_CHECKED
and only use the check's states instead.

11 years agoMINOR: checks: replace state DISABLED with CONFIGURED and ENABLED
Willy Tarreau [Wed, 11 Dec 2013 19:11:55 +0000 (20:11 +0100)] 
MINOR: checks: replace state DISABLED with CONFIGURED and ENABLED

At the moment, health checks and agent checks are tied : no agent
check is emitted if no health check is enabled. Other parameters
are considered in the condition for letting checks run. It will
help us selectively enable checks (agent and regular checks) to be
know whether they're enabled/disabled and configured or not. Now
we can already emit an error when trying to enable an unconfigured
agent.

11 years agoMINOR: checks: rename the state flags
Willy Tarreau [Wed, 11 Dec 2013 18:41:16 +0000 (19:41 +0100)] 
MINOR: checks: rename the state flags

The flag CHK_STATE_RUNNING is misleading as one may believe it means
the state is enabled (just like SRV_RUNNING). Let's rename these two
flags CHK_ST_INPROGRESS and CHK_ST_DISABLED.

11 years agoMINOR: checks: use an enum instead of flags to report a check result
Willy Tarreau [Wed, 11 Dec 2013 16:09:34 +0000 (17:09 +0100)] 
MINOR: checks: use an enum instead of flags to report a check result

We used to have up to 4 sets of flags which were almost all exclusive
to report a check result. And the names were inherited from the old
server states, adding to the confusion. Let's replace that with an
enum handling only the possible combinations :

   SRV_CHK_UNKNOWN                   => CHK_RES_UNKNOWN
   SRV_CHK_FAILED                    => CHK_RES_FAILED
   SRV_CHK_PASSED                    => CHK_RES_PASSED
   SRV_CHK_PASSED | SRV_CHK_DISABLE  => CHK_RES_CONDPASS

11 years agoREORG: checks: retrieve the check-specific defines from server.h to checks.h
Willy Tarreau [Wed, 11 Dec 2013 15:45:07 +0000 (16:45 +0100)] 
REORG: checks: retrieve the check-specific defines from server.h to checks.h

After the move of checks from servers to autonomous checks, we need a
massive cleanup and reordering as it's becoming increasingly difficult
to find the definitions of types and enums.

Nothing was changed, blocks were just moved.

11 years agoMINOR: checks: improve handling of the servers tracking chain
Willy Tarreau [Wed, 11 Dec 2013 14:27:05 +0000 (15:27 +0100)] 
MINOR: checks: improve handling of the servers tracking chain

Server tracking uses the same "tracknext" list for servers tracking
another one and for the servers being tracked. This caused an issue
which was fixed by commit f39c71c ([CRITICAL] fix server state tracking:
it was O(n!) instead of O(n)), consisting in ensuring that a server is
being checked before walking down the list, so that we don't propagate
the up/down information via servers being part of the track chain.

But the root cause is the fact that all servers share the same list.
The correct solution consists in having a list head for the tracked
servers and a list of next tracking servers. This simplifies the
propagation logic, especially for the case where status changes might
be passed to individual servers via the CLI.

11 years agoMINOR: chunks: always initialize the output chunk in get_trash_chunk()
Willy Tarreau [Wed, 11 Dec 2013 16:32:08 +0000 (17:32 +0100)] 
MINOR: chunks: always initialize the output chunk in get_trash_chunk()

The get_trash_chunk() function is convenient and is sometimes used even
to get a temporary string. While the chunk is initialized, the string
may contain some random garbage that some code might retrieve if it uses
chunk->str directly without checking ->len. This is what happened in checks
after commit 25e2ab5 (MEDIUM: checks: centralize error reporting). It's not
easy to guess it at first so better pre-initialize the string with a zero.

11 years agoBUILD: definitely silence some stupid GCC warnings
Willy Tarreau [Fri, 13 Dec 2013 14:14:55 +0000 (15:14 +0100)] 
BUILD: definitely silence some stupid GCC warnings

It's becoming increasingly difficult to ignore unwanted function returns in
debug code with gcc. Now even when you try to work around it, it suggests a
way to write your code differently. For example :

    src/frontend.c:187:65: warning: if statement has empty body [-Wempty-body]
                if (write(1, trash.str, trash.len) < 0) /* shut gcc warning */;
                                                                              ^
    src/frontend.c:187:65: note: put the semicolon on a separate line to silence this warning
    1 warning generated.

This is totally unacceptable, this code already had to be written this way
to shut it up in earlier versions. And now it comments the form ? What's the
purpose of the C language if you can't write anymore the code that does what
you want ?

Emeric proposed to just keep a global variable to drain such useless results
so that gcc stops complaining all the time it believes people who write code
are monkeys. The solution is acceptable because the useless assignment is done
only in debug code so it will not impact performance. This patch implements
this, until gcc becomes even "smarter" to detect that we tried to cheat.

11 years agoMINOR: chunks: allocate the trash chunks before parsing the config
Willy Tarreau [Fri, 13 Dec 2013 13:41:10 +0000 (14:41 +0100)] 
MINOR: chunks: allocate the trash chunks before parsing the config

get_trash_chunk() is convenient also while parsing the config, better
allocate them early just like the global trash.

11 years agoBUILD: time: adapt the type of TV_ETERNITY to the local system
Willy Tarreau [Fri, 13 Dec 2013 08:22:23 +0000 (09:22 +0100)] 
BUILD: time: adapt the type of TV_ETERNITY to the local system

Some systems use different types for tv_sec/tv_usec, some are
signed others not. From time to time new warnings are reported
about implicit casts being done.

This patch ensures that TV_ETERNITY is cast to the appropriate
type in assignments and conversions.

11 years agoTESTS: add regression tests for ACL and sample expression parsers
Willy Tarreau [Fri, 13 Dec 2013 00:32:09 +0000 (01:32 +0100)] 
TESTS: add regression tests for ACL and sample expression parsers

These ones trigger each of the error messages in the code about
argument and converters syntax.

11 years agoCLEANUP: acl: remove useless blind copy-paste from sample converters
Willy Tarreau [Fri, 13 Dec 2013 00:30:22 +0000 (01:30 +0100)] 
CLEANUP: acl: remove useless blind copy-paste from sample converters

The second error pointer is not needed, we use memprintf() to report
errors, it's a leftover from a blind copy-paste of the original code.

11 years agoMEDIUM: acl: fix the initialization order of the ACL expression
Willy Tarreau [Fri, 13 Dec 2013 00:24:09 +0000 (01:24 +0100)] 
MEDIUM: acl: fix the initialization order of the ACL expression

The ACL expression parser recently became a huge mess like a
spaghetti plate. The keyword is looked up at the beginning, then
sample fetches are processed, then an expression is initialized,
then arguments and converters are parsed but only if the keyword
was an ACL one, etc... Lots of "if" and redundant variables
everywhere making it hard to read and follow.

Let's move the args/conv parsing just after the keyword lookup.
At least now it's consistent that when we leave this if/else
statement, we have a sample expression initialized and full
parsed wherever the elements came from.

11 years agoMEDIUM: acl: fix the argument parser to let the lower layer report detailed errors
Willy Tarreau [Fri, 13 Dec 2013 00:08:36 +0000 (01:08 +0100)] 
MEDIUM: acl: fix the argument parser to let the lower layer report detailed errors

Just like for the last commit, we need to fix the ACL argument parser so
that it lets the lower layer do the job of referencing unresolved arguments
and correctly report the type of missing arguments.

11 years agoBUG/MEDIUM: sample: simplify and fix the argument parsing
Willy Tarreau [Thu, 12 Dec 2013 23:40:11 +0000 (00:40 +0100)] 
BUG/MEDIUM: sample: simplify and fix the argument parsing

Some errors may be reported about missing mandatory arguments when some
sample fetch arguments are marked as mandatory and implicit (eg: proxy
names such as in table_cnt or be_conn).

In practice the argument parser already handles all the situations very
well, it's just that the sample fetch parser want to go beyond its role
and starts some controls that it should not do. Simply removing these
useless controls lets make_arg_list() create the correct argument types
when such types are encountered.

This regression was introduced by the recent use of sample_parse_expr()
in ACLs which makes use of its own argument parser, while previously
the arguments were parsed in the ACL function itself. No backport is
needed.

11 years agoMINOR: arg: improve wording on error reporting
Willy Tarreau [Thu, 12 Dec 2013 23:38:47 +0000 (00:38 +0100)] 
MINOR: arg: improve wording on error reporting

We make the distinction between missing too many arguments and no
arguments supported.

11 years agoMINOR: sample: make sample_parse_expr() use memprintf() to report parse errors
Willy Tarreau [Thu, 12 Dec 2013 22:16:54 +0000 (23:16 +0100)] 
MINOR: sample: make sample_parse_expr() use memprintf() to report parse errors

Doing so ensures that we're consistent between all the functions in the whole
chain. This is important so that we can extract the argument parsing from this
function.

11 years agoMEDIUM: map: dynamic manipulation of maps
Thierry FOURNIER [Wed, 11 Dec 2013 15:55:52 +0000 (16:55 +0100)] 
MEDIUM: map: dynamic manipulation of maps

This patch adds map manipulation commands to the socket interface.

add map <map> <key> <value>
  Add the value <value> in the map <map>, at the entry corresponding to
  the key <key>. This command does not verify if the entry already
  exists.

clear map <map>
  Remove entries from the map <map>

del map <map> <key>
  Delete all the map entries corresponding to the <key> value in the map
  <map>.

set map <map> <key> <value>
  Modify the value corresponding to each key <key> in a map <map>. The
  new value is <value>.

show map [<map>]
  Dump info about map converters. Without argument, the list of all
  available maps are returned. If a <map> is specified, is content is
  dumped.

11 years agoMEDIUM: dumpstat: make the CLI parser understand the backslash as an escape char
Thierry FOURNIER [Tue, 10 Dec 2013 17:54:58 +0000 (18:54 +0100)] 
MEDIUM: dumpstat: make the CLI parser understand the backslash as an escape char

We'll need to pass patterns on the CLI for lookups. Till now there was no
need for a backslash, so it's still time to support them just like in the
config file.

11 years agoMINOR: pattern/map: Each pattern must free the associated sample
Thierry FOURNIER [Tue, 10 Dec 2013 14:08:39 +0000 (15:08 +0100)] 
MINOR: pattern/map: Each pattern must free the associated sample

11 years agoMINOR: pattern: add function to lookup a specific entry in pattern list
Thierry FOURNIER [Tue, 10 Dec 2013 14:08:01 +0000 (15:08 +0100)] 
MINOR: pattern: add function to lookup a specific entry in pattern list

This is used to dynamically delete or update map entry.

11 years agoMINOR: map: export parse output sample functions
Thierry FOURNIER [Tue, 10 Dec 2013 14:05:34 +0000 (15:05 +0100)] 
MINOR: map: export parse output sample functions

This export is used to identify the parser used

11 years agoMINOR: pattern: make the pattern matching function return a pointer to the matched...
Thierry FOURNIER [Tue, 10 Dec 2013 14:03:38 +0000 (15:03 +0100)] 
MINOR: pattern: make the pattern matching function return a pointer to the matched element

This feature will be used by the CLI to look up keys.

11 years agoMINOR: pattern: add support for compiling patterns for lookups
Thierry FOURNIER [Fri, 6 Dec 2013 19:33:50 +0000 (20:33 +0100)] 
MINOR: pattern: add support for compiling patterns for lookups

With this patch, patterns can be compiled for two modes :
  - match
  - lookup

The match mode is used for example in ACLs or maps. The lookup mode
is used to lookup a key for pattern maintenance. For example, looking
up a network is different from looking up one address belonging to
this network.

A special case is made for regex. In lookup mode they return the input
regex string and do not compile the regex.

11 years agoMINOR: regex: Copy the original regex expression into string.
Thierry FOURNIER [Fri, 6 Dec 2013 19:38:46 +0000 (20:38 +0100)] 
MINOR: regex: Copy the original regex expression into string.

This is useful for the debug or for search regex in maps.

11 years agoMINOR: regex: Change the struct containing regex
Thierry FOURNIER [Fri, 6 Dec 2013 19:36:20 +0000 (20:36 +0100)] 
MINOR: regex: Change the struct containing regex

This change permits to remove the typedef. The original regex structs
are set in haproxy's struct.

11 years agoMINOR: standard: The function parse_binary() can use preallocated buffer
Thierry FOURNIER [Fri, 6 Dec 2013 18:59:28 +0000 (19:59 +0100)] 
MINOR: standard: The function parse_binary() can use preallocated buffer

Let the function support pre-allocated buffers if the argument is not null,
or allocate its own buffer if it is null.

11 years agoMEDIUM: pattern: Extract the index process from the pat_parse_*() functions
Thierry FOURNIER [Fri, 6 Dec 2013 18:06:43 +0000 (19:06 +0100)] 
MEDIUM: pattern: Extract the index process from the pat_parse_*() functions

Now, the pat_parse_*() functions parses the incoming data. The input
"pattern" struct can be preallocated. If the parser needs to add some
buffers, it allocates memory.

The function pattern_register() runs the call to the parser, process
the key indexation and associate the "sample_storage" used by maps.

11 years agoMINOR: pattern: do not assign SMP_TYPES by default to patterns
Willy Tarreau [Thu, 12 Dec 2013 10:34:55 +0000 (11:34 +0100)] 
MINOR: pattern: do not assign SMP_TYPES by default to patterns

This is never used since we exit on parse failure, and it's confusing.

11 years agoMINOR: tools: buf2ip6 must not modify output on failure
Willy Tarreau [Thu, 12 Dec 2013 10:29:39 +0000 (11:29 +0100)] 
MINOR: tools: buf2ip6 must not modify output on failure

Use a temporary output buffer to ensure we don't affect the output
on failure of inet_pton().

11 years agoMEDIUM: acl: Last patch change the output type
Thierry FOURNIER [Fri, 6 Dec 2013 14:36:54 +0000 (15:36 +0100)] 
MEDIUM: acl: Last patch change the output type

This patch remove the compatibility check from the input type and the
match method. Now, it checks if a casts from the input type to output
type exists and the pattern_exec_match() function apply casts before
each pattern matching.

11 years agoMINOR: pattern: Each pattern sets the expected input type
Thierry FOURNIER [Fri, 6 Dec 2013 15:56:40 +0000 (16:56 +0100)] 
MINOR: pattern: Each pattern sets the expected input type

This is used later for increasing the compability with incoming
sample types. When multiple compatible types are supported, one
is arbitrarily used (eg: UINT).

11 years agoMINOR: map: export map_get_reference() function
Thierry FOURNIER [Fri, 6 Dec 2013 09:39:48 +0000 (10:39 +0100)] 
MINOR: map: export map_get_reference() function

This function is used to identify map with his reference into the CLI
functions.

11 years agoBUG/MEDIUM: sample: conversion from str to ipv6 may read data past end
Thierry FOURNIER [Wed, 11 Dec 2013 11:38:57 +0000 (12:38 +0100)] 
BUG/MEDIUM: sample: conversion from str to ipv6 may read data past end

Applying inet_pton() to input contents is not reliable because the
function requires a zero-terminated string. While inet_pton() will
stop when contents do not match an IPv6 address anymore, it could
theorically read past the end of a buffer if the data to be converted
was at the end of a buffer (this cannot happen right now thanks to
the reserve at the end of the buffer). At least the conversion does
not work.

Fix this by using buf2ip6() instead, which copies the string into a
padded aread.

This bug came with recent commit b805f71 (MEDIUM: sample: let the
cast functions set their output type), no backport is needed.

11 years agoCLEANUP/MINOR: standard: use the system define INET6_ADDRSTRLEN in place of MAX_IP6_LEN
Thierry FOURNIER [Wed, 11 Dec 2013 11:33:54 +0000 (12:33 +0100)] 
CLEANUP/MINOR: standard: use the system define INET6_ADDRSTRLEN in place of MAX_IP6_LEN

11 years agoBUG/MEDIUM: map: Bad map file parser
Thierry FOURNIER [Wed, 11 Dec 2013 10:20:24 +0000 (11:20 +0100)] 
BUG/MEDIUM: map: Bad map file parser

There is a mix-up between input type of the data and input type of the
map file. This mix-up causes that all pattern matching function based
on "string"  (reg, beg, end, ...) don't run.

This bug came with commit d5f624d (MEDIUM: sample: add the "map" converter),
no backport is needed.

11 years agoBUG/MEDIUM: checks: agent doesn't get the response if server does not closes
Willy Tarreau [Wed, 11 Dec 2013 20:40:11 +0000 (21:40 +0100)] 
BUG/MEDIUM: checks: agent doesn't get the response if server does not closes

The agent refrains from reading the server's response until the server
closes, but if the server waits for the client to close, the response
is never read. Let's try to fetch a whole line before deciding to wait
more.

11 years agoBUG/MINOR: check_config_validity: check the returned value of stktable_init()
Godbach [Wed, 11 Dec 2013 13:11:41 +0000 (21:11 +0800)] 
BUG/MINOR: check_config_validity: check the returned value of stktable_init()

The function stktable_init() will return 0 if create_pool() returns NULL. Since
the returned value of this function is ignored, HAProxy will crash if the pool
of stick table is NULL and stksess_new() is called to allocate a new stick
session. It is a better choice to check the returned value and make HAProxy exit
with alert message if any error is caught.

Signed-off-by: Godbach <nylzhaowei@gmail.com>
11 years agoDOC: checkcache: block responses with cacheable cookies
Godbach [Wed, 11 Dec 2013 12:01:07 +0000 (20:01 +0800)] 
DOC: checkcache: block responses with cacheable cookies

"requests" -> "responses"

Signed-off-by: Godbach <nylzhaowei@gmail.com>
11 years agoCLEANUP: code style: use tabs to indent codes
Godbach [Wed, 11 Dec 2013 11:48:57 +0000 (19:48 +0800)] 
CLEANUP: code style: use tabs to indent codes

The original codes are indented by spaces and not aligned with the former line.
It should be a convention to indent by tabs in HAProxy.

Signed-off-by: Godbach <nylzhaowei@gmail.com>
11 years agoDOC: compression: chunk are not compressed anymore
William Lallemand [Tue, 10 Dec 2013 16:28:48 +0000 (17:28 +0100)] 
DOC: compression: chunk are not compressed anymore

Add the chunk issue to the list of non-working cases.

11 years agoCLEANUP: check: server port is unsigned
Willy Tarreau [Tue, 10 Dec 2013 22:32:30 +0000 (23:32 +0100)] 
CLEANUP: check: server port is unsigned

Baptiste Assmann reported some confusing printf() output of the server
port since it's declared signed. Better turn it to unsigned.

There's no need to backport this, it's only used in 16-bit places.

11 years agoBUG/MEDIUM: channel: bo_getline() must wait for \n until buffer is full
Willy Tarreau [Tue, 10 Dec 2013 17:58:23 +0000 (18:58 +0100)] 
BUG/MEDIUM: channel:  bo_getline() must wait for \n until buffer is full

We must not report incomplete data if the buffer is not full, otherwise
we can abort some processing on the stats socket when dealing with massive
amounts of commands.

11 years agoBUILD: use format tags in VERDATE and SUBVERS files
Willy Tarreau [Tue, 10 Dec 2013 10:19:04 +0000 (11:19 +0100)] 
BUILD: use format tags in VERDATE and SUBVERS files

The first line now contains a git format tag asking git-archive to
place the last commit's commit date and the last commit's abbreviated
ID respectively. The makefile will use these information in preference
when they're available and git is not available.

Now it's only necessary to add the two following lines in
.git/info/attributes to have the files automatically filled by git-archive :

SUBVERS export-subst
VERDATE export-subst

11 years agoBUILD: prepare the makefile to skip format lines in SUBVERS and VERDATE
Willy Tarreau [Tue, 10 Dec 2013 10:16:09 +0000 (11:16 +0100)] 
BUILD: prepare the makefile to skip format lines in SUBVERS and VERDATE

We're going to put format lines in these files for use by git archive,
so let's ensure that the current default format still works. For this
we'll use two lines and only take the first one without a format tag.

11 years agoBUILD: simplify the date and version retrieval in the makefile
Willy Tarreau [Tue, 10 Dec 2013 08:31:06 +0000 (09:31 +0100)] 
BUILD: simplify the date and version retrieval in the makefile

The makefile currently uses some complex and non-always portable
methods to retrieve the date and version (eg: linux's date command).

For the date, we can use git log -1 --pretty=format:%ci instead of
date+sed. For the version, it's easier and safer to count single log
lines.

Note that the VERSION variable was wrong since it could contain the
version+subversion instead of just the version. This is now fixed by
adding --abbrev=0 in describe.

11 years agoBUILD/MINOR: systemd: fix compiler warning about unused result
Lukas Tribus [Tue, 10 Dec 2013 07:32:56 +0000 (08:32 +0100)] 
BUILD/MINOR: systemd: fix compiler warning about unused result

There is a compiler warning after commit 1b6e75fa84 ("MEDIUM: haproxy-
systemd-wrapper: Use haproxy in same directory"):

src/haproxy-systemd-wrapper.c: In function â\80\98locate_haproxyâ\80\99:
src/haproxy-systemd-wrapper.c:28:10: warning: ignoring return value of â\80\98readlinkâ\80\99, declared with attribute warn_unused_result [-Wunused-result]

Fix the compiler warning by checking the return value of readlink().

11 years agoMINOR: session: report lack of resources using the new stream-interface's error code
Willy Tarreau [Mon, 9 Dec 2013 16:14:23 +0000 (17:14 +0100)] 
MINOR: session: report lack of resources using the new stream-interface's error code

Let's now use SI_ET_CONN_RES to report lack of resources instead of
SO_ET_CONN_OTHER with a handcrafted code.

11 years agoMINOR: stream_interface: add reporting of ressouce allocation errors
Willy Tarreau [Mon, 14 May 2012 10:11:47 +0000 (12:11 +0200)] 
MINOR: stream_interface: add reporting of ressouce allocation errors

SSL and keep-alive will need to be able to fail on allocation errors,
and the stream interface did not allow to report such a cause. The flag
will then be "RC" as already documented.

11 years agoDIET/MINOR: task: reduce struct task size by 8 bytes
Willy Tarreau [Sat, 7 Dec 2013 00:01:39 +0000 (01:01 +0100)] 
DIET/MINOR: task: reduce struct task size by 8 bytes

Just by reordering the struct task, we could shrink it by 8 bytes from
120 to 112 bytes. A careful reordering allowed each part to be located
closer to the hot parts it's used with, resulting in another performance
increase of about 0.5%.

11 years agoMINOR: http: use an enum for the auth method in http_auth_data
Willy Tarreau [Fri, 6 Dec 2013 23:18:34 +0000 (00:18 +0100)] 
MINOR: http: use an enum for the auth method in http_auth_data

This method now takes a single byte, with 7 bytes left to be used
after it. No savings were gained but at least now we have an enum.

11 years agoMINOR: http: switch the http state to an enum
Willy Tarreau [Fri, 6 Dec 2013 23:01:53 +0000 (00:01 +0100)] 
MINOR: http: switch the http state to an enum

This reduces its size which is not reused by anything else. However it
will significantly improve the debugger's output since we'll now get
real state values.

The default case had to be enabled in the parsers because gcc tries
to optimize the switch/case and noticed some values were missing from
the enums and emitted a warning.

11 years agoDIET/MINOR: http: reduce the size of struct http_txn by 8 bytes
Willy Tarreau [Fri, 6 Dec 2013 22:43:17 +0000 (23:43 +0100)] 
DIET/MINOR: http: reduce the size of struct http_txn by 8 bytes

Here again we had some oversized and misaligned entries. The method
and the status don't need 4 bytes each, and there was a hole after
the status that does not exist anymore. That's 8 additional bytes
saved from http_txn and as much for the session.

Also some fields were slightly moved to present better memory access
patterns resulting in a steady 0.5% performance increase.

11 years agoDIET/MINOR: stream-int: rearrange a few fields in struct stream_interface to save...
Willy Tarreau [Fri, 6 Dec 2013 22:31:58 +0000 (23:31 +0100)] 
DIET/MINOR: stream-int: rearrange a few fields in struct stream_interface to save 8 bytes

The current and previous states are now packed enums instead of ints. This will
also help in gdb. The flags have been turned to 16-bit instead of 32 since only
10 are used. This resulted in saving 8 bytes per streamm interface, or 16 per
session.

11 years agoDIET/MINOR: session: reduce the struct session size by 8 bytes
Willy Tarreau [Fri, 6 Dec 2013 21:01:11 +0000 (22:01 +0100)] 
DIET/MINOR: session: reduce the struct session size by 8 bytes

Move uniq_id upper to fill a hole and kill one. Another hole remains
after store_count.

11 years agoDIET/MINOR: proxy: rearrange a few fields in struct proxy to save 16 bytes
Willy Tarreau [Fri, 6 Dec 2013 20:29:13 +0000 (21:29 +0100)] 
DIET/MINOR: proxy: rearrange a few fields in struct proxy to save 16 bytes

Turn the proxy state to a packed enum (1 char), same for the proxy mode,
and store the capabitilies as a char. These 3 ints can now fill the hole
after obj_type and save 8 bytes in the proxy struct. Moving the maxconn
value just after, which is frequently accessed and was in a block of 3
ints saved another 8 bytes.

11 years agoDIET/MINOR: listener: rearrange a few fields in struct listener to save 16 bytes
Willy Tarreau [Fri, 6 Dec 2013 20:18:49 +0000 (21:18 +0100)] 
DIET/MINOR: listener: rearrange a few fields in struct listener to save 16 bytes

Pack the listener state to 1 char, store it as an enum instead of an
int (more gdb-friendly), and move a few fields around to fill holes.

The <nice> field can only be -1024..1024 so it was stored as a signed
short and completes well with obj_type and li_state.

Doing this has reduced the struct listener from 376 to 360 bytes (4.2%).

11 years agoDIET/MINOR: connection: rearrange a few fields to save 8 bytes in the struct
Willy Tarreau [Fri, 6 Dec 2013 20:09:57 +0000 (21:09 +0100)] 
DIET/MINOR: connection: rearrange a few fields to save 8 bytes in the struct

By moving the error code to 8 bits the send_proxy_ofs to 16 bits, and
moving them just after the obj_type, we can save 8 bytes in the struct
connection, down from 328 to 320.

11 years agoDIET/MINOR: obj: pack the obj_type enum to 8 bits
Willy Tarreau [Fri, 6 Dec 2013 20:08:11 +0000 (21:08 +0100)] 
DIET/MINOR: obj: pack the obj_type enum to 8 bits

Taking 32-bit in each struct just to store an obj_type is a waste
considering the very small amount of possible values. Let's force
it to be as small as possible (1 char) and we'll be able to move
some structs around to save some space.

11 years agoMINOR: stats: provide some appctx information in "show sess all"
Willy Tarreau [Sun, 1 Dec 2013 19:45:00 +0000 (20:45 +0100)] 
MINOR: stats: provide some appctx information in "show sess all"

When dumping a session, it can be useful to know what applet it is
connected to instead of having just the appctx pointer. We also
report st0/st1/st2 to help debugging.

11 years agoMEDIUM: peers: delay appctx initialization
Willy Tarreau [Sun, 1 Dec 2013 11:54:55 +0000 (12:54 +0100)] 
MEDIUM: peers: delay appctx initialization

Now that the session handler can automatically initialize the appctx,
let's not do it in peers_accept() anymore.

11 years agoCLEANUP: peers: use less confusing state/status code names
Willy Tarreau [Sun, 1 Dec 2013 11:47:35 +0000 (12:47 +0100)] 
CLEANUP: peers: use less confusing state/status code names

Currently, all states, all status codes and a few constants used in
the peers are all prefixed with "PEER_SESSION_". It's confusing because
there is no way to know which one is a state, a status code or anything
else. Thus, let's rename them this way :

    PEER_SESS_ST_* : states
    PEER_SESS_SC_* : status codes

Additionally the states have been numbered from zero and contigously.
This will allow us not to have to deal with the stream interface
initialization anymore and to ease debugging using enums.

11 years agoMEDIUM: stats: delay appctx initialization
Willy Tarreau [Sun, 1 Dec 2013 11:32:30 +0000 (12:32 +0100)] 
MEDIUM: stats: delay appctx initialization

Now that the session handler can automatically initialize the appctx,
let's not do it in stats_accept() anymore.

11 years agoMEDIUM: session: automatically register the applet designated by the target
Willy Tarreau [Sun, 1 Dec 2013 11:25:52 +0000 (12:25 +0100)] 
MEDIUM: session: automatically register the applet designated by the target

Some applet users don't need to initialize their applet, they just want
to route the traffic there just as if it were a server. Since applets
are now connected to from session.c, let's simply ensure that when
connecting, the applet in si->end matches the target, and allocate
one there if it's not already done. In case of error, we force the
status code to resource and connection so that it's clear that it
happens because of a memory shortage.

11 years agoMAJOR: stream-interface: dynamically allocate the applet context
Willy Tarreau [Sun, 1 Dec 2013 10:31:38 +0000 (11:31 +0100)] 
MAJOR: stream-interface: dynamically allocate the applet context

From now on, a call to stream_int_register_handler() causes a call
to si_alloc_appctx() and returns an initialized appctx for the
current stream interface. If one was previously allocated, it is
released. If the stream interface was attached to a connection, it
is released as well.

The appctx are allocated from the same pools as the connections, because
they're substantially smaller in size, and we can't have both a connection
and an appctx on an interface at any moment.

In case of memory shortage, the call may return NULL, which is already
handled by all consumers of stream_int_register_handler().

The field appctx was removed from the stream interface since we only
rely on the endpoint now. On 32-bit, the stream_interface size went down
from 108 to 44 bytes. On 64-bit, it went down from 144 to 64 bytes. This
represents a memory saving of 160 bytes per session.

It seems that a later improvement could be to move the call to
stream_int_register_handler() to session.c for most cases.

11 years agoMEDIUM: stream-int: return the allocated appctx in stream_int_register_handler()
Willy Tarreau [Sun, 1 Dec 2013 08:35:41 +0000 (09:35 +0100)] 
MEDIUM: stream-int: return the allocated appctx in stream_int_register_handler()

The task returned by stream_int_register_handler() is never used, however we
always need to access the appctx afterwards. So make it return the appctx
instead. We already plan for it to fail, which is the reason for the addition
of a few tests and the possibility for the HTTP analyser to return a status
code 500.

11 years agoMEDIUM: stream-int: replace occurrences of si->appctx with si_appctx()
Willy Tarreau [Sun, 1 Dec 2013 08:15:12 +0000 (09:15 +0100)] 
MEDIUM: stream-int: replace occurrences of si->appctx with si_appctx()

We're about to remove si->appctx, so first let's replace all occurrences
of its usage with a dynamic extract from si->end. A lot of code was changed
by search-n-replace, but the behaviour was intentionally not altered.

The code surrounding calls to stream_int_register_handler() was slightly
changed since we can only use si->end *after* the registration.

11 years agoMEDIUM: connection: merge the send_proxy and local_send_proxy calls
Willy Tarreau [Thu, 24 Oct 2013 20:01:26 +0000 (22:01 +0200)] 
MEDIUM: connection: merge the send_proxy and local_send_proxy calls

We used to have two very similar functions for sending a PROXY protocol
line header. The reason is that the default one relies on the stream
interface to retrieve the other end's address, while the "local" one
performs a local address lookup and sends that instead (used by health
checks).

Now that the send_proxy_ofs is stored in the connection and not the
stream interface, we can make the local_send_proxy rely on it and
support partial sends. This also simplifies the code by removing the
local_send_proxy function, making health checks use send_proxy_ofs,
resulting in the removal of the CO_FL_LOCAL_SPROXY flag, and the
associated test in the connection handler. The other flag,
CO_FL_SI_SEND_PROXY was renamed without the "SI" part so that it
is clear that it is not dedicated anymore to a usage with a stream
interface.

11 years agoMINOR: connection: check for send_proxy during the connect(), not the SI
Willy Tarreau [Thu, 24 Oct 2013 19:45:00 +0000 (21:45 +0200)] 
MINOR: connection: check for send_proxy during the connect(), not the SI

It's cleaner to check for a pending send_proxy_ofs while establishing
the connection (which already checks it anyway) and not in the stream
interface.

11 years agoMEDIUM: connection: move the send_proxy offset to the connection
Willy Tarreau [Thu, 24 Oct 2013 19:10:08 +0000 (21:10 +0200)] 
MEDIUM: connection: move the send_proxy offset to the connection

Till now the send_proxy_ofs field remained in the stream interface,
but since the dynamic allocation of the connection, it makes a lot
of sense to move that into the connection instead of the stream
interface, since it will not be statically allocated for each
session.

Also, it turns out that moving it to the connection fils an alignment
hole on 64 bit architectures so it does not consume more memory, and
removing it from the stream interface was an opportunity to correctly
reorder fields and reduce the stream interface's size from 160 to 144
bytes (-10%). This is 32 bytes saved per session.

11 years agoMAJOR: stream interface: dynamically allocate the outgoing connection
Willy Tarreau [Fri, 11 Oct 2013 17:34:20 +0000 (19:34 +0200)] 
MAJOR: stream interface: dynamically allocate the outgoing connection

The outgoing connection is now allocated dynamically upon the first attempt
to touch the connection's source or destination address. If this allocation
fails, we fail on SN_ERR_RESOURCE.

As we didn't use si->conn anymore, it was removed. The endpoints are released
upon session_free(), on the error path, and upon a new transaction. That way
we are able to carry the existing server's address across retries.

The stream interfaces are not initialized anymore before session_complete(),
so we could even think about allocating them dynamically as well, though
that would not provide much savings.

The session initialization now makes use of conn_new()/conn_free(). This
slightly simplifies the code and makes it more logical. The connection
initialization code is now shorter by about 120 bytes because it's done
at once, allowing the compiler to remove all redundant initializations.

The si_attach_applet() function now takes care of first detaching the
existing endpoint, and it is called from stream_int_register_handler(),
so we can safely remove the calls to si_release_endpoint() in the
application code around this call.

A call to si_detach() was made upon stream_int_unregister_handler() to
ensure we always free the allocated connection if one was allocated in
parallel to setting an applet (eg: detect HTTP proxy while proceeding
with stats maybe).

11 years agoMEDIUM: stream-interface: introduce si_attach_conn to replace si_prepare_conn
Willy Tarreau [Thu, 24 Oct 2013 13:50:53 +0000 (15:50 +0200)] 
MEDIUM: stream-interface: introduce si_attach_conn to replace si_prepare_conn

si_prepare_conn() is not appropriate in our case as it both initializes and
attaches the connection to the stream interface. Due to the asymmetry between
accept() and connect(), it causes some fields such as the control and transport
layers to be reinitialized.

Now that we can separately initialize these fields using conn_prepare(), let's
break this function to only attach the connection to the stream interface.

Also, by analogy, si_prepare_none() was renamed si_detach(), and
si_prepare_applet() was renamed si_attach_applet().

11 years agoMINOR: connection: replace conn_assign with conn_attach
Willy Tarreau [Thu, 24 Oct 2013 13:31:04 +0000 (15:31 +0200)] 
MINOR: connection: replace conn_assign with conn_attach

We don't want to assign the control nor transport layers anymore
at the same time as the data layer, because it prevents one from
keeping existing settings when reattaching a connection to an
existing stream interface.

Let's have conn_attach() replace conn_assign() for this purpose.

Thus, conn_prepare() + conn_attach() do exactly the same as the
previous conn_assign().

11 years agoMINOR: connection: reintroduce conn_prepare to set the protocol and transport
Willy Tarreau [Thu, 24 Oct 2013 13:08:37 +0000 (15:08 +0200)] 
MINOR: connection: reintroduce conn_prepare to set the protocol and transport

Now that we can assign conn->xprt regardless of the initialization state,
we can reintroduce conn_prepare() to set only the protocol, the transport
layer and initialize the transport layer's state.

11 years agoMINOR: stream-interface: introduce si_reset() and si_set_state()
Willy Tarreau [Thu, 24 Oct 2013 09:51:38 +0000 (11:51 +0200)] 
MINOR: stream-interface: introduce si_reset() and si_set_state()

The first function is used to (re)initialize a stream interface and
the second to force it into a known state. These are intended for
cleaning up the stream interface initialization code in session.c
and peers.c and avoiding future issues with missing initializations.