Skip to content

Compile-time safety for referencing maps from user-space #1342

@thomaseizinger

Description

@thomaseizinger

It would be nice if there were a way of referencing a map by name in a way that is compile-time safe from user-space. For example, if I declare a map like this:

#[map]
static INT_ADDR_V4: PerCpuArray<[u8; 4]> = PerCpuArray::with_max_entries(1, 0);

I currently have to refer to this map from user-space as "INT_ADDR_V4". Nothing stops me from making a typo there. Arrays in particular are problematic here because they are 0-initialized, so the eBPF code can always access the data but it will just all be zeros.

Maybe the map macro could also export a const with the map name as a string? That would require the map to be defined a shared crate referenced from both user-space & the eBPF kernel. Not sure if that is possible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions