types.go 14 KB

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