Skip to contentSkip to conversation

ipt_expire - expiring iptables rules

RFC PATCH In review Bryan Cardillo 3 participants 5 messages Jun 10, 2005 – Jun 13, 2005

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

RFC PATCH 1/1 ipt_expire - expiring iptables rules

I've written a new match module for automatically expiring rules. Basically, I want to be able to add a rule, and know it will eventually go away, without any additional work on my part. I know, I could write some scripts to track and expire rules from cron or something, but this seemed like more fun. Anyway, right now the module itself is pretty crude, so consider it a proof of concept. I'm curious, would others find this useful? Has this been done?

Cheers,
Bryan Cardillo

include/linux/netfilter_ipv4/ipt_expire.h +10 -0
diff -Nru a/include/linux/netfilter_ipv4/ipt_expire.h b/include/linux/netfilter_ipv4/ipt_expire.h
@@ -0,0 +1,10 @@
+#ifndef __IPT_EXPIRE_H
+#define __IPT_EXPIRE_H
+
+#include <linux/types.h>
+
+struct ipt_exp_info {
+	time_t expiration;
+};
+
+#endif
net/ipv4/netfilter/ipt_expire.c +476 -0

476 lines not on this page · raw message

net/ipv4/netfilter/Kconfig +11 -0
diff -Nru a/net/ipv4/netfilter/Kconfig b/net/ipv4/netfilter/Kconfig
@@ -342,6 +342,17 @@
 	  If you want to compile it as a module, say M here and read
 	  Documentation/modules.txt.  If unsure, say `N'.
 
+config IP_NF_MATCH_EXPIRE
+	tristate  'expiring match support'
+	depends on IP_NF_IPTABLES
+	help
+	  This option adds an expiring match, which allows you to add
+	  rules to your iptables ruleset which will later be removed
+          automatically.
+
+	  If you want to compile it as a module, say M here and read
+	  Documentation/modules.txt.  If unsure, say `N'.
+
 # `filter', generic and specific targets
 config IP_NF_FILTER
 	tristate "Packet filtering"
net/ipv4/netfilter/Makefile +1 -0
diff -Nru a/net/ipv4/netfilter/Makefile b/net/ipv4/netfilter/Makefile
@@ -67,6 +67,7 @@
 obj-$(CONFIG_IP_NF_MATCH_ADDRTYPE) += ipt_addrtype.o
 obj-$(CONFIG_IP_NF_MATCH_PHYSDEV) += ipt_physdev.o
 obj-$(CONFIG_IP_NF_MATCH_COMMENT) += ipt_comment.o
+obj-$(CONFIG_IP_NF_MATCH_EXPIRE) += ipt_expire.o
 
 # targets
 obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
extensions/libipt_expire.c +170 -0

170 lines not on this page · raw message

extensions/Makefile +1 -1
diff -Nru a/extensions/Makefile b/extensions/Makefile
@@ -5,7 +5,7 @@
 # header files are present in the include/linux directory of this iptables
 # package (HW)
 #
-PF_EXT_SLIB:=ah addrtype comment connlimit connmark conntrack dscp ecn esp hashlimit helper icmp iprange length limit mac mark multiport owner physdev pkttype realm rpc sctp standard state tcp tcpmss tos ttl udp unclean CLASSIFY CONNMARK DNAT DSCP ECN LOG MARK MASQUERADE MIRROR NETMAP NOTRACK REDIRECT REJECT SAME SNAT TARPIT TCPMSS TOS TRACE TTL ULOG
+PF_EXT_SLIB:=ah addrtype comment expire connlimit connmark conntrack dscp ecn esp hashlimit helper icmp iprange length limit mac mark multiport owner physdev pkttype realm rpc sctp standard state tcp tcpmss tos ttl udp unclean CLASSIFY CONNMARK DNAT DSCP ECN LOG MARK MASQUERADE MIRROR NETMAP NOTRACK REDIRECT REJECT SAME SNAT TARPIT TCPMSS TOS TRACE TTL ULOG
 PF6_EXT_SLIB:=eui64 hl icmpv6 length limit mac mark multiport owner physdev standard tcp udp HL LOG MARK TRACE
 
 # Optionals
#1 lore raw
Quoted 3 lines

crude, so consider it a proof of concept. I'm curious, would others find this useful? Has this been done?

Hm this sounds like a reverse implementation of ipt_recent.
I once wanted something like ipt_expire to add a DROP target on a specific IP when that IP does something "bad", and let it go away someday. However, ipt_recent would do almost the same afaics.

Jan Engelhardt

Signature · 2 lines
| Gesellschaft fuer Wissenschaftliche Datenverarbeitung Goettingen,
| Am Fassberg, 37077 Goettingen, www.gwdg.de
#2 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoting Jan Engelhardt on 2005-06-12 15:48 UTC:

Quoted 7 lines
Quoted 2 lines

crude, so consider it a proof of concept. I'm curious, would others find this useful? Has this been done?

Hm this sounds like a reverse implementation of ipt_recent.
I once wanted something like ipt_expire to add a DROP target on a specific IP when that IP does something "bad", and let it go away someday. However, ipt_recent would do almost the same afaics.

I think the difference here is you can let any rule expire.. For example one that matches tcp packets to port 22. It's more generic when it comes to the kind of rules it can expire but otoh it doesn't provide any rule creation mechanisms like ipt_recent does.

Bryan, this is a nice module, a friend of mine asked for this not too long ago.. keep up the good work :)

Quoted 2 lines

+/* This module matches until it expires, at which point the entire
+ * rule is deleted

I'm sure my friend is going to ask whether it would be possible for these rules to clean up by themselves (i.e. schedule some kernel timer at the time of expiry to remove the rule) instead of the next time they are hit? Or is that already done?

- --
- - xkr47
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFCrRIRxyF48ZTvn+4RAuGBAKC8Iud1z7wGIMbfeVcUmt+unjI5LACfSgKs wqs5Z+TKyea1Q7D0zMLileA=
=eImN
-----END PGP SIGNATURE-----

#3 lore raw
Quoted 9 lines · Jonas Berlin

Quoting Jan Engelhardt on 2005-06-12 15:48 UTC:

Quoted 7 lines
Quoted 2 lines

crude, so consider it a proof of concept. I'm curious, would others find this useful? Has this been done?

Hm this sounds like a reverse implementation of ipt_recent.
I once wanted something like ipt_expire to add a DROP target on a specific IP when that IP does something "bad", and let it go away someday. However, ipt_recent would do almost the same afaics.

Quoted 4 lines

I think the difference here is you can let any rule expire.. For example one that matches tcp packets to port 22. It's more generic when it comes to the kind of rules it can expire but otoh it doesn't provide any rule creation mechanisms like ipt_recent does.

exactly.

Quoted 2 lines

Bryan, this is a nice module, a friend of mine asked for this not too long ago.. keep up the good work :)

great, glad to know it will be of use, I'll keep fixing it up, and role it up for p-o-m soon.

Quoted 7 lines
Quoted 2 lines

+/* This module matches until it expires, at which point the entire
+ * rule is deleted

I'm sure my friend is going to ask whether it would be possible for these rules to clean up by themselves (i.e. schedule some kernel timer at the time of expiry to remove the rule) instead of the next time they are hit? Or is that already done?

this is exactly how it works now, basically a timer based, in-kernel version of `iptables -D ...'.

--Bryan

#4 lore raw
Quoted 3 lines

this is exactly how it works now, basically a timer based, in-kernel version of `iptables -D ...'.

Ok, I took a deeper logical comparison between ipt_expire and ipt_recent. Put it into pom, might be useful. After all, replacing a ton of ipt_recent matches by user-space triggered "iptables -A ... -m ipt_expire" might give me back some performance.

Though, with [already released] the upcoming version of my fw scripts, I will probably hardly need any of {recent,expire} anymore :(
Keep it in pom.

Jan Engelhardt

Signature · 2 lines
| Gesellschaft fuer Wissenschaftliche Datenverarbeitung Goettingen,
| Am Fassberg, 37077 Goettingen, www.gwdg.de