Module: sip-router Branch: master Commit: bb4cd6b04928615d02ec9b1c6f8c64a157e1fe3d URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=bb4cd6b0...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Sun May 3 13:04:49 2009 +0200
core: auto_aliases to control rev DNS aliases
- parameter takes boolean value - if set, rev dns results are added to aliases list - default is set
---
cfg.lex | 3 +++ cfg.y | 3 +++ globals.h | 1 + main.c | 2 ++ socket_info.c | 9 +++++---- 5 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/cfg.lex b/cfg.lex index b1f9c55..21d30b9 100644 --- a/cfg.lex +++ b/cfg.lex @@ -273,6 +273,7 @@ LOGSTDERROR log_stderror LOGFACILITY log_facility LISTEN listen ALIAS alias +SR_AUTO_ALIASES auto_aliases DNS dns REV_DNS rev_dns DNS_TRY_IPV6 dns_try_ipv6 @@ -550,6 +551,8 @@ EAT_ABLE [\ \t\b\r] <INITIAL>{LOGFACILITY} { yylval.strval=yytext; return LOGFACILITY; } <INITIAL>{LISTEN} { count(); yylval.strval=yytext; return LISTEN; } <INITIAL>{ALIAS} { count(); yylval.strval=yytext; return ALIAS; } +<INITIAL>{SR_AUTO_ALIASES} { count(); yylval.strval=yytext; + return SR_AUTO_ALIASES; } <INITIAL>{DNS} { count(); yylval.strval=yytext; return DNS; } <INITIAL>{REV_DNS} { count(); yylval.strval=yytext; return REV_DNS; } <INITIAL>{DNS_TRY_IPV6} { count(); yylval.strval=yytext; diff --git a/cfg.y b/cfg.y index a281052..622e880 100644 --- a/cfg.y +++ b/cfg.y @@ -333,6 +333,7 @@ static int case_check_default(struct case_stms* stms); %token LOGFACILITY %token LISTEN %token ALIAS +%token SR_AUTO_ALIASES %token DNS %token REV_DNS %token DNS_TRY_IPV6 @@ -1272,6 +1273,8 @@ assign_stm: free_socket_id_lst($3); } | ALIAS EQUAL error { yyerror(" hostname expected"); } + | SR_AUTO_ALIASES EQUAL NUMBER { sr_auto_aliases=$3; } + | SR_AUTO_ALIASES EQUAL error { yyerror("boolean value expected"); } | ADVERTISED_ADDRESS EQUAL listen_id { default_global_address.s=$3; default_global_address.len=strlen($3); diff --git a/globals.h b/globals.h index 734c370..f7ef9f8 100644 --- a/globals.h +++ b/globals.h @@ -117,6 +117,7 @@ extern int sock_gid; extern int sock_mode; extern char* chroot_dir; extern char* working_dir; +extern int sr_auto_aliases;
#ifdef USE_MCAST extern int mcast_loopback; diff --git a/main.c b/main.c index 4f0169b..4d7fd1f 100644 --- a/main.c +++ b/main.c @@ -348,6 +348,8 @@ int mhomed=0; /* use dns and/or rdns or to see if we need to add a ;received=x.x.x.x to via: */ int received_dns = 0; +/* add or not the rev dns names to aliases list */ +int sr_auto_aliases=1; char* working_dir = 0; char* chroot_dir = 0; char* user=0; diff --git a/socket_info.c b/socket_info.c index 8fa909b..ac2c82f 100644 --- a/socket_info.c +++ b/socket_info.c @@ -822,7 +822,8 @@ static int fix_hostname(str* name, struct ip_addr* address, str* address_str, } /* check if we got the official name */ if (strcasecmp(he->h_name, name->s)!=0){ - if (add_alias(name->s, name->len, s->port_no, s->proto)<0){ + if (sr_auto_aliases && + add_alias(name->s, name->len, s->port_no, s->proto)<0){ LOG(L_ERR, "ERROR: fix_hostname: add_alias failed\n"); } /* change the official name */ @@ -836,9 +837,9 @@ static int fix_hostname(str* name, struct ip_addr* address, str* address_str, strncpy(name->s, he->h_name, name->len+1); } /* add the aliases*/ - for(h=he->h_aliases; h && *h; h++) + for(h=he->h_aliases; sr_auto_aliases && h && *h; h++) if (add_alias(*h, strlen(*h), s->port_no, s->proto)<0){ - LOG(L_ERR, "ERROR: fix_hostname: add_alias failed\n"); + LOG(L_ERR, "ERROR: fix_hostname: add_alias failed\n"); } hostent2ip_addr(address, he, 0); /*convert to ip_addr format*/ if (type_flags){ @@ -853,7 +854,7 @@ static int fix_hostname(str* name, struct ip_addr* address, str* address_str, strncpy(address_str->s, tmp, strlen(tmp)+1); /* set is_ip (1 if name is an ip address, 0 otherwise) */ address_str->len=strlen(tmp); - if ((address_str->len==name->len) && + if (sr_auto_aliases && (address_str->len==name->len) && (strncasecmp(address_str->s, name->s, address_str->len)==0)){ *flags|=SI_IS_IP; /* do rev. DNS on it (for aliases)*/