mqtt.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. }
  45. type OldPeerUpdateFields struct {
  46. NodePeers []wgtypes.PeerConfig `json:"peers" bson:"peers" yaml:"peers"`
  47. OldPeers []wgtypes.PeerConfig `json:"Peers"`
  48. EndpointDetection bool `json:"endpoint_detection"`
  49. }
  50. type FwRule struct {
  51. SrcIP net.IPNet `json:"src_ip"`
  52. DstIP net.IPNet `json:"dst_ip"`
  53. AllowedProtocol Protocol `json:"allowed_protocols"` // tcp, udp, etc.
  54. AllowedPorts []string `json:"allowed_ports"`
  55. Allow bool `json:"allow"`
  56. }
  57. // IngressInfo - struct for ingress info
  58. type IngressInfo struct {
  59. IngressID string `json:"ingress_id"`
  60. Network net.IPNet `json:"network"`
  61. Network6 net.IPNet `json:"network6"`
  62. StaticNodeIps []net.IP `json:"static_node_ips"`
  63. Rules []FwRule `json:"rules"`
  64. EgressRanges []net.IPNet `json:"egress_ranges"`
  65. EgressRanges6 []net.IPNet `json:"egress_ranges6"`
  66. }
  67. // EgressInfo - struct for egress info
  68. type EgressInfo struct {
  69. EgressID string `json:"egress_id" yaml:"egress_id"`
  70. Network net.IPNet `json:"network" yaml:"network"`
  71. EgressGwAddr net.IPNet `json:"egress_gw_addr" yaml:"egress_gw_addr"`
  72. Network6 net.IPNet `json:"network6" yaml:"network6"`
  73. EgressGwAddr6 net.IPNet `json:"egress_gw_addr6" yaml:"egress_gw_addr6"`
  74. EgressGWCfg EgressGatewayRequest `json:"egress_gateway_cfg" yaml:"egress_gateway_cfg"`
  75. EgressFwRules map[string]AclRule `json:"egress_fw_rules"`
  76. }
  77. // EgressNetworkRoutes - struct for egress network routes for adding routes to peer's interface
  78. type EgressNetworkRoutes struct {
  79. PeerKey string `json:"peer_key"`
  80. EgressGwAddr net.IPNet `json:"egress_gw_addr" yaml:"egress_gw_addr"`
  81. EgressGwAddr6 net.IPNet `json:"egress_gw_addr6" yaml:"egress_gw_addr6"`
  82. NodeAddr net.IPNet `json:"node_addr"`
  83. NodeAddr6 net.IPNet `json:"node_addr6"`
  84. EgressRanges []string `json:"egress_ranges"`
  85. EgressRangesWithMetric []EgressRangeMetric `json:"egress_ranges_metric"`
  86. Network string `json:"network"`
  87. }
  88. // PeerRouteInfo - struct for peer info for an ext. client
  89. type PeerRouteInfo struct {
  90. PeerAddr net.IPNet `json:"peer_addr" yaml:"peer_addr"`
  91. PeerKey string `json:"peer_key" yaml:"peer_key"`
  92. Allow bool `json:"allow" yaml:"allow"`
  93. ID string `json:"id,omitempty" yaml:"id,omitempty"`
  94. }
  95. // ExtClientInfo - struct for ext. client and it's peers
  96. type ExtClientInfo struct {
  97. IngGwAddr net.IPNet `json:"ingress_gw_addr" yaml:"ingress_gw_addr"`
  98. Network net.IPNet `json:"network" yaml:"network"`
  99. Masquerade bool `json:"masquerade" yaml:"masquerade"`
  100. ExtPeerAddr net.IPNet `json:"ext_peer_addr" yaml:"ext_peer_addr"`
  101. ExtPeerKey string `json:"ext_peer_key" yaml:"ext_peer_key"`
  102. Peers map[string]PeerRouteInfo `json:"peers" yaml:"peers"`
  103. }
  104. // KeyUpdate - key update struct
  105. type KeyUpdate struct {
  106. Network string `json:"network" bson:"network"`
  107. Interface string `json:"interface" bson:"interface"`
  108. }
  109. // FwUpdate - struct for firewall updates
  110. type FwUpdate struct {
  111. AllowAll bool `json:"allow_all"`
  112. AllowedNetworks []AclRule `json:"networks"`
  113. IsEgressGw bool `json:"is_egress_gw"`
  114. IsIngressGw bool `json:"is_ingress_gw"`
  115. EgressInfo map[string]EgressInfo `json:"egress_info"`
  116. IngressInfo map[string]IngressInfo `json:"ingress_info"`
  117. AclRules map[string]AclRule `json:"acl_rules"`
  118. }
  119. // FailOverMeReq - struct for failover req
  120. type FailOverMeReq struct {
  121. NodeID string `json:"node_id"`
  122. }
  123. // AutoRelayMeReq - struct for autorelay req
  124. type AutoRelayMeReq struct {
  125. NodeID string `json:"node_id"`
  126. AutoRelayGwID string `json:"auto_relay_gw_id"`
  127. }