-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix nftables module check function doesn't understand that braces are optional #67079
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix nftables module check function doesn't understand that braces are optional |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -569,13 +569,12 @@ def check(table="filter", chain=None, rule=None, family="ipv4"): | |
return res | ||
|
||
nft_family = _NFTABLES_FAMILIES[family] | ||
cmd = "{} --handle --numeric --numeric --numeric list chain {} {} {}".format( | ||
_nftables_cmd(), nft_family, table, chain | ||
) | ||
search_rule = f"{rule} #" | ||
out = __salt__["cmd.run"](cmd, python_shell=False).find(search_rule) | ||
cmd = f"{_nftables_cmd()} --handle list chain {nft_family} {table} {chain}" | ||
search_rule = f"{rule} #".replace("{ ", "{? ?").replace(" }", " ?}?") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we want to be in the business of trying to parse and maintain the syntax of nftables rules. I suggest trying to find a way to have the tools canonicalize both rules. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are other things that would make the rules not normalized and therefore not match like extra whitespaces. Here is a list according to copilot:
|
||
out = __salt__["cmd.run"](cmd, python_shell=False) | ||
found = re.search(search_rule, out) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We did not escape the search_rule before using it as a regex so regex special characters like |
||
|
||
if out == -1: | ||
if not found: | ||
ret["comment"] = ( | ||
"Rule {} in chain {} in table {} in family {} does not exist".format( | ||
rule, chain, table, family | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove
--numeric
? While I don't think multiple--numeric
args has any different effect, at least one does and is probably desired.