From b2f4a755a0edba81eede6e87577a80d5def7d27a Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 31 Jul 2017 05:15:05 +0200 Subject: [PATCH] cli: add multi-DNS to wg-quick Signed-off-by: Jason A. Donenfeld --- cli/wg-quick.bash | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cli/wg-quick.bash b/cli/wg-quick.bash index 40417358..7720f349 100644 --- a/cli/wg-quick.bash +++ b/cli/wg-quick.bash @@ -15,7 +15,7 @@ INTERFACE="" NETID=0 ADDRESSES=( ) MTU="" -DNS="" +DNS=( ) CONFIG_FILE="" PROGRAM="${0##*/}" ARGS=( "$@" ) @@ -38,7 +38,7 @@ parse_options() { case "$key" in Address) ADDRESSES+=( ${value//,/ } ); continue ;; MTU) MTU="$value"; continue ;; - DNS) DNS="$value"; continue ;; + DNS) DNS+=( ${value//,/ } ); continue ;; esac fi WG_CONFIG+="$line"$'\n' @@ -86,7 +86,7 @@ up_if() { } set_dns() { - cndc resolver setnetdns "$NETID" "" "$1" + cndc resolver setnetdns "$NETID" "" "${DNS[@]}" } add_addr() { @@ -157,7 +157,7 @@ cmd_up() { add_addr "$i" done up_if - [[ -z $DNS ]] || set_dns "$DNS" + set_dns for i in $(while read -r _ i; do for i in $i; do [[ $i =~ ^[0-9a-z:.]+/[0-9]+$ ]] && echo "$i"; done; done < <(wg show "$INTERFACE" allowed-ips) | sort -nr -k 2 -t /); do [[ $(ip route get "$i" 2>/dev/null) == *dev\ $INTERFACE\ * ]] || add_route "$i" done