Browse code

core: new global parameter return_mode

- control the return code evaluation mode:
- 0 (default) - evaluation is like so far (negative is false, positive
is true)
- 1 - propagate return value and evaluation has to be done with >0 or
<0, otherwise value!=0 is evaluated to true no matter is negative
or positive

Daniel-Constantin Mierla authored on 17/11/2022 12:05:59
Showing 1 changed files
... ...
@@ -227,6 +227,7 @@ extern char *default_routename;
227 227
 %token EXIT
228 228
 %token DROP
229 229
 %token RETURN
230
+%token RETURN_MODE
230 231
 %token BREAK
231 232
 %token LOG_TOK
232 233
 %token ERROR
... ...
@@ -1900,6 +1901,8 @@ assign_stm:
1900 1901
 	| WAIT_WORKER1_USLEEP EQUAL error { yyerror("number expected"); }
1901 1902
     | SERVER_ID EQUAL NUMBER { server_id=$3; }
1902 1903
 	| SERVER_ID EQUAL error  { yyerror("number expected"); }
1904
+    | RETURN_MODE EQUAL NUMBER { ksr_return_mode=$3; }
1905
+	| RETURN_MODE EQUAL error  { yyerror("number expected"); }
1903 1906
 	| KEMI DOT ONSEND_ROUTE_CALLBACK EQUAL STRING {
1904 1907
 			kemi_onsend_route_callback.s = $5;
1905 1908
 			kemi_onsend_route_callback.len = strlen($5);
Browse code

core: rename RV_INT to RV_LONG and RVE_INT_OP to RVE_LONG_OP

Daniel-Constantin Mierla authored on 16/11/2022 13:20:38
Showing 1 changed files
... ...
@@ -2438,7 +2438,7 @@ preprocess_stm:
2438 2438
 			}else if (!rve_check_type((enum rval_type*)&i_tmp, $1, 0, 0 ,0)){
2439 2439
 				yyerror("invalid expression");
2440 2440
 				$$=0;
2441
-			}else if (i_tmp!=RV_INT && i_tmp!=RV_NONE){
2441
+			}else if (i_tmp!=RV_LONG && i_tmp!=RV_NONE){
2442 2442
 				yyerror("invalid expression type, int expected\n");
2443 2443
 				$$=0;
2444 2444
 			}else
... ...
@@ -2562,7 +2562,7 @@ exp_elem:
2562 2562
 			$$=0;
2563 2563
 			if (rve_is_constant($3)){
2564 2564
 				i_tmp=rve_guess_type($3);
2565
-				if (i_tmp==RV_INT)
2565
+				if (i_tmp==RV_LONG)
2566 2566
 					yyerror("string expected");
2567 2567
 				else if (i_tmp==RV_STR){
2568 2568
 					if (((rval_tmp=rval_expr_eval(0, 0, $3))==0) ||
... ...
@@ -2806,7 +2806,7 @@ ct_rval: rval_expr {
2806 2806
 			} else if ($1 &&
2807 2807
 						!rve_check_type((enum rval_type*)&i_tmp, $1, 0, 0 ,0)){
2808 2808
 				yyerror("invalid expression (bad type)");
2809
-			}else if ($1 && i_tmp!=RV_INT){
2809
+			}else if ($1 && i_tmp!=RV_LONG){
2810 2810
 				yyerror("invalid expression type, int expected\n");
2811 2811
 			*/
2812 2812
 			}else
... ...
@@ -3166,7 +3166,7 @@ lval: attr_id_ass {
3166 3166
 				}
3167 3167
 	;
3168 3168
 
3169
-rval: intno			{$$=mk_rve_rval(RV_INT, (void*)$1); }
3169
+rval: intno			{$$=mk_rve_rval(RV_LONG, (void*)$1); }
3170 3170
 	| STRING			{	s_tmp.s=$1; s_tmp.len=strlen($1);
3171 3171
 							$$=mk_rve_rval(RV_STR, &s_tmp); }
3172 3172
 	| attr_id_any		{$$=mk_rve_rval(RV_AVP, $1); pkg_free($1); }
... ...
@@ -3217,7 +3217,7 @@ rval_expr: rval						{ $$=$1;
3217 3217
 										}
3218 3218
 									}
3219 3219
 		| rve_un_op rval_expr %prec UNARY	{$$=mk_rve1($1, $2); }
3220
-		| INTCAST rval_expr				{$$=mk_rve1(RVE_INT_OP, $2); }
3220
+		| INTCAST rval_expr				{$$=mk_rve1(RVE_LONG_OP, $2); }
3221 3221
 		| STRCAST rval_expr				{$$=mk_rve1(RVE_STR_OP, $2); }
3222 3222
 		| rval_expr PLUS rval_expr		{$$=mk_rve2(RVE_PLUS_OP, $1, $3); }
3223 3223
 		| rval_expr MINUS rval_expr		{$$=mk_rve2(RVE_MINUS_OP, $1, $3); }
... ...
@@ -4033,7 +4033,7 @@ static int rval_expr_int_check(struct rval_expr *rve)
4033 4033
 		else
4034 4034
 			yyerror("BUG: unexpected null \"bad\" expression\n");
4035 4035
 		return -1;
4036
-	}else if (type!=RV_INT && type!=RV_NONE){
4036
+	}else if (type!=RV_LONG && type!=RV_NONE){
4037 4037
 		warn_at(&rve->fpos, "non-int expression (you might want to use"
4038 4038
 				" casts)\n");
4039 4039
 		return 1;
Browse code

core: support to specify options for load module

- prototypes:
loadmodule("path", "options")
loadmodulex("path", "options")
- options is a string with characters:
- 'g' or 'G' - open the module shared object file with RTLD_GLOBAL set,
wich can be used for modules related to external scripting languages
to avoid reloading
- example: loadmodule("app_lua", "g")

Daniel-Constantin Mierla authored on 02/09/2022 11:15:35
Showing 1 changed files
... ...
@@ -2045,26 +2045,38 @@ cfg_var:
2045 2045
 module_stm:
2046 2046
 	LOADMODULE STRING {
2047 2047
 		LM_DBG("loading module %s\n", $2);
2048
-			if (load_module($2)!=0) {
2048
+			if (ksr_load_module($2, NULL)!=0) {
2049 2049
 				yyerror("failed to load module");
2050 2050
 			}
2051 2051
 	}
2052 2052
 	| LOADMODULE LPAREN STRING RPAREN {
2053 2053
 		LM_DBG("loading module %s\n", $3);
2054
-			if (load_module($3)!=0) {
2054
+			if (ksr_load_module($3, NULL)!=0) {
2055
+				yyerror("failed to load module");
2056
+			}
2057
+	}
2058
+	| LOADMODULE LPAREN STRING COMMA STRING RPAREN {
2059
+		LM_DBG("loading module %s opts %s\n", $3, $5);
2060
+			if (ksr_load_module($3, $5)!=0) {
2055 2061
 				yyerror("failed to load module");
2056 2062
 			}
2057 2063
 	}
2058 2064
 	| LOADMODULE error	{ yyerror("string expected"); }
2059 2065
 	| LOADMODULEX STRING {
2060 2066
 		LM_DBG("loading module %s\n", $2);
2061
-			if (load_modulex($2)!=0) {
2067
+			if (ksr_load_modulex($2, NULL)!=0) {
2062 2068
 				yyerror("failed to load module");
2063 2069
 			}
2064 2070
 	}
2065 2071
 	| LOADMODULEX LPAREN STRING RPAREN {
2066 2072
 		LM_DBG("loading module %s\n", $3);
2067
-			if (load_modulex($3)!=0) {
2073
+			if (ksr_load_modulex($3, NULL)!=0) {
2074
+				yyerror("failed to load module");
2075
+			}
2076
+	}
2077
+	| LOADMODULEX LPAREN STRING COMMA STRING RPAREN {
2078
+		LM_DBG("loading module %s opts %s\n", $3, $5);
2079
+			if (ksr_load_modulex($3, $5)!=0) {
2068 2080
 				yyerror("failed to load module");
2069 2081
 			}
2070 2082
 	}
Browse code

core: support for loadmodule("path") and loadmodules("path")

Daniel-Constantin Mierla authored on 02/09/2022 10:06:20
Showing 1 changed files
... ...
@@ -2049,6 +2049,12 @@ module_stm:
2049 2049
 				yyerror("failed to load module");
2050 2050
 			}
2051 2051
 	}
2052
+	| LOADMODULE LPAREN STRING RPAREN {
2053
+		LM_DBG("loading module %s\n", $3);
2054
+			if (load_module($3)!=0) {
2055
+				yyerror("failed to load module");
2056
+			}
2057
+	}
2052 2058
 	| LOADMODULE error	{ yyerror("string expected"); }
2053 2059
 	| LOADMODULEX STRING {
2054 2060
 		LM_DBG("loading module %s\n", $2);
... ...
@@ -2056,6 +2062,12 @@ module_stm:
2056 2062
 				yyerror("failed to load module");
2057 2063
 			}
2058 2064
 	}
2065
+	| LOADMODULEX LPAREN STRING RPAREN {
2066
+		LM_DBG("loading module %s\n", $3);
2067
+			if (load_modulex($3)!=0) {
2068
+				yyerror("failed to load module");
2069
+			}
2070
+	}
2059 2071
 	| LOADMODULEX error	{ yyerror("string expected"); }
2060 2072
 	| LOADPATH STRING {
2061 2073
 		if(mods_dir_cmd==0) {
Browse code

core: fix build warning

> In file included from /usr/include/string.h:519,
> from core/socket_info.c:34:
> In function 'strncpy',
> inlined from 'fix_hostname' at core/socket_info.c:1741:2:
> Warning: /usr/include/x86_64-linux-gnu/bits/string_fortified.h:95:10: warning: '__builtin_strncpy' specified bound depends on the length of the source argument [-Wstringop-truncation]
> 95 | return __builtin___strncpy_chk (__dest, __src, __len,
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 96 | __glibc_objsize (__dest));
> | ~~~~~~~~~~~~~~~~~~~~~~~~~
> core/socket_info.c: In function 'fix_hostname':
> core/socket_info.c:1741:38: note: length computed here
> 1741 | strncpy(address_str->s, tmp, strlen(tmp)+1);
> | ^~~~~~~~~~~
> In file included from /usr/include/string.h:519,
> from core/socket_info.c:34:
> In function 'strncpy',
> inlined from 'build_iface_list' at core/socket_info.c:1554:5:
> Warning: /usr/include/x86_64-linux-gnu/bits/string_fortified.h:95:10: warning: '__builtin_strncpy' output may be truncated copying 63 bytes from a string of length 63 [-Wstringop-truncation]
> 95 | return __builtin___strncpy_chk (__dest, __src, __len,
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 96 | __glibc_objsize (__dest));
> | ~~~~~~~~~~~~~~~~~~~~~~~~~

> In file included from /usr/include/string.h:519,
> from core/cfg.y:40:
> In function 'strncpy',
> inlined from 'yyparse' at core/cfg.y:708:6:
> Warning: /usr/include/x86_64-linux-gnu/bits/string_fortified.h:95:10: warning: '__builtin_strncpy' specified bound depends on the length of the source argument [-Wstringop-truncation]
> 95 | return __builtin___strncpy_chk (__dest, __src, __len,
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 96 | __glibc_objsize (__dest));
> | ~~~~~~~~~~~~~~~~~~~~~~~~~
> core/cfg.tab.c: In function 'yyparse':
> core/cfg.y:708:84: note: length computed here
> 708 | strncpy($$, $1, strlen($1)+1);
> | ^
> In file included from /usr/include/string.h:519,
> from core/cfg.y:40:
> In function 'strncpy',
> inlined from 'yyparse' at core/cfg.y:699:5:
> Warning: /usr/include/x86_64-linux-gnu/bits/string_fortified.h:95:10: warning: '__builtin_strncpy' specified bound depends on the length of the source argument [-Wstringop-truncation]
> 95 | return __builtin___strncpy_chk (__dest, __src, __len,
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 96 | __glibc_objsize (__dest));
> | ~~~~~~~~~~~~~~~~~~~~~~~~~
> core/cfg.tab.c: In function 'yyparse':
> core/cfg.y:699:76: note: length computed here
> 699 | strncpy($$, $1, strlen($1)+1);
> | ^
> In file included from /usr/include/string.h:519,
> from core/cfg.y:40:
> In function 'strncpy',
> inlined from 'yyparse' at core/cfg.y:689:6:
> Warning: /usr/include/x86_64-linux-gnu/bits/string_fortified.h:95:10: warning: '__builtin_strncpy' specified bound depends on the length of the source argument [-Wstringop-truncation]
> 95 | return __builtin___strncpy_chk (__dest, __src, __len,
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 96 | __glibc_objsize (__dest));
> | ~~~~~~~~~~~~~~~~~~~~~~~~~
> core/cfg.tab.c: In function 'yyparse':
> core/cfg.y:689:70: note: length computed here
> 689 | strncpy($$, tmp, strlen(tmp)+1);
> |

Victor Seva authored on 01/07/2022 13:26:47
Showing 1 changed files
... ...
@@ -682,11 +682,12 @@ listen_id:
682 682
 				LM_CRIT("cfg. parser: bad ip address.\n");
683 683
 				$$=0;
684 684
 			} else {
685
-				$$=pkg_malloc(strlen(tmp)+1);
685
+				i_tmp=strlen(tmp)+1;
686
+				$$=pkg_malloc(i_tmp);
686 687
 				if ($$==0) {
687 688
 					PKG_MEM_CRITICAL;
688 689
 				} else {
689
-					strncpy($$, tmp, strlen(tmp)+1);
690
+					strncpy($$, tmp, i_tmp);
690 691
 				}
691 692
 			}
692 693
 		}
... ...
@@ -696,7 +697,8 @@ listen_id:
696 697
 		if ($$==0) {
697 698
 				PKG_MEM_CRITICAL;
698 699
 		} else {
699
-				strncpy($$, $1, strlen($1)+1);
700
+				i_tmp=strlen($1)+1;
701
+				strncpy($$, $1, i_tmp);
700 702
 		}
701 703
 	}
702 704
 	| host_or_if {
... ...
@@ -705,7 +707,8 @@ listen_id:
705 707
 			if ($$==0) {
706 708
 					PKG_MEM_CRITICAL;
707 709
 			} else {
708
-					strncpy($$, $1, strlen($1)+1);
710
+					i_tmp=strlen($1)+1;
711
+					strncpy($$, $1, i_tmp);
709 712
 			}
710 713
 		}
711 714
 	}
Browse code

core: added domain and auto_domains as variants for alias and auto_aliases

Daniel-Constantin Mierla authored on 17/06/2022 07:53:01
Showing 1 changed files
... ...
@@ -333,6 +333,8 @@ extern char *default_routename;
333 333
 %token STRNAME
334 334
 %token ALIAS
335 335
 %token SR_AUTO_ALIASES
336
+%token DOMAIN
337
+%token SR_AUTO_DOMAINS
336 338
 %token DNS
337 339
 %token REV_DNS
338 340
 %token DNS_TRY_IPV6
... ...
@@ -1737,8 +1739,22 @@ assign_stm:
1737 1739
 		free_socket_id_lst($3);
1738 1740
 	}
1739 1741
 	| ALIAS  EQUAL error  { yyerror("hostname expected"); }
1742
+	| DOMAIN EQUAL  id_lst {
1743
+		for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next){
1744
+			add_alias(	lst_tmp->addr_lst->name,
1745
+						strlen(lst_tmp->addr_lst->name),
1746
+						lst_tmp->port, lst_tmp->proto);
1747
+			for (nl_tmp=lst_tmp->addr_lst->next; nl_tmp; nl_tmp=nl_tmp->next)
1748
+				add_alias(nl_tmp->name, strlen(nl_tmp->name),
1749
+							lst_tmp->port, lst_tmp->proto);
1750
+		}
1751
+		free_socket_id_lst($3);
1752
+	}
1753
+	| DOMAIN  EQUAL error  { yyerror("hostname expected"); }
1740 1754
 	| SR_AUTO_ALIASES EQUAL NUMBER { sr_auto_aliases=$3; }
1741 1755
 	| SR_AUTO_ALIASES EQUAL error  { yyerror("boolean value expected"); }
1756
+	| SR_AUTO_DOMAINS EQUAL NUMBER { sr_auto_aliases=$3; }
1757
+	| SR_AUTO_DOMAINS EQUAL error  { yyerror("boolean value expected"); }
1742 1758
 	| ADVERTISED_ADDRESS EQUAL listen_id {
1743 1759
 		if ($3){
1744 1760
 			default_global_address.s=$3;
Browse code

core: stop at the first config error on startup

- continuing to look for more errors to print them on one check can end
up in crashing because some internal interpreter structure may not be
filled properly
- new cli option --all-errors that can be used to enable printing
details for more detected config errors

Daniel-Constantin Mierla authored on 14/06/2022 09:44:24
Showing 1 changed files
... ...
@@ -3854,6 +3854,9 @@ static void yyerror_at(struct cfg_pos* p, char* format, ...)
3854 3854
 		LM_CRIT("parse error in config file %s, line %d, column %d: %s\n",
3855 3855
 					p->fname, p->s_line, p->s_col, s);
3856 3856
 	cfg_errors++;
3857
+	if(ksr_all_errors==0) {
3858
+		ksr_exit(-1);
3859
+	}
3857 3860
 }
3858 3861
 
3859 3862
 
Browse code

core: new socket global parameter to set listen attributes with a structure style

- alternative to listen when a usual bind address is provided
- example:

socket = {
bind = udp:127.0.0.1:5060;
advertise = 1.2.3.4:5080;
name = "udp0";
}

Daniel-Constantin Mierla authored on 01/06/2022 06:24:50
Showing 1 changed files
... ...
@@ -151,6 +151,7 @@ static struct action *mod_func_action = NULL;
151 151
 static struct lvalue* lval_tmp = NULL;
152 152
 static struct rvalue* rval_tmp = NULL;
153 153
 static struct rval_expr* rve_tmp = NULL;
154
+static socket_attrs_t tmp_sa;
154 155
 
155 156
 static void warn(char* s, ...);
156 157
 static void warn_at(struct cfg_pos* pos, char* s, ...);
... ...
@@ -382,6 +383,9 @@ extern char *default_routename;
382 383
 %token STAT
383 384
 %token STATS_NAMESEP
384 385
 %token CHILDREN
386
+%token SOCKET
387
+%token BIND
388
+%token WORKERS
385 389
 %token SOCKET_WORKERS
386 390
 %token ASYNC_WORKERS
387 391
 %token ASYNC_USLEEP
... ...
@@ -797,6 +801,48 @@ avpflag_spec:
797 801
 			yyerror("cannot declare avpflag");
798 802
 	}
799 803
 	;
804
+socket_lattr:
805
+	BIND EQUAL proto COLON listen_id COLON port	{
806
+			tmp_sa.bindproto = $3;
807
+			tmp_sa.bindaddr.s = $5;
808
+			tmp_sa.bindaddr.len = strlen(tmp_sa.bindaddr.s);
809
+			tmp_sa.bindport = $7;
810
+		}
811
+	| BIND EQUAL listen_id COLON port	{
812
+			tmp_sa.bindaddr.s = $3;
813
+			tmp_sa.bindaddr.len = strlen(tmp_sa.bindaddr.s);
814
+			tmp_sa.bindport = $5;
815
+		}
816
+	| BIND EQUAL proto COLON listen_id	{
817
+			tmp_sa.bindproto = $3;
818
+			tmp_sa.bindaddr.s = $5;
819
+			tmp_sa.bindaddr.len = strlen(tmp_sa.bindaddr.s);
820
+		}
821
+	| BIND EQUAL listen_id	{
822
+			tmp_sa.bindaddr.s = $3;
823
+			tmp_sa.bindaddr.len = strlen(tmp_sa.bindaddr.s);
824
+		}
825
+	| BIND EQUAL error { yyerror("string value expected"); }
826
+	| STRNAME EQUAL STRING {
827
+			tmp_sa.sockname.s = $3;
828
+			tmp_sa.sockname.len = strlen(tmp_sa.sockname.s);
829
+		}
830
+	| STRNAME EQUAL error { yyerror("string value expected"); }
831
+	| ADVERTISE EQUAL listen_id COLON NUMBER {
832
+			tmp_sa.useaddr.s = $3;
833
+			tmp_sa.useaddr.len = strlen(tmp_sa.useaddr.s);
834
+			tmp_sa.useport = $5;
835
+		}
836
+	| WORKERS EQUAL NUMBER { tmp_sa.workers=$3; }
837
+	| WORKERS EQUAL error { yyerror("number expected"); }
838
+	| VIRTUAL EQUAL NUMBER { if($3!=0) { tmp_sa.sflags |= SI_IS_VIRTUAL; } }
839
+	| VIRTUAL EQUAL error { yyerror("number expected"); }
840
+	| SEMICOLON {}
841
+	;
842
+socket_lattrs:
843
+	socket_lattrs socket_lattr {}
844
+	| socket_lattr {}
845
+	;
800 846
 assign_stm:
801 847
 	DEBUG_V EQUAL intno { default_core_cfg.debug=$3; }
802 848
 	| DEBUG_V EQUAL error  { yyerror("number  expected"); }
... ...
@@ -949,6 +995,15 @@ assign_stm:
949 995
 	| CHILDREN EQUAL error { yyerror("number expected"); }
950 996
 	| STATS_NAMESEP EQUAL STRING { ksr_stats_namesep=$3; }
951 997
 	| STATS_NAMESEP EQUAL error { yyerror("string value expected"); }
998
+	| SOCKET {
999
+				memset(&tmp_sa, 0, sizeof(socket_attrs_t));
1000
+			} EQUAL LBRACE socket_lattrs RBRACE {
1001
+				if(add_listen_socket(&tmp_sa)<0) {
1002
+					LM_ERR("failed to add listen socket\n");
1003
+					yyerror("failed to add listen socket");
1004
+					ksr_exit(-1);
1005
+				}
1006
+	}
952 1007
 	| SOCKET_WORKERS EQUAL NUMBER { socket_workers=$3; }
953 1008
 	| SOCKET_WORKERS EQUAL error { yyerror("number expected"); }
954 1009
 	| ASYNC_WORKERS EQUAL NUMBER { async_task_set_workers($3); }
Browse code

core: add an option to trigger also an RST on tcp connection close

- This gives an option to also send RST in case kamailio closes the
connection. There are cases where a FIN,ACK back forth leaves
the connection in the host in TIME_WAIT state, but the ports on both
sides are fixed. This leads to no request can send until
the TIME_WAIT state is gone.

Rick Barenthin authored on 03/05/2022 17:42:31 • Daniel-Constantin Mierla committed on 16/05/2022 06:01:02
Showing 1 changed files
... ...
@@ -450,6 +450,7 @@ extern char *default_routename;
450 450
 %token TCP_OPT_ACCEPT_NO_CL
451 451
 %token TCP_OPT_ACCEPT_HEP3
452 452
 %token TCP_OPT_ACCEPT_HAPROXY
453
+%token TCP_OPT_CLOSE_RST
453 454
 %token TCP_CLONE_RCVBUF
454 455
 %token TCP_REUSE_PORT
455 456
 %token TCP_WAIT_DATA
... ...
@@ -1301,6 +1302,14 @@ assign_stm:
1301 1302
 		#endif
1302 1303
 	}
1303 1304
 	| TCP_OPT_ACCEPT_HAPROXY EQUAL error { yyerror("boolean value expected"); }
1305
+	| TCP_OPT_CLOSE_RST EQUAL NUMBER {
1306
+         #ifdef USE_TCP
1307
+             tcp_default_cfg.close_rst=$3;
1308
+         #else
1309
+             warn("tcp support not compiled in");
1310
+         #endif
1311
+     }
1312
+     | TCP_OPT_CLOSE_RST EQUAL error { yyerror("boolean value expected"); }
1304 1313
 
1305 1314
 	| TCP_CLONE_RCVBUF EQUAL NUMBER {
1306 1315
 		#ifdef USE_TCP
Browse code

core: added tcp_script_mode global parameter

- control if the tcp connection should be closed if received message
processing resulted in error return code

Daniel-Constantin Mierla authored on 14/02/2022 07:49:57
Showing 1 changed files
... ...
@@ -453,6 +453,7 @@ extern char *default_routename;
453 453
 %token TCP_CLONE_RCVBUF
454 454
 %token TCP_REUSE_PORT
455 455
 %token TCP_WAIT_DATA
456
+%token TCP_SCRIPT_MODE
456 457
 %token DISABLE_TLS
457 458
 %token ENABLE_TLS
458 459
 %token TLSLOG
... ...
@@ -1329,6 +1330,14 @@ assign_stm:
1329 1330
 		#endif
1330 1331
 	}
1331 1332
 	| TCP_WAIT_DATA EQUAL error { yyerror("number expected"); }
1333
+	| TCP_SCRIPT_MODE EQUAL intno {
1334
+		#ifdef USE_TCP
1335
+			ksr_tcp_script_mode=$3;
1336
+		#else
1337
+			warn("tcp support not compiled in");
1338
+		#endif
1339
+	}
1340
+	| TCP_SCRIPT_MODE EQUAL error { yyerror("number expected"); }
1332 1341
 	| DISABLE_TLS EQUAL NUMBER {
1333 1342
 		#ifdef USE_TLS
1334 1343
 			tls_disable=$3;
Browse code

core: listen can now have a "virtual" flag to check for nonlocal floating IPs.

A new option to "listen" has been added called "virtual". This sets a flag on the listening socket to modify the behaviour of grep_sock_info.
When this flag is set, grep_sock_info will only consider the listening IP a match if the IP is found in the system's current list of
local IP addresses. If the IP is not currently local, then the matching IP is ignored.
If the virtual flag is not set on the socket then existing behaviour used instead.

This is useful in scenarios with an active/active cluster where Kamailio must know if a floating IP is currently local or not.

Rhys Hanrahan authored on 22/12/2021 11:13:47 • Daniel-Constantin Mierla committed on 07/01/2022 11:27:25
Showing 1 changed files
... ...
@@ -328,6 +328,7 @@ extern char *default_routename;
328 328
 %token XAVPVIAFIELDS
329 329
 %token LISTEN
330 330
 %token ADVERTISE
331
+%token VIRTUAL
331 332
 %token STRNAME
332 333
 %token ALIAS
333 334
 %token SR_AUTO_ALIASES
... ...
@@ -1503,6 +1504,19 @@ assign_stm:
1503 1504
 		}
1504 1505
 		free_socket_id_lst($3);
1505 1506
 	}
1507
+        | LISTEN EQUAL id_lst VIRTUAL {
1508
+                for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next) {
1509
+			lst_tmp->flags |= SI_IS_VIRTUAL;
1510
+                        if (add_listen_iface(   lst_tmp->addr_lst->name,
1511
+                                                                        lst_tmp->addr_lst->next,
1512
+                                                                        lst_tmp->port, lst_tmp->proto,
1513
+                                                                        lst_tmp->flags)!=0) {
1514
+                                LM_CRIT("cfg. parser: failed to add listen address\n");
1515
+                                break;
1516
+                        }
1517
+                }
1518
+                free_socket_id_lst($3);
1519
+        }
1506 1520
 	| LISTEN EQUAL id_lst STRNAME STRING {
1507 1521
 		for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next) {
1508 1522
 			if (add_listen_iface_name(lst_tmp->addr_lst->name,
... ...
@@ -1515,6 +1529,19 @@ assign_stm:
1515 1529
 		}
1516 1530
 		free_socket_id_lst($3);
1517 1531
 	}
1532
+        | LISTEN EQUAL id_lst STRNAME STRING VIRTUAL {
1533
+                for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next) {
1534
+                        lst_tmp->flags |= SI_IS_VIRTUAL;
1535
+                        if (add_listen_iface_name(lst_tmp->addr_lst->name,
1536
+                                                                        lst_tmp->addr_lst->next,
1537
+                                                                        lst_tmp->port, lst_tmp->proto, $5,
1538
+                                                                        lst_tmp->flags)!=0) {
1539
+                                LM_CRIT("cfg. parser: failed to add listen address\n");
1540
+                                break;
1541
+                        }
1542
+                }
1543
+                free_socket_id_lst($3);
1544
+        }
1518 1545
 	| LISTEN EQUAL id_lst ADVERTISE listen_id COLON NUMBER {
1519 1546
 		for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next) {
1520 1547
 			if (add_listen_advertise_iface(	lst_tmp->addr_lst->name,
... ...
@@ -1528,6 +1555,20 @@ assign_stm:
1528 1555
 		}
1529 1556
 		free_socket_id_lst($3);
1530 1557
 	}
1558
+        | LISTEN EQUAL id_lst ADVERTISE listen_id COLON NUMBER VIRTUAL {
1559
+                for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next) {
1560
+			lst_tmp->flags |= SI_IS_VIRTUAL;
1561
+                        if (add_listen_advertise_iface( lst_tmp->addr_lst->name,
1562
+                                                                        lst_tmp->addr_lst->next,
1563
+                                                                        lst_tmp->port, lst_tmp->proto,
1564
+                                                                        $5, $7,
1565
+                                                                        lst_tmp->flags)!=0) {
1566
+                                LM_CRIT("cfg. parser: failed to add listen address\n");
1567
+                                break;
1568
+                        }
1569
+                }
1570
+                free_socket_id_lst($3);
1571
+        }
1531 1572
 	| LISTEN EQUAL id_lst ADVERTISE listen_id COLON NUMBER STRNAME STRING {
1532 1573
 		for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next) {
1533 1574
 			if (add_listen_advertise_iface_name(lst_tmp->addr_lst->name,
... ...
@@ -1541,6 +1582,20 @@ assign_stm:
1541 1582
 		}
1542 1583
 		free_socket_id_lst($3);
1543 1584
 	}
1585
+        | LISTEN EQUAL id_lst ADVERTISE listen_id COLON NUMBER STRNAME STRING VIRTUAL {
1586
+                for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next) {
1587
+			lst_tmp->flags |= SI_IS_VIRTUAL;
1588
+                        if (add_listen_advertise_iface_name(lst_tmp->addr_lst->name,
1589
+                                                                        lst_tmp->addr_lst->next,
1590
+                                                                        lst_tmp->port, lst_tmp->proto,
1591
+                                                                        $5, $7, $9,
1592
+                                                                        lst_tmp->flags)!=0) {
1593
+                                LM_CRIT("cfg. parser: failed to add listen address\n");
1594
+                                break;
1595
+                        }
1596
+                }
1597
+                free_socket_id_lst($3);
1598
+        }
1544 1599
 	| LISTEN EQUAL id_lst ADVERTISE listen_id {
1545 1600
 		for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next) {
1546 1601
 			if (add_listen_advertise_iface(	lst_tmp->addr_lst->name,
... ...
@@ -1554,6 +1609,20 @@ assign_stm:
1554 1609
 		}
1555 1610
 		free_socket_id_lst($3);
1556 1611
 	}
1612
+        | LISTEN EQUAL id_lst ADVERTISE listen_id VIRTUAL {
1613
+                for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next) {
1614
+			lst_tmp->flags |= SI_IS_VIRTUAL;
1615
+                        if (add_listen_advertise_iface( lst_tmp->addr_lst->name,
1616
+                                                                        lst_tmp->addr_lst->next,
1617
+                                                                        lst_tmp->port, lst_tmp->proto,
1618
+                                                                        $5, 0,
1619
+                                                                        lst_tmp->flags)!=0) {
1620
+                                LM_CRIT("cfg. parser: failed to add listen address\n");
1621
+                                break;
1622
+                        }
1623
+                }
1624
+                free_socket_id_lst($3);
1625
+        }
1557 1626
 	| LISTEN EQUAL id_lst ADVERTISE listen_id STRNAME STRING {
1558 1627
 		for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next) {
1559 1628
 			if (add_listen_advertise_iface_name(lst_tmp->addr_lst->name,
... ...
@@ -1567,6 +1636,20 @@ assign_stm:
1567 1636
 		}
1568 1637
 		free_socket_id_lst($3);
1569 1638
 	}
1639
+        | LISTEN EQUAL id_lst ADVERTISE listen_id STRNAME STRING VIRTUAL {
1640
+                for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next) {
1641
+			lst_tmp->flags |= SI_IS_VIRTUAL;
1642
+                        if (add_listen_advertise_iface_name(lst_tmp->addr_lst->name,
1643
+                                                                        lst_tmp->addr_lst->next,
1644
+                                                                        lst_tmp->port, lst_tmp->proto,
1645
+                                                                        $5, 0, $7,
1646
+                                                                        lst_tmp->flags)!=0) {
1647
+                                LM_CRIT("cfg. parser: failed to add listen address\n");
1648
+                                break;
1649
+                        }
1650
+                }
1651
+                free_socket_id_lst($3);
1652
+        }
1570 1653
 	| LISTEN EQUAL  error { yyerror("ip address, interface name or"
1571 1654
 									" hostname expected"); }
1572 1655
 	| ALIAS EQUAL  id_lst {
Browse code

core: tcp - added core parameter tcp_wait_data

- specify how long to wait (in milliseconds) to wait for data on tcp
connections in certain cases
- default is 5000ms (5secs)
- now applies when reading on tcp connection for haproxy protocol

Daniel-Constantin Mierla authored on 13/12/2021 13:42:50
Showing 1 changed files
... ...
@@ -451,6 +451,7 @@ extern char *default_routename;
451 451
 %token TCP_OPT_ACCEPT_HAPROXY
452 452
 %token TCP_CLONE_RCVBUF
453 453
 %token TCP_REUSE_PORT
454
+%token TCP_WAIT_DATA
454 455
 %token DISABLE_TLS
455 456
 %token ENABLE_TLS
456 457
 %token TLSLOG
... ...
@@ -1319,6 +1320,14 @@ assign_stm:
1319 1320
 		#endif
1320 1321
 	}
1321 1322
 	| TCP_REUSE_PORT EQUAL error { yyerror("boolean value expected"); }
1323
+	| TCP_WAIT_DATA EQUAL intno {
1324
+		#ifdef USE_TCP
1325
+			tcp_default_cfg.wait_data_ms=$3;
1326
+		#else
1327
+			warn("tcp support not compiled in");
1328
+		#endif
1329
+	}
1330
+	| TCP_WAIT_DATA EQUAL error { yyerror("number expected"); }
1322 1331
 	| DISABLE_TLS EQUAL NUMBER {
1323 1332
 		#ifdef USE_TLS
1324 1333
 			tls_disable=$3;
Browse code

core: add new param sip_parser_log_oneline

To log SIP headers with . instead of \r\n.

Stefan Mititelu authored on 25/10/2021 06:08:36
Showing 1 changed files
... ...
@@ -394,6 +394,7 @@ extern char *default_routename;
394 394
 %token MEMSAFETY
395 395
 %token MEMJOIN
396 396
 %token MEMSTATUSMODE
397
+%token SIP_PARSER_LOG_ONELINE
397 398
 %token SIP_PARSER_LOG
398 399
 %token SIP_PARSER_MODE
399 400
 %token CORELOG
... ...
@@ -970,6 +971,8 @@ assign_stm:
970 971
 	| MEMJOIN EQUAL error { yyerror("int value expected"); }
971 972
 	| MEMSTATUSMODE EQUAL intno { default_core_cfg.mem_status_mode=$3; }
972 973
 	| MEMSTATUSMODE EQUAL error { yyerror("int value expected"); }
974
+	| SIP_PARSER_LOG_ONELINE EQUAL intno { default_core_cfg.sip_parser_log_oneline=$3; }
975
+	| SIP_PARSER_LOG_ONELINE EQUAL error { yyerror("int value expected"); }
973 976
 	| SIP_PARSER_LOG EQUAL intno { default_core_cfg.sip_parser_log=$3; }
974 977
 	| SIP_PARSER_LOG EQUAL error { yyerror("int value expected"); }
975 978
 	| SIP_PARSER_MODE EQUAL intno { ksr_sip_parser_mode=$3; }
Browse code

core: fix building quoted value for #!subsdefs

Daniel-Constantin Mierla authored on 01/07/2021 09:17:56
Showing 1 changed files
... ...
@@ -2213,9 +2213,9 @@ event_route_stm:
2213 2213
 preprocess_stm:
2214 2214
 	SUBST STRING { if(pp_subst_add($2)<0) YYERROR; }
2215 2215
 	| SUBST error { yyerror("invalid subst preprocess statement"); }
2216
-	| SUBSTDEF STRING { if(pp_substdef_add($2, 0)<0) YYERROR; }
2216
+	| SUBSTDEF STRING { if(pp_substdef_add($2, KSR_PPDEF_NORMAL)<0) YYERROR; }
2217 2217
 	| SUBSTDEF error { yyerror("invalid substdef preprocess statement"); }
2218
-	| SUBSTDEFS STRING { if(pp_substdef_add($2, 1)<0) YYERROR; }
2218
+	| SUBSTDEFS STRING { if(pp_substdef_add($2, KSR_PPDEF_QUOTED)<0) YYERROR; }
2219 2219
 	| SUBSTDEFS error { yyerror("invalid substdefs preprocess statement"); }
2220 2220
 	;
2221 2221
 
Browse code

core: renamed recent params wait_child1_* to wait_worker1_*

- consistent with the event route name

Daniel-Constantin Mierla authored on 16/03/2021 08:33:04
Showing 1 changed files
... ...
@@ -498,9 +498,9 @@ extern char *default_routename;
498 498
 %token VERSION_TABLE_CFG
499 499
 %token VERBOSE_STARTUP
500 500
 %token ROUTE_LOCKS_SIZE
501
-%token WAIT_CHILD1_MODE
502
-%token WAIT_CHILD1_TIME
503
-%token WAIT_CHILD1_USLEEP
501
+%token WAIT_WORKER1_MODE
502
+%token WAIT_WORKER1_TIME
503
+%token WAIT_WORKER1_USLEEP
504 504
 %token CFG_DESCRIPTION
505 505
 %token SERVER_ID
506 506
 %token KEMI
... ...
@@ -1705,10 +1705,12 @@ assign_stm:
1705 1705
 	| VERBOSE_STARTUP EQUAL error { yyerror("boolean value expected"); }
1706 1706
 	| ROUTE_LOCKS_SIZE EQUAL NUMBER { ksr_route_locks_size=$3; }
1707 1707
 	| ROUTE_LOCKS_SIZE EQUAL error { yyerror("number expected"); }
1708
-	| WAIT_CHILD1_MODE EQUAL NUMBER { ksr_wait_child1_mode=$3; }
1709
-	| WAIT_CHILD1_MODE EQUAL error { yyerror("number expected"); }
1710
-	| WAIT_CHILD1_TIME EQUAL NUMBER { ksr_wait_child1_time=$3; }
1711
-	| WAIT_CHILD1_TIME EQUAL error { yyerror("number expected"); }
1708
+	| WAIT_WORKER1_MODE EQUAL NUMBER { ksr_wait_worker1_mode=$3; }
1709
+	| WAIT_WORKER1_MODE EQUAL error { yyerror("number expected"); }
1710
+	| WAIT_WORKER1_TIME EQUAL NUMBER { ksr_wait_worker1_time=$3; }
1711
+	| WAIT_WORKER1_TIME EQUAL error { yyerror("number expected"); }
1712
+	| WAIT_WORKER1_USLEEP EQUAL NUMBER { ksr_wait_worker1_usleep=$3; }
1713
+	| WAIT_WORKER1_USLEEP EQUAL error { yyerror("number expected"); }
1712 1714
     | SERVER_ID EQUAL NUMBER { server_id=$3; }
1713 1715
 	| SERVER_ID EQUAL error  { yyerror("number expected"); }
1714 1716
 	| KEMI DOT ONSEND_ROUTE_CALLBACK EQUAL STRING {
Browse code

core: global parameters to enable waiting for child one worker initialization

- new paramters:
- wait_child1_mode=[0|1] - set to wait or not
- wait_child1_time=1000000 (micro-seconds) - how long to wait over all
- wait_child1_usleep=100000 (micro-seconds) - step to wait before
checking if initialization completed

Daniel-Constantin Mierla authored on 15/03/2021 11:29:08
Showing 1 changed files
... ...
@@ -498,6 +498,9 @@ extern char *default_routename;
498 498
 %token VERSION_TABLE_CFG
499 499
 %token VERBOSE_STARTUP
500 500
 %token ROUTE_LOCKS_SIZE
501
+%token WAIT_CHILD1_MODE
502
+%token WAIT_CHILD1_TIME
503
+%token WAIT_CHILD1_USLEEP
501 504
 %token CFG_DESCRIPTION
502 505
 %token SERVER_ID
503 506
 %token KEMI
... ...
@@ -1702,6 +1705,10 @@ assign_stm:
1702 1705
 	| VERBOSE_STARTUP EQUAL error { yyerror("boolean value expected"); }
1703 1706
 	| ROUTE_LOCKS_SIZE EQUAL NUMBER { ksr_route_locks_size=$3; }
1704 1707
 	| ROUTE_LOCKS_SIZE EQUAL error { yyerror("number expected"); }
1708
+	| WAIT_CHILD1_MODE EQUAL NUMBER { ksr_wait_child1_mode=$3; }
1709
+	| WAIT_CHILD1_MODE EQUAL error { yyerror("number expected"); }
1710
+	| WAIT_CHILD1_TIME EQUAL NUMBER { ksr_wait_child1_time=$3; }
1711
+	| WAIT_CHILD1_TIME EQUAL error { yyerror("number expected"); }
1705 1712
     | SERVER_ID EQUAL NUMBER { server_id=$3; }
1706 1713
 	| SERVER_ID EQUAL error  { yyerror("number expected"); }
1707 1714
 	| KEMI DOT ONSEND_ROUTE_CALLBACK EQUAL STRING {
Browse code

core: cfg.lex - do not destroy action if pre-fixup fails

- params might be in inconsistent state, shutdown is triggered which
cleans the pkg anyhow
- GH #2630

Daniel-Constantin Mierla authored on 11/02/2021 09:27:20
Showing 1 changed files
... ...
@@ -3542,7 +3542,7 @@ cmd:
3542 3542
 		}else{
3543 3543
 			if (mod_func_action && mod_f_params_pre_fixup(mod_func_action)<0) {
3544 3544
 				/* error messages are printed inside the function */
3545
-				free_mod_func_action(mod_func_action);
3545
+				/* free_mod_func_action(mod_func_action); */
3546 3546
 				mod_func_action = 0;
3547 3547
 				YYERROR;
3548 3548
 			}
Browse code

core: more use of ksr_exit() macro to follow --atexit param

Daniel-Constantin Mierla authored on 09/02/2021 09:50:03
Showing 1 changed files
... ...
@@ -69,6 +69,7 @@
69 69
 #include "ppcfg.h"
70 70
 #include "pvapi.h"
71 71
 #include "config.h"
72
+#include "daemonize.h"
72 73
 #include "cfg_core.h"
73 74
 #include "cfg/cfg.h"
74 75
 #ifdef CORE_TLS
... ...
@@ -3521,7 +3522,7 @@ cmd:
3521 3522
 		if (mod_func_action != NULL) {
3522 3523
 			LM_ERR("function used inside params of another function: %s\n", $1);
3523 3524
 			yyerror("use of function execution inside params not allowed\n");
3524
-			exit(-1);
3525
+			ksr_exit(-1);
3525 3526
 		}
3526 3527
 		mod_func_action = mk_action(MODULE0_T, 2, MODEXP_ST, NULL, NUMBER_ST, 0);
3527 3528
 		} LPAREN func_params RPAREN	{
Browse code

core: added selval(evalexpr, valexp1, valexpr2)

- this is a core statement that return the 2nd parameter if the 1st
parameter is evaluated to true, or 3rd parameter if the 1st parameter is
evaluated to false
- it can be considered a core function that is equivalent of ternary
condition/operator
- example:
$var(x) = selval($Ts mod 2, "true/" + $ru, "false/" + $rd);
- the first parameter is a conditional expression, like those used for
IF, the 2nd and 3rd parameters can be expressions like those used in the
right side of assignments

Daniel-Constantin Mierla authored on 08/02/2021 10:18:44
Showing 1 changed files
... ...
@@ -149,6 +149,7 @@ static pv_spec_t* pv_spec = NULL;
149 149
 static struct action *mod_func_action = NULL;
150 150
 static struct lvalue* lval_tmp = NULL;
151 151
 static struct rvalue* rval_tmp = NULL;
152
+static struct rval_expr* rve_tmp = NULL;
152 153
 
153 154
 static void warn(char* s, ...);
154 155
 static void warn_at(struct cfg_pos* pos, char* s, ...);
... ...
@@ -560,6 +561,7 @@ extern char *default_routename;
560 561
 /* no precedence, they use () */
561 562
 %token STRLEN
562 563
 %token STREMPTY
564
+%token SELVAL
563 565
 
564 566
 /* values */
565 567
 %token <intval> NUMBER
... ...
@@ -3031,6 +3033,14 @@ rval_expr: rval						{ $$=$1;
3031 3033
 		| STRLEN LPAREN rval_expr RPAREN { $$=mk_rve1(RVE_STRLEN_OP, $3);}
3032 3034
 		| STREMPTY LPAREN rval_expr RPAREN {$$=mk_rve1(RVE_STREMPTY_OP, $3);}
3033 3035
 		| DEFINED rval_expr				{ $$=mk_rve1(RVE_DEFINED_OP, $2);}
3036
+		| SELVAL LPAREN rval_expr COMMA rval_expr COMMA rval_expr RPAREN {
3037
+				rve_tmp=mk_rve2(RVE_SELVALOPT_OP, $5, $7);
3038
+				if(rve_tmp == NULL) {
3039
+					$$=0;
3040
+					yyerror("faild to create tenary target expression");
3041
+				}
3042
+				$$=mk_rve2(RVE_SELVALEXP_OP, $3, rve_tmp);
3043
+		}
3034 3044
 		| rve_un_op error %prec UNARY 		{ $$=0; yyerror("bad expression"); }
3035 3045
 		| INTCAST error					{ $$=0; yyerror("bad expression"); }
3036 3046
 		| STRCAST error					{ $$=0; yyerror("bad expression"); }
... ...
@@ -3049,6 +3059,7 @@ rval_expr: rval						{ $$=$1;
3049 3059
 		| rval_expr LOG_OR error		{ $$=0; yyerror("bad expression"); }
3050 3060
 		| STRLEN LPAREN error RPAREN	{ $$=0; yyerror("bad expression"); }
3051 3061
 		| STREMPTY LPAREN error RPAREN	{ $$=0; yyerror("bad expression"); }
3062
+		| SELVAL LPAREN error RPAREN	{ $$=0; yyerror("bad expression"); }
3052 3063
 		| DEFINED error					{ $$=0; yyerror("bad expression"); }
3053 3064
 		;
3054 3065
 
Browse code

core: added loadmodulex - can evaluate the vars in the parameter

- example
#!define MYMOD async.so
loadmodulex "$def(MYMOD)"

Daniel-Constantin Mierla authored on 03/01/2021 21:05:06
Showing 1 changed files
... ...
@@ -401,6 +401,7 @@ extern char *default_routename;
401 401
 %token USER_AGENT_HEADER
402 402
 %token REPLY_TO_VIA
403 403
 %token LOADMODULE
404
+%token LOADMODULEX
404 405
 %token LOADPATH
405 406
 %token MODPARAM
406 407
 %token MODPARAMX
... ...
@@ -1850,6 +1851,13 @@ module_stm:
1850 1851
 			}
1851 1852
 	}
1852 1853
 	| LOADMODULE error	{ yyerror("string expected"); }
1854
+	| LOADMODULEX STRING {
1855
+		LM_DBG("loading module %s\n", $2);
1856
+			if (load_modulex($2)!=0) {
1857
+				yyerror("failed to load module");
1858
+			}
1859
+	}
1860
+	| LOADMODULEX error	{ yyerror("string expected"); }
1853 1861
 	| LOADPATH STRING {
1854 1862
 		if(mods_dir_cmd==0) {
1855 1863
 			LM_DBG("loading modules under %s\n", $2);
Browse code

core: new core directive modparamx(mod, param, val)

- alternative to modparam() where all its parameters are evaluated for
config script variables
- note that only variables that do not depend on SIP message processing
should be used at this stage
- example - set a module parameter using the value of an evironment
variable:
modparamx("dispatcher", "db_url", "$env(DBURL)")

Daniel-Constantin Mierla authored on 28/12/2020 13:08:16
Showing 1 changed files
... ...
@@ -403,6 +403,7 @@ extern char *default_routename;
403 403
 %token LOADMODULE
404 404
 %token LOADPATH
405 405
 %token MODPARAM
406
+%token MODPARAMX
406 407
 %token CFGENGINE
407 408
 %token MAXBUFFER
408 409
 %token SQL_BUFFER_SIZE
... ...
@@ -1890,6 +1891,34 @@ module_stm:
1890 1891
 		}
1891 1892
 	}
1892 1893
 	| MODPARAM error { yyerror("Invalid arguments"); }
1894
+	| MODPARAMX LPAREN STRING COMMA STRING COMMA STRING RPAREN {
1895
+		if (!shm_initialized() && init_shm()<0) {
1896
+			yyerror("Can't initialize shared memory");
1897
+			YYABORT;
1898
+		}
1899
+		if (modparamx_set($3, $5, PARAM_STRING, $7) != 0) {
1900
+			 yyerror("Can't set module parameter");
1901
+		}
1902
+	}
1903
+	| MODPARAMX LPAREN STRING COMMA STRING COMMA intno RPAREN {
1904
+		if (!shm_initialized() && init_shm()<0) {
1905
+			yyerror("Can't initialize shared memory");
1906
+			YYABORT;
1907
+		}
1908
+		if (modparamx_set($3, $5, PARAM_INT, (void*)$7) != 0) {
1909
+			 yyerror("Can't set module parameter");
1910
+		}
1911
+	}
1912
+	| MODPARAMX LPAREN STRING COMMA STRING COMMA PVAR RPAREN {
1913
+		if (!shm_initialized() && init_shm()<0) {
1914
+			yyerror("Can't initialize shared memory");
1915
+			YYABORT;
1916
+		}
1917
+		if (modparamx_set($3, $5, PARAM_VAR, (void*)$7) != 0) {
1918
+			 yyerror("Can't set module parameter");
1919
+		}
1920
+	}
1921
+	| MODPARAMX error { yyerror("Invalid arguments"); }
1893 1922
 	| CFGENGINE STRING {
1894 1923
 		if(sr_kemi_eng_setz($2, NULL)) {
1895 1924
 			yyerror("Can't set config routing engine");
Browse code

core: new global parameter async_workers_group

- define groups of async worker processes
- async_workers_group="name=abc;workers=N;nonblock=[0|1];usleep=M"
- groups of worker processes can be used now with sworker module

Daniel-Constantin Mierla authored on 26/11/2020 15:04:39
Showing 1 changed files
... ...
@@ -383,6 +383,7 @@ extern char *default_routename;
383 383
 %token ASYNC_WORKERS
384 384
 %token ASYNC_USLEEP
385 385
 %token ASYNC_NONBLOCK
386
+%token ASYNC_WORKERS_GROUP
386 387
 %token CHECK_VIA
387 388
 %token PHONE2TEL
388 389
 %token MEMLOG
... ...
@@ -943,6 +944,8 @@ assign_stm:
943 944
 	| ASYNC_USLEEP EQUAL error { yyerror("number expected"); }
944 945
 	| ASYNC_NONBLOCK EQUAL NUMBER { async_task_set_nonblock($3); }
945 946
 	| ASYNC_NONBLOCK EQUAL error { yyerror("number expected"); }
947
+	| ASYNC_WORKERS_GROUP EQUAL STRING { async_task_set_workers_group($3); }
948
+	| ASYNC_WORKERS_GROUP EQUAL error { yyerror("string expected"); }
946 949
 	| CHECK_VIA EQUAL NUMBER { check_via=$3; }
947 950
 	| CHECK_VIA EQUAL error { yyerror("boolean value expected"); }
948 951
 	| PHONE2TEL EQUAL NUMBER { phone2tel=$3; }
Browse code

core: new event_route[core:pre-routing]

- executed before running config script for SIP messages, if received
from the network, it is not executed if the message was dispatched
internally
- can be used to delegate processing to special workers via sworker
module
- if drop is used, then processing stops for that message, otherwise it
goes forther to request_route or reply_route

Daniel-Constantin Mierla authored on 26/11/2020 12:23:05
Showing 1 changed files
... ...
@@ -501,6 +501,7 @@ extern char *default_routename;
501 501
 %token EVENT_ROUTE_CALLBACK
502 502
 %token RECEIVED_ROUTE_CALLBACK
503 503
 %token RECEIVED_ROUTE_MODE
504
+%token PRE_ROUTING_CALLBACK
504 505
 %token MAX_RECURSIVE_LEVEL
505 506
 %token MAX_BRANCHES_PARAM
506 507
 %token LATENCY_CFG_LOG
... ...
@@ -1735,6 +1736,16 @@ assign_stm:
1735 1736
 			}
1736 1737
 		}
1737 1738
 	| KEMI DOT RECEIVED_ROUTE_CALLBACK EQUAL error { yyerror("string expected"); }
1739
+	| KEMI DOT PRE_ROUTING_CALLBACK EQUAL STRING {
1740
+			kemi_pre_routing_callback.s = $5;
1741
+			kemi_pre_routing_callback.len = strlen($5);
1742
+			if(kemi_pre_routing_callback.len==4
1743
+					&& strcasecmp(kemi_pre_routing_callback.s, "none")==0) {
1744
+				kemi_pre_routing_callback.s = "";
1745
+				kemi_pre_routing_callback.len = 0;
1746
+			}
1747
+		}
1748
+	| KEMI DOT PRE_ROUTING_CALLBACK EQUAL error { yyerror("string expected"); }
1738 1749
     | RECEIVED_ROUTE_MODE EQUAL intno { ksr_evrt_received_mode=$3; }
1739 1750
 	| RECEIVED_ROUTE_MODE EQUAL error  { yyerror("number  expected"); }
1740 1751
     | MAX_RECURSIVE_LEVEL EQUAL NUMBER { set_max_recursive_level($3); }
Browse code

core: added local_rport global parameter

- similar to add_local_rport() but set globally

Daniel-Constantin Mierla authored on 11/11/2020 08:29:08
Showing 1 changed files
... ...
@@ -253,6 +253,7 @@ extern char *default_routename;
253 253
 %token REVERT_URI
254 254
 %token FORCE_RPORT
255 255
 %token ADD_LOCAL_RPORT
256
+%token LOCAL_RPORT
256 257
 %token FORCE_TCP_ALIAS
257 258
 %token UDP_MTU
258 259
 %token UDP_MTU_TRY_PROTO
... ...
@@ -1757,6 +1758,8 @@ assign_stm:
1757 1758
 	| FORCE_RPORT EQUAL NUMBER
1758 1759
 		{ default_core_cfg.force_rport=$3; fix_global_req_flags(0, 0); }
1759 1760
 	| FORCE_RPORT EQUAL error { yyerror("boolean value expected"); }
1761
+	| LOCAL_RPORT EQUAL NUMBER { ksr_local_rport=$3; }
1762
+	| LOCAL_RPORT EQUAL error { yyerror("boolean value expected"); }
1760 1763
 	| UDP_MTU_TRY_PROTO EQUAL proto
1761 1764
 		{ default_core_cfg.udp_mtu_try_proto=$3; fix_global_req_flags(0, 0); }
1762 1765
 	| UDP_MTU_TRY_PROTO EQUAL error
Browse code

core: switch to use blocklist structures and functions

Daniel-Constantin Mierla authored on 30/10/2020 09:25:09
Showing 1 changed files
... ...
@@ -109,10 +109,10 @@
109 109
 	#define IF_NAPTR(x) warn("dns naptr support not compiled in")
110 110
 #endif
111 111
 
112
-#ifdef USE_DST_BLACKLIST
113
-	#define IF_DST_BLACKLIST(x) x
112
+#ifdef USE_DST_BLOCKLIST
113
+	#define IF_DST_BLOCKLIST(x) x
114 114
 #else
115
-	#define IF_DST_BLACKLIST(x) warn("dst blacklist support not compiled in")
115
+	#define IF_DST_BLOCKLIST(x) warn("dst blocklist support not compiled in")
116 116
 #endif
117 117
 
118 118
 #ifdef USE_SCTP
... ...
@@ -362,7 +362,7 @@ extern char *default_routename;
362 362
 
363 363
 %token IPV6_HEX_STYLE
364 364
 
365
-/*blacklist*/
365
+/*blocklist*/
366 366
 %token DST_BLST_INIT
367 367
 %token USE_DST_BLST
368 368
 %token DST_BLST_MEM
... ...
@@ -889,36 +889,36 @@ assign_stm:
889 889
 	| IPV6_HEX_STYLE error { yyerror("string value expected"); }
890 890
 	| BIND_IPV6_LINK_LOCAL EQUAL NUMBER {sr_bind_ipv6_link_local = $3;}
891 891
 	| BIND_IPV6_LINK_LOCAL error { yyerror("boolean value expected"); }
892
-	| DST_BLST_INIT EQUAL NUMBER   { IF_DST_BLACKLIST(dst_blacklist_init=$3); }
892
+	| DST_BLST_INIT EQUAL NUMBER   { IF_DST_BLOCKLIST(dst_blocklist_init=$3); }
893 893
 	| DST_BLST_INIT error { yyerror("boolean value expected"); }
894 894
 	| USE_DST_BLST EQUAL NUMBER {
895
-		IF_DST_BLACKLIST(default_core_cfg.use_dst_blacklist=$3);
895
+		IF_DST_BLOCKLIST(default_core_cfg.use_dst_blocklist=$3);
896 896
 	}
897 897
 	| USE_DST_BLST error { yyerror("boolean value expected"); }
898 898
 	| DST_BLST_MEM EQUAL NUMBER {
899
-		IF_DST_BLACKLIST(default_core_cfg.blst_max_mem=$3);
899
+		IF_DST_BLOCKLIST(default_core_cfg.blst_max_mem=$3);
900 900
 	}
901 901
 	| DST_BLST_MEM error { yyerror("boolean value expected"); }
902 902
 	| DST_BLST_TTL EQUAL NUMBER {
903
-		IF_DST_BLACKLIST(default_core_cfg.blst_timeout=$3);
903
+		IF_DST_BLOCKLIST(default_core_cfg.blst_timeout=$3);
904 904
 	}
905 905
 	| DST_BLST_TTL error { yyerror("boolean value expected"); }
906
-	| DST_BLST_GC_INT EQUAL NUMBER { IF_DST_BLACKLIST(blst_timer_interval=$3);}
906
+	| DST_BLST_GC_INT EQUAL NUMBER { IF_DST_BLOCKLIST(blst_timer_interval=$3);}
907 907
 	| DST_BLST_GC_INT error { yyerror("boolean value expected"); }
908 908
 	| DST_BLST_UDP_IMASK EQUAL NUMBER {
909
-		IF_DST_BLACKLIST(default_core_cfg.blst_udp_imask=$3);
909
+		IF_DST_BLOCKLIST(default_core_cfg.blst_udp_imask=$3);
910 910
 	}
911 911
 	| DST_BLST_UDP_IMASK error { yyerror("number(flags) expected"); }
912 912
 	| DST_BLST_TCP_IMASK EQUAL NUMBER {
913
-		IF_DST_BLACKLIST(default_core_cfg.blst_tcp_imask=$3);
913
+		IF_DST_BLOCKLIST(default_core_cfg.blst_tcp_imask=$3);
914 914
 	}
915 915
 	| DST_BLST_TCP_IMASK error { yyerror("number(flags) expected"); }
916 916
 	| DST_BLST_TLS_IMASK EQUAL NUMBER {
917
-		IF_DST_BLACKLIST(default_core_cfg.blst_tls_imask=$3);
917
+		IF_DST_BLOCKLIST(default_core_cfg.blst_tls_imask=$3);
918 918
 	}
919 919
 	| DST_BLST_TLS_IMASK error { yyerror("number(flags) expected"); }
920 920
 	| DST_BLST_SCTP_IMASK EQUAL NUMBER {
921
-		IF_DST_BLACKLIST(default_core_cfg.blst_sctp_imask=$3);
921
+		IF_DST_BLOCKLIST(default_core_cfg.blst_sctp_imask=$3);
922 922
 	}
923 923
 	| DST_BLST_SCTP_IMASK error { yyerror("number(flags) expected"); }
924 924
 	| IP_FREE_BIND EQUAL intno { _sr_ip_free_bind=$3; }
Browse code

core: relocation and refactoring on ip addr handling code

- many static inline functions moved from ip_addr.h to ip_addr.c, code
size for some of them increased over the time
- ipv6_hex_style can be set to "c" to have IPv6 addresses compacted and
using lowercase hexdigits (rfc5952#section-4.2.1), GH #2510
- when ipv6_hex_style="c", ip6tosbuf() uses POSIX inet_ntop(),
conforming with POSIX.1-2001, POSIX.1-2008

Daniel-Constantin Mierla authored on 19/10/2020 10:32:43
Showing 1 changed files
... ...
@@ -879,10 +879,12 @@ assign_stm:
879 879
 	| AUTO_BIND_IPV6 EQUAL NUMBER {IF_AUTO_BIND_IPV6(auto_bind_ipv6 = $3);}
880 880
 	| AUTO_BIND_IPV6 error { yyerror("boolean value expected"); }
881 881
 	| IPV6_HEX_STYLE EQUAL STRING {
882
-		ksr_ipv6_hex_style = $3;
883
-		if(ksr_ipv6_hex_style[0]!='a' && ksr_ipv6_hex_style[0]!='A') {
884
-			yyerror("expected \"a\" or \"A\" value");
882
+		ksr_ipv6_hex_style.s = $3;
883
+		if(ksr_ipv6_hex_style.s[0]!='a' && ksr_ipv6_hex_style.s[0]!='A'
884
+				&& ksr_ipv6_hex_style.s[0]!='c') {
885
+			yyerror("expected \"a\", \"A\" or \"c\" value");
885 886
 		}
887
+		ksr_ipv6_hex_style.len = strlen(ksr_ipv6_hex_style.s);
886 888
 	}
887 889
 	| IPV6_HEX_STYLE error { yyerror("string value expected"); }
888 890
 	| BIND_IPV6_LINK_LOCAL EQUAL NUMBER {sr_bind_ipv6_link_local = $3;}
Browse code

core: new global parameter sip_parser_mode

- allow to control how sip parser behaves
- 0 - be less restrictive, to support more protocols
- 1 - be more strict on sip headers checks
- default 1

Daniel-Constantin Mierla authored on 10/10/2020 09:20:48
Showing 1 changed files
... ...
@@ -391,6 +391,7 @@ extern char *default_routename;
391 391
 %token MEMJOIN
392 392
 %token MEMSTATUSMODE
393 393
 %token SIP_PARSER_LOG
394
+%token SIP_PARSER_MODE
394 395
 %token CORELOG
395 396
 %token SIP_WARNING
396 397
 %token SERVER_SIGNATURE
... ...
@@ -956,6 +957,8 @@ assign_stm:
956 957
 	| MEMSTATUSMODE EQUAL error { yyerror("int value expected"); }
957 958
 	| SIP_PARSER_LOG EQUAL intno { default_core_cfg.sip_parser_log=$3; }
958 959
 	| SIP_PARSER_LOG EQUAL error { yyerror("int value expected"); }
960
+	| SIP_PARSER_MODE EQUAL intno { ksr_sip_parser_mode=$3; }
961
+	| SIP_PARSER_MODE EQUAL error { yyerror("int value expected"); }
959 962
 	| CORELOG EQUAL intno { default_core_cfg.corelog=$3; }
960 963
 	| CORELOG EQUAL error { yyerror("int value expected"); }
961 964
 	| SIP_WARNING EQUAL NUMBER { sip_warning=$3; }
Browse code

core: new parameter ipv6_hex_style

- can be set to "a" or "A" to specify if hex digits in local computed
ipv6 addresses are lowercase or uppercase. Default is "A" (same format
used so far).
- enables the ability to follow recommedations of RFC5952, section 4.3
- GH #2488

Daniel-Constantin Mierla authored on 30/09/2020 07:17:03
Showing 1 changed files
... ...
@@ -360,6 +360,8 @@ extern char *default_routename;
360 360
 %token AUTO_BIND_IPV6
361 361
 %token BIND_IPV6_LINK_LOCAL
362 362