libs/core: trigger garbage collection in coxpcall() if 80% of the allocated memory...
[project/luci.git] / modules / admin-full / luasrc / model / cbi / admin_status / routes.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10         http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13 ]]--
14
15 require("luci.tools.webadmin")
16 m = Map("network", translate("a_n_routes"), translate("a_n_routes1"))
17
18 local routes = luci.sys.net.routes()
19 local routes6 = luci.sys.net.routes6()
20 local bit = require "bit"
21
22 v = m:section(Table, routes, translate("a_n_routes_kernel4"))
23
24 net = v:option(DummyValue, "iface", translate("network"))
25 function net.cfgvalue(self, section)
26         return luci.tools.webadmin.iface_get_network(routes[section].device)
27          or routes[section].device
28 end
29
30 target  = v:option(DummyValue, "target", translate("target"))
31 function target.cfgvalue(self, section)
32         return routes[section].dest:network():string()
33 end
34
35 netmask = v:option(DummyValue, "netmask", translate("netmask"))
36 function netmask.cfgvalue(self, section)
37         return routes[section].dest:mask():string()
38 end
39
40 gateway = v:option(DummyValue, "gateway", translate("gateway"))
41 function gateway.cfgvalue(self, section)
42         return routes[section].gateway:string()
43 end
44
45 metric = v:option(DummyValue, "metric", translate("metric"))
46 function metric.cfgvalue(self, section)
47         return routes[section].metric
48 end
49
50 if routes6 then
51         v = m:section(Table, routes6, translate("a_n_routes_kernel6"))
52
53         net = v:option(DummyValue, "iface", translate("network"))
54         function net.cfgvalue(self, section)
55                 return luci.tools.webadmin.iface_get_network(routes6[section].device)
56                  or routes6[section].device
57         end
58
59         target  = v:option(DummyValue, "target", translate("target"))
60         function target.cfgvalue(self, section)
61                 return routes6[section].dest:string()
62         end
63
64         gateway = v:option(DummyValue, "gateway", translate("gateway6"))
65         function gateway.cfgvalue(self, section)
66                 return routes6[section].source:string()
67         end
68
69         metric = v:option(DummyValue, "metric", translate("metric"))
70         function metric.cfgvalue(self, section)
71                 local metr = routes6[section].metric
72                 local lower = bit.band(metr, 0xffff)
73                 local higher = bit.rshift(bit.band(metr, 0xffff0000), 16)
74                 return "%04X%04X" % {higher, lower}
75         end
76 end
77
78
79 return m