diff options
author | Ping Xie <11568491+PingXie@users.noreply.github.com> | 2022-01-30 09:43:37 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-30 19:43:37 +0200 |
commit | 8013af6f3dcbcc5042f5ab6db07c05fd83058975 (patch) | |
tree | 214192cff4aa4875c17e3b5f4b83adbeb402a70a /src/cluster.h | |
parent | 52b2fbe9705739fd5f03099011f652775ab3285f (diff) | |
download | redis-8013af6f3dcbcc5042f5ab6db07c05fd83058975.tar.gz |
Fix cluster bus extensions backwards compatibility (#10206)
Before this commit, notused1 was incorrectly resized resulting with a clusterMsg that is not backwards compatible as expected.
Diffstat (limited to 'src/cluster.h')
-rw-r--r-- | src/cluster.h | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/cluster.h b/src/cluster.h index ae63a9d84..465654205 100644 --- a/src/cluster.h +++ b/src/cluster.h @@ -321,7 +321,7 @@ typedef struct { char slaveof[CLUSTER_NAMELEN]; char myip[NET_IP_STR_LEN]; /* Sender IP, if not all zeroed. */ uint16_t extensions; /* Number of extensions sent along with this packet. */ - char notused1[16]; /* 16 bytes reserved for future usage. */ + char notused1[30]; /* 30 bytes reserved for future usage. */ uint16_t pport; /* Sender TCP plaintext port, if base port is TLS */ uint16_t cport; /* Sender TCP cluster bus port */ uint16_t flags; /* Sender node flags */ @@ -330,6 +330,40 @@ typedef struct { union clusterMsgData data; } clusterMsg; +/* clusterMsg defines the gossip wire protocol exchanged among Redis cluster + * members, which can be running different versions of redis-server bits, + * especially during cluster rolling upgrades. + * + * Therefore, fields in this struct should remain at the same offset from + * release to release. The static asserts below ensures that incompatible + * changes in clusterMsg be caught at compile time. + */ + +/* Avoid static_assert on non-C11 compilers. */ +#if __STDC_VERSION__ >= 201112L +static_assert(offsetof(clusterMsg, sig) == 0, "unexpected field offset"); +static_assert(offsetof(clusterMsg, totlen) == 4, "unexpected field offset"); +static_assert(offsetof(clusterMsg, ver) == 8, "unexpected field offset"); +static_assert(offsetof(clusterMsg, port) == 10, "unexpected field offset"); +static_assert(offsetof(clusterMsg, type) == 12, "unexpected field offset"); +static_assert(offsetof(clusterMsg, count) == 14, "unexpected field offset"); +static_assert(offsetof(clusterMsg, currentEpoch) == 16, "unexpected field offset"); +static_assert(offsetof(clusterMsg, configEpoch) == 24, "unexpected field offset"); +static_assert(offsetof(clusterMsg, offset) == 32, "unexpected field offset"); +static_assert(offsetof(clusterMsg, sender) == 40, "unexpected field offset"); +static_assert(offsetof(clusterMsg, myslots) == 80, "unexpected field offset"); +static_assert(offsetof(clusterMsg, slaveof) == 2128, "unexpected field offset"); +static_assert(offsetof(clusterMsg, myip) == 2168, "unexpected field offset"); +static_assert(offsetof(clusterMsg, extensions) == 2214, "unexpected field offset"); +static_assert(offsetof(clusterMsg, notused1) == 2216, "unexpected field offset"); +static_assert(offsetof(clusterMsg, pport) == 2246, "unexpected field offset"); +static_assert(offsetof(clusterMsg, cport) == 2248, "unexpected field offset"); +static_assert(offsetof(clusterMsg, flags) == 2250, "unexpected field offset"); +static_assert(offsetof(clusterMsg, state) == 2252, "unexpected field offset"); +static_assert(offsetof(clusterMsg, mflags) == 2253, "unexpected field offset"); +static_assert(offsetof(clusterMsg, data) == 2256, "unexpected field offset"); +#endif + #define CLUSTERMSG_MIN_LEN (sizeof(clusterMsg)-sizeof(union clusterMsgData)) /* Message flags better specify the packet content or are used to |