-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 api for lua - v9 #12377
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Re-work the Lua dataset lib to be required into a user script like: local dataset = require("suricata.data") The main difference from loading it into global space is providing a custom require function (as we removed it in the sandbox) and load it on demand, returning a table to the module.
This is mainly for header sanitization to avoid pulling in detect modules into the Lua sandbox definition. Plus if we namespace modules with names like "suricata.dataset", it probably makes sense to keep those modules in their own files.
Closed
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #12377 +/- ##
==========================================
- Coverage 82.49% 82.48% -0.01%
==========================================
Files 912 914 +2
Lines 258220 258314 +94
==========================================
+ Hits 213006 213069 +63
- Misses 45214 45245 +31
Flags with carried forward coverage won't be shown. Click here to find out more. |
victorjulien
approved these changes
Jan 12, 2025
WARNING:
Pipeline 24172 |
Merged
Merged in #12379, thanks! |
Nice, thanks for making the require stuff work 🎉 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Rebase of #12121, with change to "require"
API.
For example, to use the script must:
SV_BRANCH=OISF/suricata-verify#2229
Ticket: https://redmine.openinfosecfoundation.org/issues/7243