miniupnpd: use epoch_origin for NAT-PMP as well

see #254
This commit is contained in:
Thomas Bernard 2017-11-27 21:47:35 +01:00
parent 165c5f0d57
commit cc0fad78d7
4 changed files with 18 additions and 6 deletions

View File

@ -1,6 +1,6 @@
/* $Id: natpmp.c,v 1.52 2015/05/27 12:43:14 nanard Exp $ */
/* MiniUPnP project
* (c) 2007-2015 Thomas Bernard
* (c) 2007-2017 Thomas Bernard
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */
@ -244,7 +244,10 @@ void ProcessIncomingNATPMPPacket(int s, unsigned char *msg_buff, int len,
/* setting response TIME STAMP :
* time elapsed since its port mapping table was initialized on
* startup or reset for any other reason */
WRITENU32(resp+4, time(NULL) - startup_time);
if(epoch_origin == 0) {
epoch_origin = startup_time;
}
WRITENU32(resp+4, time(NULL) - epoch_origin);
if(req[0] > 0) {
/* invalid version */
syslog(LOG_WARNING, "unsupported NAT-PMP version : %u",
@ -433,7 +436,10 @@ void SendNATPMPPublicAddressChangeNotification(int * sockets, int n_sockets)
/* seconds since "start of epoch" :
* time elapsed since the port mapping table was initialized on
* startup or reset for any other reason */
WRITENU32(notif+4, time(NULL) - startup_time);
if(epoch_origin == 0) {
epoch_origin = startup_time;
}
WRITENU32(notif+4, time(NULL) - epoch_origin);
#ifndef MULTIPLE_EXTERNAL_IP
FillPublicAddressResponse(notif, 0);
if(notif[3])

View File

@ -103,9 +103,6 @@ struct pcp_server_info {
/* default server settings, highest version supported is the default */
static const struct pcp_server_info this_server_info = {2};
/* origin for "epoch time" sent into responses */
time_t epoch_origin = 0;
/* structure holding information from PCP msg*/
/* all variables are in host byte order except IP addresses */
typedef struct pcp_info {

View File

@ -31,6 +31,11 @@ unsigned long upstream_bitrate = 0;
/* startup time */
time_t startup_time = 0;
#if defined(ENABLE_NATPMP) || defined(ENABLE_PCP)
/* origin for "epoch time" sent into NATPMP and PCP responses */
time_t epoch_origin = 0;
#endif /* defined(ENABLE_NATPMP) || defined(ENABLE_PCP) */
#ifdef ENABLE_PCP
/* for PCP */
unsigned long int min_lifetime = 120;

View File

@ -32,6 +32,10 @@ extern unsigned long upstream_bitrate;
/* statup time */
extern time_t startup_time;
#if defined(ENABLE_NATPMP) || defined(ENABLE_PCP)
/* origin for "epoch time" sent into NATPMP and PCP responses */
extern time_t epoch_origin;
#endif /* defined(ENABLE_NATPMP) || defined(ENABLE_PCP) */
extern unsigned long int min_lifetime;
extern unsigned long int max_lifetime;