Commit Graph

81 Commits (caf29e92b3f314f552bc9fece4f2e7a542551ed5)

Author SHA1 Message Date
Eric Leblond 276b93fb53 unix-socket: add ebpf-bypassed-stats command
This command output the count of element in IPv4 and IPv6 flow
table of interfaces using eBPF/XDP bypass.
8 years ago
Eric Leblond 3d0ba36ba8 unix socket: protocol v0.2
This patch updates the unix socket protocol. Messages send from
the server and the client have now a '\n' at the end. This allows
both sides to detect easily the end of a command.

As a side effect, this fixes the problem of long answer in
suricatasc. There is now a limit at the arbitrary value of 65536.

Backward compatility is preserved as a client with the older
version of the protocol can still connect to a Suricata with
version 2 of the protocol.
8 years ago
Pascal Delalande 63b9b9e9aa unix-socket: socket permission update
So far, the suricata socket suricata-command.socket has the rights
 rw-r----- suricata:user.
When suricata is used with restricted access, an other application
(suricatasc like) that needs to access to the command socket also
with restricted access can not write to the socket since it is not
the owner (e.g suricata within container, with an hardened value
for umask and hardened rights for users).

The socket should be set as rw-rw----. Use chmod instead of fchmod
and set it after the socket creation.
8 years ago
Victor Julien d8ddd3b5bc mingw: work around mingw mkdir
mingw doesn't come with a posix compliant mkdir as it only takes
a single argument.
8 years ago
Giuseppe Longo 3668ea2522 runmode-unix-socket: add commands for memcap handling
This permits to handle memcap values through
unix socket for:
- stream
- stream-reassembly
- flow
- applayer-proto-http
- defrag
- ippair
- host

It will be possible to show or change a memcap value
for a specified configuration and list all memcap values
available.

The following commands are registered for unix-socket:
- memcap-set
- memcap-show
- memcap-list

Output:
>>> memcap-show flow
Success:
{
    "value": "64mb"
}

>>> memcap-set flow 64mb
Success:
"memcap value for 'flow' updated: 67108864"

Command with invalid memcap key:
>>> memcap-set udp 32mb
Error:
"Available config: stream stream-reassembly flow applayer-proto-http defrag ippair host"

Command with an invalid memcap value:
>>> memcap-set http 32mmb
Error:
"error parsing memcap specified, value not changed"
8 years ago
Eric Leblond 3205a8789b unix-socket: add logs reopen command
We did had a race condition with running logrotate with multiple
EVE Json files. Consequence was one of the file not being reopen
by suricata that did continue to write to the rotated one.

Trying fix on signal handler did fail so this patch implements
log rotation support by adding a dedicated command to unix socket
to reopen the log files.
8 years ago
Giuseppe Longo e7392a0780 unix-manager: block live reload when -s/-S is specified
Currently, when live reload is executed through
unix-socket, suri prints in the console the following
error message:
"Live rule reload not possible if -s or -S option used at runtime."

Instead, prints "done" in unix socket,
when the live reload is not executed.
8 years ago
Giuseppe Longo f1d372a505 unix-manager: add "ruleset-reload-rules" command
This add a new command the new naming convention.

The (old) command "reload-rules" is kept for
backward compatibility
8 years ago
Giuseppe Longo 9131afbe71 unix-manager: print failed rules
This permits to print the invalid rules through
unix socket.

An example output is the following:

>>> show-failed-rules
Success:
[
    {
        "filename": "/home/eric/git/oisf/benches/tls-store.rules",
        "line": 2,
        "rule": "alert ts any any -> any 334 (msg:\"Store TLS\"; tls.store; sid:2; rev:1;)"
    },
    {
        "filename": "/home/eric/git/oisf/benches/tls-store.rules",
        "line": 3,
        "rule": "alert ls any any -> any 334 (msg:\"Store TLS\"; tls.store; sid:3; rev:1;)"
    }
]

The dump is limited to 20 entries to avoid to send a too big
message to the client that don't support it by default.
8 years ago
Eric Leblond e17b9616ab unix-socket: add ruleset-reload-nonblocking command
Add a non blocking function to reload rules. It will be useful
for remote system management to avoid to block them waiting the
reload. And as we now have a last-reload command we can get the
status of the current reload.
8 years ago
Giuseppe Longo 1567f84cd2 detect-engine: remove DONE state
Remove the DONE state to fix a problem with state not being
changed correctly when multiple reload were done. As DONE was
not really useful, we can remove it.
8 years ago
Giuseppe Longo 89c629a79d unix-socket: add commands to print engine stats
This permits to print engine stats through
unix socket.
8 years ago
Victor Julien c02739e535 mingw: don't try to build unix socket 8 years ago
Victor Julien 8127730f00 bug 2113: fix live modes 8 years ago
Victor Julien c513896786 bug 2113: unix-socket start up race 8 years ago
Victor Julien ab1200fbd7 compiler: more strict compiler warnings
Set flags by default:

    -Wmissing-prototypes
    -Wmissing-declarations
    -Wstrict-prototypes
    -Wwrite-strings
    -Wcast-align
    -Wbad-function-cast
    -Wformat-security
    -Wno-format-nonliteral
    -Wmissing-format-attribute
    -funsigned-char

Fix minor compiler warnings for these new flags on gcc and clang.
8 years ago
Jason Ish ff30d924db unix-socket: return failure on failure
UnixManagerThreadInit needs to return a failure code if the socket
fails to initialize to avoid entering the UnixManager loop which
will continuously fail on the call to bind, as no listening
socket was setup.

This can occur when the socket fails to initialize due to a
permissions error and fatal init errors is not on.
8 years ago
Victor Julien f380871057 threads: don't sleep under lock 9 years ago
Victor Julien 88888c3d8b unix-socket: add/list/remove hostbit commands
add-hostbit adds a named hostbit with an expire time in seconds.
remove-hostbit removes hostbit by name.

add-hostbit, remove-hostbit return success or failure.

list-hostbit returns a json array of hostbits with their name and
expire time:

    {
        "message": {
            "count": 1,
            "hostbits":
                [{
                    "expire": 3222,
                    "name": "firefox-users"
                }]
        },
        "return": "OK"
    }
9 years ago
Victor Julien babe8a299e startup/shutdown: cleanup and unify with unix mode 9 years ago
Jason Ish 20111cab23 unix-socket: fix shadowed variable
ret does not need to be redefined here, the existing
declaration of ret can be used.
9 years ago
Victor Julien abbc0f76eb unix-socket: clean up path handling
Create/check socket path in a single place. Don't use dynamic
memory allocation.
9 years ago
Victor Julien c5e550b10d unix-socket: create socket directory if possible
Create the socket directory in the default case.

Since we're doing stat+mkdir indicate to Coverity not to worry about
the toctou case.
9 years ago
Victor Julien 3f741e450b unix-socket: be more specific about problems 9 years ago
Victor Julien 9368013645 unix-socket: don't error out on unix socket failure
If --init-errors-fatal is specified do error out.

Bug https://redmine.openinfosecfoundation.org/issues/1973
9 years ago
Victor Julien f80ce51ddf unix-socket: don't try to change permissions on BSD
On BSD using fchmod on a socket is not supported and will result
in EINVAL.
9 years ago
Victor Julien 96c28b2995 bug 1353: don't cut off last char of unix path 9 years ago
Victor Julien 85db260eed threads: remove EngineKill & SURICATA_KILL
EngineStop and EngineKill were effectively doing the same, so
removed the kill variant.
9 years ago
Eric Leblond 1cdd062dc6 unix-manager: fix output of version command
Make it consistent with the output of version command line flag.
9 years ago
Zachary Rasmor 68cfa009a0 Update thread creation and threads to use global thread names.
Thread name is now stored as a static string buffer,
string duplication and alloc/de-alloc is no longer required.
9 years ago
Eric Leblond f34fe85cfe unix-manager: fix memleak at exit
Buffer allocated for UnixClient was not correctly freed.
10 years ago
Eric Leblond b1f907a58f unix-manager: fix memleak
This fixes:

2,595 (1,824 direct, 771 indirect) bytes in 57 blocks are definitely lost in loss record 328 of 332
   at 0x4C29C0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x66D0C7B: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.7.0)
   by 0x911A27: UnixManagerListCommand (unix-manager.c:766)
   by 0x9108A9: UnixCommandExecute (unix-manager.c:486)
   by 0x910D9E: UnixCommandRun (unix-manager.c:545)
   by 0x9111B3: UnixMain (unix-manager.c:593)
   by 0x913D27: UnixManager (unix-manager.c:961)
   by 0x907773: TmThreadsManagement (tm-threads.c:600)
   by 0x68DE283: start_thread (pthread_create.c:333)
   by 0x80A6A4C: clone (in /lib/x86_64-linux-gnu/libc-2.21.so)
10 years ago
Victor Julien f5ce7549be unix-manager: fix memleak in error case (CID 1353491) 10 years ago
Victor Julien 3f3ed71fe7 jansson: cleanup JSON_ESCAPE_SLASH use 10 years ago
Victor Julien 654829f969 unix-socket: optimize response sends
Instead of sending responses to clients in small chunks, send it in
one big chunk. For this the JSON message is first serialized into
a MemBuffer before sending.
10 years ago
Alexander Gozman 2aa971240b unix manager: log client's version with debug level
As (dis)connects are already logged as a debug events, this one
should do the same.
10 years ago
Eric Leblond 384db27800 unix-manager: fix ressource leak when init fail 10 years ago
Eric Leblond 6b37985c66 unix-manager: fix race condition
Under high load it is possible that the thread is not yet started
and that we register a command at the same time. As a consequence,
the commands list is not yet initialized and we have a segfault.

This patch moves the initialization in the ThreadInit function to
be sure the commands list is available when needed.
10 years ago
Alexander Gozman 3e29a23208 unix-manager: log client (dis)connection with DEBUG level.
Also select/receive errors are logged as ERROR.
10 years ago
Victor Julien d8181802d3 multi-detect: add reload-tenant command
Allow for a tenant to be reloaded. The command is the same as the
register-tenant command, so with a yaml and tenant-id as argument.
However this replaces an existing tenant.
10 years ago
Victor Julien 216638c342 multi-detect: implement unregister-tenant-handler
Remove a tenant handler from the list and apply it.
10 years ago
Victor Julien 6d92e8d220 unix-socket: implement register-tenant-handler
Register tenant handlers/selectors based on what the unix command
"register-tenant-handler" tells.

Check traffic id before adding it. No duplicated registrations for
a traffic id are allowed.
10 years ago
Victor Julien 147a6d2bfd multi-detect: (un)register-tenant unix socket commands
Make available to live mode and unix socket mode.

register-tenant:
    Loads a new YAML, does basic validation.
    Loads a new detection engine
    Loads rules
    Add new de_ctx to master store and stores tenant id in the de_ctx so
        we can look it up by tenant id later.

unregister-tenant:
    Gets the de_ctx, moves it to the freelist
    Removes config

Introduce DetectEngineGetByTenantId, which gets a reference to the
detect engine by tenant id.
10 years ago
Victor Julien 752f03e7a4 counters: remaining s/SCPerf/Stats/g 10 years ago
Victor Julien 74ab84c194 counters: introduce SCPerfSetupPrivate for thread setup 10 years ago
Victor Julien 799640f906 counters: make threadvars::perf_private_ctx static
Update SCPerfGetAllCountersArray and add a UT workaround.
10 years ago
Victor Julien 9a8bff7d96 counters: threadvars s/sc_perf_pca/perf_private_ctx/g 10 years ago
Victor Julien 50bb995458 counters: rename threadvars public counters 10 years ago
Victor Julien df5e9d44ca unix-manager: convert to thread module
Sync command thread for unix manager with other managers and make
it a full thread module.
10 years ago
Victor Julien 7c9e015748 unix-socket: implement reload-rules
Implement the reload-rules unix socket command. The unix command
thread signals the main thread to do the reload and it waits for
it to complete.
11 years ago