mirror of
https://github.com/pi-hole/dnsmasq.git
synced 2025-12-19 10:18:25 +00:00
Largely replace the Debian packaging with a new and much more up-to-date
Debhelper based version.
This commit is contained in:
7
debian/tests/compile-time-options
vendored
Executable file
7
debian/tests/compile-time-options
vendored
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
. debian/tests/functions
|
||||
|
||||
check_compile_time_options
|
||||
7
debian/tests/compile-time-options+lua
vendored
Executable file
7
debian/tests/compile-time-options+lua
vendored
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
. debian/tests/functions
|
||||
|
||||
check_compile_time_options +lua
|
||||
39
debian/tests/control
vendored
Normal file
39
debian/tests/control
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
Tests: compile-time-options
|
||||
Depends: dnsmasq,
|
||||
dnsmasq-base,
|
||||
Restrictions: needs-root,
|
||||
isolation-container,
|
||||
|
||||
Tests: compile-time-options+lua
|
||||
Depends: dnsmasq,
|
||||
dnsmasq-base-lua,
|
||||
Restrictions: needs-root,
|
||||
isolation-container,
|
||||
|
||||
Tests: get-address+query-dns+check-utils
|
||||
Depends: bind9,
|
||||
bind9-dnsutils,
|
||||
dnsmasq,
|
||||
dnsmasq-base,
|
||||
dnsmasq-utils,
|
||||
Restrictions: needs-root,
|
||||
allow-stderr,
|
||||
isolation-container,
|
||||
|
||||
Tests: get-address+query-dns+lua+alt
|
||||
Depends: bind9,
|
||||
bind9-dnsutils,
|
||||
dnsmasq,
|
||||
dnsmasq-base-lua,
|
||||
Restrictions: needs-root,
|
||||
allow-stderr,
|
||||
isolation-container,
|
||||
|
||||
Tests: get-address+query-dns+sysv+alt
|
||||
Depends: bind9,
|
||||
bind9-dnsutils,
|
||||
dnsmasq,
|
||||
dnsmasq-base,
|
||||
Restrictions: needs-root,
|
||||
allow-stderr,
|
||||
isolation-container,
|
||||
151
debian/tests/functions
vendored
Normal file
151
debian/tests/functions
vendored
Normal file
@@ -0,0 +1,151 @@
|
||||
# -*- shell-script -*-
|
||||
|
||||
FUNCTIONS_DIR="debian/tests/functions.d"
|
||||
|
||||
match_or_exit () {
|
||||
file_to_match="$1"
|
||||
pattern_file="$2"
|
||||
|
||||
while read line_to_match <&3 && read pattern_line <&4 ; do
|
||||
if [ "${line_to_match##$pattern_line}" ]; then
|
||||
echo '!!! MISMATCH !!!' >&2
|
||||
echo "Line: ${line_to_match}" >&2
|
||||
echo "Pattern: ${pattern_line}" >&2
|
||||
exit 1
|
||||
fi;
|
||||
done 3<"${file_to_match}" 4<"${pattern_file}"
|
||||
}
|
||||
|
||||
linecount () {
|
||||
wc -l $1 | cut -d' ' -f1
|
||||
}
|
||||
|
||||
error_exit () {
|
||||
echo "ERROR: $1"
|
||||
exit 1
|
||||
}
|
||||
|
||||
stop_dnsmasq_bind_networking () {
|
||||
systemctl stop dnsmasq.service
|
||||
systemctl stop named.service
|
||||
systemctl stop networking.service
|
||||
}
|
||||
|
||||
configure_and_start_networking () {
|
||||
#Add interfaces needed for the test
|
||||
cat ${FUNCTIONS_DIR}/add-to.interfaces >> /etc/network/interfaces
|
||||
systemctl start networking.service
|
||||
}
|
||||
|
||||
configure_and_start_bind () {
|
||||
cp ${FUNCTIONS_DIR}/db.autopkg.test /etc/bind/
|
||||
cat ${FUNCTIONS_DIR}/add-to.named.conf.local >> /etc/bind/named.conf.local
|
||||
cp ${FUNCTIONS_DIR}/named.conf.options /etc/bind/named.conf.options
|
||||
systemctl start named.service
|
||||
}
|
||||
|
||||
configure_and_start_dnsmasq () {
|
||||
alt_mode=0
|
||||
lua_mode=0
|
||||
sysv_mode=0
|
||||
service='dnsmasq.service'
|
||||
sysv_param2=''
|
||||
conf_dir='/etc/dnsmasq.d'
|
||||
|
||||
while [ -n "$1" ]; do
|
||||
case "$1" in
|
||||
alt|lua|sysv) eval ${1}_mode=1 ;;
|
||||
*) error_exit "configure_and_start_dnsmasq(): invalid flag '$1'"
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [ ${alt_mode} -eq 1 ]; then
|
||||
cp ${FUNCTIONS_DIR}/dnsmasq.alt-autopkgtest.default /etc/default/dnsmasq.alt
|
||||
cp /etc/dnsmasq.conf /etc/dnsmasq.alt.conf
|
||||
mkdir /etc/dnsmasq.alt.d
|
||||
service='dnsmasq@alt.service'
|
||||
sysv_param2='alt'
|
||||
conf_dir='/etc/dnsmasq.alt.d'
|
||||
fi
|
||||
|
||||
cp ${FUNCTIONS_DIR}/dnsmasq-autopkgtest.conf "${conf_dir}"
|
||||
|
||||
if [ ${lua_mode} -eq 1 ]; then
|
||||
mkdir -p /usr/local/share/dnsmasq
|
||||
cp ${FUNCTIONS_DIR}/log.lua /usr/local/share/dnsmasq/
|
||||
echo "dhcp-luascript=/usr/local/share/dnsmasq/log.lua\n" \
|
||||
>>"${conf_dir}"/dnsmasq-autopkgtest.conf
|
||||
fi
|
||||
|
||||
if [ ${sysv_mode} -eq 1 ]; then
|
||||
SYSTEMCTL_SKIP_REDIRECT=1 /etc/init.d/dnsmasq start "${sysv_param2}"
|
||||
else
|
||||
systemctl enable "${service}"
|
||||
systemctl start "${service}"
|
||||
fi
|
||||
}
|
||||
|
||||
check_compile_time_options () {
|
||||
journalctl -b -u dnsmasq
|
||||
echo ~~~ Check compile time options...
|
||||
journalctl -b -u dnsmasq -g '[a-z]+: ' --output cat >options.msg
|
||||
cat options.msg
|
||||
match_or_exit options.msg ${FUNCTIONS_DIR}/options${1}.patterns
|
||||
}
|
||||
|
||||
get_address_on_veth1_and_check_the_result () {
|
||||
echo ~~~ Get an address on veth1 and check the result...
|
||||
ip netns exec clientnet ifup veth1
|
||||
ip netns exec clientnet ip addr show dev veth1 >ip-addr.out 2>&1
|
||||
cat ip-addr.out
|
||||
match_or_exit ip-addr.out ${FUNCTIONS_DIR}/ip-addr.patterns
|
||||
}
|
||||
|
||||
query_test_zone_records_and_check_the_result () {
|
||||
echo ~~~ Query some test zone records and check the result...
|
||||
ip netns exec clientnet dig +short SOA autopkg.test >dig.out 2>&1
|
||||
ip netns exec clientnet dig +short NS autopkg.test >>dig.out 2>&1
|
||||
ip netns exec clientnet dig +short A ns.autopkg.test >>dig.out 2>&1
|
||||
ip netns exec clientnet dig +short A dhcp3.autopkg.test >>dig.out 2>&1
|
||||
cat dig.out
|
||||
if [ `linecount dig.out` -ne `linecount ${FUNCTIONS_DIR}/dig.patterns` ] ; then
|
||||
error_exit 'empty or unexpected output'
|
||||
fi
|
||||
match_or_exit dig.out ${FUNCTIONS_DIR}/dig.patterns
|
||||
}
|
||||
|
||||
check_utils () {
|
||||
#Test dhcp_lease_time and dhcp_release
|
||||
leases_file='/var/lib/misc/dnsmasq.leases'
|
||||
client_ip_address=`cut -d' ' -f3 $leases_file`
|
||||
client_mac_address=`cut -d' ' -f2 $leases_file`
|
||||
echo ~~~ Test dhcp_lease_time...
|
||||
if ! dhcp_lease_time $client_ip_address; then
|
||||
error_exit "'dhcp_lease_time $client_ip_address' failed with return code $?"
|
||||
else
|
||||
#Add \n to dhcp_lease_time's output
|
||||
echo ''
|
||||
fi
|
||||
echo ~~~ Test dhcp_release...
|
||||
cat $leases_file
|
||||
if ! dhcp_release veth0 $client_ip_address 1-$client_mac_address; then
|
||||
error_exit "'dhcp_release veth0 $client_ip_address 1-$client_mac_address' failed with return code $?0"
|
||||
fi
|
||||
if [ -n "`cat $leases_file`" ]; then
|
||||
cat $leases_file
|
||||
error_exit "$leases_file is not empty"
|
||||
fi
|
||||
}
|
||||
|
||||
check_lua_log () {
|
||||
log_file='/var/log/dnsmasq-lua.log'
|
||||
echo ~~~ Check log file generated by lua script
|
||||
ls -l ${log_file}
|
||||
if [ -s ${log_file} ]; then
|
||||
cat ${log_file}
|
||||
match_or_exit ${log_file} ${FUNCTIONS_DIR}/log.patterns
|
||||
else
|
||||
error_exit "${log_file} is empty"
|
||||
fi
|
||||
}
|
||||
18
debian/tests/functions.d/add-to.interfaces
vendored
Normal file
18
debian/tests/functions.d/add-to.interfaces
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
auto dummy0
|
||||
iface dummy0 inet static
|
||||
pre-up ip link add dummy0 type dummy
|
||||
address 192.168.141.1
|
||||
netmask 255.255.255.248
|
||||
post-down ip link del dummy0
|
||||
|
||||
auto veth0
|
||||
iface veth0 inet static
|
||||
pre-up ip netns add clientnet
|
||||
pre-up ip link add veth0 type veth peer veth1 netns clientnet
|
||||
address 192.168.142.1
|
||||
netmask 255.255.255.248
|
||||
post-down ip link del veth0
|
||||
post-down ip netns del clientnet
|
||||
|
||||
iface veth1 inet dhcp
|
||||
2
debian/tests/functions.d/add-to.named.conf.local
vendored
Normal file
2
debian/tests/functions.d/add-to.named.conf.local
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
zone "autopkg.test" { type master; file "/etc/bind/db.autopkg.test"; };
|
||||
|
||||
18
debian/tests/functions.d/db.autopkg.test
vendored
Normal file
18
debian/tests/functions.d/db.autopkg.test
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
$TTL 604800
|
||||
@ IN SOA ns.autopkg.test. hostmaster.autopkg.test. (
|
||||
2 ; Serial
|
||||
604800 ; Refresh
|
||||
86400 ; Retry
|
||||
2419200 ; Expire
|
||||
300 ) ; Negative Cache TTL
|
||||
;
|
||||
@ IN NS ns
|
||||
ns IN A 192.168.141.1
|
||||
host IN A 192.168.142.1
|
||||
dhcp0 IN A 192.168.142.2
|
||||
dhcp1 IN A 192.168.142.3
|
||||
dhcp2 IN A 192.168.142.4
|
||||
dhcp3 IN A 192.168.142.5
|
||||
dhcp4 IN A 192.168.142.6
|
||||
brdcst IN A 192.168.142.7
|
||||
|
||||
4
debian/tests/functions.d/dig.patterns
vendored
Normal file
4
debian/tests/functions.d/dig.patterns
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
ns.autopkg.test. hostmaster.autopkg.test. 2 604800 86400 2419200 300
|
||||
ns.autopkg.test.
|
||||
192.168.141.1
|
||||
192.168.142.5
|
||||
6
debian/tests/functions.d/dnsmasq-autopkgtest.conf
vendored
Normal file
6
debian/tests/functions.d/dnsmasq-autopkgtest.conf
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
no-resolv
|
||||
server=/autopkg.test/192.168.141.1
|
||||
listen-address=192.168.142.1,127.0.0.1
|
||||
bind-interfaces
|
||||
dhcp-range=192.168.142.2,192.168.142.6
|
||||
dhcp-authoritative
|
||||
42
debian/tests/functions.d/dnsmasq.alt-autopkgtest.default
vendored
Normal file
42
debian/tests/functions.d/dnsmasq.alt-autopkgtest.default
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
# This file has six functions:
|
||||
# 1) to completely disable starting this dnsmasq instance
|
||||
# 2) to set DOMAIN_SUFFIX by running `dnsdomainname`
|
||||
# 3) to select an alternative config file
|
||||
# by setting DNSMASQ_OPTS to --conf-file=<file>
|
||||
# 4) to tell dnsmasq to read the files in /etc/dnsmasq.d for
|
||||
# more configuration variables.
|
||||
# 5) to stop the resolvconf package from controlling dnsmasq's
|
||||
# idea of which upstream nameservers to use.
|
||||
# 6) to avoid using this dnsmasq instance as the system's default resolver
|
||||
# by setting DNSMASQ_EXCEPT="lo"
|
||||
# For upgraders from very old versions, all the shell variables set
|
||||
# here in previous versions are still honored by the init script
|
||||
# so if you just keep your old version of this file nothing will break.
|
||||
|
||||
#DOMAIN_SUFFIX=`dnsdomainname`
|
||||
DNSMASQ_OPTS="--conf-file=/etc/dnsmasq.alt.conf"
|
||||
|
||||
# The dnsmasq daemon is run by default conforming to the Debian Policy.
|
||||
# To disable the service,
|
||||
# for SYSV init, use "update-rc.d dnsmasq disable",
|
||||
# for systemd, use "systemctl disable dnsmasq".
|
||||
|
||||
# By default search this drop directory for configuration options.
|
||||
# Libvirt leaves a file here to make the system dnsmasq play nice.
|
||||
# Comment out this line if you don't want this. The dpkg-* are file
|
||||
# endings which cause dnsmasq to skip that file. This avoids pulling
|
||||
# in backups made by dpkg.
|
||||
CONFIG_DIR=/etc/dnsmasq.alt.d,.dpkg-dist,.dpkg-old,.dpkg-new
|
||||
|
||||
# If the resolvconf package is installed, dnsmasq will use its output
|
||||
# rather than the contents of /etc/resolv.conf to find upstream
|
||||
# nameservers. Uncommenting this line inhibits this behaviour.
|
||||
# Note that including a "resolv-file=<filename>" line in
|
||||
# /etc/dnsmasq.conf is not enough to override resolvconf if it is
|
||||
# installed: the line below must be uncommented.
|
||||
#IGNORE_RESOLVCONF=yes
|
||||
|
||||
# If the resolvconf package is installed, dnsmasq will tell resolvconf
|
||||
# to use dnsmasq under 127.0.0.1 as the system's default resolver.
|
||||
# Uncommenting this line inhibits this behaviour.
|
||||
#DNSMASQ_EXCEPT="lo"
|
||||
6
debian/tests/functions.d/ip-addr.patterns
vendored
Normal file
6
debian/tests/functions.d/ip-addr.patterns
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
?: veth1@if?: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
|
||||
link/ether ??:??:??:??:??:?? brd ff:ff:ff:ff:ff:ff link-netnsid 0
|
||||
inet 192.168.142.?/29 brd 192.168.142.7 scope global dynamic veth1
|
||||
valid_lft 3[56][0-9][0-9]sec preferred_lft 3[56][0-9][0-9]sec
|
||||
inet6 fe80::*:*:*:*/64 scope link*
|
||||
valid_lft forever preferred_lft forever
|
||||
40
debian/tests/functions.d/log.lua
vendored
Normal file
40
debian/tests/functions.d/log.lua
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
-- Lua script logging calls from dnsmasq
|
||||
|
||||
-- Open the log file in append mode
|
||||
logfile = assert(io.open("/var/log/dnsmasq-lua.log", "a"))
|
||||
|
||||
-- Prepend date and time to a string and write the result to the log file
|
||||
function __log(str)
|
||||
logfile:write(os.date("!%FT%TZ ")..str.."\n")
|
||||
end
|
||||
|
||||
-- flush the log file
|
||||
function __flush_log()
|
||||
logfile:flush()
|
||||
end
|
||||
|
||||
-- Log a call to init()
|
||||
function init()
|
||||
__log("initialising")
|
||||
__flush_log()
|
||||
end
|
||||
|
||||
-- Log a call to shutdown()
|
||||
function shutdown()
|
||||
__log("shutting down")
|
||||
__flush_log()
|
||||
end
|
||||
|
||||
-- Log a call to lease() including all arguments
|
||||
function lease(operation, params)
|
||||
local lines = {}
|
||||
__log(operation.." lease")
|
||||
for key,value in pairs(params) do
|
||||
table.insert(lines, key..": "..value)
|
||||
end
|
||||
table.sort(lines)
|
||||
for index,line in ipairs(lines) do
|
||||
__log("\t"..line)
|
||||
end
|
||||
__flush_log()
|
||||
end
|
||||
10
debian/tests/functions.d/log.patterns
vendored
Normal file
10
debian/tests/functions.d/log.patterns
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
????-??-??T??:??:??Z initialising
|
||||
????-??-??T??:??:??Z add lease
|
||||
????-??-??T??:??:??Z client_id: ??:??:??:??:??:??:??:??:??:??:??:??:??:??:??:??:??:??:??
|
||||
????-??-??T??:??:??Z data_missing: 1.0
|
||||
????-??-??T??:??:??Z hostname: ?*
|
||||
????-??-??T??:??:??Z interface: veth0
|
||||
????-??-??T??:??:??Z ip_address: 192.168.142.[2-6]
|
||||
????-??-??T??:??:??Z lease_expires: [1-9]*
|
||||
????-??-??T??:??:??Z mac_address: ??:??:??:??:??:??
|
||||
????-??-??T??:??:??Z time_remaining: 3600.0
|
||||
6
debian/tests/functions.d/named.conf.options
vendored
Normal file
6
debian/tests/functions.d/named.conf.options
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
options {
|
||||
directory "/var/cache/bind";
|
||||
listen-on { 192.168.141.1; };
|
||||
recursion no;
|
||||
};
|
||||
|
||||
1
debian/tests/functions.d/options+lua.patterns
vendored
Normal file
1
debian/tests/functions.d/options+lua.patterns
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*: IPv6 GNU-getopt DBus no-UBus i18n IDN2 DHCP DHCPv6 Lua TFTP conntrack ipset nftset auth cryptohash DNSSEC loop-detect inotify dumpfile
|
||||
1
debian/tests/functions.d/options.patterns
vendored
Normal file
1
debian/tests/functions.d/options.patterns
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*: IPv6 GNU-getopt DBus no-UBus i18n IDN2 DHCP DHCPv6 no-Lua TFTP conntrack ipset nftset auth cryptohash DNSSEC loop-detect inotify dumpfile
|
||||
19
debian/tests/get-address+query-dns+check-utils
vendored
Executable file
19
debian/tests/get-address+query-dns+check-utils
vendored
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
. debian/tests/functions
|
||||
|
||||
stop_dnsmasq_bind_networking
|
||||
configure_and_start_networking
|
||||
configure_and_start_bind
|
||||
configure_and_start_dnsmasq
|
||||
|
||||
get_address_on_veth1_and_check_the_result
|
||||
|
||||
query_test_zone_records_and_check_the_result
|
||||
|
||||
check_utils
|
||||
|
||||
#Done
|
||||
echo Looks good.
|
||||
19
debian/tests/get-address+query-dns+lua+alt
vendored
Executable file
19
debian/tests/get-address+query-dns+lua+alt
vendored
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
. debian/tests/functions
|
||||
|
||||
stop_dnsmasq_bind_networking
|
||||
configure_and_start_networking
|
||||
configure_and_start_bind
|
||||
configure_and_start_dnsmasq lua alt
|
||||
|
||||
get_address_on_veth1_and_check_the_result
|
||||
|
||||
query_test_zone_records_and_check_the_result
|
||||
|
||||
check_lua_log
|
||||
|
||||
#Done
|
||||
echo Looks good.
|
||||
18
debian/tests/get-address+query-dns+sysv+alt
vendored
Executable file
18
debian/tests/get-address+query-dns+sysv+alt
vendored
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
. debian/tests/functions
|
||||
|
||||
stop_dnsmasq_bind_networking
|
||||
configure_and_start_networking
|
||||
configure_and_start_bind
|
||||
configure_and_start_dnsmasq sysv alt
|
||||
|
||||
get_address_on_veth1_and_check_the_result
|
||||
|
||||
query_test_zone_records_and_check_the_result
|
||||
|
||||
#Done
|
||||
echo Looks good.
|
||||
SYSTEMCTL_SKIP_REDIRECT=1 /etc/init.d/dnsmasq stop alt
|
||||
Reference in New Issue
Block a user