Main request is the first branch.
So consider changed $ru after lookup as the first (0) branch.
Other branches will be appended as addition.

On Fri, 8 Sept 2023, 14:03 Benoît Panizzon, <benoit.panizzon@imp.ch> wrote:
Hi Yuriy

> You also can filter it in the request route and not create branch wich
> doesn't belong this server ( you can achieve that by verifying ucl
> variable details), or making it UDP branch being forwarded to proper
> server which handles the particular connection.

I have started trying to solve this in request route.

I'm still truggling on how to distinguish local and non local
registrations.

I have 4 CPE registered to the same AOR.

kamclt ul show [AOR] does show they are registered. 3 on the local
registrar (with a socket) and one with socket [not set].

If I repeat on the other registrar I get matching information. One with
a socket, the other three are [not set].

So trying to understand the hard way, what happens:

        $var(i)=0;
        while($var(i)<=$branch(count))
        {
                $var(socket) = $(ulc(aor=>socket)[$var(i)]);
                xlog("L_INFO", "$cfg(route): DEBUG BEFORE: IDX: $var(i) TOTAL: $branch(count) URI: $(branch(uri)[$var(i)]) Socket: $var(socket)\n");
                $var(i) = $var(i) + 1;
        }

        $var(i)=0;
        while($var(i)<=$branch(count))
        {
                $var(socket) = $(ulc(aor=>socket)[$var(i)]);
                xlog("L_INFO", "$cfg(route): DEBUG REMOVE: IDX: $var(i) TOTAL: $branch(count) URI: $(branch(uri)[$var(i)]) Socket: $var(socket)\n");
                if ($var(socket) == 0) {
                        xlog("L_INFO", "$cfg(route): Dropping Branch IDX $var(i) URI: $(branch(uri)[$var(i)]) Socket: $var(socket)\n");
                        $(branch(uri)[$var(i)]) = $null;
                } else {
                        $var(i) = $var(i) + 1; # do NOT increment index as the branches got renumbered.
                }
        }

        $var(i)=0;
        while($var(i)<=$branch(count))
        {
                $var(socket) = $(ulc(aor=>socket)[$var(i)]);
                xlog("L_INFO", "$cfg(route): DEBUG AFTER: IDX: $var(i) TOTAL: $branch(count) URI: $(branch(uri)[$var(i)]) Socket: $var(socket)\n");
                $var(i) = $var(i) + 1;
        }

What I did not yet understand.

$branch(count) is 3 !

So, does kamailio only consider the 3 registrations WITH a socket?
Or is this the index starting with 0, thus 4 contacts?

When I do $(branch(uri)[$var(i)]) = $null; then $branch(count) is decremented. I suppose because the next contact takes that index, this is why I do NOT increment $var(i).

But I then get no $(branch(uri)[$var(i)]) on the highest index, suggesting that I only see 3 contacts, not all 4 of them.

Indeed, my 'BEFORE' loop did not output the contact registered on the other registrar.

So WHY is there still the INVITE being sent to the fourth, non local contact?

=> Confused!

--
Mit freundlichen Grüssen

-Benoît Panizzon- @ HomeOffice und normal erreichbar
--
I m p r o W a r e   A G    -    Leiter Commerce Kunden
______________________________________________________

Zurlindenstrasse 29             Tel  +41 61 826 93 00
CH-4133 Pratteln                Fax  +41 61 826 93 01
Schweiz                         Web  http://www.imp.ch
______________________________________________________