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("bird6", "Bird6 BGP protocol's configuration")
27 uciout:foreach('bird6', 'bgp_template', function (s)
28 local name = s[".name"]
30 table.insert(tab_templates, name)
34 -- Section BGP Templates
36 sect_templates = m:section(TypedSection, "bgp_template", "BGP Templates", "Configuration of the templates used in BGP instances.")
37 sect_templates.addremove = true
38 sect_templates.anonymous = false
40 disabled = sect_templates:option(Flag, "disabled", "Disabled", "Enable/Disable BGP Protocol")
41 disabled.optional=true
42 table = sect_templates:option(ListValue, "table", "Table", "Set the table used for BGP Routing")
44 uciout:foreach("bird6", "table",
50 import = sect_templates:option(Value, "import", "Import","")
52 export = sect_templates:option(Value, "export", "Export", "")
55 source_addr = sect_templates:option(Value, "source_address", "Source Address", "Source address for BGP routing. By default uses Router ID")
56 source_addr.optional = true
58 description = sect_templates:option(TextValue, "description", "Description", "Description of the current BGP instance")
59 description.optional = true
61 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")
62 next_hop_self.default = nil
63 next_hop_self.optional = true
65 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")
66 next_hop_keep.default = nil
67 next_hop_keep.optional = true
69 rr_client = sect_templates:option(Flag, "rr_client", "Route Reflector server", "This router serves as a Route Reflector server and treats neighbors as clients")
70 rr_client.default = nil
71 rr_client.optional = true
73 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")
74 rr_cluster_id.optional = true
76 import_limit = sect_templates:option(Value, "import_limit", "Routes import limit", "Specify an import route limit. By default is disabled '0'")
77 import_limit.default= "0"
78 import_limit.optional = true
80 import_limit_action = sect_templates:option(ListValue, "import_limit_action", "Routes import limit action", "Action to take when import routes limit ir reached")
81 import_limit_action:value("warn")
82 import_limit_action:value("block")
83 import_limit_action:value("disable")
84 import_limit_action:value("restart")
85 import_limit_action.default = "warn"
86 import_limit_action.optional = true
88 export_limit = sect_templates:option(Value, "export_limit", "Routes export limit", "Specify an export route limit. By default is disabled '0'")
89 export_limit.default="0"
90 export_limit.optional = true
92 export_limit_action = sect_templates:option(ListValue, "export_limit_action", "Routes export limit action", "Action to take when export routes limit is reached")
93 export_limit_action:value("warn")
94 export_limit_action:value("block")
95 export_limit_action:value("disable")
96 export_limit_action:value("restart")
97 export_limit_action.default = "warn"
98 export_limit_action.optional = true
100 receive_limit = sect_templates:option(Value, "receive_limit", "Routes received limit", "Specify a received route limit. By default is disabled '0'")
101 receive_limit.default="0"
102 receive_limit.optional = true
104 receive_limit_action = sect_templates:option(ListValue, "receive_limit_action", "Routes received limit action", "Action to take when received routes limit is reached")
105 receive_limit_action:value("warn")
106 receive_limit_action:value("block")
107 receive_limit_action:value("disable")
108 receive_limit_action:value("restart")
109 receive_limit_action.default = "warn"
110 receive_limit_action.optional = true
112 local_address = sect_templates:option(Value, "local_address", "Local BGP address", "")
113 local_address.optional=true
114 local_as = sect_templates:option(Value, "local_as", "Local AS", "")
115 local_as.optional=true
117 -- Section BGP Instances:
119 sect_instances = m:section(TypedSection, "bgp", "BGP Instances", "Configuration of the BGP protocol instances")
120 sect_instances.addremove = true
121 sect_instances.anonymous = false
123 templates = sect_instances:option(ListValue, "template", "Templates", "Available BGP templates")
125 uciout:foreach("bird6", "bgp_template",
127 templates:value(s[".name"])
130 neighbor_address = sect_instances:option(Value, "neighbor_address", "Neighbor IP Address", "")
131 neighbor_as = sect_instances:option(Value, "neighbor_as", "Neighbor AS", "")
133 disabled = sect_instances:option(Flag, "disabled", "Disabled", "Enable/Disable BGP Protocol")
134 disabled.optional=true
136 table = sect_instances:option(ListValue, "table", "Table", "Set the table used for BGP Routing")
138 uciout:foreach("bird6", "table",
144 description = sect_instances:option(TextValue, "description", "Description", "Description of the current BGP instance")
145 description.optional = true
147 import = sect_instances:option(Value, "import", "Import","")
149 export = sect_instances:option(Value, "export", "Export", "")
152 source_addr = sect_instances:option(Value, "source_address", "Source Address", "Source address for BGP routing. By default uses Router ID")
153 source_addr.optional = true
155 local_address = sect_instances:option(Value, "local_address", "Local BGP address", "")
156 local_address.optional=true
157 local_as = sect_instances:option(Value, "local_as", "Local AS", "")
158 local_as.optional=true
160 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")
161 next_hop_self.default = nil
162 next_hop_self.optional = true
164 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")
165 next_hop_keep.default = nil
166 next_hop_keep.optional = true
168 rr_client = sect_instances:option(Flag, "rr_client", "Route Reflector server", "This router serves as a Route Reflector server and treats neighbors as clients")
169 rr_client.default = nil
170 rr_client.optional = true
172 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")
173 rr_cluster_id.optional = true
175 import_limit = sect_instances:option(Value, "import_limit", "Routes import limit", "Specify an import route limit. By default is disabled '0'")
176 import_limit.default="0"
177 import_limit.optional = true
179 import_limit_action = sect_instances:option(ListValue, "import_limit_action", "Routes import limit action", "Action to take when import routes limit ir reached")
180 import_limit_action:value("warn")
181 import_limit_action:value("block")
182 import_limit_action:value("disable")
183 import_limit_action:value("restart")
184 import_limit_action.default = "warn"
185 import_limit_action.optional = true
187 export_limit = sect_instances:option(Value, "export_limit", "Routes export limit", "Specify an export route limit. By default is disabled '0'")
188 export_limit.default="0"
189 export_limit.optional = true
191 export_limit_action = sect_instances:option(ListValue, "export_limit_action", "Routes export limit action", "Action to take when export routes limit is reached")
192 export_limit_action:value("warn")
193 export_limit_action:value("block")
194 export_limit_action:value("disable")
195 export_limit_action:value("restart")
196 export_limit_action.default = "warn"
197 export_limit_action.optional = true
199 receive_limit = sect_instances:option(Value, "receive_limit", "Routes received limit", "Specify a received route limit. By default is disabled '0'")
200 receive_limit.default="0"
201 receive_limit.optional = true
203 receive_limit_action = sect_instances:option(ListValue, "receive_limit_action", "Routes received limit action", "Action to take when received routes limit is reached")
204 receive_limit_action:value("warn")
205 receive_limit_action:value("block")
206 receive_limit_action:value("disable")
207 receive_limit_action:value("restart")
208 receive_limit_action.default = "warn"
209 receive_limit_action.optional = true
211 -- Section BGP Filters
213 sect_filters = m:section(TypedSection, "filter", "BGP Filters", "Filters of the BGP instances")
214 sect_filters.addremove = true
215 sect_filters.anonymous = false
216 sect_filters:depends("type", "bgp")
218 instance = sect_filters:option(ListValue, "instance", "BGP instance", "Filter's BGP instance")
219 instance:depends("type", "bgp")
221 uciout:foreach("bird6", "bgp",
223 instance:value(s[".name"])
226 type = sect_filters:option(Value, "type", "Filter type", "")
229 path = sect_filters:option(Value, "file_path", "Filter's file path", "Path to the Filter's file")
230 path:depends("type", "bgp")
232 function m.on_commit(self,map)
233 luci.sys.call('/etc/init.d/bird6 stop; /etc/init.d/bird6 start')