@@ -41,7 +41,6 @@ const (
4141 structRawPacketEventDataSize = 256
4242
4343 dropStatsKeyStackOffset = int16 (- 8 )
44- dropStatsValStackOffset = int16 (- 16 )
4544)
4645
4746// ProgOpts defines options
@@ -109,38 +108,25 @@ func (opts *ProgOpts) WithDropStatsMapFd(fd int) *ProgOpts {
109108
110109func dropStatsIncrementInsts (filterIndex int , dropStatsMapFd int , nextLabel string ) asm.Instructions {
111110 incLabel := fmt .Sprintf ("inc_drop_stat_%d" , filterIndex )
112- initLabel := fmt .Sprintf ("init_drop_stat_%d" , filterIndex )
113111
114112 return asm.Instructions {
115113 // Put the key on the stack
116114 asm .Mov .Reg (asm .R1 , asm .RFP ).WithSymbol (incLabel ),
117115 asm .Add .Imm (asm .R1 , int32 (dropStatsKeyStackOffset )),
118116 asm .Mov .Imm (asm .R2 , int32 (filterIndex )),
119- asm .StoreMem (asm .R1 , 0 , asm .R2 , asm .DWord ),
117+ asm .StoreMem (asm .R1 , 0 , asm .R2 , asm .Word ),
120118 // Lookup in the map
121119 asm .LoadMapPtr (asm .R1 , dropStatsMapFd ),
122120 asm .Mov .Reg (asm .R2 , asm .RFP ),
123121 asm .Add .Imm (asm .R2 , int32 (dropStatsKeyStackOffset )),
124122 asm .FnMapLookupElem .Call (),
125- asm .JEq .Imm (asm .R0 , 0 , initLabel ),
126- // Increment if it exists
123+ // should never happen
124+ asm .JEq .Imm (asm .R0 , 0 , nextLabel ),
125+ // Increment
127126 asm .Mov .Reg (asm .R5 , asm .R0 ),
128- asm .LoadMem (asm .R6 , asm .R5 , 0 , asm .DWord ),
127+ asm .LoadMem (asm .R6 , asm .R5 , 0 , asm .Word ),
129128 asm .Add .Imm (asm .R6 , 1 ),
130- asm .StoreMem (asm .R5 , 0 , asm .R6 , asm .DWord ),
131- asm .Ja .Label (nextLabel ),
132- // Otherwise create the key and insert it
133- asm .Mov .Reg (asm .R3 , asm .RFP ).WithSymbol (initLabel ),
134- asm .Add .Imm (asm .R3 , int32 (dropStatsValStackOffset )),
135- asm .Mov .Imm (asm .R4 , 1 ),
136- asm .StoreMem (asm .R3 , 0 , asm .R4 , asm .DWord ),
137- asm .LoadMapPtr (asm .R1 , dropStatsMapFd ),
138- asm .Mov .Reg (asm .R2 , asm .RFP ),
139- asm .Add .Imm (asm .R2 , int32 (dropStatsKeyStackOffset )),
140- asm .Mov .Reg (asm .R3 , asm .RFP ),
141- asm .Add .Imm (asm .R3 , int32 (dropStatsValStackOffset )),
142- asm .Mov .Imm (asm .R4 , 0 ),
143- asm .FnMapUpdateElem .Call (),
129+ asm .StoreMem (asm .R5 , 0 , asm .R6 , asm .Word ),
144130 asm .Ja .Label (nextLabel ),
145131 }
146132}
@@ -270,6 +256,10 @@ func filtersToProgs(filters []Filter, opts ProgOpts, headerInsts, footerInsts as
270256 )
271257
272258 for i , filter := range filters {
259+ if i >= MaxDropActionFilters {
260+ mErr = multierror .Append (mErr , fmt .Errorf ("too many filters, stop adding filters, max is %d" , MaxDropActionFilters ))
261+ break
262+ }
273263 filterInsts , err := FilterToInsts (i , filter , opts )
274264 if err != nil {
275265 mErr = multierror .Append (mErr , fmt .Errorf ("unable to generate eBPF bytecode for rule `%s`: %s" , filter .RuleID , err ))
0 commit comments