@@ -119,13 +119,28 @@ func (pm *PolicyManager) updateBPF(
119119 return nil
120120}
121121
122+ // eBPF data filter only supports first 64 rules for each key.
123+ type stringFilterConfigBPF struct {
124+ prefixEnabled uint64
125+ suffixEnabled uint64
126+ exactEnabled uint64
127+ prefixMatchIfKeyMissing uint64
128+ suffixMatchIfKeyMissing uint64
129+ exactMatchIfKeyMissing uint64
130+ }
131+
132+ type dataFilterConfigBPF struct {
133+ string stringFilterConfigBPF
134+ }
135+
122136type eventConfig struct {
123137 rulesVersion uint16
124- padding [6 ]uint8 // free for further use
138+ hasOverflow uint8
139+ padding [5 ]uint8 // free for further use
125140 submitForRules uint64
126141 fieldTypes uint64
127142 scopeFilters scopeFiltersConfig
128- dataFilter dataFilterConfig
143+ dataFilter dataFilterConfigBPF
129144}
130145
131146// updateEventsConfigMap updates the events config map with the given events fields and filter config.
@@ -145,6 +160,27 @@ func (pm *PolicyManager) updateEventsConfigMap(
145160 filterConfig = dataFilterConfig {}
146161 }
147162
163+ // Extract the first bitmap from each field of stringFilterConfig
164+ dataFilterCfg := dataFilterConfigBPF {}
165+ if len (filterConfig .string .prefixEnabled ) > 0 {
166+ dataFilterCfg .string .prefixEnabled = filterConfig .string .prefixEnabled [0 ]
167+ }
168+ if len (filterConfig .string .suffixEnabled ) > 0 {
169+ dataFilterCfg .string .suffixEnabled = filterConfig .string .suffixEnabled [0 ]
170+ }
171+ if len (filterConfig .string .exactEnabled ) > 0 {
172+ dataFilterCfg .string .exactEnabled = filterConfig .string .exactEnabled [0 ]
173+ }
174+ if len (filterConfig .string .prefixMatchIfKeyMissing ) > 0 {
175+ dataFilterCfg .string .prefixMatchIfKeyMissing = filterConfig .string .prefixMatchIfKeyMissing [0 ]
176+ }
177+ if len (filterConfig .string .suffixMatchIfKeyMissing ) > 0 {
178+ dataFilterCfg .string .suffixMatchIfKeyMissing = filterConfig .string .suffixMatchIfKeyMissing [0 ]
179+ }
180+ if len (filterConfig .string .exactMatchIfKeyMissing ) > 0 {
181+ dataFilterCfg .string .exactMatchIfKeyMissing = filterConfig .string .exactMatchIfKeyMissing [0 ]
182+ }
183+
148184 // encoded event's field types
149185 var fieldTypes uint64
150186 fields := eventsFields [id ]
@@ -154,16 +190,25 @@ func (pm *PolicyManager) updateEventsConfigMap(
154190
155191 // Create submit bitmap based on rules count - n least significant bits set to 1
156192 submitForRules := uint64 (0 )
157- if ecfg .rulesCount > 0 {
193+ if ecfg .rulesCount >= 64 {
194+ submitForRules = ^ uint64 (0 ) // All bits set to 1
195+ } else if ecfg .rulesCount > 0 {
158196 submitForRules = (uint64 (1 ) << ecfg .rulesCount ) - 1
159197 }
160198
199+ // Set hasOverflow flag
200+ var overflowFlag uint8
201+ if ecfg .hasOverflow {
202+ overflowFlag = 1
203+ }
204+
161205 eventConfig := eventConfig {
162206 rulesVersion : ecfg .rulesVersion ,
207+ hasOverflow : overflowFlag ,
163208 submitForRules : submitForRules ,
164209 fieldTypes : fieldTypes ,
165210 scopeFilters : pm .computeScopeFiltersConfig (id ),
166- dataFilter : filterConfig ,
211+ dataFilter : dataFilterCfg ,
167212 }
168213
169214 err := eventsConfigMap .Update (unsafe .Pointer (& id ), unsafe .Pointer (& eventConfig ))
@@ -218,8 +263,8 @@ func (pm *PolicyManager) computeScopeFiltersConfig(eventID events.ID) scopeFilte
218263
219264 // Loop through rules for this event
220265 for _ , rule := range eventRules .Rules {
221- if rule .Policy == nil {
222- continue // Skip dependency rules that have no policy
266+ if rule .Policy == nil || rule . ID >= 64 {
267+ continue
223268 }
224269
225270 offset := rule .ID // Use rule ID (0-63) for bitmap position
@@ -301,7 +346,7 @@ func (pm *PolicyManager) computeScopeFiltersConfig(eventID events.ID) scopeFilte
301346// updateUIntFilterBPF updates the BPF maps for the given uint filter map.
302347func (pm * PolicyManager ) updateUIntFilterBPF (
303348 bpfModule * bpf.Module ,
304- filterMap map [filterVersionKey ]map [uint64 ]ruleBitmap ,
349+ filterMap map [filterVersionKey ]map [uint64 ][] ruleBitmap ,
305350 innerMapName string ,
306351 outerMapName string ,
307352) error {
@@ -318,7 +363,15 @@ func (pm *PolicyManager) updateUIntFilterBPF(
318363 vKey .Version , vKey .EventID , err )
319364 }
320365
321- for key , bitmap := range innerMap {
366+ for key , bitmaps := range innerMap {
367+ // Check if there are bitmaps for this key
368+ if len (bitmaps ) == 0 {
369+ continue
370+ }
371+
372+ // Update only the first bitmap (first 64 rules)
373+ bitmap := bitmaps [0 ]
374+
322375 // Convert the uint64 key to []byte
323376 keyBytes := make ([]byte , 4 )
324377 binary .LittleEndian .PutUint32 (keyBytes , uint32 (key ))
@@ -343,7 +396,7 @@ func (pm *PolicyManager) updateUIntFilterBPF(
343396// updateStringFilterBPF updates the BPF maps for the given string filter map.
344397func (pm * PolicyManager ) updateStringFilterBPF (
345398 bpfModule * bpf.Module ,
346- filterMap map [filterVersionKey ]map [string ]ruleBitmap ,
399+ filterMap map [filterVersionKey ]map [string ][] ruleBitmap ,
347400 innerMapName string ,
348401 outerMapName string ,
349402) error {
@@ -360,7 +413,15 @@ func (pm *PolicyManager) updateStringFilterBPF(
360413 vKey .Version , vKey .EventID , err )
361414 }
362415
363- for key , bitmap := range innerMap {
416+ for key , bitmaps := range innerMap {
417+ // Check if there are bitmaps for this key
418+ if len (bitmaps ) == 0 {
419+ continue
420+ }
421+
422+ // Update only the first bitmap (first 64 rules)
423+ bitmap := bitmaps [0 ]
424+
364425 byteStr := make ([]byte , maxBpfStrFilterSize )
365426 copy (byteStr , key )
366427 keyPointer := unsafe .Pointer (& byteStr [0 ])
@@ -383,7 +444,7 @@ func (pm *PolicyManager) updateStringFilterBPF(
383444// updateBinaryFilterBPF updates the BPF maps for the given binary filter map.
384445func (pm * PolicyManager ) updateBinaryFilterBPF (
385446 bpfModule * bpf.Module ,
386- filterMap map [filterVersionKey ]map [filters.NSBinary ]ruleBitmap ,
447+ filterMap map [filterVersionKey ]map [filters.NSBinary ][] ruleBitmap ,
387448 innerMapName string ,
388449 outerMapName string ,
389450) error {
@@ -400,7 +461,15 @@ func (pm *PolicyManager) updateBinaryFilterBPF(
400461 vKey .Version , vKey .EventID , err )
401462 }
402463
403- for key , bitmap := range innerMap {
464+ for key , bitmaps := range innerMap {
465+ // Check if there are bitmaps for this key
466+ if len (bitmaps ) == 0 {
467+ continue
468+ }
469+
470+ // Update only the first bitmap (first 64 rules)
471+ bitmap := bitmaps [0 ]
472+
404473 if len (key .Path ) > maxBpfBinPathSize {
405474 return filters .InvalidValue (key .Path )
406475 }
@@ -434,7 +503,7 @@ func (pm *PolicyManager) updateBinaryFilterBPF(
434503// updateStringDataFilterLPMBPF updates the BPF maps for the given kernel data LPM filter map.
435504func (pm * PolicyManager ) updateStringDataFilterLPMBPF (
436505 bpfModule * bpf.Module ,
437- filterMap map [filterVersionKey ]map [string ]ruleBitmap ,
506+ filterMap map [filterVersionKey ]map [string ][] ruleBitmap ,
438507 innerMapName string ,
439508 outerMapName string ,
440509) error {
@@ -451,7 +520,15 @@ func (pm *PolicyManager) updateStringDataFilterLPMBPF(
451520 vKey .Version , vKey .EventID , err )
452521 }
453522
454- for key , bitmap := range innerMap {
523+ for key , bitmaps := range innerMap {
524+ // Check if there are bitmaps for this key
525+ if len (bitmaps ) == 0 {
526+ continue
527+ }
528+
529+ // Update only the first bitmap (first 64 rules)
530+ bitmap := bitmaps [0 ]
531+
455532 // Ensure the string length is within the maximum allowed limit,
456533 // excluding the NULL terminator.
457534 if len (key ) > maxBpfDataFilterStrSize - 1 {
@@ -484,7 +561,7 @@ func (pm *PolicyManager) updateStringDataFilterLPMBPF(
484561// updateStringDataFilterBPF updates the BPF maps for the given kernel data filter map.
485562func (pm * PolicyManager ) updateStringDataFilterBPF (
486563 bpfModule * bpf.Module ,
487- filterMap map [filterVersionKey ]map [string ]ruleBitmap ,
564+ filterMap map [filterVersionKey ]map [string ][] ruleBitmap ,
488565 innerMapName string ,
489566 outerMapName string ,
490567) error {
@@ -501,7 +578,15 @@ func (pm *PolicyManager) updateStringDataFilterBPF(
501578 vKey .Version , vKey .EventID , err )
502579 }
503580
504- for key , bitmap := range innerMap {
581+ for key , bitmaps := range innerMap {
582+ // Check if there are bitmaps for this key
583+ if len (bitmaps ) == 0 {
584+ continue
585+ }
586+
587+ // Update only the first bitmap (first 64 rules)
588+ bitmap := bitmaps [0 ]
589+
505590 // Ensure the string length is within the maximum allowed limit,
506591 // excluding the NULL terminator
507592 if len (key ) > maxBpfDataFilterStrSize - 1 {
@@ -636,7 +721,7 @@ type procInfo struct {
636721// populateProcInfoMap populates the ProcInfoMap with the binaries to track.
637722// TODO: Should ProcInfoMap be cleared when a Policies new version is created?
638723// Or should it be versioned too?
639- func populateProcInfoMap (bpfModule * bpf.Module , filterMap map [filterVersionKey ]map [filters.NSBinary ]ruleBitmap ) error {
724+ func populateProcInfoMap (bpfModule * bpf.Module , filterMap map [filterVersionKey ]map [filters.NSBinary ][] ruleBitmap ) error {
640725 procInfoMap , err := bpfModule .GetMap (ProcInfoMap )
641726 if err != nil {
642727 return errfmt .WrapError (err )
0 commit comments