Browse code

core: support to add rport parameter to local via hdr

- new cfg function - add_local_rport() - to add rport parameter to local
via header (rfc3581)

Daniel-Constantin Mierla authored on 20/08/2009 09:57:01
Showing 6 changed files
... ...
@@ -1129,6 +1129,10 @@ match_cleanup:
1129 1129
 			msg->msg_flags|=FL_FORCE_RPORT;
1130 1130
 			ret=1; /* continue processing */
1131 1131
 			break;
1132
+		case ADD_LOCAL_RPORT_T:
1133
+			msg->msg_flags|=FL_ADD_LOCAL_RPORT;
1134
+			ret=1; /* continue processing */
1135
+			break;
1132 1136
 		case UDP_MTU_TRY_PROTO_T:
1133 1137
 			msg->msg_flags|= (unsigned int)a->val[0].u.number & FL_MTU_FB_MASK;
1134 1138
 			ret=1; /* continue processing */
... ...
@@ -166,6 +166,7 @@ ROUTE_SEND onsend_route
166 166
 ROUTE_EVENT event_route
167 167
 EXEC	exec
168 168
 FORCE_RPORT		"force_rport"|"add_rport"
169
+ADD_LOCAL_RPORT		"add_local_rport"
169 170
 FORCE_TCP_ALIAS		"force_tcp_alias"|"add_tcp_alias"
170 171
 UDP_MTU		"udp_mtu"
171 172
 UDP_MTU_TRY_PROTO	"udp_mtu_try_proto"
... ...
@@ -534,6 +535,8 @@ EAT_ABLE	[\ \t\b\r]
534 534
 <INITIAL>{SET_USERPHONE}	{ count(); yylval.strval=yytext;
535 535
 								return SET_USERPHONE; }
536 536
 <INITIAL>{FORCE_RPORT}	{ count(); yylval.strval=yytext; return FORCE_RPORT; }
537
+<INITIAL>{ADD_LOCAL_RPORT}	{ count(); yylval.strval=yytext;
538
+								return ADD_LOCAL_RPORT; }
537 539
 <INITIAL>{FORCE_TCP_ALIAS}	{ count(); yylval.strval=yytext;
538 540
 								return FORCE_TCP_ALIAS; }
539 541
 <INITIAL>{UDP_MTU}	{ count(); yylval.strval=yytext; return UDP_MTU; }
... ...
@@ -295,6 +295,7 @@ static int case_check_default(struct case_stms* stms);
295 295
 %token SET_URI
296 296
 %token REVERT_URI
297 297
 %token FORCE_RPORT
298
+%token ADD_LOCAL_RPORT
298 299
 %token FORCE_TCP_ALIAS
299 300
 %token UDP_MTU
300 301
 %token UDP_MTU_TRY_PROTO
... ...
@@ -2886,6 +2887,8 @@ cmd:
2886 2886
 	| REVERT_URI { $$=mk_action(REVERT_URI_T, 0); }
2887 2887
 	| FORCE_RPORT LPAREN RPAREN	{ $$=mk_action(FORCE_RPORT_T, 0); }
2888 2888
 	| FORCE_RPORT	{$$=mk_action(FORCE_RPORT_T, 0); }
2889
+	| ADD_LOCAL_RPORT LPAREN RPAREN	{ $$=mk_action(ADD_LOCAL_RPORT_T, 0); }
2890
+	| ADD_LOCAL_RPORT	{$$=mk_action(ADD_LOCAL_RPORT_T, 0); }
2889 2891
 	| FORCE_TCP_ALIAS LPAREN NUMBER RPAREN	{
2890 2892
 		#ifdef USE_TCP
2891 2893
 			$$=mk_action(FORCE_TCP_ALIAS_T, 1, NUMBER_ST, (void*)$3);
... ...
@@ -2382,14 +2382,31 @@ char* create_via_hf( unsigned int *len,
2382 2382
 	}
2383 2383
 #endif /* USE_TCP || USE_SCTP */
2384 2384
 
2385
+	/* test and add rport parameter to local via - rfc3581 */
2386
+	if(msg->msg_flags&FL_ADD_LOCAL_RPORT) {
2387
+		/* params so far + ';rport' + '\0' */
2388
+		via = (char*)pkg_malloc(extra_params.len+RPORT_LEN);
2389
+		if(via==0) {
2390
+			LM_ERR("building local rport via param failed\n");
2391
+			if (extra_params.s) pkg_free(extra_params.s);
2392
+			return 0;
2393
+		}
2394
+		if(extra_params.len!=0) {
2395
+			memcpy(via, extra_params.s, extra_params.len);
2396
+			pkg_free(extra_params.s);
2397
+		}
2398
+		memcpy(via + extra_params.len, RPORT, RPORT_LEN-1);
2399
+		extra_params.s = via;
2400
+		extra_params.len += RPORT_LEN-1;
2401
+		extra_params.s[extra_params.len]='\0';
2402
+	}
2403
+
2385 2404
 	set_hostport(&hp, msg);
2386 2405
 	via = via_builder( len, send_info, branch,
2387 2406
 							extra_params.len?&extra_params:0, &hp);
2388 2407
 
2389
-#if defined USE_TCP || defined USE_SCTP
2390
-	/* we do not need id_buf any more, the id is already in the new via header */
2391
-	if (id_buf) pkg_free(id_buf);
2392
-#endif
2408
+	/* we do not need extra_params any more, already in the new via header */
2409
+	if (extra_params.s) pkg_free(extra_params.s);
2393 2410
 	return via;
2394 2411
 }
2395 2412
 
... ...
@@ -109,6 +109,7 @@ enum request_method {
109 109
 #define FL_MTU_TCP_FB   (1 << 8)
110 110
 #define FL_MTU_TLS_FB   (1 << 9)
111 111
 #define FL_MTU_SCTP_FB  (1 << 10)
112
+#define FL_ADD_LOCAL_RPORT  (1 << 11) /* add 'rport' to local via hdr */
112 113
 
113 114
 /* WARNING: Value (1 << 29) is temporarily reserved for use in kamailio acc
114 115
  * module (flag FL_REQ_UPSTREAM)! */
... ...
@@ -97,6 +97,7 @@ enum action_type{
97 97
 		FORWARD_SCTP_T,
98 98
 		SEND_TCP_T,
99 99
 		FORCE_RPORT_T,
100
+		ADD_LOCAL_RPORT_T,
100 101
 		SET_ADV_ADDR_T,
101 102
 		SET_ADV_PORT_T,
102 103
 		FORCE_TCP_ALIAS_T,