2 Copyright (C) 2014-2017 - Eloi Carbo
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.
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.
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/>.
19 local http = require "luci.http"
20 local uci = luci.model.uci.cursor()
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
27 m=Map("bird4", "Bird4 general protocol's configuration.")
29 -- Optional parameters lists
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"}}
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"}}
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
56 -- Default kernel parameters
57 disabled = sect_kernel_protos:option(Flag, "disabled", "Disabled", "If this option is true, the protocol will not be configured.")
60 -- Optional parameters
61 for _,o in ipairs(protoptions) do
63 for _, d in ipairs(o.depends) do
65 if o.name == "learn" or o.name == "persist" then
66 value = sect_kernel_protos:option(Flag, o.name, translate(o.name), translate(o.help))
67 elseif o.name == "table" then
68 value = sect_kernel_protos:option(ListValue, o.name, translate(o.name), translate(o.help))
69 uci:foreach("bird4", "table",
76 value = sect_kernel_protos:option(Value, o.name, translate(o.name), translate(o.help))
90 sect_device_protos = m:section(TypedSection, "device", "Device options", "Configuration of the device protocols.")
91 sect_device_protos.addremove = true
92 sect_device_protos.anonymous = false
94 -- Default kernel parameters
96 disabled = sect_device_protos:option(Flag, "disabled", "Disabled", "If this option is true, the protocol will not be configured.")
99 -- Optional parameters
100 for _,o in ipairs(protoptions) do
101 if o.name ~= nil then
102 for _, d in ipairs(o.depends) do
103 if d == "device" then
104 value = sect_device_protos:option(Value, o.name, translate(o.name), translate(o.help))
105 value.optional = true
116 sect_pipe_protos = m:section(TypedSection, "pipe", "Pipe options", "Configuration of the Pipe protocols.")
117 sect_pipe_protos.addremove = true
118 sect_pipe_protos.anonymous = false
120 -- Default Pipe parameters
121 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'.")
124 table = sect_pipe_protos:option(ListValue, "table", "Table", "Select the Primary Table to connect.")
125 table.optional = false
126 uci:foreach("bird4", "table",
133 peer_table = sect_pipe_protos:option(ListValue, "peer_table", "Peer Table", "Select the Secondary Table to connect.")
134 table.optional = false
135 uci:foreach("bird4", "table",
137 peer_table:value(s.name)
140 peer_table.default = ""
142 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)")
143 mode.optional = false
144 mode:value("transparent")
146 mode.default = "transparent"
148 import = sect_pipe_protos:option(Value, "import", "Import",imp_string)
151 export = sect_pipe_protos:option(Value, "export", "Export", exp_string)
158 sect_direct_protos = m:section(TypedSection, "direct", "Direct options", "Configuration of the Direct protocols.")
159 sect_direct_protos.addremove = true
160 sect_direct_protos.anonymous = false
162 -- Default Direct parameters
163 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'.")
164 disabled.optional = false
167 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).")
168 interface.optional = false
169 interface.default = "\"*\""
175 sect_static_protos = m:section(TypedSection, "static", "Static options", "Configuration of the static protocols.")
176 sect_static_protos.addremove = true
177 sect_static_protos.anonymous = false
179 -- Default kernel parameters
180 disabled = sect_static_protos:option(Flag, "disabled", "Disabled", "If this option is true, the protocol will not be configured.")
183 -- Optional parameters
184 for _,o in ipairs(protoptions) do
185 if o.name ~= nil then
186 for _, d in ipairs(o.depends) do
187 if d == "static" then
188 if o.name == "table" then
189 value = sect_static_protos:option(ListValue, o.name, translate(o.name), translate(o.help))
190 uci:foreach("bird4", "table",
197 value = sect_static_protos:option(Value, o.name, translate(o.name), translate(o.help))
199 value.optional = true
208 -- ROUTES FOR STATIC PROTOCOL
210 sect_routes = m:section(TypedSection, "route", "Routes configuration", "Configuration of the routes used in static protocols.")
211 sect_routes.addremove = true
212 sect_routes.anonymous = true
214 instance = sect_routes:option(ListValue, "instance", "Route instance", "")
216 uci:foreach("bird4", "static",
218 instance:value(s[".name"])
221 prefix = sect_routes:option(Value, "prefix", "Route prefix", "")
223 type = sect_routes:option(ListValue, "type", "Type of route", "")
225 type:value("special")
227 type:value("recursive")
228 type:value("multipath")
230 valueVia = sect_routes:option(Value, "via", "Via", "")
231 valueVia.optional = false
232 valueVia:depends("type", "router")
233 valueVia.datatype = "ip4addr"
235 listVia = sect_routes:option(DynamicList, "l_via", "Via", "")
236 listVia:depends("type", "multipath")
237 listVia.optional=false
238 listVia.datatype = "ip4addr"
240 attribute = sect_routes:option(ListValue, "attribute", "Attribute", "")
241 attribute:depends("type", "special")
242 attribute:value("unreachable")
243 attribute:value("prohibit")
244 attribute:value("blackhole")
246 iface = sect_routes:option(ListValue, "iface", "Interface", "")
247 iface:depends("type", "iface")
248 uci:foreach("network", "interface",
250 if section[".name"] ~= "loopback" then
251 iface:value(section[".name"])
255 ip = sect_routes:option(Value, "ip", "IP address", "")
256 ip:depends("type", "ip")
257 ip.datatype = [[ or"ip4addr", "ip6addr" ]]
259 function m.on_commit(self,map)
260 luci.sys.exec('/etc/init.d/bird4 restart')