From 5567e7c7e05f2cda8e2f82d97b4054c5729fb933 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Fri, 18 Jun 2021 00:21:16 +0200 Subject: [PATCH] miniupnpd: improves error handling during init. - Fails on config parsing and init errors. - print errors during init to both syslog and stderr. fixes #551 --- miniupnpd/Changelog.txt | 4 + miniupnpd/macros.h | 7 +- miniupnpd/miniupnpd.c | 293 ++++++++++++++++++++++----------------- miniupnpd/options.c | 28 ++-- miniupnpd/options.h | 4 +- miniupnpd/pcplearndscp.c | 23 +-- miniupnpd/pcplearndscp.h | 2 +- 7 files changed, 212 insertions(+), 149 deletions(-) diff --git a/miniupnpd/Changelog.txt b/miniupnpd/Changelog.txt index 98056b3..a2865e5 100644 --- a/miniupnpd/Changelog.txt +++ b/miniupnpd/Changelog.txt @@ -1,5 +1,9 @@ $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: dynamically retrieve `uname -r` diff --git a/miniupnpd/macros.h b/miniupnpd/macros.h index 89cddeb..fc13c05 100644 --- a/miniupnpd/macros.h +++ b/miniupnpd/macros.h @@ -1,7 +1,7 @@ /* $Id: macros.h,v 1.5 2019/09/24 09:37:52 nanard Exp $ */ /* MiniUPnP project * 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 * in the LICENCE file provided within the distribution */ @@ -16,6 +16,11 @@ #define FALL_THROUGH #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 #ifndef INLINE diff --git a/miniupnpd/miniupnpd.c b/miniupnpd/miniupnpd.c index 10924c7..e4feac2 100644 --- a/miniupnpd/miniupnpd.c +++ b/miniupnpd/miniupnpd.c @@ -919,7 +919,7 @@ struct runtime_vars { * 0 : ok * -1 : error */ 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; unsigned int n; @@ -939,6 +939,7 @@ parselanaddr(struct lan_addr_s * lan_addr, const char * str) &lan_addr->addr, &lan_addr->mask) < 0) { #ifdef ENABLE_IPV6 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->addr.s_addr = htonl(0x00000000u); lan_addr->mask.s_addr = htonl(0xffffffffu); @@ -958,10 +959,10 @@ parselanaddr(struct lan_addr_s * lan_addr, const char * str) goto parselan_error; } if(!addr_is_reserved(&lan_addr->addr)) { - fprintf(stderr, "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"); - fprintf(stderr, "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("Error: LAN address contains public IP address : %s\n", lan_addr->str); + INIT_PRINT_ERR("Public IP address can be configured via ext_ip= option\n"); + INIT_PRINT_ERR("LAN address should contain private address, e.g. from 192.168. block\n"); + INIT_PRINT_ERR("Listening on public IP address is a security issue\n"); return -1; } if(*p == '/') @@ -1010,12 +1011,12 @@ parselanaddr(struct lan_addr_s * lan_addr, const char * str) lan_addr->ext_ip_str[n] = '\0'; if(!inet_aton(lan_addr->ext_ip_str, &lan_addr->ext_ip_addr)) { /* 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; } if(addr_is_reserved(&lan_addr->ext_ip_addr)) { /* 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; } } @@ -1033,7 +1034,7 @@ parselanaddr(struct lan_addr_s * lan_addr, const char * str) n++; } if(n >= sizeof(tmp)) { - fprintf(stderr, "Cannot parse '%s'\n", p); + INIT_PRINT_ERR("Cannot parse '%s'\n", p); break; } tmp[n] = '\0'; @@ -1041,6 +1042,8 @@ parselanaddr(struct lan_addr_s * lan_addr, const char * str) if(index == 0) { fprintf(stderr, "Cannot get index for network interface %s\n", tmp); + syslog(LOG_WARNING, "Cannot get index for network interface %s\n", + tmp); } else { lan_addr->add_indexes |= (1UL << (index - 1)); } @@ -1048,31 +1051,25 @@ parselanaddr(struct lan_addr_s * lan_addr, const char * str) } } #endif - if(lan_addr->ifname[0] != '\0') - { + if(lan_addr->ifname[0] != '\0') { 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", lan_addr->ifname); - } + syslog(LOG_WARNING, "Cannot get index for network interface %s\n", + lan_addr->ifname); + } + } else { #ifdef ENABLE_IPV6 - else - { - fprintf(stderr, - "Error: please specify LAN network interface by name instead of IPv4 address : %s\n", - str); + INIT_PRINT_ERR("Error: please specify LAN network interface by name instead of IPv4 address : %s\n", str); return -1; - } #else - else - { syslog(LOG_NOTICE, "it is advised to use network interface name instead of %s", str); - } #endif + } return 0; parselan_error: - fprintf(stderr, "Error parsing address/mask (or interface name) : %s\n", - str); + INIT_PRINT_ERR("Error parsing address/mask (or interface name) : %s\n", str); 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")) 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 /* first check if "-f" option is used */ for(i=2; i= max_lifetime) { - fprintf(stderr, "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("Minimum lifetime (%lu) is greater than or equal to maximum lifetime (%lu).\n", min_lifetime, max_lifetime); + INIT_PRINT_ERR("Check your configuration file.\n"); return 1; } #endif /* ENABLE_PCP */ 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; } } @@ -1467,7 +1480,8 @@ init(int argc, char * * argv, struct runtime_vars * v) { 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]) { @@ -1491,8 +1505,10 @@ init(int argc, char * * argv, struct runtime_vars * v) case 'b': if(i+1 < argc) { upnp_bootid = (unsigned int)strtoul(argv[++i], NULL, 10); - } else - fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]); + } else { + INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]); + goto print_usage; + } break; case 'o': if(i+1 < argc) { @@ -1508,49 +1524,63 @@ init(int argc, char * * argv, struct runtime_vars * v) } } else use_ext_ip_addr = argv[i]; - } else - fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]); + } else { + INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]); + goto print_usage; + } break; case 't': - if(i+1 < argc) + if(i+1 < argc) { v->notify_interval = atoi(argv[++i]); - else - fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]); + } else { + INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]); + goto print_usage; + } break; case 'r': - if(i+1 < argc) + if(i+1 < argc) { v->clean_ruleset_interval = atoi(argv[++i]); - else - fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]); + } else { + INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]); + goto print_usage; + } break; case 'u': if(i+1 < argc) { strncpy(uuidvalue_igd+5, argv[++i], strlen(uuidvalue_igd+5) + 1); complete_uuidvalues(); - } else - fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]); + } else { + INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]); + goto print_usage; + } break; #ifdef ENABLE_MANUFACTURER_INFO_CONFIGURATION case 'z': - if(i+1 < argc) + if(i+1 < argc) { strncpy(friendly_name, argv[++i], FRIENDLY_NAME_MAX_LEN); - else - fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]); + } else { + INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]); + goto print_usage; + } friendly_name[FRIENDLY_NAME_MAX_LEN-1] = '\0'; break; #endif /* ENABLE_MANUFACTURER_INFO_CONFIGURATION */ case 's': - if(i+1 < argc) + if(i+1 < argc) { strncpy(serialnumber, argv[++i], SERIALNUMBER_MAX_LEN); - else - fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]); + } else { + INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]); + goto print_usage; + } serialnumber[SERIALNUMBER_MAX_LEN-1] = '\0'; break; case 'm': - if(i+1 < argc) + if(i+1 < argc) { strncpy(modelnumber, argv[++i], MODELNUMBER_MAX_LEN); - else - fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]); + } else { + INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]); + goto print_usage; + } modelnumber[MODELNUMBER_MAX_LEN-1] = '\0'; break; #ifdef ENABLE_NATPMP @@ -1576,55 +1606,67 @@ init(int argc, char * * argv, struct runtime_vars * v) SETFLAG(SECUREMODEMASK); break; case 'i': - if(i+1 < argc) + if(i+1 < argc) { ext_if_name = argv[++i]; - else - fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]); + } else { + INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]); + goto print_usage; + } break; #ifdef ENABLE_IPV6 case 'I': - if(i+1 < argc) + if(i+1 < argc) { ext_if_name6 = argv[++i]; - else - fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]); + } else { + INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]); + goto print_usage; + } break; #endif #ifdef USE_PF case 'q': - if(i+1 < argc) + if(i+1 < argc) { queue = argv[++i]; - else - fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]); + } else { + INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]); + goto print_usage; + } break; case 'T': - if(i+1 < argc) + if(i+1 < argc) { tag = argv[++i]; - else - fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]); + } else { + INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]); + goto print_usage; + } break; #endif /* USE_PF */ case 'p': - if(i+1 < argc) + if(i+1 < argc) { v->port = atoi(argv[++i]); - else - fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]); + } else { + INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]); + goto print_usage; + } break; #ifdef ENABLE_HTTPS case 'H': - if(i+1 < argc) + if(i+1 < argc) { v->https_port = atoi(argv[++i]); - else - fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]); + } else { + INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]); + goto print_usage; + } break; #endif /* ENABLE_HTTPS */ #ifdef ENABLE_NFQUEUE case 'Q': - if(i+1list.le_next) @@ -1694,33 +1740,34 @@ init(int argc, char * * argv, struct runtime_vars * v) } if (lan_addr2 == NULL) 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 */ if(i+2 < argc) { char *val = calloc((strlen(argv[i+1]) + strlen(argv[i+2]) + 2), sizeof(char)); if (val == NULL) { - fprintf(stderr, "memory allocation error for listen address storage\n"); - break; + INIT_PRINT_ERR("memory allocation error for listen address storage\n"); + return 1; } sprintf(val, "%s %s", argv[i+1], argv[i+2]); lan_addr = (struct lan_addr_s *) malloc(sizeof(struct lan_addr_s)); 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); - 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(val); - break; + return 1; } /* check if we already have this address */ 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); 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 */ break; case 'A': @@ -1743,23 +1791,28 @@ init(int argc, char * * argv, struct runtime_vars * v) void * tmp; tmp = realloc(upnppermlist, sizeof(struct upnpperm) * (num_upnpperm+1)); if(tmp == NULL) { - fprintf(stderr, "memory allocation error for permission\n"); + INIT_PRINT_ERR("memory allocation error for permission\n"); + return 1; } else { upnppermlist = tmp; if(read_permission_line(upnppermlist + num_upnpperm, argv[++i]) >= 0) { num_upnpperm++; } 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 - fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]); + } else { + INIT_PRINT_ERR("Option -%c takes one argument.\n", argv[i][1]); + goto print_usage; + } break; case 'f': i++; /* discarding, the config file is already read */ break; 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) { @@ -1774,17 +1827,17 @@ init(int argc, char * * argv, struct runtime_vars * v) #endif 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; } if (use_ext_ip_addr) { 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; } 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; } } @@ -1807,14 +1860,6 @@ init(int argc, char * * argv, struct runtime_vars * v) } #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) { switch (verbosity_level) diff --git a/miniupnpd/options.c b/miniupnpd/options.c index 05fa317..026a1fe 100644 --- a/miniupnpd/options.c +++ b/miniupnpd/options.c @@ -19,6 +19,7 @@ #include "pcplearndscp.h" #endif /* PCP_SADSPC */ #include "upnpglobalvars.h" +#include "macros.h" #ifndef DISABLE_CONFIG_FILE struct option * ary_options = NULL; @@ -99,7 +100,7 @@ static const struct { }; int -readoptionsfile(const char * fname) +readoptionsfile(const char * fname, int debug_flag) { FILE *hfile = NULL; char buffer[1024]; @@ -164,8 +165,9 @@ readoptionsfile(const char * fname) tmp = realloc(upnppermlist, sizeof(struct upnpperm) * (num_upnpperm+1)); 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); + return -1; } else { @@ -177,8 +179,9 @@ readoptionsfile(const char * fname) } 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); + return -1; } } continue; @@ -190,8 +193,9 @@ readoptionsfile(const char * fname) tmp = realloc(dscp_values_list, sizeof(struct dscp_values) * (num_dscp_values+1)); 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); + return -1; } else { @@ -203,8 +207,9 @@ readoptionsfile(const char * fname) } 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); + return -1; } } continue; @@ -212,9 +217,9 @@ readoptionsfile(const char * fname) #endif /* PCP_SADSCP */ 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); - continue; + return -1; } /* remove ending whitespaces */ @@ -243,16 +248,18 @@ readoptionsfile(const char * fname) 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); + return -1; } else { tmp = realloc(ary_options, (num_options + 1) * sizeof(struct option)); 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); + return -1; } else { @@ -261,8 +268,9 @@ readoptionsfile(const char * fname) tmp = realloc(string_repo, string_repo_len + len); 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); + return -1; } else { diff --git a/miniupnpd/options.h b/miniupnpd/options.h index 96cdbbf..b5fd0cc 100644 --- a/miniupnpd/options.h +++ b/miniupnpd/options.h @@ -3,7 +3,7 @@ * MiniUPnP project * http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/ * author: Ryan Wagoner - * (c) 2006-2020 Thomas Bernard + * (c) 2006-2021 Thomas Bernard * This software is subject to the conditions detailed * in the LICENCE file provided within the distribution */ @@ -84,7 +84,7 @@ enum upnpconfigoptions { * parse and store the option file values * returns: 0 success, -1 failure */ int -readoptionsfile(const char * fname); +readoptionsfile(const char * fname, int debug_flag); /* freeoptions() * frees memory allocated to option values */ diff --git a/miniupnpd/pcplearndscp.c b/miniupnpd/pcplearndscp.c index 55814d3..15dd7a9 100644 --- a/miniupnpd/pcplearndscp.c +++ b/miniupnpd/pcplearndscp.c @@ -40,6 +40,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "upnpglobalvars.h" #include "pcplearndscp.h" +#include "macros.h" #ifdef PCP_SADSCP @@ -58,7 +59,7 @@ print_dscp(void) { } 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; size_t len; @@ -106,8 +107,8 @@ read_learn_dscp_line(struct dscp_values *dscpvalues, char *p) *q = '\0'; dscpvalues->delay = (unsigned char)atoi(p); if (dscpvalues->delay >= 3) { - fprintf(stderr, "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("Wrong delay value %d in \n", dscpvalues->delay); + 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; } } @@ -129,8 +130,8 @@ read_learn_dscp_line(struct dscp_values *dscpvalues, char *p) *q = '\0'; dscpvalues->loss = (unsigned char)atoi(p); if (dscpvalues->loss >= 3) { - fprintf(stderr, "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("Wrong loss value %d \n", dscpvalues->loss); + 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; } } @@ -151,9 +152,9 @@ read_learn_dscp_line(struct dscp_values *dscpvalues, char *p) *q = '\0'; dscpvalues->jitter = (unsigned char)atoi(p); if (dscpvalues->jitter >= 3) { - fprintf(stderr, "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"); - goto exit_err_and_cleanup; + INIT_PRINT_ERR("Wrong jitter value %d \n", dscpvalues->jitter); + 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; } } else @@ -228,7 +229,7 @@ read_learn_dscp_line(struct dscp_values *dscpvalues, char *p) dscpvalues->dscp_value = 38; break; 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; } } @@ -239,7 +240,7 @@ read_learn_dscp_line(struct dscp_values *dscpvalues, char *p) dscpvalues->dscp_value = 0; } 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; } else { @@ -267,7 +268,7 @@ read_learn_dscp_line(struct dscp_values *dscpvalues, char *p) dscpvalues->dscp_value = 56; break; 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; } } diff --git a/miniupnpd/pcplearndscp.h b/miniupnpd/pcplearndscp.h index 93fee33..21a00c9 100644 --- a/miniupnpd/pcplearndscp.h +++ b/miniupnpd/pcplearndscp.h @@ -46,6 +46,6 @@ struct dscp_values { /* #set_learn_dscp "Webex" 1 1 1 34 */ 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 */