2
0

routes.htm 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <%#
  2. Copyright 2008-2009 Steven Barth <steven@midlink.org>
  3. Copyright 2008-2015 Jo-Philipp Wich <jow@openwrt.org>
  4. Licensed to the public under the Apache License 2.0.
  5. -%>
  6. <%-
  7. require "luci.tools.webadmin"
  8. require "nixio.fs"
  9. local ip = require "luci.ip"
  10. local style = true
  11. local _, v
  12. local rtn = {
  13. [255] = "local",
  14. [254] = "main",
  15. [253] = "default",
  16. [0] = "unspec"
  17. }
  18. if nixio.fs.access("/etc/iproute2/rt_tables") then
  19. local ln
  20. for ln in io.lines("/etc/iproute2/rt_tables") do
  21. local i, n = ln:match("^(%d+)%s+(%S+)")
  22. if i and n then
  23. rtn[tonumber(i)] = n
  24. end
  25. end
  26. end
  27. -%>
  28. <%+header%>
  29. <div class="cbi-map" id="cbi-network">
  30. <h2 name="content"><%:Routes%></h2>
  31. <div class="cbi-map-descr"><%:The following rules are currently active on this system.%></div>
  32. <fieldset class="cbi-section">
  33. <legend>ARP</legend>
  34. <div class="cbi-section-node">
  35. <table class="cbi-section-table">
  36. <tr class="cbi-section-table-titles">
  37. <th class="cbi-section-table-cell"><%_<abbr title="Internet Protocol Version 4">IPv4</abbr>-Address%></th>
  38. <th class="cbi-section-table-cell"><%_<abbr title="Media Access Control">MAC</abbr>-Address%></th>
  39. <th class="cbi-section-table-cell"><%:Interface%></th>
  40. </tr>
  41. <%
  42. for _, v in ipairs(ip.neighbors({ family = 4 })) do
  43. if v.mac then
  44. %>
  45. <tr class="cbi-section-table-row cbi-rowstyle-<%=(style and 1 or 2)%>">
  46. <td class="cbi-value-field"><%=v.dest%></td>
  47. <td class="cbi-value-field"><%=v.mac%></td>
  48. <td class="cbi-value-field"><%=v.dev%></td>
  49. </tr>
  50. <%
  51. style = not style
  52. end
  53. end
  54. %>
  55. </table>
  56. </div>
  57. </fieldset>
  58. <br />
  59. <fieldset class="cbi-section">
  60. <legend><%_Active <abbr title="Internet Protocol Version 4">IPv4</abbr>-Routes%></legend>
  61. <div class="cbi-section-node">
  62. <table class="cbi-section-table">
  63. <tr class="cbi-section-table-titles">
  64. <th class="cbi-section-table-cell"><%:Network%></th>
  65. <th class="cbi-section-table-cell"><%:Target%></th>
  66. <th class="cbi-section-table-cell"><%_<abbr title="Internet Protocol Version 4">IPv4</abbr>-Gateway%></th>
  67. <th class="cbi-section-table-cell"><%:Metric%></th>
  68. <th class="cbi-section-table-cell"><%:Table%></th>
  69. </tr>
  70. <% for _, v in ipairs(ip.routes({ family = 4, type = 1 })) do %>
  71. <tr class="cbi-section-table-row cbi-rowstyle-<%=(style and 1 or 2)%>">
  72. <td class="cbi-value-field"><%=luci.tools.webadmin.iface_get_network(v.dev) or v.dev%></td>
  73. <td class="cbi-value-field"><%=v.dest%></td>
  74. <td class="cbi-value-field"><%=v.gw%></td>
  75. <td class="cbi-value-field"><%=v.metric or 0%></td>
  76. <td class="cbi-value-field"><%=rtn[v.table] or v.table%></td>
  77. </tr>
  78. <% style = not style end %>
  79. </table>
  80. </div>
  81. </fieldset>
  82. <br />
  83. <%
  84. if nixio.fs.access("/proc/net/ipv6_route") then
  85. style = true
  86. %>
  87. <fieldset class="cbi-section">
  88. <legend><%_Active <abbr title="Internet Protocol Version 6">IPv6</abbr>-Routes%></legend>
  89. <div class="cbi-section-node">
  90. <table class="cbi-section-table">
  91. <tr class="cbi-section-table-titles">
  92. <th class="cbi-section-table-cell"><%:Network%></th>
  93. <th class="cbi-section-table-cell"><%:Target%></th>
  94. <th class="cbi-section-table-cell"><%:Source%></th>
  95. <th class="cbi-section-table-cell"><%:Metric%></th>
  96. <th class="cbi-section-table-cell"><%:Table%></th>
  97. </tr>
  98. <%
  99. for _, v in ipairs(ip.routes({ family = 6, type = 1 })) do
  100. if v.dest and not v.dest:is6linklocal() then
  101. %>
  102. <tr class="cbi-section-table-row cbi-rowstyle-<%=(style and 1 or 2)%>">
  103. <td class="cbi-value-field"><%=luci.tools.webadmin.iface_get_network(v.dev) or '(' .. v.dev .. ')'%></td>
  104. <td class="cbi-value-field"><%=v.dest%></td>
  105. <td class="cbi-value-field"><%=v.from%></td>
  106. <td class="cbi-value-field"><%=v.metric or 0%></td>
  107. <td class="cbi-value-field"><%=rtn[v.table] or v.table%></td>
  108. </tr>
  109. <%
  110. style = not style
  111. end
  112. end
  113. %>
  114. </table>
  115. </div>
  116. </fieldset>
  117. <br />
  118. <fieldset class="cbi-section">
  119. <legend><%:IPv6 Neighbours%></legend>
  120. <div class="cbi-section-node">
  121. <table class="cbi-section-table">
  122. <tr class="cbi-section-table-titles">
  123. <th class="cbi-section-table-cell"><%:IPv6-Address%></th>
  124. <th class="cbi-section-table-cell"><%:MAC-Address%></th>
  125. <th class="cbi-section-table-cell"><%:Interface%></th>
  126. </tr>
  127. <%
  128. for _, v in ipairs(ip.neighbors({ family = 6 })) do
  129. if v.dest and not v.dest:is6linklocal() and v.mac then
  130. %>
  131. <tr class="cbi-section-table-row cbi-rowstyle-<%=(style and 1 or 2)%>">
  132. <td class="cbi-value-field"><%=v.dest%></td>
  133. <td class="cbi-value-field"><%=v.mac%></td>
  134. <td class="cbi-value-field"><%=luci.tools.webadmin.iface_get_network(v.dev) or '(' .. v.dev .. ')'%></td>
  135. </tr>
  136. <%
  137. style = not style
  138. end
  139. end
  140. %>
  141. </table>
  142. </div>
  143. </fieldset>
  144. <br />
  145. <% end %>
  146. </div>
  147. <%+footer%>