types.go 6.9 KB

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