Finalizing netfilter version of get_pinhole_info()

This commit is contained in:
Thomas Bernard 2012-05-08 00:21:03 +02:00
parent ddbc22865f
commit 457092c60a
3 changed files with 42 additions and 11 deletions

View File

@ -1,4 +1,7 @@
$Id: Changelog.txt,v 1.280 2012/05/01 22:37:52 nanard Exp $
$Id: Changelog.txt,v 1.281 2012/05/07 15:40:03 nanard Exp $
2012/05/07:
Finalizing netfilter version of get_pinhole_info()
2012/05/01:
Move IPv6FirewallControl related code from upnpredirect.c to upnppinhole.c

View File

@ -1,4 +1,4 @@
/* $Id: iptpinhole.c,v 1.4 2012/05/01 22:37:53 nanard Exp $ */
/* $Id: iptpinhole.c,v 1.6 2012/05/07 15:40:04 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2012 Thomas Bernard
@ -336,11 +336,36 @@ get_pinhole_info(unsigned short uid,
*proto = p->proto;
if(timestamp)
*timestamp = p->timestamp;
/* TODO */
if(packets || bytes) {
/* theses informations need to be read from netfilter */
IP6TC_HANDLE h;
const struct ip6t_entry * e;
const struct ip6t_entry_match * match;
h = ip6tc_init("filter");
if(!h) {
syslog(LOG_ERR, "ip6tc_init error : %s", ip6tc_strerror(errno));
return -1;
}
for(e = ip6tc_first_rule(miniupnpd_v6_filter_chain, h);
e;
e = ip6tc_next_rule(e, h)) {
if((e->ipv6.proto == p->proto) &&
(0 == memcmp(&e->ipv6.src, &p->saddr, sizeof(e->ipv6.src))) &&
(0 == memcmp(&e->ipv6.dst, &p->daddr, sizeof(e->ipv6.dst)))) {
const struct ip6t_tcp * info;
match = (const struct ip6t_entry_match *)&e->elems;
info = (const struct ip6t_tcp *)&match->data;
if((info->spts[0] == p->sport) && (info->dpts[0] == p->dport)) {
if(packets)
*packets = 0;
*packets = e->counters.pcnt;
if(bytes)
*bytes = 0;
*bytes = e->counters.bcnt;
break;
}
}
}
ip6tc_free(h);
}
return 0;
}

View File

@ -1,4 +1,4 @@
/* $Id: upnppinhole.c,v 1.2 2012/05/01 22:37:53 nanard Exp $ */
/* $Id: upnppinhole.c,v 1.3 2012/05/07 15:40:04 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2012 Thomas Bernard
@ -220,11 +220,14 @@ upnp_get_pinhole_info(unsigned short uid,
#if defined(USE_PF) || defined(USE_NETFILTER)
int r;
unsigned int timestamp;
u_int64_t packets_tmp, bytes_tmp;
u_int64_t packets_tmp;
/*u_int64_t bytes_tmp;*/
r = get_pinhole_info(uid, raddr, raddrlen, rport,
iaddr, iaddrlen, iport, proto, &timestamp,
&packets_tmp, &bytes_tmp);
iaddr, iaddrlen, iport, proto,
leasetime ? &timestamp : NULL,
packets ? &packets_tmp : NULL,
NULL/*&bytes_tmp*/);
if(r >= 0) {
if(leasetime) {
time_t current_time;