types.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. Action string `json:"action,omitempty"` // "lookup", "blackhole", "unreachable"
  20. Disabled bool `json:"disabled"` // MikroTik 'X' flag
  21. Comment string `json:"comment,omitempty"`
  22. // Gateway Health Check & Behind-NAT Internet Prober
  23. CheckGateway string `json:"check_gateway,omitempty"` // "none", "ping", "internet"
  24. CheckTarget string `json:"check_target,omitempty"` // Target to probe (e.g. "1.1.1.1", "8.8.8.8")
  25. CheckInterval int `json:"check_interval,omitempty"` // Seconds between probes (default 5)
  26. CheckThreshold int `json:"check_threshold,omitempty"` // Consecutive failures before failover (default 3)
  27. HealthStatus string `json:"health_status,omitempty"` // "online", "offline", "checking", "none"
  28. HealthRTT float64 `json:"health_rtt_ms,omitempty"` // Round trip latency in ms
  29. HealthLossPct float64 `json:"health_loss_pct,omitempty"` // Packet loss percentage
  30. HealthFailCount int `json:"health_fail_count,omitempty"` // Consecutive failures count
  31. HealthLastCheck string `json:"health_last_check,omitempty"` // Formatted timestamp of last probe
  32. // Old values for modifying existing routes
  33. OldDstAddress string `json:"old_dst_address,omitempty"`
  34. OldGateway string `json:"old_gateway,omitempty"`
  35. OldRoutingTable string `json:"old_routing_table,omitempty"`
  36. OldDistance *int `json:"old_distance,omitempty"`
  37. OldInterface string `json:"old_interface,omitempty"`
  38. }
  39. // PolicyRuleItem represents a MikroTik /ip route rule (Linux `ip rule`)
  40. type PolicyRuleItem struct {
  41. ID string `json:"id"`
  42. Priority int `json:"priority"` // Preference number (e.g. 1000, 32766)
  43. SrcAddress string `json:"src_address,omitempty"`
  44. DstAddress string `json:"dst_address,omitempty"`
  45. RoutingMark string `json:"routing_mark,omitempty"` // Matches fwmark set in Mangle
  46. Table string `json:"table"` // Table to lookup (e.g. "wan2", "main")
  47. TableID int `json:"table_id"`
  48. Action string `json:"action"` // lookup, unreachable, blackhole, prohibit
  49. Comment string `json:"comment,omitempty"`
  50. IsDefault bool `json:"is_default,omitempty"`
  51. IsSystem bool `json:"is_system,omitempty"`
  52. }
  53. // RoutingTableItem represents a named routing table in Linux (/etc/iproute2/rt_tables)
  54. type RoutingTableItem struct {
  55. Name string `json:"name"`
  56. TableID int `json:"table_id"`
  57. Comment string `json:"comment,omitempty"`
  58. }