Update the node address to the IP address that can be extracted * from link->fd, or if hdr->myip is non empty, to the address the node * is announcing us. The port is taken from the packet header as well. * * If the address or port changed, disconnect the node link so that we'll * connect again to the new address. * * If the ip/port pair are already correct no operation is performed at * a
| 1566 | * The function returns 0 if the node address is still the same, |
| 1567 | * otherwise 1 is returned. */ |
| 1568 | int nodeUpdateAddressIfNeeded(clusterNode *node, clusterLink *link, |
| 1569 | clusterMsg *hdr) |
| 1570 | { |
| 1571 | char ip[NET_IP_STR_LEN] = {0}; |
| 1572 | int port = ntohs(hdr->port); |
| 1573 | int pport = ntohs(hdr->pport); |
| 1574 | int cport = ntohs(hdr->cport); |
| 1575 | |
| 1576 | /* We don't proceed if the link is the same as the sender link, as this |
| 1577 | * function is designed to see if the node link is consistent with the |
| 1578 | * symmetric link that is used to receive PINGs from the node. |
| 1579 | * |
| 1580 | * As a side effect this function never frees the passed 'link', so |
| 1581 | * it is safe to call during packet processing. */ |
| 1582 | if (link == node->link) return 0; |
| 1583 | |
| 1584 | nodeIp2String(ip,link,hdr->myip); |
| 1585 | if (node->port == port && node->cport == cport && node->pport == pport && |
| 1586 | strcmp(ip,node->ip) == 0) return 0; |
| 1587 | |
| 1588 | /* IP / port is different, update it. */ |
| 1589 | memcpy(node->ip,ip,sizeof(ip)); |
| 1590 | node->port = port; |
| 1591 | node->pport = pport; |
| 1592 | node->cport = cport; |
| 1593 | if (node->link) freeClusterLink(node->link); |
| 1594 | node->flags &= ~CLUSTER_NODE_NOADDR; |
| 1595 | serverLog(LL_WARNING,"Address updated for node %.40s, now %s:%d", |
| 1596 | node->name, node->ip, node->port); |
| 1597 | |
| 1598 | /* Check if this is our master and we have to change the |
| 1599 | * replication target as well. */ |
| 1600 | if (nodeIsSlave(myself) && myself->slaveof == node) |
| 1601 | replicationSetMaster(node->ip, node->port); |
| 1602 | return 1; |
| 1603 | } |
| 1604 | |
| 1605 | /* Reconfigure the specified node 'n' as a master. This function is called when |
| 1606 | * a node that we believed to be a slave is now acting as master in order to |
no test coverage detected