On Thu, 2012-04-26 at 02:35 +0100, David Woodhouse wrote:
>       Fix pptp handling of routes to server. 

That one probably does want sending as a patch, for review.

I was going to ignore this brokenness, but it ended up actually doing
stupid things on my setup because it was adding a broken route to the
server. So I fixed it anyway...

If there's a way to do this right with the legacy ifconfig tool rather
than ip, that would be interesting. But I don't think there is, and
having to use modern tools if you want pptp or l2tp support isn't *such*
an imposition...

From ad1b90974f249ff50c8de690022a33b8848b2308 Mon Sep 17 00:00:00 2001
From: David Woodhouse <david.woodho...@intel.com>
Date: Thu, 26 Apr 2012 02:13:12 +0100
Subject: [PATCH] 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.woodho...@intel.com>
---
 package/pptp/Makefile      |    2 +-
 package/pptp/files/pptp.sh |   24 +++++++++++-------------
 2 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/package/pptp/Makefile b/package/pptp/Makefile
index a6d213d..748abde 100644
--- a/package/pptp/Makefile
+++ b/package/pptp/Makefile
@@ -23,7 +23,7 @@ define Package/pptp
   TITLE:=PPTP client
   MAINTAINER:=Jo-Philipp Wich <x...@subsignal.org>
   URL:=http://pptpclient.sourceforge.net/
-  DEPENDS:=+ppp +kmod-gre +resolveip
+  DEPENDS:=+ppp +kmod-gre +resolveip +ip
 endef
 
 define Package/pptp/description
diff --git a/package/pptp/files/pptp.sh b/package/pptp/files/pptp.sh
index 19023e7..b898769 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
-- 
1.7.7.6


-- 
dwmw2

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to