Browse code

rr: try to enforce send socket using name in Route URI params

- done when sockname_mode=1; if param not found or no socket matching
found, then it tries the classic socket lookup

Daniel-Constantin Mierla authored on 02/04/2020 13:09:36
Showing 1 changed files
... ...
@@ -36,6 +36,7 @@
36 36
 #include "../../core/parser/parse_rr.h"
37 37
 #include "../../core/parser/parse_uri.h"
38 38
 #include "../../core/parser/parse_from.h"
39
+#include "../../core/parser/parse_param.h"
39 40
 #include "../../core/mem/mem.h"
40 41
 #include "../../core/dset.h"
41 42
 #include "loose.h"
... ...
@@ -61,6 +62,7 @@ static msg_ctx_id_t routed_msg_id = {0};
61 62
 static str routed_params = {0,0};
62 63
 
63 64
 extern int rr_force_send_socket;
65
+extern int rr_sockname_mode;
64 66
 
65 67
 /*!
66 68
  * \brief Test whether we are processing pre-loaded route set by looking at the To tag
... ...
@@ -749,7 +751,44 @@ static inline int after_strict(struct sip_msg* _m)
749 751
 static inline void rr_do_force_send_socket(sip_msg_t *_m, sip_uri_t *puri,
750 752
 		rr_t* rt, int rr2on)
751 753
 {
752
-	socket_info_t *si;
754
+	socket_info_t *si = NULL;
755
+	param_hooks_t phooks;
756
+	param_t* plist = NULL;
757
+	param_t *pit=NULL;
758
+	str s;
759
+
760
+
761
+	if(rr_sockname_mode!=0 && puri->params.len>0) {
762
+		s = puri->params;
763
+		if(s.s[s.len-1]==';') {
764
+			s.len--;
765
+		}
766
+		if (parse_params(&s, CLASS_ANY, &phooks, &plist)<0) {
767
+			LM_ERR("bad sip uri parameters: %.*s\n", s.len, s.s);
768
+			return;
769
+		}
770
+		for (pit = plist; pit; pit=pit->next) {
771
+			if (pit->name.len==SOCKNAME_PARAM_LEN
772
+					&& strncasecmp(pit->name.s, SOCKNAME_PARAM,
773
+							SOCKNAME_PARAM_LEN)==0) {
774
+				if(pit->body.len>0) {
775
+					si = ksr_get_socket_by_name(&pit->body);
776
+					if(si != NULL) {
777
+						LM_DBG("found socket with name: %.*s\n",
778
+								pit->body.len, pit->body.s);
779
+						set_force_socket(_m, si);
780
+						free_params(plist);
781
+						return;
782
+					} else {
783
+						LM_DBG("failed to find socket with name: %.*s\n",
784
+								pit->body.len, pit->body.s);
785
+					}
786
+				}
787
+			}
788
+		}
789
+		LM_DBG("use of sockname parameter enabled, but failed to find it\n");
790
+		free_params(plist);
791
+	}
753 792
 
754 793
 	if ((si = grep_sock_info(&puri->host,
755 794
 				puri->port_no?puri->port_no:proto_default_port(puri->proto),