Fix optional match key mask using XOR instead of shift#133
Open
gaetschwartz wants to merge 1 commit into
Open
Conversation
The mask was built as (2 ^ field_size) - 1, treating ^ as exponentiation; compute (1ULL << field_size) - 1 so valid optional keys get an all-ones mask.
jafingerhut
approved these changes
Jun 11, 2026
jafingerhut
left a comment
Contributor
There was a problem hiding this comment.
Looks like this was a bug, and a good fix, to me.
Contributor
|
@gaetschwartz The DCO check is failing for this PR. Please take a look at the page of the PR here #133 and find the "DCO" link in the section near the bottom under "Some checks were not successful". You can click on that link to get to a page with some suggestions for how to sign your commit for the PR. If it is easier to create a new separate PR where you have done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
BfRtMatchActionKey::setValueOptionalbuilds the mask for a valid optional key as(2 ^ field_size) - 1, treating^as exponentiation. In C++ this is bitwise XOR, so the mask is wrong for essentially every field size — e.g. an 8-bit field gets(2 XOR 8) - 1 = 9(0b00001001) instead of0xFF, and a 2-bit field underflows to an all-ones mask. As a result, optional match keys set through BF-RT match against incorrect bits instead of performing an exact match on the full field.This computes the mask as
(1ULL << field_size) - 1, falling back toUINT64_MAXfor 64-bit fields since shifting by the full type width is undefined behavior.