miniupnpd: possibility to disable ipv6 at runtime

fixes #049
This commit is contained in:
Thomas Bernard 2014-02-06 10:55:28 +01:00
parent dce25a2e27
commit 18f02dccb3
6 changed files with 63 additions and 26 deletions

View File

@ -1,4 +1,7 @@
$Id: Changelog.txt,v 1.348 2014/02/03 09:32:09 nanard Exp $
$Id: Changelog.txt,v 1.350 2014/02/06 09:52:03 nanard Exp $
2014/02/06:
possibility to disable ipv6 at runtime
2014/02/03:
PCP : Add support for ANNOUNCE requests

View File

@ -1,7 +1,7 @@
/* $Id: minissdp.c,v 1.56 2014/02/01 16:35:37 nanard Exp $ */
/* $Id: minissdp.c,v 1.57 2014/02/06 09:52:03 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2013 Thomas Bernard
* (c) 2006-2014 Thomas Bernard
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */
@ -280,9 +280,16 @@ OpenAndConfSSDPNotifySockets(int * sockets)
goto error;
i++;
#ifdef ENABLE_IPV6
sockets[i] = OpenAndConfSSDPNotifySocketIPv6(lan_addr->index);
if(sockets[i] < 0)
goto error;
if(ipv6_enabled)
{
sockets[i] = OpenAndConfSSDPNotifySocketIPv6(lan_addr->index);
if(sockets[i] < 0)
goto error;
}
else
{
sockets[i] = -1;
}
i++;
#endif
}
@ -568,8 +575,11 @@ SendSSDPNotifies2(int * sockets,
lifetime, 0);
i++;
#ifdef ENABLE_IPV6
SendSSDPNotifies(sockets[i], ipv6_addr_for_http_with_brackets, port,
lifetime, 1);
if(sockets[i] >= 0)
{
SendSSDPNotifies(sockets[i], ipv6_addr_for_http_with_brackets, port,
lifetime, 1);
}
i++;
#endif
}

View File

@ -1,4 +1,4 @@
/* $Id: miniupnpd.c,v 1.182 2014/02/03 08:37:32 nanard Exp $ */
/* $Id: miniupnpd.c,v 1.183 2014/02/06 09:52:01 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2014 Thomas Bernard
@ -116,7 +116,8 @@ OpenAndConfHTTPSocket(unsigned short port)
int s;
int i = 1;
#ifdef ENABLE_IPV6
struct sockaddr_in6 listenname;
struct sockaddr_in6 listenname6;
struct sockaddr_in listenname4;
#else
struct sockaddr_in listenname;
#endif
@ -124,7 +125,7 @@ OpenAndConfHTTPSocket(unsigned short port)
if( (s = socket(
#ifdef ENABLE_IPV6
PF_INET6,
ipv6_enabled ? PF_INET6 : PF_INET,
#else
PF_INET,
#endif
@ -153,19 +154,35 @@ OpenAndConfHTTPSocket(unsigned short port)
}
#ifdef ENABLE_IPV6
memset(&listenname, 0, sizeof(struct sockaddr_in6));
listenname.sin6_family = AF_INET6;
listenname.sin6_port = htons(port);
listenname.sin6_addr = in6addr_any;
listenname_len = sizeof(struct sockaddr_in6);
if(ipv6_enabled)
{
memset(&listenname6, 0, sizeof(struct sockaddr_in6));
listenname6.sin6_family = AF_INET6;
listenname6.sin6_port = htons(port);
listenname6.sin6_addr = in6addr_any;
listenname_len = sizeof(struct sockaddr_in6);
} else {
memset(&listenname4, 0, sizeof(struct sockaddr_in));
listenname4.sin_family = AF_INET;
listenname4.sin_port = htons(port);
listenname4.sin_addr.s_addr = htonl(INADDR_ANY);
listenname_len = sizeof(struct sockaddr_in);
}
#else
memset(&listenname, 0, sizeof(struct sockaddr_in));
listenname.sin_family = AF_INET;
listenname.sin_port = htons(port);
listenname.sin_addr.s_addr = htonl(INADDR_ANY);
listenname_len = sizeof(struct sockaddr_in);
#endif
#ifdef ENABLE_IPV6
if(bind(s,
ipv6_enabled ? (struct sockaddr *)&listenname6 : (struct sockaddr *)&listenname4,
listenname_len) < 0)
#else
if(bind(s, (struct sockaddr *)&listenname, listenname_len) < 0)
#endif
{
syslog(LOG_ERR, "bind(http): %m");
close(s);
@ -181,6 +198,7 @@ OpenAndConfHTTPSocket(unsigned short port)
return s;
}
#ifdef ENABLE_NFQUEUE
int identify_ip_protocol(char *payload) {
@ -1347,7 +1365,7 @@ main(int argc, char * * argv)
int sudpv6 = -1; /* IP v6 socket for receiving SSDP */
#endif
#ifdef ENABLE_NATPMP
int * snatpmp = NULL;
int * snatpmp = NULL; /* also used for PCP */
#endif
#ifdef ENABLE_NFQUEUE
int nfqh = -1;
@ -1455,7 +1473,8 @@ main(int argc, char * * argv)
ipv6_addr_for_http_with_brackets);
} else {
memcpy(ipv6_addr_for_http_with_brackets, "[::1]", 6);
syslog(LOG_WARNING, "no HTTP IPv6 address");
syslog(LOG_WARNING, "no HTTP IPv6 address, disabling IPv6");
ipv6_enabled = 0;
}
#endif
@ -1470,10 +1489,13 @@ main(int argc, char * * argv)
}
}
#ifdef ENABLE_IPV6
sudpv6 = OpenAndConfSSDPReceiveSocket(1);
if(sudpv6 < 0)
if(ipv6_enabled)
{
syslog(LOG_WARNING, "Failed to open socket for receiving SSDP (IP v6).");
sudpv6 = OpenAndConfSSDPReceiveSocket(1);
if(sudpv6 < 0)
{
syslog(LOG_WARNING, "Failed to open socket for receiving SSDP (IP v6).");
}
}
#endif

View File

@ -1,4 +1,4 @@
/* $Id: upnpglobalvars.c,v 1.33 2014/02/03 08:37:32 nanard Exp $ */
/* $Id: upnpglobalvars.c,v 1.34 2014/02/06 09:52:03 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2014 Thomas Bernard
@ -121,6 +121,7 @@ struct lan_addr_list lan_addrs;
#ifdef ENABLE_IPV6
/* ipv6 address used for HTTP */
char ipv6_addr_for_http_with_brackets[64];
int ipv6_enabled = 1;
#endif
/* Path of the Unix socket used to communicate with MiniSSDPd */

View File

@ -1,7 +1,7 @@
/* $Id: upnpglobalvars.h,v 1.35 2013/06/13 13:21:30 nanard Exp $ */
/* $Id: upnpglobalvars.h,v 1.37 2014/02/06 09:52:03 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2012 Thomas Bernard
* (c) 2006-2014 Thomas Bernard
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */
@ -139,6 +139,7 @@ extern struct lan_addr_list lan_addrs;
#ifdef ENABLE_IPV6
/* ipv6 address used for HTTP */
extern char ipv6_addr_for_http_with_brackets[64];
extern int ipv6_enabled;
#endif
extern const char * minissdpdsocketpath;

View File

@ -1,7 +1,7 @@
/* $Id: upnputils.c,v 1.7 2013/04/20 09:03:18 nanard Exp $ */
/* $Id: upnputils.c,v 1.8 2014/02/05 17:00:26 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2013 Thomas Bernard
* (c) 2006-2014 Thomas Bernard
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */