tm: transaction uses number of branches specified by max_branches global parameter
authorDaniel-Constantin Mierla <miconda@gmail.com>
Fri, 17 Oct 2014 09:06:41 +0000 (11:06 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Fri, 17 Oct 2014 09:06:41 +0000 (11:06 +0200)
- the number of UACs per transaction is based on max_branches global
  parameter

modules/tm/h_table.c
modules/tm/h_table.h
modules/tm/t_fwd.c
modules/tm/t_lookup.c
modules/tm/timer.c
modules/tm/tm.c

index 051c326..d0d2d5b 100644 (file)
@@ -290,7 +290,7 @@ static void inline init_branches(struct cell *t)
        unsigned int i;
        struct ua_client *uac;
 
-       for(i=0;i<MAX_BRANCHES;i++)
+       for(i=0;i<sr_dst_max_branches;i++)
        {
                uac=&t->uac[i];
                uac->request.my_T = t;
@@ -313,21 +313,29 @@ struct cell*  build_cell( struct sip_msg* p_msg )
 #ifdef WITH_XAVP
        sr_xavp_t** xold;
 #endif
+       unsigned int cell_size;
 
-       /* allocs a new cell, add space for md5 (MD5_LEN - sizeof(struct cell.md5)) */
-       new_cell = (struct cell*)shm_malloc( sizeof( struct cell )+
-                       MD5_LEN-sizeof(((struct cell*)0)->md5) );
+       /* allocs a new cell, add space for:
+        * md5 (MD5_LEN - sizeof(struct cell.md5))
+        * uac (sr_dst_max_banches * sizeof(struct ua_client) ) */
+       cell_size = sizeof( struct cell ) + MD5_LEN - sizeof(((struct cell*)0)->md5)
+                               + (sr_dst_max_branches * sizeof(struct ua_client));
+
+       new_cell = (struct cell*)shm_malloc( cell_size );
        if  ( !new_cell ) {
                ser_error=E_OUT_OF_MEM;
                return NULL;
        }
 
        /* filling with 0 */
-       memset( new_cell, 0, sizeof( struct cell ) );
+       memset( new_cell, 0, cell_size );
 
        /* UAS */
        new_cell->uas.response.my_T=new_cell;
        init_rb_timers(&new_cell->uas.response);
+       /* UAC */
+       new_cell->uac = (struct ua_client*)((char*)new_cell + sizeof(struct cell)
+                                                       + MD5_LEN - sizeof(((struct cell*)0)->md5));
        /* timers */
        init_cell_timers(new_cell);
 
index 42551bb..23d005f 100644 (file)
@@ -427,7 +427,7 @@ typedef struct cell
        /* UA Server */
        struct ua_server  uas;
        /* UA Clients */
-       struct ua_client  uac[ MAX_BRANCHES ];
+       struct ua_client  *uac;
        
        /* store transaction state to be used for async transactions */
        struct async_state async_backup;
@@ -461,7 +461,7 @@ typedef struct cell
 #endif
        ticks_t end_of_life; /* maximum lifetime */
 
-       /* nr of replied branch; 0..MAX_BRANCHES=branch value,
+       /* nr of replied branch; 0..sr_dst_max_branches=branch value,
         * -1 no reply, -2 local reply */
        short relayed_reply_branch;
 
index 61b6e6a..1e61183 100644 (file)
@@ -746,7 +746,7 @@ int add_blind_uac( /*struct cell *t*/ )
        }
 
        branch=t->nr_of_outgoings;      
-       if (branch==MAX_BRANCHES) {
+       if (branch==sr_dst_max_branches) {
                LOG(L_ERR, "ERROR: add_blind_uac: "
                        "maximum number of branches exceeded\n");
                return -1;
@@ -811,7 +811,7 @@ int add_uac( struct cell *t, struct sip_msg *request, str *uri,
 #endif /* TM_UAC_FLAGS */
 
        branch=t->nr_of_outgoings;
-       if (branch==MAX_BRANCHES) {
+       if (branch==sr_dst_max_branches) {
                LOG(L_ERR, "ERROR: add_uac: maximum number of branches exceeded\n");
                ret=ser_error=E_TOO_MANY_BRANCHES;
                goto error;
@@ -898,7 +898,7 @@ static int add_uac_from_buf( struct cell *t, struct sip_msg *request,
        unsigned int len;
 
        branch=t->nr_of_outgoings;
-       if (branch==MAX_BRANCHES) {
+       if (branch==sr_dst_max_branches) {
                LOG(L_ERR, "ERROR: add_uac_from_buf: maximum number of branches"
                                        " exceeded\n");
                ret=ser_error=E_TOO_MANY_BRANCHES;
@@ -1060,7 +1060,7 @@ int add_uac_dns_fallback(struct cell *t, struct sip_msg* msg,
                                        return ret;
                                }
                        }
-                       if (t->nr_of_outgoings >= MAX_BRANCHES){
+                       if (t->nr_of_outgoings >= sr_dst_max_branches){
                                LOG(L_ERR, "ERROR: add_uac_dns_fallback: maximum number of "
                                                        "branches exceeded\n");
                                if (lock_replies)
index cb3a720..79b1083 100644 (file)
@@ -936,7 +936,7 @@ int t_reply_matching( struct sip_msg *p_msg , int *p_branch )
        if (unlikely(reverse_hex2int(hashi, hashl, &hash_index)<0
                ||hash_index>=TABLE_ENTRIES
                || reverse_hex2int(branchi, branchl, &branch_id)<0
-               ||branch_id>=MAX_BRANCHES
+               || branch_id>=sr_dst_max_branches
                || loopl!=MD5_LEN)
        ) {
                DBG("DEBUG: t_reply_matching: poor reply labels %d label %d "
index 6f1a597..7856570 100644 (file)
@@ -491,7 +491,7 @@ inline static void final_response_handler(  struct retr_buf* r_buf,
 #ifdef EXTRA_DEBUG
        DBG("DEBUG: final_response_handler:stop retr. and send CANCEL (%p)\n", t);
 #endif
-       if ((r_buf->branch < MAX_BRANCHES) && /* r_buf->branch is always >=0 */
+       if ((r_buf->branch < sr_dst_max_branches) && /* r_buf->branch is always >=0 */
                        (t->uac[r_buf->branch].last_received==0) &&
                        (t->uac[r_buf->branch].request.buffer!=NULL) /* not a blind UAC */
        ){
index 54bcc78..f3568c1 100644 (file)
@@ -801,9 +801,9 @@ static int mod_init(void)
 
        /* checking if we have sufficient bitmap capacity for given
           maximum number of  branches */
-       if (MAX_BRANCHES+1>31) {
+       if (sr_dst_max_branches+1>31) {
                LOG(L_CRIT, "Too many max UACs for UAC branch_bm_t bitmap: %d\n",
-                       MAX_BRANCHES );
+                       sr_dst_max_branches );
                return -1;
        }