Allow runtime override of igd to v1 for people running binaries with v2 enabled

Towards miniupnp/miniupnp#277
This commit is contained in:
Nye Liu 2018-02-19 22:14:05 -08:00
parent a752cf30b5
commit c6bf0ba6f3
6 changed files with 65 additions and 0 deletions

View File

@ -1294,6 +1294,17 @@ init(int argc, char * * argv, struct runtime_vars * v)
case UPNPMINISSDPDSOCKET: case UPNPMINISSDPDSOCKET:
minissdpdsocketpath = ary_options[i].value; minissdpdsocketpath = ary_options[i].value;
break; break;
#ifdef IGD_V2
case UPNPFORCEIGDDESCV1:
if (strcmp(ary_options[i].value, "yes")!=0 &&
strcmp(ary_options[i].value, "no")!=0 ) {
fprintf(stderr, "force_igd_desc_v1 can only be yes or no\n");
}
/* ary_options is processed by genRootDesc() to find
this because there is apperently no way to pass
options to the http server */
break;
#endif
default: default:
fprintf(stderr, "Unknown option in file %s\n", fprintf(stderr, "Unknown option in file %s\n",
optionsfile); optionsfile);

View File

@ -129,6 +129,10 @@ uuid=00000000-0000-0000-0000-000000000000
#serial=12345678 #serial=12345678
#model_number=1 #model_number=1
# If compiled with IGD_V2 defined, force reporting IGDv1 in rootDesc (default
# is no)
#force_igd_desc_v1=no
# UPnP permission rules # UPnP permission rules
# (allow|deny) (external port range) IP/mask (internal port range) # (allow|deny) (external port range) IP/mask (internal port range)
# A port range is <min port>-<max port> or <port> if there is only # A port range is <min port>-<max port> or <port> if there is only

View File

@ -82,6 +82,9 @@ static const struct {
#endif #endif
#ifdef ENABLE_LEASEFILE #ifdef ENABLE_LEASEFILE
{ UPNPLEASEFILE, "lease_file"}, { UPNPLEASEFILE, "lease_file"},
#endif
#ifdef IGD_V2
{ UPNPFORCEIGDDESCV1, "force_igd_desc_v1"},
#endif #endif
{ UPNPMINISSDPDSOCKET, "minissdpdsocket"}, { UPNPMINISSDPDSOCKET, "minissdpdsocket"},
{ UPNPSECUREMODE, "secure_mode"} { UPNPSECUREMODE, "secure_mode"}

View File

@ -66,6 +66,9 @@ enum upnpconfigoptions {
UPNPLEASEFILE, /* lease_file */ UPNPLEASEFILE, /* lease_file */
#endif #endif
UPNPMINISSDPDSOCKET, /* minissdpdsocket */ UPNPMINISSDPDSOCKET, /* minissdpdsocket */
#ifdef IGD_V2
UPNPFORCEIGDDESCV1,
#endif
UPNPENABLE /* enable_upnp */ UPNPENABLE /* enable_upnp */
}; };

View File

@ -44,6 +44,11 @@ const char * ext_if_name = "eth0";
int runtime_flags = 0; int runtime_flags = 0;
#ifdef IGD_V2
struct option * ary_options = NULL;
unsigned int num_options = 0;
#endif
int getifaddr(const char * ifname, char * buf, int len, struct in_addr * addr, struct in_addr * mask) int getifaddr(const char * ifname, char * buf, int len, struct in_addr * addr, struct in_addr * mask)
{ {
UNUSED(ifname); UNUSED(ifname);

View File

@ -17,6 +17,7 @@
#endif #endif
#include "upnpdescgen.h" #include "upnpdescgen.h"
#include "miniupnpdpath.h" #include "miniupnpdpath.h"
#include "options.h"
#include "upnpglobalvars.h" #include "upnpglobalvars.h"
#include "upnpdescstrings.h" #include "upnpdescstrings.h"
#include "upnpurns.h" #include "upnpurns.h"
@ -878,6 +879,31 @@ strcat_int(char * str, int * len, int * tmplen, int i)
return str; return str;
} }
#ifdef IGD_V2
int force_igd_desc_v1(void)
{
/* keep a cache so we only do it once */
static int force=-1;
int i;
if (force!=-1) return force;
force=0;
for(i=0; i<num_options; i++) {
if(ary_options[i].id==UPNPFORCEIGDDESCV1)
{
if (strcmp(ary_options[i].value, "yes")==0)
force=1;
else if (strcmp(ary_options[i].value, "no")==0)
force=0;
}
}
return force;
}
#endif
/* iterative subroutine using a small stack /* iterative subroutine using a small stack
* This way, the progam stack usage is kept low */ * This way, the progam stack usage is kept low */
static char * static char *
@ -921,6 +947,19 @@ genXML(char * str, int * len, int * tmplen,
} }
#endif /* RANDOMIZE_URLS */ #endif /* RANDOMIZE_URLS */
str = strcat_str(str, len, tmplen, p[i].data); str = strcat_str(str, len, tmplen, p[i].data);
#ifdef IGD_V2
if (force_igd_desc_v1())
{
if ((strcmp(p[i].data, DEVICE_TYPE_IGD) == 0) ||
(strcmp(p[i].data, DEVICE_TYPE_WAN) == 0) ||
(strcmp(p[i].data, DEVICE_TYPE_WANC) == 0) ||
(strcmp(p[i].data, SERVICE_TYPE_WANIPC) == 0) )
{
int pos = strlen(str)-1;
if (pos>0) str[pos] = '1';
}
}
#endif
str = strcat_char(str, len, tmplen, '<'); str = strcat_char(str, len, tmplen, '<');
str = strcat_str(str, len, tmplen, eltname); str = strcat_str(str, len, tmplen, eltname);
str = strcat_char(str, len, tmplen, '>'); str = strcat_char(str, len, tmplen, '>');