modules/admin-full: whitesapce cleanup in routes.lua
authorJo-Philipp Wich <jow@openwrt.org>
Sun, 30 Nov 2008 19:12:58 +0000 (19:12 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Sun, 30 Nov 2008 19:12:58 +0000 (19:12 +0000)
libs/sys: code changes in routes6() and defaultroute6()

libs/sys/luasrc/sys.lua
modules/admin-full/luasrc/model/cbi/admin_network/routes.lua

index e92adc1ad6ab8972f990baa4aff02eb160293535..fee1feeafd46e09239ccfbf4b4124281808b749c 100644 (file)
@@ -319,14 +319,15 @@ end
 --                     { "source", "dest", "nexthop", "metric", "refcount", "usecount",
 --                       "flags", "device" }
 function net.defaultroute6()
-       local route = nil
+       local route   = nil
        local routes6 = net.routes6()
-       if not routes6 then
-               return nil
-       end
-       for _, r in pairs(routes6) do
-               if r.dest:prefix() == 0 and (not route or route.metric > r.metric) then
-                       route = r
+       if routes6 then
+               for _, r in pairs(routes6) do
+                       if r.dest:prefix() == 0 and
+                          (not route or route.metric > r.metric)
+                       then
+                               route = r
+                       end
                end
        end
        return route
@@ -419,46 +420,44 @@ end
 --                     { "source", "dest", "nexthop", "metric", "refcount", "usecount",
 --                       "flags", "device" }
 function net.routes6()
-       local routes = { }
-
-       if not luci.fs.access("/proc/net/ipv6_route", "r") then
-               return nil
-       end
+       if luci.fs.access("/proc/net/ipv6_route", "r") then
+               local routes = { }
+
+               for line in io.lines("/proc/net/ipv6_route") do
+
+                       local dst_ip, dst_prefix, src_ip, src_prefix, nexthop,
+                                 metric, refcnt, usecnt, flags, dev = line:match(
+                               "([a-f0-9]+) ([a-f0-9]+) " ..
+                               "([a-f0-9]+) ([a-f0-9]+) " ..
+                               "([a-f0-9]+) ([a-f0-9]+) " ..
+                               "([a-f0-9]+) ([a-f0-9]+) " ..
+                               "([a-f0-9]+) +([^%s]+)"
+                       )
 
-       for line in io.lines("/proc/net/ipv6_route") do
+                       src_ip = luci.ip.Hex(
+                               src_ip, tonumber(src_prefix, 16), luci.ip.FAMILY_INET6, false
+                       )
 
-               local dst_ip, dst_prefix, src_ip, src_prefix, nexthop,
-                         metric, refcnt, usecnt, flags, dev = line:match(
-                       "([a-f0-9]+) ([a-f0-9]+) " ..
-                       "([a-f0-9]+) ([a-f0-9]+) " ..
-                       "([a-f0-9]+) ([a-f0-9]+) " ..
-                       "([a-f0-9]+) ([a-f0-9]+) " ..
-                       "([a-f0-9]+) +([^%s]+)"
-               )
+                       dst_ip = luci.ip.Hex(
+                               dst_ip, tonumber(dst_prefix, 16), luci.ip.FAMILY_INET6, false
+                       )
 
-               src_ip = luci.ip.Hex(
-                       src_ip, tonumber(src_prefix, 16), luci.ip.FAMILY_INET6, false
-               )
+                       nexthop = luci.ip.Hex( nexthop, 128, luci.ip.FAMILY_INET6, false )
 
-               dst_ip = luci.ip.Hex(
-                       dst_ip, tonumber(dst_prefix, 16), luci.ip.FAMILY_INET6, false
-               )
+                       routes[#routes+1] = {
+                               source   = src_ip,
+                               dest     = dst_ip,
+                               nexthop  = nexthop,
+                               metric   = tonumber(metric, 16),
+                               refcount = tonumber(refcnt, 16),
+                               usecount = tonumber(usecnt, 16),
+                               flags    = tonumber(flags, 16),
+                               device   = dev
+                       }
+               end
 
-               nexthop = luci.ip.Hex( nexthop, 128, luci.ip.FAMILY_INET6, false )
-
-               routes[#routes+1] = {
-                       source   = src_ip,
-                       dest     = dst_ip,
-                       nexthop  = nexthop,
-                       metric   = tonumber(metric, 16),
-                       refcount = tonumber(refcnt, 16),
-                       usecount = tonumber(usecnt, 16),
-                       flags    = tonumber(flags, 16),
-                       device   = dev
-               }
+               return routes
        end
-
-       return routes
 end
 
 --- Tests whether the given host responds to ping probes.
index 0d20d67223bdfd0d43dbb31ca7db706925edf603..be6629774fda4f9b830be0180db6757bf724014f 100644 (file)
@@ -42,7 +42,10 @@ if not arg or not arg[1] then
                return routes[section].gateway:string()
        end
 
-       metric = v:option(DummyValue, "Metric", translate("metric"))
+       metric = v:option(DummyValue, "metric", translate("metric"))
+       function metric.cfgvalue(self, section)
+               return routes[section].metric
+       end
 
        if routes6 then
                v = m:section(Table, routes6, translate("a_n_routes_kernel6"))
@@ -63,10 +66,10 @@ if not arg or not arg[1] then
                        return routes6[section].source:string()
                end
 
-               metric = v:option(DummyValue, "Metric", translate("metric"))
-           function metric.cfgvalue(self, section)
-               return string.format( "%08X", routes6[section].metric )
-           end
+               metric = v:option(DummyValue, "metric", translate("metric"))
+               function metric.cfgvalue(self, section)
+                       return string.format( "%08X", routes6[section].metric )
+               end
        end
 end