Example #1
0
func (table *BpfTable) Set(keyX, leafX interface{}) error {
	fd := C.bpf_table_fd_id(table.module.p, table.id)
	key, err := table.keyToBytes(keyX)
	if err != nil {
		return err
	}
	leaf, err := table.leafToBytes(leafX)
	if err != nil {
		return err
	}
	keyP := unsafe.Pointer(&key[0])
	leafP := unsafe.Pointer(&leaf[0])
	r := C.bpf_update_elem(fd, keyP, leafP, 0)
	if r != 0 {
		return fmt.Errorf("BpfTable.Set: unable to update element")
	}
	return nil
}
Example #2
0
func (table *BpfTable) Set(keyStr, leafStr string) error {
	if table == nil || table.module.p == nil {
		panic("table is nil")
	}
	fd := C.bpf_table_fd_id(table.module.p, table.id)
	key, err := table.keyToBytes(keyStr)
	if err != nil {
		return err
	}
	leaf, err := table.leafToBytes(leafStr)
	if err != nil {
		return err
	}
	keyP := unsafe.Pointer(&key[0])
	leafP := unsafe.Pointer(&leaf[0])
	r, err := C.bpf_update_elem(fd, keyP, leafP, 0)
	if r != 0 {
		return fmt.Errorf("BpfTable.Set: unable to update element (%s=%s): %s", keyStr, leafStr, err)
	}
	return nil
}