Hello!
I need an advice why the firewall rules which set marks are not working as expected and how to fix/change them. I have two rules: the first one is marking traffic with 0x1 value, the second one is marking traffic with 0x2 value. They both can be applied to the same packet and I expect the firewall to match the first rule, apply the mark and do not process the second rule. But it seems that the second rule is also processed and as a result I don't know what mark do I get, but surely not the mark I need.
Some more details.
I have an nft set which then is filled by dnsmasq
with two host IPs (ifconfig.io and myip.com):
/etc/config/firewall - nft set
config ipset
option name 'no_vpn'
option family 'ipv4'
list match 'dest_net'
I also have two routing rules which redirects traffic either to the wan
or to the wg_out
interface:
/etc/config/network - routing rules
config rule
option priority '100'
option mark '0x1'
option lookup 'main'
config rule
option priority '110'
option mark '0x2'
option lookup 'wg_out_table'
And I have two firewall rules to mark the traffic:
/etc/config/firewall - traffic rules
config rule
option name 'Mark 0x1 ipconfig.io myip.com'
option family 'ipv4'
option src 'lan'
option ipset 'no_vpn'
option target 'MARK'
option dest '*'
list proto 'all'
option set_mark '0x1'
config rule
option name 'Mark 0x2 all other'
option family 'ipv4'
option src 'lan'
option dest '*'
option target 'MARK'
option set_mark '0x2'
list proto 'all'
Please note that I still have main
and default
routing tables which route traffic through wan
.
The logic behind this is:
- Mark traffic to the specific hosts (ifconfig.io, myip.com) with
0x1
and route them throughwan
. - Mark all other traffic with
0x2
and route it throughwg_out
.
Unfortunately if I go to ifconfig.io or myip.com I will see the wg_out
IP address.
But If I rearrange these two rules and change their order (set mark 0x2
first and 0x1
second) then it works as it should. But I expect the opposite behavior.
I.e. I expect the firewall to match the first rule (before rearranging), mark traffic with 0x1
and stop processing (or at least do not process the second rule).
I am confused and do not understand what is happening. I will be happy if you help me sort it out.