Skip to contentSkip to conversation

Backported conntrack-acct/connbytes to 2.4 tree

PATCH Piotr Chytla 2 participants 4 messages Nov 16, 2004 – Apr 3, 2005 netfilter

lore
Share & tools
lore
#0 lore raw

Hi ,

I attached two backports from 2.6 tree to 2.4 for patch-o-matic-ng ,

1) Backported conntrack-acct
2) Backported connbytes with per-connection accounting support , also shared library for iptables is attached .
Shared library for iptables works with connbytes from 2.6 tree.

/pch

PS. This is my first two patchs for pom-ng.

connbytes/info +1 -1
diff -Nru -x '*.orig' -x '*.rej' a/connbytes/info b/connbytes/info
@@ -1,4 +1,4 @@
-Author: Harald Welte <[email protected]> / Martin Devera <[email protected]> 
+Author: Piotr Chytla <[email protected]> / Harald Welte <[email protected]> / Martin Devera <[email protected]> 
 Status: Experimental
 Repository: extra
 Depends: !CONNMARK
connbytes/iptables/extensions/libipt_connbytes.c +256 -0

256 lines not on this page · raw message

connbytes/linux-2.4/include/linux/netfilter_ipv4/ipt_connbytes.h +18 -3
diff -Nru -x '*.orig' -x '*.rej' a/connbytes/linux-2.4/include/linux/netfilter_ipv4/ipt_connbytes.h b/connbytes/linux-2.4/include/linux/netfilter_ipv4/ipt_connbytes.h
@@ -1,10 +1,25 @@
 #ifndef _IPT_CONNBYTES_H
 #define _IPT_CONNBYTES_H
+enum ipt_connbytes_what {
+	        IPT_CONNBYTES_WHAT_PKTS,
+	        IPT_CONNBYTES_WHAT_BYTES,
+	        IPT_CONNBYTES_WHAT_AVGPKT,
+};
+
+enum ipt_connbytes_direction {
+	        IPT_CONNBYTES_DIR_ORIGINAL,
+	        IPT_CONNBYTES_DIR_REPLY,
+	        IPT_CONNBYTES_DIR_BOTH,
+};
 
 struct ipt_connbytes_info
 {
-       /* if from <= to then it matches the range; if from > to then
-          inverse range is matched */
-       unsigned long from, to;
+        struct {
+                u_int64_t from; /* count to be matched */
+                u_int64_t to;   /* count to be matched */
+        } count;
+        u_int8_t what;          /* ipt_connbytes_what */
+        u_int8_t direction;     /* ipt_connbytes_direction */
 };
+
 #endif
connbytes/linux-2.4/net/ipv4/netfilter/ipt_connbytes.c +108 -5

145 lines not on this page · raw message

conntrack-acct/info +1 -1
diff -Nru -x '*.orig' -x '*.rej' a/conntrack-acct/info b/conntrack-acct/info
@@ -1,3 +1,3 @@
-Author: Harald Welte <[email protected]> 
+Author: Piotr Chytla <[email protected]> / Harald Welte <[email protected]> 
 Status: Stable
 Repository: pending
conntrack-acct/linux-2.4/net/ipv4/netfilter/Config.in.ladd +3 -0
diff -Nru -x '*.orig' -x '*.rej' a/conntrack-acct/linux-2.4/net/ipv4/netfilter/Config.in.ladd b/conntrack-acct/linux-2.4/net/ipv4/netfilter/Config.in.ladd
@@ -0,0 +1,3 @@
+    dep_tristate '  IRC protocol support' CONFIG_IP_NF_IRC $CONFIG_IP_NF_CONNTRACK             
+    dep_tristate '  Connection tracking flow accounting' CONFIG_IP_NF_CT_ACCT $CONFIG_IP_NF_CONNTRACK
+
conntrack-acct/linux-2.4.patch +210 -0

210 lines not on this page · raw message

#1 lore raw
Quoted 5 lines · Piotr Chytla

1) Backported conntrack-acct
2) Backported connbytes with per-connection accounting support , also shared library for iptables is attached .
Shared library for iptables works with connbytes from 2.6 tree.

I've removed myself from pom-ng info file(fixed patches for pomng in attachment). I was stupid, sorry for inconvenience.

/pch

connbytes/iptables/extensions/libipt_connbytes.c +256 -0
diff -Nru a/connbytes/iptables/extensions/libipt_connbytes.c b/connbytes/iptables/extensions/libipt_connbytes.c
@@ -0,0 +1,256 @@
+/* Shared library add-on to iptables to add byte tracking support. 
+ *
+ * 2004-11-11 - Piotr Chytla <[email protected]>
+ * 	- Some adaptation to backported module with per-conntrack accounting
+ * 	- Added connpkts/connavgpkt/direction ,
+ *
+ */ 
+
+#include <stdio.h>
+#include <netdb.h>
+#include <string.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <iptables.h>
+#include <linux/netfilter_ipv4/ip_conntrack.h>
+#include <linux/netfilter_ipv4/ipt_connbytes.h>
+
+/* Function which prints out usage message. */
+static void
+help(void)
+{
+	printf(
+"connbytes v%s options:\n"
+" [!] --connbytes from:[to]\n"
+"				Transfered bytes range to match\n"
+" [!] --connpkts from:[to]\n"
+"				Transfered number of packets range to match\n"
+" [!] --connavgpkt from:[to]\n"
+"				Transfered average packet size range to match\n"
+" --direction original|reply|both\n"
+"				Match only from direction \n"
+"\n", IPTABLES_VERSION);
+}
+
+static struct option opts[] = {
+	{ "connpkts", 1, 0, '1' },
+	{ "connbytes", 1, 0, '2' },
+	{ "connavgpkt", 1, 0, '3' },
+	{ "direction", 1, 0, '4'},
+	{0}
+};
+
+static char *sinfo_names[] = {
+	"connpkts",
+	"connbytes",
+	"connavgpkt",
+	NULL
+};
+
+static char *sinfo_directions[] = {
+	"original",
+	"replay",
+	"both",
+	NULL
+};
+
+#define IPT_CONNBYTES_PKTS	0x1
+#define IPT_CONNBYTES_BYTES	0x2
+#define IPT_CONNBYTES_AVGPKT	0x4
+#define IPT_CONNBYTES_ORIGINAL	0x8
+#define IPT_CONNBYTES_REPLY	0x10
+#define IPT_CONNBYTES_BOTH	0x20
+
+/* Initialize the match. */
+static void
+init(struct ipt_entry_match *m, unsigned int *nfcache)
+{
+	/* Can't cache this */
+	*nfcache |= NFC_UNKNOWN;
+} 
+
+static void
+parse_range(const char *arg, struct ipt_connbytes_info *si)
+{
+	char *colon,*p;
+
+	si->count.from = strtoul(arg,&colon,10);
+	if (*colon != ':') 
+		exit_error(PARAMETER_PROBLEM, "Bad range `%s'", arg);
+	si->count.to = strtoul(colon+1,&p,10);
+	if (p == colon+1) {
+		/* second number omited */
+		si->count.to = 0xffffffff;
+	}
+	if (si->count.from > si->count.to)
+		exit_error(PARAMETER_PROBLEM, "%llu should be less than %llu", si->count.from,si->count.to);
+}
+
+static int 
+parse_direction(const char *direction,size_t strlen,struct ipt_connbytes_info *sinfo,unsigned int *flags)
+{
+	if (strncasecmp(direction,"original",strlen) == 0)
+	{
+		sinfo->direction=IPT_CONNBYTES_DIR_ORIGINAL;
+		*flags |= IPT_CONNBYTES_ORIGINAL;
+	} else if (strncasecmp(direction,"both",strlen) == 0) 
+	{
+		sinfo->direction=IPT_CONNBYTES_DIR_BOTH;
+		*flags |= IPT_CONNBYTES_BOTH;
+	} else if (strncasecmp(direction,"replay",strlen) == 0)
+	{
+		sinfo->direction=IPT_CONNBYTES_DIR_REPLY;
+		*flags |= IPT_CONNBYTES_REPLY;
+	} else return 0;
+	return 1;
+}
+	
+
+/* Function which parses command options; returns true if it
+   ate an option */
+static int
+parse(int c, char **argv, int invert, unsigned int *flags,
+      const struct ipt_entry *entry,
+      unsigned int *nfcache,
+      struct ipt_entry_match **match)
+{
+	struct ipt_connbytes_info *sinfo = (struct ipt_connbytes_info *)(*match)->data;
+	unsigned long i;
+	switch (c) {
+	case '2':
+		if (*flags & IPT_CONNBYTES_BYTES)
+			exit_error(PARAMETER_PROBLEM,
+					"Can't specify --connbytes twice");
+		if (*flags & IPT_CONNBYTES_PKTS)
+			exit_error(PARAMETER_PROBLEM,
+					"Can't use --connpkts and --connbytes together");
+		if (*flags & IPT_CONNBYTES_AVGPKT)
+			exit_error(PARAMETER_PROBLEM,
+					"Can't use --connavgpkt and --connbytes together");
+
+		if (check_inverse(optarg, &invert, &optind, 0))
+			optind++;
+
+		parse_range(argv[optind-1], sinfo);
+		if (invert) {
+			i = sinfo->count.from;
+			sinfo->count.from = sinfo->count.to;
+			sinfo->count.to = i;
+		}
+		sinfo->what=IPT_CONNBYTES_WHAT_BYTES;
+		sinfo->direction=IPT_CONNBYTES_DIR_BOTH;
+		*flags |= IPT_CONNBYTES_BYTES;
+		break;
+	case '1':
+		if (*flags & IPT_CONNBYTES_PKTS)
+			exit_error(PARAMETER_PROBLEM,
+					"Can't specify --connpkts twice");
+		if (*flags & IPT_CONNBYTES_BYTES)
+			exit_error(PARAMETER_PROBLEM,
+					"Can't use --connbytes and --connpkts together");
+		if (*flags & IPT_CONNBYTES_AVGPKT)
+			exit_error(PARAMETER_PROBLEM,
+					"Can't use --connavgpkt and --connpkts together");
+		
+		if (check_inverse(optarg,&invert,&optind,0))
+			optind++;
+
+		parse_range(argv[optind-1],sinfo);
+		if (invert) {
+			i = sinfo->count.from;
+			sinfo->count.from = sinfo->count.to;
+			sinfo->count.to = i;
+		}
+		sinfo->what=IPT_CONNBYTES_WHAT_PKTS;
+		sinfo->direction=IPT_CONNBYTES_DIR_BOTH;
+		*flags |= IPT_CONNBYTES_PKTS;
+		break;
+	case '3':
+		if (*flags & IPT_CONNBYTES_AVGPKT)
+			exit_error(PARAMETER_PROBLEM,
+					"Can't specify --connavgpkt twice");
+		if (*flags & IPT_CONNBYTES_PKTS)
+			exit_error(PARAMETER_PROBLEM,
+					"Can't use --connpkts and --connavgpkt together");
+		if (*flags & IPT_CONNBYTES_BYTES)
+			exit_error(PARAMETER_PROBLEM,
+					"Can't use --connbytes and --connavgpkt together");
+		
+		if (check_inverse(optarg,&invert,&optind,0))
+			optind++;
+
+		parse_range(argv[optind-1],sinfo);
+		if (invert) {
+			i = sinfo->count.from;
+			sinfo->count.from = sinfo->count.to;
+			sinfo->count.to = i;
+		}
+		sinfo->what=IPT_CONNBYTES_WHAT_AVGPKT;
+		sinfo->direction=IPT_CONNBYTES_DIR_BOTH;
+		*flags |= IPT_CONNBYTES_AVGPKT;
+		break;
+	case '4':
+		if (*flags & (IPT_CONNBYTES_ORIGINAL|IPT_CONNBYTES_BOTH|IPT_CONNBYTES_REPLY))
+			exit_error(PARAMETER_PROBLEM,
+					"Can't specify --direction twice");
+		if (!parse_direction(argv[optind-1],strlen(argv[optind-1]),sinfo,flags))
+			exit_error(PARAMETER_PROBLEM, "Bad direction '%s'",argv[optind-1]);
+		
+		break;
+	default:	
+		return 0;
+	}
+	return 1;
+}
+
+static void final_check(unsigned int flags)
+{
+	if (!flags)
+		exit_error(PARAMETER_PROBLEM, "You must specify `--connbytes or --connpkts or--connavgpkt'");
+}
+
+/* Prints out the matchinfo. */
+static void
+print(const struct ipt_ip *ip,
+      const struct ipt_entry_match *match,
+      int numeric)
+{
+	struct ipt_connbytes_info *sinfo = (struct ipt_connbytes_info *)match->data;
+
+		if (sinfo->count.from > sinfo->count.to) 
+			printf("%s ! %llu:%llu direction:%s",sinfo_names[sinfo->what],sinfo->count.to,sinfo->count.from,sinfo_directions[sinfo->direction]);
+		else
+		printf("%s %llu:%llu direction:%s",sinfo_names[sinfo->what],sinfo->count.from,sinfo->count.to,sinfo_directions[sinfo->direction]);
+}
+
+/* Saves the matchinfo in parsable form to stdout. */
+static void save(const struct ipt_ip *ip, const struct ipt_entry_match *match)
+{
+	struct ipt_connbytes_info *sinfo = (struct ipt_connbytes_info *)match->data;
+
+	if (sinfo->count.from > sinfo->count.to) 
+		printf("! --%s %llu:%llu --direction %s",sinfo_names[sinfo->what],sinfo->count.to,sinfo->count.from,sinfo_directions[sinfo->direction]);
+	else
+		printf("--%s %llu:%llu --direction %s",sinfo_names[sinfo->what],sinfo->count.from,sinfo->count.to,sinfo_directions[sinfo->direction]);
+}
+
+static
+struct iptables_match state
+= { NULL,
+    "connbytes",
+    IPTABLES_VERSION,
+    IPT_ALIGN(sizeof(struct ipt_connbytes_info)),
+    IPT_ALIGN(sizeof(struct ipt_connbytes_info)),
+    &help,
+    &init,
+    &parse,
+    &final_check,
+    &print,
+    &save,
+    opts
+};
+
+void _init(void)
+{
+	register_match(&state);
+}
connbytes/linux-2.4/include/linux/netfilter_ipv4/ipt_connbytes.h +18 -3
diff -Nru a/connbytes/linux-2.4/include/linux/netfilter_ipv4/ipt_connbytes.h b/connbytes/linux-2.4/include/linux/netfilter_ipv4/ipt_connbytes.h
@@ -1,10 +1,25 @@
 #ifndef _IPT_CONNBYTES_H
 #define _IPT_CONNBYTES_H
+enum ipt_connbytes_what {
+	        IPT_CONNBYTES_WHAT_PKTS,
+	        IPT_CONNBYTES_WHAT_BYTES,
+	        IPT_CONNBYTES_WHAT_AVGPKT,
+};
+
+enum ipt_connbytes_direction {
+	        IPT_CONNBYTES_DIR_ORIGINAL,
+	        IPT_CONNBYTES_DIR_REPLY,
+	        IPT_CONNBYTES_DIR_BOTH,
+};
 
 struct ipt_connbytes_info
 {
-       /* if from <= to then it matches the range; if from > to then
-          inverse range is matched */
-       unsigned long from, to;
+        struct {
+                u_int64_t from; /* count to be matched */
+                u_int64_t to;   /* count to be matched */
+        } count;
+        u_int8_t what;          /* ipt_connbytes_what */
+        u_int8_t direction;     /* ipt_connbytes_direction */
 };
+
 #endif
connbytes/linux-2.4/net/ipv4/netfilter/ipt_connbytes.c +108 -5

145 lines not on this page · raw message

conntrack-acct/linux-2.4/net/ipv4/netfilter/Config.in.ladd +3 -0
diff -Nru a/conntrack-acct/linux-2.4/net/ipv4/netfilter/Config.in.ladd b/conntrack-acct/linux-2.4/net/ipv4/netfilter/Config.in.ladd
@@ -0,0 +1,3 @@
+    dep_tristate '  IRC protocol support' CONFIG_IP_NF_IRC $CONFIG_IP_NF_CONNTRACK             
+    dep_tristate '  Connection tracking flow accounting' CONFIG_IP_NF_CT_ACCT $CONFIG_IP_NF_CONNTRACK
+
conntrack-acct/linux-2.4.patch +210 -0

210 lines not on this page · raw message

#2 lore raw

Hi all, I'd like to ask, what is state of this patch? Is it going to main tree? I'm not able to build iptables-1.3.1 without it, but it breaks (at least) conntrack_{gre,mppe}
Can I do somethink to help?
Thanks!

Piotr Chytla píše v Ne 21. 11. 2004 v 17:34 +0100:

Quoted 11 lines · Piotr Chytla
Quoted 5 lines

1) Backported conntrack-acct
2) Backported connbytes with per-connection accounting support , also shared library for iptables is attached .
Shared library for iptables works with connbytes from 2.6 tree.

I've removed myself from pom-ng info file(fixed patches for pomng in attachment). I was stupid, sorry for inconvenience.

/pch

#3 lore raw
Quoted 2 lines · Nikola Ciprich

Hi all, I'd like to ask, what is state of this patch? Is it going to main tree?

conntrack-acct is in 2.6 main tree but Herald wrote this patch not me , my patch is only dirty backport :>

Quoted 2 lines

I'm not able to build iptables-1.3.1 without it, but it breaks (at least) conntrack_{gre,mppe}

What kernel version? maybe you have old kernel headers.

/pch