aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/contrib
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2016-12-20 04:08:41 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2016-12-23 21:09:23 +0100
commit50e1f58fde7d54a4ff640a8361632cd5b646e57d (patch)
treea53116d2616fd51f63ffbfa5bd9549116b076dce /contrib
parentwg: fix latest-handshake typo in documentation (diff)
downloadwireguard-tools-50e1f58fde7d54a4ff640a8361632cd5b646e57d.tar.xz
wireguard-tools-50e1f58fde7d54a4ff640a8361632cd5b646e57d.zip
wg-config: cleanup ip parsing
This also sorts routes by cidr. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/wg-config/wg-config4
1 files changed, 2 insertions, 2 deletions
diff --git a/contrib/wg-config/wg-config b/contrib/wg-config/wg-config
index eaa45f2..f2272b3 100755
--- a/contrib/wg-config/wg-config
+++ b/contrib/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