瀏覽代碼

- changed build_dlg_ack and build_local_ack to directly return the destination
of the ack (they have to find it anyway for building the via), thus avoiding
a double dns lookup for next_hop.

Andrei Pelinescu-Onciul 18 年之前
父節點
當前提交
33f7438a50
共有 3 個文件被更改,包括 41 次插入26 次删除
  1. 17 13
      modules/tm/t_msgbuilder.c
  2. 4 3
      modules/tm/t_msgbuilder.h
  3. 20 10
      modules/tm/t_reply.c

+ 17 - 13
modules/tm/t_msgbuilder.c

@@ -42,6 +42,8 @@
  *              uri2sock replaced with uri2dst (andrei)
  * 2006-08-11  build_dlg_ack: use the first dns ip for which a send_sock
  *              is found (andrei)
+ * 2007-03-15  build_dls_ack: removed next_hop and replaced by dst to avoid
+ *               resolving nexthop twice (andrei)
  */
 
 #include "defs.h"
@@ -362,12 +364,13 @@ static inline int get_contact_uri(struct sip_msg* msg, str* uri)
 
      /*
       * The function creates an ACK to 200 OK. Route set will be created
-      * and parsed and next_hop parameter will contain the uri to which the
-      * request should be send. The function is used by tm when it generates
-      * local ACK to 200 OK (on behalf of applications using uac)
+      * and parsed and the dst parameter will contain the destination to which 
+	  * the request should be send. The function is used by tm when it 
+	  * generates local ACK to 200 OK (on behalf of applications using uac)
       */
-char *build_dlg_ack(struct sip_msg* rpl, struct cell *Trans, unsigned int branch,
-		    str* to, unsigned int *len, str *next_hop)
+char *build_dlg_ack(struct sip_msg* rpl, struct cell *Trans, 
+					unsigned int branch, str* to, unsigned int *len,
+					struct dest_info* dst)
 {
 	char *req_buf, *p, *via;
 	unsigned int via_len;
@@ -377,7 +380,7 @@ char *build_dlg_ack(struct sip_msg* rpl, struct cell *Trans, unsigned int branch
 	struct hostport hp;
 	struct rte* list;
 	str contact, ruri, *cont;
-	struct dest_info dst;
+	str next_hop;
 #ifdef USE_DNS_FAILOVER
 	struct dns_srv_handle dns_h;
 #endif
@@ -386,7 +389,7 @@ char *build_dlg_ack(struct sip_msg* rpl, struct cell *Trans, unsigned int branch
 		return 0;
 	}
 	
-	if (process_routeset(rpl, &contact, &list, &ruri, next_hop) < 0) {
+	if (process_routeset(rpl, &contact, &list, &ruri, &next_hop) < 0) {
 		return 0;
 	}
 	
@@ -411,22 +414,23 @@ char *build_dlg_ack(struct sip_msg* rpl, struct cell *Trans, unsigned int branch
 #ifdef USE_DNS_FAILOVER
 	if (use_dns_failover){
 		dns_srv_handle_init(&dns_h);
-		if ((uri2dst(&dns_h , &dst, rpl, next_hop, PROTO_NONE)==0) ||
-				(dst.send_sock==0)){
+		if ((uri2dst(&dns_h , dst, rpl, &next_hop, PROTO_NONE)==0) ||
+				(dst->send_sock==0)){
 			dns_srv_handle_put(&dns_h);
 			LOG(L_ERR, "build_dlg_ack: no socket found\n");
 			goto error;
 		}
 		dns_srv_handle_put(&dns_h); /* not needed any more */
 	}else{
-		if ((uri2dst(0 , &dst, rpl, next_hop, PROTO_NONE)==0) ||
-				(dst.send_sock==0)){
+		if ((uri2dst(0 , dst, rpl, &next_hop, PROTO_NONE)==0) ||
+				(dst->send_sock==0)){
 			LOG(L_ERR, "build_dlg_ack: no socket found\n");
 			goto error;
 		}
 	}
 #else
-	if ( (uri2dst( &dst, rpl, next_hop, PROTO_NONE)==0) || (dst.send_sock==0)){
+	if ( (uri2dst( dst, rpl, &next_hop, PROTO_NONE)==0) ||
+			(dst->send_sock==0)){
 			LOG(L_ERR, "build_dlg_ack: no socket found\n");
 		goto error;
 	}
@@ -436,7 +440,7 @@ char *build_dlg_ack(struct sip_msg* rpl, struct cell *Trans, unsigned int branch
 	branch_str.s = branch_buf;
 	branch_str.len = branch_len;
 	set_hostport(&hp, 0);
-	via = via_builder(&via_len, &dst, &branch_str, 0, &hp);
+	via = via_builder(&via_len, dst, &branch_str, 0, &hp);
 	if (!via) {
 		LOG(L_ERR, "build_dlg_ack: No via header got from builder\n");
 		goto error;

+ 4 - 3
modules/tm/t_msgbuilder.h

@@ -77,12 +77,13 @@ char *build_uac_request(  str msg_type, str dst, str from,
 
 /*
  * The function creates an ACK to 200 OK. Route set will be created
- * and parsed and next_hop parameter will contain uri the which the
+ * and parsed and the dst parameter will contain the destination to which the
  * request should be send. The function is used by tm when it generates
  * local ACK to 200 OK (on behalf of applications using uac
  */
-char *build_dlg_ack(struct sip_msg* rpl, struct cell *Trans, unsigned int branch,
-		    str* to, unsigned int *len, str *next_hop);
+char *build_dlg_ack(struct sip_msg* rpl, struct cell *Trans, 
+					unsigned int branch, str* to, unsigned int *len,
+					struct dest_info *dst);
 
 
 /*

+ 20 - 10
modules/tm/t_reply.c

@@ -79,6 +79,8 @@
  * 2006-10-16  aggregate all the authorization headers/challenges when
  *               the final response is 401 or 407 (andrei)
  * 2007-03-08  membar_write() used in update_totag_set(...)(andrei)
+ * 2007-03-15  build_local_ack: removed next_hop and replaced with dst to 
+ *              avoid resolving next_hop twice (andrei)
  *
  */
 
@@ -331,12 +333,16 @@ static char *build_ack(struct sip_msg* rpl,struct cell *trans,int branch,
 
 
 /*
- * The function builds an ACK to 200 OK of local transactions, honor the
- * route set, the URI to which the message should be sent will be returned
- * in next_hop parameter
+ * The function builds an ACK to 200 OK of local transactions, honoring the
+ * route set.
+ * The destination to which the message should be sent will be returned
+ * in the dst parameter.
+ * returns 0 on error and a pkg_malloc'ed buffer with length in ret_len
+ *  and intended destination in dst on success.
  */
-static char *build_local_ack(struct sip_msg* rpl, struct cell *trans, int branch,
-			     unsigned int *ret_len, str* next_hop)
+static char *build_local_ack(struct sip_msg* rpl, struct cell *trans, 
+								int branch, unsigned int *ret_len,
+								struct dest_info*  dst)
 {
 	str to;
 	if (parse_headers(rpl, HDR_EOH_F, 0) == -1 || !rpl->to) {
@@ -346,10 +352,12 @@ static char *build_local_ack(struct sip_msg* rpl, struct cell *trans, int branch
 
 	to.s = rpl->to->name.s;
 	to.len = rpl->to->len;
-	return build_dlg_ack(rpl, trans, branch, &to, ret_len, next_hop);
+	return build_dlg_ack(rpl, trans, branch, &to, ret_len, dst);
 }
 
 
+
+#if 0 /* candidate for removal --andrei */
      /*
       * The function is used to send a localy generated ACK to INVITE
       * (tm generates the ACK on behalf of application using UAC
@@ -391,6 +399,8 @@ static int send_local_ack(struct sip_msg* msg, str* next_hop,
 #endif
 	return msg_send(&dst, ack, ack_len);
 }
+#endif
+
 
 
 static int _reply_light( struct cell *trans, char* buf, unsigned int len,
@@ -1554,7 +1564,7 @@ int reply_received( struct sip_msg  *p_msg )
 	branch_bm_t cancel_bitmap;
 	struct ua_client *uac;
 	struct cell *t;
-	str next_hop;
+	struct dest_info  lack_dst;
 	avp_list_t* backup_user_from, *backup_user_to;
 	avp_list_t* backup_domain_from, *backup_domain_to;
 	avp_list_t* backup_uri_from, *backup_uri_to;
@@ -1608,10 +1618,10 @@ int reply_received( struct sip_msg  *p_msg )
 					SEND_PR_BUFFER(&uac->request, ack, ack_len);
 					shm_free(ack);
 				}
-			} else if (is_local(t) /*&& msg_status >= 200*/) {
-				ack = build_local_ack(p_msg, t, branch, &ack_len, &next_hop);
+			} else if (is_local(t) /*&& 200 <= msg_status < 300*/) {
+				ack = build_local_ack(p_msg, t, branch, &ack_len, &lack_dst);
 				if (ack) {
-					if (send_local_ack(p_msg, &next_hop, ack, ack_len) < 0) {
+					if (msg_send(&lack_dst, ack, ack_len)<0){
 						LOG(L_ERR, "Error while sending local ACK\n");
 					}
 					shm_free(ack);