Ignore:
Timestamp:
Apr 3, 2007 7:15:10 PM (17 years ago)
Author:
bennylp
Message:

Added ICE-CONTROLLED and ICE-CONTROLLING attribute, handle ICE 487 error, and add response source address checking

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjnath/src/pjnath/ice_session.c

    r1140 r1141  
    116116                                     pj_status_t status, 
    117117                                     pj_stun_tx_data *tdata, 
    118                                      const pj_stun_msg *response); 
     118                                     const pj_stun_msg *response, 
     119                                     const pj_sockaddr_t *src_addr, 
     120                                     unsigned src_addr_len); 
    119121static pj_status_t on_stun_rx_indication(pj_stun_session *sess, 
    120122                                         const pj_uint8_t *pkt, 
     
    12071209                              PJ_STUN_ATTR_PRIORITY, prio); 
    12081210 
    1209     /* Add USE-CANDIDATE and set this check to nominated */ 
     1211    /* Add USE-CANDIDATE and set this check to nominated. 
     1212     * Also add ICE-CONTROLLING or ICE-CONTROLLED 
     1213     */ 
    12101214    if (ice->role == PJ_ICE_SESS_ROLE_CONTROLLING) { 
    12111215        pj_stun_msg_add_empty_attr(check->tdata->pool, check->tdata->msg,  
    12121216                                   PJ_STUN_ATTR_USE_CANDIDATE); 
    12131217        check->nominated = PJ_TRUE; 
    1214     } 
     1218 
     1219        pj_stun_msg_add_uint64_attr(check->tdata->pool, check->tdata->msg,  
     1220                                    PJ_STUN_ATTR_ICE_CONTROLLING, 
     1221                                    &ice->tie_breaker); 
     1222 
     1223    } else { 
     1224        pj_stun_msg_add_uint64_attr(check->tdata->pool, check->tdata->msg,  
     1225                                    PJ_STUN_ATTR_ICE_CONTROLLED, 
     1226                                    &ice->tie_breaker); 
     1227    } 
     1228 
    12151229 
    12161230    /* Note that USERNAME and MESSAGE-INTEGRITY will be added by the  
     
    14291443                                     pj_status_t status, 
    14301444                                     pj_stun_tx_data *tdata, 
    1431                                      const pj_stun_msg *response) 
     1445                                     const pj_stun_msg *response, 
     1446                                     const pj_sockaddr_t *src_addr, 
     1447                                     unsigned src_addr_len) 
    14321448{ 
    14331449    struct req_data *rd = (struct req_data*) tdata->user_data; 
     
    14411457 
    14421458    PJ_UNUSED_ARG(stun_sess); 
     1459    PJ_UNUSED_ARG(src_addr_len); 
    14431460 
    14441461    ice = rd->ice; 
     
    14571474    lcand = NULL; 
    14581475 
    1459     LOG4((ice->obj_name,  
    1460          "Check %s%s: connectivity check %s", 
    1461          dump_check(buffer, sizeof(buffer), &ice->clist, check), 
    1462          (check->nominated ? " (nominated)" : " (not nominated)"), 
    1463          (status==PJ_SUCCESS ? "SUCCESS" : "FAILED"))); 
    1464  
    14651476    if (status != PJ_SUCCESS) { 
     1477        char errmsg[PJ_ERR_MSG_SIZE]; 
     1478 
     1479        if (status==PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_ROLE_CONFLICT)) { 
     1480            /* Role conclict response. 
     1481             * 7.1.2.1.  Failure Cases: 
     1482             * If the request had contained the ICE-CONTROLLED attribute,  
     1483             * the agent MUST switch to the controlling role if it has not 
     1484             * already done so.  If the request had contained the  
     1485             * ICE-CONTROLLING attribute, the agent MUST switch to the  
     1486             * controlled role if it has not already done so.  Once it has 
     1487             * switched, the agent MUST immediately retry the request with 
     1488             * the ICE-CONTROLLING or ICE-CONTROLLED attribute reflecting  
     1489             * its new role. 
     1490             */ 
     1491            pj_ice_sess_role new_role = PJ_ICE_SESS_ROLE_UNKNOWN; 
     1492            pj_stun_msg *req = tdata->msg; 
     1493 
     1494            if (pj_stun_msg_find_attr(req, PJ_STUN_ATTR_ICE_CONTROLLING, 0)) { 
     1495                new_role = PJ_ICE_SESS_ROLE_CONTROLLED; 
     1496            } else if (pj_stun_msg_find_attr(req, PJ_STUN_ATTR_ICE_CONTROLLED,  
     1497                                             0)) { 
     1498                new_role = PJ_ICE_SESS_ROLE_CONTROLLING; 
     1499            } else { 
     1500                pj_assert(!"We should have put CONTROLLING/CONTROLLED attr!"); 
     1501                new_role = PJ_ICE_SESS_ROLE_CONTROLLED; 
     1502            } 
     1503 
     1504            if (new_role != ice->role) { 
     1505                LOG4((ice->obj_name,  
     1506                      "Changing role because of role conflict")); 
     1507                pj_ice_sess_change_role(ice, new_role); 
     1508            } 
     1509 
     1510            /* Resend request */ 
     1511            LOG4((ice->obj_name, "Resending check because of role conflict")); 
     1512            check_set_state(ice, check, PJ_ICE_SESS_CHECK_STATE_WAITING, 0); 
     1513            perform_check(ice, clist, rd->ckid); 
     1514            pj_mutex_unlock(ice->mutex); 
     1515            return; 
     1516        } 
     1517 
     1518        pj_strerror(status, errmsg, sizeof(errmsg)); 
     1519        LOG4((ice->obj_name,  
     1520             "Check %s%s: connectivity check FAILED: %s", 
     1521             dump_check(buffer, sizeof(buffer), &ice->clist, check), 
     1522             (check->nominated ? " (nominated)" : " (not nominated)"), 
     1523             errmsg)); 
     1524 
    14661525        check_set_state(ice, check, PJ_ICE_SESS_CHECK_STATE_FAILED, status); 
    14671526        on_check_complete(ice, check); 
     
    14691528        return; 
    14701529    } 
     1530 
    14711531 
    14721532    /* The agent MUST check that the source IP address and port of the 
     
    14761536     * Request was sent from. 
    14771537     */ 
    1478     PJ_TODO(ICE_CHECK_RESPONSE_SOURCE_ADDRESS); 
     1538    if (sockaddr_cmp(&check->rcand->addr, src_addr) != 0) { 
     1539        status = PJNATH_EICEINSRCADDR; 
     1540        LOG4((ice->obj_name,  
     1541             "Check %s%s: connectivity check FAILED: source address mismatch", 
     1542             dump_check(buffer, sizeof(buffer), &ice->clist, check), 
     1543             (check->nominated ? " (nominated)" : " (not nominated)"))); 
     1544        check_set_state(ice, check, PJ_ICE_SESS_CHECK_STATE_FAILED, status); 
     1545        on_check_complete(ice, check); 
     1546        pj_mutex_unlock(ice->mutex); 
     1547        return; 
     1548    } 
     1549 
     1550    LOG4((ice->obj_name,  
     1551         "Check %s%s: connectivity check SUCCESS", 
     1552         dump_check(buffer, sizeof(buffer), &ice->clist, check), 
     1553         (check->nominated ? " (nominated)" : " (not nominated)"))); 
    14791554 
    14801555    /* Get the STUN XOR-MAPPED-ADDRESS attribute. */ 
Note: See TracChangeset for help on using the changeset viewer.