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. (microsoft#2139)

Signed-off-by: Prince Pereira <ppereira@microsoft.com>
  • Loading branch information
princepereira committed Jun 14, 2024
1 parent a3c4052 commit 35f5136
Show file tree
Hide file tree
Showing 4 changed files with 37 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")
}

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

// VxlanPortSupported returns an error if the HCN version does not support configuring the VXLAN TCP port.
func VxlanPortSupported() error {
supported, err := GetCachedSupportedFeatures()
Expand Down
6 changes: 6 additions & 0 deletions hcn/hcnerrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/Microsoft/hcsshim/internal/hcserror"
"github.com/Microsoft/hcsshim/internal/interop"
"github.com/sirupsen/logrus"
"golang.org/x/sys/windows"
)

var (
Expand Down Expand Up @@ -50,6 +51,7 @@ type ErrorCode uint32
const (
ERROR_NOT_FOUND = 0x490
HCN_E_PORT_ALREADY_EXISTS ErrorCode = 0x803b0013
HCN_E_NOTIMPL ErrorCode = ErrorCode(windows.E_NOTIMPL)
)

type HcnError struct {
Expand Down Expand Up @@ -77,6 +79,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
11 changes: 11 additions & 0 deletions hcn/hcnglobals.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ var (

//HNS 14.0 allows for TierAcl Policy support
TierAclPolicyVersion = VersionRanges{VersionRange{MinVersion: Version{Major: 14, Minor: 0}, MaxVersion: Version{Major: math.MaxInt32, Minor: math.MaxInt32}}}

//HNS 15.0 allows for NetworkACL Policy support
NetworkACLPolicyVersion = VersionRanges{VersionRange{MinVersion: Version{Major: 15, Minor: 0}, MaxVersion: Version{Major: math.MaxInt32, Minor: math.MaxInt32}}}

//HNS 15.0 allows for NestedIpSet support
NestedIpSetVersion = VersionRanges{VersionRange{MinVersion: Version{Major: 15, Minor: 0}, MaxVersion: Version{Major: math.MaxInt32, Minor: math.MaxInt32}}}

//HNS 15.1 allows support for DisableHostPort flag.
DisableHostPortVersion = VersionRanges{VersionRange{MinVersion: Version{Major: 15, Minor: 1}, MaxVersion: Version{Major: math.MaxInt32, Minor: math.MaxInt32}}}
// HNS 15.4 allows for Modify Loadbalancer support
ModifyLoadbalancerVersion = VersionRanges{VersionRange{MinVersion: Version{Major: 15, Minor: 4}, MaxVersion: Version{Major: math.MaxInt32, Minor: math.MaxInt32}}}
)

// GetGlobals returns the global properties of the HCN Service.
Expand Down
8 changes: 8 additions & 0 deletions hcn/hcnsupport.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ type SupportedFeatures struct {
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
TierAcl bool `json:"TierAcl"`
NetworkACL bool `json:"NetworkACL"`
NestedIpSet bool `json:"NestedIpSet"`
DisableHostPort bool `json:"DisableHostPort"`
ModifyLoadbalancer bool `json:"ModifyLoadbalancer"`
}

// AclFeatures are the supported ACL possibilities.
Expand Down Expand Up @@ -107,6 +111,10 @@ func getSupportedFeatures() (SupportedFeatures, error) {
features.L4Proxy = isFeatureSupported(globals.Version, L4ProxyPolicyVersion)
features.L4WfpProxy = isFeatureSupported(globals.Version, L4WfpProxyPolicyVersion)
features.TierAcl = isFeatureSupported(globals.Version, TierAclPolicyVersion)
features.NetworkACL = isFeatureSupported(globals.Version, NetworkACLPolicyVersion)
features.NestedIpSet = isFeatureSupported(globals.Version, NestedIpSetVersion)
features.DisableHostPort = isFeatureSupported(globals.Version, DisableHostPortVersion)
features.ModifyLoadbalancer = isFeatureSupported(globals.Version, ModifyLoadbalancerVersion)

logrus.WithFields(logrus.Fields{
"version": fmt.Sprintf("%+v", globals.Version),
Expand Down

0 comments on commit 35f5136

Please sign in to comment.