Browse code

- added suuport for setting the source address and port in the sip requests (adevertised_address= ip|string, advertised_port= no, set_advertised_address(ip|string), set_advertised_port(no) )

Andrei Pelinescu-Onciul authored on 03/10/2003 07:19:41
Showing 13 changed files
... ...
@@ -43,7 +43,7 @@ export makefile_defs
43 43
 VERSION = 0
44 44
 PATCHLEVEL = 8
45 45
 SUBLEVEL =   12
46
-EXTRAVERSION = dev-t16
46
+EXTRAVERSION = dev-17-cristian
47 47
 
48 48
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
49 49
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -3,8 +3,6 @@ $Id$
3 3
 ( - todo, x - done)
4 4
 
5 5
 - grep parse_uri & replace with parse_sip_msg_uri (e.g do_action!)
6
-- WARNING: tm fr_timer fixup is not in HEAD (should it be? is it the
7
- rigth fix?)
8 6
 x update AUTHORS, debian/copyright, ser.8, ser.cfg.5 from stable
9 7
 x update Makefile*  from stable
10 8
 x update all package specs from stable
... ...
@@ -20,8 +18,8 @@ x port receive.c pre_script_cb fix from stable
20 18
     something like alias= foo1.bar:5080 foo2.bar foo3.bar:*
21 19
 - extend listen and alias to include port numbers and protocol:
22 20
        tcp foo.bar:5063, udp foo.bar:5062, foo2.bar
23
-- add force_via, force_srcip a.s.o (the advertised addresses should be
24
- overwritable from the script).
21
+x added set_advertised_{address,port} -- was: add force_via, force_srcip a.s.o
22
+(the advertised addresses should be overwritable from the script).
25 23
 - ? add force_outbound_socket(ip)? (choose an apropriate socket from the
26 24
  listen list for sending the msg; works on udp only)
27 25
 
... ...
@@ -34,6 +34,7 @@
34 34
  *  2003-04-01  Added support for loose routing in forward (janakj)
35 35
  *  2003-04-12  FORCE_RPORT_T added (andrei)
36 36
  *  2003-04-22  strip_tail added (jiri)
37
+ *  2003-10-02  added SET_ADV_ADDR_T & SET_ADV_PORT_T (andrei)
37 38
  */
38 39
 
39 40
 
... ...
@@ -608,6 +609,26 @@ int do_action(struct action* a, struct sip_msg* msg)
608 609
 			msg->msg_flags|=FL_FORCE_RPORT;
609 610
 			ret=1; /* continue processing */
610 611
 			break;
612
+		case SET_ADV_ADDR_T:
613
+			if (a->p1_type!=STR_ST){
614
+				LOG(L_CRIT, "BUG: do_action: bad set_advertised_address() "
615
+						"type %d\n", a->p1_type);
616
+				ret=E_BUG;
617
+				break;
618
+			}
619
+			msg->set_global_address=*((str*)a->p1.data);
620
+			ret=1; /* continue processing */
621
+			break;
622
+		case SET_ADV_PORT_T:
623
+			if (a->p1_type!=STR_ST){
624
+				LOG(L_CRIT, "BUG: do_action: bad set_advertised_port() "
625
+						"type %d\n", a->p1_type);
626
+				ret=E_BUG;
627
+				break;
628
+			}
629
+			msg->set_global_port=*((str*)a->p1.data);
630
+			ret=1; /* continue processing */
631
+			break;
611 632
 		default:
612 633
 			LOG(L_CRIT, "BUG: do_action: unknown type %d\n", a->type);
613 634
 	}
... ...
@@ -38,6 +38,7 @@
38 38
  *  2003-07-03  tls* (disable, certificate, private_key, ca_list, verify, 
39 39
  *               require_certificate added (andrei)
40 40
  *  2003-07-06  more tls config. vars added: tls_method, tls_port_no (andrei)
41
+ *  2003-10-02  added {,set_}advertised_{address,port} (andrei)
41 42
  */
42 43
 
43 44
 
... ...
@@ -106,6 +107,8 @@ STRIP_TAIL		"strip_tail"
106 107
 APPEND_BRANCH	"append_branch"
107 108
 IF				"if"
108 109
 ELSE			"else"
110
+SET_ADV_ADDRESS	"set_advertised_address"
111
+SET_ADV_PORT	"set_advertised_port"
109 112
 
110 113
 /*ACTION LVALUES*/
111 114
 URIHOST			"uri:host"
... ...
@@ -172,6 +175,8 @@ TLS_REQUIRE_CERTIFICATE "tls_require_certificate"
172 175
 TLS_CERTIFICATE	"tls_certificate"
173 176
 TLS_PRIVATE_KEY "tls_private_key"
174 177
 TLS_CA_LIST		"tls_ca_list"
178
+ADVERTISED_ADDRESS	"advertised_address"
179
+ADVERTISED_PORT		"advertised_port"
175 180
 
176 181
 LOADMODULE	loadmodule
177 182
 MODPARAM        modparam
... ...
@@ -260,6 +265,11 @@ EAT_ABLE	[\ \t\b\r]
260 265
 <INITIAL>{IF}	{ count(); yylval.strval=yytext; return IF; }
261 266
 <INITIAL>{ELSE}	{ count(); yylval.strval=yytext; return ELSE; }
262 267
 
268
+<INITIAL>{SET_ADV_ADDRESS}	{ count(); yylval.strval=yytext;
269
+										return SET_ADV_ADDRESS; }
270
+<INITIAL>{SET_ADV_PORT}	{ count(); yylval.strval=yytext;
271
+										return SET_ADV_PORT; }
272
+
263 273
 <INITIAL>{URIHOST}	{ count(); yylval.strval=yytext; return URIHOST; }
264 274
 <INITIAL>{URIPORT}	{ count(); yylval.strval=yytext; return URIPORT; }
265 275
 
... ...
@@ -314,6 +324,10 @@ EAT_ABLE	[\ \t\b\r]
314 324
 <INITIAL>{FIFO_MODE}	{ count(); yylval.strval=yytext; return FIFO_MODE; }
315 325
 <INITIAL>{SERVER_SIGNATURE}	{ count(); yylval.strval=yytext; return SERVER_SIGNATURE; }
316 326
 <INITIAL>{REPLY_TO_VIA}	{ count(); yylval.strval=yytext; return REPLY_TO_VIA; }
327
+<INITIAL>{ADVERTISED_ADDRESS}	{	count(); yylval.strval=yytext;
328
+									return ADVERTISED_ADDRESS; }
329
+<INITIAL>{ADVERTISED_PORT}		{	count(); yylval.strval=yytext;
330
+									return ADVERTISED_PORT; }
317 331
 <INITIAL>{LOADMODULE}	{ count(); yylval.strval=yytext; return LOADMODULE; }
318 332
 <INITIAL>{MODPARAM}     { count(); yylval.strval=yytext; return MODPARAM; }
319 333
 
... ...
@@ -42,6 +42,7 @@
42 42
  * 2003-07-03  tls* (disable, certificate, private_key, ca_list, verify, 
43 43
  *              require_certificate added (andrei)
44 44
  * 2003-07-06  more tls config. vars added: tls_method, tls_port_no (andrei)
45
+ * 2003-10-02  added {,set_}advertised_{address,port} (andrei)
45 46
  */
46 47
 
47 48
 
... ...
@@ -63,6 +64,7 @@
63 64
 #include "modparam.h"
64 65
 #include "ip_addr.h"
65 66
 #include "name_alias.h"
67
+#include "ut.h"
66 68
 
67 69
 #include "config.h"
68 70
 #ifdef USE_TLS
... ...
@@ -84,10 +86,12 @@ struct id_list{
84 86
 
85 87
 extern int yylex();
86 88
 void yyerror(char* s);
87
-char* tmp;
88
-void* f_tmp;
89
-struct id_list* lst_tmp;
90
-int rt;  /* Type of route block for find_export */
89
+static char* tmp;
90
+static int i_tmp;
91
+static void* f_tmp;
92
+static struct id_list* lst_tmp;
93
+static int rt;  /* Type of route block for find_export */
94
+static str* str_tmp;
91 95
 
92 96
 void warn(char* s);
93 97
  
... ...
@@ -136,6 +140,8 @@ void warn(char* s);
136 140
 %token FORCE_RPORT
137 141
 %token IF
138 142
 %token ELSE
143
+%token SET_ADV_ADDRESS
144
+%token SET_ADV_PORT
139 145
 %token URIHOST
140 146
 %token URIPORT
141 147
 %token MAX_LEN
... ...
@@ -195,6 +201,9 @@ void warn(char* s);
195 201
 %token TLS_CERTIFICATE
196 202
 %token TLS_PRIVATE_KEY
197 203
 %token TLS_CA_LIST
204
+%token ADVERTISED_ADDRESS
205
+%token ADVERTISED_PORT
206
+
198 207
 
199 208
 
200 209
 
... ...
@@ -527,6 +536,27 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
527 536
 								add_alias(lst_tmp->s, strlen(lst_tmp->s), 0);
528 537
 							  }
529 538
 		| ALIAS  EQUAL error  { yyerror(" hostname expected"); }
539
+		| ADVERTISED_ADDRESS EQUAL listen_id {
540
+								default_global_address.s=$3;
541
+								default_global_address.len=strlen($3);
542
+								}
543
+		|ADVERTISED_ADDRESS EQUAL error {yyerror("ip address or hostname "
544
+												"expected"); }
545
+		| ADVERTISED_PORT EQUAL NUMBER {
546
+								tmp=int2str($3, &i_tmp);
547
+								if ((default_global_port.s=pkg_malloc(i_tmp))
548
+										==0){
549
+										LOG(L_CRIT, "ERROR: cfg. parser:"
550
+													" out of memory.\n");
551
+										default_global_port.len=0;
552
+								}else{
553
+									default_global_port.len=i_tmp;
554
+									memcpy(default_global_port.s, tmp,
555
+											default_global_port.len);
556
+								};
557
+								}
558
+		|ADVERTISED_PORT EQUAL error {yyerror("ip address or hostname "
559
+												"expected"); }
530 560
 		| error EQUAL { yyerror("unknown config variable"); }
531 561
 	;
532 562
 
... ...
@@ -1341,6 +1371,42 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
1341 1371
 		| REVERT_URI { $$=mk_action( REVERT_URI_T, 0,0,0,0); }
1342 1372
 		| FORCE_RPORT LPAREN RPAREN	{$$=mk_action(FORCE_RPORT_T,0, 0, 0, 0); }
1343 1373
 		| FORCE_RPORT				{$$=mk_action(FORCE_RPORT_T,0, 0, 0, 0); }
1374
+		| SET_ADV_ADDRESS LPAREN listen_id RPAREN {
1375
+								$$=0;
1376
+								if ((str_tmp=pkg_malloc(sizeof(str)))==0){
1377
+										LOG(L_CRIT, "ERROR: cfg. parser:"
1378
+													" out of memory.\n");
1379
+								}else{
1380
+										str_tmp->s=$3;
1381
+										str_tmp->len=strlen($3);
1382
+										$$=mk_action(SET_ADV_ADDR_T, STR_ST,
1383
+										             0, str_tmp, 0);
1384
+								}
1385
+												  }
1386
+		| SET_ADV_ADDRESS LPAREN error RPAREN { $$=0; yyerror("bad argument, "
1387
+														"string expected"); }
1388
+		| SET_ADV_ADDRESS error {$$=0; yyerror("missing '(' or ')' ?"); }
1389
+		| SET_ADV_PORT LPAREN NUMBER RPAREN {
1390
+								$$=0;
1391
+								tmp=int2str($3, &i_tmp);
1392
+								if ((str_tmp=pkg_malloc(sizeof(str)))==0){
1393
+										LOG(L_CRIT, "ERROR: cfg. parser:"
1394
+													" out of memory.\n");
1395
+								}else{
1396
+									if ((str_tmp->s=pkg_malloc(i_tmp))==0){
1397
+										LOG(L_CRIT, "ERROR: cfg. parser:"
1398
+													" out of memory.\n");
1399
+									}else{
1400
+										memcpy(str_tmp->s, tmp, i_tmp);
1401
+										str_tmp->len=i_tmp;
1402
+										$$=mk_action(SET_ADV_PORT_T, STR_ST,
1403
+													0, str_tmp, 0);
1404
+									}
1405
+								}
1406
+								            }
1407
+		| SET_ADV_PORT LPAREN error RPAREN { $$=0; yyerror("bad argument, "
1408
+														"string expected"); }
1409
+		| SET_ADV_PORT  error {$$=0; yyerror("missing '(' or ')' ?"); }
1344 1410
 		| ID LPAREN RPAREN			{ f_tmp=(void*)find_export($1, 0, rt);
1345 1411
 									   if (f_tmp==0){
1346 1412
 										   if (find_export($1, 0, 0)) {
... ...
@@ -129,4 +129,9 @@ extern int mhomed;
129 129
 extern int my_argc;
130 130
 extern char **my_argv;
131 131
 
132
+/* pre-set addresses */
133
+extern str default_global_address;
134
+/* pre-ser ports */
135
+extern str default_global_port;
136
+
132 137
 #endif
... ...
@@ -35,6 +35,7 @@
35 35
  * 2003-04-14  build_local no longer checks reply status as it
36 36
  *             is now called before reply status is updated to
37 37
  *             avoid late ACK sending (jiri)
38
+ * 2003-10-02  added via_builder set host/port support (andrei)
38 39
  */
39 40
 
40 41
 #include "defs.h"
... ...
@@ -78,6 +79,7 @@ char *build_local(struct cell *Trans,unsigned int branch,
78 79
 	char branch_buf[MAX_BRANCH_PARAM_LEN];
79 80
 	int branch_len;
80 81
 	str branch_str;
82
+	struct hostport hp;
81 83
 
82 84
 #ifdef _OBSO
83 85
 	if ( Trans->uac[branch].last_received<100)
... ...
@@ -98,8 +100,9 @@ char *build_local(struct cell *Trans,unsigned int branch,
98 100
 		goto error;
99 101
 	branch_str.s=branch_buf;
100 102
 	branch_str.len=branch_len;
103
+	set_hostport(&hp, (Trans->local)?0:(Trans->uas.request));
101 104
 	via=via_builder(&via_len, Trans->uac[branch].request.dst.send_sock,
102
-		&branch_str, 0, Trans->uac[branch].request.dst.proto );
105
+		&branch_str, 0, Trans->uac[branch].request.dst.proto, &hp );
103 106
 	if (!via)
104 107
 	{
105 108
 		LOG(L_ERR, "ERROR: t_build_and_send_CANCEL: "
... ...
@@ -236,6 +239,7 @@ static inline int assemble_via(str* dest, struct cell* t, struct socket_info* so
236 239
 	int len;
237 240
 	unsigned int via_len;
238 241
 	str branch_str;
242
+	struct hostport hp;
239 243
 
240 244
 	if (!t_calc_branch(t, branch, branch_buf, &len)) {
241 245
 		LOG(L_ERR, "ERROR: build_via: branch calculation failed\n");
... ...
@@ -249,7 +253,8 @@ static inline int assemble_via(str* dest, struct cell* t, struct socket_info* so
249 253
 	printf("!!!proto: %d\n", sock->proto);
250 254
 #endif
251 255
 
252
-	via = via_builder(&via_len, sock, &branch_str, 0, sock->proto);
256
+	set_hostport(&hp, 0);
257
+	via = via_builder(&via_len, sock, &branch_str, 0, sock->proto, &hp);
253 258
 	if (!via) {
254 259
 		LOG(L_ERR, "build_via: via building failed\n");
255 260
 		return -2;
... ...
@@ -52,6 +52,7 @@
52 52
  *              references (e.g [::1]) (andrei)
53 53
  *             build_req_fomr_sip_req no longer adds 1 for ipv6 via parameter
54 54
  *              position calculations ([] are part of host.s now) (andrei)
55
+ * 2003-10-02  via+lump dst address/port can be set to preset values (andrei)
55 56
  *
56 57
  */
57 58
 /* Via special params:
... ...
@@ -142,6 +143,8 @@ extern int version_len;
142 143
 
143 144
 
144 145
 
146
+
147
+
145 148
 /* checks if ip is in host(name) and ?host(ip)=name?
146 149
  * ip must be in network byte order!
147 150
  *  resolver = DO_DNS | DO_REV_DNS; if 0 no dns check is made
... ...
@@ -485,6 +488,8 @@ static inline int lumps_len(struct sip_msg* msg, struct socket_info* send_sock)
485 488
 	int new_len;
486 489
 	struct lump* t;
487 490
 	struct lump* r;
491
+	str* send_address_str;
492
+	str* send_port_str;
488 493
 
489 494
 #define SUBST_LUMP_LEN(subst_l) \
490 495
 		switch((subst_l)->u.subst){ \
... ...
@@ -559,8 +564,9 @@ static inline int lumps_len(struct sip_msg* msg, struct socket_info* send_sock)
559 564
 				break; \
560 565
 			case SUBST_SND_IP: \
561 566
 				if (send_sock){ \
562
-					new_len+=send_sock->address_str.len; \
563
-					if (send_sock->address.af!=AF_INET) \
567
+					new_len+=send_address_str->len; \
568
+					if (send_sock->address.af!=AF_INET && \
569
+							send_address_str==&(send_sock->address_str)) \
564 570
 						new_len+=2; \
565 571
 				}else{ \
566 572
 					LOG(L_CRIT, "FIXME: lumps_len called with" \
... ...
@@ -569,7 +575,7 @@ static inline int lumps_len(struct sip_msg* msg, struct socket_info* send_sock)
569 575
 				break; \
570 576
 			case SUBST_SND_PORT: \
571 577
 				if (send_sock){ \
572
-					new_len+=send_sock->port_no_str.len; \
578
+					new_len+=send_port_str->len; \
573 579
 				}else{ \
574 580
 					LOG(L_CRIT, "FIXME: lumps_len called with" \
575 581
 							" null send_sock\n"); \
... ...
@@ -598,12 +604,14 @@ static inline int lumps_len(struct sip_msg* msg, struct socket_info* send_sock)
598 604
 				break; \
599 605
 			case SUBST_SND_ALL: \
600 606
 				if (send_sock){ \
601
-					new_len+=send_sock->address_str.len; \
602
-					if (send_sock->address.af!=AF_INET) \
607
+					new_len+=send_address_str->len; \
608
+					if ((send_sock->address.af!=AF_INET) && \
609
+							(send_address_str==&(send_sock->address_str))) \
603 610
 						new_len+=2; \
604
-					if (send_sock->port_no!=SIP_PORT){ \
611
+					if ((send_sock->port_no!=SIP_PORT) || \
612
+							(send_port_str!=&(send_sock->port_no_str))){ \
605 613
 						/* add :port_no */ \
606
-						new_len+=1+send_sock->port_no_str.len; \
614
+						new_len+=1+send_port_str->len; \
607 615
 					}\
608 616
 					/*add;transport=xxx*/ \
609 617
 					switch(send_sock->proto){ \
... ...
@@ -636,6 +644,16 @@ static inline int lumps_len(struct sip_msg* msg, struct socket_info* send_sock)
636 644
 	
637 645
 	s_offset=0;
638 646
 	new_len=0;
647
+	/* init send_address_str & send_port_str */
648
+	if (msg->set_global_address.len)
649
+		send_address_str=&(msg->set_global_address);
650
+	else
651
+		send_address_str=&(send_sock->address_str);
652
+	if (msg->set_global_port.len)
653
+		send_port_str=&(msg->set_global_address);
654
+	else
655
+		send_port_str=&(send_sock->port_no_str);
656
+	
639 657
 	
640 658
 	for(t=msg->add_rm;t;t=t->next){
641 659
 		/* skip if this is an OPT lump and the condition is not satisfied */
... ...
@@ -740,6 +758,8 @@ static inline void process_lumps(	struct sip_msg* msg,
740 758
 	int size;
741 759
 	int offset;
742 760
 	int s_offset;
761
+	str* send_address_str;
762
+	str* send_port_str;
743 763
 
744 764
 #define SUBST_LUMP(subst_l) \
745 765
 	switch((subst_l)->u.subst){ \
... ...
@@ -825,13 +845,15 @@ static inline void process_lumps(	struct sip_msg* msg,
825 845
 			break; \
826 846
 		case SUBST_SND_IP: \
827 847
 			if (send_sock){  \
828
-				if (send_sock->address.af!=AF_INET){\
848
+				if ((send_sock->address.af!=AF_INET) && \
849
+						(send_address_str==&(send_sock->address_str))){\
829 850
 					new_buf[offset]='['; offset++; \
830 851
 				}\
831
-				memcpy(new_buf+offset, send_sock->address_str.s, \
832
-									send_sock->address_str.len); \
833
-				offset+=send_sock->address_str.len; \
834
-				if (send_sock->address.af!=AF_INET){\
852
+				memcpy(new_buf+offset, send_address_str->s, \
853
+									send_address_str->len); \
854
+				offset+=send_address_str->len; \
855
+				if ((send_sock->address.af!=AF_INET) && \
856
+						(send_address_str==&(send_sock->address_str))){\
835 857
 					new_buf[offset]=']'; offset++; \
836 858
 				}\
837 859
 			}else{  \
... ...
@@ -842,9 +864,9 @@ static inline void process_lumps(	struct sip_msg* msg,
842 864
 			break; \
843 865
 		case SUBST_SND_PORT: \
844 866
 			if (send_sock){  \
845
-				memcpy(new_buf+offset, send_sock->port_no_str.s, \
846
-									send_sock->port_no_str.len); \
847
-				offset+=send_sock->port_no_str.len; \
867
+				memcpy(new_buf+offset, send_port_str->s, \
868
+									send_port_str->len); \
869
+				offset+=send_port_str->len; \
848 870
 			}else{  \
849 871
 				/*FIXME*/ \
850 872
 				LOG(L_CRIT, "FIXME: process_lumps: called with" \
... ...
@@ -854,21 +876,24 @@ static inline void process_lumps(	struct sip_msg* msg,
854 876
 		case SUBST_SND_ALL: \
855 877
 			if (send_sock){  \
856 878
 				/* address */ \
857
-				if (send_sock->address.af!=AF_INET){\
879
+				if ((send_sock->address.af!=AF_INET) && \
880
+						(send_address_str==&(send_sock->address_str))){\
858 881
 					new_buf[offset]='['; offset++; \
859 882
 				}\
860
-				memcpy(new_buf+offset, send_sock->address_str.s, \
861
-						send_sock->address_str.len); \
862
-				offset+=send_sock->address_str.len; \
863
-				if (send_sock->address.af!=AF_INET){\
883
+				memcpy(new_buf+offset, send_address_str->s, \
884
+						send_address_str->len); \
885
+				offset+=send_address_str->len; \
886
+				if ((send_sock->address.af!=AF_INET) && \
887
+						(send_address_str==&(send_sock->address_str))){\
864 888
 					new_buf[offset]=']'; offset++; \
865 889
 				}\
866 890
 				/* :port */ \
867
-				if (send_sock->port_no!=SIP_PORT){ \
891
+				if ((send_sock->port_no!=SIP_PORT) || \
892
+					(send_port_str!=&(send_sock->port_no_str))){ \
868 893
 					new_buf[offset]=':'; offset++; \
869
-					memcpy(new_buf+offset, send_sock->port_no_str.s, \
870
-							send_sock->port_no_str.len); \
871
-					offset+=send_sock->port_no_str.len; \
894
+					memcpy(new_buf+offset, send_port_str->s, \
895
+							send_port_str->len); \
896
+					offset+=send_port_str->len; \
872 897
 				}\
873 898
 				switch(send_sock->proto){ \
874 899
 					case PROTO_NONE: \
... ...
@@ -970,6 +995,15 @@ static inline void process_lumps(	struct sip_msg* msg,
970 995
 	} \
971 996
  \
972 997
 	
998
+	/* init send_address_str & send_port_str */
999
+	if (msg->set_global_address.len)
1000
+		send_address_str=&(msg->set_global_address);
1001
+	else
1002
+		send_address_str=&(send_sock->address_str);
1003
+	if (msg->set_global_port.len)
1004
+		send_port_str=&(msg->set_global_address);
1005
+	else
1006
+		send_port_str=&(send_sock->port_no_str);
973 1007
 	
974 1008
 	
975 1009
 	orig=msg->buf;
... ...
@@ -1149,6 +1183,7 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
1149 1183
 	struct lump* via_insert_param;
1150 1184
 	str branch;
1151 1185
 	str extra_params;
1186
+	struct hostport hp;
1152 1187
 	
1153 1188
 #ifdef USE_TCP
1154 1189
 	char* id_buf;
... ...
@@ -1221,8 +1256,9 @@ skip_clen:
1221 1256
 #endif
1222 1257
 	branch.s=msg->add_to_branch_s;
1223 1258
 	branch.len=msg->add_to_branch_len;
1259
+	set_hostport(&hp, msg);
1224 1260
 	line_buf = via_builder( &via_len, send_sock, &branch,
1225
-							extra_params.len?&extra_params:0, proto);
1261
+							extra_params.len?&extra_params:0, proto, &hp);
1226 1262
 	if (!line_buf){
1227 1263
 		LOG(L_ERR,"ERROR: build_req_buf_from_sip_req: no via received!\n");
1228 1264
 		goto error00;
... ...
@@ -1844,16 +1880,27 @@ int branch_builder( unsigned int hash_index,
1844 1880
 
1845 1881
 char* via_builder( unsigned int *len, 
1846 1882
 	struct socket_info* send_sock,
1847
-	str* branch, str* extra_params, int proto )
1883
+	str* branch, str* extra_params, int proto, struct hostport* hp)
1848 1884
 {
1849 1885
 	unsigned int  via_len, extra_len;
1850 1886
 	char               *line_buf;
1851 1887
 	int max_len;
1888
+	str* address_str; /* address displayed in via */
1889
+	str* port_str; /* port no displayed in via */
1890
+	
1891
+	/* use pre-set address in via or the outbound socket one */
1892
+	if ( hp && hp->host->len)
1893
+		address_str=hp->host;
1894
+	else
1895
+		address_str=&(send_sock->address_str);
1896
+	if (hp && hp->port->len)
1897
+		port_str=hp->port;
1898
+	else
1899
+		port_str=&(send_sock->port_no_str);
1852 1900
 
1853
-
1854
-	max_len=MY_VIA_LEN+send_sock->address_str.len /* space in MY_VIA */
1901
+	max_len=MY_VIA_LEN+address_str->len /* space in MY_VIA */
1855 1902
 		+2 /* just in case it is a v6 address ... [ ] */
1856
-		+1 /*':'*/+send_sock->port_no_str.len
1903
+		+1 /*':'*/+port_str->len
1857 1904
 		+(branch?(MY_BRANCH_LEN+branch->len):0)
1858 1905
 		+(extra_params?extra_params->len:0)
1859 1906
 		+CRLF_LEN+1;
... ...
@@ -1866,7 +1913,7 @@ char* via_builder( unsigned int *len,
1866 1913
 
1867 1914
 	extra_len=0;
1868 1915
 
1869
-	via_len=MY_VIA_LEN+send_sock->address_str.len; /*space included in MY_VIA*/
1916
+	via_len=MY_VIA_LEN+address_str->len; /*space included in MY_VIA*/
1870 1917
 
1871 1918
 	memcpy(line_buf, MY_VIA, MY_VIA_LEN); 
1872 1919
 	if (proto==PROTO_UDP){
... ...
@@ -1880,20 +1927,21 @@ char* via_builder( unsigned int *len,
1880 1927
 		return 0;
1881 1928
 	}
1882 1929
 #	ifdef USE_IPV6
1883
-	if (send_sock->address.af==AF_INET6) {
1930
+	/* add [] only if ipv6 and outbound socket address is used;
1931
+	 * if using pre-set no check is made */
1932
+	if ((send_sock->address.af==AF_INET6) &&
1933
+		(address_str==&(send_sock->address_str))) {
1884 1934
 		line_buf[MY_VIA_LEN]='[';
1885
-		line_buf[MY_VIA_LEN+1+send_sock->address_str.len]=']';
1935
+		line_buf[MY_VIA_LEN+1+address_str->len]=']';
1886 1936
 		extra_len=1;
1887 1937
 		via_len+=2; /* [ ]*/
1888 1938
 	}
1889 1939
 #	endif
1890
-	memcpy(line_buf+MY_VIA_LEN+extra_len, send_sock->address_str.s,
1891
-		send_sock->address_str.len);
1892
-	if (send_sock->port_no!=SIP_PORT){
1940
+	memcpy(line_buf+MY_VIA_LEN+extra_len, address_str->s, address_str->len);
1941
+	if ((send_sock->port_no!=SIP_PORT) || (port_str!=&send_sock->port_no_str)){
1893 1942
 		line_buf[via_len]=':'; via_len++;
1894
-		memcpy(line_buf+via_len, send_sock->port_no_str.s,
1895
-			 send_sock->port_no_str.len);
1896
-		via_len+=send_sock->port_no_str.len;
1943
+		memcpy(line_buf+via_len, port_str->s, port_str->len);
1944
+		via_len+=port_str->len;
1897 1945
 	}
1898 1946
 
1899 1947
 	/* branch parameter */
... ...
@@ -55,6 +55,25 @@ struct bookmark {
55 55
 	str to_tag_val;
56 56
 };
57 57
 
58
+/* used by via_builder */
59
+struct hostport {
60
+	str* host;
61
+	str* port;
62
+};
63
+
64
+
65
+#define set_hostport(hp, msg) \
66
+	do{ \
67
+		if ((msg) && ((struct sip_msg*)(msg))->set_global_address.len) \
68
+			(hp)->host=&(((struct sip_msg*)(msg))->set_global_address); \
69
+		else \
70
+			(hp)->host=&default_global_address; \
71
+		if ((msg) && ((struct sip_msg*)(msg))->set_global_port.len) \
72
+			(hp)->port=&(((struct sip_msg*)(msg))->set_global_port); \
73
+		else \
74
+			(hp)->port=&default_global_port; \
75
+	}while(0)
76
+
58 77
 char * build_req_buf_from_sip_req (	struct sip_msg* msg, 
59 78
 				unsigned int *returned_len, struct socket_info* send_sock,
60 79
 				int proto);
... ...
@@ -84,7 +103,7 @@ char * build_res_buf_with_body_from_sip_req(	unsigned int code ,
84 103
 */
85 104
 char* via_builder( unsigned int *len,
86 105
 	struct socket_info* send_sock,
87
-	str *branch, str* extra_params, int proto );
106
+	str *branch, str* extra_params, int proto, struct hostport *hp );
88 107
 
89 108
 
90 109
 int branch_builder( unsigned int hash_index, 
... ...
@@ -228,6 +228,8 @@ struct sip_msg {
228 228
 	      * reached 
229 229
 	      */
230 230
 	flag_t flags;	
231
+	str set_global_address;
232
+	str set_global_port;
231 233
 };
232 234
 
233 235
 /* pointer to a fakes message which was never received ;
... ...
@@ -59,6 +59,12 @@
59 59
 #endif
60 60
 
61 61
 unsigned int msg_no=0;
62
+/* address preset vars */
63
+str default_global_address={0,0};
64
+str default_global_port={0,0};
65
+str default_via_address={0,0};
66
+str default_via_port={0,0};
67
+
62 68
 
63 69
 
64 70
 /* WARNING: buf must be 0 terminated (buf[len]=0) or some things might 
... ...
@@ -93,6 +99,8 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
93 99
 	/* buf[len]=0; */ /* WARNING: zero term removed! */
94 100
 	msg->rcv=*rcv_info;
95 101
 	msg->id=msg_no;
102
+	msg->set_global_address=default_global_address;
103
+	msg->set_global_port=default_global_port;
96 104
 	
97 105
 	if (parse_msg(buf,len, msg)!=0){
98 106
 		LOG(L_ERR, "ERROR: receive_msg: parse_msg failed\n");
... ...
@@ -127,7 +135,6 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
127 135
 #ifdef  STATS
128 136
 		gettimeofday( & tvb, &tz );
129 137
 #endif
130
-
131 138
 		if (run_actions(rlist[0], msg)<0){
132 139
 
133 140
 			LOG(L_WARN, "WARNING: receive_msg: "
... ...
@@ -31,6 +31,7 @@
31 31
  *  2003-01-29  src_port introduced (jiri)
32 32
  *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
33 33
  *  2003-04-12  FORCE_RPORT_T added (andrei)
34
+ *  2003-10-02  added SET_ADV_ADDRESS & SET_ADV_PORT (andrei)
34 35
  */
35 36
 
36 37
 
... ...
@@ -317,6 +318,12 @@ void print_action(struct action* a)
317 318
 			case FORCE_RPORT_T:
318 319
 					DBG("force_rport(");
319 320
 					break;
321
+			case SET_ADV_ADDR_T:
322
+					DBG("set_advertised_address(");
323
+					break;
324
+			case SET_ADV_PORT_T:
325
+					DBG("set_advertised_port(");
326
+					break;
320 327
 			default:
321 328
 					DBG("UNKNOWN(");
322 329
 		}
... ...
@@ -66,11 +66,13 @@ enum { FORWARD_T=1, SEND_T, DROP_T, LOG_T, ERROR_T, ROUTE_T, EXEC_T,
66 66
 		FORWARD_UDP_T,
67 67
 		FORWARD_TLS_T,
68 68
 		SEND_TCP_T,
69
-		FORCE_RPORT_T
69
+		FORCE_RPORT_T,
70
+		SET_ADV_ADDR_T,
71
+		SET_ADV_PORT_T
70 72
 };
71 73
 enum { NOSUBTYPE=0, STRING_ST, NET_ST, NUMBER_ST, IP_ST, RE_ST, PROXY_ST,
72 74
 		EXPR_ST, ACTIONS_ST, CMDF_ST, MODFIXUP_ST, URIHOST_ST, URIPORT_ST,
73
-		MYSELF_ST };
75
+		MYSELF_ST, STR_ST };
74 76
 
75 77
 	
76 78
 struct expr{