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
64typedef 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
71typedef 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
83int LogCustomFormatParse(LogCustomFormat *cf, const char *format);
84
85void LogCustomFormatWriteTimestamp(MemBuffer *buffer, const char *fmt, const SCTime_t ts);
87
88#endif /* SURICATA_LOG_CF_COMMON_H */
void LogCustomFormatRegister(void)
void LogCustomFormatWriteTimestamp(MemBuffer *buffer, const char *fmt, const SCTime_t ts)
Writes a timestamp with given format into a MemBuffer.
void LogCustomFormatNodeFree(LogCustomFormatNode *node)
Frees memory held by a custom format node.
struct LogCustomFormatNode_ LogCustomFormatNode
void LogCustomFormatFree(LogCustomFormat *cf)
Frees memory held by a custom format.
LogCustomFormatNode * LogCustomFormatNodeAlloc(void)
Creates a custom format node.
void LogCustomFormatAddNode(LogCustomFormat *cf, LogCustomFormatNode *node)
Adds a node to custom format.
#define LOG_NODE_STRLEN
LogCustomFormat * LogCustomFormatAlloc(void)
Creates a custom format.
#define LOG_MAXN_NODES
int LogCustomFormatParse(LogCustomFormat *cf, const char *format)
Parses and saves format nodes for custom format.
struct LogCustomFormat_ LogCustomFormat
uint64_t ts
char data[LOG_NODE_STRLEN]
LogCustomFormatNode * cf_nodes[LOG_MAXN_NODES]