Skip to content

aya parse btf type fail #1284

@Sherlock-Holo

Description

@Sherlock-Holo

consider aya still doesn't have SkStore map, so I have to create my SkStore type

#[repr(C)]
pub struct SkStore<V> {
    r#type: *const [c_int; BPF_MAP_TYPE_SK_STORAGE as _],
    map_flags: *const [c_int; BPF_F_NO_PREALLOC as _],
    key: *const c_int,
    value: *const V,
    max_entries: *const [c_int; 0],
}

unsafe impl<V: Sync> Sync for SkStore<V> {}

#[link_section = ".maps"]
#[export_name = "CONNECT_DST_IPV4_ADDR_STORAGE"]
pub static CONNECT_DST_IPV4_ADDR_STORAGE: SyncUnsafeCell<SkStore<Ipv4Addr>> =
    SyncUnsafeCell::new(SkStore {
        r#type: ptr::null(),
        map_flags: ptr::null(),
        key: ptr::null(),
        value: ptr::null(),
        max_entries: ptr::null(),
    });

however, it will fail when EbpfLoader try to load the ebpf file with error

called `Result::unwrap()` on an `Err` value: ParseError(BtfError(UnexpectedBtfType { type_id: 23 }))

unless I use

#[link_section = ".maps"]
#[export_name = "CONNECT_DST_IPV4_ADDR_STORAGE"]
pub static mut CONNECT_DST_IPV4_ADDR_STORAGE: SkStore<Ipv4Addr> = SkStore {
    r#type: ptr::null(),
    map_flags: ptr::null(),
    key: ptr::null(),
    value: ptr::null(),
    max_entries: ptr::null(),
};

to create this global static variable directly

I am not sure which one cause this problem, rustc, bpf-linker or aya crate?

Metadata

Metadata

Assignees

No one assigned

    Labels

    upstream/llvmIssue which needs upstream work in LLVM

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions