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

Supports map of maps #2

Merged
merged 1 commit into from
Jun 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions bcc/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ func (table *Table) Name() string {
return C.GoString(C.bpf_table_name(table.module.p, table.id))
}

// Fd returns the table file descriptor.
func (table *Table) Fd() int {
mod := table.module.p
return int(C.bpf_table_fd_id(mod, table.id))
}

// Config returns the table properties (name, fd, ...).
func (table *Table) Config() map[string]interface{} {
mod := table.module.p
Expand Down Expand Up @@ -228,6 +234,22 @@ func (table *Table) SetP(key, leaf unsafe.Pointer) error {
return nil
}

// SetMap sets a key to values for BPF_HASH_OF_MAPS and BPF_ARRAY_OF_MAPS.
func (table *Table) SetMap(key unsafe.Pointer, innerMapFd int) error {
fd := C.bpf_table_fd_id(table.module.p, table.id)

leaf := make([]byte, 8)
GetHostByteOrder().PutUint64(leaf, uint64(innerMapFd))
leafP := unsafe.Pointer(&leaf[0])

_, err := C.bpf_update_elem(fd, key, leafP, 0)
if err != nil {
return err
}

return nil
}

// Delete a key.
func (table *Table) Delete(key []byte) error {
fd := C.bpf_table_fd_id(table.module.p, table.id)
Expand Down