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

aya,aya-obj,integration-test: add better support in ProgramInfo & MapInfo for old kernels #1007

Merged
merged 4 commits into from
Sep 3, 2024

Commits on Sep 1, 2024

  1. aya,integration-test: improve integration tests for info API

    Improves the existing integraiton tests for `loaded_programs()` and
    `loaded_maps()` in consideration for older kernels:
      - Opt for `SocketFilter` program in tests since XDP requires v4.8 and
        fragments requires v5.18.
      - For assertion tests, first perform the assertion, if the assertion
        fails, then it checks the host kernel version to see if it is above
        the minimum version requirement. If not, then continue with test,
        otherwise fail.
        For assertions that are skipped, they're logged in stderr which can
        be observed with `-- --nocapture`.
    
    This also fixes the `bpf_prog_get_info_by_fd()` call for kernels below
    v4.15. If calling syscall  on kernels below v4.15, it can produce an
    `E2BIG` error  because `check_uarg_tail_zero()` expects the entire
    struct to all-zero bytes (which is caused from the map info).
    
    Instead, we first attempt the syscall with the map info filled, if it
    returns `E2BIG`, then perform syscall again with empty closure.
    
    Also adds doc for which version a kernel feature was introduced for
    better  awareness.
    
    The tests have been verified kernel versions:
      - 4.13.0
      - 4.15.0
      - 6.1.0
    tyrone-wu committed Sep 1, 2024
    Configuration menu
    Copy the full SHA
    cb8e478 View commit details
    Browse the repository at this point in the history

Commits on Sep 2, 2024

  1. aya-obj: add conversion u32 to enum type for prog, link, & attach type

    Add conversion from u32 to program type, link type, and attach type.
    Additionally, remove duplicate match statement for u32 conversion to
    `BPF_MAP_TYPE_BLOOM_FILTER` & `BPF_MAP_TYPE_CGRP_STORAGE`.
    
    New error `InvalidTypeBinding<T>` is created to represent when a
    parsed/received value binding to a type is invalid.
    This is used in the new conversions added here, and also replaces
    `InvalidMapTypeError` in `TryFrom` for `bpf_map_type`.
    tyrone-wu committed Sep 2, 2024
    Configuration menu
    Copy the full SHA
    1634fa7 View commit details
    Browse the repository at this point in the history
  2. aya,obj,int-test: revamp ProgramInfo be more friendly with older kernels

    Purpose of this commit is to add detections for whether a field is
    available in `ProgramInfo`.
    - For `program_type()`, we return the new enum `ProgramType` instead of
      the integer representation.
    - For fields that we know cannot be zero, we return `Option<NonZero*>`
      type.
    - For `name_as_str()`, it now also uses the feature probe `bpf_name()`
      to detect if field is available or not.
    - Two additional feature probes are added for the fields:
      - `prog_info_map_ids()` probe -> `map_ids()` field
      - `prog_info_gpl_compatible()` probe -> `gpl_compatible()` field
    
    With the `prog_info_map_ids()` probe, the previous implementation that
    I had for `bpf_prog_get_info_by_fd()` is shortened to use the probe
    instead of having to make 2 potential syscalls.
    
    The `test_loaded_at()` test is also moved into info tests since it is
    better related to the info tests.
    
    `aya::programs::Programs::prog_type(&self)` now returns `ProgramType`
    instead of the generated FFI from aya-obj.
    
    Also previously, `loaded_programs()` could be accessed either through
    `aya` or `aya::programs`. To avoid confusion and duplicate export of
    the item, the function should now only be exposed through
    `aya::programs`.
    tyrone-wu committed Sep 2, 2024
    Configuration menu
    Copy the full SHA
    88f5ac3 View commit details
    Browse the repository at this point in the history
  3. aya,int-test: revamp MapInfo be more friendly with older kernels

    Adds detection for whether a field is available in `MapInfo`:
    - For `map_type()`, we treturn new enum `MapType` instead of the integer
      representation.
    - For fields that can't be zero, we return `Option<NonZero*>` type.
    - For `name_as_str()`, it now uses the feature probe `bpf_name()` to
      detect if field is available.
      Although the feature probe checks for program name, it can also be
      used for map name since they were both introduced in the same commit.
    tyrone-wu committed Sep 2, 2024
    Configuration menu
    Copy the full SHA
    fbb0930 View commit details
    Browse the repository at this point in the history