Improvements
------------
- policy.suffix: update the aho-corasick code (#200)
+- root hints are now loaded from a zonefile; exposed as hints.root_file().
+ You can override the path by defining ROOTHINTS during compilation.
Knot Resolver 1.3.3 (2017-08-09)
INCLUDEDIR ?= $(PREFIX)/include
MODULEDIR ?= $(LIBDIR)/kdns_modules
ETCDIR ?= $(PREFIX)/etc/kresd
-ROOTHINTS ?= $(ETCDIR)/hints.zone
+ROOTHINTS ?= $(ETCDIR)/root.hints
# Tools
CC ?= cc
kresd_CFLAGS := -fPIE \
-Dlibknot_SONAME=\"$(libknot_SONAME)\" \
-Dlibzscanner_SONAME=\"$(libzscanner_SONAME)\" \
+ -DROOTHINTS=\"$(ROOTHINTS)\" \
-DLUA_HAS_SETFUNCS="$(LUA_HAS_SETFUNCS)"
kresd_DEPEND := $(libkres) $(contrib)
kresd_LIBS := $(libkres_TARGET) $(contrib_TARGET) $(libknot_LIBS) \
endif
daemon-clean: kresd-clean
@$(RM) daemon/lua/*.inc daemon/lua/kres.lua daemon/lua/trust_anchors.lua \
- daemon/lua/zonefile.lua daemon/lua/config.lua
+ daemon/lua/zonefile.lua
KNOT_RRSET_TXT_DUMP := \
$(shell pkg-config libknot --atleast-version=2.4.0 && echo true || echo false)
daemon/lua/trust_anchors.lua: daemon/lua/trust_anchors.lua.in
@$(call quiet,SED,$<) -e "s|@ETCDIR@|$(ETCDIR)|g" $< > $@
-daemon/lua/config.lua: daemon/lua/config.lua.in
- @$(call quiet,SED,$<) -e "s|@ROOTHINTS@|$(ROOTHINTS)|g" $< > $@
-
LIBZSCANNER_COMMENTS := \
$(shell pkg-config libzscanner --atleast-version=2.4.2 && echo true || echo false)
daemon/lua/zonefile.lua: daemon/lua/zonefile.lua.in
return 1;
}
-/** @internal for l_roothints */
+/** @internal for l_hints_root_file */
static void roothints_add(zs_scanner_t *zs)
{
struct kr_zonecut *hints = zs->process.data;
if (!hints) {
return;
}
- if(zs->r_type == KNOT_RRTYPE_A || zs->r_type == KNOT_RRTYPE_AAAA) {
+ if (zs->r_type == KNOT_RRTYPE_A || zs->r_type == KNOT_RRTYPE_AAAA) {
knot_rdata_t rdata[RDATA_ARR_MAX];
knot_rdata_init(rdata, zs->r_data_length, zs->r_data, zs->r_ttl);
- kr_zonecut_add(hints,zs->r_owner, rdata);
- }
+ kr_zonecut_add(hints, zs->r_owner, rdata);
+ }
}
/** Load root hints from zonefile. */
-static int l_roothints(lua_State *L)
+static int l_hint_root_file(lua_State *L)
{
struct engine *engine = engine_luaget(L);
struct kr_context *ctx = &engine->resolver;
- struct kr_zonecut *root_hints = &ctx->root_hints;
const char *file = lua_tostring(L, 1);
- if (!file || strlen(file) == 0) {
- return 0;
- }
- zs_scanner_t *zs = malloc(sizeof(*zs));
- if (!zs || zs_init(zs, ".", 1, 0) != 0) {
- free(zs);
- lua_pushstring(L, "not enough memory");
+ const char *err = lua_hint_root_file(ctx, file);
+ if (err) {
+ lua_pushstring(L, err);
lua_error(L);
+ } else {
+ lua_pushboolean(L, true);
+ return 1;
}
-
- if (zs_set_input_file(zs, file) != 0) {
- free(zs);
- lua_pushstring(L, "failed to open root hints file");
- lua_error(L);
+}
+
+const char* lua_hint_root_file(struct kr_context *ctx, const char *file)
+{
+ if (!file) {
+ file = ROOTHINTS;
+ }
+ if (strlen(file) == 0 || !ctx) {
+ return "invalid parameters";
+ }
+ struct kr_zonecut *root_hints = &ctx->root_hints;
+
+ zs_scanner_t zs;
+ if (zs_init(&zs, ".", 1, 0) != 0) {
+ return "not enough memory";
}
-
+ if (zs_set_input_file(&zs, file) != 0) {
+ return "failed to open root hints file";
+ }
+
kr_zonecut_set(root_hints, (const uint8_t *)"");
- zs_set_processing(zs, roothints_add, NULL, root_hints);
- zs_parse_all(zs);
-
- lua_pushboolean(L, true);
- free(zs);
- return 1;
+ zs_set_processing(&zs, roothints_add, NULL, root_hints);
+ zs_parse_all(&zs);
+ return NULL;
}
+
/** Unpack JSON object to table */
static void l_unpack_json(lua_State *L, JsonNode *table)
{
lua_setglobal(engine->L, "user");
lua_pushcfunction(engine->L, l_trustanchor);
lua_setglobal(engine->L, "trustanchor");
- lua_pushcfunction(engine->L, l_roothints);
- lua_setglobal(engine->L, "roothints");
+ lua_pushcfunction(engine->L, l_hint_root_file);
+ lua_setglobal(engine->L, "_hint_root_file");
lua_pushliteral(engine->L, libknot_SONAME);
lua_setglobal(engine->L, "libknot_SONAME");
lua_pushliteral(engine->L, libzscanner_SONAME);
/** Set/get the per engine moduledir */
char *engine_get_moduledir(struct engine *engine);
int engine_set_moduledir(struct engine *engine, const char *moduledir);
+
+/** Load root hints from a zonefile (or config-time default if NULL).
+ *
+ * @return error message or NULL (statically allocated)
+ */
+const char* lua_hint_root_file(struct kr_context *ctx, const char *file);
+
end
if kres.context().root_hints.nsset.root == nil then
- roothints('@ROOTHINTS@')
+ _hint_root_file()
end
config.isp \
config.personal \
config.splitview \
- hints.zone
+ root.hints
etc-install: $(DESTDIR)$(ETCDIR)
$(INSTALL) -m 0640 $(addprefix etc/,$(etc_SOURCES)) $(DESTDIR)$(ETCDIR)
-etc: etc/hints.zone
+etc: etc/root.hints
-etc/hints.zone:
+etc/root.hints:
wget -O $@ https://www.internic.net/domain/named.root
.PHONY: etc-install
.. tip:: If no parameters are passed, returns current root hints set.
+.. function:: hints.root_file(path)
+
+ Replace current root hints from a zonefile. If the path is omitted, the compiled-in path is used, i.e. the root hints are reset to the default.
+
.. function:: hints.root(root_hints)
:param table root_hints: new set of root hints i.e. ``{['name'] = 'addr', ...}``
return pack_hints(root_hints);
}
+static char* hint_root_file(void *env, struct kr_module *module, const char *args)
+{
+ struct engine *engine = env;
+ struct kr_context *ctx = &engine->resolver;
+ return (char*)lua_hint_root_file(ctx, args);
+}
+
/*
* Module implementation.
*/
{ &hint_get, "get", "Retrieve hint for given name.", },
{ &hint_add_hosts, "add_hosts", "Load a file with hosts-like formatting and add contents into hints.", },
{ &hint_root, "root", "Replace root hints set (empty value to return current list).", },
+ { &hint_root_file, "root_file", "Replace root hints set from a zonefile.", },
{ NULL, NULL, NULL }
};
return prop_list;
+++ /dev/null
-#!/bin/sh -e
-
-echo "/* generated root hints */"
-
-for atype in A AAAA; do
- # address length when using \xNN escapes
- if [ "$atype" = A ]; then
- alen=16
- elif [ "$atype" = AAAA ]; then
- alen=64
- else
- exit 1
- fi
-
- for n in a b c d e f g h i j k l m; do
- ip="$(kdig "$atype" "$n.root-servers.net." +dnssec +short)"
- ip_hex="$("$(dirname "$0")"/inet_pton.py "$ip")"
- [ "$(printf "%s" "$ip_hex" | wc -c)" = "$alen" ] || exit 1
- echo "#define HINT_${n}_${atype} \"$ip_hex\""
- done
-done
-