2023-02-11 22:53:38 +00:00
|
|
|
/* $Id: upnppermissions.h,v 1.14 2023/02/11 23:02:17 nanard Exp $ */
|
2011-09-28 19:13:20 +00:00
|
|
|
/* MiniUPnP project
|
2020-10-30 21:44:02 +00:00
|
|
|
* http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
|
2023-02-11 22:53:38 +00:00
|
|
|
* (c) 2006-2023 Thomas Bernard
|
2011-09-28 19:13:20 +00:00
|
|
|
* This software is subject to the conditions detailed
|
|
|
|
* in the LICENCE file provided within the distribution */
|
|
|
|
|
2012-09-20 20:52:51 +00:00
|
|
|
#ifndef UPNPPERMISSIONS_H_INCLUDED
|
|
|
|
#define UPNPPERMISSIONS_H_INCLUDED
|
2011-09-28 19:13:20 +00:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
2022-10-16 02:16:11 +00:00
|
|
|
|
2023-02-11 22:53:38 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2022-10-16 02:16:11 +00:00
|
|
|
#ifdef ENABLE_REGEX
|
|
|
|
#include <regex.h>
|
|
|
|
#endif
|
|
|
|
|
2011-09-28 19:13:20 +00:00
|
|
|
/* UPnP permission rule samples:
|
|
|
|
* allow 1024-65535 192.168.3.0/24 1024-65535
|
|
|
|
* deny 0-65535 192.168.1.125/32 0-65535 */
|
|
|
|
struct upnpperm {
|
|
|
|
enum {UPNPPERM_ALLOW=1, UPNPPERM_DENY=2 } type;
|
|
|
|
/* is it an allow or deny permission rule ? */
|
|
|
|
u_short eport_min, eport_max; /* external port range */
|
|
|
|
struct in_addr address, mask; /* ip/mask */
|
|
|
|
u_short iport_min, iport_max; /* internal port range */
|
2022-10-16 02:16:11 +00:00
|
|
|
char * re;
|
|
|
|
#ifdef ENABLE_REGEX
|
|
|
|
regex_t regex; /* matching regex */
|
|
|
|
#endif
|
2011-09-28 19:13:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* read_permission_line()
|
|
|
|
* returns: 0 line read okay
|
|
|
|
* -1 error reading line
|
|
|
|
*
|
|
|
|
* line sample :
|
2012-03-01 01:44:38 +00:00
|
|
|
* allow 1024-65535 192.168.3.0/24 1024-65535
|
2011-09-28 19:13:20 +00:00
|
|
|
* allow 22 192.168.4.33/32 22
|
|
|
|
* deny 0-65535 0.0.0.0/0 0-65535 */
|
|
|
|
int
|
|
|
|
read_permission_line(struct upnpperm * perm,
|
|
|
|
char * p);
|
|
|
|
|
2022-10-16 02:16:11 +00:00
|
|
|
void
|
|
|
|
free_permission_line(struct upnpperm * perm);
|
|
|
|
|
2012-03-01 01:44:38 +00:00
|
|
|
/* check_upnp_rule_against_permissions()
|
2011-09-28 19:13:20 +00:00
|
|
|
* returns: 0 if the upnp rule should be rejected,
|
|
|
|
* 1 if it could be accepted */
|
|
|
|
int
|
|
|
|
check_upnp_rule_against_permissions(const struct upnpperm * permary,
|
|
|
|
int n_perms,
|
|
|
|
u_short eport, struct in_addr address,
|
2022-10-16 02:16:11 +00:00
|
|
|
u_short iport, const char * desc);
|
2011-09-28 19:13:20 +00:00
|
|
|
|
2020-10-17 22:20:24 +00:00
|
|
|
/**
|
|
|
|
* Build an array of all allowed external ports (for the address and internal port)
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
get_permitted_ext_ports(uint32_t * allowed,
|
|
|
|
const struct upnpperm * permary, int n_perms,
|
2020-10-22 21:20:50 +00:00
|
|
|
in_addr_t addr, u_short iport);
|
2020-10-17 22:20:24 +00:00
|
|
|
|
2011-09-28 19:13:20 +00:00
|
|
|
#ifdef USE_MINIUPNPDCTL
|
|
|
|
void
|
|
|
|
write_permlist(int fd, const struct upnpperm * permary,
|
|
|
|
int nperms);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|