Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use merge-friendly way of adding vars to genpost #29124

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion pkg/ebpf/cgo/genpost.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"os"
"regexp"
"runtime"
"strings"
)

func main() {
Expand All @@ -23,9 +24,24 @@ func main() {

b = removeAbsolutePath(b, runtime.GOOS)

int8variableNames := []string{
"Buf",
"Cgroup",
"Cgroup_name",
"LocalAddr",
"LocalAddress",
"Probe_id",
"RemoteAddr",
"RemoteAddress",
"Request_fragment",
"Topic_name",
"Trigger_comm",
"Victim_comm",
}

// Convert []int8 to []byte in multiple generated fields from the kernel, to simplify
// conversion to string; see golang.org/issue/20753
convertInt8ArrayToByteArrayRegex := regexp.MustCompile(`(Request_fragment|Topic_name|Buf|Cgroup|RemoteAddr|LocalAddr|Cgroup_name|Victim_comm|Trigger_comm|LocalAddress|RemoteAddress|Probe_id)(\s+)\[(\d+)\]u?int8`)
convertInt8ArrayToByteArrayRegex := regexp.MustCompile(`(` + strings.Join(int8variableNames, "|") + `)(\s+)\[(\d+)\]u?int8`)
b = convertInt8ArrayToByteArrayRegex.ReplaceAll(b, []byte("$1$2[$3]byte"))

b, err = format.Source(b)
Expand Down
Loading