Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

btf: move wire type definitions into sys #1218

Open
lmb opened this issue Nov 10, 2023 · 2 comments
Open

btf: move wire type definitions into sys #1218

lmb opened this issue Nov 10, 2023 · 2 comments
Labels
good first issue Good for newcomers

Comments

@lmb
Copy link
Collaborator

lmb commented Nov 10, 2023

btf_types.go contains a bunch of hand written structs that map to types defined in the kernel's UAPI. We should replace these with auto generated types in sys package and use those from btf. This guarantees that we match the kernel 1:1 and also ensures that there is no implicit padding present.

  • btfType
  • btfEnum
  • btfArray
  • btfMember
  • btfParam
  • btfVar
  • btfVarSecInfo
  • btfDeclTag
  • btfEnum64

The changes need to be made here:

structs := []struct {
goType string
cType string
patches []patch
}{
{
"ProgInfo", "bpf_prog_info",
[]patch{
replace(objName, "name"),
replace(pointer, "xlated_prog_insns"),
replace(pointer, "map_ids"),
replace(pointer, "line_info"),
replace(pointer, "func_info"),
replace(btfID, "btf_id", "attach_btf_obj_id"),
replace(typeID, "attach_btf_id"),
},
},
{
"MapInfo", "bpf_map_info",
[]patch{
replace(objName, "name"),
replace(mapFlags, "map_flags"),
replace(typeID, "btf_vmlinux_value_type_id", "btf_key_type_id", "btf_value_type_id"),
},
},
{
"BtfInfo", "bpf_btf_info",
[]patch{
replace(pointer, "btf", "name"),
replace(btfID, "id"),
},
},
{
"LinkInfo", "bpf_link_info",
[]patch{
replace(enumTypes["LinkType"], "type"),
replace(linkID, "id"),
name(3, "extra"),
replaceWithBytes("extra"),
},
},
{"FuncInfo", "bpf_func_info", nil},
{"LineInfo", "bpf_line_info", nil},
{"XdpMd", "xdp_md", nil},
{
"SkLookup", "bpf_sk_lookup",
[]patch{
choose(0, "cookie"),
replaceWithBytes("remote_ip4", "remote_ip6", "local_ip4", "local_ip6"),
},
},
}

@lmb lmb added bug Something isn't working good first issue Good for newcomers and removed bug Something isn't working labels Nov 10, 2023
@amiremohamadi
Copy link

amiremohamadi commented Dec 29, 2023

I see bunch of helper functions and methods in btf_types.go . are we gonna keep them inside that file and just auto generate the structs inside sys package?

@lmb

@lmb
Copy link
Collaborator Author

lmb commented Jan 8, 2024

We could move those into a separate file in sys. That way we can have manually written methods on auto generated types.

OmarTariq612 added a commit to OmarTariq612/ebpf that referenced this issue Jan 10, 2024
…es.go structs.

This is guaranteed to match the kernel struct defenitions.
OmarTariq612 added a commit to OmarTariq612/ebpf that referenced this issue Jan 10, 2024
…es.go structs.

This is guaranteed to match the kernel struct defenitions.

Signed-off-by: OmarTariq612 <az2339913@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
Status: No status
Development

No branches or pull requests

2 participants