From f3b772c10b782196060fe39ca6da142ba75e43d9 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Thu, 19 Jul 2018 18:32:05 +0200 Subject: xtables: introduce save_chain callback In preparation for ebtables-save implementation, introduce a callback for convenient per-family formatting of chains in save output. Signed-off-by: Phil Sutter Signed-off-by: Florian Westphal --- iptables/nft-shared.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'iptables/nft-shared.c') diff --git a/iptables/nft-shared.c b/iptables/nft-shared.c index 60b539c8..66db7ed1 100644 --- a/iptables/nft-shared.c +++ b/iptables/nft-shared.c @@ -16,6 +16,7 @@ #include #include #include +#include #include @@ -802,6 +803,16 @@ void save_counters(const void *data) (unsigned long long)cs->counters.bcnt); } +void nft_ipv46_save_chain(const struct nftnl_chain *c, const char *policy) +{ + const char *chain = nftnl_chain_get_str(c, NFTNL_CHAIN_NAME); + uint64_t pkts = nftnl_chain_get_u64(c, NFTNL_CHAIN_PACKETS); + uint64_t bytes = nftnl_chain_get_u64(c, NFTNL_CHAIN_BYTES); + + printf(":%s %s [%"PRIu64":%"PRIu64"]\n", + chain, policy ?: "-", pkts, bytes); +} + void save_matches_and_target(struct xtables_rule_match *m, struct xtables_target *target, const char *jumpto, uint8_t flags, const void *fw) -- cgit v1.2.3