Skip to content

Bindings to kernel headers? #9

Open

Description

@akshayknarayan

Hi, I am writing a simple program that reads the tcp/tcp_probe tracepoint.

A common programming technique when writing BPF programs is including kernel headers to access struct definitions. Indeed, kernelscript init does usefully auto-generate bindings to certain kernel definitions.

Is there an easy way to have kernelscript additionally generate bindings to other values or kernel headers without manually copying them? For tcp/tcp_probe specifically, parsing struct sockaddr_in is relevant.

Activity

  1. congwang commented on Sep 29, 2025

    @congwang

    Good question! Currently kernelscript init only pulls context-related kernel structs from BTF (probably also its dependencies). Without hard-coding, it does not have knowledge to pull other related structs like struct sockaddr_in. Do you have any better ideas here?

  2. akshayknarayan commented on Sep 29, 2025

    @akshayknarayan
    Author

    Thanks for the clarification! I agree that pulling in related structs automatically is going to be quite hard, since tracepoint defs erase type info.

    A workaround might be to generate further bindings at compile time, with a statement such as the following (extrapolated from the syntax described here: https://github.com/multikernel/kernelscript/blob/main/SPEC.md#14-unified-import-and-include-system)

    import "struct sockaddr_in" from "<uapi/linux/in.h>"
    
  3. congwang commented on Sep 30, 2025

    @congwang

    Good idea! I think that is feasible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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