/bird1-openwrt/bird1-ipv6-openwrt/src/model/bgp_proto.lua

https://gitlab.com/jiangming1399/routing · Lua · 286 lines · 266 code · 3 blank · 17 comment · 2 complexity · 9ef88cbbe24e9d730de689edf8a45a0c MD5 · raw file

  1. --[[
  2. Copyright (C) 2014-2017 - Eloi Carbo
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. --]]
  14. require("luci.sys")
  15. local http = require "luci.http"
  16. local uci = luci.model.uci.cursor()
  17. -- Repeated Strings
  18. 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)"
  19. local imp_string = "Set if the protocol must import routes.<br />" .. common_string
  20. local exp_string = "Set if the protocol must export routes.<br />" .. common_string
  21. m=Map("bird6", "Bird6 BGP protocol's configuration")
  22. tab_templates = {}
  23. uci:foreach('bird6', 'bgp_template', function (s)
  24. local name = s[".name"]
  25. if (name ~= nil) then
  26. table.insert(tab_templates, name)
  27. end
  28. end)
  29. --
  30. -- BGP TEMPLATES
  31. --
  32. sect_templates = m:section(TypedSection, "bgp_template", "BGP Templates", "Configuration of the templates used in BGP instances.")
  33. sect_templates.addremove = true
  34. sect_templates.anonymous = false
  35. disabled = sect_templates:option(Flag, "disabled", "Disabled", "Enable/Disable BGP Protocol")
  36. disabled.optional=true
  37. description = sect_templates:option(TextValue, "description", "Description", "Description of the current BGP instance")
  38. description.optional = true
  39. table = sect_templates:option(ListValue, "table", "Table", "Set the table used for BGP Routing")
  40. table.optional=true
  41. uci:foreach("bird6", "table",
  42. function (s)
  43. table:value(s.name)
  44. end)
  45. table:value("")
  46. table.default = ""
  47. igp_table = sect_templates:option(ListValue, "igp_table", "IGP Table", "Select the IGP Routing Table to use. Hint: usually the same table as BGP.")
  48. igp_table.optional = true
  49. uci:foreach("bird6", "table",
  50. function(s)
  51. igp_table:value(s.name)
  52. end)
  53. igp_table:value("")
  54. igp_table.default = ""
  55. import = sect_templates:option(Value, "import", "Import", imp_string)
  56. import.optional=true
  57. export = sect_templates:option(Value, "export", "Export", exp_string)
  58. export.optional=true
  59. source_addr = sect_templates:option(Value, "source_address", "Source Address", "Source address for BGP routing. By default uses Router ID")
  60. source_addr.optional = true
  61. local_address = sect_templates:option(Value, "local_address", "Local BGP address", "")
  62. local_address.optional = false
  63. local_as = sect_templates:option(Value, "local_as", "Local AS", "")
  64. local_as.optional = false
  65. 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")
  66. next_hop_self.default = nil
  67. next_hop_self.optional = true
  68. 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")
  69. next_hop_keep.default = nil
  70. next_hop_keep.optional = true
  71. rr_client = sect_templates:option(Flag, "rr_client", "Route Reflector server", "This router serves as a Route Reflector server and treats neighbors as clients")
  72. rr_client.default = nil
  73. rr_client.optional = true
  74. 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")
  75. rr_cluster_id.optional = true
  76. import_trigger = sect_templates:option(Flag, "import_trigger", "Import Limit", "Enable Routes Import limit settings")
  77. import_trigger.default = 0
  78. import_trigger.rmempty = false
  79. import_trigger.optional = false
  80. import_limit = sect_templates:option(Value, "import_limit", "Routes import limit", "Specify an import route limit.")
  81. import_limit:depends({import_trigger = "1"})
  82. import_limit.rmempty = true
  83. import_limit_action = sect_templates:option(ListValue, "import_limit_action", "Routes import limit action", "Action to take when import routes limit ir reached")
  84. import_limit_action:depends({import_trigger = "1"})
  85. import_limit_action:value("warn")
  86. import_limit_action:value("block")
  87. import_limit_action:value("disable")
  88. import_limit_action:value("restart")
  89. import_limit_action.default = "warn"
  90. import_limit_action.rmempty = true
  91. export_trigger = sect_templates:option(Flag, "export_trigger", "Export Limit", "Enable Routes Export limit settings")
  92. export_trigger.default = 0
  93. export_trigger.rmempty = false
  94. export_trigger.optional = false
  95. export_limit = sect_templates:option(Value, "export_limit", "Routes export limit", "Specify an export route limit.")
  96. export_limit:depends({export_trigger = "1"})
  97. export_limit.rmempty = true
  98. export_limit_action = sect_templates:option(ListValue, "export_limit_action", "Routes export limit action", "Action to take when export routes limit is reached")
  99. export_limit_action:depends({export_trigger = "1"})
  100. export_limit_action.rmempty = true
  101. export_limit_action:value("warn")
  102. export_limit_action:value("block")
  103. export_limit_action:value("disable")
  104. export_limit_action:value("restart")
  105. export_limit_action.default = "warn"
  106. receive_trigger = sect_templates:option(Flag, "receive_trigger", "Received Limit", "Enable Routes Received Limit settings")
  107. receive_trigger.default = 0
  108. receive_trigger.rmempty = false
  109. receive_trigger.optional = false
  110. receive_limit = sect_templates:option(Value, "receive_limit", "Routes received limit", "Specify a received route limit.")
  111. receive_limit:depends({receive_trigger = "1"})
  112. receive_limit.rmempty = true
  113. receive_limit_action = sect_templates:option(ListValue, "receive_limit_action", "Routes received limit action", "Action to take when received routes limit is reached")
  114. receive_limit_action:depends({receive_trigger = "1"})
  115. receive_limit_action:value("warn")
  116. receive_limit_action:value("block")
  117. receive_limit_action:value("disable")
  118. receive_limit_action:value("restart")
  119. receive_limit_action.default = "warn"
  120. receive_limit_action.rmempty= true
  121. --
  122. -- BGP INSTANCES
  123. --
  124. sect_instances = m:section(TypedSection, "bgp", "BGP Instances", "Configuration of the BGP protocol instances")
  125. sect_instances.addremove = true
  126. sect_instances.anonymous = false
  127. templates = sect_instances:option(ListValue, "template", "Templates", "Available BGP templates")
  128. uci:foreach("bird6", "bgp_template",
  129. function(s)
  130. templates:value(s[".name"])
  131. end)
  132. templates:value("")
  133. disabled = sect_instances:option(Flag, "disabled", "Disabled", "Enable/Disable BGP Protocol")
  134. disabled.optional = false
  135. disabled.rmempty = false
  136. disabled.default = nil
  137. description = sect_instances:option(TextValue, "description", "Description", "Description of the current BGP instance")
  138. description.optional = true
  139. table = sect_instances:option(ListValue, "table", "Table", "Set the table used for BGP Routing")
  140. table.optional=true
  141. uci:foreach("bird6", "table",
  142. function (s)
  143. table:value(s.name)
  144. end)
  145. table:value("")
  146. table.default = ""
  147. igp_table = sect_instances:option(ListValue, "igp_table", "IGP Table", "Select the IGP Routing Table to use. Hint: usually the same table as BGP.")
  148. igp_table.optional = true
  149. uci:foreach("bird6", "table",
  150. function(s)
  151. igp_table:value(s.name)
  152. end)
  153. igp_table:value("")
  154. igp_table.default = ""
  155. import = sect_instances:option(Value, "import", "Import", imp_string)
  156. import.optional=true
  157. export = sect_instances:option(Value, "export", "Export", exp_string)
  158. export.optional=true
  159. source_address = sect_instances:option(Value, "source_address", "Source Address", "Source address for BGP routing. By default uses Router ID")
  160. source_address.optional = true
  161. local_address = sect_instances:option(Value, "local_address", "Local BGP address", "")
  162. local_address.optional=true
  163. local_as = sect_instances:option(Value, "local_as", "Local AS", "")
  164. local_as.optional=true
  165. neighbor_address = sect_instances:option(Value, "neighbor_address", "Neighbor IP Address", "")
  166. neighbor_address.optional = false
  167. neighbor_as = sect_instances:option(Value, "neighbor_as", "Neighbor AS", "")
  168. neighbor_as.optional = false
  169. 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")
  170. next_hop_self.default = nil
  171. next_hop_self.optional = true
  172. 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")
  173. next_hop_keep.default = nil
  174. next_hop_keep.optional = true
  175. rr_client = sect_instances:option(Flag, "rr_client", "Route Reflector server", "This router serves as a Route Reflector server and treats neighbors as clients")
  176. rr_client.default = nil
  177. rr_client.optional = true
  178. 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")
  179. rr_cluster_id.optional = true
  180. import_trigger = sect_instances:option(Flag, "import_trigger", "Import Limit", "Enable Routes Import limit settings")
  181. import_trigger.default = 0
  182. import_trigger.rmempty = false
  183. import_trigger.optional = false
  184. import_limit = sect_instances:option(Value, "import_limit", "Routes import limit", "Specify an import route limit.")
  185. import_limit:depends({import_trigger = "1"})
  186. import_limit.rmempty = true
  187. import_limit_action = sect_instances:option(ListValue, "import_limit_action", "Routes import limit action", "Action to take when import routes limit ir reached")
  188. import_limit_action:depends({import_trigger = "1"})
  189. import_limit_action:value("warn")
  190. import_limit_action:value("block")
  191. import_limit_action:value("disable")
  192. import_limit_action:value("restart")
  193. import_limit_action.default = "warn"
  194. import_limit_action.rmempty = true
  195. export_trigger = sect_instances:option(Flag, "export_trigger", "Export Limit", "Enable Routes Export limit settings")
  196. export_trigger.default = 0
  197. export_trigger.rmempty = false
  198. export_trigger.optional = false
  199. export_limit = sect_instances:option(Value, "export_limit", "Routes export limit", "Specify an export route limit.")
  200. export_limit:depends({export_trigger = "1"})
  201. export_limit.rmempty = true
  202. export_limit_action = sect_instances:option(ListValue, "export_limit_action", "Routes export limit action", "Action to take when export routes limit is reached")
  203. export_limit_action:depends({export_trigger = "1"})
  204. export_limit_action.rmempty = true
  205. export_limit_action:value("warn")
  206. export_limit_action:value("block")
  207. export_limit_action:value("disable")
  208. export_limit_action:value("restart")
  209. export_limit_action.default = "warn"
  210. receive_trigger = sect_instances:option(Flag, "receive_trigger", "Received Limit", "Enable Routes Received Limit settings")
  211. receive_trigger.default = 0
  212. receive_trigger.rmempty = false
  213. receive_trigger.optional = false
  214. receive_limit = sect_instances:option(Value, "receive_limit", "Routes received limit", "Specify a received route limit.")
  215. receive_limit:depends({receive_trigger = "1"})
  216. receive_limit.rmempty = true
  217. receive_limit_action = sect_instances:option(ListValue, "receive_limit_action", "Routes received limit action", "Action to take when received routes limit is reached")
  218. receive_limit_action:depends({receive_trigger = "1"})
  219. receive_limit_action:value("warn")
  220. receive_limit_action:value("block")
  221. receive_limit_action:value("disable")
  222. receive_limit_action:value("restart")
  223. receive_limit_action.default = "warn"
  224. receive_limit_action.rmempty= true
  225. function m.on_commit(self,map)
  226. luci.sys.exec('/etc/init.d/bird6 restart')
  227. end
  228. return m