netfilter: make net/stat/nf_conntrack procfs available again
Subsystems (2)
Florian Westphal
maintainerPATCH 1/1 netfilter: make net/stat/nf_conntrack procfs available again
partially reverts commit 54b07dca68557b0952585b5f4834cd0dd86eba35 (netfilter: provide config option to disable ancient procfs parts).
Problem is that this also disabled net/stat/nf_conntrack, which is useful for diagnosing certain conntrack-related issues; and there are currently no other means to obtain these statistics from userspace.
(conntrack-tools "conntrack -S" uses the proc interface, too...)
--- net/netfilter/nf_conntrack_standalone.c | 30 +++++++++++++++++++++++++----- 1 files changed, 25 insertions(+), 5 deletions(-)
net/netfilter/nf_conntrack_standalone.c +25 -5
@@ -269,6 +269,27 @@ static const struct file_operations ct_file_ops = { .release = seq_release_net, }; +static bool nf_conntrack_procfs_create (struct net *net) +{ +return !!proc_net_fops_create (net,"nf_conntrack" ,0440 , &ct_file_ops); +} + +static void nf_conntrack_procfs_remove (struct net *net) +{ +proc_net_remove (net,"nf_conntrack" ); +} +#else +static bool nf_conntrack_procfs_create (struct net *net) +{ +return true; +} + +static inline void nf_conntrack_procfs_remove (struct net *net) +{ +} +#endif /* CONFIG_NF_CONNTRACK_PROCFS */ + +#ifdef CONFIG_PROC_FS static void *ct_cpu_seq_start (struct seq_file *seq,loff_t *pos) {struct net *net =seq_file_net (seq);
@@ -366,8 +387,7 @@ static int nf_conntrack_standalone_init_proc(struct net *net) {struct proc_dir_entry *pde; - pde =proc_net_fops_create (net,"nf_conntrack" ,0440 , &ct_file_ops); -if (!pde) +if (!nf_conntrack_procfs_create (net)) goto out_nf_conntrack; pde = proc_create("nf_conntrack", S_IRUGO, net->proc_net_stat,
@@ -377,7 +397,7 @@ static int nf_conntrack_standalone_init_proc(struct net *net)return 0 ; out_stat_nf_conntrack: -proc_net_remove (net,"nf_conntrack" ); +nf_conntrack_procfs_remove (net); out_nf_conntrack:return -ENOMEM ; }
@@ -385,7 +405,7 @@ out_nf_conntrack:static void nf_conntrack_standalone_fini_proc (struct net *net) {remove_proc_entry ("nf_conntrack" , net->proc_net_stat); -proc_net_remove (net,"nf_conntrack" ); +nf_conntrack_procfs_remove (net); }#else static int nf_conntrack_standalone_init_proc (struct net *net)
@@ -396,7 +416,7 @@ static int nf_conntrack_standalone_init_proc(struct net *net)static void nf_conntrack_standalone_fini_proc (struct net *net) { } -#endif /* CONFIG_NF_CONNTRACK_PROCFS */ +#endif /* CONFIG_PROC_FS */ /* Sysctl support */
Signature · 1 line
1.7.3.4
Pablo Neira Ayuso
maintainerHi Florian,
Quoted 8 lines · Florian Westphal
partially reverts commit
54b07dca68557b0952585b5f4834cd0dd86eba35(netfilter: provide config option to disable ancient procfs parts).Problem is that this also disabled
net/stat/nf_conntrack, which is useful for diagnosing certain conntrack-related issues; and there are currently no other means to obtain these statistics from userspace.(conntrack-tools "conntrack -S" uses the proc interface, too...)
I can pass the following patch to David. It implements the missing code in ctnetlink to dump the statistics. Thus, conntrack doesn't use any /proc interface anymore (the changes to conntrack still pending).
You can test them by means of:
http://git.netfilter.org/cgi-bin/gitweb.cgi?p=libmnl.git;a=shortlog;h=refs/heads/nfct-stats
If you're OK with it, I'll integrate this in a backward compatible way (first try to use netlink, if not available, use /proc).
Still, I think that passing this to current may be useful. Although you can workaround this by enable that option. What do you prefer?
Quoted 1 line
From
f1bb652b62671bc87d01ab2d94d267a481f795c5Mon Sep 17 00:00:00 2001
From: Pablo Neira Ayuso <[email protected]>
Date: Tue, 26 Jun 2012 20:27:09 +0200
Subject: [PATCH] ctnetlink: export conntrack statistic via netlink
This patch adds the following messages:
IPCTNL_MSG_CT_GET_STATS_CPUIPCTNL_MSG_CT_GET_STATSIPCTNL_MSG_EXP_GET_STATS_CPU
To display connection tracking system per-cpu and global statistics.
This provides a replacement for the following /proc interfaces:
/proc/net/stat/nf_conntrack/proc/sys/net/netfilter/nf_conntrack_count
--- include/linux/netfilter/nfnetlink_conntrack.h | 38 +++++ net/netfilter/nf_conntrack_netlink.c | 227 ++++++++++++++++++++++++- 2 files changed, 264 insertions(+), 1 deletion(-)
include/linux/netfilter/nfnetlink_conntrack.h +38 -0
@@ -7,6 +7,8 @@ enum cntl_msg_types {IPCTNL_MSG_CT_GET ,IPCTNL_MSG_CT_DELETE ,IPCTNL_MSG_CT_GET_CTRZERO , +IPCTNL_MSG_CT_GET_STATS_CPU , +IPCTNL_MSG_CT_GET_STATS , IPCTNL_MSG_MAX };
@@ -15,6 +17,7 @@ enum ctnl_exp_msg_types {IPCTNL_MSG_EXP_NEW ,IPCTNL_MSG_EXP_GET ,IPCTNL_MSG_EXP_DELETE , +IPCTNL_MSG_EXP_GET_STATS_CPU , IPCTNL_MSG_EXP_MAX };
@@ -203,4 +206,39 @@ enum ctattr_secctx { };#define CTA_SECCTX_MAX (__CTA_SECCTX_MAX - 1) +enum ctattr_stats_cpu { +CTA_STATS_UNSPEC , +CTA_STATS_SEARCHED , +CTA_STATS_FOUND , +CTA_STATS_NEW , +CTA_STATS_INVALID , +CTA_STATS_IGNORE , +CTA_STATS_DELETE , +CTA_STATS_DELETE_LIST , +CTA_STATS_INSERT , +CTA_STATS_INSERT_FAILED , +CTA_STATS_DROP , +CTA_STATS_EARLY_DROP , +CTA_STATS_ERROR , +CTA_STATS_SEARCH_RESTART , + __CTA_STATS_MAX, +}; +#define CTA_STATS_MAX (__CTA_STATS_MAX - 1) + +enum ctattr_stats_global { +CTA_STATS_GLOBAL_UNSPEC , +CTA_STATS_GLOBAL_ENTRIES , + __CTA_STATS_GLOBAL_MAX, +}; +#define CTA_STATS_GLOBAL_MAX (__CTA_STATS_GLOBAL_MAX - 1) + +enum ctattr_expect_stats { +CTA_STATS_EXP_UNSPEC , +CTA_STATS_EXP_NEW , +CTA_STATS_EXP_CREATE , +CTA_STATS_EXP_DELETE , + __CTA_STATS_EXP_MAX, +}; +#define CTA_STATS_EXP_MAX (__CTA_STATS_EXP_MAX - 1) +#endif /* _IPCONNTRACK_NETLINK_H */
net/netfilter/nf_conntrack_netlink.c +226 -1
257 lines not on this page · raw message
Signature · 1 line
1.7.10
Florian Westphal
maintainerQuoted 8 lines · Pablo Neira Ayuso
Quoted 7 lines · Florian Westphal
partially reverts commit
54b07dca68557b0952585b5f4834cd0dd86eba35(netfilter: provide config option to disable ancient procfs parts).Problem is that this also disabled
net/stat/nf_conntrack, which is useful for diagnosing certain conntrack-related issues; and there are currently no other means to obtain these statistics from userspace.
Quoted 5 lines
Quoted 1 line
(conntrack-tools "conntrack -S" uses the proc interface, too...)
I can pass the following patch to David. It implements the missing code in ctnetlink to dump the statistics. Thus, conntrack doesn't use any /proc interface anymore (the changes to conntrack still pending).
Thanks, that would be fine, too.
Quoted 2 lines
If you're OK with it, I'll integrate this in a backward compatible way (first try to use netlink, if not available, use /proc).
Sounds good.
Quoted 2 lines
Still, I think that passing this to current may be useful. Although you can workaround this by enable that option. What do you prefer?
Ignore my patch. In the meantime people can NF_CONNTRACK_PROCFS=y; we just have to wait a bit (e.g. a year) before killing the nfct proc code completely.
Pablo Neira Ayuso
maintainerQuoted 15 lines · Florian Westphal
Quoted 8 lines · Pablo Neira Ayuso
Quoted 7 lines · Florian Westphal
partially reverts commit
54b07dca68557b0952585b5f4834cd0dd86eba35(netfilter: provide config option to disable ancient procfs parts).Problem is that this also disabled
net/stat/nf_conntrack, which is useful for diagnosing certain conntrack-related issues; and there are currently no other means to obtain these statistics from userspace.Quoted 5 lines
Quoted 1 line
(conntrack-tools "conntrack -S" uses the proc interface, too...)
I can pass the following patch to David. It implements the missing code in ctnetlink to dump the statistics. Thus, conntrack doesn't use any /proc interface anymore (the changes to conntrack still pending).
Quoted 6 lines
Thanks, that would be fine, too.
Quoted 2 lines
If you're OK with it, I'll integrate this in a backward compatible way (first try to use netlink, if not available, use /proc).
Sounds good.
JFYI:
I've pushed those two patches to the ct-stats branch to support dumping statistics via ctnetlink. I'll merge them once we hit 3.6-rc1.
Part of that code can be moved to the libraries, we can do that later.
BTW, you require git tree snapshot from libnetfilter_conntrack for this.
And the -S output format is not backward compatible to previous:
cpu=0 searched=9367 found=428234 new=287508 invalid=1 ignore=4 delete=291546 delete_list=6045 insert=2007 insert_failed=0 drop=0 early_drop=0 error=0 search_restart=0 cpu=1 searched=394 found=40745 new=1667 invalid=0 ignore=0 delete=378 delete_list=378 insert=1667 insert_failed=0 drop=0 early_drop=0 error=0 search_restart=0 cpu=2 searched=336 found=77297 new=2127 invalid=0 ignore=1 delete=661 delete_list=661 insert=2128 insert_failed=0 drop=0 early_drop=0 error=0 search_restart=0 cpu=3 searched=71 found=15016 new=1391 invalid=0 ignore=0 delete=87 delete_list=87 insert=1391 insert_failed=0 drop=0 early_drop=0 error=0 search_restart=0
Quoted 6 lines
Quoted 2 lines
Still, I think that passing this to current may be useful. Although you can workaround this by enable that option. What do you prefer?
Ignore my patch. In the meantime people can NF_CONNTRACK_PROCFS=y; we just have to wait a bit (e.g. a year) before killing the nfct proc code completely.
Makes sense. I'll pass my patch to David, drop this and extend the time to kill that /proc code for some time.