提交 e6bf4c26 编写于 作者: G Geoff Garside 提交者: antirez

Update clusterCommand to handle AF_INET6 addresses

Changes the sockaddr_in to a sockaddr_storage. Attempts to convert the
IP address into an AF_INET or AF_INET6 before returning an "Invalid IP
address" error. Handles converting the sockaddr from either AF_INET or
AF_INET6 back into a string for storage in the clusterNode ip field.
上级 5be83eec
......@@ -2075,11 +2075,12 @@ void clusterCommand(redisClient *c) {
if (!strcasecmp(c->argv[1]->ptr,"meet") && c->argc == 4) {
/* CLUSTER MEET <ip> <port> */
clusterNode *n;
struct sockaddr_in sa;
struct sockaddr_storage sa;
long port;
/* Perform sanity checks on IP/port */
if (inet_pton(AF_INET,c->argv[0]->ptr,&(sa.sin_addr)) == 0) {
if ((inet_pton(AF_INET,c->argv[0]->ptr,&(((struct sockaddr_in *)&sa)->sin_addr)) ||
inet_pton(AF_INET6,c->argv[0]->ptr,&(((struct sockaddr_in6 *)&sa)->sin6_addr))) == 0) {
addReplyError(c,"Invalid IP address in MEET");
return;
}
......@@ -2093,7 +2094,9 @@ void clusterCommand(redisClient *c) {
/* Finally add the node to the cluster with a random name, this
* will get fixed in the first handshake (ping/pong). */
n = createClusterNode(NULL,REDIS_NODE_HANDSHAKE|REDIS_NODE_MEET);
inet_ntop(sa.sin_family,(void*)&(sa.sin_addr),n->ip,REDIS_CLUSTER_IPLEN);
sa.ss_family == AF_INET ?
inet_ntop(AF_INET,(void*)&(((struct sockaddr_in *)&sa)->sin_addr),n->ip,REDIS_CLUSTER_IPLEN) :
inet_ntop(AF_INET6,(void*)&(((struct sockaddr_in6 *)&sa)->sin6_addr),n->ip,REDIS_CLUSTER_IPLEN);
n->port = port;
clusterAddNode(n);
addReply(c,shared.ok);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册