mqtt.go 5.8 KB

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