dect
/
libnl
Archived
13
0
Fork 0

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
This commit is contained in:
Коренберг Марк (дома) 2012-08-27 23:39:29 +06:00 committed by Коренберг Марк
parent 052a131193
commit a0f1c0e281
1 changed files with 19 additions and 8 deletions

View File

@ -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);
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;
}
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);
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);
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,