Skip to contentSkip to conversation

connrate for patch-o-matic-ng (again)

PATCH In review Nuutti Kotivuori 2 participants 3 messages Apr 18, 2004 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 connrate for patch-o-matic-ng (again)

The last status on this patch thingy was that it was missing copyright notices on some source files. I made and posted the changes for it, but never heard any comments on it.

I now refreshed both parts of the patch, and refreshed the patch against the kernel tree to be against 2.6.5, tested that it applies cleanly and works.

So, I'd like to know if there's still something that I should be doing for this patch, or has it been forgotten or has everybody just been too busy to handle it?

Thanks in advance :-)
-- Naked

Index: connrate/help
===================================================================
RCS file: connrate/help

help new file +34 -0
diff -N connrate/help
@@ -0,0 +1,34 @@
+The connrate match is used to match against the current transfer speed of a
+connection. The algorithm averages transferred bytes over a time sliding window
+of constant size. The maximum and minimum rates measurable are explained in the
+code, along the algorithm used in the measurements.
+
+This match can easily be used to reclassify connections based on their current
+transfer rate, but is not meant for directly dropping packets, because packet
+drops affect the rate being estimated.
+
+The transfer rate per connection can also be viewed through
+/proc/net/ip_conntrack.
+
+Usage:
+--connrate [!] [FROM]:[TO]
+
+will match packet from a connection which is currently transferring more than
+FROM bytes per second and less than TO byte per second. 'inf' can be used to
+signify largest measurable transfer rate. If FROM is omitted, it defaults to
+zero. If TO is omitted, it defaults to infinity. "!" is used to match packets
+not falling in the range.
+
+Example:
+
+iptables .. -m connrate --connrate 10000:100000 ...
+
+ => match packets in connections transferring faster than 10kbps, but slower
+    than 100kbps.
+
+iptables .. -m tos --tos Minimize-Delay \
+            -m connrate --connrate 20000:inf \
+            -j TOS --set-tos Maximize-Throughput
+
+ => match packets in minimize-delay TOS connections that are transferring
+    faster than 20kbps and change their tos to maximize-throughput instead.

Index: connrate/info
===================================================================
RCS file: connrate/info

info new file +4 -0
diff -N connrate/info
@@ -0,0 +1,4 @@
+Author: Nuutti Kotivuori <[email protected]>
+Status: Working, but received only minimal testing
+Repository: extra
+Requires: linux >= 2.6.0

Index: connrate/linux.patch
===================================================================
RCS file: connrate/linux.patch

linux.patch new file +65 -0

65 lines not on this page · raw message

Index: connrate/linux/include/linux/netfilter_ipv4/ip_conntrack_rate.h
===================================================================
RCS file: connrate/linux/include/linux/netfilter_ipv4/ip_conntrack_rate.h

linux/include/linux/netfilter_ipv4/ip_conntrack_rate.h new file +33 -0
diff -N connrate/linux/include/linux/netfilter_ipv4/ip_conntrack_rate.h
@@ -0,0 +1,33 @@
+#ifndef _IP_CONNTRACK_RATE_H
+#define _IP_CONNTRACK_RATE_H
+
+/* estimation interval, in jiffies */
+#define IP_CONNTRACK_RATE_INTERVAL (3 * HZ)
+
+/* scale on how many tokens per byte to generate */
+#define IP_CONNTRACK_RATE_SCALE 100
+
+/* per conntrack: transfer rate in connection */
+struct ip_conntrack_rate {
+	/* jiffies of previous received packet */
+	unsigned long prev;
+	/* average rate of tokens per jiffy */
+	u_int32_t avgrate;
+};
+
+#ifdef __KERNEL__
+
+/* Count a packet of len into given rate structure. */
+extern void
+ip_conntrack_rate_count(struct ip_conntrack_rate *ctr,
+			unsigned int len);
+
+/* Return current rate as bytes per second. Note that the returned
+   rate is the rate at last received packet, not counting time has
+   that passed after it. */
+extern u_int32_t
+ip_conntrack_rate_get(struct ip_conntrack_rate *ctr);
+
+#endif /* __KERNEL__ */
+
+#endif /* _IP_CONNTRACK_RATE_H */

Index: connrate/linux/include/linux/netfilter_ipv4/ipt_connrate.h
===================================================================
RCS file: connrate/linux/include/linux/netfilter_ipv4/ipt_connrate.h

linux/include/linux/netfilter_ipv4/ipt_connrate.h new file +12 -0
diff -N connrate/linux/include/linux/netfilter_ipv4/ipt_connrate.h
@@ -0,0 +1,12 @@
+#ifndef _IPT_CONNRATE_H
+#define _IPT_CONNRATE_H
+
+struct ipt_connrate_info
+{
+	/* Per connection transfer rate, in bytes per second. If
+	   'from' is smaller or equal to 'to', rate is matched to be
+	   inside the inclusive range [from,to], otherwise rate is
+	   matched to be outside the inclusive range [to,from]. */
+	u_int32_t from, to;
+};
+#endif

Index: connrate/linux/net/ipv4/netfilter/Kconfig.ladd
===================================================================
RCS file: connrate/linux/net/ipv4/netfilter/Kconfig.ladd

linux/net/ipv4/netfilter/Kconfig.ladd new file +28 -0
diff -N connrate/linux/net/ipv4/netfilter/Kconfig.ladd
@@ -0,0 +1,28 @@
+config IP_NF_CONNTRACK_RATE
+	bool "Connection rate estimation"
+	depends on IP_NF_CONNTRACK
+	help
+
+	  This enables per connection transfer rate estimation in connection
+	  tracking code. This enlarges the amount of memory required by each
+	  connection tracked a bit and adds the overhead of calculating the
+	  transmission rate on every received packet.
+	
+	  This is required to be able to match on the per connection transfer
+	  rate, and can be a nice statistic to see in the connection tracking
+	  table, but is useless otherwise.
+	
+	  If unsure, say N.
+
+config IP_NF_MATCH_CONNRATE
+	tristate "Connection rate match support"
+	depends on IP_NF_CONNTRACK_RATE && IP_NF_CONNTRACK && IP_NF_IPTABLES
+	help
+	  This allows matching on the transfer rate on a per connection basis.
+
+	  Connection transfer rate estimation is performed separately by the
+	  connection tracking code and is unaffected by the presence of matches
+	  on it. Several connection rate matches may match a single packet and
+	  every match will see the same rate.
+
+	  To compile it as a module, choose M here.  If unsure, say N.

Index: connrate/linux/net/ipv4/netfilter/Makefile.ladd
===================================================================
RCS file: connrate/linux/net/ipv4/netfilter/Makefile.ladd

linux/net/ipv4/netfilter/Makefile.ladd new file +2 -0
diff -N connrate/linux/net/ipv4/netfilter/Makefile.ladd
@@ -0,0 +1,2 @@
+obj-$(CONFIG_IP_NF_CONNTRACK) += ip_conntrack.o
+obj-$(CONFIG_IP_NF_CONNTRACK_RATE) += ip_conntrack_rate.o

Index: connrate/linux/net/ipv4/netfilter/Makefile.ladd_2
===================================================================
RCS file: connrate/linux/net/ipv4/netfilter/Makefile.ladd_2

linux/net/ipv4/netfilter/Makefile.ladd_2 new file +2 -0
diff -N connrate/linux/net/ipv4/netfilter/Makefile.ladd_2
@@ -0,0 +1,2 @@
+obj-$(CONFIG_IP_NF_MATCH_CONNTRACK) += ipt_conntrack.o
+obj-$(CONFIG_IP_NF_MATCH_CONNRATE) += ipt_connrate.o

Index: connrate/linux/net/ipv4/netfilter/ip_conntrack_rate.c
===================================================================
RCS file: connrate/linux/net/ipv4/netfilter/ip_conntrack_rate.c

linux/net/ipv4/netfilter/ip_conntrack_rate.c new file +131 -0

131 lines not on this page · raw message

Index: connrate/linux/net/ipv4/netfilter/ipt_connrate.c
===================================================================
RCS file: connrate/linux/net/ipv4/netfilter/ipt_connrate.c

linux/net/ipv4/netfilter/ipt_connrate.c new file +74 -0

74 lines not on this page · raw message

Index: extensions/.connrate-test
===================================================================
RCS file: extensions/.connrate-test

.connrate-test new file +2 -0
diff -N extensions/.connrate-test
@@ -0,0 +1,2 @@
+#! /bin/sh
+[ -f $KERNEL_DIR/include/linux/netfilter_ipv4/ipt_connrate.h ] && echo connrate

Index: extensions/libipt_connrate.c
===================================================================
RCS file: extensions/libipt_connrate.c

libipt_connrate.c new file +189 -0

189 lines not on this page · raw message

Index: extensions/libipt_connrate.man
===================================================================
RCS file: extensions/libipt_connrate.man

libipt_connrate.man new file +6 -0
diff -N extensions/libipt_connrate.man
@@ -0,0 +1,6 @@
+This module matches the current transfer rate in a connection.
+.TP
+.BI "--connrate " "[!] [\fIfrom\fP]:[\fIto\fP]"
+Match against the current connection transfer rate being within 'from'
+and 'to' bytes per second. When the "!" argument is used before the
+range, the sense of the match is inverted.
#1 lore raw
Quoted 11 lines · Nuutti Kotivuori

The last status on this patch thingy was that it was missing copyright notices on some source files. I made and posted the changes for it, but never heard any comments on it.

I now refreshed both parts of the patch, and refreshed the patch against the kernel tree to be against 2.6.5, tested that it applies cleanly and works.

So, I'd like to know if there's still something that I should be doing for this patch, or has it been forgotten or has everybody just been too busy to handle it?

The patch is fine, I've added it to CVS, with minor whitespace-cleanup.

Regards
Patrick

Quoted 3 lines

Thanks in advance :-)
-- Naked

#2 lore raw
Quoted 2 lines · Patrick McHardy

The patch is fine, I've added it to CVS, with minor whitespace-cleanup.

Cool! Thumbs up!

-- Naked