Commit e04fdf26 authored by Geoff Garside's avatar Geoff Garside Committed by antirez
Browse files

Add IPv6 support to sentinel.c.

This has been done by exposing the anetSockName() function anet.c
to be used when the sentinel is publishing its existence to the masters.

This implementation is very unintelligent as it will likely break if used
with IPv6 as the nested colons will break any parsing of the PUBLISH string
by the master.
parent a68e3d4c
...@@ -57,5 +57,6 @@ int anetDisableTcpNoDelay(char *err, int fd); ...@@ -57,5 +57,6 @@ int anetDisableTcpNoDelay(char *err, int fd);
int anetTcpKeepAlive(char *err, int fd); int anetTcpKeepAlive(char *err, int fd);
int anetPeerToString(int fd, char *ip, size_t ip_len, int *port); int anetPeerToString(int fd, char *ip, size_t ip_len, int *port);
int anetKeepAlive(char *err, int fd, int interval); int anetKeepAlive(char *err, int fd, int interval);
int anetSockName(int fd, char *ip, size_t ip_len, int *port);
#endif #endif
...@@ -1837,14 +1837,13 @@ void sentinelPingInstance(sentinelRedisInstance *ri) { ...@@ -1837,14 +1837,13 @@ void sentinelPingInstance(sentinelRedisInstance *ri) {
(now - ri->last_pub_time) > SENTINEL_PUBLISH_PERIOD) (now - ri->last_pub_time) > SENTINEL_PUBLISH_PERIOD)
{ {
/* PUBLISH hello messages only to masters. */ /* PUBLISH hello messages only to masters. */
struct sockaddr_in sa; char ip[INET6_ADDRSTRLEN];
socklen_t salen = sizeof(sa); if (anetSockName(ri->cc->c.fd,ip,sizeof(ip),NULL) != -1) {
if (getsockname(ri->cc->c.fd,(struct sockaddr*)&sa,&salen) != -1) {
char myaddr[128]; char myaddr[128];
// FIXME: IPv6 will break this due to nested : characters -geoffgarside
snprintf(myaddr,sizeof(myaddr),"%s:%d:%s:%d", snprintf(myaddr,sizeof(myaddr),"%s:%d:%s:%d",
inet_ntoa(sa.sin_addr), server.port, server.runid, ip, server.port, server.runid,
(ri->flags & SRI_CAN_FAILOVER) != 0); (ri->flags & SRI_CAN_FAILOVER) != 0);
retval = redisAsyncCommand(ri->cc, retval = redisAsyncCommand(ri->cc,
sentinelPublishReplyCallback, NULL, "PUBLISH %s %s", sentinelPublishReplyCallback, NULL, "PUBLISH %s %s",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment