From c2d6b1af05d511289a5db8c0564f75a9cf3ad8ce Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Mon, 29 Aug 2016 18:23:34 +0100 Subject: [PATCH 01/12] Update tests for new logic around DOMAIN and DOMAIN-SEARCH Both DOMAIN and DOMAIN-SEARCH will now be searchable domains at all times, which will mirror the logic of scripts already built, for example update-resolv-conf and update-systemd-network. We will introduce a new DOMAIN-ROUTE option to better handle the logic specific to systemd-resolved. --- tests/06_dns_domain_and_search_1.sh | 2 +- tests/07_dns_domain_and_search_2.sh | 2 +- tests/09_dns_ipv4_domain_and_search.sh | 2 +- tests/18_dns_ipv4_ipv6_domain_and_search.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/06_dns_domain_and_search_1.sh b/tests/06_dns_domain_and_search_1.sh index c5bfe15..3bba872 100644 --- a/tests/06_dns_domain_and_search_1.sh +++ b/tests/06_dns_domain_and_search_1.sh @@ -5,4 +5,4 @@ foreign_option_2="dhcp-option DOMAIN-SEARCH example.org" TEST_TITLE="DNS Domain and Search (Part 1)" 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/07_dns_domain_and_search_2.sh index e548052..afdafe9 100644 --- a/tests/07_dns_domain_and_search_2.sh +++ b/tests/07_dns_domain_and_search_2.sh @@ -6,4 +6,4 @@ foreign_option_3="dhcp-option DOMAIN-SEARCH example.net" TEST_TITLE="DNS Domain and Search (Part 2)" 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/09_dns_ipv4_domain_and_search.sh b/tests/09_dns_ipv4_domain_and_search.sh index 2387e3e..8ecffc1 100644 --- a/tests/09_dns_ipv4_domain_and_search.sh +++ b/tests/09_dns_ipv4_domain_and_search.sh @@ -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/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" From 857e72e9a6d57158aee5311e5b37df2af4ba3a38 Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Mon, 29 Aug 2016 18:48:30 +0100 Subject: [PATCH 02/12] Add additional test for DOMAIN logic. DOMAIN should only ever allowed once. Any subsequent calls should be override the previous. Additionally, DOMAIN should always be first in the search list as it is the primary name defined. --- .../{05_dns_domain_only.sh => 05a_single_dns_domain.sh} | 2 +- tests/05b_multiple_dns_domains.sh | 8 ++++++++ ...in_and_search_1.sh => 06a_dns_domain_and_search_1.sh} | 2 +- ...in_and_search_2.sh => 06b_dns_domain_and_search_2.sh} | 2 +- tests/06c_dns_domain_and_search_3.sh | 9 +++++++++ 5 files changed, 20 insertions(+), 3 deletions(-) rename tests/{05_dns_domain_only.sh => 05a_single_dns_domain.sh} (82%) create mode 100644 tests/05b_multiple_dns_domains.sh rename tests/{06_dns_domain_and_search_1.sh => 06a_dns_domain_and_search_1.sh} (81%) rename tests/{07_dns_domain_and_search_2.sh => 06b_dns_domain_and_search_2.sh} (86%) create mode 100644 tests/06c_dns_domain_and_search_3.sh diff --git a/tests/05_dns_domain_only.sh b/tests/05a_single_dns_domain.sh similarity index 82% rename from tests/05_dns_domain_only.sh rename to tests/05a_single_dns_domain.sh index 0f5baaa..dc96dbc 100644 --- a/tests/05_dns_domain_only.sh +++ b/tests/05a_single_dns_domain.sh @@ -2,6 +2,6 @@ script_type="up" dev="tun05" 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/05b_multiple_dns_domains.sh b/tests/05b_multiple_dns_domains.sh new file mode 100644 index 0000000..4a666e8 --- /dev/null +++ b/tests/05b_multiple_dns_domains.sh @@ -0,0 +1,8 @@ +script_type="up" +dev="tun05" +foreign_option_1="dhcp-option DOMAIN example.com" +foreign_option_1="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/06a_dns_domain_and_search_1.sh similarity index 81% rename from tests/06_dns_domain_and_search_1.sh rename to tests/06a_dns_domain_and_search_1.sh index 3bba872..bc73c42 100644 --- a/tests/06_dns_domain_and_search_1.sh +++ b/tests/06a_dns_domain_and_search_1.sh @@ -3,6 +3,6 @@ dev="tun06" 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 false" diff --git a/tests/07_dns_domain_and_search_2.sh b/tests/06b_dns_domain_and_search_2.sh similarity index 86% rename from tests/07_dns_domain_and_search_2.sh rename to tests/06b_dns_domain_and_search_2.sh index afdafe9..14d2469 100644 --- a/tests/07_dns_domain_and_search_2.sh +++ b/tests/06b_dns_domain_and_search_2.sh @@ -4,6 +4,6 @@ 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 false example.net false" diff --git a/tests/06c_dns_domain_and_search_3.sh b/tests/06c_dns_domain_and_search_3.sh new file mode 100644 index 0000000..3e8253a --- /dev/null +++ b/tests/06c_dns_domain_and_search_3.sh @@ -0,0 +1,9 @@ +script_type="up" +dev="tun07" +foreign_option_2="dhcp-option DOMAIN-SEARCH example.org" +foreign_option_1="dhcp-option DOMAIN example.com" +foreign_option_3="dhcp-option DOMAIN-SEARCH example.net" + +TEST_TITLE="DNS Single Domain and Dual Search (Order Check)" +TEST_BUSCTL_CALLED=1 +TEST_BUSCTL_DOMAINS="3 example.com false example.org false example.net false" From 6cb50b6c32285334b3cba07cc77b98b29c71fcf1 Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Mon, 29 Aug 2016 19:03:44 +0100 Subject: [PATCH 03/12] Rename some tests --- tests/{03_multiple_ipv4_dns_1.sh => 03a_multiple_ipv4_dns_1.sh} | 0 tests/{04_multiple_ipv4_dns_2.sh => 03b_multiple_ipv4_dns_2.sh} | 0 tests/{05a_single_dns_domain.sh => 04a_single_dns_domain.sh} | 0 .../{05b_multiple_dns_domains.sh => 04b_multiple_dns_domains.sh} | 0 ..._dns_domain_and_search_1.sh => 05a_dns_domain_and_search_1.sh} | 0 ..._dns_domain_and_search_2.sh => 05b_dns_domain_and_search_2.sh} | 0 ..._dns_domain_and_search_3.sh => 05c_dns_domain_and_search_3.sh} | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename tests/{03_multiple_ipv4_dns_1.sh => 03a_multiple_ipv4_dns_1.sh} (100%) rename tests/{04_multiple_ipv4_dns_2.sh => 03b_multiple_ipv4_dns_2.sh} (100%) rename tests/{05a_single_dns_domain.sh => 04a_single_dns_domain.sh} (100%) rename tests/{05b_multiple_dns_domains.sh => 04b_multiple_dns_domains.sh} (100%) rename tests/{06a_dns_domain_and_search_1.sh => 05a_dns_domain_and_search_1.sh} (100%) rename tests/{06b_dns_domain_and_search_2.sh => 05b_dns_domain_and_search_2.sh} (100%) rename tests/{06c_dns_domain_and_search_3.sh => 05c_dns_domain_and_search_3.sh} (100%) 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 100% rename from tests/04_multiple_ipv4_dns_2.sh rename to tests/03b_multiple_ipv4_dns_2.sh diff --git a/tests/05a_single_dns_domain.sh b/tests/04a_single_dns_domain.sh similarity index 100% rename from tests/05a_single_dns_domain.sh rename to tests/04a_single_dns_domain.sh diff --git a/tests/05b_multiple_dns_domains.sh b/tests/04b_multiple_dns_domains.sh similarity index 100% rename from tests/05b_multiple_dns_domains.sh rename to tests/04b_multiple_dns_domains.sh diff --git a/tests/06a_dns_domain_and_search_1.sh b/tests/05a_dns_domain_and_search_1.sh similarity index 100% rename from tests/06a_dns_domain_and_search_1.sh rename to tests/05a_dns_domain_and_search_1.sh diff --git a/tests/06b_dns_domain_and_search_2.sh b/tests/05b_dns_domain_and_search_2.sh similarity index 100% rename from tests/06b_dns_domain_and_search_2.sh rename to tests/05b_dns_domain_and_search_2.sh diff --git a/tests/06c_dns_domain_and_search_3.sh b/tests/05c_dns_domain_and_search_3.sh similarity index 100% rename from tests/06c_dns_domain_and_search_3.sh rename to tests/05c_dns_domain_and_search_3.sh From 630dcfe22a946ad00f06b3ea87e75a53a25eec1c Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Mon, 29 Aug 2016 19:17:39 +0100 Subject: [PATCH 04/12] Change DOMAIN-SEARCH domains to be searchable --- update-systemd-resolved | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update-systemd-resolved b/update-systemd-resolved index 791d62e..5cec339 100755 --- a/update-systemd-resolved +++ b/update-systemd-resolved @@ -316,7 +316,7 @@ process_domain_search() { info "Adding DNS Search Domain ${domain}" (( dns_domain_count += 1 )) - dns_domains+=("${domain}" true) + dns_domains+=("${domain}" false) } main() { From 7775f9da9567cf2625d4584b6221120a6baa85c3 Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Mon, 29 Aug 2016 19:19:28 +0100 Subject: [PATCH 05/12] Alter logic for DOMAIN and DOMAIN-SEARCH Made DOMAIN a specific entry for systemd-resolve as the first searchable domain for an entry, and only a single value take (subsequent calls will override any previously set). --- update-systemd-resolved | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/update-systemd-resolved b/update-systemd-resolved index 5cec339..5b2a73d 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=() + local -i dns_server_count=0 dns_domain_count=0 dns_search_count=0 while read -r setting; do setting_type="${setting%% *}" @@ -103,8 +103,14 @@ 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 ]]; then + busctl_params=("$if_index" "$((dns_domain_count+dns_search_count))") + if [[ "${#dns_domain[*]}" -gt 0 ]]; then + busctl_params+=("${dns_domain[@]}") + fi + if [[ "${#dns_search[*]}" -gt 0 ]]; then + busctl_params+=("${dns_search[@]}") + fi info "SetLinkDomains(${busctl_params[*]})" busctl_call SetLinkDomains 'ia(sb)' "${busctl_params[@]}" || return $? fi @@ -305,9 +311,9 @@ process_domain() { local domain="$1" shift - info "Adding DNS Domain ${domain}" + info "Setting DNS Domain ${domain}" (( dns_domain_count += 1 )) - dns_domains+=("${domain}" false) + dns_domain=("${domain}" false) } process_domain_search() { @@ -315,8 +321,8 @@ process_domain_search() { shift info "Adding DNS Search Domain ${domain}" - (( dns_domain_count += 1 )) - dns_domains+=("${domain}" false) + (( dns_search_count += 1 )) + dns_search+=("${domain}" false) } main() { From c2005a3b26176cad5eefe75eea451b58004b488e Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Mon, 29 Aug 2016 19:28:16 +0100 Subject: [PATCH 06/12] FIx tun names in tests --- tests/03b_multiple_ipv4_dns_2.sh | 2 +- tests/04a_single_dns_domain.sh | 2 +- tests/04b_multiple_dns_domains.sh | 2 +- tests/05a_dns_domain_and_search_1.sh | 2 +- tests/05b_dns_domain_and_search_2.sh | 2 +- tests/05c_dns_domain_and_search_3.sh | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/03b_multiple_ipv4_dns_2.sh b/tests/03b_multiple_ipv4_dns_2.sh index 55d5683..ec0d172 100644 --- a/tests/03b_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/04a_single_dns_domain.sh b/tests/04a_single_dns_domain.sh index dc96dbc..5038ad2 100644 --- a/tests/04a_single_dns_domain.sh +++ b/tests/04a_single_dns_domain.sh @@ -1,5 +1,5 @@ script_type="up" -dev="tun05" +dev="tun04" foreign_option_1="dhcp-option DOMAIN example.com" TEST_TITLE="Single DNS Domain" diff --git a/tests/04b_multiple_dns_domains.sh b/tests/04b_multiple_dns_domains.sh index 4a666e8..cca7ef5 100644 --- a/tests/04b_multiple_dns_domains.sh +++ b/tests/04b_multiple_dns_domains.sh @@ -1,5 +1,5 @@ script_type="up" -dev="tun05" +dev="tun04" foreign_option_1="dhcp-option DOMAIN example.com" foreign_option_1="dhcp-option DOMAIN example.co" diff --git a/tests/05a_dns_domain_and_search_1.sh b/tests/05a_dns_domain_and_search_1.sh index bc73c42..9a0d6a6 100644 --- a/tests/05a_dns_domain_and_search_1.sh +++ b/tests/05a_dns_domain_and_search_1.sh @@ -1,5 +1,5 @@ script_type="up" -dev="tun06" +dev="tun05" foreign_option_1="dhcp-option DOMAIN example.com" foreign_option_2="dhcp-option DOMAIN-SEARCH example.org" diff --git a/tests/05b_dns_domain_and_search_2.sh b/tests/05b_dns_domain_and_search_2.sh index 14d2469..a76b3cd 100644 --- a/tests/05b_dns_domain_and_search_2.sh +++ b/tests/05b_dns_domain_and_search_2.sh @@ -1,5 +1,5 @@ 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" diff --git a/tests/05c_dns_domain_and_search_3.sh b/tests/05c_dns_domain_and_search_3.sh index 3e8253a..9fdea69 100644 --- a/tests/05c_dns_domain_and_search_3.sh +++ b/tests/05c_dns_domain_and_search_3.sh @@ -1,5 +1,5 @@ script_type="up" -dev="tun07" +dev="tun05" foreign_option_2="dhcp-option DOMAIN-SEARCH example.org" foreign_option_1="dhcp-option DOMAIN example.com" foreign_option_3="dhcp-option DOMAIN-SEARCH example.net" From 41fb3fe374908469db184503f9ba0699fcf7d4c1 Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Mon, 29 Aug 2016 19:32:58 +0100 Subject: [PATCH 07/12] Correct foreign_option order for Test 05c This check is supposed to test order, but it relies on the order of the numbers, not the order in the test file. Fix the appended numbers. --- tests/05c_dns_domain_and_search_3.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/05c_dns_domain_and_search_3.sh b/tests/05c_dns_domain_and_search_3.sh index 9fdea69..39d8dda 100644 --- a/tests/05c_dns_domain_and_search_3.sh +++ b/tests/05c_dns_domain_and_search_3.sh @@ -1,9 +1,9 @@ script_type="up" dev="tun05" -foreign_option_2="dhcp-option DOMAIN-SEARCH example.org" -foreign_option_1="dhcp-option DOMAIN example.com" +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 (Order Check)" +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" From 0ce7b9bc9b2b39334b4f84885b671456657a1dfd Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Mon, 29 Aug 2016 19:37:12 +0100 Subject: [PATCH 08/12] Fix handling for multiple DNS Domains Incorrect test 04b meant that the dns_domain_count was incremented with every DOMAIN options supplied, when it should only be set to 1 (i.e. it has a value). Added additional test as well to test alongside DOMAIN-SEARCH. --- tests/04b_multiple_dns_domains.sh | 2 +- tests/05d_dns_domain_and_search_4.sh | 10 ++++++++++ update-systemd-resolved | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 tests/05d_dns_domain_and_search_4.sh diff --git a/tests/04b_multiple_dns_domains.sh b/tests/04b_multiple_dns_domains.sh index cca7ef5..7b985a1 100644 --- a/tests/04b_multiple_dns_domains.sh +++ b/tests/04b_multiple_dns_domains.sh @@ -1,7 +1,7 @@ script_type="up" dev="tun04" foreign_option_1="dhcp-option DOMAIN example.com" -foreign_option_1="dhcp-option DOMAIN example.co" +foreign_option_2="dhcp-option DOMAIN example.co" TEST_TITLE="Multiple DNS Domains" TEST_BUSCTL_CALLED=1 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/update-systemd-resolved b/update-systemd-resolved index 5b2a73d..a46de9b 100755 --- a/update-systemd-resolved +++ b/update-systemd-resolved @@ -312,7 +312,7 @@ process_domain() { shift info "Setting DNS Domain ${domain}" - (( dns_domain_count += 1 )) + (( dns_domain_count = 1 )) dns_domain=("${domain}" false) } From 0c27da1ce397f1e6284adbe5a2f7a9f6aa9ece2a Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Mon, 29 Aug 2016 19:46:06 +0100 Subject: [PATCH 09/12] Add tests for DOMAIN-ROUTE Add in the required tests for DOMAIN-ROUTE so we can check handling. --- tests/06a_single_domain_route.sh | 7 +++++++ tests/06b_multiple_domain_routes.sh | 9 +++++++++ tests/07a_dns_domain_search_and_route_1.sh | 10 ++++++++++ tests/07b_dns_domain_search_and_route_2.sh | 12 ++++++++++++ ...pv4_and_domain.sh => 08a_dns_ipv4_and_domain.sh} | 0 ..._search.sh => 08b_dns_ipv4_domain_and_search.sh} | 2 +- tests/08b_dns_ipv4_domain_search_and_route.sh | 13 +++++++++++++ 7 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 tests/06a_single_domain_route.sh create mode 100644 tests/06b_multiple_domain_routes.sh create mode 100644 tests/07a_dns_domain_search_and_route_1.sh create mode 100644 tests/07b_dns_domain_search_and_route_2.sh rename tests/{08_dns_ipv4_and_domain.sh => 08a_dns_ipv4_and_domain.sh} (100%) rename tests/{09_dns_ipv4_domain_and_search.sh => 08b_dns_ipv4_domain_and_search.sh} (97%) create mode 100644 tests/08b_dns_ipv4_domain_search_and_route.sh 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 97% rename from tests/09_dns_ipv4_domain_and_search.sh rename to tests/08b_dns_ipv4_domain_and_search.sh index 8ecffc1..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" 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..683eb2a --- /dev/null +++ b/tests/08b_dns_ipv4_domain_search_and_route.sh @@ -0,0 +1,13 @@ +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-SEARCH example.com" +foreign_option_6="dhcp-option DOMAIN-ROUTE example.net" + +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 false example.net true" From 92c136ac05856505f2f7ee9158adf691b85e09c6 Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Mon, 29 Aug 2016 19:46:52 +0100 Subject: [PATCH 10/12] Ensure that run-tests checks busctl was run run-tests assumed that busctl always ran if TEST_BUSCTL_CALLED was called. If it is expected, and busctl_called is not set, that should be a fail! --- run-tests | 3 +++ 1 file changed, 3 insertions(+) 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 From 02d128c74c2771e370fc06035a95818ea3c634dc Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Mon, 29 Aug 2016 19:51:40 +0100 Subject: [PATCH 11/12] Fix Test 08b to ensure correct domain count --- tests/08b_dns_ipv4_domain_search_and_route.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/08b_dns_ipv4_domain_search_and_route.sh b/tests/08b_dns_ipv4_domain_search_and_route.sh index 683eb2a..8b3aadc 100644 --- a/tests/08b_dns_ipv4_domain_search_and_route.sh +++ b/tests/08b_dns_ipv4_domain_search_and_route.sh @@ -4,10 +4,9 @@ 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-SEARCH example.com" -foreign_option_6="dhcp-option DOMAIN-ROUTE example.net" +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 false example.net true" +TEST_BUSCTL_DOMAINS="3 example.co.uk false example.co false example.com true" From 71678f9bebb38faed377c454d1696012c9202ab9 Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Mon, 29 Aug 2016 19:54:47 +0100 Subject: [PATCH 12/12] Add support for DOMAIN-ROUTE processing Add support for DOMAIN-ROUTE as an option to be passed to the script which will specify the listed domain to be routed using systemd-resolved via this VPN link using the DNS servers specified. This is not the same as DOMAIN or DOMAIN-SEARCH, as both of those options will allow systemd-resolved to append them to any bare name for searching (as in keeping with update-resolv-conf and update-systemd-network), and to some extent, Windows and macOS as well. --- update-systemd-resolved | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/update-systemd-resolved b/update-systemd-resolved index a46de9b..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_domain=() dns_search=() - local -i dns_server_count=0 dns_domain_count=0 dns_search_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,14 +103,20 @@ up() { busctl_call SetLinkDNS 'ia(iay)' "${busctl_params[@]}" || return $? fi - if [[ "${#dns_domain[*]}" -gt 0 || "${#dns_search[*]}" -gt 0 ]]; then - busctl_params=("$if_index" "$((dns_domain_count+dns_search_count))") + 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 @@ -325,6 +331,15 @@ process_domain_search() { 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() { local script_type="$1" shift