Coverage Report

Created: 2025-07-23 07:29

/src/suricata7/src/output-json-tftp.c
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (C) 2020-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 Clément Galland <clement.galland@epita.fr>
22
 *
23
 * Implement JSON/eve logging app-layer TFTP.
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-tftp.h"
47
#include "output-json-tftp.h"
48
49
#include "rust.h"
50
51
static int JsonTFTPLogger(ThreadVars *tv, void *thread_data,
52
    const Packet *p, Flow *f, void *state, void *tx, uint64_t tx_id)
53
16
{
54
16
    OutputJsonThreadCtx *thread = thread_data;
55
56
16
    JsonBuilder *jb = CreateEveHeader(p, LOG_DIR_PACKET, "tftp", NULL, thread->ctx);
57
16
    if (unlikely(jb == NULL)) {
58
0
        return TM_ECODE_FAILED;
59
0
    }
60
61
16
    jb_open_object(jb, "tftp");
62
16
    if (unlikely(!rs_tftp_log_json_request(tx, jb))) {
63
0
        goto error;
64
0
    }
65
16
    jb_close(jb);
66
67
16
    OutputJsonBuilderBuffer(jb, thread);
68
69
16
    jb_free(jb);
70
16
    return TM_ECODE_OK;
71
72
0
error:
73
0
    jb_free(jb);
74
0
    return TM_ECODE_FAILED;
75
16
}
76
77
static OutputInitResult OutputTFTPLogInitSub(ConfNode *conf,
78
    OutputCtx *parent_ctx)
79
2
{
80
2
    AppLayerParserRegisterLogger(IPPROTO_UDP, ALPROTO_TFTP);
81
2
    return OutputJsonLogInitSub(conf, parent_ctx);
82
2
}
83
84
void JsonTFTPLogRegister(void)
85
33
{
86
    /* Register as an eve sub-module. */
87
33
    OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonTFTPLog", "eve-log.tftp",
88
33
            OutputTFTPLogInitSub, ALPROTO_TFTP, JsonTFTPLogger, JsonLogThreadInit,
89
33
            JsonLogThreadDeinit, NULL);
90
91
33
    SCLogDebug("TFTP JSON logger registered.");
92
33
}