- Timestamp:
- Jun 21, 2016 6:55:10 AM (8 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib-util/include/pjlib-util/dns.h
r3553 r5350 428 428 429 429 /** 430 * Initialize DNS record as DNS AAAA record. 431 * 432 * @param rec The DNS resource record to be initialized as DNS 433 * AAAA record. 434 * @param res_name Resource name. 435 * @param dnsclass DNS class. 436 * @param ttl Resource TTL value. 437 * @param ip_addr Host address. 438 */ 439 PJ_DECL(void) pj_dns_init_aaaa_rr(pj_dns_parsed_rr *rec, 440 const pj_str_t *res_name, 441 unsigned dnsclass, 442 unsigned ttl, 443 const pj_in6_addr *ip_addr); 444 445 /** 430 446 * Dump DNS packet to standard log. 431 447 * -
pjproject/trunk/pjlib-util/src/pjlib-util/dns.c
r5183 r5350 750 750 } 751 751 752 753 PJ_DEF(void) pj_dns_init_aaaa_rr(pj_dns_parsed_rr *rec, 754 const pj_str_t *res_name, 755 unsigned dnsclass, 756 unsigned ttl, 757 const pj_in6_addr *ip_addr) 758 { 759 pj_bzero(rec, sizeof(*rec)); 760 rec->name = *res_name; 761 rec->type = PJ_DNS_TYPE_AAAA; 762 rec->dnsclass = (pj_uint16_t) dnsclass; 763 rec->ttl = ttl; 764 rec->rdata.aaaa.ip_addr = *ip_addr; 765 } 766 -
pjproject/trunk/pjlib-util/src/pjlib-util/dns_server.c
r4537 r5350 312 312 size -= 6; 313 313 314 } else if (rr->type == PJ_DNS_TYPE_AAAA) { 315 316 if (size < 18) 317 return -1; 318 319 /* RDLEN is 16 */ 320 write16(p, 16); 321 322 /* Address */ 323 pj_memcpy(p+2, &rr->rdata.aaaa.ip_addr, 16); 324 325 p += 18; 326 size -= 18; 327 314 328 } else if (rr->type == PJ_DNS_TYPE_CNAME || 315 329 rr->type == PJ_DNS_TYPE_NS || -
pjproject/trunk/pjnath/src/pjnath-test/ice_test.c
r4728 r5350 40 40 WRONG_TURN = 1, 41 41 DEL_ON_ERR = 2, 42 CLIENT_IPV4 = 4, 43 CLIENT_IPV6 = 8 42 44 }; 43 44 45 45 46 /* Test results */ 46 47 struct test_result 47 48 { 49 pj_status_t start_status; /* start ice successful? */ 48 50 pj_status_t init_status; /* init successful? */ 49 51 pj_status_t nego_status; /* negotiation successful? */ … … 102 104 struct sess_param *param; 103 105 104 test_server *server; 106 test_server *server1; /* Test server for IPv4. */ 107 test_server *server2; /* Test server for IPv6. */ 105 108 106 109 pj_thread_t *worker_threads[MAX_THREADS]; … … 122 125 static void destroy_sess(struct test_sess *sess, unsigned wait_msec); 123 126 127 static void set_stun_turn_cfg(struct ice_ept *ept, 128 pj_ice_strans_cfg *ice_cfg, 129 char *serverip, 130 pj_bool_t use_ipv6) 131 { 132 if (ept->cfg.enable_stun & YES) { 133 unsigned stun_idx = ice_cfg->stun_tp_cnt++; 134 pj_ice_strans_stun_cfg_default(&ice_cfg->stun_tp[stun_idx]); 135 136 if ((ept->cfg.enable_stun & SRV) == SRV) { 137 ice_cfg->stun_tp[stun_idx].server = pj_str(SRV_DOMAIN); 138 } else { 139 ice_cfg->stun_tp[stun_idx].server = pj_str(serverip); 140 } 141 ice_cfg->stun_tp[stun_idx].port = STUN_SERVER_PORT; 142 143 ice_cfg->stun_tp[stun_idx].af = GET_AF(use_ipv6); 144 } 145 ice_cfg->stun.af = GET_AF(use_ipv6); 146 if (ept->cfg.enable_host == 0) { 147 ice_cfg->stun.max_host_cands = 0; 148 } else { 149 //ice_cfg.stun.no_host_cands = PJ_FALSE; 150 ice_cfg->stun.loop_addr = PJ_TRUE; 151 } 152 153 if (ept->cfg.enable_turn & YES) { 154 unsigned turn_idx = ice_cfg->turn_tp_cnt++; 155 pj_ice_strans_turn_cfg_default(&ice_cfg->turn_tp[turn_idx]); 156 157 if ((ept->cfg.enable_turn & SRV) == SRV) { 158 ice_cfg->turn_tp[turn_idx].server = pj_str(SRV_DOMAIN); 159 } else { 160 ice_cfg->turn_tp[turn_idx].server = pj_str(serverip); 161 } 162 ice_cfg->turn_tp[turn_idx].port = TURN_SERVER_PORT; 163 ice_cfg->turn_tp[turn_idx].conn_type = PJ_TURN_TP_UDP; 164 ice_cfg->turn_tp[turn_idx].auth_cred.type = PJ_STUN_AUTH_CRED_STATIC; 165 ice_cfg->turn_tp[turn_idx].auth_cred.data.static_cred.realm = 166 pj_str(SRV_DOMAIN); 167 if (ept->cfg.client_flag & WRONG_TURN) 168 ice_cfg->turn_tp[turn_idx].auth_cred.data.static_cred.username = 169 pj_str("xxx"); 170 else 171 ice_cfg->turn_tp[turn_idx].auth_cred.data.static_cred.username = 172 pj_str(TURN_USERNAME); 173 174 ice_cfg->turn_tp[turn_idx].auth_cred.data.static_cred.data_type = 175 PJ_STUN_PASSWD_PLAIN; 176 ice_cfg->turn_tp[turn_idx].auth_cred.data.static_cred.data = 177 pj_str(TURN_PASSWD); 178 179 ice_cfg->turn_tp[turn_idx].af = GET_AF(use_ipv6); 180 } 181 } 182 124 183 /* Create ICE stream transport */ 125 184 static int create_ice_strans(struct test_sess *test_sess, 126 struct ice_ept *ept, 185 struct ice_ept *ept, 127 186 pj_ice_strans **p_ice) 128 187 { … … 131 190 pj_ice_strans_cfg ice_cfg; 132 191 pj_sockaddr hostip; 133 char serverip[PJ_INET6_ADDRSTRLEN]; 192 char serveripv4[PJ_INET6_ADDRSTRLEN]; 193 char serveripv6[PJ_INET6_ADDRSTRLEN]; 134 194 pj_status_t status; 195 unsigned flag = (ept->cfg.client_flag)?ept->cfg.client_flag:CLIENT_IPV4; 135 196 136 197 status = pj_gethostip(pj_AF_INET(), &hostip); … … 138 199 return -1030; 139 200 140 pj_sockaddr_print(&hostip, serverip, sizeof(serverip), 0); 201 pj_sockaddr_print(&hostip, serveripv4, sizeof(serveripv4), 0); 202 203 if (flag & CLIENT_IPV6) { 204 status = pj_gethostip(pj_AF_INET6(), &hostip); 205 if (status != PJ_SUCCESS) 206 return -1031; 207 208 pj_sockaddr_print(&hostip, serveripv6, sizeof(serveripv6), 0); 209 } 141 210 142 211 /* Init callback structure */ … … 151 220 ice_cfg.resolver = test_sess->resolver; 152 221 153 if (ept->cfg.enable_stun & YES) { 154 if ((ept->cfg.enable_stun & SRV) == SRV) { 155 ice_cfg.stun.server = pj_str(SRV_DOMAIN); 156 } else { 157 ice_cfg.stun.server = pj_str(serverip); 158 } 159 ice_cfg.stun.port = STUN_SERVER_PORT; 160 } 161 162 if (ept->cfg.enable_host == 0) { 163 ice_cfg.stun.max_host_cands = 0; 164 } else { 165 //ice_cfg.stun.no_host_cands = PJ_FALSE; 166 ice_cfg.stun.loop_addr = PJ_TRUE; 167 } 168 169 170 if (ept->cfg.enable_turn & YES) { 171 if ((ept->cfg.enable_turn & SRV) == SRV) { 172 ice_cfg.turn.server = pj_str(SRV_DOMAIN); 173 } else { 174 ice_cfg.turn.server = pj_str(serverip); 175 } 176 ice_cfg.turn.port = TURN_SERVER_PORT; 177 ice_cfg.turn.conn_type = PJ_TURN_TP_UDP; 178 ice_cfg.turn.auth_cred.type = PJ_STUN_AUTH_CRED_STATIC; 179 ice_cfg.turn.auth_cred.data.static_cred.realm = pj_str(SRV_DOMAIN); 180 if (ept->cfg.client_flag & WRONG_TURN) 181 ice_cfg.turn.auth_cred.data.static_cred.username = pj_str("xxx"); 182 else 183 ice_cfg.turn.auth_cred.data.static_cred.username = pj_str(TURN_USERNAME); 184 ice_cfg.turn.auth_cred.data.static_cred.data_type = PJ_STUN_PASSWD_PLAIN; 185 ice_cfg.turn.auth_cred.data.static_cred.data = pj_str(TURN_PASSWD); 222 if (flag & CLIENT_IPV4) { 223 set_stun_turn_cfg(ept, &ice_cfg, serveripv4, PJ_FALSE); 224 } 225 226 if (flag & CLIENT_IPV6) { 227 set_stun_turn_cfg(ept, &ice_cfg, serveripv6, PJ_TRUE); 186 228 } 187 229 … … 216 258 pj_uint16_t ns_port; 217 259 unsigned flags; 218 pj_status_t status ;260 pj_status_t status = PJ_SUCCESS; 219 261 220 262 /* Create session structure */ … … 233 275 /* Create server */ 234 276 flags = server_flag; 235 status = create_test_server(stun_cfg, flags, SRV_DOMAIN, &sess->server); 277 if (flags & SERVER_IPV4) { 278 status = create_test_server(stun_cfg, (flags & ~SERVER_IPV6), 279 SRV_DOMAIN, &sess->server1); 280 } 281 282 if ((status == PJ_SUCCESS) && (flags & SERVER_IPV6)) { 283 status = create_test_server(stun_cfg, (flags & ~SERVER_IPV4), 284 SRV_DOMAIN, &sess->server2); 285 } 286 236 287 if (status != PJ_SUCCESS) { 237 288 app_perror(INDENT "error: create_test_server()", status); … … 239 290 return -10; 240 291 } 241 sess->server->turn_respond_allocate = 242 sess->server->turn_respond_refresh = PJ_TRUE; 292 if (flags & SERVER_IPV4) { 293 sess->server1->turn_respond_allocate = 294 sess->server1->turn_respond_refresh = PJ_TRUE; 295 } 296 297 if (flags & SERVER_IPV6) { 298 sess->server2->turn_respond_allocate = 299 sess->server2->turn_respond_refresh = PJ_TRUE; 300 } 243 301 244 302 /* Create resolver */ 245 status = pj_dns_resolver_create(mem, NULL, 0, stun_cfg->timer_heap, 246 stun_cfg->ioqueue, &sess->resolver); 247 if (status != PJ_SUCCESS) { 248 app_perror(INDENT "error: pj_dns_resolver_create()", status); 249 destroy_sess(sess, 500); 250 return -20; 251 } 252 253 ns_ip = pj_str("127.0.0.1"); 254 ns_port = (pj_uint16_t)DNS_SERVER_PORT; 255 status = pj_dns_resolver_set_ns(sess->resolver, 1, &ns_ip, &ns_port); 256 if (status != PJ_SUCCESS) { 257 app_perror( INDENT "error: pj_dns_resolver_set_ns()", status); 258 destroy_sess(sess, 500); 259 return -21; 303 if ((sess->callee.cfg.enable_stun & SRV)==SRV || 304 (sess->callee.cfg.enable_turn & SRV)==SRV || 305 (sess->caller.cfg.enable_stun & SRV)==SRV || 306 (sess->caller.cfg.enable_turn & SRV)==SRV) 307 { 308 status = pj_dns_resolver_create(mem, NULL, 0, stun_cfg->timer_heap, 309 stun_cfg->ioqueue, &sess->resolver); 310 if (status != PJ_SUCCESS) { 311 app_perror(INDENT "error: pj_dns_resolver_create()", status); 312 destroy_sess(sess, 500); 313 return -20; 314 } 315 316 ns_ip = (flags & SERVER_IPV6)?pj_str("::1"):pj_str("127.0.0.1"); 317 ns_port = (pj_uint16_t)DNS_SERVER_PORT; 318 status = pj_dns_resolver_set_ns(sess->resolver, 1, &ns_ip, &ns_port); 319 if (status != PJ_SUCCESS) { 320 app_perror(INDENT "error: pj_dns_resolver_set_ns()", status); 321 destroy_sess(sess, 500); 322 return -21; 323 } 260 324 } 261 325 … … 306 370 } 307 371 308 if (sess->server) { 309 destroy_test_server(sess->server); 310 sess->server = NULL; 372 if (sess->server1) { 373 destroy_test_server(sess->server1); 374 sess->server1 = NULL; 375 } 376 377 if (sess->server2) { 378 destroy_test_server(sess->server2); 379 sess->server2 = NULL; 311 380 } 312 381 … … 385 454 status = pj_ice_strans_start_ice(ept->ice, &remote->ufrag, &remote->pass, 386 455 rcand_cnt, rcand); 387 if (status != PJ_SUCCESS) { 456 457 if (status != ept->cfg.expected.start_status) { 388 458 app_perror(INDENT "err: pj_ice_strans_start_ice()", status); 389 459 return status; 390 460 } 391 461 392 return PJ_SUCCESS;462 return status; 393 463 } 394 464 … … 499 569 unsigned i; 500 570 int rc; 501 502 PJ_LOG(3,(THIS_FILE, INDENT "%s", title)); 571 char add_title1[16]; 572 char add_title2[16]; 573 pj_bool_t client_mix_test = ((callee_cfg->client_flag & 574 (CLIENT_IPV4+CLIENT_IPV6)) != 575 (caller_cfg->client_flag & 576 (CLIENT_IPV4+CLIENT_IPV6))); 577 578 sprintf(add_title1, "%s%s%s", (server_flag & SERVER_IPV4)?"IPv4":"", 579 ((server_flag & SERVER_IPV4)&&(server_flag & SERVER_IPV6))?"+":"", 580 (server_flag & SERVER_IPV6)?"IPv6":""); 581 582 sprintf(add_title2, "%s", client_mix_test?"Mix test":""); 583 584 PJ_LOG(3,(THIS_FILE, INDENT "%s (%s) %s", title, add_title1, add_title2)); 503 585 504 586 capture_pjlib_state(stun_cfg, &pjlib_state); 505 587 506 rc = create_sess(stun_cfg, server_flag, caller_cfg, callee_cfg, test_param, &sess); 588 rc = create_sess(stun_cfg, server_flag, caller_cfg, callee_cfg, test_param, 589 &sess); 507 590 if (rc != 0) 508 591 return rc; … … 558 641 rc = start_ice(&sess->callee, &sess->caller); 559 642 if (rc != PJ_SUCCESS) { 560 destroy_sess(sess, 500); 561 return -120; 643 int retval = (rc == sess->callee.cfg.expected.start_status)?0:-120; 644 destroy_sess(sess, 500); 645 return retval; 562 646 } 563 647 /* Wait for callee's answer_delay */ … … 566 650 rc = start_ice(&sess->caller, &sess->callee); 567 651 if (rc != PJ_SUCCESS) { 568 destroy_sess(sess, 500); 569 return -130; 652 int retval = (rc == sess->caller.cfg.expected.start_status)?0:-130; 653 destroy_sess(sess, 500); 654 return retval; 570 655 } 571 656 … … 664 749 } 665 750 751 static void set_client_server_flag(unsigned server_flag, 752 unsigned caller_flag, 753 unsigned callee_flag, 754 unsigned *res_server_flag, 755 unsigned *res_caller_flag, 756 unsigned *res_callee_flag) 757 { 758 enum { 759 RST_CLT_FLAG = CLIENT_IPV4+CLIENT_IPV6, 760 RST_SRV_FLAG = SERVER_IPV4+SERVER_IPV6 761 }; 762 763 *res_server_flag = (*res_server_flag & ~RST_SRV_FLAG) | server_flag; 764 *res_caller_flag = (*res_caller_flag & ~RST_CLT_FLAG) | caller_flag; 765 *res_callee_flag = (*res_callee_flag & ~RST_CLT_FLAG) | callee_flag; 766 } 767 666 768 static int perform_test(const char *title, 667 769 pj_stun_config *stun_cfg, … … 671 773 { 672 774 struct sess_param test_param; 775 int rc; 776 int expected_caller_start_ice = caller_cfg->expected.start_status; 777 int expected_callee_start_ice = callee_cfg->expected.start_status; 778 779 set_client_server_flag(SERVER_IPV4, CLIENT_IPV4, CLIENT_IPV4, 780 &server_flag, &caller_cfg->client_flag, 781 &callee_cfg->client_flag); 782 673 783 674 784 pj_bzero(&test_param, sizeof(test_param)); 675 return perform_test2(title, stun_cfg, server_flag, caller_cfg, 676 callee_cfg, &test_param); 785 786 rc = perform_test2(title, stun_cfg, server_flag, caller_cfg, 787 callee_cfg, &test_param); 788 789 #if USE_IPV6 790 /* Test for IPV6. */ 791 if (rc == PJ_SUCCESS) { 792 pj_bzero(&test_param, sizeof(test_param)); 793 set_client_server_flag(SERVER_IPV6, CLIENT_IPV6, CLIENT_IPV6, 794 &server_flag, &caller_cfg->client_flag, 795 &callee_cfg->client_flag); 796 797 rc = perform_test2(title, stun_cfg, server_flag, caller_cfg, 798 callee_cfg, &test_param); 799 } 800 801 /* Test for IPV4+IPV6. */ 802 if (rc == PJ_SUCCESS) { 803 pj_bzero(&test_param, sizeof(test_param)); 804 set_client_server_flag(SERVER_IPV4+SERVER_IPV6, 805 CLIENT_IPV4+CLIENT_IPV6, 806 CLIENT_IPV4+CLIENT_IPV6, 807 &server_flag, 808 &caller_cfg->client_flag, 809 &callee_cfg->client_flag); 810 811 rc = perform_test2(title, stun_cfg, server_flag, caller_cfg, 812 callee_cfg, &test_param); 813 } 814 815 /* Test controller(IPV4) vs controlled(IPV6). */ 816 if (rc == PJ_SUCCESS) { 817 pj_bzero(&test_param, sizeof(test_param)); 818 set_client_server_flag(SERVER_IPV4+SERVER_IPV6, 819 CLIENT_IPV4, 820 CLIENT_IPV6, 821 &server_flag, 822 &caller_cfg->client_flag, 823 &callee_cfg->client_flag); 824 caller_cfg->expected.start_status = PJ_ENOTFOUND; 825 callee_cfg->expected.start_status = PJ_ENOTFOUND; 826 827 rc = perform_test2(title, stun_cfg, server_flag, caller_cfg, 828 callee_cfg, &test_param); 829 } 830 831 #endif 832 callee_cfg->expected.start_status = expected_callee_start_ice; 833 caller_cfg->expected.start_status = expected_caller_start_ice; 834 835 return rc; 677 836 } 678 837 … … 696 855 { 697 856 "hosts candidates only", 698 0x FFFF,699 {ROLE1, 1, YES, NO, NO, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS }},700 {ROLE2, 1, YES, NO, NO, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS }}857 0x1FFF, 858 {ROLE1, 1, YES, NO, NO, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}}, 859 {ROLE2, 1, YES, NO, NO, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}} 701 860 }, 702 861 { 703 862 "host and srflxes", 704 0x FFFF,705 {ROLE1, 1, YES, YES, NO, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS }},706 {ROLE2, 1, YES, YES, NO, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS }}863 0x1FFF, 864 {ROLE1, 1, YES, YES, NO, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}}, 865 {ROLE2, 1, YES, YES, NO, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}} 707 866 }, 708 867 { 709 868 "host vs relay", 710 0x FFFF,711 {ROLE1, 1, YES, NO, NO, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS }},712 {ROLE2, 1, NO, NO, YES, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS }}869 0x1FFF, 870 {ROLE1, 1, YES, NO, NO, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}}, 871 {ROLE2, 1, NO, NO, YES, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}} 713 872 }, 714 873 { 715 874 "relay vs host", 716 0x FFFF,717 {ROLE1, 1, NO, NO, YES, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS }},718 {ROLE2, 1, YES, NO, NO, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS }}875 0x1FFF, 876 {ROLE1, 1, NO, NO, YES, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}}, 877 {ROLE2, 1, YES, NO, NO, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}} 719 878 }, 720 879 { 721 880 "relay vs relay", 722 0x FFFF,723 {ROLE1, 1, NO, NO, YES, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS }},724 {ROLE2, 1, NO, NO, YES, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS }}881 0x1FFF, 882 {ROLE1, 1, NO, NO, YES, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}}, 883 {ROLE2, 1, NO, NO, YES, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}} 725 884 }, 726 885 { 727 886 "all candidates", 728 0x FFFF,729 {ROLE1, 1, YES, YES, YES, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS }},730 {ROLE2, 1, YES, YES, YES, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS }}887 0x1FFF, 888 {ROLE1, 1, YES, YES, YES, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}}, 889 {ROLE2, 1, YES, YES, YES, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}} 731 890 }, 732 891 }; … … 746 905 0x0, 747 906 /* Role comp# host? stun? turn? flag? ans_del snd_del des_del */ 748 {ROLE1, 1, YES, NO, NO, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS }},749 {ROLE2, 1, YES, NO, NO, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS }}907 {ROLE1, 1, YES, NO, NO, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}}, 908 {ROLE2, 1, YES, NO, NO, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}} 750 909 }; 751 910 … … 771 930 0xFFFF, 772 931 /* Role comp# host? stun? turn? flag? ans_del snd_del des_del */ 773 {ROLE1, 1, YES, YES, NO, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS }},774 {ROLE2, 1, YES, YES, NO, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS }}932 {ROLE1, 1, YES, YES, NO, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}}, 933 {ROLE2, 1, YES, YES, NO, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}} 775 934 }; 776 935 … … 797 956 0xFFFF, 798 957 /* Role comp# host? stun? turn? flag? ans_del snd_del des_del */ 799 {ROLE1, 1, NO, NO, YES, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS }},800 {ROLE2, 1, NO, NO, YES, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS }}958 {ROLE1, 1, NO, NO, YES, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}}, 959 {ROLE2, 1, NO, NO, YES, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}} 801 960 }; 802 961 … … 823 982 0x0, 824 983 /* Role comp# host? stun? turn? flag? ans_del snd_del des_del */ 825 {ROLE1, 2, NO, YES, NO, 0, 0, 0, 0, {PJ NATH_ESTUNTIMEDOUT, -1}},826 {ROLE2, 2, NO, YES, NO, 0, 0, 0, 0, {PJ NATH_ESTUNTIMEDOUT, -1}}984 {ROLE1, 2, NO, YES, NO, 0, 0, 0, 0, {PJ_SUCCESS, PJNATH_ESTUNTIMEDOUT, -1}}, 985 {ROLE2, 2, NO, YES, NO, 0, 0, 0, 0, {PJ_SUCCESS, PJNATH_ESTUNTIMEDOUT, -1}} 827 986 }; 828 987 … … 849 1008 0xFFFF, 850 1009 /* Role comp# host? stun? turn? flag? ans_del snd_del des_del */ 851 {ROLE1, 2, NO, NO, YES, WRONG_TURN, 0, 0, 0, {PJ_S TATUS_FROM_STUN_CODE(401), -1}},852 {ROLE2, 2, NO, NO, YES, WRONG_TURN, 0, 0, 0, {PJ_S TATUS_FROM_STUN_CODE(401), -1}}1010 {ROLE1, 2, NO, NO, YES, WRONG_TURN, 0, 0, 0, {PJ_SUCCESS, PJ_STATUS_FROM_STUN_CODE(401), -1}}, 1011 {ROLE2, 2, NO, NO, YES, WRONG_TURN, 0, 0, 0, {PJ_SUCCESS, PJ_STATUS_FROM_STUN_CODE(401), -1}} 853 1012 }; 854 1013 … … 876 1035 0xFFFF & (~(CREATE_STUN_SERVER)), 877 1036 /* Role comp# host? stun? turn? flag? ans_del snd_del des_del */ 878 {ROLE1, 1, YES, YES, YES, 0, 0, 0, 0, {PJ NATH_ESTUNTIMEDOUT, -1}},879 {ROLE2, 1, YES, YES, YES, 0, 0, 0, 0, {PJ NATH_ESTUNTIMEDOUT, -1}}1037 {ROLE1, 1, YES, YES, YES, 0, 0, 0, 0, {PJ_SUCCESS, PJNATH_ESTUNTIMEDOUT, -1}}, 1038 {ROLE2, 1, YES, YES, YES, 0, 0, 0, 0, {PJ_SUCCESS, PJNATH_ESTUNTIMEDOUT, -1}} 880 1039 }; 881 1040 … … 970 1129 { 971 1130 "Concurrency test", 972 0x FFFF,1131 0x1FFF, 973 1132 /* Role comp# host? stun? turn? flag? ans_del snd_del des_del */ 974 {ROLE1, 1, YES, YES, YES, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS}},975 {ROLE2, 1, YES, YES, YES, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS}}1133 {ROLE1, 1, YES, YES, YES, CLIENT_IPV4, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}}, 1134 {ROLE2, 1, YES, YES, YES, CLIENT_IPV4, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}} 976 1135 }; 977 1136 struct sess_param test_param; -
pjproject/trunk/pjnath/src/pjnath-test/server.c
r5170 r5350 54 54 char strbuf[100]; 55 55 pj_status_t status; 56 pj_bool_t use_ipv6 = flags & SERVER_IPV6; 56 57 57 58 PJ_ASSERT_RETURN(stun_cfg && domain && p_test_srv, PJ_EINVAL); 58 59 59 status = pj_gethostip( pj_AF_INET(), &hostip);60 status = pj_gethostip(GET_AF(use_ipv6), &hostip); 60 61 if (status != PJ_SUCCESS) 61 62 return status; … … 75 76 if (flags & CREATE_DNS_SERVER) { 76 77 status = pj_dns_server_create(mem, test_srv->stun_cfg->ioqueue, 77 pj_AF_INET(), DNS_SERVER_PORT,78 GET_AF(use_ipv6), DNS_SERVER_PORT, 78 79 0, &test_srv->dns_server); 79 80 if (status != PJ_SUCCESS) { … … 86 87 pj_dns_parsed_rr rr; 87 88 pj_str_t res_name; 88 pj_in_addr ip_addr;89 89 90 90 pj_strdup2(pool, &res_name, domain); 91 ip_addr = hostip.ipv4.sin_addr; 92 pj_dns_init_a_rr(&rr, &res_name, PJ_DNS_CLASS_IN, 60, &ip_addr); 91 92 if (use_ipv6) { 93 pj_dns_init_aaaa_rr(&rr, &res_name, PJ_DNS_CLASS_IN, 60, 94 &hostip.ipv6.sin6_addr); 95 } else { 96 pj_dns_init_a_rr(&rr, &res_name, PJ_DNS_CLASS_IN, 60, 97 &hostip.ipv4.sin_addr); 98 } 99 93 100 pj_dns_server_add_rec(test_srv->dns_server, 1, &rr); 94 101 } … … 103 110 stun_sock_cb.on_data_recvfrom = &stun_on_data_recvfrom; 104 111 105 pj_sockaddr_in_init(&bound_addr.ipv4, NULL, STUN_SERVER_PORT); 112 pj_sockaddr_init(GET_AF(use_ipv6), &bound_addr, 113 NULL, STUN_SERVER_PORT); 106 114 107 115 status = pj_activesock_create_udp(pool, &bound_addr, NULL, … … 124 132 pj_str_t res_name, target; 125 133 pj_dns_parsed_rr rr; 126 pj_in_addr ip_addr;127 134 128 135 /* Add DNS entries: … … 141 148 142 149 res_name = target; 143 ip_addr = hostip.ipv4.sin_addr; 144 pj_dns_init_a_rr(&rr, &res_name, PJ_DNS_CLASS_IN, 60, &ip_addr); 150 if (use_ipv6) { 151 pj_dns_init_aaaa_rr(&rr, &res_name, PJ_DNS_CLASS_IN, 60, 152 &hostip.ipv6.sin6_addr); 153 } else { 154 pj_dns_init_a_rr(&rr, &res_name, PJ_DNS_CLASS_IN, 60, 155 &hostip.ipv4.sin_addr); 156 } 145 157 pj_dns_server_add_rec(test_srv->dns_server, 1, &rr); 146 158 } … … 155 167 turn_sock_cb.on_data_recvfrom = &turn_on_data_recvfrom; 156 168 157 pj_sockaddr_in _init(&bound_addr.ipv4, NULL, TURN_SERVER_PORT);169 pj_sockaddr_init(GET_AF(use_ipv6), &bound_addr, NULL, TURN_SERVER_PORT); 158 170 159 171 status = pj_activesock_create_udp(pool, &bound_addr, NULL, … … 176 188 pj_str_t res_name, target; 177 189 pj_dns_parsed_rr rr; 178 pj_in_addr ip_addr;179 190 180 191 /* Add DNS entries: … … 193 204 194 205 res_name = target; 195 ip_addr = hostip.ipv4.sin_addr; 196 pj_dns_init_a_rr(&rr, &res_name, PJ_DNS_CLASS_IN, 60, &ip_addr); 206 207 if (use_ipv6) { 208 pj_dns_init_aaaa_rr(&rr, &res_name, PJ_DNS_CLASS_IN, 60, 209 &hostip.ipv6.sin6_addr); 210 } else { 211 pj_dns_init_a_rr(&rr, &res_name, PJ_DNS_CLASS_IN, 60, 212 &hostip.ipv4.sin_addr); 213 } 197 214 pj_dns_server_add_rec(test_srv->dns_server, 1, &rr); 198 215 } … … 345 362 unsigned i; 346 363 pj_ssize_t len; 364 pj_bool_t use_ipv6 = PJ_FALSE; 347 365 348 366 if (status != PJ_SUCCESS) … … 352 370 353 371 test_srv = (test_server*) pj_activesock_get_user_data(asock); 372 use_ipv6 = test_srv->flags & SERVER_IPV6; 354 373 pool = pj_pool_create(test_srv->stun_cfg->pf, NULL, 512, 512, NULL); 355 374 … … 481 500 alloc->pool = pj_pool_create(test_srv->stun_cfg->pf, "alloc", 512, 512, NULL); 482 501 483 /* Create relay socket */ 484 pj_sockaddr_in _init(&alloc->alloc_addr.ipv4, NULL, 0);485 pj_gethostip( pj_AF_INET(), &alloc->alloc_addr);502 /* Create relay socket */ 503 pj_sockaddr_init(GET_AF(use_ipv6), &alloc->alloc_addr, NULL, 0); 504 pj_gethostip(GET_AF(use_ipv6), &alloc->alloc_addr); 486 505 487 506 status = pj_activesock_create_udp(alloc->pool, &alloc->alloc_addr, NULL, … … 698 717 unsigned i; 699 718 719 PJ_UNUSED_ARG(addr_len); 720 700 721 if (status != PJ_SUCCESS) 701 722 return PJ_TRUE; … … 708 729 /* Check that this peer has a permission */ 709 730 for (i=0; i<alloc->perm_cnt; ++i) { 710 if (pj_sockaddr_get_len(&alloc->perm[i]) == (unsigned)addr_len && 711 pj_memcmp(pj_sockaddr_get_addr(&alloc->perm[i]), 712 pj_sockaddr_get_addr(src_addr), 713 addr_len) == 0) 731 if (pj_sockaddr_cmp(&alloc->perm[i], src_addr) == 0) 714 732 { 715 733 break; -
pjproject/trunk/pjnath/src/pjnath-test/server.h
r3553 r5350 40 40 CREATE_A_RECORD_FOR_DOMAIN = (1 << 1), 41 41 42 CREATE_STUN_SERVER = (1 << 5),43 CREATE_STUN_SERVER_DNS_SRV = (1 << 6),42 CREATE_STUN_SERVER = (1 << 4), 43 CREATE_STUN_SERVER_DNS_SRV = (1 << 5), 44 44 45 CREATE_TURN_SERVER = (1 << 10),46 CREATE_TURN_SERVER_DNS_SRV = (1 << 11),45 CREATE_TURN_SERVER = (1 << 8), 46 CREATE_TURN_SERVER_DNS_SRV = (1 << 9), 47 47 48 SERVER_IPV4 = (1 << 12), 49 SERVER_IPV6 = (1 << 13) 48 50 }; 49 51 -
pjproject/trunk/pjnath/src/pjnath-test/sess_auth.c
r4537 r5350 230 230 /* Instantiate standard server */ 231 231 static int create_std_server(pj_stun_auth_type auth_type, 232 pj_bool_t responding) 232 pj_bool_t responding, 233 pj_bool_t use_ipv6) 233 234 { 234 235 pj_pool_t *pool; … … 267 268 268 269 /* Create socket */ 269 status = pj_sock_socket( pj_AF_INET(), pj_SOCK_DGRAM(), 0, &server->sock);270 status = pj_sock_socket(GET_AF(use_ipv6), pj_SOCK_DGRAM(), 0, &server->sock); 270 271 if (status != PJ_SUCCESS) { 271 272 destroy_server(); … … 274 275 275 276 /* Bind */ 276 pj_sockaddr_in _init(&server->addr.ipv4, NULL, 0);277 pj_sockaddr_init(GET_AF(use_ipv6), &server->addr, NULL, 0); 277 278 status = pj_sock_bind(server->sock, &server->addr, pj_sockaddr_get_len(&server->addr)); 278 279 if (status != PJ_SUCCESS) { … … 290 291 } 291 292 292 status = pj_gethostip( pj_AF_INET(), &addr);293 status = pj_gethostip(GET_AF(use_ipv6), &addr); 293 294 if (status != PJ_SUCCESS) { 294 295 destroy_server(); … … 453 454 const char *password, 454 455 pj_bool_t dummy_mi, 455 456 pj_bool_t use_ipv6, 456 457 pj_bool_t expected_error, 457 458 pj_status_t expected_code, … … 466 467 pj_stun_tx_data *tdata; 467 468 pj_status_t status; 469 pj_sockaddr addr; 468 470 int rc = 0; 469 471 470 PJ_LOG(3,(THIS_FILE, " %s test ", title));472 PJ_LOG(3,(THIS_FILE, " %s test (%s)", title, use_ipv6?"IPv6":"IPv4")); 471 473 472 474 /* Create client */ … … 494 496 495 497 /* Create client socket */ 496 status = pj_sock_socket( pj_AF_INET(), pj_SOCK_DGRAM(), 0, &client->sock);498 status = pj_sock_socket(GET_AF(use_ipv6), pj_SOCK_DGRAM(), 0, &client->sock); 497 499 if (status != PJ_SUCCESS) { 498 500 destroy_client_server(); … … 501 503 502 504 /* Bind client socket */ 503 status = pj_sock_bind_in(client->sock, 0, 0); 505 pj_sockaddr_init(GET_AF(use_ipv6), &addr, NULL, 0); 506 status = pj_sock_bind(client->sock, &addr, pj_sockaddr_get_len(&addr)); 504 507 if (status != PJ_SUCCESS) { 505 508 destroy_client_server(); … … 529 532 530 533 /* Create the server */ 531 status = create_std_server(server_auth_type, server_responding );534 status = create_std_server(server_auth_type, server_responding, use_ipv6); 532 535 if (status != 0) { 533 536 destroy_client_server(); … … 681 684 done: 682 685 destroy_client_server(); 686 687 /* If IPv6 is enabled, test again for IPv4. */ 688 if ((rc == 0) && use_ipv6) { 689 rc = run_client_test(title, 690 server_responding, 691 server_auth_type, 692 client_auth_type, 693 realm, 694 username, 695 nonce, 696 password, 697 dummy_mi, 698 0, 699 expected_error, 700 expected_code, 701 expected_realm, 702 expected_nonce, 703 more_check); 704 } 705 683 706 return rc; 684 707 } … … 779 802 NULL, // password 780 803 PJ_FALSE, // dummy MI 804 USE_IPV6, // use IPv6 781 805 PJ_TRUE, // expected error 782 806 PJNATH_ESTUNTIMEDOUT,// expected code … … 809 833 NULL, // password 810 834 PJ_FALSE, // dummy MI 835 USE_IPV6, // use IPv6 811 836 PJ_TRUE, // expected error 812 837 PJ_STATUS_FROM_STUN_CODE(400),// expected code … … 833 858 "anotherpass", // password 834 859 PJ_FALSE, // dummy MI 860 USE_IPV6, // use IPv6 835 861 PJ_TRUE, // expected error 836 862 PJ_STATUS_FROM_STUN_CODE(401),// expected code … … 861 887 "anotherpass", // password 862 888 PJ_FALSE, // dummy MI 889 USE_IPV6, // use IPv6 863 890 PJ_TRUE, // expected error 864 891 PJ_STATUS_FROM_STUN_CODE(401),// expected code … … 883 910 NULL, // password 884 911 PJ_TRUE, // dummy MI 912 USE_IPV6, // use IPv6 885 913 PJ_TRUE, // expected error 886 914 PJ_STATUS_FROM_STUN_CODE(400), // expected code … … 903 931 PASSWORD, // password 904 932 PJ_FALSE, // dummy MI 933 USE_IPV6, // use IPv6 905 934 PJ_FALSE, // expected error 906 935 PJ_SUCCESS, // expected code … … 929 958 PASSWORD, // password 930 959 PJ_TRUE, // dummy MI 960 USE_IPV6, // use IPv6 931 961 PJ_TRUE, // expected error 932 962 PJ_STATUS_FROM_STUN_CODE(401), // expected code … … 962 992 NULL, // client password 963 993 PJ_FALSE, // client dummy MI 994 USE_IPV6, // use IPv6 964 995 PJ_TRUE, // expected error 965 996 PJ_STATUS_FROM_STUN_CODE(401), // expected code … … 988 1019 PASSWORD, // client password 989 1020 PJ_TRUE, // client dummy MI 1021 USE_IPV6, // use IPv6 990 1022 PJ_TRUE, // expected error 991 1023 PJ_STATUS_FROM_STUN_CODE(400), // expected code … … 1008 1040 PASSWORD, // client password 1009 1041 PJ_TRUE, // client dummy MI 1042 USE_IPV6, // use IPv6 1010 1043 PJ_TRUE, // expected error 1011 1044 PJ_STATUS_FROM_STUN_CODE(400), // expected code … … 1028 1061 PASSWORD, // client password 1029 1062 PJ_TRUE, // client dummy MI 1063 USE_IPV6, // use IPv6 1030 1064 PJ_TRUE, // expected error 1031 1065 PJ_STATUS_FROM_STUN_CODE(400), // expected code … … 1064 1098 "somepassword", // client password 1065 1099 PJ_FALSE, // client dummy MI 1100 USE_IPV6, // use IPv6 1066 1101 PJ_TRUE, // expected error 1067 1102 PJ_STATUS_FROM_STUN_CODE(401), // expected code … … 1084 1119 PASSWORD, // client password 1085 1120 PJ_FALSE, // client dummy MI 1121 USE_IPV6, // use IPv6 1086 1122 PJ_FALSE, // expected error 1087 1123 0, // expected code … … 1114 1150 PASSWORD, // client password 1115 1151 PJ_FALSE, // client dummy MI 1152 USE_IPV6, // use IPv6 1116 1153 PJ_TRUE, // expected error 1117 1154 PJ_STATUS_FROM_STUN_CODE(401), // expected code -
pjproject/trunk/pjnath/src/pjnath-test/stun_sock_test.c
r4898 r5350 90 90 /* Add MAPPED-ADDRESS or XOR-MAPPED-ADDRESS (or don't add) */ 91 91 if (srv->flag & WITH_MAPPED) { 92 pj_sockaddr_in addr; 93 94 pj_sockaddr_in_init(&addr, &srv->ip_to_send, srv->port_to_send); 92 pj_sockaddr addr; 93 pj_bool_t use_ipv6 = (srv->addr.addr.sa_family == pj_AF_INET6()); 94 95 pj_sockaddr_init(GET_AF(use_ipv6), &addr, &srv->ip_to_send, 96 srv->port_to_send); 97 95 98 pj_stun_msg_add_sockaddr_attr(pool, res_msg, PJ_STUN_ATTR_MAPPED_ADDR, 96 99 PJ_FALSE, &addr, sizeof(addr)); 97 100 } else if (srv->flag & WITH_XOR_MAPPED) { 98 pj_sockaddr_in addr; 99 100 pj_sockaddr_in_init(&addr, &srv->ip_to_send, srv->port_to_send); 101 pj_sockaddr addr; 102 pj_bool_t use_ipv6 = (srv->addr.addr.sa_family == pj_AF_INET6()); 103 104 pj_sockaddr_init(GET_AF(use_ipv6), &addr, &srv->ip_to_send, 105 srv->port_to_send); 106 101 107 pj_stun_msg_add_sockaddr_attr(pool, res_msg, 102 108 PJ_STUN_ATTR_XOR_MAPPED_ADDR, … … 134 140 pj_ioqueue_t *ioqueue, 135 141 unsigned flag, 142 pj_bool_t use_ipv6, 136 143 struct stun_srv **p_srv) 137 144 { … … 142 149 srv = PJ_POOL_ZALLOC_T(pool, struct stun_srv); 143 150 srv->flag = flag; 144 srv->ip_to_send = pj_str("1.1.1.1");151 srv->ip_to_send = (use_ipv6)?pj_str("2002:101:101::"):pj_str("1.1.1.1"); 145 152 srv->port_to_send = 1000; 146 153 147 status = pj_sockaddr_in _init(&srv->addr.ipv4, NULL, 0);154 status = pj_sockaddr_init(GET_AF(use_ipv6), &srv->addr, NULL, 0); 148 155 if (status != PJ_SUCCESS) 149 156 return status; … … 231 238 static pj_status_t create_client(pj_stun_config *cfg, 232 239 struct stun_client **p_client, 233 pj_bool_t destroy_on_err) 240 pj_bool_t destroy_on_err, 241 pj_bool_t use_ipv6) 234 242 { 235 243 pj_pool_t *pool; … … 248 256 cb.on_status = &stun_sock_on_status; 249 257 cb.on_rx_data = &stun_sock_on_rx_data; 250 status = pj_stun_sock_create(cfg, NULL, pj_AF_INET(), &cb,251 &sock_cfg,client, &client->sock);258 status = pj_stun_sock_create(cfg, NULL, GET_AF(use_ipv6), &cb, &sock_cfg, 259 client, &client->sock); 252 260 if (status != PJ_SUCCESS) { 253 261 app_perror(" pj_stun_sock_create()", status); … … 293 301 * Timeout test: scenario when no response is received from server 294 302 */ 295 static int timeout_test(pj_stun_config *cfg, pj_bool_t destroy_on_err) 303 static int timeout_test(pj_stun_config *cfg, pj_bool_t destroy_on_err, 304 pj_bool_t use_ipv6) 296 305 { 297 306 struct stun_srv *srv; … … 302 311 pj_status_t status; 303 312 304 PJ_LOG(3,(THIS_FILE, " timeout test [%d]", destroy_on_err)); 305 306 status = create_client(cfg, &client, destroy_on_err); 313 PJ_LOG(3,(THIS_FILE, " timeout test [%d] - (%s)", destroy_on_err, 314 (use_ipv6)?"IPv6":"IPv4")); 315 316 status = create_client(cfg, &client, destroy_on_err, use_ipv6); 307 317 if (status != PJ_SUCCESS) 308 318 return -10; 309 319 310 status = create_server(client->pool, cfg->ioqueue, 0, &srv);320 status = create_server(client->pool, cfg->ioqueue, 0, use_ipv6, &srv); 311 321 if (status != PJ_SUCCESS) { 312 322 destroy_client(client); … … 314 324 } 315 325 316 srv_addr = pj_str("127.0.0.1"); 326 srv_addr = (use_ipv6)?pj_str("::1"):pj_str("127.0.0.1"); 327 317 328 status = pj_stun_sock_start(client->sock, &srv_addr, 318 pj_ ntohs(srv->addr.ipv4.sin_port), NULL);329 pj_sockaddr_get_port(&srv->addr), NULL); 319 330 if (status != PJ_SUCCESS) { 320 331 destroy_server(srv); … … 362 373 for (i=0; i<7; ++i) 363 374 handle_events(cfg, 100); 375 376 if ((ret == 0) && use_ipv6) 377 ret = timeout_test(cfg, destroy_on_err, 0); 378 364 379 return ret; 365 380 } … … 370 385 * XOR-MAPPED-ADDRESS attribute. 371 386 */ 372 static int missing_attr_test(pj_stun_config *cfg, pj_bool_t destroy_on_err) 387 static int missing_attr_test(pj_stun_config *cfg, pj_bool_t destroy_on_err, 388 pj_bool_t use_ipv6) 373 389 { 374 390 struct stun_srv *srv; … … 379 395 pj_status_t status; 380 396 381 PJ_LOG(3,(THIS_FILE, " missing attribute test [%d]", destroy_on_err)); 382 383 status = create_client(cfg, &client, destroy_on_err); 397 PJ_LOG(3,(THIS_FILE, " missing attribute test [%d] - (%s)", 398 destroy_on_err, (use_ipv6)?"IPv6":"IPv4")); 399 400 status = create_client(cfg, &client, destroy_on_err, use_ipv6); 384 401 if (status != PJ_SUCCESS) 385 402 return -110; 386 403 387 status = create_server(client->pool, cfg->ioqueue, RESPOND_STUN, &srv); 404 status = create_server(client->pool, cfg->ioqueue, RESPOND_STUN, use_ipv6, 405 &srv); 388 406 if (status != PJ_SUCCESS) { 389 407 destroy_client(client); 390 408 return -120; 391 409 } 392 393 srv_addr = pj_str("127.0.0.1"); 410 srv_addr = (use_ipv6)?pj_str("::1"):pj_str("127.0.0.1"); 411 394 412 status = pj_stun_sock_start(client->sock, &srv_addr, 395 pj_ ntohs(srv->addr.ipv4.sin_port), NULL);413 pj_sockaddr_get_port(&srv->addr), NULL); 396 414 if (status != PJ_SUCCESS) { 397 415 destroy_server(srv); … … 431 449 for (i=0; i<7; ++i) 432 450 handle_events(cfg, 100); 451 452 if ((ret == 0) && use_ipv6) 453 ret = missing_attr_test(cfg, destroy_on_err, 0); 454 433 455 return ret; 434 456 } … … 437 459 * Keep-alive test. 438 460 */ 439 static int keep_alive_test(pj_stun_config *cfg )461 static int keep_alive_test(pj_stun_config *cfg, pj_bool_t use_ipv6) 440 462 { 441 463 struct stun_srv *srv; 442 464 struct stun_client *client; 443 pj_sockaddr _inmapped_addr;465 pj_sockaddr mapped_addr; 444 466 pj_stun_sock_info info; 445 467 pj_str_t srv_addr; … … 448 470 pj_status_t status; 449 471 450 PJ_LOG(3,(THIS_FILE, " normal operation")); 451 452 status = create_client(cfg, &client, PJ_TRUE); 472 PJ_LOG(3,(THIS_FILE, " normal operation - (%s)", 473 (use_ipv6)?"IPv6":"IPv4")); 474 475 status = create_client(cfg, &client, PJ_TRUE, use_ipv6); 453 476 if (status != PJ_SUCCESS) 454 477 return -310; 455 478 456 status = create_server(client->pool, cfg->ioqueue, RESPOND_STUN|WITH_XOR_MAPPED, &srv); 479 status = create_server(client->pool, cfg->ioqueue, RESPOND_STUN|WITH_XOR_MAPPED, 480 use_ipv6, &srv); 457 481 if (status != PJ_SUCCESS) { 458 482 destroy_client(client); … … 464 488 */ 465 489 PJ_LOG(3,(THIS_FILE, " initial Binding request")); 466 srv_addr = pj_str("127.0.0.1"); 490 491 srv_addr = (use_ipv6)?pj_str("::1"):pj_str("127.0.0.1"); 492 467 493 status = pj_stun_sock_start(client->sock, &srv_addr, 468 pj_ ntohs(srv->addr.ipv4.sin_port), NULL);494 pj_sockaddr_get_port(&srv->addr), NULL); 469 495 if (status != PJ_SUCCESS) { 470 496 destroy_server(srv); … … 522 548 } 523 549 /* verify the mapped address */ 524 pj_sockaddr_in_init(&mapped_addr, &srv->ip_to_send, srv->port_to_send); 550 pj_sockaddr_init(GET_AF(use_ipv6), &mapped_addr, 551 &srv->ip_to_send, srv->port_to_send); 525 552 if (pj_sockaddr_cmp(&info.mapped_addr, &mapped_addr) != 0) { 526 553 PJ_LOG(3,(THIS_FILE, " error: mapped address mismatched")); … … 659 686 660 687 /* Change mapped address in the response */ 661 srv->ip_to_send = pj_str("2.2.2.2");688 srv->ip_to_send = (use_ipv6)?pj_str("2002:202:202::"):pj_str("2.2.2.2"); 662 689 srv->port_to_send++; 663 690 … … 730 757 } 731 758 /* verify the mapped address */ 732 pj_sockaddr_in_init(&mapped_addr, &srv->ip_to_send, srv->port_to_send); 759 pj_sockaddr_init(GET_AF(use_ipv6), &mapped_addr, 760 &srv->ip_to_send, srv->port_to_send); 733 761 if (pj_sockaddr_cmp(&info.mapped_addr, &mapped_addr) != 0) { 734 762 PJ_LOG(3,(THIS_FILE, " error: mapped address mismatched")); … … 798 826 for (i=0; i<7; ++i) 799 827 handle_events(cfg, 100); 828 829 if ((ret == 0) && use_ipv6) 830 ret = keep_alive_test(cfg, 0); 831 800 832 return ret; 801 833 } … … 838 870 pj_stun_config_init(&stun_cfg, mem, 0, ioqueue, timer_heap); 839 871 840 DO_TEST(timeout_test(&stun_cfg, PJ_FALSE ));841 DO_TEST(timeout_test(&stun_cfg, PJ_TRUE ));842 843 DO_TEST(missing_attr_test(&stun_cfg, PJ_FALSE ));844 DO_TEST(missing_attr_test(&stun_cfg, PJ_TRUE ));845 846 DO_TEST(keep_alive_test(&stun_cfg ));872 DO_TEST(timeout_test(&stun_cfg, PJ_FALSE, USE_IPV6)); 873 DO_TEST(timeout_test(&stun_cfg, PJ_TRUE, USE_IPV6)); 874 875 DO_TEST(missing_attr_test(&stun_cfg, PJ_FALSE, USE_IPV6)); 876 DO_TEST(missing_attr_test(&stun_cfg, PJ_TRUE, USE_IPV6)); 877 878 DO_TEST(keep_alive_test(&stun_cfg, USE_IPV6)); 847 879 848 880 on_return: -
pjproject/trunk/pjnath/src/pjnath-test/test.h
r4360 r5350 27 27 #define INCLUDE_TURN_SOCK_TEST 1 28 28 #define INCLUDE_CONCUR_TEST 1 29 30 #define GET_AF(use_ipv6) (use_ipv6?pj_AF_INET6():pj_AF_INET()) 31 32 #if defined(PJ_HAS_IPV6) && PJ_HAS_IPV6 33 # define USE_IPV6 1 34 #else 35 # define USE_IPV6 0 36 #endif 29 37 30 38 int stun_test(void); -
pjproject/trunk/pjnath/src/pjnath-test/turn_sock_test.c
r3553 r5350 103 103 pj_stun_auth_cred cred; 104 104 pj_status_t status; 105 pj_bool_t use_ipv6 = cfg->srv.flags & SERVER_IPV6; 105 106 106 107 /* Create client */ … … 114 115 turn_sock_cb.on_rx_data = &turn_on_rx_data; 115 116 turn_sock_cb.on_state = &turn_on_state; 116 status = pj_turn_sock_create(sess->stun_cfg, pj_AF_INET(), PJ_TURN_TP_UDP, 117 &turn_sock_cb, 0, sess, &sess->turn_sock); 117 status = pj_turn_sock_create(sess->stun_cfg, 118 GET_AF(use_ipv6), 119 PJ_TURN_TP_UDP, 120 &turn_sock_cb, 121 0, 122 sess, 123 &sess->turn_sock); 118 124 if (status != PJ_SUCCESS) { 119 125 destroy_session(sess); … … 122 128 123 129 /* Create test server */ 124 status = create_test_server(sess->stun_cfg, cfg->srv.flags, 125 SRV_DOMAIN,&sess->test_srv);130 status = create_test_server(sess->stun_cfg, cfg->srv.flags, SRV_DOMAIN, 131 &sess->test_srv); 126 132 if (status != PJ_SUCCESS) { 127 133 destroy_session(sess); … … 140 146 141 147 } else { 142 pj_str_t dns_srv = pj_str("127.0.0.1");148 pj_str_t dns_srv = use_ipv6?pj_str("::1") : pj_str("127.0.0.1"); 143 149 pj_uint16_t dns_srv_port = (pj_uint16_t) DNS_SERVER_PORT; 144 150 status = pj_dns_resolver_set_ns(sess->resolver, 1, &dns_srv, &dns_srv_port); … … 171 177 } else { 172 178 /* Explicitly specify server address */ 173 pj_str_t host = pj_str("127.0.0.1");179 pj_str_t host = use_ipv6?pj_str("::1") : pj_str("127.0.0.1"); 174 180 status = pj_turn_sock_alloc(sess->turn_sock, &host, TURN_SERVER_PORT, 175 181 NULL, &cred, &alloc_param); … … 251 257 ///////////////////////////////////////////////////////////////////// 252 258 253 static int state_progression_test(pj_stun_config *stun_cfg) 259 static void set_server_flag(struct test_session_cfg *test_cfg, 260 pj_bool_t use_ipv6) 261 { 262 test_cfg->srv.flags &= ~(SERVER_IPV4+SERVER_IPV6); 263 test_cfg->srv.flags |= (use_ipv6)?SERVER_IPV6:SERVER_IPV4; 264 } 265 266 static int state_progression_test(pj_stun_config *stun_cfg, 267 pj_bool_t use_ipv6) 254 268 { 255 269 struct test_session_cfg test_cfg = 256 270 { 257 { /* Client cfg */ 258 /* DNS SRV */ /* Destroy on state */259 PJ_TRUE, 0xFFFF271 { /* Client cfg */ 272 PJ_TRUE, /* DNS SRV */ 273 0xFFFF /* Destroy on state */ 260 274 }, 261 275 { /* Server cfg */ … … 267 281 struct test_session *sess; 268 282 unsigned i; 269 int rc; 270 271 PJ_LOG(3,("", " state progression tests")); 272 283 int rc = 0; 284 285 PJ_LOG(3,("", " state progression tests - (%s)",use_ipv6?"IPv6":"IPv4")); 286 287 set_server_flag(&test_cfg, use_ipv6); 273 288 for (i=0; i<=1; ++i) { 274 289 enum { TIMEOUT = 60 }; … … 373 388 } 374 389 375 return 0; 390 if (use_ipv6) 391 rc = state_progression_test(stun_cfg, 0); 392 393 return rc; 376 394 } 377 395 … … 381 399 static int destroy_test(pj_stun_config *stun_cfg, 382 400 pj_bool_t with_dns_srv, 383 pj_bool_t in_callback) 401 pj_bool_t in_callback, 402 pj_bool_t use_ipv6) 384 403 { 385 404 struct test_session_cfg test_cfg = 386 405 { 387 { /* Client cfg */ 388 /* DNS SRV */ /* Destroy on state */389 PJ_TRUE, 0xFFFF406 { /* Client cfg */ 407 PJ_TRUE, /* DNS SRV */ 408 0xFFFF /* Destroy on state */ 390 409 }, 391 410 { /* Server cfg */ … … 405 424 406 425 test_cfg.client.enable_dns_srv = with_dns_srv; 426 set_server_flag(&test_cfg, use_ipv6); 407 427 408 428 for (target_state=PJ_TURN_STATE_RESOLVING; target_state<=PJ_TURN_STATE_READY; ++target_state) { … … 496 516 } 497 517 498 rc = state_progression_test(&stun_cfg );518 rc = state_progression_test(&stun_cfg, USE_IPV6); 499 519 if (rc != 0) 500 520 goto on_return; … … 503 523 int j; 504 524 for (j=0; j<=1; ++j) { 505 rc = destroy_test(&stun_cfg, i, j );525 rc = destroy_test(&stun_cfg, i, j, USE_IPV6); 506 526 if (rc != 0) 507 527 goto on_return; -
pjproject/trunk/pjnath/src/pjnath/stun_msg_dump.c
r5311 r5350 89 89 char addr[PJ_INET6_ADDRSTRLEN]; 90 90 const pj_stun_sockaddr_attr *attr; 91 pj_uint16_t af; 91 92 92 93 attr = (const pj_stun_sockaddr_attr*)ahdr; 93 94 if (attr->sockaddr.addr.sa_family == pj_AF_INET()) { 94 af = attr->sockaddr.addr.sa_family; 95 96 if ((af == pj_AF_INET()) || (af == pj_AF_INET6())) { 95 97 len = pj_ansi_snprintf(p, end-p, 96 ", IPv4 addr=%s:%d\n", 98 ", %s addr=%s\n", 99 (af == pj_AF_INET())?"IPv4":"IPv6", 97 100 pj_sockaddr_print(&attr->sockaddr, 98 addr, sizeof(addr),0), 99 pj_sockaddr_get_port(&attr->sockaddr)); 100 101 } else if (attr->sockaddr.addr.sa_family == pj_AF_INET6()) { 102 len = pj_ansi_snprintf(p, end-p, 103 ", IPv6 addr present\n"); 101 addr, sizeof(addr),3)); 104 102 } else { 105 103 len = pj_ansi_snprintf(p, end-p,
Note: See TracChangeset
for help on using the changeset viewer.