diff options
author | Коренберг Марк (дома) <socketpair@gmail.com> | 2012-08-27 23:39:29 +0600 |
---|---|---|
committer | Коренберг Марк <mark@ideco.ru> | 2012-08-28 18:53:33 +0600 |
commit | a0f1c0e281ee78ab8ee874bbb6c2140c12101284 (patch) | |
tree | d2539a6c212a1cd620bee67c5670ec8ff5df5ac5 /lib | |
parent | 052a13119353f97e70216808b02bc692bcb18378 (diff) | |
download | libnl-a0f1c0e281ee78ab8ee874bbb6c2140c12101284.tar.gz |
ct_dump_stats: detect when stats are not available
Since about 2.6.27 kernel, stats are not enabled by default.
Stats can be enabled using sysctl named
net.netfilter.nf_conntrack_acct
So, do not print zeroes in stats if it's not available.
When not checked, trash may appear in output
Diffstat (limited to 'lib')
-rw-r--r-- | lib/netfilter/ct_obj.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/lib/netfilter/ct_obj.c b/lib/netfilter/ct_obj.c index c205427..70a814f 100644 --- a/lib/netfilter/ct_obj.c +++ b/lib/netfilter/ct_obj.c @@ -256,18 +256,29 @@ static void ct_dump_stats(struct nl_object *a, struct nl_dump_params *p) struct nfnl_ct *ct = (struct nfnl_ct *) a; double res; char *unit; + uint64_t packets; + const char * const names[] = {"rx", "tx"}; + int i; ct_dump_details(a, p); - nl_dump_line(p, " # packets volume\n"); - - res = nl_cancel_down_bytes(nfnl_ct_get_bytes(ct, 1), &unit); - nl_dump_line(p, " rx %10llu %7.2f %s\n", - nfnl_ct_get_packets(ct, 1), res, unit); + if (!nfnl_ct_test_bytes(ct, 0) || + !nfnl_ct_test_packets(ct, 0) || + !nfnl_ct_test_bytes(ct, 1) || + !nfnl_ct_test_packets(ct, 1)) + { + nl_dump_line(p, " Statics are not available.\n"); + nl_dump_line(p, " Please set sysctl net.netfilter.nf_conntrack_acct = 1\n"); + nl_dump_line(p, " (Require kernel 2.6.27)\n"); + return; + } - res = nl_cancel_down_bytes(nfnl_ct_get_bytes(ct, 0), &unit); - nl_dump_line(p, " tx %10llu %7.2f %s\n", - nfnl_ct_get_packets(ct, 0), res, unit); + nl_dump_line(p, " # packets volume\n"); + for (i=0; i<=1; i++) { + res = nl_cancel_down_bytes(nfnl_ct_get_bytes(ct, i), &unit); + packets = nfnl_ct_get_packets(ct, i); + nl_dump_line(p, " %s %10llu %7.2f %s\n", names[i], packets, res, unit); + } } static int ct_compare(struct nl_object *_a, struct nl_object *_b, |