Commit 8fa8f214 authored by Vladimír Čunát's avatar Vladimír Čunát

roothints: various changes

- expose the function as hints.root_file
- use the same filename as Debian
- remove the unneeded script
- docs and some nitpicks
parent cac9e018
......@@ -11,6 +11,8 @@ Incompatible changes
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)
......
......@@ -19,7 +19,7 @@ MANDIR ?= $(PREFIX)/share/man
INCLUDEDIR ?= $(PREFIX)/include
MODULEDIR ?= $(LIBDIR)/kdns_modules
ETCDIR ?= $(PREFIX)/etc/kresd
ROOTHINTS ?= $(ETCDIR)/hints.zone
ROOTHINTS ?= $(ETCDIR)/root.hints
# Tools
CC ?= cc
......
......@@ -31,6 +31,7 @@ LUA_HAS_SETFUNCS := \
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) \
......@@ -59,7 +60,7 @@ ifneq ($(SED),)
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)
......@@ -69,9 +70,6 @@ daemon/lua/kres.lua: daemon/lua/kres.lua.in
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
......
......@@ -320,52 +320,61 @@ static int l_trustanchor(lua_State *L)
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)
{
......@@ -622,8 +631,8 @@ static int init_state(struct engine *engine)
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);
......
......@@ -101,3 +101,10 @@ int engine_set_hostname(struct engine *engine, const char *hostname);
/** 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);
......@@ -16,5 +16,5 @@ if not cache.current_size then
end
if kres.context().root_hints.nsset.root == nil then
roothints('@ROOTHINTS@')
_hint_root_file()
end
......@@ -3,14 +3,14 @@ etc_SOURCES := icann-ca.pem \
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
......@@ -79,6 +79,10 @@ Properties
.. 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', ...}``
......
......@@ -565,6 +565,13 @@ static char* hint_root(void *env, struct kr_module *module, const char *args)
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.
*/
......@@ -650,6 +657,7 @@ struct kr_prop *hints_props(void)
{ &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;
......
#!/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
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