diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-05-08 23:15:50 -0600 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-05-09 00:29:53 -0600 |
commit | 7f236c79570642d466c5acab890b26c3a07f4f7a (patch) | |
tree | efae9b46fc54a72fb408e56a0fb11960f0ebfb97 /src/wg-quick/openbsd.bash | |
parent | systemd: add wg-quick.target (diff) | |
download | wireguard-tools-7f236c79570642d466c5acab890b26c3a07f4f7a.tar.xz wireguard-tools-7f236c79570642d466c5acab890b26c3a07f4f7a.zip |
wg-quick: support dns search domains
If DNS= has an IP in it, treat it as a DNS server. If DNS= has a non-IP
in it, treat it as a DNS search domain.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rwxr-xr-x | src/wg-quick/openbsd.bash | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/wg-quick/openbsd.bash b/src/wg-quick/openbsd.bash index 8d458d1..9584902 100755 --- a/src/wg-quick/openbsd.bash +++ b/src/wg-quick/openbsd.bash @@ -16,6 +16,7 @@ INTERFACE="" ADDRESSES=( ) MTU="" DNS=( ) +DNS_SEARCH=( ) TABLE="" PRE_UP=( ) POST_UP=( ) @@ -56,7 +57,9 @@ parse_options() { case "$key" in Address) ADDRESSES+=( ${value//,/ } ); continue ;; MTU) MTU="$value"; continue ;; - DNS) DNS+=( ${value//,/ } ); continue ;; + DNS) for v in ${value//,/ }; do + [[ $v =~ (^[0-9.]+$)|(^.*:.*$) ]] && DNS+=( $v ) || DNS_SEARCH+=( $v ) + done; continue ;; Table) TABLE="$value"; continue ;; PreUp) PRE_UP+=( "$value" ); continue ;; PreDown) PRE_DOWN+=( "$value" ); continue ;; @@ -270,7 +273,9 @@ set_dns() { [[ ${#DNS[@]} -gt 0 ]] || return 0 # TODO: this is a horrible way of doing it. Has OpenBSD no resolvconf? cmd cp /etc/resolv.conf "/etc/resolv.conf.wg-quick-backup.$INTERFACE" - cmd printf 'nameserver %s\n' "${DNS[@]}" > /etc/resolv.conf + { cmd printf 'nameserver %s\n' "${DNS[@]}" + [[ ${#DNS_SEARCH[@]} -eq 0 ]] || cmd printf 'search %s\n' "${DNS_SEARCH[*]}" + } > /etc/resolv.conf } unset_dns() { |