types.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package aerotun
  2. import "time"
  3. const (
  4. ProtocolName = "AeroTUN"
  5. ProtocolVersion = 2
  6. DefaultMTU = 1420
  7. DefaultPort = 51830
  8. MagicHeader = 0xAE70 // "AE"
  9. FlagCompressedLZ4 = 0x01
  10. FlagKeepalive = 0x02
  11. StoragePath = "/etc/proxmox-router/vpn/aerotun_instances.json"
  12. )
  13. // TunnelInstance represents a configured AeroTUN interface and its live status
  14. type TunnelInstance struct {
  15. Backend string `json:"backend,omitempty"`
  16. Handshakes uint64 `json:"handshakes,omitempty"`
  17. Protocol int `json:"protocol_version,omitempty"`
  18. PrivateKey string `json:"private_key,omitempty"`
  19. PublicKey string `json:"public_key,omitempty"`
  20. PeerPublicKey string `json:"peer_public_key,omitempty"`
  21. AllowedIPs []string `json:"allowed_ips,omitempty"`
  22. HasPSK bool `json:"has_psk,omitempty"`
  23. HasPrivateKey bool `json:"has_private_key,omitempty"`
  24. ID string `json:"id"`
  25. Name string `json:"name"` // e.g. "aerotun0"
  26. Mode string `json:"mode"` // "server" (listen) or "client" (dial)
  27. ListenPort int `json:"listen_port"` // UDP port to bind
  28. RemoteEndpoint string `json:"remote_endpoint"` // "host:port" (used if client or static peer)
  29. LocalAddress string `json:"local_address"` // CIDR e.g. "10.99.0.1/24"
  30. PeerAddress string `json:"peer_address"` // Peer CIDR e.g. "10.99.0.2/24"
  31. PSK string `json:"psk,omitempty"` // 32-byte hex/base64 pre-shared key
  32. Compression bool `json:"compression"` // Enable adaptive LZ4
  33. MTU int `json:"mtu"` // e.g. 1420
  34. DefaultRoute bool `json:"default_route"` // Route 0.0.0.0/0 via this tunnel
  35. Disabled bool `json:"disabled"` // MikroTik 'X' flag
  36. Comment string `json:"comment,omitempty"`
  37. CreatedAt time.Time `json:"created_at"`
  38. // Runtime state & telemetry
  39. Connected bool `json:"connected"`
  40. LastError string `json:"last_error,omitempty"`
  41. DroppedPackets uint64 `json:"dropped_packets"`
  42. AuthFailures uint64 `json:"auth_failures"`
  43. ReplayDrops uint64 `json:"replay_drops"`
  44. Running bool `json:"running"`
  45. ActivePeerEndpoint string `json:"active_peer_endpoint,omitempty"`
  46. LastHandshake string `json:"last_handshake,omitempty"`
  47. RxBytes uint64 `json:"rx_bytes"`
  48. TxBytes uint64 `json:"tx_bytes"`
  49. RawBytesIn uint64 `json:"raw_bytes_in"` // uncompressed RX payload
  50. RawBytesOut uint64 `json:"raw_bytes_out"` // uncompressed TX payload
  51. WireBytesIn uint64 `json:"wire_bytes_in"` // actual wire RX
  52. WireBytesOut uint64 `json:"wire_bytes_out"` // actual wire TX
  53. SavedBytes uint64 `json:"saved_bytes"` // Bandwidth saved through compression
  54. CompressionRatio string `json:"compression_ratio,omitempty"`
  55. PacketsRx uint64 `json:"packets_rx"`
  56. PacketsTx uint64 `json:"packets_tx"`
  57. CompressedPackets uint64 `json:"compressed_packets"`
  58. RawPackets uint64 `json:"raw_packets"`
  59. }
  60. // SummaryStats aggregates performance across all AeroTUN tunnels
  61. type SummaryStats struct {
  62. TotalTunnels int `json:"total_tunnels"`
  63. ActiveTunnels int `json:"active_tunnels"`
  64. TotalRxBytes uint64 `json:"total_rx_bytes"`
  65. TotalTxBytes uint64 `json:"total_tx_bytes"`
  66. TotalSavedBytes uint64 `json:"total_saved_bytes"`
  67. AverageRatio string `json:"average_ratio"`
  68. AlgorithmCrypto string `json:"algorithm_crypto"`
  69. AlgorithmCompress string `json:"algorithm_compress"`
  70. }