luci-mod-admin-full: switch to luci.ip route functions
[project/luci.git] / modules / luci-mod-admin-full / luasrc / view / admin_status / routes.htm
index 2d9a4a3..82dd3a7 100644 (file)
@@ -1,15 +1,33 @@
 <%#
  Copyright 2008-2009 Steven Barth <steven@midlink.org>
- Copyright 2008-2009 Jo-Philipp Wich <jow@openwrt.org>
+ Copyright 2008-2015 Jo-Philipp Wich <jow@openwrt.org>
  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 @@
        <h2><a id="content" name="content"><%:Routes%></a></h2>
        <div class="cbi-map-descr"><%:The following rules are currently active on this system.%></div>
 
-       <fieldset class="cbi-section" id="cbi-table-table">
+       <fieldset class="cbi-section">
                <legend>ARP</legend>
                <div class="cbi-section-node">
                        <table class="cbi-section-table">
                                        <th class="cbi-section-table-cell"><%:Interface%></th>
                                </tr>
 
-                               <% luci.sys.net.arptable(function(e) %>
+                               <%
+                                       for _, v in ipairs(ip.neighbors({ family = 4 })) do
+                                               if v.mac then
+                               %>
                                <tr class="cbi-section-table-row cbi-rowstyle-<%=(style and 1 or 2)%>">
-                                       <td class="cbi-value-field"><%=e["IP address"]%></td>
-                                       <td class="cbi-value-field"><%=e["HW address"]%></td>
-                                       <td class="cbi-value-field"><%=e["Device"]%></td>
+                                       <td class="cbi-value-field"><%=v.dest%></td>
+                                       <td class="cbi-value-field"><%=v.mac%></td>
+                                       <td class="cbi-value-field"><%=v.dev%></td>
                                </tr>
-                               <% style = not style; end) %>
+                               <%
+                                                       style = not style
+                                               end
+                                       end
+                               %>
                        </table>
                </div>
        </fieldset>
        <br />
 
-       <fieldset class="cbi-section" id="cbi-table-table">
+       <fieldset class="cbi-section">
                <legend><%_Active <abbr title="Internet Protocol Version 4">IPv4</abbr>-Routes%></legend>
 
                <div class="cbi-section-node">
                                        <th class="cbi-section-table-cell"><%:Target%></th>
                                        <th class="cbi-section-table-cell"><%_<abbr title="Internet Protocol Version 4">IPv4</abbr>-Gateway%></th>
                                        <th class="cbi-section-table-cell"><%:Metric%></th>
+                                       <th class="cbi-section-table-cell"><%:Table%></th>
                                </tr>
-                               <% luci.sys.net.routes(function(rt) %>
+                               <% for _, v in ipairs(ip.routes({ family = 4, type = 1 })) do %>
                                <tr class="cbi-section-table-row cbi-rowstyle-<%=(style and 1 or 2)%>">
-                                       <td class="cbi-value-field"><%=luci.tools.webadmin.iface_get_network(rt.device) or rt.device%></td>
-                                       <td class="cbi-value-field"><%=rt.dest:string()%></td>
-                                       <td class="cbi-value-field"><%=rt.gateway:string()%></td>
-                                       <td class="cbi-value-field"><%=rt.metric%></td>
+                                       <td class="cbi-value-field"><%=luci.tools.webadmin.iface_get_network(v.dev) or v.dev%></td>
+                                       <td class="cbi-value-field"><%=v.dest%></td>
+                                       <td class="cbi-value-field"><%=v.gw%></td>
+                                       <td class="cbi-value-field"><%=v.metric or 0%></td>
+                                       <td class="cbi-value-field"><%=rtn[v.table] or v.table%></td>
                                </tr>
-                               <% style = not style; end) %>
+                               <% style = not style end %>
                        </table>
                </div>
        </fieldset>
        <br />
 
-       <% 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
        %>
-       <fieldset class="cbi-section" id="cbi-table-table">
+       <fieldset class="cbi-section">
                <legend><%_Active <abbr title="Internet Protocol Version 6">IPv6</abbr>-Routes%></legend>
 
                <div class="cbi-section-node">
                                <tr class="cbi-section-table-titles">
                                        <th class="cbi-section-table-cell"><%:Network%></th>
                                        <th class="cbi-section-table-cell"><%:Target%></th>
-                                       <th class="cbi-section-table-cell"><%_<abbr title="Internet Protocol Version 6">IPv6</abbr>-Gateway%></th>
+                                       <th class="cbi-section-table-cell"><%:Source%></th>
                                        <th class="cbi-section-table-cell"><%:Metric%></th>
+                                       <th class="cbi-section-table-cell"><%:Table%></th>
+                               </tr>
+                               <%
+                                       for _, v in ipairs(ip.routes({ family = 6, type = 1 })) do
+                                               if v.dest and not v.dest:is6linklocal() then
+                               %>
+                               <tr class="cbi-section-table-row cbi-rowstyle-<%=(style and 1 or 2)%>">
+                                       <td class="cbi-value-field"><%=luci.tools.webadmin.iface_get_network(v.dev) or '(' .. v.dev .. ')'%></td>
+                                       <td class="cbi-value-field"><%=v.dest%></td>
+                                       <td class="cbi-value-field"><%=v.from%></td>
+                                       <td class="cbi-value-field"><%=v.metric or 0%></td>
+                                       <td class="cbi-value-field"><%=rtn[v.table] or v.table%></td>
+                               </tr>
+                               <%
+                                                       style = not style
+                                               end
+                                       end
+                               %>
+                       </table>
+               </div>
+       </fieldset>
+       <br />
+
+       <fieldset class="cbi-section">
+               <legend><%:IPv6 Neighbours%></legend>
+
+               <div class="cbi-section-node">
+                       <table class="cbi-section-table">
+                               <tr class="cbi-section-table-titles">
+                                       <th class="cbi-section-table-cell"><%:IPv6-Address%></th>
+                                       <th class="cbi-section-table-cell"><%:MAC-Address%></th>
+                                       <th class="cbi-section-table-cell"><%:Interface%></th>
                                </tr>
-                               <% 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
+                               %>
                                <tr class="cbi-section-table-row cbi-rowstyle-<%=(style and 1 or 2)%>">
-                                       <td class="cbi-value-field"><%=luci.tools.webadmin.iface_get_network(rt.device) or '(' .. rt.device .. ')'%></td>
-                                       <td class="cbi-value-field"><%=rt.dest:string()%></td>
-                                       <td class="cbi-value-field"><%=rt.source:string()%></td>
-                                       <td class="cbi-value-field"><%=rt.metric_raw:upper()%></td>
+                                       <td class="cbi-value-field"><%=v.dest%></td>
+                                       <td class="cbi-value-field"><%=v.mac%></td>
+                                       <td class="cbi-value-field"><%=luci.tools.webadmin.iface_get_network(v.dev) or '(' .. v.dev .. ')'%></td>
                                </tr>
-                               <% style = not style; end) %>
+                               <%
+                                                       style = not style
+                                               end
+                                       end
+                               %>
                        </table>
                </div>
        </fieldset>