Skip to content

Commit

Permalink
ct_dump_stats: detect when stats are not available
Browse files Browse the repository at this point in the history
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
  • Loading branch information
socketpair committed Aug 28, 2012
1 parent 052a131 commit a0f1c0e
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions lib/netfilter/ct_obj.c
Expand Up @@ -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,
Expand Down

0 comments on commit a0f1c0e

Please sign in to comment.