Try to guess pref in glorytun-run

Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
Adrien Gallouët
2017-11-27 10:33:16 +00:00
parent e26ecf37a3
commit 495138ffe4
2 changed files with 20 additions and 8 deletions

View File

@@ -1,5 +1,7 @@
#!/bin/sh
set -e
if [ ! -f "$1" ]; then
echo "usage: $(basename "$0") FILE"
exit 1
@@ -11,10 +13,16 @@ DEV="gt${HOST:+c}-$(basename "$1")"
# Setting BIND is like going to 'expert mode'
# This helper is pretty stupid and still needs some work
if [ -n "$HOST" ] && [ -z "$BIND" ]; then
BIND=$(ip route get "$HOST" | awk '/src/{getline;print $0}' RS=' ')
ip rule add from "$BIND" table main pref 32000
ip rule add from all table 200 pref 32001
if [ -n "$HOST" ]; then
if [ -z "$PREF" ]; then
PREF=$(ip rule | awk '/from all lookup main/{print $1; exit}' | tr -d :)
PREF=$((PREF-1))
fi
if [ -z "$BIND" ]; then
BIND=$(ip route get "$HOST" | awk '/src/{getline;print $0}' RS=' ')
ip rule add from "$BIND" table main pref "$((PREF-1))"
fi
ip rule add from all table 200 pref "$PREF"
fi
exec glorytun \