From 1fd8e12180fd8080d2ef8596d4b4a565d5b46239 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Fri, 3 Apr 2015 14:03:00 +0200 Subject: [PATCH] change local ip management to take into account new bind_address settings for both media and sig --- coreapi/linphonecall.c | 34 +++++++++++++++++++++++----------- coreapi/private.h | 3 ++- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index 1c03ec931..84d3e5b63 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -555,19 +555,19 @@ static void transfer_already_assigned_payload_types(SalMediaDescription *old, Sa } static const char *linphone_call_get_bind_ip_for_stream(LinphoneCall *call, int stream_index){ - const char *bind_ip = lp_config_get_string(call->core->config,"rtp","bind_address",call->af==AF_INET6 ? "::0" : "0.0.0.0"); ; + const char *bind_ip = lp_config_get_string(call->core->config,"rtp","bind_address",call->af==AF_INET6 ? "::0" : "0.0.0.0"); if (stream_index<2 && call->media_ports[stream_index].multicast_ip[0]!='\0'){ if (call->dir==LinphoneCallOutgoing){ /*as multicast sender, we must decide a local interface to use to send multicast, and bind to it*/ - bind_ip=call->localip; + bind_ip=call->media_localip; } } return bind_ip; } static const char *linphone_call_get_public_ip_for_stream(LinphoneCall *call, int stream_index){ - const char *public_ip=call->localip; + const char *public_ip=call->media_localip; if (stream_index<2 && call->media_ports[stream_index].multicast_ip[0]!='\0') public_ip=call->media_ports[stream_index].multicast_ip; @@ -610,7 +610,7 @@ void linphone_call_make_local_media_description(LinphoneCore *lc, LinphoneCall * md->session_ver=(old_md ? (old_md->session_ver+1) : (rand() & 0xfff)); md->nb_streams=(call->biggestdesc ? call->biggestdesc->nb_streams : 1); - strncpy(md->addr,call->localip,sizeof(md->addr)); + strncpy(md->addr,call->media_localip,sizeof(md->addr)); if (linphone_address_get_username(addr)) /*might be null in case of identity without userinfo*/ strncpy(md->username,linphone_address_get_username(addr),sizeof(md->username)); if (subject) strncpy(md->name,subject,sizeof(md->name)); @@ -906,18 +906,30 @@ static void linphone_call_get_local_ip(LinphoneCall *call, const LinphoneAddress } if (linphone_core_get_firewall_policy(call->core)==LinphonePolicyUseNatAddress && (ip=linphone_core_get_nat_address_resolved(call->core))!=NULL){ - strncpy(call->localip,ip,LINPHONE_IPADDR_SIZE); + strncpy(call->media_localip,ip,LINPHONE_IPADDR_SIZE); + strncpy(call->sig_localip,ip,LINPHONE_IPADDR_SIZE); return; } #ifdef BUILD_UPNP else if (call->core->upnp != NULL && linphone_core_get_firewall_policy(call->core)==LinphonePolicyUseUpnp && linphone_upnp_context_get_state(call->core->upnp) == LinphoneUpnpStateOk) { ip = linphone_upnp_context_get_external_ipaddress(call->core->upnp); - strncpy(call->localip,ip,LINPHONE_IPADDR_SIZE); + strncpy(call->media_localip,ip,LINPHONE_IPADDR_SIZE); + strncpy(call->sig_localip,ip,LINPHONE_IPADDR_SIZE); return; } #endif //BUILD_UPNP - linphone_core_get_local_ip(call->core, af, dest, call->localip); + /*first nominal use case*/ + linphone_core_get_local_ip(call->core, af, dest, call->media_localip); + strncpy(call->sig_localip,call->media_localip,LINPHONE_IPADDR_SIZE); + + /*next, sometime, override from config*/ + if ((ip=lp_config_get_string(call->core->config,"rtp","bind_address",NULL))) + strncpy(call->media_localip,ip,LINPHONE_IPADDR_SIZE); + if ((ip=lp_config_get_string(call->core->config,"sip","bind_address",NULL))) + strncpy(call->sig_localip,ip,LINPHONE_IPADDR_SIZE); + + return; } static void linphone_call_destroy(LinphoneCall *obj); @@ -3739,7 +3751,7 @@ void linphone_call_zoom_video(LinphoneCall* call, float zoom_factor, float* cx, static LinphoneAddress *get_fixed_contact(LinphoneCore *lc, LinphoneCall *call , LinphoneProxyConfig *dest_proxy){ LinphoneAddress *ctt=NULL; LinphoneAddress *ret=NULL; - const char *localip=call->localip; + //const char *localip=call->localip; /* first use user's supplied ip address if asked*/ if (linphone_core_get_firewall_policy(lc)==LinphonePolicyUseNatAddress){ @@ -3762,9 +3774,9 @@ static LinphoneAddress *get_fixed_contact(LinphoneCore *lc, LinphoneCall *call , ctt=linphone_core_get_primary_contact_parsed(lc); if (ctt!=NULL){ /*otherwise use supplied localip*/ - linphone_address_set_domain(ctt,localip); - linphone_address_set_port(ctt,linphone_core_get_sip_port(lc)); - ms_message("Contact has been fixed using local ip"/* to %s",ret*/); + linphone_address_set_domain(ctt,NULL/*localip*/); + linphone_address_set_port(ctt,-1/*linphone_core_get_sip_port(lc)*/); + ms_message("Contact has not been fixed stack will do"/* to %s",ret*/); ret=ctt; } } diff --git a/coreapi/private.h b/coreapi/private.h index ccb43d24c..09062267d 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -227,7 +227,8 @@ struct _LinphoneCall{ LinphoneAddress *me; /*Either from or to based on call dir*/ SalOp *op; SalOp *ping_op; - char localip[LINPHONE_IPADDR_SIZE]; /* our best guess for local ipaddress for this call */ + char sig_localip[LINPHONE_IPADDR_SIZE]; /* our best guess for local sig ipaddress for this call */ + char media_localip[LINPHONE_IPADDR_SIZE]; /* our best guess for local media ipaddress for this call */ LinphoneCallState state; LinphoneCallState prevstate; LinphoneCallState transfer_state; /*idle if no transfer*/