Commit 172d0414 authored by Vitezslav Kriz's avatar Vitezslav Kriz

policy: update aho-corasick code

Library lua-aho-corasick is provided as git submodule. Library
build is triggered with kresd build. ahocorasick.so is copied into
modules directory.
parent 1d44273b
Pipeline #9493 canceled with stages
in 0 seconds
[submodule "tests/deckard"]
path = tests/deckard
url = https://gitlab.labs.nic.cz/knot/deckard.git
[submodule "modules/policy/lua-aho-corasick"]
path = modules/policy/lua-aho-corasick
url = https://github.com/cloudflare/lua-aho-corasick.git
......@@ -123,6 +123,7 @@ info:
$(info [$(HAS_libfstrm)] libfstrm (modules/dnstap))
$(info [$(HAS_libprotobuf-c)] libprotobuf-c (modules/dnstap))
$(info [$(HAS_protoc-c)] proto-c (modules/dnstap))
$(info [$(HAS_ahocorasick)] ahocorasick (modules/policy))
$(info )
# Verify required dependencies are met, as listed above
......
......@@ -232,8 +232,9 @@ int engine_set_moduledir(struct engine *engine, const char *moduledir) {
/* Save original package.path to package._path */
snprintf(l_paths, MAXPATHLEN - 1,
"if package._path == nil then package._path = package.path end\n"
"package.path = '%s/?.lua;%s/?/init.lua;'..package._path\n",
new_moduledir,
"package.path = '%1$s/?.lua;%1$s/?/init.lua;'..package._path\n"
"if package._cpath == nil then package._cpath = package.cpath end\n"
"package.cpath = '%1$s/?.so;'..package._cpath\n",
new_moduledir);
int ret = l_dobytecode(engine->L, l_paths, strlen(l_paths), "");
......
......@@ -48,7 +48,8 @@ endef
# Lua target definition
define lua_target
$(1) := $$(addprefix $(2)/,$$($(1)_SOURCES))
$(1) := $(1) $$(addprefix $(2)/,$$($(1)_SOURCES))
$(1) : $$($(1)_DEPEND)
$(1)-clean:
ifeq ($$(strip $$($(1)_INSTALL)),)
$(1)-dist:
......
Subproject commit 47df012b383a0e79b9f40c1839b1581b00ce2989
......@@ -141,11 +141,11 @@ end
-- Requests which QNAME matches given zone list (i.e. suffix match)
function policy.suffix(action, zone_list)
local AC = require('aho-corasick')
local tree = AC.build(zone_list)
local AC = require('ahocorasick')
local tree = AC.create(zone_list)
return function(req, query)
local match = AC.match(tree, query:name(), false)
if match[1] ~= nil then
if match ~= nil then
return action
end
return nil
......
policy_SOURCES := policy.lua aho-corasick.lua
policy_SOURCES := policy.lua lua-aho-corasick/ahocorasick.so
policy_DEPEND := modules/policy/lua-aho-corasick/ahocorasick.so
$(call make_lua_module,policy)
AHOCORASICK_DIR = modules/policy/lua-aho-corasick/
policy-clean:
$(MAKE) -C $(AHOCORASICK_DIR) clean
$(AHOCORASICK_DIR)ahocorasick.so: $(AHOCORASICK_DIR)Makefile
$(MAKE) -C $(AHOCORASICK_DIR) MY_CFLAGS=$(lua_CFLAGS) SO_EXT=so
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment