diff --git a/Makefile b/Makefile index 0ffc844eb..4f53b37f3 100644 --- a/Makefile +++ b/Makefile @@ -92,8 +92,8 @@ all: format $(addsuffix -el.elf,$(TARGETS)) $(addsuffix -eb.elf,$(TARGETS)) gene ln -srf testdata/loader-$(CLANG)-eb.elf testdata/loader-eb.elf generate: - go generate -run "internal/cmd/gentypes" ./... - go generate -skip "internal/cmd/gentypes" ./... + go generate -run "gentypes" ./... + go generate -skip "gentypes" ./... testdata/loader-%-el.elf: testdata/loader.c $* $(CFLAGS) -target bpfel -c $< -o $@ diff --git a/asm/alu.go b/asm/alu.go index 282233d32..a4ae72212 100644 --- a/asm/alu.go +++ b/asm/alu.go @@ -1,6 +1,6 @@ package asm -//go:generate go run golang.org/x/tools/cmd/stringer@latest -output alu_string.go -type=Source,Endianness,ALUOp +//go:generate go tool stringer -output alu_string.go -type=Source,Endianness,ALUOp // Source of ALU / ALU64 / Branch operations // diff --git a/asm/func.go b/asm/func.go index 5ee4e954f..fe75c7578 100644 --- a/asm/func.go +++ b/asm/func.go @@ -2,7 +2,7 @@ package asm import "github.com/cilium/ebpf/internal/platform" -//go:generate go run golang.org/x/tools/cmd/stringer@latest -output func_string.go -type=BuiltinFunc +//go:generate go tool stringer -output func_string.go -type=BuiltinFunc // BuiltinFunc is a built-in eBPF function. type BuiltinFunc uint32 diff --git a/asm/jump.go b/asm/jump.go index 2738d736b..a14bc4c89 100644 --- a/asm/jump.go +++ b/asm/jump.go @@ -1,6 +1,6 @@ package asm -//go:generate go run golang.org/x/tools/cmd/stringer@latest -output jump_string.go -type=JumpOp +//go:generate go tool stringer -output jump_string.go -type=JumpOp // JumpOp affect control flow. // diff --git a/asm/load_store.go b/asm/load_store.go index 29571a74e..a32a9b318 100644 --- a/asm/load_store.go +++ b/asm/load_store.go @@ -2,7 +2,7 @@ package asm import "fmt" -//go:generate go run golang.org/x/tools/cmd/stringer@latest -output load_store_string.go -type=Mode,Size +//go:generate go tool stringer -output load_store_string.go -type=Mode,Size // Mode for load and store operations // diff --git a/asm/opcode.go b/asm/opcode.go index c82a1f8fb..9b2f80f0a 100644 --- a/asm/opcode.go +++ b/asm/opcode.go @@ -5,7 +5,7 @@ import ( "strings" ) -//go:generate go run golang.org/x/tools/cmd/stringer@latest -output opcode_string.go -type=Class +//go:generate go tool stringer -output opcode_string.go -type=Class // Class of operations // diff --git a/asm/opcode_string.go b/asm/opcode_string.go index 58bc3e7e7..07825e0dd 100644 --- a/asm/opcode_string.go +++ b/asm/opcode_string.go @@ -23,8 +23,9 @@ const _Class_name = "LdClassLdXClassStClassStXClassALUClassJumpClassJump32ClassA var _Class_index = [...]uint8{0, 7, 15, 22, 30, 38, 47, 58, 68} func (i Class) String() string { - if i >= Class(len(_Class_index)-1) { + idx := int(i) - 0 + if i < 0 || idx >= len(_Class_index)-1 { return "Class(" + strconv.FormatInt(int64(i), 10) + ")" } - return _Class_name[_Class_index[i]:_Class_index[i+1]] + return _Class_name[_Class_index[idx]:_Class_index[idx+1]] } diff --git a/btf/btf_types.go b/btf/btf_types.go index d227e416c..c957f5970 100644 --- a/btf/btf_types.go +++ b/btf/btf_types.go @@ -7,7 +7,7 @@ import ( "unsafe" ) -//go:generate go run golang.org/x/tools/cmd/stringer@latest -linecomment -output=btf_types_string.go -type=FuncLinkage,VarLinkage,btfKind +//go:generate go tool stringer -linecomment -output=btf_types_string.go -type=FuncLinkage,VarLinkage,btfKind // btfKind describes a Type. type btfKind uint8 diff --git a/btf/btf_types_string.go b/btf/btf_types_string.go index b7a1b80d1..a9d2d82b6 100644 --- a/btf/btf_types_string.go +++ b/btf/btf_types_string.go @@ -18,10 +18,11 @@ const _FuncLinkage_name = "staticglobalextern" var _FuncLinkage_index = [...]uint8{0, 6, 12, 18} func (i FuncLinkage) String() string { - if i < 0 || i >= FuncLinkage(len(_FuncLinkage_index)-1) { + idx := int(i) - 0 + if i < 0 || idx >= len(_FuncLinkage_index)-1 { return "FuncLinkage(" + strconv.FormatInt(int64(i), 10) + ")" } - return _FuncLinkage_name[_FuncLinkage_index[i]:_FuncLinkage_index[i+1]] + return _FuncLinkage_name[_FuncLinkage_index[idx]:_FuncLinkage_index[idx+1]] } func _() { // An "invalid array index" compiler error signifies that the constant values have changed. @@ -37,10 +38,11 @@ const _VarLinkage_name = "staticglobalextern" var _VarLinkage_index = [...]uint8{0, 6, 12, 18} func (i VarLinkage) String() string { - if i < 0 || i >= VarLinkage(len(_VarLinkage_index)-1) { + idx := int(i) - 0 + if i < 0 || idx >= len(_VarLinkage_index)-1 { return "VarLinkage(" + strconv.FormatInt(int64(i), 10) + ")" } - return _VarLinkage_name[_VarLinkage_index[i]:_VarLinkage_index[i+1]] + return _VarLinkage_name[_VarLinkage_index[idx]:_VarLinkage_index[idx+1]] } func _() { // An "invalid array index" compiler error signifies that the constant values have changed. @@ -73,8 +75,9 @@ const _btfKind_name = "UnknownIntPointerArrayStructUnionEnumForwardTypedefVolati var _btfKind_index = [...]uint8{0, 7, 10, 17, 22, 28, 33, 37, 44, 51, 59, 64, 72, 76, 85, 88, 95, 100, 107, 114, 120} func (i btfKind) String() string { - if i >= btfKind(len(_btfKind_index)-1) { + idx := int(i) - 0 + if i < 0 || idx >= len(_btfKind_index)-1 { return "btfKind(" + strconv.FormatInt(int64(i), 10) + ")" } - return _btfKind_name[_btfKind_index[i]:_btfKind_index[i+1]] + return _btfKind_name[_btfKind_index[idx]:_btfKind_index[idx+1]] } diff --git a/cmd/bpf2go/README.md b/cmd/bpf2go/README.md index 5f33b81e1..052efdddb 100644 --- a/cmd/bpf2go/README.md +++ b/cmd/bpf2go/README.md @@ -7,9 +7,13 @@ eBPF from disk at runtime and to minimise the amount of manual work required to interact with eBPF programs. It takes inspiration from `bpftool gen skeleton`. -Invoke the program using go generate: +Add `bpf2go` as a tool dependency in your project's Go module: - //go:generate go run github.com/cilium/ebpf/cmd/bpf2go foo path/to/src.c -- -I/path/to/include + go get -tool github.com/cilium/ebpf/cmd/bpf2go + +Invoke the tool using go generate: + + //go:generate go tool bpf2go foo path/to/src.c -- -I/path/to/include This will emit `foo_bpfel.go` and `foo_bpfeb.go`, with types using `foo` as a stem. The two files contain compiled BPF for little and big diff --git a/cmd/bpf2go/test/doc.go b/cmd/bpf2go/test/doc.go index 92ff2e295..c2bcc80cb 100644 --- a/cmd/bpf2go/test/doc.go +++ b/cmd/bpf2go/test/doc.go @@ -2,4 +2,4 @@ // specific API. package test -//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -tags linux test ../testdata/minimal.c +//go:generate go tool bpf2go -tags linux test ../testdata/minimal.c diff --git a/docs/ebpf/guides/getting-started.md b/docs/ebpf/guides/getting-started.md index 57a95bc39..0f6a01b96 100644 --- a/docs/ebpf/guides/getting-started.md +++ b/docs/ebpf/guides/getting-started.md @@ -145,14 +145,12 @@ go: to add module requirements and sums: % go mod tidy ``` -We also need to manually add a dependency on `bpf2go` since it's not explicitly -imported by a `.go` source file: - -```{ .shell-session data-copy="go get github.com/cilium/ebpf/cmd/bpf2go" } -% go get github.com/cilium/ebpf/cmd/bpf2go -go: added github.com/cilium/ebpf v0.11.0 -go: added golang.org/x/exp v0.0.0-20230224173230-c95f2b4c22f2 -go: added golang.org/x/sys v0.6.0 +First, add `bpf2go` as a tool dependency to your Go module. This ensures the +version of `bpf2go` used by the Go toolchain always matches your version of the +library. + +```{ .shell-session data-copy="go get -tool github.com/cilium/ebpf/cmd/bpf2go" } +% go get -tool github.com/cilium/ebpf/cmd/bpf2go ``` Now we're ready to run `go generate`: diff --git a/docs/examples/getting_started/gen.go b/docs/examples/getting_started/gen.go index 9135e18dd..2468a05ab 100644 --- a/docs/examples/getting_started/gen.go +++ b/docs/examples/getting_started/gen.go @@ -3,6 +3,6 @@ // getting_started_gen { package main -//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -tags linux counter counter.c +//go:generate go tool bpf2go -tags linux counter counter.c // } diff --git a/docs/examples/variables/gen.go b/docs/examples/variables/gen.go index a21e64154..4eeadc813 100644 --- a/docs/examples/variables/gen.go +++ b/docs/examples/variables/gen.go @@ -1,3 +1,3 @@ package main -//go:generate go run github.com/cilium/ebpf/cmd/bpf2go variables variables.c +//go:generate go tool bpf2go variables variables.c diff --git a/examples/cgroup_skb/main.go b/examples/cgroup_skb/main.go index c6061b3fa..57edfc89c 100644 --- a/examples/cgroup_skb/main.go +++ b/examples/cgroup_skb/main.go @@ -19,7 +19,7 @@ import ( "github.com/cilium/ebpf/rlimit" ) -//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -tags linux bpf cgroup_skb.c -- -I../headers +//go:generate go tool bpf2go -tags linux bpf cgroup_skb.c -- -I../headers func main() { // Allow the current process to lock memory for eBPF resources. diff --git a/examples/fentry/main.go b/examples/fentry/main.go index 2fa605f8f..610a99c05 100644 --- a/examples/fentry/main.go +++ b/examples/fentry/main.go @@ -29,7 +29,7 @@ import ( "github.com/cilium/ebpf/rlimit" ) -//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -tags linux bpf fentry.c -- -I../headers +//go:generate go tool bpf2go -tags linux bpf fentry.c -- -I../headers func main() { stopper := make(chan os.Signal, 1) diff --git a/examples/kprobe/main.go b/examples/kprobe/main.go index 4b6fb3e9b..0d742704a 100644 --- a/examples/kprobe/main.go +++ b/examples/kprobe/main.go @@ -14,7 +14,7 @@ import ( "github.com/cilium/ebpf/rlimit" ) -//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -tags linux bpf kprobe.c -- -I../headers +//go:generate go tool bpf2go -tags linux bpf kprobe.c -- -I../headers const mapKey uint32 = 0 diff --git a/examples/kprobe_percpu/main.go b/examples/kprobe_percpu/main.go index 724506620..36c79ae90 100644 --- a/examples/kprobe_percpu/main.go +++ b/examples/kprobe_percpu/main.go @@ -14,7 +14,7 @@ import ( "github.com/cilium/ebpf/rlimit" ) -//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -tags linux bpf kprobe_percpu.c -- -I../headers +//go:generate go tool bpf2go -tags linux bpf kprobe_percpu.c -- -I../headers const mapKey uint32 = 0 diff --git a/examples/kprobepin/main.go b/examples/kprobepin/main.go index 46cb0ac64..790bf0635 100644 --- a/examples/kprobepin/main.go +++ b/examples/kprobepin/main.go @@ -17,7 +17,7 @@ import ( "github.com/cilium/ebpf/rlimit" ) -//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -tags linux bpf kprobe_pin.c -- -I../headers +//go:generate go tool bpf2go -tags linux bpf kprobe_pin.c -- -I../headers const ( mapKey uint32 = 0 diff --git a/examples/ringbuffer/main.go b/examples/ringbuffer/main.go index ee2f6c1ab..9decf376d 100644 --- a/examples/ringbuffer/main.go +++ b/examples/ringbuffer/main.go @@ -18,7 +18,7 @@ import ( "github.com/cilium/ebpf/rlimit" ) -//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -tags linux bpf ringbuffer.c -- -I../headers +//go:generate go tool bpf2go -tags linux bpf ringbuffer.c -- -I../headers func main() { // Name of the kernel function to trace. diff --git a/examples/tcprtt/main.go b/examples/tcprtt/main.go index 57768ec96..c84efb74e 100644 --- a/examples/tcprtt/main.go +++ b/examples/tcprtt/main.go @@ -30,7 +30,7 @@ import ( "github.com/cilium/ebpf/rlimit" ) -//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -tags linux bpf tcprtt.c -- -I../headers +//go:generate go tool bpf2go -tags linux bpf tcprtt.c -- -I../headers func main() { stopper := make(chan os.Signal, 1) diff --git a/examples/tcprtt_sockops/main.go b/examples/tcprtt_sockops/main.go index a1fc0508b..a428e208d 100644 --- a/examples/tcprtt_sockops/main.go +++ b/examples/tcprtt_sockops/main.go @@ -39,7 +39,7 @@ import ( "golang.org/x/sys/unix" ) -//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -tags linux -tags "linux" bpf tcprtt_sockops.c -- -I../headers +//go:generate go tool bpf2go -tags linux -tags "linux" bpf tcprtt_sockops.c -- -I../headers func main() { stopper := make(chan os.Signal, 1) diff --git a/examples/tcx/main.go b/examples/tcx/main.go index 12aa45928..dbbe11b64 100644 --- a/examples/tcx/main.go +++ b/examples/tcx/main.go @@ -18,7 +18,7 @@ import ( "github.com/cilium/ebpf/link" ) -//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -tags linux bpf tcx.c -- -I../headers +//go:generate go tool bpf2go -tags linux bpf tcx.c -- -I../headers func main() { if len(os.Args) < 2 { log.Fatalf("Please specify a network interface") diff --git a/examples/tracepoint_in_c/main.go b/examples/tracepoint_in_c/main.go index 8a60d46d4..fac3d468d 100644 --- a/examples/tracepoint_in_c/main.go +++ b/examples/tracepoint_in_c/main.go @@ -14,7 +14,7 @@ import ( "github.com/cilium/ebpf/rlimit" ) -//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -tags linux bpf tracepoint.c -- -I../headers +//go:generate go tool bpf2go -tags linux bpf tracepoint.c -- -I../headers const mapKey uint32 = 0 diff --git a/examples/uretprobe/main.go b/examples/uretprobe/main.go index b2e662935..675c097a4 100644 --- a/examples/uretprobe/main.go +++ b/examples/uretprobe/main.go @@ -22,7 +22,7 @@ import ( "github.com/cilium/ebpf/rlimit" ) -//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -tags linux -target amd64 bpf uretprobe.c -- -I../headers +//go:generate go tool bpf2go -tags linux -target amd64 bpf uretprobe.c -- -I../headers const ( // The path to the ELF binary containing the function to trace. diff --git a/examples/xdp/main.go b/examples/xdp/main.go index 2b71331e7..9f6c0e1b8 100644 --- a/examples/xdp/main.go +++ b/examples/xdp/main.go @@ -23,7 +23,7 @@ import ( "github.com/cilium/ebpf/link" ) -//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -tags linux bpf xdp.c -- -I../headers +//go:generate go tool bpf2go -tags linux bpf xdp.c -- -I../headers func main() { if len(os.Args) < 2 { diff --git a/go.mod b/go.mod index 6a0557bcf..02720a6a0 100644 --- a/go.mod +++ b/go.mod @@ -1,12 +1,12 @@ module github.com/cilium/ebpf -go 1.24 +go 1.24.0 require ( github.com/go-quicktest/qt v1.101.1-0.20240301121107-c6c8733fa1e6 github.com/google/go-cmp v0.6.0 github.com/jsimonetti/rtnetlink/v2 v2.0.1 - golang.org/x/sys v0.31.0 + golang.org/x/sys v0.37.0 ) require ( @@ -16,6 +16,14 @@ require ( github.com/mdlayher/netlink v1.7.2 // indirect github.com/mdlayher/socket v0.4.1 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect - golang.org/x/net v0.38.0 // indirect - golang.org/x/sync v0.1.0 // indirect + golang.org/x/mod v0.29.0 // indirect + golang.org/x/net v0.46.0 // indirect + golang.org/x/sync v0.17.0 // indirect + golang.org/x/tools v0.38.0 // indirect +) + +tool ( + github.com/cilium/ebpf/cmd/bpf2go + github.com/cilium/ebpf/internal/cmd/gentypes + golang.org/x/tools/cmd/stringer ) diff --git a/go.sum b/go.sum index 5d11e207f..6c959d9bf 100644 --- a/go.sum +++ b/go.sum @@ -19,9 +19,13 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsK github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= -golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8= -golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= -golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= -golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= -golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/mod v0.29.0 h1:HV8lRxZC4l2cr3Zq1LvtOsi/ThTgWnUk/y64QSs8GwA= +golang.org/x/mod v0.29.0/go.mod h1:NyhrlYXJ2H4eJiRy/WDBO6HMqZQ6q9nk4JzS3NuCK+w= +golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4= +golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210= +golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug= +golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= +golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ= +golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/tools v0.38.0 h1:Hx2Xv8hISq8Lm16jvBZ2VQf+RLmbd7wVUsALibYI/IQ= +golang.org/x/tools v0.38.0/go.mod h1:yEsQ/d/YK8cjh0L6rZlY8tgtlKiBNTL14pGDJPJpYQs= diff --git a/internal/efw/result.go b/internal/efw/result.go index 3275941d3..4c68da931 100644 --- a/internal/efw/result.go +++ b/internal/efw/result.go @@ -5,7 +5,7 @@ package efw // See https://github.com/microsoft/ebpf-for-windows/blob/main/include/ebpf_result.h type Result int32 -//go:generate go run golang.org/x/tools/cmd/stringer@latest -tags windows -output result_string_windows.go -type=Result +//go:generate go tool stringer -tags windows -output result_string_windows.go -type=Result const ( EBPF_SUCCESS Result = iota diff --git a/internal/sys/doc.go b/internal/sys/doc.go index dfe174448..75d7e4013 100644 --- a/internal/sys/doc.go +++ b/internal/sys/doc.go @@ -3,4 +3,4 @@ package sys // Regenerate types.go by invoking go generate in the current directory. -//go:generate go run github.com/cilium/ebpf/internal/cmd/gentypes ../../btf/testdata/vmlinux.btf.gz +//go:generate go tool gentypes ../../btf/testdata/vmlinux.btf.gz diff --git a/internal/tracefs/kprobe.go b/internal/tracefs/kprobe.go index 68a1804d5..d0b5be66c 100644 --- a/internal/tracefs/kprobe.go +++ b/internal/tracefs/kprobe.go @@ -23,7 +23,7 @@ var ( ErrInvalidMaxActive = errors.New("can only set maxactive on kretprobes") ) -//go:generate go run golang.org/x/tools/cmd/stringer@latest -type=ProbeType -linecomment +//go:generate go tool stringer -type=ProbeType -linecomment type ProbeType uint8 diff --git a/internal/tracefs/probetype_string.go b/internal/tracefs/probetype_string.go index 87cb0a059..ed8471a89 100644 --- a/internal/tracefs/probetype_string.go +++ b/internal/tracefs/probetype_string.go @@ -17,8 +17,9 @@ const _ProbeType_name = "kprobeuprobe" var _ProbeType_index = [...]uint8{0, 6, 12} func (i ProbeType) String() string { - if i >= ProbeType(len(_ProbeType_index)-1) { + idx := int(i) - 0 + if i < 0 || idx >= len(_ProbeType_index)-1 { return "ProbeType(" + strconv.FormatInt(int64(i), 10) + ")" } - return _ProbeType_name[_ProbeType_index[i]:_ProbeType_index[i+1]] + return _ProbeType_name[_ProbeType_index[idx]:_ProbeType_index[idx+1]] } diff --git a/internal/unix/errno_windows.go b/internal/unix/errno_windows.go index 7500cd6d4..2dd30f2d6 100644 --- a/internal/unix/errno_windows.go +++ b/internal/unix/errno_windows.go @@ -9,7 +9,7 @@ import ( "syscall" ) -//go:generate go run golang.org/x/tools/cmd/stringer@latest -type=Errno -tags=windows -output=errno_string_windows.go +//go:generate go tool stringer -type=Errno -tags=windows -output=errno_string_windows.go // Windows specific constants for Unix errnos. // diff --git a/staticcheck.conf b/staticcheck.conf new file mode 100644 index 000000000..cfc907da3 --- /dev/null +++ b/staticcheck.conf @@ -0,0 +1,3 @@ +# Default configuration from https://staticcheck.dev/docs/configuration with +# SA4003 disabled. Remove when https://github.com/cilium/ebpf/issues/1876 is fixed. +checks = ["all", "-SA9003", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022", "-ST1023", "-SA4003"] diff --git a/types.go b/types.go index 56e318208..afe5658c2 100644 --- a/types.go +++ b/types.go @@ -5,7 +5,7 @@ import ( "github.com/cilium/ebpf/internal/sys" ) -//go:generate go run golang.org/x/tools/cmd/stringer@latest -output types_string.go -type=MapType,ProgramType,PinType +//go:generate go tool stringer -output types_string.go -type=MapType,ProgramType,PinType // MapType indicates the type map structure // that will be initialized in the kernel. @@ -252,7 +252,7 @@ func ProgramTypeForPlatform(plat string, value uint32) (ProgramType, error) { // Will cause invalid argument (EINVAL) at program load time if set incorrectly. type AttachType uint32 -//go:generate go run golang.org/x/tools/cmd/stringer@latest -type AttachType -trimprefix Attach +//go:generate go tool stringer -type AttachType -trimprefix Attach // AttachNone is an alias for AttachCGroupInetIngress for readability reasons. const AttachNone AttachType = 0 diff --git a/types_string.go b/types_string.go index efcd6a7dd..94bc2e26c 100644 --- a/types_string.go +++ b/types_string.go @@ -162,8 +162,9 @@ const _PinType_name = "PinNonePinByName" var _PinType_index = [...]uint8{0, 7, 16} func (i PinType) String() string { - if i >= PinType(len(_PinType_index)-1) { + idx := int(i) - 0 + if i < 0 || idx >= len(_PinType_index)-1 { return "PinType(" + strconv.FormatInt(int64(i), 10) + ")" } - return _PinType_name[_PinType_index[i]:_PinType_index[i+1]] + return _PinType_name[_PinType_index[idx]:_PinType_index[idx+1]] }