Splitting international and local traffic on a Linksys WRT54G

Gatecrasher

Executive Member
Joined
Jan 11, 2005
Messages
6,278
#22
Hey Gatecrasher... I was wondering about that LED issue to check on both routes being up...
What about a tray app that polls the router for this info somehow... wonder how easy that would be... does the dd-wrt do FTP by default? Maybe a smb share mount on the local machine and push a small file to that share using cron on the router... then check for the presence of that file for the up or down status in the tray app. there are probably cleaner ways of doing it...
I was thinking of something much simpler - using the LEDs on the router itself. There are are two LEDs behind the Cisco Systems logo, and most people do not use DMZ, so that LED is free too. I've written some code that will turn all these LEDs off after the default process has been killed. Then in order the amber LED indicates Local connection is up, the white LED indicates international connection is up, and finally the DMZ LED lights up when the routes are up.

Also working on making it as fast, efficient and as bullet proof as I can.

2.4 kb is small enough. I'm not sure, though, if binary data can be stored in nvram. I'm also not sure how to get it there.

But I don't think accessing the routes file via http is a big issue. It should work fine if all the steps preceding occur in the correct order. Its just about bullet proofing the script.
 

Gatecrasher

Executive Member
Joined
Jan 11, 2005
Messages
6,278
#23
Spent way too much time on this! But it seems to be rock solid now. It makes sure everything is in place before attempting to set up routes.

if you have two logins, amber LED is local up, white LED is intl up, dmz LED is for local routing active.

If you have one login, only the white LED will light up.

It no longer uses cron. It monitors the connections every 15 seconds, and restores the routing if required.

Still a beta, so if you find problems let me know.

Code:
echo "#!/bin/sh
user0=\`nvram get pppoe_username|awk '{ print \$2 }'\`
if [ \"\$user0\" != \"\" ]; then
  # 2nd login found - split required
  while sleep 1; do
    # wait for GUI pppd to run
    guippp=\`ps|grep -c /usr/sbin/pppd\`
    if [ \$guippp -gt 1 ]; then
      # gui pppd is running
      killall pppd
      killall redial
      while sleep 1; do
        # wait for GUI pppd to die
        guippp=\`ps|grep -c /usr/sbin/pppd\` 
        if [ \$guippp -lt 2 ]; then
          # gui pppd is dead - set all leds off  
          gpio enable 2
          gpio enable 3  
          gpio enable 7  
          user1=\`nvram get pppoe_username|awk '{ print \$1 }'\` 
          pass0=\`nvram get pppoe_passwd|awk '{ print \$2 }'\`
          pass1=\`nvram get pppoe_passwd|awk '{ print \$1 }'\`
          # create local pppd on ppp0
          /usr/sbin/pppd pty '/usr/sbin/pppoe -U -I vlan1' noipdefault noauth nodefaultroute noaccomp noccp nobsdcomp nodeflate nopcomp novj novjccomp nomppe nomppc usepeerdns user \$user0 password \$pass0 default-asyncmap mtu 1492 mru 1492 persist lcp-echo-interval 5 lcp-echo-failure 10 holdoff 30 unit 0
          while sleep 1; do
            # wait for local to connect
            locppp=\`/sbin/ifconfig|grep ppp0|awk '{print \$1}'\`
            if [ \"\$locppp\" == \"ppp0\" ]; then
              # local connected - amber led on
              gpio disable 3
              # create int pppd on ppp1
              /usr/sbin/pppd pty '/usr/sbin/pppoe -U -I vlan1' noipdefault noauth defaultroute noaccomp noccp nobsdcomp nodeflate nopcomp novj novjccomp nomppe nomppc usepeerdns user \$user1 password \$pass1 default-asyncmap mtu 1492 mru 1492 persist lcp-echo-interval 5 lcp-echo-failure 10 holdoff 30 unit 1
              while sleep 1; do
                # main monitoring/processing loop 
                intppp=\`/sbin/ifconfig|grep ppp1|awk '{print \$1}'\`
                if [ \"\$intppp\" == \"ppp1\" ]; then
                  # int connected - white led on
                  gpio disable 2
                  locppp=\`/sbin/ifconfig|grep ppp0|awk '{print \$1}'\`
                  if [ \"\$locppp\" == \"ppp0\" ]; then
                    # local connected
                    gpio disable 3
                    isrouted=\`/sbin/route -n|grep '196.26.0.0'|awk '{print \$8}'\`  
                    if [ \"\$isrouted\" == \"ppp0\" ]; then
                      # local is routed - dmz led on
                      gpio disable 7
                      # all is well so sleep longer
                      sleep 14
                    else
                      # local is not routed
                      gpio enable 7
                      # set default route 
                      /sbin/route add default dev ppp1 metric 0
                      /sbin/route del default dev ppp0 metric 0
                      sleep 2
                      if [ -f /tmp/localroutes4.txt ]; then
                        # route file exists 
                        isfound=\`cat /tmp/localroutes4.txt|grep '196.26.0.0/16'|awk '{print \$1}'\`
                        if [ \"\$isfound\" == \"route\" ]; then
                          # route file is valid - set routes
                          for IP in \`cat /tmp/localroutes4.txt | awk '{print \$4}'\`; do
                             /sbin/route add -net \$IP ppp0
                          done
                          # add SAIX mail and news to intl
                          /sbin/route add -host 196.25.240.94 ppp1
                          /sbin/route add -host 196.43.2.61 ppp1
                          sleep 2
                          # reset default routes 
                          /sbin/route add default dev ppp1 metric 0
                          /sbin/route del default dev ppp0 metric 0
                          sleep 2
                          # set maquerading 
                          /usr/sbin/iptables -t nat -A POSTROUTING -o ppp+ -j MASQUERADE
                          sleep 2
                          gpio disable 7
                        else
                          # route file invalid/empty - fetch   
                          /usr/bin/wget http://alm.za.net/ip/localroutes4.txt -O /tmp/localroutes4.txt
                        fi
                      else
                        # route file not found - fetch 
                        /usr/bin/wget http://alm.za.net/ip/localroutes4.txt -O /tmp/localroutes4.txt   
                      fi
                    fi
                  else
                    # local disconnected 
                    gpio enable 3
                    gpio enable 7
                  fi
                else
                  # int disconnected 
                  gpio enable 2 
                fi
              done    
            fi         
          done 
        fi 
      done
    fi
  done
else
  # split not required
  while sleep 1; do
    # process loop
    intppp=\`/sbin/ifconfig|grep ppp0|awk '{print \$1}'\`
    if [ \"\$intppp\" == \"ppp0\" ]; then
      # int connected - white led on
      gpio enable 3
      gpio disable 2
      # all is well so sleep longer
      sleep 14         
    else
      # int disconnected - leds off
      gpio enable 3
      gpio enable 2 
    fi
  done
fi" > /tmp/splitter
chmod +x /tmp/splitter
/tmp/splitter &
Requirements:
Linksys WRT54G/GS/GL v3.0+ (LED control may not work on earlier versions)
Latest stable DD-WRT firmware
1 international and 1 local ADSL account.

Instructions:
1. Paste above code into DD-WRT GUI - Administration - Commands. Click "Save Startup"
2. Go to SetUp - Basic SetUp and make sure your connection type is PPPoE
3. Set connection strategy to keep alive - redial 30
4. Enable RP PPPoE
5. To split international and local, enter both usernames separated by a space in the user name field ie: [int@myisp loc@myotherisp]
6. Do the same the with the passwords (it helps to unmask while editing). Make sure you enter international first, local second.
7. Click "Save Settings". The router will reboot.

To remove the script at anytime, clear the command box and click "Save Startup" and then "Reboot Router" form the Administration - Management screen.

Hope this is it. Need to get my life back.

EDIT: The script has been updated to fix zombie process problem.
29/7: The script routes SAIX smtp and news servers to the international account.
 
Last edited:

mancombseepgood

Executive Member
Joined
Jun 1, 2004
Messages
9,352
#24
Lol - shotto Gatecrasher ;)
I will test and let you know!

What I was thinking was adding a message to the status page (which can be viewed without loggin in to the router) that says ppp1 up/down and ppp2 up/down, then a tray app that polls that page and shows the status of ppp1 and 2... Useful for folk not in the same room as the router. Just not sure how to incorporate that into the web gui - have to rebuild the .bin... I'll take a look.

BTW - excellent work on the script!
 
Last edited:

Kooku

Active Member
Joined
Sep 6, 2005
Messages
94
#25
Will this work on the Micro Version of DD-WRT

Hi Gatecrasher

Thanks for the awesome project, you are helping loads of people out with this :D

I have a WRT54G V5 which I have reflashed with the Micro edition of DD-WRT. Do you know if the Micro version has all the modules necessary to get the traffic routing to work on it?

Thanks

JohnB
 

mancombseepgood

Executive Member
Joined
Jun 1, 2004
Messages
9,352
#26
Hi Gatecrasher

Thanks for the awesome project, you are helping loads of people out with this :D

I have a WRT54G V5 which I have reflashed with the Micro edition of DD-WRT. Do you know if the Micro version has all the modules necessary to get the traffic routing to work on it?

Thanks

JohnB
Just interested - what's the benefit of running the micro version?
 

Gatecrasher

Executive Member
Joined
Jan 11, 2005
Messages
6,278
#27
I have a WRT54G V5 which I have reflashed with the Micro edition of DD-WRT. Do you know if the Micro version has all the modules necessary to get the traffic routing to work on it?
Judging by This I would expect it to work on v5 and v6. All the requirements appear to be present. The only doubtful module might be rp-pppoe. But you should be able to see whether it is available on the GUI setup page.

BTW: I've run into a snag on my last script. It seems to produce ever increasing numbers of zombie processes on the router, which eventually requires a reboot after about 24 hours. It also effects upnp. This is probably due to the script running permanently rather than from the cron - perhaps it is preventing regular maintenance tasks to run.

I've written a fix, but haven't tested it yet. Hopefully I will have an update tonight.
 
Last edited:

mancombseepgood

Executive Member
Joined
Jun 1, 2004
Messages
9,352
#29
Judging by This I would expect it to work on v5 and v6. All the requirements appear to be present. The only doubtful module might be rp-pppoe. But you should be able to see whether it is available on the GUI setup page.

BTW: I've run into a snag on my last script. It seems to produce ever increasing numbers of zombie processes on the router, which eventually requires a reboot after about 24 hours. It also effects upnp. This is probably due to the script running permanently rather than from the cron - perhaps it is preventing regular maintenance tasks to run.

I've written a fix, but haven't tested it yet. Hopefully I will have an update tonight.
Hi, I noticed a hang at one point yesterday, but otherwise it works like a bomb. I will reset it from time to time - no harm done. Thanks!
 

Kooku

Active Member
Joined
Sep 6, 2005
Messages
94
#31
The larger versions don't run on the V5 & V6 routers, not enough memory.

It is also possible to schedule an automatic reboot on the routers in the DD-WRT firmware so I may do this to keep things running smoothly for the time being.

JohnB
 

Gatecrasher

Executive Member
Joined
Jan 11, 2005
Messages
6,278
#32
The fix was relatively painless. The entire script is written to /tmp and then run as a background process, passing control back to the router. No more zombies, and all the services are functioning normally.

I've updated the script here.
 

Gatecrasher

Executive Member
Joined
Jan 11, 2005
Messages
6,278
#33
Update:

Most local accounts are IS based which, with the local routing, would deny you access to SAIX's smtp server and SAIX's news server. So both of these have now been routed to the international account.

I'm thinking of adding additional pppoe connections to allow for:
A gaming account (unshaped) to specified game servers.
A local SAIX account, expressly for SAIX smtp and SAIX news, but acting as local if no IS account is specified.

Worth it? Any demand?
 

mancombseepgood

Executive Member
Joined
Jun 1, 2004
Messages
9,352
#34
Update:

Most local accounts are IS based which, with the local routing, would deny you access to SAIX's smtp server and SAIX's news server. So both of these have now been routed to the international account.

I'm thinking of adding additional pppoe connections to allow for:
A gaming account (unshaped) to specified game servers.
A local SAIX account, expressly for SAIX smtp and SAIX news, but acting as local if no IS account is specified.

Worth it? Any demand?
You're on to something big here Gatecrasher - we need to figure out how to release this as a bin for intl. use - I'm sure we're not the only people to find it useful...
I'd relly like to see if we can get this into the GUI front end - if nothing else, just some txt in the help.
THanks ALOT for the u/date!
 

pl1982

Active Member
Joined
Nov 13, 2006
Messages
46
#35
Thanks and 2 questions

Update:

Most local accounts are IS based which, with the local routing, would deny you access to SAIX's smtp server and SAIX's news server. So both of these have now been routed to the international account.

I'm thinking of adding additional pppoe connections to allow for:
A gaming account (unshaped) to specified game servers.
A local SAIX account, expressly for SAIX smtp and SAIX news, but acting as local if no IS account is specified.

Worth it? Any demand?
Hi Gatecrasher. Thanks for all your effort in the matter of setting up this script for routing traffic. I appreciate it. I have been using it for about 3 days now and it is working perfectly so far. I just have a question or 2 though. Firstly, from your post I could not with certainty ascertain whether you have now already implemented the international routing for use with the SAIX News server and SMTP server or whether you still plan on doing it seeing as the page with the script does not say that you updated it. If you could clarify that for me, I would greatly appreciate it.

Secondly, I have 2 accounts, one shaped SAIX international and one IS local. This might seem a noobish question, but let's say that you have now enabled the routing that allows those with local IS accounts to access the SAIX News server, then I am guessing that any downloads from the SAIX News server will go over international bandwidth and not over the IS local account for me right? IE: I am hoping that the international routing just gives you access to the SAIX News server (via your IP with SAIX), but then the downloads still go over the local account seeing as how the SAIX News server (196.43.2.61) is hosted locally. I am guessing I am wrong and it's to good to be true, but would just like confirmation from you. Thanks again.
 
Last edited:

mancombseepgood

Executive Member
Joined
Jun 1, 2004
Messages
9,352
#36
Hi Gatecrasher. Thanks for all your effort in the matter of setting up this script for routing traffic. I appreciate it. I have been using it for about 3 days now and it is working perfectly so far. I just have a question or 2 though. Firstly, from your post I could not with certainty ascertain whether you have now already implemented the international routing for use with the SAIX News server and SMTP server or whether you still plan on doing it seeing as the page with the script does not say that you updated it. If you could clarify that for me, I would greatly appreciate it.

Secondly, I have 2 accounts, one shaped SAIX international and one IS local. This might seem a noobish question, but let's say that you have now enabled the routing that allows those with local IS accounts to access the SAIX News server, then I am guessing that any downloads from the SAIX News server will go over international bandwidth and not over the IS local account for me right? IE: I am hoping that the international routing just gives you access to the SAIX News server (via your IP with SAIX), but then the downloads still go over the local account seeing as how the SAIX News server (196.43.2.61) is hosted locally. I am guessing I am wrong and it's to good to be true, but would just like confirmation from you. Thanks again.
I don't believe it's possible to d/l from SAIX news server with an IS account full stop.. the SAIX traffic will go over the international account AFAIK.
 

Gatecrasher

Executive Member
Joined
Jan 11, 2005
Messages
6,278
#37
Hi Gatecrasher. Thanks for all your effort in the matter of setting up this script for routing traffic. I appreciate it. I have been using it for about 3 days now and it is working perfectly so far. I just have a question or 2 though. Firstly, from your post I could not with certainty ascertain whether you have now already implemented the international routing for use with the SAIX News server and SMTP server or whether you still plan on doing it seeing as the page with the script does not say that you updated it. If you could clarify that for me, I would greatly appreciate it.

Secondly, I have 2 accounts, one shaped SAIX international and one IS local. This might seem a noobish question, but let's say that you have now enabled the routing that allows those with local IS accounts to access the SAIX News server, then I am guessing that any downloads from the SAIX News server will go over international bandwidth and not over the IS local account for me right? IE: I am hoping that the international routing just gives you access to the SAIX News server (via your IP with SAIX), but then the downloads still go over the local account seeing as how the SAIX News server (196.43.2.61) is hosted locally. I am guessing I am wrong and it's to good to be true, but would just like confirmation from you. Thanks again.
I have already implemented the update here..

Sadly, SAIX smtp and news is only accessible from your international account.

I've used the SAIX news server this weekend. It is light years faster than IS for non-cached content. It is so good that I'm tempted to buy a SAIX local account (@ R19/Gb) for the sole purpose. If I do, though, I would like it set up as a 3rd pppoe connection.

I've also seen many people ask whether they can split out their (expensive) unshaped gaming traffic from their regular internet usage. So I am thinking of incorporating something that can achieve this too.
 
Last edited:

Gatecrasher

Executive Member
Joined
Jan 11, 2005
Messages
6,278
#38
You're on to something big here Gatecrasher - we need to figure out how to release this as a bin for intl. use - I'm sure we're not the only people to find it useful...
I'd relly like to see if we can get this into the GUI front end - if nothing else, just some txt in the help.
THanks ALOT for the u/date!
When I was researching, I found a few international people looking for a similar solution, but generally overseas ADSL services don't require all this fiddling about. You pay a flat fee and you can use them for everything.

I think when the script has developed as far as it can, I may look into converting it into a plug-in binary. Not sure I have sufficient inclination yet.

One annoying (not fatal) problem I have found is with upnp. It always links itself with the last ppp dialed, which is a problem when local disconnects and reconnects. p2p clients then report a firewall and speeds drop noticeably. Unfortunately I haven't managed to find documentation on the upnp app in dd-wrt. One quick and nasty solution is take down both accounts when local disconnects, and start all over again. But getting upnp to behave better seems a far better solution.
 

pl1982

Active Member
Joined
Nov 13, 2006
Messages
46
#39
I have already implemented the update here..

Sadly, SAIX smtp and news is only accessible from your international account.

I've used the SAIX news server this weekend. It is light years faster than IS for non-cached content. It is so good that I'm tempted to buy a SAIX local account (@ R19/Gb) for the sole purpose. If I do, though, I would like it set up as a 3rd pppoe connection.

I've also seen many people ask whether they can split out their (expensive) unshaped gaming traffic from their regular internet usage. So I am thinking of incorporating something that can achieve this too.
Hi again. Thanks for the update. The SAIX News server (they recently started syncing with Giganews as well I believe) seems much better yes, from the reports I have been getting and personal experience. I just wonder though - seeing as how not that many people are downloading from the SAIX News server (IS local bandwidth is still quite a bit cheaper), the speeds are still good, but as more and more people get on there, SAIX might start gimping the server like IS did gradually and caching might start coming in.

Just another question if I may Gatecrasher. Let's say I get a local SAIX account now and replace my local IS account with it. Then I will have a shaped international and a local SAIX account for access to the SAIX News server. How will your script function then after this new update? Will it then correctly route the local SAIX account for usage with the SAIX News server or will it then still use the international one to connect to the SAIX News server and thus the expensive international bandwidth? Thanks again for the patience and time to answer my questions.
 

Gatecrasher

Executive Member
Joined
Jan 11, 2005
Messages
6,278
#40
Hi again. Thanks for the update. The SAIX News server (they recently started syncing with Giganews as well I believe) seems much better yes, from the reports I have been getting and personal experience. I just wonder though - seeing as how not that many people are downloading from the SAIX News server (IS local bandwidth is still quite a bit cheaper), the speeds are still good, but as more and more people get on there, SAIX might start gimping the server like IS did gradually and caching might start coming in.
R19/gb on SAIX vs R2/gb on IS is still a large disincentive to using the SAIX newserver. I don't think anyone is going to use it to the same extent as IS. But you can at least update newsgroups on the fly. With IS you can wait hours while it crawls...

Just another question if I may Gatecrasher. Let's say I get a local SAIX account now and replace my local IS account with it. Then I will have a shaped international and a local SAIX account for access to the SAIX News server. How will your script function then after this new update? Will it then correctly route the local SAIX account for usage with the SAIX News server or will it then still use the international one to connect to the SAIX News server and thus the expensive international bandwidth? Thanks again for the patience and time to answer my questions.
That's another good reason to incorporate SAIX local and gaming accounts into the script. If you used a SAIX local account with the existing script, you would have to remove these three lines

Code:
                          # add SAIX mail and news to intl
                          /sbin/route add -host 196.25.240.94 ppp1
                          /sbin/route add -host 196.43.2.61 ppp1
BTW: Which router model and version are you using?
 
Top