target for modifying conntrack timeout value
Subsystems (3)
Quoted 16 lines
-----Original Message-----
From: Richard [mailto:[email protected]]
Sent: Wednesday, December 08, 2004 3:48 PM
To: 'Pablo Neira'
Cc: '[email protected]'
Subject: RE: [NEW TARGET] target for modifying conntrack timeout valueQuoted 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...
Quoted 9 lines
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...
Just wonder if there is any update on this please...
Thanks,
Richard
Quoted 31 lines · Richard
Quoted 19 lines
-----Original Message-----
From: Richard [mailto:[email protected]]
Sent: Wednesday, December 08, 2004 3:48 PM
To: 'Pablo Neira'
Cc: '[email protected]'
Subject: RE: [NEW TARGET] target for modifying conntrack timeout valueQuoted 8 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...Quoted 11 lines
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...
Quoted 3 lines
Just wonder if there is any update on this please...
sorry, I'm busy as hell right now. But I'll go through it as soon as I find some spare time. Reviewing your target is still in my todo list. Please, be patient.
--
Pablo
Quoted 31 lines · Richard
Quoted 19 lines
-----Original Message-----
From: Richard [mailto:[email protected]]
Sent: Wednesday, December 08, 2004 3:48 PM
To: 'Pablo Neira'
Cc: '[email protected]'
Subject: RE: [NEW TARGET] target for modifying conntrack timeout valueQuoted 8 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...Quoted 11 lines
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...
Quoted 3 lines
Just wonder if there is any update on this please...
Some comments:
a) I think that you should implement this thing as a match instead of a target. Have a look at ipt_limit. It isn't actually matching anything but, for example, you could use it together with nat targets. A match gives you more flexibility.
b) About source code:
+ if (!is_confirmed(ct)) {
^^^remove this `if' condition. ip_ct_refresh worries about about this for you and makes the thing more simple.
c) In checkentry:
+ if (info->mode > IPT_CTEXPIRE_MAXMODE) {
+ printk(KERN_WARNING "CTEXPIRE: invalid or unknown Mode %u\n",
+ info->mode);
+ return 0;
+ }
+ [...]
+
+ if (info->expires * HZ < info->expires) {
+ /* if user specified value is too big, *HZ can overflow the counter + */ + printk(KERN_WARNING "CTEXPIRE: expire value too big, will overflow counter: %ld\n", info->expires); + return 0;
+ }
You should do those checkings in user space. Those error must be handle in iptables, not in kernel.
A minor aesthetic comment, a line must fit 80 columns, split longer lines in two.
--
Pablo
Quoted 6 lines
Some comments:
a) I think that you should implement this thing as a match instead of a target. Have a look at
ipt_limit. It isn't actually matching anything but, for example, you could use it together with nat targets. A match gives you more flexibility.
Not sure that I follow you. This target changes the conntrack expire timer. For example, the default timeout for udp stream is 180 seconds. If I want to make it 3600 for sip (udp 5060) traffic, I would do,
iptables -t mangle -A INPUT -p UDP --dport 5060 -j CTEXPIRE --ctexpire-set 3600
iptables -t mangle -A OUTPUT -p UDP --sport 5060 -j CTEXPIRE --ctexpire-set 3600
Quoted 6 lines
b) About source code:
+ if (!is_confirmed(ct)) { ^^^remove this `if' condition.
ip_ct_refreshworries about about this for you and makes the thing more simple.
In order to increase or decrease the expire value, we need to get the current expire value. If it is !is_confirmed, the ct->timeout value is the real expire value. Otherwise, it is jiffies + expire value. Is there a function to get this value without checking is_confirmed?
Quoted 19 lines
c) In checkentry:
(quoted diff) +2
-0+ if (info->mode > IPT_CTEXPIRE_MAXMODE) { + printk(KERN_WARNING "CTEXPIRE: invalid or unknown Mode%u\n",
(quoted diff) +7
-0+ info->mode); + return 0; + } + [...] + + if (info->expires * HZ < info->expires) { + /* if user specified value is too big, *HZ can overflowthe counter
(quoted diff) +2
-0+ */ + printk(KERN_WARNING "CTEXPIRE: expire value too big,will overflow counter: %ld\n",
info->expires);(quoted diff) +2
-0+ return 0; + }
Quoted 2 lines
You should do those checkings in user space. Those error must be handle in iptables, not in kernel.
It is already done in user space. It is probably redundant doing the same thing here. I will drop it.
Quoted 2 lines
A minor aesthetic comment, a line must fit 80 columns, split longer lines in two.
It will be changed.
Thanks for your comments. Looking forward to your next email.
Richard
Quoted 8 lines · Richard
Quoted 8 lines
Some comments:
a) I think that you should implement this thing as a match instead of a target. Have a look at
ipt_limit. It isn't actually matching anything but, for example, you could use it together with nat targets. A match gives you more flexibility.
Quoted 9 lines
Not sure that I follow you. This target changes the conntrack expire timer. For example, the default timeout for udp stream is 180 seconds. If I want to make it 3600 for sip (udp 5060) traffic, I would do,
iptables -t mangle -A INPUT -p UDP --dport 5060 -j CTEXPIRE --ctexpire-set 3600
iptables -t mangle -A OUTPUT -p UDP --sport 5060 -j CTEXPIRE --ctexpire-set 3600
An example of what I mean:
iptables -A OUTPUT -m ctexpire --ctexpire-set 3600 -j ACCEPT
BTW, why can you only use this target in mangle? I think that it's safe using it elsewhere, except by the `raw' table where you can not.
Quoted 8 lines
Quoted 8 lines
b) About source code:
+ if (!is_confirmed(ct)) { ^^^remove this `if' condition.
ip_ct_refreshworries about about this for you and makes the thing more simple.
Quoted 6 lines
In order to increase or decrease the expire value, we need to get the current expire value. If it is !is_confirmed, the
ct->timeoutvalue is the real expire value. Otherwise, it is jiffies + expire value. Is there a function to get this value without checkingis_confirmed?
you are right, you need that for increments and decrements, forget this comment.
Quoted 19 lines
Quoted 19 lines
c) In checkentry:
(quoted diff) +2
-0+ if (info->mode > IPT_CTEXPIRE_MAXMODE) { + printk(KERN_WARNING "CTEXPIRE: invalid or unknown Mode%u\n",
(quoted diff) +7
-0+ info->mode); + return 0; + } + [...] + + if (info->expires * HZ < info->expires) { + /* if user specified value is too big, *HZ can overflowthe counter
(quoted diff) +2
-0+ */ + printk(KERN_WARNING "CTEXPIRE: expire value too big,will overflow counter: %ld\n",
info->expires);(quoted diff) +2
-0+ return 0; + }
Quoted 8 lines
Quoted 4 lines
You should do those checkings in user space. Those error must be handle in iptables, not in kernel.
It is already done in user space. It is probably redundant doing the same thing here. I will drop it.
yes, it's redudant. Please, drop that.
--
Pablo
Quoted 11 lines
Quoted 8 lines
Quoted 4 lines
You should do those checkings in user space. Those error must be handle in iptables, not in kernel.
It is already done in user space. It is probably redundant doing the same thing here. I will drop it.
yes, it's redudant. Please, drop that.
I drop it and also implemented other suggestions. Here is the latest.
Thanks,
Richard
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
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
net/ipv4/netfilter/ipt_CTEXPIRE.c +133 -0
133 lines not on this page · raw message
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
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'.
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.
extensions/libipt_CTEXPIRE.c +196 -0
196 lines not on this page · raw message
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: iptables/extensions/.CTEXPIRE-test
___________________________________________________________________
Name: svn:executable
+ *
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
Hi Richard,
Quoted 3 lines · Richard
I drop it and also implemented other suggestions. Here is the latest.
I've converted your target to a match because that way we can use ctexpire together with NAT actions in the same rule. This was inspired by reading ipt_limit. I've done some minor cleanups and a checking to make sure that this match is never used in the raw table.
Would like to send to the list a version for patch-o-matic-ng? Then we could push it to the SVN repository.
--
Pablo
ipv4/netfilter/ipt_ctexpire.c new file +132 -0
@@ -0,0 +1,132 @@ +/* ctexpire modification match for IP tables +* (C) 2004 by Richard Zheng <[email protected]> +* +* 020105 -- converted to match. Pablo Neira Ayuso <[email protected]> +* +* Version: 1.1 +* +* This software is distributed under the terms of GNU GPL version 2 +*/ + +#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" ); + +static int +ipt_ctexpire_match (const struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +const void *matchinfo, +int offset, +int *hotdrop) +{ +const struct ipt_ctexpire_info *info = matchinfo; +unsigned long new_expires =0UL ; +enum ip_conntrack_info ctinfo; +struct ip_conntrack *ct =ip_conntrack_get (skb, &ctinfo); + +if (ct ==NULL ) +return 0 ; + +IP_NF_ASSERT (ct->timeout.data == (unsigned long )ct); + + new_expires = info->expires*HZ ; + +#ifdef EXTRADEBUG +DEBUGP (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 + +switch (info->mode) { +case IPT_CTEXPIRE_SET : +break ; +case IPT_CTEXPIRE_INC : +/* If not in hash table, timer will not be active yet */ +if (!is_confirmed (ct)) +/* TODO should we check if counter overflow? +* other kernel function didn't check this */ + new_expires += ct->timeout.expires; +else + new_expires += ct->timeout.expires - jiffies; +break ; +case IPT_CTEXPIRE_DEC : +/* If not in hash table, timer will not be active yet */ +if (!is_confirmed (ct)) { + new_expires = (ct->timeout.expires <= new_expires) ? +0 : (ct->timeout.expires - new_expires); + }else { + new_expires = + (ct->timeout.expires - jiffies <= new_expires) ? +0 : (ct->timeout.expires - jiffies - new_expires); + } +break ; +default : +/* Shouldn't happen */ +break ; + } + + +ip_ct_refresh_acct (ct,0 ,NULL , new_expires); + +#ifdef EXTRADEBUG +printk (KERN_WARNING +"ctexpire: enter = %ld/%ld, exit = %ld/%ld, diff = %ld\n" , + enter, enter-jiffies, ct->timeout.expires, + ct->timeout.expires-jiffies, ct->timeout.expires - enter); +#endif + +return 0 ; +} + +static int +ipt_ctexpire_checkentry (const char *tablename, +const struct ipt_ip *ip, +void *matchinfo, +unsigned int matchsize, +unsigned int hook_mask) +{ +if (matchsize !=IPT_ALIGN (sizeof (struct ipt_ctexpire_info ))) { +printk (KERN_WARNING "ctexpire: targinfosize %u != %Zu\n" , + matchsize, +IPT_ALIGN (sizeof (struct ipt_ctexpire_info ))); +return 0 ; + } + +if (strcmp (tablename,"raw" ) ==0 ) { +printk (KERN_WARNING "ctexpire can't be used in the raw' table" ); +return 0 ; + } + +return 1 ; +} + +static struct ipt_match ipt_ctexpire = { + .name ="ctexpire" , + .match = ipt_ctexpire_match, + .checkentry = ipt_ctexpire_checkentry, + .me =THIS_MODULE , +}; + +static int __init init (void ) +{ +return ipt_register_match (&ipt_ctexpire); +} + +static void __exit fini(void) +{ +ipt_unregister_match (&ipt_ctexpire); +} + +module_init (init); +module_exit (fini); +
linux/netfilter_ipv4/ipt_ctexpire.h new file +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/netfilter_ipv4/ipt_ctexpire.h +23 -0
@@ -0,0 +1,23 @@ +/* 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
libipt_ctexpire.c +199 -0
199 lines not on this page · raw message
Quoted 9 lines
I've converted your target to a match because that way we can use ctexpire together with NAT actions in the same rule. This was inspired by reading
ipt_limit. I've done some minor cleanups and a checking to make sure that this match is never used in the raw table.Would like to send to the list a version for patch-o-matic-ng? Then we could push it to the SVN repository.
Hi Pablo,
Thanks for the change and cleanups. Here is the version for pom. The only change I made is
+#if 0
+ ip_ct_refresh_acct(ct, 0, NULL, new_expires);
+#endif
+ ip_ct_refresh(ct, new_expires);
This is because I got unresolved symbol ip_ct_refresh_acct when loading the kernel module. I am using kernel version 2.4.25.
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 +3 -0
@@ -0,0 +1,3 @@ +obj-$(CONFIG_IP_NF_MATCH_STATE) += ipt_state.o +obj-$(CONFIG_IP_NF_MATCH_CTEXPIRE) += ipt_ctexpire.o +
linux/net/ipv4/netfilter/ipt_ctexpire.c +134 -0
134 lines not on this page · raw message
linux/net/ipv4/netfilter/Config.in.ladd +2 -0
@@ -0,0 +1,2 @@ + dep_tristate ' Connection state match support' CONFIG_IP_NF_MATCH_STATE $CONFIG_IP_NF_CONNTRACK $CONFIG_IP_NF_IPTABLES + dep_tristate ' ctexpire match support' CONFIG_IP_NF_MATCH_CTEXPIRE $CONFIG_IP_NF_IPTABLES
linux/Documentation/Configure.help.ladd +8 -0
@@ -0,0 +1,8 @@ +CONFIG_IP_NF_MATCH_STATE +ctexpire match support +CONFIG_IP_NF_MATCH_CTEXPIRE + This match allows you 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 +199 -0
199 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 +23 -0
@@ -0,0 +1,23 @@ +/* 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 +9 -0
@@ -0,0 +1,9 @@ +This adds an iptables ctexpire mtach, which enables the user +to set the expire value of a conntrack or to increment / decrement it by a +given value. + +Examples: + +# allow sip (udp 5060) streams to have 3600 second timeout +iptables -p udp -m udp --dport 5060 -m ctexpire --ctexpire-set 3600 -j ACCEPT +iptables -p udp -m udp --sport 5060 -m ctexpire --ctexpire-set 3600 -j ACCEPT
info +3 -0
@@ -0,0 +1,3 @@ +Author: Richard Zheng <[email protected]> +Status: Experiment +Repository: extra
Quoted 11 lines · Richard
The only change I made is
linux/net/ipv4/netfilter/ipt_ctexpire.c +4
-0+#if 0 +ip_ct_refresh_acct (ct,0 ,NULL , new_expires); +#endif +ip_ct_refresh (ct, new_expires);This is because I got unresolved symbol
ip_ct_refresh_acctwhen loading the kernel module. I am using kernel version 2.4.25.
I forgot to tell you, ip_ct_refresh was renamed to ip_ct_refresh_acct in 2.6.9. Ick, the API is kinda broken now :(. Since I work with lastest 2.6 bk snapshot, I needed to use the new name. I think that it would be nice if you add a comment in that section of code to explain why you did that?
--
Pablo
Quoted 20 lines
-----Original Message-----
From: Pablo Neira [mailto:[email protected]]
Sent: Sunday, January 02, 2005 3:15 AM
To: Richard
Cc: 'Netfilter Development Mailinglist'
Subject: Re: [NEW TARGET] target for modifying conntrack timeout valueQuoted 8 lines · Richard
The only change I made is
(quoted diff) +4
-0+#if 0 + ip_ct_refresh_acct(ct, 0, NULL, new_expires); +#endif + ip_ct_refresh(ct, new_expires);This is because I got unresolved symbol
ip_ct_refresh_acctwhen loadingthe
Quoted 9 lines
Quoted 3 lines
kernel module. I am using kernel version 2.4.25.
I forgot to tell you,
ip_ct_refreshwas renamed toip_ct_refresh_acctin 2.6.9. Ick, the API is kinda broken now :(. Since I work with lastest 2.6 bk snapshot, I needed to use the new name. I think that it would be nice if you add a comment in that section of code to explain why you did that?
ok, I changed the code to this,
+ /* To refresh the expire timer value of a conntrack,
+ * linux 2.6.9 kernel starts using ip_ct_refresh_acct(),
+ * while older ones use ip_ct_refresh()
+ */
+#ifdef ip_ct_refresh_acct
+ ip_ct_refresh_acct(ct, 0, NULL, new_expires);
+#else
+ ip_ct_refresh(ct, new_expires);
+#endif
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 +3 -0
@@ -0,0 +1,3 @@ +obj-$(CONFIG_IP_NF_MATCH_STATE) += ipt_state.o +obj-$(CONFIG_IP_NF_MATCH_CTEXPIRE) += ipt_ctexpire.o +
linux/net/ipv4/netfilter/ipt_ctexpire.c +139 -0
139 lines not on this page · raw message
linux/net/ipv4/netfilter/Config.in.ladd +2 -0
@@ -0,0 +1,2 @@ + dep_tristate ' Connection state match support' CONFIG_IP_NF_MATCH_STATE $CONFIG_IP_NF_CONNTRACK $CONFIG_IP_NF_IPTABLES + dep_tristate ' ctexpire match support' CONFIG_IP_NF_MATCH_CTEXPIRE $CONFIG_IP_NF_IPTABLES
linux/Documentation/Configure.help.ladd +8 -0
@@ -0,0 +1,8 @@ +CONFIG_IP_NF_MATCH_STATE +ctexpire match support +CONFIG_IP_NF_MATCH_CTEXPIRE + This match allows you 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 +199 -0
199 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 +23 -0
@@ -0,0 +1,23 @@ +/* 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 +9 -0
@@ -0,0 +1,9 @@ +This adds an iptables ctexpire mtach, which enables the user +to set the expire value of a conntrack or to increment / decrement it by a +given value. + +Examples: + +# allow sip (udp 5060) streams to have 3600 second timeout +iptables -p udp -m udp --dport 5060 -m ctexpire --ctexpire-set 3600 -j ACCEPT +iptables -p udp -m udp --sport 5060 -m ctexpire --ctexpire-set 3600 -j ACCEPT
info +3 -0
@@ -0,0 +1,3 @@ +Author: Richard Zheng <[email protected]> +Status: Experiment +Repository: extra
Quoted 7 lines
Quoted 6 lines
I forgot to tell you,
ip_ct_refreshwas renamed toip_ct_refresh_acctin 2.6.9. Ick, the API is kinda broken now :(. Since I work with lastest 2.6 bk snapshot, I needed to use the new name. I think that it would be nice if you add a comment in that section of code to explain why you did that?ok, I changed the code to this,
linux/net/ipv4/netfilter/ipt_ctexpire.c line 86
Quoted 9 lines
linux/net/ipv4/netfilter/ipt_ctexpire.c +9
-0+/* To refresh the expire timer value of a conntrack, +* linux 2.6.9 kernel starts using ip_ct_refresh_acct(), +* while older ones use ip_ct_refresh() +*/ +#ifdef ip_ct_refresh_acct +ip_ct_refresh_acct (ct,0 ,NULL , new_expires); +#else +ip_ct_refresh (ct, new_expires); +#endif
Did you actually verify this works?
I don't see ip_ct_refresh_acct defined as a macro, only a forward decl. Forward decls don't count because ifdef operates on the preprocessor level. You'll need another way to test (netfilter version, kernel version, etc.)
Signature · 2 lines
Old timer, n.:
One who remembers when charity was a virtue and not an organization.Quoted 14 lines
linux/net/ipv4/netfilter/ipt_ctexpire.c line 86
Quoted 11 lines
Quoted 1 line
ok, I changed the code to this,
linux/net/ipv4/netfilter/ipt_ctexpire.c +9
-0+/* To refresh the expire timer value of a conntrack, +* linux 2.6.9 kernel starts using ip_ct_refresh_acct(), +* while older ones use ip_ct_refresh() +*/ +#ifdef ip_ct_refresh_acct +ip_ct_refresh_acct (ct,0 ,NULL , new_expires); +#else +ip_ct_refresh (ct, new_expires); +#endif Did you actually verify this works?
Quoted 2 lines
I don't see
ip_ct_refresh_acctdefined as a macro, only a forward decl. Forward decls don't count because ifdef operates on the preprocessor
level.
Quoted 2 lines
You'll need another way to test (netfilter version, kernel version, etc.)
I tried the following and it worked on 2.4.25, so I assume that the above code works. And both versions compile without a problem.
#ifdef ip_ct_refresh
ip_ct_refresh(ct, new_expires);
#else
ip_ct_refresh_acct(ct, 0, NULL, new_expires);#endif
Richard
Quoted 5 lines
Did you actually verify this works?
I don't see
ip_ct_refresh_acctdefined as a macro, only a forward decl. Forward decls don't count because ifdef operates on the preprocessor
level.
Quoted 1 line
You'll need another way to test (netfilter version, kernel version, etc.)
Hi Tom,
Here is a new method verifying the kernel version.
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9)
+ ip_ct_refresh(ct, new_expires);
+#else
+ ip_ct_refresh_acct(ct, 0, NULL, new_expires);
+#endif
Thanks!
Richard
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
net/ipv4/netfilter/Makefile.ladd +3 -0
@@ -0,0 +1,3 @@ +obj-$(CONFIG_IP_NF_MATCH_STATE) += ipt_state.o +obj-$(CONFIG_IP_NF_MATCH_CTEXPIRE) += ipt_ctexpire.o +
net/ipv4/netfilter/ipt_ctexpire.c +140 -0
140 lines not on this page · raw message
net/ipv4/netfilter/Config.in.ladd +2 -0
@@ -0,0 +1,2 @@ + dep_tristate ' Connection state match support' CONFIG_IP_NF_MATCH_STATE $CONFIG_IP_NF_CONNTRACK $CONFIG_IP_NF_IPTABLES + dep_tristate ' ctexpire match support' CONFIG_IP_NF_MATCH_CTEXPIRE $CONFIG_IP_NF_IPTABLES
Documentation/Configure.help.ladd +8 -0
@@ -0,0 +1,8 @@ +CONFIG_IP_NF_MATCH_STATE +ctexpire match support +CONFIG_IP_NF_MATCH_CTEXPIRE + This match allows you 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'.
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.
extensions/libipt_ctexpire.c +199 -0
199 lines not on this page · raw message
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: iptables/extensions/.CTEXPIRE-test
___________________________________________________________________
Name: svn:executable
+ *
include/linux/netfilter_ipv4/ipt_ctexpire.h +23 -0
@@ -0,0 +1,23 @@ +/* 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 +9 -0
@@ -0,0 +1,9 @@ +This adds an iptables ctexpire mtach, which enables the user +to set the expire value of a conntrack or to increment / decrement it by a +given value. + +Examples: + +# allow sip (udp 5060) streams to have 3600 second timeout +iptables -p udp -m udp --dport 5060 -m ctexpire --ctexpire-set 3600 -j ACCEPT +iptables -p udp -m udp --sport 5060 -m ctexpire --ctexpire-set 3600 -j ACCEPT
info +3 -0
@@ -0,0 +1,3 @@ +Author: Richard Zheng <[email protected]> +Status: Experiment +Repository: extra