Add cleaning of IPv6 PinHoles + fix get_pinhole_info

This commit is contained in:
Thomas Bernard 2012-04-22 02:58:27 +02:00
parent 430d9c7240
commit 82355aca40
6 changed files with 53 additions and 62 deletions

View File

@ -1,4 +1,4 @@
/* $Id: miniupnpd.c,v 1.151 2012/04/06 17:24:37 nanard Exp $ */
/* $Id: miniupnpd.c,v 1.152 2012/04/22 00:55:44 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2012 Thomas Bernard
@ -1411,6 +1411,10 @@ main(int argc, char * * argv)
timeout.tv_usec = 0;
}
#endif
#endif
#ifdef ENABLE_6FC_SERVICE
/* Clean up expired IPv6 PinHoles */
upnp_clean_expired_pinholes(NULL);
#endif
/* select open sockets (SSDP, HTTP listen, and all HTTP soap sockets) */

View File

@ -1,4 +1,4 @@
/* $Id: pfpinhole.c,v 1.11 2012/04/21 23:31:31 nanard Exp $ */
/* $Id: pfpinhole.c,v 1.12 2012/04/22 00:55:51 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2012 Thomas Bernard
@ -256,7 +256,7 @@ int get_pinhole(unsigned short uid,
return -1;
}
int clean_pinehole_list(unsigned int * next_timestamp)
int clean_pinhole_list(unsigned int * next_timestamp)
{
int i;
struct pfioc_rule pr;

View File

@ -1,4 +1,4 @@
/* $Id: pfpinhole.h,v 1.5 2012/04/21 23:25:18 nanard Exp $ */
/* $Id: pfpinhole.h,v 1.6 2012/04/22 00:55:51 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2012 Thomas Bernard
@ -20,7 +20,7 @@ int get_pinhole(unsigned short uid,
char * int_client, int int_clientlen, unsigned short * int_port,
int * proto, unsigned int * timestamp);
int clean_pinehole_list(unsigned int * next_timestamp);
int clean_pinhole_list(unsigned int * next_timestamp);
#endif

View File

@ -1,4 +1,4 @@
/* $Id: testpfpinhole.c,v 1.8 2012/04/21 23:31:31 nanard Exp $ */
/* $Id: testpfpinhole.c,v 1.9 2012/04/22 00:55:51 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2012 Thomas Bernard
@ -73,7 +73,7 @@ int main(int argc, char * *argv)
print_pinhole(1);
print_pinhole(2);
clean_pinehole_list(NULL);
clean_pinhole_list(NULL);
ret = delete_pinhole(1);
printf("delete_pinhole() returned %d\n", ret);

View File

@ -1,4 +1,4 @@
/* $Id: upnpredirect.c,v 1.67 2012/04/20 21:52:57 nanard Exp $ */
/* $Id: upnpredirect.c,v 1.70 2012/04/22 00:55:46 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2012 Thomas Bernard
@ -764,17 +764,32 @@ upnp_add_inboundpinhole_internal(const char * raddr, unsigned short rport,
}
int
upnp_get_pinhole_info(const char * raddr,
unsigned short rport,
char * iaddr,
upnp_get_pinhole_info(unsigned short uid,
char * raddr, int raddrlen,
unsigned short * rport,
char * iaddr, int iaddrlen,
unsigned short * iport,
char * proto,
const char * uid,
char * lt)
int * proto,
unsigned int * leasetime)
{
/* TODO : to be done
* Call Firewall specific code to get IPv6 pinhole infos */
return 0;
/* Call Firewall specific code to get IPv6 pinhole infos */
#ifdef USE_PF
int r;
unsigned int timestamp;
r = get_pinhole(uid, raddr, raddrlen, rport,
iaddr, iaddrlen, iport, proto, &timestamp);
if(r >= 0) {
time_t current_time;
current_time = time(NULL);
if(timestamp > current_time)
*leasetime = timestamp - current_time;
else
*leasetime = 0;
}
return r;
#else
return -42; /* not implemented */
#endif
}
int
@ -799,15 +814,10 @@ upnp_update_inboundpinhole(const char * uid, const char * leasetime)
}
int
upnp_delete_inboundpinhole(const char * uid)
upnp_delete_inboundpinhole(unsigned short uid)
{
unsigned short uid_s;
if(!uid)
return -1;
uid_s = (unsigned short)atoi(uid);
#ifdef USE_PF
return delete_pinhole(uid_s);
return delete_pinhole(uid);
#else
return -1;
#endif
@ -1051,34 +1061,13 @@ upnp_get_pinhole_packets(const char * uid, int * packets)
}
int
upnp_update_expiredpinhole(void)
upnp_clean_expired_pinholes(unsigned int * next_timestamp)
{
#if 0
int r;
char uid[5], leaseTime[12];
r = get_rule_from_leasetime(uid, leaseTime);
if(r<0)
return r;
else
{
strcpy(nextpinholetoclean_uid, uid);
nextpinholetoclean_timestamp = atoi(leaseTime);
return 1;
}
#endif
#ifdef USE_PF
return clean_pinhole_list(next_timestamp);
#else
return 0;
}
int
upnp_clean_expiredpinhole()
{
#if 0
upnp_delete_inboundpinhole(nextpinholetoclean_uid);
return upnp_update_expiredpinhole();
#endif
return 0;
}
#endif

View File

@ -1,4 +1,4 @@
/* $Id: upnpredirect.h,v 1.27 2012/04/20 21:52:58 nanard Exp $ */
/* $Id: upnpredirect.h,v 1.30 2012/04/22 00:55:46 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2012 Thomas Bernard
@ -125,20 +125,18 @@ upnp_add_inboundpinhole(const char * raddr, unsigned short rport,
const char * iaddr, unsigned short iport,
int proto, unsigned int leasetime, int * uid);
int
upnp_add_inboundpinhole_internal(const char * raddr, unsigned short rport,
const char * iaddr, unsigned short iport,
const char * proto, int * uid);
/*
* return values :
* -4 not found
* -5 in another table
* -6 in another chain
* -7 in a chain but not a rule. (chain policy)
* -1 not found
* */
int
upnp_get_pinhole_info(const char * raddr, unsigned short rport, char * iaddr, unsigned short * iport, char * proto, const char * uid, char * lt);
upnp_get_pinhole_info(unsigned short uid,
char * raddr, int raddrlen,
unsigned short * rport,
char * iaddr, int iaddrlen,
unsigned short * iport,
int * proto,
unsigned int * leasetime);
/* update the lease time */
int
@ -146,7 +144,7 @@ upnp_update_inboundpinhole(const char * uid, const char * leasetime);
/* remove the inbound pinhole */
int
upnp_delete_inboundpinhole(const char * uid);
upnp_delete_inboundpinhole(unsigned short uid);
/* ... */
int
@ -158,7 +156,7 @@ upnp_get_pinhole_packets(const char * uid, int * packets);
/* ? */
int
upnp_clean_expiredpinhole(void);
upnp_clean_expired_pinholes(unsigned int * next_timestamp);
#endif /* ENABLE_6FC_SERVICE */