Changeset 2316


Ignore:
Timestamp:
Sep 24, 2008 4:52:41 PM (16 years ago)
Author:
bennylp
Message:

Ticket #643: Do not try to re-register with a new Contact when the REGISTER response contains private IP address

Location:
pjproject/trunk
Files:
2 edited

Legend:

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

    r2301 r2316  
    13581358 
    13591359    /*  */ 
    1360     if (acc_cfg->allow_contact_rewrite==0) 
     1360    if (acc_cfg->allow_contact_rewrite!=1) 
    13611361    { 
    13621362        pj_ansi_sprintf(line, "--auto-update-nat %i\n", 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c

    r2301 r2316  
    538538} 
    539539 
     540/* Check if IP is private IP address */ 
     541static pj_bool_t is_private_ip(const pj_str_t *addr) 
     542{ 
     543    const pj_str_t private_net[] =  
     544    { 
     545        { "10.", 3 }, 
     546        { "127.", 4 }, 
     547        { "172.16.", 7 }, 
     548        { "192.168.", 8 } 
     549    }; 
     550    unsigned i; 
     551 
     552    for (i=0; i<PJ_ARRAY_SIZE(private_net); ++i) { 
     553        if (pj_strncmp(addr, &private_net[i], private_net[i].slen)==0) 
     554            return PJ_TRUE; 
     555    } 
     556 
     557    return PJ_FALSE; 
     558} 
    540559 
    541560/* Update NAT address from the REGISTER response */ 
     
    549568    pjsip_sip_uri *uri; 
    550569    pjsip_via_hdr *via; 
     570    pj_str_t srv_ip; 
    551571 
    552572    tp = param->rdata->tp_info.transport; 
     
    614634    } 
    615635 
     636    /* Get server IP */ 
     637    srv_ip = pj_str(param->rdata->pkt_info.src_name); 
     638 
    616639    /* At this point we've detected that the address as seen by registrar. 
    617640     * has changed. 
    618641     */ 
     642 
     643    /* Do not switch if both Contact and server's IP address are 
     644     * public but response contains private IP. A NAT in the middle 
     645     * might have messed up with the SIP packets. 
     646     */ 
     647    if (!is_private_ip(&uri->host) && !is_private_ip(&srv_ip) && 
     648        is_private_ip(via_addr)) 
     649    { 
     650        /* Don't switch */ 
     651        pj_pool_release(pool); 
     652        return PJ_FALSE; 
     653    } 
     654 
    619655    PJ_LOG(3,(THIS_FILE, "IP address change detected for account %d " 
    620656                         "(%.*s:%d --> %.*s:%d). Updating registration..", 
Note: See TracChangeset for help on using the changeset viewer.