MCPcopy
hub / github.com/cilium/ebpf / findTargetInModule

Function findTargetInModule

prog.go:1279–1313  ·  view source on GitHub ↗

findTargetInModule attempts to find a named type in any loaded module. base must contain the kernel's types and is used to parse kmod BTF. Modules are searched in the order they were loaded. Returns btf.ErrNotFound if the target can't be found in any module.

(typeName string, target *btf.Type, cache *btf.Cache)

Source from the content-addressed store, hash-verified

1277//
1278// Returns btf.ErrNotFound if the target can't be found in any module.
1279func findTargetInModule(typeName string, target *btf.Type, cache *btf.Cache) (*btf.Spec, *btf.Handle, error) {
1280 it := new(btf.HandleIterator)
1281 defer it.Handle.Close()
1282
1283 for it.Next() {
1284 info, err := it.Handle.Info()
1285 if err != nil {
1286 return nil, nil, fmt.Errorf("get info for BTF ID %d: %w", it.ID, err)
1287 }
1288
1289 if !info.IsModule() {
1290 continue
1291 }
1292
1293 spec, err := cache.Module(info.Name)
1294 if err != nil {
1295 return nil, nil, fmt.Errorf("parse types for module %s: %w", info.Name, err)
1296 }
1297
1298 err = spec.TypeByName(typeName, target)
1299 if errors.Is(err, btf.ErrNotFound) {
1300 continue
1301 }
1302 if err != nil {
1303 return nil, nil, fmt.Errorf("lookup type in module %s: %w", info.Name, err)
1304 }
1305
1306 return spec, it.Take(), nil
1307 }
1308 if err := it.Err(); err != nil {
1309 return nil, nil, fmt.Errorf("iterate modules: %w", err)
1310 }
1311
1312 return nil, nil, btf.ErrNotFound
1313}
1314
1315// find an attach target type in a program.
1316//

Callers 1

findTargetInKernelFunction · 0.85

Calls 9

IsModuleMethod · 0.80
ModuleMethod · 0.80
TypeByNameMethod · 0.80
CloseMethod · 0.65
InfoMethod · 0.65
NextMethod · 0.45
IsMethod · 0.45
TakeMethod · 0.45
ErrMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…