mqtt.go 4.6 KB

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