-
Notifications
You must be signed in to change notification settings - Fork 19
fix(netifyd): improvements #1700
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
26c93fe
fix(netifyd): accepting untracked traffic instead of queueing it
Tbaile 33173dd
perf(netifyd): updated the buffer size 10X
Tbaile 368b4d3
feat(netifyd): added exclusion toggle for firewall traffic
Tbaile 2d9c0db
refactor: using chain selector for all nft chains
Tbaile 24ccf33
using stderr to print warnings
Tbaile File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -34,10 +34,18 @@ | |||||
| } | ||||||
|
|
||||||
| # push input packets to userspace queues for DPI analysis | ||||||
| {%- if 'input' in firewall_chains %} | ||||||
| chain nfq_input { | ||||||
| type filter hook input priority filter + 10; policy accept; | ||||||
| iifname lo accept | ||||||
|
|
||||||
| # Skip untracked traffic | ||||||
| ct state untracked accept | ||||||
| {%- if 'output' not in firewall_chains %} | ||||||
| # Skip reply traffic for connections initiated by the firewall itself | ||||||
| # (e.g. DNS responses, monitoring ping replies) | ||||||
| ct direction reply accept | ||||||
| {%- endif %} | ||||||
| # Accept traffic matching bypass set | ||||||
| ip saddr @nfq_bypass_v4 accept | ||||||
| ip daddr @nfq_bypass_v4 accept | ||||||
|
|
@@ -50,11 +58,15 @@ | |||||
| # Traffic to queues 54-57 | ||||||
| queue flags bypass to 54-57 | ||||||
| } | ||||||
| {%- endif %} | ||||||
|
|
||||||
| # push forward packets to userspace queues for DPI analysis | ||||||
| {%- if 'forward' in firewall_chains %} | ||||||
| chain nfq_forward { | ||||||
| type filter hook forward priority filter + 10; policy accept; | ||||||
|
|
||||||
| # Skip untracked traffic | ||||||
| ct state untracked accept | ||||||
| # Accept traffic matching bypass set | ||||||
| ip saddr @nfq_bypass_v4 accept | ||||||
| ip daddr @nfq_bypass_v4 accept | ||||||
|
|
@@ -67,12 +79,16 @@ | |||||
| # Traffic to queues 50-53 | ||||||
| queue flags bypass to 50-53 | ||||||
| } | ||||||
| {%- endif %} | ||||||
|
|
||||||
| {%- if 'output' in firewall_chains %} | ||||||
| # push output packets to userspace queues for DPI analysis | ||||||
| chain nfq_output { | ||||||
| type filter hook output priority filter + 10; policy accept; | ||||||
| oifname lo accept | ||||||
|
|
||||||
| # Skip untracked traffic | ||||||
| ct state untracked accept | ||||||
| # Accept traffic matching bypass set | ||||||
| ip saddr @nfq_bypass_v4 accept | ||||||
| ip daddr @nfq_bypass_v4 accept | ||||||
|
|
@@ -85,6 +101,8 @@ | |||||
| # Traffic to queues 54-57 | ||||||
| queue flags bypass to 54-57 | ||||||
| } | ||||||
| {%- endif %} | ||||||
|
|
||||||
| } | ||||||
| """ | ||||||
|
|
||||||
|
|
@@ -125,11 +143,27 @@ def generate_nfq_table(): | |||||
| # Format elements with optional comments for nftables | ||||||
| v4_elements = _format_nft_elements(v4_raw) | ||||||
| v6_elements = _format_nft_elements(v6_raw) | ||||||
|
|
||||||
|
|
||||||
| # Read which nftables chains to add for DPI analysis. | ||||||
| # Valid values: 'input', 'output', 'forward'. | ||||||
| # Defaults to all three chains if the option is missing. | ||||||
| valid_chains = {'input', 'output', 'forward'} | ||||||
| raw_chains = e_uci.get('netifyd', 'config', 'firewall_traffic', dtype=str, list=True, default=list(valid_chains)) | ||||||
| firewall_chains = [] | ||||||
| for chain in raw_chains: | ||||||
| if chain in valid_chains: | ||||||
| firewall_chains.append(chain) | ||||||
| else: | ||||||
| print(f"Warning: invalid firewall_traffic value '{chain}', ignoring. Valid values: {sorted(valid_chains)}") | ||||||
|
Member
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. Maybe it's better to print to stderr?
Suggested change
|
||||||
| if not firewall_chains: | ||||||
| print("Warning: no valid firewall_traffic chains configured, defaulting to all chains.") | ||||||
|
Member
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. Maybe it's better to print to stderr?
Suggested change
|
||||||
| firewall_chains = list(valid_chains) | ||||||
|
|
||||||
| template = Environment(loader=BaseLoader()).from_string(NFQ_TABLE) | ||||||
| render = template.render( | ||||||
| v4_elements=v4_elements, | ||||||
| v6_elements=v6_elements, | ||||||
| firewall_chains=firewall_chains, | ||||||
| ) | ||||||
|
|
||||||
| # Apply nftables | ||||||
|
|
||||||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.