types.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. package dynamicrouting
  2. // BGPInstance represents global BGP settings (/routing bgp instance)
  3. type BGPInstance struct {
  4. Enabled bool `json:"enabled"`
  5. AS uint32 `json:"as"`
  6. RouterID string `json:"router_id"`
  7. HoldTime int `json:"hold_time"` // Default 180
  8. KeepaliveTime int `json:"keepalive_time"` // Default 60
  9. RedistributeConnected bool `json:"redistribute_connected"`
  10. RedistributeStatic bool `json:"redistribute_static"`
  11. RedistributeOSPF bool `json:"redistribute_ospf"`
  12. Running bool `json:"running"`
  13. }
  14. // BGPPeer represents a BGP peer connection (/routing bgp connection / peer)
  15. type BGPPeer struct {
  16. ID string `json:"id"`
  17. Name string `json:"name"`
  18. Enabled bool `json:"enabled"`
  19. Comment string `json:"comment,omitempty"`
  20. LocalAS uint32 `json:"local_as,omitempty"` // Multi-Instance Local AS (if 0, uses global AS)
  21. RouterID string `json:"router_id,omitempty"`
  22. AFI string `json:"afi,omitempty"` // "ip", "ipv6"
  23. RemoteAddress string `json:"remote_address"`
  24. RemotePort int `json:"remote_port,omitempty"`
  25. RemoteAS uint32 `json:"remote_as"`
  26. LocalAddress string `json:"local_address,omitempty"`
  27. LocalPort int `json:"local_port,omitempty"`
  28. LocalRole string `json:"local_role,omitempty"` // ebgp, ibgp
  29. Password string `json:"password,omitempty"` // TCP MD5 Key
  30. Multihop bool `json:"multihop"`
  31. Connect bool `json:"connect"`
  32. Listen bool `json:"listen"`
  33. HoldTime int `json:"hold_time,omitempty"`
  34. KeepaliveTime int `json:"keepalive_time,omitempty"`
  35. RoutingTable string `json:"routing_table,omitempty"`
  36. RedistConnected bool `json:"redist_connected"`
  37. RedistStatic bool `json:"redist_static"`
  38. RedistOSPF bool `json:"redist_ospf"`
  39. RedistBGP bool `json:"redist_bgp"`
  40. DefaultOriginate bool `json:"default_originate"`
  41. NexthopChoice string `json:"nexthop_choice,omitempty"` // default, force-self
  42. NexthopSelf bool `json:"nexthop_self"`
  43. DefaultPrepend int `json:"default_prepend,omitempty"`
  44. AllowASIn int `json:"allow_as_in,omitempty"`
  45. RemovePrivateAS bool `json:"remove_private_as"`
  46. InFilter string `json:"in_filter,omitempty"` // Routing Filter chain for incoming routes
  47. OutFilter string `json:"out_filter,omitempty"` // Routing Filter chain for outgoing routes
  48. OutputNetworks []string `json:"output_networks,omitempty"` // Dynamic [+] / [-] output networks
  49. Disabled bool `json:"disabled"`
  50. Passive bool `json:"passive"`
  51. // Runtime telemetry
  52. State string `json:"state,omitempty"` // Established, Active, Connect, Idle
  53. Uptime string `json:"uptime,omitempty"`
  54. PrefixReceived int `json:"prefix_received"`
  55. PrefixSent int `json:"prefix_sent"`
  56. }
  57. // BGPNetwork represents an advertised network (/routing bgp network)
  58. type BGPNetwork struct {
  59. ID string `json:"id"`
  60. Network string `json:"network"` // CIDR, e.g. 10.200.0.0/24
  61. Disabled bool `json:"disabled"`
  62. Comment string `json:"comment,omitempty"`
  63. }
  64. // BGPRoute represents an active BGP route
  65. type BGPRoute struct {
  66. Prefix string `json:"prefix"`
  67. NextHop string `json:"next_hop"`
  68. Metric int `json:"metric"`
  69. Weight int `json:"weight"`
  70. Path string `json:"path"`
  71. Origin string `json:"origin"`
  72. Best bool `json:"best"`
  73. }
  74. // OSPFInstance represents an OSPF instance (/routing ospf instance)
  75. type OSPFInstance struct {
  76. ID string `json:"id"`
  77. Name string `json:"name"` // Default "Default"
  78. Version int `json:"version"` // 2 or 3 (default 2)
  79. VRF string `json:"vrf"` // Default "main"
  80. RouterID string `json:"router_id"` // e.g. "10.42.62.254"
  81. RoutingTable string `json:"routing_table,omitempty"`// Default "main"
  82. Enabled bool `json:"enabled"`
  83. Disabled bool `json:"disabled"`
  84. Comment string `json:"comment,omitempty"`
  85. RedistributeConnected bool `json:"redistribute_connected"`
  86. RedistributeStatic bool `json:"redistribute_static"`
  87. RedistributeBGP bool `json:"redistribute_bgp"`
  88. DefaultMetric int `json:"default_metric"`
  89. Running bool `json:"running"`
  90. }
  91. // OSPFArea represents an OSPF area (/routing ospf area)
  92. type OSPFArea struct {
  93. ID string `json:"id"`
  94. Name string `json:"name"` // Default "Default"
  95. Instance string `json:"instance,omitempty"` // Default "Default"
  96. AreaID string `json:"area_id"` // e.g. "0.0.0.0"
  97. AreaType string `json:"area_type"` // default, stub, nssa
  98. DefaultCost int `json:"default_cost,omitempty"`
  99. NoSummaries bool `json:"no_summaries,omitempty"`
  100. Disabled bool `json:"disabled"`
  101. Comment string `json:"comment,omitempty"`
  102. }
  103. // OSPFAreaRange represents an area range (/routing ospf area range)
  104. type OSPFAreaRange struct {
  105. ID string `json:"id"`
  106. Area string `json:"area"` // Area name or ID
  107. Prefix string `json:"prefix"` // CIDR e.g. "10.42.0.0/16"
  108. Cost int `json:"cost"`
  109. Advertise bool `json:"advertise"` // default true
  110. Disabled bool `json:"disabled"`
  111. Comment string `json:"comment,omitempty"`
  112. }
  113. // OSPFInterface represents an OSPF interface template (/routing ospf interface-template)
  114. type OSPFInterface struct {
  115. ID string `json:"id"`
  116. Interfaces string `json:"interfaces,omitempty"` // ether1, wlan1, all...
  117. Area string `json:"area"` // Area ID or name e.g. "Default" / "0.0.0.0"
  118. Networks string `json:"networks,omitempty"` // CIDR e.g. "10.42.36.244/30"
  119. NetworkType string `json:"network_type"` // broadcast, ptp, nbma, point-to-multipoint
  120. Cost int `json:"cost"` // Metric, default 1
  121. Priority int `json:"priority"` // Default 128
  122. HelloInterval int `json:"hello_interval"` // Default 10
  123. DeadInterval int `json:"dead_interval"` // Default 40
  124. Passive bool `json:"passive"`
  125. Auth string `json:"auth,omitempty"` // none, simple, md5
  126. AuthKey string `json:"auth_key,omitempty"`
  127. Disabled bool `json:"disabled"`
  128. Comment string `json:"comment,omitempty"`
  129. // Backward compatibility aliases
  130. Network string `json:"network,omitempty"`
  131. Interface string `json:"interface,omitempty"`
  132. AuthType string `json:"auth_type,omitempty"`
  133. }
  134. // OSPFInterfaceLive represents dynamic live OSPF interface state (/routing ospf interface)
  135. type OSPFInterfaceLive struct {
  136. Flags string `json:"flags"` // "D" (dynamic)
  137. Interface string `json:"interface"` // e.g. "eth0"
  138. Address string `json:"address"` // e.g. "192.168.131.0/24"
  139. Area string `json:"area"` // e.g. "Default" or "0.0.0.0"
  140. InstanceID int `json:"instance_id"` // 0
  141. State string `json:"state"` // dr, backup, waiting, passive, ptp
  142. Cost int `json:"cost"`
  143. Priority int `json:"priority"`
  144. }
  145. // OSPFStaticNeighbor represents a static OSPF neighbor (/routing ospf static-neighbor)
  146. type OSPFStaticNeighbor struct {
  147. ID string `json:"id"`
  148. Address string `json:"address"`
  149. Area string `json:"area"`
  150. PollInterval int `json:"poll_interval"`
  151. Cost int `json:"cost"`
  152. Disabled bool `json:"disabled"`
  153. Comment string `json:"comment,omitempty"`
  154. }
  155. // OSPFNeighbor represents a live OSPF neighbor (/routing ospf neighbor)
  156. type OSPFNeighbor struct {
  157. Flags string `json:"flags"` // "D" (dynamic)
  158. Comment string `json:"comment,omitempty"`
  159. Instance string `json:"instance"` // "Default"
  160. Area string `json:"area"` // "Default"
  161. Address string `json:"address"` // "10.42.62.249"
  162. State string `json:"state"` // "Full"
  163. StateChanges int `json:"state_changes"` // e.g. 6
  164. NeighborID string `json:"neighbor_id,omitempty"`
  165. Interface string `json:"interface,omitempty"`
  166. DeadTimer string `json:"dead_timer,omitempty"`
  167. Priority int `json:"priority,omitempty"`
  168. }
  169. // OSPFLSA represents an LSA record in the Link-State Database (/routing ospf lsa)
  170. type OSPFLSA struct {
  171. Flags string `json:"flags"` // "D", "SD"
  172. Instance string `json:"instance"` // "Default"
  173. Area string `json:"area"` // "Default"
  174. Type string `json:"type"` // "router", "network", "as-external", "summary-net", "summary-asbr"
  175. Originator string `json:"originator"` // Router ID
  176. ID string `json:"id"` // LS ID
  177. Link string `json:"link"`
  178. LinkIndex int `json:"link_index"`
  179. Sequence string `json:"sequence"` // e.g. "8000006e"
  180. Age int `json:"age"` // seconds
  181. }
  182. // OSPFRoute represents an active OSPF route
  183. type OSPFRoute struct {
  184. Prefix string `json:"prefix"`
  185. RouteType string `json:"route_type"` // Intra-Area, Inter-Area, External
  186. Cost int `json:"cost"`
  187. Area string `json:"area"`
  188. NextHop string `json:"next_hop"`
  189. Interface string `json:"interface"`
  190. }
  191. // RoutingFilterRule represents a route filter rule (/routing filter rule)
  192. type RoutingFilterRule struct {
  193. ID string `json:"id"`
  194. Chain string `json:"chain"` // e.g. "bgp-in", "bgp-out", "isp-in"
  195. RuleOrder int `json:"rule_order"` // e.g. 10, 20, 30... Sequence number
  196. Rule string `json:"rule"` // RouterOS v7 rule script e.g. "if (dst in 10.0.0.0/8) { set bgp-local-pref 150; accept; }"
  197. Action string `json:"action"` // "accept" (permit), "discard" (deny), "reject", "passthrough"
  198. Prefix string `json:"prefix,omitempty"` // CIDR e.g. "10.0.0.0/8" or "0.0.0.0/0"
  199. PrefixLen string `json:"prefix_len,omitempty"` // e.g. "24-32", "ge 24 le 32", "24"
  200. MatchProtocol string `json:"match_protocol,omitempty"` // "any", "bgp", "ospf", "connected", "static"
  201. MatchASPath string `json:"match_as_path,omitempty"` // regex e.g. "^65000_"
  202. MatchCommunity string `json:"match_community,omitempty"`// e.g. "65001:100"
  203. SetLocalPref int `json:"set_local_pref,omitempty"` // BGP Local Preference
  204. SetMetric int `json:"set_metric,omitempty"` // BGP MED / OSPF Metric
  205. SetASPrepend int `json:"set_as_prepend,omitempty"` // AS Path prepend count
  206. SetCommunity string `json:"set_community,omitempty"` // Set BGP community
  207. SetNextHop string `json:"set_next_hop,omitempty"` // Custom Next Hop IP
  208. SetDistance int `json:"set_distance,omitempty"` // Administrative Distance
  209. Disabled bool `json:"disabled"`
  210. Comment string `json:"comment,omitempty"`
  211. }
  212. // RoutingFilterSelectRule represents a route selection rule (/routing filter select-rule)
  213. type RoutingFilterSelectRule struct {
  214. ID string `json:"id"`
  215. Chain string `json:"chain"`
  216. RuleOrder int `json:"rule_order"`
  217. Rule string `json:"rule"`
  218. Disabled bool `json:"disabled"`
  219. Comment string `json:"comment,omitempty"`
  220. }
  221. // RoutingFilterCommunityList represents a named community set (/routing filter community-list)
  222. type RoutingFilterCommunityList struct {
  223. ID string `json:"id"`
  224. Name string `json:"name"`
  225. Communities []string `json:"communities"`
  226. Regexp string `json:"regexp,omitempty"`
  227. Disabled bool `json:"disabled"`
  228. Comment string `json:"comment,omitempty"`
  229. }
  230. // RoutingFilterASList represents a named AS number list (/routing filter num-list)
  231. type RoutingFilterASList struct {
  232. ID string `json:"id"`
  233. Name string `json:"name"`
  234. Range string `json:"range"`
  235. Disabled bool `json:"disabled"`
  236. Comment string `json:"comment,omitempty"`
  237. }
  238. // DynamicRoutingSummary aggregates status for dashboard & badges
  239. type DynamicRoutingSummary struct {
  240. BGPEnabled bool `json:"bgp_enabled"`
  241. BGPRunning bool `json:"bgp_running"`
  242. BGPPeerCount int `json:"bgp_peer_count"`
  243. BGPEstablishedCount int `json:"bgp_established_count"`
  244. OSPFEnabled bool `json:"ospf_enabled"`
  245. OSPFRunning bool `json:"ospf_running"`
  246. OSPFNeighborCount int `json:"ospf_neighbor_count"`
  247. OSPFAdjacentCount int `json:"ospf_adjacent_count"`
  248. RoutingFilterCount int `json:"routing_filter_count"`
  249. }
  250. // DynamicConfig stores all dynamic routing data on disk
  251. type DynamicConfig struct {
  252. BGPInstance BGPInstance `json:"bgp_instance"`
  253. BGPPeers []BGPPeer `json:"bgp_peers"`
  254. BGPNetworks []BGPNetwork `json:"bgp_networks"`
  255. OSPFInstances []OSPFInstance `json:"ospf_instances"`
  256. OSPFInstance OSPFInstance `json:"ospf_instance"` // Backward compatibility
  257. OSPFAreas []OSPFArea `json:"ospf_areas"`
  258. OSPFAreaRanges []OSPFAreaRange `json:"ospf_area_ranges"`
  259. OSPFInterfaces []OSPFInterface `json:"ospf_interfaces"`
  260. OSPFStaticNbrs []OSPFStaticNeighbor `json:"ospf_static_nbrs"`
  261. RoutingFilters []RoutingFilterRule `json:"routing_filters"`
  262. RoutingSelectRules []RoutingFilterSelectRule `json:"routing_select_rules"`
  263. RoutingCommunityLists []RoutingFilterCommunityList `json:"routing_community_lists"`
  264. RoutingASLists []RoutingFilterASList `json:"routing_as_lists"`
  265. }