Linux Netfilter discussions
 help / color / mirror / Atom feed
From: Radek Kanovsky <rk@dat.cz>
To: netfilter@vger.kernel.org
Subject: iptables rules in comparable form
Date: Tue, 1 Jun 2010 10:10:53 +0200	[thread overview]
Message-ID: <20100601081053.GA13943@q.uh.cz> (raw)

Hello,

is there some way to get iptables rules in some normalized form?
What I mean is normalized or canonical form that is convenient
for rule comparison. For example following rules are internaly
equivalent although writen differently and I not aware of any
utility that could told me that they are the same:

    iptables -A SSH -s 1.2.3.4 -p tcp --dport ssh
    iptables -A SSH -s 1.2.3.4/32 -p tcp --dport ssh
    iptables -A SSH -s w1.something.com -p tcp --dport ssh
    iptables -A SSH -s w1.something.com -p tcp --dport 22
    iptables -A SSH -s w1.something.com/32 -p tcp -m tcp --dport 22
    iptables -A SSH -s 1.2.3.4 -d 0.0.0.0/0 -p tcp -m tcp --dport 22

When I want update rules on firewall or router with thousands of rules
I want to do it incrementaly. Reloading whole iptables on small change
every ten minutes is not acceptable because it takes very long time
and resets counters defined for accounting purposes. But incremental
solution requires some comparable rule form so machine can decide
which rule already exists, which is new and which should be deleted.

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 am not sure if I go right way because this concept is a bit fragile.
Iptables can have plugins not known to this script, every host can
have different /etc/services, /etc/protocols used by ipatables, there
are bugs in iptables stdout, etc. How would you solve this?

Regards

Radek Kanovsky

             reply	other threads:[~2010-06-01  8:10 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-01  8:10 Radek Kanovsky [this message]
2010-06-01  8:50 ` iptables rules in comparable form Jan Engelhardt
2010-06-01  9:18   ` Mart Frauenlob
2010-06-01 11:25     ` Radek Kanovsky
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=20100601081053.GA13943@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox