packages icon indicating copy to clipboard operation
packages copied to clipboard

MWAN3 doesn't support correctly WAN based on OpenVPN tun

Open etomm opened this issue 10 years ago • 42 comments

MWAN3 is not able to recognize when a OpenVPN based “wan interface” is online or not. This is due to the fact that lib/functions/network.sh network_get_gateway uses ubus to collect the gateway information and in case of openvpn ubus return a perfectly emtpy result. I modified the network_get_gateway function to use "ip addr, grep and awk" and it began to work.

This is not the case with CC 15.05 that was having a really more simple hotplug script for mwan3.

All the tests are being done on LEDE trunk on a Linksys EA8500. Before, in OpenWRT CC 15.05 on a Archer C7 everything was working correctly.

etomm avatar Nov 07 '16 06:11 etomm

Hey etomm,

Any chance you could create patch based on your local copy of network.sh, showing your changes please? I'm seeing the same issue, and would like to get things working.

ghost avatar Dec 16 '16 20:12 ghost

I really have few time to look into the modifications, but I can try to collect something. Difficultly would be a patch, I did it live on a working LEDE system.

I still don't build my LEDE and relay on prebuild firmwares.

etomm avatar Dec 19 '16 12:12 etomm

I definitely don't want to cause you work, is there any chance you could paste in network.sh? I'm happy to diff out the, uh, differences :)

ghost avatar Dec 19 '16 12:12 ghost

Tried to change network.sh network_get_gateway to this:

network_get_gateway() { local $__tmp __tmp="$(/sbin/ip route | grep '^default' | awk "/$2/ {print $3; found=1} END{exit !found}") eval "$__tmp" &&
return 0 }

however, it's not working.

is network_get_gateway is supposed to get the gateway or check if gateway belongs to interface?

@etomm Any help with this will is appreciated!

nidstigator avatar Jan 21 '17 16:01 nidstigator

You are right, I completely forgot the issue... too much things to think about. So I opened the network.sh and I modified the network_get_gateway like this:

# determine IPv4 gateway of given logical interface
# 1: destination variable
# 2: interface
# 3: consider inactive gateway if "true" (optional)
network_get_gateway() {
	__network_ifstatus "$1" "$2" ".route[@.target='0.0.0.0' && [email protected]].nexthop" "" 1 && \
		return 0

	[ "$3" = 1 -o "$3" = "true" ] && \
		__network_ifstatus "$1" "$2" ".inactive.route[@.target='0.0.0.0' && [email protected]].nexthop" "" 1
	
	network_get_physdev ___dummydev "$2"

	[ -z "$___dummydev" ] && return 1
 	___gateway=`ip addr show $___dummydev | grep peer | awk -F'peer |/' '{printf $2}'`
	unset ___dummydev	

	[ -z "$___gateway" ] && return 1
 	eval "$1=$___gateway"
	unset ___gateway

	return 0
}

I added my rows to the ones that were just present... right now I don't remember which one they were. I think from when the _dummydev variable is appearing until the unset ___gateway.

Hope this can help both of you.

etomm avatar Jan 21 '17 22:01 etomm

@etomm Hey man, thanks for sharing your changes. Just replaced my network_get_gateway() function on my setup (WRT1900ACS LEDE r1967), still not working. Tun0 wan always shows up offline no matter what settings I change....

nidstigator avatar Jan 21 '17 23:01 nidstigator

I'm sorry it didn't work for you. That time I remember I debugged the script adding various log messages before catching the failing function was that one. Did you try to do the same?

etomm avatar Jan 22 '17 11:01 etomm

Thanks @etomm. I have tried. The problem is the same you were having - empty gateway info. However this fix and others I've tried didn't work.

nidstigator avatar Jan 25 '17 11:01 nidstigator

Maybe a bit of configuration files would help. Like Network, OpenVPN and MWAN3. But for example to me sound strange that you are doing it in tun0? is it the Device name or the Interface name?

etomm avatar Jan 25 '17 12:01 etomm

Hi etomm, would it be possible to post your modified /lib/functions/network.sh somewhere? Say using dropbox link? This way we can try whether your version works for us. The files should not contain any personal info anyway so it should be safe to be posted.

dziny avatar Jan 26 '17 12:01 dziny

Here it is http://pastebin.com/3py8Pesc but I still suppose a misconfiguration.

etomm avatar Jan 27 '17 23:01 etomm

@etomm I have uninstalled all relevant packages along with all configs. I wasted 2 days on this. Just a heads up everyone watching this thread, a new package called vpnbypass was merged into openwrt/packages yesterday. Should have same functionality (but easier to configure via its luci app) but confirmed working on latest LEDE and Openwrt.

nidstigator avatar Jan 28 '17 15:01 nidstigator

I believe the package is dead. Try OpenVPN-Policy-Based-Routing. Here: https://forum.lede-project.org/t/openvpn-policy-based-routing-web-ui-testers-needed/1422/156

nidstigator avatar Mar 30 '17 07:03 nidstigator

I believe the package is dead.

Not quite, but the previous maintainer went MIA.

@feckert has been doing mwan3 stuff lately.

hnyman avatar Mar 30 '17 07:03 hnyman

Aside from the issue with network_get_gateway, network_get_ipaddr does not return the correct information for OpenVPN interfaces, due to the ipv4-addreses (and ipv6-addresses, for that matter) block being empty in the output of ubus call network.interface dump. This results in an invalid iptables call on line 168 of mwan3.sh as $src_ip is blank.

jscinoz avatar Mar 30 '17 08:03 jscinoz

@nidstigator mwan3 is not tied just to OpenVPN. It is useful for whichever redirection policy and I use it together with ipsets.

Maybe we should move the but to the OpenVPN package?

etomm avatar Mar 30 '17 09:03 etomm

@nidstigator i am not sure if this is a problem of mwan3. What is the setup and configuration?

feckert avatar Mar 30 '17 11:03 feckert

@hnyman @jscinoz I apologise if I was misleading, I didn't mean to. I assumed the package is dead due to lack of updates and communication regarding this issue and other issues.

@feckert I gave up a long time ago on using mwan3 for my split tunnelling setup, and have been using OpenVPN-Policy-Based-Routing. mwan3 doesn't recognise that tun interfaces are up/down. I am happy with my current setup and don't need to use mwan3 anymore. But thanks for asking.

@etomm I agree, that was an oversight on my part. Mwan3 isn't the same as OPBR.

nidstigator avatar Mar 30 '17 11:03 nidstigator

@feckert almost sure it is a problem of OpenVPN that doesn't fill ubus informations correctly. I don't know if it should be solved OpenVPN side or MWAN3 side.

With my modified scripts I bypassed the problem, but I don't think it is the right solution. Maybe the maintainer of OpenVPN should look at this.

etomm avatar Mar 30 '17 20:03 etomm

Related: https://github.com/openwrt/openwrt/issues/220

jscinoz avatar Apr 01 '17 05:04 jscinoz