]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
13 years agoMEDIUM: stream_interface: remove the si->init
Willy Tarreau [Fri, 18 May 2012 13:15:26 +0000 (15:15 +0200)] 
MEDIUM: stream_interface: remove the si->init

Calling the init() function in sess_establish was a bad idea, it is
too late to allow it to fail on lack of resource and does not help at
all. Remove it for now before it's used.

13 years agoBUG/MAJOR: trash must always be the size of a buffer
David du Colombier [Wed, 16 May 2012 12:16:48 +0000 (14:16 +0200)] 
BUG/MAJOR: trash must always be the size of a buffer

Before it was possible to resize the buffers using global.tune.bufsize,
the trash has always been the size of a buffer by design. Unfortunately,
the recent buffer sizing at runtime forgot to adjust the trash, resulting
in it being too short for content rewriting if buffers were enlarged from
the default value.

The bug was encountered in 1.4 so the fix must be backported there.

13 years agoDOC: fix minor regex example issue and improve doc on stats
Dmitry Sivachenko [Wed, 16 May 2012 10:00:26 +0000 (14:00 +0400)] 
DOC: fix minor regex example issue and improve doc on stats

URL rewriting should use [^\ :]* to avoid matching headers.

13 years ago[RELEASE] Released version 1.5-dev10 v1.5-dev10
Willy Tarreau [Mon, 14 May 2012 05:26:56 +0000 (07:26 +0200)] 
[RELEASE] Released version 1.5-dev10

Released version 1.5-dev10 with the following main changes :
    - BUG/MINOR: stats admin: "Unexpected result" was displayed unconditionally
    - BUG/MAJOR: acl: http_auth_group() must not accept any user from the userlist
    - CLEANUP: auth: make the code build again with DEBUG_AUTH
    - BUG/MEDIUM: config: don't crash at config load time on invalid userlist names
    - REORG: use the name sock_raw instead of stream_sock
    - MINOR: stream_interface: add a client target : TARG_TYPE_CLIENT
    - BUG/MEDIUM: stream_interface: restore get_src/get_dst
    - CLEANUP: sock_raw: remove last references to stream_sock
    - CLEANUP: stream_interface: stop exporting socket layer functions
    - MINOR: stream_interface: add an init callback to sock_ops
    - MEDIUM: stream_interface: derive the socket operations from the target
    - MAJOR: fd: remove the need for the socket layer to recheck the connection
    - MINOR: session: call the socket layer init function when a session establishes
    - MEDIUM: session: add support for tunnel timeouts
    - MINOR: standard: add a new debug macro : fddebug()
    - CLEANUP: fd: remove unused cb->b pointers in the struct fdtab
    - OPTIM: proto_http: don't enable quick-ack on empty buffers
    - OPTIM/MAJOR: ev_sepoll: process spec events after polled events
    - OPTIM/MEDIUM: stream_interface: add a new SI_FL_NOHALF flag

13 years agoOPTIM/MEDIUM: stream_interface: add a new SI_FL_NOHALF flag
Willy Tarreau [Sun, 13 May 2012 12:48:59 +0000 (14:48 +0200)] 
OPTIM/MEDIUM: stream_interface: add a new SI_FL_NOHALF flag

This flag indicates that we're not interested in keeping half-open
connections on a stream interface. It has the benefit of allowing
the socket layer to cause an immediate write close when detecting
an incoming read close. This releases resources much faster and
saves one syscall (either a shutdown or setsockopt).

This flag is only set by HTTP on the interface going to the server
since we don't want to continue pushing data there when it has
closed.

Another benefit is that it responds with a FIN to a server's FIN
instead of responding with an RST as it used to, which is much
cleaner.

Performance gains of 7.5% have been measured on HTTP connection
rate on empty objects.

13 years agoOPTIM/MAJOR: ev_sepoll: process spec events after polled events
Willy Tarreau [Sun, 13 May 2012 07:42:26 +0000 (09:42 +0200)] 
OPTIM/MAJOR: ev_sepoll: process spec events after polled events

A suboptimal behaviour was appearing quite often with sepoll. When a
speculative write failed after a connect(), the socket was added to
the poll list using epoll_ctl(ADD). Then when epoll_wait() returned a
write event, the send() was performed and write event disabled, causing
it to get back to the spec list in order to be disabled later. But if
some new accept() did succeed in the same run, then fd_created was not
null, causing a new run of the spec list to happen. This run would then
detect the old event in STOP state and would remove it from the poll
list using epoll_ctl(DEL).

After this, process_session() enables reading on the FD, attempting
an speculative recv() which fails then adds it again using epoll_ctl(ADD)
to do it again. So the total sequence of syscalls looked like this :

connect(fd) = EAGAIN
send(fd) = EAGAIN
epoll_ctl(ADD(fd:OUT))
epoll_wait() = fd:OUT
send(fd) > 0
epoll_ctl(DEL(fd))
recv(fd) = EAGAIN
epoll_ctl(ADD(fd:IN))
recv(fd) > 0

In order to fix this stupid situation, we must compute the epoll_ctl()
parameters at the last moment, just before doing epoll_wait(). This is
what was done except that the spec events were processed just before doing
that without leaving time for the tasks to adjust the FDs if needed. This
is also the reason we have the re_poll_once label to try to catch new
events in case of a successful accept().

The new solution consists in doing the opposite :

  - compute epoll_ctl()
  - call epoll_wait()
  - call spec events

This significantly reduces the number of iterations on the spec events
and avoids a huge number of epoll_ctl() ping/pongs. The new sequence
above simply becomes :

connect(fd) = EAGAIN
send(fd) = EAGAIN
epoll_ctl(ADD(fd:OUT))
epoll_wait() = fd:OUT
send(fd) > 0
epoll_ctl(MOD(fd:IN))
recv(fd) > 0

Also, there is no need to re-run the spec events after an accept() as
it will automatically be detected in the spec list after a return from
polled events.

The gains are important, with up to 4.5% global performance increase in
connection rate on HTTP with small objects. The code is less tricky and
does not need anymore to skip epoll_wait() every other call, nor to
track the number of FDs newly created.

13 years agoOPTIM: proto_http: don't enable quick-ack on empty buffers
Willy Tarreau [Sun, 13 May 2012 06:44:16 +0000 (08:44 +0200)] 
OPTIM: proto_http: don't enable quick-ack on empty buffers

Commit 5e205524 was a bit overzealous by inconditionally enabling
quick ack when a request is not yet in the buffer, because it also
does so when nothing has been received yet, causing a useless ACK
to be emitted.

Improve the situation by doing this only if the input buffer is
empty (indicating that nothing was sent by the client).

In case of keep-alive, an empty buffer means we already have a
response in flight which will serve as an ACK.

13 years agoCLEANUP: fd: remove unused cb->b pointers in the struct fdtab
Willy Tarreau [Sat, 12 May 2012 22:35:44 +0000 (00:35 +0200)] 
CLEANUP: fd: remove unused cb->b pointers in the struct fdtab

These pointers were used to hold pointers to buffers in the past, but
since we introduced the stream interface, they're no longer used but
they were still sometimes set.

Removing them shrink the struct fdtab from 32 to 24 bytes on 32-bit machines,
and from 52 to 36 bytes on 64-bit machines, which is a significant saving. A
quick tests shows a steady 0.5% performance gain, probably due to the better
cache efficiency.

13 years agoMINOR: standard: add a new debug macro : fddebug()
Willy Tarreau [Sat, 12 May 2012 22:21:17 +0000 (00:21 +0200)] 
MINOR: standard: add a new debug macro : fddebug()

This macro is usable like printf but sends messages to fd #-1, which has no
visible effect but is easy to spot in strace. This is very useful to put
tracers at many points during debugging sessions.

13 years agoMEDIUM: session: add support for tunnel timeouts
Willy Tarreau [Sat, 12 May 2012 10:50:00 +0000 (12:50 +0200)] 
MEDIUM: session: add support for tunnel timeouts

Tunnel timeouts are used when TCP connections are forwarded, or
when forwarding upgraded HTTP connections (WebSocket) as well as
CONNECT requests to proxies.

This timeout allows long-lived sessions to be supported without
having to set large timeouts to normal requests.

13 years agoMINOR: session: call the socket layer init function when a session establishes
Willy Tarreau [Sat, 12 May 2012 06:08:09 +0000 (08:08 +0200)] 
MINOR: session: call the socket layer init function when a session establishes

In sess_establish, once we've prepared everythin, we can call the socket layer
init function. We pass an argument for targets which have one (eg: servers). At
the moment, the existing socket layers don't have init functions, but SSL will
need one.

13 years agoMAJOR: fd: remove the need for the socket layer to recheck the connection
Willy Tarreau [Fri, 11 May 2012 17:53:32 +0000 (19:53 +0200)] 
MAJOR: fd: remove the need for the socket layer to recheck the connection

Up to now, if an outgoing connection had no data to send, the socket layer
had to perform a connect() again to check for establishment. This is not
acceptable for SSL, and will cause problems with socketpair(). Some socket
layers will also need an initializer before sending data (eg: SSL).

The solution consists in moving the connect() test to the protocol layer
(eg: TCP) and to make it hold the fd->write callback until the connection
is validated. At this point, it will switch the write callback to the
socket layer's write function. In fact we need to hold both read and write
callbacks to ensure the socket layer is never called before being initialized.

This intermediate callback is used only if there is a socket init function
or if there are no data to send.

The socket layer does not have any code to check for connection establishment
anymore, which makes sense.

13 years agoMEDIUM: stream_interface: derive the socket operations from the target
Willy Tarreau [Fri, 11 May 2012 16:32:18 +0000 (18:32 +0200)] 
MEDIUM: stream_interface: derive the socket operations from the target

Instead of hard-coding sock_raw in connect_server(), we set this socket
operation at config parsing time. Right now, only servers and peers have
it. Proxies are still hard-coded as sock_raw. This will be needed for
future work on SSL which requires a different socket layer.

13 years agoMINOR: stream_interface: add an init callback to sock_ops
Willy Tarreau [Fri, 11 May 2012 16:38:44 +0000 (18:38 +0200)] 
MINOR: stream_interface: add an init callback to sock_ops

This will be needed for some socket layers such as SSL. It's not used
at the moment.

13 years agoCLEANUP: stream_interface: stop exporting socket layer functions
Willy Tarreau [Fri, 11 May 2012 15:47:17 +0000 (17:47 +0200)] 
CLEANUP: stream_interface: stop exporting socket layer functions

Similarly to the previous patch, we don't need the socket-layer functions
outside of stream_interface. They could even move to a file dedicated to
applets, though that does not seem particularly useful at the moment.

13 years agoCLEANUP: sock_raw: remove last references to stream_sock
Willy Tarreau [Fri, 11 May 2012 14:59:14 +0000 (16:59 +0200)] 
CLEANUP: sock_raw: remove last references to stream_sock

We also stop exporting all functions since they're not needed anymore outside
of sock_raw.c.

13 years agoBUG/MEDIUM: stream_interface: restore get_src/get_dst
Willy Tarreau [Fri, 11 May 2012 14:16:40 +0000 (16:16 +0200)] 
BUG/MEDIUM: stream_interface: restore get_src/get_dst

Commit e164e7a removed get_src/get_dst setting in the stream interfaces but
forgot to set it in proto_tcp. Get the feature back because we need it for
logging, transparent mode, ACLs etc... We now rely on the stream interface
direction to know what syscall to use.

One benefit of doing it this way is that we don't use getsockopt() anymore
on outgoing stream interfaces nor on UNIX sockets.

13 years agoMINOR: stream_interface: add a client target : TARG_TYPE_CLIENT
Willy Tarreau [Fri, 11 May 2012 12:47:34 +0000 (14:47 +0200)] 
MINOR: stream_interface: add a client target : TARG_TYPE_CLIENT

This one will be used to identify the direction the SI is being used. All
incoming connections have a target of type TARG_TYPE_CLIENT.

13 years agoREORG: use the name sock_raw instead of stream_sock
Willy Tarreau [Fri, 11 May 2012 12:23:52 +0000 (14:23 +0200)] 
REORG: use the name sock_raw instead of stream_sock

We'll soon have an SSL socket layer, and in order to ease the difference
between the two, we use the name "sock_raw" to designate the one which
directly talks to the sockets without any conversion.

13 years agoBUG/MEDIUM: config: don't crash at config load time on invalid userlist names
Willy Tarreau [Thu, 10 May 2012 21:40:14 +0000 (23:40 +0200)] 
BUG/MEDIUM: config: don't crash at config load time on invalid userlist names

Cyril Bonté reported that passing an invalid userlist name to
http_auth_group() caused haproxy to crash at load. This was due
to an attempt to use the unresolved userlist pointer later to
resolve auth groups since we report many errors before leaving
now.

This issue does not exist in earlier versions since they immediately
abort on the first error, so no backport is needed.

13 years agoCLEANUP: auth: make the code build again with DEBUG_AUTH
Willy Tarreau [Thu, 10 May 2012 21:25:35 +0000 (23:25 +0200)] 
CLEANUP: auth: make the code build again with DEBUG_AUTH

Reported by Cyril Bonté, minor issue caused by recent ACL rework.

13 years agoBUG/MAJOR: acl: http_auth_group() must not accept any user from the userlist
Willy Tarreau [Thu, 10 May 2012 21:18:26 +0000 (23:18 +0200)] 
BUG/MAJOR: acl: http_auth_group() must not accept any user from the userlist

http_auth and http_auth_group used to share the same fetch function, while
they're doing very different things. The first one only checks whether the
supplied credentials are valid wrt a userlist while the second not only
checks this but also checks group ownership from a list of patterns.

Recent acl/pattern merge caused a simplification here by which the fetch
function would always return a boolean, so the group match was always fine
if the user:password was valid, regardless of the patterns provided with
the ACL.

The proper solution consists in splitting the function in two, depending
on what is desired.

It's also worth noting that check_user() would probably be split, one to
check user:password, and the other one to check for group ownership for
an already valid user:password combination. At this point it is not certain
if the group mask is still useful or not considering that the passwd check
is always made.

This bug was reported and diagnosed by Cyril Bonté. It first appeared
in 1.5-dev9 so it does not need any backporting.

13 years agoBUG/MINOR: stats admin: "Unexpected result" was displayed unconditionally
Cyril Bonté [Thu, 10 May 2012 17:42:52 +0000 (19:42 +0200)] 
BUG/MINOR: stats admin: "Unexpected result" was displayed unconditionally

I introduced a regression in commit 19979e176e while reworking the admin
actions results.
"Unexpected result" was displayed even if the action was applied due to a
misplaced initialization. This small patch should fix it.

Note: no need to backport.

13 years ago[RELEASE] Released version 1.5-dev9 v1.5-dev9
Willy Tarreau [Tue, 8 May 2012 19:56:27 +0000 (21:56 +0200)] 
[RELEASE] Released version 1.5-dev9

Released version 1.5-dev9 with the following main changes :
    - MINOR: Add release callback to si_applet
    - CLEANUP: Fix some minor typos
    - MINOR: Add TO/FROM_SET flags to struct stream_interface
    - CLEANUP: Fix some minor whitespace issues
    - MINOR: stats admin: allow unordered parameters in POST requests
    - CLEANUP: fix typo in findserver() log message
    - MINOR: stats admin: use the backend id instead of its name in the form
    - MINOR: stats admin: reduce memcmp()/strcmp() calls on status codes
    - DOC: cleanup indentation, alignment, columns and chapters
    - DOC: fix some keywords arguments documentation
    - MINOR: cli: display the 4 IP addresses and ports on "show sess XXX"
    - BUG/MAJOR: log: possible segfault with logformat
    - MEDIUM: log: split of log_format generation
    - MEDIUM: log: New format-log flags: %Fi %Fp %Si %Sp %Ts %rt %H %pid
    - MEDIUM: log: Unique ID
    - MINOR: log: log-format: usable without httplog and tcplog
    - BUG/MEDIUM: balance source did not properly hash IPv6 addresses
    - MINOR: contrib/iprange: add a network IP range to mask converter
    - MEDIUM: session: implement the "use-server" directive
    - MEDIUM: log: add a new cookie flag 'U' to report situations where cookie is not used
    - MEDIUM: http: make extract_cookie_value() iterate over cookie values
    - MEDIUM: http: add cookie and scookie ACLs
    - CLEANUP: lb_first: add reference to a paper describing the original idea
    - MEDIUM: stream_sock: add a get_src and get_dst callback and remove SN_FRT_ADDR_SET
    - BUG/MINOR: acl: req_ssl_sni would randomly fail if a session ID is present
    - BUILD: http: make extract_cookie_value() return an int not size_t
    - BUILD: http: stop gcc-4.1.2 from complaining about possibly uninitialized values
    - CLEANUP: http: message parser must ignore HTTP_MSG_ERROR
    - MINOR: standard: add a memprintf() function to build formatted error messages
    - CLEANUP: remove a few warning about unchecked return values in debug code
    - MEDIUM: move message-related flags from transaction to message
    - DOC: add a diagram to explain how circular buffers work
    - MAJOR: buffer rework: replace ->send_max with ->o
    - MAJOR: buffer: replace buf->l with buf->{o+i}
    - MINOR: buffers: provide simple pointer normalization functions
    - MINOR: buffers: remove unused function buffer_contig_data()
    - MAJOR: buffers: replace buf->w with buf->p - buf->o
    - MAJOR: buffers: replace buf->r with buf->p + buf->i
    - MAJOR: http: move buffer->lr to http_msg->next
    - MAJOR: http: change msg->{som,col,sov,eoh} to be relative to buffer origin
    - CLEANUP: http: remove unused http_msg->col
    - MAJOR: http: turn http_msg->eol to a buffer-relative offset
    - MEDIUM: http: add a pointer to the buffer in http_msg
    - MAJOR: http: make http_msg->sol relative to buffer's origin
    - MEDIUM: http: http_send_name_header: remove references to msg and buffer
    - MEDIUM: http: remove buffer arg in a few header manipulation functions
    - MEDIUM: http: remove buffer arg in http_capture_bad_message
    - MEDIUM: http: remove buffer arg in http_msg_analyzer
    - MEDIUM: http: remove buffer arg in http_upgrade_v09_to_v10
    - MEDIUM: http: remove buffer arg in http_buffer_heavy_realign
    - MEDIUM: http: remove buffer arg in chunk parsing functions
    - MINOR: http: remove useless wrapping checks in http_msg_analyzer
    - MEDIUM: buffers: fix unsafe use of buffer_ignore at some places
    - MEDIUM: buffers: add new pointer wrappers and get rid of almost all buffer_wrap_add calls
    - MEDIUM: buffers: implement b_adv() to advance a buffer's pointer
    - MEDIUM: buffers: rename a number of buffer management functions
    - MEDIUM: http: add a prefetch function for ACL pattern fetch
    - MEDIUM: http: make all ACL fetch function use acl_prefetch_http()
    - BUG/MINOR: http_auth: ACLs are volatile, not permanent
    - MEDIUM: http/acl: merge all request and response ACL fetches of headers and cookies
    - MEDIUM: http/acl: make acl_fetch_hdr_{ip,val} rely on acl_fetch_hdr()
    - MEDIUM: add a new typed argument list parsing framework
    - MAJOR: acl: make use of the new argument parsing framework
    - MAJOR: acl: store the ACL argument types in the ACL keyword declaration
    - MEDIUM: acl: acl_find_target() now resolves arguments based on their types
    - MAJOR: acl: make acl_find_targets also resolve proxy names at config time
    - MAJOR: acl: ensure that implicit table and proxies are valid
    - MEDIUM: acl: remove unused tests for missing args when args are mandatory
    - MEDIUM: pattern: replace type pattern_arg with type arg
    - MEDIUM: pattern: get rid of arg_i in all functions making use of arguments
    - MEDIUM: pattern: use the standard arg parser
    - MEDIUM: pattern: add an argument validation callback to pattern descriptors
    - MEDIUM: pattern: report the precise argument parsing error when known.
    - MEDIUM: acl: remove the ACL_TEST_F_NULL_MATCH flag
    - MINOR: pattern: add a new 'sample' type to store fetched data
    - MEDIUM: pattern: add new sample types to replace pattern types
    - MAJOR: acl: make use of the new sample struct and get rid of acl_test
    - MEDIUM: pattern/acl: get rid of temp_pattern in ACLs
    - MEDIUM: acl: get rid of the SET_RES flags
    - MEDIUM: get rid of SMP_F_READ_ONLY and SMP_F_MUST_FREE
    - MINOR: pattern: replace struct pattern with struct sample
    - MEDIUM: pattern: integrate pattern_data into sample and use sample everywhere
    - MEDIUM: pattern: retrieve the sample type in the sample, not in the keyword description
    - MEDIUM: acl/pattern: switch rdp_cookie functions stack up-down
    - MEDIUM: acl: replace acl_expr with args in acl fetch_* functions
    - MINOR: tcp: replace acl_fetch_rdp_cookie with smp_fetch_rdp_cookie
    - MEDIUM: acl/pattern: use the same direction scheme
    - MEDIUM: acl/pattern: start merging common sample fetch functions
    - MEDIUM: pattern: ensure that sample types always cast into other types.
    - MEDIUM: acl/pattern: factor out the src/dst address fetches
    - MEDIUM: acl: implement payload and payload_lv
    - CLEANUP: pattern: ensure that payload and payload_lv always stay in the buffer
    - MINOR: stick_table: centralize the handling of empty keys
    - MINOR: pattern: centralize handling of unstable data in pattern_process()
    - MEDIUM: pattern: use smp_fetch_rdp_cookie instead of the pattern specific version
    - MINOR: acl: set SMP_OPT_ITERATE on fetch functions
    - MINOR: acl: add a val_args field to keywords
    - MINOR: proto_tcp: validate arguments of payload and payload_lv ACLs
    - MEDIUM: http: merge acl and pattern header fetch functions
    - MEDIUM: http: merge ACL and pattern cookie fetches into a single one
    - MEDIUM: acl: report parsing errors to the caller
    - MINOR: arg: improve error reporting on invalid arguments
    - MINOR: acl: report errors encountered when loading patterns from files
    - MEDIUM: acl: extend the pattern parsers to report meaningful errors
    - REORG: use the name "sample" instead of "pattern" to designate extracted data
    - REORG: rename "pattern" files
    - MINOR: acl: add types to ACL patterns
    - MINOR: standard: add an IPv6 parsing function (str62net)
    - MEDIUM: acl: support IPv6 address matching
    - REORG: stream_interface: create a struct sock_ops to hold socket operations
    - REORG/MEDIUM: move protocol->{read,write} to sock_ops
    - REORG/MEDIUM: stream_interface: initialize socket ops from descriptors
    - REORG/MEDIUM: replace stream interface protocol functions by a proto pointer
    - REORG/MEDIUM: move the default accept function from sockstream to protocols.c
    - MEDIUM: proto_tcp: remove src6 and dst6 pattern fetch methods
    - BUG/MINOR: http: error snapshots are wrong if buffer wraps
    - BUG/MINOR: http: ensure that msg->err_pos is always relative to buf->p
    - MEDIUM: http: improve error capture reports
    - MINOR: acl: add the cook_val() match to match a cookie against an integer
    - BUG/MEDIUM: send_proxy: fix initialisation of send_proxy_ofs
    - MEDIUM: memory: add the ability to poison memory at run time
    - BUG/MEDIUM: log: ensure that unique_id is properly initialized
    - MINOR: cfgparse: use a common errmsg pointer for all parsers
    - MEDIUM: cfgparse: make backend_parse_balance() use memprintf to report errors
    - MEDIUM: cfgparse: use the new error reporting framework for remaining cfg_keywords
    - MINOR: http: replace http_message_realign() with  buffer_slow_realign()

13 years agoMINOR: http: replace http_message_realign() with buffer_slow_realign()
Willy Tarreau [Tue, 8 May 2012 18:40:09 +0000 (20:40 +0200)] 
MINOR: http: replace http_message_realign() with  buffer_slow_realign()

There is no more reason for the realign function being HTTP specific,
it only operates on a buffer now. Let's move it to buffers.c instead.

It's likely that buffer_bounce_realign is broken (not used), this will
have to be inspected. The function is worth rewriting as it can be
cheaper than buffer_slow_realign() to realign large wrapping buffers.

13 years agoMEDIUM: cfgparse: use the new error reporting framework for remaining cfg_keywords
Willy Tarreau [Tue, 8 May 2012 17:47:01 +0000 (19:47 +0200)] 
MEDIUM: cfgparse: use the new error reporting framework for remaining cfg_keywords

All keywords registered using a cfg_kw_list now make use of the new error reporting
framework. This allows easier and more precise error reporting without having to
deal with complex buffer allocation issues.

13 years agoMEDIUM: cfgparse: make backend_parse_balance() use memprintf to report errors
Willy Tarreau [Tue, 8 May 2012 16:14:39 +0000 (18:14 +0200)] 
MEDIUM: cfgparse: make backend_parse_balance() use memprintf to report errors

Using the new error reporting framework makes it easier to report complex
errors.

13 years agoMINOR: cfgparse: use a common errmsg pointer for all parsers
Willy Tarreau [Tue, 8 May 2012 15:37:49 +0000 (17:37 +0200)] 
MINOR: cfgparse: use a common errmsg pointer for all parsers

In order to generalize the simplified error reporting mechanism, let's
centralize the error pointer.

13 years agoBUG/MEDIUM: log: ensure that unique_id is properly initialized
Willy Tarreau [Tue, 8 May 2012 13:51:44 +0000 (15:51 +0200)] 
BUG/MEDIUM: log: ensure that unique_id is properly initialized

Last memory poisonning patch immediately made this issue appear.
The unique_id field is released but not properly initialized. The
feature was introduced very recently, no backport is needed.

13 years agoMEDIUM: memory: add the ability to poison memory at run time
Willy Tarreau [Tue, 8 May 2012 13:40:42 +0000 (15:40 +0200)] 
MEDIUM: memory: add the ability to poison memory at run time

From time to time, some bugs are discovered that are caused by non-initialized
memory areas. It happens that most platforms return a zero-filled area upon
first malloc() thus hiding potential bugs. This patch also replaces malloc()
in pools with calloc() to ensure that all platforms exhibit the same behaviour
upon startup. In order to catch these bugs more easily, add a -dM command line
flag to enable memory poisonning. Optionally, passing -dM<byte> forces the
poisonning byte to <byte>.

13 years agoBUG/MEDIUM: send_proxy: fix initialisation of send_proxy_ofs
Willy Tarreau [Tue, 8 May 2012 13:20:43 +0000 (15:20 +0200)] 
BUG/MEDIUM: send_proxy: fix initialisation of send_proxy_ofs

Commit b22e55bc introduced send_proxy_ofs but forgot to initialize it,
which remained unnoticed since it's always at the same place in the
stream interface. On a machine with dirty RAM returned by malloc(),
some responses were holding a PROXY header, which normally is not
possible.

The problem goes away after properly initializing the field upon each
new session_accept().

This fix does not need to be backported except if any code makes use of
a backport of this feature.

13 years agoMINOR: acl: add the cook_val() match to match a cookie against an integer
Willy Tarreau [Tue, 8 May 2012 10:46:28 +0000 (12:46 +0200)] 
MINOR: acl: add the cook_val() match to match a cookie against an integer

13 years agoMEDIUM: http: improve error capture reports
Willy Tarreau [Tue, 8 May 2012 09:03:10 +0000 (11:03 +0200)] 
MEDIUM: http: improve error capture reports

A number of important information were missing from the error captures, so
let's improve them. Now we also log source port, session flags, transaction
flags, message flags, pending output bytes, expected buffer wrapping position,
total bytes transferred, message chunk length, and message body length.

As such, the output format has slightly evolved and the source address moved
to the third line :

[08/May/2012:11:14:36.341] frontend echo (#1): invalid request
  backend echo (#1), server <NONE> (#-1), event #1
  src 127.0.0.1:40616, session #4, session flags 0x00000000
  HTTP msg state 26, msg flags 0x00000000, tx flags 0x00000000
  HTTP chunk len 0 bytes, HTTP body len 0 bytes
  buffer flags 0x00909002, out 0 bytes, total 28 bytes
  pending 28 bytes, wrapping at 8030, error at position 7:

  00000  GET / /?t=20000 HTTP/1.1\r\n
  00026  \r\n

[08/May/2012:11:13:13.426] backend echo (#1) : invalid response
  frontend echo (#1), server local (#1), event #0
  src 127.0.0.1:40615, session #1, session flags 0x0000044e
  HTTP msg state 32, msg flags 0x0000000e, tx flags 0x08200000
  HTTP chunk len 0 bytes, HTTP body len 20 bytes
  buffer flags 0x00008002, out 81 bytes, total 92 bytes
  pending 11 bytes, wrapping at 7949, error at position 9:

  00000  Foo: bar\r\r\n

13 years agoBUG/MINOR: http: ensure that msg->err_pos is always relative to buf->p
Willy Tarreau [Tue, 8 May 2012 07:44:41 +0000 (09:44 +0200)] 
BUG/MINOR: http: ensure that msg->err_pos is always relative to buf->p

Since the beginning of buffer&msg changes, the error position (err_pos)
had not completely been converted and some offsets still appear wrong.
Now we ensure that everywhere msg->err_pos is relative to buf->p and
we always report buf->i bytes starting at buf->p in all error captures,
which ensures that err_pos is there.

This is not exactly a bug and is specific to latest changes so no backport
is needed.

13 years agoBUG/MINOR: http: error snapshots are wrong if buffer wraps
Willy Tarreau [Tue, 8 May 2012 06:54:15 +0000 (08:54 +0200)] 
BUG/MINOR: http: error snapshots are wrong if buffer wraps

Commit 81f2fb added support for wrapping buffer captures, but unfortunately
the code used to perform two memcpy() over the same destination, causing a
loss of the start of the buffer rendering some error snapshots unusable.

This bug is present in 1.4 too and must be backported.

13 years agoMEDIUM: proto_tcp: remove src6 and dst6 pattern fetch methods
Willy Tarreau [Mon, 7 May 2012 19:36:48 +0000 (21:36 +0200)] 
MEDIUM: proto_tcp: remove src6 and dst6 pattern fetch methods

These methods have been superseded by src and dst which support
multiple families. There is no point keeping them since they appeared
in a development version anyway.

For configurations using "src6", please use "src" instead. For "dst6",
use "dst" instead.

13 years agoREORG/MEDIUM: move the default accept function from sockstream to protocols.c
Willy Tarreau [Mon, 7 May 2012 19:22:09 +0000 (21:22 +0200)] 
REORG/MEDIUM: move the default accept function from sockstream to protocols.c

The previous sockstream_accept() function uses nothing from sockstream, and
is totally irrelevant to stream interfaces. Move this to the protocols.c
file which handles listeners and protocols, and call it listener_accept().

It now makes much more sense that the code dealing with listen() also handles
accept() and passes it to upper layers.

13 years agoREORG/MEDIUM: replace stream interface protocol functions by a proto pointer
Willy Tarreau [Mon, 7 May 2012 16:12:14 +0000 (18:12 +0200)] 
REORG/MEDIUM: replace stream interface protocol functions by a proto pointer

The stream interface now makes use of the socket protocol pointer instead
of the direct functions.

13 years agoREORG/MEDIUM: stream_interface: initialize socket ops from descriptors
Willy Tarreau [Mon, 7 May 2012 15:15:39 +0000 (17:15 +0200)] 
REORG/MEDIUM: stream_interface: initialize socket ops from descriptors

13 years agoREORG/MEDIUM: move protocol->{read,write} to sock_ops
Willy Tarreau [Mon, 7 May 2012 15:01:39 +0000 (17:01 +0200)] 
REORG/MEDIUM: move protocol->{read,write} to sock_ops

The protocol must not set the read and write callbacks, they're specific
to the socket layer. Move them to sock_ops instead.

13 years agoREORG: stream_interface: create a struct sock_ops to hold socket operations
Willy Tarreau [Mon, 7 May 2012 14:50:03 +0000 (16:50 +0200)] 
REORG: stream_interface: create a struct sock_ops to hold socket operations

These operators are used regardless of the socket protocol family. Move
them to a "sock_ops" struct. ->read and ->write have been moved there too
as they have no reason to remain at the protocol level.

13 years agoMEDIUM: acl: support IPv6 address matching
Willy Tarreau [Fri, 27 Apr 2012 22:41:46 +0000 (00:41 +0200)] 
MEDIUM: acl: support IPv6 address matching

Make use of the new IPv6 pattern type so that acl_match_ip() knows how to
compare pattern and sample.

IPv6 may be entered in their usual form, with or without a netmask appended.
Only bit counts are accepted for IPv6 netmasks. In order to avoid any risk of
trouble with randomly resolved IP addresses, host names are never allowed in
IPv6 patterns.

HAProxy is also able to match IPv4 addresses with IPv6 addresses in the
following situations :
  - tested address is IPv4, pattern address is IPv4, the match applies
    in IPv4 using the supplied mask if any.
  - tested address is IPv6, pattern address is IPv6, the match applies
    in IPv6 using the supplied mask if any.
  - tested address is IPv6, pattern address is IPv4, the match applies in IPv4
    using the pattern's mask if the IPv6 address matches with 2002:IPV4::,
    ::IPV4 or ::ffff:IPV4, otherwise it fails.
  - tested address is IPv4, pattern address is IPv6, the IPv4 address is first
    converted to IPv6 by prefixing ::ffff: in front of it, then the match is
    applied in IPv6 using the supplied IPv6 mask.

13 years agoMINOR: standard: add an IPv6 parsing function (str62net)
Willy Tarreau [Fri, 27 Apr 2012 20:49:47 +0000 (22:49 +0200)] 
MINOR: standard: add an IPv6 parsing function (str62net)

str62net returns an address and a netmask in number of bits.

13 years agoMINOR: acl: add types to ACL patterns
Willy Tarreau [Fri, 27 Apr 2012 20:10:57 +0000 (22:10 +0200)] 
MINOR: acl: add types to ACL patterns

We cannot currently match IPv6 addresses in ACL simply because we don't
support types on the patterns. Let's introduce this notion. For now, we
rely on the SMP_TYPES though it doesn't seem like it will last forever
given that some types are not present there (eg: regex, meth). Still it
should be enough to support mixed matchings for most types.

We use the special impossible value SMP_TYPES for types that don't exist
in the SMP_T_* space.

13 years agoREORG: rename "pattern" files
Willy Tarreau [Fri, 27 Apr 2012 19:52:18 +0000 (21:52 +0200)] 
REORG: rename "pattern" files

They're now called "sample" everywhere to match their description.

13 years agoREORG: use the name "sample" instead of "pattern" to designate extracted data
Willy Tarreau [Fri, 27 Apr 2012 19:37:17 +0000 (21:37 +0200)] 
REORG: use the name "sample" instead of "pattern" to designate extracted data

This is mainly a massive renaming in the code to get it in line with the
calling convention. Next patch will rename a few files to complete this
operation.

13 years agoMEDIUM: acl: extend the pattern parsers to report meaningful errors
Willy Tarreau [Fri, 27 Apr 2012 15:52:25 +0000 (17:52 +0200)] 
MEDIUM: acl: extend the pattern parsers to report meaningful errors

By passing the error pointer to all ACL parsers, we can make them report
useful errors and not simply fail.

13 years agoMINOR: acl: report errors encountered when loading patterns from files
Willy Tarreau [Fri, 27 Apr 2012 15:25:24 +0000 (17:25 +0200)] 
MINOR: acl: report errors encountered when loading patterns from files

This happens in acl_read_patterns_from_file(). Errors are still incomplete,
parsing functions must be improved to report parsing errors.

13 years agoMINOR: arg: improve error reporting on invalid arguments
Willy Tarreau [Fri, 27 Apr 2012 14:32:26 +0000 (16:32 +0200)] 
MINOR: arg: improve error reporting on invalid arguments

It's important to report the faulty argument position and to distinguish
between empty arguments and wrong ones.

Integers were not properly tested either, now their parsing has been improved
to report use of incorrect characters.

13 years agoMEDIUM: acl: report parsing errors to the caller
Willy Tarreau [Fri, 27 Apr 2012 10:38:15 +0000 (12:38 +0200)] 
MEDIUM: acl: report parsing errors to the caller

All parsing errors were known but impossible to return. Now by making use
of memprintf(), we're able to build meaningful error messages that the
caller can display.

13 years agoMEDIUM: http: merge ACL and pattern cookie fetches into a single one
Willy Tarreau [Thu, 26 Apr 2012 19:26:10 +0000 (21:26 +0200)] 
MEDIUM: http: merge ACL and pattern cookie fetches into a single one

It's easy to merge pattern and ACL fetches of cookies. It allows us
to remove two distinct fetch functions. The new function internally
uses an occurrence number to serve both purposes, but it didn't appear
worth exposing it outside so there is no keyword argument to set it.
However one of the benefits is that the "cookie" fetch for stick tables
now automatically adapts to requests and responses, so there is no more
need for set-cookie().

13 years agoMEDIUM: http: merge acl and pattern header fetch functions
Willy Tarreau [Thu, 26 Apr 2012 13:11:51 +0000 (15:11 +0200)] 
MEDIUM: http: merge acl and pattern header fetch functions

HTTP header fetch is now done using smp_fetch_hdr() for both ACLs and
patterns. This one also supports an occurrence number, making it possible
to specify explicit occurrences for ACLs and patterns.

13 years agoMINOR: proto_tcp: validate arguments of payload and payload_lv ACLs
Willy Tarreau [Thu, 26 Apr 2012 10:24:45 +0000 (12:24 +0200)] 
MINOR: proto_tcp: validate arguments of payload and payload_lv ACLs

Now it's possible to control arguments, so let's do it.

13 years agoMINOR: acl: add a val_args field to keywords
Willy Tarreau [Thu, 26 Apr 2012 10:13:35 +0000 (12:13 +0200)] 
MINOR: acl: add a val_args field to keywords

This will make it possible to delegate argument validating to functions
shared with smp_fetch_*.

13 years agoMINOR: acl: set SMP_OPT_ITERATE on fetch functions
Willy Tarreau [Thu, 26 Apr 2012 09:44:02 +0000 (11:44 +0200)] 
MINOR: acl: set SMP_OPT_ITERATE on fetch functions

This way, fetch functions will be able to tell if they're called for a single
request or as part of a loop. This is important for instance when we use
hdr(foo), because in an ACL this means that all hdr(foo) occurrences must
be checked while in a pattern it means only one of them (eg: last one).

13 years agoMEDIUM: pattern: use smp_fetch_rdp_cookie instead of the pattern specific version
Willy Tarreau [Thu, 26 Apr 2012 09:23:39 +0000 (11:23 +0200)] 
MEDIUM: pattern: use smp_fetch_rdp_cookie instead of the pattern specific version

pattern_fetch_rdp_cookie() is useless now since it only used to add controls
on top of smp_fetch_rdp_cookie() which have now been integrated into the
pattern subsystem. Let's remove it.

13 years agoMINOR: pattern: centralize handling of unstable data in pattern_process()
Willy Tarreau [Thu, 26 Apr 2012 09:05:50 +0000 (11:05 +0200)] 
MINOR: pattern: centralize handling of unstable data in pattern_process()

Pattern fetch functions currently check for unstable data and return 0
when SMP_F_MAY_CHANGE is set. Instead of doing this everywhere and having
to support specific fetch functions, better do that in pattern_process()
which is the one interested in having stable data.

13 years agoMINOR: stick_table: centralize the handling of empty keys
Willy Tarreau [Thu, 26 Apr 2012 09:03:17 +0000 (11:03 +0200)] 
MINOR: stick_table: centralize the handling of empty keys

Right now, it's up to each pattern fetch method to return NULL when an
empty string is returned, which is neither correct nor desirable as it
is only stick tables which need to ignore empty patterns. Let's perform
this check in stktable_fetch_key() instead.

13 years agoCLEANUP: pattern: ensure that payload and payload_lv always stay in the buffer
Willy Tarreau [Wed, 25 Apr 2012 17:19:43 +0000 (19:19 +0200)] 
CLEANUP: pattern: ensure that payload and payload_lv always stay in the buffer

A test was already performed which worked by pure luck due to integer types,
otherwise it would have been possible to start checking for an offset out of
the buffer's bounds if the buffer size was large enough to allow an integer
wrap. Let's perform explicit checks and use unsigned ints for offsets instead
of risking being hit later.

13 years agoMEDIUM: acl: implement payload and payload_lv
Willy Tarreau [Wed, 25 Apr 2012 16:46:33 +0000 (18:46 +0200)] 
MEDIUM: acl: implement payload and payload_lv

These ones were easy to adapt to ACL usage and may really be useful,
so let's make them available right now. It's likely that some extension
such as regex, string-to-IP and raw IP matching will be implemented in
the near future.

13 years agoMEDIUM: acl/pattern: factor out the src/dst address fetches
Willy Tarreau [Wed, 25 Apr 2012 15:31:42 +0000 (17:31 +0200)] 
MEDIUM: acl/pattern: factor out the src/dst address fetches

Since pattern_process() is able to automatically cast returned types
into expected types, we can safely use the sample functions to fetch
addresses whatever their family. The lowest castable type must be
declared with the keyword so that config checks pass.

Right now this means that src/dst use the same fetch function for ACLs
and patterns. src6/dst6 have been kept so that configs which explicitly
rely on v6 are properly checked.

13 years agoMEDIUM: pattern: ensure that sample types always cast into other types.
Willy Tarreau [Wed, 25 Apr 2012 15:21:49 +0000 (17:21 +0200)] 
MEDIUM: pattern: ensure that sample types always cast into other types.

We want to ensure that a dynamically returned type will always have a
cast before calling the cast function. This is done in pattern_process()
and in stktable_fetch_key().

13 years agoMEDIUM: acl/pattern: start merging common sample fetch functions
Willy Tarreau [Wed, 25 Apr 2012 14:21:44 +0000 (16:21 +0200)] 
MEDIUM: acl/pattern: start merging common sample fetch functions

src_port, dst_port and url_param have converged between ACLs and patterns.
This means that src_port is now available in patterns and that urlp_* has
been added to ACLs. Some code has moved to accommodate for static function
definitions, but there were little changes.

13 years agoMEDIUM: acl/pattern: use the same direction scheme
Willy Tarreau [Wed, 25 Apr 2012 08:13:36 +0000 (10:13 +0200)] 
MEDIUM: acl/pattern: use the same direction scheme

Patterns were using a bitmask to indicate if request or response was desired
in fetch functions and keywords. ACLs were using a bitmask in fetch keywords
and a single bit in fetch functions. ACLs were also using an ACL_PARTIAL bit
in fetch functions indicating that a non-final fetch was performed, which was
an abuse of the existing direction flag.

The change now consists in using :
  - a capabilities field for fetch keywords => SMP_CAP_REQ/RES to indicate
    if a keyword supports requests, responses, both, etc...
  - an option field for fetch functions to indicate what the caller expects
    (request/response, final/non-final)

The ACL_PARTIAL bit was reversed to get SMP_OPT_FINAL as it's more explicit
to know we're working on a final buffer than on a non-final one.

ACL_DIR_* were removed, as well as PATTERN_FETCH_*. L4 fetches were improved
to support being called on responses too since they're still available.

The <dir> field of all fetch functions was changed to <opt> which is now
unsigned.

The patch is large but mostly made of cosmetic changes to accomodate this, as
almost no logic change happened.

13 years agoMINOR: tcp: replace acl_fetch_rdp_cookie with smp_fetch_rdp_cookie
Willy Tarreau [Mon, 23 Apr 2012 22:09:26 +0000 (00:09 +0200)] 
MINOR: tcp: replace acl_fetch_rdp_cookie with smp_fetch_rdp_cookie

The former was only a wrapper to the second, let's remove it now that
the calling convention is exactly the same. This is the first function
to be unified between ACLs and samples.

13 years agoMEDIUM: acl: replace acl_expr with args in acl fetch_* functions
Willy Tarreau [Mon, 23 Apr 2012 21:55:44 +0000 (23:55 +0200)] 
MEDIUM: acl: replace acl_expr with args in acl fetch_* functions

Having the args everywhere will make it easier to share fetch functions
between patterns and ACLs. The only place where we could have needed
the expr was in the http_prefetch function which can do well without.

13 years agoMEDIUM: acl/pattern: switch rdp_cookie functions stack up-down
Willy Tarreau [Mon, 23 Apr 2012 21:13:20 +0000 (23:13 +0200)] 
MEDIUM: acl/pattern: switch rdp_cookie functions stack up-down

Previously, both pattern, backend and persist_rdp_cookie would build fake
ACL expressions to fetch an RDP cookie by calling acl_fetch_rdp_cookie().

Now we switch roles. The RDP cookie fetch function is provided as a sample
fetch function that all others rely on, including ACL. The code is exactly
the same, only the args handling moved from expr->args to args. The code
was moved to proto_tcp.c, but probably that a dedicated file would be more
suited to content handling.

13 years agoMEDIUM: pattern: retrieve the sample type in the sample, not in the keyword description
Willy Tarreau [Mon, 23 Apr 2012 20:38:26 +0000 (22:38 +0200)] 
MEDIUM: pattern: retrieve the sample type in the sample, not in the keyword description

We need the pattern fetchers and converters to correctly set the output type
so that they can be used by ACL fetchers. By using the sample type instead of
the keyword type, we also open the possibility to create some multi-type
pattern fetch methods later (eg: "src" being v4/v6). Right now the type in
the keyword is used to validate the configuration.

13 years agoMEDIUM: pattern: integrate pattern_data into sample and use sample everywhere
Willy Tarreau [Mon, 23 Apr 2012 20:03:39 +0000 (22:03 +0200)] 
MEDIUM: pattern: integrate pattern_data into sample and use sample everywhere

Now there is no more reference to union pattern_data. All pattern fetch and
conversion functions now make use of the common sample type. Note: none of
them adjust the type right now so it's important to do it next otherwise
we would risk sharing such functions with ACLs and seeing them fail.

13 years agoMINOR: pattern: replace struct pattern with struct sample
Willy Tarreau [Mon, 23 Apr 2012 19:35:11 +0000 (21:35 +0200)] 
MINOR: pattern: replace struct pattern with struct sample

This change is pretty minor. Struct pattern is only used for
pattern_process() now so changing it to use the common type is
quite obvious. It's worth noting that the last argument of
pattern_process() is never used so the function is self-sufficient.

Note that pattern_process() does not initialize the pattern at all
before calling fetch->process(), and that minimal initialization
will be required when we later change the argument for the sample.

13 years agoMEDIUM: get rid of SMP_F_READ_ONLY and SMP_F_MUST_FREE
Willy Tarreau [Mon, 23 Apr 2012 17:25:44 +0000 (19:25 +0200)] 
MEDIUM: get rid of SMP_F_READ_ONLY and SMP_F_MUST_FREE

These ones were either unused or improperly used. Some integers were marked
read-only, which does not make much sense. Buffers are not read-only, they're
"constant" in that they must be kept intact after any possible change.

13 years agoMEDIUM: acl: get rid of the SET_RES flags
Willy Tarreau [Mon, 23 Apr 2012 17:18:42 +0000 (19:18 +0200)] 
MEDIUM: acl: get rid of the SET_RES flags

We now simply rely on a boolean result from a fetch to declare a match.
Booleans are not compared against patterns, they fix the result.

13 years agoMEDIUM: pattern/acl: get rid of temp_pattern in ACLs
Willy Tarreau [Mon, 23 Apr 2012 16:53:56 +0000 (18:53 +0200)] 
MEDIUM: pattern/acl: get rid of temp_pattern in ACLs

This one is not needed anymore as we can return the data and its type in the
sample provided by the caller. ACLs now always return the proper type. BOOL
is already returned when the result is expected to be processed as a boolean.

temp_pattern has been unexported now.

13 years agoMAJOR: acl: make use of the new sample struct and get rid of acl_test
Willy Tarreau [Mon, 23 Apr 2012 14:16:37 +0000 (16:16 +0200)] 
MAJOR: acl: make use of the new sample struct and get rid of acl_test

This change is invasive in lines of code but not much in terms of
functionalities as it's mainly a replacement of struct acl_test
with struct sample.

13 years agoMEDIUM: pattern: add new sample types to replace pattern types
Willy Tarreau [Fri, 20 Apr 2012 18:49:27 +0000 (20:49 +0200)] 
MEDIUM: pattern: add new sample types to replace pattern types

The new sample types are necessary for the acl-pattern convergence.
These types are boolean and signed int. Some types were renamed for
less ambiguity (ip->ipv4, integer->uint).

13 years agoMINOR: pattern: add a new 'sample' type to store fetched data
Willy Tarreau [Mon, 23 Apr 2012 12:24:58 +0000 (14:24 +0200)] 
MINOR: pattern: add a new 'sample' type to store fetched data

The pattern type is ambiguous because a pattern is only a type and a data
part, and is normally used to match against samples. Currently, patterns
cannot hold information related to the life of the data which was extracted.
We don't want to overload patterns either, so let's add a new "sample" type
which will progressively supersede the acl_test and maybe the pattern at most
places. The sample shares similar information with patterns and also has flags
describing the data volatility and protection.

13 years agoMEDIUM: acl: remove the ACL_TEST_F_NULL_MATCH flag
Willy Tarreau [Fri, 20 Apr 2012 16:16:26 +0000 (18:16 +0200)] 
MEDIUM: acl: remove the ACL_TEST_F_NULL_MATCH flag

This flag was used to force a boolean match even if there was no pattern
to match. It was used only by http_auth() and designed only for this one.
It's easier and cleaner to make the fetch function perform the test and
report the boolean result as a few other functions already do. It simplifies
the acl_exec_cond() logic and will help merging ACLs and patterns.

13 years agoMEDIUM: pattern: report the precise argument parsing error when known.
Willy Tarreau [Fri, 20 Apr 2012 14:04:47 +0000 (16:04 +0200)] 
MEDIUM: pattern: report the precise argument parsing error when known.

The argument parser knows what exact error it has faced, and the pattern
parser is able to report errors, so let's make use of it. From now on, it
becomes possible to detect such things :

$ ./haproxy -db -f echo5.cfg
[ALERT] 110/160344 (4791) : parsing [echo5.cfg:38] : 'stick': invalid arg 2 in fetch method 'payload' : Missing arguments (got 1/2), type 'unsigned integer' expected.
[ALERT] 110/160344 (4791) : parsing [echo5.cfg:39] : 'stick': invalid args in fetch method 'payload' : payload length must be > 0.
[ALERT] 110/160344 (4791) : parsing [echo5.cfg:40] : 'stick': invalid arg 3 in fetch method 'payload_lv' : Failed to parse 'x' as type 'signed integer'.
[ALERT] 110/160344 (4791) : parsing [echo5.cfg:41] : 'stick': invalid arg 4 in fetch method 'payload_lv' : End of arguments expected at ',13'.
[ALERT] 110/160344 (4791) : Error(s) found in configuration file : echo5.cfg
[ALERT] 110/160344 (4791) : Fatal errors found in configuration.

13 years agoMEDIUM: pattern: add an argument validation callback to pattern descriptors
Willy Tarreau [Fri, 20 Apr 2012 13:52:36 +0000 (15:52 +0200)] 
MEDIUM: pattern: add an argument validation callback to pattern descriptors

This is used to validate that arguments are coherent. For instance,
payload_lv expects that the last arg (if any) is not more negative
than the sum of the first two. The error is reported if any.

13 years agoMEDIUM: pattern: use the standard arg parser
Willy Tarreau [Fri, 20 Apr 2012 12:45:49 +0000 (14:45 +0200)] 
MEDIUM: pattern: use the standard arg parser

We don't need the pattern-specific args parsers anymore, make use of the
common parser instead. We still need to improve this by adding a validation
function to report abnormal argument values or combinations. We don't report
precise parsing errors yet but this was not previously done either.

13 years agoMEDIUM: pattern: get rid of arg_i in all functions making use of arguments
Willy Tarreau [Fri, 20 Apr 2012 12:03:29 +0000 (14:03 +0200)] 
MEDIUM: pattern: get rid of arg_i in all functions making use of arguments

arg_i was almost unused, and since we migrated to use struct arg everywhere,
the rare cases where arg_i was needed could be replaced by switching to
arg->type = ARGT_STOP.

13 years agoMEDIUM: pattern: replace type pattern_arg with type arg
Willy Tarreau [Fri, 20 Apr 2012 10:29:52 +0000 (12:29 +0200)] 
MEDIUM: pattern: replace type pattern_arg with type arg

arg is more complete than pattern_arg since it also covers ACL args,
so let's use this one instead.

13 years agoMEDIUM: acl: remove unused tests for missing args when args are mandatory
Willy Tarreau [Fri, 20 Apr 2012 09:37:56 +0000 (11:37 +0200)] 
MEDIUM: acl: remove unused tests for missing args when args are mandatory

A number of ACL fetch methods use mandatory arguments (eg: proxy names) so
it's pointless to test for the presence of this argument now.

13 years agoMAJOR: acl: ensure that implicit table and proxies are valid
Willy Tarreau [Thu, 19 Apr 2012 21:35:54 +0000 (23:35 +0200)] 
MAJOR: acl: ensure that implicit table and proxies are valid

A large number of ACLs make use of frontend, backend or table names in their
arguments, and fall back to the current proxy when no argument is passed. If
the expected capability is not available, the ACL silently fails at runtime.

Now we make all those names mandatory in the parser and we rely on
acl_find_targets() to replace the missing names with the holding proxy,
then to perform the appropriate tests, and to reject errors at parsing
time.

It is possible that some faulty configurations will get rejected from now
on, while they used to silently fail till now. This is the reason why this
change is marked as MAJOR.

13 years agoMAJOR: acl: make acl_find_targets also resolve proxy names at config time
Willy Tarreau [Thu, 19 Apr 2012 17:28:33 +0000 (19:28 +0200)] 
MAJOR: acl: make acl_find_targets also resolve proxy names at config time

Proxy names are now resolved when the config is parsed and not at runtime.
This means that errors will be caught for real instead of having an ACL
silently never match. Another benefit is that the fetch will be much faster
since the lookup will not have to be performed anymore, eg for all ACLs
based on explicitly named stick-tables.

However some buggy configurations which used to silently fail in the past
will now refuse to load, hence the MAJOR tag.

13 years agoMEDIUM: acl: acl_find_target() now resolves arguments based on their types
Willy Tarreau [Thu, 19 Apr 2012 17:11:13 +0000 (19:11 +0200)] 
MEDIUM: acl: acl_find_target() now resolves arguments based on their types

This function does not rely on the keyword anymore but just on its type.
It's much cleaner and much safer. It should be extended to do the same for
all PRX type arguments.

13 years agoMAJOR: acl: store the ACL argument types in the ACL keyword declaration
Willy Tarreau [Thu, 19 Apr 2012 16:42:05 +0000 (18:42 +0200)] 
MAJOR: acl: store the ACL argument types in the ACL keyword declaration

The types and minimal number of ACL keyword arguments are now stored in
their declaration. This will allow many more fantasies if some ACL use
several arguments or types.

Doing so required to rework all ACL keyword declarations to add two
parameters. So this was a good opportunity for a general cleanup and
to sort all entries in alphabetical order.

We still have two pending issues :
  - parse_acl_expr() checks for errors but has no way to report them to
    the user ;
  - the types of some arguments are still not resolved and kept as strings
    (eg: ARGT_FE/BE/TAB) for compatibility reasons, which must be resolved
    in acl_find_targets()

13 years agoMAJOR: acl: make use of the new argument parsing framework
Willy Tarreau [Thu, 19 Apr 2012 15:16:54 +0000 (17:16 +0200)] 
MAJOR: acl: make use of the new argument parsing framework

The ACL parser now uses the argument parser to build a typed argument list.
Right now arguments are all strings and only one argument is supported since
this is what ACLs currently support.

13 years agoMEDIUM: add a new typed argument list parsing framework
Willy Tarreau [Thu, 19 Apr 2012 13:24:50 +0000 (15:24 +0200)] 
MEDIUM: add a new typed argument list parsing framework

make_arg_list() builds an array of typed arguments with their values,
that the caller describes how to parse. This will be used to support
multiple arguments for ACLs and patterns, which is currently problematic
and prevents ACLs and patterns from being merged. Up to 7 arguments types
may be enumerated in a single 32-bit word, including their number of
mandatory parts.

At the moment, these files are not used yet, they're only built. Note that
the 4-bit encoding for the type has left only one unused type!

13 years agoMEDIUM: http/acl: make acl_fetch_hdr_{ip,val} rely on acl_fetch_hdr()
Willy Tarreau [Mon, 16 Apr 2012 15:21:11 +0000 (17:21 +0200)] 
MEDIUM: http/acl: make acl_fetch_hdr_{ip,val} rely on acl_fetch_hdr()

These two functions will now exploit the return of acl_fetch_hdr() instead
of doing the same work again and again.

13 years agoMEDIUM: http/acl: merge all request and response ACL fetches of headers and cookies
Willy Tarreau [Mon, 16 Apr 2012 14:26:40 +0000 (16:26 +0200)] 
MEDIUM: http/acl: merge all request and response ACL fetches of headers and cookies

Latest changes have made it possible to remove all differences between
request and response processing, making it worth merging request and
response ACL fetch functions to reduce code size.

Most likely with minor adaptation it will be possible to use the same hdr_*
functions to match in the response path, and cook_* for the response cookie
too.

13 years agoBUG/MINOR: http_auth: ACLs are volatile, not permanent
Willy Tarreau [Mon, 16 Apr 2012 13:00:51 +0000 (15:00 +0200)] 
BUG/MINOR: http_auth: ACLs are volatile, not permanent

ACLs are volatile since they require a fetch of request buffer data which is
then copied to a temporary shared place. The issue is minor though since auth
is generally checked very early.

13 years agoMEDIUM: http: make all ACL fetch function use acl_prefetch_http()
Willy Tarreau [Mon, 16 Apr 2012 12:42:55 +0000 (14:42 +0200)] 
MEDIUM: http: make all ACL fetch function use acl_prefetch_http()

All ACLs which need to process HTTP contents first call this function which
performs all the preliminary tests and also triggers the request parsing if
needed. A macro was written to simplify the code.

As a side effect, it's not required anymore to check for the HTTP ACL before
checking for HTTP contents.

13 years agoMEDIUM: http: add a prefetch function for ACL pattern fetch
Willy Tarreau [Mon, 16 Apr 2012 12:34:04 +0000 (14:34 +0200)] 
MEDIUM: http: add a prefetch function for ACL pattern fetch

This function will be called by all ACL fetch functions. Right now all ACL
fetch functions have to perform the exact same tests to check whether data
are available. Also, only one of them is able to actually parse an HTTP
request.

Using the prefetch function, it will be possible to try to parse a request
on the fly and to avoid the fetch if some data are missing. This will
significantly reduce the amount of tests in all ACL fetch functions.

13 years agoMEDIUM: buffers: rename a number of buffer management functions
Willy Tarreau [Mon, 7 May 2012 09:56:55 +0000 (11:56 +0200)] 
MEDIUM: buffers: rename a number of buffer management functions

The following renaming took place :
1) buffer input functions
  buffer_put_block => bi_putblk
  buffer_put_char => bi_putchr
  buffer_put_string => bi_putstr
  buffer_put_chunk => bi_putchk
  buffer_feed => bi_putstr
  buffer_feed_chunk => bi_putchk
  buffer_cut_tail => bi_erase
  buffer_ignore => bi_fast_delete

2) buffer output functions
  buffer_get_char => bo_getchr
  buffer_get_line => bo_getline
  buffer_get_block => bo_getblk
  buffer_skip => bo_skip
  buffer_write => bo_inject

3) buffer input avail/full functions were introduced :
  bi_avail
  bi_full

13 years agoMEDIUM: buffers: implement b_adv() to advance a buffer's pointer
Willy Tarreau [Sat, 5 May 2012 21:32:27 +0000 (23:32 +0200)] 
MEDIUM: buffers: implement b_adv() to advance a buffer's pointer

This is more convenient and efficient than buf->p = b_ptr(buf, n);
It simply advances the buffer's pointer by <n> and trasfers that
amount of bytes from <in> to <out>. The BF_OUT_EMPTY flag is updated
accordingly.

A few occurrences of such computations in buffers.c and stream_sock.c
were updated to use b_adv(), which resulted in a small code shrink.

13 years agoMEDIUM: buffers: add new pointer wrappers and get rid of almost all buffer_wrap_add...
Willy Tarreau [Fri, 4 May 2012 19:35:27 +0000 (21:35 +0200)] 
MEDIUM: buffers: add new pointer wrappers and get rid of almost all buffer_wrap_add calls

buffer_wrap_add was convenient for the migration but is not handy at all.
Let's have new wrappers that report input begin/end and output begin/end
instead.

It looks like we'll also need a b_adv(ofs) to advance a buffer's pointer.

13 years agoMEDIUM: buffers: fix unsafe use of buffer_ignore at some places
Willy Tarreau [Fri, 9 Mar 2012 14:03:30 +0000 (15:03 +0100)] 
MEDIUM: buffers: fix unsafe use of buffer_ignore at some places

buffer_ignore may only be used when the output of a buffer is empty,
but it's not granted it is always the case when sending HTTP error
responses. Better use buffer_cut_tail() instead, and use buffer_ignore
only on non-wrapping data.

13 years agoMINOR: http: remove useless wrapping checks in http_msg_analyzer
Willy Tarreau [Fri, 9 Mar 2012 13:46:19 +0000 (14:46 +0100)] 
MINOR: http: remove useless wrapping checks in http_msg_analyzer

The message cannot wrap here.

13 years agoMEDIUM: http: remove buffer arg in chunk parsing functions
Willy Tarreau [Fri, 9 Mar 2012 13:10:20 +0000 (14:10 +0100)] 
MEDIUM: http: remove buffer arg in chunk parsing functions

The buffer pointer is now taken from the http_msg in the following
functions :

http_parse_chunk_size
http_forward_trailers
http_skip_chunk_crlf

Most internal pointers were converted to const as the result of the
operation.