Skip to content

Commit

Permalink
use merge-friendly way of adding vars to genpost
Browse files Browse the repository at this point in the history
  • Loading branch information
brycekahle committed Sep 6, 2024
1 parent d003e99 commit bc6448d
Showing 1 changed file with 17 additions and 1 deletion.
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

0 comments on commit bc6448d

Please sign in to comment.