ebpf icon indicating copy to clipboard operation
ebpf copied to clipboard

link: RawTracepoint and Iter link information

Open mehrdadrad opened this issue 3 years ago • 3 comments

LoadPinnedLink doesn't expose RawLinkInfo like LoadPinnedRawLink (deprecated). The RawLinkInfo already has type, id and programID fields and we can add more type-specific information later to this structure like ifindex for XDP, attach_type for tracing/cgroup/netns/iter etc. Any thoughts?

mehrdadrad avatar Nov 26 '21 06:11 mehrdadrad

You're right, the same problem applies to RawLink.UpdateArgs. As a workaround you can assert that the Link implements an interface:

interface {
    Info() (*RawLinkInfo, error)
}

There are a couple of options to fix this:

  1. Add Info() (*RawLinkInfo, error) to Link. This is a problem for BPF link types that have custom metadata like bpf_iter_link_info. For those we probably want something like Info() (*IterInfo, error) with IterInfo embedding RawLinkInfo. With Info() part of the interface this becomes impossible.
  2. Add structs like NetNsInfo for all link types we currently have defined, and export the currently unexported link types. Then the user can simply assert link.(*Iter).Info() which embeds a RawLinkInfo. Downside: there is no way to get the RawLinkInfo for a generic Link without type asserting it.
  3. Add a struct Info which contains all the possible metadata. Access to individual fields would have to happen via getters like ProgramInfo.MapIDs. Then we can add Info() (*Info, error) to Link.

Needs some experimentation, but I think the third one seems simplest / the one with the least amount of drawbacks. We can even make it somewhat backwards compatible by aliasing NetNsInfo to Info.

lmb avatar Nov 26 '21 16:11 lmb

@lmb Actually I tried to add type-specific information and expose all link_info last weekend and I just cleaned up the code and added it as draft pull request #509 please review and let me know what do you think.

mehrdadrad avatar Nov 29 '21 04:11 mehrdadrad

Most of the link types now have info thanks to @mehrdadrad's PR. The two missing ones are RawTracepointInfo and IterInfo since they contain strings.

lmb avatar Dec 17 '21 18:12 lmb