From 884f7c50cea1b7830d3726f18af5f9b774705718 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 17 May 2018 04:07:11 +0200 Subject: [PATCH] wg-quick: darwin: avoid routing loop if no default Signed-off-by: Jason A. Donenfeld --- src/wg-quick/darwin.bash | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/wg-quick/darwin.bash b/src/wg-quick/darwin.bash index dfdd54e..0edf2fe 100755 --- a/src/wg-quick/darwin.bash +++ b/src/wg-quick/darwin.bash @@ -211,9 +211,9 @@ set_endpoint_direct_route() { for endpoint in "${old_endpoints[@]}"; do [[ $remove_all_old -eq 0 && " ${ENDPOINTS[*]} " == *" $endpoint "* ]] && continue - if [[ $endpoint == *:* ]]; then + if [[ $endpoint == *:* && $AUTO_ROUTE6 -eq 1 ]]; then cmd route -q delete -inet6 "$endpoint" >/dev/null 2>&1 || true - else + elif [[ $AUTO_ROUTE4 -eq 1 ]]; then cmd route -q delete -inet "$endpoint" >/dev/null 2>&1 || true fi done @@ -223,11 +223,21 @@ set_endpoint_direct_route() { added+=( "$endpoint" ) continue fi - if [[ $endpoint == *:* && -n $GATEWAY6 ]]; then - cmd route -q add -inet6 "$endpoint" -gateway "$GATEWAY6" >/dev/null || true + if [[ $endpoint == *:* && $AUTO_ROUTE6 -eq 1 ]]; then + if [[ -n $GATEWAY6 ]]; then + cmd route -q add -inet6 "$endpoint" -gateway "$GATEWAY6" >/dev/null || true + else + # Prevent routing loop + cmd route -q add -inet6 "$endpoint" ::1 -blackhole >/dev/null || true + fi added+=( "$endpoint" ) - elif [[ -n $GATEWAY4 ]]; then - cmd route -q add -inet "$endpoint" -gateway "$GATEWAY4" >/dev/null || true + elif [[ $AUTO_ROUTE4 -eq 1 ]]; then + if [[ -n $GATEWAY4 ]]; then + cmd route -q add -inet "$endpoint" -gateway "$GATEWAY4" >/dev/null || true + else + # Prevent routing loop + cmd route -q add -inet "$endpoint" 127.0.0.1 -blackhole >/dev/null || true + fi added+=( "$endpoint" ) fi done