Skip to content

btf: move wire type definitions into sys #1218

Description

@lmb

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"),
},
},
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions