libs/core/ip: optmizations
[project/luci.git] / modules / admin-full / luasrc / model / cbi / admin_network / 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 require("luci.tools.webadmin")
15 m = Map("network", translate("a_n_routes"), translate("a_n_routes1"))
16
17 if not arg or not arg[1] then
18         local routes = luci.sys.net.routes()
19
20         v = m:section(Table, routes, translate("a_n_routes_kernel4"))
21
22         net = v:option(DummyValue, "iface", translate("network"))
23         function net.cfgvalue(self, section)
24                 return luci.tools.webadmin.iface_get_network(routes[section].device)
25                  or routes[section].device
26         end
27
28         target  = v:option(DummyValue, "target", translate("target"))
29         function target.cfgvalue(self, section)
30                 return routes[section].dest:network():string()
31         end
32
33         netmask = v:option(DummyValue, "netmask", translate("netmask"))
34         function netmask.cfgvalue(self, section)
35                 return routes[section].dest:mask():string()
36         end
37
38         gateway = v:option(DummyValue, "gateway", translate("gateway"))
39         function gateway.cfgvalue(self, section)
40                 return routes[section].gateway:string()
41         end
42
43         metric = v:option(DummyValue, "Metric", translate("metric"))
44
45
46         local routes6 = luci.sys.net.routes6()
47
48         v = m:section(Table, routes6, translate("a_n_routes_kernel6"))
49
50         net = v:option(DummyValue, "iface", translate("network"))
51         function net.cfgvalue(self, section)
52                 return luci.tools.webadmin.iface_get_network(routes6[section].device)
53                  or routes6[section].device
54         end
55
56         target  = v:option(DummyValue, "target", translate("target"))
57         function target.cfgvalue(self, section)
58                 return routes6[section].dest:string()
59         end
60
61         gateway = v:option(DummyValue, "gateway", translate("gateway6"))
62         function gateway.cfgvalue(self, section)
63                 return routes6[section].source:string()
64         end
65
66         metric = v:option(DummyValue, "Metric", translate("metric"))
67     function metric.cfgvalue(self, section)
68         return string.format( "%08X", routes6[section].metric )
69     end
70 end
71
72
73 s = m:section(TypedSection, "route", translate("a_n_routes_static4"))
74 s.addremove = true
75 s.anonymous = true
76
77 s.template  = "cbi/tblsection"
78
79 iface = s:option(ListValue, "interface", translate("interface"))
80 luci.tools.webadmin.cbi_add_networks(iface)
81
82 if not arg or not arg[1] then
83         net.titleref = iface.titleref
84 end
85
86 s:option(Value, "target", translate("target"), translate("a_n_r_target1"))
87
88 s:option(Value, "netmask", translate("netmask"), translate("a_n_r_netmask1")).rmemepty = true
89
90 s:option(Value, "gateway", translate("gateway"))
91
92
93 s = m:section(TypedSection, "route6", translate("a_n_routes_static6"))
94 s.addremove = true
95 s.anonymous = true
96
97 s.template  = "cbi/tblsection"
98
99 iface = s:option(ListValue, "interface", translate("interface"))
100 luci.tools.webadmin.cbi_add_networks(iface)
101
102 if not arg or not arg[1] then
103         net.titleref = iface.titleref
104 end
105
106 s:option(Value, "target", translate("target"), translate("a_n_r_target6"))
107
108 s:option(Value, "gateway", translate("gateway6")).rmempty = true
109
110
111 return m