]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
lua: remove old lua payload/packet calls
authorVictor Julien <vjulien@oisf.net>
Tue, 21 Jan 2025 19:14:07 +0000 (20:14 +0100)
committerVictor Julien <victor@inliniac.net>
Wed, 12 Feb 2025 16:08:32 +0000 (17:08 +0100)
Moving forward the packetlib is to be used.

Ticket: #7488.

src/detect-lua.c
src/util-lua-common.c

index b7c5c9f1b295c7ac4a1c1a096337a8b16268bc5d..93306b2cc9d368de631eb1d5c7da6efce614946c 100644 (file)
@@ -353,16 +353,6 @@ static int DetectLuaMatch (DetectEngineThreadCtx *det_ctx,
     lua_getglobal(tlua->luastate, "match");
     lua_newtable(tlua->luastate); /* stack at -1 */
 
-    if ((tlua->flags & FLAG_DATATYPE_PAYLOAD) && p->payload_len) {
-        lua_pushliteral(tlua->luastate, "payload"); /* stack at -2 */
-        LuaPushStringBuffer (tlua->luastate, (const uint8_t *)p->payload, (size_t)p->payload_len); /* stack at -3 */
-        lua_settable(tlua->luastate, -3);
-    }
-    if ((tlua->flags & FLAG_DATATYPE_PACKET) && GET_PKT_LEN(p)) {
-        lua_pushliteral(tlua->luastate, "packet"); /* stack at -2 */
-        LuaPushStringBuffer (tlua->luastate, (const uint8_t *)GET_PKT_DATA(p), (size_t)GET_PKT_LEN(p)); /* stack at -3 */
-        lua_settable(tlua->luastate, -3);
-    }
     if (tlua->alproto == ALPROTO_HTTP1) {
         HtpState *htp_state = p->flow->alstate;
         if (htp_state != NULL && htp_state->connp != NULL) {
index 4811bd9d7d791785cdf4314ff5f6986a055325ac..94d562e0ad9dc8fbe0859b0c4e3cf1635f9104c6 100644 (file)
@@ -133,90 +133,6 @@ static int LuaCallbackStreamingBuffer(lua_State *luastate)
     return LuaCallbackStreamingBufferPushToStack(luastate, b);
 }
 
-/** \internal
- *  \brief fill lua stack with payload
- *  \param luastate the lua state
- *  \param p packet
- *  \retval cnt number of data items placed on the stack
- *
- *  Places: payload (string)
- */
-static int LuaCallbackPacketPayloadPushToStackFromPacket(lua_State *luastate, const Packet *p)
-{
-    lua_pushlstring (luastate, (const char *)p->payload, p->payload_len);
-    return 1;
-}
-
-/** \internal
- *  \brief Wrapper for getting payload into a lua script
- *  \retval cnt number of items placed on the stack
- */
-static int LuaCallbackPacketPayload(lua_State *luastate)
-{
-    const Packet *p = LuaStateGetPacket(luastate);
-    if (p == NULL)
-        return LuaCallbackError(luastate, "internal error: no packet");
-
-    return LuaCallbackPacketPayloadPushToStackFromPacket(luastate, p);
-}
-
-/** \internal
- *  \brief fill lua stack with packet timestamp
- *  \param luastate the lua state
- *  \param p packet
- *  \retval cnt number of data items placed on the stack
- *
- *  Places: seconds (number), microseconds (number)
- */
-static int LuaCallbackTimestampPushToStack(lua_State *luastate, const SCTime_t ts)
-{
-    lua_pushnumber(luastate, (double)SCTIME_SECS(ts));
-    lua_pushnumber(luastate, (double)SCTIME_USECS(ts));
-    return 2;
-}
-
-/** \internal
- *  \brief fill lua stack with header info
- *  \param luastate the lua state
- *  \param p packet
- *  \retval cnt number of data items placed on the stack
- *
- *  Places: ts (string)
- */
-static int LuaCallbackTimeStringPushToStackFromPacket(lua_State *luastate, const Packet *p)
-{
-    char timebuf[64];
-    CreateTimeString(p->ts, timebuf, sizeof(timebuf));
-    lua_pushstring (luastate, timebuf);
-    return 1;
-}
-
-/** \internal
- *  \brief Wrapper for getting packet timestamp (as numbers) into a lua script
- *  \retval cnt number of items placed on the stack
- */
-static int LuaCallbackPacketTimestamp(lua_State *luastate)
-{
-    const Packet *p = LuaStateGetPacket(luastate);
-    if (p == NULL)
-        return LuaCallbackError(luastate, "internal error: no packet");
-
-    return LuaCallbackTimestampPushToStack(luastate, p->ts);
-}
-
-/** \internal
- *  \brief Wrapper for getting tuple info into a lua script
- *  \retval cnt number of items placed on the stack
- */
-static int LuaCallbackPacketTimeString(lua_State *luastate)
-{
-    const Packet *p = LuaStateGetPacket(luastate);
-    if (p == NULL)
-        return LuaCallbackError(luastate, "internal error: no packet");
-
-    return LuaCallbackTimeStringPushToStackFromPacket(luastate, p);
-}
-
 /** \internal
  *  \brief fill lua stack with flow timestamps
  *  \param luastate the lua state
@@ -314,69 +230,6 @@ static int LuaCallbackFlowHasAlerts(lua_State *luastate)
     return r;
 }
 
-/** \internal
- *  \brief fill lua stack with header info
- *  \param luastate the lua state
- *  \param p packet
- *  \retval cnt number of data items placed on the stack
- *
- *  Places: ipver (number), src ip (string), dst ip (string), protocol (number),
- *          sp or icmp type (number), dp or icmp code (number).
- */
-static int LuaCallbackTuplePushToStackFromPacket(lua_State *luastate, const Packet *p)
-{
-    int ipver = 0;
-    if (PacketIsIPv4(p)) {
-        ipver = 4;
-    } else if (PacketIsIPv6(p)) {
-        ipver = 6;
-    }
-    lua_pushinteger(luastate, ipver);
-    if (ipver == 0)
-        return 1;
-
-    char srcip[46] = "", dstip[46] = "";
-    if (PacketIsIPv4(p)) {
-        PrintInet(AF_INET, (const void *)GET_IPV4_SRC_ADDR_PTR(p), srcip, sizeof(srcip));
-        PrintInet(AF_INET, (const void *)GET_IPV4_DST_ADDR_PTR(p), dstip, sizeof(dstip));
-    } else if (PacketIsIPv6(p)) {
-        PrintInet(AF_INET6, (const void *)GET_IPV6_SRC_ADDR(p), srcip, sizeof(srcip));
-        PrintInet(AF_INET6, (const void *)GET_IPV6_DST_ADDR(p), dstip, sizeof(dstip));
-    }
-
-    lua_pushstring (luastate, srcip);
-    lua_pushstring (luastate, dstip);
-
-    /* proto and ports (or type/code) */
-    lua_pushinteger(luastate, p->proto);
-    if (p->proto == IPPROTO_TCP || p->proto == IPPROTO_UDP) {
-        lua_pushinteger(luastate, p->sp);
-        lua_pushinteger(luastate, p->dp);
-
-    } else if (p->proto == IPPROTO_ICMP || p->proto == IPPROTO_ICMPV6) {
-        lua_pushinteger(luastate, p->icmp_s.type);
-        lua_pushinteger(luastate, p->icmp_s.code);
-    } else {
-        lua_pushinteger(luastate, 0);
-        lua_pushinteger(luastate, 0);
-    }
-
-    return 6;
-}
-
-/** \internal
- *  \brief Wrapper for getting tuple info into a lua script
- *  \retval cnt number of items placed on the stack
- */
-static int LuaCallbackTuple(lua_State *luastate)
-{
-    const Packet *p = LuaStateGetPacket(luastate);
-    if (p == NULL)
-        return LuaCallbackError(luastate, "internal error: no packet");
-
-    return LuaCallbackTuplePushToStackFromPacket(luastate, p);
-}
-
 /** \internal
  *  \brief fill lua stack with header info
  *  \param luastate the lua state
@@ -931,15 +784,6 @@ static int LuaCallbackThreadInfo(lua_State *luastate)
 int LuaRegisterFunctions(lua_State *luastate)
 {
     /* registration of the callbacks */
-    lua_pushcfunction(luastate, LuaCallbackPacketPayload);
-    lua_setglobal(luastate, "SCPacketPayload");
-    lua_pushcfunction(luastate, LuaCallbackPacketTimestamp);
-    lua_setglobal(luastate, "SCPacketTimestamp");
-    lua_pushcfunction(luastate, LuaCallbackPacketTimeString);
-    lua_setglobal(luastate, "SCPacketTimeString");
-    lua_pushcfunction(luastate, LuaCallbackTuple);
-    lua_setglobal(luastate, "SCPacketTuple");
-
     lua_pushcfunction(luastate, LuaCallbackFlowTimestamps);
     lua_setglobal(luastate, "SCFlowTimestamps");
     lua_pushcfunction(luastate, LuaCallbackFlowTimeString);