Commit Graph

14 Commits

Author SHA1 Message Date
Willy Tarreau b7a6d0d8d7 CONTRIB: tcploop: add action "X" to execute a command
Sometimes it's convenient to be able to execute a command directly on
the stream, whether we're connecting or accepting an incoming connection.
New command 'X' makes this possible. It simply calls execvp() on the
next arguments and branches stdin/stdout/stderr on the socket. Optionally
it's possible to limit the passed FDs to any combination of them by
appending 'i', 'o', 'e' after the X. In any case the program ends just
after executing this command.

Examples :
- chargen server
      tcploop 8001 L A Xo cat /dev/zero

- telnet server
      tcploop 8001 L W N A X /usr/sbin/in.telnetd
2017-05-03 06:58:53 +02:00
Willy Tarreau a84a2dba94 CONTRIB: tcploop: use the trash instead of NULL for recv()
NULL is Linux-centric and we're not focused on performance here but
portability and reproducibility. Don't use NULL and use the trash
instead. It may lead to multiple recv() calls for large blocks but
as a benefit it will be possible to see the contents with strace.
2017-03-15 11:48:46 +01:00
Willy Tarreau 24d41b9b4d CONTRIB: tcploop: fix connect's address length
FreeBSD wants the address size to be correct, so let's pass the size
of a sockaddr_in struct, not the sockaddr_storage.
2017-03-15 11:48:46 +01:00
Willy Tarreau bcd817e669 CONTRIB: tcploop: report action 'K' (kill) in usage message
It was missing from the initial import.
2017-03-15 11:48:46 +01:00
Willy Tarreau 752cc49728 CONTRIB: tcploop: fix time format to silence build warnings
timeval doesn't necessarily have ints for tv_sec/tv_usec, let's cast
them.
2017-03-15 11:48:46 +01:00
Willy Tarreau 0c0c0a6c26 CONTRIB: tcploop: make it build on FreeBSD
A few changes :
- SOL_TCP must be replaced with IPPROTO_TCP
- TCP_NOQUICKACK is not defined
- MSG_MORE can be ignored and replaced with 0
2017-03-15 11:48:46 +01:00
Willy Tarreau 5cd60670a6 CONTRIB: tcploop: add limits.h to fix build issue with some compilers
Just got this while cross-compiling :

tcploop.c: In function 'tcp_recv':
tcploop.c:444:48: error: 'INT_MAX' undeclared (first use in this function)
tcploop.c:444:48: note: each undeclared identifier is reported only once for each function it appears in
2016-12-17 14:27:30 +01:00
Willy Tarreau 29cc11ca41 CONTRIB: tcploop: add basic loops via a jump instruction
This one jumps back to the oldest post-fork and post-accept action,
so it allows to recv(), pause() and send() in loops after a fork()
and an accept() for example. This is handy for bugs that reproduce
once in a while or to keep idle connections working.
2016-11-12 19:16:29 +01:00
Willy Tarreau 1973e81c06 CONTRIB: tcploop: don't report failed send() or recv()
Many clients close with an RST on the last response or when they get
their response, so let's not report an error.
2016-11-12 19:16:19 +01:00
Willy Tarreau 59623e0aa8 CONTRIB: tcploop: support sending plain strings
By passing "S:<string>" instead of S<size> it's possible to send
a pre-defined string, which is convenient to write HTTP requests or
responses.

Example : produce two responses, one in keep-alive, one not for ab :

  ./tcploop 8001 L W N2 A R S:"HTTP/1.0 200 OK\r\nConnection: keep-alive\r\nContent-length: 50\r\n\r\n0123456789.123456789.123456789.123456789.123456789" R S:"HTTP/1.0 200 OK\r\nContent-length: 50\r\n\r\n0123456789.123456789.123456789.123456789.123456789"

With 20 such keep-alive responses and 10 parallel processes, ab achieves
350kreq/s, so it should be possible to get precise timings.
2016-11-12 18:39:32 +01:00
Willy Tarreau 9557bacfff CONTRIB: tcploop: update the usage output
Otherwise we have no other help.
2016-11-12 18:28:29 +01:00
Willy Tarreau 869c759153 CONTRIB: tcploop: implement logging when called with -v
This is helpful to show what state we're dealing with. The pid is
written, optionally followed by the time in 3 different formats
(relative/absolute) depending on the command line option (-t, -tt, -ttt).
2016-11-12 18:28:29 +01:00
Willy Tarreau 95a6b786fc CONTRIB: tcploop: implement fork()
Fork is a very convenient way to deal with independant yet properly
timed connections. It's particularly useful here for accept(), and
ensures that any accepted FD will automatically be released. The
principle is that when we hit a fork command, the parent restarts
evaluating the actions from the beginning and the child continues
to evaluate the next actions. Listen and connect are skipped if the
connection is already established. Fork() is amazingly cheap on
Linux, 21k forked connections per second are handled on a single
core, and 38k on two cores.

For now it's not possible to have two different code paths so in order
to have both a listener and a connector, two distinct commands are
still needed.
2016-11-12 18:26:43 +01:00
Willy Tarreau 84393aa863 CONTRIB: tcploop: scriptable TCP I/O for debugging purposes
netcat, nc6 and socat are only partially convenient as reproducers for
state machine bugs, but when it comes to adding delays, forcing resets,
waiting for data to be acked, they become useless.

The purpose of this utility is to be able to easily script some TCP
operations such as connect, accept, send, receive, shutdown and of
course pauses.
2016-11-12 18:04:05 +01:00