• 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-rule.c
1
/* Copyright (C) 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
#include "suricata-common.h"
19
#include "action-globals.h"
20
#include "app-layer.h"
21
#include "util-lua-rule.h"
22
#include "util-lua-common.h"
23
#include "util-lua.h"
24

25
#include "lauxlib.h"
26

27
static const char suricata_rule_mt[] = "suricata:rule:mt";
28

29
static int LuaRuleGetRule(lua_State *L)
UNCOV
30
{
×
UNCOV
31
    const PacketAlert *pa = LuaStateGetPacketAlert(L);
×
UNCOV
32
    const Signature *s = NULL;
×
UNCOV
33
    if (pa != NULL) {
×
UNCOV
34
        s = pa->s;
×
UNCOV
35
    } else {
×
UNCOV
36
        s = LuaStateGetSignature(L);
×
UNCOV
37
    }
×
UNCOV
38
    if (s == NULL) {
×
39
        return LuaCallbackError(L, "internal error: no packet alert or signature");
×
40
    }
×
41

UNCOV
42
    void **p = lua_newuserdata(L, sizeof(*p));
×
UNCOV
43
    if (p == NULL) {
×
44
        return LuaCallbackError(L, "error: failed to allocate user data");
×
45
    }
×
UNCOV
46
    *p = (void *)s;
×
47

UNCOV
48
    luaL_getmetatable(L, suricata_rule_mt);
×
UNCOV
49
    lua_setmetatable(L, -2);
×
50

UNCOV
51
    return 1;
×
UNCOV
52
}
×
53

54
static int LuaRuleGetSid(lua_State *L)
UNCOV
55
{
×
UNCOV
56
    void **data = luaL_testudata(L, 1, suricata_rule_mt);
×
UNCOV
57
    if (data == NULL) {
×
58
        lua_pushnil(L);
×
59
        return 1;
×
60
    }
×
UNCOV
61
    const Signature *s = *data;
×
UNCOV
62
    lua_pushinteger(L, s->id);
×
UNCOV
63
    return 1;
×
UNCOV
64
}
×
65

66
static int LuaRuleGetGid(lua_State *L)
UNCOV
67
{
×
UNCOV
68
    void **data = luaL_testudata(L, 1, suricata_rule_mt);
×
UNCOV
69
    if (data == NULL) {
×
70
        lua_pushnil(L);
×
71
        return 1;
×
72
    }
×
UNCOV
73
    const Signature *s = *data;
×
UNCOV
74
    lua_pushinteger(L, s->gid);
×
UNCOV
75
    return 1;
×
UNCOV
76
}
×
77

78
static int LuaRuleGetRev(lua_State *L)
UNCOV
79
{
×
UNCOV
80
    void **data = luaL_testudata(L, 1, suricata_rule_mt);
×
UNCOV
81
    if (data == NULL) {
×
82
        lua_pushnil(L);
×
83
        return 1;
×
84
    }
×
UNCOV
85
    const Signature *s = *data;
×
UNCOV
86
    lua_pushinteger(L, s->rev);
×
UNCOV
87
    return 1;
×
UNCOV
88
}
×
89

90
static int LuaRuleGetAction(lua_State *L)
UNCOV
91
{
×
UNCOV
92
    void **data = luaL_testudata(L, 1, suricata_rule_mt);
×
UNCOV
93
    if (data == NULL) {
×
94
        lua_pushnil(L);
×
95
        return 1;
×
96
    }
×
UNCOV
97
    const Signature *s = *data;
×
98

UNCOV
99
    const char *action = "";
×
UNCOV
100
    if (s->action & ACTION_PASS) {
×
101
        action = "pass";
×
UNCOV
102
    } else if ((s->action & ACTION_REJECT) || (s->action & ACTION_REJECT_BOTH) ||
×
UNCOV
103
               (s->action & ACTION_REJECT_DST)) {
×
104
        action = "reject";
×
UNCOV
105
    } else if (s->action & ACTION_DROP) {
×
UNCOV
106
        action = "drop";
×
UNCOV
107
    } else if (s->action & ACTION_ALERT) {
×
UNCOV
108
        action = "alert";
×
UNCOV
109
    }
×
UNCOV
110
    lua_pushstring(L, action);
×
UNCOV
111
    return 1;
×
UNCOV
112
}
×
113

114
static int LuaRuleGetMsg(lua_State *L)
UNCOV
115
{
×
UNCOV
116
    void **data = luaL_testudata(L, 1, suricata_rule_mt);
×
UNCOV
117
    if (data == NULL) {
×
118
        lua_pushnil(L);
×
119
        return 1;
×
120
    }
×
UNCOV
121
    const Signature *s = *data;
×
UNCOV
122
    lua_pushstring(L, s->msg);
×
UNCOV
123
    return 1;
×
UNCOV
124
}
×
125

126
static int LuaRuleGetClassDescription(lua_State *L)
UNCOV
127
{
×
UNCOV
128
    void **data = luaL_testudata(L, 1, suricata_rule_mt);
×
UNCOV
129
    if (data == NULL) {
×
130
        lua_pushnil(L);
×
131
        return 1;
×
132
    }
×
UNCOV
133
    const Signature *s = *data;
×
UNCOV
134
    lua_pushstring(L, s->class_msg);
×
UNCOV
135
    return 1;
×
UNCOV
136
}
×
137

138
static int LuaRuleGetPriority(lua_State *L)
UNCOV
139
{
×
UNCOV
140
    void **data = luaL_testudata(L, 1, suricata_rule_mt);
×
UNCOV
141
    if (data == NULL) {
×
142
        lua_pushnil(L);
×
143
        return 1;
×
144
    }
×
UNCOV
145
    const Signature *s = *data;
×
UNCOV
146
    lua_pushinteger(L, s->prio);
×
UNCOV
147
    return 1;
×
UNCOV
148
}
×
149

150
static const struct luaL_Reg rulemt[] = {
151
    // clang-format off
152
    { "action", LuaRuleGetAction },
153
    { "class_description", LuaRuleGetClassDescription, },
154
    { "gid", LuaRuleGetGid, },
155
    { "msg", LuaRuleGetMsg },
156
    { "priority", LuaRuleGetPriority },
157
    { "rev", LuaRuleGetRev, },
158
    { "sid", LuaRuleGetSid, },
159
    { NULL, NULL },
160
    // clang-format on
161
};
162

163
static const struct luaL_Reg rulelib[] = {
164
    // clang-format off
165
    { "get_rule", LuaRuleGetRule, },
166
    { NULL, NULL, }
167
    // clang-format on
168
};
169

170
int SCLuaLoadRuleLib(lua_State *L)
UNCOV
171
{
×
UNCOV
172
    luaL_newmetatable(L, suricata_rule_mt);
×
UNCOV
173
    lua_pushvalue(L, -1);
×
UNCOV
174
    lua_setfield(L, -2, "__index");
×
UNCOV
175
    luaL_setfuncs(L, rulemt, 0);
×
176

UNCOV
177
    luaL_newlib(L, rulelib);
×
178

UNCOV
179
    return 1;
×
UNCOV
180
}
×
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