2 Copyright (C) 2014 - Eloi Carbó Solé (GSoC2014)
3 BGP/Bird integration with OpenWRT and QMP
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 local http = require "luci.http"
21 local uci = require "luci.model.uci"
22 local uciout = uci.cursor()
24 m=Map("bird4", "Bird4 general protocol's configuration.")
26 -- Optional parameters lists
28 {["name"]="table", ["help"]="Auxiliar table for routing", ["depends"]={"static","kernel"}},
29 {["name"]="import", ["help"]="Set if the protocol must import routes", ["depends"]={"kernel"}},
30 {["name"]="export", ["help"]="Set if the protocol must export routes", ["depends"]={"kernel"}},
31 {["name"]="scan_time", ["help"]="Time between scans", ["depends"]={"kernel","device"}},
32 {["name"]="kernel_table", ["help"]="Set which table must be used as auxiliar kernel table", ["depends"]={"kernel"}},
33 {["name"]="learn", ["help"]="Learn routes", ["depends"]={"kernel"}},
34 {["name"]="persist", ["help"]="Store routes. After a restart, routes will be still configured", ["depends"]={"kernel"}}
37 local routeroptions = {
38 {["name"]="prefix",["help"]="",["depends"]={"router","special","iface","multipath","recursive"}},
39 {["name"]="via",["help"]="",["depends"]={"router","multipath"}},
40 {["name"]="attribute",["help"]="",["depends"]={"special"}},
41 {["name"]="iface",["help"]="",["depends"]={"iface"}},
42 {["name"]="ip",["help"]="",["depends"]={"recursive"}}
49 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).")
50 sect_kernel_protos.addremove = true
51 sect_kernel_protos.anonymous = false
53 -- Default kernel parameters
55 disabled = sect_kernel_protos:option(Flag, "disabled", "Disabled", "If this option is true, the protocol will not be configured.")
58 -- Optional parameters
59 for _,o in ipairs(protoptions) do
61 for _, d in ipairs(o.depends) do
63 if o.name == "learn" or o.name == "persist" then
64 value = sect_kernel_protos:option(Flag, o.name, translate(o.name), translate(o.help))
65 elseif o.name == "table" then
66 value = sect_kernel_protos:option(ListValue, o.name, translate(o.name), translate(o.help))
67 uciout:foreach("bird4", "table",
73 value = sect_kernel_protos:option(Value, o.name, translate(o.name), translate(o.help))
87 sect_device_protos = m:section(TypedSection, "device", "Device options", "Configuration of the device protocols.")
88 sect_device_protos.addremove = true
89 sect_device_protos.anonymous = false
91 -- Default kernel parameters
93 disabled = sect_device_protos:option(Flag, "disabled", "Disabled", "If this option is true, the protocol will not be configured.")
96 -- Optional parameters
97 for _,o in ipairs(protoptions) do
99 for _, d in ipairs(o.depends) do
100 if d == "device" then
101 value = sect_device_protos:option(Value, o.name, translate(o.name), translate(o.help))
102 value.optional = true
113 sect_static_protos = m:section(TypedSection, "static", "Static options", "Configuration of the static protocols.")
114 sect_static_protos.addremove = true
115 sect_static_protos.anonymous = false
117 -- Default kernel parameters
119 disabled = sect_static_protos:option(Flag, "disabled", "Disabled", "If this option is true, the protocol will not be configured.")
122 -- Optional parameters
123 for _,o in ipairs(protoptions) do
124 if o.name ~= nil then
125 for _, d in ipairs(o.depends) do
126 if d == "static" then
127 if o.name == "table" then
128 value = sect_static_protos:option(ListValue, o.name, translate(o.name), translate(o.help))
129 uciout:foreach("bird4", "table",
135 value = sect_static_protos:option(Value, o.name, translate(o.name), translate(o.help))
137 value.optional = true
145 -- ROUTES FOR STATIC PROTOCOL
149 sect_routes = m:section(TypedSection, "route", "Routes configuration", "Configuration of the routes used in static protocols.")
150 sect_routes.addremove = true
151 sect_routes.anonymous = true
153 instance = sect_routes:option(ListValue, "instance", "Route instance", "")
156 uciout:foreach("bird4", "static",
158 instance:value(s[".name"])
161 prefix = sect_routes:option(Value, "prefix", "Route prefix", "")
163 type = sect_routes:option(ListValue, "type", "Type of route", "")
165 type:value("special")
167 type:value("recursive")
168 type:value("multipath")
170 valueVia = sect_routes:option(Value, "via", "Via", "")
171 valueVia.optional = false
172 valueVia:depends("type", "router")
173 valueVia.datatype = "ip4addr"
175 listVia = sect_routes:option(DynamicList, "l_via", "Via", "")
176 listVia:depends("type", "multipath")
177 listVia.optional=false
178 listVia.datatype = "ip4addr"
180 attribute = sect_routes:option(Value, "attribute", "Attribute", "Types are: unreachable, prohibit and blackhole")
181 attribute:depends("type", "special")
183 iface = sect_routes:option(ListValue, "iface", "Interface", "")
184 iface:depends("type", "iface")
186 uciout:foreach("wireless", "wifi-iface",
188 iface:value(section[".name"])
191 ip = sect_routes:option(Value, "ip", "IP address", "")
192 ip:depends("type", "ip")
193 ip.datatype = [[ or"ip4addr", "ip6addr" ]]
195 function m.on_commit(self,map)
196 luci.sys.call('/etc/init.d/bird4 stop; /etc/init.d/bird4 start')