]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
policy: update aho-corasick code
authorVitezslav Kriz <vitezslav.kriz@nic.cz>
Wed, 19 Jul 2017 14:41:01 +0000 (16:41 +0200)
committerVitezslav Kriz <vitezslav.kriz@nic.cz>
Thu, 20 Jul 2017 09:21:25 +0000 (11:21 +0200)
Library lua-aho-corasick is provided as git submodule. Library
build is triggered with kresd build. ahocorasick.so is copied into
modules directory.

.gitmodules
Makefile
daemon/engine.c
modules/modules.mk
modules/policy/lua-aho-corasick [new submodule]
modules/policy/policy.lua
modules/policy/policy.mk

index 380cf702eab67191638f8e69407edc3672626b35..c4c2b89d51de2b4dbcc5fa5a78cd33c8d540ad86 100644 (file)
@@ -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
index ef757509cac8f01b4cf758d5e7cfe4db040c7613..b25a7553e3c160525acabc938ac11b5a3dc1133e 100644 (file)
--- 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
index 034ab836faae76d1e64733f50b882c96a386cc5c..5d44466e093e9094ae036b635036363c68a1680f 100644 (file)
@@ -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), "");
index 3a77ab6081ad85c900217fe6df7338b35ed306dd..dfbbec071a596da79f08536025cc53426df001a2 100644 (file)
@@ -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 (submodule)
index 0000000..47df012
--- /dev/null
@@ -0,0 +1 @@
+Subproject commit 47df012b383a0e79b9f40c1839b1581b00ce2989
index dafbdf3ea8abee8e1b121007a4d891cd22919be3..ac6e2792dabfbef91bb13e4603594e8c7dfaee4d 100644 (file)
@@ -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
index f859ac9701d71dffc607e99c963e64a29d39d9d2..2e485a9b2dd1f63569589ab917f855980defeaf1 100644 (file)
@@ -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