improve get_redirect_rule_count() for netfilter_nft too

This commit is contained in:
Thomas Bernard 2020-06-04 00:37:17 +02:00
parent 95d611e7a0
commit 9b32a523bf
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C
2 changed files with 15 additions and 1 deletions

View File

@ -538,6 +538,20 @@ get_redirect_rule(const char * ifname, unsigned short eport, int proto,
timestamp, packets, bytes); 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() * get_redirect_rule_by_index()
* return -1 when the rule was not found * return -1 when the rule was not found

View File

@ -583,7 +583,7 @@ upnp_delete_redirection(unsigned short eport, const char * protocol)
int int
upnp_get_portmapping_number_of_entries() 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); return get_redirect_rule_count(ext_if_name);
#else #else
int n = 0, r = 0; int n = 0, r = 0;