-
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 packetlib/v2 #12512
base: master
Are you sure you want to change the base?
Lua packetlib/v2 #12512
Conversation
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 `timestamp` returns time as 2 numbers: seconds and microseconds `timestring` returns a timestamp as a string 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.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #12512 +/- ##
=======================================
Coverage 80.56% 80.57%
=======================================
Files 925 926 +1
Lines 259292 259333 +41
=======================================
+ Hits 208906 208947 +41
Misses 50386 50386
Flags with carried forward coverage won't be shown. Click here to find out more. |
Information: QA ran without warnings. Pipeline 24450 |
} | ||
|
||
char timebuf[64]; | ||
CreateTimeString(s->p->ts, timebuf, sizeof(timebuf)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for a new API it would be really nice to generate a stanard timestring.. So instead of
YYYY/MM/DD-HH:mm:ss.ssssss
we should do:
YYYY-MM-DDTHH:mm:ss.ssssssZ
If needed, add a _legacy
variant for the old one. Or timestamp_rfc3339
for this new one, and some other specifier for the legacy format?
static const luaL_Reg packetlib[] = { | ||
// clang-format off | ||
{ "get", LuaPacketGet }, | ||
{ NULL, NULL } | ||
// clang-format on | ||
}; | ||
|
||
static const luaL_Reg packetlib_meta[] = { | ||
// clang-format off | ||
{ "packet", LuaPacketPacket }, | ||
{ "payload", LuaPacketPayload }, | ||
{ "pcap_cnt", LuaPacketPcapCnt }, | ||
{ "timestring", LuaPacketTimestring }, | ||
{ "timestamp", LuaPacketTimestamp }, | ||
{ "tuple", LuaPacketTuple }, | ||
{ "sp", LuaPacketSport }, | ||
{ "dp", LuaPacketDport }, | ||
{ "__gc", LuaPacketGC }, | ||
{ NULL, NULL } | ||
// clang-format on | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise API looks OK to me. Time for docs :)
SV_BRANCH=OISF/suricata-verify#2267
https://redmine.openinfosecfoundation.org/issues/7488
#12506 with fixes.
Docs are still a todo.