ebpf
ebpf copied to clipboard
link: RawTracepoint and Iter link information
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?
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:
- Add
Info() (*RawLinkInfo, error)
toLink
. This is a problem for BPF link types that have custom metadata likebpf_iter_link_info
. For those we probably want something likeInfo() (*IterInfo, error)
with IterInfo embedding RawLinkInfo. WithInfo()
part of the interface this becomes impossible. - Add structs like
NetNsInfo
for all link types we currently have defined, and export the currently unexported link types. Then the user can simply assertlink.(*Iter).Info()
which embeds a RawLinkInfo. Downside: there is no way to get the RawLinkInfo for a genericLink
without type asserting it. - Add a
struct Info
which contains all the possible metadata. Access to individual fields would have to happen via getters likeProgramInfo.MapIDs
. Then we can addInfo() (*Info, error)
toLink
.
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 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.
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.