Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua dataset/v7 #12121

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Lua dataset/v7 #12121

wants to merge 3 commits into from

Conversation

victorjulien
Copy link
Member

Initial dataset support for lua.

Changes since #12090:

More idiomatic lua:

function init (args)
    local needs = {}
    needs["packet"] = tostring(true)
    return needs
end

function thread_init (args)
    conn_new, err = dataset.new()
    ret, err = conn_new:get("conn-seen")
    if err ~= nil then
        SCLogWarning("dataset warning: " .. err)
        return 0
    end
end

function match (args)
    ipver, srcip, dstip, proto, sp, dp = SCFlowTuple()
    str = ipver .. ":<" .. srcip .. ">:<" .. dstip .. ">:" .. dp

    ret, err = conn_new:add(str, #str);
    if ret == 1 then
        SCLogInfo(str .. " => " .. ret)
    end
    return ret
end

One question is if we should add support for require, so that to be able to use dataset a script author would have to include require dataset or require suricata.dataset before being able to use it...

https://redmine.openinfosecfoundation.org/issues/7243

SV_BRANCH=OISF/suricata-verify#2129

Only useful when debugging. Add a prefix and a stack size indication.
Add optional `thread_init` function support. This function is called per
script, per thread to allow a user to initialize the lua state.
dataset.new
  create a dataset object in lua

<dataset>:get
  gets a reference to an existing dataset

<dataset>:add
  returns 1 if a new entry was added
  returns 0 if entry was already in the set

Example:
```
function init (args)
    local needs = {}
    needs["packet"] = tostring(true)
    return needs
end

function thread_init (args)
    conn_new, dataset.new()
    ret, err conn_new:get("conn-seen")
    if err ~= nil then
        SCLogWarning("dataset warning: " .. err)
        return 0
    end
end

function match (args)
    ipver, srcip, dstip, proto, sp, dp = SCFlowTuple()
    str = ipver .. ":<" .. srcip .. ">:<" .. dstip .. ">:" .. dp

    ret, err = conn_new:add(str, #str);
    if ret == 1 then
        SCLogInfo(str .. " => " .. ret)
    end
    return ret
end
```

Ticket: OISF#7243.
Copy link

codecov bot commented Nov 15, 2024

Codecov Report

Attention: Patch coverage is 80.76923% with 15 lines in your changes missing coverage. Please review.

Project coverage is 83.15%. Comparing base (5d766df) to head (dd27b43).

Additional details and impacted files
@@             Coverage Diff             @@
##           master   #12121       +/-   ##
===========================================
+ Coverage   62.68%   83.15%   +20.47%     
===========================================
  Files         840      909       +69     
  Lines      153669   257983   +104314     
===========================================
+ Hits        96323   214532   +118209     
+ Misses      57346    43451    -13895     
Flag Coverage Δ
fuzzcorpus 60.96% <0.00%> (?)
livemode 19.42% <0.00%> (?)
pcap 44.37% <0.00%> (?)
suricata-verify 62.73% <80.76%> (+0.05%) ⬆️
unittests 59.25% <30.76%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

@victorjulien victorjulien mentioned this pull request Nov 15, 2024
@suricata-qa
Copy link

Information: QA ran without warnings.

Pipeline 23322

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants