Browse code

core: new global parameter xavp_via_fields

- set the name of xavp from where to take Via header field: address and
port
- use them to build local Via header

Daniel-Constantin Mierla authored on 04/10/2018 14:45:14
Showing 6 changed files
... ...
@@ -294,6 +294,7 @@ LOGPREFIXMODE	log_prefix_mode
294 294
 LOGENGINETYPE	log_engine_type
295 295
 LOGENGINEDATA	log_engine_data
296 296
 XAVPVIAPARAMS	xavp_via_params
297
+XAVPVIAFIELDS	xavp_via_fields
297 298
 LISTEN		listen
298 299
 ADVERTISE	advertise|ADVERTISE
299 300
 ALIAS		alias
... ...
@@ -697,6 +698,7 @@ IMPORTFILE      "import_file"
697 698
 <INITIAL>{LOGENGINETYPE}	{ yylval.strval=yytext; return LOGENGINETYPE; }
698 699
 <INITIAL>{LOGENGINEDATA}	{ yylval.strval=yytext; return LOGENGINEDATA; }
699 700
 <INITIAL>{XAVPVIAPARAMS}	{ yylval.strval=yytext; return XAVPVIAPARAMS; }
701
+<INITIAL>{XAVPVIAFIELDS}	{ yylval.strval=yytext; return XAVPVIAFIELDS; }
700 702
 <INITIAL>{LISTEN}	{ count(); yylval.strval=yytext; return LISTEN; }
701 703
 <INITIAL>{ADVERTISE}	{ count(); yylval.strval=yytext; return ADVERTISE; }
702 704
 <INITIAL>{ALIAS}	{ count(); yylval.strval=yytext; return ALIAS; }
... ...
@@ -324,6 +324,7 @@ extern char *default_routename;
324 324
 %token LOGENGINETYPE
325 325
 %token LOGENGINEDATA
326 326
 %token XAVPVIAPARAMS
327
+%token XAVPVIAFIELDS
327 328
 %token LISTEN
328 329
 %token ADVERTISE
329 330
 %token ALIAS
... ...
@@ -802,6 +803,10 @@ assign_stm:
802 803
 			_ksr_xavp_via_params.len=strlen($3);
803 804
 		}
804 805
 	| XAVPVIAPARAMS EQUAL error { yyerror("string value expected"); }
806
+	| XAVPVIAFIELDS EQUAL STRING { _ksr_xavp_via_params.s=$3;
807
+			_ksr_xavp_via_fields.len=strlen($3);
808
+		}
809
+	| XAVPVIAFIELDS EQUAL error { yyerror("string value expected"); }
805 810
 	| DNS EQUAL NUMBER   { received_dns|= ($3)?DO_DNS:0; }
806 811
 	| DNS EQUAL error { yyerror("boolean value expected"); }
807 812
 	| REV_DNS EQUAL NUMBER { received_dns|= ($3)?DO_REV_DNS:0; }
... ...
@@ -206,6 +206,7 @@ extern int _sr_ip_free_bind;
206 206
 extern int ksr_verbose_startup;
207 207
 extern int ksr_route_locks_size;
208 208
 extern str _ksr_xavp_via_params;
209
+extern str _ksr_xavp_via_fields;
209 210
 
210 211
 #ifdef USE_DNS_CACHE
211 212
 extern int dns_cache_init; /* if 0, the DNS cache is not initialized at startup */
... ...
@@ -114,6 +114,7 @@ extern char version[];
114 114
 extern int version_len;
115 115
 
116 116
 str _ksr_xavp_via_params = STR_NULL;
117
+str _ksr_xavp_via_fields = STR_NULL;
117 118
 
118 119
 /** per process fixup function for global_req_flags.
119 120
   * It should be called from the configuration framework.
... ...
@@ -2673,10 +2674,10 @@ int branch_builder( unsigned int hash_index,
2673 2674
 
2674 2675
 
2675 2676
 
2676
-/* uses only the send_info->send_socket, send_info->proto and 
2677
+/* uses only the send_info->send_socket, send_info->proto and
2677 2678
  * send_info->comp (so that a send_info used for sending can be passed
2678 2679
  * to this function w/o changes and the correct via will be built) */
2679
-char* via_builder( unsigned int *len,
2680
+char* via_builder(unsigned int *len, sip_msg_t *msg,
2680 2681
 	struct dest_info* send_info /* where to send the reply */,
2681 2682
 	str* branch, str* extra_params, struct hostport* hp)
2682 2683
 {
... ...
@@ -2684,8 +2685,8 @@ char* via_builder( unsigned int *len,
2684 2685
 	char               *line_buf;
2685 2686
 	int max_len;
2686 2687
 	int via_prefix_len;
2687
-	str* address_str; /* address displayed in via */
2688
-	str* port_str; /* port no displayed in via */
2688
+	str* address_str = NULL; /* address displayed in via */
2689
+	str* port_str = NULL; /* port no displayed in via */
2689 2690
 	struct socket_info* send_sock;
2690 2691
 	int comp_len, comp_name_len;
2691 2692
 #ifdef USE_COMP
... ...
@@ -2696,22 +2697,46 @@ char* via_builder( unsigned int *len,
2696 2697
 	union sockaddr_union *from = NULL;
2697 2698
 	union sockaddr_union local_addr;
2698 2699
 	struct tcp_connection *con = NULL;
2700
+	sr_xavp_t *rxavp = NULL;
2701
+	str xname;
2699 2702
 
2700 2703
 	send_sock=send_info->send_sock;
2701 2704
 	/* use pre-set address in via, the outbound socket alias or address one */
2702
-	if (hp && hp->host->len)
2703
-		address_str=hp->host;
2704
-	else if(send_sock->useinfo.name.len>0)
2705
-		address_str=&(send_sock->useinfo.name);
2706
-	else
2707
-		address_str=&(send_sock->address_str);
2708
-	if (hp && hp->port->len)
2709
-		port_str=hp->port;
2710
-	else if(send_sock->useinfo.port_no>0)
2711
-		port_str=&(send_sock->useinfo.port_no_str);
2712
-	else
2713
-		port_str=&(send_sock->port_no_str);
2714
-	
2705
+	if(msg && (msg->msg_flags&FL_USE_XAVP_VIA_FIELDS)
2706
+			&& _ksr_xavp_via_fields.len>0) {
2707
+		xname.s = "address";
2708
+		xname.len = 7;
2709
+		rxavp = xavp_get_child_with_sval(&_ksr_xavp_via_fields, &xname);
2710
+		if(rxavp!=NULL) {
2711
+			address_str = &rxavp->val.v.s;
2712
+		}
2713
+	}
2714
+	if(address_str==NULL) {
2715
+		if (hp && hp->host->len)
2716
+			address_str=hp->host;
2717
+		else if(send_sock->useinfo.name.len>0)
2718
+			address_str=&(send_sock->useinfo.name);
2719
+		else
2720
+			address_str=&(send_sock->address_str);
2721
+	}
2722
+	if(msg && (msg->msg_flags&FL_USE_XAVP_VIA_FIELDS)
2723
+			&& _ksr_xavp_via_fields.len>0) {
2724
+		xname.s = "port";
2725
+		xname.len = 4;
2726
+		rxavp = xavp_get_child_with_sval(&_ksr_xavp_via_fields, &xname);
2727
+		if(rxavp!=NULL) {
2728
+			port_str = &rxavp->val.v.s;
2729
+		}
2730
+	}
2731
+	if(port_str==NULL) {
2732
+		if (hp && hp->port->len)
2733
+			port_str=hp->port;
2734
+		else if(send_sock->useinfo.port_no>0)
2735
+			port_str=&(send_sock->useinfo.port_no_str);
2736
+		else
2737
+			port_str=&(send_sock->port_no_str);
2738
+	}
2739
+
2715 2740
 	comp_len=comp_name_len=0;
2716 2741
 #ifdef USE_COMP
2717 2742
 	comp_name=0;
... ...
@@ -2861,7 +2886,7 @@ char* via_builder( unsigned int *len,
2861 2886
 
2862 2887
 /* creates a via header honoring the protocol of the incoming socket
2863 2888
  * msg is an optional parameter */
2864
-char* create_via_hf( unsigned int *len,
2889
+char* create_via_hf(unsigned int *len,
2865 2890
 	struct sip_msg *msg,
2866 2891
 	struct dest_info* send_info /* where to send the reply */,
2867 2892
 	str* branch)
... ...
@@ -2982,7 +3007,7 @@ char* create_via_hf( unsigned int *len,
2982 3007
 	}
2983 3008
 
2984 3009
 	set_hostport(&hp, msg);
2985
-	via = via_builder( len, send_info, branch,
3010
+	via = via_builder(len, msg, send_info, branch,
2986 3011
 							extra_params.len?&extra_params:0, &hp);
2987 3012
 
2988 3013
 	/* we do not need extra_params any more, already in the new via header */
... ...
@@ -107,9 +107,9 @@ char * build_res_buf_with_body_from_sip_req(	unsigned int code ,
107 107
 				unsigned int *returned_len,
108 108
 				struct bookmark *bmark);
109 109
 */
110
-char* via_builder( unsigned int *len,
110
+char* via_builder(unsigned int *len, sip_msg_t *msg,
111 111
 	struct dest_info* send_info,
112
-	str *branch, str* extra_params, struct hostport *hp );
112
+	str *branch, str* extra_params, struct hostport *hp);
113 113
 
114 114
 /* creates a via header honoring the protocol of the incoming socket
115 115
  * msg is an optional parameter */
... ...
@@ -107,7 +107,8 @@ typedef enum request_method {
107 107
 #define FL_UAC_AUTH          (1<<19)  /* Proxy UAC-like authentication */
108 108
 #define FL_ADD_SRVID         (1<<20) /*!< add 'srvid' to local via hdr */
109 109
 #define FL_ADD_XAVP_VIA_PARAMS (1<<21) /*!< add xavp fields to local via params */
110
-#define FL_MSG_NOREPLY       (1<<22) /*!< do not send sip reply for request */
110
+#define FL_USE_XAVP_VIA_FIELDS (1<<22) /*!< use xavp fields for local via attrs */
111
+#define FL_MSG_NOREPLY       (1<<23) /*!< do not send sip reply for request */
111 112
 
112 113
 /* WARNING: Value (1 << 28) is temporarily reserved for use in kamailio call_control
113 114
  * module (flag  FL_USE_CALL_CONTROL )! */