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 20
     something like alias= foo1.bar:5080 foo2.bar foo3.bar:*
21 21
 - extend listen and alias to include port numbers and protocol:
22 22
        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).
23
+x added set_advertised_{address,port} -- was: add force_via, force_srcip a.s.o
24
+(the advertised addresses should be overwritable from the script).
25 25
 - ? add force_outbound_socket(ip)? (choose an apropriate socket from the
26 26
  listen list for sending the msg; works on udp only)
27 27
 
... ...
@@ -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 608
 			msg->msg_flags|=FL_FORCE_RPORT;
609 609
 			ret=1; /* continue processing */
610 610
 			break;
611
+		case SET_ADV_ADDR_T:
612
+			if (a->p1_type!=STR_ST){
613
+				LOG(L_CRIT, "BUG: do_action: bad set_advertised_address() "
614
+						"type %d\n", a->p1_type);
615
+				ret=E_BUG;
616
+				break;
617
+			}
618
+			msg->set_global_address=*((str*)a->p1.data);
619
+			ret=1; /* continue processing */
620
+			break;
621
+		case SET_ADV_PORT_T:
622
+			if (a->p1_type!=STR_ST){
623
+				LOG(L_CRIT, "BUG: do_action: bad set_advertised_port() "
624
+						"type %d\n", a->p1_type);
625
+				ret=E_BUG;
626
+				break;
627
+			}
628
+			msg->set_global_port=*((str*)a->p1.data);
629
+			ret=1; /* continue processing */
630
+			break;
611 631
 		default:
612 632
 			LOG(L_CRIT, "BUG: do_action: unknown type %d\n", a->type);
613 633
 	}
... ...
@@ -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 106
 APPEND_BRANCH	"append_branch"
107 107
 IF				"if"
108 108
 ELSE			"else"
109
+SET_ADV_ADDRESS	"set_advertised_address"
110
+SET_ADV_PORT	"set_advertised_port"
109 111
 
110 112
 /*ACTION LVALUES*/
111 113
 URIHOST			"uri:host"
... ...
@@ -172,6 +175,8 @@ TLS_REQUIRE_CERTIFICATE "tls_require_certificate"
172 172
 TLS_CERTIFICATE	"tls_certificate"
173 173
 TLS_PRIVATE_KEY "tls_private_key"
174 174
 TLS_CA_LIST		"tls_ca_list"
175
+ADVERTISED_ADDRESS	"advertised_address"
176
+ADVERTISED_PORT		"advertised_port"
175 177
 
176 178
 LOADMODULE	loadmodule
177 179
 MODPARAM        modparam
... ...
@@ -260,6 +265,11 @@ EAT_ABLE	[\ \t\b\r]
260 260
 <INITIAL>{IF}	{ count(); yylval.strval=yytext; return IF; }
261 261
 <INITIAL>{ELSE}	{ count(); yylval.strval=yytext; return ELSE; }
262 262
 
263
+<INITIAL>{SET_ADV_ADDRESS}	{ count(); yylval.strval=yytext;
264
+										return SET_ADV_ADDRESS; }
265
+<INITIAL>{SET_ADV_PORT}	{ count(); yylval.strval=yytext;
266
+										return SET_ADV_PORT; }
267
+
263 268
 <INITIAL>{URIHOST}	{ count(); yylval.strval=yytext; return URIHOST; }
264 269
 <INITIAL>{URIPORT}	{ count(); yylval.strval=yytext; return URIPORT; }
265 270
 
... ...
@@ -314,6 +324,10 @@ EAT_ABLE	[\ \t\b\r]
314 314
 <INITIAL>{FIFO_MODE}	{ count(); yylval.strval=yytext; return FIFO_MODE; }
315 315
 <INITIAL>{SERVER_SIGNATURE}	{ count(); yylval.strval=yytext; return SERVER_SIGNATURE; }
316 316
 <INITIAL>{REPLY_TO_VIA}	{ count(); yylval.strval=yytext; return REPLY_TO_VIA; }
317
+<INITIAL>{ADVERTISED_ADDRESS}	{	count(); yylval.strval=yytext;
318
+									return ADVERTISED_ADDRESS; }
319
+<INITIAL>{ADVERTISED_PORT}		{	count(); yylval.strval=yytext;
320
+									return ADVERTISED_PORT; }
317 321
 <INITIAL>{LOADMODULE}	{ count(); yylval.strval=yytext; return LOADMODULE; }
318 322
 <INITIAL>{MODPARAM}     { count(); yylval.strval=yytext; return MODPARAM; }
319 323
 
... ...
@@ -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 63
 #include "modparam.h"
64 64
 #include "ip_addr.h"
65 65
 #include "name_alias.h"
66
+#include "ut.h"
66 67
 
67 68
 #include "config.h"
68 69
 #ifdef USE_TLS
... ...
@@ -84,10 +86,12 @@ struct id_list{
84 84
 
85 85
 extern int yylex();
86 86
 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 */
87
+static char* tmp;
88
+static int i_tmp;
89
+static void* f_tmp;
90
+static struct id_list* lst_tmp;
91
+static int rt;  /* Type of route block for find_export */
92
+static str* str_tmp;
91 93
 
92 94
 void warn(char* s);
93 95
  
... ...
@@ -136,6 +140,8 @@ void warn(char* s);
136 136
 %token FORCE_RPORT
137 137
 %token IF
138 138
 %token ELSE
139
+%token SET_ADV_ADDRESS
140
+%token SET_ADV_PORT
139 141
 %token URIHOST
140 142
 %token URIPORT
141 143
 %token MAX_LEN
... ...
@@ -195,6 +201,9 @@ void warn(char* s);
195 195
 %token TLS_CERTIFICATE
196 196
 %token TLS_PRIVATE_KEY
197 197
 %token TLS_CA_LIST
198
+%token ADVERTISED_ADDRESS
199
+%token ADVERTISED_PORT
200
+
198 201
 
199 202
 
200 203
 
... ...
@@ -527,6 +536,27 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
527 527
 								add_alias(lst_tmp->s, strlen(lst_tmp->s), 0);
528 528
 							  }
529 529
 		| ALIAS  EQUAL error  { yyerror(" hostname expected"); }
530
+		| ADVERTISED_ADDRESS EQUAL listen_id {
531
+								default_global_address.s=$3;
532
+								default_global_address.len=strlen($3);
533
+								}
534
+		|ADVERTISED_ADDRESS EQUAL error {yyerror("ip address or hostname "
535
+												"expected"); }
536
+		| ADVERTISED_PORT EQUAL NUMBER {
537
+								tmp=int2str($3, &i_tmp);
538
+								if ((default_global_port.s=pkg_malloc(i_tmp))
539
+										==0){
540
+										LOG(L_CRIT, "ERROR: cfg. parser:"
541
+													" out of memory.\n");
542
+										default_global_port.len=0;
543
+								}else{
544
+									default_global_port.len=i_tmp;
545
+									memcpy(default_global_port.s, tmp,
546
+											default_global_port.len);
547
+								};
548
+								}
549
+		|ADVERTISED_PORT EQUAL error {yyerror("ip address or hostname "
550
+												"expected"); }
530 551
 		| error EQUAL { yyerror("unknown config variable"); }
531 552
 	;
532 553
 
... ...
@@ -1341,6 +1371,42 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
1341 1341
 		| REVERT_URI { $$=mk_action( REVERT_URI_T, 0,0,0,0); }
1342 1342
 		| FORCE_RPORT LPAREN RPAREN	{$$=mk_action(FORCE_RPORT_T,0, 0, 0, 0); }
1343 1343
 		| FORCE_RPORT				{$$=mk_action(FORCE_RPORT_T,0, 0, 0, 0); }
1344
+		| SET_ADV_ADDRESS LPAREN listen_id RPAREN {
1345
+								$$=0;
1346
+								if ((str_tmp=pkg_malloc(sizeof(str)))==0){
1347
+										LOG(L_CRIT, "ERROR: cfg. parser:"
1348
+													" out of memory.\n");
1349
+								}else{
1350
+										str_tmp->s=$3;
1351
+										str_tmp->len=strlen($3);
1352
+										$$=mk_action(SET_ADV_ADDR_T, STR_ST,
1353
+										             0, str_tmp, 0);
1354
+								}
1355
+												  }
1356
+		| SET_ADV_ADDRESS LPAREN error RPAREN { $$=0; yyerror("bad argument, "
1357
+														"string expected"); }
1358
+		| SET_ADV_ADDRESS error {$$=0; yyerror("missing '(' or ')' ?"); }
1359
+		| SET_ADV_PORT LPAREN NUMBER RPAREN {
1360
+								$$=0;
1361
+								tmp=int2str($3, &i_tmp);
1362
+								if ((str_tmp=pkg_malloc(sizeof(str)))==0){
1363
+										LOG(L_CRIT, "ERROR: cfg. parser:"
1364
+													" out of memory.\n");
1365
+								}else{
1366
+									if ((str_tmp->s=pkg_malloc(i_tmp))==0){
1367
+										LOG(L_CRIT, "ERROR: cfg. parser:"
1368
+													" out of memory.\n");
1369
+									}else{
1370
+										memcpy(str_tmp->s, tmp, i_tmp);
1371
+										str_tmp->len=i_tmp;
1372
+										$$=mk_action(SET_ADV_PORT_T, STR_ST,
1373
+													0, str_tmp, 0);
1374
+									}
1375
+								}
1376
+								            }
1377
+		| SET_ADV_PORT LPAREN error RPAREN { $$=0; yyerror("bad argument, "
1378
+														"string expected"); }
1379
+		| SET_ADV_PORT  error {$$=0; yyerror("missing '(' or ')' ?"); }
1344 1380
 		| ID LPAREN RPAREN			{ f_tmp=(void*)find_export($1, 0, rt);
1345 1381
 									   if (f_tmp==0){
1346 1382
 										   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 78
 	char branch_buf[MAX_BRANCH_PARAM_LEN];
79 79
 	int branch_len;
80 80
 	str branch_str;
81
+	struct hostport hp;
81 82
 
82 83
 #ifdef _OBSO
83 84
 	if ( Trans->uac[branch].last_received<100)
... ...
@@ -98,8 +100,9 @@ char *build_local(struct cell *Trans,unsigned int branch,
98 98
 		goto error;
99 99
 	branch_str.s=branch_buf;
100 100
 	branch_str.len=branch_len;
101
+	set_hostport(&hp, (Trans->local)?0:(Trans->uas.request));
101 102
 	via=via_builder(&via_len, Trans->uac[branch].request.dst.send_sock,
102
-		&branch_str, 0, Trans->uac[branch].request.dst.proto );
103
+		&branch_str, 0, Trans->uac[branch].request.dst.proto, &hp );
103 104
 	if (!via)
104 105
 	{
105 106
 		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 236
 	int len;
237 237
 	unsigned int via_len;
238 238
 	str branch_str;
239
+	struct hostport hp;
239 240
 
240 241
 	if (!t_calc_branch(t, branch, branch_buf, &len)) {
241 242
 		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 249
 	printf("!!!proto: %d\n", sock->proto);
250 250
 #endif
251 251
 
252
-	via = via_builder(&via_len, sock, &branch_str, 0, sock->proto);
252
+	set_hostport(&hp, 0);
253
+	via = via_builder(&via_len, sock, &branch_str, 0, sock->proto, &hp);
253 254
 	if (!via) {
254 255
 		LOG(L_ERR, "build_via: via building failed\n");
255 256
 		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 142
 
143 143
 
144 144
 
145
+
146
+
145 147
 /* checks if ip is in host(name) and ?host(ip)=name?
146 148
  * ip must be in network byte order!
147 149
  *  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 485
 	int new_len;
486 486
 	struct lump* t;
487 487
 	struct lump* r;
488
+	str* send_address_str;
489
+	str* send_port_str;
488 490
 
489 491
 #define SUBST_LUMP_LEN(subst_l) \
490 492
 		switch((subst_l)->u.subst){ \
... ...
@@ -559,8 +564,9 @@ static inline int lumps_len(struct sip_msg* msg, struct socket_info* send_sock)
559 559
 				break; \
560 560
 			case SUBST_SND_IP: \
561 561
 				if (send_sock){ \
562
-					new_len+=send_sock->address_str.len; \
563
-					if (send_sock->address.af!=AF_INET) \
562
+					new_len+=send_address_str->len; \
563
+					if (send_sock->address.af!=AF_INET && \
564
+							send_address_str==&(send_sock->address_str)) \
564 565
 						new_len+=2; \
565 566
 				}else{ \
566 567
 					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 569
 				break; \
570 570
 			case SUBST_SND_PORT: \
571 571
 				if (send_sock){ \
572
-					new_len+=send_sock->port_no_str.len; \
572
+					new_len+=send_port_str->len; \
573 573
 				}else{ \
574 574
 					LOG(L_CRIT, "FIXME: lumps_len called with" \
575 575
 							" null send_sock\n"); \
... ...
@@ -598,12 +604,14 @@ static inline int lumps_len(struct sip_msg* msg, struct socket_info* send_sock)
598 598
 				break; \
599 599
 			case SUBST_SND_ALL: \
600 600
 				if (send_sock){ \
601
-					new_len+=send_sock->address_str.len; \
602
-					if (send_sock->address.af!=AF_INET) \
601
+					new_len+=send_address_str->len; \
602
+					if ((send_sock->address.af!=AF_INET) && \
603
+							(send_address_str==&(send_sock->address_str))) \
603 604
 						new_len+=2; \
604
-					if (send_sock->port_no!=SIP_PORT){ \
605
+					if ((send_sock->port_no!=SIP_PORT) || \
606
+							(send_port_str!=&(send_sock->port_no_str))){ \
605 607
 						/* add :port_no */ \
606
-						new_len+=1+send_sock->port_no_str.len; \
608
+						new_len+=1+send_port_str->len; \
607 609
 					}\
608 610
 					/*add;transport=xxx*/ \
609 611
 					switch(send_sock->proto){ \
... ...
@@ -636,6 +644,16 @@ static inline int lumps_len(struct sip_msg* msg, struct socket_info* send_sock)
636 636
 	
637 637
 	s_offset=0;
638 638
 	new_len=0;
639
+	/* init send_address_str & send_port_str */
640
+	if (msg->set_global_address.len)
641
+		send_address_str=&(msg->set_global_address);
642
+	else
643
+		send_address_str=&(send_sock->address_str);
644
+	if (msg->set_global_port.len)
645
+		send_port_str=&(msg->set_global_address);
646
+	else
647
+		send_port_str=&(send_sock->port_no_str);
648
+	
639 649
 	
640 650
 	for(t=msg->add_rm;t;t=t->next){
641 651
 		/* 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 740
 	int size;
741 741
 	int offset;
742 742
 	int s_offset;
743
+	str* send_address_str;
744
+	str* send_port_str;
743 745
 
744 746
 #define SUBST_LUMP(subst_l) \
745 747
 	switch((subst_l)->u.subst){ \
... ...
@@ -825,13 +845,15 @@ static inline void process_lumps(	struct sip_msg* msg,
825 825
 			break; \
826 826
 		case SUBST_SND_IP: \
827 827
 			if (send_sock){  \
828
-				if (send_sock->address.af!=AF_INET){\
828
+				if ((send_sock->address.af!=AF_INET) && \
829
+						(send_address_str==&(send_sock->address_str))){\
829 830
 					new_buf[offset]='['; offset++; \
830 831
 				}\
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){\
832
+				memcpy(new_buf+offset, send_address_str->s, \
833
+									send_address_str->len); \
834
+				offset+=send_address_str->len; \
835
+				if ((send_sock->address.af!=AF_INET) && \
836
+						(send_address_str==&(send_sock->address_str))){\
835 837
 					new_buf[offset]=']'; offset++; \
836 838
 				}\
837 839
 			}else{  \
... ...
@@ -842,9 +864,9 @@ static inline void process_lumps(	struct sip_msg* msg,
842 842
 			break; \
843 843
 		case SUBST_SND_PORT: \
844 844
 			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; \
845
+				memcpy(new_buf+offset, send_port_str->s, \
846
+									send_port_str->len); \
847
+				offset+=send_port_str->len; \
848 848
 			}else{  \
849 849
 				/*FIXME*/ \
850 850
 				LOG(L_CRIT, "FIXME: process_lumps: called with" \
... ...
@@ -854,21 +876,24 @@ static inline void process_lumps(	struct sip_msg* msg,
854 854
 		case SUBST_SND_ALL: \
855 855
 			if (send_sock){  \
856 856
 				/* address */ \
857
-				if (send_sock->address.af!=AF_INET){\
857
+				if ((send_sock->address.af!=AF_INET) && \
858
+						(send_address_str==&(send_sock->address_str))){\
858 859
 					new_buf[offset]='['; offset++; \
859 860
 				}\
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){\
861
+				memcpy(new_buf+offset, send_address_str->s, \
862
+						send_address_str->len); \
863
+				offset+=send_address_str->len; \
864
+				if ((send_sock->address.af!=AF_INET) && \
865
+						(send_address_str==&(send_sock->address_str))){\
864 866
 					new_buf[offset]=']'; offset++; \
865 867
 				}\
866 868
 				/* :port */ \
867
-				if (send_sock->port_no!=SIP_PORT){ \
869
+				if ((send_sock->port_no!=SIP_PORT) || \
870
+					(send_port_str!=&(send_sock->port_no_str))){ \
868 871
 					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; \
872
+					memcpy(new_buf+offset, send_port_str->s, \
873
+							send_port_str->len); \
874
+					offset+=send_port_str->len; \
872 875
 				}\
873 876
 				switch(send_sock->proto){ \
874 877
 					case PROTO_NONE: \
... ...
@@ -970,6 +995,15 @@ static inline void process_lumps(	struct sip_msg* msg,
970 970
 	} \
971 971
  \
972 972
 	
973
+	/* init send_address_str & send_port_str */
974
+	if (msg->set_global_address.len)
975
+		send_address_str=&(msg->set_global_address);
976
+	else
977
+		send_address_str=&(send_sock->address_str);
978
+	if (msg->set_global_port.len)
979
+		send_port_str=&(msg->set_global_address);
980
+	else
981
+		send_port_str=&(send_sock->port_no_str);
973 982
 	
974 983
 	
975 984
 	orig=msg->buf;
... ...
@@ -1149,6 +1183,7 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
1149 1149
 	struct lump* via_insert_param;
1150 1150
 	str branch;
1151 1151
 	str extra_params;
1152
+	struct hostport hp;
1152 1153
 	
1153 1154
 #ifdef USE_TCP
1154 1155
 	char* id_buf;
... ...
@@ -1221,8 +1256,9 @@ skip_clen:
1221 1221
 #endif
1222 1222
 	branch.s=msg->add_to_branch_s;
1223 1223
 	branch.len=msg->add_to_branch_len;
1224
+	set_hostport(&hp, msg);
1224 1225
 	line_buf = via_builder( &via_len, send_sock, &branch,
1225
-							extra_params.len?&extra_params:0, proto);
1226
+							extra_params.len?&extra_params:0, proto, &hp);
1226 1227
 	if (!line_buf){
1227 1228
 		LOG(L_ERR,"ERROR: build_req_buf_from_sip_req: no via received!\n");
1228 1229
 		goto error00;
... ...
@@ -1844,16 +1880,27 @@ int branch_builder( unsigned int hash_index,
1844 1844
 
1845 1845
 char* via_builder( unsigned int *len, 
1846 1846
 	struct socket_info* send_sock,
1847
-	str* branch, str* extra_params, int proto )
1847
+	str* branch, str* extra_params, int proto, struct hostport* hp)
1848 1848
 {
1849 1849
 	unsigned int  via_len, extra_len;
1850 1850
 	char               *line_buf;
1851 1851
 	int max_len;
1852
+	str* address_str; /* address displayed in via */
1853
+	str* port_str; /* port no displayed in via */
1854
+	
1855
+	/* use pre-set address in via or the outbound socket one */
1856
+	if ( hp && hp->host->len)
1857
+		address_str=hp->host;
1858
+	else
1859
+		address_str=&(send_sock->address_str);
1860
+	if (hp && hp->port->len)
1861
+		port_str=hp->port;
1862
+	else
1863
+		port_str=&(send_sock->port_no_str);
1852 1864
 
1853
-
1854
-	max_len=MY_VIA_LEN+send_sock->address_str.len /* space in MY_VIA */
1865
+	max_len=MY_VIA_LEN+address_str->len /* space in MY_VIA */
1855 1866
 		+2 /* just in case it is a v6 address ... [ ] */
1856
-		+1 /*':'*/+send_sock->port_no_str.len
1867
+		+1 /*':'*/+port_str->len
1857 1868
 		+(branch?(MY_BRANCH_LEN+branch->len):0)
1858 1869
 		+(extra_params?extra_params->len:0)
1859 1870
 		+CRLF_LEN+1;
... ...
@@ -1866,7 +1913,7 @@ char* via_builder( unsigned int *len,
1866 1866
 
1867 1867
 	extra_len=0;
1868 1868
 
1869
-	via_len=MY_VIA_LEN+send_sock->address_str.len; /*space included in MY_VIA*/
1869
+	via_len=MY_VIA_LEN+address_str->len; /*space included in MY_VIA*/
1870 1870
 
1871 1871
 	memcpy(line_buf, MY_VIA, MY_VIA_LEN); 
1872 1872
 	if (proto==PROTO_UDP){
... ...
@@ -1880,20 +1927,21 @@ char* via_builder( unsigned int *len,
1880 1880
 		return 0;
1881 1881
 	}
1882 1882
 #	ifdef USE_IPV6
1883
-	if (send_sock->address.af==AF_INET6) {
1883
+	/* add [] only if ipv6 and outbound socket address is used;
1884
+	 * if using pre-set no check is made */
1885
+	if ((send_sock->address.af==AF_INET6) &&
1886
+		(address_str==&(send_sock->address_str))) {
1884 1887
 		line_buf[MY_VIA_LEN]='[';
1885
-		line_buf[MY_VIA_LEN+1+send_sock->address_str.len]=']';
1888
+		line_buf[MY_VIA_LEN+1+address_str->len]=']';
1886 1889
 		extra_len=1;
1887 1890
 		via_len+=2; /* [ ]*/
1888 1891
 	}
1889 1892
 #	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){
1893
+	memcpy(line_buf+MY_VIA_LEN+extra_len, address_str->s, address_str->len);
1894
+	if ((send_sock->port_no!=SIP_PORT) || (port_str!=&send_sock->port_no_str)){
1893 1895
 		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;
1896
+		memcpy(line_buf+via_len, port_str->s, port_str->len);
1897
+		via_len+=port_str->len;
1897 1898
 	}
1898 1899
 
1899 1900
 	/* 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 84
 */
85 85
 char* via_builder( unsigned int *len,
86 86
 	struct socket_info* send_sock,
87
-	str *branch, str* extra_params, int proto );
87
+	str *branch, str* extra_params, int proto, struct hostport *hp );
88 88
 
89 89
 
90 90
 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 93
 	/* buf[len]=0; */ /* WARNING: zero term removed! */
94 94
 	msg->rcv=*rcv_info;
95 95
 	msg->id=msg_no;
96
+	msg->set_global_address=default_global_address;
97
+	msg->set_global_port=default_global_port;
96 98
 	
97 99
 	if (parse_msg(buf,len, msg)!=0){
98 100
 		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 127
 #ifdef  STATS
128 128
 		gettimeofday( & tvb, &tz );
129 129
 #endif
130
-
131 130
 		if (run_actions(rlist[0], msg)<0){
132 131
 
133 132
 			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 317
 			case FORCE_RPORT_T:
318 318
 					DBG("force_rport(");
319 319
 					break;
320
+			case SET_ADV_ADDR_T:
321
+					DBG("set_advertised_address(");
322
+					break;
323
+			case SET_ADV_PORT_T:
324
+					DBG("set_advertised_port(");
325
+					break;
320 326
 			default:
321 327
 					DBG("UNKNOWN(");
322 328
 		}
... ...
@@ -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{