Increase Schedule Based FW Rules To 5 Minute Intervalls
G'day mates ;-)
I have to make schedule based firewall rules to be more fine granular, e.g. down to 5 minutes intervals for a customer of mine.
I see the backend already allows me to set timeranges such as 01:23-13:37.
I think the job that calls the packet filter rules update only runs every X (15?) minutes, so there is currently some precision lost. Not sure how the mechanism works, this is me guessing.
So I'd highly appreciate if you could point me in the right direction, maybe also briefly describe how the underlying mechanism works and which components are involved.
Thank you and best regards,
afaik the rules are immediately put on place,
the problem is if you still have active state at, for example, 13:37 , they are still valid and not killed so you need to kill the states for that rule if you want it to be immediately effective
so only new states are blocked at 13:37 but the old one that are still active and valid are not blocked until they expire
Well, I there must be a mechanism that puts the rules in place or removes them according to the schedule. Because they are either visible in:
pfctl -s all
or they get completely removed when inactive.
Maybe just adding your own cronjod for
/etc/rc.filter_configure_syncwith whatever intervals you need would be simplest.
Assuming you are setting the time ranges manually.
Well, in the end this was super simple. There is also a cron section in $config and it's pretty straight forward, e.g.:
pfSense shell: print_r($config[cron]); ...  => Array ( [minute] => 0,5,10,15,20,25,30,35,40,45,50,55 [hour] => * [mday] => * [month] => * [wday] => * [who] => root [command] => /etc/rc.filter_configure_sync ) ...
and the schedule
print_r($config[schedules]); ... Array ( [schedule] => Array (  => Array ( [name] => AccesTimes [descr] => AccesTimesDesc [timerange] => Array (  => Array ( [position] => 1,2,3,4,5 [hour] => 7:50-9:15 [rangedescr] => )  => Array ( [position] => 1,2,3,4,5 [hour] => 9:40-11:05 [rangedescr] => )  => Array ( [position] => 1,2,3,4,5 [hour] => 11:25-12:50 [rangedescr] => )  => Array ( [position] => 1,2,3,4,5 [hour] => 12:55-15:15 [rangedescr] => )  => Array ( [position] => 1,2,3,4,5 [hour] => 15:30-16:55 [rangedescr] => ) ) [schedlabel] => 5dd4268dea560 )
I must have been blind not to see that in the first place :p
You probably only need that to run at minute 15 and minute 50 which might save some unnecessary churn.
Unless you plan to add more rules.
Small update I want to share here for reference. It happened, that the cron job 7 got reset to run only at the default times 0,15,30,45. So my next try is, to add an additional job (8) which covers the missing times:
$config[cron][item] = ; $config[cron][item][minute] = "5,10,20,25,35,40,50,55"; $config[cron][item][hour] = "*"; $config[cron][item][mday] = "*"; $config[cron][item][month] = "*"; $config[cron][item][wday] = "*"; $config[cron][item][who] = "root"; $config[cron][item][command] = "/etc/rc.filter_configure_sync"; write_config(); exec;
heper last edited by
@ErnestoRey perhaps you could use the 'cron' package instead of manually editting the config?