Skip to content

Commit 7adcc37

Browse files
peterk-akamaiaboch
authored andcommitted
Fix bug in modify U32 filter, correct the number of Keys in Sel
When `func (h *Handle) filterModify(...)` handles an `U32` filter, it also corrects the endiannes for the `Mask` and `Val` in the filter's `Sel.Keys`. For this it creates a new Keys slice and copies the values from the old one. This new slice is created with an incorrect size, likely the intention was to specify its capacity, but instead the size is specified. The old code happens to work correctly in practice when the number of keys is a power of 2. Otherwise empty (match all) keys are added to the end to make the number a power of 2. This commit fixes the issue. It was well tested, here's an excerpt: - Create a U32 filter with 5 Keys. The content of keys is irrelevant, only the number matters. - Print the filter back with `tc filter show ...`. The old behaviour: ``` filter parent ffff: protocol all pref 49150 u32 chain 0 fh 800::601 order 1537 key ht 800 bkt 0 *flowid :1 not_in_hw match 40000000/60000000 at 0 match 07010723/ffffffff at 24 match 07450767/ffffffff at 28 match 07890733/ffffffff at 32 match 07420801/ffe00000 at 36 match 00000000/00000000 at 0 match 00000000/00000000 at 0 match 00000000/00000000 at 0 ``` The last 3 entries were added by netlink. New behaviour: ``` filter parent ffff: protocol all pref 49150 u32 chain 0 fh 800::801 order 2049 key ht 800 bkt 0 flowid :1 not_in_hw match 60000000/f0000000 at 0 match 07010723/ffffffff at 24 match 07450767/ffffffff at 28 match 07890733/ffffffff at 32 match 07400000/ffe00000 at 36 ```
1 parent 17daef6 commit 7adcc37

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

filter_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ func (h *Handle) filterModify(filter Filter, proto, flags int) error {
349349
if native != networkOrder {
350350
// Copy TcU32Sel.
351351
cSel := *sel
352-
keys := make([]nl.TcU32Key, cap(sel.Keys))
352+
keys := make([]nl.TcU32Key, len(sel.Keys))
353353
copy(keys, sel.Keys)
354354
cSel.Keys = keys
355355
sel = &cSel

0 commit comments

Comments
 (0)