+ local routes = { }
+
+ for line in io.lines("/proc/net/route") do
+
+ local dev, dst_ip, gateway, flags, refcnt, usecnt, metric,
+ dst_mask, mtu, win, irtt = line:match(
+ "([^%s]+)\t([A-F0-9]+)\t([A-F0-9]+)\t([A-F0-9]+)\t" ..
+ "(%d+)\t(%d+)\t(%d+)\t([A-F0-9]+)\t(%d+)\t(%d+)\t(%d+)"
+ )
+
+ if dev then
+ gateway = luci.ip.Hex( gateway, 32, luci.ip.FAMILY_INET4 )
+ dst_mask = luci.ip.Hex( dst_mask, 32, luci.ip.FAMILY_INET4 )
+ dst_ip = luci.ip.Hex(
+ dst_ip, dst_mask:prefix(dst_mask), luci.ip.FAMILY_INET4
+ )
+
+ routes[#routes+1] = {
+ dest = dst_ip,
+ gateway = gateway,
+ metric = tonumber(metric),
+ refcount = tonumber(refcnt),
+ usecount = tonumber(usecnt),
+ mtu = tonumber(mtu),
+ window = tonumber(window),
+ irtt = tonumber(irtt),
+ flags = tonumber(flags, 16),
+ device = dev
+ }
+ end
+ end
+
+ return routes