Skip to content

Commit

Permalink
Changes for checking the global version for modify policy version sup…
Browse files Browse the repository at this point in the history
…port.
  • Loading branch information
princepereira committed May 13, 2024
1 parent 46ef279 commit 29907e1
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions hcn/hcn.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,18 @@ func SetPolicySupported() error {
return platformDoesNotSupportError("SetPolicy")
}

// ModifyPolicySupported returns an error if the HCN version does not support ModifyPolicy.
func ModifyPolicySupported() error {
supported, err := GetCachedSupportedFeatures()
if err != nil {
return err
}
if supported.ModifyPolicy {
return nil
}
return platformDoesNotSupportError("ModifyPolicy")
}

// VxlanPortSupported returns an error if the HCN version does not support configuring the VXLAN TCP port.
func VxlanPortSupported() error {
supported, err := GetCachedSupportedFeatures()
Expand Down
5 changes: 5 additions & 0 deletions hcn/hcnerrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type ErrorCode uint32
const (
ERROR_NOT_FOUND = ErrorCode(windows.ERROR_NOT_FOUND)
HCN_E_PORT_ALREADY_EXISTS ErrorCode = ErrorCode(windows.HCN_E_PORT_ALREADY_EXISTS)
HCN_E_NOTIMPL ErrorCode = ErrorCode(windows.E_NOTIMPL)
)

type HcnError struct {
Expand Down Expand Up @@ -79,6 +80,10 @@ func IsPortAlreadyExistsError(err error) bool {
return CheckErrorWithCode(err, HCN_E_PORT_ALREADY_EXISTS)
}

func IsNotImplemented(err error) bool {
return CheckErrorWithCode(err, HCN_E_NOTIMPL)
}

func new(hr error, title string, rest string) error {
err := &HcnError{}
hcsError := hcserror.New(hr, title, rest)
Expand Down
2 changes: 2 additions & 0 deletions hcn/hcnglobals.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ var (
}
// HNS 13.0 allows for Set Policy support
SetPolicyVersion = VersionRanges{VersionRange{MinVersion: Version{Major: 13, Minor: 0}, MaxVersion: Version{Major: math.MaxInt32, Minor: math.MaxInt32}}}
// HNS 15.4 allows for Modify Policy support
ModifyPolicyVersion = VersionRanges{VersionRange{MinVersion: Version{Major: 15, Minor: 4}, MaxVersion: Version{Major: math.MaxInt32, Minor: math.MaxInt32}}}
// HNS 10.3 allows for VXLAN ports
VxlanPortVersion = VersionRanges{VersionRange{MinVersion: Version{Major: 10, Minor: 3}, MaxVersion: Version{Major: math.MaxInt32, Minor: math.MaxInt32}}}

Expand Down
1 change: 1 addition & 0 deletions hcn/hcnpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const (
VxlanPort NetworkPolicyType = "VxlanPort"
HostRoute NetworkPolicyType = "HostRoute"
SetPolicy NetworkPolicyType = "SetPolicy"
ModifyPolicy NetworkPolicyType = "ModifyPolicy"
NetworkL4Proxy NetworkPolicyType = "L4Proxy"
LayerConstraint NetworkPolicyType = "LayerConstraint"
NetworkACL NetworkPolicyType = "NetworkACL"
Expand Down
2 changes: 2 additions & 0 deletions hcn/hcnsupport.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type SupportedFeatures struct {
SessionAffinity bool `json:"SessionAffinity"`
IPv6DualStack bool `json:"IPv6DualStack"`
SetPolicy bool `json:"SetPolicy"`
ModifyPolicy bool `json:"ModifyPolicy"`
VxlanPort bool `json:"VxlanPort"`
L4Proxy bool `json:"L4Proxy"` // network policy that applies VFP rules to all endpoints on the network to redirect traffic
L4WfpProxy bool `json:"L4WfpProxy"` // endpoint policy that applies WFP filters to redirect traffic to/from that endpoint
Expand Down Expand Up @@ -109,6 +110,7 @@ func getSupportedFeatures() (SupportedFeatures, error) {
features.SessionAffinity = isFeatureSupported(globals.Version, SessionAffinityVersion)
features.IPv6DualStack = isFeatureSupported(globals.Version, IPv6DualStackVersion)
features.SetPolicy = isFeatureSupported(globals.Version, SetPolicyVersion)
features.ModifyPolicy = isFeatureSupported(globals.Version, ModifyPolicyVersion)
features.VxlanPort = isFeatureSupported(globals.Version, VxlanPortVersion)
features.L4Proxy = isFeatureSupported(globals.Version, L4ProxyPolicyVersion)
features.L4WfpProxy = isFeatureSupported(globals.Version, L4WfpProxyPolicyVersion)
Expand Down

0 comments on commit 29907e1

Please sign in to comment.