miniupnpd: remove int_if_name, use ip_mreqn if available
This commit is contained in:
parent
138ec9e972
commit
0cf182e51e
|
@ -125,6 +125,7 @@ case $OS_NAME in
|
||||||
if [ $VER -ge 700049 ]; then
|
if [ $VER -ge 700049 ]; then
|
||||||
echo "#define PFRULE_INOUT_COUNTS" >> ${CONFIGFILE}
|
echo "#define PFRULE_INOUT_COUNTS" >> ${CONFIGFILE}
|
||||||
fi
|
fi
|
||||||
|
HAVE_IP_MREQN=1
|
||||||
# new way to see which one to use PF or IPF.
|
# new way to see which one to use PF or IPF.
|
||||||
# see http://miniupnp.tuxfamily.org/forum/viewtopic.php?p=957
|
# see http://miniupnp.tuxfamily.org/forum/viewtopic.php?p=957
|
||||||
if [ -f /etc/rc.subr ] && [ -f /etc/rc.conf ] ; then
|
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}'`
|
KERNVERC=`echo $OS_VERSION | awk -F. '{print $3}'`
|
||||||
KERNVERD=`echo $OS_VERSION | awk -F. '{print $4}'`
|
KERNVERD=`echo $OS_VERSION | awk -F. '{print $4}'`
|
||||||
#echo "$KERNVERA.$KERNVERB.$KERNVERC.$KERNVERD"
|
#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
|
# Debian GNU/Linux special case
|
||||||
if [ -f /etc/debian_version ]; then
|
if [ -f /etc/debian_version ]; then
|
||||||
OS_NAME=Debian
|
OS_NAME=Debian
|
||||||
|
@ -434,6 +439,11 @@ else
|
||||||
fi
|
fi
|
||||||
echo "" >> ${CONFIGFILE}
|
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 "/* Enable the support of IGD v2 specification." >> ${CONFIGFILE}
|
||||||
echo " * This is not fully tested yet and can cause incompatibilities with some" >> ${CONFIGFILE}
|
echo " * This is not fully tested yet and can cause incompatibilities with some" >> ${CONFIGFILE}
|
||||||
echo " * control points, so enable with care. */" >> ${CONFIGFILE}
|
echo " * control points, so enable with care. */" >> ${CONFIGFILE}
|
||||||
|
|
|
@ -44,25 +44,42 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* AddMulticastMembership()
|
/* AddMulticastMembership()
|
||||||
* param s socket
|
* param s socket
|
||||||
* param ifaddr ip v4 address
|
* param lan_addr lan address
|
||||||
*/
|
*/
|
||||||
static int
|
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 */
|
struct ip_mreqn imr; /* Ip multicast membership */
|
||||||
|
#endif /* HAVE_IP_MREQN */
|
||||||
|
|
||||||
/* setting up imr structure */
|
/* setting up imr structure */
|
||||||
imr.imr_multiaddr.s_addr = inet_addr(SSDP_MCAST_ADDR);
|
imr.imr_multiaddr.s_addr = inet_addr(SSDP_MCAST_ADDR);
|
||||||
/*imr.imr_interface.s_addr = htonl(INADDR_ANY);*/
|
/*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
|
#ifndef MULTIPLE_EXTERNAL_IP
|
||||||
imr.imr_ifindex = if_nametoindex(int_if_name);
|
#ifdef ENABLE_IPV6
|
||||||
#else
|
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;
|
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)
|
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");
|
syslog(LOG_ERR, "setsockopt(udp, IP_ADD_MEMBERSHIP): %m");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -160,12 +177,14 @@ OpenAndConfSSDPReceiveSocket(int ipv6)
|
||||||
"OpenAndConfSSDPReceiveSocket");
|
"OpenAndConfSSDPReceiveSocket");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* TODO: Bind to device only if one LAN interface
|
||||||
#ifndef MULTIPLE_EXTERNAL_IP
|
#ifndef MULTIPLE_EXTERNAL_IP
|
||||||
if(setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, int_if_name, strlen(int_if_name)) < 0)
|
if(setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, int_if_name, strlen(int_if_name)) < 0)
|
||||||
{
|
{
|
||||||
syslog(LOG_WARNING, "setsockopt(udp, SO_BINDTODEVICE): %m");
|
syslog(LOG_WARNING, "setsockopt(udp, SO_BINDTODEVICE): %m");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
*/
|
||||||
|
|
||||||
if(bind(s, (struct sockaddr *)&sockname, sockname_len) < 0)
|
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)
|
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,
|
syslog(LOG_WARNING,
|
||||||
"Failed to add multicast membership for interface %s",
|
"Failed to add multicast membership for interface %s",
|
||||||
|
|
|
@ -370,12 +370,14 @@ OpenAndConfHTTPSocket(unsigned short * port)
|
||||||
listenname_len = sizeof(struct sockaddr_in);
|
listenname_len = sizeof(struct sockaddr_in);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* TODO: Bind to device only if one LAN interface
|
||||||
#ifndef MULTIPLE_EXTERNAL_IP
|
#ifndef MULTIPLE_EXTERNAL_IP
|
||||||
if(setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, int_if_name, strlen(int_if_name)) < 0)
|
if(setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, int_if_name, strlen(int_if_name)) < 0)
|
||||||
{
|
{
|
||||||
syslog(LOG_WARNING, "setsockopt(udp, SO_BINDTODEVICE): %m");
|
syslog(LOG_WARNING, "setsockopt(udp, SO_BINDTODEVICE): %m");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef ENABLE_IPV6
|
#ifdef ENABLE_IPV6
|
||||||
if(bind(s,
|
if(bind(s,
|
||||||
|
@ -1108,9 +1110,6 @@ init(int argc, char * * argv, struct runtime_vars * v)
|
||||||
use_ext_ip_addr = ary_options[i].value;
|
use_ext_ip_addr = ary_options[i].value;
|
||||||
break;
|
break;
|
||||||
case UPNPLISTENING_IP:
|
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));
|
lan_addr = (struct lan_addr_s *) malloc(sizeof(struct lan_addr_s));
|
||||||
if (lan_addr == NULL)
|
if (lan_addr == NULL)
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,10 +14,6 @@
|
||||||
|
|
||||||
/* network interface for internet */
|
/* network interface for internet */
|
||||||
const char * ext_if_name = 0;
|
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 */
|
/* file to store leases */
|
||||||
#ifdef ENABLE_LEASEFILE
|
#ifdef ENABLE_LEASEFILE
|
||||||
|
|
|
@ -15,10 +15,6 @@
|
||||||
|
|
||||||
/* name of the network interface used to acces internet */
|
/* name of the network interface used to acces internet */
|
||||||
extern const char * ext_if_name;
|
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 */
|
/* file to store all leases */
|
||||||
#ifdef ENABLE_LEASEFILE
|
#ifdef ENABLE_LEASEFILE
|
||||||
|
|
Loading…
Reference in New Issue