Module: kamailio
Branch: master
Commit: ed80ec347ec74d0364fce9cc74fe83df443b9ac8
URL:
https://github.com/kamailio/kamailio/commit/ed80ec347ec74d0364fce9cc74fe83d…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2020-11-11T09:29:08+01:00
core: added local_rport global parameter
- similar to add_local_rport() but set globally
---
Modified: src/core/cfg.lex
Modified: src/core/cfg.y
Modified: src/core/globals.h
Modified: src/core/msg_translator.c
---
Diff:
https://github.com/kamailio/kamailio/commit/ed80ec347ec74d0364fce9cc74fe83d…
Patch:
https://github.com/kamailio/kamailio/commit/ed80ec347ec74d0364fce9cc74fe83d…
---
diff --git a/src/core/cfg.lex b/src/core/cfg.lex
index 679ffdb898..d40434c442 100644
--- a/src/core/cfg.lex
+++ b/src/core/cfg.lex
@@ -154,6 +154,7 @@ ROUTE_SEND onsend_route
ROUTE_EVENT event_route
EXEC exec
FORCE_RPORT "force_rport"|"add_rport"
+LOCAL_RPORT "local_rport"
ADD_LOCAL_RPORT "add_local_rport"
FORCE_TCP_ALIAS "force_tcp_alias"|"add_tcp_alias"
UDP_MTU "udp_mtu"
@@ -638,6 +639,8 @@ IMPORTFILE "import_file"
<INITIAL>{SET_USERPHONE} { count(); yylval.strval=yytext;
return SET_USERPHONE; }
<INITIAL>{FORCE_RPORT} { count(); yylval.strval=yytext; return FORCE_RPORT; }
+<INITIAL>{LOCAL_RPORT} { count(); yylval.strval=yytext;
+ return LOCAL_RPORT; }
<INITIAL>{ADD_LOCAL_RPORT} { count(); yylval.strval=yytext;
return ADD_LOCAL_RPORT; }
<INITIAL>{FORCE_TCP_ALIAS} { count(); yylval.strval=yytext;
diff --git a/src/core/cfg.y b/src/core/cfg.y
index cd2db30cd8..8390075c4e 100644
--- a/src/core/cfg.y
+++ b/src/core/cfg.y
@@ -253,6 +253,7 @@ extern char *default_routename;
%token REVERT_URI
%token FORCE_RPORT
%token ADD_LOCAL_RPORT
+%token LOCAL_RPORT
%token FORCE_TCP_ALIAS
%token UDP_MTU
%token UDP_MTU_TRY_PROTO
@@ -1757,6 +1758,8 @@ assign_stm:
| FORCE_RPORT EQUAL NUMBER
{ default_core_cfg.force_rport=$3; fix_global_req_flags(0, 0); }
| FORCE_RPORT EQUAL error { yyerror("boolean value expected"); }
+ | LOCAL_RPORT EQUAL NUMBER { ksr_local_rport=$3; }
+ | LOCAL_RPORT EQUAL error { yyerror("boolean value expected"); }
| UDP_MTU_TRY_PROTO EQUAL proto
{ default_core_cfg.udp_mtu_try_proto=$3; fix_global_req_flags(0, 0); }
| UDP_MTU_TRY_PROTO EQUAL error
diff --git a/src/core/globals.h b/src/core/globals.h
index 8d4c467741..c56c5bec84 100644
--- a/src/core/globals.h
+++ b/src/core/globals.h
@@ -222,6 +222,7 @@ extern unsigned char *_ksr_hname_extra_chars;
extern char *ksr_stats_namesep;
extern str ksr_ipv6_hex_style;
+extern int ksr_local_rport;
#ifdef USE_DNS_CACHE
extern int dns_cache_init; /* if 0, the DNS cache is not initialized at startup */
diff --git a/src/core/msg_translator.c b/src/core/msg_translator.c
index 77b90a92c6..07e70b715f 100644
--- a/src/core/msg_translator.c
+++ b/src/core/msg_translator.c
@@ -114,6 +114,7 @@ extern int version_len;
str _ksr_xavp_via_params = STR_NULL;
str _ksr_xavp_via_fields = STR_NULL;
+int ksr_local_rport = 0;
/** per process fixup function for global_req_flags.
* It should be called from the configuration framework.
@@ -2975,7 +2976,7 @@ char* create_via_hf(unsigned int *len,
#endif /* USE_TCP || USE_SCTP */
/* test and add rport parameter to local via - rfc3581 */
- if(msg && msg->msg_flags&FL_ADD_LOCAL_RPORT) {
+ if((ksr_local_rport) || (msg && (msg->msg_flags&FL_ADD_LOCAL_RPORT))) {
/* params so far + ';rport' + '\0' */
via = (char*)pkg_malloc(extra_params.len+RPORT_LEN);
if(via==0) {