From 56df3a6b34a48de757548cde0e1d1b234b8bef6d Mon Sep 17 00:00:00 2001 From: Sam Machin Date: Thu, 6 Nov 2025 23:19:24 +0000 Subject: [PATCH] Fix/regtrunks (#118) * restore only use port if proxy is IPv4 address broke in this commit https://github.com/jambonz/sbc-sip-sidecar/commit/543f52d3dd6fb2070fb06b94d5c3ca70e649fb1f * use sip gateway host for DNS lookup of ephemeral gw and only if not an IP address --- lib/regbot.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/regbot.js b/lib/regbot.js index 89354dc..4d5b7c1 100644 --- a/lib/regbot.js +++ b/lib/regbot.js @@ -6,7 +6,7 @@ const { REGISTER_RESPONSE_REMOVE, JAMBONES_REGBOT_USER_AGENT } = require('./config'); -const {isValidDomainOrIP} = require('./utils'); +const {isValidDomainOrIP, isValidIPv4} = require('./utils'); const DEFAULT_EXPIRES = (parseInt(JAMBONES_REGBOT_DEFAULT_EXPIRES_INTERVAL) || 3600); const MIN_EXPIRES = (parseInt(JAMBONES_REGBOT_MIN_EXPIRES_INTERVAL) || 30); const assert = require('assert'); @@ -119,7 +119,8 @@ class Regbot { proxy = `sip:${this.outbound_sip_proxy};transport=${transport}`; this.logger.debug(`sending via proxy ${proxy}`); } else { - proxy = `sip:${this.ipv4}:${this.port};transport=${transport}`; + const isIPv4 = isValidIPv4(this.ipv4); + proxy = `sip:${this.ipv4}${isIPv4 ? `:${this.port}` : ''};transport=${transport}`; this.logger.debug(`sending to registrar ${proxy}`); } const req = await srf.request(`${scheme}:${this.sip_realm}`, { @@ -203,14 +204,14 @@ class Regbot { })); // for reg trunks, create ephemeral set of IP addresses for inbound gateways - if (this.trunk_type === 'reg') { + if (this.trunk_type === 'reg' && !isValidIPv4(this.ipv4)) { this.addresses = []; if (this.port) { - const addrs = await dnsResolverA(this.logger, this.sip_realm); + const addrs = await dnsResolverA(this.logger, this.ipv4); this.addresses.push(...addrs); } else { - const addrs = await dnsResolverSrv(this.logger, this.sip_realm, this.transport); + const addrs = await dnsResolverSrv(this.logger, this.ipv4, this.transport); this.addresses.push(...addrs); }