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 BPFMap API into managed and unmanaged #356

Merged
merged 7 commits into from
Aug 17, 2023

Commits on Aug 8, 2023

  1. Configuration menu
    Copy the full SHA
    d45e8f6 View commit details
    Browse the repository at this point in the history

Commits on Aug 9, 2023

  1. Configuration menu
    Copy the full SHA
    c9b7e75 View commit details
    Browse the repository at this point in the history
  2. chore(c): move C definitions to 'libbpfgo.c'

    Leaving 'libbpfgo.h' only with declarations to avoid multiple
    declaration errors when importing 'libbpfgo.h' from different Go files.
    geyslan committed Aug 9, 2023
    Configuration menu
    Copy the full SHA
    f58df61 View commit details
    Browse the repository at this point in the history

Commits on Aug 17, 2023

  1. chore(c): prefix helpers with 'cgo_'

    Prefix all C helpers used in Go with 'cgo_', renaming two cases
    where the functions does not reflect the libbpf API:
    
    set_print_fn -> cgo_libbpf_set_print_fn
    get_internal_map_init_value -> cgo_bpf_map__initial_value
    geyslan committed Aug 17, 2023
    Configuration menu
    Copy the full SHA
    8b1190a View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    7b73fc0 View commit details
    Browse the repository at this point in the history
  3. chore(map): logic refactoring and standardization

    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.
    
      These are replacements for 'BPFMapBatchOpts' and 'bpfMapBatchOptsToC()'.
      - cgo_bpf_map_batch_opts_new
      - cgo_bpf_map_batch_opts_free
    
      These are replacements for 'bpfMapCreateOptsToC()'
      - cgo_bpf_map_create_opts_new
      - cgo_bpf_map_create_opts_free
    
    Restructured libbpf BPF map logic into separate files:
    - 'map-common.go' contains generic BPF map types, constants, and helpers
      like 'GetMapInfoByFD()'.
    - 'map-low.go' includes 'BPFMapLow' and respective logic and helpers
      like 'CreateMap()'.
    - 'map-iterator.go' contains related types and logic.
    
    In the 'BPFMap' struct:
    - Removed fields like 'fd' and 'name' since they must be retrieved
      directly from 'libbpf'.
    - Added 'bpfMapLow' instance for access to low-level methods.
    - Deprecated 'BPFMap.GetMaxEntries' in favor of using 'MaxEntries'.
    - Exposed 'InitialValue' and 'SetInitialValue' as public wrappers.
    - Introduced MapFlags(), IfIndex() and MapExtra() methods.
    
    Introduced 'misc.go' as a place for miscellaneous generic helpers.
    
    Bug Fixes:
    - Fixed cases where 'BPFMap.ValueSize()', possibly 0, was being passed
      directly to 'make()' - detected on the map of maps effort aquasecurity#343.
    
    Further Refactoring and Standardization on the map related logic and on
    lines touched by other changes:
    - Removed check for 'BPFMap.Name()' against nil, as 'C.GoString(C.NULL)'
      returns "".
    - Changed error 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 values or
      pointers to values.
    - Suffixed variable names that are C types with 'C'.
    - Applied the use of 'defer' for better resource management.
    geyslan committed Aug 17, 2023
    Configuration menu
    Copy the full SHA
    fe71839 View commit details
    Browse the repository at this point in the history
  4. feat(map): introduce ReuseFD() to reuse a map fd

    The `ReuseFD` function links the current BPFMap instance to a provided
    map file descriptor. This enables the reuse of a map that was initiated
    by another process.
    
    Initial effort: aquasecurity#346
    
    Co-authored-by: Francisco Javier Honduvilla Coto <[email protected]>
    geyslan and javierhonduco committed Aug 17, 2023
    Configuration menu
    Copy the full SHA
    9cb8ba9 View commit details
    Browse the repository at this point in the history