Unix Technical Forum

Re: time-based pf rules in crontab do not survive a reboot (naturally)?

This is a discussion on Re: time-based pf rules in crontab do not survive a reboot (naturally)? within the lucky.openbsd.misc forums, part of the OpenBSD category; --> Thanks jared and others for your replies. I'll try all of your suggestions. However, if you agree with me, ...


Go Back   Unix Technical Forum > Unix Operating Systems > OpenBSD > lucky.openbsd.misc

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-18-2008, 05:46 AM
Soner Tari
 
Posts: n/a
Default Re: time-based pf rules in crontab do not survive a reboot (naturally)?

Thanks jared and others for your replies. I'll try all of your
suggestions.

However, if you agree with me, I get the feeling that all of these are
inelegant workarounds compared to the ideal solution: time support in pf
(similar to perhaps iptables). I've read the replies from developers to
a similar question a few months back, and they were not interested in
adding such support in pf. I am sure there are other priorities for
them, and it's totally OK with me.

But time rules are important for me, so ultimately I'd like to achieve
the correct solution, if I can (which is the OpenBSD way after all).
Therefore, I am even willing to play with the pf source code to add time
support just for packet filtering rules. I am sure, if it were so easy,
we would probably have it by now. So, before I attempt it myself, do you
guys think it is too difficult?

Or perhaps, the developers have changed their minds, and there is
already some development effort to add such support. May I ask if that's
the case, hopefully?

Thanks,

On Sat, 2006-07-15 at 15:36 -0400, jared r r spiegel wrote:
> On Sat, Jul 15, 2006 at 08:27:32PM +0300, Soner Tari wrote:
> > > Have your cron job copy the current anchor rules to pf-current.conf,
> > > then add pfctl -f pf-current.conf to rc.local.

> >
> > Thank you for the reply (and Gaby too). But I am not sure if this would
> > be an elegant workaround. Because by chance there may be cron jobs
> > scheduled to run exactly during downtime, and I would miss them. This is
> > still true no matter how small the chances are.

>
> well, since rc.local is sourced right before the 'standard daemons:'
> echo in /etc/rc, which is itself above when cron is started, it may
> be entirely feasible to use rc.local for this.
>
> perhaps create a system by which you somehow drop a file into somewhere
> in var which describes what time-based anchor/ruleset you're using - you
> could populate that file either upon each instance of it changing via
> cron, or also in /etc/rc.shutdown (or both).
>
> then in rc.local, have it look for that file, if it finds it, it will
> load the appropriate pf ruleset pertaining to whatever time period the
> file indicates the host was in when it last updated that file.
>
> i don't know if this will inspire or help at all, but here is what i use
> to make some of my pf tables persist through reboots. basically it
> tries to save/populate any table which i have named without an initial
> underscore -- if i have tables i don't want to persist through reboots,
> my convention is to name them with an initial underscore:
>
> -[rc.shutdown]--------
> TABLE_STATE_DIR=/var/db/pftablestate
> if [ -w "${TABLE_STATE_DIR}" ] && [ -d "${TABLE_STATE_DIR}" ]; then
> echo "writing contents of pf tables:"
> for table in $(pfctl -sT); {
> # don't keep state for tables starting
> # with an underscore
> if [[ "${table}" = _* ]]; then
> continue
> # only be concerned with nonempty tables
> elif [ $(pfctl -t "${table}" -Ts | wc -l) -gt 0 ]; then
> echo -n "\t${table} "
> pfctl -t "${table}" -Ts > "${TABLE_STATE_DIR}/${table}"
> fi
> };
> unset table
> echo "done."
> fi
> unset TABLE_STATE_DIR
> ----------------------
>
> -[rc.local]-----------
> TABLE_STATE_DIR=/var/db/pftablestate
> if [ -w "${TABLE_STATE_DIR}" ] && [ -d "${TABLE_STATE_DIR}" ]; then
> echo "restoring contents of pf tables:"
> for table in $(pfctl -sT); {
> # don't keep state for tables starting
> # with an underscore
> if [[ "${table}" = _* ]]; then
> continue
> # only be concerned with nonempty tables
> elif [ -r "${TABLE_STATE_DIR}/${table}" ] && \
> [ $(wc -l < "${TABLE_STATE_DIR}/${table}") -gt 0 ]; then
> echo -n "\t${table} "
> pfctl -t "${table}" -Ta $(<"${TABLE_STATE_DIR}/${table}") && \
> rm -- "${TABLE_STATE_DIR}/${table}"
> fi
> };
> unset table
> echo "done."
> fi
> unset TABLE_STATE_DIR
> ----------------------


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:08 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com