types.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 global OSPF settings (/routing ospf instance)
  75. type OSPFInstance struct {
  76. Enabled bool `json:"enabled"`
  77. RouterID string `json:"router_id"`
  78. RedistributeConnected bool `json:"redistribute_connected"`
  79. RedistributeStatic bool `json:"redistribute_static"`
  80. RedistributeBGP bool `json:"redistribute_bgp"`
  81. DefaultMetric int `json:"default_metric"`
  82. Running bool `json:"running"`
  83. }
  84. // OSPFArea represents an OSPF area (/routing ospf area)
  85. type OSPFArea struct {
  86. ID string `json:"id"`
  87. Name string `json:"name"`
  88. AreaID string `json:"area_id"` // e.g. "0.0.0.0" or "0"
  89. AreaType string `json:"area_type"` // default, stub, nssa
  90. Comment string `json:"comment,omitempty"`
  91. }
  92. // OSPFInterface represents an OSPF network/interface template (/routing ospf interface-template)
  93. type OSPFInterface struct {
  94. ID string `json:"id"`
  95. Network string `json:"network"` // CIDR, e.g. "192.168.131.0/24"
  96. Area string `json:"area"` // Area ID e.g. "0.0.0.0"
  97. Interface string `json:"interface,omitempty"` // eth0, vlan10, wg0...
  98. Cost int `json:"cost"` // Metric, default 10
  99. Priority int `json:"priority"` // Default 1
  100. HelloInterval int `json:"hello_interval"` // Default 10
  101. DeadInterval int `json:"dead_interval"` // Default 40
  102. Passive bool `json:"passive"`
  103. AuthType string `json:"auth_type"` // none, simple, md5
  104. AuthKey string `json:"auth_key,omitempty"`
  105. Disabled bool `json:"disabled"`
  106. Comment string `json:"comment,omitempty"`
  107. }
  108. // OSPFNeighbor represents a live OSPF neighbor
  109. type OSPFNeighbor struct {
  110. NeighborID string `json:"neighbor_id"`
  111. Address string `json:"address"`
  112. Interface string `json:"interface"`
  113. Area string `json:"area"`
  114. State string `json:"state"` // Full/DR, Full/Backup, 2-Way...
  115. DeadTimer string `json:"dead_timer"`
  116. }
  117. // OSPFRoute represents an active OSPF route
  118. type OSPFRoute struct {
  119. Prefix string `json:"prefix"`
  120. RouteType string `json:"route_type"` // Intra-Area, Inter-Area, External
  121. Cost int `json:"cost"`
  122. Area string `json:"area"`
  123. NextHop string `json:"next_hop"`
  124. Interface string `json:"interface"`
  125. }
  126. // RoutingFilterRule represents a route filter rule (/routing filter)
  127. type RoutingFilterRule struct {
  128. ID string `json:"id"`
  129. Chain string `json:"chain"` // e.g. "bgp-in", "bgp-out", "isp-in"
  130. RuleOrder int `json:"rule_order"` // e.g. 10, 20, 30... Sequence number
  131. Action string `json:"action"` // "accept" (permit), "discard" (deny), "reject", "passthrough"
  132. Prefix string `json:"prefix,omitempty"` // CIDR e.g. "10.0.0.0/8" or "0.0.0.0/0"
  133. PrefixLen string `json:"prefix_len,omitempty"` // e.g. "24-32", "ge 24 le 32", "24"
  134. MatchProtocol string `json:"match_protocol,omitempty"` // "any", "bgp", "ospf", "connected", "static"
  135. MatchASPath string `json:"match_as_path,omitempty"` // regex e.g. "^65000_"
  136. MatchCommunity string `json:"match_community,omitempty"`// e.g. "65001:100"
  137. SetLocalPref int `json:"set_local_pref,omitempty"` // BGP Local Preference
  138. SetMetric int `json:"set_metric,omitempty"` // BGP MED / OSPF Metric
  139. SetASPrepend int `json:"set_as_prepend,omitempty"` // AS Path prepend count
  140. SetCommunity string `json:"set_community,omitempty"` // Set BGP community
  141. SetNextHop string `json:"set_next_hop,omitempty"` // Custom Next Hop IP
  142. SetDistance int `json:"set_distance,omitempty"` // Administrative Distance
  143. Disabled bool `json:"disabled"`
  144. Comment string `json:"comment,omitempty"`
  145. }
  146. // DynamicRoutingSummary aggregates status for dashboard & badges
  147. type DynamicRoutingSummary struct {
  148. BGPEnabled bool `json:"bgp_enabled"`
  149. BGPRunning bool `json:"bgp_running"`
  150. BGPPeerCount int `json:"bgp_peer_count"`
  151. BGPEstablishedCount int `json:"bgp_established_count"`
  152. OSPFEnabled bool `json:"ospf_enabled"`
  153. OSPFRunning bool `json:"ospf_running"`
  154. OSPFNeighborCount int `json:"ospf_neighbor_count"`
  155. OSPFAdjacentCount int `json:"ospf_adjacent_count"`
  156. RoutingFilterCount int `json:"routing_filter_count"`
  157. }
  158. // DynamicConfig stores all dynamic routing data on disk
  159. type DynamicConfig struct {
  160. BGPInstance BGPInstance `json:"bgp_instance"`
  161. BGPPeers []BGPPeer `json:"bgp_peers"`
  162. BGPNetworks []BGPNetwork `json:"bgp_networks"`
  163. OSPFInstance OSPFInstance `json:"ospf_instance"`
  164. OSPFAreas []OSPFArea `json:"ospf_areas"`
  165. OSPFInterfaces []OSPFInterface `json:"ospf_interfaces"`
  166. RoutingFilters []RoutingFilterRule `json:"routing_filters"`
  167. }