types.go 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package routing
  2. // RouteItem represents a MikroTik-style /ip route entry
  3. type RouteItem struct {
  4. ID string `json:"id"`
  5. DstAddress string `json:"dst_address"` // CIDR e.g. "0.0.0.0/0", "192.168.10.0/24"
  6. Gateway string `json:"gateway"` // Gateway IP e.g. "192.168.1.1" or interface "wg0"
  7. Interface string `json:"interface"` // Output device
  8. Distance int `json:"distance"` // Metric / Administrative Distance
  9. Protocol string `json:"protocol,omitempty"` // Protocol e.g. "bgp", "ospf", "static", "connected", "dhcp"
  10. RoutingTable string `json:"routing_table"` // Table name e.g. "main", "wan2", "vpn_out"
  11. TableID int `json:"table_id"`
  12. Active bool `json:"active"` // MikroTik 'A' flag
  13. Dynamic bool `json:"dynamic"` // MikroTik 'D' flag (kernel learned)
  14. Connect bool `json:"connect"` // MikroTik 'C' flag (directly connected interface subnet)
  15. Static bool `json:"static"` // MikroTik 'S' flag (user defined)
  16. ECMP bool `json:"ecmp"` // Equal-Cost Multi-Path route (MikroTik 'E' flag)
  17. Multicast bool `json:"multicast"` // Multicast / IGMP route (224.0.0.0/4 or kernel multicast)
  18. IsMultiPath bool `json:"is_multipath"` // Linux kernel multipath nexthop
  19. Disabled bool `json:"disabled"` // MikroTik 'X' flag
  20. Comment string `json:"comment,omitempty"`
  21. // Gateway Health Check & Behind-NAT Internet Prober
  22. CheckGateway string `json:"check_gateway,omitempty"` // "none", "ping", "internet"
  23. CheckTarget string `json:"check_target,omitempty"` // Target to probe (e.g. "1.1.1.1", "8.8.8.8")
  24. CheckInterval int `json:"check_interval,omitempty"` // Seconds between probes (default 5)
  25. CheckThreshold int `json:"check_threshold,omitempty"` // Consecutive failures before failover (default 3)
  26. HealthStatus string `json:"health_status,omitempty"` // "online", "offline", "checking", "none"
  27. HealthRTT float64 `json:"health_rtt_ms,omitempty"` // Round trip latency in ms
  28. HealthLossPct float64 `json:"health_loss_pct,omitempty"` // Packet loss percentage
  29. HealthFailCount int `json:"health_fail_count,omitempty"` // Consecutive failures count
  30. HealthLastCheck string `json:"health_last_check,omitempty"` // Formatted timestamp of last probe
  31. // Old values for modifying existing routes
  32. OldDstAddress string `json:"old_dst_address,omitempty"`
  33. OldGateway string `json:"old_gateway,omitempty"`
  34. OldRoutingTable string `json:"old_routing_table,omitempty"`
  35. OldDistance *int `json:"old_distance,omitempty"`
  36. OldInterface string `json:"old_interface,omitempty"`
  37. }
  38. // PolicyRuleItem represents a MikroTik /ip route rule (Linux `ip rule`)
  39. type PolicyRuleItem struct {
  40. ID string `json:"id"`
  41. Priority int `json:"priority"` // Preference number (e.g. 1000, 32766)
  42. SrcAddress string `json:"src_address,omitempty"`
  43. DstAddress string `json:"dst_address,omitempty"`
  44. RoutingMark string `json:"routing_mark,omitempty"` // Matches fwmark set in Mangle
  45. Table string `json:"table"` // Table to lookup (e.g. "wan2", "main")
  46. TableID int `json:"table_id"`
  47. Action string `json:"action"` // lookup, unreachable, blackhole, prohibit
  48. Comment string `json:"comment,omitempty"`
  49. IsDefault bool `json:"is_default,omitempty"`
  50. IsSystem bool `json:"is_system,omitempty"`
  51. }
  52. // RoutingTableItem represents a named routing table in Linux (/etc/iproute2/rt_tables)
  53. type RoutingTableItem struct {
  54. Name string `json:"name"`
  55. TableID int `json:"table_id"`
  56. Comment string `json:"comment,omitempty"`
  57. }