Skip to content

Commit 13b7504

Browse files
committed
nathelper: port add_contact_alias() and handle_ruri_alias()
Those are slightly better version of the fix_nated_contact() originating from Kamailio. The problem with fix_nated_contact() is that it could cause RURI for in-dialog requests contain a different IP address as compared to the Contact in the initial INVITE. Most endpoints are fine with that, however tere are some, notably MS Teams, which would reject such request with: SIP/2.0 500 Internal Server Error Reason: Q.850;cause=47;text="76a7afc3-d033-4988-9000-f70b41e4db1b;RURI in request has invalid FQDN value" The full exchange when using fix_nated_contact() is as follows: UA->OpenSIPS (initial INVITE): opensips[42757]: RECEIVED message from 10.2.80.32:5060: INVITE sip:[...] Contact: <sip:[...]@10.2.80.22:5060> ^^^^^^^^^^ OpenSIPS->UA: SIP/2.0 100 Giving it a try SIP/2.0 200 OK UA->OpenSIPS: ACK sip:[...] OpenSIPS->UA (re-INVITE): opensips[42759]: SENDING message to 10.2.80.32:5060: INVITE sip:[...]@10.2.80.32:5060 SIP/2.0 ^^^^^^^^^^ UA->OpenSIPS: SIP/2.0 500 Internal Server Error
1 parent b7e02bb commit 13b7504

File tree

3 files changed

+559
-2
lines changed

3 files changed

+559
-2
lines changed

modules/nathelper/README

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ nathelper Module
4343
1.5.3. add_rcv_param([flag]),
4444
1.5.4. fix_nated_register()
4545
1.5.5. nat_uac_test(flags)
46+
1.5.6. add_contact_alias([ip_addr, port, proto])
47+
1.5.7. handle_ruri_alias()
4648

4749
1.6. Exported MI Functions
4850

@@ -91,7 +93,9 @@ nathelper Module
9193
1.22. add_rcv_paramer usage
9294
1.23. fix_nated_register usage
9395
1.24. nat_uac_test usage
94-
1.25. nh_enable_ping usage
96+
1.25. add_contact_alias usage
97+
1.26. handle_ruri_alias usage
98+
1.27. nh_enable_ping usage
9599

96100
Chapter 1. Admin Guide
97101

@@ -595,6 +599,46 @@ if (nat_uac_test("private-contact,private-sdp"))
595599
xlog("SIP message is NAT'ed (Call-ID: $ci)\n");
596600
...
597601

602+
1.5.6. add_contact_alias([ip_addr, port, proto])
603+
604+
Adds a standards-compliant “;alias=” parameter to the Contact URI
605+
containing the signalling source IP, port and transport protocol
606+
when they differ from the advertised Contact address.
607+
608+
Meaning of the parameters is as follows:
609+
* ip_addr (string, optional) - IP to encode inside the alias. If
610+
omitted, the message source IP is used.
611+
* port (string, optional) - port to encode inside the alias. If
612+
omitted, the message source port is used.
613+
* proto (string, optional) - transport protocol to encode inside
614+
the alias (for example “udp”, “tcp”, “tls”, “sctp”, “ws” or
615+
“wss”). If omitted, the transport used to receive the message is
616+
used.
617+
618+
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
619+
BRANCH_ROUTE and FAILURE_ROUTE.
620+
621+
Example 1.25. add_contact_alias usage
622+
...
623+
if (!add_contact_alias("$si", "$sp", "tcp")) {
624+
xlog("[NAT] cannot create alias\n");
625+
}
626+
...
627+
628+
1.5.7. handle_ruri_alias()
629+
630+
If the Request URI contains an “alias” parameter, the destination
631+
URI is set based on its encoded IP, port and transport, and the
632+
parameter is removed from the URI.
633+
634+
This function can be used from REQUEST_ROUTE, BRANCH_ROUTE and
635+
LOCAL_ROUTE.
636+
637+
Example 1.26. handle_ruri_alias usage
638+
...
639+
handle_ruri_alias();
640+
...
641+
598642
1.6. Exported MI Functions
599643

600644
1.6.1. nh_enable_ping
@@ -607,7 +651,7 @@ if (nat_uac_test("private-contact,private-sdp"))
607651
parameter value greater than 0 or disables natping if
608652
parameter value is 0.
609653

610-
Example 1.25. nh_enable_ping usage
654+
Example 1.27. nh_enable_ping usage
611655
...
612656
$ opensips-cli -x mi nh_enable_ping
613657
Status:: 1

modules/nathelper/doc/nathelper_admin.xml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,55 @@ fix_nated_register();
833833
if (nat_uac_test("private-contact,private-sdp"))
834834
xlog("SIP message is NAT'ed (Call-ID: $ci)\n");
835835
...
836+
</programlisting>
837+
</example>
838+
</section>
839+
<section id="nathelper.f.add_contact_alias">
840+
<title>
841+
<function moreinfo="none">add_contact_alias([ip_addr, port, proto])</function>
842+
</title>
843+
<para>
844+
Adds an “alias” URI parameter to the Contact address that encodes the
845+
signalling source IP, port and transport protocol when they differ from
846+
the advertised Contact address.
847+
</para>
848+
<itemizedlist>
849+
<listitem><para><emphasis>ip_addr</emphasis> (string, optional) - IP to encode
850+
inside the alias. If omitted, the source IP of the SIP message is used.</para></listitem>
851+
<listitem><para><emphasis>port</emphasis> (string, optional) - port to encode inside
852+
the alias. If omitted, the source port of the SIP message is used.</para></listitem>
853+
<listitem><para><emphasis>proto</emphasis> (string, optional) - transport protocol to
854+
encode inside the alias (e.g. “udp”, “tcp”, “tls”, “sctp”, “ws” or “wss”). If omitted,
855+
the transport used to receive the message is used.</para></listitem>
856+
</itemizedlist>
857+
<para>This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, BRANCH_ROUTE and
858+
FAILURE_ROUTE.</para>
859+
<example>
860+
<title><function>add_contact_alias</function> usage</title>
861+
<programlisting format="linespecific">
862+
...
863+
if (!add_contact_alias("$si", "$sp", "tcp")) {
864+
xlog("[NAT] cannot create alias\n");
865+
}
866+
...
867+
</programlisting>
868+
</example>
869+
</section>
870+
<section id="nathelper.f.handle_ruri_alias">
871+
<title>
872+
<function moreinfo="none">handle_ruri_alias()</function>
873+
</title>
874+
<para>
875+
Parses an “alias” parameter from the Request URI, sets the destination URI based on its
876+
contents and removes the parameter from the Request URI.
877+
</para>
878+
<para>This function can be used from REQUEST_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.</para>
879+
<example>
880+
<title><function>handle_ruri_alias</function> usage</title>
881+
<programlisting format="linespecific">
882+
...
883+
handle_ruri_alias();
884+
...
836885
</programlisting>
837886
</example>
838887
</section>

0 commit comments

Comments
 (0)