hcnsupport.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package hcn
  2. import (
  3. "github.com/sirupsen/logrus"
  4. )
  5. // SupportedFeatures are the features provided by the Service.
  6. type SupportedFeatures struct {
  7. Acl AclFeatures `json:"ACL"`
  8. Api ApiSupport `json:"API"`
  9. RemoteSubnet bool `json:"RemoteSubnet"`
  10. HostRoute bool `json:"HostRoute"`
  11. DSR bool `json:"DSR"`
  12. }
  13. // AclFeatures are the supported ACL possibilities.
  14. type AclFeatures struct {
  15. AclAddressLists bool `json:"AclAddressLists"`
  16. AclNoHostRulePriority bool `json:"AclHostRulePriority"`
  17. AclPortRanges bool `json:"AclPortRanges"`
  18. AclRuleId bool `json:"AclRuleId"`
  19. }
  20. // ApiSupport lists the supported API versions.
  21. type ApiSupport struct {
  22. V1 bool `json:"V1"`
  23. V2 bool `json:"V2"`
  24. }
  25. // GetSupportedFeatures returns the features supported by the Service.
  26. func GetSupportedFeatures() SupportedFeatures {
  27. var features SupportedFeatures
  28. globals, err := GetGlobals()
  29. if err != nil {
  30. // Expected on pre-1803 builds, all features will be false/unsupported
  31. logrus.Debugf("Unable to obtain globals: %s", err)
  32. return features
  33. }
  34. features.Acl = AclFeatures{
  35. AclAddressLists: isFeatureSupported(globals.Version, HNSVersion1803),
  36. AclNoHostRulePriority: isFeatureSupported(globals.Version, HNSVersion1803),
  37. AclPortRanges: isFeatureSupported(globals.Version, HNSVersion1803),
  38. AclRuleId: isFeatureSupported(globals.Version, HNSVersion1803),
  39. }
  40. features.Api = ApiSupport{
  41. V2: isFeatureSupported(globals.Version, V2ApiSupport),
  42. V1: true, // HNSCall is still available.
  43. }
  44. features.RemoteSubnet = isFeatureSupported(globals.Version, RemoteSubnetVersion)
  45. features.HostRoute = isFeatureSupported(globals.Version, HostRouteVersion)
  46. features.DSR = isFeatureSupported(globals.Version, DSRVersion)
  47. return features
  48. }
  49. func isFeatureSupported(currentVersion Version, minVersionSupported Version) bool {
  50. if currentVersion.Major < minVersionSupported.Major {
  51. return false
  52. }
  53. if currentVersion.Major > minVersionSupported.Major {
  54. return true
  55. }
  56. if currentVersion.Minor < minVersionSupported.Minor {
  57. return false
  58. }
  59. return true
  60. }