func (pl *ProfileLoader) InsertMapOfMapsKeyValue(kv *keyvalue.MapOfMapsKeyValue) error {
	byteOrder := utils.GetHostByteOrder()
	// Select inner map and clone it
	kMap, ok := pl.collection.Maps[kv.MapSectionToClone]
	if !ok {
		return errors.Wrap(errors.New(kv.MapSectionToClone), "unknown inner map")
	}
	// Clone map
	newSpec := kMap.MapSpec
	newSpec.Name = keyvalue.NewRandomMapName()
	// Create duplicated map
	newMap, err := ebpf.NewMap(newSpec)
	if err != nil {
		return errors.Wrapf(err, "couldn't duplicate map %s", kv.MapSectionToClone)
	}
	// Add map to the list of program handled by the collection
	pl.collection.Maps[newSpec.Name] = newMap
	// Insert key-values in this new map
	for _, innerKV := range kv.Keys {
		// Generate Key unsafe pointer
		keyPtr, err := innerKV.GetKey(byteOrder)
		if err != nil {
			return errors.Wrapf(err, "couldn't create unsafe pointer key for type %s", reflect.TypeOf(innerKV.Key))
		}
		// Generate Value unsafe pointer
		valuePtr, err := innerKV.GetValue(byteOrder)
		if err != nil {
			return errors.Wrapf(err, "couldn't create unsafe pointer value for type %s", reflect.TypeOf(innerKV.Key))
		}
		// Insert key-value in map
		if err := newMap.Put(keyPtr, valuePtr); err != nil {
			return errors.Wrapf(err, "failed to insert element in map %s", newSpec.Name)
		}
	}
	// Select map of maps
	mapOfMaps, ok := pl.collection.Maps[kv.MapOfMapsKey.GetMapSection()]
	if !ok {
		return errors.Wrap(errors.New(kv.MapOfMapsKey.GetMapSection()), "unknown map")
	}
	// Add new inner map entry
	keyPtr, err := kv.MapOfMapsKey.GetKey(byteOrder)
	if err != nil {
		return errors.Wrapf(err, "couldn't create unsafe pointer key for type %s", reflect.TypeOf(kv.MapOfMapsKey))
	}
	value := uint32(newMap.FD())
	if err := mapOfMaps.Put(keyPtr, unsafe.Pointer(&value)); err != nil {
		return errors.Wrapf(err, "failed to insert element in map %s", kv.MapOfMapsKey.GetMapSection())
	}
	// Retrieve inner map ID and save inner map ID <-> map name
	innerMapIDB, err := mapOfMaps.GetBytes(keyPtr)
	if err != nil {
		return errors.Wrap(err, "couldn't retrieve inner map ID")
	}
	innerMapID := byteOrder.Uint32(innerMapIDB)
	pl.MapIDMapName[innerMapID] = newSpec.Name
	return nil
}
// InsertMapOfMapsKeyValue - Inserts a map-of-maps key value in the kernel
Inserts a map-of-maps key value in the kernel
// InsertMapOfMapsKeyValue - Inserts a map - of - maps key value in the kernel
func (pl *ProfileLoader) InsertMapOfMapsKeyValue(kv *keyvalue.MapOfMapsKeyValue) error {
	byteOrder := utils.GetHostByteOrder()
	kMap, ok := pl.collection.Maps[kv.MapSectionToClone]
	if !ok {
		return errors.Wrap(errors.New(kv.MapSectionToClone), "unknown inner map")
	}
	newSpec := kMap.MapSpec
	newSpec.Name = keyvalue.NewRandomMapName()
	newMap, err := ebpf.NewMap(newSpec)
	if err != nil {
		return errors.Wrapf(err, "couldn't duplicate map %s", kv.MapSectionToClone)
	}
	pl.collection.Maps[newSpec.Name] = newMap
	for _, innerKV := range kv.Keys {
		keyPtr, err := innerKV.GetKey(byteOrder)
		if err != nil {
			return errors.Wrapf(err, "couldn't create unsafe pointer key for type %s", reflect.TypeOf(innerKV.Key))
		}
		valuePtr, err := innerKV.GetValue(byteOrder)
		if err != nil {
			return errors.Wrapf(err, "couldn't create unsafe pointer value for type %s", reflect.TypeOf(innerKV.Key))
		}
		if err := newMap.Put(keyPtr, valuePtr); err != nil {
			return errors.Wrapf(err, "failed to insert element in map %s", newSpec.Name)
		}
	}
	mapOfMaps, ok := pl.collection.Maps[kv.MapOfMapsKey.GetMapSection()]
	if !ok {
		return errors.Wrap(errors.New(kv.MapOfMapsKey.GetMapSection()), "unknown map")
	}
	keyPtr, err := kv.MapOfMapsKey.GetKey(byteOrder)
	if err != nil {
		return errors.Wrapf(err, "couldn't create unsafe pointer key for type %s", reflect.TypeOf(kv.MapOfMapsKey))
	}
	value := uint32(newMap.FD())
	if err := mapOfMaps.Put(keyPtr, unsafe.Pointer(&value)); err != nil {
		return errors.Wrapf(err, "failed to insert element in map %s", kv.MapOfMapsKey.GetMapSection())
	}
	innerMapIDB, err := mapOfMaps.GetBytes(keyPtr)
	if err != nil {
		return errors.Wrap(err, "couldn't retrieve inner map ID")
	}
	innerMapID := byteOrder.Uint32(innerMapIDB)
	pl.MapIDMapName[innerMapID] = newSpec.Name
	return nil
}
func ( pl * ProfileLoader ) InsertMapOfMapsKeyValue ( kv * keyvalue . MapOfMapsKeyValue ) error { byteOrder := utils . GetHostByteOrder ( ) kMap , ok := pl . collection . Maps [ kv . MapSectionToClone ] if ! ok { return errors . Wrap ( errors . New ( kv . MapSectionToClone ) , " " ) } newSpec := kMap . MapSpec newSpec . Name = keyvalue . NewRandomMapName ( ) newMap , err := ebpf . NewMap ( newSpec ) if err != nil { return errors . Wrapf ( err , " " , kv . MapSectionToClone ) } pl . collection . Maps [ newSpec . Name ] = newMap for _ , innerKV := range kv . Keys { keyPtr , err := innerKV . GetKey ( byteOrder ) if err != nil { return errors . Wrapf ( err , " " , reflect . TypeOf ( innerKV . Key ) ) } valuePtr , err := innerKV . GetValue ( byteOrder ) if err != nil { return errors . Wrapf ( err , " " , reflect . TypeOf ( innerKV . Key ) ) } if err := newMap . Put ( keyPtr , valuePtr ) ; err != nil { return errors . Wrapf ( err , " " , newSpec . Name ) } } mapOfMaps , ok := pl . collection . Maps [ kv . MapOfMapsKey . GetMapSection ( ) ] if ! ok { return errors . Wrap ( errors . New ( kv . MapOfMapsKey . GetMapSection ( ) ) , " " ) } keyPtr , err := kv . MapOfMapsKey . GetKey ( byteOrder ) if err != nil { return errors . Wrapf ( err , " " , reflect . TypeOf ( kv . MapOfMapsKey ) ) } value := uint32 ( newMap . FD ( ) ) if err := mapOfMaps . Put ( keyPtr , unsafe . Pointer ( & value ) ) ; err != nil { return errors . Wrapf ( err , " " , kv . MapOfMapsKey . GetMapSection ( ) ) } innerMapIDB , err := mapOfMaps . GetBytes ( keyPtr ) if err != nil { return errors . Wrap ( err , " " ) } innerMapID := byteOrder . Uint32 ( innerMapIDB ) pl . MapIDMapName [ innerMapID ] = newSpec . Name return nil }
Inserts a map-of-maps key value in the kernel
Inserts a map - of - maps key value in the kernel
// Select inner map and clone it // Clone map // Create duplicated map // Add map to the list of program handled by the collection // Insert key-values in this new map // Generate Key unsafe pointer // Generate Value unsafe pointer // Insert key-value in map // Select map of maps // Add new inner map entry // Retrieve inner map ID and save inner map ID <-> map name