bird: Rename to bird1 and bump to v1.6.4
[feed/routing.git] / bird1-openwrt / bird1-ipv4-openwrt / src / model / bgp_proto.lua
1 --[[
2 Copyright (C) 2014-2017 - Eloi Carbo
3
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.
8
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.
13
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/>.
16 --]]
17
18 require("luci.sys")
19 local http = require "luci.http"
20 local uci = luci.model.uci.cursor()
21
22 -- Repeated Strings
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
26
27 m=Map("bird4", "Bird4 BGP protocol's configuration")
28
29 tab_templates = {}
30 uci:foreach('bird4', 'bgp_template', function (s)
31 local name = s[".name"]
32 if (name ~= nil) then
33 table.insert(tab_templates, name)
34 end
35 end)
36
37 --
38 -- BGP TEMPLATES
39 --
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
43
44 disabled = sect_templates:option(Flag, "disabled", "Disabled", "Enable/Disable BGP Protocol")
45 disabled.optional=true
46
47 table = sect_templates:option(ListValue, "table", "Table", "Set the table used for BGP Routing")
48 table.optional=true
49 uci:foreach("bird4", "table",
50 function (s)
51 table:value(s.name)
52 end)
53 table:value("")
54 table.default = ""
55
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",
59 function(s)
60 igp_table:value(s.name)
61 end)
62 igp_table:value("")
63 igp_table.default = ""
64
65 import = sect_templates:option(Value, "import", "Import", imp_string)
66 import.optional=true
67
68 export = sect_templates:option(Value, "export", "Export", exp_string)
69 export.optional=true
70
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
73
74 local_as = sect_templates:option(Value, "local_as", "Local AS", "")
75 local_as.optional = false
76
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
80
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
84
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
88
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
91
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
96
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
100
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
109
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
114
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
118
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"
127
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
132
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
136
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
145
146 --
147 -- BGP INSTANCES
148 --
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
152
153 disabled = sect_instances:option(Flag, "disabled", "Disabled", "Enable/Disable BGP Protocol")
154 disabled.optional = false
155 disabled.rmempty = false
156 disabled.default = nil
157
158 templates = sect_instances:option(ListValue, "template", "Templates", "Available BGP templates")
159 uci:foreach("bird4", "bgp_template",
160 function(s)
161 templates:value(s[".name"])
162 end)
163 templates:value("")
164
165 description = sect_instances:option(TextValue, "description", "Description", "Description of the current BGP instance")
166 description.optional = true
167
168 table = sect_instances:option(ListValue, "table", "Table", "Set the table used for BGP Routing")
169 table.optional=true
170 uci:foreach("bird4", "table",
171 function (s)
172 table:value(s.name)
173 end)
174 table:value("")
175 table.default = ""
176
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",
180 function(s)
181 igp_table:value(s.name)
182 end)
183 igp_table:value("")
184 igp_table.default = ""
185
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
190
191 import = sect_instances:option(Value, "import", "Import", imp_string)
192 import.optional=true
193
194 export = sect_instances:option(Value, "export", "Export", exp_string)
195 export.optional=true
196
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
199
200 local_as = sect_instances:option(Value, "local_as", "Local AS", "")
201 local_as.optional=true
202
203 neighbor_address = sect_instances:option(Value, "neighbor_address", "Neighbor IP Address", "")
204 neighbor_address.optional = false
205
206 neighbor_as = sect_instances:option(Value, "neighbor_as", "Neighbor AS", "")
207 neighbor_as.optional = false
208
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
212
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
216
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
220
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
223
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
228
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
232
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
241
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
246
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
250
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
259
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
264
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
268
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
277
278
279 function m.on_commit(self,map)
280 luci.sys.exec('/etc/init.d/bird4 restart')
281 end
282 return m