From f03633a1a6b3134eabd22546c70cee16f1db36fb Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 20 Dec 2016 04:08:41 +0100 Subject: wg-config: cleanup ip parsing This also sorts routes by cidr. --- contrib/examples/wg-config/wg-config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'contrib') diff --git a/contrib/examples/wg-config/wg-config b/contrib/examples/wg-config/wg-config index eaa45f2..f2272b3 100755 --- a/contrib/examples/wg-config/wg-config +++ b/contrib/examples/wg-config/wg-config @@ -45,7 +45,7 @@ add_default() { echo "tungate: does not yet support IPv6, skipping ::/0" >&2 return 0 elif [[ $1 == 0.0.0.0/0 ]]; then - local endpoint="$(wg show "$INTERFACE" endpoints | grep "^$(wg show "$INTERFACE" allowed-ips | grep 0.0.0.0/0 | head -n 1 | cut -f 1)" | cut -f 2 | cut -d : -f 1)" + local endpoint="$(join <(wg show "$INTERFACE" allowed-ips) <(wg show "$INTERFACE" endpoints) | sed -n 's/.* 0\.0\.0\.0\/0.* \([0-9.:\/a-z]\+\):[0-9]\+$/\1/p')" add_route 0/1 add_route 128/1 killall tungate 2>/dev/null || true @@ -129,7 +129,7 @@ cmd_add() { done up_if if [[ $AUTO_ROUTE -eq 1 ]]; then - for i in $(wg show "$INTERFACE" allowed-ips | cut -f 2 | tr -d ,); do + for i in $(wg show "$INTERFACE" allowed-ips | grep -Po '(?<=[\t ])[0-9.:/a-z]+(?<=,)?' | sort -nr -k 2 -t /); do if ! add_default "$i" && [[ $(ip route get "$i") != *dev\ $INTERFACE\ * ]]; then add_route "$i" fi -- cgit v1.2.3-59-g8ed1b