Skip to contentSkip to conversation

REJECT target

DISCUSSION Peteris Krumins 1 participant 3 messages Apr 10, 2003 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

Hello netfilter,

Holy christ, i relied i could REJECT packets in any table, but unfortunately after launching the program i was working on i got ugly 'iptables: Invalid argument' after executing iptables -A PREROUTING -t mangle .. -j REJECT

why cant i put -j REJECT in the PREROUTING chain of mangle table?

Manual says it makes no sense, but it makes sense for me.

I mark certain packets (-j MARK) in the mangle table, and those which are not marked should be REJECTed.
The only way, i think, i can solve it is using FORWARD and INPUT chains of the filter table. Match any not marked packets in these chains and REJECT from there. But this adds some extra time (packet has to traverse other chain) and i have to duplicate the rules (because of putting on both INPUT and FORWARD).

Is there a patch or smth to this problem, or it cant be done (REJECT in mangle)?

P.Krumins

A message that is not in the archive (sent off-list or not yet received): 008701c2ff97$9d98b310$3201a8c0@ESTACAO

#2 lore raw

Hello Leonardo,

Thursday, April 10, 2003, 10:30:07 PM, you wrote:

LRM> Use DROP instead of REJECT .... you can only REJECT in filter tables.
LRM> nat and mangle tables can only DROP packets ....

There are certain cases i want to REJECT --reject-with tcp-reset, or --reject-with icmp-port-unreachable.

So from what you are saying, REJECT is impossible in not filter table? (or is it just not implemented?)

P.Krumins

A message that is not in the archive (sent off-list or not yet received): 003d01c2ffb2$42c91090$3201a8c0@ESTACAO

#4 lore raw

Friday, April 11, 2003, 1:41:00 AM, you wrote:

LRM> Well, what i've read and studied is that mangle and nat table should NOT
LRM> be used for filtering stuff. If you wanna really REJECT something based in a LRM> mangle MARK, you can safelly do that in the INPUT/OUTPUT/FORWARD tables.

yes, i have read the same. but i still havent found out why cant i use nat and mangle tables for filtering.

LRM> Seems that you cannot reject and send something in the mangle and nat
LRM> tables. You can only DROP a packet, that means, dissapear with it. No LRM> notification of any kind can be sent from nat or mangle.

Why is it so?

LRM> You told you need something that was MARKed in MANGLE to be rejected.
LRM> What exactly are we talking ? Is this a routed packet that will reach LRM> another machine ? If yes, is it leaving or is it arriving in your network ? LRM> If no ( packet is for the machine ), is it arriving or leaving the machine ? LRM> Can you send me some iptables rules so I can help you ?

I queue some packets which arrive into my machine to userspace, the userspace tool looks at the MARK value of a packet and does something accoring to it.

(is there another way to mark (make a distinguishable mark) a packet as soon as it enters the machine? I could change TOS as it enters and make it 0 as it leaves machine, but this is uneffective method)

The packets can be either arriving for that machine or for a network and also packets only arrive to the machine (machine does not send any itself).

here are some rules i just made (similat to those i use, but simplified and commented):

--
alias i='iptables'
i -A PREROUTING -t mangle ..something.. -j MARK --set-mark 1 -i eth0 ..
.. N more rules all with -j MARK
..
i -A PREROUTING -m <my custom match which matches only marked packets> -m limit --limit 3/minute --limit-burst 2 -j QUEUE

# my userspace tool examines NF_MARK and NF_ACCEPTs the packet so it
# continues traversing the PREROUTING chain.

now here i want to REJECT the packet with tcp-reset if it's -p tcp or icmp-port-unreachable if it's -p udp but not simply DROP it. --

as i mentioned the only way i found out to REJECT them is add a 2 rules in INPUT -t filter and FORWARD -t filter (which would match if packet is marked with my match), but this is inconvenient
because of 2 reasons - packet still has to travel from mangle to nat then to filter and only then it gets dropped (adds latency) and i have to duplicate the rules as i dont know if the packet will be destinated for my machine or for network behind the machine.

P.Krumins