types.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. RedistributeDefault bool `json:"redistribute_default"` // MikroTik redistribute-default
  121. OriginateDefault string `json:"originate_default,omitempty"` // "never", "if-installed", "always"
  122. DefaultMetric int `json:"default_metric"`
  123. Running bool `json:"running"`
  124. }
  125. // OSPFArea represents an OSPF area (/routing ospf area)
  126. type OSPFArea struct {
  127. ID string `json:"id"`
  128. Name string `json:"name"` // Default "Default"
  129. Instance string `json:"instance,omitempty"` // Default "Default"
  130. AreaID string `json:"area_id"` // e.g. "0.0.0.0"
  131. AreaType string `json:"area_type"` // default, stub, nssa
  132. DefaultCost int `json:"default_cost,omitempty"`
  133. NoSummaries bool `json:"no_summaries,omitempty"`
  134. Disabled bool `json:"disabled"`
  135. Comment string `json:"comment,omitempty"`
  136. }
  137. // OSPFAreaRange represents an area range (/routing ospf area range)
  138. type OSPFAreaRange struct {
  139. ID string `json:"id"`
  140. Area string `json:"area"` // Area name or ID
  141. Prefix string `json:"prefix"` // CIDR e.g. "10.42.0.0/16"
  142. Cost int `json:"cost"`
  143. Advertise bool `json:"advertise"` // default true
  144. Disabled bool `json:"disabled"`
  145. Comment string `json:"comment,omitempty"`
  146. }
  147. // OSPFInterface represents an OSPF interface template (/routing ospf interface-template)
  148. type OSPFInterface struct {
  149. ID string `json:"id"`
  150. Interfaces string `json:"interfaces,omitempty"` // ether1, wlan1, all...
  151. Area string `json:"area"` // Area ID or name e.g. "Default" / "0.0.0.0"
  152. Networks string `json:"networks,omitempty"` // CIDR e.g. "10.42.36.244/30"
  153. NetworkType string `json:"network_type"` // broadcast, ptp, nbma, point-to-multipoint
  154. Cost int `json:"cost"` // Metric, default 1
  155. Priority int `json:"priority"` // Default 128
  156. HelloInterval int `json:"hello_interval"` // Default 10
  157. DeadInterval int `json:"dead_interval"` // Default 40
  158. Passive bool `json:"passive"`
  159. Auth string `json:"auth,omitempty"` // none, simple, md5
  160. AuthKey string `json:"auth_key,omitempty"`
  161. Disabled bool `json:"disabled"`
  162. Comment string `json:"comment,omitempty"`
  163. // Backward compatibility aliases
  164. Network string `json:"network,omitempty"`
  165. Interface string `json:"interface,omitempty"`
  166. AuthType string `json:"auth_type,omitempty"`
  167. }
  168. // OSPFInterfaceLive represents dynamic live OSPF interface state (/routing ospf interface)
  169. type OSPFInterfaceLive struct {
  170. Flags string `json:"flags"` // "D" (dynamic)
  171. Interface string `json:"interface"` // e.g. "eth0"
  172. Address string `json:"address"` // e.g. "192.168.131.0/24"
  173. Area string `json:"area"` // e.g. "Default" or "0.0.0.0"
  174. InstanceID int `json:"instance_id"` // 0
  175. State string `json:"state"` // dr, backup, waiting, passive, ptp
  176. Cost int `json:"cost"`
  177. Priority int `json:"priority"`
  178. }
  179. // OSPFStaticNeighbor represents a static OSPF neighbor (/routing ospf static-neighbor)
  180. type OSPFStaticNeighbor struct {
  181. ID string `json:"id"`
  182. Address string `json:"address"`
  183. Area string `json:"area"`
  184. PollInterval int `json:"poll_interval"`
  185. Cost int `json:"cost"`
  186. Disabled bool `json:"disabled"`
  187. Comment string `json:"comment,omitempty"`
  188. }
  189. // OSPFNeighbor represents a live OSPF neighbor (/routing ospf neighbor)
  190. type OSPFNeighbor struct {
  191. Flags string `json:"flags"` // "D" (dynamic)
  192. Comment string `json:"comment,omitempty"`
  193. Instance string `json:"instance"` // "Default"
  194. Area string `json:"area"` // "Default"
  195. Address string `json:"address"` // "10.42.62.249"
  196. State string `json:"state"` // "Full"
  197. StateChanges int `json:"state_changes"` // e.g. 6
  198. NeighborID string `json:"neighbor_id,omitempty"`
  199. Interface string `json:"interface,omitempty"`
  200. DeadTimer string `json:"dead_timer,omitempty"`
  201. Priority int `json:"priority,omitempty"`
  202. }
  203. // OSPFLSA represents an LSA record in the Link-State Database (/routing ospf lsa)
  204. type OSPFLSA struct {
  205. Flags string `json:"flags"` // "D", "SD"
  206. Instance string `json:"instance"` // "Default"
  207. Area string `json:"area"` // "Default"
  208. Type string `json:"type"` // "router", "network", "as-external", "summary-net", "summary-asbr"
  209. Originator string `json:"originator"` // Router ID
  210. ID string `json:"id"` // LS ID
  211. Link string `json:"link"`
  212. LinkIndex int `json:"link_index"`
  213. Sequence string `json:"sequence"` // e.g. "8000006e"
  214. Age int `json:"age"` // seconds
  215. }
  216. // OSPFRoute represents an active OSPF route
  217. type OSPFRoute struct {
  218. Prefix string `json:"prefix"`
  219. RouteType string `json:"route_type"` // Intra-Area, Inter-Area, External
  220. Cost int `json:"cost"`
  221. Area string `json:"area"`
  222. NextHop string `json:"next_hop"`
  223. Interface string `json:"interface"`
  224. }
  225. // RoutingFilterRule represents a route filter rule (/routing filter rule)
  226. type RoutingFilterRule struct {
  227. ID string `json:"id"`
  228. Chain string `json:"chain"` // e.g. "bgp-in", "bgp-out", "isp-in"
  229. RuleOrder int `json:"rule_order"` // e.g. 10, 20, 30... Sequence number
  230. Rule string `json:"rule"` // RouterOS v7 rule script e.g. "if (dst in 10.0.0.0/8) { set bgp-local-pref 150; accept; }"
  231. Action string `json:"action"` // "accept" (permit), "discard" (deny), "reject", "passthrough"
  232. Prefix string `json:"prefix,omitempty"` // CIDR e.g. "10.0.0.0/8" or "0.0.0.0/0"
  233. PrefixLen string `json:"prefix_len,omitempty"` // e.g. "24-32", "ge 24 le 32", "24"
  234. MatchProtocol string `json:"match_protocol,omitempty"` // "any", "bgp", "ospf", "connected", "static"
  235. MatchASPath string `json:"match_as_path,omitempty"` // regex e.g. "^65000_"
  236. MatchCommunity string `json:"match_community,omitempty"`// e.g. "65001:100"
  237. SetLocalPref int `json:"set_local_pref,omitempty"` // BGP Local Preference
  238. SetMetric int `json:"set_metric,omitempty"` // BGP MED / OSPF Metric
  239. SetASPrepend int `json:"set_as_prepend,omitempty"` // AS Path prepend count
  240. SetCommunity string `json:"set_community,omitempty"` // Set BGP community
  241. SetNextHop string `json:"set_next_hop,omitempty"` // Custom Next Hop IP
  242. SetDistance int `json:"set_distance,omitempty"` // Administrative Distance
  243. Disabled bool `json:"disabled"`
  244. Comment string `json:"comment,omitempty"`
  245. }
  246. // RoutingFilterSelectRule represents a deprecated route selection rule (/routing filter select-rule)
  247. type RoutingFilterSelectRule struct {
  248. ID string `json:"id"`
  249. Chain string `json:"chain"`
  250. RuleOrder int `json:"rule_order"`
  251. Rule string `json:"rule"`
  252. Disabled bool `json:"disabled"`
  253. Comment string `json:"comment,omitempty"`
  254. }
  255. // RoutingFilterCommunityList represents a named community set (/routing filter community-list)
  256. type RoutingFilterCommunityList struct {
  257. ID string `json:"id"`
  258. Name string `json:"name"`
  259. Communities []string `json:"communities"`
  260. Regexp string `json:"regexp,omitempty"`
  261. Disabled bool `json:"disabled"`
  262. Comment string `json:"comment,omitempty"`
  263. }
  264. // RoutingFilterASList represents a named AS number list (/routing filter num-list)
  265. type RoutingFilterASList struct {
  266. ID string `json:"id"`
  267. Name string `json:"name"`
  268. Range string `json:"range"`
  269. Disabled bool `json:"disabled"`
  270. Comment string `json:"comment,omitempty"`
  271. }
  272. // DynamicRoutingSummary aggregates status for dashboard & badges
  273. type DynamicRoutingSummary struct {
  274. BGPEnabled bool `json:"bgp_enabled"`
  275. BGPRunning bool `json:"bgp_running"`
  276. BGPPeerCount int `json:"bgp_peer_count"`
  277. BGPEstablishedCount int `json:"bgp_established_count"`
  278. OSPFEnabled bool `json:"ospf_enabled"`
  279. OSPFRunning bool `json:"ospf_running"`
  280. OSPFNeighborCount int `json:"ospf_neighbor_count"`
  281. OSPFAdjacentCount int `json:"ospf_adjacent_count"`
  282. RoutingFilterCount int `json:"routing_filter_count"`
  283. }
  284. // DynamicConfig stores all dynamic routing data on disk
  285. type DynamicConfig struct {
  286. BGPInstance BGPInstance `json:"bgp_instance"`
  287. BGPPeers []BGPPeer `json:"bgp_peers"`
  288. BGPNetworks []BGPNetwork `json:"bgp_networks"`
  289. OSPFInstances []OSPFInstance `json:"ospf_instances"`
  290. OSPFInstance OSPFInstance `json:"ospf_instance"` // Backward compatibility
  291. OSPFAreas []OSPFArea `json:"ospf_areas"`
  292. OSPFAreaRanges []OSPFAreaRange `json:"ospf_area_ranges"`
  293. OSPFInterfaces []OSPFInterface `json:"ospf_interfaces"`
  294. OSPFStaticNbrs []OSPFStaticNeighbor `json:"ospf_static_nbrs"`
  295. RoutingFilters []RoutingFilterRule `json:"routing_filters"`
  296. RoutingSelectRules []RoutingFilterSelectRule `json:"routing_select_rules,omitempty"` // Deprecated: unused in BIRD 2
  297. RoutingCommunityLists []RoutingFilterCommunityList `json:"routing_community_lists"`
  298. RoutingASLists []RoutingFilterASList `json:"routing_as_lists"`
  299. }