suricata
util-logopenfile.h
Go to the documentation of this file.
1/* Copyright (C) 2007-2021 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 Mike Pomraning <mpomraning@qualys.com>
22 */
23
24#ifndef SURICATA_UTIL_LOGOPENFILE_H
25#define SURICATA_UTIL_LOGOPENFILE_H
26
27#include "threads.h"
28#include "conf.h" /* ConfNode */
29#include "util-buffer.h"
30#include "util-hash.h"
31
32#ifdef HAVE_LIBHIREDIS
33#include "util-log-redis.h"
34#endif /* HAVE_LIBHIREDIS */
35
36#include "output-eve.h"
37
47
48typedef struct ThreadLogFileHashEntry {
50
51 uint64_t thread_id; /* OS thread identifier */
52 ThreadId internal_thread_id; /* Suri internal thread id; to assist output plugins correlating
53 usage */
54 uint16_t slot_number; /* Slot identifier - used when forming per-thread output names*/
55 bool isopen;
57
58struct LogFileCtx_;
64
70
71/** Global structure for Output Context */
72typedef struct LogFileCtx_ {
73 union {
74 FILE *fp;
75#ifdef HAVE_LIBHIREDIS
76 void *redis;
77#endif
78 };
80
81 union {
82#ifdef HAVE_LIBHIREDIS
83 RedisSetup redis_setup;
84#endif
85 };
86
87 int (*Write)(const char *buffer, int buffer_len, struct LogFileCtx_ *fp);
88 void (*Close)(struct LogFileCtx_ *fp);
89 void (*Flush)(struct LogFileCtx_ *fp);
90
92
93 /** It will be locked if the log/alert
94 * record cannot be written to the file in one call */
96
97 /** When threaded, track of the parent and thread id */
101
102 /** the type of file */
104
105 /** The name of the file */
106 char *filename;
107
108 /** File permissions */
109 uint32_t filemode;
110
111 /** File buffering */
112 uint32_t buffer_size;
113
114 /** Suricata sensor name */
116
117 /** Handle auto-connecting / reconnecting sockets */
120 uint64_t reconn_timer;
121
122 /** The next time to rotate log file, if rotate interval is
123 specified. */
125
126 /** The interval to rotate the log file */
128
129 /**< Used by some alert loggers like the unified ones that append
130 * the date onto the end of files. */
131 char *prefix;
132 uint32_t prefix_len;
133
134 /** Generic size_limit and size_current
135 * They must be common to the threads accessing the same file */
136 uint64_t size_limit; /**< file size limit */
137 uint64_t size_current; /**< file current size */
138
139 /* flag to avoid multiple threads printing the same stats */
140 uint8_t flags;
141
142 /* flags to set when sending over a socket */
143 uint8_t send_flags;
144
145 /* Flag if file is a regular file or not. Only regular files
146 * allow for rotation. */
147 uint8_t is_regular;
148
149 /* JSON flags */
150 size_t json_flags; /* passed to json_dump_callback() */
151
152 /* Flag set when file rotation notification is received. */
154
155 /* if set to true EVE will add a pcap file record */
157
158 /* Socket types may need to drop events to keep from blocking
159 * Suricata. */
160 uint64_t dropped;
161
163
164 /* Track buffered content */
167
168/* Min time (msecs) before trying to reconnect a Unix domain socket */
169#define LOGFILE_RECONN_MIN_TIME 500
170
171/* flags for LogFileCtx */
172#define LOGFILE_ROTATE_INTERVAL 0x04
173
174/* Default EVE output buffering size */
175#define LOGFILE_EVE_BUFFER_SIZE 0
176
179int LogFileWrite(LogFileCtx *file_ctx, MemBuffer *buffer);
180void LogFileFlush(LogFileCtx *file_ctx);
181
183int SCConfLogOpenGeneric(SCConfNode *conf, LogFileCtx *, const char *, int);
185bool SCLogOpenThreadedFile(const char *log_path, const char *append, LogFileCtx *parent_ctx);
186
187#endif /* SURICATA_UTIL_LOGOPENFILE_H */
EVE logging subsystem.
uint32_t ThreadId
Definition output-eve.h:37
uint64_t reconn_timer
uint64_t rotate_interval
uint32_t prefix_len
uint64_t bytes_since_last_flush
uint64_t output_errors
LogFileTypeCtx filetype
int(* Write)(const char *buffer, int buffer_len, struct LogFileCtx_ *fp)
enum LogFileType type
struct LogFileCtx_ * parent
void(* Flush)(struct LogFileCtx_ *fp)
uint64_t size_current
uint32_t buffer_size
LogThreadedFileCtx * threads
uint64_t size_limit
void(* Close)(struct LogFileCtx_ *fp)
ThreadLogFileHashEntry * entry
SCEveFileType * filetype
Structure used to define an EVE output file type plugin.
Definition output-eve.h:74
struct LogFileCtx_ * ctx
#define SCMutex
struct LogThreadedFileCtx_ LogThreadedFileCtx
int LogFileWrite(LogFileCtx *file_ctx, MemBuffer *buffer)
bool SCLogOpenThreadedFile(const char *log_path, const char *append, LogFileCtx *parent_ctx)
LogFileType
@ LOGFILE_TYPE_REDIS
@ LOGFILE_TYPE_FILETYPE
@ LOGFILE_TYPE_FILE
@ LOGFILE_TYPE_UNIX_STREAM
@ LOGFILE_TYPE_NOTSET
@ LOGFILE_TYPE_UNIX_DGRAM
int SCConfLogReopen(LogFileCtx *)
Reopen a regular log file with the side-affect of truncating it.
LogFileCtx * LogFileNewCtx(void)
LogFileNewCtx() Get a new LogFileCtx.
void LogFileFlush(LogFileCtx *file_ctx)
struct LogFileTypeCtx_ LogFileTypeCtx
LogFileCtx * LogFileEnsureExists(ThreadId thread_id, LogFileCtx *lf_ctx)
LogFileEnsureExists() Ensure a log file context for the thread exists.
struct LogFileCtx_ LogFileCtx
int SCConfLogOpenGeneric(SCConfNode *conf, LogFileCtx *, const char *, int)
open a generic output "log file", which may be a regular file or a socket
int LogFileFreeCtx(LogFileCtx *)
LogFileFreeCtx() Destroy a LogFileCtx (Close the file and free memory)