[Zrouter-src] ZRouter.org: push to ZRouter profiles/lua_web_ui/files/etc/www/l...
zrouter-src at zrouter.org
zrouter-src at zrouter.org
Mon Sep 24 11:23:53 UTC 2012
details: http://zrouter.org/hg/zrouter//rev/f533387b0dd6
changeset: 468:f533387b0dd6
user: Aleksandr Rybalko <ray at ddteam.net>
date: Mon Sep 24 14:20:43 2012 +0300
description:
Helper to do link test.
Currently implement most correct way:
1. Install route for ISP DNSs to link associated to that ISP.
2. query some domain that well known as Not Existent.
3. a) NX Domain - link works
b) Serv Fail - ISP have problem with their uplinks.
c) Timeout - no link to ISP
diffstat:
profiles/lua_web_ui/files/etc/www/lib/linktest.lua | 75 ++++++++++++++++++++++
1 files changed, 75 insertions(+), 0 deletions(-)
diffs (79 lines):
diff -r 2b4ab6b5816c -r f533387b0dd6 profiles/lua_web_ui/files/etc/www/lib/linktest.lua
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/profiles/lua_web_ui/files/etc/www/lib/linktest.lua Mon Sep 24 14:20:43 2012 +0300
@@ -0,0 +1,75 @@
+LinkTest = {};
+mtLinkTest = {};
+
+function LinkTest:new(name)
+ ltest = {};
+
+ ltest.name = name;
+
+ return (setmetatable(ltest, mtLinkTest));
+end
+
+function LinkTest:NXDomainInit()
+ self.dns = require "dns";
+ self.ns = {};
+ self.iface = "wan0"; -- XXX: test only
+-- table.insert(self.ns, "192.168.10.10");
+ table.insert(self.ns, "192.168.10.15");
+
+ function setup_ns_route(ns, iface)
+ local routecmd = string.format(
+ "/sbin/route add %s -iface %s", ns, iface);
+ print("LinkTest: exec", routecmd);
+ os.execute(routecmd);
+ end
+
+ for i,ns in ipairs(self.ns) do
+ setup_ns_route(ns, self.iface);
+ end
+end
+
+function LinkTest:NXDomain()
+ local function query(dns, server, host)
+ local e = dns.encode {
+ id = math.random(),
+ query = true,
+ rd = true,
+ opcode = 'query',
+ question = {
+ name = host,
+ type = 'a',
+ class = 'in'
+ }
+ }
+
+ local r,err = dns.query(server, e);
+
+ if r == nil then
+ print("error:",err)
+ return nil
+ end
+
+ return dns.decode(r)
+ end
+ for i,ns in ipairs(self.ns) do
+ local nxhost = os.time() .. "nxdom.com.";
+ print("LinkTest: Ask " .. ns .. " for \"" .. nxhost ..
+ "\" via " .. self.iface);
+ local result = query(self.dns, ns, nxhost);
+ if (result.rcode == 3) then
+ return (true);
+ end
+ end
+
+ return (false);
+end
+
+mtLinkTest.__index = LinkTest;
+
+--[[
+How to test:
+
+lt = LinkTest:new("test");
+lt:NXDomainInit();
+lt:NXDomain();
+]]
More information about the Zrouter-src
mailing list