/src/suricata8/src/output-json-nfs.c
Line | Count | Source |
1 | | /* Copyright (C) 2015-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 | | * Implement JSON/eve logging app-layer NFS. |
24 | | */ |
25 | | |
26 | | #include "suricata-common.h" |
27 | | #include "detect.h" |
28 | | #include "pkt-var.h" |
29 | | #include "conf.h" |
30 | | |
31 | | #include "threads.h" |
32 | | #include "threadvars.h" |
33 | | #include "tm-threads.h" |
34 | | |
35 | | #include "util-unittest.h" |
36 | | #include "util-buffer.h" |
37 | | #include "util-debug.h" |
38 | | #include "util-byte.h" |
39 | | |
40 | | #include "output.h" |
41 | | #include "output-json.h" |
42 | | |
43 | | #include "app-layer.h" |
44 | | #include "app-layer-parser.h" |
45 | | |
46 | | #include "output-json-nfs.h" |
47 | | |
48 | | #include "rust.h" |
49 | | |
50 | | bool EveNFSAddMetadataRPC(const Flow *f, uint64_t tx_id, SCJsonBuilder *jb) |
51 | 5.34k | { |
52 | 5.34k | NFSState *state = FlowGetAppState(f); |
53 | 5.34k | if (state) { |
54 | 5.34k | NFSTransaction *tx = AppLayerParserGetTx(f->proto, ALPROTO_NFS, state, tx_id); |
55 | 5.34k | if (tx) { |
56 | 5.34k | return SCNfsRpcLogJsonResponse(tx, jb); |
57 | 5.34k | } |
58 | 5.34k | } |
59 | 0 | return false; |
60 | 5.34k | } |
61 | | |
62 | | bool EveNFSAddMetadata(const Flow *f, uint64_t tx_id, SCJsonBuilder *jb) |
63 | 5.34k | { |
64 | 5.34k | NFSState *state = FlowGetAppState(f); |
65 | 5.34k | if (state) { |
66 | 5.34k | NFSTransaction *tx = AppLayerParserGetTx(f->proto, ALPROTO_NFS, state, tx_id); |
67 | 5.34k | if (tx) { |
68 | 5.34k | return SCNfsLogJsonResponse(state, tx, jb); |
69 | 5.34k | } |
70 | 5.34k | } |
71 | 0 | return false; |
72 | 5.34k | } |
73 | | |
74 | | static int JsonNFSLogger(ThreadVars *tv, void *thread_data, |
75 | | const Packet *p, Flow *f, void *state, void *tx, uint64_t tx_id) |
76 | 30.4k | { |
77 | 30.4k | NFSTransaction *nfstx = tx; |
78 | 30.4k | OutputJsonThreadCtx *thread = thread_data; |
79 | | |
80 | 30.4k | if (SCNfsTxLoggingIsFiltered(state, nfstx)) |
81 | 4.17k | return TM_ECODE_OK; |
82 | | |
83 | 26.2k | SCJsonBuilder *jb = CreateEveHeader(p, LOG_DIR_PACKET, "nfs", NULL, thread->ctx); |
84 | 26.2k | if (unlikely(jb == NULL)) { |
85 | 0 | return TM_ECODE_OK; |
86 | 0 | } |
87 | | |
88 | 26.2k | SCJbOpenObject(jb, "rpc"); |
89 | 26.2k | SCNfsRpcLogJsonResponse(tx, jb); |
90 | 26.2k | SCJbClose(jb); |
91 | | |
92 | 26.2k | SCJbOpenObject(jb, "nfs"); |
93 | 26.2k | SCNfsLogJsonResponse(state, tx, jb); |
94 | 26.2k | SCJbClose(jb); |
95 | | |
96 | 26.2k | MemBufferReset(thread->buffer); |
97 | 26.2k | OutputJsonBuilderBuffer(tv, p, p->flow, jb, thread); |
98 | 26.2k | SCJbFree(jb); |
99 | 26.2k | return TM_ECODE_OK; |
100 | 26.2k | } |
101 | | |
102 | | static OutputInitResult NFSLogInitSub(SCConfNode *conf, OutputCtx *parent_ctx) |
103 | 4 | { |
104 | 4 | SCAppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_NFS); |
105 | 4 | SCAppLayerParserRegisterLogger(IPPROTO_UDP, ALPROTO_NFS); |
106 | 4 | return OutputJsonLogInitSub(conf, parent_ctx); |
107 | 4 | } |
108 | | |
109 | | void JsonNFSLogRegister(void) |
110 | 78 | { |
111 | | /* Register as an eve sub-module. */ |
112 | 78 | OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonNFSLog", "eve-log.nfs", NFSLogInitSub, |
113 | 78 | ALPROTO_NFS, JsonNFSLogger, JsonLogThreadInit, JsonLogThreadDeinit); |
114 | | |
115 | 78 | SCLogDebug("NFS JSON logger registered."); |
116 | 78 | } |