types.go 16 KB

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