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 packetlib/v4 #12568

Closed
wants to merge 7 commits into from
Closed

Conversation

victorjulien
Copy link
Member

SV_BRANCH=OISF/suricata-verify#2285

Rebased #12551

Replaces timestring with timestring_legacy (fastlog) and timestring_iso8601 (eve). Went with these as I realized eve has iso 8601 output as mentioned here 6c3c234

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

Example:

```
local packet = require "suricata.packet"

function init (args)
    local needs = {}
    return needs
end

function match (args)
    p = packet.get()
    payload = p:payload()
    ts = p:timestring()

    for line in payload:gmatch("([^\r\n]*)[\r\n]+") do
        if line == "GET /index.html HTTP/1.0" then
            ipver, srcip, dstip, proto, sp, dp = p:tuple()
            SCLogNotice(string.format("%s %s->%s %d->%d (pcap_cnt:%d) match! %s", ts, srcip, dstip, sp, dp, p:pcap_cnt(), line));
            return 1
        end
    end

    return 0
end
```

Methods:
`get` creates the packet object.
`payload` returns the packet payload as a buffer
`packet` returns the whole packet (includes headers)
`pcap_cnt` returns the `pcap_cnt` (pcap file mode only)
`tuple` returns various fields: srcip, dstip, proto, sp, dp
`sp` returns source port
`dp` returns destination port
`timestamp` returns time as 2 numbers: seconds and microseconds
`timestring_legacy` returns a timestamp as a string (like fastlog)
`timestring_iso8601` returns a iso8601 compat timestring (like eve)

Ticket: OISF#7488.
Moving forward the packetlib is to be used.

Ticket: OISF#7488.
Register internal libs for the case where loading external modules is allowed.
Copy link

codecov bot commented Feb 12, 2025

Codecov Report

Attention: Patch coverage is 74.24242% with 34 lines in your changes missing coverage. Please review.

Project coverage is 80.70%. Comparing base (0165830) to head (1c6b4ca).
Report is 19 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #12568   +/-   ##
=======================================
  Coverage   80.70%   80.70%           
=======================================
  Files         928      929    +1     
  Lines      259013   259062   +49     
=======================================
+ Hits       209033   209083   +50     
+ Misses      49980    49979    -1     
Flag Coverage Δ
fuzzcorpus 56.95% <0.75%> (-0.02%) ⬇️
livemode 19.39% <0.00%> (-0.01%) ⬇️
pcap 44.21% <0.00%> (+0.01%) ⬆️
suricata-verify 63.39% <73.48%> (-0.01%) ⬇️
unittests 58.36% <0.75%> (-0.02%) ⬇️

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

@suricata-qa
Copy link

WARNING:

field baseline test %
SURI_TLPR1_stats_chk
.uptime 636 656 103.14%

Pipeline 24699

@victorjulien victorjulien added this to the 8.0 milestone Feb 12, 2025
@victorjulien
Copy link
Member Author

Merged in #12569, thanks!

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.

3 participants