suricata
log-cf-common.h
Go to the documentation of this file.
1 /* Copyright (C) 2016 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 Victor Julien <victor@inliniac.net>
22  * \author Ignacio Sanchez <sanchezmartin.ji@gmail.com>
23  * \author Paulo Pacheco <fooinha@gmail.com>
24  *
25  * Common custom logging format
26  */
27 
28 #ifndef SURICATA_LOG_CF_COMMON_H
29 #define SURICATA_LOG_CF_COMMON_H
30 
31 #define LOG_MAXN_NODES 64
32 #define LOG_NODE_STRLEN 256
33 #define LOG_NODE_MAXOUTPUTLEN 8192
34 
35 #define TIMESTAMP_DEFAULT_FORMAT "%D-%H:%M:%S"
36 
37 /* Common format nodes */
38 #define LOG_CF_NONE "-"
39 #define LOG_CF_LITERAL '%'
40 #define LOG_CF_TIMESTAMP 't'
41 #define LOG_CF_TIMESTAMP_U 'z'
42 #define LOG_CF_CLIENT_IP 'a'
43 #define LOG_CF_SERVER_IP 'A'
44 #define LOG_CF_CLIENT_PORT 'p'
45 #define LOG_CF_SERVER_PORT 'P'
46 
47 /* Line log common separators **/
48 #define LOG_CF_STAR_SEPARATOR "[**]"
49 #define LOG_CF_SPACE_SEPARATOR " "
50 #define LOG_CF_UNKNOWN_VALUE "-"
51 
52 #define LOG_CF_WRITE_STAR_SEPARATOR(buffer) MemBufferWriteString(buffer, LOG_CF_STAR_SEPARATOR);
53 
54 #define LOG_CF_WRITE_SPACE_SEPARATOR(buffer) \
55  MemBufferWriteString(buffer, LOG_CF_SPACE_SEPARATOR);
56 
57 #define LOG_CF_WRITE_UNKNOWN_VALUE(buffer) \
58  MemBufferWriteString(buffer, LOG_CF_UNKNOWN_VALUE);
59 
60 /* Include */
61 #include "suricata-common.h"
62 #include "util-buffer.h"
63 
64 typedef struct LogCustomFormatNode_ {
65  uint32_t type; /**< Node format type. ie: LOG_CF_LITERAL, ... */
66  uint32_t maxlen; /**< Maximum length of the data */
67  char data[LOG_NODE_STRLEN]; /**< optional data. ie: http header name */
69 
70 
71 typedef struct LogCustomFormat_ {
72  uint32_t cf_n; /**< Total number of custom string format nodes */
73  LogCustomFormatNode *cf_nodes[LOG_MAXN_NODES]; /**< Custom format string nodes */
75 
78 
81 
83 int LogCustomFormatParse(LogCustomFormat *cf, const char *format);
84 
85 void LogCustomFormatWriteTimestamp(MemBuffer *buffer, const char *fmt, const SCTime_t ts);
86 void LogCustomFormatRegister(void);
87 
88 #endif /* SURICATA_LOG_CF_COMMON_H */
ts
uint64_t ts
Definition: source-erf-file.c:55
LogCustomFormatAddNode
void LogCustomFormatAddNode(LogCustomFormat *cf, LogCustomFormatNode *node)
Adds a node to custom format.
Definition: log-cf-common.c:185
LogCustomFormatFree
void LogCustomFormatFree(LogCustomFormat *cf)
Frees memory held by a custom format.
Definition: log-cf-common.c:80
LOG_MAXN_NODES
#define LOG_MAXN_NODES
Definition: log-cf-common.h:31
LogCustomFormatRegister
void LogCustomFormatRegister(void)
Definition: log-cf-common.c:271
LogCustomFormatWriteTimestamp
void LogCustomFormatWriteTimestamp(MemBuffer *buffer, const char *fmt, const SCTime_t ts)
Writes a timestamp with given format into a MemBuffer.
Definition: log-cf-common.c:211
LogCustomFormat_::cf_n
uint32_t cf_n
Definition: log-cf-common.h:72
LogCustomFormatNode_
Definition: log-cf-common.h:64
LogCustomFormatNode_::type
uint32_t type
Definition: log-cf-common.h:65
LOG_NODE_STRLEN
#define LOG_NODE_STRLEN
Definition: log-cf-common.h:32
SCTime_t
Definition: util-time.h:40
LogCustomFormatParse
int LogCustomFormatParse(LogCustomFormat *cf, const char *format)
Parses and saves format nodes for custom format.
Definition: log-cf-common.c:96
LogCustomFormatNode
struct LogCustomFormatNode_ LogCustomFormatNode
LogCustomFormatNode_::maxlen
uint32_t maxlen
Definition: log-cf-common.h:66
MemBuffer_
Definition: util-buffer.h:27
LogCustomFormat_
Definition: log-cf-common.h:71
LogCustomFormatNode_::data
char data[LOG_NODE_STRLEN]
Definition: log-cf-common.h:67
LogCustomFormatNodeFree
void LogCustomFormatNodeFree(LogCustomFormatNode *node)
Frees memory held by a custom format node.
Definition: log-cf-common.c:68
suricata-common.h
LogCustomFormatNodeAlloc
LogCustomFormatNode * LogCustomFormatNodeAlloc(void)
Creates a custom format node.
Definition: log-cf-common.c:39
util-buffer.h
LogCustomFormat_::cf_nodes
LogCustomFormatNode * cf_nodes[LOG_MAXN_NODES]
Definition: log-cf-common.h:73
LogCustomFormatAlloc
LogCustomFormat * LogCustomFormatAlloc(void)
Creates a custom format.
Definition: log-cf-common.c:54
LogCustomFormat
struct LogCustomFormat_ LogCustomFormat