All of lore.kernel.org
 help / color / mirror / Atom feed
* PATCH: extra conntrack stats
@ 2003-04-19 21:42 Rolf Fokkens
  2003-04-25  8:23 ` Patrick Schaaf
                   ` (2 more replies)
  0 siblings, 3 replies; 42+ messages in thread
From: Rolf Fokkens @ 2003-04-19 21:42 UTC (permalink / raw)
  To: netfilter-devel

Hi!

This patch adds a little statistical information to the connection tracking:
the number of packets and bytes that have gone throught each connection.

We've been using the connection tracking info so far to count concurrently
connected users on an Oracle environment. Now our customer would like us to
measure the size of print jobs and the nunmber of print jobs - this patch may
be an option for us. Of course one can also measure other kinds of traffic.

It might even be possible now to limit the amount of data that has gone 
throught a connection by implementing other targets.

Well, it's a small patch that may not do any harm and please some people.

Cheers,

Rolf

diff -ruN linux-2.4.20.orig/include/linux/netfilter_ipv4/ip_conntrack_tuple.h linux-2.4.20/include/linux/netfilter_ipv4/ip_conntrack_tuple.h
--- linux-2.4.20.orig/include/linux/netfilter_ipv4/ip_conntrack_tuple.h	Mon Feb 25 20:38:13 2002
+++ linux-2.4.20/include/linux/netfilter_ipv4/ip_conntrack_tuple.h	Fri Apr 18 20:26:48 2003
@@ -60,6 +60,8 @@
 		/* The protocol. */
 		u_int16_t protonum;
 	} dst;
+
+	unsigned long npackets, nbytes;
 };
 
 enum ip_conntrack_dir
diff -ruN linux-2.4.20.orig/net/ipv4/netfilter/ip_conntrack_core.c linux-2.4.20/net/ipv4/netfilter/ip_conntrack_core.c
--- linux-2.4.20.orig/net/ipv4/netfilter/ip_conntrack_core.c	Fri Nov 29 00:53:15 2002
+++ linux-2.4.20/net/ipv4/netfilter/ip_conntrack_core.c	Sat Apr 19 15:13:34 2003
@@ -140,6 +140,8 @@
 	else if (iph->ihl * 4 + 8 > len)
 		return 0;
 
+	tuple->npackets = 0;
+	tuple->nbytes = 0;
 	tuple->src.ip = iph->saddr;
 	tuple->dst.ip = iph->daddr;
 	tuple->dst.protonum = iph->protocol;
@@ -158,6 +160,8 @@
 	inverse->src.ip = orig->dst.ip;
 	inverse->dst.ip = orig->src.ip;
 	inverse->dst.protonum = orig->dst.protonum;
+	inverse->npackets = 0;
+	inverse->nbytes = 0;
 
 	return protocol->invert_tuple(inverse, orig);
 }
@@ -760,7 +764,10 @@
 		if (IS_ERR(h))
 			return (void *)h;
 	}
-
+	WRITE_LOCK(&ip_conntrack_lock);
+	h->tuple.npackets ++;
+	h->tuple.nbytes += skb->len;
+	WRITE_UNLOCK(&ip_conntrack_lock);
 	/* It exists; we have (non-exclusive) reference. */
 	if (DIRECTION(h) == IP_CT_DIR_REPLY) {
 		*ctinfo = IP_CT_ESTABLISHED + IP_CT_IS_REPLY;
diff -ruN linux-2.4.20.orig/net/ipv4/netfilter/ip_conntrack_standalone.c linux-2.4.20/net/ipv4/netfilter/ip_conntrack_standalone.c
--- linux-2.4.20.orig/net/ipv4/netfilter/ip_conntrack_standalone.c	Fri Nov 29 00:53:15 2002
+++ linux-2.4.20/net/ipv4/netfilter/ip_conntrack_standalone.c	Sat Apr 19 11:51:26 2003
@@ -48,8 +48,11 @@
 {
 	int len;
 
-	len = sprintf(buffer, "src=%u.%u.%u.%u dst=%u.%u.%u.%u ",
-		      NIPQUAD(tuple->src.ip), NIPQUAD(tuple->dst.ip));
+	len = sprintf(buffer, "src=%u.%u.%u.%u dst=%u.%u.%u.%u "
+			      "packets=%lu bytes=%lu ",
+		      NIPQUAD(tuple->src.ip), NIPQUAD(tuple->dst.ip),
+		      tuple->npackets, tuple->nbytes
+		      );
 
 	len += proto->print_tuple(buffer + len, tuple);
 

^ permalink raw reply	[flat|nested] 42+ messages in thread

end of thread, other threads:[~2003-05-05 13:07 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-04-19 21:42 PATCH: extra conntrack stats Rolf Fokkens
2003-04-25  8:23 ` Patrick Schaaf
2003-04-27 12:48 ` Harald Welte
2003-04-27 15:23   ` Rolf Fokkens
2003-04-27 20:42     ` Harald Welte
2003-04-28  6:13       ` Patrick Schaaf
2003-04-29 22:15     ` Jozsef Kadlecsik
2003-04-29 22:38       ` Martin Josefsson
2003-04-30 10:49         ` Jozsef Kadlecsik
2003-04-30 11:19           ` Martin Josefsson
2003-04-30 23:05             ` Martin Josefsson
2003-05-01  4:05               ` Rusty Russell
2003-05-01  6:05                 ` Patrick Schaaf
2003-05-01  6:46                   ` Rusty Russell
2003-05-01  7:04                     ` Patrick Schaaf
2003-05-01  7:38                       ` Rusty Russell
2003-05-01  9:58                 ` Martin Josefsson
2003-05-01 11:32                 ` Harald Welte
2003-05-01 11:26               ` Harald Welte
2003-05-02 12:18                 ` Jozsef Kadlecsik
2003-05-02 12:30                   ` Martin Josefsson
2003-05-02 21:51                     ` Jozsef Kadlecsik
2003-05-02 21:58                       ` Martin Josefsson
2003-05-05  9:24                         ` Jozsef Kadlecsik
2003-05-05 12:38                         ` Jozsef Kadlecsik
2003-05-05 13:07                           ` Martin Josefsson
2003-05-01  0:06           ` Rusty Russell
2003-05-01  5:48             ` Patrick Schaaf
2003-05-01 10:01               ` Martin Josefsson
2003-05-01  9:06             ` Martin Josefsson
2003-05-02  5:31               ` Rusty Russell
2003-05-02  7:06                 ` Patrick Schaaf
2003-05-02  8:57                   ` Rusty Russell
2003-05-02  9:54                     ` SNAT and IP ID Patrick Schaaf
2003-05-02 15:43                       ` Harald Welte
2003-05-05  8:43             ` PATCH: extra conntrack stats Jozsef Kadlecsik
2003-04-28  9:13 ` vecna
2003-04-28 13:47   ` Patrick Schaaf
2003-04-28 15:07     ` possible target SBALANCE ? vecna
2003-04-29 14:48       ` Harald Welte
2003-04-30 11:59         ` vecna
2003-04-30 13:02           ` Roberto Nibali

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.