hnssupport.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package hns
  2. import (
  3. "github.com/sirupsen/logrus"
  4. )
  5. type HNSSupportedFeatures struct {
  6. Acl HNSAclFeatures `json:"ACL"`
  7. }
  8. type HNSAclFeatures struct {
  9. AclAddressLists bool `json:"AclAddressLists"`
  10. AclNoHostRulePriority bool `json:"AclHostRulePriority"`
  11. AclPortRanges bool `json:"AclPortRanges"`
  12. AclRuleId bool `json:"AclRuleId"`
  13. }
  14. func GetHNSSupportedFeatures() HNSSupportedFeatures {
  15. var hnsFeatures HNSSupportedFeatures
  16. globals, err := GetHNSGlobals()
  17. if err != nil {
  18. // Expected on pre-1803 builds, all features will be false/unsupported
  19. logrus.Debugf("Unable to obtain HNS globals: %s", err)
  20. return hnsFeatures
  21. }
  22. hnsFeatures.Acl = HNSAclFeatures{
  23. AclAddressLists: isHNSFeatureSupported(globals.Version, HNSVersion1803),
  24. AclNoHostRulePriority: isHNSFeatureSupported(globals.Version, HNSVersion1803),
  25. AclPortRanges: isHNSFeatureSupported(globals.Version, HNSVersion1803),
  26. AclRuleId: isHNSFeatureSupported(globals.Version, HNSVersion1803),
  27. }
  28. return hnsFeatures
  29. }
  30. func isHNSFeatureSupported(currentVersion HNSVersion, minVersionSupported HNSVersion) bool {
  31. if currentVersion.Major < minVersionSupported.Major {
  32. return false
  33. }
  34. if currentVersion.Major > minVersionSupported.Major {
  35. return true
  36. }
  37. if currentVersion.Minor < minVersionSupported.Minor {
  38. return false
  39. }
  40. return true
  41. }