minissdpd: set multicast TTL to 2 by default and configurable

fixes #140
This commit is contained in:
Thomas Bernard 2015-07-21 17:40:51 +02:00
parent d456889b52
commit ed4a01d2d6
4 changed files with 49 additions and 29 deletions

View File

@ -1,4 +1,7 @@
$Id: Changelog.txt,v 1.39 2014/12/05 13:42:59 nanard Exp $
$Id: Changelog.txt,v 1.41 2015/07/21 15:39:36 nanard Exp $
2015/07/21:
set multicast TTL to 2 by default and configurable
2015/05/27:
support larger buffer size (useful for type 3 requests)

View File

@ -1,4 +1,4 @@
/* $Id: minissdpd.c,v 1.47 2015/05/27 12:43:14 nanard Exp $ */
/* $Id: minissdpd.c,v 1.48 2015/07/21 15:39:36 nanard Exp $ */
/* MiniUPnP project
* (c) 2007-2015 Thomas Bernard
* website : http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
@ -1062,6 +1062,7 @@ int main(int argc, char * * argv)
struct sockaddr_in6 sendername6;
socklen_t sendername6_len;
#endif /* ENABLE_IPV6 */
unsigned char ttl = 2; /* UDA says it should default to 2 */
LIST_INIT(&reqlisthead);
LIST_INIT(&servicelisthead);
@ -1069,28 +1070,38 @@ int main(int argc, char * * argv)
/* process command line */
for(i=1; i<argc; i++)
{
if(0==strcmp(argv[i], "-i")) {
lan_addr = malloc(sizeof(struct lan_addr_s));
if(lan_addr == NULL) {
fprintf(stderr, "malloc(%d) FAILED\n", (int)sizeof(struct lan_addr_s));
break;
}
if(parselanaddr(lan_addr, argv[++i]) != 0) {
fprintf(stderr, "can't parse \"%s\" as a valid address or interface name\n", argv[i]);
free(lan_addr);
} else {
LIST_INSERT_HEAD(&lan_addrs, lan_addr, list);
}
} else if(0==strcmp(argv[i], "-d"))
if(0==strcmp(argv[i], "-d"))
debug_flag = 1;
else if(0==strcmp(argv[i], "-s"))
sockpath = argv[++i];
else if(0==strcmp(argv[i], "-p"))
pidfilename = argv[++i];
#ifdef ENABLE_IPV6
else if(0==strcmp(argv[i], "-6"))
ipv6 = 1;
#endif /* ENABLE_IPV6 */
else {
if((i + 1) >= argc) {
fprintf(stderr, "option %s needs an argument.\n", argv[i]);
break;
}
if(0==strcmp(argv[i], "-i")) {
lan_addr = malloc(sizeof(struct lan_addr_s));
if(lan_addr == NULL) {
fprintf(stderr, "malloc(%d) FAILED\n", (int)sizeof(struct lan_addr_s));
break;
}
if(parselanaddr(lan_addr, argv[++i]) != 0) {
fprintf(stderr, "can't parse \"%s\" as a valid address or interface name\n", argv[i]);
free(lan_addr);
} else {
LIST_INSERT_HEAD(&lan_addrs, lan_addr, list);
}
} else if(0==strcmp(argv[i], "-s"))
sockpath = argv[++i];
else if(0==strcmp(argv[i], "-p"))
pidfilename = argv[++i];
else if(0==strcmp(argv[i], "-t"))
ttl = (unsigned char)atoi(argv[++i]);
else
fprintf(stderr, "unknown commandline option %s.\n", argv[i]);
}
}
if(lan_addrs.lh_first == NULL)
{
@ -1099,7 +1110,7 @@ int main(int argc, char * * argv)
#ifdef ENABLE_IPV6
"[-6] "
#endif /* ENABLE_IPV6 */
"[-s socket] [-p pidfile] "
"[-s socket] [-p pidfile] [-t TTL] "
"-i <interface> [-i <interface2>] ...\n",
argv[0]);
fprintf(stderr,
@ -1143,7 +1154,7 @@ int main(int argc, char * * argv)
/* open route/interface config changes socket */
s_ifacewatch = OpenAndConfInterfaceWatchSocket();
/* open UDP socket(s) for receiving SSDP packets */
s_ssdp = OpenAndConfSSDPReceiveSocket(0);
s_ssdp = OpenAndConfSSDPReceiveSocket(0, ttl);
if(s_ssdp < 0)
{
syslog(LOG_ERR, "Cannot open socket for receiving SSDP messages, exiting");
@ -1152,7 +1163,7 @@ int main(int argc, char * * argv)
}
#ifdef ENABLE_IPV6
if(ipv6) {
s_ssdp6 = OpenAndConfSSDPReceiveSocket(1);
s_ssdp6 = OpenAndConfSSDPReceiveSocket(1, ttl);
if(s_ssdp6 < 0)
{
syslog(LOG_ERR, "Cannot open socket for receiving SSDP messages (IPv6), exiting");

View File

@ -1,7 +1,7 @@
/* $Id: openssdpsocket.c,v 1.15 2014/11/28 16:20:58 nanard Exp $ */
/* $Id: openssdpsocket.c,v 1.16 2015/07/21 15:39:37 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2014 Thomas Bernard
* (c) 2006-2015 Thomas Bernard
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */
@ -102,7 +102,7 @@ AddDropMulticastMembership(int s, struct lan_addr_s * lan_addr, int ipv6, int dr
}
int
OpenAndConfSSDPReceiveSocket(int ipv6)
OpenAndConfSSDPReceiveSocket(int ipv6, unsigned char ttl)
{
int s;
int opt = 1;
@ -192,10 +192,15 @@ OpenAndConfSSDPReceiveSocket(int ipv6)
}
else
#endif /* SSDP_LISTEN_ON_SPECIFIC_ADDR */
sockname.sin_addr.s_addr = htonl(INADDR_ANY);
sockname.sin_addr.s_addr = htonl(INADDR_ANY);
sockname_len = sizeof(struct sockaddr_in);
#endif /* ENABLE_IPV6 */
if(setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0)
{
syslog(LOG_WARNING, "setsockopt(IP_MULTICAST_TTL): %m");
}
if(setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0)
{
syslog(LOG_WARNING, "setsockopt(SO_REUSEADDR): %m");

View File

@ -1,7 +1,7 @@
/* $Id: openssdpsocket.h,v 1.6 2014/11/28 16:20:58 nanard Exp $ */
/* $Id: openssdpsocket.h,v 1.7 2015/07/21 15:39:38 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2014 Thomas Bernard
* (c) 2006-2015 Thomas Bernard
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */
#ifndef OPENSSDPSOCKET_H_INCLUDED
@ -13,10 +13,11 @@
* Open a socket and configure it for receiving SSDP packets
*
* @param ipv6 open INET6 or INET socket
* @param ttl multicast TTL
* @return socket
*/
int
OpenAndConfSSDPReceiveSocket(int ipv6);
OpenAndConfSSDPReceiveSocket(int ipv6, unsigned char ttl);
/**
* Add or Drop the multicast membership for SSDP on the interface