server_types.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package dhcp
  2. import "time"
  3. // DHCPServerInstance represents an interface-bound DHCP server
  4. type DHCPServerInstance struct {
  5. ID string `json:"id"`
  6. Name string `json:"name"` // e.g. "dhcp1", "defconf"
  7. Interface string `json:"interface"` // e.g. "bridge1", "eth0"
  8. Network string `json:"network"` // Assigned DHCP Network CIDR or ID e.g. "192.168.88.0/24"
  9. LeaseTime string `json:"lease_time"` // e.g. "12h", "1d", "30m"
  10. AddressPool string `json:"address_pool"` // e.g. "192.168.88.10-192.168.88.254"
  11. Authoritative bool `json:"authoritative"` // default true
  12. Disabled bool `json:"disabled"` // 'X' flag
  13. Comment string `json:"comment,omitempty"`
  14. // Runtime telemetry
  15. Running bool `json:"running"`
  16. ActiveLeases int `json:"active_leases"`
  17. }
  18. // DHCPNetwork defines options and gateway for a specific subnet (/ip dhcp-server network)
  19. type DHCPNetwork struct {
  20. ID string `json:"id"`
  21. Address string `json:"address"` // CIDR e.g. "192.168.88.0/24"
  22. Gateway string `json:"gateway"` // Option 3 (Router IP)
  23. Netmask string `json:"netmask"` // Netmask e.g. "255.255.255.0" or "24"
  24. DNSServers []string `json:"dns_servers"` // Option 6
  25. Domain string `json:"domain"` // Option 15
  26. NTPServers []string `json:"ntp_servers"` // Option 42 (requested by user)
  27. NextServer string `json:"next_server"` // Option 66 / TFTP server IP/hostname (requested by user)
  28. BootFileName string `json:"boot_file_name"`// Option 67 / PXE boot filename
  29. WINSServers []string `json:"wins_servers"` // Option 44
  30. DHCPOptions []string `json:"dhcp_options"` // Linked custom option IDs
  31. Comment string `json:"comment,omitempty"`
  32. }
  33. // DHCPLease represents an active dynamic lease or static reservation (/ip dhcp-server lease)
  34. type DHCPLease struct {
  35. ID string `json:"id"`
  36. Address string `json:"address"` // Assigned IP
  37. MACAddress string `json:"mac_address"` // Format "aa:bb:cc:dd:ee:ff"
  38. ClientID string `json:"client_id,omitempty"`
  39. Server string `json:"server"` // Server name or "all"
  40. HostName string `json:"hostname"`
  41. ExpiresIn string `json:"expires_in"` // e.g. "11h 45m" or "never"
  42. ExpiresAt time.Time `json:"expires_at"`
  43. Dynamic bool `json:"dynamic"` // true=from dnsmasq.leases, false=static reservation
  44. Status string `json:"status"` // "bound", "static", "waiting"
  45. Disabled bool `json:"disabled"`
  46. Comment string `json:"comment,omitempty"`
  47. }
  48. // DHCPOption represents a raw or typed custom DHCP option (/ip dhcp-server option)
  49. type DHCPOption struct {
  50. ID string `json:"id"`
  51. Name string `json:"name"` // e.g. "unifi-controller", "voip-tftp"
  52. Code int `json:"code"` // Option code (1 - 254)
  53. Value string `json:"value"` // Raw IP, text, hex or option string
  54. Comment string `json:"comment,omitempty"`
  55. }
  56. // DHCPServerSummary provides aggregated statistics for KPI cards & sidebar badges
  57. type DHCPServerSummary struct {
  58. TotalServers int `json:"total_servers"`
  59. ActiveServers int `json:"active_servers"`
  60. TotalNetworks int `json:"total_networks"`
  61. ActiveLeases int `json:"active_leases"`
  62. StaticLeases int `json:"static_leases"`
  63. TotalOptions int `json:"total_options"`
  64. }
  65. // DHCPServerConfigStore wraps JSON persistence
  66. type DHCPServerConfigStore struct {
  67. Servers []DHCPServerInstance `json:"servers"`
  68. Networks []DHCPNetwork `json:"networks"`
  69. StaticLeases []DHCPLease `json:"static_leases"`
  70. Options []DHCPOption `json:"options"`
  71. }
  72. // DHCPServerSetupRequest is used by the MikroTik-style 1-click DHCP Setup Wizard
  73. type DHCPServerSetupRequest struct {
  74. Interface string `json:"interface"` // e.g. "bridge1"
  75. AddressSpace string `json:"address_space"` // e.g. "192.168.88.0/24"
  76. Gateway string `json:"gateway"` // e.g. "192.168.88.1"
  77. AddressPool string `json:"address_pool"` // e.g. "192.168.88.10-192.168.88.254"
  78. DNSServers []string `json:"dns_servers"` // e.g. ["192.168.88.1", "1.1.1.1"]
  79. LeaseTime string `json:"lease_time"` // e.g. "12h"
  80. Domain string `json:"domain,omitempty"` // e.g. "lan"
  81. NTPServers []string `json:"ntp_servers,omitempty"` // e.g. ["192.168.88.1"]
  82. NextServer string `json:"next_server,omitempty"` // e.g. "192.168.88.50"
  83. BootFileName string `json:"boot_file_name,omitempty"`// e.g. "pxelinux.0"
  84. }