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

Split logic #367

Merged
merged 11 commits into from
Oct 26, 2023
Merged

Split logic #367

merged 11 commits into from
Oct 26, 2023

Conversation

geyslan
Copy link
Member

@geyslan geyslan commented Aug 22, 2023

Close: #355
Close: #365
Close: #159
Close: #357

commit f1738f9 (HEAD -> split-logic, origin/split-logic)

chore: consider errno in NULL return

commit 62f0ccc

chore(prog): add TODO

commit 0228f12

chore: give breath to the code putting spaces

This adds spaces to the code to make it more readable.

This also puts RingBuffer.Stop() and PerfBuffer.Stop() happy path
out of the branching logic.

commit 77c521f

chore(prog): remove inner name field

The API must rely on the program name returned by the libbpf API.

commit 87088b6

chore: standardize defer use

Applied the use of 'defer' for better resource management.

commit 3aeb45b

fix(link)!: Unpin link API

The underlying bpf_link__unpin() does not receive a pointer to the
pin path, only for the link itself.

commit 1b882cf

chore: add information to SetStrictMode()

SetStrictMode is no-op as of libbpf v1.0.

commit 913d1ea

chore: use cgo_* helpers for struct lifecycle

Introduced struct helpers to manage the C struct lifecycle on the C side,
which avoids problems with structs which may contain bitfields. See #244.

  - cgo_bpf_map_info_new()
  - cgo_bpf_map_info_size()
  - cgo_bpf_map_info_free()

  - cgo_bpf_tc_opts_new()
  - cgo_bpf_tc_opts_free()

  - cgo_bpf_tc_hook_new()
  - cgo_bpf_tc_hook_free()

Based on the same #244 concerns, introduced bpf_map_info getters:

  - cgo_bpf_map_info_type()
  - cgo_bpf_map_info_id()
  - cgo_bpf_map_info_key_size()
  - cgo_bpf_map_info_value_size()
  - cgo_bpf_map_info_max_entries()
  - cgo_bpf_map_info_map_flags()
  - cgo_bpf_map_info_name()
  - cgo_bpf_map_info_ifindex()
  - cgo_bpf_map_info_btf_vmlinux_value_type_id()
  - cgo_bpf_map_info_netns_dev()
  - cgo_bpf_map_info_netns_ino()
  - cgo_bpf_map_info_btf_id()
  - cgo_bpf_map_info_btf_key_type_id()
  - cgo_bpf_map_info_btf_value_type_id()
  - cgo_bpf_map_info_map_extra()

  - cgo_bpf_tc_opts_prog_fd()
  - cgo_bpf_tc_opts_flags()
  - cgo_bpf_tc_opts_prog_id()
  - cgo_bpf_tc_opts_handle()
  - cgo_bpf_tc_opts_priority()

Changed these functions to use cgo_* struct handlers:

  - NewModuleFromFileArgs()
  - GetMapInfoByFD()
  - TcHook.Destroy()
  - TcHook.Attach()
  - TcHook.Detach()
  - TcHook.Query()

commit a4c5f50

chore(go): rename C variables

- Changed C function returns to 'retC' in functions that return error
  values to avoid confusion with possible use of errno.
- Changed returns to 'valueC' in functions that return 'value' or
  pointers to 'value'.

This also changed comparisons to "< 0" instead of "!= 0".

commit 0c6a05f

chore(link): make BPF link legacy a private type

It has no methods, and is only used embedded in the BPFLink type.

commit c192943

chore: split logic into multiple files

This only moves code around, no functional changes.

This only moves code around, no functional changes.
It has no methods, and is only used embedded in the BPFLink type.
- Changed C function returns to 'retC' in functions that return error
  values to avoid confusion with possible use of errno.
- Changed returns to 'valueC' in functions that return 'value' or
  pointers to 'value'.

This also changed comparisons to "< 0" instead of "!= 0".
Introduced struct helpers to manage the C struct lifecycle on the C side,
which avoids problems with structs which may contain bitfields. See aquasecurity#244.

  - cgo_bpf_map_info_new()
  - cgo_bpf_map_info_size()
  - cgo_bpf_map_info_free()

  - cgo_bpf_tc_opts_new()
  - cgo_bpf_tc_opts_free()

  - cgo_bpf_tc_hook_new()
  - cgo_bpf_tc_hook_free()

Based on the same aquasecurity#244 concerns, introduced bpf_map_info getters:

  - cgo_bpf_map_info_type()
  - cgo_bpf_map_info_id()
  - cgo_bpf_map_info_key_size()
  - cgo_bpf_map_info_value_size()
  - cgo_bpf_map_info_max_entries()
  - cgo_bpf_map_info_map_flags()
  - cgo_bpf_map_info_name()
  - cgo_bpf_map_info_ifindex()
  - cgo_bpf_map_info_btf_vmlinux_value_type_id()
  - cgo_bpf_map_info_netns_dev()
  - cgo_bpf_map_info_netns_ino()
  - cgo_bpf_map_info_btf_id()
  - cgo_bpf_map_info_btf_key_type_id()
  - cgo_bpf_map_info_btf_value_type_id()
  - cgo_bpf_map_info_map_extra()

  - cgo_bpf_tc_opts_prog_fd()
  - cgo_bpf_tc_opts_flags()
  - cgo_bpf_tc_opts_prog_id()
  - cgo_bpf_tc_opts_handle()
  - cgo_bpf_tc_opts_priority()

Changed these functions to use cgo_* struct handlers:

  - NewModuleFromFileArgs()
  - GetMapInfoByFD()
  - TcHook.Destroy()
  - TcHook.Attach()
  - TcHook.Detach()
  - TcHook.Query()
SetStrictMode is no-op as of libbpf v1.0.
The underlying bpf_link__unpin() does not receive a pointer to the
pin path, only for the link itself.
Applied the use of 'defer' for better resource management.
The API must rely on the program name returned by the libbpf API.
This adds spaces to the code to make it more readable.

This also puts RingBuffer.Stop() and PerfBuffer.Stop() happy path
out of the branching logic.
@geyslan geyslan merged commit 083f15c into aquasecurity:main Oct 26, 2023
14 checks passed
@geyslan geyslan deleted the split-logic branch November 28, 2023 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant