Skip to content

Commit 951bb28

Browse files
rgo3ti-mo
authored andcommitted
features: rename HaveProgType API
In order to be in line with other naming schemes throughout the library this commit deprecates HaveProgType() in favor of HaveProgamType(). Signed-off-by: Robin Gögge <[email protected]>
1 parent d1edf5a commit 951bb28

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

features/prog.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
func init() {
18-
pc.progTypes = make(map[ebpf.ProgramType]error)
18+
pc.types = make(map[ebpf.ProgramType]error)
1919
pc.helpers = make(map[ebpf.ProgramType]map[asm.BuiltinFunc]error)
2020
allocHelperCache()
2121
}
@@ -31,8 +31,8 @@ var (
3131
)
3232

3333
type progCache struct {
34-
typeMu sync.Mutex
35-
progTypes map[ebpf.ProgramType]error
34+
typeMu sync.Mutex
35+
types map[ebpf.ProgramType]error
3636

3737
helperMu sync.Mutex
3838
helpers map[ebpf.ProgramType]map[asm.BuiltinFunc]error
@@ -95,17 +95,22 @@ func createProgLoadAttr(pt ebpf.ProgramType, helper asm.BuiltinFunc) (*sys.ProgL
9595

9696
// HaveProgType probes the running kernel for the availability of the specified program type.
9797
//
98+
// Deprecated: use HaveProgramType() instead.
99+
var HaveProgType = HaveProgramType
100+
101+
// HaveProgramType probes the running kernel for the availability of the specified program type.
102+
//
98103
// See the package documentation for the meaning of the error return value.
99-
func HaveProgType(pt ebpf.ProgramType) error {
100-
if err := validateProgType(pt); err != nil {
104+
func HaveProgramType(pt ebpf.ProgramType) error {
105+
if err := validateProgramType(pt); err != nil {
101106
return err
102107
}
103108

104-
return haveProgType(pt)
109+
return haveProgramType(pt)
105110

106111
}
107112

108-
func validateProgType(pt ebpf.ProgramType) error {
113+
func validateProgramType(pt ebpf.ProgramType) error {
109114
if pt > pt.Max() {
110115
return os.ErrInvalid
111116
}
@@ -120,10 +125,10 @@ func validateProgType(pt ebpf.ProgramType) error {
120125
return nil
121126
}
122127

123-
func haveProgType(pt ebpf.ProgramType) error {
128+
func haveProgramType(pt ebpf.ProgramType) error {
124129
pc.typeMu.Lock()
125130
defer pc.typeMu.Unlock()
126-
if err, ok := pc.progTypes[pt]; ok {
131+
if err, ok := pc.types[pt]; ok {
127132
return err
128133
}
129134

@@ -154,7 +159,7 @@ func haveProgType(pt ebpf.ProgramType) error {
154159
fd.Close()
155160
}
156161

157-
pc.progTypes[pt] = err
162+
pc.types[pt] = err
158163

159164
return err
160165
}
@@ -173,7 +178,7 @@ func haveProgType(pt ebpf.ProgramType) error {
173178
//
174179
// Probe results are cached and persist throughout any process capability changes.
175180
func HaveProgramHelper(pt ebpf.ProgramType, helper asm.BuiltinFunc) error {
176-
if err := validateProgType(pt); err != nil {
181+
if err := validateProgramType(pt); err != nil {
177182
return err
178183
}
179184

features/prog_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var progTypeMinVersion = map[ebpf.ProgramType]string{
4747
ebpf.Syscall: "5.14",
4848
}
4949

50-
func TestHaveProgType(t *testing.T) {
50+
func TestHaveProgramType(t *testing.T) {
5151
for progType := ebpf.UnspecifiedProgram + 1; progType <= progType.Max(); progType++ {
5252
// Need inner loop copy to make use of t.Parallel()
5353
pt := progType
@@ -69,7 +69,7 @@ func TestHaveProgType(t *testing.T) {
6969
}
7070
testutils.SkipOnOldKernel(t, minVersion, feature)
7171

72-
if err := HaveProgType(pt); err != nil {
72+
if err := HaveProgramType(pt); err != nil {
7373
if pt == ebpf.LircMode2 {
7474
// CI kernels are built with CONFIG_BPF_LIRC_MODE2, but some
7575
// mainstream distro's don't ship with it. Make this prog type
@@ -84,14 +84,14 @@ func TestHaveProgType(t *testing.T) {
8484
}
8585
}
8686

87-
func TestHaveProgTypeUnsupported(t *testing.T) {
88-
if err := haveProgType(ebpf.ProgramType(math.MaxUint32)); err != ebpf.ErrNotSupported {
87+
func TestHaveProgramTypeUnsupported(t *testing.T) {
88+
if err := haveProgramType(ebpf.ProgramType(math.MaxUint32)); err != ebpf.ErrNotSupported {
8989
t.Fatalf("Expected ebpf.ErrNotSupported but was: %v", err)
9090
}
9191
}
9292

93-
func TestHaveProgTypeInvalid(t *testing.T) {
94-
if err := HaveProgType(ebpf.ProgramType(math.MaxUint32)); err != os.ErrInvalid {
93+
func TestHaveProgramTypeInvalid(t *testing.T) {
94+
if err := HaveProgramType(ebpf.ProgramType(math.MaxUint32)); err != os.ErrInvalid {
9595
t.Fatalf("Expected os.ErrInvalid but was: %v", err)
9696
}
9797
}

0 commit comments

Comments
 (0)