Skip to content

Conversation

@jfirles
Copy link

@jfirles jfirles commented Aug 12, 2020

Some providers like Microsoft Teams require set the host part in the "Contact" header with the required value for auth the INVITE request, with this pull request we can change the contact host part of that header.

This is useful for multitenant scenarios.

Copy link
Collaborator

@mjerris mjerris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this entire block of code can be significantly simplified by building out vars for user and host and only building the invite contact one time.

Copy link
Collaborator

@mjerris mjerris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is right but totally untested:

if (zstr(tech_pvt->invite_contact)) {
	const char *contact_user = switch_channel_get_variable(channel, "sip_contact_user”);
	const char *contact_host = switch_channel_get_variable(channel, "sip_contact_host”);

	if (!contact_user && !contact_host) {
		tech_pvt->invite_contact = sofia_glue_get_profile_url(tech_pvt->profile, tech_pvt->mparams.remote_ip, tech_pvt->transport);
	} else {
		switch_port_t port = sofia_glue_transport_has_tls(tech_pvt->transport) ? tech_pvt->profile->tls_sip_port : tech_pvt->profile->extsipport

		if (zstr(contact_user)) {
			contact_user = “mod_sofia”;
		}

		if (zstr(contact_host)) {
			char *ip_addr = tech_pvt->profile->sipip;
			char *ipv6;

			if (!zstr(tech_pvt->mparams.remote_ip) && sofia_glue_check_nat(tech_pvt->profile, tech_pvt->mparams.remote_ip)) {
				ip_addr = tech_pvt->profile->extsipip;
			}

			ipv6 = strchr(ip_addr, ':');
			contact_host = switch_core_session_sprintf(session, “%s%s%s”, ipv6 ? "[" : "", ip_addr, ipv6 ? "]" : “”);
		}

		tech_pvt->invite_contact = switch_core_session_sprintf(session, "sip:%s@%s:%d", contact_user, contact_host, port);
	}
}

@crienzo crienzo requested a review from briankwest August 12, 2020 17:11
@wmasilva
Copy link
Contributor

wmasilva commented May 6, 2021

in current version, deecaae, when using a gateway we can set the contact-host parameter, so the contact is correctly changed.

I do find an issue, the incoming call from MS TEAMS, is authenticated by IP, so it doesn't hit the gateway detection so the replies we send back have the sipip address of our profile. We can set the sip-ip address to the domain name, but for multi-tenant is not valid.

We need to set it from the dialplan, the the incoming invite reach the default context.
(if there is a way of identifying a gateway by ip, please let me know :) )

I test this code and it doesn't solve the issue, the 200OK sent have in contact the profile ip.
i suggest the following fix: #1189

attach the log and my configuration simulating this scenario.
freeswitch-pr787.log.txt
freeswitch.xml.txt

@jfirles
Copy link
Author

jfirles commented May 7, 2021

I'm using it for multitenant scenario.

You must set the sip-ip to de base domain and in dialplan the sip_contact_host var.

Best regards.

@wmasilva
Copy link
Contributor

wmasilva commented May 7, 2021

Hi,
for outgoing calls it works, what i found is for incoming calls, the 200OK will have the value you put in sip-ip.

In the log, the variable is set correctly:
2021-05-06 19:16:36.395925 [DEBUG] mod_dptools.c:1685 SET sofia/a/[email protected] [sip_contact_host]=[vm.lab.local]

but the 200OK Contact uses value of sip-ip
Contact: sip:[email protected]:5060;transport=udp

for what i could test the "sofia_glue_do_invite" function is not called when receiving a call.

@jfirles
Copy link
Author

jfirles commented May 7, 2021

Hi,
for outgoing calls it works, what i found is for incoming calls, the 200OK will have the value you put in sip-ip.

In the log, the variable is set correctly:
2021-05-06 19:16:36.395925 [DEBUG] mod_dptools.c:1685 SET sofia/a/[email protected] [sip_contact_host]=[vm.lab.local]

but the 200OK Contact uses value of sip-ip
Contact: sip:[email protected]:5060;transport=udp

for what i could test the "sofia_glue_do_invite" function is not called when receiving a call.

Yes in the 200 OK the contact is the sip-ip value, but this works for Teams integration.
This is an example of 200 OK from my sbc to Teams:

SIP/2.0 200 OK
Via: SIP/2.0/TLS 52.114.76.76:5061;branch=z9hG4bK486d67fb;rport=7745
Record-Route: sip:sip-du-a-eu.pstnhub.microsoft.com:5061;transport=tls;lr
FROM: Teams Usersip:[email protected]:5061;user=phone;tag=9ef297297e464f578c6f5456b136d282
To: sip:[email protected]:5061;user=phone;tag=SUeUFXNj0BpZD
CALL-ID: 561c7283db84588fac46ec9bb5435997
CSEQ: 1 INVITE
Contact: sip:[email protected]:5061;transport=tls
User-Agent: Siptize Teams SBC
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, NOTIFY
Require: timer
Supported: timer, path, replaces
Allow-Events: talk, hold, conference, refer
Session-Expires: 300;refresher=uac
Content-Type: application/sdp
Content-Disposition: session
Content-Length: 793

SDP CONTENT

@shaunjstokes
Copy link
Contributor

shaunjstokes commented Feb 13, 2023

I've created an alternative PR for review that we propose, these changes have been used in a production environment for the last few years with thousands of calls per day.
#1962

I closed the original PR years ago #849 as there was no progress getting it merged. I'm still receiving messages from FS users for this so I'm having attempt to get it merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants