Skip to contentSkip to conversation

Limit module accept negation?

DISCUSSION Jorge Agrelo 2 participants 7 messages Jan 11, 2005 – Jan 14, 2005

lore
Share & tools
lore
#0 lore raw

Can I replace this two rules

iptables -A INPUT -p tcp --syn -m limit --limit 1/s --limit-burst 4 -j ACCEPT iptables -A INPUT -p tcp --syn -j DROP

For only this one? (Using negation)

iptables -A INPUT -p tcp --syn -m limit ! --limit 1/s --limit-burst 4 -j DROP

Thanks in advanced
**********************************
CTO: Eng. Jorge Agrelo O.
WEb: www.novadevices.com
E-Mail: [email protected]
Phone: (593-2) 225-7711 ext. 105
Av. Brasil N45-08 y Condor, Quito Ecuador
**********************************

#1 lore raw
Quoted 10 lines · Jorge Agrelo

Can I replace this two rules

iptables -A INPUT -p tcp --syn -m limit --limit 1/s --limit-burst 4 -j ACCEPT
iptables -A INPUT -p tcp --syn -j DROP

For only this one? (Using negation)

iptables -A INPUT -p tcp --syn -m limit ! --limit 1/s --limit-burst 4 -j DROP

Unfortunately, you can't without a bit of hacking. If it happens you would, just grab ipt_limit.c and search for:

/* We're underlimit */

Change the return codes so it returns 0 when 'underlimit', otherwise, 1. Am sorry if this is straigh, I am at work.
Note that this won't add '!' support but just doesn't match unless it bursts the limit.

By the way, do you want to limit as soon as you receive more than 1/s packet regardless of the source address?

Quoted 2 lines

Thanks in advanced

HTH,

Samuel

#2 lore raw

Hi Samuel

Yes, I want to limit (drop) as soon as we receive more than 1/s packet regardless of the source address?, Is there any other way to do that without using limit match with negation?

Regards

Quoted 33 lines · Samuel Jean
Quoted 10 lines · Jorge Agrelo

Can I replace this two rules

iptables -A INPUT -p tcp --syn -m limit --limit 1/s --limit-burst 4 -j ACCEPT
iptables -A INPUT -p tcp --syn -j DROP

For only this one? (Using negation)

iptables -A INPUT -p tcp --syn -m limit ! --limit 1/s --limit-burst 4 -j DROP

Unfortunately, you can't without a bit of hacking. If it happens you would, just grab ipt_limit.c and search for:

/* We're underlimit */

Change the return codes so it returns 0 when 'underlimit', otherwise, 1. Am sorry if this is straigh, I am at work.
Note that this won't add '!' support but just doesn't match unless it bursts the limit.

By the way, do you want to limit as soon as you receive more than 1/s packet regardless of the source address?

Quoted 2 lines

Thanks in advanced

HTH,

Samuel

#3 lore raw
Quoted 3 lines · Jorge Agrelo

Yes, I want to limit (drop) as soon as we receive more than 1/s packet regardless of the source address?, Is there any other way to do that without using limit match with negation?

AFAIK, there isn't.

Quoted 3 lines

Regards

The patch below is against ipt_limit.c from 2.6.10. It's *untested* but reflects what I told you. It's just an exemple of how you can make this module behaving the other way arround.

(NOTE: ipt_limit.c was written to avoid flooding -j LOG)

HTH,

Samuel

ipt_limit.c.orig renamed from ipt_limit.c +2 -2
@@ -82,11 +82,11 @@
 		/* We're not limited. */
 		r->credit -= r->cost;
 		spin_unlock_bh(&limit_lock);
-		return 0;
+		return 1;
 	}
 
        	spin_unlock_bh(&limit_lock);
-	return 1;
+	return 0;
 }
 
 /* Precision saver. */
#4 lore raw
Quoted 3 lines · Samuel Jean

The patch below is against ipt_limit.c from 2.6.10. It's *untested* but reflects what I told you. It's just an exemple of how you can make this module behaving the other way arround.

Doh! crapy patch. Attached good one. I hope.

ipt_limit.c renamed from ipt_limit.c.orig +2 -2
@@ -82,11 +82,11 @@
 		/* We're not limited. */
 		r->credit -= r->cost;
 		spin_unlock_bh(&limit_lock);
-		return 1;
+		return 0;
 	}
 
        	spin_unlock_bh(&limit_lock);
-	return 0;
+	return 1;
 }
 
 /* Precision saver. */
#5 lore raw

Thanks Samuel, after I apply the patch, How look like the rule with limit to drop packets flowing above 1p/s

Regards

Quoted 8 lines · Samuel Jean
Quoted 4 lines · Samuel Jean

The patch below is against ipt_limit.c from 2.6.10. It's *untested* but reflects what I told you. It's just an exemple of how you can make this module behaving the other way arround.

Doh! crapy patch. Attached good one. I hope.

#6 lore raw
Quoted 2 lines · Jorge Agrelo

Thanks Samuel, after I apply the patch, How look like the rule with limit to drop packets flowing above 1p/s

iptables -I INPUT -m limit --limit 1/s -j DROP

Let me know if that didn't work.

Quoted 1 line

Regards

Cheers,

Samuel