improve upnp_get_portmapping_number_of_entries()
This commit is contained in:
parent
ddf328845a
commit
26c46e5a49
|
@ -2,6 +2,7 @@ $Id: Changelog.txt,v 1.464 2020/05/10 17:57:56 nanard Exp $
|
|||
|
||||
2020/06/03:
|
||||
configure --disable-fork to disable going to background
|
||||
improve upnp_get_portmapping_number_of_entries()
|
||||
|
||||
2020/05/07:
|
||||
Linux: use libcap or libcap-ng to drop unnecessary capabilities
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* $Id: commonrdr.h,v 1.11 2019/10/02 22:12:02 nanard Exp $ */
|
||||
/* MiniUPnP project
|
||||
* (c) 2006-2019 Thomas Bernard
|
||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||
* (c) 2006-2020 Thomas Bernard
|
||||
* http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
|
||||
* This software is subject to the conditions detailed
|
||||
* in the LICENCE file provided within the distribution */
|
||||
#ifndef COMMONRDR_H_INCLUDED
|
||||
|
@ -19,6 +19,11 @@ init_redirect(void);
|
|||
void
|
||||
shutdown_redirect(void);
|
||||
|
||||
/* get_redirect_rule_count()
|
||||
* return value : -1 for error or the number of redirection rules */
|
||||
int
|
||||
get_redirect_rule_count(const char * ifname);
|
||||
|
||||
/* get_redirect_rule() gets internal IP and port from
|
||||
* interface, external port and protocol
|
||||
* return value :
|
||||
|
|
|
@ -522,6 +522,31 @@ add_filter_rule2(const char * ifname,
|
|||
#endif
|
||||
}
|
||||
|
||||
/* get_redirect_rule_count()
|
||||
* return value : -1 for error or the number of rdr rules */
|
||||
int
|
||||
get_redirect_rule_count(const char * ifname)
|
||||
{
|
||||
struct pfioc_rule pr;
|
||||
UNUSED(ifname);
|
||||
|
||||
if(dev<0) {
|
||||
syslog(LOG_ERR, "pf device is not open");
|
||||
return -1;
|
||||
}
|
||||
memset(&pr, 0, sizeof(pr));
|
||||
strlcpy(pr.anchor, anchor_name, MAXPATHLEN);
|
||||
#ifndef PF_NEWSTYLE
|
||||
pr.rule.action = PF_RDR;
|
||||
#endif
|
||||
if(ioctl(dev, DIOCGETRULES, &pr) < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ioctl(dev, DIOCGETRULES, ...): %m");
|
||||
return -1;
|
||||
}
|
||||
return pr.nr;
|
||||
}
|
||||
|
||||
/* get_redirect_rule()
|
||||
* return value : 0 success (found)
|
||||
* -1 = error or rule not found */
|
||||
|
|
|
@ -579,11 +579,13 @@ upnp_delete_redirection(unsigned short eport, const char * protocol)
|
|||
return _upnp_delete_redir(eport, proto_atoi(protocol));
|
||||
}
|
||||
|
||||
/* upnp_get_portmapping_number_of_entries()
|
||||
* TODO: improve this code. */
|
||||
/* upnp_get_portmapping_number_of_entries() */
|
||||
int
|
||||
upnp_get_portmapping_number_of_entries()
|
||||
{
|
||||
#if defined(USE_PF)
|
||||
return get_redirect_rule_count(ext_if_name);
|
||||
#else
|
||||
int n = 0, r = 0;
|
||||
unsigned short eport, iport;
|
||||
char protocol[4], iaddr[32], desc[64], rhost[32];
|
||||
|
@ -598,6 +600,7 @@ upnp_get_portmapping_number_of_entries()
|
|||
n++;
|
||||
} while(r==0);
|
||||
return (n-1);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* functions used to remove unused rules
|
||||
|
|
Loading…
Reference in New Issue