netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH conntrack-tools] conntrack: add support for CLASH_RESOLVED counter
@ 2020-08-25 22:53 Florian Westphal
  0 siblings, 0 replies; only message in thread
From: Florian Westphal @ 2020-08-25 22:53 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Florian Westphal

While at it, also allow to display up to 4 counters that are sent
by kernel but that we do not know.

This is useful to list counters that a new kernel supports with
and older release of conntrack-tools.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 src/conntrack.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/conntrack.c b/src/conntrack.c
index fb4e5be86ed8..a26fa60bbbc9 100644
--- a/src/conntrack.c
+++ b/src/conntrack.c
@@ -1986,11 +1986,13 @@ static int nfct_stats_attr_cb(const struct nlattr *attr, void *data)
 	return MNL_CB_OK;
 }
 
+#define UNKNOWN_STATS_NUM 4
+
 static int nfct_stats_cb(const struct nlmsghdr *nlh, void *data)
 {
-	struct nlattr *tb[CTA_STATS_MAX+1] = {};
+	struct nlattr *tb[CTA_STATS_MAX + UNKNOWN_STATS_NUM + 1] = {};
 	struct nfgenmsg *nfg = mnl_nlmsg_get_payload(nlh);
-	const char *attr2name[CTA_STATS_MAX+1] = {
+	const char *attr2name[CTA_STATS_MAX + UNKNOWN_STATS_NUM + 1] = {
 		[CTA_STATS_SEARCHED]	= "searched",
 		[CTA_STATS_FOUND]	= "found",
 		[CTA_STATS_NEW]		= "new",
@@ -2004,6 +2006,15 @@ static int nfct_stats_cb(const struct nlmsghdr *nlh, void *data)
 		[CTA_STATS_EARLY_DROP]	= "early_drop",
 		[CTA_STATS_ERROR]	= "error",
 		[CTA_STATS_SEARCH_RESTART] = "search_restart",
+		[CTA_STATS_CLASH_RESOLVE] = "clash_resolve",
+
+		/* leave at end.  Allows to show counters supported
+		 * by newer kernel with older conntrack-tools release.
+		 */
+		[CTA_STATS_MAX + 1] = "unknown1",
+		[CTA_STATS_MAX + 2] = "unknown2",
+		[CTA_STATS_MAX + 3] = "unknown3",
+		[CTA_STATS_MAX + 4] = "unknown4",
 	};
 	int i;
 
@@ -2011,7 +2022,7 @@ static int nfct_stats_cb(const struct nlmsghdr *nlh, void *data)
 
 	printf("cpu=%-4u\t", ntohs(nfg->res_id));
 
-	for (i=0; i<CTA_STATS_MAX+1; i++) {
+	for (i=0; i <= CTA_STATS_MAX + UNKNOWN_STATS_NUM; i++) {
 		if (tb[i]) {
 			printf("%s=%u ",
 				attr2name[i], ntohl(mnl_attr_get_u32(tb[i])));
-- 
2.26.2


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-08-25 22:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-25 22:53 [PATCH conntrack-tools] conntrack: add support for CLASH_RESOLVED counter Florian Westphal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).