diff --git a/run-tests b/run-tests index f06396c..e751c55 100755 --- a/run-tests +++ b/run-tests @@ -132,6 +132,9 @@ function runtest { [[ ${busctl_called} -eq 0 ]] && \ _pass "busctl was not called, as expected" || \ _fail "busctl was called, not expected" + else + [[ ${busctl_called} -eq 0 ]] && \ + _fail "busctl was not called, not expected" fi echo diff --git a/tests/03_multiple_ipv4_dns_1.sh b/tests/03a_multiple_ipv4_dns_1.sh similarity index 100% rename from tests/03_multiple_ipv4_dns_1.sh rename to tests/03a_multiple_ipv4_dns_1.sh diff --git a/tests/04_multiple_ipv4_dns_2.sh b/tests/03b_multiple_ipv4_dns_2.sh similarity index 95% rename from tests/04_multiple_ipv4_dns_2.sh rename to tests/03b_multiple_ipv4_dns_2.sh index 55d5683..ec0d172 100644 --- a/tests/04_multiple_ipv4_dns_2.sh +++ b/tests/03b_multiple_ipv4_dns_2.sh @@ -1,5 +1,5 @@ script_type="up" -dev="tun04" +dev="tun03" foreign_option_1="dhcp-option DNS 1.23.4.56" foreign_option_2="dhcp-option DNS 5.6.7.89" foreign_option_3="dhcp-option DNS 34.5.67.8" diff --git a/tests/05_dns_domain_only.sh b/tests/04a_single_dns_domain.sh similarity index 75% rename from tests/05_dns_domain_only.sh rename to tests/04a_single_dns_domain.sh index 0f5baaa..5038ad2 100644 --- a/tests/05_dns_domain_only.sh +++ b/tests/04a_single_dns_domain.sh @@ -1,7 +1,7 @@ script_type="up" -dev="tun05" +dev="tun04" foreign_option_1="dhcp-option DOMAIN example.com" -TEST_TITLE="DNS Domain Only" +TEST_TITLE="Single DNS Domain" TEST_BUSCTL_CALLED=1 TEST_BUSCTL_DOMAINS="1 example.com false" diff --git a/tests/04b_multiple_dns_domains.sh b/tests/04b_multiple_dns_domains.sh new file mode 100644 index 0000000..7b985a1 --- /dev/null +++ b/tests/04b_multiple_dns_domains.sh @@ -0,0 +1,8 @@ +script_type="up" +dev="tun04" +foreign_option_1="dhcp-option DOMAIN example.com" +foreign_option_2="dhcp-option DOMAIN example.co" + +TEST_TITLE="Multiple DNS Domains" +TEST_BUSCTL_CALLED=1 +TEST_BUSCTL_DOMAINS="1 example.co false" diff --git a/tests/06_dns_domain_and_search_1.sh b/tests/05a_dns_domain_and_search_1.sh similarity index 54% rename from tests/06_dns_domain_and_search_1.sh rename to tests/05a_dns_domain_and_search_1.sh index c5bfe15..9a0d6a6 100644 --- a/tests/06_dns_domain_and_search_1.sh +++ b/tests/05a_dns_domain_and_search_1.sh @@ -1,8 +1,8 @@ script_type="up" -dev="tun06" +dev="tun05" foreign_option_1="dhcp-option DOMAIN example.com" foreign_option_2="dhcp-option DOMAIN-SEARCH example.org" -TEST_TITLE="DNS Domain and Search (Part 1)" +TEST_TITLE="DNS Single Domain and Single Search" TEST_BUSCTL_CALLED=1 -TEST_BUSCTL_DOMAINS="2 example.com false example.org true" +TEST_BUSCTL_DOMAINS="2 example.com false example.org false" diff --git a/tests/07_dns_domain_and_search_2.sh b/tests/05b_dns_domain_and_search_2.sh similarity index 59% rename from tests/07_dns_domain_and_search_2.sh rename to tests/05b_dns_domain_and_search_2.sh index e548052..a76b3cd 100644 --- a/tests/07_dns_domain_and_search_2.sh +++ b/tests/05b_dns_domain_and_search_2.sh @@ -1,9 +1,9 @@ script_type="up" -dev="tun07" +dev="tun05" foreign_option_1="dhcp-option DOMAIN example.com" foreign_option_2="dhcp-option DOMAIN-SEARCH example.org" foreign_option_3="dhcp-option DOMAIN-SEARCH example.net" -TEST_TITLE="DNS Domain and Search (Part 2)" +TEST_TITLE="DNS Single Domain and Dual Search" TEST_BUSCTL_CALLED=1 -TEST_BUSCTL_DOMAINS="3 example.com false example.org true example.net true" +TEST_BUSCTL_DOMAINS="3 example.com false example.org false example.net false" diff --git a/tests/05c_dns_domain_and_search_3.sh b/tests/05c_dns_domain_and_search_3.sh new file mode 100644 index 0000000..39d8dda --- /dev/null +++ b/tests/05c_dns_domain_and_search_3.sh @@ -0,0 +1,9 @@ +script_type="up" +dev="tun05" +foreign_option_1="dhcp-option DOMAIN-SEARCH example.org" +foreign_option_2="dhcp-option DOMAIN example.com" +foreign_option_3="dhcp-option DOMAIN-SEARCH example.net" + +TEST_TITLE="DNS Single Domain and Dual Search (with Order Check)" +TEST_BUSCTL_CALLED=1 +TEST_BUSCTL_DOMAINS="3 example.com false example.org false example.net false" diff --git a/tests/05d_dns_domain_and_search_4.sh b/tests/05d_dns_domain_and_search_4.sh new file mode 100644 index 0000000..6d3b61f --- /dev/null +++ b/tests/05d_dns_domain_and_search_4.sh @@ -0,0 +1,10 @@ +script_type="up" +dev="tun05" +foreign_option_1="dhcp-option DOMAIN-SEARCH example.org" +foreign_option_2="dhcp-option DOMAIN example.co" +foreign_option_3="dhcp-option DOMAIN example.com" +foreign_option_4="dhcp-option DOMAIN-SEARCH example.net" + +TEST_TITLE="DNS Dual Domain and Dual Search (with Order Check)" +TEST_BUSCTL_CALLED=1 +TEST_BUSCTL_DOMAINS="3 example.com false example.org false example.net false" diff --git a/tests/06a_single_domain_route.sh b/tests/06a_single_domain_route.sh new file mode 100644 index 0000000..61275b0 --- /dev/null +++ b/tests/06a_single_domain_route.sh @@ -0,0 +1,7 @@ +script_type="up" +dev="tun06" +foreign_option_1="dhcp-option DOMAIN-ROUTE example.com" + +TEST_TITLE="Single DNS Route" +TEST_BUSCTL_CALLED=1 +TEST_BUSCTL_DOMAINS="1 example.com true" diff --git a/tests/06b_multiple_domain_routes.sh b/tests/06b_multiple_domain_routes.sh new file mode 100644 index 0000000..0829512 --- /dev/null +++ b/tests/06b_multiple_domain_routes.sh @@ -0,0 +1,9 @@ +script_type="up" +dev="tun06" +foreign_option_1="dhcp-option DOMAIN-ROUTE example.com" +foreign_option_2="dhcp-option DOMAIN-ROUTE example.co" +foreign_option_3="dhcp-option DOMAIN-ROUTE example.co.uk" + +TEST_TITLE="Single DNS Route" +TEST_BUSCTL_DOMAINS="3 example.com true example.co true example.co.uk true" +TEST_BUSCTL_CALLED=1 diff --git a/tests/07a_dns_domain_search_and_route_1.sh b/tests/07a_dns_domain_search_and_route_1.sh new file mode 100644 index 0000000..0d1e8e0 --- /dev/null +++ b/tests/07a_dns_domain_search_and_route_1.sh @@ -0,0 +1,10 @@ +script_type="up" +dev="tun07" +foreign_option_1="dhcp-option DOMAIN example.com" +foreign_option_2="dhcp-option DOMAIN-SEARCH example.org" +foreign_option_3="dhcp-option DOMAIN-SEARCH example.co.uk" +foreign_option_4="dhcp-option DOMAIN-ROUTE example.net" + +TEST_TITLE="DNS Single Domain, Dual Search, Single Route" +TEST_BUSCTL_CALLED=1 +TEST_BUSCTL_DOMAINS="4 example.com false example.org false example.co.uk false example.net true" diff --git a/tests/07b_dns_domain_search_and_route_2.sh b/tests/07b_dns_domain_search_and_route_2.sh new file mode 100644 index 0000000..177eb6c --- /dev/null +++ b/tests/07b_dns_domain_search_and_route_2.sh @@ -0,0 +1,12 @@ +script_type="up" +dev="tun07" +foreign_option_1="dhcp-option DOMAIN example.com" +foreign_option_2="dhcp-option DOMAIN-SEARCH example.org" +foreign_option_3="dhcp-option DOMAIN-ROUTE example.net" +foreign_option_4="dhcp-option DOMAIN-SEARCH example.co.uk" +foreign_option_5="dhcp-option DOMAIN example.co" +foreign_option_6="dhcp-option DOMAIN-ROUTE example.uk.com" + +TEST_TITLE="DNS Dual Domain, Dual Search, Dual Route (with Order Check)" +TEST_BUSCTL_CALLED=1 +TEST_BUSCTL_DOMAINS="5 example.co false example.org false example.co.uk false example.net true example.uk.com true" diff --git a/tests/08_dns_ipv4_and_domain.sh b/tests/08a_dns_ipv4_and_domain.sh similarity index 100% rename from tests/08_dns_ipv4_and_domain.sh rename to tests/08a_dns_ipv4_and_domain.sh diff --git a/tests/09_dns_ipv4_domain_and_search.sh b/tests/08b_dns_ipv4_domain_and_search.sh similarity index 81% rename from tests/09_dns_ipv4_domain_and_search.sh rename to tests/08b_dns_ipv4_domain_and_search.sh index 2387e3e..327e048 100644 --- a/tests/09_dns_ipv4_domain_and_search.sh +++ b/tests/08b_dns_ipv4_domain_and_search.sh @@ -1,5 +1,5 @@ script_type="up" -dev="tun09" +dev="tun08" foreign_option_1="dhcp-option DNS 1.23.4.56" foreign_option_2="dhcp-option DNS 2.34.5.67" foreign_option_3="dhcp-option DOMAIN example.co.uk" @@ -9,4 +9,4 @@ foreign_option_5="dhcp-option DOMAIN-SEARCH example.com" TEST_TITLE="DNS IPv4 Servers, Domain, and Search" TEST_BUSCTL_CALLED=1 TEST_BUSCTL_DNS="2 2 4 1 23 4 56 2 4 2 34 5 67" -TEST_BUSCTL_DOMAINS="3 example.co.uk false example.co true example.com true" +TEST_BUSCTL_DOMAINS="3 example.co.uk false example.co false example.com false" diff --git a/tests/08b_dns_ipv4_domain_search_and_route.sh b/tests/08b_dns_ipv4_domain_search_and_route.sh new file mode 100644 index 0000000..8b3aadc --- /dev/null +++ b/tests/08b_dns_ipv4_domain_search_and_route.sh @@ -0,0 +1,12 @@ +script_type="up" +dev="tun08" +foreign_option_1="dhcp-option DNS 1.23.4.56" +foreign_option_2="dhcp-option DNS 2.34.5.67" +foreign_option_3="dhcp-option DOMAIN example.co.uk" +foreign_option_4="dhcp-option DOMAIN-SEARCH example.co" +foreign_option_5="dhcp-option DOMAIN-ROUTE example.com" + +TEST_TITLE="DNS IPv4 Servers, Domain, Search, and Route" +TEST_BUSCTL_CALLED=1 +TEST_BUSCTL_DNS="2 2 4 1 23 4 56 2 4 2 34 5 67" +TEST_BUSCTL_DOMAINS="3 example.co.uk false example.co false example.com true" diff --git a/tests/18_dns_ipv4_ipv6_domain_and_search.sh b/tests/18_dns_ipv4_ipv6_domain_and_search.sh index 2be1243..0b592ed 100644 --- a/tests/18_dns_ipv4_ipv6_domain_and_search.sh +++ b/tests/18_dns_ipv4_ipv6_domain_and_search.sh @@ -10,4 +10,4 @@ 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" +TEST_BUSCTL_DOMAINS="2 example.com false example.co false" diff --git a/update-systemd-resolved b/update-systemd-resolved index 791d62e..e2a60b0 100755 --- a/update-systemd-resolved +++ b/update-systemd-resolved @@ -80,8 +80,8 @@ up() { # Preset values for processing -- will be altered in the various process_* # functions. - local -a dns_servers=() dns_domains=() - local -i dns_server_count=0 dns_domain_count=0 + local -a dns_servers=() dns_domain=() dns_search=() dns_routed=() + local -i dns_server_count=0 dns_domain_count=0 dns_search_count=0 dns_routed_count=0 while read -r setting; do setting_type="${setting%% *}" @@ -103,8 +103,20 @@ up() { busctl_call SetLinkDNS 'ia(iay)' "${busctl_params[@]}" || return $? fi - if [[ "${#dns_domains[*]}" -gt 0 ]]; then - busctl_params=("$if_index" "$dns_domain_count" "${dns_domains[@]}") + if [[ "${#dns_domain[*]}" -gt 0 \ + || "${#dns_search[*]}" -gt 0 \ + || "${#dns_routed[*]}" -gt 0 ]]; then + dns_count=$((dns_domain_count+dns_search_count+dns_routed_count)) + busctl_params=("$if_index" "$dns_count") + if [[ "${#dns_domain[*]}" -gt 0 ]]; then + busctl_params+=("${dns_domain[@]}") + fi + if [[ "${#dns_search[*]}" -gt 0 ]]; then + busctl_params+=("${dns_search[@]}") + fi + if [[ "${#dns_routed[*]}" -gt 0 ]]; then + busctl_params+=("${dns_routed[@]}") + fi info "SetLinkDomains(${busctl_params[*]})" busctl_call SetLinkDomains 'ia(sb)' "${busctl_params[@]}" || return $? fi @@ -305,9 +317,9 @@ process_domain() { local domain="$1" shift - info "Adding DNS Domain ${domain}" - (( dns_domain_count += 1 )) - dns_domains+=("${domain}" false) + info "Setting DNS Domain ${domain}" + (( dns_domain_count = 1 )) + dns_domain=("${domain}" false) } process_domain_search() { @@ -315,8 +327,17 @@ process_domain_search() { shift info "Adding DNS Search Domain ${domain}" - (( dns_domain_count += 1 )) - dns_domains+=("${domain}" true) + (( dns_search_count += 1 )) + dns_search+=("${domain}" false) +} + +process_domain_route() { + local domain="$1" + shift + + info "Adding DNS Routed Domain ${domain}" + (( dns_routed_count += 1 )) + dns_routed+=("${domain}" true) } main() {