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

Welcome To SNBForums

SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.

If you'd like to post a question, simply register and have at it!

While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!

Dual WAN latency based Failover

Discussion in 'Asuswrt-Merlin' started by Colanta, May 29, 2020.

  1. Colanta

    Colanta Occasional Visitor

    Jul 2, 2018

    Currently i have a problem with my main isp (300/10), where its connection node on my town, while working (0.2/10), gives an insane high latency (300ms+) to Google DNS Server, pretty away from the normal (20ms).

    I'm looking to add a parameter to the falldown configuration, to be ping not responding or higher than XXX, but i really do not know if it is possible to do this in an User Script/WatchDog (haven't found it on source yet?) mod.

    Any Ideas? or something already posted and done elsewhere?

    Thank You

    PD. Sorry for my English
    Last edited by a moderator: May 30, 2020
  2. Colanta

    Colanta Occasional Visitor

    Jul 2, 2018
    I've found what i guess is the code responsible for checking the dual wan connectivity by ping, i've done a small (dirty) patch just to try on the next node failure:

    int do_ping_detect(int wan_unit, const char *target)
    	FILE *fp;
    	char cmd[512];
    	int count, ret = -1, validLatency;
    	float latency = -1;
    	int debug = nvram_get_int("ping_debug");
    	/* can be default target, if necesary *//*
    	if (!target)
    		target = nvram_safe_get("ping_target");
    	/* Check for valid domain to avoid shell escaping */
    	if (!is_valid_domainname(target))
    		return -1;
    	if (debug)
    		_dprintf("%s: %s %s\n", __FUNCTION__, "check", target);
    	snprintf(cmd, sizeof(cmd), "ping -c1 -w2 -s32 %s -Mdont '%s' 2>/dev/null",
    		 nvram_get_int("ttl_spoof_enable") ? "" : "-t128", target);
    	if ((fp = popen(cmd, "r")) != NULL) {
    		while (fgets(cmd, sizeof(cmd), fp) != NULL) {
    			if (sscanf(cmd, "%*s %*s transmitted, %d %*s received", &count) == 1) {
    				ret = (count > 0);
    				if (debug)
    					_dprintf("%s: %s %s\n", __FUNCTION__, target, ret ? "ret: ok" : "ret: fail");
    			} else if (sscanf(cmd, "rtt %*s = %f/%*s ms", &latency) == 1){
    			    //TODO: Get '100' from an NVRAM Value
    				validLatency = (latency < 100);
    				if (debug)
    				    _dprintf("%s: %s %s\n", __FUNCTION__, target, validLatency ? "latency: ok" : "latency: fail");
    	return ret && validPing;