From aed5bd789af4eea28bfa7d9fe325fe66b1477f57 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Mon, 8 Sep 2014 11:32:37 +0200 Subject: [PATCH] Improve tunnel test: check that SIP packet actually use the tunnel --- coreapi/private.h | 2 +- coreapi/proxy.c | 4 ++ coreapi/sal.c | 6 +++ include/sal/sal.h | 2 +- mediastreamer2 | 2 +- tester/transport_tester.c | 80 ++++++++++++++++++++++++++++++--------- 6 files changed, 76 insertions(+), 20 deletions(-) diff --git a/coreapi/private.h b/coreapi/private.h index c993fc89a..4fbf1d0e2 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -289,6 +289,7 @@ void linphone_proxy_config_write_all_to_config_file(LinphoneCore *lc); * Can be NULL * */ const LinphoneAddress* linphone_proxy_config_get_service_route(const LinphoneProxyConfig* cfg); +char* linphone_proxy_config_get_contact(const LinphoneProxyConfig *cfg); void linphone_friend_close_subscriptions(LinphoneFriend *lf); void linphone_friend_update_subscribes(LinphoneFriend *fr, LinphoneProxyConfig *cfg, bool_t only_when_registered); @@ -365,7 +366,6 @@ void linphone_friend_write_to_config_file(struct _LpConfig *config, LinphoneFrie LinphoneFriend * linphone_friend_new_from_config_file(struct _LinphoneCore *lc, int index); void linphone_proxy_config_update(LinphoneProxyConfig *cfg); -void linphone_proxy_config_get_contact(LinphoneProxyConfig *cfg, const char **ip, int *port); LinphoneProxyConfig * linphone_core_lookup_known_proxy(LinphoneCore *lc, const LinphoneAddress *uri); const char *linphone_core_find_best_identity(LinphoneCore *lc, const LinphoneAddress *to); int linphone_core_get_local_ip_for(int type, const char *dest, char *result); diff --git a/coreapi/proxy.c b/coreapi/proxy.c index 3f403579b..cec96db24 100644 --- a/coreapi/proxy.c +++ b/coreapi/proxy.c @@ -1667,3 +1667,7 @@ void linphone_proxy_config_set_avpf_rr_interval(LinphoneProxyConfig *cfg, uint8_ uint8_t linphone_proxy_config_get_avpf_rr_interval(const LinphoneProxyConfig *cfg) { return cfg->avpf_rr_interval; } + +char* linphone_proxy_config_get_contact(const LinphoneProxyConfig *cfg) { + return sal_get_public_uri(cfg->op); +} diff --git a/coreapi/sal.c b/coreapi/sal.c index 8a48c79d0..ef266bfe7 100644 --- a/coreapi/sal.c +++ b/coreapi/sal.c @@ -735,3 +735,9 @@ belle_sip_stack_t *sal_get_belle_sip_stack(Sal *sal) { return sal->stack; } +char* sal_get_public_uri(SalOp *sal) { + if (sal&&sal->refresher) { + return belle_sip_refresher_get_public_uri(sal->refresher); + } + return NULL; +} diff --git a/include/sal/sal.h b/include/sal/sal.h index ffca87c5f..f518aff47 100644 --- a/include/sal/sal.h +++ b/include/sal/sal.h @@ -751,5 +751,5 @@ int sal_body_has_type(const SalBody *body, const char *type, const char *subtype int sal_lines_get_value(const char *data, const char *key, char *value, size_t value_size); belle_sip_stack_t *sal_get_belle_sip_stack(Sal *sal); - +char* sal_get_public_uri(SalOp *sal); #endif diff --git a/mediastreamer2 b/mediastreamer2 index 73ee30b2f..a8c099577 160000 --- a/mediastreamer2 +++ b/mediastreamer2 @@ -1 +1 @@ -Subproject commit 73ee30b2f6dcf4ca752d0a26bef4c1415e4796d3 +Subproject commit a8c09957733d1504744ac5388ecedddd9f5575ac diff --git a/tester/transport_tester.c b/tester/transport_tester.c index 5d4b9ffaa..5c8607299 100644 --- a/tester/transport_tester.c +++ b/tester/transport_tester.c @@ -26,28 +26,54 @@ #include "private.h" #include "liblinphone_tester.h" +/* Retrieve the public IP from a given hostname */ +static const char* get_ip_from_hostname(const char * tunnel_hostname){ + struct addrinfo hints; + struct addrinfo *res = NULL, *it = NULL; + struct sockaddr_in *add; + char * output = NULL; + int err; + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + if ((err = getaddrinfo(tunnel_hostname, NULL, &hints, &res))){ + ms_error("error while retrieving IP from %s: %s", tunnel_hostname, gai_strerror(err)); + return NULL; + } + + for (it=res; it!=NULL; it=it->ai_next){ + add = (struct sockaddr_in *) it->ai_addr; + output = inet_ntoa( add->sin_addr ); + } + freeaddrinfo(res); + return output; +} +static char* get_public_contact_ip(LinphoneCore* lc) { + long contact_host_ip_len; + char contact_host_ip[255]; + char * contact = linphone_proxy_config_get_contact(linphone_core_get_default_proxy_config(lc)); + CU_ASSERT_PTR_NOT_NULL(contact); + contact_host_ip_len = strchr(contact, ':')-contact; + strncpy(contact_host_ip, contact, contact_host_ip_len); + contact_host_ip[contact_host_ip_len]='\0'; + ms_free(contact); + return ms_strdup(contact_host_ip); +} static void call_with_transport_base(bool_t use_tunnel, LinphoneMediaEncryption encryption) { if (linphone_core_tunnel_available()){ - /*enabling the tunnel cause another REGISTER to be made*/ - int pauline_register_count_expected = use_tunnel ? 2 : 1; char *tmp_char; LinphoneCoreManager *pauline = linphone_core_manager_new( "pauline_rc"); LinphoneCoreManager *marie = linphone_core_manager_new( "marie_rc"); LinphoneCall *pauline_call; - - /*tunnel works only in UDP mode*/ LinphoneProxyConfig *proxy = linphone_core_get_default_proxy_config(pauline->lc); LinphoneAddress *server_addr = linphone_address_new(linphone_proxy_config_get_server_addr(proxy)); LinphoneAddress *route = linphone_address_new(linphone_proxy_config_get_route(proxy)); - linphone_proxy_config_edit(proxy); - linphone_address_set_transport(server_addr, LinphoneTransportUdp); - linphone_address_set_transport(route, LinphoneTransportUdp); - tmp_char = linphone_address_as_string(server_addr); - linphone_proxy_config_set_server_addr(proxy, tmp_char); - ms_free(tmp_char); - tmp_char = linphone_address_as_string(route); - linphone_proxy_config_set_route(proxy, tmp_char); - ms_free(tmp_char); + const char * tunnel_ip = get_ip_from_hostname("tunnel.linphone.org"); + char *public_ip; + + CU_ASSERT_TRUE(wait_for(pauline->lc,NULL,&pauline->stat.number_of_LinphoneRegistrationOk,1)); + public_ip = get_public_contact_ip(pauline->lc); + CU_ASSERT_STRING_NOT_EQUAL(public_ip, tunnel_ip); linphone_core_set_media_encryption(pauline->lc, encryption); @@ -55,15 +81,34 @@ static void call_with_transport_base(bool_t use_tunnel, LinphoneMediaEncryption LinphoneTunnel *tunnel = linphone_core_get_tunnel(pauline->lc); LinphoneTunnelConfig *config = linphone_tunnel_config_new(); + /*tunnel works only in UDP mode*/ + linphone_proxy_config_edit(proxy); + linphone_address_set_transport(server_addr, LinphoneTransportUdp); + linphone_address_set_transport(route, LinphoneTransportUdp); + tmp_char = linphone_address_as_string(server_addr); + linphone_proxy_config_set_server_addr(proxy, tmp_char); + ms_free(tmp_char); + tmp_char = linphone_address_as_string(route); + linphone_proxy_config_set_route(proxy, tmp_char); + ms_free(tmp_char); linphone_tunnel_enable(tunnel, TRUE); linphone_tunnel_config_set_host(config, "tunnel.linphone.org"); linphone_tunnel_config_set_port(config, 443); linphone_tunnel_add_server(tunnel, config); - } - linphone_proxy_config_done(proxy); + linphone_proxy_config_done(proxy); - CU_ASSERT_TRUE(wait_for(pauline->lc,NULL,&pauline->stat.number_of_LinphoneRegistrationOk,pauline_register_count_expected)); - CU_ASSERT_TRUE(wait_for(marie->lc, NULL, &marie->stat.number_of_LinphoneRegistrationOk, 1)); + /*enabling the tunnel cause another REGISTER to be made*/ + CU_ASSERT_TRUE(wait_for(pauline->lc,NULL,&pauline->stat.number_of_LinphoneRegistrationOk,2)); + + /* Ensure that we did use the tunnel. If so, we should see contact changed from: + Contact: ;.[...] + To: + Contact: ;[....] (91.121.209.194 must be tunnel.liphone.org) + */ + ms_free(public_ip); + public_ip = get_public_contact_ip(pauline->lc); + CU_ASSERT_STRING_EQUAL(public_ip, tunnel_ip); + } CU_ASSERT_TRUE(call(pauline,marie)); pauline_call=linphone_core_get_current_call(pauline->lc); @@ -74,6 +119,7 @@ static void call_with_transport_base(bool_t use_tunnel, LinphoneMediaEncryption } end_call(pauline,marie); + ms_free(public_ip); linphone_address_destroy(server_addr); linphone_address_destroy(route); linphone_core_manager_destroy(pauline);