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 27
 - introduce variables & function in the script language (cfg. file)
16 28
 - ? variable number of params functions in script (no longer limited to 2)?
17 29
 - kill bind_idx
18
-- fix bind_address for tcp (in some  way)
30
+x fix bind_address for tcp (in some  way)
19 31
 - add conflict in debs/rpms/etc (conflict w/ older ser-mysql, ser-jabber)
20 32
 - new packages ser-radius etc
21 33
 - tcp_destroy (called on ser exit)
22 34
 - BUG:?? ipv6 only and try to send to ipv4 => getsendsocket=>0 (send_ipv6=0)
23 35
   the reverse is also true
24
-- resolver should resolve [ipv6]
25
-- remove parse_uri debugging info
26
-- fix DBG("<%.*s>", len, _null_)
27 36
 
28 37
 
29 38
 High priority:
... ...
@@ -47,7 +56,6 @@ x forward to received= if present
47 56
 - make it easier to register a statically linkable module.
48 57
 x add support for -u user and -g group (not only -u uid, -g uid)
49 58
 - change uid/gid after opening the sockets
50
-- add -t, -w, -u -g equivalents to the config file
51 59
 - exec improvments (add format strings to it)
52 60
 - command line switch for checking the config file syntax
53 61
 - config file version (a la sendmail)
... ...
@@ -79,8 +87,6 @@ x freopen stdin, stdout, stderr to /dev/null
79 87
 x add src_port, dst_port, proto to cfg.{y,lex}
80 88
 x generic locking lib
81 89
 x convert tm to use new locking lib
82
-- force add rport (setflag(rport)???)
83
-- kill all the fprintf
84 90
 
85 91
 optimizations:
86 92
 - 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 570
 				LOG(L_CRIT,"BUG: do_action: bad module call\n");
570 571
 			}
571 572
 			break;
573
+		case FORCE_RPORT_T:
574
+			msg->msg_flags|=FL_FORCE_RPORT;
575
+			ret=1; /* continue processing */
576
+			break;
572 577
 		default:
573 578
 			LOG(L_CRIT, "BUG: do_action: unknown type %d\n", a->type);
574 579
 	}
... ...
@@ -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 83
 ROUTE_FAILURE failure_route
83 84
 ROUTE_ONREPLY onreply_route
84 85
 EXEC	exec
86
+FORCE_RPORT		"force_rport"|"add_rport"
85 87
 SETFLAG		setflag
86 88
 RESETFLAG	resetflag
87 89
 ISFLAGSET	isflagset
... ...
@@ -150,6 +152,8 @@ SERVER_SIGNATURE server_signature
150 152
 REPLY_TO_VIA reply_to_via
151 153
 USER		"user"|"uid"
152 154
 GROUP		"group"|"gid"
155
+CHROOT		"chroot"
156
+WDIR		"workdir"|"wdir"
153 157
 MHOMED		mhomed
154 158
 
155 159
 LOADMODULE	loadmodule
... ...
@@ -226,7 +230,10 @@ EAT_ABLE	[\ \t\b\r]
226 230
 <INITIAL>{REVERT_URI}	{ count(); yylval.strval=yytext; return REVERT_URI; }
227 231
 <INITIAL>{PREFIX}	{ count(); yylval.strval=yytext; return PREFIX; }
228 232
 <INITIAL>{STRIP}	{ count(); yylval.strval=yytext; return STRIP; }
229
-<INITIAL>{APPEND_BRANCH}	{ count(); yylval.strval=yytext; return APPEND_BRANCH; }
233
+<INITIAL>{APPEND_BRANCH}	{ count(); yylval.strval=yytext; 
234
+								return APPEND_BRANCH; }
235
+<INITIAL>{FORCE_RPORT}	{ count(); yylval.strval=yytext; return FORCE_RPORT; }
236
+	
230 237
 <INITIAL>{IF}	{ count(); yylval.strval=yytext; return IF; }
231 238
 <INITIAL>{ELSE}	{ count(); yylval.strval=yytext; return ELSE; }
232 239
 
... ...
@@ -262,6 +269,8 @@ EAT_ABLE	[\ \t\b\r]
262 269
 <INITIAL>{SIP_WARNING}	{ count(); yylval.strval=yytext; return SIP_WARNING; }
263 270
 <INITIAL>{USER}		{ count(); yylval.strval=yytext; return USER; }
264 271
 <INITIAL>{GROUP}	{ count(); yylval.strval=yytext; return GROUP; }
272
+<INITIAL>{CHROOT}	{ count(); yylval.strval=yytext; return CHROOT; }
273
+<INITIAL>{WDIR}	{ count(); yylval.strval=yytext; return WDIR; }
265 274
 <INITIAL>{MHOMED}	{ count(); yylval.strval=yytext; return MHOMED; }
266 275
 <INITIAL>{FIFO}	{ count(); yylval.strval=yytext; return FIFO; }
267 276
 <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 121
 %token SET_PORT
121 122
 %token SET_URI
122 123
 %token REVERT_URI
124
+%token FORCE_RPORT
123 125
 %token IF
124 126
 %token ELSE
125 127
 %token URIHOST
... ...
@@ -163,6 +165,8 @@ int rt;  /* Type of route block for find_export */
163 165
 %token MAXBUFFER
164 166
 %token USER
165 167
 %token GROUP
168
+%token CHROOT
169
+%token WDIR
166 170
 %token MHOMED
167 171
 
168 172
 
... ...
@@ -332,6 +336,12 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
332 336
 		| GROUP EQUAL STRING     { group=$3; }
333 337
 		| GROUP EQUAL ID         { group=$3; }
334 338
 		| GROUP EQUAL error      { yyerror("string value expected"); }
339
+		| CHROOT EQUAL STRING     { chroot_dir=$3; }
340
+		| CHROOT EQUAL ID         { chroot_dir=$3; }
341
+		| CHROOT EQUAL error      { yyerror("string value expected"); }
342
+		| WDIR EQUAL STRING     { working_dir=$3; }
343
+		| WDIR EQUAL ID         { working_dir=$3; }
344
+		| WDIR EQUAL error      { yyerror("string value expected"); }
335 345
 		| MHOMED EQUAL NUMBER { mhomed=$3; }
336 346
 		| MHOMED EQUAL error { yyerror("boolean value expected"); }
337 347
 		| SERVER_SIGNATURE EQUAL NUMBER { server_signature=$3; }
... ...
@@ -1063,6 +1073,8 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
1063 1073
 										"string expected"); }
1064 1074
 		| REVERT_URI LPAREN RPAREN { $$=mk_action( REVERT_URI_T, 0,0,0,0); }
1065 1075
 		| REVERT_URI { $$=mk_action( REVERT_URI_T, 0,0,0,0); }
1076
+		| FORCE_RPORT LPAREN RPAREN	{$$=mk_action(FORCE_RPORT_T,0, 0, 0, 0); }
1077
+		| FORCE_RPORT				{$$=mk_action(FORCE_RPORT_T,0, 0, 0, 0); }
1066 1078
 		| ID LPAREN RPAREN			{ f_tmp=(void*)find_export($1, 0, rt);
1067 1079
 									   if (f_tmp==0){
1068 1080
 										   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 368
 		/* _local_ reply, we ignore any rport or received value
367 369
 		 * (but we will send back to the original port if rport is
368 370
 		 *  present) */
369
-		if (via->rport) port=msg->rcv.src_port;
371
+		if ((msg->msg_flags&FL_FORCE_RPORT)||(via->rport))
372
+			port=msg->rcv.src_port;
370 373
 		else port=via->port;
371 374
 		name=&(via->host); /* received=ip in 1st via is ignored (it's
372 375
 							  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 62
 /* use src_ip, port=src_port if rport, via port if via port, 5060 otherwise */
62 63
 #define update_sock_struct_from_ip(  to, msg ) \
63 64
 	init_su((to), &(msg)->rcv.src_ip, \
64
-			((msg)->via1->rport)?(msg)->rcv.src_port: \
65
-			((msg)->via1->port)?(msg)->via1->port: SIP_PORT )
65
+			(((msg)->via1->rport)||((msg)->msg_flags&&FL_FORCE_RPORT))? \
66
+							(msg)->rcv.src_port: \
67
+							((msg)->via1->port)?(msg)->via1->port: SIP_PORT )
66 68
 
67 69
 int forward_reply( struct sip_msg* msg);
68 70
 
... ...
@@ -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 1141
 	char* buf;
1094 1142
 	unsigned int offset, s_offset, size;
1095 1143
 	struct lump* anchor;
1096
-	int r;
1144
+	struct lump* via_insert_param;
1097 1145
 	str branch;
1098 1146
 	str extra_params;
1099 1147
 	
... ...
@@ -1109,6 +1157,7 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
1109 1157
 	clen_buf=0;
1110 1158
 	clen_len=0;
1111 1159
 #endif
1160
+	via_insert_param=0;
1112 1161
 	extra_params.len=0;
1113 1162
 	extra_params.s=0;
1114 1163
 	uri_len=0;
... ...
@@ -1161,9 +1210,9 @@ skip_clen:
1161 1210
 		goto error00;
1162 1211
 	}
1163 1212
 	/* 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){
1213
+	if ( msg->via1->received || 
1214
+			check_via_address(&msg->rcv.src_ip, &msg->via1->host, 
1215
+									msg->via1->port, received_dns) ){
1167 1216
 		if ((received_buf=received_builder(msg,&received_len))==0){
1168 1217
 			LOG(L_ERR, "ERROR: build_req_buf_from_sip_req:"
1169 1218
 							" received_builder failed\n");
... ...
@@ -1171,8 +1220,13 @@ skip_clen:
1171 1220
 		}
1172 1221
 	}
1173 1222
 	
1174
-	/* check if rport needs to be updated */
1175
-	if (msg->via1->rport && msg->via1->rport->value.s==0){
1223
+	/* check if rport needs to be updated:
1224
+	 *  - if FL_FORCE_RPORT is set add it (and del. any previous version)
1225
+	 *  - if via already contains an rport add it and overwrite the previous
1226
+	 *  rport value if present (if you don't want to overwrite the previous
1227
+	 *  version remove the comments) */
1228
+	if ((msg->msg_flags&FL_FORCE_RPORT)||
1229
+			(msg->via1->rport /*&& msg->via1->rport->value.s==0*/)){
1176 1230
 		if ((rport_buf=rport_builder(msg, &rport_len))==0){
1177 1231
 			LOG(L_ERR, "ERROR: build_req_buf_from_sip_req:"
1178 1232
 							" rport_builder failed\n");
... ...
@@ -1187,34 +1241,52 @@ skip_clen:
1187 1241
 	if (anchor==0) goto error01;
1188 1242
 	if (insert_new_lump_before(anchor, line_buf, via_len, HDR_VIA)==0)
1189 1243
 		goto error01;
1190
-	/* if received needs to be added, add anchor after host and add it */
1244
+	/* find out where the offset of the first parameter that should be added
1245
+	 * (after host:port), needed by add receive & maybe rport */
1246
+	if (msg->via1->params.s){
1247
+			size= msg->via1->params.s-msg->via1->hdr.s-1; /*compensate
1248
+														  for ';' */
1249
+	}else{
1250
+			size= msg->via1->host.s-msg->via1->hdr.s+msg->via1->host.len;
1251
+			if (msg->via1->port!=0){
1252
+				/*size+=strlen(msg->via1->hdr.s+size+1)+1;*/
1253
+				size += msg->via1->port_str.len + 1; /* +1 for ':'*/
1254
+			}
1255
+		#ifdef USE_IPV6
1256
+			if(send_sock->address.af==AF_INET6) size+=1; /* +1 for ']'*/
1257
+		#endif
1258
+	}
1259
+	/* if received needs to be added, add anchor after host and add it, or 
1260
+	 * overwrite the previous one if already present */
1191 1261
 	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
1262
+		if (msg->via1->received){ /* received already present => overwrite it*/
1263
+			via_insert_param=del_lump(&(msg->add_rm),
1264
+								msg->via1->received->start-buf-1, /*;*/
1265
+								msg->via1->received->size+1, /*;*/ HDR_VIA);
1266
+		}else if (via_insert_param==0){ /* receive not present, ok */
1267
+			via_insert_param=anchor_lump(&(msg->add_rm),
1268
+										msg->via1->hdr.s-buf+size,0, HDR_VIA);
1204 1269
 		}
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 */
1270
+		if (via_insert_param==0) goto error02; /* free received_buf */
1271
+		if (insert_new_lump_after(via_insert_param, received_buf, received_len,
1272
+					HDR_VIA) ==0 ) goto error02; /* free received_buf */
1210 1273
 	}
1211
-	/* if rport needs to be updated, delete it and add it's value */
1274
+	/* if rport needs to be updated, delete it if present and add it's value */
1212 1275
 	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*/
1276
+		if (msg->via1->rport){ /* rport already present */
1277
+			via_insert_param=del_lump(&(msg->add_rm),
1278
+								msg->via1->rport->start-buf-1, /*';'*/
1279
+								msg->via1->rport->size+1 /* ; */, HDR_VIA);
1280
+		}else if (via_insert_param==0){ /*force rport, no rport present */
1281
+			/* no rport, add it */
1282
+			via_insert_param=anchor_lump(&(msg->add_rm),
1283
+										msg->via1->hdr.s-buf+size,0, HDR_VIA);
1284
+		}
1285
+		if (via_insert_param==0) goto error03; /* free rport_buf */
1286
+		if (insert_new_lump_after(via_insert_param, rport_buf, rport_len,
1287
+									HDR_VIA) ==0 )
1288
+			goto error03; /* free rport_buf */
1289
+			
1218 1290
 	}
1219 1291
 #ifdef USE_TCP
1220 1292
 	/* 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 1509
 	char              *warning;
1438 1510
 	unsigned int      warning_len;
1439 1511
 	unsigned int	  text_len;
1440
-	int  r;
1441 1512
 	int  content_len_len;
1442 1513
 	char *content_len;
1443 1514
 	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 1541
 	/* check if received needs to be added */
1471 1542
 	backup = msg->via1->host.s[msg->via1->host.len];
1472 1543
 	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);
1544
+	if (msg->via1->received || 
1545
+			check_via_address(&msg->rcv.src_ip, &msg->via1->host, 
1546
+								msg->via1->port, received_dns)) {
1475 1547
 	msg->via1->host.s[msg->via1->host.len] = backup;
1476
-	if (r!=0) {
1477 1548
 		if ((received_buf=received_builder(msg,&received_len))==0) {
1478 1549
 			LOG(L_ERR, "ERROR: build_res_buf_from_sip_req: "
1479 1550
 				"alas, received_builder failed\n");
... ...
@@ -1481,13 +1552,15 @@ char * build_res_buf_with_body_from_sip_req( unsigned int code, char *text ,
1481 1552
 		}
1482 1553
 	}
1483 1554
 	/* check if rport needs to be updated */
1484
-	if (msg->via1->rport && msg->via1->rport->value.s==0){
1555
+	if ( (msg->msg_flags&FL_FORCE_RPORT)||
1556
+		(msg->via1->rport /*&& msg->via1->rport->value.s==0*/)){
1485 1557
 		if ((rport_buf=rport_builder(msg, &rport_len))==0){
1486 1558
 			LOG(L_ERR, "ERROR: build_res_buf_from_sip_req:"
1487 1559
 							" rport_builder failed\n");
1488 1560
 			goto error01; /* free everything */
1489 1561
 		}
1490
-		delete_len=msg->via1->rport->size+1; /* include ';' */
1562
+		if (msg->via1->rport) 
1563
+			delete_len=msg->via1->rport->size+1; /* include ';' */
1491 1564
 	}
1492 1565
 
1493 1566
 	/*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 1660
 			case HDR_VIA:
1588 1661
 				if (hdr==msg->h_via1){
1589 1662
 					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);
1663
+						if (msg->via1->rport){ /* delete the old one */
1664
+							/* copy until rport */
1665
+							append_str_trans( p, hdr->name.s ,
1666
+								msg->via1->rport->start-hdr->name.s-1,msg);
1667
+							/* copy new rport */
1668
+							append_str(p, rport_buf, rport_len);
1669
+							/* copy the rest of the via */
1670
+							append_str_trans(p, msg->via1->rport->start+
1671
+												msg->via1->rport->size, 
1672
+												hdr->body.s+hdr->body.len-
1673
+												msg->via1->rport->start-
1674
+												msg->via1->rport->size, msg);
1675
+						}else{ /* just append the new one */
1676
+							/* normal whole via copy */
1677
+							append_str_trans( p, hdr->name.s , 
1678
+								(hdr->body.s+hdr->body.len)-hdr->name.s, msg);
1679
+							append_str(p, rport_buf, rport_len);
1680
+						}
1601 1681
 					}else{
1602 1682
 						/* normal whole via copy */
1603 1683
 						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 66
 enum request_method { METHOD_UNDEF=0, METHOD_INVITE=1, METHOD_CANCEL=2, METHOD_ACK=4, 
66 67
 	METHOD_BYE=8, METHOD_OTHER=16 };
67 68
 
69
+#define FL_FORCE_RPORT 1 /* force rport */
70
+
68 71
 
69 72
 #define IFISMETHOD(methodname,firstchar)                                  \
70 73
 if (  (*tmp==(firstchar) || *tmp==((firstchar) | 32)) &&                  \
... ...
@@ -207,7 +210,7 @@ struct sip_msg {
207 210
 	
208 211
 	     /* index to TM hash table; stored in core to avoid unnecessary calcs */
209 212
 	unsigned int  hash_index;
210
-	
213
+	unsigned int msg_flags; /* flags used by core */
211 214
 	     /* allows to set various flags on the message; may be used for 
212 215
 	      *	simple inter-module communication or remembering processing state
213 216
 	      * 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 314
 			case MODULE_T:
314 315
 					DBG(" external_module_call(");
315 316
 					break;
317
+			case FORCE_RPORT_T:
318
+					DBG("force_rport(");
319
+					break;
316 320
 			default:
317 321
 					DBG("UNKNOWN(");
318 322
 		}
... ...
@@ -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 63
 		REVERT_URI_T,
59 64
 		FORWARD_TCP_T,
60 65
 		FORWARD_UDP_T,
61
-		SEND_TCP_T};
66
+		SEND_TCP_T,
67
+		FORCE_RPORT_T
68
+};
62 69
 enum { NOSUBTYPE=0, STRING_ST, NET_ST, NUMBER_ST, IP_ST, RE_ST, PROXY_ST,
63 70
 		EXPR_ST, ACTIONS_ST, CMDF_ST, MODFIXUP_ST, URIHOST_ST, URIPORT_ST,
64 71
 		MYSELF_ST };