From 950825d323964b40dc53d7386e2d337e655ed33e Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Wed, 26 Nov 2008 22:57:57 +0000 Subject: [PATCH] libs/sys: implement luci.sys.net.routes6() --- libs/sys/luasrc/sys.lua | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/libs/sys/luasrc/sys.lua b/libs/sys/luasrc/sys.lua index 52ed0c36d..b4b6f6805 100644 --- a/libs/sys/luasrc/sys.lua +++ b/libs/sys/luasrc/sys.lua @@ -361,6 +361,52 @@ function net.routes() return _parse_delimited_table(io.lines("/proc/net/route")) end +--- Returns the current ipv6 kernel routing table entries. +-- @return Table of tables with properties of the corresponding routes. +-- The following fields are defined for route entry tables: +-- { "src_ip", "src_prefix", "dst_ip", "dst_prefix", "nexthop_ip", +-- "metric", "refcount", "usecount", "flags", "device" } +function net.routes6() + 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]+) " .. + "(%d+) (%d+) ([^%s]+) +([^%s]+)" + ) + + src_ip = luci.ip.Hex( + src_ip, tonumber(src_prefix, 16), + luci.ip.FAMILY_INET6, false + ) + + dst_ip = luci.ip.Hex( + dst_ip, tonumber(dst_prefix, 16), + luci.ip.FAMILY_INET6, false + ) + + nexthop = luci.ip.Hex( nexthop, 128, luci.ip.FAMILY_INET6, false ) + + routes[#routes+1] = { + src_ip = src_ip:host():string(), + src_prefix = src_ip:prefix(), + dst_ip = dst_ip:host():string(), + dst_prefix = dst_ip:prefix(), + nexthop_ip = nexthop:string(), + metric = tonumber(metric, 16), + refcount = tonumber(refcnt), + usecount = tonumber(usecnt), + flags = tonumber(flags), -- hex? + device = dev + } + end + + return routes +end --- Tests whether the given host responds to ping probes. -- @param host String containing a hostname or IPv4 address -- 2.25.1