Skip to content

Commit

Permalink
feat: add AttachStructOps() (#476)
Browse files Browse the repository at this point in the history
Add AttachStructOps() and selftest.
  • Loading branch information
ianchen0119 authored Mar 6, 2025
1 parent 12c2216 commit d3930cf
Show file tree
Hide file tree
Showing 11 changed files with 860 additions and 0 deletions.
2 changes: 2 additions & 0 deletions link.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
CgroupLegacy
Netns
Iter
StructOps
)

//
Expand All @@ -47,6 +48,7 @@ type bpfLinkLegacy struct {
type BPFLink struct {
link *C.struct_bpf_link
prog *BPFProg
m *BPFMap
linkType LinkType
eventName string
legacy *bpfLinkLegacy // if set, this is a fake BPFLink
Expand Down
13 changes: 13 additions & 0 deletions map.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ func (m *BPFMap) ReuseFD(fd int) error {
return nil
}

func (m *BPFMap) AttachStructOps() (*BPFLink, error) {
linkC, errno := C.bpf_map__attach_struct_ops(m.bpfMap)
if linkC == nil {
return nil, fmt.Errorf("failed to attach struct_ops: %w", errno)
}
return &BPFLink{
link: linkC,
m: m,
linkType: StructOps,
eventName: fmt.Sprintf("structOps-%s", m.Name()),
}, nil
}

func (m *BPFMap) Name() string {
return C.GoString(C.bpf_map__name(m.bpfMap))
}
Expand Down
1 change: 1 addition & 0 deletions selftest/common/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scx
Loading

0 comments on commit d3930cf

Please sign in to comment.