Working on DeletePinhole() and GetPinholePackets()
This commit is contained in:
parent
82355aca40
commit
d27f35ccde
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: pfpinhole.c,v 1.12 2012/04/22 00:55:51 nanard Exp $ */
|
/* $Id: pfpinhole.c,v 1.15 2012/04/22 23:36:41 nanard Exp $ */
|
||||||
/* MiniUPnP project
|
/* MiniUPnP project
|
||||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||||
* (c) 2012 Thomas Bernard
|
* (c) 2012 Thomas Bernard
|
||||||
|
@ -199,13 +199,14 @@ int delete_pinhole(unsigned short uid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* not found */
|
/* not found */
|
||||||
return -1;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_pinhole(unsigned short uid,
|
int get_pinhole(unsigned short uid,
|
||||||
char * rem_host, int rem_hostlen, unsigned short * rem_port,
|
char * rem_host, int rem_hostlen, unsigned short * rem_port,
|
||||||
char * int_client, int int_clientlen, unsigned short * int_port,
|
char * int_client, int int_clientlen, unsigned short * int_port,
|
||||||
int * proto, unsigned int * timestamp)
|
int * proto, unsigned int * timestamp,
|
||||||
|
u_int64_t * packets, u_int64_t * bytes)
|
||||||
{
|
{
|
||||||
int i, n;
|
int i, n;
|
||||||
struct pfioc_rule pr;
|
struct pfioc_rule pr;
|
||||||
|
@ -239,23 +240,40 @@ int get_pinhole(unsigned short uid,
|
||||||
p = tmp_label;
|
p = tmp_label;
|
||||||
strsep(&p, " ");
|
strsep(&p, " ");
|
||||||
if(0 == strcmp(tmp_label, label_start)) {
|
if(0 == strcmp(tmp_label, label_start)) {
|
||||||
if(inet_ntop(AF_INET6, &pr.rule.src.addr.v.a.addr.v6, rem_host, rem_hostlen) == NULL) {
|
if(rem_host && (inet_ntop(AF_INET6, &pr.rule.src.addr.v.a.addr.v6, rem_host, rem_hostlen) == NULL)) {
|
||||||
return -2;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if(rem_port)
|
||||||
*rem_port = ntohs(pr.rule.src.port[0]);
|
*rem_port = ntohs(pr.rule.src.port[0]);
|
||||||
if(inet_ntop(AF_INET6, &pr.rule.dst.addr.v.a.addr.v6, int_client, int_clientlen) == NULL) {
|
if(int_client && (inet_ntop(AF_INET6, &pr.rule.dst.addr.v.a.addr.v6, int_client, int_clientlen) == NULL)) {
|
||||||
return -2;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if(int_port)
|
||||||
*int_port = ntohs(pr.rule.dst.port[0]);
|
*int_port = ntohs(pr.rule.dst.port[0]);
|
||||||
|
if(proto)
|
||||||
*proto = pr.rule.proto;
|
*proto = pr.rule.proto;
|
||||||
|
if(timestamp)
|
||||||
sscanf(p, "ts-%u", timestamp);
|
sscanf(p, "ts-%u", timestamp);
|
||||||
|
#ifdef PFRULE_INOUT_COUNTS
|
||||||
|
if(packets)
|
||||||
|
*packets = pr.rule.packets[0] + pr.rule.packets[1];
|
||||||
|
if(bytes)
|
||||||
|
*bytes = pr.rule.bytes[0] + pr.rule.bytes[1];
|
||||||
|
#else
|
||||||
|
if(packets)
|
||||||
|
*packets = pr.rule.packets;
|
||||||
|
if(bytes)
|
||||||
|
*bytes = pr.rule.bytes;
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* not found */
|
/* not found */
|
||||||
return -1;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* return the number of rules removed
|
||||||
|
* or a negative integer in case of error */
|
||||||
int clean_pinhole_list(unsigned int * next_timestamp)
|
int clean_pinhole_list(unsigned int * next_timestamp)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -265,6 +283,7 @@ int clean_pinhole_list(unsigned int * next_timestamp)
|
||||||
int uid;
|
int uid;
|
||||||
unsigned int min_ts = UINT_MAX;
|
unsigned int min_ts = UINT_MAX;
|
||||||
int min_uid = INT_MAX, max_uid = -1;
|
int min_uid = INT_MAX, max_uid = -1;
|
||||||
|
int n = 0;
|
||||||
|
|
||||||
if(dev<0) {
|
if(dev<0) {
|
||||||
syslog(LOG_ERR, "pf device is not open");
|
syslog(LOG_ERR, "pf device is not open");
|
||||||
|
@ -303,6 +322,7 @@ int clean_pinhole_list(unsigned int * next_timestamp)
|
||||||
syslog(LOG_ERR, "ioctl(dev, DIOCCHANGERULE, ...) PF_CHANGE_REMOVE: %m");
|
syslog(LOG_ERR, "ioctl(dev, DIOCCHANGERULE, ...) PF_CHANGE_REMOVE: %m");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
n++;
|
||||||
#ifndef PF_NEWSTYLE
|
#ifndef PF_NEWSTYLE
|
||||||
pr.rule.action = PF_PASS;
|
pr.rule.action = PF_PASS;
|
||||||
#endif
|
#endif
|
||||||
|
@ -329,7 +349,7 @@ int clean_pinhole_list(unsigned int * next_timestamp)
|
||||||
next_uid = 1;
|
next_uid = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return n; /* number of rules removed */
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* ENABLE_IPV6 */
|
#endif /* ENABLE_IPV6 */
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: pfpinhole.h,v 1.6 2012/04/22 00:55:51 nanard Exp $ */
|
/* $Id: pfpinhole.h,v 1.7 2012/04/22 23:08:51 nanard Exp $ */
|
||||||
/* MiniUPnP project
|
/* MiniUPnP project
|
||||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||||
* (c) 2012 Thomas Bernard
|
* (c) 2012 Thomas Bernard
|
||||||
|
@ -18,7 +18,8 @@ int delete_pinhole(unsigned short uid);
|
||||||
int get_pinhole(unsigned short uid,
|
int get_pinhole(unsigned short uid,
|
||||||
char * rem_host, int rem_hostlen, unsigned short * rem_port,
|
char * rem_host, int rem_hostlen, unsigned short * rem_port,
|
||||||
char * int_client, int int_clientlen, unsigned short * int_port,
|
char * int_client, int int_clientlen, unsigned short * int_port,
|
||||||
int * proto, unsigned int * timestamp);
|
int * proto, unsigned int * timestamp,
|
||||||
|
u_int64_t * packets, u_int64_t * bytes);
|
||||||
|
|
||||||
int clean_pinhole_list(unsigned int * next_timestamp);
|
int clean_pinhole_list(unsigned int * next_timestamp);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: testpfpinhole.c,v 1.9 2012/04/22 00:55:51 nanard Exp $ */
|
/* $Id: testpfpinhole.c,v 1.10 2012/04/22 23:12:51 nanard Exp $ */
|
||||||
/* MiniUPnP project
|
/* MiniUPnP project
|
||||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||||
* (c) 2012 Thomas Bernard
|
* (c) 2012 Thomas Bernard
|
||||||
|
@ -30,17 +30,20 @@ static int print_pinhole(int uid)
|
||||||
unsigned short int_port;
|
unsigned short int_port;
|
||||||
int proto;
|
int proto;
|
||||||
unsigned int timestamp;
|
unsigned int timestamp;
|
||||||
|
u_int64_t packets, bytes;
|
||||||
|
|
||||||
r = get_pinhole((unsigned short)uid,
|
r = get_pinhole((unsigned short)uid,
|
||||||
rem_host, sizeof(rem_host), &rem_port,
|
rem_host, sizeof(rem_host), &rem_port,
|
||||||
int_client, sizeof(int_client), &int_port,
|
int_client, sizeof(int_client), &int_port,
|
||||||
&proto, ×tamp);
|
&proto, ×tamp,
|
||||||
|
&packets, &bytes);
|
||||||
if(r < 0) {
|
if(r < 0) {
|
||||||
fprintf(stderr, "get_pinhole(%d) returned %d\n", uid, r);
|
fprintf(stderr, "get_pinhole(%d) returned %d\n", uid, r);
|
||||||
} else {
|
} else {
|
||||||
printf("pinhole %d : [%s]:%hu => [%s]:%hu proto=%d ts=%u\n",
|
printf("pinhole %d : [%s]:%hu => [%s]:%hu proto=%d ts=%u\n",
|
||||||
uid, rem_host, rem_port, int_client, int_port,
|
uid, rem_host, rem_port, int_client, int_port,
|
||||||
proto, timestamp);
|
proto, timestamp);
|
||||||
|
printf(" packets=%llu bytes=%llu\n", packets, bytes);
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: upnpredirect.c,v 1.70 2012/04/22 00:55:46 nanard Exp $ */
|
/* $Id: upnpredirect.c,v 1.72 2012/04/22 23:25:22 nanard Exp $ */
|
||||||
/* MiniUPnP project
|
/* MiniUPnP project
|
||||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||||
* (c) 2006-2012 Thomas Bernard
|
* (c) 2006-2012 Thomas Bernard
|
||||||
|
@ -763,6 +763,14 @@ upnp_add_inboundpinhole_internal(const char * raddr, unsigned short rport,
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* upnp_get_pinhole_info()
|
||||||
|
* return values :
|
||||||
|
* 0 OK
|
||||||
|
* -1 Internal error
|
||||||
|
* -2 NOT FOUND (no such entry)
|
||||||
|
* ..
|
||||||
|
* -42 Not implemented
|
||||||
|
*/
|
||||||
int
|
int
|
||||||
upnp_get_pinhole_info(unsigned short uid,
|
upnp_get_pinhole_info(unsigned short uid,
|
||||||
char * raddr, int raddrlen,
|
char * raddr, int raddrlen,
|
||||||
|
@ -770,14 +778,17 @@ upnp_get_pinhole_info(unsigned short uid,
|
||||||
char * iaddr, int iaddrlen,
|
char * iaddr, int iaddrlen,
|
||||||
unsigned short * iport,
|
unsigned short * iport,
|
||||||
int * proto,
|
int * proto,
|
||||||
unsigned int * leasetime)
|
unsigned int * leasetime,
|
||||||
|
unsigned int * packets)
|
||||||
{
|
{
|
||||||
/* Call Firewall specific code to get IPv6 pinhole infos */
|
/* Call Firewall specific code to get IPv6 pinhole infos */
|
||||||
#ifdef USE_PF
|
#ifdef USE_PF
|
||||||
int r;
|
int r;
|
||||||
unsigned int timestamp;
|
unsigned int timestamp;
|
||||||
|
u_int64_t packets_tmp, bytes_tmp;
|
||||||
r = get_pinhole(uid, raddr, raddrlen, rport,
|
r = get_pinhole(uid, raddr, raddrlen, rport,
|
||||||
iaddr, iaddrlen, iport, proto, ×tamp);
|
iaddr, iaddrlen, iport, proto, ×tamp,
|
||||||
|
&packets_tmp, &bytes_tmp);
|
||||||
if(r >= 0) {
|
if(r >= 0) {
|
||||||
time_t current_time;
|
time_t current_time;
|
||||||
current_time = time(NULL);
|
current_time = time(NULL);
|
||||||
|
@ -785,6 +796,8 @@ upnp_get_pinhole_info(unsigned short uid,
|
||||||
*leasetime = timestamp - current_time;
|
*leasetime = timestamp - current_time;
|
||||||
else
|
else
|
||||||
*leasetime = 0;
|
*leasetime = 0;
|
||||||
|
if(packets)
|
||||||
|
*packets = (unsigned int)packets_tmp;
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
#else
|
#else
|
||||||
|
@ -1040,26 +1053,6 @@ upnp_check_pinhole_working(const char * uid,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
upnp_get_pinhole_packets(const char * uid, int * packets)
|
|
||||||
{
|
|
||||||
/* TODO : to be implemented */
|
|
||||||
#if 0
|
|
||||||
int line=0, r;
|
|
||||||
char cmd[256];
|
|
||||||
r = check_rule_from_file(uid, &line);
|
|
||||||
if(r < 0)
|
|
||||||
return r;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
snprintf(cmd, sizeof(cmd), "ip6tables -L MINIUPNPD %d -v", line);
|
|
||||||
return retrieve_packets(cmd, &line, packets);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
upnp_clean_expired_pinholes(unsigned int * next_timestamp)
|
upnp_clean_expired_pinholes(unsigned int * next_timestamp)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: upnpredirect.h,v 1.30 2012/04/22 00:55:46 nanard Exp $ */
|
/* $Id: upnpredirect.h,v 1.31 2012/04/22 23:08:48 nanard Exp $ */
|
||||||
/* MiniUPnP project
|
/* MiniUPnP project
|
||||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||||
* (c) 2006-2012 Thomas Bernard
|
* (c) 2006-2012 Thomas Bernard
|
||||||
|
@ -136,7 +136,8 @@ upnp_get_pinhole_info(unsigned short uid,
|
||||||
char * iaddr, int iaddrlen,
|
char * iaddr, int iaddrlen,
|
||||||
unsigned short * iport,
|
unsigned short * iport,
|
||||||
int * proto,
|
int * proto,
|
||||||
unsigned int * leasetime);
|
unsigned int * leasetime,
|
||||||
|
unsigned int * packets);
|
||||||
|
|
||||||
/* update the lease time */
|
/* update the lease time */
|
||||||
int
|
int
|
||||||
|
@ -150,10 +151,6 @@ upnp_delete_inboundpinhole(unsigned short uid);
|
||||||
int
|
int
|
||||||
upnp_check_pinhole_working(const char * uid, char * eaddr, char * iaddr, unsigned short * eport, unsigned short * iport, char * protocol, int * rulenum_used);
|
upnp_check_pinhole_working(const char * uid, char * eaddr, char * iaddr, unsigned short * eport, unsigned short * iport, char * protocol, int * rulenum_used);
|
||||||
|
|
||||||
/* number of packets that went through the pinhole */
|
|
||||||
int
|
|
||||||
upnp_get_pinhole_packets(const char * uid, int * packets);
|
|
||||||
|
|
||||||
/* ? */
|
/* ? */
|
||||||
int
|
int
|
||||||
upnp_clean_expired_pinholes(unsigned int * next_timestamp);
|
upnp_clean_expired_pinholes(unsigned int * next_timestamp);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: upnpsoap.c,v 1.99 2012/04/22 00:02:46 nanard Exp $ */
|
/* $Id: upnpsoap.c,v 1.104 2012/04/22 23:36:20 nanard Exp $ */
|
||||||
/* MiniUPnP project
|
/* MiniUPnP project
|
||||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||||
* (c) 2006-2012 Thomas Bernard
|
* (c) 2006-2012 Thomas Bernard
|
||||||
|
@ -1224,7 +1224,6 @@ PinholeVerification(struct upnphttp * h, char * int_ip, unsigned short int_port)
|
||||||
{
|
{
|
||||||
inet_ntop(AF_INET6, (struct in6_addr *) p, int_ip, sizeof(struct in6_addr));
|
inet_ntop(AF_INET6, (struct in6_addr *) p, int_ip, sizeof(struct in6_addr));
|
||||||
result_ip = *((struct in6_addr *) p);
|
result_ip = *((struct in6_addr *) p);
|
||||||
/* fprintf(stderr, "upnpsoap / AddPinhole: assuming int addr = %s", int_ip); */
|
|
||||||
/* TODO : deal with more than one ip per hostname */
|
/* TODO : deal with more than one ip per hostname */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1432,15 +1431,17 @@ clear_and_exit:
|
||||||
static void
|
static void
|
||||||
UpdatePinhole(struct upnphttp * h, const char * action)
|
UpdatePinhole(struct upnphttp * h, const char * action)
|
||||||
{
|
{
|
||||||
int r, n;
|
int r/*, n*/;
|
||||||
static const char resp[] =
|
static const char resp[] =
|
||||||
"<u:UpdatePinholeResponse "
|
"<u:UpdatePinholeResponse "
|
||||||
"xmlns:u=\"urn:schemas-upnp-org:service:WANIPv6FirewallControl:1\">"
|
"xmlns:u=\"urn:schemas-upnp-org:service:WANIPv6FirewallControl:1\">"
|
||||||
"</u:UpdatePinholeResponse>";
|
"</u:UpdatePinholeResponse>";
|
||||||
struct NameValueParserData data;
|
struct NameValueParserData data;
|
||||||
const char * uid, * leaseTime;
|
const char * uid, * leaseTime;
|
||||||
|
#if 0
|
||||||
char iaddr[40], proto[6], lt[12];
|
char iaddr[40], proto[6], lt[12];
|
||||||
unsigned short iport;
|
unsigned short iport;
|
||||||
|
#endif
|
||||||
int ltime = -1;
|
int ltime = -1;
|
||||||
|
|
||||||
if(CheckStatus(h)==0)
|
if(CheckStatus(h)==0)
|
||||||
|
@ -1461,6 +1462,7 @@ UpdatePinhole(struct upnphttp * h, const char * action)
|
||||||
|
|
||||||
/* Check that client is not deleting an pinhole
|
/* Check that client is not deleting an pinhole
|
||||||
* it doesn't have access to, because of its public access */
|
* it doesn't have access to, because of its public access */
|
||||||
|
#if 0
|
||||||
n = upnp_get_pinhole_info(0, 0, iaddr, &iport, proto, uid, lt);
|
n = upnp_get_pinhole_info(0, 0, iaddr, &iport, proto, uid, lt);
|
||||||
if (n > 0)
|
if (n > 0)
|
||||||
{
|
{
|
||||||
|
@ -1470,6 +1472,7 @@ UpdatePinhole(struct upnphttp * h, const char * action)
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
syslog(LOG_INFO, "%s: (inbound) updating lease duration to %s for pinhole with ID: %s", action, leaseTime, uid);
|
syslog(LOG_INFO, "%s: (inbound) updating lease duration to %s for pinhole with ID: %s", action, leaseTime, uid);
|
||||||
|
|
||||||
|
@ -1546,7 +1549,7 @@ GetOutboundPinholeTimeout(struct upnphttp * h, const char * action)
|
||||||
static void
|
static void
|
||||||
DeletePinhole(struct upnphttp * h, const char * action)
|
DeletePinhole(struct upnphttp * h, const char * action)
|
||||||
{
|
{
|
||||||
int r, n;
|
int n;
|
||||||
|
|
||||||
static const char resp[] =
|
static const char resp[] =
|
||||||
"<u:DeletePinholeResponse "
|
"<u:DeletePinholeResponse "
|
||||||
|
@ -1554,73 +1557,81 @@ DeletePinhole(struct upnphttp * h, const char * action)
|
||||||
"</u:DeletePinholeResponse>";
|
"</u:DeletePinholeResponse>";
|
||||||
|
|
||||||
struct NameValueParserData data;
|
struct NameValueParserData data;
|
||||||
const char * uid;
|
const char * uid_str;
|
||||||
char iaddr[40], proto[6], lt[12];
|
char iaddr[INET6_ADDRSTRLEN];
|
||||||
|
int proto;
|
||||||
unsigned short iport;
|
unsigned short iport;
|
||||||
|
unsigned int leasetime;
|
||||||
|
int uid;
|
||||||
|
|
||||||
if(CheckStatus(h)==0)
|
if(CheckStatus(h)==0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ParseNameValue(h->req_buf + h->req_contentoff, h->req_contentlen, &data);
|
ParseNameValue(h->req_buf + h->req_contentoff, h->req_contentlen, &data);
|
||||||
uid = GetValueFromNameValueList(&data, "UniqueID");
|
uid_str = GetValueFromNameValueList(&data, "UniqueID");
|
||||||
|
uid = uid_str ? atoi(uid_str) : -1;
|
||||||
if(!uid || atoi(uid) < 0 || atoi(uid) > 65535)
|
|
||||||
{
|
|
||||||
ClearNameValueList(&data);
|
ClearNameValueList(&data);
|
||||||
|
|
||||||
|
if(uid < 0 || uid > 65535)
|
||||||
|
{
|
||||||
SoapError(h, 402, "Invalid Args");
|
SoapError(h, 402, "Invalid Args");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check that client is not deleting an pinhole
|
/* Check that client is not deleting an pinhole
|
||||||
* it doesn't have access to, because of its public access */
|
* it doesn't have access to, because of its public access */
|
||||||
n = upnp_get_pinhole_info(0, 0, iaddr, &iport, proto, uid, lt);
|
n = upnp_get_pinhole_info(uid, NULL, 0, NULL,
|
||||||
if (n > 0)
|
iaddr, sizeof(iaddr), &iport,
|
||||||
|
&proto, &leasetime, NULL);
|
||||||
|
if (n >= 0)
|
||||||
{
|
{
|
||||||
if(PinholeVerification(h, iaddr, iport)==0)
|
if(!PinholeVerification(h, iaddr, iport))
|
||||||
{
|
return;
|
||||||
ClearNameValueList(&data);
|
|
||||||
return ;
|
|
||||||
}
|
}
|
||||||
}
|
else if(n == -2)
|
||||||
|
|
||||||
syslog(LOG_INFO, "%s: (inbound) delete pinhole with ID: %s", action, uid);
|
|
||||||
|
|
||||||
r = upnp_delete_inboundpinhole(uid);
|
|
||||||
|
|
||||||
if(r < 0)
|
|
||||||
{
|
{
|
||||||
syslog(LOG_INFO, "%s: (inbound) failed to remove pinhole with ID: %s", action, uid);
|
|
||||||
if(r==-4)
|
|
||||||
SoapError(h, 704, "NoSuchEntry");
|
SoapError(h, 704, "NoSuchEntry");
|
||||||
else
|
return;
|
||||||
SoapError(h, 501, "ActionFailed");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
syslog(LOG_INFO, "%s: (inbound) pinhole successfully removed", action);
|
SoapError(h, 501, "ActionFailed");
|
||||||
BuildSendAndCloseSoapResp(h, resp, sizeof(resp)-1);
|
return;
|
||||||
}
|
}
|
||||||
ClearNameValueList(&data);
|
|
||||||
|
n = upnp_delete_inboundpinhole(uid);
|
||||||
|
if(n < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_INFO, "%s: (inbound) failed to remove pinhole with ID: %d",
|
||||||
|
action, uid);
|
||||||
|
SoapError(h, 501, "ActionFailed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
syslog(LOG_INFO, "%s: (inbound) pinhole with ID %d successfully removed",
|
||||||
|
action, uid);
|
||||||
|
BuildSendAndCloseSoapResp(h, resp, sizeof(resp)-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
CheckPinholeWorking(struct upnphttp * h, const char * action)
|
CheckPinholeWorking(struct upnphttp * h, const char * action)
|
||||||
{
|
{
|
||||||
int r, d;
|
#if 0
|
||||||
|
|
||||||
static const char resp[] =
|
static const char resp[] =
|
||||||
"<u:%sResponse "
|
"<u:%sResponse "
|
||||||
"xmlns:u=\"%s\">"
|
"xmlns:u=\"%s\">"
|
||||||
"<IsWorking>%d</IsWorking>"
|
"<IsWorking>%d</IsWorking>"
|
||||||
"</u:%sResponse>";
|
"</u:%sResponse>";
|
||||||
|
|
||||||
char body[512];
|
char body[512];
|
||||||
int bodylen;
|
int bodylen;
|
||||||
|
int r, d;
|
||||||
|
#endif
|
||||||
struct NameValueParserData data;
|
struct NameValueParserData data;
|
||||||
const char * uid;
|
const char * uid;
|
||||||
|
#if 0
|
||||||
char eaddr[40], iaddr[40], proto[6], lt[12];
|
char eaddr[40], iaddr[40], proto[6], lt[12];
|
||||||
unsigned short eport, iport;
|
unsigned short eport, iport;
|
||||||
int isWorking = 0;
|
int isWorking = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
if(CheckStatus(h)==0)
|
if(CheckStatus(h)==0)
|
||||||
return;
|
return;
|
||||||
|
@ -1637,6 +1648,7 @@ CheckPinholeWorking(struct upnphttp * h, const char * action)
|
||||||
|
|
||||||
/* Check that client is not checking a pinhole
|
/* Check that client is not checking a pinhole
|
||||||
* it doesn't have access to, because of its public access */
|
* it doesn't have access to, because of its public access */
|
||||||
|
#if 0
|
||||||
r = upnp_get_pinhole_info(eaddr, eport, iaddr, &iport, proto, uid, lt);
|
r = upnp_get_pinhole_info(eaddr, eport, iaddr, &iport, proto, uid, lt);
|
||||||
if (r > 0)
|
if (r > 0)
|
||||||
{
|
{
|
||||||
|
@ -1694,6 +1706,7 @@ CheckPinholeWorking(struct upnphttp * h, const char * action)
|
||||||
SoapError(h, 704, "NoSuchEntry");
|
SoapError(h, 704, "NoSuchEntry");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
SoapError(h, 501, "ActionFailed");
|
SoapError(h, 501, "ActionFailed");
|
||||||
ClearNameValueList(&data);
|
ClearNameValueList(&data);
|
||||||
|
@ -1705,66 +1718,60 @@ CheckPinholeWorking(struct upnphttp * h, const char * action)
|
||||||
static void
|
static void
|
||||||
GetPinholePackets(struct upnphttp * h, const char * action)
|
GetPinholePackets(struct upnphttp * h, const char * action)
|
||||||
{
|
{
|
||||||
int r, n;
|
|
||||||
|
|
||||||
static const char resp[] =
|
static const char resp[] =
|
||||||
"<u:%sResponse "
|
"<u:%sResponse "
|
||||||
"xmlns:u=\"%s\">"
|
"xmlns:u=\"%s\">"
|
||||||
"<PinholePackets>%d</PinholePackets>"
|
"<PinholePackets>%u</PinholePackets>"
|
||||||
"</u:%sResponse>";
|
"</u:%sResponse>";
|
||||||
|
|
||||||
char body[512];
|
char body[512];
|
||||||
int bodylen;
|
int bodylen;
|
||||||
struct NameValueParserData data;
|
struct NameValueParserData data;
|
||||||
const char * uid;
|
const char * uid_str;
|
||||||
char iaddr[40], proto[6], lt[12];
|
int n;
|
||||||
|
char iaddr[INET6_ADDRSTRLEN];
|
||||||
unsigned short iport;
|
unsigned short iport;
|
||||||
int pinholePackets = 0;
|
unsigned int packets = 0;
|
||||||
|
int uid;
|
||||||
|
int proto;
|
||||||
|
unsigned int leasetime;
|
||||||
|
|
||||||
if(CheckStatus(h)==0)
|
if(CheckStatus(h)==0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ParseNameValue(h->req_buf + h->req_contentoff, h->req_contentlen, &data);
|
ParseNameValue(h->req_buf + h->req_contentoff, h->req_contentlen, &data);
|
||||||
uid = GetValueFromNameValueList(&data, "UniqueID");
|
uid_str = GetValueFromNameValueList(&data, "UniqueID");
|
||||||
|
uid = uid_str ? atoi(uid_str) : -1;
|
||||||
if(!uid)
|
|
||||||
{
|
|
||||||
ClearNameValueList(&data);
|
ClearNameValueList(&data);
|
||||||
|
|
||||||
|
if(uid < 0 || uid > 65535)
|
||||||
|
{
|
||||||
SoapError(h, 402, "Invalid Args");
|
SoapError(h, 402, "Invalid Args");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check that client is not getting infos of a pinhole
|
/* Check that client is not getting infos of a pinhole
|
||||||
* it doesn't have access to, because of its public access */
|
* it doesn't have access to, because of its public access */
|
||||||
r = upnp_get_pinhole_info(0, 0, iaddr, &iport, proto, uid, lt);
|
n = upnp_get_pinhole_info(uid, NULL, 0, NULL,
|
||||||
if (r > 0)
|
iaddr, sizeof(iaddr), &iport,
|
||||||
|
&proto, &leasetime, &packets);
|
||||||
|
if (n >= 0)
|
||||||
{
|
{
|
||||||
if(PinholeVerification(h, iaddr, iport)==0)
|
if(PinholeVerification(h, iaddr, iport)==0)
|
||||||
{
|
{
|
||||||
ClearNameValueList(&data);
|
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
n = upnp_get_pinhole_packets(uid, &pinholePackets);
|
|
||||||
if(n > 0)
|
|
||||||
{
|
|
||||||
bodylen = snprintf(body, sizeof(body), resp,
|
|
||||||
action, "urn:schemas-upnp-org:service:WANIPv6FirewallControl:1",
|
|
||||||
pinholePackets, action);
|
|
||||||
BuildSendAndCloseSoapResp(h, body, bodylen);
|
|
||||||
}
|
|
||||||
else if(r == -4 || r == -1)
|
else if(r == -4 || r == -1)
|
||||||
{
|
{
|
||||||
SoapError(h, 704, "NoSuchEntry");
|
SoapError(h, 704, "NoSuchEntry");
|
||||||
}
|
}
|
||||||
else
|
#endif
|
||||||
{
|
|
||||||
SoapError(h, 501, "ActionFailed");
|
bodylen = snprintf(body, sizeof(body), resp,
|
||||||
ClearNameValueList(&data);
|
action, "urn:schemas-upnp-org:service:WANIPv6FirewallControl:1",
|
||||||
return ;
|
packets, action);
|
||||||
}
|
BuildSendAndCloseSoapResp(h, body, bodylen);
|
||||||
ClearNameValueList(&data);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue