All of lore.kernel.org
 help / color / mirror / Atom feed
* One little problem I don't understand
@ 2006-08-09 20:14 Vultur Constantin
  2006-08-10  7:35 ` Martijn Lievaart
  0 siblings, 1 reply; 5+ messages in thread
From: Vultur Constantin @ 2006-08-09 20:14 UTC (permalink / raw)
  To: netfilter

Hi,

I have a little problem understanding the way iptables does the matching 
of packets.
The problem is like this:
I have an subnet A.B.C.D/X which I mark it with --set-mark 1:

$IPT -A fw-interfaces -i $INT_IF -s $INT_NET  -d A.B.C.D/X -m state 
--state NEW    -j ACCEPT
$IPT -t mangle -A PREROUTING -i $INT_IF -d A.B.C.D/X  -j MARK --set-mark 1

and I mark the connections to port 22 ( ssh ) with --set-mark 2

$IPT -A fw-interfaces -i $INT_IF -s $INT_NET  -p tcp --dport 22 -m state 
--state NEW    -j ACCEPT
$IPT -t mangle -A PREROUTING -i $INT_IF -p tcp --dport 22 -j MARK 
--set-mark 2   
 
fw-interfaces is used as a custom chain in FORWARD.

Now my problem is like this:
If I want to connect to ssh to one of the ip's from d A.B.C.D/X all my 
packets are set-marked with 2. The rule with d A.B.C.D/X   is above tho 
one with ssh.
Shouldn't the ssh connection to A.B.C.D/X  be marked with 1 ? If not 
what I am doing wrong.

Thanks,

-- 
Constantin Daniel VULTUR



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: One little problem I don't understand
  2006-08-09 20:14 One little problem I don't understand Vultur Constantin
@ 2006-08-10  7:35 ` Martijn Lievaart
  2006-08-10  7:55   ` Costi
  0 siblings, 1 reply; 5+ messages in thread
From: Martijn Lievaart @ 2006-08-10  7:35 UTC (permalink / raw)
  To: Vultur Constantin; +Cc: netfilter

Vultur Constantin wrote:

> Hi,
>
> I have a little problem understanding the way iptables does the 
> matching of packets.
> The problem is like this:
> I have an subnet A.B.C.D/X which I mark it with --set-mark 1:
>
> $IPT -A fw-interfaces -i $INT_IF -s $INT_NET  -d A.B.C.D/X -m state 
> --state NEW    -j ACCEPT
> $IPT -t mangle -A PREROUTING -i $INT_IF -d A.B.C.D/X  -j MARK 
> --set-mark 1
>
> and I mark the connections to port 22 ( ssh ) with --set-mark 2
>
> $IPT -A fw-interfaces -i $INT_IF -s $INT_NET  -p tcp --dport 22 -m 
> state --state NEW    -j ACCEPT
> $IPT -t mangle -A PREROUTING -i $INT_IF -p tcp --dport 22 -j MARK 
> --set-mark 2  
> fw-interfaces is used as a custom chain in FORWARD.
>
> Now my problem is like this:
> If I want to connect to ssh to one of the ip's from d A.B.C.D/X all my 
> packets are set-marked with 2. The rule with d A.B.C.D/X   is above 
> tho one with ssh.
> Shouldn't the ssh connection to A.B.C.D/X  be marked with 1 ? If not 
> what I am doing wrong.


It IS marked with 1, subsequently overwritten by 2 by the second rule.

HTH,
M4



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: One little problem I don't understand
  2006-08-10  7:35 ` Martijn Lievaart
@ 2006-08-10  7:55   ` Costi
  2006-08-10  8:20     ` Rob Sterenborg
  2006-08-10 12:13     ` Martijn Lievaart
  0 siblings, 2 replies; 5+ messages in thread
From: Costi @ 2006-08-10  7:55 UTC (permalink / raw)
  To: Martijn Lievaart; +Cc: netfilter

But still isn't iptables  *first rule wins* policy ? From what I know 
iptables runs with this policy?

Martijn Lievaart wrote:
> Vultur Constantin wrote:
>
>> Hi,
>>
>> I have a little problem understanding the way iptables does the 
>> matching of packets.
>> The problem is like this:
>> I have an subnet A.B.C.D/X which I mark it with --set-mark 1:
>>
>> $IPT -A fw-interfaces -i $INT_IF -s $INT_NET  -d A.B.C.D/X -m state 
>> --state NEW    -j ACCEPT
>> $IPT -t mangle -A PREROUTING -i $INT_IF -d A.B.C.D/X  -j MARK 
>> --set-mark 1
>>
>> and I mark the connections to port 22 ( ssh ) with --set-mark 2
>>
>> $IPT -A fw-interfaces -i $INT_IF -s $INT_NET  -p tcp --dport 22 -m 
>> state --state NEW    -j ACCEPT
>> $IPT -t mangle -A PREROUTING -i $INT_IF -p tcp --dport 22 -j MARK 
>> --set-mark 2  fw-interfaces is used as a custom chain in FORWARD.
>>
>> Now my problem is like this:
>> If I want to connect to ssh to one of the ip's from d A.B.C.D/X all 
>> my packets are set-marked with 2. The rule with d A.B.C.D/X   is 
>> above tho one with ssh.
>> Shouldn't the ssh connection to A.B.C.D/X  be marked with 1 ? If not 
>> what I am doing wrong.
>
>
> It IS marked with 1, subsequently overwritten by 2 by the second rule.
>
> HTH,
> M4
>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: One little problem I don't understand
  2006-08-10  7:55   ` Costi
@ 2006-08-10  8:20     ` Rob Sterenborg
  2006-08-10 12:13     ` Martijn Lievaart
  1 sibling, 0 replies; 5+ messages in thread
From: Rob Sterenborg @ 2006-08-10  8:20 UTC (permalink / raw)
  To: netfilter

On Thu, August 10, 2006 09:55, Costi wrote:
> But still isn't iptables  *first rule wins* policy ? From what I know
> iptables runs with this policy?

That depends on the target.
If the target is definitive (AFAIK these are: ACCEPT, DROP, REJECT) then
subsequent rules will not be processed. A MARK target is not definitive so
subsequent rules are processed.


Gr,
Rob




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: One little problem I don't understand
  2006-08-10  7:55   ` Costi
  2006-08-10  8:20     ` Rob Sterenborg
@ 2006-08-10 12:13     ` Martijn Lievaart
  1 sibling, 0 replies; 5+ messages in thread
From: Martijn Lievaart @ 2006-08-10 12:13 UTC (permalink / raw)
  To: Costi; +Cc: netfilter

Costi wrote:

[ Please don't top post! ]

>>>
>>> Now my problem is like this:
>>> If I want to connect to ssh to one of the ip's from d A.B.C.D/X all 
>>> my packets are set-marked with 2. The rule with d A.B.C.D/X   is 
>>> above tho one with ssh.
>>> Shouldn't the ssh connection to A.B.C.D/X  be marked with 1 ? If not 
>>> what I am doing wrong.
>>
>>
>>
>> It IS marked with 1, subsequently overwritten by 2 by the second rule.
>>

 > But still isn't iptables  *first rule wins* policy ? From what I know 
iptables runs with this policy?

No, first rule gets executed first. If that is a rule with a terminal 
target, the processing stops there. Otherwise processing continues with 
the next rule.

To get what you want, do this:

$IPT -t mangle -A PREROUTING -i $INT_IF -d A.B.C.D/X  -j  T1
$IPT -N T1
$IPT -A T1 -j MARK --set-mark 1
$IPT -A T1 -j ACCEPT
$IPT -t mangle -A PREROUTING -i $INT_IF -p tcp --dport 22 -j MARK 
--set-mark 2

HTH,
M4



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-08-10 12:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-09 20:14 One little problem I don't understand Vultur Constantin
2006-08-10  7:35 ` Martijn Lievaart
2006-08-10  7:55   ` Costi
2006-08-10  8:20     ` Rob Sterenborg
2006-08-10 12:13     ` Martijn Lievaart

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.