summaryrefslogtreecommitdiff
path: root/vendor/github.com/cilium/ebpf/internal/feature.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/cilium/ebpf/internal/feature.go')
-rw-r--r--vendor/github.com/cilium/ebpf/internal/feature.go48
1 files changed, 5 insertions, 43 deletions
diff --git a/vendor/github.com/cilium/ebpf/internal/feature.go b/vendor/github.com/cilium/ebpf/internal/feature.go
index ec62ed39b..0a6c2d1d5 100644
--- a/vendor/github.com/cilium/ebpf/internal/feature.go
+++ b/vendor/github.com/cilium/ebpf/internal/feature.go
@@ -54,11 +54,6 @@ type FeatureTestFn func() error
//
// Returns an error wrapping ErrNotSupported if the feature is not supported.
func FeatureTest(name, version string, fn FeatureTestFn) func() error {
- v, err := NewVersion(version)
- if err != nil {
- return func() error { return err }
- }
-
ft := new(featureTest)
return func() error {
ft.RLock()
@@ -79,6 +74,11 @@ func FeatureTest(name, version string, fn FeatureTestFn) func() error {
err := fn()
switch {
case errors.Is(err, ErrNotSupported):
+ v, err := NewVersion(version)
+ if err != nil {
+ return err
+ }
+
ft.result = &UnsupportedFeatureError{
MinimumVersion: v,
Name: name,
@@ -98,41 +98,3 @@ func FeatureTest(name, version string, fn FeatureTestFn) func() error {
return ft.result
}
}
-
-// A Version in the form Major.Minor.Patch.
-type Version [3]uint16
-
-// NewVersion creates a version from a string like "Major.Minor.Patch".
-//
-// Patch is optional.
-func NewVersion(ver string) (Version, error) {
- var major, minor, patch uint16
- n, _ := fmt.Sscanf(ver, "%d.%d.%d", &major, &minor, &patch)
- if n < 2 {
- return Version{}, fmt.Errorf("invalid version: %s", ver)
- }
- return Version{major, minor, patch}, nil
-}
-
-func (v Version) String() string {
- if v[2] == 0 {
- return fmt.Sprintf("v%d.%d", v[0], v[1])
- }
- return fmt.Sprintf("v%d.%d.%d", v[0], v[1], v[2])
-}
-
-// Less returns true if the version is less than another version.
-func (v Version) Less(other Version) bool {
- for i, a := range v {
- if a == other[i] {
- continue
- }
- return a < other[i]
- }
- return false
-}
-
-// Unspecified returns true if the version is all zero.
-func (v Version) Unspecified() bool {
- return v[0] == 0 && v[1] == 0 && v[2] == 0
-}