miniupnpd: remove int_if_name, use ip_mreqn if available

This commit is contained in:
Thomas Bernard 2015-08-25 20:33:47 +02:00
parent 138ec9e972
commit 0cf182e51e
5 changed files with 39 additions and 19 deletions

View File

@ -125,6 +125,7 @@ case $OS_NAME in
if [ $VER -ge 700049 ]; then
echo "#define PFRULE_INOUT_COUNTS" >> ${CONFIGFILE}
fi
HAVE_IP_MREQN=1
# new way to see which one to use PF or IPF.
# see http://miniupnp.tuxfamily.org/forum/viewtopic.php?p=957
if [ -f /etc/rc.subr ] && [ -f /etc/rc.conf ] ; then
@ -213,6 +214,10 @@ case $OS_NAME in
KERNVERC=`echo $OS_VERSION | awk -F. '{print $3}'`
KERNVERD=`echo $OS_VERSION | awk -F. '{print $4}'`
#echo "$KERNVERA.$KERNVERB.$KERNVERC.$KERNVERD"
# from the 2.4 version, struct ip_mreqn instead of struct ip_mreq
if [ \( $KERNVERA -ge 3 \) -o \( $KERNVERA -eq 2 -a $KERNVERB -ge 4 \) ]; then
HAVE_IP_MREQN=1
fi
# Debian GNU/Linux special case
if [ -f /etc/debian_version ]; then
OS_NAME=Debian
@ -434,6 +439,11 @@ else
fi
echo "" >> ${CONFIGFILE}
if [ -n "$HAVE_IP_MREQN" ]; then
echo "#define HAVE_IP_MREQN" >> ${CONFIGFILE}
echo "" >> ${CONFIGFILE}
fi
echo "/* Enable the support of IGD v2 specification." >> ${CONFIGFILE}
echo " * This is not fully tested yet and can cause incompatibilities with some" >> ${CONFIGFILE}
echo " * control points, so enable with care. */" >> ${CONFIGFILE}

View File

@ -44,25 +44,42 @@
#endif
/* AddMulticastMembership()
* param s socket
* param ifaddr ip v4 address
* param s socket
* param lan_addr lan address
*/
static int
AddMulticastMembership(int s, in_addr_t ifaddr)
AddMulticastMembership(int s, struct lan_addr_s * lan_addr)
{
#ifndef HAVE_IP_MREQN
/* The ip_mreqn structure appeared in Linux 2.4. */
struct ip_mreq imr; /* Ip multicast membership */
#else /* HAVE_IP_MREQN */
struct ip_mreqn imr; /* Ip multicast membership */
#endif /* HAVE_IP_MREQN */
/* setting up imr structure */
imr.imr_multiaddr.s_addr = inet_addr(SSDP_MCAST_ADDR);
/*imr.imr_interface.s_addr = htonl(INADDR_ANY);*/
imr.imr_address.s_addr = ifaddr; /*inet_addr(ifaddr);*/
#ifndef HAVE_IP_MREQN
imr.imr_interface.s_addr = lan_addr->addr.s_addr;
#else /* HAVE_IP_MREQN */
imr.imr_address.s_addr = lan_addr->addr.s_addr;
#ifndef MULTIPLE_EXTERNAL_IP
imr.imr_ifindex = if_nametoindex(int_if_name);
#else
#ifdef ENABLE_IPV6
imr.imr_ifindex = lan_addr->index;
#else /* ENABLE_IPV6 */
imr.imr_ifindex = if_nametoindex(lan_addr->ifname);
#endif /* ENABLE_IPV6 */
#else /* MULTIPLE_EXTERNAL_IP */
imr.imr_ifindex = 0;
#endif
#endif /* MULTIPLE_EXTERNAL_IP */
#endif /* HAVE_IP_MREQN */
#ifndef HAVE_IP_MREQN
if (setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&imr, sizeof(struct ip_mreq)) < 0)
#else /* HAVE_IP_MREQN */
if (setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&imr, sizeof(struct ip_mreqn)) < 0)
#endif /* HAVE_IP_MREQN */
{
syslog(LOG_ERR, "setsockopt(udp, IP_ADD_MEMBERSHIP): %m");
return -1;
@ -160,12 +177,14 @@ OpenAndConfSSDPReceiveSocket(int ipv6)
"OpenAndConfSSDPReceiveSocket");
}
/* TODO: Bind to device only if one LAN interface
#ifndef MULTIPLE_EXTERNAL_IP
if(setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, int_if_name, strlen(int_if_name)) < 0)
{
syslog(LOG_WARNING, "setsockopt(udp, SO_BINDTODEVICE): %m");
}
#endif
*/
if(bind(s, (struct sockaddr *)&sockname, sockname_len) < 0)
{
@ -193,7 +212,7 @@ OpenAndConfSSDPReceiveSocket(int ipv6)
{
for(lan_addr = lan_addrs.lh_first; lan_addr != NULL; lan_addr = lan_addr->list.le_next)
{
if(AddMulticastMembership(s, lan_addr->addr.s_addr) < 0)
if(AddMulticastMembership(s, lan_addr) < 0)
{
syslog(LOG_WARNING,
"Failed to add multicast membership for interface %s",

View File

@ -370,12 +370,14 @@ OpenAndConfHTTPSocket(unsigned short * port)
listenname_len = sizeof(struct sockaddr_in);
#endif
/* TODO: Bind to device only if one LAN interface
#ifndef MULTIPLE_EXTERNAL_IP
if(setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, int_if_name, strlen(int_if_name)) < 0)
{
syslog(LOG_WARNING, "setsockopt(udp, SO_BINDTODEVICE): %m");
}
#endif
*/
#ifdef ENABLE_IPV6
if(bind(s,
@ -1108,9 +1110,6 @@ init(int argc, char * * argv, struct runtime_vars * v)
use_ext_ip_addr = ary_options[i].value;
break;
case UPNPLISTENING_IP:
#ifndef MULTIPLE_EXTERNAL_IP
int_if_name = ary_options[i].value;
#endif
lan_addr = (struct lan_addr_s *) malloc(sizeof(struct lan_addr_s));
if (lan_addr == NULL)
{

View File

@ -14,10 +14,6 @@
/* network interface for internet */
const char * ext_if_name = 0;
#ifndef MULTIPLE_EXTERNAL_IP
/* network interface for LAN */
const char * int_if_name = 0;
#endif
/* file to store leases */
#ifdef ENABLE_LEASEFILE

View File

@ -15,10 +15,6 @@
/* name of the network interface used to acces internet */
extern const char * ext_if_name;
#ifndef MULTIPLE_EXTERNAL_IP
/* network interface for LAN */
extern const char * int_if_name;
#endif
/* file to store all leases */
#ifdef ENABLE_LEASEFILE