mqtt.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package models
  2. import (
  3. "net"
  4. "golang.zx2c4.com/wireguard/wgctrl/wgtypes"
  5. )
  6. // HostPeerUpdate - struct for host peer updates
  7. type HostPeerUpdate struct {
  8. Host Host `json:"host"`
  9. ChangeDefaultGw bool `json:"change_default_gw"`
  10. DefaultGwIp net.IP `json:"default_gw_ip"`
  11. IsInternetGw bool `json:"is_inet_gw"`
  12. NodeAddrs []net.IPNet `json:"nodes_addrs"`
  13. Server string `json:"server"`
  14. ServerVersion string `json:"serverversion"`
  15. ServerAddrs []ServerAddr `json:"serveraddrs"`
  16. NodePeers []wgtypes.PeerConfig `json:"node_peers"`
  17. Peers []wgtypes.PeerConfig `json:"host_peers"`
  18. PeerIDs PeerMap `json:"peerids"`
  19. HostNetworkInfo HostInfoMap `json:"host_network_info,omitempty"`
  20. EgressRoutes []EgressNetworkRoutes `json:"egress_network_routes"`
  21. FwUpdate FwUpdate `json:"fw_update"`
  22. ReplacePeers bool `json:"replace_peers"`
  23. ServerConfig
  24. OldPeerUpdateFields
  25. }
  26. type OldPeerUpdateFields struct {
  27. NodePeers []wgtypes.PeerConfig `json:"peers" bson:"peers" yaml:"peers"`
  28. OldPeers []wgtypes.PeerConfig `json:"Peers"`
  29. EndpointDetection bool `json:"endpoint_detection"`
  30. }
  31. type FwRule struct {
  32. SrcIP net.IPNet `json:"src_ip"`
  33. DstIP net.IPNet `json:"dst_ip"`
  34. AllowedProtocol Protocol `json:"allowed_protocols"` // tcp, udp, etc.
  35. AllowedPorts []string `json:"allowed_ports"`
  36. Allow bool `json:"allow"`
  37. }
  38. // IngressInfo - struct for ingress info
  39. type IngressInfo struct {
  40. IngressID string `json:"ingress_id"`
  41. Network net.IPNet `json:"network"`
  42. Network6 net.IPNet `json:"network6"`
  43. StaticNodeIps []net.IP `json:"static_node_ips"`
  44. Rules []FwRule `json:"rules"`
  45. AllowAll bool `json:"allow_all"`
  46. EgressRanges []net.IPNet `json:"egress_ranges"`
  47. EgressRanges6 []net.IPNet `json:"egress_ranges6"`
  48. }
  49. // EgressInfo - struct for egress info
  50. type EgressInfo struct {
  51. EgressID string `json:"egress_id" yaml:"egress_id"`
  52. Network net.IPNet `json:"network" yaml:"network"`
  53. EgressGwAddr net.IPNet `json:"egress_gw_addr" yaml:"egress_gw_addr"`
  54. Network6 net.IPNet `json:"network6" yaml:"network6"`
  55. EgressGwAddr6 net.IPNet `json:"egress_gw_addr6" yaml:"egress_gw_addr6"`
  56. EgressGWCfg EgressGatewayRequest `json:"egress_gateway_cfg" yaml:"egress_gateway_cfg"`
  57. }
  58. // EgressNetworkRoutes - struct for egress network routes for adding routes to peer's interface
  59. type EgressNetworkRoutes struct {
  60. EgressGwAddr net.IPNet `json:"egress_gw_addr" yaml:"egress_gw_addr"`
  61. EgressGwAddr6 net.IPNet `json:"egress_gw_addr6" yaml:"egress_gw_addr6"`
  62. NodeAddr net.IPNet `json:"node_addr"`
  63. NodeAddr6 net.IPNet `json:"node_addr6"`
  64. EgressRanges []string `json:"egress_ranges"`
  65. }
  66. // PeerRouteInfo - struct for peer info for an ext. client
  67. type PeerRouteInfo struct {
  68. PeerAddr net.IPNet `json:"peer_addr" yaml:"peer_addr"`
  69. PeerKey string `json:"peer_key" yaml:"peer_key"`
  70. Allow bool `json:"allow" yaml:"allow"`
  71. ID string `json:"id,omitempty" yaml:"id,omitempty"`
  72. }
  73. // ExtClientInfo - struct for ext. client and it's peers
  74. type ExtClientInfo struct {
  75. IngGwAddr net.IPNet `json:"ingress_gw_addr" yaml:"ingress_gw_addr"`
  76. Network net.IPNet `json:"network" yaml:"network"`
  77. Masquerade bool `json:"masquerade" yaml:"masquerade"`
  78. ExtPeerAddr net.IPNet `json:"ext_peer_addr" yaml:"ext_peer_addr"`
  79. ExtPeerKey string `json:"ext_peer_key" yaml:"ext_peer_key"`
  80. Peers map[string]PeerRouteInfo `json:"peers" yaml:"peers"`
  81. }
  82. // KeyUpdate - key update struct
  83. type KeyUpdate struct {
  84. Network string `json:"network" bson:"network"`
  85. Interface string `json:"interface" bson:"interface"`
  86. }
  87. // FwUpdate - struct for firewall updates
  88. type FwUpdate struct {
  89. AllowAll bool `json:"allow_all"`
  90. AllowedNetworks []net.IPNet `json:"networks"`
  91. IsEgressGw bool `json:"is_egress_gw"`
  92. IsIngressGw bool `json:"is_ingress_gw"`
  93. EgressInfo map[string]EgressInfo `json:"egress_info"`
  94. IngressInfo map[string]IngressInfo `json:"ingress_info"`
  95. AclRules map[string]AclRule `json:"acl_rules"`
  96. }
  97. // FailOverMeReq - struct for failover req
  98. type FailOverMeReq struct {
  99. NodeID string `json:"node_id"`
  100. }