When a device registers we need to unlink them (if linked) from the peers_by_ip conta...
[asterisk/asterisk.git] / channels / chan_sip.c
index 51fc59b..ae9e99c 100644 (file)
@@ -11153,6 +11153,11 @@ static enum parse_register_result parse_register_contact(struct sip_pvt *pvt, st
 
        oldsin = peer->addr;
 
+       /* If we were already linked into the peers_by_ip container unlink ourselves so nobody can find us */
+       if (peer->addr.sin_addr.s_addr) {
+               ao2_t_unlink(peers_by_ip, peer, "ao2_unlink of peer from peers_by_ip table");
+       }
+
        /* Check that they're allowed to register at this IP */
        /* XXX This could block for a long time XXX */
        /*! \todo Check NAPTR/SRV if we have not got a port in the URI */
@@ -11184,6 +11189,9 @@ static enum parse_register_result parse_register_contact(struct sip_pvt *pvt, st
                peer->addr = pvt->recv;
        }
 
+       /* Now that our address has been updated put ourselves back into the container for lookups */
+       ao2_t_link(peers_by_ip, peer, "ao2_link into peers_by_ip table");
+
        /* Save SIP options profile */
        peer->sipoptions = pvt->sipoptions;