---- Determine the current IPv4 default route. If multiple default routes exist,
--- return the one with the lowest metric.
--- @return Table with the properties of the current default route.
--- The following fields are defined:
--- { "dest", "gateway", "metric", "refcount", "usecount", "irtt",
--- "flags", "device" }
-function net.defaultroute()
- local route
-
- net.routes(function(rt)
- if rt.dest:prefix() == 0 and (not route or route.metric > rt.metric) then
- route = rt
- end
- end)
-
- return route
-end
-
---- Determine the current IPv6 default route. If multiple default routes exist,
--- return the one with the lowest metric.
--- @return Table with the properties of the current default route.
--- The following fields are defined:
--- { "source", "dest", "nexthop", "metric", "refcount", "usecount",
--- "flags", "device" }
-function net.defaultroute6()
- local route
-
- net.routes6(function(rt)
- if rt.dest:prefix() == 0 and rt.device ~= "lo" and
- (not route or route.metric > rt.metric)
- then
- route = rt
- end
- end)
-
- if not route then
- local global_unicast = luci.ip.IPv6("2000::/3")
- net.routes6(function(rt)
- if rt.dest:equal(global_unicast) and
- (not route or route.metric > rt.metric)
- then
- route = rt
- end
- end)
- end
-
- return route
-end
-