Skip to content

Commit

Permalink
Merge pull request #2 from jonathanio/feature/ipv6-support
Browse files Browse the repository at this point in the history
Add IPv6 address support for DNS Servers
  • Loading branch information
jonathanio authored Jun 23, 2016
2 parents bd8b181 + 75f22dc commit 21097b0
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 8 deletions.
12 changes: 9 additions & 3 deletions run-tests
Original file line number Diff line number Diff line change
Expand Up @@ -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}: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP>" \
Expand Down Expand Up @@ -127,15 +127,21 @@ 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" || \
_fail "busctl was called, not expected"
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 ]]
8 changes: 8 additions & 0 deletions tests/10_single_ipv6_dns_full.sh
Original file line number Diff line number Diff line change
@@ -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=""
8 changes: 8 additions & 0 deletions tests/11_single_ipv6_dns_simple.sh
Original file line number Diff line number Diff line change
@@ -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=""
8 changes: 8 additions & 0 deletions tests/12_single_ipv6_dns_compact_1.sh
Original file line number Diff line number Diff line change
@@ -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=""
8 changes: 8 additions & 0 deletions tests/13_single_ipv6_dns_compact_2.sh
Original file line number Diff line number Diff line change
@@ -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=""
8 changes: 8 additions & 0 deletions tests/14_single_ipv6_dns_compact_3.sh
Original file line number Diff line number Diff line change
@@ -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=""
8 changes: 8 additions & 0 deletions tests/15_single_ipv6_dns_localhost.sh
Original file line number Diff line number Diff line change
@@ -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=""
9 changes: 9 additions & 0 deletions tests/16_dual_ipv6_single_ipv4.sh
Original file line number Diff line number Diff line change
@@ -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=""
10 changes: 10 additions & 0 deletions tests/17_single_ipv6_single_ipv4.sh
Original file line number Diff line number Diff line change
@@ -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=""
13 changes: 13 additions & 0 deletions tests/18_dns_ipv4_ipv6_domain_and_search.sh
Original file line number Diff line number Diff line change
@@ -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"
29 changes: 24 additions & 5 deletions update-systemd-resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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//./ }"
Expand All @@ -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
Expand Down

0 comments on commit 21097b0

Please sign in to comment.