Module: sip-router
Branch: tmp/build_request
Commit: 5c037f80bd047518c6bc879f33acad611014143a
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=5c037f8…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Tue Jul 21 11:58:51 2009 +0200
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).
---
modules/tm/tm.c | 9 ++++++---
modules/tm/uac.c | 25 ++++++++++++++-----------
modules/tm/uac.h | 6 ++++++
3 files changed, 26 insertions(+), 14 deletions(-)
diff --git a/modules/tm/tm.c b/modules/tm/tm.c
index 034b8c7..18565c1 100644
--- a/modules/tm/tm.c
+++ b/modules/tm/tm.c
@@ -435,7 +435,7 @@ static param_export_t params[]={
{"max_noninv_lifetime", PARAM_INT,
&default_tm_cfg.tm_max_noninv_lifetime},
{"noisy_ctimer", PARAM_INT, &default_tm_cfg.noisy_ctimer
},
{"auto_inv_100", PARAM_INT, &default_tm_cfg.tm_auto_inv_100
},
- {"auto_inv_100_reason", PARAM_STRING, &default_tm_cfg.tm_auto_inv_100_r
},
+ {"auto_inv_100_reason", PARAM_STRING, &default_tm_cfg.tm_auto_inv_100_r
},
{"unix_tx_timeout", PARAM_INT, &default_tm_cfg.tm_unix_tx_timeout
},
{"restart_fr_on_each_reply", PARAM_INT,
&default_tm_cfg.restart_fr_on_each_reply},
@@ -460,10 +460,8 @@ static param_export_t params[]={
{"cancel_b_method", PARAM_INT, &default_tm_cfg.cancel_b_flags},
{"reparse_on_dns_failover", PARAM_INT,
&default_tm_cfg.reparse_on_dns_failover},
{"on_sl_reply", PARAM_STRING|PARAM_USE_FUNC, fixup_on_sl_reply },
-
{"fr_inv_timer_next", PARAM_INT, &default_tm_cfg.fr_inv_timeout_next
},
{"contacts_avp", PARAM_STRING, &contacts_avp_param
},
-
{0,0,0}
};
@@ -768,6 +766,11 @@ static int mod_init(void)
LOG(L_ERR,"ERROR:tm:mod_init: failed to process AVP params\n");
return -1;
}
+#ifdef WITH_EVENT_LOCAL_REQUEST
+ goto_on_local_req=route_lookup(&event_rt, "tm:local-request");
+ if (goto_on_local_req>=0 && event_rt.rlist[goto_on_local_req]==0)
+ goto_on_local_req=-1; /* disable */
+#endif /* WITH_EVENT_LOCAL_REQUEST */
tm_init = 1;
return 0;
}
diff --git a/modules/tm/uac.c b/modules/tm/uac.c
index c3b49be..b1a79fa 100644
--- a/modules/tm/uac.c
+++ b/modules/tm/uac.c
@@ -90,6 +90,11 @@
#define FROM_TAG_LEN (MD5_LEN + 1 /* - */ + CRC16_LEN) /* length of FROM tags */
+#ifdef WITH_EVENT_LOCAL_REQUEST
+/* where to go for the local request route ("tm:local-request") */
+int goto_on_local_req=-1; /* default disabled */
+#endif /* WITH_EVEN_LOCAL_REQuEST */
+
static char from_tag[FROM_TAG_LEN + 1];
/*
@@ -200,7 +205,6 @@ static inline int t_uac_prepare(uac_req_t *uac_r,
#endif
long nhtype;
#ifdef WITH_EVENT_LOCAL_REQUEST
- int rt;
static struct sip_msg lreq;
char *buf1;
int buf_len1;
@@ -325,13 +329,12 @@ static inline int t_uac_prepare(uac_req_t *uac_r,
}
#ifdef WITH_EVENT_LOCAL_REQUEST
- /* todo: cache this at startup */
- rt = route_lookup(&event_rt, "tm:local-request");
- if (rt>=0 && event_rt.rlist[rt]!=NULL) {
- LM_DBG("executing event_route[tm:local-request]\n");
- if(build_sip_msg_from_buf(&lreq, buf, buf_len, inc_msg_no())==0) {
+ if (unlikely(goto_on_local_req>=0)) {
+ DBG("executing event_route[tm:local-request]\n");
+ if(likely(build_sip_msg_from_buf(&lreq, buf, buf_len, inc_msg_no())
+ == 0)) {
/* fill some field in sip_msg */
- if (set_dst_uri(&lreq, uac_r->dialog->hooks.next_hop)) {
+ if (unlikely(set_dst_uri(&lreq, uac_r->dialog->hooks.next_hop))) {
LM_ERR("failed to set dst_uri");
free_sip_msg(&lreq);
} else {
@@ -365,7 +368,7 @@ static inline int t_uac_prepare(uac_req_t *uac_r,
/* run the route */
backup_route_type = get_route_type();
set_route_type(LOCAL_ROUTE);
- run_top_route(event_rt.rlist[rt], &lreq, 0);
+ run_top_route(event_rt.rlist[goto_on_local_req], &lreq, 0);
set_route_type( backup_route_type );
/* restore original environment */
@@ -378,20 +381,20 @@ static inline int t_uac_prepare(uac_req_t *uac_r,
set_avp_list(AVP_TRACK_TO | AVP_CLASS_DOMAIN, backup_domain_to);
setsflagsval(sflag_bk);
- if (lreq.new_uri.s)
+ if (unlikely(lreq.new_uri.s))
{
pkg_free(lreq.new_uri.s);
lreq.new_uri.s=0;
lreq.new_uri.len=0;
}
- if (lreq.dst_uri.s)
+ if (unlikely(lreq.dst_uri.s))
{
pkg_free(lreq.dst_uri.s);
lreq.dst_uri.s=0;
lreq.dst_uri.len=0;
}
- if (lreq.add_rm || lreq.body_lumps) {
+ if (unlikely(lreq.add_rm || lreq.body_lumps)) {
LM_DBG("apply new updates to sip msg\n");
buf1 = build_req_buf_from_sip_req(&lreq,
(unsigned int*)&buf_len1,
diff --git a/modules/tm/uac.h b/modules/tm/uac.h
index 8106727..2f98aa8 100644
--- a/modules/tm/uac.h
+++ b/modules/tm/uac.h
@@ -73,6 +73,12 @@ typedef struct uac_req {
(_req)->cbp = (_cbp); \
} while (0)
+
+#ifdef WITH_EVENT_LOCAL_REQUEST
+/* where to go for the local request route ("tm:local-request") */
+extern int goto_on_local_req;
+#endif /* WITH_EVEN_LOCAL_REQuEST */
+
/*
* Function prototypes
*/