]> git.ipfire.org Git - thirdparty/suricata.git/commit
lua: add initial suricata.flow lib
authorJuliana Fajardini <jufajardini@oisf.net>
Tue, 25 Mar 2025 21:53:19 +0000 (14:53 -0700)
committerVictor Julien <victor@inliniac.net>
Fri, 28 Mar 2025 05:59:38 +0000 (06:59 +0100)
commitb03d1aed81a1ed76ad90f48e78138cf5339b302f
tree65d19bec576c65f2735517d4a0391b0650d45a2f
parent5e86c662ef4896394104efe78dd95c7fca9d35d0
lua: add initial suricata.flow lib

Methods:
`get` creates the flow object.
`id`  returns the flow id.
`has_alerts` returns a boolean indicating if the flow triggered alerts.
`app_layer_proto` returns various app-layer related fields as 5 strings:
  alproto, alproto_ts, alproto_tc, alproto_orig, alproto_expect.
`stats` returns cnts for bytes and packets to sever and to client, as 4
  numbers.
`tuple` -- returns various fields: srcip, dstip, proto, sp, dp.
`timestamps` returns time as 4 numbers: seconds and microseconds, for
  first and last packet of the flow.
`timestring_legacy` returns the first packet from the flow's timestring
  as a string (like fastlog).
`timestring_iso8601` returns the first packet from the flow's
  timestring as an iso8601 compat timestring (like eve).

Example:

```
name = "lua-scflowstats.log"

local flow = require("suricata.flow")

function init(args)
    local needs = {}
    needs["type"] = "flow"
    return needs
end

function setup(args)
    filename = SCLogPath() .. "/" .. name
    file = assert(io.open(filename, "a"))
    SCLogInfo("lua SCFlowStats Log Filename " .. filename)
end

function log(args)
    local f = flow.get()
    timestring = f:timestring_legacy()
    tscnt, tsbytes, tccnt, tcbytes = f:stats()

   file:write ("[**] " .. timestring .. "\nSCFlowStats is\nPacket count to server:  " .. tscnt .. "\nByte count to server: " .. tsbytes .. "\nPacket count to client: " .. tccnt .. "\nByte count to client: " .. tcbytes .. "\n[**]")
    file:flush()
end

function deinit(args)
    file:close(file)
end
```

Task #7489
src/Makefile.am
src/util-lua-builtins.c
src/util-lua-flowlib.c [new file with mode: 0644]
src/util-lua-flowlib.h [new file with mode: 0644]