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 351
 
352 352
 
353 353
 int update_sock_struct_from_via( union sockaddr_union* to,
354
+								 struct sip_msg* msg,
354 355
 								 struct via_body* via )
355 356
 {
356 357
 	struct hostent* he;
... ...
@@ -359,24 +362,36 @@ int update_sock_struct_from_via( union sockaddr_union* to,
359 359
 	unsigned short port;
360 360
 
361 361
 	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; 
362
+	if(via==msg->via1){ 
363
+		/* _local_ reply, we ignore any rport or received value
364
+		 * (but we will send back to the original port if rport is
365
+		 *  present) */
366
+		if (via->rport) port=msg->rcv.src_port;
367
+		else port=via->port;
368
+		name=&(via->host); /* received=ip in 1st via is ignored (it's
369
+							  not added by us so it's bad) */
376 370
 	}else{
377
-		DBG("update_sock_struct_from_via: using via host\n");
378
-		name=&(via->host);
379
-		if (port==0) port=via->port;
371
+		/* "normal" reply, we use rport's & received value if present */
372
+		if (via->rport && via->rport->value.s){
373
+			DBG("update_sock_struct_from_via: using 'rport'\n");
374
+			port=str2s(via->rport->value.s, via->rport->value.len, &err);
375
+			if (err){
376
+				LOG(L_NOTICE, "ERROR: forward_reply: bad rport value(%.*s)\n",
377
+						via->rport->value.len, via->rport->value.s);
378
+				port=0;
379
+			}
380
+		}
381
+		if (via->received){
382
+			DBG("update_sock_struct_from_via: using 'received'\n");
383
+			name=&(via->received->value);
384
+			/* making sure that we won't do SRV lookup on "received"
385
+			 * (possible if no DNS_IP_HACK is used)*/
386
+			if (port==0) port=via->port?via->port:SIP_PORT; 
387
+		}else{
388
+			DBG("update_sock_struct_from_via: using via host\n");
389
+			name=&(via->host);
390
+			if (port==0) port=via->port;
391
+		}
380 392
 	}
381 393
 	/* we do now a malloc/memcpy because gethostbyname loves \0-terminated 
382 394
 	   strings; -jiri 
... ...
@@ -460,7 +475,7 @@ int forward_reply(struct sip_msg* msg)
460 460
 	}
461 461
 
462 462
 	proto=msg->via2->proto;
463
-	if (update_sock_struct_from_via( to, msg->via2 )==-1) goto error;
463
+	if (update_sock_struct_from_via( to, msg, msg->via2 )==-1) goto error;
464 464
 
465 465
 
466 466
 #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 ) \