Rules order randomly changes
-
@w0w Thank you. Try with this patch:
diff --git a/src/etc/inc/pfsense-utils.inc b/src/etc/inc/pfsense-utils.inc index 5095c9ff0f..23cdbdf295 100644 --- a/src/etc/inc/pfsense-utils.inc +++ b/src/etc/inc/pfsense-utils.inc @@ -3088,18 +3088,33 @@ function filter_rules_sort() { config_set_path('filter/rule', $rules); } function filter_rules_compare($a, $b) { - if ((isset($a['floating']) && isset($b['floating'])) || - (isset($b['ethernet']) && isset($b['ethernet']))) { - return $a['seq'] - $b['seq']; - } else if (isset($a['floating']) || isset($a['ethernet'])) { - return -1; - } else if (isset($b['floating']) || isset($b['ethernet'])) { + if (isset($a['ethernet'])) { + // Ethernet rules always come first. + if (!isset($b['ethernet'])) { + return -1; + } + } elseif (isset($a['floating'])) { + // Floating rules are placed after Ethernet rules and before Interface rules. + if (isset($b['ethernet'])) { + return 1; + } elseif (!isset($b['floating'])) { + return -1; + } + } elseif (isset($b['ethernet']) || isset($b['floating'])) { + // Interface rules are placed after Ethernet and Floating rules. return 1; - } else if ($a['interface'] == $b['interface']) { - return $a['seq'] - $b['seq']; - } else { + } elseif ($a['interface'] != $b['interface']) { + // Interface rules for the same interface are grouped together. return compare_interface_friendly_names($a['interface'], $b['interface']); } + + // Use the sequence number as a last resort. + if (isset($a['seq']) && isset($b['seq'])) { + return ($a['seq'] <=> $b['seq']); + } + + // Nothing to compare. + return 0; } function generate_ipv6_from_mac($mac) {If testing on 24.11, apply this one after first applying the latest recommended System patches. If testing on 25.03-BETA, first apply
c181ebe180017116626da28f30407a1da3cba061and the previous one, then this one. -
@marcosm said in Rules order randomly changes:
At first glance, everything seems to be working, but we won't rush. I'll test it for some more time.
-
P patient0 referenced this topic on
-
This is still happening on pfsense 2.8.1-RELEASE rules can get rearranged after saving.
-
@aGeekhere the mentioned patches should definitely be in 2.8.1. Please provide more details and how to reproduce it, if possible.
-
@patient0 Here are the things that i did to cause it,
- Use separators
- Move rules around and save
- Using pfBlockerNG rules, moving them to the bottom
It could be working then i reboot and it can switch around
-
@aGeekhere what have you set in pfBlockerNG / IP > Firewall 'Auto' Rule Order ?
-
-
@aGeekhere I was hoping to get to a "give a man a fish, teach a man to fish" situation, but I failed.
If you press the blue 'i' thingy it will explain what that setting does.
The setting you have, means pfBlocker rules at the top, all other rules after that. And that's why they are moved back to the top.
You read:
https://docs.netgate.com/pfsense/en/latest/packages/pfblocker.html#faq"pfBlocker always moves its rules to the top, how can I stop this?:"
-
@patient0 said in Rules order randomly changes:
@aGeekhere I was hoping to get to a "give a man a fish, teach a man to fish" situation, but I failed.
If you press the blue 'i' thingy it will explain what that setting does.
The setting you have, means pfBlocker rules at the top, all other rules after that. And that's why they are moved back to the top.
You read:
https://docs.netgate.com/pfsense/en/latest/packages/pfblocker.html#faq"pfBlocker always moves its rules to the top, how can I stop this?:"
I never liked the fact pfBlockerNG does rules injection/sorting, so I deliberately do not use it. The only way I have found out to “avoid it” is by not letting it create any rules at all:
In the “inbound/outbound firewall rules” just above the sorting selector, make sure you have no interfaces selected.
In the auto rules sorting selector there is NO “do not mess with my rules”, so I had to resort to not let it create any rules.Afterwards make sure you set all your IP blocking lists to generate “aliases” instead. Essentially that will generate aliases in the FIREWALL -> ALIASES -> URLs section that you can then use in your created firewall rules as needed - and placed where you like.
MUCH MUCH better way of doing firewalling even though it does take a little longer to create the basic block/allow countries this way.
-
@keyser Thank you i now understand what is happening
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register LoginPrivacy Policy · Cookie Policy
