diff --git a/run-tests b/run-tests index 8d4b751..677f346 100755 --- a/run-tests +++ b/run-tests @@ -70,8 +70,8 @@ function ip { _log "ip called with: ${@}" [[ "${1} ${2} ${3} ${4}" == "link show dev ${dev}" ]] && \ - _pass "ip called with correct arguments" || \ - _fail "ip called with incorrect or unknown arguments" + _pass "ip was called correctly" || \ + _fail "ip was called with incorrect or unknown arguments" # Return fake ip statement echo -e "${ip_ifindex}: ${dev}: " \ @@ -127,6 +127,10 @@ for TEST in tests/*.sh; do # external calls out to system commands source update-systemd-resolved + [[ ${?} -eq 0 ]] && + _pass "script exited with a 0 exit status" || \ + _fail "script exited with a ${1} exit status" + if [[ ${TEST_BUSCTL_CALLED} -eq 0 ]]; then [[ ${busctl_called} -eq 0 ]] && \ _pass "busctl was not called, as expected" || \ @@ -134,8 +138,10 @@ for TEST in tests/*.sh; do fi echo - done echo -e " ${GREEN}${PASS} ${COUNT_PASS} Passed${RESET}" echo -e " ${RED}${FAIL} ${COUNT_FAIL} Failed${RESET}" + +# Make sure we fail if there are failed tests +[[ ${COUNT_FAIL} -eq 0 ]] diff --git a/tests/10_single_ipv6_dns_full.sh b/tests/10_single_ipv6_dns_full.sh new file mode 100644 index 0000000..c594f53 --- /dev/null +++ b/tests/10_single_ipv6_dns_full.sh @@ -0,0 +1,8 @@ +script_type="up" +dev="tun10" +foreign_option_1="dhcp-option DNS 1234:5678:90ab:cdef:4321:8765:ba09:fedc" + +TEST_TITLE="Single IPv6 DNS Server (Full)" +TEST_BUSCTL_CALLED=1 +TEST_BUSCTL_DNS="1 2 16 18 52 86 120 144 171 205 239 67 33 135 101 186 9 254 220" +TEST_BUSCTL_DOMAINS="" diff --git a/tests/11_single_ipv6_dns_simple.sh b/tests/11_single_ipv6_dns_simple.sh new file mode 100644 index 0000000..b4660f8 --- /dev/null +++ b/tests/11_single_ipv6_dns_simple.sh @@ -0,0 +1,8 @@ +script_type="up" +dev="tun11" +foreign_option_1="dhcp-option DNS 1234:567:89:0:ab:cde:f123:4567" + +TEST_TITLE="Single IPv6 DNS Server (Full, Simple)" +TEST_BUSCTL_CALLED=1 +TEST_BUSCTL_DNS="1 2 16 18 52 5 103 0 137 0 0 0 171 12 222 241 35 69 103" +TEST_BUSCTL_DOMAINS="" diff --git a/tests/12_single_ipv6_dns_compact_1.sh b/tests/12_single_ipv6_dns_compact_1.sh new file mode 100644 index 0000000..10d234d --- /dev/null +++ b/tests/12_single_ipv6_dns_compact_1.sh @@ -0,0 +1,8 @@ +script_type="up" +dev="tun12" +foreign_option_1="dhcp-option DNS 1234:567:89::ab:cde:f123:4567" + +TEST_TITLE="Single IPv6 DNS Server (Compact) (Part 1)" +TEST_BUSCTL_CALLED=1 +TEST_BUSCTL_DNS="1 2 16 18 52 5 103 0 137 0 0 0 171 12 222 241 35 69 103" +TEST_BUSCTL_DOMAINS="" diff --git a/tests/13_single_ipv6_dns_compact_2.sh b/tests/13_single_ipv6_dns_compact_2.sh new file mode 100644 index 0000000..7452b5f --- /dev/null +++ b/tests/13_single_ipv6_dns_compact_2.sh @@ -0,0 +1,8 @@ +script_type="up" +dev="tun13" +foreign_option_1="dhcp-option DNS 1234:567:89::ab:cdef" + +TEST_TITLE="Single IPv6 DNS Server (Compact) (Part 2)" +TEST_BUSCTL_CALLED=1 +TEST_BUSCTL_DNS="1 2 16 18 52 5 103 0 137 0 0 0 0 0 0 0 171 205 239" +TEST_BUSCTL_DOMAINS="" diff --git a/tests/14_single_ipv6_dns_compact_3.sh b/tests/14_single_ipv6_dns_compact_3.sh new file mode 100644 index 0000000..0f469c8 --- /dev/null +++ b/tests/14_single_ipv6_dns_compact_3.sh @@ -0,0 +1,8 @@ +script_type="up" +dev="tun14" +foreign_option_1="dhcp-option DNS 20a0::1" + +TEST_TITLE="Single IPv6 DNS Server (Compact) (Part 3)" +TEST_BUSCTL_CALLED=1 +TEST_BUSCTL_DNS="1 2 16 32 160 0 0 0 0 0 0 0 0 0 0 0 0 0 1" +TEST_BUSCTL_DOMAINS="" diff --git a/tests/15_single_ipv6_dns_localhost.sh b/tests/15_single_ipv6_dns_localhost.sh new file mode 100644 index 0000000..c531c07 --- /dev/null +++ b/tests/15_single_ipv6_dns_localhost.sh @@ -0,0 +1,8 @@ +script_type="up" +dev="tun15" +foreign_option_1="dhcp-option DNS ::1" + +TEST_TITLE="Single IPv6 DNS Server (Localhost)" +TEST_BUSCTL_CALLED=1 +TEST_BUSCTL_DNS="1 2 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1" +TEST_BUSCTL_DOMAINS="" diff --git a/tests/16_dual_ipv6_single_ipv4.sh b/tests/16_dual_ipv6_single_ipv4.sh new file mode 100644 index 0000000..07c5e01 --- /dev/null +++ b/tests/16_dual_ipv6_single_ipv4.sh @@ -0,0 +1,9 @@ +script_type="up" +dev="tun16" +foreign_option_1="dhcp-option DNS 1234:567:89::ab:cdef" +foreign_option_2="dhcp-option DNS 1.23.4.56" + +TEST_TITLE="Single IPv6 and Single IPv4 DNS Servers" +TEST_BUSCTL_CALLED=1 +TEST_BUSCTL_DNS="2 2 16 18 52 5 103 0 137 0 0 0 0 0 0 0 171 205 239 2 4 1 23 4 56" +TEST_BUSCTL_DOMAINS="" diff --git a/tests/17_single_ipv6_single_ipv4.sh b/tests/17_single_ipv6_single_ipv4.sh new file mode 100644 index 0000000..0ed5e0d --- /dev/null +++ b/tests/17_single_ipv6_single_ipv4.sh @@ -0,0 +1,10 @@ +script_type="up" +dev="tun17" +foreign_option_1="dhcp-option DNS 1234:567:89::ab:cdef" +foreign_option_2="dhcp-option DNS 1.23.4.56" +foreign_option_3="dhcp-option DNS 20a0::1" + +TEST_TITLE="Single IPv6 and Single IPv4 DNS Servers" +TEST_BUSCTL_CALLED=1 +TEST_BUSCTL_DNS="3 2 16 18 52 5 103 0 137 0 0 0 0 0 0 0 171 205 239 2 4 1 23 4 56 2 16 32 160 0 0 0 0 0 0 0 0 0 0 0 0 0 1" +TEST_BUSCTL_DOMAINS="" diff --git a/tests/18_dns_ipv4_ipv6_domain_and_search.sh b/tests/18_dns_ipv4_ipv6_domain_and_search.sh new file mode 100644 index 0000000..2be1243 --- /dev/null +++ b/tests/18_dns_ipv4_ipv6_domain_and_search.sh @@ -0,0 +1,13 @@ +script_type="up" +dev="tun18" +foreign_option_1="dhcp-option DNS 1.23.4.56" +foreign_option_2="dhcp-option DNS 2.34.56.7" +foreign_option_3="dhcp-option DNS 1234:567:89::ab:cdef" +foreign_option_4="dhcp-option DNS 1234:567:89::ba:cdef" +foreign_option_5="dhcp-option DOMAIN example.com" +foreign_option_6="dhcp-option DOMAIN-SEARCH example.co" + +TEST_TITLE="DNS IPv4 and IPv6 Servers, plus Domain and Search" +TEST_BUSCTL_CALLED=1 +TEST_BUSCTL_DNS="4 2 4 1 23 4 56 2 4 2 34 56 7 2 16 18 52 5 103 0 137 0 0 0 0 0 0 0 171 205 239 2 16 18 52 5 103 0 137 0 0 0 0 0 0 0 186 205 239" +TEST_BUSCTL_DOMAINS="2 example.com false example.co true" diff --git a/update-systemd-resolved b/update-systemd-resolved index 34f2880..b8498e9 100755 --- a/update-systemd-resolved +++ b/update-systemd-resolved @@ -61,9 +61,28 @@ case $script_type in dns_server_count=$((dns_server_count+1)) if [[ "${address}" =~ ":" ]]; then log "Adding IPv6 DNS Server ${address}" - # The following is a placeholder. Will need a way to convert to - # full address and then break into a 16 byte array - # dns_servers="2 16 ${address//:/ }" + # Add array count and byte count + dns_servers="${dns_servers} 2 16" + declare -a fields + if [[ "${address}" =~ "::" ]]; then + declare -a split + count_left=0; count_right=0 + split=(${address//::/ }) + [[ -z "${split[1]}" ]] && \ + split[1]="${split[0]}" && split[0]="0" + address="${split[0]}" + fields=(${split[0]//:/ }); count_left=${#fields[@]} + fields=(${split[1]//:/ }); count_right=${#fields[@]} + for null in $(seq 1 $((8-(count_left+count_right)))); do + address+=":0" + done + address+=":${split[1]}" + fi + fields=("${address//:/ }") + for field in ${fields[@]}; do + field_full="$(printf "%04x" "0x${field}")" + dns_servers="${dns_servers} $((16#${field_full:0:2})) $((16#${field_full:2:2}))" + done else log "Adding IPv4 DNS Server ${address}" dns_servers="${dns_servers} 2 4 ${address//./ }" @@ -73,14 +92,14 @@ case $script_type in domain="${setting//DOMAIN }" [[ -z "${domain}" ]] && continue dns_domain_count=$((dns_domain_count+1)) - log "Adding DNS Domain ${address}" + log "Adding DNS Domain ${domain}" dns_domains="${dns_domains} ${domain} false" ;; DOMAIN-SEARCH) domain="${setting//DOMAIN-SEARCH }" [[ -z "${domain}" ]] && continue dns_domain_count=$((dns_domain_count+1)) - log "Adding DNS Search Domain ${address}" + log "Adding DNS Search Domain ${domain}" dns_domains="${dns_domains} ${domain} true" ;; esac