From d0f2af0ef2ce2f4eaba716067b91b46e008b90a9 Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Wed, 15 Jun 2016 20:40:00 +0100 Subject: [PATCH 01/12] Add first IPv6 tests --- tests/10_single_ipv6_dns_full.sh | 8 ++++++++ tests/11_single_ipv6_dns_simple.sh | 8 ++++++++ 2 files changed, 16 insertions(+) create mode 100644 tests/10_single_ipv6_dns_full.sh create mode 100644 tests/11_single_ipv6_dns_simple.sh diff --git a/tests/10_single_ipv6_dns_full.sh b/tests/10_single_ipv6_dns_full.sh new file mode 100644 index 0000000..2e89dae --- /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 70 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="" From 34ce7d7e1573888d554b788007b5194d25acd268 Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Wed, 15 Jun 2016 20:55:23 +0100 Subject: [PATCH 02/12] Fix wrong octet value in IPv6 test --- tests/10_single_ipv6_dns_full.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/10_single_ipv6_dns_full.sh b/tests/10_single_ipv6_dns_full.sh index 2e89dae..c594f53 100644 --- a/tests/10_single_ipv6_dns_full.sh +++ b/tests/10_single_ipv6_dns_full.sh @@ -4,5 +4,5 @@ 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 70 120 144 171 205 239 67 33 135 101 186 9 254 220" +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="" From f8d4d7434f29af7fb5bc136f129496846b791f21 Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Wed, 15 Jun 2016 20:55:56 +0100 Subject: [PATCH 03/12] Add first support for IPv6 addresses --- update-systemd-resolved | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/update-systemd-resolved b/update-systemd-resolved index 34f2880..dfb6d82 100755 --- a/update-systemd-resolved +++ b/update-systemd-resolved @@ -61,9 +61,14 @@ 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 + 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//./ }" From ae0676e677cb1b4a5ca9eec26f5441466a3075db Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Wed, 15 Jun 2016 21:00:20 +0100 Subject: [PATCH 04/12] Make sure we exit appropriately if we have failed tests --- run-tests | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/run-tests b/run-tests index 8d4b751..4645a1b 100755 --- a/run-tests +++ b/run-tests @@ -134,8 +134,12 @@ 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 ]] \ + && exit 0 \ + || exit 1 From f36bfaaca7e45dab6dcedd4c990b0cf12cf2d53e Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Wed, 15 Jun 2016 21:09:36 +0100 Subject: [PATCH 05/12] Add remaining IPv6 single-address tests --- tests/12_single_ipv6_dns_compact_1.sh | 8 ++++++++ tests/13_single_ipv6_dns_compact_2.sh | 8 ++++++++ tests/14_single_ipv6_dns_compact_3.sh | 8 ++++++++ tests/15_single_ipv6_dns_localhost.sh | 8 ++++++++ 4 files changed, 32 insertions(+) create mode 100644 tests/12_single_ipv6_dns_compact_1.sh create mode 100644 tests/13_single_ipv6_dns_compact_2.sh create mode 100644 tests/14_single_ipv6_dns_compact_3.sh create mode 100644 tests/15_single_ipv6_dns_localhost.sh 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..ccdcd53 --- /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 S0 0 0 0 0 0 0 35 69 103" +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..79ff0c8 --- /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="" From 66fe4e2734bc72bf721e34b6e5208325d1a0d066 Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Wed, 15 Jun 2016 21:15:47 +0100 Subject: [PATCH 06/12] Fix test exit as we've overridden exit call --- run-tests | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/run-tests b/run-tests index 4645a1b..3b0ec23 100755 --- a/run-tests +++ b/run-tests @@ -140,6 +140,4 @@ 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 ]] \ - && exit 0 \ - || exit 1 +[[ ${COUNT_FAIL} -eq 0 ]] From d513f961e562f39401aefdb482f7554b3b242bb2 Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Thu, 16 Jun 2016 21:21:58 +0100 Subject: [PATCH 07/12] Fix invalid address and incorrect result in tests --- tests/13_single_ipv6_dns_compact_2.sh | 2 +- tests/14_single_ipv6_dns_compact_3.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/13_single_ipv6_dns_compact_2.sh b/tests/13_single_ipv6_dns_compact_2.sh index ccdcd53..7452b5f 100644 --- a/tests/13_single_ipv6_dns_compact_2.sh +++ b/tests/13_single_ipv6_dns_compact_2.sh @@ -4,5 +4,5 @@ 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 S0 0 0 0 0 0 0 35 69 103" +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 index 79ff0c8..0f469c8 100644 --- a/tests/14_single_ipv6_dns_compact_3.sh +++ b/tests/14_single_ipv6_dns_compact_3.sh @@ -1,6 +1,6 @@ script_type="up" dev="tun14" -foreign_option_1="dhcp-option DNS 20a0:::1" +foreign_option_1="dhcp-option DNS 20a0::1" TEST_TITLE="Single IPv6 DNS Server (Compact) (Part 3)" TEST_BUSCTL_CALLED=1 From 7535a56337be4ec9c08c2454344193d079c71e28 Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Thu, 16 Jun 2016 21:22:27 +0100 Subject: [PATCH 08/12] Altered output of ip test --- run-tests | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run-tests b/run-tests index 3b0ec23..738915c 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}: " \ From 755badf09e9606cde06436b83fc9529e740ac079 Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Thu, 16 Jun 2016 21:22:47 +0100 Subject: [PATCH 09/12] Add support for shortened IPv6 addresses --- update-systemd-resolved | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/update-systemd-resolved b/update-systemd-resolved index dfb6d82..354e573 100755 --- a/update-systemd-resolved +++ b/update-systemd-resolved @@ -64,6 +64,20 @@ case $script_type in # 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}")" From c21b65cb132bc18857fd8730162887e1c3af6772 Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Thu, 16 Jun 2016 21:37:01 +0100 Subject: [PATCH 10/12] Add additional tests for IPv4/Domain/Search inclusive states --- tests/16_dual_ipv6_single_ipv4.sh | 9 +++++++++ tests/17_single_ipv6_single_ipv4.sh | 10 ++++++++++ tests/18_dns_ipv4_ipv6_domain_and_search.sh | 13 +++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 tests/16_dual_ipv6_single_ipv4.sh create mode 100644 tests/17_single_ipv6_single_ipv4.sh create mode 100644 tests/18_dns_ipv4_ipv6_domain_and_search.sh 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" From 96a0577cfd8c37ceb3c14a3050127c577501bd81 Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Thu, 16 Jun 2016 21:52:31 +0100 Subject: [PATCH 11/12] Check the exit status of the script The script should always exit 0 less the VPN connection be dropped. We now test for that after it's been called in the loop. --- run-tests | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/run-tests b/run-tests index 738915c..677f346 100755 --- a/run-tests +++ b/run-tests @@ -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" || \ From 75f22dc3ce7f83b47194d3b3edfc014c4fd2b00b Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Fri, 17 Jun 2016 09:03:31 +0100 Subject: [PATCH 12/12] Fix logging message for DOMAIN and DOMAIN-SEARCH --- update-systemd-resolved | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/update-systemd-resolved b/update-systemd-resolved index 354e573..b8498e9 100755 --- a/update-systemd-resolved +++ b/update-systemd-resolved @@ -92,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