dovecot-2.0: Added support for [] around ipv6 addresses everywhere.

dovecot at dovecot.org dovecot at dovecot.org
Tue Jun 1 20:37:42 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/bdb46ba87203
changeset: 11448:bdb46ba87203
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Jun 01 18:35:48 2010 +0100
description:
Added support for [] around ipv6 addresses everywhere.

diffstat:

 src/config/old-set-parser.c |   1 +
 src/lib/network.c           |  24 ++++++++++++++++++++++--
 src/master/service.c        |   2 +-
 3 files changed, 24 insertions(+), 3 deletions(-)

diffs (70 lines):

diff -r 484eb8f1f074 -r bdb46ba87203 src/config/old-set-parser.c
--- a/src/config/old-set-parser.c	Tue Jun 01 17:51:50 2010 +0100
+++ b/src/config/old-set-parser.c	Tue Jun 01 18:35:48 2010 +0100
@@ -215,6 +215,7 @@
 	for (; *addrs != NULL; addrs++) {
 		if (strcmp(*addrs, "*") != 0 &&
 		    strcmp(*addrs, "::") != 0 &&
+		    strcmp(*addrs, "[::]") != 0 &&
 		    !is_ipv4_address(*addrs) &&
 		    !is_ipv6_address(*addrs))
 			return TRUE;
diff -r 484eb8f1f074 -r bdb46ba87203 src/lib/network.c
--- a/src/lib/network.c	Tue Jun 01 17:51:50 2010 +0100
+++ b/src/lib/network.c	Tue Jun 01 18:35:48 2010 +0100
@@ -678,11 +678,22 @@
 
 int net_addr2ip(const char *addr, struct ip_addr *ip)
 {
+	int ret;
+
 	if (strchr(addr, ':') != NULL) {
 		/* IPv6 */
 		ip->family = AF_INET6;
 #ifdef HAVE_IPV6
-		if (inet_pton(AF_INET6, addr, &ip->u.ip6) == 0)
+		T_BEGIN {
+			if (addr[0] == '[') {
+				/* allow [ipv6 addr] */
+				unsigned int len = strlen(addr);
+				if (addr[len-1] == ']')
+					addr = t_strndup(addr+1, len-2);
+			}
+			ret = inet_pton(AF_INET6, addr, &ip->u.ip6);
+		} T_END;
+		if (ret == 0)
 			return -1;
 #else
 		ip->u.ip4.s_addr = 0;
@@ -785,9 +796,18 @@
 
 bool is_ipv6_address(const char *addr)
 {
+	bool have_prefix = FALSE;
+
+	if (*addr == '[') {
+		have_prefix = TRUE;
+		addr++;
+	}
 	while (*addr != '\0') {
-		if (*addr != ':' && !i_isxdigit(*addr))
+		if (*addr != ':' && !i_isxdigit(*addr)) {
+			if (have_prefix && *addr == ']' && addr[1] == '\0')
+				break;
 			return FALSE;
+		}
                 addr++;
 	}
 
diff -r 484eb8f1f074 -r bdb46ba87203 src/master/service.c
--- a/src/master/service.c	Tue Jun 01 17:51:50 2010 +0100
+++ b/src/master/service.c	Tue Jun 01 18:35:48 2010 +0100
@@ -70,7 +70,7 @@
 		return 0;
 	}
 
-	if (strcmp(address, "::") == 0) {
+	if (strcmp(address, "::") == 0 || strcmp(address, "[::]") == 0) {
 		/* IPv6 any */
 		ip_list = t_new(struct ip_addr, 1);
 		net_get_ip_any6(ip_list);


More information about the dovecot-cvs mailing list