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 /* 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
@ -1411,6 +1411,10 @@ main(int argc, char * * argv)
timeout.tv_usec = 0; timeout.tv_usec = 0;
} }
#endif #endif
#endif
#ifdef ENABLE_6FC_SERVICE
/* Clean up expired IPv6 PinHoles */
upnp_clean_expired_pinholes(NULL);
#endif #endif
/* select open sockets (SSDP, HTTP listen, and all HTTP soap sockets) */ /* 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 /* 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
@ -256,7 +256,7 @@ int get_pinhole(unsigned short uid,
return -1; return -1;
} }
int clean_pinehole_list(unsigned int * next_timestamp) int clean_pinhole_list(unsigned int * next_timestamp)
{ {
int i; int i;
struct pfioc_rule pr; 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 /* 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
@ -20,7 +20,7 @@ int get_pinhole(unsigned short uid,
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);
int clean_pinehole_list(unsigned int * next_timestamp); int clean_pinhole_list(unsigned int * next_timestamp);
#endif #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 /* 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
@ -73,7 +73,7 @@ int main(int argc, char * *argv)
print_pinhole(1); print_pinhole(1);
print_pinhole(2); print_pinhole(2);
clean_pinehole_list(NULL); clean_pinhole_list(NULL);
ret = delete_pinhole(1); ret = delete_pinhole(1);
printf("delete_pinhole() returned %d\n", ret); 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 /* 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
@ -764,17 +764,32 @@ upnp_add_inboundpinhole_internal(const char * raddr, unsigned short rport,
} }
int int
upnp_get_pinhole_info(const char * raddr, upnp_get_pinhole_info(unsigned short uid,
unsigned short rport, char * raddr, int raddrlen,
char * iaddr, unsigned short * rport,
char * iaddr, int iaddrlen,
unsigned short * iport, unsigned short * iport,
char * proto, int * proto,
const char * uid, unsigned int * leasetime)
char * lt)
{ {
/* TODO : to be done /* Call Firewall specific code to get IPv6 pinhole infos */
* Call Firewall specific code to get IPv6 pinhole infos */ #ifdef USE_PF
return 0; 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 int
@ -799,15 +814,10 @@ upnp_update_inboundpinhole(const char * uid, const char * leasetime)
} }
int 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 #ifdef USE_PF
return delete_pinhole(uid_s); return delete_pinhole(uid);
#else #else
return -1; return -1;
#endif #endif
@ -1051,34 +1061,13 @@ upnp_get_pinhole_packets(const char * uid, int * packets)
} }
int int
upnp_update_expiredpinhole(void) upnp_clean_expired_pinholes(unsigned int * next_timestamp)
{ {
#if 0 #ifdef USE_PF
int r; return clean_pinhole_list(next_timestamp);
char uid[5], leaseTime[12]; #else
r = get_rule_from_leasetime(uid, leaseTime);
if(r<0)
return r;
else
{
strcpy(nextpinholetoclean_uid, uid);
nextpinholetoclean_timestamp = atoi(leaseTime);
return 1;
}
#endif
return 0; return 0;
}
int
upnp_clean_expiredpinhole()
{
#if 0
upnp_delete_inboundpinhole(nextpinholetoclean_uid);
return upnp_update_expiredpinhole();
#endif #endif
return 0;
} }
#endif #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 /* 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
@ -125,20 +125,18 @@ upnp_add_inboundpinhole(const char * raddr, unsigned short rport,
const char * iaddr, unsigned short iport, const char * iaddr, unsigned short iport,
int proto, unsigned int leasetime, int * uid); 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 : * return values :
* -4 not found * -1 not found
* -5 in another table
* -6 in another chain
* -7 in a chain but not a rule. (chain policy)
* */ * */
int 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 */ /* update the lease time */
int int
@ -146,7 +144,7 @@ upnp_update_inboundpinhole(const char * uid, const char * leasetime);
/* remove the inbound pinhole */ /* remove the inbound pinhole */
int int
upnp_delete_inboundpinhole(const char * uid); upnp_delete_inboundpinhole(unsigned short uid);
/* ... */ /* ... */
int int
@ -158,7 +156,7 @@ upnp_get_pinhole_packets(const char * uid, int * packets);
/* ? */ /* ? */
int int
upnp_clean_expiredpinhole(void); upnp_clean_expired_pinholes(unsigned int * next_timestamp);
#endif /* ENABLE_6FC_SERVICE */ #endif /* ENABLE_6FC_SERVICE */