Skip to contentSkip to conversation

: add sysctl to read out the number of current connections

PATCH In review Patrick McHardy 1 participant 1 message Sep 21, 2004

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/12 : add sysctl to read out the number of current connections

This patch adds a sysctl to read out the number of current connections. ip_conntrack_count is an atomic_t, but it is read out by proc_dointvec. I have checked all arches, all use an int, but I'm not sure if it works on all of them.

[email protected], 2004-09-18 23:27:31+02:00, [email protected]
[NETFILTER]: add sysctl to read out the number of current connections

Apparently a lot of scripts use a construct like
"cat /proc/net/ip_conntrack | wc -l"
which has a negative impact on system performance due to all the locking required.

# This is a BitKeeper generated diff -Nru style patch. #
# ChangeSet
# 2004/09/18 23:27:31+02:00 [email protected]
# [NETFILTER]: add sysctl to read out the number of current connections
#
# Apparently a lot of scripts use a construct like
# "cat /proc/net/ip_conntrack | wc -l"
# which has a negative impact on system performance due to all the locking
# required.
#
# Signed-off-by: Harald Welte <[email protected]>
# Signed-off-by: Patrick McHardy <[email protected]>
#

# net/ipv4/netfilter/ip_conntrack_standalone.c
#   2004/09/18 23:27:03+02:00 [email protected] +8 -0
#   [NETFILTER]: add sysctl to read out the number of current connections
#   
#   Apparently a lot of scripts use a construct like
#           "cat /proc/net/ip_conntrack | wc -l"
#   which has a negative impact on system performance due to all the locking
#   required.
#   
#   Signed-off-by: Harald Welte <[email protected]>
#   Signed-off-by: Patrick McHardy <[email protected]>
# 
# include/linux/sysctl.h
#   2004/09/18 23:27:03+02:00 [email protected] +1 -0
#   [NETFILTER]: add sysctl to read out the number of current connections
#   
#   Apparently a lot of scripts use a construct like
#           "cat /proc/net/ip_conntrack | wc -l"
#   which has a negative impact on system performance due to all the locking
#   required.
#   
#   Signed-off-by: Harald Welte <[email protected]>
#   Signed-off-by: Patrick McHardy <[email protected]>
# 
diff -Nru a/include/linux/sysctl.h b/include/linux/sysctl.h
--- a/include/linux/sysctl.h	2004-09-20 11:57:01 +02:00
+++ b/include/linux/sysctl.h	2004-09-20 11:57:01 +02:00
@@ -424,6 +424,7 @@
  	NET_IPV4_NF_CONNTRACK_SCTP_TIMEOUT_SHUTDOWN_SENT=24,
  	NET_IPV4_NF_CONNTRACK_SCTP_TIMEOUT_SHUTDOWN_RECD=25,
  	NET_IPV4_NF_CONNTRACK_SCTP_TIMEOUT_SHUTDOWN_ACK_SENT=26,
+	NET_IPV4_NF_CONNTRACK_COUNT=27,
 };

/* /proc/sys/net/ipv6 */

net/ipv4/netfilter/ip_conntrack_standalone.c +8 -0
diff -Nru a/net/ipv4/netfilter/ip_conntrack_standalone.c b/net/ipv4/netfilter/ip_conntrack_standalone.c
@@ -515,6 +515,14 @@
 		.proc_handler	= &proc_dointvec,
 	},
 	{
+		.ctl_name	= NET_IPV4_NF_CONNTRACK_COUNT,
+		.procname	= "ip_conntrack_count",
+		.data		= &ip_conntrack_count,
+		.maxlen		= sizeof(int),
+		.mode		= 0444,
+		.proc_handler	= &proc_dointvec,
+	},
+	{
 		.ctl_name	= NET_IPV4_NF_CONNTRACK_BUCKETS,
 		.procname	= "ip_conntrack_buckets",
 		.data		= &ip_conntrack_htable_size,