types.go 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package network
  2. // InterfaceInfo holds comprehensive details about a network interface.
  3. type InterfaceInfo struct {
  4. Index int `json:"index"`
  5. Name string `json:"name"`
  6. Type string `json:"type"` // "ethernet", "vlan", "loopback", "bridge", "dummy", etc.
  7. State string `json:"state"` // "UP", "DOWN", "UNKNOWN"
  8. OperState string `json:"operstate"` // "up", "down", "unknown"
  9. MAC string `json:"mac"`
  10. MTU int `json:"mtu"`
  11. IPv4 []string `json:"ipv4"` // e.g. ["192.168.1.1/24"]
  12. IPv6 []string `json:"ipv6"` // e.g. ["fe80::1/64"]
  13. Flags []string `json:"flags"`
  14. IsVLAN bool `json:"is_vlan"`
  15. VlanID int `json:"vlan_id,omitempty"`
  16. ParentName string `json:"parent_name,omitempty"`
  17. ParentIndex int `json:"parent_index,omitempty"`
  18. Role string `json:"role"` // "WAN", "LAN", "DMZ", "GUEST", "IOT", "MGMT"
  19. Description string `json:"description"`
  20. Stats NetStats `json:"stats"`
  21. Rate TrafficRate `json:"rate"`
  22. }
  23. // NetStats holds packet and byte counters.
  24. type NetStats struct {
  25. RxBytes uint64 `json:"rx_bytes"`
  26. TxBytes uint64 `json:"tx_bytes"`
  27. RxPackets uint64 `json:"rx_packets"`
  28. TxPackets uint64 `json:"tx_packets"`
  29. RxErrors uint64 `json:"rx_errors"`
  30. TxErrors uint64 `json:"tx_errors"`
  31. RxDropped uint64 `json:"rx_dropped"`
  32. TxDropped uint64 `json:"tx_dropped"`
  33. }
  34. // TrafficRate represents real-time network throughput.
  35. type TrafficRate struct {
  36. RxBytesPerSec float64 `json:"rx_bytes_sec"`
  37. TxBytesPerSec float64 `json:"tx_bytes_sec"`
  38. RxHuman string `json:"rx_human"`
  39. TxHuman string `json:"tx_human"`
  40. }
  41. // CreateVLANRequest specifies parameters for creating an 802.1Q VLAN interface.
  42. type CreateVLANRequest struct {
  43. ParentName string `json:"parent_name"` // e.g. "eth0"
  44. VlanID int `json:"vlan_id"` // 1 - 4094
  45. Name string `json:"name"` // optional, e.g. "eth0.10" or "vlan10"
  46. IPAddress string `json:"ip_address"` // optional CIDR, e.g. "192.168.10.1/24"
  47. MTU int `json:"mtu"` // defaults to 1500
  48. Role string `json:"role"` // "LAN", "DMZ", "GUEST", "IOT"
  49. Description string `json:"description"` // User-friendly label
  50. AutoUp bool `json:"auto_up"` // bring interface UP immediately
  51. }
  52. // UpdateInterfaceRequest specifies parameters for updating interface attributes.
  53. type UpdateInterfaceRequest struct {
  54. State *string `json:"state,omitempty"` // "up" or "down"
  55. MTU *int `json:"mtu,omitempty"`
  56. Role *string `json:"role,omitempty"`
  57. Description *string `json:"description,omitempty"`
  58. }
  59. // AddIPRequest defines the payload to add an IP address to an interface.
  60. type AddIPRequest struct {
  61. IP string `json:"ip"` // CIDR, e.g. "192.168.20.1/24"
  62. }
  63. // InterfaceMetadata stores custom persistent labels per interface.
  64. type InterfaceMetadata struct {
  65. Role string `json:"role"`
  66. Description string `json:"description"`
  67. }
  68. // MetadataStore is written to disk to preserve user labels across restarts.
  69. type MetadataStore struct {
  70. Interfaces map[string]InterfaceMetadata `json:"interfaces"`
  71. }