From: Vitezslav Kriz Date: Wed, 19 Jul 2017 14:41:01 +0000 (+0200) Subject: policy: update aho-corasick code X-Git-Tag: v1.4.0~18^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=172d0414acad98d7008d2b460bc16abb566f83c9;p=thirdparty%2Fknot-resolver.git 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. --- diff --git a/.gitmodules b/.gitmodules index 380cf702e..c4c2b89d5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [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 diff --git a/Makefile b/Makefile index ef757509c..b25a7553e 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/daemon/engine.c b/daemon/engine.c index 034ab836f..5d44466e0 100644 --- a/daemon/engine.c +++ b/daemon/engine.c @@ -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), ""); diff --git a/modules/modules.mk b/modules/modules.mk index 3a77ab608..dfbbec071 100644 --- a/modules/modules.mk +++ b/modules/modules.mk @@ -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: diff --git a/modules/policy/lua-aho-corasick b/modules/policy/lua-aho-corasick new file mode 160000 index 000000000..47df012b3 --- /dev/null +++ b/modules/policy/lua-aho-corasick @@ -0,0 +1 @@ +Subproject commit 47df012b383a0e79b9f40c1839b1581b00ce2989 diff --git a/modules/policy/policy.lua b/modules/policy/policy.lua index dafbdf3ea..ac6e2792d 100644 --- a/modules/policy/policy.lua +++ b/modules/policy/policy.lua @@ -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 diff --git a/modules/policy/policy.mk b/modules/policy/policy.mk index f859ac970..2e485a9b2 100644 --- a/modules/policy/policy.mk +++ b/modules/policy/policy.mk @@ -1,2 +1,9 @@ -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