From 6d32d69608e8dd197a1625558f85fc9db8d18fc1 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Fri, 6 Apr 2012 17:31:24 +0200 Subject: [PATCH] Allow LAN interface to be given as interface names. (instead of interface IP addresses) It will allow IPv6 operations. --- miniupnpd/Changelog.txt | 2 ++ miniupnpd/miniupnpd.c | 36 ++++++++++++++++++++++++++++++------ miniupnpd/miniupnpd.conf | 8 +++++--- miniupnpd/miniupnpdtypes.h | 9 +++++++-- 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/miniupnpd/Changelog.txt b/miniupnpd/Changelog.txt index 17267bf..94e31b8 100644 --- a/miniupnpd/Changelog.txt +++ b/miniupnpd/Changelog.txt @@ -1,6 +1,8 @@ $Id: Changelog.txt,v 1.266 2012/04/06 15:27:20 nanard Exp $ 2012/04/06: + Allow LAN interface to be given as interface names, instead of interface + IP addresses. It will allow IPv6 operations. fix linux/getifstats.c when bitrate is unknown 2012/03/31: diff --git a/miniupnpd/miniupnpd.c b/miniupnpd/miniupnpd.c index 2c47e29..39b8667 100644 --- a/miniupnpd/miniupnpd.c +++ b/miniupnpd/miniupnpd.c @@ -1,4 +1,4 @@ -/* $Id: miniupnpd.c,v 1.149 2012/03/31 06:57:12 nanard Exp $ */ +/* $Id: miniupnpd.c,v 1.150 2012/04/06 15:27:20 nanard Exp $ */ /* MiniUPnP project * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ * (c) 2006-2012 Thomas Bernard @@ -519,6 +519,8 @@ struct runtime_vars { * external interface associated with the lan subnet follows. * ex : 192.168.1.1/24 81.21.41.11 * + * Can also use the interface name (ie eth0) + * * return value : * 0 : ok * -1 : error */ @@ -529,14 +531,26 @@ parselanaddr(struct lan_addr_s * lan_addr, const char * str) int n; char tmp[16]; + memset(lan_addr, 0, sizeof(struct lan_addr_s)); p = str; while(*p && *p != '/' && !isspace(*p)) p++; n = p - str; - if(n>15) - goto parselan_error; - memcpy(lan_addr->str, str, n); - lan_addr->str[n] = '\0'; + if(!isdigit(str[0]) && n < sizeof(lan_addr->ifname)) + { + /* not starting with a digit : suppose it is an interface name */ + memcpy(lan_addr->ifname, str, n); + lan_addr->ifname[n] = '\0'; + if(getifaddr(lan_addr->ifname, lan_addr->str, sizeof(lan_addr->str)) < 0) + goto parselan_error; + } + else + { + if(n>15) + goto parselan_error; + memcpy(lan_addr->str, str, n); + lan_addr->str[n] = '\0'; + } if(!inet_aton(lan_addr->str, &lan_addr->addr)) goto parselan_error; if(*p == '/') @@ -587,10 +601,20 @@ parselanaddr(struct lan_addr_s * lan_addr, const char * str) } } } +#endif +#ifdef ENABLE_IPV6 + 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", + lan_addr->ifname); + } #endif return 0; parselan_error: - fprintf(stderr, "Error parsing address/mask : %s\n", str); + fprintf(stderr, "Error parsing address/mask (or interface name) : %s\n", + str); return -1; } diff --git a/miniupnpd/miniupnpd.conf b/miniupnpd/miniupnpd.conf index 4956e04..e34e088 100644 --- a/miniupnpd/miniupnpd.conf +++ b/miniupnpd/miniupnpd.conf @@ -8,13 +8,15 @@ ext_ifname=eth1 # LAN network interfaces IPs / networks # there can be multiple listening ips for SSDP traffic. # should be under the form nnn.nnn.nnn.nnn/nn -# HTTP is available on all interfaces +# It can also be the network interface name (ie "eth0") +# It if mandatory to use the network interface name to enable IPv6 +# HTTP is available on all interfaces. # 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 #listening_ip=192.168.0.1/24 -listening_ip=192.168.11.33/24 -#listening_ip= +listening_ip=192.168.10.109/24 +#listening_ip=eth0 # port for HTTP (descriptions and SOAP) traffic. set 0 for autoselect. port=0 diff --git a/miniupnpd/miniupnpdtypes.h b/miniupnpd/miniupnpdtypes.h index ccd135c..938406b 100644 --- a/miniupnpd/miniupnpdtypes.h +++ b/miniupnpd/miniupnpdtypes.h @@ -1,7 +1,7 @@ -/* $Id: miniupnpdtypes.h,v 1.3 2011/05/13 13:56:18 nanard Exp $ */ +/* $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-2007 Thomas Bernard + * (c) 2006-2012 Thomas Bernard * This software is subject to the conditions detailed * in the LICENCE file provided within the distribution */ #ifndef __MINIUPNPDTYPES_H__ @@ -9,11 +9,16 @@ #include "config.h" #include +#include #include /* structure and list for storing lan addresses * with ascii representation and mask */ struct lan_addr_s { + char ifname[IFNAMSIZ]; /* example: eth0 */ +#ifdef ENABLE_IPV6 + unsigned int index; /* use if_nametoindex() */ +#endif char str[16]; /* example: 192.168.0.1 */ struct in_addr addr, mask; /* ip/mask */ #ifdef MULTIPLE_EXTERNAL_IP