diff --git a/acl.c b/acl.c index 032e76f8a6a802862aadc740517c637e034d5777..010ce26f838ae03befa2d00a417ff63e7eaacf90 100755 --- a/acl.c +++ b/acl.c @@ -23,6 +23,7 @@ #include <sys/socket.h> #include <netdb.h> #include <net/if.h> +#include <netinet/in.h> #include <netinet/in_systm.h> #include <netinet/ip.h> #include <sys/ioctl.h> @@ -225,6 +226,26 @@ int ast_get_ip_or_srv(struct sockaddr_in *sin, const char *value, const char *se return 0; } +int ast_str2tos(const char *value, int *tos) +{ + int fval; + if (sscanf(value, "%i", &fval) == 1) + *tos = fval & 0xff; + else if (!strcasecmp(value, "lowdelay")) + *tos = IPTOS_LOWDELAY; + else if (!strcasecmp(value, "throughput")) + *tos = IPTOS_THROUGHPUT; + else if (!strcasecmp(value, "reliability")) + *tos = IPTOS_RELIABILITY; + else if (!strcasecmp(value, "mincost")) + *tos = IPTOS_MINCOST; + else if (!strcasecmp(value, "none")) + *tos = 0; + else + return -1; + return 0; +} + int ast_get_ip(struct sockaddr_in *sin, const char *value) { return ast_get_ip_or_srv(sin, value, NULL); diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index 9c12b29f58c620c0cbcc96ad4932dc0e226c16d7..34b1de6c7713ef13416cf9aafa0823125238e661 100755 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -8370,6 +8370,7 @@ static int set_config(char *config_file, int reload) struct ast_variable *v; char *cat; char *utype; + char *tosval; int format; int portno = IAX_DEFAULT_PORTNO; int x; @@ -8399,6 +8400,12 @@ static int set_config(char *config_file, int reload) v = ast_variable_browse(cfg, "general"); + /* Seed initial tos value */ + tosval = ast_variable_retrieve(cfg, "general", "tos"); + if (tosval) { + if (ast_str2tos(v->value, &tos)) + ast_log(LOG_WARNING, "Invalid tos value, should be 'lowdelay', 'throughput', 'reliability', 'mincost', or 'none'\n"); + } while(v) { if (!strcasecmp(v->name, "bindport")){ if (reload) @@ -8529,19 +8536,7 @@ static int set_config(char *config_file, int reload) if (!ast_context_find(regcontext)) ast_context_create(NULL, regcontext, channeltype); } else if (!strcasecmp(v->name, "tos")) { - if (sscanf(v->value, "%d", &format) == 1) - tos = format & 0xff; - else if (!strcasecmp(v->value, "lowdelay")) - tos = IPTOS_LOWDELAY; - else if (!strcasecmp(v->value, "throughput")) - tos = IPTOS_THROUGHPUT; - else if (!strcasecmp(v->value, "reliability")) - tos = IPTOS_RELIABILITY; - else if (!strcasecmp(v->value, "mincost")) - tos = IPTOS_MINCOST; - else if (!strcasecmp(v->value, "none")) - tos = 0; - else + if (ast_str2tos(v->value, &tos)) ast_log(LOG_WARNING, "Invalid tos value at line %d, should be 'lowdelay', 'throughput', 'reliability', 'mincost', or 'none'\n", v->lineno); } else if (!strcasecmp(v->name, "accountcode")) { ast_copy_string(accountcode, v->value, sizeof(accountcode)); diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 898c94581f3af08b2ca60fd315031fa433d5a303..83c882eb1b14b3018d6bb3bb9bf9fff1c226a76f 100755 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -11030,19 +11030,7 @@ static int reload_config(void) } else if (!strcasecmp(v->name, "recordhistory")) { recordhistory = ast_true(v->value); } else if (!strcasecmp(v->name, "tos")) { - if (sscanf(v->value, "%i", &format) == 1) - tos = format & 0xff; - else if (!strcasecmp(v->value, "lowdelay")) - tos = IPTOS_LOWDELAY; - else if (!strcasecmp(v->value, "throughput")) - tos = IPTOS_THROUGHPUT; - else if (!strcasecmp(v->value, "reliability")) - tos = IPTOS_RELIABILITY; - else if (!strcasecmp(v->value, "mincost")) - tos = IPTOS_MINCOST; - else if (!strcasecmp(v->value, "none")) - tos = 0; - else + if (ast_str2tos(v->value, &tos)) ast_log(LOG_WARNING, "Invalid tos value at line %d, should be 'lowdelay', 'throughput', 'reliability', 'mincost', or 'none'\n", v->lineno); } else if (!strcasecmp(v->name, "bindport")) { if (sscanf(v->value, "%d", &ourport) == 1) { diff --git a/include/asterisk/acl.h b/include/asterisk/acl.h index dc3e3a4c06ebf8211a611282ab7a9fa9288935a9..45553d51d484e08c99922e00959efc0dff6c6881 100755 --- a/include/asterisk/acl.h +++ b/include/asterisk/acl.h @@ -38,6 +38,7 @@ extern int ast_ouraddrfor(struct in_addr *them, struct in_addr *us); extern int ast_lookup_iface(char *iface, struct in_addr *address); extern struct ast_ha *ast_duplicate_ha_list(struct ast_ha *original); extern int ast_find_ourip(struct in_addr *ourip, struct sockaddr_in bindaddr); +extern int ast_str2tos(const char *value, int *tos); #if defined(__cplusplus) || defined(c_plusplus) }