Browse code

modules/rr: Fixes relating to outbound and record-routing

Peter Dunkley authored on 24/04/2013 15:34:29
Showing 2 changed files
... ...
@@ -501,12 +501,12 @@ static char uri_buf[MAX_ROUTE_URI_LEN];
501 501
  * \param dst_uri string to write the destination URI to (extracted from flow-token)
502 502
  * \return -1 on error, 0 when outbound not in use, 1 when outbound in use
503 503
  */
504
-static inline int process_outbound(struct sip_msg *_m, str flow_token,
505
-		str *dst_uri)
504
+static inline int process_outbound(struct sip_msg *_m, str flow_token)
506 505
 {
507 506
 	int ret;
508 507
 	struct receive_info *rcv = NULL;
509 508
 	struct socket_info *si;
509
+	str dst_uri;
510 510
 
511 511
 	if (!rr_obb.decode_flow_token)
512 512
 		return 0;
... ...
@@ -534,22 +534,29 @@ static inline int process_outbound(struct sip_msg *_m, str flow_token,
534 534
 		}
535 535
 
536 536
 		/* Second, override the destination URI */
537
-		dst_uri->s = uri_buf;
538
-		dst_uri->len = 0;
537
+		dst_uri.s = uri_buf;
538
+		dst_uri.len = 0;
539 539
 
540
-		dst_uri->len += snprintf(dst_uri->s + dst_uri->len,
541
-					MAX_ROUTE_URI_LEN - dst_uri->len,
540
+		dst_uri.len += snprintf(dst_uri.s + dst_uri.len,
541
+					MAX_ROUTE_URI_LEN - dst_uri.len,
542 542
 					"sip:%s",
543 543
 					rcv->src_ip.af == AF_INET6 ? "[" : "");
544
-		dst_uri->len += ip_addr2sbuf(&rcv->src_ip,
545
-					dst_uri->s + dst_uri->len,
546
-					MAX_ROUTE_URI_LEN - dst_uri->len);
547
-		dst_uri->len += snprintf(dst_uri->s + dst_uri->len,
548
-					MAX_ROUTE_URI_LEN - dst_uri->len,
544
+		dst_uri.len += ip_addr2sbuf(&rcv->src_ip,
545
+					dst_uri.s + dst_uri.len,
546
+					MAX_ROUTE_URI_LEN - dst_uri.len);
547
+		dst_uri.len += snprintf(dst_uri.s + dst_uri.len,
548
+					MAX_ROUTE_URI_LEN - dst_uri.len,
549 549
 					"%s:%d;transport=%s",
550 550
 					rcv->src_ip.af == AF_INET6 ? "]" : "",
551 551
 					rcv->src_port,
552 552
 					get_proto_name(rcv->proto));
553
+
554
+		if (set_dst_uri(_m, &dst_uri) < 0) {
555
+			LM_ERR("failed to set dst_uri\n");
556
+			return -1;
557
+		}
558
+		ruri_mark_new();
559
+
553 560
 		return 1;
554 561
 	}
555 562
 
... ...
@@ -754,7 +761,7 @@ static inline int after_loose(struct sip_msg* _m, int preloaded)
754 761
 	struct sip_uri puri;
755 762
 	rr_t* rt;
756 763
 	int res;
757
-	int status;
764
+	int status = RR_DRIVEN;
758 765
 	str uri;
759 766
 	struct socket_info *si;
760 767
 	int uri_is_myself, next_is_strict;
... ...
@@ -784,7 +791,7 @@ static inline int after_loose(struct sip_msg* _m, int preloaded)
784 791
 		/* set the hooks for the params */
785 792
 		routed_msg_id = _m->id;
786 793
 
787
-		if ((use_ob = process_outbound(_m, puri.user, &uri)) < 0) {
794
+		if ((use_ob = process_outbound(_m, puri.user)) < 0) {
788 795
 			LM_ERR("processing outbound flow-token\n");
789 796
 			return FLOW_TOKEN_BROKEN;
790 797
 		}
... ...
@@ -850,12 +857,10 @@ static inline int after_loose(struct sip_msg* _m, int preloaded)
850 857
 			} else rt = rt->next;
851 858
 		}
852 859
 		
853
-		if (!use_ob) {
854
-			uri = rt->nameaddr.uri;
855
-			if (parse_uri(uri.s, uri.len, &puri) < 0) {
856
-				LM_ERR("failed to parse the first route URI\n");
857
-				return RR_ERROR;
858
-			}
860
+		uri = rt->nameaddr.uri;
861
+		if (parse_uri(uri.s, uri.len, &puri) < 0) {
862
+			LM_ERR("failed to parse the first route URI\n");
863
+			return RR_ERROR;
859 864
 		}
860 865
 	} else {
861 866
 #ifdef ENABLE_USER_CHECK
... ...
@@ -884,14 +889,15 @@ static inline int after_loose(struct sip_msg* _m, int preloaded)
884 889
 				LM_ERR("checking maddr failed\n");
885 890
 				return RR_ERROR;
886 891
 			}
887
-		}
888
-		if (set_dst_uri(_m, &uri) < 0) {
889
-			LM_ERR("failed to set dst_uri\n");
890
-			return RR_ERROR;
891
-		}
892
-		/* dst_uri changed, so it makes sense to re-use the current uri for
892
+		
893
+			if (set_dst_uri(_m, &uri) < 0) {
894
+				LM_ERR("failed to set dst_uri\n");
895
+				return RR_ERROR;
896
+			}
897
+			/* dst_uri changed, so it makes sense to re-use the current uri for
893 898
 			forking */
894
-		ruri_mark_new(); /* re-use uri for serial forking */
899
+			ruri_mark_new(); /* re-use uri for serial forking */
900
+		}
895 901
 
896 902
 		/* There is a previous route uri which was 2nd uri of mine
897 903
 		 * and must be removed here */
... ...
@@ -903,12 +909,11 @@ static inline int after_loose(struct sip_msg* _m, int preloaded)
903 909
 			}
904 910
 		}
905 911
 	}
906
-	if (use_ob == 1) 
907
-	    status = RR_OB_DRIVEN;
908
-	else
909
-	    status = RR_DRIVEN;
910 912
 
911 913
 done:
914
+	if (use_ob == 1)
915
+		status = RR_OB_DRIVEN;
916
+
912 917
 	/* run RR callbacks only if we have Route URI parameters */
913 918
 	if(routed_params.len > 0)
914 919
 		run_rr_callbacks( _m, &routed_params );
... ...
@@ -447,8 +447,7 @@ int record_route(struct sip_msg* _m, str *params)
447 447
 		return -3;
448 448
 	}
449 449
 	
450
-	if (build_rr(l, l2, &user, tag, params, use_ob ? OUTBOUND : INBOUND,
451
-			sips) < 0) {
450
+	if (build_rr(l, l2, &user, tag, params, INBOUND, sips) < 0) {
452 451
 		LM_ERR("failed to insert inbound Record-Route\n");
453 452
 		return -4;
454 453
 	}
... ...
@@ -787,9 +786,7 @@ int record_route_advertised_address(struct sip_msg* _m, str* _data)
787 786
 		return -6;
788 787
 	}
789 788
 	
790
-	if (build_advertised_rr(l, l2, _data, &user, tag,
791
-				use_ob ? OUTBOUND: INBOUND,
792
-				sips) < 0) {
789
+	if (build_advertised_rr(l, l2, _data, &user, tag, INBOUND, sips) < 0) {
793 790
 		LM_ERR("failed to insert outbound Record-Route\n");
794 791
 		return -7;
795 792
 	}