-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/1.4' into bug/1170-pcre2-stack-clone
- Loading branch information
Showing
90 changed files
with
2,696 additions
and
871 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.