From: Jason Ish Date: Thu, 27 Mar 2025 17:10:21 +0000 (-0600) Subject: lua/dnp3: add is_request boolean X-Git-Tag: suricata-8.0.0-beta1~223 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c69dfc5792a5b861786bc27c8a66d52f5c13b3fc;p=thirdparty%2Fsuricata.git lua/dnp3: add is_request boolean 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 --- diff --git a/src/util-lua-dnp3.c b/src/util-lua-dnp3.c index 2efc50b5b6..3be6076c37 100644 --- a/src/util-lua-dnp3.c +++ b/src/util-lua-dnp3.c @@ -38,6 +38,13 @@ 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);