hcnpolicy.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. package hcn
  2. import "encoding/json"
  3. // EndpointPolicyType are the potential Policies that apply to Endpoints.
  4. type EndpointPolicyType string
  5. // EndpointPolicyType const
  6. const (
  7. PortMapping EndpointPolicyType = "PortMapping"
  8. ACL EndpointPolicyType = "ACL"
  9. QOS EndpointPolicyType = "QOS"
  10. L2Driver EndpointPolicyType = "L2Driver"
  11. OutBoundNAT EndpointPolicyType = "OutBoundNAT"
  12. SDNRoute EndpointPolicyType = "SDNRoute"
  13. L4Proxy EndpointPolicyType = "L4Proxy"
  14. PortName EndpointPolicyType = "PortName"
  15. EncapOverhead EndpointPolicyType = "EncapOverhead"
  16. // Endpoint and Network have InterfaceConstraint and ProviderAddress
  17. NetworkProviderAddress EndpointPolicyType = "ProviderAddress"
  18. NetworkInterfaceConstraint EndpointPolicyType = "InterfaceConstraint"
  19. )
  20. // EndpointPolicy is a collection of Policy settings for an Endpoint.
  21. type EndpointPolicy struct {
  22. Type EndpointPolicyType `json:""`
  23. Settings json.RawMessage `json:",omitempty"`
  24. }
  25. // NetworkPolicyType are the potential Policies that apply to Networks.
  26. type NetworkPolicyType string
  27. // NetworkPolicyType const
  28. const (
  29. SourceMacAddress NetworkPolicyType = "SourceMacAddress"
  30. NetAdapterName NetworkPolicyType = "NetAdapterName"
  31. VSwitchExtension NetworkPolicyType = "VSwitchExtension"
  32. DrMacAddress NetworkPolicyType = "DrMacAddress"
  33. AutomaticDNS NetworkPolicyType = "AutomaticDNS"
  34. InterfaceConstraint NetworkPolicyType = "InterfaceConstraint"
  35. ProviderAddress NetworkPolicyType = "ProviderAddress"
  36. RemoteSubnetRoute NetworkPolicyType = "RemoteSubnetRoute"
  37. HostRoute NetworkPolicyType = "HostRoute"
  38. )
  39. // NetworkPolicy is a collection of Policy settings for a Network.
  40. type NetworkPolicy struct {
  41. Type NetworkPolicyType `json:""`
  42. Settings json.RawMessage `json:",omitempty"`
  43. }
  44. // SubnetPolicyType are the potential Policies that apply to Subnets.
  45. type SubnetPolicyType string
  46. // SubnetPolicyType const
  47. const (
  48. VLAN SubnetPolicyType = "VLAN"
  49. VSID SubnetPolicyType = "VSID"
  50. )
  51. // SubnetPolicy is a collection of Policy settings for a Subnet.
  52. type SubnetPolicy struct {
  53. Type SubnetPolicyType `json:""`
  54. Settings json.RawMessage `json:",omitempty"`
  55. }
  56. /// Endpoint Policy objects
  57. // PortMappingPolicySetting defines Port Mapping (NAT)
  58. type PortMappingPolicySetting struct {
  59. Protocol uint32 `json:",omitempty"` // EX: TCP = 6, UDP = 17
  60. InternalPort uint16 `json:",omitempty"`
  61. ExternalPort uint16 `json:",omitempty"`
  62. VIP string `json:",omitempty"`
  63. }
  64. // ActionType associated with ACLs. Value is either Allow or Block.
  65. type ActionType string
  66. // DirectionType associated with ACLs. Value is either In or Out.
  67. type DirectionType string
  68. // RuleType associated with ACLs. Value is either Host (WFP) or Switch (VFP).
  69. type RuleType string
  70. const (
  71. // Allow traffic
  72. ActionTypeAllow ActionType = "Allow"
  73. // Block traffic
  74. ActionTypeBlock ActionType = "Block"
  75. // In is traffic coming to the Endpoint
  76. DirectionTypeIn DirectionType = "In"
  77. // Out is traffic leaving the Endpoint
  78. DirectionTypeOut DirectionType = "Out"
  79. // Host creates WFP (Windows Firewall) rules
  80. RuleTypeHost RuleType = "Host"
  81. // Switch creates VFP (Virtual Filter Platform) rules
  82. RuleTypeSwitch RuleType = "Switch"
  83. )
  84. // AclPolicySetting creates firewall rules on an endpoint
  85. type AclPolicySetting struct {
  86. Protocols string `json:",omitempty"` // EX: 6 (TCP), 17 (UDP), 1 (ICMPv4), 58 (ICMPv6), 2 (IGMP)
  87. Action ActionType `json:","`
  88. Direction DirectionType `json:","`
  89. LocalAddresses string `json:",omitempty"`
  90. RemoteAddresses string `json:",omitempty"`
  91. LocalPorts string `json:",omitempty"`
  92. RemotePorts string `json:",omitempty"`
  93. RuleType RuleType `json:",omitempty"`
  94. Priority uint16 `json:",omitempty"`
  95. }
  96. // QosPolicySetting sets Quality of Service bandwidth caps on an Endpoint.
  97. type QosPolicySetting struct {
  98. MaximumOutgoingBandwidthInBytes uint64
  99. }
  100. // OutboundNatPolicySetting sets outbound Network Address Translation on an Endpoint.
  101. type OutboundNatPolicySetting struct {
  102. VirtualIP string `json:",omitempty"`
  103. Exceptions []string `json:",omitempty"`
  104. }
  105. // SDNRoutePolicySetting sets SDN Route on an Endpoint.
  106. type SDNRoutePolicySetting struct {
  107. DestinationPrefix string `json:",omitempty"`
  108. NextHop string `json:",omitempty"`
  109. NeedEncap bool `json:",omitempty"`
  110. }
  111. // L4ProxyPolicySetting sets Layer-4 Proxy on an endpoint.
  112. type L4ProxyPolicySetting struct {
  113. IP string `json:",omitempty"`
  114. Port string `json:",omitempty"`
  115. Protocol uint32 `json:",omitempty"` // EX: TCP = 6, UDP = 17
  116. ExceptionList []string `json:",omitempty"`
  117. Destination string `json:","`
  118. OutboundNat bool `json:",omitempty"`
  119. }
  120. // PortnameEndpointPolicySetting sets the port name for an endpoint.
  121. type PortnameEndpointPolicySetting struct {
  122. Name string `json:",omitempty"`
  123. }
  124. // EncapOverheadEndpointPolicySetting sets the encap overhead for an endpoint.
  125. type EncapOverheadEndpointPolicySetting struct {
  126. Overhead uint16 `json:",omitempty"`
  127. }
  128. /// Endpoint and Network Policy objects
  129. // ProviderAddressEndpointPolicySetting sets the PA for an endpoint.
  130. type ProviderAddressEndpointPolicySetting struct {
  131. ProviderAddress string `json:",omitempty"`
  132. }
  133. // InterfaceConstraintPolicySetting limits an Endpoint or Network to a specific Nic.
  134. type InterfaceConstraintPolicySetting struct {
  135. InterfaceGuid string `json:",omitempty"`
  136. InterfaceLuid uint64 `json:",omitempty"`
  137. InterfaceIndex uint32 `json:",omitempty"`
  138. InterfaceMediaType uint32 `json:",omitempty"`
  139. InterfaceAlias string `json:",omitempty"`
  140. InterfaceDescription string `json:",omitempty"`
  141. }
  142. /// Network Policy objects
  143. // SourceMacAddressNetworkPolicySetting sets source MAC for a network.
  144. type SourceMacAddressNetworkPolicySetting struct {
  145. SourceMacAddress string `json:",omitempty"`
  146. }
  147. // NetAdapterNameNetworkPolicySetting sets network adapter of a network.
  148. type NetAdapterNameNetworkPolicySetting struct {
  149. NetworkAdapterName string `json:",omitempty"`
  150. }
  151. // VSwitchExtensionNetworkPolicySetting enables/disabled VSwitch extensions for a network.
  152. type VSwitchExtensionNetworkPolicySetting struct {
  153. ExtensionID string `json:",omitempty"`
  154. Enable bool `json:",omitempty"`
  155. }
  156. // DrMacAddressNetworkPolicySetting sets the DR MAC for a network.
  157. type DrMacAddressNetworkPolicySetting struct {
  158. Address string `json:",omitempty"`
  159. }
  160. // AutomaticDNSNetworkPolicySetting enables/disables automatic DNS on a network.
  161. type AutomaticDNSNetworkPolicySetting struct {
  162. Enable bool `json:",omitempty"`
  163. }
  164. /// Subnet Policy objects
  165. // VlanPolicySetting isolates a subnet with VLAN tagging.
  166. type VlanPolicySetting struct {
  167. IsolationId uint32 `json:","`
  168. }
  169. // VsidPolicySetting isolates a subnet with VSID tagging.
  170. type VsidPolicySetting struct {
  171. IsolationId uint32 `json:","`
  172. }
  173. // RemoteSubnetRoutePolicySetting creates remote subnet route rules on a network
  174. type RemoteSubnetRoutePolicySetting struct {
  175. DestinationPrefix string
  176. IsolationId uint16
  177. ProviderAddress string
  178. DistributedRouterMacAddress string
  179. }