When this function is called, there is a packet to process starting * at node->rcvbuf. Releasing the buffer is up to the caller, so this * function should just handle the higher level stuff of processing the * packet, modifying the cluster state if needed. * * The function returns 1 if the link is still valid after the packet * was processed, otherwise 0 if the link was freed since the packe
| 1795 | * processing lead to some inconsistency error (for instance a PONG |
| 1796 | * received from the wrong sender ID). */ |
| 1797 | int clusterProcessPacket(clusterLink *link) { |
| 1798 | serverAssert(ielFromEventLoop(serverTL->el) == IDX_EVENT_LOOP_MAIN); |
| 1799 | |
| 1800 | clusterMsg *hdr = (clusterMsg*) link->rcvbuf; |
| 1801 | uint32_t totlen = ntohl(hdr->totlen); |
| 1802 | uint16_t type = ntohs(hdr->type); |
| 1803 | mstime_t now = mstime(); |
| 1804 | |
| 1805 | if (type < CLUSTERMSG_TYPE_COUNT) |
| 1806 | g_pserver->cluster->stats_bus_messages_received[type]++; |
| 1807 | serverLog(LL_DEBUG,"--- Processing packet of type %d, %lu bytes", |
| 1808 | type, (unsigned long) totlen); |
| 1809 | |
| 1810 | /* Perform sanity checks */ |
| 1811 | if (totlen < 16) return 1; /* At least signature, version, totlen, count. */ |
| 1812 | if (totlen > link->rcvbuf_len) return 1; |
| 1813 | |
| 1814 | if (ntohs(hdr->ver) != CLUSTER_PROTO_VER) { |
| 1815 | /* Can't handle messages of different versions. */ |
| 1816 | return 1; |
| 1817 | } |
| 1818 | |
| 1819 | uint16_t flags = ntohs(hdr->flags); |
| 1820 | uint64_t senderCurrentEpoch = 0, senderConfigEpoch = 0; |
| 1821 | clusterNode *sender; |
| 1822 | |
| 1823 | if (type == CLUSTERMSG_TYPE_PING || type == CLUSTERMSG_TYPE_PONG || |
| 1824 | type == CLUSTERMSG_TYPE_MEET) |
| 1825 | { |
| 1826 | uint16_t count = ntohs(hdr->count); |
| 1827 | uint32_t explen; /* expected length of this packet */ |
| 1828 | |
| 1829 | explen = sizeof(clusterMsg)-sizeof(union clusterMsgData); |
| 1830 | explen += (sizeof(clusterMsgDataGossip)*count); |
| 1831 | if (totlen != explen) return 1; |
| 1832 | } else if (type == CLUSTERMSG_TYPE_FAIL) { |
| 1833 | uint32_t explen = sizeof(clusterMsg)-sizeof(union clusterMsgData); |
| 1834 | |
| 1835 | explen += sizeof(clusterMsgDataFail); |
| 1836 | if (totlen != explen) return 1; |
| 1837 | } else if (type == CLUSTERMSG_TYPE_PUBLISH) { |
| 1838 | uint32_t explen = sizeof(clusterMsg)-sizeof(union clusterMsgData); |
| 1839 | |
| 1840 | explen += sizeof(clusterMsgDataPublish) - |
| 1841 | 8 + |
| 1842 | ntohl(hdr->data.publish.msg.channel_len) + |
| 1843 | ntohl(hdr->data.publish.msg.message_len); |
| 1844 | if (totlen != explen) return 1; |
| 1845 | } else if (type == CLUSTERMSG_TYPE_FAILOVER_AUTH_REQUEST || |
| 1846 | type == CLUSTERMSG_TYPE_FAILOVER_AUTH_ACK || |
| 1847 | type == CLUSTERMSG_TYPE_MFSTART) |
| 1848 | { |
| 1849 | uint32_t explen = sizeof(clusterMsg)-sizeof(union clusterMsgData); |
| 1850 | |
| 1851 | if (totlen != explen) return 1; |
| 1852 | } else if (type == CLUSTERMSG_TYPE_UPDATE) { |
| 1853 | uint32_t explen = sizeof(clusterMsg)-sizeof(union clusterMsgData); |
| 1854 |
no test coverage detected