/src/suricata7/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, JsonBuilder *jb) |
51 | 9.20k | { |
52 | 9.20k | NFSState *state = FlowGetAppState(f); |
53 | 9.20k | if (state) { |
54 | 9.20k | NFSTransaction *tx = AppLayerParserGetTx(f->proto, ALPROTO_NFS, state, tx_id); |
55 | 9.20k | if (tx) { |
56 | 9.20k | return rs_rpc_log_json_response(tx, jb); |
57 | 9.20k | } |
58 | 9.20k | } |
59 | 0 | return false; |
60 | 9.20k | } |
61 | | |
62 | | bool EveNFSAddMetadata(const Flow *f, uint64_t tx_id, JsonBuilder *jb) |
63 | 9.20k | { |
64 | 9.20k | NFSState *state = FlowGetAppState(f); |
65 | 9.20k | if (state) { |
66 | 9.20k | NFSTransaction *tx = AppLayerParserGetTx(f->proto, ALPROTO_NFS, state, tx_id); |
67 | 9.20k | if (tx) { |
68 | 9.20k | return rs_nfs_log_json_response(state, tx, jb); |
69 | 9.20k | } |
70 | 9.20k | } |
71 | 0 | return false; |
72 | 9.20k | } |
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 | 33.0k | { |
77 | 33.0k | NFSTransaction *nfstx = tx; |
78 | 33.0k | OutputJsonThreadCtx *thread = thread_data; |
79 | | |
80 | 33.0k | if (rs_nfs_tx_logging_is_filtered(state, nfstx)) |
81 | 6.54k | return TM_ECODE_OK; |
82 | | |
83 | 26.5k | JsonBuilder *jb = CreateEveHeader(p, LOG_DIR_PACKET, "nfs", NULL, thread->ctx); |
84 | 26.5k | if (unlikely(jb == NULL)) { |
85 | 0 | return TM_ECODE_OK; |
86 | 0 | } |
87 | | |
88 | 26.5k | jb_open_object(jb, "rpc"); |
89 | 26.5k | rs_rpc_log_json_response(tx, jb); |
90 | 26.5k | jb_close(jb); |
91 | | |
92 | 26.5k | jb_open_object(jb, "nfs"); |
93 | 26.5k | rs_nfs_log_json_response(state, tx, jb); |
94 | 26.5k | jb_close(jb); |
95 | | |
96 | 26.5k | MemBufferReset(thread->buffer); |
97 | 26.5k | OutputJsonBuilderBuffer(jb, thread); |
98 | 26.5k | jb_free(jb); |
99 | 26.5k | return TM_ECODE_OK; |
100 | 26.5k | } |
101 | | |
102 | | static OutputInitResult NFSLogInitSub(ConfNode *conf, |
103 | | OutputCtx *parent_ctx) |
104 | 4 | { |
105 | 4 | AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_NFS); |
106 | 4 | AppLayerParserRegisterLogger(IPPROTO_UDP, ALPROTO_NFS); |
107 | 4 | return OutputJsonLogInitSub(conf, parent_ctx); |
108 | 4 | } |
109 | | |
110 | | void JsonNFSLogRegister(void) |
111 | 71 | { |
112 | | /* Register as an eve sub-module. */ |
113 | 71 | OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonNFSLog", "eve-log.nfs", NFSLogInitSub, |
114 | 71 | ALPROTO_NFS, JsonNFSLogger, JsonLogThreadInit, JsonLogThreadDeinit, NULL); |
115 | | |
116 | 71 | SCLogDebug("NFS JSON logger registered."); |
117 | 71 | } |