{% if not cfg.lua.script_only %}

-- FFI library
ffi = require('ffi')
local C = ffi.C

-- Do not clear the DB with rules; we had it prepared by a different process.
assert(C.kr_rules_init(nil, 0, false) == 0)

-- hostname
hostname('{{ cfg.hostname }}')

{% if cfg.nsid %}
-- nsid
modules.load('nsid')
nsid.name('{{ cfg.nsid }}' .. worker.id)
{% endif %}

-- LOGGING section ----------------------------------
{% include "logging.lua.j2" %}

-- MONITORING section -------------------------------
{% include "monitoring.lua.j2" %}

-- OPTIONS section ----------------------------------
{% include "options.lua.j2" %}

-- NETWORK section ----------------------------------
{% include "network.lua.j2" %}

-- DNSSEC section -----------------------------------
{% include "dnssec.lua.j2" %}

-- FORWARD and FALLBACK section ----------------------------------
{% include "forward.lua.j2" %}

-- CACHE section ------------------------------------
{% include "cache.lua.j2" %}

-- DNS64 section ------------------------------------
{% include "dns64.lua.j2" %}

-- RATE-LIMITING section ------------------------------------
{% include "rate_limiting.lua.j2" %}

-- DEFER section ------------------------------------
{% include "defer.lua.j2" %}

{% endif %}

-- LUA section --------------------------------------
-- Custom Lua code cannot be validated

{% if cfg.lua.script_file %}
{% import cfg.lua.script_file as script_file %}
{{ script_file }}
{% endif %}

{% if cfg.lua.script %}
{{ cfg.lua.script }}
{% endif %}
