miniupnpd: fix for bridges

you now can setup :
listening_ip=igb1 bridge0 xxx0 xxx1 ...

miniupnpd will use igd1 address, but will not complain when receiving
packets from either igb1, bridge0, xxx0 or xxx1

fixes #379
see also #408
This commit is contained in:
Thomas Bernard 2020-04-29 00:03:54 +02:00
parent a965520085
commit 7800de9429
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C
4 changed files with 44 additions and 7 deletions

View File

@ -2,7 +2,7 @@
/* vim: tabstop=4 shiftwidth=4 noexpandtab
* MiniUPnP project
* http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
* (c) 2006-2019 Thomas Bernard
* (c) 2006-2020 Thomas Bernard
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */
@ -991,11 +991,16 @@ ProcessSSDPData(int s, const char *bufr, int n,
/* get the string representation of the sender address */
sockaddr_to_string(sender, sender_str, sizeof(sender_str));
lan_addr = get_lan_for_peer(sender);
if(source_if >= 0)
if(source_if > 0)
{
if(lan_addr != NULL)
{
#ifndef MULTIPLE_EXTERNAL_IP
if(lan_addr->index != (unsigned)source_if && lan_addr->index != 0
&& !(lan_addr->add_indexes & (1UL << (source_if - 1))))
#else
if(lan_addr->index != (unsigned)source_if && lan_addr->index != 0)
#endif
{
syslog(LOG_WARNING, "interface index not matching %u != %d", lan_addr->index, source_if);
}

View File

@ -912,7 +912,7 @@ static int
parselanaddr(struct lan_addr_s * lan_addr, const char * str)
{
const char * p;
int n;
unsigned int n;
char tmp[16];
memset(lan_addr, 0, sizeof(struct lan_addr_s));
@ -958,7 +958,7 @@ parselanaddr(struct lan_addr_s * lan_addr, const char * str)
while(*p && (*p=='.' || isdigit(*p)))
p++;
n = p - q;
if(n>15)
if(n >= sizeof(tmp))
goto parselan_error;
memcpy(tmp, q, n);
tmp[n] = '\0';
@ -1003,12 +1003,39 @@ parselanaddr(struct lan_addr_s * lan_addr, const char * str)
}
}
}
#else
while(*p) {
/* skip spaces */
while(*p && isspace(*p))
p++;
if(*p) {
unsigned int index;
n = 0;
while(p[n] && !isspace(p[n]) && n < sizeof(tmp)) {
tmp[n] = p[n];
n++;
}
if(n >= sizeof(tmp)) {
fprintf(stderr, "Cannot parse '%s'\n", p);
break;
}
tmp[n] = '\0';
index = if_nametoindex(tmp);
if(index == 0) {
fprintf(stderr, "Cannot get index for network interface %s\n",
tmp);
} else {
lan_addr->add_indexes |= (1UL << (index - 1));
}
p += n;
}
}
#endif
if(lan_addr->ifname[0] != '\0')
{
lan_addr->index = if_nametoindex(lan_addr->ifname);
if(lan_addr->index == 0)
fprintf(stderr, "Cannot get index for network interface %s",
fprintf(stderr, "Cannot get index for network interface %s\n",
lan_addr->ifname);
}
#ifdef ENABLE_IPV6

View File

@ -38,6 +38,9 @@
# When MULTIPLE_EXTERNAL_IP is enabled, the external IP
# address associated with the subnet follows. For example:
# listening_ip=192.168.0.1/24 88.22.44.13
# When MULTIPLE_EXTERNAL_IP is disabled, you can list associated network
# interfaces (for bridges)
# listening_ip=bridge0 em0 wlan0
#listening_ip=192.168.0.1/24
#listening_ip=10.5.0.0/16
#listening_ip=eth0

View File

@ -1,7 +1,7 @@
/* $Id: miniupnpdtypes.h,v 1.4 2012/04/06 15:27:21 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2012 Thomas Bernard
* http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
* (c) 2006-2020 Thomas Bernard
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */
#ifndef MINIUPNPDTYPES_H_INCLUDED
@ -22,6 +22,8 @@ struct lan_addr_s {
#ifdef MULTIPLE_EXTERNAL_IP
char ext_ip_str[16];
struct in_addr ext_ip_addr;
#else
unsigned long add_indexes; /* mask of indexes of associated interfaces */
#endif
LIST_ENTRY(lan_addr_s) list;
};