From ef404cd31986708c766f09c1fb06ce60fcfd9ffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grisez?= Date: Mon, 15 Sep 2014 11:07:04 +0200 Subject: [PATCH] Add a function to prevent SIP packets to pass through tunnels --- coreapi/TunnelManager.cc | 32 +++++++++++++++++--------------- coreapi/TunnelManager.hh | 27 ++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/coreapi/TunnelManager.cc b/coreapi/TunnelManager.cc index 8c4968400..49a6464ef 100644 --- a/coreapi/TunnelManager.cc +++ b/coreapi/TunnelManager.cc @@ -147,7 +147,8 @@ TunnelManager::TunnelManager(LinphoneCore* lc) :TunnelClientController() ,mAutoDetectStarted(false) ,mReady(false) ,mHttpProxyPort(0) - ,mPreviousRegistrationEnabled(false){ + ,mPreviousRegistrationEnabled(false) + ,mTunnelizeSipPackets(true){ linphone_core_add_iterate_hook(mCore,(LinphoneCoreIterateHook)sOnIterate,this); mTransportFactories.audio_rtcp_func=sCreateRtpTransport; @@ -179,11 +180,11 @@ void TunnelManager::registration(){ if (isReady()){ linphone_core_set_firewall_policy(mCore,LinphonePolicyNoFirewall); linphone_core_set_rtp_transport_factories(mCore,&mTransportFactories); - - sal_enable_tunnel(mCore->sal, mTunnelClient); + if(mTunnelizeSipPackets) { + sal_enable_tunnel(mCore->sal, mTunnelClient); + } // tunnel was disabled } else { - linphone_core_set_sip_transports(mCore, &mRegularTransport); linphone_core_set_firewall_policy(mCore, mPreviousFirewallPolicy); } @@ -243,8 +244,7 @@ void TunnelManager::enable(bool isEnable) { ms_message("Turning tunnel [%s]", isEnable ?"on" : "off"); if (isEnable && !mEnabled){ mEnabled=true; - //1 save transport and firewall policy - linphone_core_get_sip_transports(mCore, &mRegularTransport); + //1 save firewall policy mPreviousFirewallPolicy=linphone_core_get_firewall_policy(mCore); //2 unregister waitUnRegistration(); @@ -259,17 +259,9 @@ void TunnelManager::enable(bool isEnable) { stopClient(); mReady=false; linphone_core_set_rtp_transport_factories(mCore,NULL); - sal_disable_tunnel(mCore->sal); - // Set empty transports to force the setting of regular transport, otherwise it is not applied - LCSipTransports lTransport; - lTransport.udp_port = 0; - lTransport.tcp_port = 0; - lTransport.tls_port = 0; - lTransport.dtls_port = 0; - linphone_core_set_sip_transports(mCore, &lTransport); - // register + // 3 register registration(); } } @@ -404,6 +396,16 @@ void TunnelManager::setHttpProxyAuthInfo(const char* username,const char* passwd if (mTunnelClient) mTunnelClient->setHttpProxyAuthInfo(username,passwd); } +void TunnelManager::tunnelizeSipPackets(bool enable){ + if(enable != mTunnelizeSipPackets) { + mTunnelizeSipPackets = enable; + if(mEnabled && isReady()) { + waitUnRegistration(); + registration(); + } + } +} + void TunnelManager::setHttpProxy(const char *host,int port, const char *username, const char *passwd){ mHttpUserName=username?username:""; mHttpPasswd=passwd?passwd:""; diff --git a/coreapi/TunnelManager.hh b/coreapi/TunnelManager.hh index adf4fa954..4cd8bff77 100644 --- a/coreapi/TunnelManager.hh +++ b/coreapi/TunnelManager.hh @@ -33,7 +33,7 @@ class UdpMirrorClient; * The TunnelManager class extends the LinphoneCore functionnality in order to provide an easy to use API to * - provision tunnel servers ip addresses and ports * - start/stop the tunneling service - * - be informed of of connection and disconnection events to the tunnel server + * - be informed of connection and disconnection events to the tunnel server * - perform auto-detection whether tunneling is required, based on a test of sending/receiving a flow of UDP packets. * * It takes in charge automatically the SIP registration procedure when connecting or disconnecting to a tunnel server. @@ -91,8 +91,8 @@ class UdpMirrorClient; void enable(bool isEnabled); /** * In auto detect mode, the tunnel manager try to establish a real time rtp cummunication with the tunnel server on specified port. - *
In case of success, the tunnel is automatically turned off. Otherwise, if no udp commmunication is feasible, tunnel mode is turned on. - *
Call this method each time to run the auto detection algorithm + *
In case of success, the tunnel is automatically turned off. Otherwise, if no udp commmunication is feasible, tunnel mode is turned on. + *
Call this method each time to run the auto detection algorithm */ void autoDetect(); /** @@ -115,7 +115,22 @@ class UdpMirrorClient; * @param passwd The password. **/ void setHttpProxyAuthInfo(const char* username,const char* passwd); + /** + * Indicate to the tunnel manager whether SIP packets must pass + * through the tunnel. That featurte is automatically enabled at + * the creation of the TunnelManager instance. + * @param enable If set to TRUE, SIP packets will pass through the tunnel. + * If set to FALSE, SIP packets will pass by the configured proxies. + */ + void tunnelizeSipPackets(bool enable = true); + /** + * @brief Destructor + */ ~TunnelManager(); + /** + * @brief Constructor + * @param lc The LinphoneCore instance of which the TunnelManager will be associated to. + */ TunnelManager(LinphoneCore* lc); /** * Destroy the given RtpTransport. @@ -161,8 +176,10 @@ class UdpMirrorClient; void processTunnelEvent(const Event &ev); void processUdpMirrorEvent(const Event &ev); void postEvent(const Event &ev); + void stopClient(); + + private: LinphoneCore* mCore; - LCSipTransports mRegularTransport; #ifndef USE_BELLESIP TunnelSocket *mSipSocket; eXosip_transport_hooks_t mExosipTransport; @@ -175,7 +192,6 @@ class UdpMirrorClient; UdpMirrorClientList mUdpMirrorClients; UdpMirrorClientList::iterator mCurrentUdpMirrorClient; TunnelClient* mTunnelClient; - void stopClient(); Mutex mMutex; static Mutex sMutex; bool mAutoDetectStarted; @@ -187,6 +203,7 @@ class UdpMirrorClient; int mHttpProxyPort; LinphoneFirewallPolicy mPreviousFirewallPolicy; bool mPreviousRegistrationEnabled; + bool mTunnelizeSipPackets; }; /**