Comments inline...

On 5/3/12 3:39 AM, openwrt-comm...@openwrt.org wrote:
> Author: juhosg
> Date: 2012-05-03 11:39:01 +0200 (Thu, 03 May 2012)
> New Revision: 31565
> 
> Modified:
>    trunk/package/pptp/Makefile
>    trunk/package/pptp/files/pptp.sh
> Log:
> 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>
> 
> Modified: trunk/package/pptp/Makefile
> ===================================================================
> --- trunk/package/pptp/Makefile       2012-05-03 09:38:58 UTC (rev 31564)
> +++ trunk/package/pptp/Makefile       2012-05-03 09:39:01 UTC (rev 31565)
> @@ -23,7 +23,7 @@
>    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
> 
> Modified: trunk/package/pptp/files/pptp.sh
> ===================================================================
> --- trunk/package/pptp/files/pptp.sh  2012-05-03 09:38:58 UTC (rev 31564)
> +++ trunk/package/pptp/files/pptp.sh  2012-05-03 09:39:01 UTC (rev 31565)
> @@ -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}'

I'd (a) use "ip -4 -o" instead of piping through sed to remove newlines, and 
(b) use awk munge the fields into the output.


>  }
>  
>  scan_pptp() {
> @@ -9,7 +10,7 @@
>  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 @@
>       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
> 
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to