Skip to content

Commit

Permalink
Merge branch 'release/1.4' into bug/1170-pcre2-stack-clone
Browse files Browse the repository at this point in the history
  • Loading branch information
jrcheli committed May 5, 2023
2 parents 6c5f967 + 43d2c31 commit 4110ba1
Show file tree
Hide file tree
Showing 90 changed files with 2,696 additions and 871 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
# is one. We'll use the outputs in other places.
- name: Get Version
id: version
uses: battila7/get-version-action@v2
uses: Simply007/get-version-action@v2.3.0

# This is our logic to decide how to tag the results and whether things
# get published or not.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update_latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
steps:
- name: Get Version
id: version
uses: battila7/get-version-action@v2
uses: Simply007/get-version-action@v2.3.0

- name: Get Tag
id: tag
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update_latest_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
steps:
- name: Get Version
id: version
uses: battila7/get-version-action@v2
uses: Simply007/get-version-action@v2.3.0

- name: Get Tag
id: tag
Expand Down
2 changes: 0 additions & 2 deletions cli/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ coverage.out
demo/demo-scripts/willsee.txt
demo/demo-scripts/wontsee.log
VERSION
bpf/vmlinux.h
bpf/sigdel/gen_sigdel_bpfel.*
10 changes: 0 additions & 10 deletions cli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ SCOPE := $(BINDIR)/scope
SCOPEDYN := $(BINDIR)/scopedyn
LIBSCOPE := $(LIBDIR)/libscope.so
LIBLOADER := $(LIBDIR)/libloader.a
SIGDEL := bpf/sigdel/gen_sigdel_bpfel.go
SYSHEADER := bpf/vmlinux.h
CONF_YML := $(CONFDIR)/scope.yml
LOADER_C_FILES:=$(wildcard $(SRCDIR)/loader/*.c)
LIBRARY_C_FILES:=$(wildcard $(SRCDIR)/*.c)
Expand Down Expand Up @@ -73,8 +71,6 @@ clean:
$(RM) -rf -- .gomod/*/
$(RM) -rf -- .gobin/x86_64/go*
$(RM) -rf -- .gobin/aarch64/go*
$(RM) -rf -- bpf/sigdel/gen_sigdel_bpfel.go
$(RM) -rf -- bpf/sigdel/*.o
$(RM) -rf -- bpf/vmlinux.h

## deps: install dependencies
Expand Down Expand Up @@ -120,12 +116,6 @@ $(SCOPE): $(GOVVV) $(filter-out %_test.go,$(shell find . -type f -name '*.go'))
-o $(SCOPE)
$(RM) -r $(SCOPEDYN)

$(SIGDEL): bpf/sigdel/sigdel.bpf.c $(SYSHEADER)
go generate bpf/sigdel/*.go

$(SYSHEADER):
bpftool btf dump file /sys/kernel/btf/vmlinux format c > bpf/vmlinux.h

## test: run unit tests
test:
CGO_CFLAGS="-DLIBSCOPE_SO_SIZE=\"0\" -DSCOPEDYN_SIZE=\"0\"" \
Expand Down
64 changes: 64 additions & 0 deletions cli/bpf/bpfsys.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package bpf

import (
"fmt"
"runtime"
"unsafe"

"golang.org/x/sys/unix"
)

// Pointer wraps an unsafe.Pointer to be 64bit to
// conform to the syscall specification.
type Pointer struct {
ptr unsafe.Pointer
}

// NewPointer creates a 64-bit pointer from an unsafe Pointer.
func NewPointer(ptr unsafe.Pointer) Pointer {
return Pointer{ptr: ptr}
}

// bpfCmd BPF syscall commands
type bpfCmd int

// Open a file descriptor for the eBPF program corresponding to specified program id
const BPF_PROG_GET_FD_BY_ID bpfCmd = 13

// Obtain information about the eBPF object corresponding to
const BPF_OBJ_GET_INFO_BY_FD bpfCmd = 15

// unixBbpf is wrapper to BPF syscall
func unixBbpf(cmd bpfCmd, attr unsafe.Pointer, size uintptr) (uintptr, error) {
r1, _, errno := unix.Syscall(unix.SYS_BPF, uintptr(cmd), uintptr(attr), size)
runtime.KeepAlive(attr)
if errno != 0 {
return r1, fmt.Errorf("unixBbpf failed: %w", errno)
}

return r1, nil
}

// objGetInfoByFdAttr is anonymous structure used by BPF_OBJ_GET_INFO_BY_FD
type objGetInfoByFdAttr struct {
bpfFd uint32
infoLen uint32
info Pointer
}

// objGetInfoByFdAttr get information about the eBPF object
func objGetInfobyFd(attr *objGetInfoByFdAttr) error {
_, err := unixBbpf(BPF_OBJ_GET_INFO_BY_FD, unsafe.Pointer(attr), unsafe.Sizeof(*attr))
return err
}

// progGetFdByIdAttr is structure used by BPF_PROG_GET_FD_BY_ID
type progGetFdByIdAttr struct {
progId uint32
}

// objGetProgFdbyId a file descriptor for the eBPF proram from a program id
func objGetProgFdbyId(attr *progGetFdByIdAttr) (int, error) {
fd, err := unixBbpf(BPF_PROG_GET_FD_BY_ID, unsafe.Pointer(attr), unsafe.Sizeof(*attr))
return int(fd), err
}
22 changes: 22 additions & 0 deletions cli/bpf/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package bpf

import (
"runtime"
"unsafe"
)

type Info interface {
info() (unsafe.Pointer, uint32)
}

// objInfo retrieve information about specific eBPF object
func objInfo(fd int, info Info) error {
ptr, len := info.info()
err := objGetInfobyFd(&objGetInfoByFdAttr{
bpfFd: uint32(fd),
infoLen: len,
info: NewPointer(ptr),
})
runtime.KeepAlive(fd)
return err
}
57 changes: 57 additions & 0 deletions cli/bpf/link.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package bpf

import (
"unsafe"
)

type linkType uint32

const (
BPF_LINK_TYPE_UNSPEC linkType = 0
BPF_LINK_TYPE_RAW_TRACEPOINT linkType = 1
BPF_LINK_TYPE_TRACING linkType = 2
BPF_LINK_TYPE_CGROUP linkType = 3
BPF_LINK_TYPE_ITER linkType = 4
BPF_LINK_TYPE_NETNS linkType = 5
BPF_LINK_TYPE_XDP linkType = 6
BPF_LINK_TYPE_PERF_EVENT linkType = 7
BPF_LINK_TYPE_KPROBE_MULTI linkType = 8
BPF_LINK_TYPE_STRUCT_OPS linkType = 9
MAX_BPF_LINK_TYPE linkType = 10
)

// linkId uniquely identifies a bpf_link.
type linkId uint32

type ebpflinkInfo struct {
Type linkType
Id linkId
ProgId uint32
_ [4]byte
Extra [16]uint8
}

var _ Info = (*ebpflinkInfo)(nil)

func (i *ebpflinkInfo) info() (unsafe.Pointer, uint32) {
return unsafe.Pointer(i), uint32(unsafe.Sizeof(*i))
}

type LinkInformation struct {
Type linkType
Id int
ProgId int
}

func LinkGetInfo(fd int) (LinkInformation, error) {
var info ebpflinkInfo
var information LinkInformation
if err := objInfo(fd, &info); err != nil {
return information, err
}
information.Type = info.Type
information.Id = int(info.Id)
information.ProgId = int(info.ProgId)

return information, nil
}
Loading

0 comments on commit 4110ba1

Please sign in to comment.