suricata
util-log-redis.h
Go to the documentation of this file.
1 /* Copyright (C) 2016-2024 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Paulo Pacheco <fooinha@gmail.com>
22  */
23 
24 #ifndef SURICATA_UTIL_LOG_REDIS_H
25 #define SURICATA_UTIL_LOG_REDIS_H
26 
27 #ifdef HAVE_LIBHIREDIS
28 #include <hiredis/hiredis.h>
29 
30 
31 #ifdef HAVE_LIBEVENT
32 #include <hiredis/async.h>
33 #endif /* HAVE_LIBEVENT */
34 
35 #include "conf.h" /* ConfNode */
36 
37 enum RedisMode { REDIS_LIST, REDIS_CHANNEL };
38 
39 typedef struct RedisSetup_ {
40  enum RedisMode mode;
41  const char *format;
42  const char *command;
43  const char *key;
44  const char *username;
45  const char *password;
46  const char *server;
47  uint16_t port;
48  int is_async;
49  int batch_size;
50  char *stream_format;
51 } RedisSetup;
52 
53 #if HAVE_LIBEVENT
54 enum RedisConnState {
55  /** The context is not connected to the Redis server. */
56  REDIS_STATE_DISCONNECTED,
57 
58  /** The ECHO command failed, possibly due to requiring authentication. */
59  REDIS_STATE_ECHO_FAILED,
60 
61  /** A connection to the Redis server has been established.
62  * If authentication is not required, this is the final state where data can be safely sent.
63  * If authentication is required, the client must proceed to authenticate before sending data.
64  */
65  REDIS_STATE_CONNECTED,
66 
67  /** Authentication with the Redis server failed. */
68  REDIS_STATE_AUTH_FAILED,
69 
70  /** The connection is fully authenticated, and ready to send data. */
71  REDIS_STATE_AUTHENTICATED,
72 };
73 #endif /* HAVE_LIBEVENT */
74 
75 typedef struct SCLogRedisContext_ {
76  redisContext *sync;
77 #if HAVE_LIBEVENT
78  redisAsyncContext *async;
79  struct event_base *ev_base;
80  enum RedisConnState state;
81 #endif /* HAVE_LIBEVENT */
82  time_t tried;
83  int batch_count;
84  time_t last_push;
85 } SCLogRedisContext;
86 
87 void SCLogRedisInit(void);
88 int SCConfLogOpenRedis(SCConfNode *, void *);
89 int LogFileWriteRedis(void *, const char *, size_t);
90 
91 #endif /* HAVE_LIBHIREDIS */
92 #endif /* SURICATA_UTIL_LOG_REDIS_H */
conf.h
SCConfNode_
Definition: conf.h:37