miniupnpd: improves error handling during init.
- Fails on config parsing and init errors. - print errors during init to both syslog and stderr. fixes #551
This commit is contained in:
parent
97b7ec1ad2
commit
5567e7c7e0
|
@ -1,5 +1,9 @@
|
||||||
$Id: Changelog.txt,v 1.478 2021/05/21 22:03:13 nanard Exp $
|
$Id: Changelog.txt,v 1.478 2021/05/21 22:03:13 nanard Exp $
|
||||||
|
|
||||||
|
2021/06/18:
|
||||||
|
Fails on config parsing and init errors.
|
||||||
|
print errors during init to both syslog and stderr.
|
||||||
|
|
||||||
2021/05/22:
|
2021/05/22:
|
||||||
dynamically retrieve `uname -r`
|
dynamically retrieve `uname -r`
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* $Id: macros.h,v 1.5 2019/09/24 09:37:52 nanard Exp $ */
|
/* $Id: macros.h,v 1.5 2019/09/24 09:37:52 nanard Exp $ */
|
||||||
/* MiniUPnP project
|
/* MiniUPnP project
|
||||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||||
* (c) 2012-2019 Thomas Bernard
|
* (c) 2012-2021 Thomas Bernard
|
||||||
* This software is subject to the conditions detailed
|
* This software is subject to the conditions detailed
|
||||||
* in the LICENCE file provided within the distribution */
|
* in the LICENCE file provided within the distribution */
|
||||||
|
|
||||||
|
@ -16,6 +16,11 @@
|
||||||
#define FALL_THROUGH
|
#define FALL_THROUGH
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Macro to print errors during initialization.
|
||||||
|
* Print them on both stderr and syslog.
|
||||||
|
* if debug_flag is on, syslog already print on console */
|
||||||
|
#define INIT_PRINT_ERR(...) do { if (!debug_flag) fprintf(stderr, __VA_ARGS__); syslog(LOG_ERR, __VA_ARGS__); } while(0)
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifndef INLINE
|
#ifndef INLINE
|
||||||
|
|
|
@ -919,7 +919,7 @@ struct runtime_vars {
|
||||||
* 0 : ok
|
* 0 : ok
|
||||||
* -1 : error */
|
* -1 : error */
|
||||||
static int
|
static int
|
||||||
parselanaddr(struct lan_addr_s * lan_addr, const char * str)
|
parselanaddr(struct lan_addr_s * lan_addr, const char * str, int debug_flag)
|
||||||
{
|
{
|
||||||
const char * p;
|
const char * p;
|
||||||
unsigned int n;
|
unsigned int n;
|
||||||
|
@ -939,6 +939,7 @@ parselanaddr(struct lan_addr_s * lan_addr, const char * str)
|
||||||
&lan_addr->addr, &lan_addr->mask) < 0) {
|
&lan_addr->addr, &lan_addr->mask) < 0) {
|
||||||
#ifdef ENABLE_IPV6
|
#ifdef ENABLE_IPV6
|
||||||
fprintf(stderr, "interface \"%s\" has no IPv4 address\n", str);
|
fprintf(stderr, "interface \"%s\" has no IPv4 address\n", str);
|
||||||
|
syslog(LOG_NOTICE, "interface \"%s\" has no IPv4 address\n", str);
|
||||||
lan_addr->str[0] = '\0';
|
lan_addr->str[0] = '\0';
|
||||||
lan_addr->addr.s_addr = htonl(0x00000000u);
|
lan_addr->addr.s_addr = htonl(0x00000000u);
|
||||||
lan_addr->mask.s_addr = htonl(0xffffffffu);
|
lan_addr->mask.s_addr = htonl(0xffffffffu);
|
||||||
|
@ -958,10 +959,10 @@ parselanaddr(struct lan_addr_s * lan_addr, const char * str)
|
||||||
goto parselan_error;
|
goto parselan_error;
|
||||||
}
|
}
|
||||||
if(!addr_is_reserved(&lan_addr->addr)) {
|
if(!addr_is_reserved(&lan_addr->addr)) {
|
||||||
fprintf(stderr, "Error: LAN address contains public IP address : %s\n", lan_addr->str);
|
INIT_PRINT_ERR("Error: LAN address contains public IP address : %s\n", lan_addr->str);
|
||||||
fprintf(stderr, "Public IP address can be configured via ext_ip= option\n");
|
INIT_PRINT_ERR("Public IP address can be configured via ext_ip= option\n");
|
||||||
fprintf(stderr, "LAN address should contain private address, e.g. from 192.168. block\n");
|
INIT_PRINT_ERR("LAN address should contain private address, e.g. from 192.168. block\n");
|
||||||
fprintf(stderr, "Listening on public IP address is a security issue\n");
|
INIT_PRINT_ERR("Listening on public IP address is a security issue\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(*p == '/')
|
if(*p == '/')
|
||||||
|
@ -1010,12 +1011,12 @@ parselanaddr(struct lan_addr_s * lan_addr, const char * str)
|
||||||
lan_addr->ext_ip_str[n] = '\0';
|
lan_addr->ext_ip_str[n] = '\0';
|
||||||
if(!inet_aton(lan_addr->ext_ip_str, &lan_addr->ext_ip_addr)) {
|
if(!inet_aton(lan_addr->ext_ip_str, &lan_addr->ext_ip_addr)) {
|
||||||
/* error */
|
/* error */
|
||||||
fprintf(stderr, "Error parsing address : %s\n", lan_addr->ext_ip_str);
|
INIT_PRINT_ERR("Error parsing address : %s\n", lan_addr->ext_ip_str);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(addr_is_reserved(&lan_addr->ext_ip_addr)) {
|
if(addr_is_reserved(&lan_addr->ext_ip_addr)) {
|
||||||
/* error */
|
/* error */
|
||||||
fprintf(stderr, "Error: option ext_ip address contains reserved / private address : %s\n", lan_addr->ext_ip_str);
|
INIT_PRINT_ERR("Error: option ext_ip address contains reserved / private address : %s\n", lan_addr->ext_ip_str);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1033,7 +1034,7 @@ parselanaddr(struct lan_addr_s * lan_addr, const char * str)
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
if(n >= sizeof(tmp)) {
|
if(n >= sizeof(tmp)) {
|
||||||
fprintf(stderr, "Cannot parse '%s'\n", p);
|
INIT_PRINT_ERR("Cannot parse '%s'\n", p);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
tmp[n] = '\0';
|
tmp[n] = '\0';
|
||||||
|
@ -1041,6 +1042,8 @@ parselanaddr(struct lan_addr_s * lan_addr, const char * str)
|
||||||
if(index == 0) {
|
if(index == 0) {
|
||||||
fprintf(stderr, "Cannot get index for network interface %s\n",
|
fprintf(stderr, "Cannot get index for network interface %s\n",
|
||||||
tmp);
|
tmp);
|
||||||
|
syslog(LOG_WARNING, "Cannot get index for network interface %s\n",
|
||||||
|
tmp);
|
||||||
} else {
|
} else {
|
||||||
lan_addr->add_indexes |= (1UL << (index - 1));
|
lan_addr->add_indexes |= (1UL << (index - 1));
|
||||||
}
|
}
|
||||||
|
@ -1048,31 +1051,25 @@ parselanaddr(struct lan_addr_s * lan_addr, const char * str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if(lan_addr->ifname[0] != '\0')
|
if(lan_addr->ifname[0] != '\0') {
|
||||||
{
|
|
||||||
lan_addr->index = if_nametoindex(lan_addr->ifname);
|
lan_addr->index = if_nametoindex(lan_addr->ifname);
|
||||||
if(lan_addr->index == 0)
|
if(lan_addr->index == 0) {
|
||||||
fprintf(stderr, "Cannot get index for network interface %s\n",
|
fprintf(stderr, "Cannot get index for network interface %s\n",
|
||||||
lan_addr->ifname);
|
lan_addr->ifname);
|
||||||
}
|
syslog(LOG_WARNING, "Cannot get index for network interface %s\n",
|
||||||
|
lan_addr->ifname);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
#ifdef ENABLE_IPV6
|
#ifdef ENABLE_IPV6
|
||||||
else
|
INIT_PRINT_ERR("Error: please specify LAN network interface by name instead of IPv4 address : %s\n", str);
|
||||||
{
|
|
||||||
fprintf(stderr,
|
|
||||||
"Error: please specify LAN network interface by name instead of IPv4 address : %s\n",
|
|
||||||
str);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
else
|
|
||||||
{
|
|
||||||
syslog(LOG_NOTICE, "it is advised to use network interface name instead of %s", str);
|
syslog(LOG_NOTICE, "it is advised to use network interface name instead of %s", str);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
parselan_error:
|
parselan_error:
|
||||||
fprintf(stderr, "Error parsing address/mask (or interface name) : %s\n",
|
INIT_PRINT_ERR("Error parsing address/mask (or interface name) : %s\n", str);
|
||||||
str);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1191,7 +1188,18 @@ init(int argc, char * * argv, struct runtime_vars * v)
|
||||||
{
|
{
|
||||||
if(0 == strcmp(argv[i], "-h") || 0 == strcmp(argv[i], "--help"))
|
if(0 == strcmp(argv[i], "-h") || 0 == strcmp(argv[i], "--help"))
|
||||||
goto print_usage;
|
goto print_usage;
|
||||||
|
if(0 == strcmp(argv[i], "-d"))
|
||||||
|
debug_flag = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
openlog_option = LOG_PID|LOG_CONS;
|
||||||
|
if(debug_flag)
|
||||||
|
{
|
||||||
|
openlog_option |= LOG_PERROR; /* also log on stderr */
|
||||||
|
}
|
||||||
|
|
||||||
|
openlog("miniupnpd", openlog_option, LOG_MINIUPNPD);
|
||||||
|
|
||||||
#ifndef DISABLE_CONFIG_FILE
|
#ifndef DISABLE_CONFIG_FILE
|
||||||
/* first check if "-f" option is used */
|
/* first check if "-f" option is used */
|
||||||
for(i=2; i<argc; i++)
|
for(i=2; i<argc; i++)
|
||||||
|
@ -1222,11 +1230,14 @@ init(int argc, char * * argv, struct runtime_vars * v)
|
||||||
#ifndef DISABLE_CONFIG_FILE
|
#ifndef DISABLE_CONFIG_FILE
|
||||||
/* read options file first since
|
/* read options file first since
|
||||||
* command line arguments have final say */
|
* command line arguments have final say */
|
||||||
if(readoptionsfile(optionsfile) < 0)
|
if(readoptionsfile(optionsfile, debug_flag) < 0)
|
||||||
{
|
{
|
||||||
/* only error if file exists or using -f */
|
/* only error if file exists or using -f */
|
||||||
if(access(optionsfile, F_OK) == 0 || options_flag)
|
if(access(optionsfile, F_OK) == 0 || options_flag)
|
||||||
fprintf(stderr, "Error reading configuration file %s\n", optionsfile);
|
{
|
||||||
|
INIT_PRINT_ERR("Error reading configuration file %s\n", optionsfile);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1259,18 +1270,18 @@ init(int argc, char * * argv, struct runtime_vars * v)
|
||||||
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)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "malloc(sizeof(struct lan_addr_s)): %m");
|
INIT_PRINT_ERR("malloc(sizeof(struct lan_addr_s)): %m");
|
||||||
break;
|
return 1;
|
||||||
}
|
}
|
||||||
if(parselanaddr(lan_addr, ary_options[i].value) != 0)
|
if(parselanaddr(lan_addr, ary_options[i].value, debug_flag) != 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "can't parse \"%s\" as a valid "
|
INIT_PRINT_ERR("can't parse \"%s\" as a valid "
|
||||||
#ifndef ENABLE_IPV6
|
#ifndef ENABLE_IPV6
|
||||||
"LAN address or "
|
"LAN address or "
|
||||||
#endif
|
#endif
|
||||||
"interface name\n", ary_options[i].value);
|
"interface name\n", ary_options[i].value);
|
||||||
free(lan_addr);
|
free(lan_addr);
|
||||||
break;
|
return 1;
|
||||||
}
|
}
|
||||||
LIST_INSERT_HEAD(&lan_addrs, lan_addr, list);
|
LIST_INSERT_HEAD(&lan_addrs, lan_addr, list);
|
||||||
break;
|
break;
|
||||||
|
@ -1278,7 +1289,8 @@ init(int argc, char * * argv, struct runtime_vars * v)
|
||||||
case UPNPIPV6_LISTENING_IP:
|
case UPNPIPV6_LISTENING_IP:
|
||||||
if (inet_pton(AF_INET6, ary_options[i].value, &ipv6_bind_addr) < 1)
|
if (inet_pton(AF_INET6, ary_options[i].value, &ipv6_bind_addr) < 1)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "can't parse \"%s\" as valid IPv6 listening address", ary_options[i].value);
|
INIT_PRINT_ERR("can't parse \"%s\" as valid IPv6 listening address", ary_options[i].value);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case UPNPIPV6_DISABLE:
|
case UPNPIPV6_DISABLE:
|
||||||
|
@ -1438,25 +1450,26 @@ init(int argc, char * * argv, struct runtime_vars * v)
|
||||||
if (strcmp(ary_options[i].value, "yes") == 0)
|
if (strcmp(ary_options[i].value, "yes") == 0)
|
||||||
SETFLAG(FORCEIGDDESCV1MASK);
|
SETFLAG(FORCEIGDDESCV1MASK);
|
||||||
else if (strcmp(ary_options[i].value, "no") != 0 ) {
|
else if (strcmp(ary_options[i].value, "no") != 0 ) {
|
||||||
fprintf(stderr, "force_igd_desc_v1 can only be yes or no\n");
|
INIT_PRINT_ERR("force_igd_desc_v1 can only be yes or no\n");
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Unknown option in file %s\n",
|
INIT_PRINT_ERR("Unknown option in file %s\n",
|
||||||
optionsfile);
|
optionsfile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef ENABLE_PCP
|
#ifdef ENABLE_PCP
|
||||||
/* if lifetimes are inverse */
|
/* if lifetimes are inverse */
|
||||||
if (min_lifetime >= max_lifetime) {
|
if (min_lifetime >= max_lifetime) {
|
||||||
fprintf(stderr, "Minimum lifetime (%lu) is greater than or equal to maximum lifetime (%lu).\n", min_lifetime, max_lifetime);
|
INIT_PRINT_ERR("Minimum lifetime (%lu) is greater than or equal to maximum lifetime (%lu).\n", min_lifetime, max_lifetime);
|
||||||
fprintf(stderr, "Check your configuration file.\n");
|
INIT_PRINT_ERR("Check your configuration file.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#endif /* ENABLE_PCP */
|
#endif /* ENABLE_PCP */
|
||||||
if (GETFLAG(PERFORMSTUNMASK) && !ext_stun_host) {
|
if (GETFLAG(PERFORMSTUNMASK) && !ext_stun_host) {
|
||||||
fprintf(stderr, "You must specify ext_stun_host= when ext_perform_stun=yes\n");
|
INIT_PRINT_ERR("You must specify ext_stun_host= when ext_perform_stun=yes\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1467,7 +1480,8 @@ init(int argc, char * * argv, struct runtime_vars * v)
|
||||||
{
|
{
|
||||||
if(argv[i][0]!='-')
|
if(argv[i][0]!='-')
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Unknown option: %s\n", argv[i]);
|
INIT_PRINT_ERR("Unknown option: %s\n", argv[i]);
|
||||||
|
goto print_usage;
|
||||||
}
|
}
|
||||||
else switch(argv[i][1])
|
else switch(argv[i][1])
|
||||||
{
|
{
|
||||||
|
@ -1491,8 +1505,10 @@ init(int argc, char * * argv, struct runtime_vars * v)
|
||||||
case 'b':
|
case 'b':
|
||||||
if(i+1 < argc) {
|
if(i+1 < argc) {
|
||||||
upnp_bootid = (unsigned int)strtoul(argv[++i], NULL, 10);
|
upnp_bootid = (unsigned int)strtoul(argv[++i], NULL, 10);
|
||||||
} else
|
} else {
|
||||||
fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]);
|
INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]);
|
||||||
|
goto print_usage;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
if(i+1 < argc) {
|
if(i+1 < argc) {
|
||||||
|
@ -1508,49 +1524,63 @@ init(int argc, char * * argv, struct runtime_vars * v)
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
use_ext_ip_addr = argv[i];
|
use_ext_ip_addr = argv[i];
|
||||||
} else
|
} else {
|
||||||
fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]);
|
INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]);
|
||||||
|
goto print_usage;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
if(i+1 < argc)
|
if(i+1 < argc) {
|
||||||
v->notify_interval = atoi(argv[++i]);
|
v->notify_interval = atoi(argv[++i]);
|
||||||
else
|
} else {
|
||||||
fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]);
|
INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]);
|
||||||
|
goto print_usage;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
if(i+1 < argc)
|
if(i+1 < argc) {
|
||||||
v->clean_ruleset_interval = atoi(argv[++i]);
|
v->clean_ruleset_interval = atoi(argv[++i]);
|
||||||
else
|
} else {
|
||||||
fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]);
|
INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]);
|
||||||
|
goto print_usage;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
if(i+1 < argc) {
|
if(i+1 < argc) {
|
||||||
strncpy(uuidvalue_igd+5, argv[++i], strlen(uuidvalue_igd+5) + 1);
|
strncpy(uuidvalue_igd+5, argv[++i], strlen(uuidvalue_igd+5) + 1);
|
||||||
complete_uuidvalues();
|
complete_uuidvalues();
|
||||||
} else
|
} else {
|
||||||
fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]);
|
INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]);
|
||||||
|
goto print_usage;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
#ifdef ENABLE_MANUFACTURER_INFO_CONFIGURATION
|
#ifdef ENABLE_MANUFACTURER_INFO_CONFIGURATION
|
||||||
case 'z':
|
case 'z':
|
||||||
if(i+1 < argc)
|
if(i+1 < argc) {
|
||||||
strncpy(friendly_name, argv[++i], FRIENDLY_NAME_MAX_LEN);
|
strncpy(friendly_name, argv[++i], FRIENDLY_NAME_MAX_LEN);
|
||||||
else
|
} else {
|
||||||
fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]);
|
INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]);
|
||||||
|
goto print_usage;
|
||||||
|
}
|
||||||
friendly_name[FRIENDLY_NAME_MAX_LEN-1] = '\0';
|
friendly_name[FRIENDLY_NAME_MAX_LEN-1] = '\0';
|
||||||
break;
|
break;
|
||||||
#endif /* ENABLE_MANUFACTURER_INFO_CONFIGURATION */
|
#endif /* ENABLE_MANUFACTURER_INFO_CONFIGURATION */
|
||||||
case 's':
|
case 's':
|
||||||
if(i+1 < argc)
|
if(i+1 < argc) {
|
||||||
strncpy(serialnumber, argv[++i], SERIALNUMBER_MAX_LEN);
|
strncpy(serialnumber, argv[++i], SERIALNUMBER_MAX_LEN);
|
||||||
else
|
} else {
|
||||||
fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]);
|
INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]);
|
||||||
|
goto print_usage;
|
||||||
|
}
|
||||||
serialnumber[SERIALNUMBER_MAX_LEN-1] = '\0';
|
serialnumber[SERIALNUMBER_MAX_LEN-1] = '\0';
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
if(i+1 < argc)
|
if(i+1 < argc) {
|
||||||
strncpy(modelnumber, argv[++i], MODELNUMBER_MAX_LEN);
|
strncpy(modelnumber, argv[++i], MODELNUMBER_MAX_LEN);
|
||||||
else
|
} else {
|
||||||
fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]);
|
INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]);
|
||||||
|
goto print_usage;
|
||||||
|
}
|
||||||
modelnumber[MODELNUMBER_MAX_LEN-1] = '\0';
|
modelnumber[MODELNUMBER_MAX_LEN-1] = '\0';
|
||||||
break;
|
break;
|
||||||
#ifdef ENABLE_NATPMP
|
#ifdef ENABLE_NATPMP
|
||||||
|
@ -1576,55 +1606,67 @@ init(int argc, char * * argv, struct runtime_vars * v)
|
||||||
SETFLAG(SECUREMODEMASK);
|
SETFLAG(SECUREMODEMASK);
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
if(i+1 < argc)
|
if(i+1 < argc) {
|
||||||
ext_if_name = argv[++i];
|
ext_if_name = argv[++i];
|
||||||
else
|
} else {
|
||||||
fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]);
|
INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]);
|
||||||
|
goto print_usage;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
#ifdef ENABLE_IPV6
|
#ifdef ENABLE_IPV6
|
||||||
case 'I':
|
case 'I':
|
||||||
if(i+1 < argc)
|
if(i+1 < argc) {
|
||||||
ext_if_name6 = argv[++i];
|
ext_if_name6 = argv[++i];
|
||||||
else
|
} else {
|
||||||
fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]);
|
INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]);
|
||||||
|
goto print_usage;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_PF
|
#ifdef USE_PF
|
||||||
case 'q':
|
case 'q':
|
||||||
if(i+1 < argc)
|
if(i+1 < argc) {
|
||||||
queue = argv[++i];
|
queue = argv[++i];
|
||||||
else
|
} else {
|
||||||
fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]);
|
INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]);
|
||||||
|
goto print_usage;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'T':
|
case 'T':
|
||||||
if(i+1 < argc)
|
if(i+1 < argc) {
|
||||||
tag = argv[++i];
|
tag = argv[++i];
|
||||||
else
|
} else {
|
||||||
fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]);
|
INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]);
|
||||||
|
goto print_usage;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
#endif /* USE_PF */
|
#endif /* USE_PF */
|
||||||
case 'p':
|
case 'p':
|
||||||
if(i+1 < argc)
|
if(i+1 < argc) {
|
||||||
v->port = atoi(argv[++i]);
|
v->port = atoi(argv[++i]);
|
||||||
else
|
} else {
|
||||||
fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]);
|
INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]);
|
||||||
|
goto print_usage;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
#ifdef ENABLE_HTTPS
|
#ifdef ENABLE_HTTPS
|
||||||
case 'H':
|
case 'H':
|
||||||
if(i+1 < argc)
|
if(i+1 < argc) {
|
||||||
v->https_port = atoi(argv[++i]);
|
v->https_port = atoi(argv[++i]);
|
||||||
else
|
} else {
|
||||||
fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]);
|
INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]);
|
||||||
|
goto print_usage;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
#endif /* ENABLE_HTTPS */
|
#endif /* ENABLE_HTTPS */
|
||||||
#ifdef ENABLE_NFQUEUE
|
#ifdef ENABLE_NFQUEUE
|
||||||
case 'Q':
|
case 'Q':
|
||||||
if(i+1<argc)
|
if(i+1<argc) {
|
||||||
{
|
|
||||||
nfqueue = atoi(argv[++i]);
|
nfqueue = atoi(argv[++i]);
|
||||||
|
} else {
|
||||||
|
INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]);
|
||||||
|
goto print_usage;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]);
|
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
if (i+1 < argc) {
|
if (i+1 < argc) {
|
||||||
|
@ -1632,10 +1674,11 @@ init(int argc, char * * argv, struct runtime_vars * v)
|
||||||
if(n_nfqix < MAX_LAN_ADDR) {
|
if(n_nfqix < MAX_LAN_ADDR) {
|
||||||
nfqix[n_nfqix++] = if_nametoindex(argv[i]);
|
nfqix[n_nfqix++] = if_nametoindex(argv[i]);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,"Too many nfq interfaces. Ignoring %s\n", argv[i]);
|
INIT_PRINT_ERR( "Too many nfq interfaces. Ignoring %s\n", argv[i]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]);
|
INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]);
|
||||||
|
goto print_usage;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif /* ENABLE_NFQUEUE */
|
#endif /* ENABLE_NFQUEUE */
|
||||||
|
@ -1643,27 +1686,30 @@ init(int argc, char * * argv, struct runtime_vars * v)
|
||||||
case 'P':
|
case 'P':
|
||||||
if(i+1 < argc)
|
if(i+1 < argc)
|
||||||
pidfilename = argv[++i];
|
pidfilename = argv[++i];
|
||||||
else
|
else {
|
||||||
fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]);
|
INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]);
|
||||||
|
goto print_usage;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case 'd':
|
case 'd': /* discarding */
|
||||||
debug_flag = 1;
|
|
||||||
break;
|
break;
|
||||||
case 'w':
|
case 'w':
|
||||||
if(i+1 < argc)
|
if(i+1 < argc)
|
||||||
presurl = argv[++i];
|
presurl = argv[++i];
|
||||||
else
|
else {
|
||||||
fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]);
|
INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]);
|
||||||
|
goto print_usage;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'B':
|
case 'B':
|
||||||
if(i+2<argc)
|
if(i+2<argc) {
|
||||||
{
|
|
||||||
downstream_bitrate = strtoul(argv[++i], 0, 0);
|
downstream_bitrate = strtoul(argv[++i], 0, 0);
|
||||||
upstream_bitrate = strtoul(argv[++i], 0, 0);
|
upstream_bitrate = strtoul(argv[++i], 0, 0);
|
||||||
|
} else {
|
||||||
|
INIT_PRINT_ERR("Option -%c takes two argument.\n", argv[i][1]);
|
||||||
|
goto print_usage;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
fprintf(stderr, "Option -%c takes two arguments.\n", argv[i][1]);
|
|
||||||
break;
|
break;
|
||||||
case 'a':
|
case 'a':
|
||||||
#ifndef MULTIPLE_EXTERNAL_IP
|
#ifndef MULTIPLE_EXTERNAL_IP
|
||||||
|
@ -1673,18 +1719,18 @@ init(int argc, char * * argv, struct runtime_vars * v)
|
||||||
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)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "malloc(sizeof(struct lan_addr_s)): %m");
|
INIT_PRINT_ERR("malloc(sizeof(struct lan_addr_s)): %m");
|
||||||
break;
|
return 1;
|
||||||
}
|
}
|
||||||
if(parselanaddr(lan_addr, argv[i]) != 0)
|
if(parselanaddr(lan_addr, argv[i], debug_flag) != 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "can't parse \"%s\" as a valid "
|
INIT_PRINT_ERR("can't parse \"%s\" as a valid "
|
||||||
#ifndef ENABLE_IPV6
|
#ifndef ENABLE_IPV6
|
||||||
"LAN address or "
|
"LAN address or "
|
||||||
#endif /* #ifndef ENABLE_IPV6 */
|
#endif /* #ifndef ENABLE_IPV6 */
|
||||||
"interface name\n", argv[i]);
|
"interface name\n", argv[i]);
|
||||||
free(lan_addr);
|
free(lan_addr);
|
||||||
break;
|
return 1;
|
||||||
}
|
}
|
||||||
/* check if we already have this address */
|
/* check if we already have this address */
|
||||||
for(lan_addr2 = lan_addrs.lh_first; lan_addr2 != NULL; lan_addr2 = lan_addr2->list.le_next)
|
for(lan_addr2 = lan_addrs.lh_first; lan_addr2 != NULL; lan_addr2 = lan_addr2->list.le_next)
|
||||||
|
@ -1694,33 +1740,34 @@ init(int argc, char * * argv, struct runtime_vars * v)
|
||||||
}
|
}
|
||||||
if (lan_addr2 == NULL)
|
if (lan_addr2 == NULL)
|
||||||
LIST_INSERT_HEAD(&lan_addrs, lan_addr, list);
|
LIST_INSERT_HEAD(&lan_addrs, lan_addr, list);
|
||||||
|
} else {
|
||||||
|
INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]);
|
||||||
|
goto print_usage;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]);
|
|
||||||
#else /* #ifndef MULTIPLE_EXTERNAL_IP */
|
#else /* #ifndef MULTIPLE_EXTERNAL_IP */
|
||||||
if(i+2 < argc)
|
if(i+2 < argc)
|
||||||
{
|
{
|
||||||
char *val = calloc((strlen(argv[i+1]) + strlen(argv[i+2]) + 2), sizeof(char));
|
char *val = calloc((strlen(argv[i+1]) + strlen(argv[i+2]) + 2), sizeof(char));
|
||||||
if (val == NULL)
|
if (val == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "memory allocation error for listen address storage\n");
|
INIT_PRINT_ERR("memory allocation error for listen address storage\n");
|
||||||
break;
|
return 1;
|
||||||
}
|
}
|
||||||
sprintf(val, "%s %s", argv[i+1], argv[i+2]);
|
sprintf(val, "%s %s", argv[i+1], argv[i+2]);
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "malloc(sizeof(struct lan_addr_s)): %m");
|
INIT_PRINT_ERR("malloc(sizeof(struct lan_addr_s)): %m");
|
||||||
free(val);
|
free(val);
|
||||||
break;
|
return 1;
|
||||||
}
|
}
|
||||||
if(parselanaddr(lan_addr, val) != 0)
|
if(parselanaddr(lan_addr, val, debug_flag) != 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "can't parse \"%s\" as a valid LAN address or interface name\n", val);
|
INIT_PRINT_ERR("can't parse \"%s\" as a valid LAN address or interface name\n", val);
|
||||||
free(lan_addr);
|
free(lan_addr);
|
||||||
free(val);
|
free(val);
|
||||||
break;
|
return 1;
|
||||||
}
|
}
|
||||||
/* check if we already have this address */
|
/* check if we already have this address */
|
||||||
for(lan_addr2 = lan_addrs.lh_first; lan_addr2 != NULL; lan_addr2 = lan_addr2->list.le_next)
|
for(lan_addr2 = lan_addrs.lh_first; lan_addr2 != NULL; lan_addr2 = lan_addr2->list.le_next)
|
||||||
|
@ -1733,9 +1780,10 @@ init(int argc, char * * argv, struct runtime_vars * v)
|
||||||
|
|
||||||
free(val);
|
free(val);
|
||||||
i+=2;
|
i+=2;
|
||||||
|
} else {
|
||||||
|
INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]);
|
||||||
|
goto print_usage;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
fprintf(stderr, "Option -%c takes two arguments.\n", argv[i][1]);
|
|
||||||
#endif /* #ifndef MULTIPLE_EXTERNAL_IP */
|
#endif /* #ifndef MULTIPLE_EXTERNAL_IP */
|
||||||
break;
|
break;
|
||||||
case 'A':
|
case 'A':
|
||||||
|
@ -1743,23 +1791,28 @@ init(int argc, char * * argv, struct runtime_vars * v)
|
||||||
void * tmp;
|
void * tmp;
|
||||||
tmp = realloc(upnppermlist, sizeof(struct upnpperm) * (num_upnpperm+1));
|
tmp = realloc(upnppermlist, sizeof(struct upnpperm) * (num_upnpperm+1));
|
||||||
if(tmp == NULL) {
|
if(tmp == NULL) {
|
||||||
fprintf(stderr, "memory allocation error for permission\n");
|
INIT_PRINT_ERR("memory allocation error for permission\n");
|
||||||
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
upnppermlist = tmp;
|
upnppermlist = tmp;
|
||||||
if(read_permission_line(upnppermlist + num_upnpperm, argv[++i]) >= 0) {
|
if(read_permission_line(upnppermlist + num_upnpperm, argv[++i]) >= 0) {
|
||||||
num_upnpperm++;
|
num_upnpperm++;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Permission rule parsing error :\n%s\n", argv[i]);
|
INIT_PRINT_ERR("Permission rule parsing error :\n%s\n", argv[i]);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]);
|
INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]);
|
||||||
|
goto print_usage;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
i++; /* discarding, the config file is already read */
|
i++; /* discarding, the config file is already read */
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Unknown option: %s\n", argv[i]);
|
INIT_PRINT_ERR("Unknown option: %s\n", argv[i]);
|
||||||
|
goto print_usage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!ext_if_name || !lan_addrs.lh_first) {
|
if(!ext_if_name || !lan_addrs.lh_first) {
|
||||||
|
@ -1774,17 +1827,17 @@ init(int argc, char * * argv, struct runtime_vars * v)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (use_ext_ip_addr && GETFLAG(PERFORMSTUNMASK)) {
|
if (use_ext_ip_addr && GETFLAG(PERFORMSTUNMASK)) {
|
||||||
fprintf(stderr, "Error: options ext_ip= and ext_perform_stun=yes cannot be specified together\n");
|
INIT_PRINT_ERR("Error: options ext_ip= and ext_perform_stun=yes cannot be specified together\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (use_ext_ip_addr) {
|
if (use_ext_ip_addr) {
|
||||||
if (inet_pton(AF_INET, use_ext_ip_addr, &addr) != 1) {
|
if (inet_pton(AF_INET, use_ext_ip_addr, &addr) != 1) {
|
||||||
fprintf(stderr, "Error: option ext_ip contains invalid address %s\n", use_ext_ip_addr);
|
INIT_PRINT_ERR("Error: option ext_ip contains invalid address %s\n", use_ext_ip_addr);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (addr_is_reserved(&addr)) {
|
if (addr_is_reserved(&addr)) {
|
||||||
fprintf(stderr, "Error: option ext_ip contains reserved / private address %s, not public routable\n", use_ext_ip_addr);
|
INIT_PRINT_ERR("Error: option ext_ip contains reserved / private address %s, not public routable\n", use_ext_ip_addr);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1807,14 +1860,6 @@ init(int argc, char * * argv, struct runtime_vars * v)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
openlog_option = LOG_PID|LOG_CONS;
|
|
||||||
if(debug_flag)
|
|
||||||
{
|
|
||||||
openlog_option |= LOG_PERROR; /* also log on stderr */
|
|
||||||
}
|
|
||||||
|
|
||||||
openlog("miniupnpd", openlog_option, LOG_MINIUPNPD);
|
|
||||||
|
|
||||||
if(!debug_flag)
|
if(!debug_flag)
|
||||||
{
|
{
|
||||||
switch (verbosity_level)
|
switch (verbosity_level)
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "pcplearndscp.h"
|
#include "pcplearndscp.h"
|
||||||
#endif /* PCP_SADSPC */
|
#endif /* PCP_SADSPC */
|
||||||
#include "upnpglobalvars.h"
|
#include "upnpglobalvars.h"
|
||||||
|
#include "macros.h"
|
||||||
|
|
||||||
#ifndef DISABLE_CONFIG_FILE
|
#ifndef DISABLE_CONFIG_FILE
|
||||||
struct option * ary_options = NULL;
|
struct option * ary_options = NULL;
|
||||||
|
@ -99,7 +100,7 @@ static const struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
readoptionsfile(const char * fname)
|
readoptionsfile(const char * fname, int debug_flag)
|
||||||
{
|
{
|
||||||
FILE *hfile = NULL;
|
FILE *hfile = NULL;
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
|
@ -164,8 +165,9 @@ readoptionsfile(const char * fname)
|
||||||
tmp = realloc(upnppermlist, sizeof(struct upnpperm) * (num_upnpperm+1));
|
tmp = realloc(upnppermlist, sizeof(struct upnpperm) * (num_upnpperm+1));
|
||||||
if(tmp == NULL)
|
if(tmp == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "memory allocation error. Permission line in file %s line %d\n",
|
INIT_PRINT_ERR("memory allocation error. Permission line in file %s line %d\n",
|
||||||
fname, linenum);
|
fname, linenum);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -177,8 +179,9 @@ readoptionsfile(const char * fname)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(stderr, "parsing error file %s line %d : %s\n",
|
INIT_PRINT_ERR("parsing error file %s line %d : %s\n",
|
||||||
fname, linenum, name);
|
fname, linenum, name);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
@ -190,8 +193,9 @@ readoptionsfile(const char * fname)
|
||||||
tmp = realloc(dscp_values_list, sizeof(struct dscp_values) * (num_dscp_values+1));
|
tmp = realloc(dscp_values_list, sizeof(struct dscp_values) * (num_dscp_values+1));
|
||||||
if(tmp == NULL)
|
if(tmp == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "memory allocation error. DSCP line in file %s line %d\n",
|
INIT_PRINT_ERR("memory allocation error. DSCP line in file %s line %d\n",
|
||||||
fname, linenum);
|
fname, linenum);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -203,8 +207,9 @@ readoptionsfile(const char * fname)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(stderr, "parsing error file %s line %d : %s\n",
|
INIT_PRINT_ERR("parsing error file %s line %d : %s\n",
|
||||||
fname, linenum, name);
|
fname, linenum, name);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
@ -212,9 +217,9 @@ readoptionsfile(const char * fname)
|
||||||
#endif /* PCP_SADSCP */
|
#endif /* PCP_SADSCP */
|
||||||
if(!(equals = strchr(name, '=')))
|
if(!(equals = strchr(name, '=')))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "parsing error file %s line %d : %s\n",
|
INIT_PRINT_ERR("parsing error file %s line %d : %s\n",
|
||||||
fname, linenum, name);
|
fname, linenum, name);
|
||||||
continue;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* remove ending whitespaces */
|
/* remove ending whitespaces */
|
||||||
|
@ -243,16 +248,18 @@ readoptionsfile(const char * fname)
|
||||||
|
|
||||||
if(id == UPNP_INVALID)
|
if(id == UPNP_INVALID)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "invalid option in file %s line %d : %s=%s\n",
|
INIT_PRINT_ERR("invalid option in file %s line %d : %s=%s\n",
|
||||||
fname, linenum, name, value);
|
fname, linenum, name, value);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tmp = realloc(ary_options, (num_options + 1) * sizeof(struct option));
|
tmp = realloc(ary_options, (num_options + 1) * sizeof(struct option));
|
||||||
if(tmp == NULL)
|
if(tmp == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "memory allocation error. Option in file %s line %d.\n",
|
INIT_PRINT_ERR("memory allocation error. Option in file %s line %d.\n",
|
||||||
fname, linenum);
|
fname, linenum);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -261,8 +268,9 @@ readoptionsfile(const char * fname)
|
||||||
tmp = realloc(string_repo, string_repo_len + len);
|
tmp = realloc(string_repo, string_repo_len + len);
|
||||||
if(tmp == NULL)
|
if(tmp == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "memory allocation error, Option value in file %s line %d : %s=%s\n",
|
INIT_PRINT_ERR("memory allocation error, Option value in file %s line %d : %s=%s\n",
|
||||||
fname, linenum, name, value);
|
fname, linenum, name, value);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* MiniUPnP project
|
* MiniUPnP project
|
||||||
* http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
|
* http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
|
||||||
* author: Ryan Wagoner
|
* author: Ryan Wagoner
|
||||||
* (c) 2006-2020 Thomas Bernard
|
* (c) 2006-2021 Thomas Bernard
|
||||||
* This software is subject to the conditions detailed
|
* This software is subject to the conditions detailed
|
||||||
* in the LICENCE file provided within the distribution */
|
* in the LICENCE file provided within the distribution */
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ enum upnpconfigoptions {
|
||||||
* parse and store the option file values
|
* parse and store the option file values
|
||||||
* returns: 0 success, -1 failure */
|
* returns: 0 success, -1 failure */
|
||||||
int
|
int
|
||||||
readoptionsfile(const char * fname);
|
readoptionsfile(const char * fname, int debug_flag);
|
||||||
|
|
||||||
/* freeoptions()
|
/* freeoptions()
|
||||||
* frees memory allocated to option values */
|
* frees memory allocated to option values */
|
||||||
|
|
|
@ -40,6 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include "upnpglobalvars.h"
|
#include "upnpglobalvars.h"
|
||||||
#include "pcplearndscp.h"
|
#include "pcplearndscp.h"
|
||||||
|
#include "macros.h"
|
||||||
|
|
||||||
#ifdef PCP_SADSCP
|
#ifdef PCP_SADSCP
|
||||||
|
|
||||||
|
@ -58,7 +59,7 @@ print_dscp(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
read_learn_dscp_line(struct dscp_values *dscpvalues, char *p)
|
read_learn_dscp_line(struct dscp_values *dscpvalues, char *p, int debug_flag)
|
||||||
{
|
{
|
||||||
char * q;
|
char * q;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
@ -106,8 +107,8 @@ read_learn_dscp_line(struct dscp_values *dscpvalues, char *p)
|
||||||
*q = '\0';
|
*q = '\0';
|
||||||
dscpvalues->delay = (unsigned char)atoi(p);
|
dscpvalues->delay = (unsigned char)atoi(p);
|
||||||
if (dscpvalues->delay >= 3) {
|
if (dscpvalues->delay >= 3) {
|
||||||
fprintf(stderr, "Wrong delay value %d in \n", dscpvalues->delay);
|
INIT_PRINT_ERR("Wrong delay value %d in \n", dscpvalues->delay);
|
||||||
fprintf(stderr, "Delay can be from set {0,1,2} 0=low delay, 1=medium delay, 2=high delay\n");
|
INIT_PRINT_ERR("Delay can be from set {0,1,2} 0=low delay, 1=medium delay, 2=high delay\n");
|
||||||
goto exit_err_and_cleanup;
|
goto exit_err_and_cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,8 +130,8 @@ read_learn_dscp_line(struct dscp_values *dscpvalues, char *p)
|
||||||
*q = '\0';
|
*q = '\0';
|
||||||
dscpvalues->loss = (unsigned char)atoi(p);
|
dscpvalues->loss = (unsigned char)atoi(p);
|
||||||
if (dscpvalues->loss >= 3) {
|
if (dscpvalues->loss >= 3) {
|
||||||
fprintf(stderr, "Wrong loss value %d \n", dscpvalues->loss);
|
INIT_PRINT_ERR("Wrong loss value %d \n", dscpvalues->loss);
|
||||||
fprintf(stderr, "Delay can be from set {0,1,2} 0=low loss, 1=medium loss, 2=high loss\n");
|
INIT_PRINT_ERR("Delay can be from set {0,1,2} 0=low loss, 1=medium loss, 2=high loss\n");
|
||||||
goto exit_err_and_cleanup;
|
goto exit_err_and_cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,9 +152,9 @@ read_learn_dscp_line(struct dscp_values *dscpvalues, char *p)
|
||||||
*q = '\0';
|
*q = '\0';
|
||||||
dscpvalues->jitter = (unsigned char)atoi(p);
|
dscpvalues->jitter = (unsigned char)atoi(p);
|
||||||
if (dscpvalues->jitter >= 3) {
|
if (dscpvalues->jitter >= 3) {
|
||||||
fprintf(stderr, "Wrong jitter value %d \n", dscpvalues->jitter);
|
INIT_PRINT_ERR("Wrong jitter value %d \n", dscpvalues->jitter);
|
||||||
fprintf(stderr, "Delay can be from set {0,1,2} 0=low jitter, 1=medium jitter, 2=high jitter \n");
|
INIT_PRINT_ERR("Delay can be from set {0,1,2} 0=low jitter, 1=medium jitter, 2=high jitter \n");
|
||||||
goto exit_err_and_cleanup;
|
goto exit_err_and_cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -228,7 +229,7 @@ read_learn_dscp_line(struct dscp_values *dscpvalues, char *p)
|
||||||
dscpvalues->dscp_value = 38;
|
dscpvalues->dscp_value = 38;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Unknown AF value %d \n", af_value);
|
INIT_PRINT_ERR("Unknown AF value %d \n", af_value);
|
||||||
goto exit_err_and_cleanup;
|
goto exit_err_and_cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,7 +240,7 @@ read_learn_dscp_line(struct dscp_values *dscpvalues, char *p)
|
||||||
dscpvalues->dscp_value = 0;
|
dscpvalues->dscp_value = 0;
|
||||||
}
|
}
|
||||||
else if (!isdigit(*p)) {
|
else if (!isdigit(*p)) {
|
||||||
fprintf(stderr, "Not digit after CS but %c \n", *p);
|
INIT_PRINT_ERR("Not digit after CS but %c \n", *p);
|
||||||
goto exit_err_and_cleanup;
|
goto exit_err_and_cleanup;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -267,7 +268,7 @@ read_learn_dscp_line(struct dscp_values *dscpvalues, char *p)
|
||||||
dscpvalues->dscp_value = 56;
|
dscpvalues->dscp_value = 56;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Unknown CS value %d \n", cs_value);
|
INIT_PRINT_ERR("Unknown CS value %d \n", cs_value);
|
||||||
goto exit_err_and_cleanup;
|
goto exit_err_and_cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,6 @@ struct dscp_values {
|
||||||
|
|
||||||
/* #set_learn_dscp "Webex" 1 1 1 34 */
|
/* #set_learn_dscp "Webex" 1 1 1 34 */
|
||||||
int
|
int
|
||||||
read_learn_dscp_line(struct dscp_values *dscpvalues, char *p);
|
read_learn_dscp_line(struct dscp_values *dscpvalues, char *p, int debug_flag);
|
||||||
|
|
||||||
#endif /* PCPLEARNDSCP_H_INCLUDED */
|
#endif /* PCPLEARNDSCP_H_INCLUDED */
|
||||||
|
|
Loading…
Reference in New Issue