Browse code

tm: local req. route: cache route id

- resolve the route name only once, at startup (mod_init since
this route name is fixed) and cache it.
- more likely()/unlikely() added to the ifs (optimizing for no
local req. route and local req. route not changing the message).

Andrei Pelinescu-Onciul authored on 21/07/2009 09:58:51
Showing 3 changed files
... ...
@@ -435,7 +435,7 @@ static param_export_t params[]={
435 435
 	{"max_noninv_lifetime", PARAM_INT, &default_tm_cfg.tm_max_noninv_lifetime},
436 436
 	{"noisy_ctimer",        PARAM_INT, &default_tm_cfg.noisy_ctimer          },
437 437
 	{"auto_inv_100",        PARAM_INT, &default_tm_cfg.tm_auto_inv_100       },
438
-	{"auto_inv_100_reason", PARAM_STRING, &default_tm_cfg.tm_auto_inv_100_r  },    
438
+	{"auto_inv_100_reason", PARAM_STRING, &default_tm_cfg.tm_auto_inv_100_r  },
439 439
 	{"unix_tx_timeout",     PARAM_INT, &default_tm_cfg.tm_unix_tx_timeout    },
440 440
 	{"restart_fr_on_each_reply", PARAM_INT,
441 441
 									&default_tm_cfg.restart_fr_on_each_reply},
... ...
@@ -460,10 +460,8 @@ static param_export_t params[]={
460 460
 	{"cancel_b_method",     PARAM_INT, &default_tm_cfg.cancel_b_flags},
461 461
 	{"reparse_on_dns_failover", PARAM_INT, &default_tm_cfg.reparse_on_dns_failover},
462 462
 	{"on_sl_reply",         PARAM_STRING|PARAM_USE_FUNC, fixup_on_sl_reply   },
463
-
464 463
 	{"fr_inv_timer_next",   PARAM_INT, &default_tm_cfg.fr_inv_timeout_next   },
465 464
 	{"contacts_avp",        PARAM_STRING, &contacts_avp_param                },
466
-
467 465
 	{0,0,0}
468 466
 };
469 467
 
... ...
@@ -768,6 +766,11 @@ static int mod_init(void)
768 766
 		LOG(L_ERR,"ERROR:tm:mod_init: failed to process AVP params\n");
769 767
 		return -1;
770 768
 	}
769
+#ifdef WITH_EVENT_LOCAL_REQUEST
770
+	goto_on_local_req=route_lookup(&event_rt, "tm:local-request");
771
+	if (goto_on_local_req>=0 && event_rt.rlist[goto_on_local_req]==0)
772
+		goto_on_local_req=-1; /* disable */
773
+#endif /* WITH_EVENT_LOCAL_REQUEST */
771 774
 	tm_init = 1;
772 775
 	return 0;
773 776
 }
... ...
@@ -90,6 +90,11 @@
90 90
 
91 91
 #define FROM_TAG_LEN (MD5_LEN + 1 /* - */ + CRC16_LEN) /* length of FROM tags */
92 92
 
93
+#ifdef WITH_EVENT_LOCAL_REQUEST
94
+/* where to go for the local request route ("tm:local-request") */
95
+int goto_on_local_req=-1; /* default disabled */
96
+#endif /* WITH_EVEN_LOCAL_REQuEST */
97
+
93 98
 static char from_tag[FROM_TAG_LEN + 1];
94 99
 
95 100
 /*
... ...
@@ -200,7 +205,6 @@ static inline int t_uac_prepare(uac_req_t *uac_r,
200 205
 #endif
201 206
 	long nhtype;
202 207
 #ifdef WITH_EVENT_LOCAL_REQUEST
203
-	int rt;
204 208
 	static struct sip_msg lreq;
205 209
 	char *buf1;
206 210
 	int buf_len1;
... ...
@@ -325,13 +329,12 @@ static inline int t_uac_prepare(uac_req_t *uac_r,
325 329
 	}
326 330
 
327 331
 #ifdef WITH_EVENT_LOCAL_REQUEST
328
-	/* todo: cache this at startup */
329
-	rt = route_lookup(&event_rt, "tm:local-request");
330
-	if (rt>=0 && event_rt.rlist[rt]!=NULL) {
331
-		LM_DBG("executing event_route[tm:local-request]\n");
332
-		if(build_sip_msg_from_buf(&lreq, buf, buf_len, inc_msg_no())==0) {
332
+	if (unlikely(goto_on_local_req>=0)) {
333
+		DBG("executing event_route[tm:local-request]\n");
334
+		if(likely(build_sip_msg_from_buf(&lreq, buf, buf_len, inc_msg_no())
335
+					== 0)) {
333 336
 			/* fill some field in sip_msg */
334
-			if (set_dst_uri(&lreq, uac_r->dialog->hooks.next_hop)) {
337
+			if (unlikely(set_dst_uri(&lreq, uac_r->dialog->hooks.next_hop))) {
335 338
 				LM_ERR("failed to set dst_uri");
336 339
 				free_sip_msg(&lreq);
337 340
 			} else {
... ...
@@ -365,7 +368,7 @@ static inline int t_uac_prepare(uac_req_t *uac_r,
365 368
 				/* run the route */
366 369
 				backup_route_type = get_route_type();
367 370
 				set_route_type(LOCAL_ROUTE);
368
-				run_top_route(event_rt.rlist[rt], &lreq, 0);
371
+				run_top_route(event_rt.rlist[goto_on_local_req], &lreq, 0);
369 372
 				set_route_type( backup_route_type );
370 373
 
371 374
 				/* restore original environment */
... ...
@@ -378,20 +381,20 @@ static inline int t_uac_prepare(uac_req_t *uac_r,
378 381
 				set_avp_list(AVP_TRACK_TO | AVP_CLASS_DOMAIN, backup_domain_to);
379 382
 				setsflagsval(sflag_bk);
380 383
 
381
-				if (lreq.new_uri.s)
384
+				if (unlikely(lreq.new_uri.s))
382 385
 				{
383 386
 					pkg_free(lreq.new_uri.s);
384 387
 					lreq.new_uri.s=0;
385 388
 					lreq.new_uri.len=0;
386 389
 				}
387
-				if (lreq.dst_uri.s)
390
+				if (unlikely(lreq.dst_uri.s))
388 391
 				{
389 392
 					pkg_free(lreq.dst_uri.s);
390 393
 					lreq.dst_uri.s=0;
391 394
 					lreq.dst_uri.len=0;
392 395
 				}
393 396
 
394
-				if (lreq.add_rm || lreq.body_lumps) {
397
+				if (unlikely(lreq.add_rm || lreq.body_lumps)) {
395 398
 					LM_DBG("apply new updates to sip msg\n");
396 399
 					buf1 = build_req_buf_from_sip_req(&lreq,
397 400
 							(unsigned int*)&buf_len1,
... ...
@@ -73,6 +73,12 @@ typedef struct uac_req {
73 73
 		(_req)->cbp = (_cbp); \
74 74
 	} while (0)
75 75
 
76
+
77
+#ifdef WITH_EVENT_LOCAL_REQUEST
78
+/* where to go for the local request route ("tm:local-request") */
79
+extern int goto_on_local_req;
80
+#endif /* WITH_EVEN_LOCAL_REQuEST */
81
+
76 82
 /*
77 83
  * Function prototypes
78 84
  */