Changeset 5481 for pjproject


Ignore:
Timestamp:
Nov 14, 2016 6:13:01 AM (7 years ago)
Author:
nanang
Message:

Re #1971: Request IPv4 relay address to an IPv6 TURN server for IPv6-IPv4 connectivity.

Location:
pjproject/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjnath/include/pjnath/config.h

    r5339 r5481  
    264264 */ 
    265265#ifndef PJ_ICE_MAX_TURN 
    266 #   define PJ_ICE_MAX_TURN                          2 
     266#   define PJ_ICE_MAX_TURN                          3 
    267267#endif 
    268268 
  • pjproject/trunk/pjnath/include/pjnath/turn_session.h

    r4606 r5481  
    330330     */ 
    331331    int     ka_interval; 
     332 
     333    /** 
     334     * The requested ADDRESS-FAMILY. Default is zero to request relay with 
     335     * address family matched to the one specified in TURN session creation. 
     336     * Valid values are zero, pj_AF_INET(), and pj_AF_INET6(). 
     337     * 
     338     * Default value is zero. 
     339     */ 
     340    int     af; 
     341 
    332342 
    333343} pj_turn_alloc_param; 
  • pjproject/trunk/pjnath/src/pjnath/ice_strans.c

    r5474 r5481  
    19921992        comp->default_cand = (unsigned)(cand - comp->cand_list); 
    19931993 
     1994        /* Prefer IPv4 relay as default candidate for better connectivity 
     1995         * with IPv4 endpoints. 
     1996         */ 
     1997        if (cand->addr.addr.sa_family != pj_AF_INET()) { 
     1998            for (i=0; i<comp->cand_cnt; ++i) { 
     1999                if (comp->cand_list[i].type == PJ_ICE_CAND_TYPE_RELAYED && 
     2000                    comp->cand_list[i].addr.addr.sa_family == pj_AF_INET() && 
     2001                    comp->cand_list[i].status == PJ_SUCCESS) 
     2002                { 
     2003                    comp->default_cand = i; 
     2004                    break; 
     2005                } 
     2006            } 
     2007        } 
     2008 
    19942009        PJ_LOG(4,(comp->ice_st->obj_name, 
    19952010                  "Comp %d: TURN allocation complete, relay address is %s", 
  • pjproject/trunk/pjnath/src/pjnath/turn_session.c

    r5469 r5481  
    725725                     PJ_EINVALIDOP); 
    726726 
     727    /* Verify address family in allocation param */ 
     728    if (param && param->af) { 
     729        PJ_ASSERT_RETURN(param->af==pj_AF_INET() || param->af==pj_AF_INET6(), 
     730                         PJ_EINVAL); 
     731    } 
     732 
    727733    pj_grp_lock_acquire(sess->grp_lock); 
    728734 
     
    771777    } 
    772778 
    773     /* Include ADDRESS-FAMILY for IPv6 request */ 
    774     if (sess->af == pj_AF_INET6()) { 
    775         enum { IPV6_AF_TYPE = 0x02 << 24 }; 
    776         pj_stun_msg_add_uint_attr(tdata->pool, tdata->msg, 
    777                                   PJ_STUN_ATTR_REQ_ADDR_TYPE, IPV6_AF_TYPE); 
     779    /* Include ADDRESS-FAMILY if requested */ 
     780    if (sess->alloc_param.af || sess->af == pj_AF_INET6()) { 
     781        enum  { IPV4_AF_TYPE = 0x01 << 24, 
     782                IPV6_AF_TYPE = 0x02 << 24 }; 
     783 
     784        if (sess->alloc_param.af == pj_AF_INET6() || 
     785            (sess->alloc_param.af == 0 && sess->af == pj_AF_INET6())) 
     786        { 
     787            pj_stun_msg_add_uint_attr(tdata->pool, tdata->msg, 
     788                                      PJ_STUN_ATTR_REQ_ADDR_TYPE, IPV6_AF_TYPE); 
     789        } else if (sess->alloc_param.af == pj_AF_INET()) { 
     790            /* For IPv4, only add the attribute when explicitly requested */ 
     791            pj_stun_msg_add_uint_attr(tdata->pool, tdata->msg, 
     792                                      PJ_STUN_ATTR_REQ_ADDR_TYPE, IPV4_AF_TYPE); 
     793        } 
    778794    } 
    779795 
     
    13591375        return; 
    13601376    } 
    1361     if (raddr_attr && raddr_attr->sockaddr.addr.sa_family != sess->af) { 
     1377    if (raddr_attr && 
     1378        ((sess->alloc_param.af != 0 && 
     1379          raddr_attr->sockaddr.addr.sa_family != sess->alloc_param.af) || 
     1380         (sess->alloc_param.af == 0 && 
     1381          raddr_attr->sockaddr.addr.sa_family != sess->af))) 
     1382    { 
    13621383        on_session_fail(sess, method, PJNATH_EINSTUNMSG, 
    13631384                        pj_cstr(&s, "Error: Mismatched RELAY-ADDRESS " 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c

    r5462 r5481  
    927927        ice_cfg.turn_tp_cnt = 1; 
    928928        pj_ice_strans_turn_cfg_default(&ice_cfg.turn_tp[0]); 
    929         if (use_ipv6 && PJ_ICE_MAX_TURN >= 2) { 
    930             ice_cfg.turn_tp_cnt = 2; 
     929        if (use_ipv6 && PJ_ICE_MAX_TURN >= 3) { 
     930            ice_cfg.turn_tp_cnt = 3; 
     931 
    931932            pj_ice_strans_turn_cfg_default(&ice_cfg.turn_tp[1]); 
    932933            ice_cfg.turn_tp[1].af = pj_AF_INET6(); 
     934 
     935            /* Additional candidate: IPv4 relay via IPv6 TURN server */ 
     936            pj_ice_strans_turn_cfg_default(&ice_cfg.turn_tp[2]); 
     937            ice_cfg.turn_tp[2].af = pj_AF_INET6(); 
     938            ice_cfg.turn_tp[2].alloc_param.af = pj_AF_INET(); 
    933939        } 
    934940 
     
    957963                      &acc_cfg->turn_cfg.turn_auth_cred, 
    958964                      sizeof(ice_cfg.turn_tp[1].auth_cred)); 
     965 
     966            ice_cfg.turn_tp[2].server    = ice_cfg.turn_tp[0].server; 
     967            ice_cfg.turn_tp[2].port      = ice_cfg.turn_tp[0].port; 
     968            ice_cfg.turn_tp[2].conn_type = ice_cfg.turn_tp[0].conn_type; 
     969            pj_memcpy(&ice_cfg.turn_tp[2].auth_cred,  
     970                      &acc_cfg->turn_cfg.turn_auth_cred, 
     971                      sizeof(ice_cfg.turn_tp[2].auth_cred)); 
    959972        } 
    960973 
     
    967980            pj_memcpy(&ice_cfg.turn_tp[1].cfg.qos_params, &cfg->qos_params, 
    968981                      sizeof(cfg->qos_params)); 
     982 
     983            ice_cfg.turn_tp[2].cfg.qos_type = cfg->qos_type; 
     984            pj_memcpy(&ice_cfg.turn_tp[2].cfg.qos_params, &cfg->qos_params, 
     985                      sizeof(cfg->qos_params)); 
    969986        } 
    970987 
     
    9841001            ice_cfg.turn_tp[1].cfg.port_range = 
    9851002                            ice_cfg.turn_tp[0].cfg.port_range; 
     1003 
     1004            pj_sockaddr_init(pj_AF_INET6(), 
     1005                             &ice_cfg.turn_tp[2].cfg.bound_addr, 
     1006                             &IN6_ADDR_ANY, (pj_uint16_t)cfg->port); 
     1007            ice_cfg.turn_tp[2].cfg.port_range = 
     1008                            ice_cfg.turn_tp[0].cfg.port_range; 
    9861009        } 
    9871010 
    9881011        /* Configure max packet size */ 
    9891012        ice_cfg.turn_tp[0].cfg.max_pkt_size = PJMEDIA_MAX_MRU; 
    990         if (use_ipv6 && ice_cfg.turn_tp_cnt > 1) 
     1013        if (use_ipv6 && ice_cfg.turn_tp_cnt > 1) { 
    9911014            ice_cfg.turn_tp[1].cfg.max_pkt_size = PJMEDIA_MAX_MRU; 
     1015            ice_cfg.turn_tp[2].cfg.max_pkt_size = PJMEDIA_MAX_MRU; 
     1016        } 
    9921017    } 
    9931018 
Note: See TracChangeset for help on using the changeset viewer.