From: Radek Kanovsky <rk@dat.cz>
To: netfilter@vger.kernel.org
Subject: Re: iptables rules in comparable form
Date: Tue, 1 Jun 2010 13:25:52 +0200 [thread overview]
Message-ID: <20100601112552.GA15745@q.uh.cz> (raw)
In-Reply-To: <4C04D07F.6040702@chello.at>
On Tue, Jun 01, 2010 at 11:18:55AM +0200, Mart Frauenlob wrote:
> Besides there's also iptables-xml (not sure when it came up), which can
> give you a unified output. Reading man iptables-xml the way back is
> possible like:
> Conversion from XML to iptables-save format may be done using the
> iptables.xslt script and xsltproc, or a custom program using libxsltproc
> or similar; in this fashion:
>
> xsltproc iptables.xslt my-iptables.xml | iptables-restore
>
> >>
> >> I have prototype in python that does such normalization and is able
> >> to output "patch" for existing rules according to given new rules.
> >> Script generates -N/-X/-F/-P/-I/-D/-A rules via standard python difflib
> >> and is pretty effective and simle (90 lines) but requires rules in
> >> comparable form and this is the harder part of my problem (2662 lines).
>
> I bet python has loads of xml libs.
I should clarify some facts about my conditions.
Whole iptables ruleset is represented by few files in /etc. Some of them
are generated, some of them are hand written. I am able to feed /etc
rules to iptables-restore or execute them as shell script. This is
trivial. Although iptables-restore is faster than executing iptables in
shell script, it is still very slow sometimes. Changes in /etc ruleset
are small but frequent. But primarily both solutions reset couters if
used and it is not good for me now. So I ended with script that does
incremental updates.
My script takes iptables-save output as first argument and desired
ruleset declared in /etc files as second argument (but generally any two
inputs). In first step it converts both inputs to comparable form and
builds ruleset in internal representation. Then comes iptables_diff
method, that is able to generate two rules
iptables -D SSH 10
iptables -I SSH 10 -j REJECT -s 2.3.2.3
if rule 10 in chain SSH differs in first and second ruleset. It mostly
works but it needs constant maintenance because of changes in iptables
itself so I am not satisfied. I believe that it works as I intended
because this utility dramaticaly lower reload times of firewalls on our
busy routers. As I said, changes are small. Restoring 10000 rules via
iptables-restore is often more slow than my python processing and
executing two iptables commands.
I know iptables-xml. It is mostly wrapper around iptables-save output.
It doesn't help much, because it doesnt convert '--dport ssh'
to '--dport 22' during processing /etc/ files. First form I have
in /etc (readability of hand written files should be preserved),
second form I get from kernel via iptables-save. How can I compare them?
I hope that it is more clear now.
Thanks
Radek Kanovsky
next prev parent reply other threads:[~2010-06-01 11:25 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-01 8:10 iptables rules in comparable form Radek Kanovsky
2010-06-01 8:50 ` Jan Engelhardt
2010-06-01 9:18 ` Mart Frauenlob
2010-06-01 11:25 ` Radek Kanovsky [this message]
2010-06-01 11:56 ` Jan Engelhardt
2010-06-01 16:03 ` Radek Kanovsky
2010-06-01 18:19 ` Jan Engelhardt
2010-06-01 18:35 ` Radek Kanovsky
2010-06-01 18:01 ` Radek Kanovsky
2010-06-01 18:26 ` Jan Engelhardt
2010-06-01 19:36 ` Radek Kanovsky
2010-06-01 20:29 ` Pieter Smit
2010-06-02 6:17 ` Radek Kanovsky
2010-06-01 13:27 ` Mart Frauenlob
2010-06-01 16:47 ` Radek Kanovsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100601112552.GA15745@q.uh.cz \
--to=rk@dat.cz \
--cc=netfilter@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.