[PATCH v1 5/6] netlink_netfilter: decode counters
Mathis Marion
Mathis.Marion at silabs.com
Thu Jun 12 09:56:05 UTC 2025
From: Mathis Marion <mathis.marion at silabs.com>
Signed-off-by: Mathis Marion <mathis.marion at silabs.com>
---
src/netlink_netfilter.c | 17 ++++++++++++++++-
src/xlat/nft_counter_attrs.in | 6 ++++++
2 files changed, 22 insertions(+), 1 deletion(-)
create mode 100644 src/xlat/nft_counter_attrs.in
diff --git a/src/netlink_netfilter.c b/src/netlink_netfilter.c
index 8fe11882c..fd226e05f 100644
--- a/src/netlink_netfilter.c
+++ b/src/netlink_netfilter.c
@@ -24,6 +24,7 @@
#include "xlat/nft_chain_attrs.h"
#include "xlat/nft_cmp_attrs.h"
#include "xlat/nft_cmp_ops.h"
+#include "xlat/nft_counter_attrs.h"
#include "xlat/nft_data_attrs.h"
#include "xlat/nft_expr_attrs.h"
#include "xlat/nft_flowtable_attrs.h"
@@ -285,6 +286,20 @@ static const struct nfta_decoder nfta_table_decoder = {
.size = ARRAY_SIZE(nfta_table_decoders),
};
+static bool decode_counters(struct tcb *tcp, kernel_ulong_t addr,
+ unsigned int len, const void *opaque_data)
+{
+ static const nla_decoder_t decoders[] = {
+ [NFTA_COUNTER_BYTES] = decode_nla_be64,
+ [NFTA_COUNTER_PACKETS] = decode_nla_be64,
+ [NFTA_COUNTER_PAD] = NULL,
+ };
+
+ decode_nlattr(tcp, addr, len, nft_counter_attrs, "NFTA_COUNTER_???",
+ decoders, ARRAY_SIZE(decoders), opaque_data);
+ return true;
+}
+
static const nla_decoder_t nfta_chain_decoders[] = {
[NFTA_CHAIN_TABLE] = decode_nla_str,
[NFTA_CHAIN_HANDLE] = decode_nla_be64,
@@ -293,7 +308,7 @@ static const nla_decoder_t nfta_chain_decoders[] = {
[NFTA_CHAIN_POLICY] = decode_verdict_code,
[NFTA_CHAIN_USE] = decode_nla_be32,
[NFTA_CHAIN_TYPE] = decode_nla_str,
- [NFTA_CHAIN_COUNTERS] = NULL, // TODO
+ [NFTA_CHAIN_COUNTERS] = decode_counters,
[NFTA_CHAIN_PAD] = NULL,
[NFTA_CHAIN_FLAGS] = decode_chain_flags,
[NFTA_CHAIN_ID] = decode_nla_be32,
diff --git a/src/xlat/nft_counter_attrs.in b/src/xlat/nft_counter_attrs.in
new file mode 100644
index 000000000..b113e640d
--- /dev/null
+++ b/src/xlat/nft_counter_attrs.in
@@ -0,0 +1,6 @@
+#unconditional
+#value_indexed
+NFTA_COUNTER_UNSPEC
+NFTA_COUNTER_BYTES
+NFTA_COUNTER_PACKETS
+NFTA_COUNTER_PAD
--
2.47.2
More information about the Strace-devel
mailing list