Skip to content

Commit

Permalink
Merge main to Release 1.0 (#58)
Browse files Browse the repository at this point in the history
* Mocks for public APIs

* PR feedback

* Make the sdk client global for mocks

* Update sdk client for NA mocks (#26)

* Update sdk client

* fix var

* API interface change and UTs for TC functions (#25)

* UTs for tc functions

* Fix vet

* Add mocks

* Feedback

* PR feedbacl

* UTs for recovery and progs (#27)

* UTs for recovery and progs

* PR feedbacks

* UTs for cache and kprobes (#28)

* Xdp and Events UT (#29)

* XDP and events update

* cleanup

* Third party attribution doc

* readme-v1 (#30)

* Update README.md (#33)

* Update README.md

* chore: spelling in README (#36)

* Add github action for functional tests

* Merge issue with func tests (#38)

* test-data: Fix to use __builtin_memset() instead of memset() (#40)

In BPF programs, when using functions like `memset()` and `memcpy()`,
you should use LLVM built-in functions like `__builtin_memset()`.

Signed-off-by: shun159 <[email protected]>

* Bump golang.org/x/sys from 0.6.0 to 0.12.0 (#41)

Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.6.0 to 0.12.0.
- [Commits](golang/sys@v0.6.0...v0.12.0)

---
updated-dependencies:
- dependency-name: golang.org/x/sys
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Fixup poller for events race condition (#43)

* Fixup poller for events race condition

* Testing package go tidy

* makefile: fix to remove unused option from build-bpf target (#42)

* makefile: fix to remove unused option from build-bpf target

Signed-off-by: shun159 <[email protected]>

* makefile: refactor using pattern rule

Signed-off-by: shun159 <[email protected]>

---------

Signed-off-by: shun159 <[email protected]>

* test-data: fix to solve compile warning for test-data (#45)

* test-data: fix to solve compile warning for test-data

use `void`instead of the `struct sched_process_fork_t` to solve
compile warnings for resolvedata and tc.ingress

```shellsesson
$ doas make test-data/recoverydata.bpf.elf
clang -I../../.. -g -O2 -Wall -fpie -target bpf -DCORE -D__BPF_TRACING__ -D__TARGET_ARCH_x86  -c test-data/recoverydata.bpf.c -o test-data/recoverydata.bpf.elf
test-data/recoverydata.bpf.c:101:31: warning: declaration of 'struct sched_process_fork_t' will not be visible outside of this function [-Wvisibility]
int sched_process_fork(struct sched_process_fork_t *ctx) {
                              ^
1 warning generated.
```

Signed-off-by: shun159 <[email protected]>

* makefile: Refactor the vmlinux and unit-test targets

1. Check the existence of the /sys/kernel/btf/vmlinux file before generating the header file using bpftool.

2. Improve the idempotency of the vmlinux target.

3. Add the `LOGFILE_PATH` variable to allow specifying a different path for the `AWS_EBPF_SDK_LOG_FILE`.

Signed-off-by: shun159 <[email protected]>

---------

Signed-off-by: shun159 <[email protected]>

* kprobe: Add defer statements for resource cleanup in KprobeAttach()/KretprobeAttach (#46)

Ensure that file handle is properly closed using `defer` statements.

Signed-off-by: shun159 <[email protected]>

* Add v6 test and inc log level (#53)

* Fix verifier log buffer size (#54)

* Use defer close

---------

Signed-off-by: shun159 <[email protected]>
Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Apurup Chevuru <[email protected]>
Co-authored-by: Alex Jones <[email protected]>
Co-authored-by: Davanum Srinivas <[email protected]>
Co-authored-by: Eishun Kondoh <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
6 people authored Nov 8, 2023
1 parent 2df701c commit 3a4f0f5
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions pkg/maps/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ func (m *BpfMap) CreateUpdateMapEntry(key, value uintptr, updateFlags uint64) er
log.Errorf("unable to GetMapFDfromID and ret %d and err %s", int(mapFD), err)
return fmt.Errorf("unable to get FD: %s", err)
}
defer unix.Close(mapFD)

attr := utils.BpfMapAttr{
MapFD: uint32(mapFD),
Expand All @@ -309,7 +310,6 @@ func (m *BpfMap) CreateUpdateMapEntry(key, value uintptr, updateFlags uint64) er
}

log.Infof("Create/Update map entry done with fd : %d and err %s", int(ret), errno)
unix.Close(mapFD)
return nil
}

Expand All @@ -320,6 +320,8 @@ func (m *BpfMap) DeleteMapEntry(key uintptr) error {
log.Errorf("unable to GetMapFDfromID and ID %d and err %s", int(m.MapID), err)
return fmt.Errorf("unable to get FD: %s", err)
}
defer unix.Close(mapFD)

attr := utils.BpfMapAttr{
MapFD: uint32(mapFD),
Key: uint64(key),
Expand All @@ -336,7 +338,6 @@ func (m *BpfMap) DeleteMapEntry(key uintptr) error {
}

log.Infof("Delete map entry done with fd : %d and err %s", int(ret), errno)
unix.Close(mapFD)
return nil
}

Expand All @@ -352,6 +353,8 @@ func (m *BpfMap) GetNextMapEntry(key, nextKey uintptr) error {
log.Errorf("unable to GetMapFDfromID and ret %d and err %s", int(mapFD), err)
return fmt.Errorf("unable to get FD: %s", err)
}
defer unix.Close(mapFD)

attr := utils.BpfMapAttr{
MapFD: uint32(mapFD),
Key: uint64(key),
Expand All @@ -365,17 +368,14 @@ func (m *BpfMap) GetNextMapEntry(key, nextKey uintptr) error {
)
if errors.Is(errno, unix.ENOENT) {
log.Errorf("last entry read done")
unix.Close(mapFD)
return errno
}
if errno != 0 {
log.Errorf("unable to get next map entry and ret %d and err %s", int(ret), errno)
unix.Close(mapFD)
return fmt.Errorf("unable to get next map entry: %s", errno)
}

log.Infof("Got next map entry with fd : %d and err %s", int(ret), errno)
unix.Close(mapFD)
return nil
}

Expand Down Expand Up @@ -418,6 +418,8 @@ func (m *BpfMap) GetMapEntry(key, value uintptr) error {
log.Errorf("unable to GetMapFDfromID and ret %d and err %s", int(mapFD), err)
return fmt.Errorf("unable to get FD: %s", err)
}
defer unix.Close(mapFD)

attr := utils.BpfMapAttr{
MapFD: uint32(mapFD),
Key: uint64(key),
Expand All @@ -431,12 +433,10 @@ func (m *BpfMap) GetMapEntry(key, value uintptr) error {
)
if errno != 0 {
log.Errorf("unable to get map entry and ret %d and err %s", int(ret), errno)
unix.Close(mapFD)
return fmt.Errorf("unable to get next map entry: %s", errno)
}

log.Infof("Got map entry with fd : %d and err %s", int(ret), errno)
unix.Close(mapFD)
return nil
}

Expand Down Expand Up @@ -578,6 +578,7 @@ func BpfGetAllMapInfo() ([]BpfMapInfo, error) {
bpfMapInfo, err := GetBPFmapInfo(mapfd)
if err != nil {
log.Errorf("failed to get map Info for FD", mapfd)
unix.Close(mapfd)
return nil, err
}
unix.Close(mapfd)
Expand Down Expand Up @@ -643,6 +644,8 @@ func GetNextMapEntryByID(key, nextKey uintptr, mapID int) error {
log.Errorf("unable to GetMapFDfromID and ret %d and err %s", int(mapFD), err)
return fmt.Errorf("unable to get FD: %s", err)
}

defer unix.Close(mapFD)
attr := utils.BpfMapAttr{
MapFD: uint32(mapFD),
Key: uint64(key),
Expand All @@ -655,17 +658,14 @@ func GetNextMapEntryByID(key, nextKey uintptr, mapID int) error {
unsafe.Sizeof(attr),
)
if errors.Is(errno, unix.ENOENT) {
unix.Close(mapFD)
return errno
}
if errno != 0 {
log.Errorf("unable to get next map entry and ret %d and err %s", int(ret), errno)
unix.Close(mapFD)
return fmt.Errorf("unable to get next map entry: %s", errno)
}

log.Infof("Got next map entry with fd : %d and err %s", int(ret), errno)
unix.Close(mapFD)
return nil
}

Expand All @@ -676,6 +676,7 @@ func GetMapEntryByID(key, value uintptr, mapID int) error {
log.Errorf("unable to GetMapFDfromID and ret %d and err %s", int(mapFD), err)
return fmt.Errorf("unable to get FD: %s", err)
}
defer unix.Close(mapFD)

attr := utils.BpfMapAttr{
MapFD: uint32(mapFD),
Expand All @@ -691,11 +692,9 @@ func GetMapEntryByID(key, value uintptr, mapID int) error {

if errno != 0 {
log.Errorf("unable to get map entry and ret %d and err %s", int(ret), errno)
unix.Close(mapFD)
return fmt.Errorf("unable to get next map entry: %s", errno)
}

log.Infof("Got map entry with ret : %d and err %s", int(ret), errno)
unix.Close(mapFD)
return nil
}

0 comments on commit 3a4f0f5

Please sign in to comment.