Browse code

rr: new function loose_route_mode(vmode)

- if vmode==1, then do only loose routing (do not test if r-uri==myself
to do strict routing, always do loose routing, with preloaded check like
loose_route())
- if vmode==0, then behave like loose_route()

Daniel-Constantin Mierla authored on 14/09/2020 11:24:31
Showing 3 changed files
... ...
@@ -990,9 +990,10 @@ done:
990 990
 /*!
991 991
  * \brief Do loose routing as per RFC3261
992 992
  * \param _m SIP message
993
+ * \param _mode - 0: try loose or strict routing; 1: try loose routing only
993 994
  * \return negative on failure or preloaded, 1 on success
994 995
  */
995
-int loose_route(struct sip_msg* _m)
996
+int loose_route_mode(sip_msg_t* _m, int _mode)
996 997
 {
997 998
 	int ret;
998 999
 
... ...
@@ -1012,7 +1013,7 @@ int loose_route(struct sip_msg* _m)
1012 1013
 	} else if (ret == 1) {
1013 1014
 		return after_loose(_m, 1);
1014 1015
 	} else {
1015
-		if (is_myself(&_m->parsed_uri)) {
1016
+		if ((_mode==0) && (is_myself(&_m->parsed_uri))) {
1016 1017
 			return after_strict(_m);
1017 1018
 		} else {
1018 1019
 			return after_loose(_m, 0);
... ...
@@ -1020,6 +1021,16 @@ int loose_route(struct sip_msg* _m)
1020 1021
 	}
1021 1022
 }
1022 1023
 
1024
+/*!
1025
+ * \brief Do loose routing as per RFC3261
1026
+ * \param _m SIP message
1027
+ * \return negative on failure or preloaded, 1 on success
1028
+ */
1029
+int loose_route(struct sip_msg* _m)
1030
+{
1031
+	return loose_route_mode(_m, 0);
1032
+}
1033
+
1023 1034
 /**
1024 1035
  *
1025 1036
  */
... ...
@@ -13,8 +13,8 @@
13 13
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 14
  * GNU General Public License for more details.
15 15
  *
16
- * You should have received a copy of the GNU General Public License 
17
- * along with this program; if not, write to the Free Software 
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program; if not, write to the Free Software
18 18
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19 19
  */
20 20
 
... ...
@@ -44,6 +44,15 @@
44 44
 #define RR_PRELOADED -3		/*!< The next hop is determined from a preloaded route set */
45 45
 
46 46
 
47
+/*!
48
+ * \brief Do loose routing as per RFC3261
49
+ * \param _m SIP message
50
+ * \param _mode - 0: try loose or strict routing; 1: try loose routing only
51
+ * \return negative on failure or preloaded, 1 on success
52
+ */
53
+int loose_route_mode(sip_msg_t* _m, int _mode);
54
+
55
+
47 56
 /*!
48 57
  * \brief Do loose routing as per RFC3261
49 58
  * \param _m SIP message
... ...
@@ -75,6 +75,7 @@ static int it_list_fixup(void** param, int param_no);
75 75
 /* wrapper functions */
76 76
 static int w_loose_route(struct sip_msg *, char *, char *);
77 77
 static int w_loose_route_preloaded(struct sip_msg *, char *, char *);
78
+static int w_loose_route_mode(struct sip_msg *, char *, char *);
78 79
 static int w_record_route(struct sip_msg *, char *, char *);
79 80
 static int w_record_route_preset(struct sip_msg *,char *, char *);
80 81
 static int w_record_route_advertised_address(struct sip_msg *, char *, char *);
... ...
@@ -100,6 +101,8 @@ static cmd_export_t cmds[] = {
100 101
 			REQUEST_ROUTE},
101 102
 	{"loose_route_preloaded", (cmd_function)w_loose_route_preloaded,0, 0, 0,
102 103
 			REQUEST_ROUTE},
104
+	{"loose_route_mode", (cmd_function)w_loose_route_mode, 1, fixup_igp_null, fixup_free_igp_null,
105
+			REQUEST_ROUTE},
103 106
 	{"record_route",         (cmd_function)w_record_route,		0, 0, 0,
104 107
 			REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE},
105 108
 	{"record_route",         (cmd_function)w_record_route, 		1, it_list_fixup, 0,
... ...
@@ -273,7 +276,7 @@ static int direction_fixup(void** param, int param_no)
273 276
  */
274 277
 static int w_loose_route(struct sip_msg *msg, char *p1, char *p2)
275 278
 {
276
-	return loose_route(msg);
279
+	return loose_route_mode(msg, 0);
277 280
 }
278 281
 
279 282
 /**
... ...
@@ -282,7 +285,7 @@ static int w_loose_route(struct sip_msg *msg, char *p1, char *p2)
282 285
 static int w_loose_route_preloaded(sip_msg_t *msg, char *p1, char *p2)
283 286
 {
284 287
 	int ret;
285
-	ret = loose_route(msg);
288
+	ret = loose_route_mode(msg, 0);
286 289
 	if(ret == RR_PRELOADED) {
287 290
 		return 1;
288 291
 	}
... ...
@@ -290,7 +293,20 @@ static int w_loose_route_preloaded(sip_msg_t *msg, char *p1, char *p2)
290 293
 }
291 294
 
292 295
 /**
293
- * wrapper for loose_route_(msg)
296
+ * wrapper for loose_route_mode(msg, mode)
297
+ */
298
+static int w_loose_route_mode(struct sip_msg *msg, char *pmode, char *p2)
299
+{
300
+	int vmode = 0;
301
+	if(fixup_get_ivalue(msg, (gparam_t*)pmode, &vmode) < 0) {
302
+		LM_ERR("failed to get the mode parameter\n");
303
+		return -1;
304
+	}
305
+	return loose_route_mode(msg, vmode);
306
+}
307
+
308
+/**
309
+ * wrapper for loose_route_preloaded(msg)
294 310
  */
295 311
 static int ki_loose_route_preloaded(sip_msg_t *msg)
296 312
 {
... ...
@@ -302,6 +318,14 @@ static int ki_loose_route_preloaded(sip_msg_t *msg)
302 318
 	return -1;
303 319
 }
304 320
 
321
+/**
322
+ * wrapper for loose_route_mode(msg, vmode)
323
+ */
324
+static int ki_loose_route_mode(sip_msg_t *msg, int vmode)
325
+{
326
+	return loose_route_mode(msg, vmode);
327
+}
328
+
305 329
 /**
306 330
  * common wrapper for record_route(msg, sparams)
307 331
  */
... ...
@@ -852,6 +876,11 @@ static sr_kemi_t sr_kemi_rr_exports[] = {
852 876
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
853 877
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
854 878
 	},
879
+	{ str_init("rr"), str_init("loose_route_mode"),
880
+		SR_KEMIP_INT, ki_loose_route_mode,
881
+		{ SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE,
882
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
883
+	},
855 884
 	{ str_init("rr"), str_init("remove_record_route"),
856 885
 		SR_KEMIP_INT, remove_record_route,
857 886
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,