Update cri and cgroup packages
This change includes a cri master bump and a cgroup bump for windows support with cgroup stats and reusing the cgroup metric types. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
		
							
								
								
									
										177
									
								
								vendor/github.com/Microsoft/hcsshim/hcn/hcn.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										177
									
								
								vendor/github.com/Microsoft/hcsshim/hcn/hcn.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,177 @@
 | 
			
		||||
// Package hcn is a shim for the Host Compute Networking (HCN) service, which manages networking for Windows Server
 | 
			
		||||
// containers and Hyper-V containers. Previous to RS5, HCN was referred to as Host Networking Service (HNS).
 | 
			
		||||
package hcn
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"syscall"
 | 
			
		||||
 | 
			
		||||
	"github.com/Microsoft/go-winio/pkg/guid"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
//go:generate go run ../mksyscall_windows.go -output zsyscall_windows.go hcn.go
 | 
			
		||||
 | 
			
		||||
/// HNS V1 API
 | 
			
		||||
 | 
			
		||||
//sys SetCurrentThreadCompartmentId(compartmentId uint32) (hr error) = iphlpapi.SetCurrentThreadCompartmentId
 | 
			
		||||
//sys _hnsCall(method string, path string, object string, response **uint16) (hr error) = vmcompute.HNSCall?
 | 
			
		||||
 | 
			
		||||
/// HCN V2 API
 | 
			
		||||
 | 
			
		||||
// Network
 | 
			
		||||
//sys hcnEnumerateNetworks(query string, networks **uint16, result **uint16) (hr error) = computenetwork.HcnEnumerateNetworks?
 | 
			
		||||
//sys hcnCreateNetwork(id *_guid, settings string, network *hcnNetwork, result **uint16) (hr error) = computenetwork.HcnCreateNetwork?
 | 
			
		||||
//sys hcnOpenNetwork(id *_guid, network *hcnNetwork, result **uint16) (hr error) = computenetwork.HcnOpenNetwork?
 | 
			
		||||
//sys hcnModifyNetwork(network hcnNetwork, settings string, result **uint16) (hr error) = computenetwork.HcnModifyNetwork?
 | 
			
		||||
//sys hcnQueryNetworkProperties(network hcnNetwork, query string, properties **uint16, result **uint16) (hr error) = computenetwork.HcnQueryNetworkProperties?
 | 
			
		||||
//sys hcnDeleteNetwork(id *_guid, result **uint16) (hr error) = computenetwork.HcnDeleteNetwork?
 | 
			
		||||
//sys hcnCloseNetwork(network hcnNetwork) (hr error) = computenetwork.HcnCloseNetwork?
 | 
			
		||||
 | 
			
		||||
// Endpoint
 | 
			
		||||
//sys hcnEnumerateEndpoints(query string, endpoints **uint16, result **uint16) (hr error) = computenetwork.HcnEnumerateEndpoints?
 | 
			
		||||
//sys hcnCreateEndpoint(network hcnNetwork, id *_guid, settings string, endpoint *hcnEndpoint, result **uint16) (hr error) = computenetwork.HcnCreateEndpoint?
 | 
			
		||||
//sys hcnOpenEndpoint(id *_guid, endpoint *hcnEndpoint, result **uint16) (hr error) = computenetwork.HcnOpenEndpoint?
 | 
			
		||||
//sys hcnModifyEndpoint(endpoint hcnEndpoint, settings string, result **uint16) (hr error) = computenetwork.HcnModifyEndpoint?
 | 
			
		||||
//sys hcnQueryEndpointProperties(endpoint hcnEndpoint, query string, properties **uint16, result **uint16) (hr error) = computenetwork.HcnQueryEndpointProperties?
 | 
			
		||||
//sys hcnDeleteEndpoint(id *_guid, result **uint16) (hr error) = computenetwork.HcnDeleteEndpoint?
 | 
			
		||||
//sys hcnCloseEndpoint(endpoint hcnEndpoint) (hr error) = computenetwork.HcnCloseEndpoint?
 | 
			
		||||
 | 
			
		||||
// Namespace
 | 
			
		||||
//sys hcnEnumerateNamespaces(query string, namespaces **uint16, result **uint16) (hr error) = computenetwork.HcnEnumerateNamespaces?
 | 
			
		||||
//sys hcnCreateNamespace(id *_guid, settings string, namespace *hcnNamespace, result **uint16) (hr error) = computenetwork.HcnCreateNamespace?
 | 
			
		||||
//sys hcnOpenNamespace(id *_guid, namespace *hcnNamespace, result **uint16) (hr error) = computenetwork.HcnOpenNamespace?
 | 
			
		||||
//sys hcnModifyNamespace(namespace hcnNamespace, settings string, result **uint16) (hr error) = computenetwork.HcnModifyNamespace?
 | 
			
		||||
//sys hcnQueryNamespaceProperties(namespace hcnNamespace, query string, properties **uint16, result **uint16) (hr error) = computenetwork.HcnQueryNamespaceProperties?
 | 
			
		||||
//sys hcnDeleteNamespace(id *_guid, result **uint16) (hr error) = computenetwork.HcnDeleteNamespace?
 | 
			
		||||
//sys hcnCloseNamespace(namespace hcnNamespace) (hr error) = computenetwork.HcnCloseNamespace?
 | 
			
		||||
 | 
			
		||||
// LoadBalancer
 | 
			
		||||
//sys hcnEnumerateLoadBalancers(query string, loadBalancers **uint16, result **uint16) (hr error) = computenetwork.HcnEnumerateLoadBalancers?
 | 
			
		||||
//sys hcnCreateLoadBalancer(id *_guid, settings string, loadBalancer *hcnLoadBalancer, result **uint16) (hr error) = computenetwork.HcnCreateLoadBalancer?
 | 
			
		||||
//sys hcnOpenLoadBalancer(id *_guid, loadBalancer *hcnLoadBalancer, result **uint16) (hr error) = computenetwork.HcnOpenLoadBalancer?
 | 
			
		||||
//sys hcnModifyLoadBalancer(loadBalancer hcnLoadBalancer, settings string, result **uint16) (hr error) = computenetwork.HcnModifyLoadBalancer?
 | 
			
		||||
//sys hcnQueryLoadBalancerProperties(loadBalancer hcnLoadBalancer, query string, properties **uint16, result **uint16) (hr error) = computenetwork.HcnQueryLoadBalancerProperties?
 | 
			
		||||
//sys hcnDeleteLoadBalancer(id *_guid, result **uint16) (hr error) = computenetwork.HcnDeleteLoadBalancer?
 | 
			
		||||
//sys hcnCloseLoadBalancer(loadBalancer hcnLoadBalancer) (hr error) = computenetwork.HcnCloseLoadBalancer?
 | 
			
		||||
 | 
			
		||||
// Service
 | 
			
		||||
//sys hcnOpenService(service *hcnService, result **uint16) (hr error) = computenetwork.HcnOpenService?
 | 
			
		||||
//sys hcnRegisterServiceCallback(service hcnService, callback int32, context int32, callbackHandle *hcnCallbackHandle) (hr error) = computenetwork.HcnRegisterServiceCallback?
 | 
			
		||||
//sys hcnUnregisterServiceCallback(callbackHandle hcnCallbackHandle) (hr error) = computenetwork.HcnUnregisterServiceCallback?
 | 
			
		||||
//sys hcnCloseService(service hcnService) (hr error) = computenetwork.HcnCloseService?
 | 
			
		||||
 | 
			
		||||
type _guid = guid.GUID
 | 
			
		||||
 | 
			
		||||
type hcnNetwork syscall.Handle
 | 
			
		||||
type hcnEndpoint syscall.Handle
 | 
			
		||||
type hcnNamespace syscall.Handle
 | 
			
		||||
type hcnLoadBalancer syscall.Handle
 | 
			
		||||
type hcnService syscall.Handle
 | 
			
		||||
type hcnCallbackHandle syscall.Handle
 | 
			
		||||
 | 
			
		||||
// SchemaVersion for HCN Objects/Queries.
 | 
			
		||||
type SchemaVersion = Version // hcnglobals.go
 | 
			
		||||
 | 
			
		||||
// HostComputeQueryFlags are passed in to a HostComputeQuery to determine which
 | 
			
		||||
// properties of an object are returned.
 | 
			
		||||
type HostComputeQueryFlags uint32
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	// HostComputeQueryFlagsNone returns an object with the standard properties.
 | 
			
		||||
	HostComputeQueryFlagsNone HostComputeQueryFlags
 | 
			
		||||
	// HostComputeQueryFlagsDetailed returns an object with all properties.
 | 
			
		||||
	HostComputeQueryFlagsDetailed HostComputeQueryFlags = 1
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// HostComputeQuery is the format for HCN queries.
 | 
			
		||||
type HostComputeQuery struct {
 | 
			
		||||
	SchemaVersion SchemaVersion         `json:""`
 | 
			
		||||
	Flags         HostComputeQueryFlags `json:",omitempty"`
 | 
			
		||||
	Filter        string                `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// defaultQuery generates HCN Query.
 | 
			
		||||
// Passed into get/enumerate calls to filter results.
 | 
			
		||||
func defaultQuery() HostComputeQuery {
 | 
			
		||||
	query := HostComputeQuery{
 | 
			
		||||
		SchemaVersion: SchemaVersion{
 | 
			
		||||
			Major: 2,
 | 
			
		||||
			Minor: 0,
 | 
			
		||||
		},
 | 
			
		||||
		Flags: HostComputeQueryFlagsNone,
 | 
			
		||||
	}
 | 
			
		||||
	return query
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func defaultQueryJson() string {
 | 
			
		||||
	query := defaultQuery()
 | 
			
		||||
	queryJson, err := json.Marshal(query)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return ""
 | 
			
		||||
	}
 | 
			
		||||
	return string(queryJson)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// PlatformDoesNotSupportError happens when users are attempting to use a newer shim on an older OS
 | 
			
		||||
func platformDoesNotSupportError(featureName string) error {
 | 
			
		||||
	return fmt.Errorf("Platform does not support feature %s", featureName)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// V2ApiSupported returns an error if the HCN version does not support the V2 Apis.
 | 
			
		||||
func V2ApiSupported() error {
 | 
			
		||||
	supported := GetSupportedFeatures()
 | 
			
		||||
	if supported.Api.V2 {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
	return platformDoesNotSupportError("V2 Api/Schema")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func V2SchemaVersion() SchemaVersion {
 | 
			
		||||
	return SchemaVersion{
 | 
			
		||||
		Major: 2,
 | 
			
		||||
		Minor: 0,
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// RemoteSubnetSupported returns an error if the HCN version does not support Remote Subnet policies.
 | 
			
		||||
func RemoteSubnetSupported() error {
 | 
			
		||||
	supported := GetSupportedFeatures()
 | 
			
		||||
	if supported.RemoteSubnet {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
	return platformDoesNotSupportError("Remote Subnet")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// HostRouteSupported returns an error if the HCN version does not support Host Route policies.
 | 
			
		||||
func HostRouteSupported() error {
 | 
			
		||||
	supported := GetSupportedFeatures()
 | 
			
		||||
	if supported.HostRoute {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
	return platformDoesNotSupportError("Host Route")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DSRSupported returns an error if the HCN version does not support Direct Server Return.
 | 
			
		||||
func DSRSupported() error {
 | 
			
		||||
	supported := GetSupportedFeatures()
 | 
			
		||||
	if supported.DSR {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
	return platformDoesNotSupportError("Direct Server Return (DSR)")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// RequestType are the different operations performed to settings.
 | 
			
		||||
// Used to update the settings of Endpoint/Namespace objects.
 | 
			
		||||
type RequestType string
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	// RequestTypeAdd adds the provided settings object.
 | 
			
		||||
	RequestTypeAdd RequestType = "Add"
 | 
			
		||||
	// RequestTypeRemove removes the provided settings object.
 | 
			
		||||
	RequestTypeRemove RequestType = "Remove"
 | 
			
		||||
	// RequestTypeUpdate replaces settings with the ones provided.
 | 
			
		||||
	RequestTypeUpdate RequestType = "Update"
 | 
			
		||||
	// RequestTypeRefresh refreshes the settings provided.
 | 
			
		||||
	RequestTypeRefresh RequestType = "Refresh"
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										380
									
								
								vendor/github.com/Microsoft/hcsshim/hcn/hcnendpoint.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										380
									
								
								vendor/github.com/Microsoft/hcsshim/hcn/hcnendpoint.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,380 @@
 | 
			
		||||
package hcn
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"errors"
 | 
			
		||||
 | 
			
		||||
	"github.com/Microsoft/go-winio/pkg/guid"
 | 
			
		||||
	"github.com/Microsoft/hcsshim/internal/interop"
 | 
			
		||||
	"github.com/sirupsen/logrus"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// IpConfig is assoicated with an endpoint
 | 
			
		||||
type IpConfig struct {
 | 
			
		||||
	IpAddress    string `json:",omitempty"`
 | 
			
		||||
	PrefixLength uint8  `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// EndpointFlags are special settings on an endpoint.
 | 
			
		||||
type EndpointFlags uint32
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	// EndpointFlagsNone is the default.
 | 
			
		||||
	EndpointFlagsNone EndpointFlags
 | 
			
		||||
	// EndpointFlagsRemoteEndpoint means that an endpoint is on another host.
 | 
			
		||||
	EndpointFlagsRemoteEndpoint EndpointFlags = 1
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// HostComputeEndpoint represents a network endpoint
 | 
			
		||||
type HostComputeEndpoint struct {
 | 
			
		||||
	Id                   string           `json:"ID,omitempty"`
 | 
			
		||||
	Name                 string           `json:",omitempty"`
 | 
			
		||||
	HostComputeNetwork   string           `json:",omitempty"` // GUID
 | 
			
		||||
	HostComputeNamespace string           `json:",omitempty"` // GUID
 | 
			
		||||
	Policies             []EndpointPolicy `json:",omitempty"`
 | 
			
		||||
	IpConfigurations     []IpConfig       `json:",omitempty"`
 | 
			
		||||
	Dns                  Dns              `json:",omitempty"`
 | 
			
		||||
	Routes               []Route          `json:",omitempty"`
 | 
			
		||||
	MacAddress           string           `json:",omitempty"`
 | 
			
		||||
	Flags                EndpointFlags    `json:",omitempty"`
 | 
			
		||||
	SchemaVersion        SchemaVersion    `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// EndpointResourceType are the two different Endpoint settings resources.
 | 
			
		||||
type EndpointResourceType string
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	// EndpointResourceTypePolicy is for Endpoint Policies. Ex: ACL, NAT
 | 
			
		||||
	EndpointResourceTypePolicy EndpointResourceType = "Policy"
 | 
			
		||||
	// EndpointResourceTypePort is for Endpoint Port settings.
 | 
			
		||||
	EndpointResourceTypePort EndpointResourceType = "Port"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// ModifyEndpointSettingRequest is the structure used to send request to modify an endpoint.
 | 
			
		||||
// Used to update policy/port on an endpoint.
 | 
			
		||||
type ModifyEndpointSettingRequest struct {
 | 
			
		||||
	ResourceType EndpointResourceType `json:",omitempty"` // Policy, Port
 | 
			
		||||
	RequestType  RequestType          `json:",omitempty"` // Add, Remove, Update, Refresh
 | 
			
		||||
	Settings     json.RawMessage      `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type PolicyEndpointRequest struct {
 | 
			
		||||
	Policies []EndpointPolicy `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func getEndpoint(endpointGuid guid.GUID, query string) (*HostComputeEndpoint, error) {
 | 
			
		||||
	// Open endpoint.
 | 
			
		||||
	var (
 | 
			
		||||
		endpointHandle   hcnEndpoint
 | 
			
		||||
		resultBuffer     *uint16
 | 
			
		||||
		propertiesBuffer *uint16
 | 
			
		||||
	)
 | 
			
		||||
	hr := hcnOpenEndpoint(&endpointGuid, &endpointHandle, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnOpenEndpoint", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Query endpoint.
 | 
			
		||||
	hr = hcnQueryEndpointProperties(endpointHandle, query, &propertiesBuffer, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnQueryEndpointProperties", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	properties := interop.ConvertAndFreeCoTaskMemString(propertiesBuffer)
 | 
			
		||||
	// Close endpoint.
 | 
			
		||||
	hr = hcnCloseEndpoint(endpointHandle)
 | 
			
		||||
	if err := checkForErrors("hcnCloseEndpoint", hr, nil); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Convert output to HostComputeEndpoint
 | 
			
		||||
	var outputEndpoint HostComputeEndpoint
 | 
			
		||||
	if err := json.Unmarshal([]byte(properties), &outputEndpoint); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return &outputEndpoint, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func enumerateEndpoints(query string) ([]HostComputeEndpoint, error) {
 | 
			
		||||
	// Enumerate all Endpoint Guids
 | 
			
		||||
	var (
 | 
			
		||||
		resultBuffer   *uint16
 | 
			
		||||
		endpointBuffer *uint16
 | 
			
		||||
	)
 | 
			
		||||
	hr := hcnEnumerateEndpoints(query, &endpointBuffer, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnEnumerateEndpoints", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	endpoints := interop.ConvertAndFreeCoTaskMemString(endpointBuffer)
 | 
			
		||||
	var endpointIds []guid.GUID
 | 
			
		||||
	err := json.Unmarshal([]byte(endpoints), &endpointIds)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var outputEndpoints []HostComputeEndpoint
 | 
			
		||||
	for _, endpointGuid := range endpointIds {
 | 
			
		||||
		endpoint, err := getEndpoint(endpointGuid, query)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		outputEndpoints = append(outputEndpoints, *endpoint)
 | 
			
		||||
	}
 | 
			
		||||
	return outputEndpoints, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func createEndpoint(networkId string, endpointSettings string) (*HostComputeEndpoint, error) {
 | 
			
		||||
	networkGuid, err := guid.FromString(networkId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, errInvalidNetworkID
 | 
			
		||||
	}
 | 
			
		||||
	// Open network.
 | 
			
		||||
	var networkHandle hcnNetwork
 | 
			
		||||
	var resultBuffer *uint16
 | 
			
		||||
	hr := hcnOpenNetwork(&networkGuid, &networkHandle, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnOpenNetwork", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Create endpoint.
 | 
			
		||||
	endpointId := guid.GUID{}
 | 
			
		||||
	var endpointHandle hcnEndpoint
 | 
			
		||||
	hr = hcnCreateEndpoint(networkHandle, &endpointId, endpointSettings, &endpointHandle, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnCreateEndpoint", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Query endpoint.
 | 
			
		||||
	hcnQuery := defaultQuery()
 | 
			
		||||
	query, err := json.Marshal(hcnQuery)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	var propertiesBuffer *uint16
 | 
			
		||||
	hr = hcnQueryEndpointProperties(endpointHandle, string(query), &propertiesBuffer, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnQueryEndpointProperties", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	properties := interop.ConvertAndFreeCoTaskMemString(propertiesBuffer)
 | 
			
		||||
	// Close endpoint.
 | 
			
		||||
	hr = hcnCloseEndpoint(endpointHandle)
 | 
			
		||||
	if err := checkForErrors("hcnCloseEndpoint", hr, nil); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Close network.
 | 
			
		||||
	hr = hcnCloseNetwork(networkHandle)
 | 
			
		||||
	if err := checkForErrors("hcnCloseNetwork", hr, nil); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Convert output to HostComputeEndpoint
 | 
			
		||||
	var outputEndpoint HostComputeEndpoint
 | 
			
		||||
	if err := json.Unmarshal([]byte(properties), &outputEndpoint); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return &outputEndpoint, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func modifyEndpoint(endpointId string, settings string) (*HostComputeEndpoint, error) {
 | 
			
		||||
	endpointGuid, err := guid.FromString(endpointId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, errInvalidEndpointID
 | 
			
		||||
	}
 | 
			
		||||
	// Open endpoint
 | 
			
		||||
	var (
 | 
			
		||||
		endpointHandle   hcnEndpoint
 | 
			
		||||
		resultBuffer     *uint16
 | 
			
		||||
		propertiesBuffer *uint16
 | 
			
		||||
	)
 | 
			
		||||
	hr := hcnOpenEndpoint(&endpointGuid, &endpointHandle, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnOpenEndpoint", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Modify endpoint
 | 
			
		||||
	hr = hcnModifyEndpoint(endpointHandle, settings, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnModifyEndpoint", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Query endpoint.
 | 
			
		||||
	hcnQuery := defaultQuery()
 | 
			
		||||
	query, err := json.Marshal(hcnQuery)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	hr = hcnQueryEndpointProperties(endpointHandle, string(query), &propertiesBuffer, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnQueryEndpointProperties", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	properties := interop.ConvertAndFreeCoTaskMemString(propertiesBuffer)
 | 
			
		||||
	// Close endpoint.
 | 
			
		||||
	hr = hcnCloseEndpoint(endpointHandle)
 | 
			
		||||
	if err := checkForErrors("hcnCloseEndpoint", hr, nil); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Convert output to HostComputeEndpoint
 | 
			
		||||
	var outputEndpoint HostComputeEndpoint
 | 
			
		||||
	if err := json.Unmarshal([]byte(properties), &outputEndpoint); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return &outputEndpoint, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func deleteEndpoint(endpointId string) error {
 | 
			
		||||
	endpointGuid, err := guid.FromString(endpointId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return errInvalidEndpointID
 | 
			
		||||
	}
 | 
			
		||||
	var resultBuffer *uint16
 | 
			
		||||
	hr := hcnDeleteEndpoint(&endpointGuid, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnDeleteEndpoint", hr, resultBuffer); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ListEndpoints makes a call to list all available endpoints.
 | 
			
		||||
func ListEndpoints() ([]HostComputeEndpoint, error) {
 | 
			
		||||
	hcnQuery := defaultQuery()
 | 
			
		||||
	endpoints, err := ListEndpointsQuery(hcnQuery)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return endpoints, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ListEndpointsQuery makes a call to query the list of available endpoints.
 | 
			
		||||
func ListEndpointsQuery(query HostComputeQuery) ([]HostComputeEndpoint, error) {
 | 
			
		||||
	queryJson, err := json.Marshal(query)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	endpoints, err := enumerateEndpoints(string(queryJson))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return endpoints, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ListEndpointsOfNetwork queries the list of endpoints on a network.
 | 
			
		||||
func ListEndpointsOfNetwork(networkId string) ([]HostComputeEndpoint, error) {
 | 
			
		||||
	hcnQuery := defaultQuery()
 | 
			
		||||
	// TODO: Once query can convert schema, change to {HostComputeNetwork:networkId}
 | 
			
		||||
	mapA := map[string]string{"VirtualNetwork": networkId}
 | 
			
		||||
	filter, err := json.Marshal(mapA)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	hcnQuery.Filter = string(filter)
 | 
			
		||||
 | 
			
		||||
	return ListEndpointsQuery(hcnQuery)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetEndpointByID returns an endpoint specified by Id
 | 
			
		||||
func GetEndpointByID(endpointId string) (*HostComputeEndpoint, error) {
 | 
			
		||||
	hcnQuery := defaultQuery()
 | 
			
		||||
	mapA := map[string]string{"ID": endpointId}
 | 
			
		||||
	filter, err := json.Marshal(mapA)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	hcnQuery.Filter = string(filter)
 | 
			
		||||
 | 
			
		||||
	endpoints, err := ListEndpointsQuery(hcnQuery)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	if len(endpoints) == 0 {
 | 
			
		||||
		return nil, EndpointNotFoundError{EndpointID: endpointId}
 | 
			
		||||
	}
 | 
			
		||||
	return &endpoints[0], err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetEndpointByName returns an endpoint specified by Name
 | 
			
		||||
func GetEndpointByName(endpointName string) (*HostComputeEndpoint, error) {
 | 
			
		||||
	hcnQuery := defaultQuery()
 | 
			
		||||
	mapA := map[string]string{"Name": endpointName}
 | 
			
		||||
	filter, err := json.Marshal(mapA)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	hcnQuery.Filter = string(filter)
 | 
			
		||||
 | 
			
		||||
	endpoints, err := ListEndpointsQuery(hcnQuery)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	if len(endpoints) == 0 {
 | 
			
		||||
		return nil, EndpointNotFoundError{EndpointName: endpointName}
 | 
			
		||||
	}
 | 
			
		||||
	return &endpoints[0], err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Create Endpoint.
 | 
			
		||||
func (endpoint *HostComputeEndpoint) Create() (*HostComputeEndpoint, error) {
 | 
			
		||||
	logrus.Debugf("hcn::HostComputeEndpoint::Create id=%s", endpoint.Id)
 | 
			
		||||
 | 
			
		||||
	if endpoint.HostComputeNamespace != "" {
 | 
			
		||||
		return nil, errors.New("endpoint create error, endpoint json HostComputeNamespace is read only and should not be set")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	jsonString, err := json.Marshal(endpoint)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	logrus.Debugf("hcn::HostComputeEndpoint::Create JSON: %s", jsonString)
 | 
			
		||||
	endpoint, hcnErr := createEndpoint(endpoint.HostComputeNetwork, string(jsonString))
 | 
			
		||||
	if hcnErr != nil {
 | 
			
		||||
		return nil, hcnErr
 | 
			
		||||
	}
 | 
			
		||||
	return endpoint, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Delete Endpoint.
 | 
			
		||||
func (endpoint *HostComputeEndpoint) Delete() error {
 | 
			
		||||
	logrus.Debugf("hcn::HostComputeEndpoint::Delete id=%s", endpoint.Id)
 | 
			
		||||
 | 
			
		||||
	if err := deleteEndpoint(endpoint.Id); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ModifyEndpointSettings updates the Port/Policy of an Endpoint.
 | 
			
		||||
func ModifyEndpointSettings(endpointId string, request *ModifyEndpointSettingRequest) error {
 | 
			
		||||
	logrus.Debugf("hcn::HostComputeEndpoint::ModifyEndpointSettings id=%s", endpointId)
 | 
			
		||||
 | 
			
		||||
	endpointSettingsRequest, err := json.Marshal(request)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	_, err = modifyEndpoint(endpointId, string(endpointSettingsRequest))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ApplyPolicy applies a Policy (ex: ACL) on the Endpoint.
 | 
			
		||||
func (endpoint *HostComputeEndpoint) ApplyPolicy(requestType RequestType, endpointPolicy PolicyEndpointRequest) error {
 | 
			
		||||
	logrus.Debugf("hcn::HostComputeEndpoint::ApplyPolicy id=%s", endpoint.Id)
 | 
			
		||||
 | 
			
		||||
	settingsJson, err := json.Marshal(endpointPolicy)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	requestMessage := &ModifyEndpointSettingRequest{
 | 
			
		||||
		ResourceType: EndpointResourceTypePolicy,
 | 
			
		||||
		RequestType:  requestType,
 | 
			
		||||
		Settings:     settingsJson,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return ModifyEndpointSettings(endpoint.Id, requestMessage)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NamespaceAttach modifies a Namespace to add an endpoint.
 | 
			
		||||
func (endpoint *HostComputeEndpoint) NamespaceAttach(namespaceId string) error {
 | 
			
		||||
	return AddNamespaceEndpoint(namespaceId, endpoint.Id)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NamespaceDetach modifies a Namespace to remove an endpoint.
 | 
			
		||||
func (endpoint *HostComputeEndpoint) NamespaceDetach(namespaceId string) error {
 | 
			
		||||
	return RemoveNamespaceEndpoint(namespaceId, endpoint.Id)
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										103
									
								
								vendor/github.com/Microsoft/hcsshim/hcn/hcnerrors.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										103
									
								
								vendor/github.com/Microsoft/hcsshim/hcn/hcnerrors.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,103 @@
 | 
			
		||||
// Package hcn is a shim for the Host Compute Networking (HCN) service, which manages networking for Windows Server
 | 
			
		||||
// containers and Hyper-V containers. Previous to RS5, HCN was referred to as Host Networking Service (HNS).
 | 
			
		||||
package hcn
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"errors"
 | 
			
		||||
	"fmt"
 | 
			
		||||
 | 
			
		||||
	"github.com/Microsoft/hcsshim/internal/hcserror"
 | 
			
		||||
	"github.com/Microsoft/hcsshim/internal/interop"
 | 
			
		||||
	"github.com/sirupsen/logrus"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	errInvalidNetworkID      = errors.New("invalid network ID")
 | 
			
		||||
	errInvalidEndpointID     = errors.New("invalid endpoint ID")
 | 
			
		||||
	errInvalidNamespaceID    = errors.New("invalid namespace ID")
 | 
			
		||||
	errInvalidLoadBalancerID = errors.New("invalid load balancer ID")
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func checkForErrors(methodName string, hr error, resultBuffer *uint16) error {
 | 
			
		||||
	errorFound := false
 | 
			
		||||
 | 
			
		||||
	if hr != nil {
 | 
			
		||||
		errorFound = true
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	result := ""
 | 
			
		||||
	if resultBuffer != nil {
 | 
			
		||||
		result = interop.ConvertAndFreeCoTaskMemString(resultBuffer)
 | 
			
		||||
		if result != "" {
 | 
			
		||||
			errorFound = true
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if errorFound {
 | 
			
		||||
		returnError := hcserror.New(hr, methodName, result)
 | 
			
		||||
		logrus.Debugf(returnError.Error()) // HCN errors logged for debugging.
 | 
			
		||||
		return returnError
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NetworkNotFoundError results from a failed seach for a network by Id or Name
 | 
			
		||||
type NetworkNotFoundError struct {
 | 
			
		||||
	NetworkName string
 | 
			
		||||
	NetworkID   string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (e NetworkNotFoundError) Error() string {
 | 
			
		||||
	if e.NetworkName == "" {
 | 
			
		||||
		return fmt.Sprintf("Network Name %s not found", e.NetworkName)
 | 
			
		||||
	}
 | 
			
		||||
	return fmt.Sprintf("Network Id %s not found", e.NetworkID)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// EndpointNotFoundError results from a failed seach for an endpoint by Id or Name
 | 
			
		||||
type EndpointNotFoundError struct {
 | 
			
		||||
	EndpointName string
 | 
			
		||||
	EndpointID   string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (e EndpointNotFoundError) Error() string {
 | 
			
		||||
	if e.EndpointName == "" {
 | 
			
		||||
		return fmt.Sprintf("Endpoint Name %s not found", e.EndpointName)
 | 
			
		||||
	}
 | 
			
		||||
	return fmt.Sprintf("Endpoint Id %s not found", e.EndpointID)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NamespaceNotFoundError results from a failed seach for a namsepace by Id
 | 
			
		||||
type NamespaceNotFoundError struct {
 | 
			
		||||
	NamespaceID string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (e NamespaceNotFoundError) Error() string {
 | 
			
		||||
	return fmt.Sprintf("Namespace %s not found", e.NamespaceID)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// LoadBalancerNotFoundError results from a failed seach for a loadbalancer by Id
 | 
			
		||||
type LoadBalancerNotFoundError struct {
 | 
			
		||||
	LoadBalancerId string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (e LoadBalancerNotFoundError) Error() string {
 | 
			
		||||
	return fmt.Sprintf("LoadBalancer %s not found", e.LoadBalancerId)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// IsNotFoundError returns a boolean indicating whether the error was caused by
 | 
			
		||||
// a resource not being found.
 | 
			
		||||
func IsNotFoundError(err error) bool {
 | 
			
		||||
	switch err.(type) {
 | 
			
		||||
	case NetworkNotFoundError:
 | 
			
		||||
		return true
 | 
			
		||||
	case EndpointNotFoundError:
 | 
			
		||||
		return true
 | 
			
		||||
	case NamespaceNotFoundError:
 | 
			
		||||
		return true
 | 
			
		||||
	case LoadBalancerNotFoundError:
 | 
			
		||||
		return true
 | 
			
		||||
	}
 | 
			
		||||
	return false
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										87
									
								
								vendor/github.com/Microsoft/hcsshim/hcn/hcnglobals.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								vendor/github.com/Microsoft/hcsshim/hcn/hcnglobals.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,87 @@
 | 
			
		||||
package hcn
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"fmt"
 | 
			
		||||
 | 
			
		||||
	"github.com/Microsoft/hcsshim/internal/hcserror"
 | 
			
		||||
	"github.com/Microsoft/hcsshim/internal/interop"
 | 
			
		||||
	"github.com/sirupsen/logrus"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// Globals are all global properties of the HCN Service.
 | 
			
		||||
type Globals struct {
 | 
			
		||||
	Version Version `json:"Version"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Version is the HCN Service version.
 | 
			
		||||
type Version struct {
 | 
			
		||||
	Major int `json:"Major"`
 | 
			
		||||
	Minor int `json:"Minor"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	// HNSVersion1803 added ACL functionality.
 | 
			
		||||
	HNSVersion1803 = Version{Major: 7, Minor: 2}
 | 
			
		||||
	// V2ApiSupport allows the use of V2 Api calls and V2 Schema.
 | 
			
		||||
	V2ApiSupport = Version{Major: 9, Minor: 2}
 | 
			
		||||
	// Remote Subnet allows for Remote Subnet policies on Overlay networks
 | 
			
		||||
	RemoteSubnetVersion = Version{Major: 9, Minor: 2}
 | 
			
		||||
	// A Host Route policy allows for local container to local host communication Overlay networks
 | 
			
		||||
	HostRouteVersion = Version{Major: 9, Minor: 2}
 | 
			
		||||
	// HNS 10.2 allows for Direct Server Return for loadbalancing
 | 
			
		||||
	DSRVersion = Version{Major: 10, Minor: 2}
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// GetGlobals returns the global properties of the HCN Service.
 | 
			
		||||
func GetGlobals() (*Globals, error) {
 | 
			
		||||
	var version Version
 | 
			
		||||
	err := hnsCall("GET", "/globals/version", "", &version)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	globals := &Globals{
 | 
			
		||||
		Version: version,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return globals, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type hnsResponse struct {
 | 
			
		||||
	Success bool
 | 
			
		||||
	Error   string
 | 
			
		||||
	Output  json.RawMessage
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hnsCall(method, path, request string, returnResponse interface{}) error {
 | 
			
		||||
	var responseBuffer *uint16
 | 
			
		||||
	logrus.Debugf("[%s]=>[%s] Request : %s", method, path, request)
 | 
			
		||||
 | 
			
		||||
	err := _hnsCall(method, path, request, &responseBuffer)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return hcserror.New(err, "hnsCall ", "")
 | 
			
		||||
	}
 | 
			
		||||
	response := interop.ConvertAndFreeCoTaskMemString(responseBuffer)
 | 
			
		||||
 | 
			
		||||
	hnsresponse := &hnsResponse{}
 | 
			
		||||
	if err = json.Unmarshal([]byte(response), &hnsresponse); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if !hnsresponse.Success {
 | 
			
		||||
		return fmt.Errorf("HNS failed with error : %s", hnsresponse.Error)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if len(hnsresponse.Output) == 0 {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	logrus.Debugf("Network Response : %s", hnsresponse.Output)
 | 
			
		||||
	err = json.Unmarshal(hnsresponse.Output, returnResponse)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										341
									
								
								vendor/github.com/Microsoft/hcsshim/hcn/hcnloadbalancer.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										341
									
								
								vendor/github.com/Microsoft/hcsshim/hcn/hcnloadbalancer.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,341 @@
 | 
			
		||||
package hcn
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
 | 
			
		||||
	"github.com/Microsoft/go-winio/pkg/guid"
 | 
			
		||||
	"github.com/Microsoft/hcsshim/internal/interop"
 | 
			
		||||
	"github.com/sirupsen/logrus"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// LoadBalancerPortMapping is associated with HostComputeLoadBalancer
 | 
			
		||||
type LoadBalancerPortMapping struct {
 | 
			
		||||
	Protocol     uint32                       `json:",omitempty"` // EX: TCP = 6, UDP = 17
 | 
			
		||||
	InternalPort uint16                       `json:",omitempty"`
 | 
			
		||||
	ExternalPort uint16                       `json:",omitempty"`
 | 
			
		||||
	Flags        LoadBalancerPortMappingFlags `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// HostComputeLoadBalancer represents software load balancer.
 | 
			
		||||
type HostComputeLoadBalancer struct {
 | 
			
		||||
	Id                   string                    `json:"ID,omitempty"`
 | 
			
		||||
	HostComputeEndpoints []string                  `json:",omitempty"`
 | 
			
		||||
	SourceVIP            string                    `json:",omitempty"`
 | 
			
		||||
	FrontendVIPs         []string                  `json:",omitempty"`
 | 
			
		||||
	PortMappings         []LoadBalancerPortMapping `json:",omitempty"`
 | 
			
		||||
	SchemaVersion        SchemaVersion             `json:",omitempty"`
 | 
			
		||||
	Flags                LoadBalancerFlags         `json:",omitempty"` // 0: None, 1: EnableDirectServerReturn
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//LoadBalancerFlags modify settings for a loadbalancer.
 | 
			
		||||
type LoadBalancerFlags uint32
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	// LoadBalancerFlagsNone is the default.
 | 
			
		||||
	LoadBalancerFlagsNone LoadBalancerFlags = 0
 | 
			
		||||
	// LoadBalancerFlagsDSR enables Direct Server Return (DSR)
 | 
			
		||||
	LoadBalancerFlagsDSR LoadBalancerFlags = 1
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// LoadBalancerPortMappingFlags are special settings on a loadbalancer.
 | 
			
		||||
type LoadBalancerPortMappingFlags uint32
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	// LoadBalancerPortMappingFlagsNone is the default.
 | 
			
		||||
	LoadBalancerPortMappingFlagsNone LoadBalancerPortMappingFlags
 | 
			
		||||
	// LoadBalancerPortMappingFlagsILB enables internal loadbalancing.
 | 
			
		||||
	LoadBalancerPortMappingFlagsILB LoadBalancerPortMappingFlags = 1
 | 
			
		||||
	// LoadBalancerPortMappingFlagsLocalRoutedVIP enables VIP access from the host.
 | 
			
		||||
	LoadBalancerPortMappingFlagsLocalRoutedVIP LoadBalancerPortMappingFlags = 2
 | 
			
		||||
	// LoadBalancerPortMappingFlagsUseMux enables DSR for NodePort access of VIP.
 | 
			
		||||
	LoadBalancerPortMappingFlagsUseMux LoadBalancerPortMappingFlags = 4
 | 
			
		||||
	// LoadBalancerPortMappingFlagsPreserveDIP delivers packets with destination IP as the VIP.
 | 
			
		||||
	LoadBalancerPortMappingFlagsPreserveDIP LoadBalancerPortMappingFlags = 8
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func getLoadBalancer(loadBalancerGuid guid.GUID, query string) (*HostComputeLoadBalancer, error) {
 | 
			
		||||
	// Open loadBalancer.
 | 
			
		||||
	var (
 | 
			
		||||
		loadBalancerHandle hcnLoadBalancer
 | 
			
		||||
		resultBuffer       *uint16
 | 
			
		||||
		propertiesBuffer   *uint16
 | 
			
		||||
	)
 | 
			
		||||
	hr := hcnOpenLoadBalancer(&loadBalancerGuid, &loadBalancerHandle, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnOpenLoadBalancer", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Query loadBalancer.
 | 
			
		||||
	hr = hcnQueryLoadBalancerProperties(loadBalancerHandle, query, &propertiesBuffer, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnQueryLoadBalancerProperties", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	properties := interop.ConvertAndFreeCoTaskMemString(propertiesBuffer)
 | 
			
		||||
	// Close loadBalancer.
 | 
			
		||||
	hr = hcnCloseLoadBalancer(loadBalancerHandle)
 | 
			
		||||
	if err := checkForErrors("hcnCloseLoadBalancer", hr, nil); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Convert output to HostComputeLoadBalancer
 | 
			
		||||
	var outputLoadBalancer HostComputeLoadBalancer
 | 
			
		||||
	if err := json.Unmarshal([]byte(properties), &outputLoadBalancer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return &outputLoadBalancer, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func enumerateLoadBalancers(query string) ([]HostComputeLoadBalancer, error) {
 | 
			
		||||
	// Enumerate all LoadBalancer Guids
 | 
			
		||||
	var (
 | 
			
		||||
		resultBuffer       *uint16
 | 
			
		||||
		loadBalancerBuffer *uint16
 | 
			
		||||
	)
 | 
			
		||||
	hr := hcnEnumerateLoadBalancers(query, &loadBalancerBuffer, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnEnumerateLoadBalancers", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	loadBalancers := interop.ConvertAndFreeCoTaskMemString(loadBalancerBuffer)
 | 
			
		||||
	var loadBalancerIds []guid.GUID
 | 
			
		||||
	if err := json.Unmarshal([]byte(loadBalancers), &loadBalancerIds); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var outputLoadBalancers []HostComputeLoadBalancer
 | 
			
		||||
	for _, loadBalancerGuid := range loadBalancerIds {
 | 
			
		||||
		loadBalancer, err := getLoadBalancer(loadBalancerGuid, query)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		outputLoadBalancers = append(outputLoadBalancers, *loadBalancer)
 | 
			
		||||
	}
 | 
			
		||||
	return outputLoadBalancers, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func createLoadBalancer(settings string) (*HostComputeLoadBalancer, error) {
 | 
			
		||||
	// Create new loadBalancer.
 | 
			
		||||
	var (
 | 
			
		||||
		loadBalancerHandle hcnLoadBalancer
 | 
			
		||||
		resultBuffer       *uint16
 | 
			
		||||
		propertiesBuffer   *uint16
 | 
			
		||||
	)
 | 
			
		||||
	loadBalancerGuid := guid.GUID{}
 | 
			
		||||
	hr := hcnCreateLoadBalancer(&loadBalancerGuid, settings, &loadBalancerHandle, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnCreateLoadBalancer", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Query loadBalancer.
 | 
			
		||||
	hcnQuery := defaultQuery()
 | 
			
		||||
	query, err := json.Marshal(hcnQuery)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	hr = hcnQueryLoadBalancerProperties(loadBalancerHandle, string(query), &propertiesBuffer, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnQueryLoadBalancerProperties", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	properties := interop.ConvertAndFreeCoTaskMemString(propertiesBuffer)
 | 
			
		||||
	// Close loadBalancer.
 | 
			
		||||
	hr = hcnCloseLoadBalancer(loadBalancerHandle)
 | 
			
		||||
	if err := checkForErrors("hcnCloseLoadBalancer", hr, nil); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Convert output to HostComputeLoadBalancer
 | 
			
		||||
	var outputLoadBalancer HostComputeLoadBalancer
 | 
			
		||||
	if err := json.Unmarshal([]byte(properties), &outputLoadBalancer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return &outputLoadBalancer, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func modifyLoadBalancer(loadBalancerId string, settings string) (*HostComputeLoadBalancer, error) {
 | 
			
		||||
	loadBalancerGuid, err := guid.FromString(loadBalancerId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, errInvalidLoadBalancerID
 | 
			
		||||
	}
 | 
			
		||||
	// Open loadBalancer.
 | 
			
		||||
	var (
 | 
			
		||||
		loadBalancerHandle hcnLoadBalancer
 | 
			
		||||
		resultBuffer       *uint16
 | 
			
		||||
		propertiesBuffer   *uint16
 | 
			
		||||
	)
 | 
			
		||||
	hr := hcnOpenLoadBalancer(&loadBalancerGuid, &loadBalancerHandle, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnOpenLoadBalancer", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Modify loadBalancer.
 | 
			
		||||
	hr = hcnModifyLoadBalancer(loadBalancerHandle, settings, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnModifyLoadBalancer", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Query loadBalancer.
 | 
			
		||||
	hcnQuery := defaultQuery()
 | 
			
		||||
	query, err := json.Marshal(hcnQuery)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	hr = hcnQueryLoadBalancerProperties(loadBalancerHandle, string(query), &propertiesBuffer, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnQueryLoadBalancerProperties", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	properties := interop.ConvertAndFreeCoTaskMemString(propertiesBuffer)
 | 
			
		||||
	// Close loadBalancer.
 | 
			
		||||
	hr = hcnCloseLoadBalancer(loadBalancerHandle)
 | 
			
		||||
	if err := checkForErrors("hcnCloseLoadBalancer", hr, nil); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Convert output to LoadBalancer
 | 
			
		||||
	var outputLoadBalancer HostComputeLoadBalancer
 | 
			
		||||
	if err := json.Unmarshal([]byte(properties), &outputLoadBalancer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return &outputLoadBalancer, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func deleteLoadBalancer(loadBalancerId string) error {
 | 
			
		||||
	loadBalancerGuid, err := guid.FromString(loadBalancerId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return errInvalidLoadBalancerID
 | 
			
		||||
	}
 | 
			
		||||
	var resultBuffer *uint16
 | 
			
		||||
	hr := hcnDeleteLoadBalancer(&loadBalancerGuid, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnDeleteLoadBalancer", hr, resultBuffer); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ListLoadBalancers makes a call to list all available loadBalancers.
 | 
			
		||||
func ListLoadBalancers() ([]HostComputeLoadBalancer, error) {
 | 
			
		||||
	hcnQuery := defaultQuery()
 | 
			
		||||
	loadBalancers, err := ListLoadBalancersQuery(hcnQuery)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return loadBalancers, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ListLoadBalancersQuery makes a call to query the list of available loadBalancers.
 | 
			
		||||
func ListLoadBalancersQuery(query HostComputeQuery) ([]HostComputeLoadBalancer, error) {
 | 
			
		||||
	queryJson, err := json.Marshal(query)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	loadBalancers, err := enumerateLoadBalancers(string(queryJson))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return loadBalancers, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetLoadBalancerByID returns the LoadBalancer specified by Id.
 | 
			
		||||
func GetLoadBalancerByID(loadBalancerId string) (*HostComputeLoadBalancer, error) {
 | 
			
		||||
	hcnQuery := defaultQuery()
 | 
			
		||||
	mapA := map[string]string{"ID": loadBalancerId}
 | 
			
		||||
	filter, err := json.Marshal(mapA)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	hcnQuery.Filter = string(filter)
 | 
			
		||||
 | 
			
		||||
	loadBalancers, err := ListLoadBalancersQuery(hcnQuery)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	if len(loadBalancers) == 0 {
 | 
			
		||||
		return nil, LoadBalancerNotFoundError{LoadBalancerId: loadBalancerId}
 | 
			
		||||
	}
 | 
			
		||||
	return &loadBalancers[0], err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Create LoadBalancer.
 | 
			
		||||
func (loadBalancer *HostComputeLoadBalancer) Create() (*HostComputeLoadBalancer, error) {
 | 
			
		||||
	logrus.Debugf("hcn::HostComputeLoadBalancer::Create id=%s", loadBalancer.Id)
 | 
			
		||||
 | 
			
		||||
	jsonString, err := json.Marshal(loadBalancer)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	logrus.Debugf("hcn::HostComputeLoadBalancer::Create JSON: %s", jsonString)
 | 
			
		||||
	loadBalancer, hcnErr := createLoadBalancer(string(jsonString))
 | 
			
		||||
	if hcnErr != nil {
 | 
			
		||||
		return nil, hcnErr
 | 
			
		||||
	}
 | 
			
		||||
	return loadBalancer, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Delete LoadBalancer.
 | 
			
		||||
func (loadBalancer *HostComputeLoadBalancer) Delete() error {
 | 
			
		||||
	logrus.Debugf("hcn::HostComputeLoadBalancer::Delete id=%s", loadBalancer.Id)
 | 
			
		||||
 | 
			
		||||
	if err := deleteLoadBalancer(loadBalancer.Id); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// AddEndpoint add an endpoint to a LoadBalancer
 | 
			
		||||
func (loadBalancer *HostComputeLoadBalancer) AddEndpoint(endpoint *HostComputeEndpoint) (*HostComputeLoadBalancer, error) {
 | 
			
		||||
	logrus.Debugf("hcn::HostComputeLoadBalancer::AddEndpoint loadBalancer=%s endpoint=%s", loadBalancer.Id, endpoint.Id)
 | 
			
		||||
 | 
			
		||||
	err := loadBalancer.Delete()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Add Endpoint to the Existing List
 | 
			
		||||
	loadBalancer.HostComputeEndpoints = append(loadBalancer.HostComputeEndpoints, endpoint.Id)
 | 
			
		||||
 | 
			
		||||
	return loadBalancer.Create()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// RemoveEndpoint removes an endpoint from a LoadBalancer
 | 
			
		||||
func (loadBalancer *HostComputeLoadBalancer) RemoveEndpoint(endpoint *HostComputeEndpoint) (*HostComputeLoadBalancer, error) {
 | 
			
		||||
	logrus.Debugf("hcn::HostComputeLoadBalancer::RemoveEndpoint loadBalancer=%s endpoint=%s", loadBalancer.Id, endpoint.Id)
 | 
			
		||||
 | 
			
		||||
	err := loadBalancer.Delete()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Create a list of all the endpoints besides the one being removed
 | 
			
		||||
	var endpoints []string
 | 
			
		||||
	for _, endpointReference := range loadBalancer.HostComputeEndpoints {
 | 
			
		||||
		if endpointReference == endpoint.Id {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
		endpoints = append(endpoints, endpointReference)
 | 
			
		||||
	}
 | 
			
		||||
	loadBalancer.HostComputeEndpoints = endpoints
 | 
			
		||||
	return loadBalancer.Create()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// AddLoadBalancer for the specified endpoints
 | 
			
		||||
func AddLoadBalancer(endpoints []HostComputeEndpoint, flags LoadBalancerFlags, portMappingFlags LoadBalancerPortMappingFlags, sourceVIP string, frontendVIPs []string, protocol uint16, internalPort uint16, externalPort uint16) (*HostComputeLoadBalancer, error) {
 | 
			
		||||
	logrus.Debugf("hcn::HostComputeLoadBalancer::AddLoadBalancer endpointId=%v, LoadBalancerFlags=%v, LoadBalancerPortMappingFlags=%v, sourceVIP=%s, frontendVIPs=%v, protocol=%v, internalPort=%v, externalPort=%v", endpoints, flags, portMappingFlags, sourceVIP, frontendVIPs, protocol, internalPort, externalPort)
 | 
			
		||||
 | 
			
		||||
	loadBalancer := &HostComputeLoadBalancer{
 | 
			
		||||
		SourceVIP: sourceVIP,
 | 
			
		||||
		PortMappings: []LoadBalancerPortMapping{
 | 
			
		||||
			{
 | 
			
		||||
				Protocol:     uint32(protocol),
 | 
			
		||||
				InternalPort: internalPort,
 | 
			
		||||
				ExternalPort: externalPort,
 | 
			
		||||
				Flags:        portMappingFlags,
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		FrontendVIPs: frontendVIPs,
 | 
			
		||||
		SchemaVersion: SchemaVersion{
 | 
			
		||||
			Major: 2,
 | 
			
		||||
			Minor: 0,
 | 
			
		||||
		},
 | 
			
		||||
		Flags: flags,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for _, endpoint := range endpoints {
 | 
			
		||||
		loadBalancer.HostComputeEndpoints = append(loadBalancer.HostComputeEndpoints, endpoint.Id)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return loadBalancer.Create()
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										434
									
								
								vendor/github.com/Microsoft/hcsshim/hcn/hcnnamespace.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										434
									
								
								vendor/github.com/Microsoft/hcsshim/hcn/hcnnamespace.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,434 @@
 | 
			
		||||
package hcn
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"os"
 | 
			
		||||
	"syscall"
 | 
			
		||||
 | 
			
		||||
	"github.com/Microsoft/go-winio/pkg/guid"
 | 
			
		||||
	icni "github.com/Microsoft/hcsshim/internal/cni"
 | 
			
		||||
	"github.com/Microsoft/hcsshim/internal/interop"
 | 
			
		||||
	"github.com/Microsoft/hcsshim/internal/regstate"
 | 
			
		||||
	"github.com/Microsoft/hcsshim/internal/runhcs"
 | 
			
		||||
	"github.com/sirupsen/logrus"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// NamespaceResourceEndpoint represents an Endpoint attached to a Namespace.
 | 
			
		||||
type NamespaceResourceEndpoint struct {
 | 
			
		||||
	Id string `json:"ID,"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NamespaceResourceContainer represents a Container attached to a Namespace.
 | 
			
		||||
type NamespaceResourceContainer struct {
 | 
			
		||||
	Id string `json:"ID,"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NamespaceResourceType determines whether the Namespace resource is a Container or Endpoint.
 | 
			
		||||
type NamespaceResourceType string
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	// NamespaceResourceTypeContainer are contianers associated with a Namespace.
 | 
			
		||||
	NamespaceResourceTypeContainer NamespaceResourceType = "Container"
 | 
			
		||||
	// NamespaceResourceTypeEndpoint are endpoints associated with a Namespace.
 | 
			
		||||
	NamespaceResourceTypeEndpoint NamespaceResourceType = "Endpoint"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// NamespaceResource is associated with a namespace
 | 
			
		||||
type NamespaceResource struct {
 | 
			
		||||
	Type NamespaceResourceType `json:","` // Container, Endpoint
 | 
			
		||||
	Data json.RawMessage       `json:","`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NamespaceType determines whether the Namespace is for a Host or Guest
 | 
			
		||||
type NamespaceType string
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	// NamespaceTypeHost are host namespaces.
 | 
			
		||||
	NamespaceTypeHost NamespaceType = "Host"
 | 
			
		||||
	// NamespaceTypeHostDefault are host namespaces in the default compartment.
 | 
			
		||||
	NamespaceTypeHostDefault NamespaceType = "HostDefault"
 | 
			
		||||
	// NamespaceTypeGuest are guest namespaces.
 | 
			
		||||
	NamespaceTypeGuest NamespaceType = "Guest"
 | 
			
		||||
	// NamespaceTypeGuestDefault are guest namespaces in the default compartment.
 | 
			
		||||
	NamespaceTypeGuestDefault NamespaceType = "GuestDefault"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// HostComputeNamespace represents a namespace (AKA compartment) in
 | 
			
		||||
type HostComputeNamespace struct {
 | 
			
		||||
	Id            string              `json:"ID,omitempty"`
 | 
			
		||||
	NamespaceId   uint32              `json:",omitempty"`
 | 
			
		||||
	Type          NamespaceType       `json:",omitempty"` // Host, HostDefault, Guest, GuestDefault
 | 
			
		||||
	Resources     []NamespaceResource `json:",omitempty"`
 | 
			
		||||
	SchemaVersion SchemaVersion       `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ModifyNamespaceSettingRequest is the structure used to send request to modify a namespace.
 | 
			
		||||
// Used to Add/Remove an endpoints and containers to/from a namespace.
 | 
			
		||||
type ModifyNamespaceSettingRequest struct {
 | 
			
		||||
	ResourceType NamespaceResourceType `json:",omitempty"` // Container, Endpoint
 | 
			
		||||
	RequestType  RequestType           `json:",omitempty"` // Add, Remove, Update, Refresh
 | 
			
		||||
	Settings     json.RawMessage       `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func getNamespace(namespaceGuid guid.GUID, query string) (*HostComputeNamespace, error) {
 | 
			
		||||
	// Open namespace.
 | 
			
		||||
	var (
 | 
			
		||||
		namespaceHandle  hcnNamespace
 | 
			
		||||
		resultBuffer     *uint16
 | 
			
		||||
		propertiesBuffer *uint16
 | 
			
		||||
	)
 | 
			
		||||
	hr := hcnOpenNamespace(&namespaceGuid, &namespaceHandle, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnOpenNamespace", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Query namespace.
 | 
			
		||||
	hr = hcnQueryNamespaceProperties(namespaceHandle, query, &propertiesBuffer, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnQueryNamespaceProperties", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	properties := interop.ConvertAndFreeCoTaskMemString(propertiesBuffer)
 | 
			
		||||
	// Close namespace.
 | 
			
		||||
	hr = hcnCloseNamespace(namespaceHandle)
 | 
			
		||||
	if err := checkForErrors("hcnCloseNamespace", hr, nil); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Convert output to HostComputeNamespace
 | 
			
		||||
	var outputNamespace HostComputeNamespace
 | 
			
		||||
	if err := json.Unmarshal([]byte(properties), &outputNamespace); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return &outputNamespace, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func enumerateNamespaces(query string) ([]HostComputeNamespace, error) {
 | 
			
		||||
	// Enumerate all Namespace Guids
 | 
			
		||||
	var (
 | 
			
		||||
		resultBuffer    *uint16
 | 
			
		||||
		namespaceBuffer *uint16
 | 
			
		||||
	)
 | 
			
		||||
	hr := hcnEnumerateNamespaces(query, &namespaceBuffer, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnEnumerateNamespaces", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	namespaces := interop.ConvertAndFreeCoTaskMemString(namespaceBuffer)
 | 
			
		||||
	var namespaceIds []guid.GUID
 | 
			
		||||
	if err := json.Unmarshal([]byte(namespaces), &namespaceIds); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var outputNamespaces []HostComputeNamespace
 | 
			
		||||
	for _, namespaceGuid := range namespaceIds {
 | 
			
		||||
		namespace, err := getNamespace(namespaceGuid, query)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		outputNamespaces = append(outputNamespaces, *namespace)
 | 
			
		||||
	}
 | 
			
		||||
	return outputNamespaces, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func createNamespace(settings string) (*HostComputeNamespace, error) {
 | 
			
		||||
	// Create new namespace.
 | 
			
		||||
	var (
 | 
			
		||||
		namespaceHandle  hcnNamespace
 | 
			
		||||
		resultBuffer     *uint16
 | 
			
		||||
		propertiesBuffer *uint16
 | 
			
		||||
	)
 | 
			
		||||
	namespaceGuid := guid.GUID{}
 | 
			
		||||
	hr := hcnCreateNamespace(&namespaceGuid, settings, &namespaceHandle, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnCreateNamespace", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Query namespace.
 | 
			
		||||
	hcnQuery := defaultQuery()
 | 
			
		||||
	query, err := json.Marshal(hcnQuery)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	hr = hcnQueryNamespaceProperties(namespaceHandle, string(query), &propertiesBuffer, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnQueryNamespaceProperties", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	properties := interop.ConvertAndFreeCoTaskMemString(propertiesBuffer)
 | 
			
		||||
	// Close namespace.
 | 
			
		||||
	hr = hcnCloseNamespace(namespaceHandle)
 | 
			
		||||
	if err := checkForErrors("hcnCloseNamespace", hr, nil); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Convert output to HostComputeNamespace
 | 
			
		||||
	var outputNamespace HostComputeNamespace
 | 
			
		||||
	if err := json.Unmarshal([]byte(properties), &outputNamespace); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return &outputNamespace, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func modifyNamespace(namespaceId string, settings string) (*HostComputeNamespace, error) {
 | 
			
		||||
	namespaceGuid, err := guid.FromString(namespaceId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, errInvalidNamespaceID
 | 
			
		||||
	}
 | 
			
		||||
	// Open namespace.
 | 
			
		||||
	var (
 | 
			
		||||
		namespaceHandle  hcnNamespace
 | 
			
		||||
		resultBuffer     *uint16
 | 
			
		||||
		propertiesBuffer *uint16
 | 
			
		||||
	)
 | 
			
		||||
	hr := hcnOpenNamespace(&namespaceGuid, &namespaceHandle, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnOpenNamespace", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Modify namespace.
 | 
			
		||||
	hr = hcnModifyNamespace(namespaceHandle, settings, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnModifyNamespace", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Query namespace.
 | 
			
		||||
	hcnQuery := defaultQuery()
 | 
			
		||||
	query, err := json.Marshal(hcnQuery)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	hr = hcnQueryNamespaceProperties(namespaceHandle, string(query), &propertiesBuffer, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnQueryNamespaceProperties", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	properties := interop.ConvertAndFreeCoTaskMemString(propertiesBuffer)
 | 
			
		||||
	// Close namespace.
 | 
			
		||||
	hr = hcnCloseNamespace(namespaceHandle)
 | 
			
		||||
	if err := checkForErrors("hcnCloseNamespace", hr, nil); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Convert output to Namespace
 | 
			
		||||
	var outputNamespace HostComputeNamespace
 | 
			
		||||
	if err := json.Unmarshal([]byte(properties), &outputNamespace); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return &outputNamespace, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func deleteNamespace(namespaceId string) error {
 | 
			
		||||
	namespaceGuid, err := guid.FromString(namespaceId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return errInvalidNamespaceID
 | 
			
		||||
	}
 | 
			
		||||
	var resultBuffer *uint16
 | 
			
		||||
	hr := hcnDeleteNamespace(&namespaceGuid, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnDeleteNamespace", hr, resultBuffer); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ListNamespaces makes a call to list all available namespaces.
 | 
			
		||||
func ListNamespaces() ([]HostComputeNamespace, error) {
 | 
			
		||||
	hcnQuery := defaultQuery()
 | 
			
		||||
	namespaces, err := ListNamespacesQuery(hcnQuery)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return namespaces, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ListNamespacesQuery makes a call to query the list of available namespaces.
 | 
			
		||||
func ListNamespacesQuery(query HostComputeQuery) ([]HostComputeNamespace, error) {
 | 
			
		||||
	queryJson, err := json.Marshal(query)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	namespaces, err := enumerateNamespaces(string(queryJson))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return namespaces, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetNamespaceByID returns the Namespace specified by Id.
 | 
			
		||||
func GetNamespaceByID(namespaceId string) (*HostComputeNamespace, error) {
 | 
			
		||||
	g, err := guid.FromString(namespaceId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, errInvalidNamespaceID
 | 
			
		||||
	}
 | 
			
		||||
	return getNamespace(g, defaultQueryJson())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetNamespaceEndpointIds returns the endpoints of the Namespace specified by Id.
 | 
			
		||||
func GetNamespaceEndpointIds(namespaceId string) ([]string, error) {
 | 
			
		||||
	namespace, err := GetNamespaceByID(namespaceId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	var endpointsIds []string
 | 
			
		||||
	for _, resource := range namespace.Resources {
 | 
			
		||||
		if resource.Type == "Endpoint" {
 | 
			
		||||
			var endpointResource NamespaceResourceEndpoint
 | 
			
		||||
			if err := json.Unmarshal([]byte(resource.Data), &endpointResource); err != nil {
 | 
			
		||||
				return nil, err
 | 
			
		||||
			}
 | 
			
		||||
			endpointsIds = append(endpointsIds, endpointResource.Id)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return endpointsIds, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetNamespaceContainerIds returns the containers of the Namespace specified by Id.
 | 
			
		||||
func GetNamespaceContainerIds(namespaceId string) ([]string, error) {
 | 
			
		||||
	namespace, err := GetNamespaceByID(namespaceId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	var containerIds []string
 | 
			
		||||
	for _, resource := range namespace.Resources {
 | 
			
		||||
		if resource.Type == "Container" {
 | 
			
		||||
			var contaienrResource NamespaceResourceContainer
 | 
			
		||||
			if err := json.Unmarshal([]byte(resource.Data), &contaienrResource); err != nil {
 | 
			
		||||
				return nil, err
 | 
			
		||||
			}
 | 
			
		||||
			containerIds = append(containerIds, contaienrResource.Id)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return containerIds, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NewNamespace creates a new Namespace object
 | 
			
		||||
func NewNamespace(nsType NamespaceType) *HostComputeNamespace {
 | 
			
		||||
	return &HostComputeNamespace{
 | 
			
		||||
		Type:          nsType,
 | 
			
		||||
		SchemaVersion: V2SchemaVersion(),
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Create Namespace.
 | 
			
		||||
func (namespace *HostComputeNamespace) Create() (*HostComputeNamespace, error) {
 | 
			
		||||
	logrus.Debugf("hcn::HostComputeNamespace::Create id=%s", namespace.Id)
 | 
			
		||||
 | 
			
		||||
	jsonString, err := json.Marshal(namespace)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	logrus.Debugf("hcn::HostComputeNamespace::Create JSON: %s", jsonString)
 | 
			
		||||
	namespace, hcnErr := createNamespace(string(jsonString))
 | 
			
		||||
	if hcnErr != nil {
 | 
			
		||||
		return nil, hcnErr
 | 
			
		||||
	}
 | 
			
		||||
	return namespace, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Delete Namespace.
 | 
			
		||||
func (namespace *HostComputeNamespace) Delete() error {
 | 
			
		||||
	logrus.Debugf("hcn::HostComputeNamespace::Delete id=%s", namespace.Id)
 | 
			
		||||
 | 
			
		||||
	if err := deleteNamespace(namespace.Id); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Sync Namespace endpoints with the appropriate sandbox container holding the
 | 
			
		||||
// network namespace open. If no sandbox container is found for this namespace
 | 
			
		||||
// this method is determined to be a success and will not return an error in
 | 
			
		||||
// this case. If the sandbox container is found and a sync is initiated any
 | 
			
		||||
// failures will be returned via this method.
 | 
			
		||||
//
 | 
			
		||||
// This call initiates a sync between endpoints and the matching UtilityVM
 | 
			
		||||
// hosting those endpoints. It is safe to call for any `NamespaceType` but
 | 
			
		||||
// `NamespaceTypeGuest` is the only case when a sync will actually occur. For
 | 
			
		||||
// `NamespaceTypeHost` the process container will be automatically synchronized
 | 
			
		||||
// when the the endpoint is added via `AddNamespaceEndpoint`.
 | 
			
		||||
//
 | 
			
		||||
// Note: This method sync's both additions and removals of endpoints from a
 | 
			
		||||
// `NamespaceTypeGuest` namespace.
 | 
			
		||||
func (namespace *HostComputeNamespace) Sync() error {
 | 
			
		||||
	logrus.WithField("id", namespace.Id).Debugf("hcs::HostComputeNamespace::Sync")
 | 
			
		||||
 | 
			
		||||
	// We only attempt a sync for namespace guest.
 | 
			
		||||
	if namespace.Type != NamespaceTypeGuest {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Look in the registry for the key to map from namespace id to pod-id
 | 
			
		||||
	cfg, err := icni.LoadPersistedNamespaceConfig(namespace.Id)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		if regstate.IsNotFoundError(err) {
 | 
			
		||||
			return nil
 | 
			
		||||
		}
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	req := runhcs.VMRequest{
 | 
			
		||||
		ID: cfg.ContainerID,
 | 
			
		||||
		Op: runhcs.OpSyncNamespace,
 | 
			
		||||
	}
 | 
			
		||||
	shimPath := runhcs.VMPipePath(cfg.HostUniqueID)
 | 
			
		||||
	if err := runhcs.IssueVMRequest(shimPath, &req); err != nil {
 | 
			
		||||
		// The shim is likey gone. Simply ignore the sync as if it didn't exist.
 | 
			
		||||
		if perr, ok := err.(*os.PathError); ok && perr.Err == syscall.ERROR_FILE_NOT_FOUND {
 | 
			
		||||
			// Remove the reg key there is no point to try again
 | 
			
		||||
			cfg.Remove()
 | 
			
		||||
			return nil
 | 
			
		||||
		}
 | 
			
		||||
		f := map[string]interface{}{
 | 
			
		||||
			"id":           namespace.Id,
 | 
			
		||||
			"container-id": cfg.ContainerID,
 | 
			
		||||
		}
 | 
			
		||||
		logrus.WithFields(f).
 | 
			
		||||
			WithError(err).
 | 
			
		||||
			Debugf("hcs::HostComputeNamespace::Sync failed to connect to shim pipe: '%s'", shimPath)
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ModifyNamespaceSettings updates the Endpoints/Containers of a Namespace.
 | 
			
		||||
func ModifyNamespaceSettings(namespaceId string, request *ModifyNamespaceSettingRequest) error {
 | 
			
		||||
	logrus.Debugf("hcn::HostComputeNamespace::ModifyNamespaceSettings id=%s", namespaceId)
 | 
			
		||||
 | 
			
		||||
	namespaceSettings, err := json.Marshal(request)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	_, err = modifyNamespace(namespaceId, string(namespaceSettings))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// AddNamespaceEndpoint adds an endpoint to a Namespace.
 | 
			
		||||
func AddNamespaceEndpoint(namespaceId string, endpointId string) error {
 | 
			
		||||
	logrus.Debugf("hcn::HostComputeEndpoint::AddNamespaceEndpoint id=%s", endpointId)
 | 
			
		||||
 | 
			
		||||
	mapA := map[string]string{"EndpointId": endpointId}
 | 
			
		||||
	settingsJson, err := json.Marshal(mapA)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	requestMessage := &ModifyNamespaceSettingRequest{
 | 
			
		||||
		ResourceType: NamespaceResourceTypeEndpoint,
 | 
			
		||||
		RequestType:  RequestTypeAdd,
 | 
			
		||||
		Settings:     settingsJson,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return ModifyNamespaceSettings(namespaceId, requestMessage)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// RemoveNamespaceEndpoint removes an endpoint from a Namespace.
 | 
			
		||||
func RemoveNamespaceEndpoint(namespaceId string, endpointId string) error {
 | 
			
		||||
	logrus.Debugf("hcn::HostComputeNamespace::RemoveNamespaceEndpoint id=%s", endpointId)
 | 
			
		||||
 | 
			
		||||
	mapA := map[string]string{"EndpointId": endpointId}
 | 
			
		||||
	settingsJson, err := json.Marshal(mapA)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	requestMessage := &ModifyNamespaceSettingRequest{
 | 
			
		||||
		ResourceType: NamespaceResourceTypeEndpoint,
 | 
			
		||||
		RequestType:  RequestTypeRemove,
 | 
			
		||||
		Settings:     settingsJson,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return ModifyNamespaceSettings(namespaceId, requestMessage)
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										461
									
								
								vendor/github.com/Microsoft/hcsshim/hcn/hcnnetwork.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										461
									
								
								vendor/github.com/Microsoft/hcsshim/hcn/hcnnetwork.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,461 @@
 | 
			
		||||
package hcn
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"errors"
 | 
			
		||||
 | 
			
		||||
	"github.com/Microsoft/go-winio/pkg/guid"
 | 
			
		||||
	"github.com/Microsoft/hcsshim/internal/interop"
 | 
			
		||||
	"github.com/sirupsen/logrus"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// Route is assoicated with a subnet.
 | 
			
		||||
type Route struct {
 | 
			
		||||
	NextHop           string `json:",omitempty"`
 | 
			
		||||
	DestinationPrefix string `json:",omitempty"`
 | 
			
		||||
	Metric            uint16 `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Subnet is assoicated with a Ipam.
 | 
			
		||||
type Subnet struct {
 | 
			
		||||
	IpAddressPrefix string            `json:",omitempty"`
 | 
			
		||||
	Policies        []json.RawMessage `json:",omitempty"`
 | 
			
		||||
	Routes          []Route           `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Ipam (Internet Protocol Addres Management) is assoicated with a network
 | 
			
		||||
// and represents the address space(s) of a network.
 | 
			
		||||
type Ipam struct {
 | 
			
		||||
	Type    string   `json:",omitempty"` // Ex: Static, DHCP
 | 
			
		||||
	Subnets []Subnet `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// MacRange is associated with MacPool and respresents the start and end addresses.
 | 
			
		||||
type MacRange struct {
 | 
			
		||||
	StartMacAddress string `json:",omitempty"`
 | 
			
		||||
	EndMacAddress   string `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// MacPool is assoicated with a network and represents pool of MacRanges.
 | 
			
		||||
type MacPool struct {
 | 
			
		||||
	Ranges []MacRange `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Dns (Domain Name System is associated with a network.
 | 
			
		||||
type Dns struct {
 | 
			
		||||
	Domain     string   `json:",omitempty"`
 | 
			
		||||
	Search     []string `json:",omitempty"`
 | 
			
		||||
	ServerList []string `json:",omitempty"`
 | 
			
		||||
	Options    []string `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NetworkType are various networks.
 | 
			
		||||
type NetworkType string
 | 
			
		||||
 | 
			
		||||
// NetworkType const
 | 
			
		||||
const (
 | 
			
		||||
	NAT         NetworkType = "NAT"
 | 
			
		||||
	Transparent NetworkType = "Transparent"
 | 
			
		||||
	L2Bridge    NetworkType = "L2Bridge"
 | 
			
		||||
	L2Tunnel    NetworkType = "L2Tunnel"
 | 
			
		||||
	ICS         NetworkType = "ICS"
 | 
			
		||||
	Private     NetworkType = "Private"
 | 
			
		||||
	Overlay     NetworkType = "Overlay"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// NetworkFlags are various network flags.
 | 
			
		||||
type NetworkFlags uint32
 | 
			
		||||
 | 
			
		||||
// NetworkFlags const
 | 
			
		||||
const (
 | 
			
		||||
	None                NetworkFlags = 0
 | 
			
		||||
	EnableNonPersistent NetworkFlags = 8
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// HostComputeNetwork represents a network
 | 
			
		||||
type HostComputeNetwork struct {
 | 
			
		||||
	Id            string          `json:"ID,omitempty"`
 | 
			
		||||
	Name          string          `json:",omitempty"`
 | 
			
		||||
	Type          NetworkType     `json:",omitempty"`
 | 
			
		||||
	Policies      []NetworkPolicy `json:",omitempty"`
 | 
			
		||||
	MacPool       MacPool         `json:",omitempty"`
 | 
			
		||||
	Dns           Dns             `json:",omitempty"`
 | 
			
		||||
	Ipams         []Ipam          `json:",omitempty"`
 | 
			
		||||
	Flags         NetworkFlags    `json:",omitempty"` // 0: None
 | 
			
		||||
	SchemaVersion SchemaVersion   `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NetworkResourceType are the 3 different Network settings resources.
 | 
			
		||||
type NetworkResourceType string
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	// NetworkResourceTypePolicy is for Network's policies. Ex: RemoteSubnet
 | 
			
		||||
	NetworkResourceTypePolicy NetworkResourceType = "Policy"
 | 
			
		||||
	// NetworkResourceTypeDNS is for Network's DNS settings.
 | 
			
		||||
	NetworkResourceTypeDNS NetworkResourceType = "DNS"
 | 
			
		||||
	// NetworkResourceTypeExtension is for Network's extension settings.
 | 
			
		||||
	NetworkResourceTypeExtension NetworkResourceType = "Extension"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// ModifyNetworkSettingRequest is the structure used to send request to modify an network.
 | 
			
		||||
// Used to update DNS/extension/policy on an network.
 | 
			
		||||
type ModifyNetworkSettingRequest struct {
 | 
			
		||||
	ResourceType NetworkResourceType `json:",omitempty"` // Policy, DNS, Extension
 | 
			
		||||
	RequestType  RequestType         `json:",omitempty"` // Add, Remove, Update, Refresh
 | 
			
		||||
	Settings     json.RawMessage     `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type PolicyNetworkRequest struct {
 | 
			
		||||
	Policies []NetworkPolicy `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func getNetwork(networkGuid guid.GUID, query string) (*HostComputeNetwork, error) {
 | 
			
		||||
	// Open network.
 | 
			
		||||
	var (
 | 
			
		||||
		networkHandle    hcnNetwork
 | 
			
		||||
		resultBuffer     *uint16
 | 
			
		||||
		propertiesBuffer *uint16
 | 
			
		||||
	)
 | 
			
		||||
	hr := hcnOpenNetwork(&networkGuid, &networkHandle, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnOpenNetwork", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Query network.
 | 
			
		||||
	hr = hcnQueryNetworkProperties(networkHandle, query, &propertiesBuffer, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnQueryNetworkProperties", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	properties := interop.ConvertAndFreeCoTaskMemString(propertiesBuffer)
 | 
			
		||||
	// Close network.
 | 
			
		||||
	hr = hcnCloseNetwork(networkHandle)
 | 
			
		||||
	if err := checkForErrors("hcnCloseNetwork", hr, nil); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Convert output to HostComputeNetwork
 | 
			
		||||
	var outputNetwork HostComputeNetwork
 | 
			
		||||
 | 
			
		||||
	// If HNS sets the network type to NAT (i.e. '0' in HNS.Schema.Network.NetworkMode),
 | 
			
		||||
	// the value will be omitted from the JSON blob. We therefore need to initialize NAT here before
 | 
			
		||||
	// unmarshaling the JSON blob.
 | 
			
		||||
	outputNetwork.Type = NAT
 | 
			
		||||
 | 
			
		||||
	if err := json.Unmarshal([]byte(properties), &outputNetwork); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return &outputNetwork, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func enumerateNetworks(query string) ([]HostComputeNetwork, error) {
 | 
			
		||||
	// Enumerate all Network Guids
 | 
			
		||||
	var (
 | 
			
		||||
		resultBuffer  *uint16
 | 
			
		||||
		networkBuffer *uint16
 | 
			
		||||
	)
 | 
			
		||||
	hr := hcnEnumerateNetworks(query, &networkBuffer, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnEnumerateNetworks", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	networks := interop.ConvertAndFreeCoTaskMemString(networkBuffer)
 | 
			
		||||
	var networkIds []guid.GUID
 | 
			
		||||
	if err := json.Unmarshal([]byte(networks), &networkIds); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var outputNetworks []HostComputeNetwork
 | 
			
		||||
	for _, networkGuid := range networkIds {
 | 
			
		||||
		network, err := getNetwork(networkGuid, query)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		outputNetworks = append(outputNetworks, *network)
 | 
			
		||||
	}
 | 
			
		||||
	return outputNetworks, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func createNetwork(settings string) (*HostComputeNetwork, error) {
 | 
			
		||||
	// Create new network.
 | 
			
		||||
	var (
 | 
			
		||||
		networkHandle    hcnNetwork
 | 
			
		||||
		resultBuffer     *uint16
 | 
			
		||||
		propertiesBuffer *uint16
 | 
			
		||||
	)
 | 
			
		||||
	networkGuid := guid.GUID{}
 | 
			
		||||
	hr := hcnCreateNetwork(&networkGuid, settings, &networkHandle, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnCreateNetwork", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Query network.
 | 
			
		||||
	hcnQuery := defaultQuery()
 | 
			
		||||
	query, err := json.Marshal(hcnQuery)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	hr = hcnQueryNetworkProperties(networkHandle, string(query), &propertiesBuffer, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnQueryNetworkProperties", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	properties := interop.ConvertAndFreeCoTaskMemString(propertiesBuffer)
 | 
			
		||||
	// Close network.
 | 
			
		||||
	hr = hcnCloseNetwork(networkHandle)
 | 
			
		||||
	if err := checkForErrors("hcnCloseNetwork", hr, nil); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Convert output to HostComputeNetwork
 | 
			
		||||
	var outputNetwork HostComputeNetwork
 | 
			
		||||
 | 
			
		||||
	// If HNS sets the network type to NAT (i.e. '0' in HNS.Schema.Network.NetworkMode),
 | 
			
		||||
	// the value will be omitted from the JSON blob. We therefore need to initialize NAT here before
 | 
			
		||||
	// unmarshaling the JSON blob.
 | 
			
		||||
	outputNetwork.Type = NAT
 | 
			
		||||
 | 
			
		||||
	if err := json.Unmarshal([]byte(properties), &outputNetwork); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return &outputNetwork, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func modifyNetwork(networkId string, settings string) (*HostComputeNetwork, error) {
 | 
			
		||||
	networkGuid, err := guid.FromString(networkId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, errInvalidNetworkID
 | 
			
		||||
	}
 | 
			
		||||
	// Open Network
 | 
			
		||||
	var (
 | 
			
		||||
		networkHandle    hcnNetwork
 | 
			
		||||
		resultBuffer     *uint16
 | 
			
		||||
		propertiesBuffer *uint16
 | 
			
		||||
	)
 | 
			
		||||
	hr := hcnOpenNetwork(&networkGuid, &networkHandle, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnOpenNetwork", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Modify Network
 | 
			
		||||
	hr = hcnModifyNetwork(networkHandle, settings, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnModifyNetwork", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Query network.
 | 
			
		||||
	hcnQuery := defaultQuery()
 | 
			
		||||
	query, err := json.Marshal(hcnQuery)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	hr = hcnQueryNetworkProperties(networkHandle, string(query), &propertiesBuffer, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnQueryNetworkProperties", hr, resultBuffer); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	properties := interop.ConvertAndFreeCoTaskMemString(propertiesBuffer)
 | 
			
		||||
	// Close network.
 | 
			
		||||
	hr = hcnCloseNetwork(networkHandle)
 | 
			
		||||
	if err := checkForErrors("hcnCloseNetwork", hr, nil); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Convert output to HostComputeNetwork
 | 
			
		||||
	var outputNetwork HostComputeNetwork
 | 
			
		||||
 | 
			
		||||
	// If HNS sets the network type to NAT (i.e. '0' in HNS.Schema.Network.NetworkMode),
 | 
			
		||||
	// the value will be omitted from the JSON blob. We therefore need to initialize NAT here before
 | 
			
		||||
	// unmarshaling the JSON blob.
 | 
			
		||||
	outputNetwork.Type = NAT
 | 
			
		||||
 | 
			
		||||
	if err := json.Unmarshal([]byte(properties), &outputNetwork); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return &outputNetwork, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func deleteNetwork(networkId string) error {
 | 
			
		||||
	networkGuid, err := guid.FromString(networkId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return errInvalidNetworkID
 | 
			
		||||
	}
 | 
			
		||||
	var resultBuffer *uint16
 | 
			
		||||
	hr := hcnDeleteNetwork(&networkGuid, &resultBuffer)
 | 
			
		||||
	if err := checkForErrors("hcnDeleteNetwork", hr, resultBuffer); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ListNetworks makes a call to list all available networks.
 | 
			
		||||
func ListNetworks() ([]HostComputeNetwork, error) {
 | 
			
		||||
	hcnQuery := defaultQuery()
 | 
			
		||||
	networks, err := ListNetworksQuery(hcnQuery)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return networks, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ListNetworksQuery makes a call to query the list of available networks.
 | 
			
		||||
func ListNetworksQuery(query HostComputeQuery) ([]HostComputeNetwork, error) {
 | 
			
		||||
	queryJson, err := json.Marshal(query)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	networks, err := enumerateNetworks(string(queryJson))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return networks, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetNetworkByID returns the network specified by Id.
 | 
			
		||||
func GetNetworkByID(networkID string) (*HostComputeNetwork, error) {
 | 
			
		||||
	hcnQuery := defaultQuery()
 | 
			
		||||
	mapA := map[string]string{"ID": networkID}
 | 
			
		||||
	filter, err := json.Marshal(mapA)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	hcnQuery.Filter = string(filter)
 | 
			
		||||
 | 
			
		||||
	networks, err := ListNetworksQuery(hcnQuery)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	if len(networks) == 0 {
 | 
			
		||||
		return nil, NetworkNotFoundError{NetworkID: networkID}
 | 
			
		||||
	}
 | 
			
		||||
	return &networks[0], err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetNetworkByName returns the network specified by Name.
 | 
			
		||||
func GetNetworkByName(networkName string) (*HostComputeNetwork, error) {
 | 
			
		||||
	hcnQuery := defaultQuery()
 | 
			
		||||
	mapA := map[string]string{"Name": networkName}
 | 
			
		||||
	filter, err := json.Marshal(mapA)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	hcnQuery.Filter = string(filter)
 | 
			
		||||
 | 
			
		||||
	networks, err := ListNetworksQuery(hcnQuery)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	if len(networks) == 0 {
 | 
			
		||||
		return nil, NetworkNotFoundError{NetworkName: networkName}
 | 
			
		||||
	}
 | 
			
		||||
	return &networks[0], err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Create Network.
 | 
			
		||||
func (network *HostComputeNetwork) Create() (*HostComputeNetwork, error) {
 | 
			
		||||
	logrus.Debugf("hcn::HostComputeNetwork::Create id=%s", network.Id)
 | 
			
		||||
	for _, ipam := range network.Ipams {
 | 
			
		||||
		for _, subnet := range ipam.Subnets {
 | 
			
		||||
			if subnet.IpAddressPrefix != "" {
 | 
			
		||||
				hasDefault := false
 | 
			
		||||
				for _, route := range subnet.Routes {
 | 
			
		||||
					if route.NextHop == "" {
 | 
			
		||||
						return nil, errors.New("network create error, subnet has address prefix but no gateway specified")
 | 
			
		||||
					}
 | 
			
		||||
					if route.DestinationPrefix == "0.0.0.0/0" || route.DestinationPrefix == "::/0" {
 | 
			
		||||
						hasDefault = true
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
				if !hasDefault {
 | 
			
		||||
					return nil, errors.New("network create error, no default gateway")
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	jsonString, err := json.Marshal(network)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	logrus.Debugf("hcn::HostComputeNetwork::Create JSON: %s", jsonString)
 | 
			
		||||
	network, hcnErr := createNetwork(string(jsonString))
 | 
			
		||||
	if hcnErr != nil {
 | 
			
		||||
		return nil, hcnErr
 | 
			
		||||
	}
 | 
			
		||||
	return network, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Delete Network.
 | 
			
		||||
func (network *HostComputeNetwork) Delete() error {
 | 
			
		||||
	logrus.Debugf("hcn::HostComputeNetwork::Delete id=%s", network.Id)
 | 
			
		||||
 | 
			
		||||
	if err := deleteNetwork(network.Id); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ModifyNetworkSettings updates the Policy for a network.
 | 
			
		||||
func (network *HostComputeNetwork) ModifyNetworkSettings(request *ModifyNetworkSettingRequest) error {
 | 
			
		||||
	logrus.Debugf("hcn::HostComputeNetwork::ModifyNetworkSettings id=%s", network.Id)
 | 
			
		||||
 | 
			
		||||
	networkSettingsRequest, err := json.Marshal(request)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	_, err = modifyNetwork(network.Id, string(networkSettingsRequest))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// AddPolicy applies a Policy (ex: RemoteSubnet) on the Network.
 | 
			
		||||
func (network *HostComputeNetwork) AddPolicy(networkPolicy PolicyNetworkRequest) error {
 | 
			
		||||
	logrus.Debugf("hcn::HostComputeNetwork::AddPolicy id=%s", network.Id)
 | 
			
		||||
 | 
			
		||||
	settingsJson, err := json.Marshal(networkPolicy)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	requestMessage := &ModifyNetworkSettingRequest{
 | 
			
		||||
		ResourceType: NetworkResourceTypePolicy,
 | 
			
		||||
		RequestType:  RequestTypeAdd,
 | 
			
		||||
		Settings:     settingsJson,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return network.ModifyNetworkSettings(requestMessage)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// RemovePolicy removes a Policy (ex: RemoteSubnet) from the Network.
 | 
			
		||||
func (network *HostComputeNetwork) RemovePolicy(networkPolicy PolicyNetworkRequest) error {
 | 
			
		||||
	logrus.Debugf("hcn::HostComputeNetwork::RemovePolicy id=%s", network.Id)
 | 
			
		||||
 | 
			
		||||
	settingsJson, err := json.Marshal(networkPolicy)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	requestMessage := &ModifyNetworkSettingRequest{
 | 
			
		||||
		ResourceType: NetworkResourceTypePolicy,
 | 
			
		||||
		RequestType:  RequestTypeRemove,
 | 
			
		||||
		Settings:     settingsJson,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return network.ModifyNetworkSettings(requestMessage)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// CreateEndpoint creates an endpoint on the Network.
 | 
			
		||||
func (network *HostComputeNetwork) CreateEndpoint(endpoint *HostComputeEndpoint) (*HostComputeEndpoint, error) {
 | 
			
		||||
	isRemote := endpoint.Flags&EndpointFlagsRemoteEndpoint != 0
 | 
			
		||||
	logrus.Debugf("hcn::HostComputeNetwork::CreatEndpoint, networkId=%s remote=%t", network.Id, isRemote)
 | 
			
		||||
 | 
			
		||||
	endpoint.HostComputeNetwork = network.Id
 | 
			
		||||
	endpointSettings, err := json.Marshal(endpoint)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	newEndpoint, err := createEndpoint(network.Id, string(endpointSettings))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return newEndpoint, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// CreateRemoteEndpoint creates a remote endpoint on the Network.
 | 
			
		||||
func (network *HostComputeNetwork) CreateRemoteEndpoint(endpoint *HostComputeEndpoint) (*HostComputeEndpoint, error) {
 | 
			
		||||
	endpoint.Flags = EndpointFlagsRemoteEndpoint | endpoint.Flags
 | 
			
		||||
	return network.CreateEndpoint(endpoint)
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										249
									
								
								vendor/github.com/Microsoft/hcsshim/hcn/hcnpolicy.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										249
									
								
								vendor/github.com/Microsoft/hcsshim/hcn/hcnpolicy.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,249 @@
 | 
			
		||||
package hcn
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// EndpointPolicyType are the potential Policies that apply to Endpoints.
 | 
			
		||||
type EndpointPolicyType string
 | 
			
		||||
 | 
			
		||||
// EndpointPolicyType const
 | 
			
		||||
const (
 | 
			
		||||
	PortMapping   EndpointPolicyType = "PortMapping"
 | 
			
		||||
	ACL           EndpointPolicyType = "ACL"
 | 
			
		||||
	QOS           EndpointPolicyType = "QOS"
 | 
			
		||||
	L2Driver      EndpointPolicyType = "L2Driver"
 | 
			
		||||
	OutBoundNAT   EndpointPolicyType = "OutBoundNAT"
 | 
			
		||||
	SDNRoute      EndpointPolicyType = "SDNRoute"
 | 
			
		||||
	L4Proxy       EndpointPolicyType = "L4Proxy"
 | 
			
		||||
	PortName      EndpointPolicyType = "PortName"
 | 
			
		||||
	EncapOverhead EndpointPolicyType = "EncapOverhead"
 | 
			
		||||
	// Endpoint and Network have InterfaceConstraint and ProviderAddress
 | 
			
		||||
	NetworkProviderAddress     EndpointPolicyType = "ProviderAddress"
 | 
			
		||||
	NetworkInterfaceConstraint EndpointPolicyType = "InterfaceConstraint"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// EndpointPolicy is a collection of Policy settings for an Endpoint.
 | 
			
		||||
type EndpointPolicy struct {
 | 
			
		||||
	Type     EndpointPolicyType `json:""`
 | 
			
		||||
	Settings json.RawMessage    `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NetworkPolicyType are the potential Policies that apply to Networks.
 | 
			
		||||
type NetworkPolicyType string
 | 
			
		||||
 | 
			
		||||
// NetworkPolicyType const
 | 
			
		||||
const (
 | 
			
		||||
	SourceMacAddress    NetworkPolicyType = "SourceMacAddress"
 | 
			
		||||
	NetAdapterName      NetworkPolicyType = "NetAdapterName"
 | 
			
		||||
	VSwitchExtension    NetworkPolicyType = "VSwitchExtension"
 | 
			
		||||
	DrMacAddress        NetworkPolicyType = "DrMacAddress"
 | 
			
		||||
	AutomaticDNS        NetworkPolicyType = "AutomaticDNS"
 | 
			
		||||
	InterfaceConstraint NetworkPolicyType = "InterfaceConstraint"
 | 
			
		||||
	ProviderAddress     NetworkPolicyType = "ProviderAddress"
 | 
			
		||||
	RemoteSubnetRoute   NetworkPolicyType = "RemoteSubnetRoute"
 | 
			
		||||
	HostRoute           NetworkPolicyType = "HostRoute"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// NetworkPolicy is a collection of Policy settings for a Network.
 | 
			
		||||
type NetworkPolicy struct {
 | 
			
		||||
	Type     NetworkPolicyType `json:""`
 | 
			
		||||
	Settings json.RawMessage   `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SubnetPolicyType are the potential Policies that apply to Subnets.
 | 
			
		||||
type SubnetPolicyType string
 | 
			
		||||
 | 
			
		||||
// SubnetPolicyType const
 | 
			
		||||
const (
 | 
			
		||||
	VLAN SubnetPolicyType = "VLAN"
 | 
			
		||||
	VSID SubnetPolicyType = "VSID"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// SubnetPolicy is a collection of Policy settings for a Subnet.
 | 
			
		||||
type SubnetPolicy struct {
 | 
			
		||||
	Type     SubnetPolicyType `json:""`
 | 
			
		||||
	Settings json.RawMessage  `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NatFlags are flags for portmappings.
 | 
			
		||||
type NatFlags uint32
 | 
			
		||||
 | 
			
		||||
/// Endpoint Policy objects
 | 
			
		||||
 | 
			
		||||
// PortMappingPolicySetting defines Port Mapping (NAT)
 | 
			
		||||
type PortMappingPolicySetting struct {
 | 
			
		||||
	Protocol     uint32   `json:",omitempty"` // EX: TCP = 6, UDP = 17
 | 
			
		||||
	InternalPort uint16   `json:",omitempty"`
 | 
			
		||||
	ExternalPort uint16   `json:",omitempty"`
 | 
			
		||||
	VIP          string   `json:",omitempty"`
 | 
			
		||||
	Flags        NatFlags `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ActionType associated with ACLs. Value is either Allow or Block.
 | 
			
		||||
type ActionType string
 | 
			
		||||
 | 
			
		||||
// DirectionType associated with ACLs. Value is either In or Out.
 | 
			
		||||
type DirectionType string
 | 
			
		||||
 | 
			
		||||
// RuleType associated with ACLs. Value is either Host (WFP) or Switch (VFP).
 | 
			
		||||
type RuleType string
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	// Allow traffic
 | 
			
		||||
	ActionTypeAllow ActionType = "Allow"
 | 
			
		||||
	// Block traffic
 | 
			
		||||
	ActionTypeBlock ActionType = "Block"
 | 
			
		||||
 | 
			
		||||
	// In is traffic coming to the Endpoint
 | 
			
		||||
	DirectionTypeIn DirectionType = "In"
 | 
			
		||||
	// Out is traffic leaving the Endpoint
 | 
			
		||||
	DirectionTypeOut DirectionType = "Out"
 | 
			
		||||
 | 
			
		||||
	// Host creates WFP (Windows Firewall) rules
 | 
			
		||||
	RuleTypeHost RuleType = "Host"
 | 
			
		||||
	// Switch creates VFP (Virtual Filter Platform) rules
 | 
			
		||||
	RuleTypeSwitch RuleType = "Switch"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// AclPolicySetting creates firewall rules on an endpoint
 | 
			
		||||
type AclPolicySetting struct {
 | 
			
		||||
	Protocols       string        `json:",omitempty"` // EX: 6 (TCP), 17 (UDP), 1 (ICMPv4), 58 (ICMPv6), 2 (IGMP)
 | 
			
		||||
	Action          ActionType    `json:","`
 | 
			
		||||
	Direction       DirectionType `json:","`
 | 
			
		||||
	LocalAddresses  string        `json:",omitempty"`
 | 
			
		||||
	RemoteAddresses string        `json:",omitempty"`
 | 
			
		||||
	LocalPorts      string        `json:",omitempty"`
 | 
			
		||||
	RemotePorts     string        `json:",omitempty"`
 | 
			
		||||
	RuleType        RuleType      `json:",omitempty"`
 | 
			
		||||
	Priority        uint16        `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// QosPolicySetting sets Quality of Service bandwidth caps on an Endpoint.
 | 
			
		||||
type QosPolicySetting struct {
 | 
			
		||||
	MaximumOutgoingBandwidthInBytes uint64
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// OutboundNatPolicySetting sets outbound Network Address Translation on an Endpoint.
 | 
			
		||||
type OutboundNatPolicySetting struct {
 | 
			
		||||
	VirtualIP  string   `json:",omitempty"`
 | 
			
		||||
	Exceptions []string `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SDNRoutePolicySetting sets SDN Route on an Endpoint.
 | 
			
		||||
type SDNRoutePolicySetting struct {
 | 
			
		||||
	DestinationPrefix string `json:",omitempty"`
 | 
			
		||||
	NextHop           string `json:",omitempty"`
 | 
			
		||||
	NeedEncap         bool   `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// A ProxyType is a type of proxy used by the L4 proxy policy.
 | 
			
		||||
type ProxyType int
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	// ProxyTypeVFP specifies a Virtual Filtering Protocol proxy.
 | 
			
		||||
	ProxyTypeVFP ProxyType = iota
 | 
			
		||||
	// ProxyTypeWFP specifies a Windows Filtering Platform proxy.
 | 
			
		||||
	ProxyTypeWFP
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// FiveTuple is nested in L4ProxyPolicySetting for WFP support.
 | 
			
		||||
type FiveTuple struct {
 | 
			
		||||
	Protocols       string `json:",omitempty"`
 | 
			
		||||
	LocalAddresses  string `json:",omitempty"`
 | 
			
		||||
	RemoteAddresses string `json:",omitempty"`
 | 
			
		||||
	LocalPorts      string `json:",omitempty"`
 | 
			
		||||
	RemotePorts     string `json:",omitempty"`
 | 
			
		||||
	Priority        uint16 `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// L4ProxyPolicySetting sets Layer-4 Proxy on an endpoint.
 | 
			
		||||
type L4ProxyPolicySetting struct {
 | 
			
		||||
	IP            string   `json:",omitempty"`
 | 
			
		||||
	Port          string   `json:",omitempty"`
 | 
			
		||||
	Protocol      uint32   `json:",omitempty"` // EX: TCP = 6, UDP = 17
 | 
			
		||||
	ExceptionList []string `json:",omitempty"`
 | 
			
		||||
	Destination   string   `json:","`
 | 
			
		||||
	OutboundNat   bool     `json:",omitempty"`
 | 
			
		||||
 | 
			
		||||
	// For the WFP proxy
 | 
			
		||||
	FilterTuple          FiveTuple `json:",omitempty"`
 | 
			
		||||
	ProxyType            ProxyType `json:",omitempty"`
 | 
			
		||||
	UserSID              string    `json:",omitempty"`
 | 
			
		||||
	NetworkCompartmentID uint32    `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// PortnameEndpointPolicySetting sets the port name for an endpoint.
 | 
			
		||||
type PortnameEndpointPolicySetting struct {
 | 
			
		||||
	Name string `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// EncapOverheadEndpointPolicySetting sets the encap overhead for an endpoint.
 | 
			
		||||
type EncapOverheadEndpointPolicySetting struct {
 | 
			
		||||
	Overhead uint16 `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Endpoint and Network Policy objects
 | 
			
		||||
 | 
			
		||||
// ProviderAddressEndpointPolicySetting sets the PA for an endpoint.
 | 
			
		||||
type ProviderAddressEndpointPolicySetting struct {
 | 
			
		||||
	ProviderAddress string `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// InterfaceConstraintPolicySetting limits an Endpoint or Network to a specific Nic.
 | 
			
		||||
type InterfaceConstraintPolicySetting struct {
 | 
			
		||||
	InterfaceGuid        string `json:",omitempty"`
 | 
			
		||||
	InterfaceLuid        uint64 `json:",omitempty"`
 | 
			
		||||
	InterfaceIndex       uint32 `json:",omitempty"`
 | 
			
		||||
	InterfaceMediaType   uint32 `json:",omitempty"`
 | 
			
		||||
	InterfaceAlias       string `json:",omitempty"`
 | 
			
		||||
	InterfaceDescription string `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Network Policy objects
 | 
			
		||||
 | 
			
		||||
// SourceMacAddressNetworkPolicySetting sets source MAC for a network.
 | 
			
		||||
type SourceMacAddressNetworkPolicySetting struct {
 | 
			
		||||
	SourceMacAddress string `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NetAdapterNameNetworkPolicySetting sets network adapter of a network.
 | 
			
		||||
type NetAdapterNameNetworkPolicySetting struct {
 | 
			
		||||
	NetworkAdapterName string `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// VSwitchExtensionNetworkPolicySetting enables/disabled VSwitch extensions for a network.
 | 
			
		||||
type VSwitchExtensionNetworkPolicySetting struct {
 | 
			
		||||
	ExtensionID string `json:",omitempty"`
 | 
			
		||||
	Enable      bool   `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DrMacAddressNetworkPolicySetting sets the DR MAC for a network.
 | 
			
		||||
type DrMacAddressNetworkPolicySetting struct {
 | 
			
		||||
	Address string `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// AutomaticDNSNetworkPolicySetting enables/disables automatic DNS on a network.
 | 
			
		||||
type AutomaticDNSNetworkPolicySetting struct {
 | 
			
		||||
	Enable bool `json:",omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Subnet Policy objects
 | 
			
		||||
 | 
			
		||||
// VlanPolicySetting isolates a subnet with VLAN tagging.
 | 
			
		||||
type VlanPolicySetting struct {
 | 
			
		||||
	IsolationId uint32 `json:","`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// VsidPolicySetting isolates a subnet with VSID tagging.
 | 
			
		||||
type VsidPolicySetting struct {
 | 
			
		||||
	IsolationId uint32 `json:","`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// RemoteSubnetRoutePolicySetting creates remote subnet route rules on a network
 | 
			
		||||
type RemoteSubnetRoutePolicySetting struct {
 | 
			
		||||
	DestinationPrefix           string
 | 
			
		||||
	IsolationId                 uint16
 | 
			
		||||
	ProviderAddress             string
 | 
			
		||||
	DistributedRouterMacAddress string
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										71
									
								
								vendor/github.com/Microsoft/hcsshim/hcn/hcnsupport.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								vendor/github.com/Microsoft/hcsshim/hcn/hcnsupport.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,71 @@
 | 
			
		||||
package hcn
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/sirupsen/logrus"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// SupportedFeatures are the features provided by the Service.
 | 
			
		||||
type SupportedFeatures struct {
 | 
			
		||||
	Acl          AclFeatures `json:"ACL"`
 | 
			
		||||
	Api          ApiSupport  `json:"API"`
 | 
			
		||||
	RemoteSubnet bool        `json:"RemoteSubnet"`
 | 
			
		||||
	HostRoute    bool        `json:"HostRoute"`
 | 
			
		||||
	DSR          bool        `json:"DSR"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// AclFeatures are the supported ACL possibilities.
 | 
			
		||||
type AclFeatures struct {
 | 
			
		||||
	AclAddressLists       bool `json:"AclAddressLists"`
 | 
			
		||||
	AclNoHostRulePriority bool `json:"AclHostRulePriority"`
 | 
			
		||||
	AclPortRanges         bool `json:"AclPortRanges"`
 | 
			
		||||
	AclRuleId             bool `json:"AclRuleId"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ApiSupport lists the supported API versions.
 | 
			
		||||
type ApiSupport struct {
 | 
			
		||||
	V1 bool `json:"V1"`
 | 
			
		||||
	V2 bool `json:"V2"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetSupportedFeatures returns the features supported by the Service.
 | 
			
		||||
func GetSupportedFeatures() SupportedFeatures {
 | 
			
		||||
	var features SupportedFeatures
 | 
			
		||||
 | 
			
		||||
	globals, err := GetGlobals()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		// Expected on pre-1803 builds, all features will be false/unsupported
 | 
			
		||||
		logrus.Debugf("Unable to obtain globals: %s", err)
 | 
			
		||||
		return features
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	features.Acl = AclFeatures{
 | 
			
		||||
		AclAddressLists:       isFeatureSupported(globals.Version, HNSVersion1803),
 | 
			
		||||
		AclNoHostRulePriority: isFeatureSupported(globals.Version, HNSVersion1803),
 | 
			
		||||
		AclPortRanges:         isFeatureSupported(globals.Version, HNSVersion1803),
 | 
			
		||||
		AclRuleId:             isFeatureSupported(globals.Version, HNSVersion1803),
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	features.Api = ApiSupport{
 | 
			
		||||
		V2: isFeatureSupported(globals.Version, V2ApiSupport),
 | 
			
		||||
		V1: true, // HNSCall is still available.
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	features.RemoteSubnet = isFeatureSupported(globals.Version, RemoteSubnetVersion)
 | 
			
		||||
	features.HostRoute = isFeatureSupported(globals.Version, HostRouteVersion)
 | 
			
		||||
	features.DSR = isFeatureSupported(globals.Version, DSRVersion)
 | 
			
		||||
 | 
			
		||||
	return features
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func isFeatureSupported(currentVersion Version, minVersionSupported Version) bool {
 | 
			
		||||
	if currentVersion.Major < minVersionSupported.Major {
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
	if currentVersion.Major > minVersionSupported.Major {
 | 
			
		||||
		return true
 | 
			
		||||
	}
 | 
			
		||||
	if currentVersion.Minor < minVersionSupported.Minor {
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
	return true
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										714
									
								
								vendor/github.com/Microsoft/hcsshim/hcn/zsyscall_windows.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										714
									
								
								vendor/github.com/Microsoft/hcsshim/hcn/zsyscall_windows.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,714 @@
 | 
			
		||||
// Code generated mksyscall_windows.exe DO NOT EDIT
 | 
			
		||||
 | 
			
		||||
package hcn
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"syscall"
 | 
			
		||||
	"unsafe"
 | 
			
		||||
 | 
			
		||||
	"golang.org/x/sys/windows"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var _ unsafe.Pointer
 | 
			
		||||
 | 
			
		||||
// Do the interface allocations only once for common
 | 
			
		||||
// Errno values.
 | 
			
		||||
const (
 | 
			
		||||
	errnoERROR_IO_PENDING = 997
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING)
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// errnoErr returns common boxed Errno values, to prevent
 | 
			
		||||
// allocations at runtime.
 | 
			
		||||
func errnoErr(e syscall.Errno) error {
 | 
			
		||||
	switch e {
 | 
			
		||||
	case 0:
 | 
			
		||||
		return nil
 | 
			
		||||
	case errnoERROR_IO_PENDING:
 | 
			
		||||
		return errERROR_IO_PENDING
 | 
			
		||||
	}
 | 
			
		||||
	// TODO: add more here, after collecting data on the common
 | 
			
		||||
	// error values see on Windows. (perhaps when running
 | 
			
		||||
	// all.bat?)
 | 
			
		||||
	return e
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	modiphlpapi       = windows.NewLazySystemDLL("iphlpapi.dll")
 | 
			
		||||
	modvmcompute      = windows.NewLazySystemDLL("vmcompute.dll")
 | 
			
		||||
	modcomputenetwork = windows.NewLazySystemDLL("computenetwork.dll")
 | 
			
		||||
 | 
			
		||||
	procSetCurrentThreadCompartmentId  = modiphlpapi.NewProc("SetCurrentThreadCompartmentId")
 | 
			
		||||
	procHNSCall                        = modvmcompute.NewProc("HNSCall")
 | 
			
		||||
	procHcnEnumerateNetworks           = modcomputenetwork.NewProc("HcnEnumerateNetworks")
 | 
			
		||||
	procHcnCreateNetwork               = modcomputenetwork.NewProc("HcnCreateNetwork")
 | 
			
		||||
	procHcnOpenNetwork                 = modcomputenetwork.NewProc("HcnOpenNetwork")
 | 
			
		||||
	procHcnModifyNetwork               = modcomputenetwork.NewProc("HcnModifyNetwork")
 | 
			
		||||
	procHcnQueryNetworkProperties      = modcomputenetwork.NewProc("HcnQueryNetworkProperties")
 | 
			
		||||
	procHcnDeleteNetwork               = modcomputenetwork.NewProc("HcnDeleteNetwork")
 | 
			
		||||
	procHcnCloseNetwork                = modcomputenetwork.NewProc("HcnCloseNetwork")
 | 
			
		||||
	procHcnEnumerateEndpoints          = modcomputenetwork.NewProc("HcnEnumerateEndpoints")
 | 
			
		||||
	procHcnCreateEndpoint              = modcomputenetwork.NewProc("HcnCreateEndpoint")
 | 
			
		||||
	procHcnOpenEndpoint                = modcomputenetwork.NewProc("HcnOpenEndpoint")
 | 
			
		||||
	procHcnModifyEndpoint              = modcomputenetwork.NewProc("HcnModifyEndpoint")
 | 
			
		||||
	procHcnQueryEndpointProperties     = modcomputenetwork.NewProc("HcnQueryEndpointProperties")
 | 
			
		||||
	procHcnDeleteEndpoint              = modcomputenetwork.NewProc("HcnDeleteEndpoint")
 | 
			
		||||
	procHcnCloseEndpoint               = modcomputenetwork.NewProc("HcnCloseEndpoint")
 | 
			
		||||
	procHcnEnumerateNamespaces         = modcomputenetwork.NewProc("HcnEnumerateNamespaces")
 | 
			
		||||
	procHcnCreateNamespace             = modcomputenetwork.NewProc("HcnCreateNamespace")
 | 
			
		||||
	procHcnOpenNamespace               = modcomputenetwork.NewProc("HcnOpenNamespace")
 | 
			
		||||
	procHcnModifyNamespace             = modcomputenetwork.NewProc("HcnModifyNamespace")
 | 
			
		||||
	procHcnQueryNamespaceProperties    = modcomputenetwork.NewProc("HcnQueryNamespaceProperties")
 | 
			
		||||
	procHcnDeleteNamespace             = modcomputenetwork.NewProc("HcnDeleteNamespace")
 | 
			
		||||
	procHcnCloseNamespace              = modcomputenetwork.NewProc("HcnCloseNamespace")
 | 
			
		||||
	procHcnEnumerateLoadBalancers      = modcomputenetwork.NewProc("HcnEnumerateLoadBalancers")
 | 
			
		||||
	procHcnCreateLoadBalancer          = modcomputenetwork.NewProc("HcnCreateLoadBalancer")
 | 
			
		||||
	procHcnOpenLoadBalancer            = modcomputenetwork.NewProc("HcnOpenLoadBalancer")
 | 
			
		||||
	procHcnModifyLoadBalancer          = modcomputenetwork.NewProc("HcnModifyLoadBalancer")
 | 
			
		||||
	procHcnQueryLoadBalancerProperties = modcomputenetwork.NewProc("HcnQueryLoadBalancerProperties")
 | 
			
		||||
	procHcnDeleteLoadBalancer          = modcomputenetwork.NewProc("HcnDeleteLoadBalancer")
 | 
			
		||||
	procHcnCloseLoadBalancer           = modcomputenetwork.NewProc("HcnCloseLoadBalancer")
 | 
			
		||||
	procHcnOpenService                 = modcomputenetwork.NewProc("HcnOpenService")
 | 
			
		||||
	procHcnRegisterServiceCallback     = modcomputenetwork.NewProc("HcnRegisterServiceCallback")
 | 
			
		||||
	procHcnUnregisterServiceCallback   = modcomputenetwork.NewProc("HcnUnregisterServiceCallback")
 | 
			
		||||
	procHcnCloseService                = modcomputenetwork.NewProc("HcnCloseService")
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func SetCurrentThreadCompartmentId(compartmentId uint32) (hr error) {
 | 
			
		||||
	r0, _, _ := syscall.Syscall(procSetCurrentThreadCompartmentId.Addr(), 1, uintptr(compartmentId), 0, 0)
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func _hnsCall(method string, path string, object string, response **uint16) (hr error) {
 | 
			
		||||
	var _p0 *uint16
 | 
			
		||||
	_p0, hr = syscall.UTF16PtrFromString(method)
 | 
			
		||||
	if hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	var _p1 *uint16
 | 
			
		||||
	_p1, hr = syscall.UTF16PtrFromString(path)
 | 
			
		||||
	if hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	var _p2 *uint16
 | 
			
		||||
	_p2, hr = syscall.UTF16PtrFromString(object)
 | 
			
		||||
	if hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	return __hnsCall(_p0, _p1, _p2, response)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func __hnsCall(method *uint16, path *uint16, object *uint16, response **uint16) (hr error) {
 | 
			
		||||
	if hr = procHNSCall.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall6(procHNSCall.Addr(), 4, uintptr(unsafe.Pointer(method)), uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(object)), uintptr(unsafe.Pointer(response)), 0, 0)
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnEnumerateNetworks(query string, networks **uint16, result **uint16) (hr error) {
 | 
			
		||||
	var _p0 *uint16
 | 
			
		||||
	_p0, hr = syscall.UTF16PtrFromString(query)
 | 
			
		||||
	if hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	return _hcnEnumerateNetworks(_p0, networks, result)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func _hcnEnumerateNetworks(query *uint16, networks **uint16, result **uint16) (hr error) {
 | 
			
		||||
	if hr = procHcnEnumerateNetworks.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall(procHcnEnumerateNetworks.Addr(), 3, uintptr(unsafe.Pointer(query)), uintptr(unsafe.Pointer(networks)), uintptr(unsafe.Pointer(result)))
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnCreateNetwork(id *_guid, settings string, network *hcnNetwork, result **uint16) (hr error) {
 | 
			
		||||
	var _p0 *uint16
 | 
			
		||||
	_p0, hr = syscall.UTF16PtrFromString(settings)
 | 
			
		||||
	if hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	return _hcnCreateNetwork(id, _p0, network, result)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func _hcnCreateNetwork(id *_guid, settings *uint16, network *hcnNetwork, result **uint16) (hr error) {
 | 
			
		||||
	if hr = procHcnCreateNetwork.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall6(procHcnCreateNetwork.Addr(), 4, uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(settings)), uintptr(unsafe.Pointer(network)), uintptr(unsafe.Pointer(result)), 0, 0)
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnOpenNetwork(id *_guid, network *hcnNetwork, result **uint16) (hr error) {
 | 
			
		||||
	if hr = procHcnOpenNetwork.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall(procHcnOpenNetwork.Addr(), 3, uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(network)), uintptr(unsafe.Pointer(result)))
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnModifyNetwork(network hcnNetwork, settings string, result **uint16) (hr error) {
 | 
			
		||||
	var _p0 *uint16
 | 
			
		||||
	_p0, hr = syscall.UTF16PtrFromString(settings)
 | 
			
		||||
	if hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	return _hcnModifyNetwork(network, _p0, result)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func _hcnModifyNetwork(network hcnNetwork, settings *uint16, result **uint16) (hr error) {
 | 
			
		||||
	if hr = procHcnModifyNetwork.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall(procHcnModifyNetwork.Addr(), 3, uintptr(network), uintptr(unsafe.Pointer(settings)), uintptr(unsafe.Pointer(result)))
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnQueryNetworkProperties(network hcnNetwork, query string, properties **uint16, result **uint16) (hr error) {
 | 
			
		||||
	var _p0 *uint16
 | 
			
		||||
	_p0, hr = syscall.UTF16PtrFromString(query)
 | 
			
		||||
	if hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	return _hcnQueryNetworkProperties(network, _p0, properties, result)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func _hcnQueryNetworkProperties(network hcnNetwork, query *uint16, properties **uint16, result **uint16) (hr error) {
 | 
			
		||||
	if hr = procHcnQueryNetworkProperties.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall6(procHcnQueryNetworkProperties.Addr(), 4, uintptr(network), uintptr(unsafe.Pointer(query)), uintptr(unsafe.Pointer(properties)), uintptr(unsafe.Pointer(result)), 0, 0)
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnDeleteNetwork(id *_guid, result **uint16) (hr error) {
 | 
			
		||||
	if hr = procHcnDeleteNetwork.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall(procHcnDeleteNetwork.Addr(), 2, uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(result)), 0)
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnCloseNetwork(network hcnNetwork) (hr error) {
 | 
			
		||||
	if hr = procHcnCloseNetwork.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall(procHcnCloseNetwork.Addr(), 1, uintptr(network), 0, 0)
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnEnumerateEndpoints(query string, endpoints **uint16, result **uint16) (hr error) {
 | 
			
		||||
	var _p0 *uint16
 | 
			
		||||
	_p0, hr = syscall.UTF16PtrFromString(query)
 | 
			
		||||
	if hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	return _hcnEnumerateEndpoints(_p0, endpoints, result)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func _hcnEnumerateEndpoints(query *uint16, endpoints **uint16, result **uint16) (hr error) {
 | 
			
		||||
	if hr = procHcnEnumerateEndpoints.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall(procHcnEnumerateEndpoints.Addr(), 3, uintptr(unsafe.Pointer(query)), uintptr(unsafe.Pointer(endpoints)), uintptr(unsafe.Pointer(result)))
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnCreateEndpoint(network hcnNetwork, id *_guid, settings string, endpoint *hcnEndpoint, result **uint16) (hr error) {
 | 
			
		||||
	var _p0 *uint16
 | 
			
		||||
	_p0, hr = syscall.UTF16PtrFromString(settings)
 | 
			
		||||
	if hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	return _hcnCreateEndpoint(network, id, _p0, endpoint, result)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func _hcnCreateEndpoint(network hcnNetwork, id *_guid, settings *uint16, endpoint *hcnEndpoint, result **uint16) (hr error) {
 | 
			
		||||
	if hr = procHcnCreateEndpoint.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall6(procHcnCreateEndpoint.Addr(), 5, uintptr(network), uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(settings)), uintptr(unsafe.Pointer(endpoint)), uintptr(unsafe.Pointer(result)), 0)
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnOpenEndpoint(id *_guid, endpoint *hcnEndpoint, result **uint16) (hr error) {
 | 
			
		||||
	if hr = procHcnOpenEndpoint.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall(procHcnOpenEndpoint.Addr(), 3, uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(endpoint)), uintptr(unsafe.Pointer(result)))
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnModifyEndpoint(endpoint hcnEndpoint, settings string, result **uint16) (hr error) {
 | 
			
		||||
	var _p0 *uint16
 | 
			
		||||
	_p0, hr = syscall.UTF16PtrFromString(settings)
 | 
			
		||||
	if hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	return _hcnModifyEndpoint(endpoint, _p0, result)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func _hcnModifyEndpoint(endpoint hcnEndpoint, settings *uint16, result **uint16) (hr error) {
 | 
			
		||||
	if hr = procHcnModifyEndpoint.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall(procHcnModifyEndpoint.Addr(), 3, uintptr(endpoint), uintptr(unsafe.Pointer(settings)), uintptr(unsafe.Pointer(result)))
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnQueryEndpointProperties(endpoint hcnEndpoint, query string, properties **uint16, result **uint16) (hr error) {
 | 
			
		||||
	var _p0 *uint16
 | 
			
		||||
	_p0, hr = syscall.UTF16PtrFromString(query)
 | 
			
		||||
	if hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	return _hcnQueryEndpointProperties(endpoint, _p0, properties, result)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func _hcnQueryEndpointProperties(endpoint hcnEndpoint, query *uint16, properties **uint16, result **uint16) (hr error) {
 | 
			
		||||
	if hr = procHcnQueryEndpointProperties.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall6(procHcnQueryEndpointProperties.Addr(), 4, uintptr(endpoint), uintptr(unsafe.Pointer(query)), uintptr(unsafe.Pointer(properties)), uintptr(unsafe.Pointer(result)), 0, 0)
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnDeleteEndpoint(id *_guid, result **uint16) (hr error) {
 | 
			
		||||
	if hr = procHcnDeleteEndpoint.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall(procHcnDeleteEndpoint.Addr(), 2, uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(result)), 0)
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnCloseEndpoint(endpoint hcnEndpoint) (hr error) {
 | 
			
		||||
	if hr = procHcnCloseEndpoint.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall(procHcnCloseEndpoint.Addr(), 1, uintptr(endpoint), 0, 0)
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnEnumerateNamespaces(query string, namespaces **uint16, result **uint16) (hr error) {
 | 
			
		||||
	var _p0 *uint16
 | 
			
		||||
	_p0, hr = syscall.UTF16PtrFromString(query)
 | 
			
		||||
	if hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	return _hcnEnumerateNamespaces(_p0, namespaces, result)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func _hcnEnumerateNamespaces(query *uint16, namespaces **uint16, result **uint16) (hr error) {
 | 
			
		||||
	if hr = procHcnEnumerateNamespaces.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall(procHcnEnumerateNamespaces.Addr(), 3, uintptr(unsafe.Pointer(query)), uintptr(unsafe.Pointer(namespaces)), uintptr(unsafe.Pointer(result)))
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnCreateNamespace(id *_guid, settings string, namespace *hcnNamespace, result **uint16) (hr error) {
 | 
			
		||||
	var _p0 *uint16
 | 
			
		||||
	_p0, hr = syscall.UTF16PtrFromString(settings)
 | 
			
		||||
	if hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	return _hcnCreateNamespace(id, _p0, namespace, result)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func _hcnCreateNamespace(id *_guid, settings *uint16, namespace *hcnNamespace, result **uint16) (hr error) {
 | 
			
		||||
	if hr = procHcnCreateNamespace.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall6(procHcnCreateNamespace.Addr(), 4, uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(settings)), uintptr(unsafe.Pointer(namespace)), uintptr(unsafe.Pointer(result)), 0, 0)
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnOpenNamespace(id *_guid, namespace *hcnNamespace, result **uint16) (hr error) {
 | 
			
		||||
	if hr = procHcnOpenNamespace.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall(procHcnOpenNamespace.Addr(), 3, uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(namespace)), uintptr(unsafe.Pointer(result)))
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnModifyNamespace(namespace hcnNamespace, settings string, result **uint16) (hr error) {
 | 
			
		||||
	var _p0 *uint16
 | 
			
		||||
	_p0, hr = syscall.UTF16PtrFromString(settings)
 | 
			
		||||
	if hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	return _hcnModifyNamespace(namespace, _p0, result)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func _hcnModifyNamespace(namespace hcnNamespace, settings *uint16, result **uint16) (hr error) {
 | 
			
		||||
	if hr = procHcnModifyNamespace.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall(procHcnModifyNamespace.Addr(), 3, uintptr(namespace), uintptr(unsafe.Pointer(settings)), uintptr(unsafe.Pointer(result)))
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnQueryNamespaceProperties(namespace hcnNamespace, query string, properties **uint16, result **uint16) (hr error) {
 | 
			
		||||
	var _p0 *uint16
 | 
			
		||||
	_p0, hr = syscall.UTF16PtrFromString(query)
 | 
			
		||||
	if hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	return _hcnQueryNamespaceProperties(namespace, _p0, properties, result)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func _hcnQueryNamespaceProperties(namespace hcnNamespace, query *uint16, properties **uint16, result **uint16) (hr error) {
 | 
			
		||||
	if hr = procHcnQueryNamespaceProperties.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall6(procHcnQueryNamespaceProperties.Addr(), 4, uintptr(namespace), uintptr(unsafe.Pointer(query)), uintptr(unsafe.Pointer(properties)), uintptr(unsafe.Pointer(result)), 0, 0)
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnDeleteNamespace(id *_guid, result **uint16) (hr error) {
 | 
			
		||||
	if hr = procHcnDeleteNamespace.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall(procHcnDeleteNamespace.Addr(), 2, uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(result)), 0)
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnCloseNamespace(namespace hcnNamespace) (hr error) {
 | 
			
		||||
	if hr = procHcnCloseNamespace.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall(procHcnCloseNamespace.Addr(), 1, uintptr(namespace), 0, 0)
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnEnumerateLoadBalancers(query string, loadBalancers **uint16, result **uint16) (hr error) {
 | 
			
		||||
	var _p0 *uint16
 | 
			
		||||
	_p0, hr = syscall.UTF16PtrFromString(query)
 | 
			
		||||
	if hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	return _hcnEnumerateLoadBalancers(_p0, loadBalancers, result)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func _hcnEnumerateLoadBalancers(query *uint16, loadBalancers **uint16, result **uint16) (hr error) {
 | 
			
		||||
	if hr = procHcnEnumerateLoadBalancers.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall(procHcnEnumerateLoadBalancers.Addr(), 3, uintptr(unsafe.Pointer(query)), uintptr(unsafe.Pointer(loadBalancers)), uintptr(unsafe.Pointer(result)))
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnCreateLoadBalancer(id *_guid, settings string, loadBalancer *hcnLoadBalancer, result **uint16) (hr error) {
 | 
			
		||||
	var _p0 *uint16
 | 
			
		||||
	_p0, hr = syscall.UTF16PtrFromString(settings)
 | 
			
		||||
	if hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	return _hcnCreateLoadBalancer(id, _p0, loadBalancer, result)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func _hcnCreateLoadBalancer(id *_guid, settings *uint16, loadBalancer *hcnLoadBalancer, result **uint16) (hr error) {
 | 
			
		||||
	if hr = procHcnCreateLoadBalancer.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall6(procHcnCreateLoadBalancer.Addr(), 4, uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(settings)), uintptr(unsafe.Pointer(loadBalancer)), uintptr(unsafe.Pointer(result)), 0, 0)
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnOpenLoadBalancer(id *_guid, loadBalancer *hcnLoadBalancer, result **uint16) (hr error) {
 | 
			
		||||
	if hr = procHcnOpenLoadBalancer.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall(procHcnOpenLoadBalancer.Addr(), 3, uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(loadBalancer)), uintptr(unsafe.Pointer(result)))
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnModifyLoadBalancer(loadBalancer hcnLoadBalancer, settings string, result **uint16) (hr error) {
 | 
			
		||||
	var _p0 *uint16
 | 
			
		||||
	_p0, hr = syscall.UTF16PtrFromString(settings)
 | 
			
		||||
	if hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	return _hcnModifyLoadBalancer(loadBalancer, _p0, result)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func _hcnModifyLoadBalancer(loadBalancer hcnLoadBalancer, settings *uint16, result **uint16) (hr error) {
 | 
			
		||||
	if hr = procHcnModifyLoadBalancer.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall(procHcnModifyLoadBalancer.Addr(), 3, uintptr(loadBalancer), uintptr(unsafe.Pointer(settings)), uintptr(unsafe.Pointer(result)))
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnQueryLoadBalancerProperties(loadBalancer hcnLoadBalancer, query string, properties **uint16, result **uint16) (hr error) {
 | 
			
		||||
	var _p0 *uint16
 | 
			
		||||
	_p0, hr = syscall.UTF16PtrFromString(query)
 | 
			
		||||
	if hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	return _hcnQueryLoadBalancerProperties(loadBalancer, _p0, properties, result)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func _hcnQueryLoadBalancerProperties(loadBalancer hcnLoadBalancer, query *uint16, properties **uint16, result **uint16) (hr error) {
 | 
			
		||||
	if hr = procHcnQueryLoadBalancerProperties.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall6(procHcnQueryLoadBalancerProperties.Addr(), 4, uintptr(loadBalancer), uintptr(unsafe.Pointer(query)), uintptr(unsafe.Pointer(properties)), uintptr(unsafe.Pointer(result)), 0, 0)
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnDeleteLoadBalancer(id *_guid, result **uint16) (hr error) {
 | 
			
		||||
	if hr = procHcnDeleteLoadBalancer.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall(procHcnDeleteLoadBalancer.Addr(), 2, uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(result)), 0)
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnCloseLoadBalancer(loadBalancer hcnLoadBalancer) (hr error) {
 | 
			
		||||
	if hr = procHcnCloseLoadBalancer.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall(procHcnCloseLoadBalancer.Addr(), 1, uintptr(loadBalancer), 0, 0)
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnOpenService(service *hcnService, result **uint16) (hr error) {
 | 
			
		||||
	if hr = procHcnOpenService.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall(procHcnOpenService.Addr(), 2, uintptr(unsafe.Pointer(service)), uintptr(unsafe.Pointer(result)), 0)
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnRegisterServiceCallback(service hcnService, callback int32, context int32, callbackHandle *hcnCallbackHandle) (hr error) {
 | 
			
		||||
	if hr = procHcnRegisterServiceCallback.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall6(procHcnRegisterServiceCallback.Addr(), 4, uintptr(service), uintptr(callback), uintptr(context), uintptr(unsafe.Pointer(callbackHandle)), 0, 0)
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnUnregisterServiceCallback(callbackHandle hcnCallbackHandle) (hr error) {
 | 
			
		||||
	if hr = procHcnUnregisterServiceCallback.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall(procHcnUnregisterServiceCallback.Addr(), 1, uintptr(callbackHandle), 0, 0)
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hcnCloseService(service hcnService) (hr error) {
 | 
			
		||||
	if hr = procHcnCloseService.Find(); hr != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	r0, _, _ := syscall.Syscall(procHcnCloseService.Addr(), 1, uintptr(service), 0, 0)
 | 
			
		||||
	if int32(r0) < 0 {
 | 
			
		||||
		if r0&0x1fff0000 == 0x00070000 {
 | 
			
		||||
			r0 &= 0xffff
 | 
			
		||||
		}
 | 
			
		||||
		hr = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										110
									
								
								vendor/github.com/Microsoft/hcsshim/internal/cni/registry.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										110
									
								
								vendor/github.com/Microsoft/hcsshim/internal/cni/registry.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,110 @@
 | 
			
		||||
package cni
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"errors"
 | 
			
		||||
 | 
			
		||||
	"github.com/Microsoft/go-winio/pkg/guid"
 | 
			
		||||
	"github.com/Microsoft/hcsshim/internal/regstate"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	cniRoot = "cni"
 | 
			
		||||
	cniKey  = "cfg"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// PersistedNamespaceConfig is the registry version of the `NamespaceID` to UVM
 | 
			
		||||
// map.
 | 
			
		||||
type PersistedNamespaceConfig struct {
 | 
			
		||||
	namespaceID string
 | 
			
		||||
	stored      bool
 | 
			
		||||
 | 
			
		||||
	ContainerID  string
 | 
			
		||||
	HostUniqueID guid.GUID
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NewPersistedNamespaceConfig creates an in-memory namespace config that can be
 | 
			
		||||
// persisted to the registry.
 | 
			
		||||
func NewPersistedNamespaceConfig(namespaceID, containerID string, containerHostUniqueID guid.GUID) *PersistedNamespaceConfig {
 | 
			
		||||
	return &PersistedNamespaceConfig{
 | 
			
		||||
		namespaceID:  namespaceID,
 | 
			
		||||
		ContainerID:  containerID,
 | 
			
		||||
		HostUniqueID: containerHostUniqueID,
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// LoadPersistedNamespaceConfig loads a persisted config from the registry that matches
 | 
			
		||||
// `namespaceID`. If not found returns `regstate.NotFoundError`
 | 
			
		||||
func LoadPersistedNamespaceConfig(namespaceID string) (*PersistedNamespaceConfig, error) {
 | 
			
		||||
	sk, err := regstate.Open(cniRoot, false)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	defer sk.Close()
 | 
			
		||||
 | 
			
		||||
	pnc := PersistedNamespaceConfig{
 | 
			
		||||
		namespaceID: namespaceID,
 | 
			
		||||
		stored:      true,
 | 
			
		||||
	}
 | 
			
		||||
	if err := sk.Get(namespaceID, cniKey, &pnc); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return &pnc, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Store stores or updates the in-memory config to its registry state. If the
 | 
			
		||||
// store failes returns the store error.
 | 
			
		||||
func (pnc *PersistedNamespaceConfig) Store() error {
 | 
			
		||||
	if pnc.namespaceID == "" {
 | 
			
		||||
		return errors.New("invalid namespaceID ''")
 | 
			
		||||
	}
 | 
			
		||||
	if pnc.ContainerID == "" {
 | 
			
		||||
		return errors.New("invalid containerID ''")
 | 
			
		||||
	}
 | 
			
		||||
	empty := guid.GUID{}
 | 
			
		||||
	if pnc.HostUniqueID == empty {
 | 
			
		||||
		return errors.New("invalid containerHostUniqueID 'empy'")
 | 
			
		||||
	}
 | 
			
		||||
	sk, err := regstate.Open(cniRoot, false)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	defer sk.Close()
 | 
			
		||||
 | 
			
		||||
	if pnc.stored {
 | 
			
		||||
		if err := sk.Set(pnc.namespaceID, cniKey, pnc); err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		if err := sk.Create(pnc.namespaceID, cniKey, pnc); err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	pnc.stored = true
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Remove removes any persisted state associated with this config. If the config
 | 
			
		||||
// is not found in the registery `Remove` returns no error.
 | 
			
		||||
func (pnc *PersistedNamespaceConfig) Remove() error {
 | 
			
		||||
	if pnc.stored {
 | 
			
		||||
		sk, err := regstate.Open(cniRoot, false)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			if regstate.IsNotFoundError(err) {
 | 
			
		||||
				pnc.stored = false
 | 
			
		||||
				return nil
 | 
			
		||||
			}
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		defer sk.Close()
 | 
			
		||||
 | 
			
		||||
		if err := sk.Remove(pnc.namespaceID); err != nil {
 | 
			
		||||
			if regstate.IsNotFoundError(err) {
 | 
			
		||||
				pnc.stored = false
 | 
			
		||||
				return nil
 | 
			
		||||
			}
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	pnc.stored = false
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										287
									
								
								vendor/github.com/Microsoft/hcsshim/internal/regstate/regstate.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										287
									
								
								vendor/github.com/Microsoft/hcsshim/internal/regstate/regstate.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,287 @@
 | 
			
		||||
package regstate
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"net/url"
 | 
			
		||||
	"os"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
	"reflect"
 | 
			
		||||
	"syscall"
 | 
			
		||||
 | 
			
		||||
	"golang.org/x/sys/windows/registry"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
//go:generate go run $GOROOT/src/syscall/mksyscall_windows.go -output zsyscall_windows.go regstate.go
 | 
			
		||||
 | 
			
		||||
//sys	regCreateKeyEx(key syscall.Handle, subkey *uint16, reserved uint32, class *uint16, options uint32, desired uint32, sa *syscall.SecurityAttributes, result *syscall.Handle, disposition *uint32) (regerrno error) = advapi32.RegCreateKeyExW
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	_REG_OPTION_VOLATILE = 1
 | 
			
		||||
 | 
			
		||||
	_REG_CREATED_NEW_KEY     = 1
 | 
			
		||||
	_REG_OPENED_EXISTING_KEY = 2
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Key struct {
 | 
			
		||||
	registry.Key
 | 
			
		||||
	Name string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var localMachine = &Key{registry.LOCAL_MACHINE, "HKEY_LOCAL_MACHINE"}
 | 
			
		||||
var localUser = &Key{registry.CURRENT_USER, "HKEY_CURRENT_USER"}
 | 
			
		||||
 | 
			
		||||
var rootPath = `SOFTWARE\Microsoft\runhcs`
 | 
			
		||||
 | 
			
		||||
type NotFoundError struct {
 | 
			
		||||
	Id string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (err *NotFoundError) Error() string {
 | 
			
		||||
	return fmt.Sprintf("ID '%s' was not found", err.Id)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func IsNotFoundError(err error) bool {
 | 
			
		||||
	_, ok := err.(*NotFoundError)
 | 
			
		||||
	return ok
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type NoStateError struct {
 | 
			
		||||
	ID  string
 | 
			
		||||
	Key string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (err *NoStateError) Error() string {
 | 
			
		||||
	return fmt.Sprintf("state '%s' is not present for ID '%s'", err.Key, err.ID)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func createVolatileKey(k *Key, path string, access uint32) (newk *Key, openedExisting bool, err error) {
 | 
			
		||||
	var (
 | 
			
		||||
		h syscall.Handle
 | 
			
		||||
		d uint32
 | 
			
		||||
	)
 | 
			
		||||
	fullpath := filepath.Join(k.Name, path)
 | 
			
		||||
	err = regCreateKeyEx(syscall.Handle(k.Key), syscall.StringToUTF16Ptr(path), 0, nil, _REG_OPTION_VOLATILE, access, nil, &h, &d)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, false, &os.PathError{Op: "RegCreateKeyEx", Path: fullpath, Err: err}
 | 
			
		||||
	}
 | 
			
		||||
	return &Key{registry.Key(h), fullpath}, d == _REG_OPENED_EXISTING_KEY, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hive(perUser bool) *Key {
 | 
			
		||||
	r := localMachine
 | 
			
		||||
	if perUser {
 | 
			
		||||
		r = localUser
 | 
			
		||||
	}
 | 
			
		||||
	return r
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func Open(root string, perUser bool) (*Key, error) {
 | 
			
		||||
	k, _, err := createVolatileKey(hive(perUser), rootPath, registry.ALL_ACCESS)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	defer k.Close()
 | 
			
		||||
 | 
			
		||||
	k2, _, err := createVolatileKey(k, url.PathEscape(root), registry.ALL_ACCESS)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return k2, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func RemoveAll(root string, perUser bool) error {
 | 
			
		||||
	k, err := hive(perUser).open(rootPath)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	defer k.Close()
 | 
			
		||||
	r, err := k.open(url.PathEscape(root))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	defer r.Close()
 | 
			
		||||
	ids, err := r.Enumerate()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	for _, id := range ids {
 | 
			
		||||
		err = r.Remove(id)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	r.Close()
 | 
			
		||||
	return k.Remove(root)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (k *Key) Close() error {
 | 
			
		||||
	err := k.Key.Close()
 | 
			
		||||
	k.Key = 0
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (k *Key) Enumerate() ([]string, error) {
 | 
			
		||||
	escapedIDs, err := k.ReadSubKeyNames(0)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	var ids []string
 | 
			
		||||
	for _, e := range escapedIDs {
 | 
			
		||||
		id, err := url.PathUnescape(e)
 | 
			
		||||
		if err == nil {
 | 
			
		||||
			ids = append(ids, id)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return ids, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (k *Key) open(name string) (*Key, error) {
 | 
			
		||||
	fullpath := filepath.Join(k.Name, name)
 | 
			
		||||
	nk, err := registry.OpenKey(k.Key, name, registry.ALL_ACCESS)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, &os.PathError{Op: "RegOpenKey", Path: fullpath, Err: err}
 | 
			
		||||
	}
 | 
			
		||||
	return &Key{nk, fullpath}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (k *Key) openid(id string) (*Key, error) {
 | 
			
		||||
	escaped := url.PathEscape(id)
 | 
			
		||||
	fullpath := filepath.Join(k.Name, escaped)
 | 
			
		||||
	nk, err := k.open(escaped)
 | 
			
		||||
	if perr, ok := err.(*os.PathError); ok && perr.Err == syscall.ERROR_FILE_NOT_FOUND {
 | 
			
		||||
		return nil, &NotFoundError{id}
 | 
			
		||||
	}
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, &os.PathError{Op: "RegOpenKey", Path: fullpath, Err: err}
 | 
			
		||||
	}
 | 
			
		||||
	return nk, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (k *Key) Remove(id string) error {
 | 
			
		||||
	escaped := url.PathEscape(id)
 | 
			
		||||
	err := registry.DeleteKey(k.Key, escaped)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		if err == syscall.ERROR_FILE_NOT_FOUND {
 | 
			
		||||
			return &NotFoundError{id}
 | 
			
		||||
		}
 | 
			
		||||
		return &os.PathError{Op: "RegDeleteKey", Path: filepath.Join(k.Name, escaped), Err: err}
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (k *Key) set(id string, create bool, key string, state interface{}) error {
 | 
			
		||||
	var sk *Key
 | 
			
		||||
	var err error
 | 
			
		||||
	if create {
 | 
			
		||||
		var existing bool
 | 
			
		||||
		eid := url.PathEscape(id)
 | 
			
		||||
		sk, existing, err = createVolatileKey(k, eid, registry.ALL_ACCESS)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		defer sk.Close()
 | 
			
		||||
		if existing {
 | 
			
		||||
			sk.Close()
 | 
			
		||||
			return fmt.Errorf("container %s already exists", id)
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		sk, err = k.openid(id)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		defer sk.Close()
 | 
			
		||||
	}
 | 
			
		||||
	switch reflect.TypeOf(state).Kind() {
 | 
			
		||||
	case reflect.Bool:
 | 
			
		||||
		v := uint32(0)
 | 
			
		||||
		if state.(bool) {
 | 
			
		||||
			v = 1
 | 
			
		||||
		}
 | 
			
		||||
		err = sk.SetDWordValue(key, v)
 | 
			
		||||
	case reflect.Int:
 | 
			
		||||
		err = sk.SetQWordValue(key, uint64(state.(int)))
 | 
			
		||||
	case reflect.String:
 | 
			
		||||
		err = sk.SetStringValue(key, state.(string))
 | 
			
		||||
	default:
 | 
			
		||||
		var js []byte
 | 
			
		||||
		js, err = json.Marshal(state)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		err = sk.SetBinaryValue(key, js)
 | 
			
		||||
	}
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		if err == syscall.ERROR_FILE_NOT_FOUND {
 | 
			
		||||
			return &NoStateError{id, key}
 | 
			
		||||
		}
 | 
			
		||||
		return &os.PathError{Op: "RegSetValueEx", Path: sk.Name + ":" + key, Err: err}
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (k *Key) Create(id, key string, state interface{}) error {
 | 
			
		||||
	return k.set(id, true, key, state)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (k *Key) Set(id, key string, state interface{}) error {
 | 
			
		||||
	return k.set(id, false, key, state)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (k *Key) Clear(id, key string) error {
 | 
			
		||||
	sk, err := k.openid(id)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	defer sk.Close()
 | 
			
		||||
	err = sk.DeleteValue(key)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		if err == syscall.ERROR_FILE_NOT_FOUND {
 | 
			
		||||
			return &NoStateError{id, key}
 | 
			
		||||
		}
 | 
			
		||||
		return &os.PathError{Op: "RegDeleteValue", Path: sk.Name + ":" + key, Err: err}
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (k *Key) Get(id, key string, state interface{}) error {
 | 
			
		||||
	sk, err := k.openid(id)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	defer sk.Close()
 | 
			
		||||
 | 
			
		||||
	var js []byte
 | 
			
		||||
	switch reflect.TypeOf(state).Elem().Kind() {
 | 
			
		||||
	case reflect.Bool:
 | 
			
		||||
		var v uint64
 | 
			
		||||
		v, _, err = sk.GetIntegerValue(key)
 | 
			
		||||
		if err == nil {
 | 
			
		||||
			*state.(*bool) = v != 0
 | 
			
		||||
		}
 | 
			
		||||
	case reflect.Int:
 | 
			
		||||
		var v uint64
 | 
			
		||||
		v, _, err = sk.GetIntegerValue(key)
 | 
			
		||||
		if err == nil {
 | 
			
		||||
			*state.(*int) = int(v)
 | 
			
		||||
		}
 | 
			
		||||
	case reflect.String:
 | 
			
		||||
		var v string
 | 
			
		||||
		v, _, err = sk.GetStringValue(key)
 | 
			
		||||
		if err == nil {
 | 
			
		||||
			*state.(*string) = string(v)
 | 
			
		||||
		}
 | 
			
		||||
	default:
 | 
			
		||||
		js, _, err = sk.GetBinaryValue(key)
 | 
			
		||||
	}
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		if err == syscall.ERROR_FILE_NOT_FOUND {
 | 
			
		||||
			return &NoStateError{id, key}
 | 
			
		||||
		}
 | 
			
		||||
		return &os.PathError{Op: "RegQueryValueEx", Path: sk.Name + ":" + key, Err: err}
 | 
			
		||||
	}
 | 
			
		||||
	if js != nil {
 | 
			
		||||
		err = json.Unmarshal(js, state)
 | 
			
		||||
	}
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										51
									
								
								vendor/github.com/Microsoft/hcsshim/internal/regstate/zsyscall_windows.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								vendor/github.com/Microsoft/hcsshim/internal/regstate/zsyscall_windows.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,51 @@
 | 
			
		||||
// Code generated by 'go generate'; DO NOT EDIT.
 | 
			
		||||
 | 
			
		||||
package regstate
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"syscall"
 | 
			
		||||
	"unsafe"
 | 
			
		||||
 | 
			
		||||
	"golang.org/x/sys/windows"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var _ unsafe.Pointer
 | 
			
		||||
 | 
			
		||||
// Do the interface allocations only once for common
 | 
			
		||||
// Errno values.
 | 
			
		||||
const (
 | 
			
		||||
	errnoERROR_IO_PENDING = 997
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING)
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// errnoErr returns common boxed Errno values, to prevent
 | 
			
		||||
// allocations at runtime.
 | 
			
		||||
func errnoErr(e syscall.Errno) error {
 | 
			
		||||
	switch e {
 | 
			
		||||
	case 0:
 | 
			
		||||
		return nil
 | 
			
		||||
	case errnoERROR_IO_PENDING:
 | 
			
		||||
		return errERROR_IO_PENDING
 | 
			
		||||
	}
 | 
			
		||||
	// TODO: add more here, after collecting data on the common
 | 
			
		||||
	// error values see on Windows. (perhaps when running
 | 
			
		||||
	// all.bat?)
 | 
			
		||||
	return e
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	modadvapi32 = windows.NewLazySystemDLL("advapi32.dll")
 | 
			
		||||
 | 
			
		||||
	procRegCreateKeyExW = modadvapi32.NewProc("RegCreateKeyExW")
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func regCreateKeyEx(key syscall.Handle, subkey *uint16, reserved uint32, class *uint16, options uint32, desired uint32, sa *syscall.SecurityAttributes, result *syscall.Handle, disposition *uint32) (regerrno error) {
 | 
			
		||||
	r0, _, _ := syscall.Syscall9(procRegCreateKeyExW.Addr(), 9, uintptr(key), uintptr(unsafe.Pointer(subkey)), uintptr(reserved), uintptr(unsafe.Pointer(class)), uintptr(options), uintptr(desired), uintptr(unsafe.Pointer(sa)), uintptr(unsafe.Pointer(result)), uintptr(unsafe.Pointer(disposition)))
 | 
			
		||||
	if r0 != 0 {
 | 
			
		||||
		regerrno = syscall.Errno(r0)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user