/src/suricata7/src/output-json-sip.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright (C) 2018-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 Giuseppe Longo <giuseppe@glongo.it> |
22 | | * |
23 | | * Implement JSON/eve logging app-layer SIP. |
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 "app-layer-sip.h" |
47 | | #include "output-json-sip.h" |
48 | | |
49 | | #include "rust.h" |
50 | | |
51 | | void JsonSIPAddMetadata(JsonBuilder *js, const Flow *f, uint64_t tx_id) |
52 | 0 | { |
53 | 0 | SIPState *state = FlowGetAppState(f); |
54 | 0 | if (state) { |
55 | 0 | SIPTransaction *tx = AppLayerParserGetTx(f->proto, ALPROTO_SIP, state, tx_id); |
56 | 0 | if (tx) { |
57 | 0 | rs_sip_log_json(tx, js); |
58 | 0 | } |
59 | 0 | } |
60 | 0 | } |
61 | | |
62 | | static int JsonSIPLogger(ThreadVars *tv, void *thread_data, |
63 | | const Packet *p, Flow *f, void *state, void *tx, uint64_t tx_id) |
64 | 28 | { |
65 | 28 | SIPTransaction *siptx = tx; |
66 | 28 | OutputJsonThreadCtx *thread = thread_data; |
67 | | |
68 | 28 | JsonBuilder *js = CreateEveHeader((Packet *)p, LOG_DIR_PACKET, "sip", NULL, thread->ctx); |
69 | 28 | if (unlikely(js == NULL)) { |
70 | 0 | return TM_ECODE_OK; |
71 | 0 | } |
72 | | |
73 | 28 | if (!rs_sip_log_json(siptx, js)) { |
74 | 0 | goto error; |
75 | 0 | } |
76 | | |
77 | 28 | OutputJsonBuilderBuffer(js, thread); |
78 | 28 | jb_free(js); |
79 | | |
80 | 28 | return TM_ECODE_OK; |
81 | | |
82 | 0 | error: |
83 | 0 | jb_free(js); |
84 | 0 | return TM_ECODE_FAILED; |
85 | 28 | } |
86 | | |
87 | | static OutputInitResult OutputSIPLogInitSub(ConfNode *conf, |
88 | | OutputCtx *parent_ctx) |
89 | 2 | { |
90 | 2 | AppLayerParserRegisterLogger(IPPROTO_UDP, ALPROTO_SIP); |
91 | 2 | return OutputJsonLogInitSub(conf, parent_ctx); |
92 | 2 | } |
93 | | |
94 | | void JsonSIPLogRegister(void) |
95 | 33 | { |
96 | | /* Register as an eve sub-module. */ |
97 | 33 | OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonSIPLog", "eve-log.sip", |
98 | 33 | OutputSIPLogInitSub, ALPROTO_SIP, JsonSIPLogger, JsonLogThreadInit, JsonLogThreadDeinit, |
99 | 33 | NULL); |
100 | | |
101 | 33 | SCLogDebug("SIP JSON logger registered."); |
102 | 33 | } |