Commit Graph

5166 Commits

Author SHA1 Message Date
Willy Tarreau
8f1b35b383 DOC: update coding-style to reference checkpatch.pl
Running the Linux kernel's checkpatch.pl is actually quite efficient
at spotting style issues and even sometimes bugs. The doc now suggests
how to use it to avoid the warnings that are specific to Linux's stricter
rules.

It properly reports errors like the following ones that were found on
real submissions so it should improve the situation for everyone :

ERROR: "foo * bar" should be "foo *bar"
+static char * tcpcheck_get_step_comment(struct check *, int);

ERROR: do not use assignment in if condition
+                       if ((comment = tcpcheck_get_step_comment(check, step)))

WARNING: trailing semicolon indicates no statements, indent implies otherwise
+                       if (elem->data && elem->free);
+                               elem->free(elem->data);

ERROR: do not initialise statics to 0 or NULL
+static struct lru64_head *ssl_ctx_lru_tree = NULL;

ERROR: space required after that ',' (ctx:VxV)
+           !X509_gmtime_adj(X509_get_notAfter(newcrt),(long)60*60*24*365))
                                                      ^
WARNING: space prohibited between function name and open parenthesis '('
+       else if (EVP_PKEY_type (capkey->type) == EVP_PKEY_RSA)

ERROR: trailing statements should be on next line
+       if (cacert) X509_free(cacert);

ERROR: space prohibited after that open parenthesis '('
+                                       !(         (srv_op_state == SRV_ST_STOPPED)
2015-09-21 16:45:45 +02:00
Willy Tarreau
37bb7be09c BUG/MAJOR: peers: fix a crash when stopping peers on unbound processes
Pradeep Jindal reported and troubleshooted a bug causing haproxy to die
during startup on all processes not making use of a peers section. It
only happens with nbproc > 1 when peers are declared. Technically it's
when the peers task is stopped on processes that don't use it that the
crash occurred (a task_free() called on a NULL task pointer).

This only affects peers v2 in the dev branch, no backport is needed.
2015-09-21 15:24:58 +02:00
Willy Tarreau
14a923cd2e DOC: add a MAINTAINERS file
This one indicates who to CC when sending changes affecting certain
parts of the product.
2015-09-21 15:24:34 +02:00
James Rosewell
63426cb6a6 MINOR: 51d: Improved string handling for LRU cache
Removed use of strlen with the data added to and retrived from the cache
by using chunk structures instead of string pointers.
2015-09-21 12:55:24 +02:00
James Rosewell
a28bbd53c4 MAJOR: 51d: Upgraded to support 51Degrees V3.2 and new features
Trie device detection doesn't benefit from caching compared to Pattern.
As such the LRU cache has been removed from the Trie method.

A new fetch  method has been added named 51d.all which uses all the
available HTTP headers for device device detection. The previous 51d
conv method has been changed to 51d.single where one HTTP header,
typically User-Agent, is used for detection. This method is marginally
faster but less accurate.

Three new properties are available with the Pattern method called
Method, Difference and Rank which provide insight into the validity of
the results returned.

A pool of worksets is used to avoid needing to create a new workset for
every request. The workset pool is thread safe ready to support a future
multi threaded version of HAProxy.
2015-09-21 12:44:59 +02:00
James Rosewell
3670eb1d74 BUILD: Changed 51Degrees option to support V3.2
Added support for city hash method, turned off multi threading support
and included maths library. Removed reference to compression library
which was never needed.
2015-09-21 12:14:11 +02:00
James Rosewell
a0c4c69b67 DOC: Added more explanation for 51Degrees V3.2
Changed examples to demonstrate the the new fetch and conv methods
available with the enhancements made in version 3.2 of 51Degrees.

Added reference to the accuracy indicators available with Pattern
detection method.
2015-09-21 12:13:50 +02:00
James Rosewell
10790964b0 MINOR: global: Added new fields for 51Degrees device detection
Added support for version 3.2 of 51Degrees C library.

Added fields to store HTTP header names important to device detection
other than User-Agent.

Included a pool of worksets for use with Pattern device detection.
2015-09-21 12:10:41 +02:00
James Rosewell
91a41cb32d MINOR: http: made CHECK_HTTP_MESSAGE_FIRST accessible to other functions
Added the definition of CHECK_HTTP_MESSAGE_FIRST and the declaration of
smp_prefetch_http to the header.

Changed smp_prefetch_http implementation to remove the static qualifier.
2015-09-21 12:05:26 +02:00
Willy Tarreau
11e334d972 DOC: add a CONTRIBUTING file
This file tries to explain in the most detailed way how to contribute
patches. A few parts of it were moved from the README. .gitignore was
updated.
2015-09-20 22:43:56 +02:00
Willy Tarreau
2f5cd60ed0 DOC: add the documentation about internal circular lists
This file was recovered from the first project where it was born 12 years
ago, but it's still convenient to understand how our circular lists work,
so let's add it.
2015-09-20 22:43:56 +02:00
Baptiste Assmann
71503d32a7 DOC: servers state seamless reload example
A short doc + example to help people start using seamless reload for
server state
2015-09-19 17:05:29 +02:00
Baptiste Assmann
9b6857e9b5 MINOR: cli: new stats socket command: show backend
new stats socket command which displays only the list of backends
available in the current process.
For now only the backend name is displayed.
2015-09-19 17:05:29 +02:00
Baptiste Assmann
6076d1c02d MINOR: server: startup slowstart task when using seamless reload of HAProxy
This patch uses the start up of the health check task to also start
the warmup task when required.

This is executed only once: when HAProxy has just started up and can
be started only if the load-server-state-from-file feature is enabled
and the server was in the warmup state before a reload occurs.
2015-09-19 17:05:28 +02:00
Baptiste Assmann
fecd2b53af MINOR: init: server state loaded from file
With this patch, HAProxy reads the content of server state file and
update state of servers accordingly.
2015-09-19 17:05:28 +02:00
Baptiste Assmann
01c6cc3670 DOC: load-server-state-from-file 2015-09-19 17:05:28 +02:00
Baptiste Assmann
e11cfcd2c9 MINOR: config: new backend directives: load-server-state-from-file and server-state-file-name
This directive gives HAProxy the ability to use the either the global
server-state-file directive or a local one using server-state-file-name to
load server states.
The state can be saved right before the reload by the init script, using
the "show servers state" command on the stats socket redirecting output into
a file.
2015-09-19 17:05:28 +02:00
Baptiste Assmann
ef1f0fc033 DOC: new global directive: server-state-file
Documentation related to a new global directive.
Purpose of this directive is to store a file path into the global
structure of HAProxy. The file pointed by the path may be used by
HAProxy to retrieve server state from the previous running process
after a reload occured.
2015-09-19 17:05:27 +02:00
Baptiste Assmann
e0882263e0 MINOR: config: new global section directive: server-state-file
This new global section directive is used to store the path to the file
where HAProxy will be able to retrieve server states across reloads.

The file pointed by this path is used to store a file which can contains
state of all servers from all backends.
2015-09-19 17:05:27 +02:00
Baptiste Assmann
5626f489ec DOC: global directive server-state-base
Documentation relative to the new global directive server-state-file.
2015-09-19 17:05:27 +02:00
Baptiste Assmann
6bc89366bb MINOR: config: new global directive server-state-base
This new global directive can be used to provide a base directory where
all the server state files could be loaded.
If a server state file name starts with a slash '/', then this directive
must not be applied.
2015-09-19 17:05:26 +02:00
Baptiste Assmann
6f9225ab55 DOC: stats socket command: show servers state
Documentation related to the new command available over the stats socket
"show servers state".

A description of the fields is also included.
2015-09-19 17:05:26 +02:00
Baptiste Assmann
2828946cb5 MINOR: cli: new stats socket command: show servers state
new command 'show servers state' which dumps all variable parameters
of a server during an HAProxy process life.
Purpose is to dump current server state at current run time in order to
read them right after the reload.

The format of the output is versionned and we support version 1 for now.
2015-09-19 16:52:46 +02:00
Baptiste Assmann
41472f4d98 MINOR: server: Macro definition for server-state
Introduces a few new macros used by server state save and application accros reloads:
- currently used state server file format version
- currently used state server file header fields
- MIN and MAX value for version number
- maximum number of fields that could be found in a server-state file
- an arbitrary state-file max line length
2015-09-19 11:34:41 +02:00
Baptiste Assmann
54a4730c65 BUG/MAJOR: can't enable a server through the stat socket
When a server is disabled in the configuration using the "disabled"
keyword, a single flag is positionned: SRV_ADMF_CMAINT (use to be
SRV_ADMF_FMAINT)..
That said, when providing the first version of this code, we also
changed the SRV_ADMF_MAINT mask to match any of the possible MAINT
cases: SRV_ADMF_FMAINT, SRV_ADMF_IMAINT, SRV_ADMF_CMAINT

Since SRV_ADMF_CMAINT is never (and is not supposed to be) altered at
run time, once a server has this flag set up, it can never ever be
enabled again using the stats socket.

In order to fix this, we should:
- consider SRV_ADMF_CMAINT as a simple flag to report the state in the
  old configuration file (will be used after a reload to deduce the
  state of the server in a new running process)
- enabling both SRV_ADMF_CMAINT and SRV_ADMF_FMAINT when the keyword
  "disabled" is in use in the configuration
- update the mask SRV_ADMF_MAINT as it was before, to only match
  SRV_ADMF_FMAINT and SRV_ADMF_IMAINT.

The following patch perform the changes above.
It allows fixing the regression without breaking the way the up coming
feature (seamless server state accross reloads) is going to work.

Note: this is 1.6-only, no backport needed.
2015-09-18 12:38:23 +02:00
Pieter Baauw
caa6a1bb46 MINOR: support cpu-map feature through the compile option USE_CPU_AFFINITY on FreeBSD 2015-09-17 22:11:09 +02:00
Pieter Baauw
44fc9dfa6d DOC: add references to rise/fall for the fastinter explanation 2015-09-17 22:11:04 +02:00
Thierry FOURNIER
ccf0063896 BUG/MINOR: lua: breaks the log message if his size exceed one buffer
Previously, the log was ignored if the log message exceed one buffer.
This patch doens't ignore the log, but trancate the message.
2015-09-17 17:51:51 +02:00
Thierry FOURNIER
babae28c87 BUG/MAJOR: lua: potential unexpected aborts()
This couple of function executes securely some Lua calls outside of
the lua runtime environment. Each Lua call can return a longjmp
if it encounter a memory error.

Lua documentation extract:

   If an error happens outside any protected environment, Lua calls
   a panic function (see lua_atpanic) and then calls abort, thus
   exiting the host application. Your panic function can avoid this
   exit by never returning (e.g., doing a long jump to your own
   recovery point outside Lua).

   The panic function runs as if it were a message handler (see
   2.3); in particular, the error message is at the top of the
   stack. However, there is no guarantee about stack space. To push
   anything on the stack, the panic function must first check the
   available space (see 4.2).

We must check all the Lua entry point. This includes:
 - The include/proto/hlua.h exported functions
 - the task wrapper function
 - The action wrapper function
 - The converters wrapper function
 - The sample-fetch wrapper functions

It is tolerated that the initilisation function returns an abort.
Before each Lua abort, an error message is writed on stderr.

The macro SET_SAFE_LJMP initialise the longjmp. The Macro
RESET_SAFE_LJMP reset the longjmp. These function must be macro
because they must be exists in the program stack when the longjmp
is called
2015-09-17 17:51:29 +02:00
Willy Tarreau
a02e8a6cdf [RELEASE] Released version 1.6-dev5
Released version 1.6-dev5 with the following main changes :
    - MINOR: dns: dns_resolution structure update: time_t to unsigned int
    - BUG/MEDIUM: dns: DNS resolution doesn't start
    - BUG/MAJOR: dns: dns client resolution infinite loop
    - MINOR: dns: coding style update
    - MINOR: dns: new bitmasks to use against DNS flags
    - MINOR: dns: dns_nameserver structure update: new counter for truncated response
    - MINOR: dns: New DNS response analysis code: DNS_RESP_TRUNCATED
    - MEDIUM: dns: handling of truncated response
    - MINOR: DNS client query type failover management
    - MINOR: dns: no expected DNS record type found
    - MINOR: dns: new flag to report that no IP can be found in a DNS response packet
    - BUG/MINOR: DNS request retry counter used for retry only
    - DOC: DNS documentation updated
    - MEDIUM: actions: remove ACTION_STOP
    - BUG/MEDIUM: lua: outgoing connection was broken since 1.6-dev2 (bis)
    - BUG/MINOR: lua: last log character truncated.
    - CLEANUP: typo: bad indent
    - CLEANUP: actions: missplaced includes
    - MINOR: build: missing header
    - CLEANUP: lua: Merge log functions
    - BUG/MAJOR: http: don't manipulate the server connection if it's killed
    - BUG/MINOR: http: remove stupid HTTP_METH_NONE entry
    - BUG/MAJOR: http: don't call http_send_name_header() after an error
    - MEDIUM: tools: make str2sa_range() optionally return the FQDN
    - BUG/MINOR: tools: make str2sa_range() report unresolvable addresses
    - BUG/MEDIUM: dns: use the correct server hostname when resolving
2015-09-14 12:23:10 +02:00
Thierry FOURNIER
23bc375c59 CLEANUP: lua: Merge log functions
All the code which emits error log have the same pattern. Its:
Send log with syslog system, and if it is allowed, display error
log on screen.

This patch replace this pattern by a macro. This reduces the number
of lines.
2015-09-11 20:58:04 +02:00
Thierry FOURNIER
007ff4ce0f MINOR: build: missing header
Regex header file is missing in types/action.h

Repported by Conrad Hoffmann

I cannot build the current dev's master HEAD (ec3c37d) because of this error:

> In file included from include/proto/proto_http.h:26:0,
>                  from src/stick_table.c:26:
> include/types/action.h:102:20: error: field ‘re’ has incomplete type
>     struct my_regex re;    /* used by replace-header and replace-value */
>                     ^
> Makefile:771: recipe for target 'src/stick_table.o' failed
> make: *** [src/stick_table.o] Error 1

The struct act_rule defined in action.h includes a full struct my_regex
without #include-ing regex.h. Both gcc 5.2.0 and clang 3.6.2 do not allow this.
2015-09-11 17:34:56 +02:00
Thierry FOURNIER
ec3c37db3b CLEANUP: actions: missplaced includes
The include of action.h are misplaced.
2015-09-10 21:17:04 +02:00
Thierry FOURNIER
5bc2cbf8f4 CLEANUP: typo: bad indent
A space alignment remains in the stream_interface.c file
2015-09-10 21:16:55 +02:00
Baptiste Assmann
62b75b44e6 DOC: DNS documentation updated
More information regarding DNS resolution:
- behavior in case of errors
- behavior when multiple name servers are configured in a resolvers
  section
- when a retry is performed
- when a query type change is performed
- make it clear that DNS resolution requires health checking enabled
  on the server
2015-09-10 15:50:50 +02:00
Baptiste Assmann
f778bb46d6 BUG/MINOR: DNS request retry counter used for retry only
There are two types of retries when performing a DNS resolution:
1. retry because of a timeout
2. retry of the full sequence of requests (query types failover)

Before this patch, the 'resolution->try' counter was incremented
after each send of a DNS request, which does not cover the 2 cases
above.
This patch fix this behavior.
2015-09-10 15:46:03 +02:00
Baptiste Assmann
0453a1dd45 MINOR: dns: new flag to report that no IP can be found in a DNS response packet
Some DNS response may be valid from a protocol point of view but may not
contain any IP addresses.
This patch gives a new flag to the function dns_get_ip_from_response to
report such case.
It's up to the upper layer to decide what to do with this information.
2015-09-10 15:42:55 +02:00
Baptiste Assmann
96972bcd36 MINOR: dns: no expected DNS record type found
Some DNS responses may be valid from a protocol point of view, but may
not contain any information considered as interested by the requester..
Purpose of the flag DNS_RESP_NO_EXPECTED_RECORD introduced by this patch is
to allow reporting such situation.

When this happens, a new DNS query is sent with a new query type.

For now, the function only expect A and AAAA query types which is enough
to cover current cases.
In a next future, it will be up to the caller to tell the function which
query types are expected.
2015-09-10 15:41:53 +02:00
Thierry FOURNIER
5554e2983d BUG/MINOR: lua: last log character truncated.
The send_log function needs a final \n.

This bug is repported by Michael Ezzell.

Minor bug: when writing to syslog from Lua scripts, the last character from
each log entry is truncated.

core.Alert("this is truncated");

Sep  7 15:07:56 localhost haproxy[7055]: this is truncate

This issue appears to be related to the fact that send_log() (in src/log.c)
is expecting a newline at the end of the message's format string:

/*
 * This function adds a header to the message and sends the syslog message
 * using a printf format string. It expects an LF-terminated message.
 */
void send_log(struct proxy *p, int level, const char *format, ...)

I believe the fix would be in in src/hlua.c at line 760
<http://git.haproxy.org/?p=haproxy.git;a=blob;f=src/hlua.c;h=1e4d47c31e66c16c837ff2aa5ef577f6cafdc7e7;hb=316e3196285b89a917c7d84794ced59a6a5b4eba#l760>,
where this...

   send_log(px, level, "%s", trash.str);

...should be adding a newline into the format string to accommodate what
the code expects.

    send_log(px, level, "%s\n", trash.str);

This change provides what seems to be the correct behavior:

Sep  7 15:08:30 localhost haproxy[7150]: this is truncated

All other uses of send_log() in hlua.c have a trailing dot "." in the
message that is masking the truncation issue because the output message
stops on a clean word boundary.  I suspect these would also benefit from
"\n" appended to their format strings as well, since this appears to be the
pattern seen throughout the rest of the code base.

Reported-by: Michael Ezzell <michael@ezzell.net>
2015-09-09 22:12:27 +02:00
Willy Tarreau
07101d5a16 BUG/MEDIUM: dns: use the correct server hostname when resolving
The server's host name picked for resolution was incorrect, it did not
skip the address family specifier, did not resolve environment variables,
and messed up with the optional trailing colon.

Instead, let's get the fqdn returned by str2sa_range() and use that
exclusively.
2015-09-08 16:16:35 +02:00
Willy Tarreau
9f69f46d1f BUG/MINOR: tools: make str2sa_range() report unresolvable addresses
If an environment variable is used in an address, and is not set, it's
silently considered as ":" or "0.0.0.0:0" which is not correct as it
can hide environment issues and lead to unexpected behaviours. Let's
report this case when it happens.

This fix should be backported to 1.5.
2015-09-08 16:01:25 +02:00
Willy Tarreau
72b8c1f0aa MEDIUM: tools: make str2sa_range() optionally return the FQDN
The function does a bunch of things among which resolving environment
variables, skipping address family specifiers and trimming port ranges.
It is the only one which sees the complete host name before trying to
resolve it. The DNS resolving code needs to know the original hostname,
so we modify this function to optionally provide it to the caller.

Note that the function itself doesn't know if the host part was a host
or an address, but str2ip() knows that and can be asked not to try to
resolve. So we first try to parse the address without resolving and
try again with resolving enabled. This way we know if the address is
explicit or needs some kind of resolution.
2015-09-08 15:50:19 +02:00
Baptiste Assmann
90447582d7 MINOR: DNS client query type failover management
In the first version of the DNS resolver, HAProxy sends an ANY query
type and in case of issue fails over to the type pointed by the
directive in 'resolve-prefer'.
This patch allows the following new failover management:
1. default query type is still ANY
2. if response is truncated or in error because ANY is not supported by
   the server, then a fail over to a new query type is performed. The
   new query type is the one pointed by the directive 'resolve-prefer'.
3. if no response or still some errors occurs, then a query type fail over
   is performed to the remaining IP address family.
2015-09-08 15:04:17 +02:00
Baptiste Assmann
3440f0da2a MEDIUM: dns: handling of truncated response
First dns client implementation simply ignored most of DNS response
flags.
This patch changes the way the flags are parsed, using bit masks and
also take care of truncated responses.
Such response are reported to the above layer which can handle it
properly.
2015-09-08 14:59:49 +02:00
Baptiste Assmann
0df5d9669a MINOR: dns: New DNS response analysis code: DNS_RESP_TRUNCATED
This patch introduces a new internal response state about the analysis
of a DNS response received by a server.
It is dedicated to report to above layer that the response is
'truncated'.
2015-09-08 14:58:07 +02:00
Baptiste Assmann
6cdea9359b MINOR: dns: dns_nameserver structure update: new counter for truncated response
This patch updates the dns_nameserver structure to integrate a counter
dedicated to 'truncated' response sent by servers.
Such response are important to track, since HAProxy is supposed to
replay its request.
2015-09-08 14:57:28 +02:00
Baptiste Assmann
042d0a1f8c MINOR: dns: new bitmasks to use against DNS flags
Current DNS client code implementation doesn't take care of response
flags setup by the server.
This patch introduces a couple of bitmasks one can use to retrieve the
truncated flag and the reply code available in the 2-bytes flag field.
2015-09-08 12:14:03 +02:00
Baptiste Assmann
01daef3162 MINOR: dns: coding style update
No affectation in a if condition.
2015-09-08 10:52:09 +02:00
Baptiste Assmann
11c4e4eefb BUG/MAJOR: dns: dns client resolution infinite loop
Under certain circonstance (a configuration with many servers relying on
DNS resolution and one of them triggering the replay of a request
because of a timeout or invalid response to an ANY query), HAProxy could
end up in an infinite loop over the currently supposed running DNS
queries.

This was caused because the FIFO list of running queries was improperly
updated in snr_resolution_error_cb. The head of the list was removed
instead of the resolution in error, when moving the resolution to the
end of the list.

In the mean time, a LIST_DEL statement is removed since useless. This
action is already performed by the dns_reset_resolution function.
2015-09-08 10:51:50 +02:00
Baptiste Assmann
f0d9370f6b BUG/MEDIUM: dns: DNS resolution doesn't start
Patch f046f11561 introduced a regression:
DNS resolution doesn't start anymore, while it was supposed to make it
start with first health check.

Current patch fix this issue by triggering a new DNS resolution if the
last_resolution time is not set.
2015-09-08 10:51:22 +02:00