Skip to content

Commit c82dcbe

Browse files
committed
PN Support: Complete commit e7cf1d5
The fix in e7cf1d5 was not complete, as we must add both PN, non-PN branches as well as any pre-existing append_branches() into the t_wait_for_new_branches() wait count, otherwise the UAC-side transaction could end prematurely, before the PN-branch gets a chance to deliver and connect the call. (cherry picked from commit 6b05893)
1 parent ce9dbe4 commit c82dcbe

4 files changed

Lines changed: 35 additions & 8 deletions

File tree

lib/reg/lookup.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ lookup_rc lookup(struct sip_msg *req, udomain_t *d,
6262
int max_latency = 0, ruri_is_pushed = 0;
6363
unsigned int flags = 0;
6464
int rc, ret = LOOKUP_NO_RESULTS, have_pn_cts = 0, single_branch = 0;
65+
int pn_cts_sz;
66+
unsigned int dst_branches = 0;
6567
str sip_instance = STR_NULL, call_id = STR_NULL;
6668
regex_t *ua_re = NULL;
6769

@@ -78,6 +80,13 @@ lookup_rc lookup(struct sip_msg *req, udomain_t *d,
7880
max_latency = lookup_flags->max_latency;
7981
}
8082

83+
if (!(flags & REG_BRANCH_AOR_LOOKUP_FLAG))
84+
dst_branches += get_nr_branches();
85+
86+
if ((flags & REG_LOOKUP_NO_RURI_FLAG) &&
87+
req->first_line.type == SIP_REQUEST)
88+
dst_branches++;
89+
8190
single_branch = flags & REG_LOOKUP_NOBRANCH_FLAG;
8291

8392
if (flags & REG_BRANCH_AOR_LOOKUP_FLAG) {
@@ -150,6 +159,8 @@ lookup_rc lookup(struct sip_msg *req, udomain_t *d,
150159
goto done;
151160
} else if (rc == 2) {
152161
*pn_cts++ = *ptr;
162+
} else if (rc == 0) {
163+
dst_branches++;
153164
}
154165

155166
if (rc == 0 && single_branch)
@@ -160,13 +171,18 @@ lookup_rc lookup(struct sip_msg *req, udomain_t *d,
160171
&& (flags & REG_LOOKUP_GLOBAL_FLAG)) {
161172
for (ct = r->remote_aors; ct; ct = ct->next) {
162173
rc = push_branch(req, ct, &ruri_is_pushed);
163-
if (rc == 0 && single_branch)
164-
goto done;
174+
if (rc == 0) {
175+
dst_branches++;
176+
if (single_branch)
177+
goto done;
178+
}
165179
}
166180
}
167181

168182
if (pn_cts > cts) {
169-
rc = pn_awake_pn_contacts(req, cts, single_branch ? 1 : pn_cts - cts);
183+
pn_cts_sz = single_branch ? 1 : pn_cts - cts;
184+
rc = pn_awake_pn_contacts(req, cts, pn_cts_sz,
185+
dst_branches + pn_cts_sz);
170186
if (rc <= 0) {
171187
ret = (rc == 0 ? LOOKUP_STOP_SCRIPT : LOOKUP_ERROR);
172188
goto done;

lib/reg/pn.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,8 @@ static void pn_inject_branch(void)
595595
}
596596

597597

598-
int pn_awake_pn_contacts(struct sip_msg *req, ucontact_t **cts, int sz)
598+
int pn_awake_pn_contacts(struct sip_msg *req, ucontact_t **cts, int sz,
599+
unsigned int wait_branches)
599600
{
600601
ucontact_t **end;
601602
struct sip_uri puri;
@@ -625,7 +626,7 @@ int pn_awake_pn_contacts(struct sip_msg *req, ucontact_t **cts, int sz)
625626
return -1;
626627
}
627628

628-
if (tmb.t_wait_for_new_branches(req, (unsigned int)sz) != 1)
629+
if (tmb.t_wait_for_new_branches(req, wait_branches) != 1)
629630
LM_ERR("failed to enable waiting for new branches\n");
630631

631632
for (end = cts + sz; cts < end; cts++) {

lib/reg/pn.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,15 @@ int pn_append_rpl_fcaps(struct sip_msg *msg);
182182
* @req: the current SIP request
183183
* @cts: array of PN-enabled contacts
184184
* @sz: array size
185+
* @wait_branches: maximum number of outgoing branches to wait for, including
186+
* already selected destinations and PN-injected branches
185187
*
186188
* Return:
187189
* success: 1 if at least one PN was sent, 2 otherwise
188190
* failure: 0 on retransmission, -1 on internal error
189191
*/
190-
int pn_awake_pn_contacts(struct sip_msg *req, ucontact_t **cts, int sz);
192+
int pn_awake_pn_contacts(struct sip_msg *req, ucontact_t **cts, int sz,
193+
unsigned int wait_branches);
191194

192195

193196
/**

modules/mid_registrar/lookup.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ int mid_reg_lookup(struct sip_msg *req, udomain_t *d,
5353
struct sip_uri puri;
5454
unsigned int flags = 0;
5555
int ret = LOOKUP_ERROR, pos, ruri_is_pushed = 0;
56+
unsigned int dst_branches = 0;
5657
uint64_t contact_id;
5758
str aor;
5859
ucontact_t *ct;
@@ -64,7 +65,13 @@ int mid_reg_lookup(struct sip_msg *req, udomain_t *d,
6465
if (lookup_flags)
6566
flags = lookup_flags->flags;
6667

67-
ruri_is_pushed = flags & REG_LOOKUP_NO_RURI_FLAG;
68+
dst_branches = get_nr_branches();
69+
70+
if (flags & REG_LOOKUP_NO_RURI_FLAG) {
71+
ruri_is_pushed = 1;
72+
if (req->first_line.type == SIP_REQUEST)
73+
dst_branches++;
74+
}
6875

6976
if (!uri)
7077
uri = GET_RURI(req);
@@ -127,7 +134,7 @@ int mid_reg_lookup(struct sip_msg *req, udomain_t *d,
127134
break;
128135

129136
case 2:
130-
switch (pn_awake_pn_contacts(req, &ct, 1)) {
137+
switch (pn_awake_pn_contacts(req, &ct, 1, dst_branches + 1)) {
131138
case 1:
132139
ret = LOOKUP_PN_SENT;
133140
break;

0 commit comments

Comments
 (0)