suricata
output-json-nfs.c
Go to the documentation of this file.
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-buffer.h"
36 #include "util-debug.h"
37 #include "util-byte.h"
38 
39 #include "output.h"
40 #include "output-json.h"
41 
42 #include "app-layer.h"
43 #include "app-layer-parser.h"
44 
45 #include "output-json-nfs.h"
46 
47 #include "rust.h"
48 
49 bool EveNFSAddMetadataRPC(const Flow *f, uint64_t tx_id, SCJsonBuilder *jb)
50 {
51  NFSState *state = FlowGetAppState(f);
52  if (state) {
53  NFSTransaction *tx = AppLayerParserGetTx(f->proto, ALPROTO_NFS, state, tx_id);
54  if (tx) {
55  return SCNfsRpcLogJsonResponse(tx, jb);
56  }
57  }
58  return false;
59 }
60 
61 bool EveNFSAddMetadata(const Flow *f, uint64_t tx_id, SCJsonBuilder *jb)
62 {
63  NFSState *state = FlowGetAppState(f);
64  if (state) {
65  NFSTransaction *tx = AppLayerParserGetTx(f->proto, ALPROTO_NFS, state, tx_id);
66  if (tx) {
67  return SCNfsLogJsonResponse(state, tx, jb);
68  }
69  }
70  return false;
71 }
72 
73 static int JsonNFSLogger(ThreadVars *tv, void *thread_data,
74  const Packet *p, Flow *f, void *state, void *tx, uint64_t tx_id)
75 {
76  NFSTransaction *nfstx = tx;
77  OutputJsonThreadCtx *thread = thread_data;
78 
79  if (SCNfsTxLoggingIsFiltered(state, nfstx))
80  return TM_ECODE_OK;
81 
82  SCJsonBuilder *jb = CreateEveHeader(p, LOG_DIR_PACKET, "nfs", NULL, thread->ctx);
83  if (unlikely(jb == NULL)) {
84  return TM_ECODE_OK;
85  }
86 
87  SCJbOpenObject(jb, "rpc");
88  SCNfsRpcLogJsonResponse(tx, jb);
89  SCJbClose(jb);
90 
91  SCJbOpenObject(jb, "nfs");
92  SCNfsLogJsonResponse(state, tx, jb);
93  SCJbClose(jb);
94 
95  MemBufferReset(thread->buffer);
96  OutputJsonBuilderBuffer(tv, p, p->flow, jb, thread);
97  SCJbFree(jb);
98  return TM_ECODE_OK;
99 }
100 
101 static OutputInitResult NFSLogInitSub(SCConfNode *conf, OutputCtx *parent_ctx)
102 {
105  return OutputJsonLogInitSub(conf, parent_ctx);
106 }
107 
109 {
110  /* Register as an eve sub-module. */
111  OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonNFSLog", "eve-log.nfs", NFSLogInitSub,
113 
114  SCLogDebug("NFS JSON logger registered.");
115 }
SCJsonBuilder
struct SCJsonBuilder SCJsonBuilder
Definition: detect-engine-helper.h:83
util-byte.h
tm-threads.h
OutputJsonThreadCtx_::ctx
OutputJsonCtx * ctx
Definition: output-json.h:86
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:282
Flow_::proto
uint8_t proto
Definition: flow.h:381
CreateEveHeader
SCJsonBuilder * CreateEveHeader(const Packet *p, enum SCOutputJsonLogDirection dir, const char *event_type, JsonAddrInfo *addr, OutputJsonCtx *eve_ctx)
Definition: output-json.c:816
JsonLogThreadInit
TmEcode JsonLogThreadInit(ThreadVars *t, const void *initdata, void **data)
Definition: output-json-common.c:90
threads.h
Flow_
Flow data structure.
Definition: flow.h:359
OutputRegisterTxSubModule
void OutputRegisterTxSubModule(LoggerId id, const char *parent_name, const char *name, const char *conf_name, OutputInitSubFunc InitFunc, AppProto alproto, TxLogger TxLogFunc, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Definition: output.c:411
rust.h
p
Packet * p
Definition: fuzz_dataset.c:30
OutputJsonBuilderBuffer
void OutputJsonBuilderBuffer(ThreadVars *tv, const Packet *p, Flow *f, SCJsonBuilder *js, OutputJsonThreadCtx *ctx)
Definition: output-json.c:1018
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:81
OutputCtx_
Definition: tm-modules.h:88
OutputJsonThreadCtx_
Definition: output-json.h:85
OutputJsonLogInitSub
OutputInitResult OutputJsonLogInitSub(SCConfNode *conf, OutputCtx *parent_ctx)
Definition: output-json-common.c:73
util-debug.h
SCAppLayerParserRegisterLogger
void SCAppLayerParserRegisterLogger(uint8_t ipproto, AppProto alproto)
Definition: app-layer-parser.c:535
output-json.h
EveNFSAddMetadata
bool EveNFSAddMetadata(const Flow *f, uint64_t tx_id, SCJsonBuilder *jb)
Definition: output-json-nfs.c:61
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
pkt-var.h
EveNFSAddMetadataRPC
bool EveNFSAddMetadataRPC(const Flow *f, uint64_t tx_id, SCJsonBuilder *jb)
Definition: output-json-nfs.c:49
app-layer-parser.h
Packet_
Definition: decode.h:516
conf.h
AppLayerParserGetTx
void * AppLayerParserGetTx(uint8_t ipproto, AppProto alproto, void *alstate, uint64_t tx_id)
Definition: app-layer-parser.c:1219
OutputInitResult_
Definition: output.h:46
Packet_::flow
struct Flow_ * flow
Definition: decode.h:564
OutputJsonThreadCtx_::buffer
MemBuffer * buffer
Definition: output-json.h:88
suricata-common.h
output-json-nfs.h
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:34
threadvars.h
LOGGER_JSON_TX
@ LOGGER_JSON_TX
Definition: suricata-common.h:489
util-buffer.h
LOG_DIR_PACKET
@ LOG_DIR_PACKET
Definition: output-eve-bindgen.h:34
JsonLogThreadDeinit
TmEcode JsonLogThreadDeinit(ThreadVars *t, void *data)
Definition: output-json-common.c:123
SCConfNode_
Definition: conf.h:37
ALPROTO_NFS
@ ALPROTO_NFS
Definition: app-layer-protos.h:51
output.h
JsonNFSLogRegister
void JsonNFSLogRegister(void)
Definition: output-json-nfs.c:108
app-layer.h
f
Flow f
Definition: fuzz_dataset.c:32