• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OISF / suricata / 23374838686

21 Mar 2026 07:29AM UTC coverage: 59.341% (-20.0%) from 79.315%
23374838686

Pull #15075

github

web-flow
Merge 90b4e834f into 6587e363a
Pull Request #15075: Stack 8001 v16.4

38 of 70 new or added lines in 10 files covered. (54.29%)

34165 existing lines in 563 files now uncovered.

119621 of 201584 relevant lines covered (59.34%)

650666.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/util-lua-dns.c
1
/* Copyright (C) 2014-2025 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 Eric Leblond <eric@regit.org>
22
 *
23
 */
24

25
#include "suricata-common.h"
26
#include "util-lua-dns.h"
27
#include "util-lua.h"
28
#include "util-lua-common.h"
29
#include "rust.h"
30

31
// #define DNS_MT "suricata:dns:tx"
32
static const char dns_tx[] = "suricata:dns:tx";
33

34
struct LuaTx {
35
    DNSTransaction *tx;
36
};
37

38
static int LuaDnsGetTx(lua_State *L)
UNCOV
39
{
×
UNCOV
40
    if (!(LuaStateNeedProto(L, ALPROTO_DNS))) {
×
41
        return LuaCallbackError(L, "error: protocol not dns");
×
42
    }
×
UNCOV
43
    DNSTransaction *tx = LuaStateGetTX(L);
×
UNCOV
44
    if (tx == NULL) {
×
45
        return LuaCallbackError(L, "error: no tx available");
×
46
    }
×
UNCOV
47
    struct LuaTx *ltx = (struct LuaTx *)lua_newuserdata(L, sizeof(*ltx));
×
UNCOV
48
    if (ltx == NULL) {
×
49
        return LuaCallbackError(L, "error: fail to allocate user data");
×
50
    }
×
UNCOV
51
    ltx->tx = tx;
×
52

UNCOV
53
    luaL_getmetatable(L, dns_tx);
×
UNCOV
54
    lua_setmetatable(L, -2);
×
55

UNCOV
56
    return 1;
×
UNCOV
57
}
×
58

59
static int LuaDnsTxGetRrname(lua_State *L)
UNCOV
60
{
×
UNCOV
61
    struct LuaTx *tx = luaL_testudata(L, 1, dns_tx);
×
UNCOV
62
    if (tx == NULL) {
×
63
        lua_pushnil(L);
×
64
        return 1;
×
65
    }
×
UNCOV
66
    return SCDnsLuaGetRrname(L, tx->tx);
×
UNCOV
67
}
×
68

69
static int LuaDnsTxGetTxid(lua_State *L)
UNCOV
70
{
×
UNCOV
71
    struct LuaTx *tx = luaL_testudata(L, 1, dns_tx);
×
UNCOV
72
    if (tx == NULL) {
×
73
        lua_pushnil(L);
×
74
        return 1;
×
75
    }
×
UNCOV
76
    return SCDnsLuaGetTxId(L, tx->tx);
×
UNCOV
77
}
×
78

79
static int LuaDnsTxGetRcode(lua_State *L)
UNCOV
80
{
×
UNCOV
81
    struct LuaTx *tx = luaL_testudata(L, 1, dns_tx);
×
UNCOV
82
    if (tx == NULL) {
×
83
        lua_pushnil(L);
×
84
        return 1;
×
85
    }
×
UNCOV
86
    return SCDnsLuaGetRcode(L, tx->tx);
×
UNCOV
87
}
×
88

89
static int LuaDnsTxGetRcodeString(lua_State *L)
UNCOV
90
{
×
UNCOV
91
    struct LuaTx *tx = luaL_testudata(L, 1, dns_tx);
×
UNCOV
92
    if (tx == NULL) {
×
93
        lua_pushnil(L);
×
94
        return 1;
×
95
    }
×
UNCOV
96
    return SCDnsLuaGetRcodeString(L, tx->tx);
×
UNCOV
97
}
×
98

99
static int LuaDnsTxGetRecursionDesired(lua_State *L)
100
{
×
101
    struct LuaTx *tx = luaL_testudata(L, 1, dns_tx);
×
102
    if (tx == NULL) {
×
103
        lua_pushnil(L);
×
104
        return 1;
×
105
    }
×
106
    uint16_t flags = SCDnsTxGetResponseFlags(tx->tx);
×
107
    int recursion_desired = flags & 0x0080 ? 1 : 0;
×
108
    lua_pushboolean(L, recursion_desired);
×
109
    return 1;
×
110
}
×
111

112
static int LuaDnsTxGetQueries(lua_State *L)
UNCOV
113
{
×
UNCOV
114
    struct LuaTx *tx = luaL_testudata(L, 1, dns_tx);
×
UNCOV
115
    if (tx == NULL) {
×
116
        lua_pushnil(L);
×
117
        return 1;
×
118
    }
×
UNCOV
119
    return SCDnsLuaGetQueryTable(L, tx->tx);
×
UNCOV
120
}
×
121

122
static int LuaDnsTxGetAnswers(lua_State *L)
UNCOV
123
{
×
UNCOV
124
    struct LuaTx *tx = luaL_testudata(L, 1, dns_tx);
×
UNCOV
125
    if (tx == NULL) {
×
126
        lua_pushnil(L);
×
127
        return 1;
×
128
    }
×
UNCOV
129
    return SCDnsLuaGetAnswerTable(L, tx->tx);
×
UNCOV
130
}
×
131

132
static int LuaDnsTxGetAuthorities(lua_State *L)
UNCOV
133
{
×
UNCOV
134
    struct LuaTx *tx = luaL_testudata(L, 1, dns_tx);
×
UNCOV
135
    if (tx == NULL) {
×
136
        lua_pushnil(L);
×
137
        return 1;
×
138
    }
×
UNCOV
139
    return SCDnsLuaGetAuthorityTable(L, tx->tx);
×
UNCOV
140
}
×
141

142
static const struct luaL_Reg txlib[] = {
143
    // clang-format off
144
    { "answers", LuaDnsTxGetAnswers },
145
    { "authorities", LuaDnsTxGetAuthorities },
146
    { "queries", LuaDnsTxGetQueries },
147
    { "rcode", LuaDnsTxGetRcode },
148
    { "rcode_string", LuaDnsTxGetRcodeString },
149
    { "recursion_desired", LuaDnsTxGetRecursionDesired },
150
    { "rrname", LuaDnsTxGetRrname },
151
    { "txid", LuaDnsTxGetTxid },
152
    { NULL, NULL, }
153
    // clang-format on
154
};
155

156
static const struct luaL_Reg dnslib[] = {
157
    // clang-format off
158
    { "get_tx", LuaDnsGetTx },
159
    { NULL, NULL,},
160
    // clang-format on
161
};
162

163
int SCLuaLoadDnsLib(lua_State *L)
UNCOV
164
{
×
UNCOV
165
    luaL_newmetatable(L, dns_tx);
×
UNCOV
166
    lua_pushvalue(L, -1);
×
UNCOV
167
    lua_setfield(L, -2, "__index");
×
UNCOV
168
    luaL_setfuncs(L, txlib, 0);
×
169

UNCOV
170
    luaL_newlib(L, dnslib);
×
UNCOV
171
    return 1;
×
UNCOV
172
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc