Browse code

- rport fixes for sl_send_replies (reply_to_via==1)

Andrei Pelinescu-Onciul authored on 04/04/2003 15:38:30
Showing 3 changed files
... ...
@@ -18,7 +18,7 @@
18 18
 VERSION = 0
19 19
 PATCHLEVEL = 8
20 20
 SUBLEVEL =   11
21
-EXTRAVERSION = pre9-new_opts
21
+EXTRAVERSION = pre10-allmost-there
22 22
 
23 23
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
24 24
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -37,6 +37,8 @@
37 37
  *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
38 38
  *  2003-04-02  fixed get_send_socket for tcp fwd to udp (andrei)
39 39
  *  2003-04-03  added su_setport (andrei)
40
+ *  2003-04-04  update_sock_struct_from_via now differentiates between
41
+ *               local replies  & "normal" replies (andrei)
40 42
  */
41 43
 
42 44
 
... ...
@@ -351,6 +353,7 @@ error:
351 353
 
352 354
 
353 355
 int update_sock_struct_from_via( union sockaddr_union* to,
356
+								 struct sip_msg* msg,
354 357
 								 struct via_body* via )
355 358
 {
356 359
 	struct hostent* he;
... ...
@@ -359,24 +362,36 @@ int update_sock_struct_from_via( union sockaddr_union* to,
359 362
 	unsigned short port;
360 363
 
361 364
 	port=0;
362
-	if (via->rport && via->rport->value.s){
363
-		port=str2s(via->rport->value.s, via->rport->value.len, &err);
364
-		if (err){
365
-			LOG(L_NOTICE, "ERROR: forward_reply: bad rport value(%.*s)\n",
366
-					via->rport->value.len, via->rport->value.s);
367
-			port=0;
368
-		}
369
-	}
370
-	if (via->received){
371
-		DBG("update_sock_struct_from_via: using 'received'\n");
372
-		name=&(via->received->value);
373
-		/* making sure that we won't do SRV lookup on "received"
374
-		 * (possible if no DNS_IP_HACK is used)*/
375
-		if (port==0) port=via->port?via->port:SIP_PORT; 
365
+	if(via==msg->via1){ 
366
+		/* _local_ reply, we ignore any rport or received value
367
+		 * (but we will send back to the original port if rport is
368
+		 *  present) */
369
+		if (via->rport) port=msg->rcv.src_port;
370
+		else port=via->port;
371
+		name=&(via->host); /* received=ip in 1st via is ignored (it's
372
+							  not added by us so it's bad) */
376 373
 	}else{
377
-		DBG("update_sock_struct_from_via: using via host\n");
378
-		name=&(via->host);
379
-		if (port==0) port=via->port;
374
+		/* "normal" reply, we use rport's & received value if present */
375
+		if (via->rport && via->rport->value.s){
376
+			DBG("update_sock_struct_from_via: using 'rport'\n");
377
+			port=str2s(via->rport->value.s, via->rport->value.len, &err);
378
+			if (err){
379
+				LOG(L_NOTICE, "ERROR: forward_reply: bad rport value(%.*s)\n",
380
+						via->rport->value.len, via->rport->value.s);
381
+				port=0;
382
+			}
383
+		}
384
+		if (via->received){
385
+			DBG("update_sock_struct_from_via: using 'received'\n");
386
+			name=&(via->received->value);
387
+			/* making sure that we won't do SRV lookup on "received"
388
+			 * (possible if no DNS_IP_HACK is used)*/
389
+			if (port==0) port=via->port?via->port:SIP_PORT; 
390
+		}else{
391
+			DBG("update_sock_struct_from_via: using via host\n");
392
+			name=&(via->host);
393
+			if (port==0) port=via->port;
394
+		}
380 395
 	}
381 396
 	/* we do now a malloc/memcpy because gethostbyname loves \0-terminated 
382 397
 	   strings; -jiri 
... ...
@@ -460,7 +475,7 @@ int forward_reply(struct sip_msg* msg)
460 475
 	}
461 476
 
462 477
 	proto=msg->via2->proto;
463
-	if (update_sock_struct_from_via( to, msg->via2 )==-1) goto error;
478
+	if (update_sock_struct_from_via( to, msg, msg->via2 )==-1) goto error;
464 479
 
465 480
 
466 481
 #ifdef USE_TCP
... ...
@@ -54,7 +54,8 @@ struct socket_info* get_out_socket(union sockaddr_union* to, int proto);
54 54
 int check_self(str* host, unsigned short port);
55 55
 int forward_request( struct sip_msg* msg,  struct proxy_l* p, int proto);
56 56
 int update_sock_struct_from_via( union sockaddr_union* to,
57
-								struct via_body* via );
57
+								 struct sip_msg* msg,
58
+								 struct via_body* via );
58 59
 
59 60
 /* use src_ip, port=src_port if rport, via port if via port, 5060 otherwise */
60 61
 #define update_sock_struct_from_ip(  to, msg ) \