OpenWrt Forum Archive

Topic: mwan3; multi-wan policy routing (general topic)

The content of this topic has been archived between 22 May 2013 and 6 May 2018. Unfortunately there are posts – most likely complete pages – missing.

Sorry, posts 201 to 201 are missing from our archive.

arfett wrote:

What's the highest number that will be used for ip rules? I want the troubleshooting page to show them all. Is it 1020 or higher?

IP rules 1001 till 1015 are used for the interfaces. Rules 1016 till 1127 are used for policies.

Adze, I need to write a script and need info on WAN status. Is checking the existence of 1001 and 1002 for WAN1 and WAN2 reliable? What would you suggest?

biatche wrote:

Adze, I need to write a script and need info on WAN status. Is checking the existence of 1001 and 1002 for WAN1 and WAN2 reliable? What would you suggest?

This is currently the only method of determining a link's status. It of course requires that the interface be configured with track IPs otherwise the ip rule will be permanently there regardless of link state.

I'm working on a script for you...

(Last edited by arfett on 25 Apr 2013, 13:26)

Arfett, wow thank you.. I actually had created a topic for this:

https://forum.openwrt.org/viewtopic.php?pid=199593#p199593

I've done some bash scripting and I was given some direction in that topic so I should be ok. Can't be that hard right? if grep 1001 echo up ELSE down. hehe.

Do work on completing the overview page primarily first! My WDR3600 should arrive tomorrow, so I hope to use the latest ui changes right away.. but of course you need not rush for me personally. smile

My preliminary tests on 1043ND with mwan3 went well, so I'll setup the WDR3600 right away and immediately put it to production use.

(Last edited by biatche on 25 Apr 2013, 15:46)

biatche wrote:

Arfett, wow thank you.. I actually had created a topic for this:

https://forum.openwrt.org/viewtopic.php?pid=199593#p199593

I've done some bash scripting and I was given some direction in that topic so I should be ok. Can't be that hard right? if grep 1001 echo up ELSE down. hehe.

Do work on completing the overview page primarily first! My WDR3600 should arrive tomorrow, so I hope to use the latest ui changes right away.. but of course you need not rush for me personally. smile

My preliminary tests on 1043ND with mwan3 went well, so I'll setup the WDR3600 right away and immediately put it to production use.

This assumes your WAN interfaces are named wan1, wan2, ..., wan15

Replace INTERVAL, WANFIRST, WANLAST with your desired settings.
You can easily change it so only offline WANs are entered into the RESULT variable. That way you can have the final if/then perform an action if offline WANS are detected.

#!/bin/sh

# set your preferences here
INTERVAL="10"
WANFIRST="1"
WANLAST="15"

# leave alone
[ "$(echo "$WANFIRST" | wc -c)" == "2" ] && RULEFIRST="100$WANFIRST" || RULEFIRST="10$WANFIRST"
[ "$(echo "$WANLAST" | wc -c)" == "2" ] && RULELAST="100$WANLAST" || RULELAST="10$WANLAST"

while true; do

    RESULT=""
    WANF="$WANFIRST"
    IPRULE="$(ip rule show | awk -F: '{ print $1 }' | awk -v R1="$RULEFIRST" -v R2="$RULELAST" '$1>=R1 && $1<=R2')"

    # find any downed WANs
    if [ -n "$IPRULE" ]; then
        while [ "$WANF" -le "$WANLAST" ]; do
            # set rule number to search for
            if [ "$(echo "$WANF" | wc -c)" == "2" ]; then
                WANSRCH="100$WANF"
            else
                WANSRCH="10$WANF"
            fi

            # search for rule and mark any offline WANs
            if [ $(echo "$IPRULE" | grep -q "$WANSRCH"; echo $?) -eq 0 ]; then
                RESULT=""$RESULT" wan"$WANF"=online" #comment this line to only record offline WANs
                let WANF++
            else
                RESULT=""$RESULT" wan"$WANF"=offline"
                let WANF++
            fi
        done
    else
        # all WANs are down
        while [ "$WANF" -le "$WANLAST" ]; do
            RESULT=""$RESULT" wan$WANF=down"
            let WANF++
        done
    fi

    if [ "$RESULT" ]; then
        # remove leading spaces and insert newlines
        RESULT="$(echo "$RESULT" | sed -e 's/^[[:space:]]*//' -e 's/ /\n/g')"
echo "$RESULT"
        # put whatever code you want to report online/offline interfaces here
        # variable RESULT stores the test results of configured search

    fi

    sleep "$INTERVAL"

done

(Last edited by arfett on 25 Apr 2013, 16:42)

OK thank you so much! Will give it a test tomorrow.

(Last edited by biatche on 25 Apr 2013, 16:56)

biatche wrote:

Arfett, wow thank you..
OK thank you so much! Will give it a test tomorrow.

No prob. You think you could remove the code quote from your post to save some forum space and also I may throw a few modifications in the original post if others want to use it. Quotes don't update if the quoted material is changed.

(Last edited by arfett on 25 Apr 2013, 16:43)

Adze wrote:
arfett wrote:

What's the highest number that will be used for ip rules? I want the troubleshooting page to show them all. Is it 1020 or higher?

IP rules 1001 till 1015 are used for the interfaces. Rules 1016 till 1127 are used for policies.

Is there a maximum number of policies which can be created? If so I'll document on the GUI.

Thomymaster wrote:

    -By the way, is there a possibility that if mwan3 switches to a fail-over connection (and later fail-back) to send me an email?

    -Is there a possibility (i have a static ip for my main adsl line and an umts backup) to trigger a dyndns-client update once the connection is failed-over to umts?

    Both solutions would be very great.

    Cheers

    Thomy

A quick fix: make a script in /etc/hotplug.d/iface to call your email/ddns app on certain interface up/down events.


Hey guys

How do i accomplish this? This is very important for me, maybe there is also a way to integrate this into the UI (not into mwan3 i think this doesn't make sense)?

Thomymaster wrote:

Thomymaster wrote:

    -By the way, is there a possibility that if mwan3 switches to a fail-over connection (and later fail-back) to send me an email?

    -Is there a possibility (i have a static ip for my main adsl line and an umts backup) to trigger a dyndns-client update once the connection is failed-over to umts?

    Both solutions would be very great.

    Cheers

    Thomy

A quick fix: make a script in /etc/hotplug.d/iface to call your email/ddns app on certain interface up/down events.


Hey guys

How do i accomplish this? This is very important for me, maybe there is also a way to integrate this into the UI (not into mwan3 i think this doesn't make sense)?

I would imagine that in order to send out mail, sendmail must be installed. Since hotplug events trigger mwan3 scripts, then the mwan3 script could also be made to call other scripts. Here, we can see the possibility of arfett writing another tab in his luci-mwan3 to specify custom commands that links to the custom script file. so if a shell script could be written to show WAN status (which arfett has for me), we just need to call this each time mwan3 script is called... and all we must do is channel the output somewhere (email, file, ftp, whatever..). this could also help me in notification when a line goes up or down, although in my own manner

But then I'm no professional in this, it could work, or it could otherwise simply be fantasy gibberish.

What do you think arfett/adze?

(Last edited by biatche on 25 Apr 2013, 21:33)

Yes this approach would make very much sense. So a tab in the LuCi mwan3 config:


- where you can specify one or more interfaces (like wan or wwan in my case)

and specify a script to call for each:

-interface goes up
-interfaces goes down

or just one script which is invoked every time mwan3 script is started (in this case when something changes).

And this script will mail the output (i can take care of this myself).

Adze,
Perhaps we could provide some links to some possibly useful scripts like the one I wrote last night in the OP? Not really offering support of course. There's a big wide forum for help with shell scripting.

biatche wrote:

What do you think arfett/adze?

Sounds like a lot of work and user-error is abound. I'd say this falls outside the scope of what I imagine Adze wants to get into and what I want to. Not that it would be difficult to add that.

I will be happy to give you a brief overview of making your own hotplug script. Also have you considered configuring a syslog server somewhere? OpenWRT has the option to send syslog data to a remote server on the System->System tab in the System Properties->Logging subtab.

I'll make an example hotplug script for you to use as a template.

Yes then please give me a template and ill try what i can do and post the results of course smile

This is likely to be one of the last scripts I provide unless an interesting/challenging issue comes up. You guys should start learning from the plethora of examples how to make your own page/script modifications.

/etc/hotplug.d/iface/ has a lot of scripts to look at and it should be pretty clear what they are doing if you have any knowledge of shell scripting basics.

/usr/lib/lua/luci/controller/ and /usr/lib/lua/luci/model/cbi/ is where the LuCI files are stored. The controller file is like a general overview of what is going to go on the page and the cbi files are the actual values that go on. It shouldn't take you more than about 5 seconds to see how to add your own tab to the MWAN3 or any other page. Also just browse around the files for existing pages that already do what you want and you can sort of copy/paste and edit to do precisely what you want. This is how I got into making LuCI pages and eventually you might learn some LUA scripting which is pretty handy.

Thomymaster wrote:

Yes then please give me a template and ill try what i can do and post the results of course smile

#!/bin/sh

# place in /etc/hotplug.d/iface and name 19-mymwancustom
# make executable with 'chmod +x 19-mymwancustom'
#
# available variables:
# $ACTION is the hotplug event
# $INTERFACE is the interface name (wan1, wan2, etc.)
# $DEVICE the device name attached to the interface (eth0.1, eth1, etc.)

case "$ACTION" in
    ifup)
        # run this code or additional function added to this script
        # if any interface comes online

        # if you want to limit it to certain interfaces you can do
        #if [ "$INTERFACE" == "wan1" ]; then
            # run this code
        #fi
    ;;

    ifdown)
        # run this code or additional function added to this script
        # if any interface goes offline
    ;;
esac

(Last edited by arfett on 25 Apr 2013, 23:35)

arfett wrote:

This is likely to be one of the last scripts I provide unless an interesting/challenging issue comes up. You guys should start learning from the plethora of examples how to make your own page/script modifications.

Yes but thank you for helping us here, I guess it's my inexperience and not knowing what/where to modify that puts me off. Then again that's every reason to begin learning.

Hi

Thank You for great app. Working great on 2x 3g-wan's, well almost... My main goal is to direct all traffic thru 1st wan, and only dst_port 8080 thru 2nd wan, its working but when 1st wan disconnects, load is redirect to 2nd wan! Is it normal?

Please help

(Last edited by frunzie on 26 Apr 2013, 20:17)

frunzie wrote:

My main goal is to direct all traffic thru 1st wan, and only dst_port 8080 thru 2nd wan, its working but when 1st wan disconnects, load is redirect to 2nd wan! Is it normal?


Hi,


Yes this is normal. As 1st wan is down and traffic can't be routed over 1st wan, the main routing table is used. As it still has an entry of second wan, it will route through 2nd wan. A sollution to this would be to add some firewall rules, or use the loopback route trick (explained in first post).

Adze, I was wondering.. with regards to above, what would happen if the mwan3 script is re-written in a way that:

When hotplug is triggered (due to line up/down) .. instead of recreating ip rule show. (if we make 1001, 1002 permanent) and instead change mwan3_rules in iptables only: say (port 1234 route to wan2_pri_wan1_sec) to (wan1_only if wan2 dies)

Would it work?

Also, i'd like to know - each time mwan3 script is called, is the entire iptables refreshed/restarted?

(Last edited by biatche on 26 Apr 2013, 11:30)

Hey there,

I'm trying to configure my WR941ND to use 2 WANs and following this script walkthrough says that before installing this I should have both WANs working, i'm new to openwrt/linux-like methods and sadly I have found a issue (probably easily resolved) that can't tackle myself, have been looking for this specific router help/guides about multiwan setups but information it's quite lackluster.

My brand new installed openwrt network config looks like this:

config interface 'loopback'
        option ifname 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'fdf4:e59f:3b71::/48'

config interface 'eth'
        option ifname 'eth0'
        option proto 'none'

config interface 'lan'
        option ifname 'lan1 lan2 lan3 lan4'
        option type 'bridge'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'
        option ip6assign '60'

config interface 'wan'
        option ifname 'wan'
        option proto 'dhcp'

config interface 'wan6'
        option ifname '@wan'
        option proto 'dhcpv6'

As i have seen in most tutorials/guides I should separate my ports into several vlans in order to assign specific behaviours to this vlans, as WAN1, WAN2, etc.

What I don't understand on how to do with this router is that most guides calls 'option ports 1 2 3 4' on vlans or eth0, and in this specific router this ports are binded directly to lan interface using ifname lan1 lan2 lan3 lan4. Don't know if i change this to 'option ports' will brick my router, and since i lack any modding skill to attach a serial device, probably will not be able to recover it.

If anyone can guide me a bit through this to then proceed and install this script would be awesome, please excuse me for my poor spelling, my english is quite bad.

P.S: I created a topic about this https://forum.openwrt.org/viewtopic.php?id=43797, and then after looking for an answer found this topic.

where is your gateway metric? your config file is a bit strange to me though. but maybe you should read up on creating vlans.

(Last edited by biatche on 26 Apr 2013, 19:21)

root@OpenWrt:/# ifconfig
br-lan    Link encap:Ethernet  HWaddr 90:F6:52:B0:0B:30
          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fdf4:e59f:3b71::1/60 Scope:Global
          inet6 addr: fe80::92f6:52ff:feb0:b30/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:881645 errors:0 dropped:6899 overruns:0 frame:0
          TX packets:858336 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:211693242 (201.8 MiB)  TX bytes:599432279 (571.6 MiB)

eth0      Link encap:Ethernet  HWaddr 90:F6:52:B0:0B:30
          inet6 addr: fe80::92f6:52ff:feb0:b30/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1615264 errors:0 dropped:0 overruns:34 frame:0
          TX packets:1519874 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:821585025 (783.5 MiB)  TX bytes:656056834 (625.6 MiB)
          Interrupt:4

lan1      Link encap:Ethernet  HWaddr 90:F6:52:B0:0B:30
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lan2      Link encap:Ethernet  HWaddr 90:F6:52:B0:0B:30
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lan3      Link encap:Ethernet  HWaddr 90:F6:52:B0:0B:30
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:767744 errors:0 dropped:41 overruns:0 frame:0
          TX packets:717328 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:203269053 (193.8 MiB)  TX bytes:434848148 (414.7 MiB)

lan4      Link encap:Ethernet  HWaddr 90:F6:52:B0:0B:30
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:757 errors:0 dropped:0 overruns:0 frame:0
          TX packets:757 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:118227 (115.4 KiB)  TX bytes:118227 (115.4 KiB)

wan       Link encap:Ethernet  HWaddr 90:F6:52:B0:0B:30
          inet addr:1xx.xxx.xxx.xxx  Bcast:1xx.xxx.xxx.xxx  Mask:255.255.224.0
          inet6 addr: fe80::92f6:52ff:feb0:b30/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:847519 errors:0 dropped:0 overruns:0 frame:0
          TX packets:802538 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:589241160 (561.9 MiB)  TX bytes:210721323 (200.9 MiB)

wlan0     Link encap:Ethernet  HWaddr 90:F6:52:B0:0B:30
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:156808 errors:0 dropped:0 overruns:0 frame:0
          TX packets:225949 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:19622032 (18.7 MiB)  TX bytes:181538436 (173.1 MiB)

This is my ifconfig output, not sure if you refer to this text.

I have readed that creating vlans on this router is a bit different, they should be defined in a startup file, i'll look for it when arrive home, but still have the same issue regarding my network config structure.

frunzie wrote:

my configs:

That is a mess to read. Can you please edit your post and change it to the output of 'cat /etc/config/mwan3'

And no it is not normal the traffic should be blackholed if a rule matching the traffic can not be used. Only traffic which no rule matches falls through to the main routing table.

(Last edited by arfett on 26 Apr 2013, 20:13)

mvilera wrote:

I have readed that creating vlans on this router is a bit different, they should be defined in a startup file, i'll look for it when arrive home, but still have the same issue regarding my network config structure.

If you want to let me take a peek at this over teamviewer I'll see what I can do.

First step is to get your WAN's running without mwan3. If you read the first post, you'll need to be able to "ping -I WAN_interface whatever_ip". Without this, there's no use proceeding to mwan3. And if you can't get your WAN's up because of lack of VLAN, then you need to find a way to create those VLANs

Im no expert here but that's what I would do.