diff options
author | Gabor Juhos <juhosg@openwrt.org> | 2012-05-03 09:39:01 +0000 |
---|---|---|
committer | Gabor Juhos <juhosg@openwrt.org> | 2012-05-03 09:39:01 +0000 |
commit | 59ba22536d502e4f2afdc22ba3e675da1360210e (patch) | |
tree | f5a4566d5e91a9d2afa2bd79f3ad414399124fb7 /package/pptp/files | |
parent | 5901da9cc813449f90911d131c6c779928a65324 (diff) | |
download | upstream-59ba22536d502e4f2afdc22ba3e675da1360210e.tar.gz upstream-59ba22536d502e4f2afdc22ba3e675da1360210e.tar.bz2 upstream-59ba22536d502e4f2afdc22ba3e675da1360210e.zip |
Fix pptp handling of routes to server.
The existing code is fairly broken. It assumes you're using Legacy IP, and
it assumes that the server is reachable via your default route. Via the
first default route in the 'route -n' output, in fact, regardless of metric.
Fix all those problems by using 'ip route get' to really find the *current*
route to the server, and install a host-specific route to match.
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@31565 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'package/pptp/files')
-rw-r--r-- | package/pptp/files/pptp.sh | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/package/pptp/files/pptp.sh b/package/pptp/files/pptp.sh index 19023e7ef4..b898769b66 100644 --- a/package/pptp/files/pptp.sh +++ b/package/pptp/files/pptp.sh @@ -1,5 +1,6 @@ -find_gw() { - route -n | awk '$1 == "0.0.0.0" { print $2; exit }' +find_route() { + ip route get $1 | sed -e 's/ /\n/g' | \ + sed -ne '1p;/via/{N;p};/dev/{N;p};/src/{N;p};/mtu/{N;p}' } scan_pptp() { @@ -9,7 +10,7 @@ scan_pptp() { stop_interface_pptp() { stop_interface_ppp "$1" for ip in $(uci_get_state network "$1" serv_addrs); do - route del -host "$ip" 2>/dev/null + ip route del "$ip" 2>/dev/null done } @@ -36,16 +37,13 @@ setup_interface_pptp() { done sleep 1 - local gw="$(find_gw)" - [ -n "$gw" ] && { - local serv_addrs="" - for ip in $(resolveip -4 -t 3 "$server"); do - append serv_addrs "$ip" - route delete -host "$ip" 2>/dev/null - route add -host "$ip" gw "$gw" - done - uci_toggle_state network "$config" serv_addrs "$serv_addrs" - } + local serv_addrs="" + for ip in $(resolveip -t 3 "${server}"); do + append serv_addrs "$ip" + ip route replace $(find_route $ip) + done + uci_toggle_state network "$config" serv_addrs "$serv_addrs" +} # fix up the netmask config_get netmask "$config" netmask |