Skip to content
Open
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