Browse code

rr: new parameter force_send_socket

- if set to 1, the socket is also forced for single rr
- default is 0, socket is forced only for doubgle rr
- if use outbound is set, socket is not forced

Daniel-Constantin Mierla authored on 07/02/2018 12:13:01
Showing 2 changed files
... ...
@@ -60,6 +60,7 @@ static unsigned int routed_msg_id = 0;
60 60
 static int routed_msg_pid = 0;
61 61
 static str routed_params = {0,0};
62 62
 
63
+extern int rr_force_send_socket;
63 64
 
64 65
 /*!
65 66
  * \brief Test whether we are processing pre-loaded route set by looking at the To tag
... ...
@@ -736,7 +737,7 @@ static inline int after_strict(struct sip_msg* _m)
736 737
 			return RR_ERROR;
737 738
 		}
738 739
 	}
739
-	
740
+
740 741
 	/* run RR callbacks only if we have Route URI parameters */
741 742
 	if(routed_params.len > 0)
742 743
 		run_rr_callbacks( _m, &routed_params );
... ...
@@ -745,6 +746,30 @@ static inline int after_strict(struct sip_msg* _m)
745 746
 }
746 747
 
747 748
 
749
+static inline void rr_do_force_send_socket(sip_msg_t *_m, sip_uri_t *puri,
750
+		rr_t* rt, int rr2on)
751
+{
752
+	socket_info_t *si;
753
+
754
+	if ((si = grep_sock_info(&puri->host,
755
+				puri->port_no?puri->port_no:proto_default_port(puri->proto),
756
+				puri->proto)) != 0) {
757
+		set_force_socket(_m, si);
758
+	} else if ((si = grep_sock_info(&puri->host, puri->port_no,
759
+					puri->proto)) != 0) {
760
+		set_force_socket(_m, si);
761
+	} else {
762
+		if (enable_socket_mismatch_warning && rr2on) {
763
+			LM_WARN("no socket found to match second RR (%.*s)\n",
764
+					rt->nameaddr.uri.len, ZSW(rt->nameaddr.uri.s));
765
+			if(!is_myself(puri)) {
766
+				LM_WARN("second RR uri is not myself (%.*s)\n",
767
+						rt->nameaddr.uri.len, ZSW(rt->nameaddr.uri.s));
768
+			}
769
+		}
770
+	}
771
+}
772
+
748 773
 /*!
749 774
  * \brief Previous hop was a loose router, handle this case
750 775
  * \param _m SIP message
... ...
@@ -795,6 +820,11 @@ static inline int after_loose(struct sip_msg* _m, int preloaded)
795 820
 			return FLOW_TOKEN_BROKEN;
796 821
 		}
797 822
 
823
+		if (rr_force_send_socket && !use_ob) {
824
+			if (!enable_double_rr || !is_2rr(&puri.params)) {
825
+				rr_do_force_send_socket(_m, &puri, rt, 0);
826
+			}
827
+		}
798 828
 		if (!rt->next) {
799 829
 			/* No next route in the same header, remove the whole header
800 830
 			 * field immediately
... ...
@@ -827,20 +857,7 @@ static inline int after_loose(struct sip_msg* _m, int preloaded)
827 857
 			}
828 858
 
829 859
 			if (!use_ob) {
830
-				if ((si = grep_sock_info( &puri.host, puri.port_no?puri.port_no:proto_default_port(puri.proto), puri.proto)) != 0) {
831
-					set_force_socket(_m, si);
832
-				} else if ((si = grep_sock_info( &puri.host, puri.port_no, puri.proto)) != 0) {
833
-					set_force_socket(_m, si);
834
-				} else {
835
-					if (enable_socket_mismatch_warning) {
836
-						LM_WARN("no socket found to match second RR (%.*s)\n",
837
-								rt->nameaddr.uri.len, ZSW(rt->nameaddr.uri.s));
838
-						if(!is_myself(&puri)) {
839
-							LM_WARN("second RR uri is not myself (%.*s)\n",
840
-								rt->nameaddr.uri.len, ZSW(rt->nameaddr.uri.s));
841
-						}
842
-					}
843
-				}
860
+				rr_do_force_send_socket(_m, &puri, rt, 1);
844 861
 			}
845 862
 
846 863
 			if (!rt->next) {
... ...
@@ -57,6 +57,7 @@ int append_fromtag = 1;		/*!< append from tag by default */
57 57
 int enable_double_rr = 1;	/*!< enable using of 2 RR by default */
58 58
 int enable_full_lr = 0;		/*!< compatibilty mode disabled by default */
59 59
 int add_username = 0;	 	/*!< do not add username by default */
60
+int rr_force_send_socket = 0; /*!< control if socket is forced by rr */
60 61
 int enable_socket_mismatch_warning = 1; /*!< enable socket mismatch warning */
61 62
 static str custom_user_spec = {NULL, 0};
62 63
 pv_spec_t custom_user_avp;
... ...
@@ -120,15 +121,16 @@ static cmd_export_t cmds[] = {
120 121
  * \brief Exported parameters
121 122
  */
122 123
 static param_export_t params[] ={
123
-	{"append_fromtag",	INT_PARAM, &append_fromtag},
124
+	{"append_fromtag",	    INT_PARAM, &append_fromtag},
124 125
 	{"enable_double_rr",	INT_PARAM, &enable_double_rr},
125 126
 	{"enable_full_lr",		INT_PARAM, &enable_full_lr},
126 127
 #ifdef ENABLE_USER_CHECK
127
-	{"ignore_user",		PARAM_STR, &i_user},
128
+	{"ignore_user",		    PARAM_STR, &i_user},
128 129
 #endif
129 130
 	{"add_username",		INT_PARAM, &add_username},
130 131
 	{"enable_socket_mismatch_warning",INT_PARAM,&enable_socket_mismatch_warning},
131
-	{"custom_user_avp",           PARAM_STR, &custom_user_spec},
132
+	{"custom_user_avp",     PARAM_STR, &custom_user_spec},
133
+	{"force_send_socket",   PARAM_INT, &rr_force_send_socket},
132 134
 	{0, 0, 0 }
133 135
 };
134 136