Skip to contentSkip to conversation

skip other iptables marking if packet is already marked

DISCUSSION Ming-Ching Tiew 4 participants 6 messages May 31, 2004

lore
Share & tools
lore
#0 lore raw

I have many iptables setmark commands, but as soon as there is one match, I would like to skip all the rest. How to do this.

-------not-working-not-mark-zero-is-not-accepted---------

iptables -t mangle -A PREROUTING ..... -j MARK --set-mark ..... iptables -t mangle -A PREROUTING -m MARK ! --mark 0 -j ACCEPT iptables -t mangle -A PREROUTING ..... -j MARK --set-mark ..... iptables -t mangle -A PREROUTING -m MARK ! --mark 0 -j ACCEPT iptables -t mangle -A PREROUTING ..... -j MARK --set-mark .....

--------------------end-----------------------------------

Since it is not working, I change it to :-

Assuming I have AND-ed all the mark together to obtain the MASK,

iptables -t mangle -A PREROUTING ..... -j MARK --set-mark ..... iptables -t mangle -A PREROUTING -m MARK ! --mark MASK/MARK -j ACCEPT iptables -t mangle -A PREROUTING ..... -j MARK --set-mark ..... iptables -t mangle -A PREROUTING -m MARK ! --mark MASK/MARK -j ACCEPT iptables -t mangle -A PREROUTING ..... -j MARK --set-mark .....

Wonder if it will work ?
My next question is should I use -j ACCEPT or -j RETURN ?

#1 lore raw
Quoted 10 lines · Ming-Ching Tiew

I have many iptables setmark commands, but as soon
as there is one match, I would like to skip all the rest. How to do this. -------not-working-not-mark-zero-is-not-accepted--------- iptables -t mangle -A PREROUTING ..... -j MARK --set-mark ..... iptables -t mangle -A PREROUTING -m MARK ! --mark 0 -j ACCEPT iptables -t mangle -A PREROUTING ..... -j MARK --set-mark ..... iptables -t mangle -A PREROUTING -m MARK ! --mark 0 -j ACCEPT iptables -t mangle -A PREROUTING ..... -j MARK --set-mark ..... --------------------end-----------------------------------

Why don't you just match the mark the packet has been given ?

iptables -t mangle -A PREROUTING ..... -j MARK --set-mark 1 iptables -t mangle -A PREROUTING -m MARK --mark 1 -j ACCEPT iptables -t mangle -A PREROUTING ..... -j MARK --set-mark 2 iptables -t mangle -A PREROUTING -m MARK --mark 2 -j ACCEPT [...]

I think your ruleset does not work because a packet without a mark will match your non-zero mark rule. I mean that no mark is different than 0, so all packets will match the first "-m mark ! --mark 0" rule.

iptables -t mangle -A PREROUTING -j MARK --set-mark 0 iptables -t mangle -A PREROUTING ..... -j MARK --set-mark ..... iptables -t mangle -A PREROUTING -m MARK ! --mark 0 -j ACCEPT iptables -t mangle -A PREROUTING ..... -j MARK --set-mark ..... iptables -t mangle -A PREROUTING -m MARK ! --mark 0 -j ACCEPT [...]

Quoted 2 lines

Since it is not working, I change it to :-
Assuming I have AND-ed all the mark together to obtain the MASK,

[...]

Quoted 1 line

Wonder if it will work ?

Well, it should work.

Quoted 1 line

My next question is should I use -j ACCEPT or -j RETURN ?

RETURN should not be use within builtin chains. Moreover, both have the same effect if used in builtin chain.

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!

#2 lore raw
Quoted 8 lines

Why don't you just match the mark the packet has been given ?

iptables -t mangle -A PREROUTING ..... -j MARK --set-mark 1 iptables -t mangle -A PREROUTING -m MARK --mark 1 -j ACCEPT iptables -t mangle -A PREROUTING ..... -j MARK --set-mark 2 iptables -t mangle -A PREROUTING -m MARK --mark 2 -j ACCEPT

Understand, but what if I have something on top :-

iptables -t mangle -A PREROUTING -j CONNMARK --restore-mark

I don't know what is the mark value, but i want to return as soon as the mark has been restored.

Quoted 5 lines

I think your ruleset does not work because a packet without a mark will match your non-zero mark rule. I mean that no mark is different than 0, so all packets will match the first "-m mark ! --mark 0" rule.

No, it does not work because the syntax is rejected ! I tried with "-m mark --mark ! 0" , it is alway rejected.

Quoted 6 lines
Quoted 2 lines

My next question is should I use -j ACCEPT or -j RETURN ?

RETURN should not be use within builtin chains. Moreover, both have the same effect if used in builtin chain.

Point taken.

Thanks.

#3 lore raw
In reply to Cedric Blancher
Quoted 3 lines · Cedric Blancher

I think your ruleset does not work because a packet without a mark will match your non-zero mark rule. I mean that no mark is different than 0, so all packets will match the first "-m mark ! --mark 0" rule.

Really? No mark and mark 0 are different?

How do you distinguish an unmarked packet in a ruleset?

I ask because this relates to an as yet unanswered question of mine, with Subject "CONNMARK restore-mark creates conntrack entry?"

Ciao,
Sheldon.

#4 lore raw
Quoted 1 line · Sheldon Hearn

Really? No mark and mark 0 are different?

Well, I though. I just check and I was wrong. Sorry, my fault.

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!

#5 lore raw
Quoted 3 lines · Cedric Blancher
Quoted 1 line

Really? No mark and mark 0 are different?

Well, I though. I just check and I was wrong. Sorry, my fault.

No worries; it gave me an opportunity to promote the "CONNMARK restore-mark creates conntrack entry?" thread, on which I'm pretty desperate for feedback.

Oops, I did it again! Britney Spears would be proud. ;-)

Ciao,
Sheldon.