BelledonneCommunications / linphone-sdk

Mirror for linphone-sdk (https://gitlab.linphone.org/BC/public/linphone-sdk.git)
GNU Affero General Public License v3.0
106 stars 81 forks source link

incoming calls 200 OK sdp with private ip behind nat #29

Open wirelessmundi opened 5 years ago

wirelessmundi commented 5 years ago

On a new incoming call the 200OK SDP the rtp ip is the private ip and not the public ip.

from the logs i can't see that the stun or turn is called. I've enabled and try both (enabled ice, stun, turn...)

For outgoing calls is OK, the rtp ip in the sdp is the public ip.

This issue is the same as BelledonneCommunications/linphone-android#52, just open a new one because that is already closed.

Viish commented 5 years ago

Hi, Can you attach logs please ?

Viish commented 5 years ago

Hi, Can you check in your linphonerc_default or linphonerc_factory if the following setting exists and if yes if it is correctly set to 1 ? [net] enable_nat_helper=1

wirelessmundi commented 5 years ago

Hi, Is not enabled that option, setting it to 1 now. The strange is that for outgoing calls is ok.

Attach a log for a incoming call,. the contact IP is the correct one (public), but in the SDP RTP ip is the private IP.

linphone-incoming-call.txt

wirelessmundi commented 5 years ago

Same result.. my settings:

This file shall not contain path referencing package name, in order to be portable when app is renamed.

Paths to resources must be set from LinphoneManager, after creating LinphoneCore.

[net] mtu=1300

Because dynamic bitrate adaption can increase bitrate, we must allow "no limit"

download_bw=0 upload_bw=0 force_ice_disablement=0 enable_nat_helper=1

[sip] guess_hostname=1 register_only_when_network_is_up=1 auto_net_state_mon=1 auto_answer_replacing_calls=1 ping_with_options=0 use_cpim=1

Viish commented 5 years ago

Can you add a logs in which I can see the INVITE you received please ?

wirelessmundi commented 5 years ago

Sorry, i cut the log from the message "new incoming call... "...

linphone-incoming-call.txt

There is also another issue i cannot solve or detect why it happens.. it doesn't send any video when i answer the call, if the app sends video to the server, the server is able to detect the real ip and send back video to linphone, ignoring the IP in the SDP. (probably this could be open on a different thread)

Viish commented 5 years ago

Do you have stun and/or ICE enabled ?

wirelessmundi commented 5 years ago

yes, for outgoing calls linphone sets the public IP. Same configuration, attach outgoing call log.

linphone-outgoing-call.txt

wirelessmundi commented 5 years ago

a simple difference is that in incoming calls i don't see any stun/turn/ice messages like in outgoing:

... 2019-09-12 11:42:59:030 [liblinphone] MESSAGE ICE: gathering candidates from [45.165.36.27] using TURN 2019-09-12 11:42:59:031 [mediastreamer] MESSAGE ice: Send TURN allocate request: 0.0.0.0:7078 --> 45.165.36.27:3478 [cd2be8f888582a9dd52a3c3d] ...

wirelessmundi commented 5 years ago

Hi, Just in case i download and test the master branch and i did some more digging. Same resultas, but there is also a issue in the register process, the VIA header sent in the pkt is also the private IP, the Contact header is OK (so the issue is minor). Attach the log (logcat in android studio) when registering:

2019-09-13 12:06:54.131 18364-18364/org.linphone.debug I/Linphone: Changing [client] [SUBSCRIBE] transaction [0x7f4aa73a00], from state [COMPLETED] to [TERMINATED] 2019-09-13 12:06:54.132 18364-18364/org.linphone.debug I/Linphone: Client SUBSCRIBE transaction [0x7f4aa73a00] terminated 2019-09-13 12:06:54.133 18364-18364/org.linphone.debug I/Linphone: transaction [0x7f4aa73a00]: ending transaction background task with id=[2d46]. 2019-09-13 12:06:54.140 18364-18364/org.linphone.debug I/Linphone: bellesip_wake_lock_release(): Android wake lock released [ref=0x2d46] 2019-09-13 12:06:54.283 18364-18364/org.linphone.debug I/Linphone: linphone_core_find_auth_info(): returning auth info username=1000, realm=test.local 2019-09-13 12:06:54.283 18364-18364/org.linphone.debug I/Linphone: Auth info found for [1000] realm [test.local] 2019-09-13 12:06:54.288 18364-18364/org.linphone.debug I/Linphone: bellesip_wake_lock_acquire(): Android wake lock [belle-sip transaction(0x7f54848400)] acquired [ref=0x2d26] 2019-09-13 12:06:54.288 18364-18364/org.linphone.debug I/Linphone: transaction [0x7f54848400]: starting transaction background task with id=[2d26]. 2019-09-13 12:06:54.289 18364-18364/org.linphone.debug I/Linphone: Transaction [0x7f469dde40] deleted 2019-09-13 12:06:54.289 18364-18364/org.linphone.debug I/Linphone: Changing [client] [REGISTER] transaction [0x7f54848400], from state [INIT] to [TRYING] 2019-09-13 12:06:54.289 18364-18364/org.linphone.debug I/Linphone: channel [0x7f54990980]: message sent to [UDP://a3.commsmundi.com:5071], size: [858] bytes 2019-09-13 12:06:54.290 18364-18364/org.linphone.debug I/Linphone: REGISTER sip:test.local SIP/2.0 2019-09-13 12:06:54.290 18364-18364/org.linphone.debug I/Linphone: Via: SIP/2.0/UDP 192.168.1.70:46748;branch=z9hG4bK.0KynP3Wm1;rport 2019-09-13 12:06:54.290 18364-18364/org.linphone.debug I/Linphone: From: sip:1000@test.local;tag=6eMcjBxae 2019-09-13 12:06:54.290 18364-18364/org.linphone.debug I/Linphone: To: sip:1000@test.local 2019-09-13 12:06:54.290 18364-18364/org.linphone.debug I/Linphone: CSeq: 24 REGISTER 2019-09-13 12:06:54.290 18364-18364/org.linphone.debug I/Linphone: Call-ID: MLl-PwHBZw 2019-09-13 12:06:54.290 18364-18364/org.linphone.debug I/Linphone: Max-Forwards: 70 2019-09-13 12:06:54.290 18364-18364/org.linphone.debug I/Linphone: Supported: replaces, outbound, gruu 2019-09-13 12:06:54.290 18364-18364/org.linphone.debug I/Linphone: Accept: application/sdp 2019-09-13 12:06:54.290 18364-18364/org.linphone.debug I/Linphone: Accept: text/plain 2019-09-13 12:06:54.290 18364-18364/org.linphone.debug I/Linphone: Accept: application/vnd.gsma.rcs-ft-http+xml 2019-09-13 12:06:54.290 18364-18364/org.linphone.debug I/Linphone: Contact: sip:1000@94.60.157.122:46748;transport=udp;+sip.instance="" 2019-09-13 12:06:54.290 18364-18364/org.linphone.debug I/Linphone: Expires: 3600 2019-09-13 12:06:54.290 18364-18364/org.linphone.debug I/Linphone: User-Agent: LinphoneAndroid/4.1 (ZTE A2017G) LinphoneSDK/4.2-127-ge3c7e91 (remotes/origin/feature/debian10_job_build_and_test)

In this LAN i have a yealink, configured with the same stun server and this is what it sends:

REGISTER sip:test.local:5071 SIP/2.0 Via: SIP/2.0/UDP 94.60.157.122:64168;branch=z9hG4bK1565534189;rport From: "1001" sip:1001@test.local:5071;tag=1183517189 To: "1001" sip:1001@test.local:5071 Call-ID: 1_3910430573@192.168.1.100 CSeq: 1 REGISTER Contact: sip:1001@94.60.157.122:64168 Allow: INVITE, INFO, PRACK, ACK, BYE, CANCEL, OPTIONS, NOTIFY, REGISTER, SUBSCRIBE, REFER, PUBLISH, UPDATE, MESSAGE Max-Forwards: 70 User-Agent: Yealink SIP-T41S 66.84.0.80 Expires: 3600 Allow-Events: talk,hold,conference,refer,check-sync Content-Length: 0

wirelessmundi commented 5 years ago

also with only stun configure and ice disable the stun is not done.. it is a must to have ice enabled.

found that in function setIceEnabled it disables stun if you disable ice....

public void setIceEnabled(boolean enabled) { if (getLc() == null) return; NatPolicy nat = getOrCreateNatPolicy(); nat.enableIce(enabled); nat.enableStun(enabled); getLc().setNatPolicy(nat); }

Is there a issue why stun alone is not allowed?

Viish commented 5 years ago

Is there a issue why stun alone is not allowed?

This is a bug, I'll fix it.

wirelessmundi commented 5 years ago

ok, thanks. i found that in the SDK it checks in configuration for a NAT ip address:

     tmpstr=lp_config_get_string(lc->config,"net","nat_address",NULL);
if (tmpstr!=NULL && (strlen(tmpstr)<1)) tmpstr=NULL;
linphone_core_set_nat_address(lc,tmpstr);

I've try to set it, but no luck.. Any idea on how to use it? or it can't be use with android?

Viish commented 5 years ago

Hi, I fixed the STUN issue in Android project. Regarding the [net] nat_address setting, you have to set it directly in the linphonerc_factory.

wirelessmundi commented 5 years ago

Hi, Thanks, gonna try it.

I've try multiple settings to make the nat_address work without success. From the sdk source code it looks that nat_policy don't lookup for the this parameter... and i don't understand the differece between nat_policy and firewall_policy.

In configuration i set it: [net] mtu=1300

Because dynamic bitrate adaption can increase bitrate, we must allow "no limit"

download_bw=0 upload_bw=0 force_ice_disablement=0 enable_nat_helper=1 nat_address_ip=94.60.157.122 firewall_policy=nat_address

wirelessmundi commented 5 years ago

i've test the new version and the same stun, is not requested... is the same, private ip in the SDP.

also when answered i got a crash (create a differente issue BelledonneCommunications/linphone-android#775 ).

wirelessmundi commented 5 years ago

i keep digging... and found issues:

During my tests i notice that the nat_policy_ref parameter applied to the proxy_0 section was wrong but i couldn't get how to reproduce it, i remove the file and restart linphone and everything was ok.

I'm sill trying to make it work the nat_address, in many cases the user will connect from the same source address if you have any hint i appreciate the help.

Attach the logs and configuration for all the tests

linphonerc-stunonly.txt linphonerc-ice-stun.txt linphonerc-ice.txt linphone1.log-stunonly.txt linphone1.log-ice-stun.txt linphone1.log-ice.txt

wirelessmundi commented 5 years ago

i think i got it build against local sdk but i got the error:

error: cannot find symbol class Address

Any idea why?

Viish commented 5 years ago

If it cannot find the Address class (and most probably all the other) it means you have an issue with the AAR you generated... Unless you really want to make changes in the SDK I think it's best to keep using the maven artifacts.

wirelessmundi commented 5 years ago

true, yes i wanted to try to fix the stun issue by myself and purpose you the patch. In older version i managed to do it by simple change the order where the nat where done inside the function linphone_call_init_media_streams.

i think this is something similar, the order the nat is done for the incoming call. The outgoing call with ice it works ok, so the resolution for the stun server is done correctly.

Viish commented 5 years ago

We just fixed an issue that could be yours: https://gitlab.linphone.org/BC/public/linphone/merge_requests/455#note_13902

wirelessmundi commented 5 years ago

thanks, let me try. I could make it work local sdk... i'm going to use sdk version 4.2-134-ge59695d from your maven repository.

Viish commented 5 years ago

The fix is only in maven SDK version 4.2-143-gfa00b73 or higher.

wirelessmundi commented 5 years ago

hum... i couldn't find that version.. checking it on https://linphone.org/snapshots/maven_repository/org/linphone/linphone-sdk-android/

wirelessmundi commented 5 years ago

finally i got to compile the sdk.

Some issues i found:

Checking the conf:

[nat_policy_1] ref=qjXOqrkb5fykIWe stun_server=a3.commsmundi.com protocols=stun

[nat_policy_2] ref=0wsL4vDyh-GBhAi stun_server=a3.commsmundi.com protocols=ice

[proxy_0] ... nat_policy_ref=0wsL4vDyh-GBhAi

The stun is not configure under the nat_policy used for the account. with that configuration the ice candidates offer only private ip for outgoing call,

With stun only, uncheck the enable ice in linphone, the private ip is the one offer in the SDP: c=IN IP4 192.168.1.70

I manually force the stun,ice, and that solve the issue for outgoing call.

for incoming call the issue is not solved.

BTW: i set enable_nat_helper=1 in linphonerc_factory.

wirelessmundi commented 5 years ago

when using only stun for outgoing an incoming calls i got the error:

2019-09-20 14:14:21.552 28147-28147/org.linphone.debug E/Linphone: Bind socket to 0.0.0.0:7078 failed: Address already in use

This is from the stun, when it try to check open the socket the ports (audio, video) are already reserved in function, initializeStreams() in MediaSession::configure(), that is call before the stun.

By moving the initializeStreams() to after the nat detection fix the issue. I can now use stun and the correct public IP is send in the SDP.

I also test with ice, but no luck, for outgoing calls OK, but for incoming calls no.

Attach my patch if it help you to solve the issue also for ice. linphoneSDK_fix_resolvestun.txt

Viish commented 5 years ago

Please open this issue on linphone repository as it isn't Android related.

webrtcccccc commented 4 years ago

ios app has the same issue, incoming calls 200 OK sdp with private ip behind nat.

KyronNextLevel commented 4 years ago

Issue related moved from Gitlab : "in android app found an issue with stun/nat not resolving when answering an incoming call, the 200 OK sent in the SDP contains the private IP. Attach a full call where it happens: linphone-incoming-call1.txt

Please let me know if you need more information or testing. Thanks."

alex-eri commented 3 years ago

Stun works on Linux but not in Android for now.

alex-eri commented 3 years ago

On Andorid If i use proxy media phone-to-phone calls works, but phone-to-pbx fails with codecs. If proxy media disabled and ice enabled - there no video\audio. If ice disabled there is one way video\audio

alex-eri commented 3 years ago

My logs from linhome - incoming call works, but call from linhome out without ice candidates.


2021-08-14 01:16:01:339 [/liblinphone] MESSAGE ICE state is IceStateNotActivated for stream#0 [audio] in state [Stopped]
2021-08-14 01:16:01:339 [/liblinphone] MESSAGE ICE state is IceStateNotActivated for stream#1 [video] in state [Stopped]
2021-08-14 01:16:04:498 [/liblinphone] MESSAGE ICE state is IceStateNotActivated for stream#0 [audio] in state [Stopped]
2021-08-14 01:16:04:499 [/mediastreamer] MESSAGE Stun packet sent for session [0x87b35000]
2021-08-14 01:16:04:499 [/mediastreamer] MESSAGE Stun packet sent on rtcp for session [0x87b35000]
2021-08-14 01:16:04:873 [/mediastreamer] MESSAGE Stun packet sent for session [0x87b33000]
2021-08-14 01:16:04:873 [/mediastreamer] MESSAGE Stun packet sent on rtcp for session [0x87b33000]
2021-08-14 01:16:04:876 [/mediastreamer] MESSAGE Stun packet sent for session [0x87b35000]
2021-08-14 01:16:04:877 [/mediastreamer] MESSAGE Stun packet sent on rtcp for session [0x87b35000]
disolaterX commented 1 year ago

@Viish Hi it's still the same behavior till now have this not yet fixed some how