From 7800de9429fd43b7fcf59c9ad511e1cb27d4222a Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Wed, 29 Apr 2020 00:03:54 +0200 Subject: [PATCH] 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 --- miniupnpd/minissdp.c | 9 +++++++-- miniupnpd/miniupnpd.c | 33 ++++++++++++++++++++++++++++++--- miniupnpd/miniupnpd.conf | 3 +++ miniupnpd/miniupnpdtypes.h | 6 ++++-- 4 files changed, 44 insertions(+), 7 deletions(-) diff --git a/miniupnpd/minissdp.c b/miniupnpd/minissdp.c index 81dddbf..16d57d3 100644 --- a/miniupnpd/minissdp.c +++ b/miniupnpd/minissdp.c @@ -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); } diff --git a/miniupnpd/miniupnpd.c b/miniupnpd/miniupnpd.c index 1c6367c..1271a04 100644 --- a/miniupnpd/miniupnpd.c +++ b/miniupnpd/miniupnpd.c @@ -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 diff --git a/miniupnpd/miniupnpd.conf b/miniupnpd/miniupnpd.conf index 5337c65..6274f67 100644 --- a/miniupnpd/miniupnpd.conf +++ b/miniupnpd/miniupnpd.conf @@ -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 diff --git a/miniupnpd/miniupnpdtypes.h b/miniupnpd/miniupnpdtypes.h index 4e71c7e..c2fc3ef 100644 --- a/miniupnpd/miniupnpdtypes.h +++ b/miniupnpd/miniupnpdtypes.h @@ -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; };