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("bird6", "Bird6 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
58 disabled = sect_kernel_protos:option(Flag, "disabled", "Disabled", "If this option is true, the protocol will not be configured.")
61 -- Optional parameters
62 for _,o in ipairs(protoptions) do
64 for _, d in ipairs(o.depends) do
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",
77 value = sect_kernel_protos:option(Value, o.name, translate(o.name), translate(o.help))
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
95 -- Default kernel parameters
97 disabled = sect_device_protos:option(Flag, "disabled", "Disabled", "If this option is true, the protocol will not be configured.")
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
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
121 -- Default kernel parameters
123 disabled = sect_static_protos:option(Flag, "disabled", "Disabled", "If this option is true, the protocol will not be configured.")
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",
140 value = sect_static_protos:option(Value, o.name, translate(o.name), translate(o.help))
142 value.optional = true
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
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'.")
161 table = sect_pipe_protos:option(ListValue, "table", "Table", "Select the Primary Table to connect.")
162 table.optional = false
163 uci:foreach("bird6", "table",
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",
174 peer_table:value(s.name)
177 peer_table.default = ""
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")
183 mode.default = "transparent"
185 import = sect_pipe_protos:option(Value, "import", "Import",imp_string)
188 export = sect_pipe_protos:option(Value, "export", "Export", exp_string)
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
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
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 = "\"*\""
210 -- ROUTES FOR STATIC PROTOCOL
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
216 instance = sect_routes:option(ListValue, "instance", "Route instance", "")
219 uci:foreach("bird6", "static",
221 instance:value(s[".name"])
224 prefix = sect_routes:option(Value, "prefix", "Route prefix", "")
225 prefix.datatype = "ip6prefix"
227 type = sect_routes:option(ListValue, "type", "Type of route", "")
229 type:value("special")
231 type:value("recursive")
232 type:value("multipath")
234 valueVia = sect_routes:option(Value, "via", "Via", "")
235 valueVia.optional = false
236 valueVia:depends("type", "router")
237 valueVia.datatype = "ip6addr"
239 listVia = sect_routes:option(DynamicList, "l_via", "Via", "")
240 listVia:depends("type", "multipath")
241 listVia.optional=false
242 listVia.datatype = "ip6addr"
244 attribute = sect_routes:option(Value, "attribute", "Attribute", "Types are: unreachable, prohibit and blackhole")
245 attribute:depends("type", "special")
247 iface = sect_routes:option(ListValue, "iface", "Interface", "")
248 iface:depends("type", "iface")
250 uci:foreach("network", "interface",
252 if section[".name"] ~= "loopback" then
253 iface:value(section[".name"])
257 ip = sect_routes:option(Value, "ip", "IP address", "")
258 ip:depends("type", "ip")
259 ip.datatype = [[ or"ip4addr", "ip6addr" ]]
261 function m.on_commit(self,map)
262 luci.sys.exec('/etc/init.d/bird6 restart')