From 92a7d6695ccc350bfc1eae2cadc797edf3baae98 Mon Sep 17 00:00:00 2001 From: Yann Diorcet Date: Mon, 7 Jan 2013 16:08:09 +0100 Subject: [PATCH] Set external port equal to local port the first time --- coreapi/callbacks.c | 2 +- coreapi/linphonecall.c | 2 +- coreapi/linphonecore.c | 16 ++++++++-------- coreapi/private.h | 2 +- coreapi/upnp.c | 11 +++++++++-- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/coreapi/callbacks.c b/coreapi/callbacks.c index 4eec5be3d..3a21e5a6d 100644 --- a/coreapi/callbacks.c +++ b/coreapi/callbacks.c @@ -432,7 +432,7 @@ static void call_accept_update(LinphoneCore *lc, LinphoneCall *call){ linphone_core_update_upnp_from_remote_media_description(call, rmd); linphone_core_update_local_media_description_from_upnp(call->localdesc,call->upnp_session); } -#endif +#endif //BUILD_UPNP sal_call_accept(call->op); md=sal_call_get_final_media_description(call->op); if (md && !sal_media_description_empty(md)) diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index ec76311a6..d8de9659c 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -287,7 +287,7 @@ void linphone_call_make_local_media_description(LinphoneCore *lc, LinphoneCall * if(call->upnp_session != NULL) { linphone_core_update_local_media_description_from_upnp(md, call->upnp_session); } -#endif +#endif //BUILD_UPNP linphone_address_destroy(addr); call->localdesc=md; if (old_md) sal_media_description_unref(old_md); diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 7abce8e96..1da9ad5cd 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -1219,7 +1219,7 @@ static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vta #endif #ifdef BUILD_UPNP upnp_context_init(lc); -#endif +#endif //BUILD_UPNP if (lc->vtable.display_status) lc->vtable.display_status(lc,_("Ready")); lc->auto_net_state_mon=lc->sip_conf.auto_net_state_mon; @@ -1320,7 +1320,7 @@ void linphone_core_get_local_ip(LinphoneCore *lc, const char *dest, char *result strncpy(result,ip,LINPHONE_IPADDR_SIZE); return; } -#endif +#endif //BUILD_UPNP if (linphone_core_get_local_ip_for(lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,dest,result)==0) return; /*else fallback to SAL routine that will attempt to find the most realistic interface */ @@ -2504,7 +2504,7 @@ LinphoneCall * linphone_core_invite_address_with_params(LinphoneCore *lc, const } else { defer = TRUE; } -#endif +#endif //BUILD_UPNP } if (call->dest_proxy==NULL && lc->sip_conf.ping_with_options==TRUE){ @@ -2661,7 +2661,7 @@ int linphone_core_start_update_call(LinphoneCore *lc, LinphoneCall *call){ if(call->upnp_session != NULL) { linphone_core_update_local_media_description_from_upnp(call->localdesc, call->upnp_session); } -#endif +#endif //BUILD_UPNP if (call->params.in_conference){ subject="Conference"; }else{ @@ -2780,7 +2780,7 @@ int linphone_core_start_accept_call_update(LinphoneCore *lc, LinphoneCall *call) if(call->upnp_session != NULL) { linphone_core_update_local_media_description_from_upnp(call->localdesc, call->upnp_session); } -#endif +#endif //BUILD_UPNP sal_call_set_local_media_description(call->op,call->localdesc); sal_call_accept(call->op); md=sal_call_get_final_media_description(call->op); @@ -3164,7 +3164,7 @@ int linphone_core_pause_call(LinphoneCore *lc, LinphoneCall *call) if(call->upnp_session != NULL) { linphone_core_update_local_media_description_from_upnp(call->localdesc, call->upnp_session); } -#endif +#endif //BUILD_UPNP if (sal_media_description_has_dir(call->resultdesc,SalStreamSendRecv)){ sal_media_description_set_dir(call->localdesc,SalStreamSendOnly); subject="Call on hold"; @@ -3249,7 +3249,7 @@ int linphone_core_resume_call(LinphoneCore *lc, LinphoneCall *the_call) if(call->upnp_session != NULL) { linphone_core_update_local_media_description_from_upnp(call->localdesc, call->upnp_session); } -#endif +#endif //BUILD_UPNP sal_call_set_local_media_description(call->op,call->localdesc); sal_media_description_set_dir(call->localdesc,SalStreamSendRecv); if (call->params.in_conference && !call->current_params.in_conference) subject="Conference"; @@ -4980,7 +4980,7 @@ static void linphone_core_uninit(LinphoneCore *lc) #ifdef BUILD_UPNP upnp_context_uninit(lc); -#endif +#endif //BUILD_UPNP ms_list_for_each(lc->call_logs,(void (*)(void*))linphone_call_log_destroy); lc->call_logs=ms_list_free(lc->call_logs); diff --git a/coreapi/private.h b/coreapi/private.h index d4abf16ca..b2b724d83 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -42,7 +42,7 @@ extern "C" { #include "mediastreamer2/msconference.h" #ifdef BUILD_UPNP #include "upnp.h" -#endif +#endif //BUILD_UPNP #ifndef LIBLINPHONE_VERSION #define LIBLINPHONE_VERSION LINPHONE_VERSION diff --git a/coreapi/upnp.c b/coreapi/upnp.c index 94072a4fc..530bf1bf1 100644 --- a/coreapi/upnp.c +++ b/coreapi/upnp.c @@ -132,6 +132,7 @@ void linphone_upnp_igd_callback(void *cookie, upnp_igd_event event, void *arg) { case UPNP_IGD_PORT_MAPPING_ADD_FAILURE: mapping = (upnp_igd_port_mapping *) arg; port_mapping = (UpnpPortBinding*) mapping->cookie; + port_mapping->external_port = -1; //Force a new random port if(upnp_context_send_add_port_binding(lc, port_mapping) != 0) { upnp_port_binding_log(ORTP_ERROR, "Can't add port binding", port_mapping); } @@ -188,6 +189,7 @@ int upnp_context_init(LinphoneCore *lc) { lupnp->sip_udp = upnp_port_binding_new(); lupnp->sip_udp->protocol = UPNP_IGD_IP_PROTOCOL_UDP; lupnp->sip_udp->local_port = transport.udp_port; + lupnp->sip_udp->external_port = transport.udp_port; } else { lupnp->sip_udp = NULL; } @@ -195,6 +197,7 @@ int upnp_context_init(LinphoneCore *lc) { lupnp->sip_tcp = upnp_port_binding_new(); lupnp->sip_tcp->protocol = UPNP_IGD_IP_PROTOCOL_TCP; lupnp->sip_tcp->local_port = transport.tcp_port; + lupnp->sip_tcp->external_port = transport.tcp_port; } else { lupnp->sip_tcp = NULL; } @@ -202,6 +205,7 @@ int upnp_context_init(LinphoneCore *lc) { lupnp->sip_tls = upnp_port_binding_new(); lupnp->sip_tls->protocol = UPNP_IGD_IP_PROTOCOL_TCP; lupnp->sip_tls->local_port = transport.tls_port; + lupnp->sip_tls->external_port = transport.tls_port; } else { lupnp->sip_tls = NULL; } @@ -257,7 +261,6 @@ int upnp_context_send_add_port_binding(LinphoneCore *lc, UpnpPortBinding *port) upnp_igd_port_mapping mapping; int ret; if(port->state == LinphoneUpnpStateIdle) { - port->external_port = -1; port->retry = 0; port->state = LinphoneUpnpStateAdding; } else if(port->state != LinphoneUpnpStateAdding) { @@ -272,7 +275,7 @@ int upnp_context_send_add_port_binding(LinphoneCore *lc, UpnpPortBinding *port) mapping.local_port = port->local_port; mapping.local_host = port->local_addr; if(port->external_port == -1) - mapping.remote_port = rand()%1024 + 1024; // TODO: use better method + mapping.remote_port = rand()%(0xffff - 1024) + 1024; // TODO: use better method else mapping.remote_port = port->external_port; mapping.remote_host = ""; @@ -339,9 +342,11 @@ int linphone_core_update_upnp_audio_video(LinphoneCall *call, bool_t audio, bool strncpy(call->upnp_session->audio->rtp->local_addr, local_addr, LINPHONE_IPADDR_SIZE); strncpy(call->upnp_session->audio->rtp->external_addr, external_addr, LINPHONE_IPADDR_SIZE); call->upnp_session->audio->rtp->local_port = call->audio_port; + call->upnp_session->audio->rtp->external_port = call->audio_port; strncpy(call->upnp_session->audio->rtcp->local_addr, local_addr, LINPHONE_IPADDR_SIZE); strncpy(call->upnp_session->audio->rtcp->external_addr, external_addr, LINPHONE_IPADDR_SIZE); call->upnp_session->audio->rtcp->local_port = call->audio_port+1; + call->upnp_session->audio->rtcp->external_port = call->audio_port+1; if(call->upnp_session->audio->rtp->state == LinphoneUpnpStateIdle && audio) { // Add audio port binding upnp_context_send_add_port_binding(lc, call->upnp_session->audio->rtp); @@ -363,9 +368,11 @@ int linphone_core_update_upnp_audio_video(LinphoneCall *call, bool_t audio, bool strncpy(call->upnp_session->video->rtp->local_addr, local_addr, LINPHONE_IPADDR_SIZE); strncpy(call->upnp_session->video->rtp->external_addr, external_addr, LINPHONE_IPADDR_SIZE); call->upnp_session->video->rtp->local_port = call->video_port; + call->upnp_session->video->rtp->external_port = call->video_port; strncpy(call->upnp_session->video->rtcp->local_addr, local_addr, LINPHONE_IPADDR_SIZE); strncpy(call->upnp_session->video->rtcp->external_addr, external_addr, LINPHONE_IPADDR_SIZE); call->upnp_session->video->rtcp->local_port = call->video_port+1; + call->upnp_session->video->rtcp->external_port = call->video_port+1; if(call->upnp_session->video->rtp->state == LinphoneUpnpStateIdle && video) { // Add video port binding upnp_context_send_add_port_binding(lc, call->upnp_session->video->rtp);