Skip to content

Commit d771e81

Browse files
committed
b2b_logic: provide custom max_duration at bridge time
Many thanks to Erhan Onur Sendag(@ErhanOnur) for reporting and providing a patch for the first version and also to Norm Brandinger (@NormB) for providing the final patch! Close #3800
1 parent a4984bd commit d771e81

4 files changed

Lines changed: 37 additions & 8 deletions

File tree

modules/b2b_logic/b2b_logic.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ enum b2b_tuple_state {
8383
#define B2BL_BR_FLAG_PENDING_SDP (1<<8)
8484
#define B2BL_BR_FLAG_BR_MSG_LATE_BYE (1<<9)
8585

86+
/* Internal flag: set when a per-bridge lifetime was explicitly provided
87+
* via the max_duration flag on b2b_bridge(). Prevents b2b_add_dlginfo()
88+
* from overwriting the per-bridge lifetime with the global max_duration
89+
* modparam value when the bridged call is confirmed (200 OK). */
90+
#define B2BL_BR_FLAG_EXPLICIT_LIFETIME (1<<10)
91+
8692
/* reply flags */
8793
#define B2BL_RPL_FLAG_PASS_CONTACT (1<<0)
8894

modules/b2b_logic/bridging.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,8 +1679,11 @@ int b2bl_bridge(struct sip_msg* msg, b2bl_tuple_t* tuple,
16791679

16801680
if (lifetime)
16811681
{
1682-
tuple->lifetime = lifetime + get_ticks();
1683-
LM_DBG("Lifetime defined = [%d]\n", tuple->lifetime);
1682+
unsigned int ticks = get_ticks();
1683+
tuple->lifetime = lifetime + ticks;
1684+
tuple->bridge_flags |= B2BL_BR_FLAG_EXPLICIT_LIFETIME;
1685+
LM_DBG("Per-bridge lifetime set = [%u] (duration=%d, ticks=%u)\n",
1686+
tuple->lifetime, lifetime, ticks);
16841687
}
16851688
else
16861689
tuple->lifetime = -1;
@@ -2025,6 +2028,9 @@ int b2bl_bridge_2calls(str* key1, str* key2)
20252028
}
20262029
e1->sdp_type = B2BL_SDP_LATE;
20272030
e1->state = 0;
2031+
/* Clear any per-bridge lifetime from a previous b2b_bridge() call;
2032+
* this bridge path always uses the global max_duration */
2033+
tuple->bridge_flags &= ~B2BL_BR_FLAG_EXPLICIT_LIFETIME;
20282034
tuple->state = B2B_BRIDGING_STATE;
20292035
if(max_duration)
20302036
tuple->lifetime = get_ticks() + max_duration;
@@ -2413,6 +2419,9 @@ int b2bl_bridge_msg(struct sip_msg* msg, str* key, int entity_no,
24132419
}
24142420
bridging_entity->sdp_type = B2BL_SDP_NORMAL;
24152421
bridging_entity->state = 0;
2422+
/* Clear any per-bridge lifetime from a previous b2b_bridge() call;
2423+
* this bridge path always uses the global max_duration */
2424+
tuple->bridge_flags &= ~B2BL_BR_FLAG_EXPLICIT_LIFETIME;
24162425
if(max_duration)
24172426
tuple->lifetime = get_ticks() + max_duration;
24182427
else

modules/b2b_logic/doc/b2b_logic_admin.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,10 @@ modparam("b2b_logic", "update_period", 60)
333333
<section id="param_max_duration" xreflabel="max_duration">
334334
<title><varname>max_duration</varname> (int)</title>
335335
<para>
336-
The maximum duration of a call.
336+
The maximum duration of a call. This value is applied as the default
337+
lifetime for all B2B sessions. It can be overridden on a per-bridge
338+
basis by using the <emphasis>max_duration</emphasis> flag of the
339+
<xref linkend="func_b2b_bridge"/> function.
337340
</para>
338341
<para>
339342
<emphasis>Default value is <quote>12 * 3600 (12 hours)</quote>.</emphasis>
@@ -782,7 +785,9 @@ b2b_client_new("client1", "sip:alice@opensips.org");
782785
<listitem><para>
783786
<emphasis>max_duration=[nn]</emphasis> - Maximum duration of the B2B
784787
session. If the lifetime expires, the B2BUA will send BYE messages to both
785-
ends and delete the record. Example: "max_duration=300".
788+
ends and delete the record. This per-bridge value takes precedence over the
789+
global <xref linkend="param_max_duration"/> module parameter.
790+
Example: "max_duration=300".
786791
</para></listitem>
787792
<listitem><para>
788793
<emphasis>notify</emphasis> - Enable rfc3515 NOTIFY to inform the agent

modules/b2b_logic/logic.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,19 @@ int b2b_add_dlginfo(str* key, str* entity_key, int src, b2b_dlginfo_t* dlginfo,
161161
return -1;
162162
}
163163
/* a connected call */
164-
if(max_duration)
165-
tuple->lifetime = get_ticks() + max_duration;
166-
else
167-
tuple->lifetime = 0;
164+
if (tuple->bridge_flags & B2BL_BR_FLAG_EXPLICIT_LIFETIME) {
165+
/* A per-bridge lifetime was set via the max_duration flag on
166+
* b2b_bridge(); preserve it instead of overwriting with the
167+
* global max_duration modparam */
168+
LM_DBG("Preserving per-bridge lifetime [%u] for tuple [%.*s]\n",
169+
tuple->lifetime, tuple->key ? tuple->key->len : 0,
170+
tuple->key ? tuple->key->s : "");
171+
} else {
172+
if(max_duration)
173+
tuple->lifetime = get_ticks() + max_duration;
174+
else
175+
tuple->lifetime = 0;
176+
}
168177
entity = b2bl_search_entity(tuple, entity_key, src, &ent_head);
169178
if(entity == NULL)
170179
{

0 commit comments

Comments
 (0)