target for modifying conntrack timeout value
Hi,
I sent this out a few days ago and got no reply. Thought that I should put a more obvious subject. I wonder if someone can include this into svn.
Regards,
Richard
Quoted 3 lines · Richard
I sent this out a few days ago and got no reply. Thought that I should put a more obvious subject.
yes, now it's that obvious :)
Quoted 3 lines
I wonder if someone can include this into svn.
OK, please next time post the patch clear text instead of a gzip, it's easier to review.
In the meantime this is pushed to the SVN, we have to fix some problems. I just had a look at ipt_CTEXPIRE.c. Some comments:
linux/net/ipv4/netfilter/ipt_CTEXPIRE.c (revision 0) +24 -0
@@ -0,0 +1,176 @@ +/* CTEXPIRE modification target for IP tables + * (C) 2004 by Richard Zheng <[email protected]> + * + * Version: 1.0 + * + * This software is distributed under the terms of GNU GPL + */ + +#include <linux/module.h> +#include <linux/skbuff.h> +#include <linux/ip.h> +#include <net/checksum.h> + +#include <linux/netfilter_ipv4/ip_tables.h> +#include <linux/netfilter_ipv4/ipt_CTEXPIRE.h> +#include <linux/netfilter_ipv4/ip_conntrack.h> + +MODULE_AUTHOR("Richard Zheng <[email protected]>"); +MODULE_DESCRIPTION("IP tables CTEXPIRE modification module"); +MODULE_LICENSE("GPL"); + +#undef DEBUG + +DECLARE_RWLOCK(ip_conntrack_lock);
^^^
ouch, you can't do that.
+static unsigned int
+ipt_ctexpire_target(struct sk_buff **pskb,
+ unsigned int hooknum, + const struct net_device *in, + const struct net_device *out, + const void *targinfo, + void *userinfo)
+
+{
+ const struct ipt_CTEXPIRE_info *info = targinfo;
+#ifdef KERNEL_64_USERSPACE_32
+ unsigned long long new_expires;
+#else
+ unsigned long new_expires;
+#endif
^^^^^
that ifdef just makes sense in user space, remove it and leave it as "long".
+ enum ip_conntrack_info ctinfo;
+ struct ip_conntrack *ct = ip_conntrack_get((*pskb), &ctinfo);
+
+
+ IP_NF_ASSERT(ct->timeout.data == (unsigned long)ct);
check if ct == NULL. In that case return 0.
Invalid packets don't have a conntrack associated.
+ new_expires = info->expires*HZ;
+
+ if (new_expires < info->expires) {
+ /* if user specified value is too big, *HZ can overflow the counter
+ * since it is big enough, just use the new value without *HZ
+ */
+ new_expires = info->expires;
^^^
check this in user space
+ }
+
+ WRITE_LOCK(&ip_conntrack_lock);
+
+#ifdef DEBUG
+ printk(KERN_WARNING "CTEXPIRE: fired = %s, mode %d, value %ld\n",
+ !is_confirmed(ct) ? "no" : "yes", info->mode, info->expires);
+ unsigned long enter = ct->timeout.expires;
+#endif
+
+ /* If not in hash table, timer will not be active yet */
+ if (!is_confirmed(ct)) {
+ switch (info->mode) {
+ case IPT_CTEXPIRE_SET:
+ ct->timeout.expires = new_expires;
^^^Hm I thought that I told you to use ip_ct_refresh... you should. Your target will look smarter and you can forget about proper locking... which is now completely broken...
See your next email.
--
Pablo
Quoted 6 lines
+ ct->timeout.expires = new_expires; ^^^Hm I thought that I told you to use
ip_ct_refresh... you should. Your target will look smarter and you can forget about proper locking... which is now completely broken...
Hi Pablo,
Thanks for the comments. I made the modification and attached the latest copy. Now it uses ip_ct_refresh. The target first reads the existing expire value, then modify it. If there is something in between, the expire value might get changed. Even worse, the conntrack state might change. That's why I locked it first, then read and write, finally unlock. If it is broken, there is no difference anyway...
Regards,
Richard
linux/include/linux/netfilter_ipv4/ipt_CTEXPIRE.h +19 -0
@@ -0,0 +1,19 @@ +/* CTEXPIRE modification module for IP tables +* (C) 2004 by Richard Zheng <[email protected]> */ + +#ifndef _IPT_CTEXPIRE_H +#define _IPT_CTEXPIRE_H + +enum { +IPT_CTEXPIRE_SET =0 , +IPT_CTEXPIRE_INC , +IPT_CTEXPIRE_DEC +}; + +#define IPT_CTEXPIRE_MAXMODE IPT_CTEXPIRE_DEC + +struct ipt_CTEXPIRE_info { +u_int8_t mode; +unsigned long expires; +}; +#endif
linux/net/ipv4/netfilter/Makefile.ladd +2 -0
@@ -0,0 +1,2 @@ +obj-$(CONFIG_IP_NF_TARGET_LOG) += ipt_LOG.o +obj-$(CONFIG_IP_NF_TARGET_CTEXPIRE) += ipt_CTEXPIRE.o
linux/net/ipv4/netfilter/ipt_CTEXPIRE.c +164 -0
164 lines not on this page · raw message
linux/net/ipv4/netfilter/Config.in.ladd +2 -0
@@ -0,0 +1,2 @@ + dep_tristate ' LOG target support' CONFIG_IP_NF_TARGET_LOG $CONFIG_IP_NF_IPTABLES + dep_tristate ' CTEXPIRE target support' CONFIG_IP_NF_TARGET_CTEXPIRE $CONFIG_IP_NF_IPTABLES
linux/Documentation/Configure.help.ladd +9 -0
@@ -0,0 +1,9 @@ +CONFIG_IP_NF_TARGET_LOG +CTEXPIRE target support +CONFIG_IP_NF_TARGET_CTEXPIRE + This option adds a `CTEXPIRE' target, which enables the user to set + the conntrack expire value or increment / decrement it by a given + amount (in seconds). + + If you want to compile it as a module, say M here and read + Documentation/modules.txt. If unsure, say `N'.
iptables/extensions/libipt_CTEXPIRE.man +12 -0
@@ -0,0 +1,12 @@ +This is used to modify the conntrack expire field. The conntrack expire field determines +how much time left (in seconds) for the conntrack. The conntrack will be deleted or changed +to a new state when the expire field reachs 0. +.TP +.BI "--ctexpire-set " "value" +Set the conntrack expire value to `value' (in seconds). +.TP +.BI "--ctexpire-dec " "value" +Decrement the conntrack expire value `value' (in seconds), i.e. make it live shorter. +.TP +.BI "--ctexpire-inc " "value" +Increment the conntrack expire value `value' (in seconds), i.e. make it live longer.
iptables/extensions/libipt_CTEXPIRE.c +192 -0
192 lines not on this page · raw message
iptables/extensions/.CTEXPIRE-test +2 -0
@@ -0,0 +1,2 @@ +#! /bin/sh +[ -f $KERNEL_DIR/net/ipv4/netfilter/ipt_CTEXPIRE.c ] && echo CTEXPIRE
Property changes on: CTEXPIRE/iptables/extensions/.CTEXPIRE-test
___________________________________________________________________
Name: svn:executable
+ *
iptables/include/linux/netfilter_ipv4/ipt_CTEXPIRE.h +24 -0
@@ -0,0 +1,24 @@ +/* CTEXPIRE modification module for IP tables +* (C) 2004 by Richard Zheng <[email protected]> */ + +#ifndef _IPT_CTEXPIRE_H +#define _IPT_CTEXPIRE_H + +enum { +IPT_CTEXPIRE_SET =0 , +IPT_CTEXPIRE_INC , +IPT_CTEXPIRE_DEC +}; + +#define IPT_CTEXPIRE_MAXMODE IPT_CTEXPIRE_DEC + +struct ipt_CTEXPIRE_info { +u_int8_t mode; +#ifdef KERNEL_64_USERSPACE_32 +unsigned long long expires; +#else +unsigned long expires; +#endif + +}; +#endif
help +3 -0
@@ -0,0 +1,3 @@ +This adds an iptables CTEXPIRE manipulation target, which enables the user +to set the expire value of a conntrack or to increment / decrement it by a +given value.
info +3 -0
@@ -0,0 +1,3 @@ +Author: Richard Zheng <[email protected]> +Status: Expirement +Repository: extra