Skip to content

Commit f137755

Browse files
committed
mid_registrar: persist TCP connections for absorbed REGISTERs
When `tcp_persistent_flag` is enabled, TCP connection lifetime is updated only after a forwarded REGISTER receives a successful response. Absorbed REGISTERs return a local 200 OK without extending the receiving connection, leaving new or refreshed connections at the default lifetime. Apply the UAC Contact expiration to the TCP connection in the `quick_reply` path, matching the existing behavior for forwarded registrations.
1 parent cb0dcbb commit f137755

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

‎modules/mid_registrar/save.c‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,39 @@ void calc_contact_expires(struct sip_msg* _m, param_t* _ep, int* _e,
9090
LM_DBG("expires: %d\n", *_e);
9191
}
9292

93+
static void persist_tcp_connection(struct sip_msg *msg)
94+
{
95+
contact_t *ct;
96+
struct sip_uri uri;
97+
int expires, max_expires = 0;
98+
99+
if (!is_tcp_based_proto(msg->rcv.proto) ||
100+
!(msg->flags & tcp_persistent_flag))
101+
return;
102+
103+
for (ct = get_first_contact(msg); ct; ct = get_next_contact(ct)) {
104+
calc_contact_expires(msg, ct->expires, &expires, 1);
105+
if (expires <= 0)
106+
continue;
107+
108+
if (parse_uri(ct->uri.s, ct->uri.len, &uri) < 0) {
109+
LM_ERR("failed to parse contact <%.*s>\n",
110+
ct->uri.len, ct->uri.s);
111+
continue;
112+
}
113+
114+
if (is_tcp_based_proto(uri.proto) && expires > max_expires)
115+
max_expires = expires;
116+
}
117+
118+
if (max_expires > 0) {
119+
LM_DBG("ensure TCP conn lifetime of at least %d sec\n",
120+
max_expires + 10);
121+
trans_set_dst_attr(&msg->rcv, DST_FCNTL_SET_LIFETIME,
122+
(void *)(long)(max_expires + 10));
123+
}
124+
}
125+
93126
/* with the optionally added outgoing timeout extension
94127
*
95128
* @_e: output param (UNIX timestamp) - expiration time on the main registrar
@@ -2695,6 +2728,8 @@ int mid_reg_save(struct sip_msg *msg, udomain_t *d, struct save_flags *flags,
26952728
if (unlock_udomain)
26962729
ul.unlock_udomain(d, &sctx.aor);
26972730

2731+
persist_tcp_connection(msg);
2732+
26982733
/* quick SIP reply */
26992734
if (!(sctx.flags & REG_SAVE_NOREPLY_FLAG))
27002735
send_reply(msg, sctx.flags);

0 commit comments

Comments
 (0)