Browse Source

- 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 22 years ago
parent
commit
6bfaa042d6
13 changed files with 247 additions and 53 deletions
  1. 1 1
      Makefile.defs
  2. 2 4
      TODO
  3. 21 0
      action.c
  4. 14 0
      cfg.lex
  5. 70 4
      cfg.y
  6. 5 0
      globals.h
  7. 7 2
      modules/tm/t_msgbuilder.c
  8. 86 38
      msg_translator.c
  9. 20 1
      msg_translator.h
  10. 2 0
      parser/msg_parser.h
  11. 8 1
      receive.c
  12. 7 0
      route_struct.c
  13. 4 2
      route_struct.h

+ 1 - 1
Makefile.defs

@@ -43,7 +43,7 @@ export makefile_defs
 VERSION = 0
 PATCHLEVEL = 8
 SUBLEVEL =   12
-EXTRAVERSION = dev-t16
+EXTRAVERSION = dev-17-cristian
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")

+ 2 - 4
TODO

@@ -3,8 +3,6 @@ $Id$
 ( - todo, x - done)
 
 - grep parse_uri & replace with parse_sip_msg_uri (e.g do_action!)
-- WARNING: tm fr_timer fixup is not in HEAD (should it be? is it the
- rigth fix?)
 x update AUTHORS, debian/copyright, ser.8, ser.cfg.5 from stable
 x update Makefile*  from stable
 x update all package specs from stable
@@ -20,8 +18,8 @@ x port receive.c pre_script_cb fix from stable
     something like alias= foo1.bar:5080 foo2.bar foo3.bar:*
 - extend listen and alias to include port numbers and protocol:
        tcp foo.bar:5063, udp foo.bar:5062, foo2.bar
-- add force_via, force_srcip a.s.o (the advertised addresses should be
- overwritable from the script).
+x added set_advertised_{address,port} -- was: add force_via, force_srcip a.s.o
+(the advertised addresses should be overwritable from the script).
 - ? add force_outbound_socket(ip)? (choose an apropriate socket from the
  listen list for sending the msg; works on udp only)
 

+ 21 - 0
action.c

@@ -34,6 +34,7 @@
  *  2003-04-01  Added support for loose routing in forward (janakj)
  *  2003-04-12  FORCE_RPORT_T added (andrei)
  *  2003-04-22  strip_tail added (jiri)
+ *  2003-10-02  added SET_ADV_ADDR_T & SET_ADV_PORT_T (andrei)
  */
 
 
@@ -608,6 +609,26 @@ int do_action(struct action* a, struct sip_msg* msg)
 			msg->msg_flags|=FL_FORCE_RPORT;
 			ret=1; /* continue processing */
 			break;
+		case SET_ADV_ADDR_T:
+			if (a->p1_type!=STR_ST){
+				LOG(L_CRIT, "BUG: do_action: bad set_advertised_address() "
+						"type %d\n", a->p1_type);
+				ret=E_BUG;
+				break;
+			}
+			msg->set_global_address=*((str*)a->p1.data);
+			ret=1; /* continue processing */
+			break;
+		case SET_ADV_PORT_T:
+			if (a->p1_type!=STR_ST){
+				LOG(L_CRIT, "BUG: do_action: bad set_advertised_port() "
+						"type %d\n", a->p1_type);
+				ret=E_BUG;
+				break;
+			}
+			msg->set_global_port=*((str*)a->p1.data);
+			ret=1; /* continue processing */
+			break;
 		default:
 			LOG(L_CRIT, "BUG: do_action: unknown type %d\n", a->type);
 	}

+ 14 - 0
cfg.lex

@@ -38,6 +38,7 @@
  *  2003-07-03  tls* (disable, certificate, private_key, ca_list, verify, 
  *               require_certificate added (andrei)
  *  2003-07-06  more tls config. vars added: tls_method, tls_port_no (andrei)
+ *  2003-10-02  added {,set_}advertised_{address,port} (andrei)
  */
 
 
@@ -106,6 +107,8 @@ STRIP_TAIL		"strip_tail"
 APPEND_BRANCH	"append_branch"
 IF				"if"
 ELSE			"else"
+SET_ADV_ADDRESS	"set_advertised_address"
+SET_ADV_PORT	"set_advertised_port"
 
 /*ACTION LVALUES*/
 URIHOST			"uri:host"
@@ -172,6 +175,8 @@ TLS_REQUIRE_CERTIFICATE "tls_require_certificate"
 TLS_CERTIFICATE	"tls_certificate"
 TLS_PRIVATE_KEY "tls_private_key"
 TLS_CA_LIST		"tls_ca_list"
+ADVERTISED_ADDRESS	"advertised_address"
+ADVERTISED_PORT		"advertised_port"
 
 LOADMODULE	loadmodule
 MODPARAM        modparam
@@ -260,6 +265,11 @@ EAT_ABLE	[\ \t\b\r]
 <INITIAL>{IF}	{ count(); yylval.strval=yytext; return IF; }
 <INITIAL>{ELSE}	{ count(); yylval.strval=yytext; return ELSE; }
 
+<INITIAL>{SET_ADV_ADDRESS}	{ count(); yylval.strval=yytext;
+										return SET_ADV_ADDRESS; }
+<INITIAL>{SET_ADV_PORT}	{ count(); yylval.strval=yytext;
+										return SET_ADV_PORT; }
+
 <INITIAL>{URIHOST}	{ count(); yylval.strval=yytext; return URIHOST; }
 <INITIAL>{URIPORT}	{ count(); yylval.strval=yytext; return URIPORT; }
 
@@ -314,6 +324,10 @@ EAT_ABLE	[\ \t\b\r]
 <INITIAL>{FIFO_MODE}	{ count(); yylval.strval=yytext; return FIFO_MODE; }
 <INITIAL>{SERVER_SIGNATURE}	{ count(); yylval.strval=yytext; return SERVER_SIGNATURE; }
 <INITIAL>{REPLY_TO_VIA}	{ count(); yylval.strval=yytext; return REPLY_TO_VIA; }
+<INITIAL>{ADVERTISED_ADDRESS}	{	count(); yylval.strval=yytext;
+									return ADVERTISED_ADDRESS; }
+<INITIAL>{ADVERTISED_PORT}		{	count(); yylval.strval=yytext;
+									return ADVERTISED_PORT; }
 <INITIAL>{LOADMODULE}	{ count(); yylval.strval=yytext; return LOADMODULE; }
 <INITIAL>{MODPARAM}     { count(); yylval.strval=yytext; return MODPARAM; }
 

+ 70 - 4
cfg.y

@@ -42,6 +42,7 @@
  * 2003-07-03  tls* (disable, certificate, private_key, ca_list, verify, 
  *              require_certificate added (andrei)
  * 2003-07-06  more tls config. vars added: tls_method, tls_port_no (andrei)
+ * 2003-10-02  added {,set_}advertised_{address,port} (andrei)
  */
 
 
@@ -63,6 +64,7 @@
 #include "modparam.h"
 #include "ip_addr.h"
 #include "name_alias.h"
+#include "ut.h"
 
 #include "config.h"
 #ifdef USE_TLS
@@ -84,10 +86,12 @@ struct id_list{
 
 extern int yylex();
 void yyerror(char* s);
-char* tmp;
-void* f_tmp;
-struct id_list* lst_tmp;
-int rt;  /* Type of route block for find_export */
+static char* tmp;
+static int i_tmp;
+static void* f_tmp;
+static struct id_list* lst_tmp;
+static int rt;  /* Type of route block for find_export */
+static str* str_tmp;
 
 void warn(char* s);
  
@@ -136,6 +140,8 @@ void warn(char* s);
 %token FORCE_RPORT
 %token IF
 %token ELSE
+%token SET_ADV_ADDRESS
+%token SET_ADV_PORT
 %token URIHOST
 %token URIPORT
 %token MAX_LEN
@@ -195,6 +201,9 @@ void warn(char* s);
 %token TLS_CERTIFICATE
 %token TLS_PRIVATE_KEY
 %token TLS_CA_LIST
+%token ADVERTISED_ADDRESS
+%token ADVERTISED_PORT
+
 
 
 
@@ -527,6 +536,27 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
 								add_alias(lst_tmp->s, strlen(lst_tmp->s), 0);
 							  }
 		| ALIAS  EQUAL error  { yyerror(" hostname expected"); }
+		| ADVERTISED_ADDRESS EQUAL listen_id {
+								default_global_address.s=$3;
+								default_global_address.len=strlen($3);
+								}
+		|ADVERTISED_ADDRESS EQUAL error {yyerror("ip address or hostname "
+												"expected"); }
+		| ADVERTISED_PORT EQUAL NUMBER {
+								tmp=int2str($3, &i_tmp);
+								if ((default_global_port.s=pkg_malloc(i_tmp))
+										==0){
+										LOG(L_CRIT, "ERROR: cfg. parser:"
+													" out of memory.\n");
+										default_global_port.len=0;
+								}else{
+									default_global_port.len=i_tmp;
+									memcpy(default_global_port.s, tmp,
+											default_global_port.len);
+								};
+								}
+		|ADVERTISED_PORT EQUAL error {yyerror("ip address or hostname "
+												"expected"); }
 		| error EQUAL { yyerror("unknown config variable"); }
 	;
 
@@ -1341,6 +1371,42 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
 		| REVERT_URI { $$=mk_action( REVERT_URI_T, 0,0,0,0); }
 		| FORCE_RPORT LPAREN RPAREN	{$$=mk_action(FORCE_RPORT_T,0, 0, 0, 0); }
 		| FORCE_RPORT				{$$=mk_action(FORCE_RPORT_T,0, 0, 0, 0); }
+		| SET_ADV_ADDRESS LPAREN listen_id RPAREN {
+								$$=0;
+								if ((str_tmp=pkg_malloc(sizeof(str)))==0){
+										LOG(L_CRIT, "ERROR: cfg. parser:"
+													" out of memory.\n");
+								}else{
+										str_tmp->s=$3;
+										str_tmp->len=strlen($3);
+										$$=mk_action(SET_ADV_ADDR_T, STR_ST,
+										             0, str_tmp, 0);
+								}
+												  }
+		| SET_ADV_ADDRESS LPAREN error RPAREN { $$=0; yyerror("bad argument, "
+														"string expected"); }
+		| SET_ADV_ADDRESS error {$$=0; yyerror("missing '(' or ')' ?"); }
+		| SET_ADV_PORT LPAREN NUMBER RPAREN {
+								$$=0;
+								tmp=int2str($3, &i_tmp);
+								if ((str_tmp=pkg_malloc(sizeof(str)))==0){
+										LOG(L_CRIT, "ERROR: cfg. parser:"
+													" out of memory.\n");
+								}else{
+									if ((str_tmp->s=pkg_malloc(i_tmp))==0){
+										LOG(L_CRIT, "ERROR: cfg. parser:"
+													" out of memory.\n");
+									}else{
+										memcpy(str_tmp->s, tmp, i_tmp);
+										str_tmp->len=i_tmp;
+										$$=mk_action(SET_ADV_PORT_T, STR_ST,
+													0, str_tmp, 0);
+									}
+								}
+								            }
+		| SET_ADV_PORT LPAREN error RPAREN { $$=0; yyerror("bad argument, "
+														"string expected"); }
+		| SET_ADV_PORT  error {$$=0; yyerror("missing '(' or ')' ?"); }
 		| ID LPAREN RPAREN			{ f_tmp=(void*)find_export($1, 0, rt);
 									   if (f_tmp==0){
 										   if (find_export($1, 0, 0)) {

+ 5 - 0
globals.h

@@ -129,4 +129,9 @@ extern int mhomed;
 extern int my_argc;
 extern char **my_argv;
 
+/* pre-set addresses */
+extern str default_global_address;
+/* pre-ser ports */
+extern str default_global_port;
+
 #endif

+ 7 - 2
modules/tm/t_msgbuilder.c

@@ -35,6 +35,7 @@
  * 2003-04-14  build_local no longer checks reply status as it
  *             is now called before reply status is updated to
  *             avoid late ACK sending (jiri)
+ * 2003-10-02  added via_builder set host/port support (andrei)
  */
 
 #include "defs.h"
@@ -78,6 +79,7 @@ char *build_local(struct cell *Trans,unsigned int branch,
 	char branch_buf[MAX_BRANCH_PARAM_LEN];
 	int branch_len;
 	str branch_str;
+	struct hostport hp;
 
 #ifdef _OBSO
 	if ( Trans->uac[branch].last_received<100)
@@ -98,8 +100,9 @@ char *build_local(struct cell *Trans,unsigned int branch,
 		goto error;
 	branch_str.s=branch_buf;
 	branch_str.len=branch_len;
+	set_hostport(&hp, (Trans->local)?0:(Trans->uas.request));
 	via=via_builder(&via_len, Trans->uac[branch].request.dst.send_sock,
-		&branch_str, 0, Trans->uac[branch].request.dst.proto );
+		&branch_str, 0, Trans->uac[branch].request.dst.proto, &hp );
 	if (!via)
 	{
 		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
 	int len;
 	unsigned int via_len;
 	str branch_str;
+	struct hostport hp;
 
 	if (!t_calc_branch(t, branch, branch_buf, &len)) {
 		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
 	printf("!!!proto: %d\n", sock->proto);
 #endif
 
-	via = via_builder(&via_len, sock, &branch_str, 0, sock->proto);
+	set_hostport(&hp, 0);
+	via = via_builder(&via_len, sock, &branch_str, 0, sock->proto, &hp);
 	if (!via) {
 		LOG(L_ERR, "build_via: via building failed\n");
 		return -2;

+ 86 - 38
msg_translator.c

@@ -52,6 +52,7 @@
  *              references (e.g [::1]) (andrei)
  *             build_req_fomr_sip_req no longer adds 1 for ipv6 via parameter
  *              position calculations ([] are part of host.s now) (andrei)
+ * 2003-10-02  via+lump dst address/port can be set to preset values (andrei)
  *
  */
 /* Via special params:
@@ -142,6 +143,8 @@ extern int version_len;
 
 
 
+
+
 /* checks if ip is in host(name) and ?host(ip)=name?
  * ip must be in network byte order!
  *  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)
 	int new_len;
 	struct lump* t;
 	struct lump* r;
+	str* send_address_str;
+	str* send_port_str;
 
 #define SUBST_LUMP_LEN(subst_l) \
 		switch((subst_l)->u.subst){ \
@@ -559,8 +564,9 @@ static inline int lumps_len(struct sip_msg* msg, struct socket_info* send_sock)
 				break; \
 			case SUBST_SND_IP: \
 				if (send_sock){ \
-					new_len+=send_sock->address_str.len; \
-					if (send_sock->address.af!=AF_INET) \
+					new_len+=send_address_str->len; \
+					if (send_sock->address.af!=AF_INET && \
+							send_address_str==&(send_sock->address_str)) \
 						new_len+=2; \
 				}else{ \
 					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)
 				break; \
 			case SUBST_SND_PORT: \
 				if (send_sock){ \
-					new_len+=send_sock->port_no_str.len; \
+					new_len+=send_port_str->len; \
 				}else{ \
 					LOG(L_CRIT, "FIXME: lumps_len called with" \
 							" null send_sock\n"); \
@@ -598,12 +604,14 @@ static inline int lumps_len(struct sip_msg* msg, struct socket_info* send_sock)
 				break; \
 			case SUBST_SND_ALL: \
 				if (send_sock){ \
-					new_len+=send_sock->address_str.len; \
-					if (send_sock->address.af!=AF_INET) \
+					new_len+=send_address_str->len; \
+					if ((send_sock->address.af!=AF_INET) && \
+							(send_address_str==&(send_sock->address_str))) \
 						new_len+=2; \
-					if (send_sock->port_no!=SIP_PORT){ \
+					if ((send_sock->port_no!=SIP_PORT) || \
+							(send_port_str!=&(send_sock->port_no_str))){ \
 						/* add :port_no */ \
-						new_len+=1+send_sock->port_no_str.len; \
+						new_len+=1+send_port_str->len; \
 					}\
 					/*add;transport=xxx*/ \
 					switch(send_sock->proto){ \
@@ -636,6 +644,16 @@ static inline int lumps_len(struct sip_msg* msg, struct socket_info* send_sock)
 	
 	s_offset=0;
 	new_len=0;
+	/* init send_address_str & send_port_str */
+	if (msg->set_global_address.len)
+		send_address_str=&(msg->set_global_address);
+	else
+		send_address_str=&(send_sock->address_str);
+	if (msg->set_global_port.len)
+		send_port_str=&(msg->set_global_address);
+	else
+		send_port_str=&(send_sock->port_no_str);
+	
 	
 	for(t=msg->add_rm;t;t=t->next){
 		/* 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,
 	int size;
 	int offset;
 	int s_offset;
+	str* send_address_str;
+	str* send_port_str;
 
 #define SUBST_LUMP(subst_l) \
 	switch((subst_l)->u.subst){ \
@@ -825,13 +845,15 @@ static inline void process_lumps(	struct sip_msg* msg,
 			break; \
 		case SUBST_SND_IP: \
 			if (send_sock){  \
-				if (send_sock->address.af!=AF_INET){\
+				if ((send_sock->address.af!=AF_INET) && \
+						(send_address_str==&(send_sock->address_str))){\
 					new_buf[offset]='['; offset++; \
 				}\
-				memcpy(new_buf+offset, send_sock->address_str.s, \
-									send_sock->address_str.len); \
-				offset+=send_sock->address_str.len; \
-				if (send_sock->address.af!=AF_INET){\
+				memcpy(new_buf+offset, send_address_str->s, \
+									send_address_str->len); \
+				offset+=send_address_str->len; \
+				if ((send_sock->address.af!=AF_INET) && \
+						(send_address_str==&(send_sock->address_str))){\
 					new_buf[offset]=']'; offset++; \
 				}\
 			}else{  \
@@ -842,9 +864,9 @@ static inline void process_lumps(	struct sip_msg* msg,
 			break; \
 		case SUBST_SND_PORT: \
 			if (send_sock){  \
-				memcpy(new_buf+offset, send_sock->port_no_str.s, \
-									send_sock->port_no_str.len); \
-				offset+=send_sock->port_no_str.len; \
+				memcpy(new_buf+offset, send_port_str->s, \
+									send_port_str->len); \
+				offset+=send_port_str->len; \
 			}else{  \
 				/*FIXME*/ \
 				LOG(L_CRIT, "FIXME: process_lumps: called with" \
@@ -854,21 +876,24 @@ static inline void process_lumps(	struct sip_msg* msg,
 		case SUBST_SND_ALL: \
 			if (send_sock){  \
 				/* address */ \
-				if (send_sock->address.af!=AF_INET){\
+				if ((send_sock->address.af!=AF_INET) && \
+						(send_address_str==&(send_sock->address_str))){\
 					new_buf[offset]='['; offset++; \
 				}\
-				memcpy(new_buf+offset, send_sock->address_str.s, \
-						send_sock->address_str.len); \
-				offset+=send_sock->address_str.len; \
-				if (send_sock->address.af!=AF_INET){\
+				memcpy(new_buf+offset, send_address_str->s, \
+						send_address_str->len); \
+				offset+=send_address_str->len; \
+				if ((send_sock->address.af!=AF_INET) && \
+						(send_address_str==&(send_sock->address_str))){\
 					new_buf[offset]=']'; offset++; \
 				}\
 				/* :port */ \
-				if (send_sock->port_no!=SIP_PORT){ \
+				if ((send_sock->port_no!=SIP_PORT) || \
+					(send_port_str!=&(send_sock->port_no_str))){ \
 					new_buf[offset]=':'; offset++; \
-					memcpy(new_buf+offset, send_sock->port_no_str.s, \
-							send_sock->port_no_str.len); \
-					offset+=send_sock->port_no_str.len; \
+					memcpy(new_buf+offset, send_port_str->s, \
+							send_port_str->len); \
+					offset+=send_port_str->len; \
 				}\
 				switch(send_sock->proto){ \
 					case PROTO_NONE: \
@@ -970,6 +995,15 @@ static inline void process_lumps(	struct sip_msg* msg,
 	} \
  \
 	
+	/* init send_address_str & send_port_str */
+	if (msg->set_global_address.len)
+		send_address_str=&(msg->set_global_address);
+	else
+		send_address_str=&(send_sock->address_str);
+	if (msg->set_global_port.len)
+		send_port_str=&(msg->set_global_address);
+	else
+		send_port_str=&(send_sock->port_no_str);
 	
 	
 	orig=msg->buf;
@@ -1149,6 +1183,7 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
 	struct lump* via_insert_param;
 	str branch;
 	str extra_params;
+	struct hostport hp;
 	
 #ifdef USE_TCP
 	char* id_buf;
@@ -1221,8 +1256,9 @@ skip_clen:
 #endif
 	branch.s=msg->add_to_branch_s;
 	branch.len=msg->add_to_branch_len;
+	set_hostport(&hp, msg);
 	line_buf = via_builder( &via_len, send_sock, &branch,
-							extra_params.len?&extra_params:0, proto);
+							extra_params.len?&extra_params:0, proto, &hp);
 	if (!line_buf){
 		LOG(L_ERR,"ERROR: build_req_buf_from_sip_req: no via received!\n");
 		goto error00;
@@ -1844,16 +1880,27 @@ int branch_builder( unsigned int hash_index,
 
 char* via_builder( unsigned int *len, 
 	struct socket_info* send_sock,
-	str* branch, str* extra_params, int proto )
+	str* branch, str* extra_params, int proto, struct hostport* hp)
 {
 	unsigned int  via_len, extra_len;
 	char               *line_buf;
 	int max_len;
+	str* address_str; /* address displayed in via */
+	str* port_str; /* port no displayed in via */
+	
+	/* use pre-set address in via or the outbound socket one */
+	if ( hp && hp->host->len)
+		address_str=hp->host;
+	else
+		address_str=&(send_sock->address_str);
+	if (hp && hp->port->len)
+		port_str=hp->port;
+	else
+		port_str=&(send_sock->port_no_str);
 
-
-	max_len=MY_VIA_LEN+send_sock->address_str.len /* space in MY_VIA */
+	max_len=MY_VIA_LEN+address_str->len /* space in MY_VIA */
 		+2 /* just in case it is a v6 address ... [ ] */
-		+1 /*':'*/+send_sock->port_no_str.len
+		+1 /*':'*/+port_str->len
 		+(branch?(MY_BRANCH_LEN+branch->len):0)
 		+(extra_params?extra_params->len:0)
 		+CRLF_LEN+1;
@@ -1866,7 +1913,7 @@ char* via_builder( unsigned int *len,
 
 	extra_len=0;
 
-	via_len=MY_VIA_LEN+send_sock->address_str.len; /*space included in MY_VIA*/
+	via_len=MY_VIA_LEN+address_str->len; /*space included in MY_VIA*/
 
 	memcpy(line_buf, MY_VIA, MY_VIA_LEN); 
 	if (proto==PROTO_UDP){
@@ -1880,20 +1927,21 @@ char* via_builder( unsigned int *len,
 		return 0;
 	}
 #	ifdef USE_IPV6
-	if (send_sock->address.af==AF_INET6) {
+	/* add [] only if ipv6 and outbound socket address is used;
+	 * if using pre-set no check is made */
+	if ((send_sock->address.af==AF_INET6) &&
+		(address_str==&(send_sock->address_str))) {
 		line_buf[MY_VIA_LEN]='[';
-		line_buf[MY_VIA_LEN+1+send_sock->address_str.len]=']';
+		line_buf[MY_VIA_LEN+1+address_str->len]=']';
 		extra_len=1;
 		via_len+=2; /* [ ]*/
 	}
 #	endif
-	memcpy(line_buf+MY_VIA_LEN+extra_len, send_sock->address_str.s,
-		send_sock->address_str.len);
-	if (send_sock->port_no!=SIP_PORT){
+	memcpy(line_buf+MY_VIA_LEN+extra_len, address_str->s, address_str->len);
+	if ((send_sock->port_no!=SIP_PORT) || (port_str!=&send_sock->port_no_str)){
 		line_buf[via_len]=':'; via_len++;
-		memcpy(line_buf+via_len, send_sock->port_no_str.s,
-			 send_sock->port_no_str.len);
-		via_len+=send_sock->port_no_str.len;
+		memcpy(line_buf+via_len, port_str->s, port_str->len);
+		via_len+=port_str->len;
 	}
 
 	/* branch parameter */

+ 20 - 1
msg_translator.h

@@ -55,6 +55,25 @@ struct bookmark {
 	str to_tag_val;
 };
 
+/* used by via_builder */
+struct hostport {
+	str* host;
+	str* port;
+};
+
+
+#define set_hostport(hp, msg) \
+	do{ \
+		if ((msg) && ((struct sip_msg*)(msg))->set_global_address.len) \
+			(hp)->host=&(((struct sip_msg*)(msg))->set_global_address); \
+		else \
+			(hp)->host=&default_global_address; \
+		if ((msg) && ((struct sip_msg*)(msg))->set_global_port.len) \
+			(hp)->port=&(((struct sip_msg*)(msg))->set_global_port); \
+		else \
+			(hp)->port=&default_global_port; \
+	}while(0)
+
 char * build_req_buf_from_sip_req (	struct sip_msg* msg, 
 				unsigned int *returned_len, struct socket_info* send_sock,
 				int proto);
@@ -84,7 +103,7 @@ char * build_res_buf_with_body_from_sip_req(	unsigned int code ,
 */
 char* via_builder( unsigned int *len,
 	struct socket_info* send_sock,
-	str *branch, str* extra_params, int proto );
+	str *branch, str* extra_params, int proto, struct hostport *hp );
 
 
 int branch_builder( unsigned int hash_index, 

+ 2 - 0
parser/msg_parser.h

@@ -228,6 +228,8 @@ struct sip_msg {
 	      * reached 
 	      */
 	flag_t flags;	
+	str set_global_address;
+	str set_global_port;
 };
 
 /* pointer to a fakes message which was never received ;

+ 8 - 1
receive.c

@@ -59,6 +59,12 @@
 #endif
 
 unsigned int msg_no=0;
+/* address preset vars */
+str default_global_address={0,0};
+str default_global_port={0,0};
+str default_via_address={0,0};
+str default_via_port={0,0};
+
 
 
 /* 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)
 	/* buf[len]=0; */ /* WARNING: zero term removed! */
 	msg->rcv=*rcv_info;
 	msg->id=msg_no;
+	msg->set_global_address=default_global_address;
+	msg->set_global_port=default_global_port;
 	
 	if (parse_msg(buf,len, msg)!=0){
 		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)
 #ifdef  STATS
 		gettimeofday( & tvb, &tz );
 #endif
-
 		if (run_actions(rlist[0], msg)<0){
 
 			LOG(L_WARN, "WARNING: receive_msg: "

+ 7 - 0
route_struct.c

@@ -31,6 +31,7 @@
  *  2003-01-29  src_port introduced (jiri)
  *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
  *  2003-04-12  FORCE_RPORT_T added (andrei)
+ *  2003-10-02  added SET_ADV_ADDRESS & SET_ADV_PORT (andrei)
  */
 
 
@@ -317,6 +318,12 @@ void print_action(struct action* a)
 			case FORCE_RPORT_T:
 					DBG("force_rport(");
 					break;
+			case SET_ADV_ADDR_T:
+					DBG("set_advertised_address(");
+					break;
+			case SET_ADV_PORT_T:
+					DBG("set_advertised_port(");
+					break;
 			default:
 					DBG("UNKNOWN(");
 		}

+ 4 - 2
route_struct.h

@@ -66,11 +66,13 @@ enum { FORWARD_T=1, SEND_T, DROP_T, LOG_T, ERROR_T, ROUTE_T, EXEC_T,
 		FORWARD_UDP_T,
 		FORWARD_TLS_T,
 		SEND_TCP_T,
-		FORCE_RPORT_T
+		FORCE_RPORT_T,
+		SET_ADV_ADDR_T,
+		SET_ADV_PORT_T
 };
 enum { NOSUBTYPE=0, STRING_ST, NET_ST, NUMBER_ST, IP_ST, RE_ST, PROXY_ST,
 		EXPR_ST, ACTIONS_ST, CMDF_ST, MODFIXUP_ST, URIHOST_ST, URIPORT_ST,
-		MYSELF_ST };
+		MYSELF_ST, STR_ST };
 
 	
 struct expr{