types.go 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. Name *string `json:"name,omitempty"`
  55. State *string `json:"state,omitempty"` // "up" or "down"
  56. MTU *int `json:"mtu,omitempty"`
  57. Role *string `json:"role,omitempty"`
  58. Description *string `json:"description,omitempty"`
  59. }
  60. // RenameInterfaceRequest specifies the new name for an interface.
  61. type RenameInterfaceRequest struct {
  62. Name string `json:"name,omitempty"`
  63. NewName string `json:"new_name,omitempty"`
  64. }
  65. // AddIPRequest defines the payload to add an IP address to an interface.
  66. type AddIPRequest struct {
  67. IP string `json:"ip"` // CIDR, e.g. "192.168.20.1/24"
  68. }
  69. // InterfaceMetadata stores custom persistent labels per interface.
  70. type InterfaceMetadata struct {
  71. Role string `json:"role"`
  72. Description string `json:"description"`
  73. }
  74. // MetadataStore is written to disk to preserve user labels across restarts.
  75. type MetadataStore struct {
  76. Interfaces map[string]InterfaceMetadata `json:"interfaces"`
  77. }