Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions net/unbound-uci-ext/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=unbound-uci-ext
PKG_VERSION:=0.2.2
PKG_RELEASE:=1

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/openwrt-iac/unbound-uci-ext/tar.gz/v$(PKG_VERSION)?
PKG_HASH:=741a0362817cd8874f8d53e745fde664f92c64e1b5bc57a48cd27b2efee06d26

PKG_MAINTAINER:=Guy Godfroy <guy.godfroy@gugod.fr>
PKG_LICENSE:=MIT
PKG_LICENSE_FILES:=LICENSE

include $(INCLUDE_DIR)/package.mk

define Package/unbound-uci-ext
SECTION:=net
CATEGORY:=Network
SUBMENU:=IP Addresses and Names
TITLE:=UCI options for unbound's extended config files
URL:=https://github.com/openwrt-iac/unbound-uci-ext
PKGARCH:=all
DEPENDS:=+unbound-daemon
endef

define Package/unbound-uci-ext/description
UCI options for the unbound directives that the unbound package
leaves out of UCI. /etc/config/unbound_srv renders lines of the
server: clause into /etc/unbound/unbound_srv.conf, and
/etc/config/unbound_ext renders other clauses, such as forward-zone:,
into /etc/unbound/unbound_ext.conf. Only a marked region of each file
changes.
endef

define Package/unbound-uci-ext/conffiles
/etc/config/unbound_ext
/etc/config/unbound_srv
endef

Build/Compile=

define Package/unbound-uci-ext/install
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_CONF) ./files/unbound_ext.config $(1)/etc/config/unbound_ext
$(INSTALL_CONF) ./files/unbound_srv.config $(1)/etc/config/unbound_srv

$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/unbound-uci-ext.init $(1)/etc/init.d/unbound-uci-ext

$(INSTALL_DIR) $(1)/usr/lib/unbound-uci-ext
$(INSTALL_BIN) $(PKG_BUILD_DIR)/files/usr/lib/unbound-uci-ext/generator.sh \
$(1)/usr/lib/unbound-uci-ext/
endef

$(eval $(call BuildPackage,unbound-uci-ext))
24 changes: 24 additions & 0 deletions net/unbound-uci-ext/files/unbound-uci-ext.init
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh /etc/rc.common

USE_PROCD=1
# After unbound (START=19), since the generator restarts unbound when a
# file changes.
START=92

GENERATOR=/usr/lib/unbound-uci-ext/generator.sh

start_service() {
"$GENERATOR" apply
}

stop_service() {
"$GENERATOR" clear
}

reload_service() {
"$GENERATOR" apply
}

service_triggers() {
procd_add_reload_trigger "unbound_srv" "unbound_ext"
}
11 changes: 11 additions & 0 deletions net/unbound-uci-ext/files/unbound_ext.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Clauses after server:, such as forward-zone:, rendered into a marked
# region of /etc/unbound/unbound_ext.conf, one ext_line for each line.
# Nothing checks the lines, and unbound stops on a line that it cannot
# parse, so run unbound-checkconf after a change.

config unbound_ext 'main'
option enabled '0'

#list ext_line 'forward-zone:'
#list ext_line ' name: "example.org"'
#list ext_line ' forward-addr: 192.0.2.53'
19 changes: 19 additions & 0 deletions net/unbound-uci-ext/files/unbound_srv.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Lines of the server: clause, rendered into a marked region of
# /etc/unbound/unbound_srv.conf. For another clause, such as
# forward-zone:, use /etc/config/unbound_ext.

config unbound_srv 'main'
option enabled '0'

# interface: lines, as addr or addr@port. To bind only these, also
# set interface_auto '0' in /etc/config/unbound.
#list interface_bind '127.0.0.1@5353'

# outgoing-interface: lines.
#list interface_outgoing '192.0.2.1'

# ip-transparent: 1 for yes, 0 for no.
#option ip_transparent '0'

# Any other server: line, as it is.
#list srv_line 'serve-expired: yes'
26 changes: 26 additions & 0 deletions net/unbound-uci-ext/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

# shellcheck shell=busybox

set -e

export SRV_CONF=/tmp/unbound_srv.conf EXT_CONF=/tmp/unbound_ext.conf
gen=/usr/lib/unbound-uci-ext/generator.sh

echo 'local-zone: "kept." static' > "$SRV_CONF"
uci set unbound_srv.main.enabled=1
uci add_list unbound_srv.main.interface_bind='127.0.0.1@5353'
uci set unbound_ext.main.enabled=1
uci add_list unbound_ext.main.ext_line='forward-zone:'
uci add_list unbound_ext.main.ext_line=' name: "example.org"'
uci commit

"$gen" apply
grep -Fx 'local-zone: "kept." static' "$SRV_CONF"
grep -Fx 'interface: 127.0.0.1@5353' "$SRV_CONF"
grep -Fx ' name: "example.org"' "$EXT_CONF"

"$gen" clear
grep -Fx 'local-zone: "kept." static' "$SRV_CONF"
! grep -F 'interface:' "$SRV_CONF" || exit 1
! grep -F 'name: "example.org"' "$EXT_CONF" || exit 1