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

feat: add AttachStructOps() #476

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
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
Loading
Loading