1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

No connection when cable restored--until DHCP renewed

Discussion in 'Tomato Firmware' started by dissident, Jul 24, 2007.

  1. dissident

    dissident LI Guru Member

    This may not be the problem you think it is from the subject line.

    I'm using Tomato 1.07 on a Linksys WRTSL54GS. Whenever my cable service goes out for some reason, and is restored, I lose all WAN connectivity. My LAN connectivity remains intact.

    To regain WAN connectivity, I have to manually click the Renew button, in Tomato, under Status > Overview.

    I don't understand why this would be. When my WAN connectivity is dead, Tomato is still displaying my (correct) WAN IP address under Status > Overview, and it is also displaying the status as Connected. When I click Renew, the WAN comes back to life, but nothing changes in Tomato.

    I used DD-WRT for a long time, and whenever I lost and regained cable service, the WAN just worked. I never had to do a manual renew.

    My cable service has been awful lately (coming and going all the time), and it's a huge hassle to have the WAN dead until I get home, and manually "enable" it.

    Advice, please?
     
  2. Overflow-ar

    Overflow-ar LI Guru Member

    This seems the same behaviour that I'm facing... although I don't know with other third party firmwares or even linksys 'cause i've flashed immediately after purchasing :biggrin:

    I suggest you look up on this thread
    Restart internet connection via batch?

    Maybe someone could code a script that pings modem interface to see if there's response, and if not automatically release and renew it.
     
  3. ifican

    ifican Network Guru Member

    Some providers wont allow an address they have not given out via dhcp, I have run into this issue myself and it has not been firmware or device dependent. It appears that if when the router sense the line drop and then come back alive, if it request dhcp the line will work, if it does not at it just sits there with the given ip then the service will not work until you request a new lease. Sometimes if you try and ping your device from the outside it will activate the connection but not always depending on how your service provider is setup. So fixes are do what you are doing now or create a script to monitor the connection.
     
  4. dissident

    dissident LI Guru Member

    As I mentioned, this problem does not occur with DD-WRT--only Tomato.
     
  5. mstombs

    mstombs Network Guru Member

    Does anything change in the IP, netmask or Gateway address when WAN goes down and comes back? I'd be interested to know what the "renew" does - suggest you check for changes to the routing table accessible from Tomato GUI "Advanced Routing" or command line "route command"

    A feature of my old cable connection was that the lease time is 7 days and the router (definitely Hyperwrt + I guess also Tomato?) doesn't request a new IP even if the WAN cable pulled and replaced, as windows does. If dd-wrt doesn't have this 'feature' it is actually good news - it can be fixed in Tomato.
     
  6. dissident

    dissident LI Guru Member

    No, nothing at all under Status > Overview changes the entire time--not when the WAN goes down, nor after I renew. The IP, mask, and gateway address remain the same.

    This has been such a problem for me (read: people who use my LAN calling me when I'm away and whining "the internet doesn't work!") that I need to switch back to DD-WRT.
     
  7. mstombs

    mstombs Network Guru Member

    A clearly labelled on/off switch will also do the renew!

    I suspect it is an ISP specific related issue, the modem needs to see the dhcp request before it reopens communications. The stock answer on the UK cable co helpdesk is to power everything down, power up the modem, wait till lights stabilize then power up router - which will fix this type of problem.

    When it is not working is the WAN lease time still valid - or has time remaining gone to zero?
     
  8. dissident

    dissident LI Guru Member

    When it is not working, the lease time still appears to be valid--it does not go to zero.

    I just installed DD-WRT v24 beta, and it was a waste of time. DD-WRT does the same thing, meaning I still have to manually do a renew whenever the cable service dies and is restored.

    It probably is an ISP-specific issue. I am surprised regarding DD-WRT, because I am using the same ISP (Road Runner) I have been using since 1999, but I have moved recently. I never had to do manual renews before. I guess something is different about their service in this area.

    But of course, I'm still left with the original problem.
     
  9. mstombs

    mstombs Network Guru Member

    There's a potential solution via a monitoring script in the similar thread - dd-wrt wiki also has one which suggests this is a common problem.

    You will probably want to ping the WAN gateway if it is not 0.0.0.0, with a custom version of the script, or easier - just replace "surfboardip" with a fixed local internet address that you know you should be able to ping - maybe your ISP DNS server?

    http://www.linksysinfo.org/forums/showthread.php?t=53361

    Windows (XP at least) seems to notice WAN problems 'limited connectivity' or 'Connected', it seems Linux doesn't by default - but I am sure it could..
     
  10. Sunspark

    Sunspark LI Guru Member

    This happened to me the other day.

    The router had an uptime of 33 days, the DSL lease had been connected for 20 days. But DNS lookups would fail but according to status overview the DSL was still connected according to the router.

    I clicked on 'disconnect' then 'connect' on the DSL in the status overview and it instantly worked.

    I noticed I had a window that Azureus threw up saying:
    "UPnP: Lost connection to service 'WANIPConnection' on UPnP device '192.168.1.1'"

    I am not sure if this is a clue or not. But I am sharing it just in case.

    I also want to add, that I looked at the log and it said that a windows computer connected to it was did a 'DHCPREQUEST' then it was 'DHCPACK' and 'DCHPINFORM' over and over, those two until I came along and restarted the DSL.
     
  11. ifican

    ifican Network Guru Member

    I still go back to my initial response. Certain routers will not drop there interface settings when the link drops even though they are setup dhcp. This will cause this exact issue as the router believe it still has a lease and the timer continues to tick down but the isp router knows the connection has dropped and has not seen a new dhcp request. What complicates this even further is that the link may drop between the cable modem and the isp but the router still sees the link active because the cable modem never powered down.
     
  12. mstombs

    mstombs Network Guru Member

    Now this windows PC was doing what we want the Linux router to do - it sees that it has 'limited connectivity' so tries to kickstart the connection by sending out dhcp requests even though it has a valid lease. It won't cure the problem here because the problem is not on the LAN side of the router, but would have done if connected directly to the modem!. I wonder if there is a write up anywhere on how Windows does this, at the kernel level there must be lots of 'icmp unreachable' or equivalent being received or generated for example, because most internet packets will not be getting a reply. Windows is not just checking its next hop device - it is looking through the router and modem to see the problem between it and the internet.
     
  13. dissident

    dissident LI Guru Member

    Thank you, mstombs, Overflow-ar, ifican, and Sunspark! This script (modifed per mstombs' advice above) seems to work well for me:

    Code:
    This code has been superseded by a later post.
    Where xxx.xxx.xxx.xxx is the IP address of my ISP's DNS server (the DNS server IP address was chosen for latency and reliability).

    Now, when my cable dies and is restored, there is a brief delay before a renew is done automatically.

    I commented out the logging that is performed when the ping succeeds, since I often keep an eye on the syslog, and don't want to see needless "success" messages every 60 seconds.

    My only problem--and I know, it's minor--is that I can no longer run my custom Tomato theme. I previously had a custom CSS file pasted into the Init script text box. Is there any way to use the above script and a CSS file at the same time?
     
  14. mstombs

    mstombs Network Guru Member

    Hey this is Linux - you can do anything!

    There is a problem with using the init function to do this because it never terminates, and therefore init and whatever calls it may also hang around. You could use init to write these commands to a file, make it executable and run it as standalone. BUT I don't know what you need to do for custom css - may just be a matter of moving this script down to the bottom of init after whatever you need for custom css.

    To run as standalone program wiithout waiting for it to finish use the following template, as discussed recently in this thread

    http://www.linksysinfo.org/forums/showthread.php?t=53904

    Code:
    # assign filename in writable area of ram disk
    myscript='/tmp/myscript.sh'
    # create the file using a 'here document'
    cat > $myscript <<EOF
    #!/bin/sh
    #====================
    Insert your script code here
    #====================
    EOF
    # make it executable
    chmod +x $myscript
    # run it as a detached process
    $myscript &
     
  15. dissident

    dissident LI Guru Member

    Thank you! I didn't create a standalone script--doing so probably would take me a long time to figure out--but your post got me thinking.

    All I had to do was to put the ping code after the stuff that was already there for the CSS theme. The code for the CSS theme just creates a CSS file that Tomato then looks for:

    Code:
    mkdir /var/wwwext
    cat <<END >/var/wwwext/custom.css
    [...CSS code...]
    END
    I am totally new to all this stuff (Linux scripting, etc.), and hadn't even really understood how any of this worked.

    I'm guessing that the CSS stuff needs to go on top, otherwise the "do...while" loop in the ping/renew code will prevent it from running at all. Either way, putting the CSS stuff above the ping/renew stuff works; I now have my theme, and the ping/renew works. Brilliant! (Well, to me... :))

    Thanks again.
     
  16. Overflow-ar

    Overflow-ar LI Guru Member

    I would just recommend to change de sleep 1, to something like 5 seconds. just in case this value is too short :)
     
  17. dissident

    dissident LI Guru Member

    Thank you. I've followed your advice. I also changed it from sleep to /bin/sleep. I guess this does not matter, but /bin/sleep is used elsewhere in the code. :)
     
  18. Sunspark

    Sunspark LI Guru Member

    Hmm.. does this thread contain content that could be considered to be a bug that could be patched by Jonathan in order to avoid usage of scripts?
     
  19. mstombs

    mstombs Network Guru Member

    It is a 'feature' of many Linux distros, but not easy to provide a universal fix.
    It would be good if some internal connection error counter could detect traffic failure on multiple connections and just communicate with udhcpc to mark the dhcpc lease as suspect and get it to refresh without breaking everything [which I think windows does...].

    A script could be built in as a 'new feature request' with web interface for easy config to provide the following functionality/ variables. In my previous testing of variants of the above script can cause problems by interfering with normal connection process, or breaking valid connections because the occasional ping fails. So many variables - maybe just example scripts are the best way forward?

    If using dhcp on WAN: [different options for pppoe etc]

    When we have got a valid dhcp lease on WAN check for connection by

    Enable monitoring Ping [a.b.c.d] or [ISP Gateway] or [DNS server 1/2] every [z] seconds

    If Ping fails just repeat [y] times before taking any action

    First action just try renewing dhcp lease

    If that doesn't work

    Try releasing dhcp lease wait [x] seconds renew dhcp lease

    If that doesn't work optionally reboot router as last resort, but don't do this more than [w] times...
     
  20. dissident

    dissident LI Guru Member

    Here is something I whipped up. It doesn't address all the points in the post above, but assuming it works at all, it might be an improvement.

    I was going to add some code to reboot the router if the counter reached a certain number, and cat a file as a semaphore to tell if a reboot had been done, but I'm too tired at this point.

    I haven't tested it at all.

    Code:
    This code has been superseded by a later post.
     
  21. rcordorica

    rcordorica Network Guru Member

    could this script work to detect is the wlan goes down? Due to interference in my area (apartment complex) sometimes my wlan goes down while the router and lan are ok.

    I guess you would have to add a toggle for the wlan start up and down.

    Usually power cycling helps (just to get the wlan up again).
     
  22. mstombs

    mstombs Network Guru Member

    @dissident

    I thought you said you were new to this scripting lark!

    I didn't know about the 'let' command, but just experimented - it does work - thanks.

    Re reboot count you could use a jffs/ non volatile file or easier to use a nvram variable with

    nvram set var=value; nvram commit

    recover with

    value =$(nvram get var)

    I have seen scripts that just reboot without such a counter, which could clearly fail with the device getting stuck into a reboot loop, only fixable by hard reset to defaults and re-entering all the config data:- so I encourage to add such protection before enabling an auto reboot.

    @rcordorica

    I'm sure you could mod a version of the script to ping your wireless PC and stop and restart wireless with

    service wlan stop
    sleep 5
    service wlan start

    instead of the dhcpc release/renew. Might do the job without rebooting

    But you will only want to do this when your wireless PC is supposed to be connected!
     
  23. dissident

    dissident LI Guru Member

    OK, here is another iteration of my script. Try not to laugh.

    Rather than setting an NVRAM variable to control reboots, I decided to enable a router reboot after a certain period of time of successful WAN pings. The first reboot will only be performed if the DHCP release/renew fails a number of times. Then, if the reboot didn't help, no other reboot will be performed until:

    1. WAN connectivity is restored somehow (by manual intervention and/or the DHCP release/renews still being attempted in the background);
    2. WAN connectivity is sustained for a period of time;
    3. WAN connectivity is lost again; and
    4. Subsequent DHCP release/renews fail to restore WAN connectivity.

    My thought was that if one reboot didn't help, more of the same would be a waste.

    With the counter checks as they are shown here, a reboot will be performed at most every 2 hours (actually somewhat longer than that, due to the sleeps done after DHCP renew and release/renew attempts).

    Again, this is untested. Comments welcome. :)

    Code:
    This code has been superseded by a later post.
     
  24. rcordorica

    rcordorica Network Guru Member

    thanks, i will definitely give this a try. I have an always on Desktop/Server that is connected by wireless, so it should always maintain a connection.
     
  25. dissident

    dissident LI Guru Member

    I'm new to Linux scripting, but not new to coding in general. :)

    Well, I don't blame anyone for not wanting to review this code. I'm tired of it myself! :)

    Here is what I came up with, for better or worse. I've tested it, including reboots, and it seems to work fine so far. Hopefully, it is pretty self-explanatory.

    Other random notes and comments:

    If enablereboot is set to 0, the script will never reboot the router. That is, this setting overrides everything else where rebooting is concerned.

    I set it up to enable rebooting (i.e. rebootflag gets set to 1) only when there are a number of consecutive successful pings since the last boot. I figured that if the connection is so screwed up that you can't get those consecutive pings after a router boot, a reboot probably won't help.

    The "Automatic reboot after $relrencount..." log message is generated every time there are $relrencount successful pings in a row after (1) router boot and (2) after there has been at least one failed ping. However, the only time $rebootflag is disabled is the time between router boot and the first time there are $relrencount successful pings in a row. After that, $rebootflag stays enabled, even if there are failed pings. In other words, the first time the "Automatic reboot after $relrencount..." message is logged, it means that $rebootflag was just enabled. After that, the message is purely informational.

    Code:
    # Perform DHCP renew and/or release/renew (and optional reboot) if WAN IP address pings fail
    
    ### Start of user settings ###
    # First IP address (not host name) to ping to check WAN accessibility.
    pingip1=xxx.xxx.xxx.xxx
    # Second IP address (not host name) to ping to check WAN accessibility.  Will be pinged only if first IP address ping fails.
    pingip2=xxx.xxx.xxx.xxx
    # Overall ping/DHCP release/DHCP renew loop delay. (Default: 60)
    delaysecs=60
    # Set to 0/1 to disable/enable router reboots. (Default: 1)
    enablereboot=1
    # Number of times to attempt DHCP release/renew before performing reboot. (Default: 60)
    relrencount=60
    # Number of consecutive successful pings required to enable rebootflag after each boot. (Default: 60)
    goodpingcount=60
    ### End of user settings ###
    
    # counter0 increments each time a ping of pingip1 or pingip2 succeeds.
    counter0=0
    # counter1 increments each time a DHCP renew is performed.
    counter1=0
    # counter2 increments each time a DHCP release/renew is performed.
    counter2=0
    # rebootflag is only turned on after a number of successful pings (based on counter0).
    rebootflag=0
    
    while [ true ] ; do
       if [ $counter0 -eq $goodpingcount ] ; then
          if [ $enablereboot -eq 1 ] ; then
             logger Automatic reboot after $relrencount DHCP release\/renew attempts enabled\. \($goodpingcount successful pings\.\)
             rebootflag=1
          fi
       fi
       /bin/sleep $delaysecs
       if ping -c 1 $pingip1 ; then
          if [ $counter1 -gt 0 ] ; then
             logger Ping of $pingip1 succeeded\.
          else
             if [ $counter2 -gt 0 ] ; then
                logger Ping of $pingip1 succeeded\.
             fi
          fi
          let counter0=counter0+1
          counter1=0
          counter2=0
          continue
       else
          if ping -c 1 $pingip2 ; then
             if [ $counter1 -gt 0 ] ; then
                logger Ping of $pingip2 succeeded\.
             else
                if [ $counter2 -gt 0 ] ; then
                   logger Ping of $pingip2 succeeded\.
                fi
             fi
             let counter0=counter0+1
             counter1=0
             counter2=0
             continue
          else
             counter0=0
             if [ $counter2 -eq $relrencount ] ; then
                if [ $rebootflag -eq 1 ] ; then
                   if [ $enablereboot -eq 1 ] ; then
                      logger Attempted DHCP release\/renew $counter2 times\. Performing reboot\.
                      /sbin/reboot
                      /bin/sleep 5
                   fi
                fi
             fi
             let counter1=counter1+1
             logger Ping of $pingip1 and $pingip2 failed\. Performing DHCP renew\. \(Attempt $counter1 since last successful ping\.\)
             /sbin/dhcpc-renew
             /bin/sleep 15
             if ping -c 1 $pingip1 ; then
                logger Ping of $pingip1 succeeded\.
                let counter0=counter0+1
                continue
             else
                if ping -c 1 $pingip2 ; then
                   logger Ping of $pingip2 succeeded\.
                   let counter0=counter0+1
                   continue
                else
                   let counter2=counter2+1
                   logger Ping of $pingip1 and $pingip2 failed\. Performing DHCP release\/renew\. \(Attempt $counter2 since last successful ping\.\)
                   /sbin/dhcpc-release
                   /bin/sleep 5
                   /sbin/dhcpc-renew
                fi
             fi
          fi
       fi
    done
    Thanks again, mstombs, for the advice!
     

Share This Page