cli: add multi-DNS to wg-quick
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
df4fc98493
commit
b2f4a755a0
@ -15,7 +15,7 @@ INTERFACE=""
|
|||||||
NETID=0
|
NETID=0
|
||||||
ADDRESSES=( )
|
ADDRESSES=( )
|
||||||
MTU=""
|
MTU=""
|
||||||
DNS=""
|
DNS=( )
|
||||||
CONFIG_FILE=""
|
CONFIG_FILE=""
|
||||||
PROGRAM="${0##*/}"
|
PROGRAM="${0##*/}"
|
||||||
ARGS=( "$@" )
|
ARGS=( "$@" )
|
||||||
@ -38,7 +38,7 @@ parse_options() {
|
|||||||
case "$key" in
|
case "$key" in
|
||||||
Address) ADDRESSES+=( ${value//,/ } ); continue ;;
|
Address) ADDRESSES+=( ${value//,/ } ); continue ;;
|
||||||
MTU) MTU="$value"; continue ;;
|
MTU) MTU="$value"; continue ;;
|
||||||
DNS) DNS="$value"; continue ;;
|
DNS) DNS+=( ${value//,/ } ); continue ;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
WG_CONFIG+="$line"$'\n'
|
WG_CONFIG+="$line"$'\n'
|
||||||
@ -86,7 +86,7 @@ up_if() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set_dns() {
|
set_dns() {
|
||||||
cndc resolver setnetdns "$NETID" "" "$1"
|
cndc resolver setnetdns "$NETID" "" "${DNS[@]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
add_addr() {
|
add_addr() {
|
||||||
@ -157,7 +157,7 @@ cmd_up() {
|
|||||||
add_addr "$i"
|
add_addr "$i"
|
||||||
done
|
done
|
||||||
up_if
|
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
|
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"
|
[[ $(ip route get "$i" 2>/dev/null) == *dev\ $INTERFACE\ * ]] || add_route "$i"
|
||||||
done
|
done
|
||||||
|
Loading…
Reference in New Issue
Block a user