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 BGP protocol's configuration")
30 uci:foreach('bird6', '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 description = sect_templates:option(TextValue, "description", "Description", "Description of the current BGP instance")
48 description.optional = true
50 table = sect_templates:option(ListValue, "table", "Table", "Set the table used for BGP Routing")
52 uci:foreach("bird6", "table",
59 igp_table = sect_templates:option(ListValue, "igp_table", "IGP Table", "Select the IGP Routing Table to use. Hint: usually the same table as BGP.")
60 igp_table.optional = true
61 uci:foreach("bird6", "table",
63 igp_table:value(s.name)
66 igp_table.default = ""
68 import = sect_templates:option(Value, "import", "Import", imp_string)
71 export = sect_templates:option(Value, "export", "Export", exp_string)
74 source_addr = sect_templates:option(Value, "source_address", "Source Address", "Source address for BGP routing. By default uses Router ID")
75 source_addr.optional = true
77 local_address = sect_templates:option(Value, "local_address", "Local BGP address", "")
78 local_address.optional = false
80 local_as = sect_templates:option(Value, "local_as", "Local AS", "")
81 local_as.optional = false
83 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")
84 next_hop_self.default = nil
85 next_hop_self.optional = true
87 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")
88 next_hop_keep.default = nil
89 next_hop_keep.optional = true
91 rr_client = sect_templates:option(Flag, "rr_client", "Route Reflector server", "This router serves as a Route Reflector server and treats neighbors as clients")
92 rr_client.default = nil
93 rr_client.optional = true
95 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")
96 rr_cluster_id.optional = true
98 import_trigger = sect_templates:option(Flag, "import_trigger", "Import Limit", "Enable Routes Import limit settings")
99 import_trigger.default = 0
100 import_trigger.rmempty = false
101 import_trigger.optional = false
103 import_limit = sect_templates:option(Value, "import_limit", "Routes import limit", "Specify an import route limit.")
104 import_limit:depends({import_trigger = "1"})
105 import_limit.rmempty = true
107 import_limit_action = sect_templates:option(ListValue, "import_limit_action", "Routes import limit action", "Action to take when import routes limit ir reached")
108 import_limit_action:depends({import_trigger = "1"})
109 import_limit_action:value("warn")
110 import_limit_action:value("block")
111 import_limit_action:value("disable")
112 import_limit_action:value("restart")
113 import_limit_action.default = "warn"
114 import_limit_action.rmempty = true
116 export_trigger = sect_templates:option(Flag, "export_trigger", "Export Limit", "Enable Routes Export limit settings")
117 export_trigger.default = 0
118 export_trigger.rmempty = false
119 export_trigger.optional = false
121 export_limit = sect_templates:option(Value, "export_limit", "Routes export limit", "Specify an export route limit.")
122 export_limit:depends({export_trigger = "1"})
123 export_limit.rmempty = true
125 export_limit_action = sect_templates:option(ListValue, "export_limit_action", "Routes export limit action", "Action to take when export routes limit is reached")
126 export_limit_action:depends({export_trigger = "1"})
127 export_limit_action.rmempty = true
128 export_limit_action:value("warn")
129 export_limit_action:value("block")
130 export_limit_action:value("disable")
131 export_limit_action:value("restart")
132 export_limit_action.default = "warn"
134 receive_trigger = sect_templates:option(Flag, "receive_trigger", "Received Limit", "Enable Routes Received Limit settings")
135 receive_trigger.default = 0
136 receive_trigger.rmempty = false
137 receive_trigger.optional = false
139 receive_limit = sect_templates:option(Value, "receive_limit", "Routes received limit", "Specify a received route limit.")
140 receive_limit:depends({receive_trigger = "1"})
141 receive_limit.rmempty = true
143 receive_limit_action = sect_templates:option(ListValue, "receive_limit_action", "Routes received limit action", "Action to take when received routes limit is reached")
144 receive_limit_action:depends({receive_trigger = "1"})
145 receive_limit_action:value("warn")
146 receive_limit_action:value("block")
147 receive_limit_action:value("disable")
148 receive_limit_action:value("restart")
149 receive_limit_action.default = "warn"
150 receive_limit_action.rmempty= true
155 sect_instances = m:section(TypedSection, "bgp", "BGP Instances", "Configuration of the BGP protocol instances")
156 sect_instances.addremove = true
157 sect_instances.anonymous = false
159 templates = sect_instances:option(ListValue, "template", "Templates", "Available BGP templates")
160 uci:foreach("bird6", "bgp_template",
162 templates:value(s[".name"])
166 disabled = sect_instances:option(Flag, "disabled", "Disabled", "Enable/Disable BGP Protocol")
167 disabled.optional = false
168 disabled.rmempty = false
169 disabled.default = nil
171 description = sect_instances:option(TextValue, "description", "Description", "Description of the current BGP instance")
172 description.optional = true
174 table = sect_instances:option(ListValue, "table", "Table", "Set the table used for BGP Routing")
176 uci:foreach("bird6", "table",
183 igp_table = sect_instances:option(ListValue, "igp_table", "IGP Table", "Select the IGP Routing Table to use. Hint: usually the same table as BGP.")
184 igp_table.optional = true
185 uci:foreach("bird6", "table",
187 igp_table:value(s.name)
190 igp_table.default = ""
192 import = sect_instances:option(Value, "import", "Import", imp_string)
195 export = sect_instances:option(Value, "export", "Export", exp_string)
198 source_address = sect_instances:option(Value, "source_address", "Source Address", "Source address for BGP routing. By default uses Router ID")
199 source_address.optional = true
201 local_address = sect_instances:option(Value, "local_address", "Local BGP address", "")
202 local_address.optional=true
204 local_as = sect_instances:option(Value, "local_as", "Local AS", "")
205 local_as.optional=true
207 neighbor_address = sect_instances:option(Value, "neighbor_address", "Neighbor IP Address", "")
208 neighbor_address.optional = false
210 neighbor_as = sect_instances:option(Value, "neighbor_as", "Neighbor AS", "")
211 neighbor_as.optional = false
213 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")
214 next_hop_self.default = nil
215 next_hop_self.optional = true
217 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")
218 next_hop_keep.default = nil
219 next_hop_keep.optional = true
221 rr_client = sect_instances:option(Flag, "rr_client", "Route Reflector server", "This router serves as a Route Reflector server and treats neighbors as clients")
222 rr_client.default = nil
223 rr_client.optional = true
225 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")
226 rr_cluster_id.optional = true
228 import_trigger = sect_instances:option(Flag, "import_trigger", "Import Limit", "Enable Routes Import limit settings")
229 import_trigger.default = 0
230 import_trigger.rmempty = false
231 import_trigger.optional = false
233 import_limit = sect_instances:option(Value, "import_limit", "Routes import limit", "Specify an import route limit.")
234 import_limit:depends({import_trigger = "1"})
235 import_limit.rmempty = true
237 import_limit_action = sect_instances:option(ListValue, "import_limit_action", "Routes import limit action", "Action to take when import routes limit ir reached")
238 import_limit_action:depends({import_trigger = "1"})
239 import_limit_action:value("warn")
240 import_limit_action:value("block")
241 import_limit_action:value("disable")
242 import_limit_action:value("restart")
243 import_limit_action.default = "warn"
244 import_limit_action.rmempty = true
246 export_trigger = sect_instances:option(Flag, "export_trigger", "Export Limit", "Enable Routes Export limit settings")
247 export_trigger.default = 0
248 export_trigger.rmempty = false
249 export_trigger.optional = false
251 export_limit = sect_instances:option(Value, "export_limit", "Routes export limit", "Specify an export route limit.")
252 export_limit:depends({export_trigger = "1"})
253 export_limit.rmempty = true
255 export_limit_action = sect_instances:option(ListValue, "export_limit_action", "Routes export limit action", "Action to take when export routes limit is reached")
256 export_limit_action:depends({export_trigger = "1"})
257 export_limit_action.rmempty = true
258 export_limit_action:value("warn")
259 export_limit_action:value("block")
260 export_limit_action:value("disable")
261 export_limit_action:value("restart")
262 export_limit_action.default = "warn"
264 receive_trigger = sect_instances:option(Flag, "receive_trigger", "Received Limit", "Enable Routes Received Limit settings")
265 receive_trigger.default = 0
266 receive_trigger.rmempty = false
267 receive_trigger.optional = false
269 receive_limit = sect_instances:option(Value, "receive_limit", "Routes received limit", "Specify a received route limit.")
270 receive_limit:depends({receive_trigger = "1"})
271 receive_limit.rmempty = true
273 receive_limit_action = sect_instances:option(ListValue, "receive_limit_action", "Routes received limit action", "Action to take when received routes limit is reached")
274 receive_limit_action:depends({receive_trigger = "1"})
275 receive_limit_action:value("warn")
276 receive_limit_action:value("block")
277 receive_limit_action:value("disable")
278 receive_limit_action:value("restart")
279 receive_limit_action.default = "warn"
280 receive_limit_action.rmempty= true
282 function m.on_commit(self,map)
283 luci.sys.exec('/etc/init.d/bird6 restart')