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-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
50bool EveNFSAddMetadataRPC(const Flow *f, uint64_t tx_id, SCJsonBuilder *jb)
51{
52 NFSState *state = FlowGetAppState(f);
53 if (state) {
54 NFSTransaction *tx = AppLayerParserGetTx(f->proto, ALPROTO_NFS, state, tx_id);
55 if (tx) {
56 return SCNfsRpcLogJsonResponse(tx, jb);
57 }
58 }
59 return false;
60}
61
62bool EveNFSAddMetadata(const Flow *f, uint64_t tx_id, SCJsonBuilder *jb)
63{
64 NFSState *state = FlowGetAppState(f);
65 if (state) {
66 NFSTransaction *tx = AppLayerParserGetTx(f->proto, ALPROTO_NFS, state, tx_id);
67 if (tx) {
68 return SCNfsLogJsonResponse(state, tx, jb);
69 }
70 }
71 return false;
72}
73
74static int JsonNFSLogger(ThreadVars *tv, void *thread_data,
75 const Packet *p, Flow *f, void *state, void *tx, uint64_t tx_id)
76{
77 NFSTransaction *nfstx = tx;
78 OutputJsonThreadCtx *thread = thread_data;
79
80 if (SCNfsTxLoggingIsFiltered(state, nfstx))
81 return TM_ECODE_OK;
82
83 SCJsonBuilder *jb = CreateEveHeader(p, LOG_DIR_PACKET, "nfs", NULL, thread->ctx);
84 if (unlikely(jb == NULL)) {
85 return TM_ECODE_OK;
86 }
87
88 SCJbOpenObject(jb, "rpc");
89 SCNfsRpcLogJsonResponse(tx, jb);
90 SCJbClose(jb);
91
92 SCJbOpenObject(jb, "nfs");
93 SCNfsLogJsonResponse(state, tx, jb);
94 SCJbClose(jb);
95
96 MemBufferReset(thread->buffer);
97 OutputJsonBuilderBuffer(tv, p, p->flow, jb, thread);
98 SCJbFree(jb);
99 return TM_ECODE_OK;
100}
101
102static OutputInitResult NFSLogInitSub(SCConfNode *conf, OutputCtx *parent_ctx)
103{
106 return OutputJsonLogInitSub(conf, parent_ctx);
107}
108
110{
111 /* Register as an eve sub-module. */
112 OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonNFSLog", "eve-log.nfs", NFSLogInitSub,
114
115 SCLogDebug("NFS JSON logger registered.");
116}
void * AppLayerParserGetTx(uint8_t ipproto, AppProto alproto, void *alstate, uint64_t tx_id)
void SCAppLayerParserRegisterLogger(uint8_t ipproto, AppProto alproto)
@ ALPROTO_NFS
ThreadVars * tv
@ LOG_DIR_PACKET
OutputInitResult OutputJsonLogInitSub(SCConfNode *conf, OutputCtx *parent_ctx)
TmEcode JsonLogThreadInit(ThreadVars *t, const void *initdata, void **data)
TmEcode JsonLogThreadDeinit(ThreadVars *t, void *data)
void JsonNFSLogRegister(void)
bool EveNFSAddMetadataRPC(const Flow *f, uint64_t tx_id, SCJsonBuilder *jb)
bool EveNFSAddMetadata(const Flow *f, uint64_t tx_id, SCJsonBuilder *jb)
SCJsonBuilder * CreateEveHeader(const Packet *p, enum SCOutputJsonLogDirection dir, const char *event_type, JsonAddrInfo *addr, OutputJsonCtx *eve_ctx)
void OutputJsonBuilderBuffer(ThreadVars *tv, const Packet *p, Flow *f, SCJsonBuilder *js, OutputJsonThreadCtx *ctx)
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:406
Flow data structure.
Definition flow.h:356
uint8_t proto
Definition flow.h:378
OutputJsonCtx * ctx
Definition output-json.h:84
struct Flow_ * flow
Definition decode.h:546
Per thread variable structure.
Definition threadvars.h:58
@ LOGGER_JSON_TX
@ TM_ECODE_OK
#define SCLogDebug(...)
Definition util-debug.h:275
#define unlikely(expr)