Browse code

modules/rr: Double-route and outbound support in loose.c

- Have removed outbound support from strict routing for now as it was incorrect
and I don't have a system to test with.

Peter Dunkley authored on 24/04/2013 13:24:45
Showing 1 changed files
... ...
@@ -571,7 +571,7 @@ static inline int after_strict(struct sip_msg* _m)
571 571
 	char* rem_off;
572 572
 	str uri;
573 573
 	struct socket_info *si;
574
-	int use_ob, next_is_strict;
574
+	int next_is_strict;
575 575
 
576 576
 	hdr = _m->route;
577 577
 	rt = (rr_t*)hdr->parsed;
... ...
@@ -588,14 +588,11 @@ static inline int after_strict(struct sip_msg* _m)
588 588
 	}
589 589
 
590 590
 	next_is_strict = is_strict(&puri.params);
591
-	if ((use_ob = process_outbound(_m, puri.user, &uri)) < 0) {
592
-		LM_ERR("processing outbound flow-token\n");
593
-		return FLOW_TOKEN_BROKEN;
594
-	}
595 591
 
596
-	if (!use_ob && enable_double_rr && is_2rr(&puri.params) && is_myself(&puri)) {
592
+	if (enable_double_rr && is_2rr(&puri.params) && is_myself(&puri)) {
597 593
 		/* double route may occure due different IP and port, so force as
598 594
 		 * send interface the one advertise in second Route */
595
+
599 596
 		si = grep_sock_info( &puri.host, puri.port_no, puri.proto);
600 597
 		if (si) {
601 598
 			set_force_socket(_m, si);
... ...
@@ -650,11 +647,9 @@ static inline int after_strict(struct sip_msg* _m)
650 647
 		 * always be a strict router because endpoints don't use ;lr parameter
651 648
 		 * In this case we will simply put the URI in R-URI and forward it, 
652 649
 		 * which will work perfectly */
653
-		if (!use_ob) {
654
-			if(get_maddr_uri(&uri, &puri)!=0) {
655
-				LM_ERR("failed to check maddr\n");
656
-				return RR_ERROR;
657
-			}
650
+		if(get_maddr_uri(&uri, &puri)!=0) {
651
+			LM_ERR("failed to check maddr\n");
652
+			return RR_ERROR;
658 653
 		}
659 654
 		if (rewrite_uri(_m, &uri) < 0) {
660 655
 			LM_ERR("failed to rewrite request URI\n");
... ...
@@ -676,11 +671,9 @@ static inline int after_strict(struct sip_msg* _m)
676 671
 		LM_DBG("Next hop: '%.*s' is loose router\n",
677 672
 			uri.len, ZSW(uri.s));
678 673
 
679
-		if (!use_ob) {
680
-			if(get_maddr_uri(&uri, &puri)!=0) {
681
-				LM_ERR("failed to check maddr\n");
682
-				return RR_ERROR;
683
-			}
674
+		if(get_maddr_uri(&uri, &puri)!=0) {
675
+			LM_ERR("failed to check maddr\n");
676
+			return RR_ERROR;
684 677
 		}
685 678
 		if (set_dst_uri(_m, &uri) < 0) {
686 679
 			LM_ERR("failed to set dst_uri\n");
... ...
@@ -745,10 +738,7 @@ static inline int after_strict(struct sip_msg* _m)
745 738
 	if(routed_params.len > 0)
746 739
 		run_rr_callbacks( _m, &routed_params );
747 740
 
748
-	if (use_ob == 1)
749
-	    return RR_OB_DRIVEN;
750
-	else
751
-	    return RR_DRIVEN;
741
+	return RR_DRIVEN;
752 742
 }
753 743
 
754 744
 
... ...
@@ -767,7 +757,8 @@ static inline int after_loose(struct sip_msg* _m, int preloaded)
767 757
 	int status;
768 758
 	str uri;
769 759
 	struct socket_info *si;
770
-	int uri_is_myself, use_ob, next_is_strict;
760
+	int uri_is_myself, next_is_strict;
761
+	int use_ob = 0;
771 762
 
772 763
 	hdr = _m->route;
773 764
 	rt = (rr_t*)hdr->parsed;
... ...
@@ -784,12 +775,6 @@ static inline int after_loose(struct sip_msg* _m, int preloaded)
784 775
 	next_is_strict = is_strict(&puri.params);
785 776
 	routed_params = puri.params;
786 777
 	uri_is_myself = is_myself(&puri);
787
-	if ((use_ob = process_outbound(_m, puri.user, &uri)) < 0) {
788
-		LM_ERR("processing outbound flow-token\n");
789
-		return FLOW_TOKEN_BROKEN;
790
-	}
791
-
792
-	LM_DBG("process_outbound returned <%d>\n", use_ob);
793 778
 
794 779
 	/* IF the URI was added by me, remove it */
795 780
 	if (uri_is_myself>0)
... ...
@@ -799,6 +784,11 @@ static inline int after_loose(struct sip_msg* _m, int preloaded)
799 784
 		/* set the hooks for the params */
800 785
 		routed_msg_id = _m->id;
801 786
 
787
+		if ((use_ob = process_outbound(_m, puri.user, &uri)) < 0) {
788
+			LM_ERR("processing outbound flow-token\n");
789
+			return FLOW_TOKEN_BROKEN;
790
+		}
791
+
802 792
 		if (!rt->next) {
803 793
 			/* No next route in the same header, remove the whole header
804 794
 			 * field immediately
... ...
@@ -808,10 +798,6 @@ static inline int after_loose(struct sip_msg* _m, int preloaded)
808 798
 				return RR_ERROR;
809 799
 			}
810 800
 
811
-			/* When using outbound skip past all this stuff and just set
812
- 			   the destination */
813
-			if (use_ob) goto got_uri;
814
-
815 801
 			res = find_next_route(_m, &hdr);
816 802
 			if (res < 0) {
817 803
 				LM_ERR("failed to find next route\n");
... ...
@@ -825,14 +811,15 @@ static inline int after_loose(struct sip_msg* _m, int preloaded)
825 811
 			rt = (rr_t*)hdr->parsed;
826 812
 		} else rt = rt->next;
827 813
 
828
-		if (!use_ob) {
829
-			if (enable_double_rr && is_2rr(&puri.params)) {
830
-				/* double route may occure due different IP and port, so force as
831
-				 * send interface the one advertise in second Route */
832
-				if (parse_uri(rt->nameaddr.uri.s,rt->nameaddr.uri.len,&puri)<0) {
833
-					LM_ERR("failed to parse the double route URI\n");
834
-					return RR_ERROR;
835
-				}
814
+		if (enable_double_rr && is_2rr(&puri.params)) {
815
+			/* double route may occure due different IP and port, so force as
816
+			 * send interface the one advertise in second Route */
817
+			if (parse_uri(rt->nameaddr.uri.s,rt->nameaddr.uri.len,&puri)<0) {
818
+				LM_ERR("failed to parse the double route URI\n");
819
+				return RR_ERROR;
820
+			}
821
+
822
+			if (!use_ob) {
836 823
 				si = grep_sock_info( &puri.host, puri.port_no, puri.proto);
837 824
 				if (si) {
838 825
 					set_force_socket(_m, si);
... ...
@@ -840,28 +827,30 @@ static inline int after_loose(struct sip_msg* _m, int preloaded)
840 827
 					if (enable_socket_mismatch_warning)
841 828
 						LM_WARN("no socket found for match second RR\n");
842 829
 				}
843
-	
844
-				if (!rt->next) {
845
-					/* No next route in the same header, remove the whole header
846
-					 * field immediately */
847
-					if (!del_lump(_m, hdr->name.s - _m->buf, hdr->len, 0)) {
848
-						LM_ERR("failed to remove Route HF\n");
849
-						return RR_ERROR;
850
-					}
851
-					res = find_next_route(_m, &hdr);
852
-					if (res < 0) {
853
-						LM_ERR("failed to find next route\n");
854
-						return RR_ERROR;
855
-						}
856
-					if (res > 0) { /* No next route found */
857
-						LM_DBG("no next URI found\n");
858
-						status = (preloaded ? NOT_RR_DRIVEN : RR_DRIVEN);
859
-						goto done;
860
-					}
861
-					rt = (rr_t*)hdr->parsed;
862
-				} else rt = rt->next;
863 830
 			}
864
-			
831
+
832
+			if (!rt->next) {
833
+				/* No next route in the same header, remove the whole header
834
+				 * field immediately */
835
+				if (!del_lump(_m, hdr->name.s - _m->buf, hdr->len, 0)) {
836
+					LM_ERR("failed to remove Route HF\n");
837
+					return RR_ERROR;
838
+				}
839
+				res = find_next_route(_m, &hdr);
840
+				if (res < 0) {
841
+					LM_ERR("failed to find next route\n");
842
+					return RR_ERROR;
843
+					}
844
+				if (res > 0) { /* No next route found */
845
+					LM_DBG("no next URI found\n");
846
+					status = (preloaded ? NOT_RR_DRIVEN : RR_DRIVEN);
847
+					goto done;
848
+				}
849
+				rt = (rr_t*)hdr->parsed;
850
+			} else rt = rt->next;
851
+		}
852
+		
853
+		if (!use_ob) {
865 854
 			uri = rt->nameaddr.uri;
866 855
 			if (parse_uri(uri.s, uri.len, &puri) < 0) {
867 856
 				LM_ERR("failed to parse the first route URI\n");
... ...
@@ -889,7 +878,6 @@ static inline int after_loose(struct sip_msg* _m, int preloaded)
889 878
 	} else {
890 879
 		/* Next hop is loose router */
891 880
 		LM_DBG("Next URI is a loose router\n");
892
-got_uri:
893 881
 
894 882
 		if (!use_ob) {
895 883
 			if(get_maddr_uri(&uri, &puri)!=0) {