diff options
Diffstat (limited to 'pjnath/src/pjnath-test')
-rw-r--r-- | pjnath/src/pjnath-test/ice_test.c | 101 | ||||
-rw-r--r-- | pjnath/src/pjnath-test/server.c | 30 |
2 files changed, 89 insertions, 42 deletions
diff --git a/pjnath/src/pjnath-test/ice_test.c b/pjnath/src/pjnath-test/ice_test.c index dfd7b84d..80f8c480 100644 --- a/pjnath/src/pjnath-test/ice_test.c +++ b/pjnath/src/pjnath-test/ice_test.c @@ -124,6 +124,29 @@ static void ice_on_ice_complete(pj_ice_strans *ice_st, pj_status_t status); static void destroy_sess(struct test_sess *sess, unsigned wait_msec); +#if USE_IPV6 + +static pj_bool_t enable_ipv6_test() +{ + pj_sockaddr addr; + pj_bool_t retval = PJ_TRUE; + if (pj_gethostip(pj_AF_INET6(), &addr) == PJ_SUCCESS) { + const pj_in6_addr *a = &addr.ipv6.sin6_addr; + if (a->s6_addr[0] == 0xFE && (a->s6_addr[1] & 0xC0) == 0x80) { + retval = PJ_FALSE; + PJ_LOG(3,(THIS_FILE, INDENT "Skipping IPv6 test due to link-local " + "address")); + } + } else { + retval = PJ_FALSE; + PJ_LOG(3,(THIS_FILE, INDENT "Skipping IPv6 test due to fail getting " + "IPv6 address")); + } + return retval; +} + +#endif + static void set_stun_turn_cfg(struct ice_ept *ept, pj_ice_strans_cfg *ice_cfg, char *serverip, @@ -787,47 +810,49 @@ static int perform_test(const char *title, callee_cfg, &test_param); #if USE_IPV6 - /* Test for IPV6. */ - if (rc == PJ_SUCCESS) { - pj_bzero(&test_param, sizeof(test_param)); - set_client_server_flag(SERVER_IPV6, CLIENT_IPV6, CLIENT_IPV6, - &server_flag, &caller_cfg->client_flag, - &callee_cfg->client_flag); - - rc = perform_test2(title, stun_cfg, server_flag, caller_cfg, - callee_cfg, &test_param); - } + if (enable_ipv6_test()) { - /* Test for IPV4+IPV6. */ - if (rc == PJ_SUCCESS) { - pj_bzero(&test_param, sizeof(test_param)); - set_client_server_flag(SERVER_IPV4+SERVER_IPV6, - CLIENT_IPV4+CLIENT_IPV6, - CLIENT_IPV4+CLIENT_IPV6, - &server_flag, - &caller_cfg->client_flag, - &callee_cfg->client_flag); - - rc = perform_test2(title, stun_cfg, server_flag, caller_cfg, - callee_cfg, &test_param); - } + /* Test for IPV6. */ + if (rc == PJ_SUCCESS) { + pj_bzero(&test_param, sizeof(test_param)); + set_client_server_flag(SERVER_IPV6, CLIENT_IPV6, CLIENT_IPV6, + &server_flag, &caller_cfg->client_flag, + &callee_cfg->client_flag); - /* Test controller(IPV4) vs controlled(IPV6). */ - if (rc == PJ_SUCCESS) { - pj_bzero(&test_param, sizeof(test_param)); - set_client_server_flag(SERVER_IPV4+SERVER_IPV6, - CLIENT_IPV4, - CLIENT_IPV6, - &server_flag, - &caller_cfg->client_flag, - &callee_cfg->client_flag); - caller_cfg->expected.start_status = PJ_ENOTFOUND; - callee_cfg->expected.start_status = PJ_ENOTFOUND; - - rc = perform_test2(title, stun_cfg, server_flag, caller_cfg, - callee_cfg, &test_param); - } + rc = perform_test2(title, stun_cfg, server_flag, caller_cfg, + callee_cfg, &test_param); + } + /* Test for IPV4+IPV6. */ + if (rc == PJ_SUCCESS) { + pj_bzero(&test_param, sizeof(test_param)); + set_client_server_flag(SERVER_IPV4+SERVER_IPV6, + CLIENT_IPV4+CLIENT_IPV6, + CLIENT_IPV4+CLIENT_IPV6, + &server_flag, + &caller_cfg->client_flag, + &callee_cfg->client_flag); + + rc = perform_test2(title, stun_cfg, server_flag, caller_cfg, + callee_cfg, &test_param); + } + + /* Test controller(IPV4) vs controlled(IPV6). */ + if (rc == PJ_SUCCESS) { + pj_bzero(&test_param, sizeof(test_param)); + set_client_server_flag(SERVER_IPV4+SERVER_IPV6, + CLIENT_IPV4, + CLIENT_IPV6, + &server_flag, + &caller_cfg->client_flag, + &callee_cfg->client_flag); + caller_cfg->expected.start_status = PJ_ENOTFOUND; + callee_cfg->expected.start_status = PJ_ENOTFOUND; + + rc = perform_test2(title, stun_cfg, server_flag, caller_cfg, + callee_cfg, &test_param); + } + } #endif callee_cfg->expected.start_status = expected_callee_start_ice; caller_cfg->expected.start_status = expected_caller_start_ice; diff --git a/pjnath/src/pjnath-test/server.c b/pjnath/src/pjnath-test/server.c index 99bacba1..0205f4a0 100644 --- a/pjnath/src/pjnath-test/server.c +++ b/pjnath/src/pjnath-test/server.c @@ -57,9 +57,17 @@ pj_status_t create_test_server(pj_stun_config *stun_cfg, PJ_ASSERT_RETURN(stun_cfg && domain && p_test_srv, PJ_EINVAL); - status = pj_gethostip(GET_AF(use_ipv6), &hostip); - if (status != PJ_SUCCESS) - return status; + if (use_ipv6) { + /* pj_gethostip() may return IPv6 link-local and will cause EINVAL + * error, so let's just hardcode it. + */ + pj_sockaddr_init(pj_AF_INET6(), &hostip, NULL, 0); + hostip.ipv6.sin6_addr.s6_addr[15] = 1; + } else { + status = pj_gethostip(GET_AF(use_ipv6), &hostip); + if (status != PJ_SUCCESS) + return status; + } pool = pj_pool_create(mem, THIS_FILE, 512, 512, NULL); test_srv = (test_server*) PJ_POOL_ZALLOC_T(pool, test_server); @@ -501,7 +509,21 @@ static pj_bool_t turn_on_data_recvfrom(pj_activesock_t *asock, /* Create relay socket */ pj_sockaddr_init(GET_AF(use_ipv6), &alloc->alloc_addr, NULL, 0); - pj_gethostip(GET_AF(use_ipv6), &alloc->alloc_addr); + if (use_ipv6) { + /* pj_gethostip() may return IPv6 link-local and will cause EINVAL + * error, so let's just hardcode it. + */ + pj_sockaddr_init(pj_AF_INET6(), &alloc->alloc_addr, NULL, 0); + alloc->alloc_addr.ipv6.sin6_addr.s6_addr[15] = 1; + } else { + status = pj_gethostip(GET_AF(use_ipv6), &alloc->alloc_addr); + if (status != PJ_SUCCESS) { + pj_pool_release(alloc->pool); + pj_stun_msg_create_response(pool, req, PJ_STUN_SC_SERVER_ERROR, + NULL, &resp); + goto send_pkt; + } + } status = pj_activesock_create_udp(alloc->pool, &alloc->alloc_addr, NULL, test_srv->stun_cfg->ioqueue, |