]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
lua/dnp3: add is_request boolean
authorJason Ish <jason.ish@oisf.net>
Thu, 27 Mar 2025 17:10:21 +0000 (11:10 -0600)
committerJason Ish <jason.ish@oisf.net>
Thu, 27 Mar 2025 17:10:21 +0000 (11:10 -0600)
A DNP3 message can be a request or response, but not both. This is how
the transaction is structured.

Instead of having 2 values, "has_request" and "has_response", just
provide one field, "is_request" as a boolean.

Ticket: #7601

src/util-lua-dnp3.c

index 2efc50b5b66a97ece0d2ebea84116ec6f5d3100e..3be6076c37368cf3b1a4dde31aed5c61d4de6120 100644 (file)
         lua_settable(luastate, -3);             \
     } while (0);
 
+static void SCLuaPushBoolean(lua_State *L, const char *key, bool val)
+{
+    lua_pushstring(L, key);
+    lua_pushboolean(L, val);
+    lua_settable(L, -3);
+}
+
 static void DNP3PushPoints(lua_State *luastate, DNP3Object *object)
 {
     DNP3Point *point;
@@ -165,7 +172,7 @@ static int DNP3GetTx(lua_State *luastate)
     lua_pushinteger(luastate, tx->tx_num);
     lua_settable(luastate, -3);
 
-    LUA_PUSHT_INT(luastate, "has_request", tx->is_request ? 1 : 0);
+    SCLuaPushBoolean(luastate, "is_request", tx->is_request);
     if (tx->is_request) {
         lua_pushliteral(luastate, "request");
         lua_newtable(luastate);
@@ -173,10 +180,7 @@ static int DNP3GetTx(lua_State *luastate)
         LUA_PUSHT_INT(luastate, "complete", tx->complete);
         DNP3PushRequest(luastate, tx);
         lua_settable(luastate, -3);
-    }
-
-    LUA_PUSHT_INT(luastate, "has_response", tx->is_request ? 0 : 1);
-    if (!tx->is_request) {
+    } else {
         lua_pushliteral(luastate, "response");
         lua_newtable(luastate);
         LUA_PUSHT_INT(luastate, "done", tx->done);