From a480abcdd03d8dadfd45e6d4a4eb78dae41ad08e Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Tue, 29 Dec 2020 00:43:01 +0100 Subject: [PATCH] datasets: add dump via unix socket This patch adds a dataset-dump command to the list of unix socket commands. Implementation is not optimal as we are locking the datasets when doing the dump. But if we consider that the current alternative from an implementation point of view is to stop Suricata then this is far better than current state. Ticket: #5184 --- src/runmode-unix-socket.c | 9 +++++++++ src/runmode-unix-socket.h | 1 + src/unix-manager.c | 1 + 3 files changed, 11 insertions(+) diff --git a/src/runmode-unix-socket.c b/src/runmode-unix-socket.c index e318060475..c302519464 100644 --- a/src/runmode-unix-socket.c +++ b/src/runmode-unix-socket.c @@ -763,6 +763,15 @@ TmEcode UnixSocketDatasetRemove(json_t *cmd, json_t* answer, void *data) } } +TmEcode UnixSocketDatasetDump(json_t *cmd, json_t *answer, void *data) +{ + SCEnter(); + SCLogDebug("Going to dump datasets"); + DatasetsSave(); + json_object_set_new(answer, "message", json_string("datasets dump done")); + SCReturnInt(TM_ECODE_OK); +} + /** * \brief Command to add a tenant handler * diff --git a/src/runmode-unix-socket.h b/src/runmode-unix-socket.h index ded10349f0..31c59ee2f5 100644 --- a/src/runmode-unix-socket.h +++ b/src/runmode-unix-socket.h @@ -35,6 +35,7 @@ float MemcapsGetPressure(void); #ifdef BUILD_UNIX_SOCKET TmEcode UnixSocketDatasetAdd(json_t *cmd, json_t* answer, void *data); TmEcode UnixSocketDatasetRemove(json_t *cmd, json_t* answer, void *data); +TmEcode UnixSocketDatasetDump(json_t *cmd, json_t *answer, void *data); TmEcode UnixSocketRegisterTenantHandler(json_t *cmd, json_t* answer, void *data); TmEcode UnixSocketUnregisterTenantHandler(json_t *cmd, json_t* answer, void *data); TmEcode UnixSocketRegisterTenant(json_t *cmd, json_t* answer, void *data); diff --git a/src/unix-manager.c b/src/unix-manager.c index 1d408e4af2..4d0203d933 100644 --- a/src/unix-manager.c +++ b/src/unix-manager.c @@ -1088,6 +1088,7 @@ int UnixManagerInit(void) UnixManagerRegisterCommand("dataset-remove", UnixSocketDatasetRemove, &command, UNIX_CMD_TAKE_ARGS); UnixManagerRegisterCommand( "get-flow-stats-by-id", UnixSocketGetFlowStatsById, &command, UNIX_CMD_TAKE_ARGS); + UnixManagerRegisterCommand("dataset-dump", UnixSocketDatasetDump, NULL, 0); return 0; } -- 2.47.2