Repository navigation
expr: support shift and boolean ops in Bitwise - #375
Open
saphalpdyl wants to merge 2 commits into
Open
saphalpdyl wants to merge 2 commits into
saphalpdyl wants to merge 2 commits into
Conversation
Add .Op, .Data, and .SourceRegister2 to expr.Bitwise so the kernel's NFTA_BITWISE_OP operations (lshift, rshift, and, or, xor) can be built and decoded. Attributes are sent selectively based on the operation. NFTA_BITWISE_OP, NFTA_BITWISE_DATA, NFTA_BITWISE_SREG2 are defined locally since they are not yet in golang.org/x/sys/unix. Signed-off-by: saphalpdyl <git@saphal.me>
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
…itwise.marshalData Signed-off-by: saphalpdyl <git@saphal.me>
Author
|
A PR to support the missing constants is up in https://go.dev/cl/854465. |
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.
expr.Bitwiseonly supported the original mask/xor form (dreg = (sreg & mask) ^ xor). Currently, the kernel's bitwise expression also supports shift (LSHIFT, RSHIFT) and boolean operations (AND, OR, XOR) selected throughNFTA_BITWISE_OP.nft uses these for common rules like
ip6 dscpwhich compiles to[ bitwise reg x = ( reg x >> <shiftAmt> ) ], so rules likemeta mark set ip6 dscp map @somemapwas not possible with this library.CHANGES
expr.Bitwisehas three more attributes.Op,.Data, and.SourceRegister2.BitwiseOpmatchingenum nft_bitwise_ops. sourcemarshalDatasends exactly the attributes required for a given operation..SourceRegister2for AND & OR..Datafor LSHIFT, RSHIFT, and XOR. And,.Opoperation !=BitwiseOpMaskXor.unmarshal.Backwards compatibility
.Op's zero value is mask/xor, and for it no new attributes are sent. The message payload is the same as before for mask/xor operations. Existing tests pass.NOTE
NFTA_BITWISE_OP,NFTA_BITWISE_DATA,NFTA_BITWISE_SREG2are defined locally since they are not yet in golang.org/x/sys/unix.Respective tests have been added to bitwise_test.go and nftables_test.go to test non-xor/mask operations.