Skip to content
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

fw4 assumes ether_addr sets are ipv4 only #16

Open
f00b4r0 opened this issue Nov 17, 2023 · 4 comments · May be fixed by #35
Open

fw4 assumes ether_addr sets are ipv4 only #16

f00b4r0 opened this issue Nov 17, 2023 · 4 comments · May be fixed by #35

Comments

@f00b4r0
Copy link

f00b4r0 commented Nov 17, 2023

Given the following uci configuration:

	add firewall rule
	set firewall.@rule[-1].name='Forward-auth-captive'
	set firewall.@rule[-1].src="captivezone"
	set firewall.@rule[-1].dest='wan'
	set firewall.@rule[-1].proto='any'
	set firewall.@rule[-1].target='ACCEPT'
	set firewall.@rule[-1].ipset='captive'
 
	add firewall ipset
	set firewall.@ipset[-1].name='captive'
	add_list firewall.@ipset[-1].match='src_mac'

firewall4 produces the following rules:

table inet fw4 {
	set captive {
		type ether_addr
		elements = { }
        }

[...]

	chain forward_captivezone {
		meta nfproto ipv4 ether saddr @captive counter packets 111598 bytes 30867442 jump accept_to_wan comment "!fw4: Forward-auth-captive"

The meta nfproto ipv4 match is unwarranted as the relative set is address agnostic.

@brada4
Copy link

brada4 commented Dec 19, 2023

To emit expected rule - change:

first line of /usr/share/firewall4/templates/rule.uc
-{%+ if (rule.family && !rule.has_addrs): -%}
+{%+ if (rule.family && !rule.has_addrs && length(rule.smacs_pos)!=null ): -%}

@jow- may explain why plain !rule.smacs_pos does not work in this line but works perfectly 30 lines later.
this may spread more where lenght() of an dynamic array is numeric zero vs null
same treatment has to be applied to nftporto agnostic smacs_neg and maybe port list.

@brada4
Copy link

brada4 commented Feb 28, 2024

@f00b4r0 any success editing file?

@f00b4r0
Copy link
Author

f00b4r0 commented Mar 11, 2024

@brada4 afaict the change does work, the rule is changed to:

	chain forward_captive {
		ether saddr @captive counter packets 14 bytes 1652 jump accept_to_wan comment "!fw4: Forward-auth-captive"

However I can't say for sure whether or not this breaks anything else.

@brada4
Copy link

brada4 commented Mar 11, 2024

It does not break anything else, just removes proto specifier in exact reported case.
I will make PR out of this, not dwelling into other similar situations I grepped.
EDIT: my easy idea breaks rules with multiple filters

zsien added a commit to zsien/firewall4 that referenced this issue Jul 27, 2024
zsien added a commit to zsien/firewall4 that referenced this issue Jul 27, 2024
When filtering by MAC address, it is usually necessary to
filter both IPv4 and IPv6.
If it is not allowed to set the family of ipset to any,
it will be necessary to create a separate, identical ipset
for both IPv4 and IPv6.

Fixes: openwrt#16
@zsien zsien linked a pull request Jul 27, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants