Skip to contentSkip to conversation

Introducing Bidirectional conntrack mark

PATCH In review Jesse Peng 4 participants 6 messages Sep 7, 2005 – Oct 13, 2005

Subsystems (2)
lore
Share & tools
lore

Jesse Peng

author
#0 lore raw

PATCH 1/1 Introducing Bidirectional conntrack mark

Greetings all,
This patch fully derive from Henrik Nordstrom's long known connmark patch but is extended to bidirectional solution. The solution once discussed as the following link:
https://lists.netfilter.org/pipermail/netfilter-devel/2005-March/018784.html

Dear Henrik:
Feel free to give any advice for the work extending your existing famous connmark patch.

Dear Jian:
I got approved for quite a period,but sorry for this late posting this patch after a busy season.Hope this help!

Cheers
Jesse
-------------- next part --------------

include/linux/netfilter_ipv4/ipt_ctdirmark.h Wed Sep 7 15:23:40 2005 renamed from include/linux/netfilter_ipv4/ipt_ctdirmark.h Wed Sep 7 16:12:33 2005 +16 -0
diff -Nru a/include/linux/netfilter_ipv4/ipt_ctdirmark.h b/include/linux/netfilter_ipv4/ipt_ctdirmark.h
@@ -0,0 +1,16 @@
+#ifndef _IPT_CTDIRMARK_H
+#define _IPT_CTDIRMARK_H
+
+#define IPT_CTDIRMARK_ORIGINAL         0x01
+#define IPT_CTDIRMARK_REPLY            0x02
+
+#include <linux/netfilter_ipv4/ip_conntrack_tuple.h>
+
+struct ipt_ctdirmark_info {
+        u_int8_t bitmask;
+       unsigned long mark[IP_CT_DIR_MAX], mask[IP_CT_DIR_MAX];
+       u_int8_t invert;
+};
+
+#endif /*_IPT_CTDIRMARK_H*/
+

diff -Nru a/net/ipv4/netfilter/Config.in b/net/ipv4/n etfilter/Config.in

net/ipv4/netfilter/Config.in Wed Sep 7 16:00:31 2005 renamed from net/ipv4/netfilter/Config.in Wed Jan 19 22:10:13 2005 +4 -0
@@ -7,6 +7,7 @@
 tristate 'Connection tracking (required for masq/NAT)' CONFIG_IP_NF_CONNTRACK
 if [ "$CONFIG_IP_NF_CONNTRACK" != "n" ]; then
   dep_tristate '  FTP protocol support' CONFIG_IP_NF_FTP $CONFIG_IP_NF_CONNTRACK
+  bool '  Bidirectional connection mark tracking support' CONFIG_IP_NF_CTDIRMARK
   dep_tristate '  Amanda protocol support' CONFIG_IP_NF_AMANDA $CONFIG_IP_NF_CONNTRACK
   dep_tristate '  TFTP protocol support' CONFIG_IP_NF_TFTP $CONFIG_IP_NF_CONNTRACK
   dep_tristate '  IRC protocol support' CONFIG_IP_NF_IRC $CONFIG_IP_NF_CONNTRACK
@@ -38,6 +39,9 @@
   fi
   if [ "$CONFIG_IP_NF_CONNTRACK" != "n" ]; then
     dep_tristate '  Connection state match support' CONFIG_IP_NF_MATCH_STATE $CONFIG_IP_NF_CONNTRACK $CONFIG_IP_NF_IPTABLES
+    if [ "$CONFIG_IP_NF_CTDIRMARK" != "n" ]; then
+      dep_tristate '  Bidirectional Connection mark match support' CONFIG_IP_NF_MATCH_CTDIRMARK $CONFIG_IP_NF_IPTABLES
+    fi
     dep_tristate '  Connection tracking match support' CONFIG_IP_NF_MATCH_CONNTRACK $CONFIG_IP_NF_CONNTRACK $CONFIG_IP_NF_IP

TABLES
fi
if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
@@ -105,6 +109,9 @@
dep_tristate ' MARK target support' CONFIG_IP_NF_TARGET_MARK $CONFIG_IP_NF_MANGLE
fi
dep_tristate ' LOG target support' CONFIG_IP_NF_TARGET_LOG $CONFIG_IP_NF_IPTABLES
+ if [ "$CONFIG_IP_NF_CTDIRMARK" != "n" ]; then
+ dep_tristate ' Bidirectional Connection mark target support' CONFIG_IP_NF_TARGET_CTDIRMARK $CONFIG_IP_NF_IPTABLES
+ fi
dep_tristate ' ULOG target support' CONFIG_IP_NF_TARGET_ULOG $CONFIG_IP_NF_IPTABLES dep_tristate ' TCPMSS target support' CONFIG_IP_NF_TARGET_TCPMSS $CONFIG_IP_NF_IPTABLES
fi
diff -Nru a/net/ipv4/netfilter/Makefile b/net/ipv4/ne
tfilter/Makefile

net/ipv4/netfilter/Makefile Wed Sep 7 16:24:52 2005 renamed from net/ipv4/netfilter/Makefile Mon Aug 25 19:44:44 2003 +2 -0
@@ -83,6 +83,7 @@
 
 obj-$(CONFIG_IP_NF_MATCH_TTL) += ipt_ttl.o
 obj-$(CONFIG_IP_NF_MATCH_STATE) += ipt_state.o
+obj-$(CONFIG_IP_NF_MATCH_CTDIRMARK) += ipt_ctdirmark.o
 obj-$(CONFIG_IP_NF_MATCH_CONNTRACK) += ipt_conntrack.o
 obj-$(CONFIG_IP_NF_MATCH_UNCLEAN) += ipt_unclean.o
 obj-$(CONFIG_IP_NF_MATCH_TCPMSS) += ipt_tcpmss.o
@@ -98,6 +99,7 @@
 obj-$(CONFIG_IP_NF_TARGET_REDIRECT) += ipt_REDIRECT.o
 obj-$(CONFIG_IP_NF_NAT_SNMP_BASIC) += ip_nat_snmp_basic.o
 obj-$(CONFIG_IP_NF_TARGET_LOG) += ipt_LOG.o
+obj-$(CONFIG_IP_NF_TARGET_CTDIRMARK) += ipt_CTDIRMARK.o
 obj-$(CONFIG_IP_NF_TARGET_ULOG) += ipt_ULOG.o
 obj-$(CONFIG_IP_NF_TARGET_TCPMSS) += ipt_TCPMSS.o
net/ipv4/netfilter/ipt_ctdirmark.c Wed Sep 7 15:24:48 2005 renamed from net/ipv4/netfilter/ipt_ctdirmark.c Wed Sep 7 16:27:49 2005 +30 -0
diff -Nru a/net/ipv4/netfilter/ipt_ctdirmark.c b/net/ipv4/netfilter/ipt_ctdirmark.c
@@ -0,0 +1,64 @@
+/* Kernel module to match bidirectional connection mark values. */
+#define __KERNEL__
+#define MODULE
+#define MATCH   1
+#define NOMATCH 0
+
+#include <linux/module.h>
+#include <linux/skbuff.h>
+
+#include <linux/netfilter_ipv4/ip_tables.h>
+#include <linux/netfilter_ipv4/ip_conntrack.h>
+#include "ipt_ctdirmark.h"
+
+static int
+match(const struct sk_buff *skb,
+      const struct net_device *in,
+      const struct net_device *out,
+      const void *matchinfo,
+      int offset,
+      const void *hdr,
+      u_int16_t datalen,
+      int *hotdrop)
+{
+       const struct ipt_ctdirmark_info *info = matchinfo;
+       enum ip_conntrack_info ctinfo;
+       struct ip_conntrack *ct = ip_conntrack_get((struct sk_buff *)skb, &ctinfo);
+       if (!ct)
+           return 0;
+        if ((info->bitmask & IPT_CTDIRMARK_ORIGINAL &&
+           (!((ct->mark_dir[IP_CT_DIR_ORIGINAL] & info->mask[IP_CT_DIR_ORIGINAL]) == info->mark[IP_CT_DIR_ORIGINAL]) ^ !!(in

fo->invert & IPT_CTDIRMARK_ORIGINAL))) ||
+ (info->bitmask & IPT_CTDIRMARK_REPLY &&
+ (!((ct->mark_dir[IP_CT_DIR_REPLY] & info->mask[IP_CT_DIR_REPLY]) == info->mark[IP_CT_DIR_REPLY]) ^ !!(info->inver
t & IPT_CTDIRMARK_REPLY))))
+ return NOMATCH;
+ return MATCH;
+}
+
+static int
+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_ctdirmark_info)))
+ return 0;
+
+ return 1;
+}
+
+static struct ipt_match ctdirmark_match
+= { { NULL, NULL }, "ctdirmark", &match, &checkentry, NULL, THIS_MODULE }; +
+static int __init init(void)
+{
+ return ipt_register_match(&ctdirmark_match);
+}
+
+static void __exit fini(void)
+{
+ ipt_unregister_match(&ctdirmark_match);
+}
+
+module_init(init);
+module_exit(fini);

net/ipv4/netfilter/ipt_CTDIRMARK.c Wed Sep 7 15:25:19 2005 renamed from net/ipv4/netfilter/ipt_CTDIRMARK.c Wed Sep 7 16:31:08 2005 +78 -0

78 lines not on this page · raw message

e);
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+static struct ipt_target ipt_ctdirmark_reg
+= { { NULL, NULL }, "CTDIRMARK", target, checkentry, NULL, THIS_MODULE }; +
+static int __init init(void)
+{
+ if (ipt_register_target(&ipt_ctdirmark_reg))
+ return -EINVAL;
+
+ return 0;
+}
+
+static void __exit fini(void)
+{
+ ipt_unregister_target(&ipt_ctdirmark_reg);
+}
+
+module_init(init);
+module_exit(fini);

-------------- next part --------------

extensions/Makefile Wed Sep 7 16:40:11 2005 renamed from extensions/Makefile Wed Sep 7 16:42:31 2005 +0 -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 conntrack dscp ecn esp helper icmp iplimit length limit mac mark multiport owner physdev pkttype rpc standar

d state tcp tcpmss tos ttl udp unclean DNAT DSCP ECN LOG MARK MASQUERADE MIRROR REDIRECT REJECT SAME SNAT TARPIT TCPMSS TOS T TL ULOG
+PF_EXT_SLIB:=ah conntrack dscp ecn esp helper icmp iplimit length limit mac mark multiport owner physdev pkttype rpc standar d state ctdirmark tcp tcpmss tos ttl udp unclean DNAT DSCP ECN LOG MARK MASQUERADE MIRROR REDIRECT REJECT SAME SNAT TARPIT TC PMSS TOS TTL ULOG CTDIRMARK
PF6_EXT_SLIB:=eui64 hl icmpv6 length limit mac mark multiport owner standard tcp udp HL LOG MARK

# Optionals

extensions/libipt_ctdirmark.c Wed Sep 7 15:28:33 2005 renamed from extensions/libipt_ctdirmark.c Wed Sep 7 16:46:18 2005 +171 -0

171 lines not on this page · raw message

extensions/libipt_CTDIRMARK.c Wed Sep 7 15:28:52 2005 renamed from extensions/libipt_CTDIRMARK.c Wed Sep 7 16:48:53 2005 +221 -0

221 lines not on this page · raw message

#1 lore raw
Quoted 11 lines · Jesse Peng

Greetings all,
This patch fully derive from Henrik Nordstrom's long known connmark patch but is extended to bidirectional solution. The solution once discussed as the following link:
https://lists.netfilter.org/pipermail/netfilter-devel/2005-March/018784.html

Dear Henrik:
Feel free to give any advice for the work extending your existing famous connmark patch.

Dear Jian:
I got approved for quite a period,but sorry for this late posting this patch after a busy season.Hope this help!

Patch seems incomplete. Can not find definition of conntrack->dir_mark

Also as before I still wonder if this relatively big amount of info in each conntrack is really needed. CONNMARK already declares 32 bits per conntrack entry free for any use. Perhaps better to extend CONNMARK with shifting of the value allowing simple save/restore operations based on direction (where directions is selected by the already existing conntrack match).

But I do fully agree with the principle of being able to intelligenly keep conntrack state information/mark direction dependent and that having just a simple masking of the value is perhaps not sufficient in all situations.

Regards
Henrik

author
#2 lore raw

----- Original Message -----
From: "Henrik Nordstrom" <[email protected]>
To: "Jesse Peng" <[email protected]>
Cc: "Wang Jian" <[email protected]>; "netfilter-devel" <[email protected]>
Sent: Friday, September 09, 2005 12:10 AM
Subject: Re: [PATCH 2.4] Introducing Bidirectional conntrack mark

Quoted 1 line

Patch seems incomplete. Can not find definition of conntrack->dir_mark

Thanks,post them below.

Quoted 6 lines

Also as before I still wonder if this relatively big amount of info in each conntrack is really needed. CONNMARK already declares 32 bits per conntrack entry free for any use. Perhaps better to extend CONNMARK with shifting of the value allowing simple save/restore operations based on direction (where directions is selected by the already existing conntrack match).

As only getting them twice as a space,why not treat them easily? :) Otherwise,I will do things as keeping a private structure and cast the existing 32 bits to address pointer pointing to it while needed.

Quoted 4 lines

But I do fully agree with the principle of being able to intelligenly keep conntrack state information/mark direction dependent and that having just a simple masking of the value is perhaps not sufficient in all situations.

Yes,you are a wise person! :)

diff -Nur a/include/linux/netfilter_ipv4/ip_conntrack.h b/include/linux/netfilter_ipv4/ip_conntrack.h
--- a/include/linux/netfilter_ipv4/ip_conntrack.h Mon Apr 4 09:42:20
2005
+++ b/include/linux/netfilter_ipv4/ip_conntrack.h Fri Sep 9 14:20:02
2005
@@ -207,6 +207,9 @@

        } nat;

#endif /* CONFIG_IP_NF_NAT_NEEDED */

+#if defined(CONFIG_IP_NF_CTDIRMARK)
+ unsigned long mark_dir[IP_CT_DIR_MAX];
+#endif
};
diff -Nur a/net/ipv4/netfilter/ip_conntrack_standalone.c b/net/ipv4/netfilter/ip_conntrack_standalone.c
--- a/net/ipv4/netfilter/ip_conntrack_standalone.c Mon Apr 4 09:42:20
2005
+++ b/net/ipv4/netfilter/ip_conntrack_standalone.c Wed Sep 7 15:43:01
2005
@@ -107,7 +107,13 @@

                len += sprintf(buffer + len, "[ASSURED] ");
        len += sprintf(buffer + len, "use=%u ",
                       atomic_read(&conntrack->ct_general.use));

- len += sprintf(buffer + len, "\n");
+
+#if defined(CONFIG_IP_NF_CTDIRMARK)
+ len += sprintf(buffer + len,
+ "ctdirmark_original=%x,ctdirmark_reply=%x",
mark_dir[IP_CT_DIR_ORIGINAL],mark_dir[IP_CT_DIR_REPLY]); +#endif
+
+ len += sprintf(buffer + len, "\n");

        return len;

}
diff -Nur a/net/ipv4/netfilter/ip_conntrack_core.c b/net/ipv4/netfilter/ip_conntrack_core.c

net/ipv4/netfilter/ip_conntrack_core.c Wed Sep 7 15:46:09 2005 renamed from net/ipv4/netfilter/ip_conntrack_core.c Mon Apr 4 09:42:20 2005 +3 -1
@@ -742,7 +742,14 @@
                __set_bit(IPS_EXPECTED_BIT, &conntrack->status);
                conntrack->master = expected;
                expected->sibling = conntrack;
-               LIST_DELETE(&ip_conntrack_expect_list, expected);
+
+#if CONFIG_IP_NF_CTDIRMARK
+                conntrack->mark_dir[IP_CT_DIR_ORIGINAL] =

expected->expectant->mark_dir[IP_CT_DIR_ORIGINAL];
+ conntrack->mark_dir[IP_CT_DIR_REPLY] =
expected->expectant->mark_dir[IP_CT_DIR_REPLY]; +#endif
+
+

+                LIST_DELETE(&ip_conntrack_expect_list, expected);
                expected->expectant->expecting--;
                nf_conntrack_get(&master_ct(conntrack)->infos[0]);
        }
#3 lore raw

Need a method to reset the ip_conntrack_count

In reply to Jesse Peng

Hello folks,

I have encountered one question. Does it have a way to flush the conntrack table beside reloading the ip_conntrack module
(because I use the method of building into kernel.

As far as I know, the current conntrack number was recorded in the /proc/sys/net/ipv4/netfilter/ip_conntrack_count
So I want to know whether it exists a method or not to reset the current counter of conntrack.

My Enviroment:
Kenel: 2.6.10
Iptables: 1.2.9

Any hint are appreciated.

Vincent

#4 lore raw

Re: Need a method to reset the ip_conntrack_count

Quoted 7 lines

Hello folks,

I have encountered one question. Does it have a way to flush the

My Enviroment:
Kenel: 2.6.10
Iptables: 1.2.9

you need to use the upcoming 2.6.14 to be able to do so.... Pablo Neira's conntrack tool can do the job.

Quoted 8 lines

Any hint are appreciated.

Vincent

#5 lore raw

Re: Need a method to reset the ip_conntrack_count

In reply to Vincent
Quoted 3 lines · Vincent

I have encountered one question. Does it have a way to flush the conntrack table beside reloading the ip_conntrack module (because I use the method of building into kernel.

See the conntrack tool announced some time back..

Regards
Henrik