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 BGP protocol's configuration")
30 uci:foreach('bird4', 'bgp_template', function (s)
31 local name = s[".name"]
33 table.insert(tab_templates, name)
40 sect_templates = m:section(TypedSection, "bgp_template", "BGP Templates", "Configuration of the templates used in BGP instances.")
41 sect_templates.addremove = true
42 sect_templates.anonymous = false
44 disabled = sect_templates:option(Flag, "disabled", "Disabled", "Enable/Disable BGP Protocol")
45 disabled.optional=true
47 table = sect_templates:option(ListValue, "table", "Table", "Set the table used for BGP Routing")
49 uci:foreach("bird4", "table",
56 igp_table = sect_templates:option(ListValue, "igp_table", "IGP Table", "Select the IGP Routing Table to use. Hint: usually the same table as BGP.")
57 igp_table.optional = true
58 uci:foreach("bird4", "table",
60 igp_table:value(s.name)
63 igp_table.default = ""
65 import = sect_templates:option(Value, "import", "Import", imp_string)
68 export = sect_templates:option(Value, "export", "Export", exp_string)
71 source_addr = sect_templates:option(Value, "source_address", "Source Address", "Source address for BGP routing. By default uses Router ID")
72 source_addr.optional = true
74 local_as = sect_templates:option(Value, "local_as", "Local AS", "")
75 local_as.optional = false
77 next_hop_self = sect_templates:option(Flag, "next_hop_self", "Next hop self", "Avoid next hop calculation and advertise own source address as next hop")
78 next_hop_self.default = nil
79 next_hop_self.optional = true
81 next_hop_keep = sect_templates:option(Flag, "next_hop_keep", "Next hop keep", "Forward the received Next Hop attribute event in situations where the local address should be used instead, like subneting")
82 next_hop_keep.default = nil
83 next_hop_keep.optional = true
85 rr_client = sect_templates:option(Flag, "rr_client", "Route Reflector server", "This router serves as a Route Reflector server and treats neighbors as clients")
86 rr_client.default = nil
87 rr_client.optional = true
89 rr_cluster_id = sect_templates:option(Value, "rr_cluster_id", "Route Reflector Cluster ID", "Identificator of the RR cluster. By default uses the Router ID")
90 rr_cluster_id.optional = true
92 import_trigger = sect_templates:option(Flag, "import_trigger", "Import Limit", "Enable Routes Import limit settings")
93 import_trigger.default = 0
94 import_trigger.rmempty = false
95 import_trigger.optional = false
97 import_limit = sect_templates:option(Value, "import_limit", "Routes import limit", "Specify an import route limit.")
98 import_limit:depends({import_trigger = "1"})
99 import_limit.rmempty = true
101 import_limit_action = sect_templates:option(ListValue, "import_limit_action", "Routes import limit action", "Action to take when import routes limit ir reached")
102 import_limit_action:depends({import_trigger = "1"})
103 import_limit_action:value("warn")
104 import_limit_action:value("block")
105 import_limit_action:value("disable")
106 import_limit_action:value("restart")
107 import_limit_action.default = "warn"
108 import_limit_action.rmempty = true
110 export_trigger = sect_templates:option(Flag, "export_trigger", "Export Limit", "Enable Routes Export limit settings")
111 export_trigger.default = 0
112 export_trigger.rmempty = false
113 export_trigger.optional = false
115 export_limit = sect_templates:option(Value, "export_limit", "Routes export limit", "Specify an export route limit.")
116 export_limit:depends({export_trigger = "1"})
117 export_limit.rmempty = true
119 export_limit_action = sect_templates:option(ListValue, "export_limit_action", "Routes export limit action", "Action to take when export routes limit is reached")
120 export_limit_action:depends({export_trigger = "1"})
121 export_limit_action.rmempty = true
122 export_limit_action:value("warn")
123 export_limit_action:value("block")
124 export_limit_action:value("disable")
125 export_limit_action:value("restart")
126 export_limit_action.default = "warn"
128 receive_trigger = sect_templates:option(Flag, "receive_trigger", "Received Limit", "Enable Routes Received Limit settings")
129 receive_trigger.default = 0
130 receive_trigger.rmempty = false
131 receive_trigger.optional = false
133 receive_limit = sect_templates:option(Value, "receive_limit", "Routes received limit", "Specify a received route limit.")
134 receive_limit:depends({receive_trigger = "1"})
135 receive_limit.rmempty = true
137 receive_limit_action = sect_templates:option(ListValue, "receive_limit_action", "Routes received limit action", "Action to take when received routes limit is reached")
138 receive_limit_action:depends({receive_trigger = "1"})
139 receive_limit_action:value("warn")
140 receive_limit_action:value("block")
141 receive_limit_action:value("disable")
142 receive_limit_action:value("restart")
143 receive_limit_action.default = "warn"
144 receive_limit_action.rmempty= true
149 sect_instances = m:section(TypedSection, "bgp", "BGP Instances", "Configuration of the BGP protocol instances")
150 sect_instances.addremove = true
151 sect_instances.anonymous = false
153 disabled = sect_instances:option(Flag, "disabled", "Disabled", "Enable/Disable BGP Protocol")
154 disabled.optional = false
155 disabled.rmempty = false
156 disabled.default = nil
158 templates = sect_instances:option(ListValue, "template", "Templates", "Available BGP templates")
159 uci:foreach("bird4", "bgp_template",
161 templates:value(s[".name"])
165 description = sect_instances:option(TextValue, "description", "Description", "Description of the current BGP instance")
166 description.optional = true
168 table = sect_instances:option(ListValue, "table", "Table", "Set the table used for BGP Routing")
170 uci:foreach("bird4", "table",
177 igp_table = sect_instances:option(ListValue, "igp_table", "IGP Table", "Select the IGP Routing Table to use. Hint: usually the same table as BGP.")
178 igp_table.optional = true
179 uci:foreach("bird4", "table",
181 igp_table:value(s.name)
184 igp_table.default = ""
186 passive = sect_instances:option(Flag, "passive", "Passive", "Disable automatic initialization of outgoing connections.")
187 passive.optional=true
188 passive.rmempty = false
189 passive.default = nil
191 import = sect_instances:option(Value, "import", "Import", imp_string)
194 export = sect_instances:option(Value, "export", "Export", exp_string)
197 source_address = sect_instances:option(Value, "source_address", "Source Address", "Source address for BGP routing. By default uses Router ID")
198 source_address.optional = true
200 local_as = sect_instances:option(Value, "local_as", "Local AS", "")
201 local_as.optional=true
203 neighbor_address = sect_instances:option(Value, "neighbor_address", "Neighbor IP Address", "")
204 neighbor_address.optional = false
206 neighbor_as = sect_instances:option(Value, "neighbor_as", "Neighbor AS", "")
207 neighbor_as.optional = false
209 next_hop_self = sect_instances:option(Flag, "next_hop_self", "Next hop self", "Avoid next hop calculation and advertise own source address as next hop")
210 next_hop_self.default = nil
211 next_hop_self.optional = true
213 next_hop_keep = sect_instances:option(Flag, "next_hop_keep", "Next hop keep", "Forward the received Next Hop attribute event in situations where the local address should be used instead, like subneting")
214 next_hop_keep.default = nil
215 next_hop_keep.optional = true
217 rr_client = sect_instances:option(Flag, "rr_client", "Route Reflector server", "This router serves as a Route Reflector server and treats neighbors as clients")
218 rr_client.default = nil
219 rr_client.optional = true
221 rr_cluster_id = sect_instances:option(Value, "rr_cluster_id", "Route Reflector Cluster ID", "Identificator of the RR cluster. By default uses the Router ID")
222 rr_cluster_id.optional = true
224 import_trigger = sect_instances:option(Flag, "import_trigger", "Import Limit", "Enable Routes Import limit settings")
225 import_trigger.default = 0
226 import_trigger.rmempty = false
227 import_trigger.optional = false
229 import_limit = sect_instances:option(Value, "import_limit", "Routes import limit", "Specify an import route limit.")
230 import_limit:depends({import_trigger = "1"})
231 import_limit.rmempty = true
233 import_limit_action = sect_instances:option(ListValue, "import_limit_action", "Routes import limit action", "Action to take when import routes limit ir reached")
234 import_limit_action:depends({import_trigger = "1"})
235 import_limit_action:value("warn")
236 import_limit_action:value("block")
237 import_limit_action:value("disable")
238 import_limit_action:value("restart")
239 import_limit_action.default = "warn"
240 import_limit_action.rmempty = true
242 export_trigger = sect_instances:option(Flag, "export_trigger", "Export Limit", "Enable Routes Export limit settings")
243 export_trigger.default = 0
244 export_trigger.rmempty = false
245 export_trigger.optional = false
247 export_limit = sect_instances:option(Value, "export_limit", "Routes export limit", "Specify an export route limit.")
248 export_limit:depends({export_trigger = "1"})
249 export_limit.rmempty = true
251 export_limit_action = sect_instances:option(ListValue, "export_limit_action", "Routes export limit action", "Action to take when export routes limit is reached")
252 export_limit_action:depends({export_trigger = "1"})
253 export_limit_action:value("warn")
254 export_limit_action:value("block")
255 export_limit_action:value("disable")
256 export_limit_action:value("restart")
257 export_limit_action.default = "warn"
258 export_limit_action.rmempty= true
260 receive_trigger = sect_instances:option(Flag, "receive_trigger", "Received Limit", "Enable Routes Received Limit settings")
261 receive_trigger.default = 0
262 receive_trigger.rmempty = false
263 receive_trigger.optional = false
265 receive_limit = sect_instances:option(Value, "receive_limit", "Routes received limit", "Specify a received route limit.")
266 receive_limit:depends({receive_trigger = "1"})
267 receive_limit.rmempty = true
269 receive_limit_action = sect_instances:option(ListValue, "receive_limit_action", "Routes received limit action", "Action to take when received routes limit is reached")
270 receive_limit_action:depends({receive_trigger = "1"})
271 receive_limit_action:value("warn")
272 receive_limit_action:value("block")
273 receive_limit_action:value("disable")
274 receive_limit_action:value("restart")
275 receive_limit_action.default = "warn"
276 receive_limit_action.rmempty= true
279 function m.on_commit(self,map)
280 luci.sys.exec('/etc/init.d/bird4 restart')