Commit Graph

6079 Commits

Author SHA1 Message Date
Thierry FOURNIER / OZON.IO
8a4e4420fb MEDIUM: log-format: Use standard HAProxy log system to report errors
The function log format emit its own error message using Alert(). This
patch replaces this behavior and uses the standard HAProxy error system
(with memprintf).

The benefits are:
 - cleaning the log system

 - the logformat can ignore the caller (actually the caller must set
   a flag designing the caller function).

 - Make the usage of the logformat function easy for future components.
2016-11-25 07:32:58 +01:00
Thierry FOURNIER / OZON.IO
4ed1c9585d MINOR: http/conf: store the use_backend configuration file and line for logs
The error log of the directive use_backend doesn't provide the
file and line containing the declaration. This patch stores
theses informations.
2016-11-25 07:15:09 +01:00
Thierry FOURNIER / OZON.IO
5948b01149 BUG/MINOR: conf: calloc untested
A calloc is executed without check of its returns code.
2016-11-25 07:15:06 +01:00
Thierry FOURNIER / OZON.IO
8a1027aa45 MINOR: lua: Add tokenize function.
For tokenizing a string, standard Lua recommends to use regexes.
The followinf example splits words:

   for i in string.gmatch(example, "%S+") do
      print(i)
   end

This is a little bit overkill for simply split words. This patch
adds a tokenize function which quick and do not use regexes.
2016-11-24 21:35:34 +01:00
Thierry FOURNIER / OZON.IO
7f3aa8b62f MINOR: lua: add utility function for check boolean argument
Strangely, the Lua API doesn't provides a function like
luaL_checkboolean(). This little function add this one.
2016-11-24 21:35:10 +01:00
Willy Tarreau
e365815007 BUILD: vars: remove a build warning on vars.c
gcc 3.4.6 noticed a possibly unitialized variable in vars.c, and while it
cannot happen the way the function is used, it's surprizing that newer
versions did not report it.

This fix may be backported to 1.6.
2016-11-24 21:25:43 +01:00
Willy Tarreau
80ebacfc82 BUILD: ssl: make the SSL layer build again with openssl 0.9.8
Commit 1866d6d ("MEDIUM: ssl: Add support for OpenSSL 1.1.0")
introduced support for openssl 1.1.0 and temporarily broke 0.9.8.
In the end the port was not very hard given that the only cause of
build failures were functions supposedly absent from 0.9.8 that in
fact did exist.

Thus, adding a new #if to move these functions for versions older
than 0.9.8 was enough to fix the trouble. It received very light
testing, basically only an SSL bridge decrypting and re-encrypting
traffic, and checking that everything looks right. That said, the
functions specific to 0.9.8 here compared to 1.0.x are only
SSL_SESSION_set1_id_context(), EVP_PKEY_base_id(), and
X509_PUBKEY_get0_param().
2016-11-24 20:18:21 +01:00
Thierry FOURNIER / OZON.IO
59fd511555 MEDIUM: log-format/conf: take into account the parse_logformat_string() return code
This patch takes into account the return code of the parse_logformat_string()
function. Now the configuration parser will fail if the log_format is not
strict.
2016-11-24 18:54:26 +01:00
Thierry FOURNIER / OZON.IO
a2c38d7904 MEDIUM: log-format: strict parsing and enable fail
Until now, the function parse_logformat_string() never fails. It
send warnings when it parses bad format, and returns expression in
best effort.

This patch replaces warnings by alert and returns a fail code.

Maybe the warning mode is designed for a compatibility with old
configuration versions. If it is the case, now this compatibility
is broken.

[wt: no, the reason is that an alert must cause a startup failure,
 but this will be OK with next patch]
2016-11-24 18:54:26 +01:00
Thierry FOURNIER / OZON.IO
6fe0e1b977 CLEANUP: log-format: remove unused arguments
The log-format function parse_logformat_string() takes file and line
for building parsing logs. These two parameters are embedded in the
struct proxy curproxy, which is the current parsing context.

This patch removes these two unused arguments.
2016-11-24 18:54:26 +01:00
Thierry FOURNIER / OZON.IO
bca46f0d9d CLEANUP: log-format: fix return code of function parse_logformat_var_args()
This patch replace the successful return code from 0 to 1. The
error code is replaced from 1 to 0.

The return code of this function is actually unused, so this
patch cannot modify the behaviour.
2016-11-24 18:54:26 +01:00
Thierry FOURNIER / OZON.IO
eca4d95317 CLEANUP: log-format: fix return code of the function parse_logformat_var()
This patch replaces the successful return code from 0 to 1. The
error code is replaced from -1 to 0.

The return code of this function is actually unused, so this
patch cannot modify the behaviour.
2016-11-24 18:54:25 +01:00
Thierry FOURNIER / OZON.IO
eb51e16306 CLEANUP/MINOR: log-format: unexport functions parse_logformat_var_args() and parse_logformat_var()
Remove export of the fucntion parse_logformat_var_args() and
parse_logformat_var(). These functions are a part of the
logformat parser, and this export is useless.
2016-11-24 18:54:25 +01:00
Thierry FOURNIER / OZON.IO
a69c912187 CLEANUP: log-format: useless file and line in json converter
The caller must log location information, so this information is
provided two times in the log line. The error log is like this:

   [ALERT] 327/011513 (14291) : parsing [o3.conf:38]: 'http-response
   set-header': Sample fetch <method,json(rrr)> failed with : invalid
   args in conv method 'json' : Unexpected input code type at file
   'o3.conf', line 38. Allowed value are 'ascii', 'utf8', 'utf8s',
   'utf8p' and 'utf8ps'.

This patch removes the second location indication, the the same error
becomes:

   [ALERT] 327/011637 (14367) : parsing [o3.conf:38]: 'http-response
   set-header': Sample fetch <method,json(rrr)> failed with : invalid
   args in conv method 'json' : Unexpected input code type. Allowed
   value are 'ascii', 'utf8', 'utf8s', 'utf8p' and 'utf8ps'.
2016-11-24 18:54:25 +01:00
Thierry FOURNIER / OZON.IO
9cbfef2455 BUG/MINOR: log-format: uncatched memory allocation functions
Some return code of memory allocation functions are not tested.
This patch fix theses checks.
2016-11-24 18:54:25 +01:00
Willy Tarreau
df4399fcb6 BUILD: server: remove a build warning introduced by latest series
We get this when Lua is disabled, just a missing include.

In file included from src/queue.c:18:0:
include/proto/server.h:51:39: warning: 'struct appctx' declared inside parameter list [enabled by default]
2016-11-24 17:32:01 +01:00
Willy Tarreau
30e5e18bbb CLEANUP: cli: remove assignments to st0 and st2 in keyword parsers
Now it's not needed anymore to set STAT_ST_INIT nor CLI_ST_CALLBACK
in the parsers, remove it in the various places.
2016-11-24 16:59:28 +01:00
Willy Tarreau
419085656b CLEANUP: cli: simplify the request parser a little bit
stats_sock_parse_request() was renamed cli_parse_request(). It now takes
an appctx instead of a stream interface, and presets ->st2 to 0 so that
most handlers will not have to set it anymore. The io_handler is set by
default to the keyword's IO handler so that the parser can simply change
it without having to rewrite the new state.
2016-11-24 16:59:28 +01:00
Willy Tarreau
3b6e547be8 CLEANUP: cli: rename STAT_CLI_* to CLI_ST_*
These are in CLI states, not stats states anymore. STAT_CLI_O_CUSTOM
was more appropriately renamed CLI_ST_CALLBACK.
2016-11-24 16:59:28 +01:00
Willy Tarreau
45c742be05 REORG: cli: move the "set rate-limit" functions to their own parser
All 4 rate-limit settings were handled at once given that exactly the
same checks are performed on them. In case of missing or incorrect
argument, the detailed supported options are printed with their use
case.

This was the last specific entry in the CLI parser, some additional
cleanup may still be done.
2016-11-24 16:59:28 +01:00
Willy Tarreau
58d9cb7d22 REORG: cli: move "{enable|disable} agent" to server.c
Also mention that "set server" is preferred now. Note that these
were the last enable/disable commands in cli.c. Also remove the
now unused expect_server_admin() function.
2016-11-24 16:59:28 +01:00
Willy Tarreau
2c04eda8b5 REORG: cli: move "{enable|disable} health" to server.c
Also mention that "set server" is preferred now.
2016-11-24 16:59:28 +01:00
Willy Tarreau
ffb4d58e1b REORG: cli: move "{enable|disable} server" to server.c
Also mention that "set server" is preferred now.
2016-11-24 16:59:28 +01:00
Willy Tarreau
15b9e68a78 REORG: cli: move "{enable|disable} frontend" to proxy.c
These are the last frontend-specific actions on the CLI. The function
expect_frontend_admin() which is not used anymore was removed.
2016-11-24 16:59:28 +01:00
Willy Tarreau
5212d7f24c REORG: cli: move "shutdown frontend" to proxy.c
Now we don't have any "shutdown" commands left in cli.c.
2016-11-24 16:59:28 +01:00
Willy Tarreau
61b6521cbf REORG: cli: move "shutdown session" to stream.c
It really kills streams in fact, but we can't change the name now.
2016-11-24 16:59:28 +01:00
Willy Tarreau
4e46b62ab1 REORG: cli: move "shutdown sessions server" to stream.c
It could be argued that it's between server, stream and session but
at least due to the fact that it operates on streams, its best place
is in stream.c.
2016-11-24 16:59:28 +01:00
Willy Tarreau
c429a1fc2d REORG: cli: move "set maxconn frontend" to proxy.c
And get rid of the last specific "set maxconn" case.
2016-11-24 16:59:28 +01:00
Willy Tarreau
b802627eb3 REORG: cli: move "set maxconn server" to server.c
It's used to manipulate the server's maxconn setting.
2016-11-24 16:59:28 +01:00
Willy Tarreau
2af9941bcd REORG: cli: move "set maxconn global" to its own handler
The code remained in the same file, it just simplifies the parser
and makes use of cli_has_level().
2016-11-24 16:59:28 +01:00
Willy Tarreau
89d467c105 REORG: cli: move "clear counters" to stats.c
This command is only used to clear stats. It now relies on cli_has_level()
to validate the permissions.
2016-11-24 16:59:28 +01:00
Willy Tarreau
599852eade REORG: cli: move "set timeout" to its own handler
The code remained in the same file, it just simplifies the parser.
2016-11-24 16:59:28 +01:00
Willy Tarreau
0a73929dc8 REORG: cli: make "show env" also use the generic keyword registration
This way we don't have any more state specific to a given yieldable
command. The other commands should be easier to move as they only
involve a parser.
2016-11-24 16:59:28 +01:00
Willy Tarreau
12207b360a REORG: cli: move "show errors" out of cli.c
It really belongs to proto_http.c since it's a dump for HTTP request
and response errors. Note that it's possible that some parts do not
need to be exported anymore since it really is the only place where
errors are manipulated.
2016-11-24 16:59:28 +01:00
Willy Tarreau
f13ebdf286 REORG: cli: move table dump/clear/set to stick_table.c
The table dump code was a horrible mess, with common parts interleaved
all the way to deal with the various actions (set/clear/show). A few
error messages were still incorrect, as the "set" operation did not
update them so they would still report "unknown action" (now fixed).

The action was now passed as a private argument to the CLI keyword
which itself is copied into the appctx private field. It's just an
int cast to a pointer.

Some minor issues were noticed while doing this, for example when dumping
an entry by key, if the key doesn't exist, nothing is printed, not even
the table's header. It's unclear whether this was intentional but it
doesn't really match what is done for data-based dumps. It was left
unchanged for now so that a later fix can be backported if needed.

Enum entries STAT_CLI_O_TAB, STAT_CLI_O_CLR and STAT_CLI_O_SET were
removed.
2016-11-24 16:59:28 +01:00
Willy Tarreau
97c2ae13bc REORG: cli: move dump_text(), dump_text_line(), and dump_binary() to standard.c
These are general purpose functions, move them away.
2016-11-24 16:59:27 +01:00
Willy Tarreau
0baac8cf1f REORG: cli: move "show info" to stats.c
Move the "show info" command to stats.c using the CLI keyword API
to register it on the CLI. The stats_dump_info_to_buffer() function
is now static again. Note, we don't need proto_ssl anymore in cli.c.
2016-11-24 16:59:27 +01:00
Willy Tarreau
2b812e29f6 REORG: cli: move "show stat" to stats.c
Move the "show stat" command to stats.c using the CLI keyword API
to register it on the CLI. The stats_dump_stat_to_buffer() function
is now static again.
2016-11-24 16:59:27 +01:00
William Lallemand
6b16094355 REORG: cli: move get/set weight to server.c
Move get/set weight CLI functions to server.c and use the cli keyword API
to register it on the CLI.
2016-11-24 16:59:27 +01:00
William Lallemand
933efcd01a REORG: cli: move 'show backend' to proxy.c
Move 'show backend' CLI functions to proxy.c and use the cli keyword API
to register it on the CLI.
2016-11-24 16:59:27 +01:00
William Lallemand
4c5b4d531c REORG: cli: move 'show sess' to stream.c
Move 'show sess' CLI functions to stream.c and use the cli keyword API
to register it on the CLI.

[wt: the choice of stream vs session makes sense because since 1.6 these
 really are streams that we're dumping and not sessions anymore]
2016-11-24 16:59:27 +01:00
William Lallemand
a6c5f3372d REORG: cli: move 'show servers' to proxy.c
Move 'show servers' CLI functions to proxy.c and use the cli keyword
API to register it on the CLI.
2016-11-24 16:59:27 +01:00
William Lallemand
e7ed8855de REORG: cli: move 'show pools' to memory.c
Move 'show pools' CLI functions to memory.c and use the cli keyword
API to register it on the CLI.
2016-11-24 16:59:27 +01:00
William Lallemand
222baf20da REORG: cli: move 'set server' to server.c
Move 'set server' CLI functions to server.c and use the cli keyword API
to register it on the CLI.
2016-11-24 16:59:27 +01:00
Willy Tarreau
960f2cb056 MINOR: proxy: create new function cli_find_frontend() to find a frontend
Several CLI commands require a frontend, so let's have a function to
look this one up and prepare the appropriate error message and the
appctx's state in case of failure.
2016-11-24 16:59:27 +01:00
Willy Tarreau
21b069dca8 MINOR: server: create new function cli_find_server() to find a server
Several CLI commands require a server, so let's have a function to
look this one up and prepare the appropriate error message and the
appctx's state in case of failure.
2016-11-24 16:59:27 +01:00
Willy Tarreau
de57a578ba MINOR: cli: create new function cli_has_level() to validate permissions
This function is used to check that the CLI features the appropriate
level of permissions or to prepare the adequate error message.
2016-11-24 16:59:27 +01:00
William Lallemand
69e9644e35 REORG: cli: move show stat resolvers to dns.c
Move dns CLI functions to dns.c and use the cli keyword API to register
actions on the CLI.
2016-11-24 16:59:27 +01:00
William Lallemand
ad8be61c7e REORG: cli: move map and acl code to map.c
Move map and acl CLI functions to map.c and use the cli keyword API to
register actions on the CLI. Then remove the now unused individual
"add" and "del" keywords.
2016-11-24 16:59:27 +01:00
William Lallemand
32af203b75 REORG: cli: move ssl CLI functions to ssl_sock.c
Move ssl CLI functions to ssl_sock.c and use the cli keyword API to
register ssl actions on the CLI.
2016-11-24 16:59:27 +01:00