two negatived parameters
Hi,
I have a little question with two negatived parameters in one rule.
I create a rule, which should only match if source and destination are not the given. I think that it is easy and try the following rule:
iptables -A FORWARD -s ! host1 -d ! host2 -j ACCEPT
But with this rule pakets from host1 to host3 (or from host2 to host3) were not affected. It seems like the logical combination is OR and not AND unlike the not negatived rule.
I think that the rule is logical right. Is it a little bug or have I misunderstood something?
I used the version 1.2.11 with kernel 2.4.26.
Markus
Signature · 2 lines
NEU: Bis zu 10 GB Speicher für e-mails & Dateien! 1 GB bereits bei GMX FreeMail http://www.gmx.net/de/go/mail
Quoted 15 lines · On September 6, 2004 04:28 am, [email protected] wrote:
Hi,
I have a little question with two negatived parameters in one rule.
I create a rule, which should only match if source and destination are not the given. I think that it is easy and try the following rule:
iptables -A FORWARD -s ! host1 -d ! host2 -j ACCEPT
But with this rule pakets from host1 to host3 (or from host2 to host3) were not affected. It seems like the logical combination is OR and not AND unlike the not negatived rule.
I think that the rule is logical right. Is it a little bug or have I misunderstood something?
Quoted 3 lines
I used the version 1.2.11 with kernel 2.4.26.
Markus
I take it to mean that packets from host2 to host 3 were NOT accepted by this
rule? ... What do the counters for the rule say? ( iptables -L -n -v -x ).
What other rules exist that might affect said packets? -- I note the above is
an ADD. Could rules farther up the FORWARD chain have already accepted/denied the said packets?
FYI -- I just tested this by inserting a double negative rule in my firewall
iptables -I tcp_packets -p tcp -s ! {internal_lan} -d ! {internal lan ip} --dport 25 -j allowed
and sending myself an email from outside. The packet counter incremented
appropriately.
2.6.7 linux iptables 1.2.11 and now that rule is gone. Alistair
Quoted 6 lines · Le lun 06/09/2004 à 10:28, [email protected] a écrit :
I create a rule, which should only match if source and destination are not the given. I think that it is easy and try the following rule:
iptables -A FORWARD -s ! host1 -d ! host2 -j ACCEPT
But with this rule pakets from host1 to host3 (or from host2 to host3) were not affected. It seems like the logical combination is OR and not AND unlike the not negatived rule.
When you build a rule, all parameters are combined with an AND, and it's logical (to me) that it is style the case here. When you write :
iptables -A FORWARD -s host1 -d host2 -j ACCEPT
You say :
if packet is (from host1) AND (to host2) then ACCEPT
Now, if you negate a parameter, you only negate this one, not a couple of them. So you get :
if packet is (not from host1) AND (not to host2) then ACCEPT
Which can be translated as :
if packet is not (from host1 OR to host2) then ACCEPT
And it explains why your packets are not matched, as your test packet is from host1. So there's no bug (imho) ;)
But there's something about the second packet that should matche (host2 to host3). Can you confirm that this very packet does not match ? As Alistair, I did a similar test (iptables 1.2.11 on 2.6.5 kernel) on a double negative rule and it matched.
Signature · 2 lines
http://www.netexit.com/~sid/ PGP KeyID: 157E98EE FingerPrint: FA62226DA9E72FA8AECAA240008B480E157E98EE
Quoted 2 lines
Quoted 2 lines
Hi! I'm your friendly neighbourhood signature virus. Copy me to your signature file and help me spread!
Quoted 15 lines · On Mon, 2004-09-06 at 04:28, [email protected] wrote:
Hi,
I have a little question with two negatived parameters in one rule.
I create a rule, which should only match if source and destination are not the given. I think that it is easy and try the following rule:
iptables -A FORWARD -s ! host1 -d ! host2 -j ACCEPT
But with this rule pakets from host1 to host3 (or from host2 to host3) were not affected. It seems like the logical combination is OR and not AND unlike the not negatived rule.
I think that the rule is logical right. Is it a little bug or have I misunderstood something?
Quoted 3 lines
I used the version 1.2.11 with kernel 2.4.26.
Markus
a rule matches only when all the parameters are true. a packet from host1 does not match your example rule (it explicitly says "-s ! host1"), and this is how it should work. consider the non-negative example:
-A FORWARD -s host1 -d host2 -j ACCEPT
would you propose that a packet from host1 to host3 should match that rule? i don't think so...
in your example rule, as soon as the source is host1 or the destination is host2--the rule no longer matches.
-j
Signature · 1 line
Jason Opperisano <[email protected]>
Quoted 7 lines · [email protected] wrote:
Hi,
I have a little question with two negatived parameters in one rule.
I create a rule, which should only match if source and destination are not the given. I think that it is easy and try the following rule:
Quoted 7 lines
iptables -A FORWARD -s ! host1 -d ! host2 -j ACCEPT
But with this rule pakets from host1 to host3 (or from host2 to host3) were not affected. It seems like the logical combination is OR and not AND unlike the not negatived rule.
I think that the rule is logical right. Is it a little bug or have I misunderstood something?
If src is host1 and dst is host3 you get:
not true and not false = false and true = false
So the rule does not match, and packets from host1 to host3 will not be affected by it. Also, note that "not host1 and not host2" is logically the same thing as "not (host1 or host2)". Which was probably the reason why it looked like an or to you. Double negations in human languages do not always translate well into negations in computer languages.
Signature · 3 lines
Aleksandar Milivojevic <[email protected]> Pollard Banknote Limited Systems Administrator 1499 Buffalo Place Tel: (204) 474-2323 ext 276 Winnipeg, MB R3T 1L7
Quoted 10 lines · On Mon, 2004-09-06 at 04:28, [email protected] wrote:
I create a rule, which should only match if source and destination are not the given. I think that it is easy and try the following rule:
iptables -A FORWARD -s ! host1 -d ! host2 -j ACCEPT
But with this rule pakets from host1 to host3 (or from host2 to host3) were not affected. It seems like the logical combination is OR and not AND unlike the not negatived rule.
I think that the rule is logical right. Is it a little bug or have I misunderstood something?
not to beat this thread to death...but if your original intention was to ACCEPT any traffic not from host1 OR any traffic not to host2, try explicitly dropping the specific traffic, rather than trying to implicitly allow traffic as a negation:
iptables -A FORWARD -s host1 -j DROP
iptables -A FORWARD -d host2 -j DROP
iptables -A FORWARD -j ACCEPT
or--if your intention was to jump to a custom chain where the source is not host1 nor is the destination host2:
iptables -A FORWARD -s ! host1 -j custom
iptables -A custom -d host2 -j RETURN
# neither the source is host1,
# nor the dest is host2 at this point in the chain iptables -A custom [ ... ]
hope this helps you get towards your goal...
-j
Signature · 1 line
Jason Opperisano <[email protected]>