Skip to contentSkip to conversation

NETFILTER: add support for invert condition (!) in ipt_limit

PATCH New Marco Innocenti 1 participant 1 message Oct 17, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NETFILTER: add support for invert condition (!) in ipt_limit

Add support for invert condition (!) in ipt_limit.

---
Hi, this is my first patch and I hope I followed the guideline. The patch change the kernel and iptables. Should I have sent two mail?

include/linux/netfilter_ipv4/ipt_limit.h +1 -0
diff -uprN linux-2.6.13.4/include/linux/netfilter_ipv4/ipt_limit.h linux-2.6.13.4.mio/include/linux/netfilter_ipv4/ipt_limit.h
@@ -9,6 +9,7 @@
 struct ipt_rateinfo {
 	u_int32_t avg;    /* Average secs between packets * scale */
 	u_int32_t burst;  /* Period multiplier for upper limit. */
+	u_int8_t invert;
 
 	/* Used internally by the kernel */
 	unsigned long prev;
net/ipv4/netfilter/ipt_limit.c +2 -2
diff -uprN linux-2.6.13.4/net/ipv4/netfilter/ipt_limit.c linux-2.6.13.4.mio/net/ipv4/netfilter/ipt_limit.c
@@ -82,11 +82,11 @@ ipt_limit_match(const struct sk_buff *sk
 		/* We're not limited. */
 		r->credit -= r->cost;
 		spin_unlock_bh(&limit_lock);
-		return 1;
+		return 1 ^ r->invert;
 	}
 
        	spin_unlock_bh(&limit_lock);
-	return 0;
+	return 0 ^ r->invert;
 }
 
 /* Precision saver. */

+diff -upNr iptables-1.3.3/extensions/libipt_limit.c iptables-1.3.3.mio/extensions/libipt_limit.c

extensions/libipt_limit.c +4 -3
@@ -23,7 +23,7 @@ help(void)
 {
 	printf(
 "limit v%s options:\n"
-"--limit avg			max average match rate: default "IPT_LIMIT_AVG"\n"
+"[!] --limit avg			max average match rate: default "IPT_LIMIT_AVG"\n"
 "                                [Packets per second unless followed by \n"
 "                                /sec /minute /hour /day postfixes]\n"
 "--limit-burst number		number to match in a burst, default %u\n"
@@ -121,8 +121,7 @@ parse(int c, char **argv, int invert, un
 	}
 
 	if (invert)
-		exit_error(PARAMETER_PROBLEM,
-			   "limit does not support invert");
+		r->invert = 1;
 
 	return 1;
 }
@@ -161,6 +160,8 @@ print(const struct ipt_ip *ip,
       int numeric)
 {
 	struct ipt_rateinfo *r = (struct ipt_rateinfo *)match->data;
+	if (r->invert)
+		printf("! ");
 	printf("limit: avg "); print_rate(r->avg);
 	printf("burst %u ", r->burst);
 }
include/linux/netfilter_ipv4/ipt_limit.h +1 -0
diff -upNr iptables-1.3.3/include/linux/netfilter_ipv4/ipt_limit.h iptables-1.3.3.mio/include/linux/netfilter_ipv4/ipt_limit.h
@@ -9,6 +9,7 @@
 struct ipt_rateinfo {
 	u_int32_t avg;    /* Average secs between packets * scale */
 	u_int32_t burst;  /* Period multiplier for upper limit. */
+	u_int8_t invert;
 
 #ifdef KERNEL_64_USERSPACE_32
 	u_int64_t prev;
Signature · 2 lines
Ciao
     Marco Innocenti