From: Jo-Philipp Wich Date: Thu, 22 Jan 2015 14:53:16 +0000 (+0100) Subject: luci-mod-admin-full: switch to luci.ip route functions X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=5b94c1cca21aac49c0e105abd6b49b608b40e53e;p=oweals%2Fluci.git luci-mod-admin-full: switch to luci.ip route functions Signed-off-by: Jo-Philipp Wich --- diff --git a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/routes.lua b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/routes.lua index 01580f101..ac02b156e 100644 --- a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/routes.lua +++ b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/routes.lua @@ -1,14 +1,14 @@ -- Copyright 2008 Steven Barth -- Licensed to the public under the Apache License 2.0. -require("luci.tools.webadmin") +local wa = require "luci.tools.webadmin" +local fs = require "nixio.fs" + m = Map("network", translate("Routes"), translate("Routes specify over which interface and gateway a certain host or network " .. "can be reached.")) -local routes6 = luci.sys.net.routes6() - s = m:section(TypedSection, "route", translate("Static IPv4 Routes")) s.addremove = true s.anonymous = true @@ -16,7 +16,7 @@ s.anonymous = true s.template = "cbi/tblsection" iface = s:option(ListValue, "interface", translate("Interface")) -luci.tools.webadmin.cbi_add_networks(iface) +wa.cbi_add_networks(iface) t = s:option(Value, "target", translate("Target"), translate("Host-IP or Network")) t.datatype = "ip4addr" @@ -41,7 +41,7 @@ mtu.placeholder = 1500 mtu.datatype = "range(64,9000)" mtu.rmempty = true -if routes6 then +if fs.access("/proc/net/ipv6_route") then s = m:section(TypedSection, "route6", translate("Static IPv6 Routes")) s.addremove = true s.anonymous = true @@ -49,7 +49,7 @@ if routes6 then s.template = "cbi/tblsection" iface = s:option(ListValue, "interface", translate("Interface")) - luci.tools.webadmin.cbi_add_networks(iface) + wa.cbi_add_networks(iface) t = s:option(Value, "target", translate("Target"), translate("IPv6-Address or Network (CIDR)")) t.datatype = "ip6addr" diff --git a/modules/luci-mod-admin-full/luasrc/view/admin_status/routes.htm b/modules/luci-mod-admin-full/luasrc/view/admin_status/routes.htm index 2d9a4a3dc..82dd3a7df 100644 --- a/modules/luci-mod-admin-full/luasrc/view/admin_status/routes.htm +++ b/modules/luci-mod-admin-full/luasrc/view/admin_status/routes.htm @@ -1,15 +1,33 @@ <%# Copyright 2008-2009 Steven Barth - Copyright 2008-2009 Jo-Philipp Wich + Copyright 2008-2015 Jo-Philipp Wich Licensed to the public under the Apache License 2.0. -%> <%- - require "luci.sys" require "luci.tools.webadmin" require "nixio.fs" + local ip = require "luci.ip" local style = true + local _, v + + local rtn = { + [255] = "local", + [254] = "main", + [253] = "default", + [0] = "unspec" + } + + if nixio.fs.access("/etc/iproute2/rt_tables") then + local ln + for ln in io.lines("/etc/iproute2/rt_tables") do + local i, n = ln:match("^(%d+)%s+(%S+)") + if i and n then + rtn[tonumber(i)] = n + end + end + end -%> <%+header%> @@ -18,7 +36,7 @@

<%:Routes%>

<%:The following rules are currently active on this system.%>
-
+
ARP
@@ -28,19 +46,26 @@ - <% luci.sys.net.arptable(function(e) %> + <% + for _, v in ipairs(ip.neighbors({ family = 4 })) do + if v.mac then + %> - - - + + + - <% style = not style; end) %> + <% + style = not style + end + end + %>
<%:Interface%>
<%=e["IP address"]%><%=e["HW address"]%><%=e["Device"]%><%=v.dest%><%=v.mac%><%=v.dev%>

-
+
<%_Active IPv4-Routes%>
@@ -50,25 +75,27 @@ <%:Target%> <%_IPv4-Gateway%> <%:Metric%> + <%:Table%> - <% luci.sys.net.routes(function(rt) %> + <% for _, v in ipairs(ip.routes({ family = 4, type = 1 })) do %> - <%=luci.tools.webadmin.iface_get_network(rt.device) or rt.device%> - <%=rt.dest:string()%> - <%=rt.gateway:string()%> - <%=rt.metric%> + <%=luci.tools.webadmin.iface_get_network(v.dev) or v.dev%> + <%=v.dest%> + <%=v.gw%> + <%=v.metric or 0%> + <%=rtn[v.table] or v.table%> - <% style = not style; end) %> + <% style = not style end %>

- <% if nixio.fs.access("/proc/net/ipv6_route") then - style = true - fe80 = luci.ip.IPv6("fe80::/10") + <% + if nixio.fs.access("/proc/net/ipv6_route") then + style = true %> -
+
<%_Active IPv6-Routes%>
@@ -76,17 +103,55 @@ <%:Network%> <%:Target%> - <%_IPv6-Gateway%> + <%:Source%> <%:Metric%> + <%:Table%> + + <% + for _, v in ipairs(ip.routes({ family = 6, type = 1 })) do + if v.dest and not v.dest:is6linklocal() then + %> + + <%=luci.tools.webadmin.iface_get_network(v.dev) or '(' .. v.dev .. ')'%> + <%=v.dest%> + <%=v.from%> + <%=v.metric or 0%> + <%=rtn[v.table] or v.table%> + + <% + style = not style + end + end + %> + +
+
+
+ +
+ <%:IPv6 Neighbours%> + +
+ + + + + - <% luci.sys.net.routes6(function(rt) if fe80:contains(rt.dest) then return end %> + <% + for _, v in ipairs(ip.neighbors({ family = 6 })) do + if v.dest and not v.dest:is6linklocal() and v.mac then + %> - - - - + + + - <% style = not style; end) %> + <% + style = not style + end + end + %>
<%:IPv6-Address%><%:MAC-Address%><%:Interface%>
<%=luci.tools.webadmin.iface_get_network(rt.device) or '(' .. rt.device .. ')'%><%=rt.dest:string()%><%=rt.source:string()%><%=rt.metric_raw:upper()%><%=v.dest%><%=v.mac%><%=luci.tools.webadmin.iface_get_network(v.dev) or '(' .. v.dev .. ')'%>