Changeset 5995


Ignore:
Timestamp:
May 17, 2019 9:37:18 AM (5 years ago)
Author:
ming
Message:

Fixed #2198: SIP resolve to return both IPv4 and IPv6 synthesized addresses (if any) for IPv4 address literals.

  • Also included in this changeset: ipv6 option of sample pjsua_app will now try IPv6 STUN, bind the account to IPv6 transport and set the IPv6 media
Location:
pjproject/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c

    r5994 r5995  
    12311231{ 
    12321232    pjsua_transport_id transport_id = -1; 
     1233    pjsua_transport_id udp6_tp_id = -1, tcp6_tp_id = -1, tls6_tp_id = -1; 
    12331234    pjsua_transport_config tcp_cfg; 
    12341235    unsigned i; 
     
    12591260        return status; 
    12601261    } 
     1262     
     1263    if (app_config.ipv6) 
     1264        app_config.cfg.stun_try_ipv6 = PJ_TRUE; 
    12611265 
    12621266    /* Initialize application callbacks */ 
     
    15851589        if (status != PJ_SUCCESS) 
    15861590            goto on_error; 
     1591        udp6_tp_id = transport_id; 
    15871592 
    15881593        /* Add local account */ 
     
    16501655        if (status != PJ_SUCCESS) 
    16511656            goto on_error; 
     1657        tcp6_tp_id = transport_id; 
    16521658 
    16531659        /* Add local account */ 
     
    16891695        if (status != PJ_SUCCESS) 
    16901696            goto on_error; 
     1697        tls6_tp_id = transport_id; 
    16911698         
    16921699        /* Add local account */ 
     
    17511758        app_config.acc_cfg[i].reg_retry_interval = 300; 
    17521759        app_config.acc_cfg[i].reg_first_retry_interval = 60; 
     1760        if (app_config.ipv6) { 
     1761            pj_str_t *dst_uri = NULL; 
     1762            pj_str_t tmp; 
     1763            pjsip_uri *uri; 
     1764 
     1765            // Uncomment this for testing in a NAT64 network 
     1766            // app_config.acc_cfg[i].nat64_opt = PJSUA_NAT64_ENABLED; 
     1767            app_config.acc_cfg[i].ipv6_media_use = PJSUA_IPV6_ENABLED; 
     1768 
     1769            if ((app_config.cfg.outbound_proxy_cnt > 0) && 
     1770                (app_config.acc_cfg[i].reg_use_proxy == 1 /* outbound */ || 
     1771                 app_config.acc_cfg[i].reg_use_proxy == 3 /* all */)) 
     1772            { 
     1773                dst_uri = &app_config.cfg.outbound_proxy[0]; 
     1774            } else if ((app_config.acc_cfg[i].proxy_cnt > 0) && 
     1775                (app_config.acc_cfg[i].reg_use_proxy == 2 /* acc */ || 
     1776                 app_config.acc_cfg[i].reg_use_proxy == 3 /* all */)) 
     1777            { 
     1778                dst_uri = &app_config.acc_cfg[i].proxy[0]; 
     1779            } else if (app_config.acc_cfg[i].reg_uri.slen > 0) { 
     1780                dst_uri = &app_config.acc_cfg[i].reg_uri; 
     1781            } 
     1782             
     1783            pj_strdup_with_null(app_config.pool, &tmp, dst_uri); 
     1784 
     1785            uri = pjsip_parse_uri(app_config.pool, tmp.ptr, tmp.slen, 0); 
     1786            if (uri != NULL) { 
     1787                pjsip_sip_uri *sip_uri; 
     1788                pjsip_transport_type_e tp_type = PJSIP_TRANSPORT_UNSPECIFIED;    
     1789                 
     1790                sip_uri = (pjsip_sip_uri*)pjsip_uri_get_uri(uri); 
     1791 
     1792                /* Get transport type of the URI */ 
     1793                if (PJSIP_URI_SCHEME_IS_SIPS(sip_uri)) { 
     1794                    tp_type = PJSIP_TRANSPORT_TLS; 
     1795                } else if (sip_uri->transport_param.slen == 0) { 
     1796                    tp_type = PJSIP_TRANSPORT_UDP; 
     1797                } else { 
     1798                    tp_type = pjsip_transport_get_type_from_name( 
     1799                                  &sip_uri->transport_param); 
     1800                    tp_type &= ~ PJSIP_TRANSPORT_IPV6; 
     1801                } 
     1802                 
     1803                if (tp_type == PJSIP_TRANSPORT_UDP) { 
     1804                    app_config.acc_cfg[i].transport_id = udp6_tp_id; 
     1805                } else if (tp_type == PJSIP_TRANSPORT_TCP) { 
     1806                    app_config.acc_cfg[i].transport_id = tcp6_tp_id; 
     1807                } else if (tp_type == PJSIP_TRANSPORT_TLS) { 
     1808                    app_config.acc_cfg[i].transport_id = tls6_tp_id; 
     1809                } 
     1810            } 
     1811        } 
    17531812 
    17541813        app_config_init_video(&app_config.acc_cfg[i]); 
  • pjproject/trunk/pjsip/src/pjsip/sip_resolve.c

    r5984 r5995  
    277277            svr_addr.count = 1; 
    278278            if (ip_addr_ver == 4) { 
    279                 if (af == pj_AF_INET6()) { 
     279                if (af == pj_AF_INET()) { 
     280                    pj_sockaddr_init(pj_AF_INET(), &svr_addr.entry[0].addr,  
     281                                     NULL, 0); 
     282                    pj_inet_pton(pj_AF_INET(), &target->addr.host, 
     283                                 &svr_addr.entry[0].addr.ipv4.sin_addr); 
     284                } 
     285 
     286                if (af == pj_AF_INET6() || PJSIP_MAX_RESOLVED_ADDRESSES > 1) 
     287                { 
    280288                    /* Generate a synthesized IPv6 address, if possible. */ 
    281289                    unsigned int count = 1; 
     
    288296                        ai[0].ai_addr.addr.sa_family == pj_AF_INET6()) 
    289297                    { 
     298                        unsigned idx = 0; 
     299                         
     300                        if (target->type == PJSIP_TRANSPORT_UNSPECIFIED) { 
     301                            idx = 1; 
     302                            svr_addr.count++; 
     303                        } 
    290304                        pj_sockaddr_init(pj_AF_INET6(), 
    291                                          &svr_addr.entry[0].addr, 
     305                                         &svr_addr.entry[idx].addr, 
    292306                                         NULL, 0); 
    293                         svr_addr.entry[0].addr.ipv6.sin6_addr = 
     307                        svr_addr.entry[idx].addr.ipv6.sin6_addr = 
    294308                            ai[0].ai_addr.ipv6.sin6_addr; 
    295                     } else { 
    296                         pj_sockaddr_init(pj_AF_INET(), 
    297                                          &svr_addr.entry[0].addr, NULL, 0); 
    298                         pj_inet_pton(pj_AF_INET(), &target->addr.host, 
    299                                      &svr_addr.entry[0].addr.ipv4.sin_addr); 
     309                    } else if (af == pj_AF_INET6()) { 
     310                        svr_addr.count = 0; 
     311                        status = PJ_ERESOLVE; 
     312                        goto on_error; 
    300313                    } 
    301                 } else { 
    302                     pj_sockaddr_init(pj_AF_INET(), &svr_addr.entry[0].addr,  
    303                                      NULL, 0); 
    304                     pj_inet_pton(pj_AF_INET(), &target->addr.host, 
    305                                  &svr_addr.entry[0].addr.ipv4.sin_addr); 
    306314                } 
    307315            } else { 
Note: See TracChangeset for help on using the changeset viewer.