func()

in pkg/maps/loader.go [289:320]


func (m *BpfMap) CreateUpdateMapEntry(key, value uintptr, updateFlags uint64) error {

	mapFD, err := utils.GetMapFDFromID(int(m.MapID))
	if err != nil {
		log.Errorf("unable to GetMapFDfromID and ret %d and err %s", int(mapFD), err)
		return fmt.Errorf("unable to get FD: %s", err)
	}
	defer unix.Close(mapFD)

	attr := utils.BpfMapAttr{
		MapFD: uint32(mapFD),
		Flags: updateFlags,
		Key:   uint64(key),
		Value: uint64(value),
	}
	ret, _, errno := unix.Syscall(
		unix.SYS_BPF,
		uintptr(constdef.BPF_MAP_UPDATE_ELEM),
		uintptr(unsafe.Pointer(&attr)),
		unsafe.Sizeof(attr),
	)
	runtime.KeepAlive(key)
	runtime.KeepAlive(value)

	if errno != 0 {
		log.Errorf("unable to create/update map entry and ret %d and err %s", int(ret), errno)
		return fmt.Errorf("unable to update map: %s", errno)
	}

	log.Infof("Create/Update map entry done with fd : %d and err %s", int(ret), errno)
	return nil
}