From 9b32a523bf284a661310b22b3fe8716ab31294ca Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Thu, 4 Jun 2020 00:37:17 +0200 Subject: [PATCH] improve get_redirect_rule_count() for netfilter_nft too --- miniupnpd/netfilter_nft/nftnlrdr.c | 14 ++++++++++++++ miniupnpd/upnpredirect.c | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/miniupnpd/netfilter_nft/nftnlrdr.c b/miniupnpd/netfilter_nft/nftnlrdr.c index f3ae1f4..23e78d6 100644 --- a/miniupnpd/netfilter_nft/nftnlrdr.c +++ b/miniupnpd/netfilter_nft/nftnlrdr.c @@ -538,6 +538,20 @@ get_redirect_rule(const char * ifname, unsigned short eport, int proto, timestamp, packets, bytes); } +/* get_redirect_rule_count() + * return value : -1 for error or the number of redirection rules */ +int +get_redirect_rule_count(const char * ifname) +{ + int n = 0; + + refresh_nft_cache_redirect(); + LIST_FOREACH(r, &head_redirect, entry) { + n++; + } + return n; +} + /* * get_redirect_rule_by_index() * return -1 when the rule was not found diff --git a/miniupnpd/upnpredirect.c b/miniupnpd/upnpredirect.c index 25c3744..4a159c1 100644 --- a/miniupnpd/upnpredirect.c +++ b/miniupnpd/upnpredirect.c @@ -583,7 +583,7 @@ upnp_delete_redirection(unsigned short eport, const char * protocol) int upnp_get_portmapping_number_of_entries() { -#if defined(USE_PF) +#if defined(USE_PF) || defined(USE_NFTABLES) return get_redirect_rule_count(ext_if_name); #else int n = 0, r = 0;