types.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. RemoteAddress string `json:"remote_address"`
  19. RemoteAS uint32 `json:"remote_as"`
  20. LocalAddress string `json:"local_address,omitempty"`
  21. LocalAS uint32 `json:"local_as,omitempty"` // Multi-Instance Local AS (if 0, uses global AS)
  22. Multihop bool `json:"multihop"`
  23. NexthopSelf bool `json:"nexthop_self"`
  24. Passive bool `json:"passive"`
  25. Password string `json:"password,omitempty"`
  26. Disabled bool `json:"disabled"`
  27. Comment string `json:"comment,omitempty"`
  28. InFilter string `json:"in_filter,omitempty"` // Routing Filter chain for incoming routes
  29. OutFilter string `json:"out_filter,omitempty"` // Routing Filter chain for outgoing routes
  30. // Runtime telemetry
  31. State string `json:"state,omitempty"` // Established, Active, Connect, Idle
  32. Uptime string `json:"uptime,omitempty"`
  33. PrefixReceived int `json:"prefix_received"`
  34. PrefixSent int `json:"prefix_sent"`
  35. }
  36. // BGPNetwork represents an advertised network (/routing bgp network)
  37. type BGPNetwork struct {
  38. ID string `json:"id"`
  39. Network string `json:"network"` // CIDR, e.g. 10.200.0.0/24
  40. Disabled bool `json:"disabled"`
  41. Comment string `json:"comment,omitempty"`
  42. }
  43. // BGPRoute represents an active BGP route
  44. type BGPRoute struct {
  45. Prefix string `json:"prefix"`
  46. NextHop string `json:"next_hop"`
  47. Metric int `json:"metric"`
  48. Weight int `json:"weight"`
  49. Path string `json:"path"`
  50. Origin string `json:"origin"`
  51. Best bool `json:"best"`
  52. }
  53. // OSPFInstance represents global OSPF settings (/routing ospf instance)
  54. type OSPFInstance struct {
  55. Enabled bool `json:"enabled"`
  56. RouterID string `json:"router_id"`
  57. RedistributeConnected bool `json:"redistribute_connected"`
  58. RedistributeStatic bool `json:"redistribute_static"`
  59. RedistributeBGP bool `json:"redistribute_bgp"`
  60. DefaultMetric int `json:"default_metric"`
  61. Running bool `json:"running"`
  62. }
  63. // OSPFArea represents an OSPF area (/routing ospf area)
  64. type OSPFArea struct {
  65. ID string `json:"id"`
  66. Name string `json:"name"`
  67. AreaID string `json:"area_id"` // e.g. "0.0.0.0" or "0"
  68. AreaType string `json:"area_type"` // default, stub, nssa
  69. Comment string `json:"comment,omitempty"`
  70. }
  71. // OSPFInterface represents an OSPF network/interface template (/routing ospf interface-template)
  72. type OSPFInterface struct {
  73. ID string `json:"id"`
  74. Network string `json:"network"` // CIDR, e.g. "192.168.131.0/24"
  75. Area string `json:"area"` // Area ID e.g. "0.0.0.0"
  76. Interface string `json:"interface,omitempty"` // eth0, vlan10, wg0...
  77. Cost int `json:"cost"` // Metric, default 10
  78. Priority int `json:"priority"` // Default 1
  79. HelloInterval int `json:"hello_interval"` // Default 10
  80. DeadInterval int `json:"dead_interval"` // Default 40
  81. Passive bool `json:"passive"`
  82. AuthType string `json:"auth_type"` // none, simple, md5
  83. AuthKey string `json:"auth_key,omitempty"`
  84. Disabled bool `json:"disabled"`
  85. Comment string `json:"comment,omitempty"`
  86. }
  87. // OSPFNeighbor represents a live OSPF neighbor
  88. type OSPFNeighbor struct {
  89. NeighborID string `json:"neighbor_id"`
  90. Address string `json:"address"`
  91. Interface string `json:"interface"`
  92. Area string `json:"area"`
  93. State string `json:"state"` // Full/DR, Full/Backup, 2-Way...
  94. DeadTimer string `json:"dead_timer"`
  95. }
  96. // OSPFRoute represents an active OSPF route
  97. type OSPFRoute struct {
  98. Prefix string `json:"prefix"`
  99. RouteType string `json:"route_type"` // Intra-Area, Inter-Area, External
  100. Cost int `json:"cost"`
  101. Area string `json:"area"`
  102. NextHop string `json:"next_hop"`
  103. Interface string `json:"interface"`
  104. }
  105. // RoutingFilterRule represents a route filter rule (/routing filter)
  106. type RoutingFilterRule struct {
  107. ID string `json:"id"`
  108. Chain string `json:"chain"` // e.g. "bgp-in", "bgp-out", "isp-in"
  109. RuleOrder int `json:"rule_order"` // e.g. 10, 20, 30... Sequence number
  110. Action string `json:"action"` // "accept" (permit), "discard" (deny), "reject", "passthrough"
  111. Prefix string `json:"prefix,omitempty"` // CIDR e.g. "10.0.0.0/8" or "0.0.0.0/0"
  112. PrefixLen string `json:"prefix_len,omitempty"` // e.g. "24-32", "ge 24 le 32", "24"
  113. MatchProtocol string `json:"match_protocol,omitempty"` // "any", "bgp", "ospf", "connected", "static"
  114. MatchASPath string `json:"match_as_path,omitempty"` // regex e.g. "^65000_"
  115. MatchCommunity string `json:"match_community,omitempty"`// e.g. "65001:100"
  116. SetLocalPref int `json:"set_local_pref,omitempty"` // BGP Local Preference
  117. SetMetric int `json:"set_metric,omitempty"` // BGP MED / OSPF Metric
  118. SetASPrepend int `json:"set_as_prepend,omitempty"` // AS Path prepend count
  119. SetCommunity string `json:"set_community,omitempty"` // Set BGP community
  120. SetNextHop string `json:"set_next_hop,omitempty"` // Custom Next Hop IP
  121. SetDistance int `json:"set_distance,omitempty"` // Administrative Distance
  122. Disabled bool `json:"disabled"`
  123. Comment string `json:"comment,omitempty"`
  124. }
  125. // DynamicRoutingSummary aggregates status for dashboard & badges
  126. type DynamicRoutingSummary struct {
  127. BGPEnabled bool `json:"bgp_enabled"`
  128. BGPRunning bool `json:"bgp_running"`
  129. BGPPeerCount int `json:"bgp_peer_count"`
  130. BGPEstablishedCount int `json:"bgp_established_count"`
  131. OSPFEnabled bool `json:"ospf_enabled"`
  132. OSPFRunning bool `json:"ospf_running"`
  133. OSPFNeighborCount int `json:"ospf_neighbor_count"`
  134. OSPFAdjacentCount int `json:"ospf_adjacent_count"`
  135. RoutingFilterCount int `json:"routing_filter_count"`
  136. }
  137. // DynamicConfig stores all dynamic routing data on disk
  138. type DynamicConfig struct {
  139. BGPInstance BGPInstance `json:"bgp_instance"`
  140. BGPPeers []BGPPeer `json:"bgp_peers"`
  141. BGPNetworks []BGPNetwork `json:"bgp_networks"`
  142. OSPFInstance OSPFInstance `json:"ospf_instance"`
  143. OSPFAreas []OSPFArea `json:"ospf_areas"`
  144. OSPFInterfaces []OSPFInterface `json:"ospf_interfaces"`
  145. RoutingFilters []RoutingFilterRule `json:"routing_filters"`
  146. }