Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@nicholasmhughes
Copy link
Collaborator

What does this PR do?

See issue for details

What issues does this PR fix or reference?

Fixes #67078

Previous Behavior

See issue for details

New Behavior

The braces are effectively ignored for comparison purposes

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

Yes

Please review Salt's Contributing Guide for best practices, including the
PR Guidelines.

See GitHub's page on GPG signing for more information about signing commits with GPG.

@nicholasmhughes nicholasmhughes requested a review from a team as a code owner November 29, 2024 20:52
Copy link
Contributor

@dmurphy18 dmurphy18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use f-strings at this point.
Can you email [email protected] to discuss salt extensions too, since this PR has your attention and reaching out to you has failed so far.

BTW pipelines are under development, so it will be a while before they are running correctly, hopefully by the end of the week,

)
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}"
Copy link
Contributor

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.

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(" }", " ?}?")
Copy link
Contributor

Choose a reason for hiding this comment

The 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. nft also has a --json flag to give json output which may also be cleaner/safer to handle.

Copy link
Contributor

Choose a reason for hiding this comment

The 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:

Whitespace: Variations in spaces or tabs can impact rule formatting, although it generally doesn’t affect functionality.

Comments: Inline or separate comments within rules might not be present in the canonical form.

Ordering: The sequence of rules and attributes can differ.

Default actions: When default actions aren’t explicitly stated, different interpretations may arise.

Aliases: Using aliases for set names or interfaces may introduce variations.

Optional attributes: Omitting certain attributes might create differences.

Nesting: The manner and extent of nesting in expressions might vary.

Copy link
Contributor

@bdrx312 bdrx312 Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of trying to normalize and and check the rule yourself, maybe we could use the --check flag with nft.

cmd = f"{_nftables_cmd()} --handle list chain {nft_family} {table} {chain}"
search_rule = f"{rule} #".replace("{ ", "{? ?").replace(" }", " ?}?")
out = __salt__["cmd.run"](cmd, python_shell=False)
found = re.search(search_rule, out)
Copy link
Contributor

Choose a reason for hiding this comment

The 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 . and [ will not be treated as literal.

@dwoz dwoz force-pushed the fix-nftables-brace-handling branch from 3654ccf to 9f888fb Compare February 5, 2025 09:38
@twangboy
Copy link
Contributor

@nicholasmhughes Could you address the comments from @bdrx312?

@twangboy twangboy added the test:full Run the full test suite label Jul 1, 2025
Copy link
Contributor

@twangboy twangboy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make this PR against the 3006.x branch as it is a bugfix there.

@twangboy twangboy added this to the Sulfur v3006.14 milestone Jul 1, 2025
@twangboy twangboy added pending-changes The pull request needs additional changes before it can be merged needs-rebase Needs to be rebased, against either the current branch or a different one labels Jul 9, 2025
@twangboy twangboy force-pushed the fix-nftables-brace-handling branch from 9f888fb to 365708c Compare August 28, 2025 14:34
@twangboy twangboy changed the base branch from master to 3006.x August 28, 2025 14:36
@twangboy
Copy link
Contributor

twangboy commented Oct 2, 2025

@nicholasmhughes It looks like tests are passing. Could you address the comments from @bdrx312 ?

@twangboy
Copy link
Contributor

twangboy commented Oct 6, 2025

@nicholasmhughes Thanks for rebasing. Could you address @bdrx312 questions?

@dwoz
Copy link
Contributor

dwoz commented Oct 13, 2025

@nicholasmhughes ping. Looking to see if this can land in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] nftables module check function doesn't understand that braces are optional

5 participants