nftables: Add more operations and raise kernel errors #902
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.
Hello,
this PR is motivated by the lack of error reporting for nftables write operations. I have seen that there are unfinished classes like
BatchSocket
andBatchAddrPool
, which are probably supposed to tackle the issue which I am addressing here. So I hope that this PR is not too intrusive or diverging too much from your intention.Currently, the handling of batch messages is difficult, as
nlm_request
sends each message separately and listens for responses from a single message sequence number only. Therefore, 39741a4 introducesnlm_request_batch
, which can be supplied with a list of messages. The function will then listen for expected responses for any of the supplied messages and return/yield them to the caller.This is leveraged by 729de2d, which introduces acknowledgements for write operations by default. With this commit, errors, e.g. caused by invalid rule expressions or missing NLAs, will no longer go unnoticed and silent failures will no longer happen. The commit also adds some additional commands for the
table
,chain
andrule
objects.Before, the following would silently fail because the chain does not exist:
nft.rule('add', table='test', chain='doesnotexist', expressions=some_valid_expr)
Now it will fail as indicated by the errno from the kernel:
pr2modules.netlink.exceptions.NetlinkError: (2, 'No such file or directory')
Silent failures can still be enabled by setting the
flags
parameter to 0. If the parameter is not set, it will default toNLM_F_ACK
, which will cause the batch request function to expect an acknowledgement:nft.rule('add', table='test', chain='doesnotexist', expressions=some_expr, flags=0)
Kind regards.