]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
doc: document lua function about flow var
authorEric Leblond <eric@regit.org>
Fri, 16 Feb 2018 08:22:35 +0000 (09:22 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 3 Apr 2018 08:07:45 +0000 (10:07 +0200)
doc/userguide/lua/lua-functions.rst

index 856512a7df7cd6faca8a070c04fb0c339d80783a..0d829ab722a3be66799f33dff31633ad8dbf1d48 100644 (file)
@@ -734,6 +734,88 @@ SCStreamingBuffer
       hex_dump(data)
   end
 
+Flow variables
+--------------
+
+It is possible to access, define and modify Flow variables from Lua. To do so,
+you must use the functions described in this section and declare the counter in
+init function:
+
+::
+
+ function init(args)
+     local needs = {}
+     needs["tls"] tostring(true)
+     needs["flowint"] = {"tls-cnt"}
+     return needs
+ end
+
+Here we define a `tls-cnt` Flowint that can now be used in output or in a
+signature via dedicted functions. The access to the Flow variable is done by
+index so in our case we need to use 0.
+
+::
+
+ function match(args)
+     a = ScFlowintGet(0);
+     if a then
+         ScFlowintSet(0, a + 1)
+     else
+         ScFlowintSet(0, 1)
+     end 
+
+ScFlowintGet
+~~~~~~~~~~~~
+
+Get the Flowint at index given by the parameter.
+
+ScFlowintSet
+~~~~~~~~~~~~
+
+Set the Flowint at index given by the first parameter. The second parameter is the value.
+
+ScFlowintIncr
+~~~~~~~~~~~~~
+
+Increment Flowint at index given by the first parameter.
+
+ScFlowintDecr
+~~~~~~~~~~~~~
+
+Decrement Flowint at index given by the first parameter.
+
+ScFlowvarGet
+~~~~~~~~~~~~
+
+Get the Flowvar at index given by the parameter.
+
+ScFlowvarSet
+~~~~~~~~~~~~
+
+Set a Flowvar. First parameter is the index, second is the data
+and third is the length of data.
+
+You can use it to set string 
+
+::
+
+ function init (args)
+     local needs = {}
+     needs["http.request_headers"] = tostring(true)
+     needs["flowvar"] = {"cnt"}
+     return needs
+ end
+ function match(args)
+     a = ScFlowvarGet(0);
+     if a then
+         a = tostring(tonumber(a)+1)
+         ScFlowvarSet(0, a, #a)
+     else
+         a = tostring(1)
+         ScFlowvarSet(0, a, #a)
+     end 
+
 Misc
 ----