d823907fc843248c2787138a917c0a4207360e44
[feed/routing.git] / bird-openwrt / bird6-openwrt / src / model / gen_proto.lua
1 --[[
2 Copyright (C) 2014-2017 - Eloi Carbo
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 --]]
17
18 require("luci.sys")
19 local http = require "luci.http"
20 local uci = luci.model.uci.cursor()
21
22 -- Repeated Strings
23 local common_string = "Valid options are:<br />" .. "1. all (All the routes)<br />" .. "2. none (No routes)<br />" .. "3. filter <b>Your_Filter_Name</b> (Call a specific filter from any of the available in the filters files)"
24 local imp_string = "Set if the protocol must import routes.<br />" .. common_string
25 local exp_string = "Set if the protocol must export routes.<br />" .. common_string
26
27 m=Map("bird6", "Bird6 general protocol's configuration.")
28
29 -- Optional parameters lists
30 local protoptions = {
31 {["name"]="table", ["help"]="Auxiliar table for routing", ["depends"]={"static","kernel"}},
32 {["name"]="import", ["help"]=imp_string, ["depends"]={"kernel"}},
33 {["name"]="export", ["help"]=exp_string, ["depends"]={"kernel"}},
34 {["name"]="scan_time", ["help"]="Time between scans", ["depends"]={"kernel","device"}},
35 {["name"]="kernel_table", ["help"]="Set which table must be used as auxiliar kernel table", ["depends"]={"kernel"}},
36 {["name"]="learn", ["help"]="Learn routes", ["depends"]={"kernel"}},
37 {["name"]="persist", ["help"]="Store routes. After a restart, routes willstill be configured", ["depends"]={"kernel"}}
38 }
39
40 local routeroptions = {
41 {["name"]="prefix",["help"]="",["depends"]={"router","special","iface","multipath","recursive"}},
42 {["name"]="via",["help"]="",["depends"]={"router","multipath"}},
43 {["name"]="attribute",["help"]="",["depends"]={"special"}},
44 {["name"]="iface",["help"]="",["depends"]={"iface"}},
45 {["name"]="ip",["help"]="",["depends"]={"recursive"}}
46 }
47
48 --
49 -- KERNEL PROTOCOL
50 --
51
52 sect_kernel_protos = m:section(TypedSection, "kernel", "Kernel options", "Configuration of the kernel protocols. First Instance MUST be Primary table (no table or kernel_table fields).")
53 sect_kernel_protos.addremove = true
54 sect_kernel_protos.anonymous = false
55
56 -- Default kernel parameters
57
58 disabled = sect_kernel_protos:option(Flag, "disabled", "Disabled", "If this option is true, the protocol will not be configured.")
59 disabled.default=0
60
61 -- Optional parameters
62 for _,o in ipairs(protoptions) do
63 if o.name ~= nil then
64 for _, d in ipairs(o.depends) do
65 if d == "kernel" then
66 if o.name == "learn" or o.name == "persist" then
67 value = sect_kernel_protos:option(Flag, o.name, translate(o.name), translate(o.help))
68 elseif o.name == "table" then
69 value = sect_kernel_protos:option(ListValue, o.name, translate(o.name), translate(o.help))
70 uci:foreach("bird6", "table",
71 function (s)
72 value:value(s.name)
73 end)
74 value:value("")
75 value.default = ""
76 else
77 value = sect_kernel_protos:option(Value, o.name, translate(o.name), translate(o.help))
78 end
79 value.optional = true
80 value.rmempty = true
81 end
82 end
83
84 end
85 end
86
87 --
88 -- DEVICE PROTOCOL
89 --
90
91 sect_device_protos = m:section(TypedSection, "device", "Device options", "Configuration of the device protocols.")
92 sect_device_protos.addremove = true
93 sect_device_protos.anonymous = false
94
95 -- Default kernel parameters
96
97 disabled = sect_device_protos:option(Flag, "disabled", "Disabled", "If this option is true, the protocol will not be configured.")
98 disabled.default=0
99
100 -- Optional parameters
101 for _,o in ipairs(protoptions) do
102 if o.name ~= nil then
103 for _, d in ipairs(o.depends) do
104 if d == "device" then
105 value = sect_device_protos:option(Value, o.name, translate(o.name), translate(o.help))
106 value.optional = true
107 value.rmempty = true
108 end
109 end
110 end
111 end
112
113 --
114 -- STATIC PROTOCOL
115 --
116
117 sect_static_protos = m:section(TypedSection, "static", "Static options", "Configuration of the static protocols.")
118 sect_static_protos.addremove = true
119 sect_static_protos.anonymous = false
120
121 -- Default kernel parameters
122
123 disabled = sect_static_protos:option(Flag, "disabled", "Disabled", "If this option is true, the protocol will not be configured.")
124 disabled.default=0
125
126 -- Optional parameters
127 for _,o in ipairs(protoptions) do
128 if o.name ~= nil then
129 for _, d in ipairs(o.depends) do
130 if d == "static" then
131 if o.name == "table" then
132 value = sect_static_protos:option(ListValue, o.name, translate(o.name), translate(o.help))
133 uci:foreach("bird6", "table",
134 function (s)
135 value:value(s.name)
136 end)
137 value:value("")
138 value.default = ""
139 else
140 value = sect_static_protos:option(Value, o.name, translate(o.name), translate(o.help))
141 end
142 value.optional = true
143 value.rmempty = true
144 end
145 end
146 end
147 end
148
149
150 --
151 -- PIPE PROTOCOL
152 --
153 sect_pipe_protos = m:section(TypedSection, "pipe", "Pipe options", "Configuration of the Pipe protocols.")
154 sect_pipe_protos.addremove = true
155 sect_pipe_protos.anonymous = false
156
157 -- Default Pipe parameters
158 disabled = sect_pipe_protos:option(Flag, "disabled", "Disabled", "If this option is true, the protocol will not be configured. This protocol will connect the configured 'Table' to the 'Peer Table'.")
159 disabled.default=0
160
161 table = sect_pipe_protos:option(ListValue, "table", "Table", "Select the Primary Table to connect.")
162 table.optional = false
163 uci:foreach("bird6", "table",
164 function (s)
165 table:value(s.name)
166 end)
167 table:value("")
168 table.default = ""
169
170 peer_table = sect_pipe_protos:option(ListValue, "peer_table", "Peer Table", "Select the Secondary Table to connect.")
171 table.optional = false
172 uci:foreach("bird6", "table",
173 function (s)
174 peer_table:value(s.name)
175 end)
176 peer_table:value("")
177 peer_table.default = ""
178
179 mode = sect_pipe_protos:option(ListValue, "mode", "Mode", "Select <b>transparent</b> to retransmit all routes and their attributes<br />Select <b>opaque</b> to retransmit optimal routes (similar to what other protocols do)")
180 mode.optional = false
181 mode:value("transparent")
182 mode:value("opaque")
183 mode.default = "transparent"
184
185 import = sect_pipe_protos:option(Value, "import", "Import",imp_string)
186 import.optional=true
187
188 export = sect_pipe_protos:option(Value, "export", "Export", exp_string)
189 export.optional=true
190
191
192 --
193 -- DIRECT PROTOCOL
194 --
195 sect_direct_protos = m:section(TypedSection, "direct", "Direct options", "Configuration of the Direct protocols.")
196 sect_direct_protos.addremove = true
197 sect_direct_protos.anonymous = false
198
199 -- Default Direct parameters
200 disabled = sect_direct_protos:option(Flag, "disabled", "Disabled", "If this option is true, the protocol will not be configured. This protocol will connect the configured 'Table' to the 'Peer Table'.")
201 disabled.optional = false
202 disabled.default = 0
203
204 interface = sect_direct_protos:option(Value, "interface", "Interfaces", "By default Direct will generate device routes for all the interfaces. To restrict this behaviour, select a number of patterns to match your desired interfaces:" .. "<br />" .. "1. All the strings <b>MUST</b> be quoted: \"pattern\"" .. "<br />" .. "2. Use * (star) to match patterns: \"eth*\" (<b>include</b> all eth... interfaces)" .. "<br />" .. "3. You can add \"-\" (minus) to exclude patterns: \"-em*\" (<b>exclude</b> all em... interfaces)." .. "<br />" .. "4. Separate several patterns using , (coma): \"-em*\", \"eth*\" (<b>exclude</b> em... and <b>include</b> all eth... interfaces).")
205 interface.optional = false
206 interface.default = "\"*\""
207
208
209 --
210 -- ROUTES FOR STATIC PROTOCOL
211 --
212 sect_routes = m:section(TypedSection, "route", "Routes configuration", "Configuration of the routes used in static protocols.")
213 sect_routes.addremove = true
214 sect_routes.anonymous = true
215
216 instance = sect_routes:option(ListValue, "instance", "Route instance", "")
217 i = 0
218
219 uci:foreach("bird6", "static",
220 function (s)
221 instance:value(s[".name"])
222 end)
223
224 prefix = sect_routes:option(Value, "prefix", "Route prefix", "")
225 prefix.datatype = "ip6prefix"
226
227 type = sect_routes:option(ListValue, "type", "Type of route", "")
228 type:value("router")
229 type:value("special")
230 type:value("iface")
231 type:value("recursive")
232 type:value("multipath")
233
234 valueVia = sect_routes:option(Value, "via", "Via", "")
235 valueVia.optional = false
236 valueVia:depends("type", "router")
237 valueVia.datatype = "ip6addr"
238
239 listVia = sect_routes:option(DynamicList, "l_via", "Via", "")
240 listVia:depends("type", "multipath")
241 listVia.optional=false
242 listVia.datatype = "ip6addr"
243
244 attribute = sect_routes:option(Value, "attribute", "Attribute", "Types are: unreachable, prohibit and blackhole")
245 attribute:depends("type", "special")
246
247 iface = sect_routes:option(ListValue, "iface", "Interface", "")
248 iface:depends("type", "iface")
249
250 uci:foreach("network", "interface",
251 function(section)
252 if section[".name"] ~= "loopback" then
253 iface:value(section[".name"])
254 end
255 end)
256
257 ip = sect_routes:option(Value, "ip", "IP address", "")
258 ip:depends("type", "ip")
259 ip.datatype = [[ or"ip4addr", "ip6addr" ]]
260
261 function m.on_commit(self,map)
262 luci.sys.exec('/etc/init.d/bird6 restart')
263 end
264
265 return m
266