/src/suricata7/src/output-json-metadata.c
Line | Count | Source |
1 | | /* Copyright (C) 2013-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 Victor Julien <victor@inliniac.net> |
22 | | * |
23 | | * Logs vars in JSON format. |
24 | | * |
25 | | */ |
26 | | |
27 | | #include "suricata-common.h" |
28 | | #include "detect.h" |
29 | | #include "flow.h" |
30 | | #include "conf.h" |
31 | | |
32 | | #include "threads.h" |
33 | | #include "tm-threads.h" |
34 | | #include "threadvars.h" |
35 | | #include "util-debug.h" |
36 | | |
37 | | #include "util-misc.h" |
38 | | #include "util-unittest.h" |
39 | | #include "util-unittest-helper.h" |
40 | | |
41 | | #include "detect-parse.h" |
42 | | #include "detect-engine.h" |
43 | | #include "detect-engine-mpm.h" |
44 | | #include "detect-reference.h" |
45 | | #include "app-layer-parser.h" |
46 | | #include "app-layer-dnp3.h" |
47 | | #include "app-layer-htp.h" |
48 | | #include "app-layer-htp-xff.h" |
49 | | #include "util-classification-config.h" |
50 | | #include "util-syslog.h" |
51 | | #include "util-logopenfile.h" |
52 | | |
53 | | #include "output.h" |
54 | | #include "output-json.h" |
55 | | #include "output-json-metadata.h" |
56 | | |
57 | | #include "util-byte.h" |
58 | | #include "util-privs.h" |
59 | | #include "util-print.h" |
60 | | #include "util-proto-name.h" |
61 | | #include "util-optimize.h" |
62 | | #include "util-buffer.h" |
63 | | |
64 | 142 | #define MODULE_NAME "JsonMetadataLog" |
65 | | |
66 | | static int MetadataJson(ThreadVars *tv, OutputJsonThreadCtx *aft, const Packet *p) |
67 | 5 | { |
68 | 5 | JsonBuilder *js = CreateEveHeader(p, LOG_DIR_PACKET, "metadata", NULL, aft->ctx); |
69 | 5 | if (unlikely(js == NULL)) |
70 | 0 | return TM_ECODE_OK; |
71 | | |
72 | | /* If metadata is not enabled for eve, explicitly log it here as this is |
73 | | * what logging metadata is about. */ |
74 | 5 | if (!aft->ctx->cfg.include_metadata) { |
75 | 0 | EveAddMetadata(p, p->flow, js); |
76 | 0 | } |
77 | 5 | OutputJsonBuilderBuffer(js, aft); |
78 | | |
79 | 5 | jb_free(js); |
80 | 5 | return TM_ECODE_OK; |
81 | 5 | } |
82 | | |
83 | | static int JsonMetadataLogger(ThreadVars *tv, void *thread_data, const Packet *p) |
84 | 5 | { |
85 | 5 | OutputJsonThreadCtx *aft = thread_data; |
86 | | |
87 | 5 | return MetadataJson(tv, aft, p); |
88 | 5 | } |
89 | | |
90 | | static int JsonMetadataLogCondition(ThreadVars *tv, void *data, const Packet *p) |
91 | 8.50M | { |
92 | 8.50M | if (p->pktvar) { |
93 | 0 | return TRUE; |
94 | 0 | } |
95 | 8.50M | return FALSE; |
96 | 8.50M | } |
97 | | |
98 | | void JsonMetadataLogRegister (void) |
99 | 71 | { |
100 | 71 | OutputRegisterPacketSubModule(LOGGER_JSON_METADATA, "eve-log", MODULE_NAME, "eve-log.metadata", |
101 | 71 | OutputJsonLogInitSub, JsonMetadataLogger, JsonMetadataLogCondition, JsonLogThreadInit, |
102 | 71 | JsonLogThreadDeinit, NULL); |
103 | | |
104 | | /* Kept for compatibility. */ |
105 | 71 | OutputRegisterPacketSubModule(LOGGER_JSON_METADATA, "eve-log", MODULE_NAME, "eve-log.vars", |
106 | 71 | OutputJsonLogInitSub, JsonMetadataLogger, JsonMetadataLogCondition, JsonLogThreadInit, |
107 | | JsonLogThreadDeinit, NULL); |
108 | 71 | } |