Skip to content

Asking kresd about its configuration, notably its configured upstream servers  #122

@bernd-wechner

Description

@bernd-wechner

I know that I can talk to kresd on a tty. In fact use a small script to do just that:

#!/bin/bash
#
# Opens a tty connection to the knot resolver.
# 
# Assumes only one instance running and connects to that.
#
# Documented here:
#
#	http://knot-resolver.readthedocs.io/en/latest/daemon.html#cli-interface
#
# Just a quick shortcut to getting at CLI for the resolver. 

tty_dir="$(uci get resolver.kresd.rundir)/control"
tty=$(ls -1 $tty_dir | head -1)

if [[ $tty =~ ^-?[0-9]+$ && -a /proc/$tty ]]; then 
	socat - UNIX-CONNECT:$tty_dir/$tty
else
	echo "Looks like kresd is not running"
fi

and I can type lua at the prompt. But it's hard to work out what lua. A simple example is using a discovered tty:

# echo 'modules.list()' | socat - UNIX-CONNECT:/tmp/kresd/control/14898 
> {
    'iterate',
    'hints',
    'validate',
    'cache',
    'ta_update',
    'ta_signal_query',
    'extended_error',
    'priming',
    'detect_time_skew',
    'detect_time_jump',
    'ta_sentinel',
    'edns_keepalive',
    'refuse_nord',
    'watchdog',
    'policy',
    'stats',
    'predict',
}

But what can I send to kresd to answer the question "What are your configured upstream servers?"

I see a wonderful lua example here that is related (but not the same):

#40 (comment)

But I can't send that to this TTY successfully.

I can save that lua script to reset_forwarders.lua and then:

# cat reset_forwarders.lua | socat - UNIX-CONNECT:/tmp/kresd/control/14898 
> 
> /usr/lib/knot-resolver/sandbox.lua:540: [string "function policy:reload_resolv_file()"]:1: 'end' expected near '<eof>'
> /usr/lib/knot-resolver/sandbox.lua:540: [string "  for i = 1, #policy.forwarders do"]:1: 'end' expected near '<eof>'
> [string "return table_print(    print('removing forwar..."]:1: attempt to index a nil value
> [string "return table_print(    policy.del(policy.forw..."]:1: attempt to index a nil value
> /usr/lib/knot-resolver/sandbox.lua:540: [string "  end"]:1: '<eof>' expected near 'end'
> 
> /usr/lib/knot-resolver/sandbox.lua:540: [string "  for line in io.lines(policy.resolv_file) do"]:1: 'end' expected near '<eof>'
> /usr/lib/knot-resolver/sandbox.lua:540: [string "    if not line:match("^%s+#") then"]:1: 'end' expected near '<eof>'
> [string "      local split = string.gmatch(line, "[^%s..."]:1: bad argument #1 to 'gmatch' (string expected, got nil)
> [string "      local name = split()"]:1: attempt to call global 'split' (a nil value)
> [string "      local value = split()"]:1: attempt to call global 'split' (a nil value)
> /usr/lib/knot-resolver/sandbox.lua:540: [string "      if name == 'nameserver' then"]:1: 'end' expected near '<eof>'
> 
> /usr/lib/knot-resolver/kres_modules/policy.lua:45: attempt to concatenate local 'target' (a nil value)
> /usr/lib/knot-resolver/sandbox.lua:540: [string "      end"]:1: '<eof>' expected near 'end'
> /usr/lib/knot-resolver/sandbox.lua:540: [string "    end"]:1: '<eof>' expected near 'end'
> /usr/lib/knot-resolver/sandbox.lua:540: [string "  end"]:1: '<eof>' expected near 'end'
> /usr/lib/knot-resolver/sandbox.lua:540: [string "end"]:1: '<eof>' expected near 'end'
> 
> [string "return table_print(policy:reload_resolv_file())"]:1: attempt to call method 'reload_resolv_file' (a nil value)

Clearly something to do with sandbox.lua and it not supporting this kind of input (and it seems sandbox.lua is driving the interaction).

Which raises two questions:

  1. How is a lua file like that sent to kresd. The issue cited pipes it to sudo nc -U /run/knot-resolver/control but I have kresd on a Turris Omnia (an OpenWRT based router) and we don't have nc (well there's a BusyBox nc on board but it doesn't do that. We do have socat though)

  2. What can I send to it that would reveal the configured upstream servers (or the forwarder configurations)., that kresd is using.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions