Browse code

- added force rport (force_rport command in script, FL_FORCE_RPORT flags, msg->msg_flags) - added chroot and wdir in script (to bring it in line with the cmd. line options)

Andrei Pelinescu-Onciul authored on 12/04/2003 19:26:15
Showing 11 changed files
... ...
@@ -2,6 +2,18 @@ $Id$
2 2
 
3 3
 ( - todo, x - done)
4 4
 
5
+release:
6
+- resolver should resolve [ipv6]
7
+- remove parse_uri debugging info
8
+- fix DBG("<%.*s>", len, _null_)
9
+- add -t, -w, -u -g equivalents to the config file
10
+x force add rport : force_rport()
11
+- kill all the fprintf
12
+see also tcp & tm
13
+
14
+
15
+
16
+not so critical:
5 17
 x replace  remaining mallocs/frees at least in msg_translator.c
6 18
 - add $(INCLUDES) to the Makefiles
7 19
 x make ser suncc ready
... ...
@@ -15,15 +27,12 @@ x (different way) add request header bitmap field for the modules
15 15
 - introduce variables & function in the script language (cfg. file)
16 16
 - ? variable number of params functions in script (no longer limited to 2)?
17 17
 - kill bind_idx
18
-- fix bind_address for tcp (in some  way)
18
+x fix bind_address for tcp (in some  way)
19 19
 - add conflict in debs/rpms/etc (conflict w/ older ser-mysql, ser-jabber)
20 20
 - new packages ser-radius etc
21 21
 - tcp_destroy (called on ser exit)
22 22
 - BUG:?? ipv6 only and try to send to ipv4 => getsendsocket=>0 (send_ipv6=0)
23 23
   the reverse is also true
24
-- resolver should resolve [ipv6]
25
-- remove parse_uri debugging info
26
-- fix DBG("<%.*s>", len, _null_)
27 24
 
28 25
 
29 26
 High priority:
... ...
@@ -47,7 +56,6 @@ x forward to received= if present
47 47
 - make it easier to register a statically linkable module.
48 48
 x add support for -u user and -g group (not only -u uid, -g uid)
49 49
 - change uid/gid after opening the sockets
50
-- add -t, -w, -u -g equivalents to the config file
51 50
 - exec improvments (add format strings to it)
52 51
 - command line switch for checking the config file syntax
53 52
 - config file version (a la sendmail)
... ...
@@ -79,8 +87,6 @@ x freopen stdin, stdout, stderr to /dev/null
79 79
 x add src_port, dst_port, proto to cfg.{y,lex}
80 80
 x generic locking lib
81 81
 x convert tm to use new locking lib
82
-- force add rport (setflag(rport)???)
83
-- kill all the fprintf
84 82
 
85 83
 optimizations:
86 84
 - better timer interface with hashes (a la openbsd)
... ...
@@ -26,12 +26,13 @@
26 26
  *
27 27
  * History:
28 28
  * ---------
29
- * 2003-02-28  scratchpad compatibility abandoned (jiri)
30
- * 2003-01-29  removed scratchpad (jiri)
31
- * 2003-03-19  fixed set* len calculation bug & simplified a little the code
29
+ *  2003-02-28  scratchpad compatibility abandoned (jiri)
30
+ *  2003-01-29  removed scratchpad (jiri)
31
+ *  2003-03-19  fixed set* len calculation bug & simplified a little the code
32 32
  *              (should be a little faster now) (andrei)
33
- *             replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
34
- * 2003-04-01  Added support for loose routing in forward (janakj)
33
+ *              replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
34
+ *  2003-04-01  Added support for loose routing in forward (janakj)
35
+ *  2003-04-12  FORCE_RPORT_T added (andrei)
35 36
  */
36 37
 
37 38
 
... ...
@@ -569,6 +570,10 @@ int do_action(struct action* a, struct sip_msg* msg)
569 569
 				LOG(L_CRIT,"BUG: do_action: bad module call\n");
570 570
 			}
571 571
 			break;
572
+		case FORCE_RPORT_T:
573
+			msg->msg_flags|=FL_FORCE_RPORT;
574
+			ret=1; /* continue processing */
575
+			break;
572 576
 		default:
573 577
 			LOG(L_CRIT, "BUG: do_action: unknown type %d\n", a->type);
574 578
 	}
... ...
@@ -33,6 +33,7 @@
33 33
  *  2003-03-19  replaced all the mallocs/frees w/ pkg_malloc/pkg_free (andrei)
34 34
  *  2003-04-01  added dst_port, proto (tcp, udp, tls), af(inet, inet6) (andrei)
35 35
  *  2003-04-05  s/reply_route/failure_route, onreply_route introduced (jiri)
36
+ *  2003-04-12  added force_rport, chdir and wdir (andrei)
36 37
  */
37 38
 
38 39
 
... ...
@@ -82,6 +83,7 @@ ROUTE	route
82 82
 ROUTE_FAILURE failure_route
83 83
 ROUTE_ONREPLY onreply_route
84 84
 EXEC	exec
85
+FORCE_RPORT		"force_rport"|"add_rport"
85 86
 SETFLAG		setflag
86 87
 RESETFLAG	resetflag
87 88
 ISFLAGSET	isflagset
... ...
@@ -150,6 +152,8 @@ SERVER_SIGNATURE server_signature
150 150
 REPLY_TO_VIA reply_to_via
151 151
 USER		"user"|"uid"
152 152
 GROUP		"group"|"gid"
153
+CHROOT		"chroot"
154
+WDIR		"workdir"|"wdir"
153 155
 MHOMED		mhomed
154 156
 
155 157
 LOADMODULE	loadmodule
... ...
@@ -226,7 +230,10 @@ EAT_ABLE	[\ \t\b\r]
226 226
 <INITIAL>{REVERT_URI}	{ count(); yylval.strval=yytext; return REVERT_URI; }
227 227
 <INITIAL>{PREFIX}	{ count(); yylval.strval=yytext; return PREFIX; }
228 228
 <INITIAL>{STRIP}	{ count(); yylval.strval=yytext; return STRIP; }
229
-<INITIAL>{APPEND_BRANCH}	{ count(); yylval.strval=yytext; return APPEND_BRANCH; }
229
+<INITIAL>{APPEND_BRANCH}	{ count(); yylval.strval=yytext; 
230
+								return APPEND_BRANCH; }
231
+<INITIAL>{FORCE_RPORT}	{ count(); yylval.strval=yytext; return FORCE_RPORT; }
232
+	
230 233
 <INITIAL>{IF}	{ count(); yylval.strval=yytext; return IF; }
231 234
 <INITIAL>{ELSE}	{ count(); yylval.strval=yytext; return ELSE; }
232 235
 
... ...
@@ -262,6 +269,8 @@ EAT_ABLE	[\ \t\b\r]
262 262
 <INITIAL>{SIP_WARNING}	{ count(); yylval.strval=yytext; return SIP_WARNING; }
263 263
 <INITIAL>{USER}		{ count(); yylval.strval=yytext; return USER; }
264 264
 <INITIAL>{GROUP}	{ count(); yylval.strval=yytext; return GROUP; }
265
+<INITIAL>{CHROOT}	{ count(); yylval.strval=yytext; return CHROOT; }
266
+<INITIAL>{WDIR}	{ count(); yylval.strval=yytext; return WDIR; }
265 267
 <INITIAL>{MHOMED}	{ count(); yylval.strval=yytext; return MHOMED; }
266 268
 <INITIAL>{FIFO}	{ count(); yylval.strval=yytext; return FIFO; }
267 269
 <INITIAL>{FIFO_MODE}	{ count(); yylval.strval=yytext; return FIFO_MODE; }
... ...
@@ -36,6 +36,7 @@
36 36
  * 2003-03-20  Regex support in modparam (janakj)
37 37
  * 2003-04-01  added dst_port, proto , af (andrei)
38 38
  * 2003-04-05  s/reply_route/failure_route, onreply_route introduced (jiri)
39
+ * 2003-04-12  added force_rport, chroot and wdir (andrei)
39 40
  */
40 41
 
41 42
 
... ...
@@ -120,6 +121,7 @@ int rt;  /* Type of route block for find_export */
120 120
 %token SET_PORT
121 121
 %token SET_URI
122 122
 %token REVERT_URI
123
+%token FORCE_RPORT
123 124
 %token IF
124 125
 %token ELSE
125 126
 %token URIHOST
... ...
@@ -163,6 +165,8 @@ int rt;  /* Type of route block for find_export */
163 163
 %token MAXBUFFER
164 164
 %token USER
165 165
 %token GROUP
166
+%token CHROOT
167
+%token WDIR
166 168
 %token MHOMED
167 169
 
168 170
 
... ...
@@ -332,6 +336,12 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
332 332
 		| GROUP EQUAL STRING     { group=$3; }
333 333
 		| GROUP EQUAL ID         { group=$3; }
334 334
 		| GROUP EQUAL error      { yyerror("string value expected"); }
335
+		| CHROOT EQUAL STRING     { chroot_dir=$3; }
336
+		| CHROOT EQUAL ID         { chroot_dir=$3; }
337
+		| CHROOT EQUAL error      { yyerror("string value expected"); }
338
+		| WDIR EQUAL STRING     { working_dir=$3; }
339
+		| WDIR EQUAL ID         { working_dir=$3; }
340
+		| WDIR EQUAL error      { yyerror("string value expected"); }
335 341
 		| MHOMED EQUAL NUMBER { mhomed=$3; }
336 342
 		| MHOMED EQUAL error { yyerror("boolean value expected"); }
337 343
 		| SERVER_SIGNATURE EQUAL NUMBER { server_signature=$3; }
... ...
@@ -1063,6 +1073,8 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
1063 1063
 										"string expected"); }
1064 1064
 		| REVERT_URI LPAREN RPAREN { $$=mk_action( REVERT_URI_T, 0,0,0,0); }
1065 1065
 		| REVERT_URI { $$=mk_action( REVERT_URI_T, 0,0,0,0); }
1066
+		| FORCE_RPORT LPAREN RPAREN	{$$=mk_action(FORCE_RPORT_T,0, 0, 0, 0); }
1067
+		| FORCE_RPORT				{$$=mk_action(FORCE_RPORT_T,0, 0, 0, 0); }
1066 1068
 		| ID LPAREN RPAREN			{ f_tmp=(void*)find_export($1, 0, rt);
1067 1069
 									   if (f_tmp==0){
1068 1070
 										   if (find_export($1, 0, 0)) {
... ...
@@ -39,6 +39,8 @@
39 39
  *  2003-04-03  added su_setport (andrei)
40 40
  *  2003-04-04  update_sock_struct_from_via now differentiates between
41 41
  *               local replies  & "normal" replies (andrei)
42
+ *  2003-04-12  update_sock_struct_form via uses also FL_FORCE_RPORT for
43
+ *               local replies (andrei)
42 44
  */
43 45
 
44 46
 
... ...
@@ -366,7 +368,8 @@ int update_sock_struct_from_via( union sockaddr_union* to,
366 366
 		/* _local_ reply, we ignore any rport or received value
367 367
 		 * (but we will send back to the original port if rport is
368 368
 		 *  present) */
369
-		if (via->rport) port=msg->rcv.src_port;
369
+		if ((msg->msg_flags&FL_FORCE_RPORT)||(via->rport))
370
+			port=msg->rcv.src_port;
370 371
 		else port=via->port;
371 372
 		name=&(via->host); /* received=ip in 1st via is ignored (it's
372 373
 							  not added by us so it's bad) */
... ...
@@ -27,10 +27,11 @@
27 27
 /*
28 28
  * History:
29 29
  * -------
30
- * 2001-??-?? created by andrei
31
- * ????-??-?? lots of changes by a lot of people
32
- * 2003-02-11 added inline msg_send (andrei)
33
- * 2003-04-07 changed all ports to host byte order (andrei)
30
+ *  2001-??-?? created by andrei
31
+ *  ????-??-?? lots of changes by a lot of people
32
+ *  2003-02-11 added inline msg_send (andrei)
33
+ *  2003-04-07 changed all ports to host byte order (andrei)
34
+ *  2003-04-12  FORCE_RPORT_T added (andrei)
34 35
  */
35 36
 
36 37
 
... ...
@@ -61,8 +62,9 @@ int update_sock_struct_from_via( union sockaddr_union* to,
61 61
 /* use src_ip, port=src_port if rport, via port if via port, 5060 otherwise */
62 62
 #define update_sock_struct_from_ip(  to, msg ) \
63 63
 	init_su((to), &(msg)->rcv.src_ip, \
64
-			((msg)->via1->rport)?(msg)->rcv.src_port: \
65
-			((msg)->via1->port)?(msg)->via1->port: SIP_PORT )
64
+			(((msg)->via1->rport)||((msg)->msg_flags&&FL_FORCE_RPORT))? \
65
+							(msg)->rcv.src_port: \
66
+							((msg)->via1->port)?(msg)->via1->port: SIP_PORT )
66 67
 
67 68
 int forward_reply( struct sip_msg* msg);
68 69
 
... ...
@@ -77,6 +77,9 @@ extern int sip_warning;
77 77
 extern int server_signature;
78 78
 extern char* user;
79 79
 extern char* group;
80
+extern char* chroot_dir;
81
+extern char* working_dir;
82
+
80 83
 /*
81 84
  * debug & log_stderr moved to dprint.h*/
82 85
 
... ...
@@ -46,10 +46,58 @@
46 46
  * 2003-04-01  added opt (conditional) lump support (andrei)
47 47
  * 2003-04-02  added more subst lumps: SUBST_{SND,RCV}_ALL  
48 48
  *              => ip:port;transport=proto (andrei)
49
+ * 2003-04-12  added FL_FORCE_RPORT support (andrei)
49 50
  *
50 51
  */
51
-
52
-
52
+/* Via special params:
53
+ * requests:
54
+ * - if the address in via is different from the src_ip or an existing
55
+ *   received=something is found, received=src_ip is added (and any preexisting
56
+ *   received is deleted). received is added as the first via parameter if no
57
+ *   receive is previoulsy present or over the old receive.
58
+ * - if the original via contains rport / rport=something or msg->msg_flags
59
+ *   FL_FORCE_RPORT is set (e.g. script force_rport() cmd) rport=src_port
60
+ *   is added (over previous rport / as first via param or after received
61
+ *   if no received was present and received is added too)
62
+ * local replies:
63
+ *    (see also sl_send_reply)
64
+ *  - rport and received are added in mostly the same way as for requests, but 
65
+ *    in the reverse order (first rport and then received). See also 
66
+ *    limitations.
67
+ *  - if reply_to_via is set (default off) the local reply will be sent to
68
+ *    the address in via (received is ignored since it was not set by us). The
69
+ *    destination port is either the message source port if via contains rport
70
+ *    or the FL_FORCE_RPORT flag is set or the port from the via. If either
71
+ *    port or rport are present a normal dns lookup (instead of a srv lookup)
72
+ *    is performed on the address. If no port is present and a srv lookup is 
73
+ *    performed the port is taken from the srv lookup. If the srv lookup failed
74
+ *    or it was not performed, the port is set to the default sip port (5060).
75
+ *  - if reply_to_via is off (default) the local reply is ent to the message
76
+ *    source ip address. The destination port is set to the source port if 
77
+ *    rport is present or FL_FORCE_RPORT flag is set, to the via port or to
78
+ *    the default sip port (5060) if neither rport or via port are present.
79
+ * "normal" replies:
80
+ *  - if received is present the message is sent to the received address else
81
+ *    if no port is present (neither a normal via port or rport) a dns srv 
82
+ *    lookup is performed on the host part and the reply is sent to the 
83
+ *    resulting ip. If a port is present or the host part is an ip address 
84
+ *    the dns lookup will be a "normal" one (A or AAAA).
85
+ *  - if rport is present, it's value will be used as the destination port
86
+ *   (and this will also disable srv lookups)
87
+ *  - if no port is present the destination port will be taken from the srv
88
+ *    lookup. If the srv lookup fails or is not performed (e.g. ip address
89
+ *    in host) the destination port will be set to the default sip port (5060).
90
+ *  
91
+ * Known limitations:
92
+ * - when locally replying to a message, rport and received will be appended to
93
+ *   the via header parameters (for forwarded requests they are inserted at the
94
+ *   beginning).
95
+ * - a locally generated reply might get two received via parameters if a
96
+ *   received is already present in the original message (this should not
97
+ *   happen though, but ...)
98
+ *
99
+ *--andrei
100
+*/
53 101
 
54 102
 #include <sys/types.h>
55 103
 #include <sys/socket.h>
... ...
@@ -1093,7 +1141,7 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
1093 1093
 	char* buf;
1094 1094
 	unsigned int offset, s_offset, size;
1095 1095
 	struct lump* anchor;
1096
-	int r;
1096
+	struct lump* via_insert_param;
1097 1097
 	str branch;
1098 1098
 	str extra_params;
1099 1099
 	
... ...
@@ -1109,6 +1157,7 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
1109 1109
 	clen_buf=0;
1110 1110
 	clen_len=0;
1111 1111
 #endif
1112
+	via_insert_param=0;
1112 1113
 	extra_params.len=0;
1113 1114
 	extra_params.s=0;
1114 1115
 	uri_len=0;
... ...
@@ -1161,9 +1210,9 @@ skip_clen:
1161 1161
 		goto error00;
1162 1162
 	}
1163 1163
 	/* check if received needs to be added */
1164
-	r=check_via_address(&msg->rcv.src_ip, &msg->via1->host, 
1165
-		msg->via1->port, received_dns);
1166
-	if (r!=0){
1164
+	if ( msg->via1->received || 
1165
+			check_via_address(&msg->rcv.src_ip, &msg->via1->host, 
1166
+									msg->via1->port, received_dns) ){
1167 1167
 		if ((received_buf=received_builder(msg,&received_len))==0){
1168 1168
 			LOG(L_ERR, "ERROR: build_req_buf_from_sip_req:"
1169 1169
 							" received_builder failed\n");
... ...
@@ -1171,8 +1220,13 @@ skip_clen:
1171 1171
 		}
1172 1172
 	}
1173 1173
 	
1174
-	/* check if rport needs to be updated */
1175
-	if (msg->via1->rport && msg->via1->rport->value.s==0){
1174
+	/* check if rport needs to be updated:
1175
+	 *  - if FL_FORCE_RPORT is set add it (and del. any previous version)
1176
+	 *  - if via already contains an rport add it and overwrite the previous
1177
+	 *  rport value if present (if you don't want to overwrite the previous
1178
+	 *  version remove the comments) */
1179
+	if ((msg->msg_flags&FL_FORCE_RPORT)||
1180
+			(msg->via1->rport /*&& msg->via1->rport->value.s==0*/)){
1176 1181
 		if ((rport_buf=rport_builder(msg, &rport_len))==0){
1177 1182
 			LOG(L_ERR, "ERROR: build_req_buf_from_sip_req:"
1178 1183
 							" rport_builder failed\n");
... ...
@@ -1187,34 +1241,52 @@ skip_clen:
1187 1187
 	if (anchor==0) goto error01;
1188 1188
 	if (insert_new_lump_before(anchor, line_buf, via_len, HDR_VIA)==0)
1189 1189
 		goto error01;
1190
-	/* if received needs to be added, add anchor after host and add it */
1190
+	/* find out where the offset of the first parameter that should be added
1191
+	 * (after host:port), needed by add receive & maybe rport */
1192
+	if (msg->via1->params.s){
1193
+			size= msg->via1->params.s-msg->via1->hdr.s-1; /*compensate
1194
+														  for ';' */
1195
+	}else{
1196
+			size= msg->via1->host.s-msg->via1->hdr.s+msg->via1->host.len;
1197
+			if (msg->via1->port!=0){
1198
+				/*size+=strlen(msg->via1->hdr.s+size+1)+1;*/
1199
+				size += msg->via1->port_str.len + 1; /* +1 for ':'*/
1200
+			}
1201
+		#ifdef USE_IPV6
1202
+			if(send_sock->address.af==AF_INET6) size+=1; /* +1 for ']'*/
1203
+		#endif
1204
+	}
1205
+	/* if received needs to be added, add anchor after host and add it, or 
1206
+	 * overwrite the previous one if already present */
1191 1207
 	if (received_len){
1192
-		if (msg->via1->params.s){
1193
-				size= msg->via1->params.s-msg->via1->hdr.s-1; /*compensate
1194
-															  for ';' */
1195
-		}else{
1196
-				size= msg->via1->host.s-msg->via1->hdr.s+msg->via1->host.len;
1197
-				if (msg->via1->port!=0){
1198
-					/*size+=strlen(msg->via1->hdr.s+size+1)+1;*/
1199
-					size += msg->via1->port_str.len + 1; /* +1 for ':'*/
1200
-				}
1201
-			#ifdef USE_IPV6
1202
-				if(send_sock->address.af==AF_INET6) size+=1; /* +1 for ']'*/
1203
-			#endif
1208
+		if (msg->via1->received){ /* received already present => overwrite it*/
1209
+			via_insert_param=del_lump(&(msg->add_rm),
1210
+								msg->via1->received->start-buf-1, /*;*/
1211
+								msg->via1->received->size+1, /*;*/ HDR_VIA);
1212
+		}else if (via_insert_param==0){ /* receive not present, ok */
1213
+			via_insert_param=anchor_lump(&(msg->add_rm),
1214
+										msg->via1->hdr.s-buf+size,0, HDR_VIA);
1204 1215
 		}
1205
-		anchor=anchor_lump(&(msg->add_rm),msg->via1->hdr.s-buf+size,0,
1206
-				HDR_VIA);
1207
-		if (anchor==0) goto error02; /* free received_buf */
1208
-		if (insert_new_lump_after(anchor, received_buf, received_len, HDR_VIA)
1209
-				==0 ) goto error02; /* free received_buf */
1216
+		if (via_insert_param==0) goto error02; /* free received_buf */
1217
+		if (insert_new_lump_after(via_insert_param, received_buf, received_len,
1218
+					HDR_VIA) ==0 ) goto error02; /* free received_buf */
1210 1219
 	}
1211
-	/* if rport needs to be updated, delete it and add it's value */
1220
+	/* if rport needs to be updated, delete it if present and add it's value */
1212 1221
 	if (rport_len){
1213
-		anchor=del_lump(&(msg->add_rm), msg->via1->rport->start-buf-1, /*';'*/
1214
-							msg->via1->rport->size+1 /* ; */, HDR_VIA);
1215
-		if (anchor==0) goto error03; /* free rport_buf*/
1216
-		if (insert_new_lump_after(anchor, rport_buf, rport_len, HDR_VIA)==0)
1217
-			goto error03; /* free rport_buf*/
1222
+		if (msg->via1->rport){ /* rport already present */
1223
+			via_insert_param=del_lump(&(msg->add_rm),
1224
+								msg->via1->rport->start-buf-1, /*';'*/
1225
+								msg->via1->rport->size+1 /* ; */, HDR_VIA);
1226
+		}else if (via_insert_param==0){ /*force rport, no rport present */
1227
+			/* no rport, add it */
1228
+			via_insert_param=anchor_lump(&(msg->add_rm),
1229
+										msg->via1->hdr.s-buf+size,0, HDR_VIA);
1230
+		}
1231
+		if (via_insert_param==0) goto error03; /* free rport_buf */
1232
+		if (insert_new_lump_after(via_insert_param, rport_buf, rport_len,
1233
+									HDR_VIA) ==0 )
1234
+			goto error03; /* free rport_buf */
1235
+			
1218 1236
 	}
1219 1237
 #ifdef USE_TCP
1220 1238
 	/* if clen needs to be added, add it */
... ...
@@ -1437,7 +1509,6 @@ char * build_res_buf_with_body_from_sip_req( unsigned int code, char *text ,
1437 1437
 	char              *warning;
1438 1438
 	unsigned int      warning_len;
1439 1439
 	unsigned int	  text_len;
1440
-	int  r;
1441 1440
 	int  content_len_len;
1442 1441
 	char *content_len;
1443 1442
 	char content_len_buf[MAX_CONTENT_LEN_BUF];
... ...
@@ -1470,10 +1541,10 @@ char * build_res_buf_with_body_from_sip_req( unsigned int code, char *text ,
1470 1470
 	/* check if received needs to be added */
1471 1471
 	backup = msg->via1->host.s[msg->via1->host.len];
1472 1472
 	msg->via1->host.s[msg->via1->host.len] = 0;
1473
-	r=check_via_address(&msg->rcv.src_ip, &msg->via1->host, 
1474
-		msg->via1->port, received_dns);
1473
+	if (msg->via1->received || 
1474
+			check_via_address(&msg->rcv.src_ip, &msg->via1->host, 
1475
+								msg->via1->port, received_dns)) {
1475 1476
 	msg->via1->host.s[msg->via1->host.len] = backup;
1476
-	if (r!=0) {
1477 1477
 		if ((received_buf=received_builder(msg,&received_len))==0) {
1478 1478
 			LOG(L_ERR, "ERROR: build_res_buf_from_sip_req: "
1479 1479
 				"alas, received_builder failed\n");
... ...
@@ -1481,13 +1552,15 @@ char * build_res_buf_with_body_from_sip_req( unsigned int code, char *text ,
1481 1481
 		}
1482 1482
 	}
1483 1483
 	/* check if rport needs to be updated */
1484
-	if (msg->via1->rport && msg->via1->rport->value.s==0){
1484
+	if ( (msg->msg_flags&FL_FORCE_RPORT)||
1485
+		(msg->via1->rport /*&& msg->via1->rport->value.s==0*/)){
1485 1486
 		if ((rport_buf=rport_builder(msg, &rport_len))==0){
1486 1487
 			LOG(L_ERR, "ERROR: build_res_buf_from_sip_req:"
1487 1488
 							" rport_builder failed\n");
1488 1489
 			goto error01; /* free everything */
1489 1490
 		}
1490
-		delete_len=msg->via1->rport->size+1; /* include ';' */
1491
+		if (msg->via1->rport) 
1492
+			delete_len=msg->via1->rport->size+1; /* include ';' */
1491 1493
 	}
1492 1494
 
1493 1495
 	/*computes the lenght of the new response buffer*/
... ...
@@ -1587,17 +1660,24 @@ char * build_res_buf_with_body_from_sip_req( unsigned int code, char *text ,
1587 1587
 			case HDR_VIA:
1588 1588
 				if (hdr==msg->h_via1){
1589 1589
 					if (rport_buf){
1590
-						/* copy until rport */
1591
-						append_str_trans( p, hdr->name.s ,
1592
-							msg->via1->rport->start-hdr->name.s-1,msg);
1593
-						/* copy new rport */
1594
-						append_str(p, rport_buf, rport_len);
1595
-						/* copy the rest of the via */
1596
-						append_str_trans(p, msg->via1->rport->start+
1597
-											msg->via1->rport->size, 
1598
-											hdr->body.s+hdr->body.len-
1599
-											msg->via1->rport->start-
1600
-											msg->via1->rport->size, msg);
1590
+						if (msg->via1->rport){ /* delete the old one */
1591
+							/* copy until rport */
1592
+							append_str_trans( p, hdr->name.s ,
1593
+								msg->via1->rport->start-hdr->name.s-1,msg);
1594
+							/* copy new rport */
1595
+							append_str(p, rport_buf, rport_len);
1596
+							/* copy the rest of the via */
1597
+							append_str_trans(p, msg->via1->rport->start+
1598
+												msg->via1->rport->size, 
1599
+												hdr->body.s+hdr->body.len-
1600
+												msg->via1->rport->start-
1601
+												msg->via1->rport->size, msg);
1602
+						}else{ /* just append the new one */
1603
+							/* normal whole via copy */
1604
+							append_str_trans( p, hdr->name.s , 
1605
+								(hdr->body.s+hdr->body.len)-hdr->name.s, msg);
1606
+							append_str(p, rport_buf, rport_len);
1607
+						}
1601 1608
 					}else{
1602 1609
 						/* normal whole via copy */
1603 1610
 						append_str_trans( p, hdr->name.s , 
... ...
@@ -34,6 +34,7 @@
34 34
  *  2003-04-01  2 macros added: GET_NEXT_HOP and GET_RURI (janakj)
35 35
  *  2003-04-04  structure for parsed inbound uri added (jiri)
36 36
  *  2003-04-11  updated the  sip_uri structure (lots of fields added) (andrei)
37
+ *  2003-04-12  added msg_flags to sip_msg (andrei)
37 38
  */
38 39
 
39 40
 
... ...
@@ -65,6 +66,8 @@
65 65
 enum request_method { METHOD_UNDEF=0, METHOD_INVITE=1, METHOD_CANCEL=2, METHOD_ACK=4, 
66 66
 	METHOD_BYE=8, METHOD_OTHER=16 };
67 67
 
68
+#define FL_FORCE_RPORT 1 /* force rport */
69
+
68 70
 
69 71
 #define IFISMETHOD(methodname,firstchar)                                  \
70 72
 if (  (*tmp==(firstchar) || *tmp==((firstchar) | 32)) &&                  \
... ...
@@ -207,7 +210,7 @@ struct sip_msg {
207 207
 	
208 208
 	     /* index to TM hash table; stored in core to avoid unnecessary calcs */
209 209
 	unsigned int  hash_index;
210
-	
210
+	unsigned int msg_flags; /* flags used by core */
211 211
 	     /* allows to set various flags on the message; may be used for 
212 212
 	      *	simple inter-module communication or remembering processing state
213 213
 	      * reached 
... ...
@@ -30,6 +30,7 @@
30 30
  * --------
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
+ *  2003-04-12  FORCE_RPORT_T added (andrei)
33 34
  */
34 35
 
35 36
 
... ...
@@ -313,6 +314,9 @@ void print_action(struct action* a)
313 313
 			case MODULE_T:
314 314
 					DBG(" external_module_call(");
315 315
 					break;
316
+			case FORCE_RPORT_T:
317
+					DBG("force_rport(");
318
+					break;
316 319
 			default:
317 320
 					DBG("UNKNOWN(");
318 321
 		}
... ...
@@ -25,6 +25,11 @@
25 25
  * along with this program; if not, write to the Free Software 
26 26
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27 27
  */
28
+/* History:
29
+ * --------
30
+ *
31
+ *  2003-04-12  FORCE_RPORT_T added (andrei)
32
+ */
28 33
 
29 34
 
30 35
 #ifndef route_struct_h
... ...
@@ -58,7 +63,9 @@ enum { FORWARD_T=1, SEND_T, DROP_T, LOG_T, ERROR_T, ROUTE_T, EXEC_T,
58 58
 		REVERT_URI_T,
59 59
 		FORWARD_TCP_T,
60 60
 		FORWARD_UDP_T,
61
-		SEND_TCP_T};
61
+		SEND_TCP_T,
62
+		FORCE_RPORT_T
63
+};
62 64
 enum { NOSUBTYPE=0, STRING_ST, NET_ST, NUMBER_ST, IP_ST, RE_ST, PROXY_ST,
63 65
 		EXPR_ST, ACTIONS_ST, CMDF_ST, MODFIXUP_ST, URIHOST_ST, URIPORT_ST,
64 66
 		MYSELF_ST };