Call routing loop between multiple PBXs

I have 2x PBXs that are geographically seperated and connected via IAX trunk via VPN. Both sites have 3x analogue lines that are connected to a capped service. DAHDi g0 controls these 3 lines and DAHDi g1 controls the remainder of the lines for non capped service.

I have my outbound routes using the r0 trunk for those capped lines first, then failover to the IAX trunk to attempt to find a line on the partner PBX’s r0 trunk, then failover back to the original PBX’s r1 trunk.

Problem I’m having is that an outbound call from PBX-A will try r0 and get a busy signal, then it passes the call via IAX trunk to the partner PBX. The partner attempts r0 and gets a busy signal so it then passes the call back to the original PBX. The original PBX will then try to use the same outbound route again which leads to the whole process repeating and effectively looping forever.

I’m looking for a way to catch the call as it is returned and move onto the next trunk which will use the DAHDi r1.

If anyone has any ideas, I’m all ears :slight_smile:

I was using the wrong approach.

Changed the from-internal context of IAX trunks’ peer details to a custom context [from-partner] at both ends. Created a matching context in extensions_custom.conf with an enten=> to catch internal bound calls and drop them into from-internal context and a couple of other extens to catch external bound calls, strip leading digits from the number before attempting to dial the DAHDI queues depending on the value of the stripped digits.

On the partner IAX trunks I prepended a 4 digit number to represent which DAHDI trunk to use on the Dialing system.

Works a treat.