<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<font face="monospace">Hi Ihor,<br>
<br>
Attached is a patch for doublechecking the AF of the forced socket
- if not matching, it will be discarded and a new socket will be
selected based on proto and AF family. It is not ideal, but let's
see.<br>
<br>
For doing DNS at the script level, see the IP transformation (it
is what you worked on previously):<br>
<a class="moz-txt-link-freetext"
href="https://www.opensips.org/Documentation/Script-Tran-3-6#ip.resolve">https://www.opensips.org/Documentation/Script-Tran-3-6#ip.resolve</a><br>
<br>
I agree, it might be useful to have it extended to (a) control the
AF and (b) to return maybe a list with all the IPs.<br>
<br>
On a much broader view, talking with Razvan on this topic, we were
brainstorming on a more generic and flexible approach for this
kind of problem (trying to force from script some kind of outbound
socket, but without knowing (yet) all the details on the
destination (like proto, port, IP). The idea here is to come up
with a kind of phony socket definition (phony as it will not be
used for listening on) to act as a routing table, to allow the
selection of a real socket based on a later determined port,
proto, etc.<br>
<br>
Like (in a json format):<br>
<br>
socket = my_socket { AF=4:udp:1.2.3.4:5060, AF=6: </font><font
face="monospace">udp:[2001:db8::1:0]:5060</font><font
face="monospace">}<br>
<br>
or something more complex, with proto filtering too:<br>
<br>
</font><font face="monospace">socket = my_socket {
AF=4,proto=udp:udp:1.2.3.4:5060, AF=6,proto=tcp: </font><font
face="monospace">tcp:[2001:db8::1:0]:5060</font><font
face="monospace">}<br>
<br>
<br>
The idea is to still have at the code level a `struct
socket_info`, but to be interpreted in a more generic way.<br>
<br>
Regards,</font>
<pre class="moz-signature" cols="72">Bogdan-Andrei Iancu
OpenSIPS Founder and Developer
<a class="moz-txt-link-freetext" href="https://www.opensips-solutions.com">https://www.opensips-solutions.com</a>
<a class="moz-txt-link-freetext" href="https://www.siphub.com">https://www.siphub.com</a></pre>
<div class="moz-cite-prefix">On 08.01.2026 18:33, Ihor Olkhovskyi
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:bfe8e910-9aca-4f14-8a0b-7f5682d4904d@gmail.com">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<p>Bogdan,</p>
<p>Thanks for this, I'm for sure will be happy to test a patch.</p>
<p>For the DNS/socket/AF, as I've said, I'm using now explicit
resolution of address with AF (resolve4 and resolve6) and acting
accordingly.</p>
<p>Still, sort of solution I see here -
<a class="moz-txt-link-freetext"
href="https://www.kamailio.org/docs/modules/devel/modules/ipops.html#ipops.f.dns_query"
moz-do-not-send="true">https://www.kamailio.org/docs/modules/devel/modules/ipops.html#ipops.f.dns_query</a>
, it also allows to deal with multiple A and AAAA records.</p>
<div class="moz-cite-prefix">Le 08/01/2026 à 16:55, Bogdan-Andrei
Iancu a écrit :<br>
</div>
<blockquote type="cite"
cite="mid:90feea59-e4b2-463b-bc40-e69a7ce3e3ed@opensips.org">
<meta http-equiv="Content-Type"
content="text/html; charset=UTF-8">
<font face="monospace">Hi Ihor,<br>
<br>
First, without the `</font><span style="font-family:monospace">dns_try_ipv6`
options, the DNS lookup will never return an IPv6 address (as
gethostbyname() will be used, which is AF_INET only).<br>
<br>
Now, going back to the original report: having the `</span><span
style="font-family:monospace">dns_try_ipv6` option on, you get
back an IPv6 address (from the DNS resolver). Now, checking
the code, if I'm not missing something obvious, I would say
the code allows sending to an IPv6 destination via an IPv4
socket :-/ ...which seems broken, IMHO. The code verifies only
the compatibility (between destination and sending socket)
when comes to the protocol, but not AF. <br>
For this case, will you be willing to test a small patch? this
will discard the forced socket if not compatible with the
destination (this is also done for the proto mismatch) - and a
new matching socket will be looked up.<br>
<br>
Now, about the multi IPs from DNS - if the DNS based fallback
is not turned off (as flag to t_relay), opensips will try to
do dns based failover (if the sending fails). But this will
not change whatever outbound socket was set...<br>
<br>
Basically, to wrap this up, your dilemma is like this: you
want to force a socket, but the DNS may give IPv4 or IPV6, so
you have no idea which socket to force...<br>
<br>
Regards, <br>
</span>
<pre class="moz-signature" cols="72">Bogdan-Andrei Iancu
OpenSIPS Founder and Developer
<a class="moz-txt-link-freetext"
href="https://www.opensips-solutions.com" moz-do-not-send="true">https://www.opensips-solutions.com</a>
<a class="moz-txt-link-freetext" href="https://www.siphub.com"
moz-do-not-send="true">https://www.siphub.com</a></pre>
<div class="moz-cite-prefix">On 02.01.2026 13:27, Ihor
Olkhovskyi wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAJTkRNs2WAtZF5Y2UL-rceGLkx2wuzZTXrecyxziTAu-EHAD7g@mail.gmail.com">
<meta http-equiv="content-type"
content="text/html; charset=UTF-8">
<div dir="ltr">
<div>Bohdan,</div>
<div><br>
</div>
<div>I've looked through code (resolve.c) and got an
impression, that only first resolved address is used along
the way. Means if destination address resolves to IPv6
with dns_try_ipv6=yes, it uses only IPv6 in packet
processing (namely for $du) and you cannot force IPv4
outbound socket later, cause no info about IPv4 is
present.</div>
<div>I've made a small hack to have a possibility to choose,
which address family I want to use (<a
href="https://github.com/igorolhovskiy/opensips-v6/commit/527d8d3d010d3a5a1e4b68475df45cb4e9f44604"
moz-do-not-send="true" class="moz-txt-link-freetext">https://github.com/igorolhovskiy/opensips-v6/commit/527d8d3d010d3a5a1e4b68475df45cb4e9f44604</a>)
but I don't like the solution.</div>
<div>Maybe I'm wrong, but my impression, that when DNS
resolution is happens, only 1 address (which includes the
family as well) is being used later with no possibility to
change it.</div>
<div>I can provide more logs soon (for relaying part), but
not sure it's the case here.</div>
<div><br>
</div>
<div>Regards,</div>
<div>Ihor</div>
</div>
<br>
<div class="gmail_quote gmail_quote_container">
<div dir="ltr" class="gmail_attr">Le lun. 29 déc. 2025
à 10:33, Bogdan-Andrei Iancu <<a
href="mailto:bogdan@opensips.org" moz-do-not-send="true"
class="moz-txt-link-freetext">bogdan@opensips.org</a>>
a écrit :<br>
</div>
<blockquote class="gmail_quote"
style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div> Hi Ihor,<br>
<br>
So, you say OpenSIPS picks the IPv6 address as
destination (confirmed by the err log), but you are not
sure what interface is to be used (even if you forced
the ipv4 one, it may be discarded by the internal fwd
logic).<br>
<br>
Could you provide debug level logs for the relaying part
?<br>
<br>
Regards,<br>
<pre cols="72">Bogdan-Andrei Iancu
OpenSIPS Founder and Developer
<a href="https://www.opensips-solutions.com" target="_blank"
moz-do-not-send="true" class="moz-txt-link-freetext">https://www.opensips-solutions.com</a>
<a href="https://www.siphub.com" target="_blank"
moz-do-not-send="true" class="moz-txt-link-freetext">https://www.siphub.com</a></pre>
<div>On 10.12.2025 17:58, Ihor Olkhovskyi wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div>Hello!</div>
<div><br>
</div>
<div>I'm trying to build ipv4/ipv6 bridge with
OpenSIPS 3.6.2.</div>
<div>I've declared the sockets like this:</div>
<div><span style="font-family:monospace"><br>
</span></div>
<div><span style="font-family:monospace"># v4
addresses<br>
socket=<a class="moz-txt-link-freetext"
href="tls:OPENSIPS_IPV4_ADDR:TLS_PORT"
moz-do-not-send="true">tls:OPENSIPS_IPV4_ADDR:TLS_PORT</a><br>
socket=<a class="moz-txt-link-freetext" href="wss:OPENSIPS_IPV4_">wss:OPENSIPS_IPV4_</a><a
class="moz-txt-link-freetext"
href="ADDR:WSS_PORT" moz-do-not-send="true">ADDR:WSS_PORT</a><br>
# v6 addresses<br>
socket=tls:[OPENSIPS_IPV6_ADDR]:TLS_PORT<br>
socket=wss:[OPENSIPS_IPV6_ADDR]:WSS_PORT<br>
dns_try_ipv6=yes<br>
# Always listen on localhost v4<br>
socket=<a class="moz-txt-link-freetext"
href="tls:127.0.0.1:TLS_PORT"
moz-do-not-send="true">tls:127.0.0.1:TLS_PORT</a></span></div>
<div><br>
</div>
<div>Means explicit to start on v4 and v6 addresses
for lately to change address family explicitly</div>
<div><br>
</div>
<div>OpenSIPS starts without any issues, but when I
try to do socket forcing with</div>
<div><br>
</div>
<div><span style="font-family:monospace">$socket_out
= "<a class="moz-txt-link-freetext" href="wss:OPENSIPS_IPV4_">wss:OPENSIPS_IPV4_</a><a
class="moz-txt-link-freetext"
href="ADDR:WSS_PORT" moz-do-not-send="true">ADDR:WSS_PORT</a>";</span></div>
<div><span style="font-family:monospace">t_relay();</span></div>
<div><br>
</div>
<div>I'm getting</div>
<div><br>
</div>
<div><span style="font-family:monospace"><a
class="moz-txt-link-freetext"
href="ERROR:proto_" moz-do-not-send="true">ERROR:proto_</a><a
moz-do-not-send="true">wss:ws_sync_connect</a>:
bind failed (22) Invalid argument<br>
<a class="moz-txt-link-freetext"
href="ERROR:proto_" moz-do-not-send="true">ERROR:proto_</a><a
moz-do-not-send="true">wss:ws_connect</a>:
connect failed<br>
<a class="moz-txt-link-freetext"
href="ERROR:proto_" moz-do-not-send="true">ERROR:proto_</a><a
moz-do-not-send="true">wss:proto_wss_send</a>:
connect failed</span></div>
<div><span style="font-family:monospace"><a
class="moz-txt-link-freetext"
href="tm:msg_send" moz-do-not-send="true">tm:msg_send</a>:
send() to EXTERNAL_IPV6(sic!) for proto wss/6
failed<br>
<a class="moz-txt-link-freetext"
href="tm:t_forward_nonack"
moz-do-not-send="true">tm:t_forward_nonack</a>:
sending request failed</span></div>
<div><br>
</div>
<div>So OpenSIPS is trying to send over IPv6. I
guess that is cause network address of RURI is v6
already, but DNS answers in dual-stack. If I
remove `<span style="font-family:monospace">dns_try_ipv6</span>`
it works, but how than I should work with v6?</div>
<div><br>
</div>
<div>What am I missing?</div>
<div><br>
</div>
<div>Thanks in advance!</div>
<div><br>
</div>
<span class="gmail_signature_prefix">-- </span><br>
<div dir="ltr" class="gmail_signature">
<div dir="ltr">Best regards,
<div>Ihor (Igor)<br>
</div>
</div>
</div>
</div>
<br>
<fieldset></fieldset>
<pre>_______________________________________________
Users mailing list
<a href="mailto:Users@lists.opensips.org" target="_blank"
moz-do-not-send="true" class="moz-txt-link-freetext">Users@lists.opensips.org</a>
<a href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a>
</pre>
</blockquote>
<br>
</div>
</blockquote>
</div>
<div><br clear="all">
</div>
<br>
<span class="gmail_signature_prefix">-- </span><br>
<div dir="ltr" class="gmail_signature">
<div dir="ltr">Best regards,
<div>Ihor (Igor)<br>
</div>
</div>
</div>
</blockquote>
<br>
</blockquote>
<pre class="moz-signature" cols="72">--
Regards,
Ihor</pre>
</blockquote>
<br>
</body>
</html>