]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Require IPv6 to build
authorMartti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
Fri, 8 Apr 2016 10:34:59 +0000 (13:34 +0300)
committerGitLab <gitlab@git.dovecot.net>
Tue, 19 Apr 2016 17:26:33 +0000 (20:26 +0300)
12 files changed:
configure.ac
src/auth/auth-penalty.c
src/director/mail-host.c
src/lib-http/test-http-url.c
src/lib-imap/imap-keepalive.c
src/lib-imap/test-imap-url.c
src/lib/net.c
src/lib/net.h
src/lib/test-net.c
src/lib/uri-util.c
src/login-common/client-common.c
src/master/main.c

index 0dc61608e45040e5e4dfcd4dd41bc8239db0fd8c..8d274e7a8a7431645be327c7976ac93e73a9cdef 100644 (file)
@@ -2441,7 +2441,6 @@ dnl **
 dnl ** IPv6 support
 dnl **
 
-have_ipv6=no
 AC_MSG_CHECKING([for IPv6])
 AC_CACHE_VAL(i_cv_type_in6_addr,
 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
@@ -2453,11 +2452,10 @@ AC_CACHE_VAL(i_cv_type_in6_addr,
 [[struct in6_addr i;]])],
 [i_cv_type_in6_addr=yes],
 [i_cv_type_in6_addr=no])])
-if test $i_cv_type_in6_addr = yes; then
-       AC_DEFINE(HAVE_IPV6,, [Build with IPv6 support])
-       have_ipv6=yes
-fi
 AC_MSG_RESULT($i_cv_type_in6_addr)
+if test $i_cv_type_in6_addr = no; then
+       AC_ERROR([Can't build without IPv6 support.])
+fi
 
 dnl **
 dnl ** storage classes
index 7400af4eebb4de1c1bc6a6e183901fe17ea7502f..3506040ce7cb7c24d224866625d57bdc4b7323ce 100644 (file)
@@ -105,13 +105,11 @@ auth_penalty_get_ident(struct auth_request *auth_request)
        struct ip_addr ip;
 
        ip = auth_request->remote_ip;
-#ifdef HAVE_IPV6
        if (IPADDR_IS_V6(&ip)) {
                memset(ip.u.ip6.s6_addr + PENALTY_IPV6_MASK_BITS/CHAR_BIT, 0,
                       sizeof(ip.u.ip6.s6_addr) -
                       PENALTY_IPV6_MASK_BITS/CHAR_BIT);
        }
-#endif
        return net_ip2addr(&ip);
 }
 
index 5682e153f29cb56392f10d4522f4b50cd6e8ff7b..6218ea45d5e11da4bfc621594611a64b8bc9fd82 100644 (file)
@@ -265,15 +265,10 @@ mail_hosts_add_range(struct mail_host_list *list,
                max_bits = 32;
                last_bits = 8;
        } else {
-#ifndef HAVE_IPV6
-               i_error("IPv6 not supported");
-               return -1;
-#else
                ip1_arr = (void *)&ip1.u.ip6;
                ip2_arr = (void *)&ip2.u.ip6;
                max_bits = 128;
                last_bits = 16;
-#endif
        }
 
        /* make sure initial bits match */
index 160a9baeac6d99170a7a7c8244fbc910e6b9fbb0..dcddddcddaa632a184e686e8ac7e9a00603edd68 100644 (file)
@@ -34,7 +34,6 @@ static struct valid_http_url_test valid_url_tests[] = {
                .url_parsed = {
                        .host_name = "127.0.0.1",
                        .have_host_ip = TRUE }
-#ifdef HAVE_IPV6
        },{
                .url = "http://[::1]",
                .url_parsed = {
@@ -46,7 +45,6 @@ static struct valid_http_url_test valid_url_tests[] = {
                        .host_name = "[::1]",
                        .have_host_ip = TRUE,
                        .port = 8080, .have_port = TRUE }
-#endif
        },{
                .url = "http://user@api.dovecot.org",
                .flags = HTTP_URL_ALLOW_USERINFO_PART,
@@ -381,10 +379,8 @@ static struct invalid_http_url_test invalid_url_tests[] = {
                .url = "http://[]/index.html"
        },{
                .url = "http://[v08.234:232:234:234:2221]/index.html"
-#ifdef HAVE_IPV6
        },{
                .url = "http://[1::34a:34:234::6]/index.html"
-#endif
        },{
                .url = "http://example%a.com/index.html"
        },{
@@ -442,9 +438,7 @@ static void test_http_url_invalid(void)
 static const char *parse_create_url_tests[] = {
        "http://www.example.com/",
        "http://10.0.0.1/",
-#ifdef HAVE_IPV6
        "http://[::1]/",
-#endif
        "http://www.example.com:993/",
        "http://www.example.com/index.html",
        "http://www.example.com/settings/index.html",
index 23993baf2f13fd572e5429b141f9f93e3c0d7714..3b73ee72fbe091aa01a413653b4d78033b43d888 100644 (file)
@@ -26,13 +26,11 @@ static bool imap_remote_ip_is_usable(const struct ip_addr *ip)
                        return FALSE; /* 127/8 */
 #undef IP4
        }
-#ifdef HAVE_IPV6
        else if (ip->family == AF_INET6) {
                addr = ip->u.ip6.s6_addr[0];
                if (addr == 0xfc || addr == 0xfd)
                        return FALSE; /* fc00::/7 */
        }
-#endif
        return TRUE;
 }
 
index 95b7ce550d56068ada31df2cfa7ebf32857279bb..d49e915035b557941b6297c36475b67835c37bdd 100644 (file)
@@ -53,14 +53,12 @@ static const struct valid_imap_url_test valid_url_tests[] = {
                        .host_name = "127.0.0.1",
                        .userid = "user",
                        .have_host_ip = TRUE }
-#ifdef HAVE_IPV6
        },{
                .url = "imap://user@[::1]",
                .url_parsed = {
                        .host_name = "[::1]",
                        .userid = "user",
                        .have_host_ip = TRUE }
-#endif
        },{
                .url = "imap://user@4example.com:423",
                .url_parsed = {
@@ -799,10 +797,8 @@ static const struct invalid_imap_url_test invalid_url_tests[] = {
                .url = "imap://[]/INBOX"
        },{
                .url = "imap://[v08.234:232:234:234:2221]/INBOX"
-#ifdef HAVE_IPV6
        },{
                .url = "imap://[1::34a:34:234::6]/INBOX"
-#endif
        },{
                .url = "imap://example%a.com/INBOX"
        },{
@@ -961,9 +957,7 @@ static void test_imap_url_invalid(void)
 static const char *parse_create_url_tests[] = {
        "imap://host.example.com/",
        "imap://10.0.0.1/",
-#ifdef HAVE_IPV6
        "imap://[::1]/",
-#endif
        "imap://user@host.example.com/",
        "imap://user@host.example.com:993/",
        "imap://su%3auser@host.example.com/",
index 5223a54419815d6b6f310687cab80ae4dcd5d201..bf0ffafd542d9c67b8aca808d1cf2115778f735d 100644 (file)
@@ -20,9 +20,7 @@
 union sockaddr_union {
        struct sockaddr sa;
        struct sockaddr_in sin;
-#ifdef HAVE_IPV6
        struct sockaddr_in6 sin6;
-#endif
 };
 
 union sockaddr_union_unix {
@@ -30,12 +28,8 @@ union sockaddr_union_unix {
        struct sockaddr_un un;
 };
 
-#ifdef HAVE_IPV6
-#  define SIZEOF_SOCKADDR(so) ((so).sa.sa_family == AF_INET6 ? \
+#define SIZEOF_SOCKADDR(so) ((so).sa.sa_family == AF_INET6 ? \
        sizeof(so.sin6) : sizeof(so.sin))
-#else
-#  define SIZEOF_SOCKADDR(so) (sizeof(so.sin))
-#endif
 
 #if !defined(HAVE_GETPEEREID) && !defined(SO_PEERCRED) && !defined(HAVE_GETPEERUCRED) && defined(MSG_WAITALL) && defined(LOCAL_CREDS)
 #  define NEEDS_LOCAL_CREDS 1
@@ -51,10 +45,8 @@ int net_ip_cmp(const struct ip_addr *ip1, const struct ip_addr *ip2)
        if (ip1->family != ip2->family)
                return ip1->family - ip2->family;
 
-#ifdef HAVE_IPV6
        if (ip1->family == AF_INET6)
                return memcmp(&ip1->u.ip6, &ip2->u.ip6, sizeof(ip1->u.ip6));
-#endif
 
        return memcmp(&ip1->u.ip4, &ip2->u.ip4, sizeof(ip1->u.ip4));
 }
@@ -64,12 +56,10 @@ unsigned int net_ip_hash(const struct ip_addr *ip)
         const unsigned char *p;
        unsigned int len, g, h = 0;
 
-#ifdef HAVE_IPV6
        if (ip->family == AF_INET6) {
                p = ip->u.ip6.s6_addr;
                len = sizeof(ip->u.ip6);
        } else
-#endif
        {
                return ip->u.ip4.s_addr;
        }
@@ -90,22 +80,15 @@ static inline void
 sin_set_ip(union sockaddr_union *so, const struct ip_addr *ip)
 {
        if (ip == NULL) {
-#ifdef HAVE_IPV6
                so->sin6.sin6_family = AF_INET6;
                so->sin6.sin6_addr = in6addr_any;
-#else
-               so->sin.sin_family = AF_INET;
-               so->sin.sin_addr.s_addr = INADDR_ANY;
-#endif
                return;
        }
 
        so->sin.sin_family = ip->family;
-#ifdef HAVE_IPV6
        if (ip->family == AF_INET6)
                memcpy(&so->sin6.sin6_addr, &ip->u.ip6, sizeof(ip->u.ip6));
        else
-#endif
                memcpy(&so->sin.sin_addr, &ip->u.ip4, sizeof(ip->u.ip4));
 }
 
@@ -118,11 +101,9 @@ sin_get_ip(const union sockaddr_union *so, struct ip_addr *ip)
 
        ip->family = so->sin.sin_family;
 
-#ifdef HAVE_IPV6
        if (ip->family == AF_INET6)
                memcpy(&ip->u.ip6, &so->sin6.sin6_addr, sizeof(ip->u.ip6));
        else
-#endif
        if (ip->family == AF_INET)
                memcpy(&ip->u.ip4, &so->sin.sin_addr, sizeof(ip->u.ip4));
        else
@@ -131,20 +112,16 @@ sin_get_ip(const union sockaddr_union *so, struct ip_addr *ip)
 
 static inline void sin_set_port(union sockaddr_union *so, in_port_t port)
 {
-#ifdef HAVE_IPV6
        if (so->sin.sin_family == AF_INET6)
                 so->sin6.sin6_port = htons(port);
        else
-#endif
                so->sin.sin_port = htons(port);
 }
 
 static inline in_port_t sin_get_port(union sockaddr_union *so)
 {
-#ifdef HAVE_IPV6
        if (so->sin.sin_family == AF_INET6)
                return ntohs(so->sin6.sin6_port);
-#endif
        if (so->sin.sin_family == AF_INET)
                return ntohs(so->sin.sin_port);
 
@@ -382,12 +359,8 @@ void net_get_ip_any4(struct ip_addr *ip)
 
 void net_get_ip_any6(struct ip_addr *ip)
 {
-#ifdef HAVE_IPV6
        ip->family = AF_INET6;
        ip->u.ip6 = in6addr_any;
-#else
-       memset(ip, 0, sizeof(struct ip_addr));
-#endif
 }
 
 int net_listen(const struct ip_addr *my_ip, in_port_t *port, int backlog)
@@ -410,7 +383,6 @@ int net_listen_full(const struct ip_addr *my_ip, in_port_t *port,
 
        /* create the socket */
        fd = socket(so.sin.sin_family, SOCK_STREAM, 0);
-#ifdef HAVE_IPV6
        if (fd == -1 && my_ip == NULL &&
            (errno == EINVAL || errno == EAFNOSUPPORT)) {
                /* IPv6 is not supported by OS */
@@ -419,7 +391,6 @@ int net_listen_full(const struct ip_addr *my_ip, in_port_t *port,
 
                fd = socket(AF_INET, SOCK_STREAM, 0);
        }
-#endif
        if (fd == -1) {
                i_error("socket() failed: %m");
                return -1;
@@ -625,20 +596,15 @@ int net_gethostbyname(const char *addr, struct ip_addr **ips,
                      unsigned int *ips_count)
 {
        /* @UNSAFE */
-#ifdef HAVE_IPV6
        union sockaddr_union *so;
        struct addrinfo hints, *ai, *origai;
        struct ip_addr ip;
        int host_error;
-#else
-       struct hostent *hp;
-#endif
         int count;
 
        *ips = NULL;
         *ips_count = 0;
 
-#ifdef HAVE_IPV6
        /* support [ipv6] style addresses here so they work globally */
        if (addr[0] == '[' && net_addr2ip(addr, &ip) == 0) {
                *ips_count = 1;
@@ -670,27 +636,6 @@ int net_gethostbyname(const char *addr, struct ip_addr **ips,
                sin_get_ip(so, &(*ips)[count]);
        }
        freeaddrinfo(origai);
-#else
-       hp = gethostbyname(addr);
-       if (hp == NULL)
-               return h_errno;
-
-        /* get number of IPs */
-       count = 0;
-       while (hp->h_addr_list[count] != NULL)
-               count++;
-
-        *ips_count = count;
-        *ips = t_malloc(sizeof(struct ip_addr) * count);
-
-       while (count > 0) {
-               count--;
-
-               (*ips)[count].family = AF_INET;
-               memcpy(&(*ips)[count].u.ip4, hp->h_addr_list[count],
-                      sizeof((*ips)[count].u.ip4));
-       }
-#endif
 
        return 0;
 }
@@ -897,7 +842,6 @@ int net_getunixcred(int fd, struct net_unix_cred *cred_r)
 
 const char *net_ip2addr(const struct ip_addr *ip)
 {
-#ifdef HAVE_IPV6
        char addr[MAX_IP_LEN+1];
 
        addr[MAX_IP_LEN] = '\0';
@@ -905,19 +849,6 @@ const char *net_ip2addr(const struct ip_addr *ip)
                return "";
 
        return t_strdup(addr);
-#else
-       unsigned long ip4;
-
-       if (ip->family != AF_INET)
-               return "";
-
-       ip4 = ntohl(ip->u.ip4.s_addr);
-       return t_strdup_printf("%lu.%lu.%lu.%lu",
-                              (ip4 & 0xff000000UL) >> 24,
-                              (ip4 & 0x00ff0000) >> 16,
-                              (ip4 & 0x0000ff00) >> 8,
-                              (ip4 & 0x000000ff));
-#endif
 }
 
 int net_addr2ip(const char *addr, struct ip_addr *ip)
@@ -926,7 +857,6 @@ int net_addr2ip(const char *addr, struct ip_addr *ip)
 
        if (strchr(addr, ':') != NULL) {
                /* IPv6 */
-#ifdef HAVE_IPV6
                T_BEGIN {
                        if (addr[0] == '[') {
                                /* allow [ipv6 addr] */
@@ -938,9 +868,6 @@ int net_addr2ip(const char *addr, struct ip_addr *ip)
                } T_END;
                if (ret == 0)
                        return -1;
-#else
-               ip->u.ip4.s_addr = 0;
-#endif
                ip->family = AF_INET6;
        } else {
                /* IPv4 */
@@ -1016,7 +943,6 @@ int net_str2hostport(const char *str, in_port_t default_port,
 int net_ipv6_mapped_ipv4_convert(const struct ip_addr *src,
                                 struct ip_addr *dest)
 {
-#ifdef HAVE_IPV6
        static uint8_t v4_prefix[] =
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff };
 
@@ -1028,9 +954,6 @@ int net_ipv6_mapped_ipv4_convert(const struct ip_addr *src,
        dest->family = AF_INET;
        memcpy(&dest->u.ip6, &src->u.ip6.s6_addr[3*4], 4);
        return 0;
-#else
-       return -1;
-#endif
 }
 
 int net_geterror(int fd)
@@ -1050,37 +973,18 @@ int net_geterror(int fd)
 
 const char *net_gethosterror(int error)
 {
-#ifdef HAVE_IPV6
        i_assert(error != 0);
 
        return gai_strerror(error);
-#else
-       switch (error) {
-       case HOST_NOT_FOUND:
-               return "Host not found";
-       case NO_ADDRESS:
-               return "No IP address found for name";
-       case NO_RECOVERY:
-               return "A non-recoverable name server error occurred";
-       case TRY_AGAIN:
-               return "A temporary error on an authoritative name server";
-       default:
-               return t_strdup_printf("Unknown error %d", error);
-       }
-#endif
 }
 
 int net_hosterror_notfound(int error)
 {
-#ifdef HAVE_IPV6
 #ifdef EAI_NODATA /* NODATA is depricated */
        return error != 1 && (error == EAI_NONAME || error == EAI_NODATA);
 #else
        return error != 1 && (error == EAI_NONAME);
 #endif
-#else
-       return error == HOST_NOT_FOUND || error == NO_ADDRESS;
-#endif
 }
 
 const char *net_getservbyport(in_port_t port)
@@ -1176,13 +1080,8 @@ bool net_is_in_network(const struct ip_addr *ip,
                ip1 = &ip->u.ip4.s_addr;
                ip2 = &net_ip->u.ip4.s_addr;
        } else {
-#ifdef HAVE_IPV6
                ip1 = (const void *)&ip->u.ip6;
                ip2 = (const void *)&net_ip->u.ip6;
-#else
-               /* shouldn't get here */
-               return FALSE;
-#endif
        }
 
        /* check first the full 32bit ints */
index 59d89a6ad7619cd632bed7f1e1529d6a9e006e19..51d3b82b61cbd56f5a06b5d1b827f5065028e9bf 100644 (file)
@@ -23,9 +23,7 @@
 struct ip_addr {
        unsigned short family;
        union {
-#ifdef HAVE_IPV6
                struct in6_addr ip6;
-#endif
                struct in_addr ip4;
        } u;
 };
@@ -38,18 +36,7 @@ struct net_unix_cred {
 };
 
 /* maxmimum string length of IP address */
-#ifdef HAVE_IPV6
-#  define MAX_IP_LEN INET6_ADDRSTRLEN
-#else
-#  define MAX_IP_LEN 20
-#endif
-
-#ifndef HAVE_IPV6
-#  undef EAI_NONAME
-#  define EAI_NONAME NO_ADDRESS
-#  undef EAI_FAIL
-#  define EAI_FAIL NO_RECOVERY
-#endif
+#define MAX_IP_LEN INET6_ADDRSTRLEN
 
 #define IPADDR_IS_V4(ip) ((ip)->family == AF_INET)
 #define IPADDR_IS_V6(ip) ((ip)->family == AF_INET6)
index fe545d99e860f1ca947b622ddc5b39e9e8d603e2..ef584e894861bc29585c35980b52d31e846165c7 100644 (file)
@@ -25,16 +25,13 @@ static void test_net_is_in_network(void)
                { "1.2.3.255", "1.2.3.0", 24, TRUE },
                { "1.2.255.255", "1.2.254.0", 23, TRUE },
                { "255.255.255.255", "128.0.0.0", 1, TRUE },
-               { "255.255.255.255", "127.0.0.0", 1, FALSE }
-#ifdef HAVE_IPV6
-               ,
+               { "255.255.255.255", "127.0.0.0", 1, FALSE },
                { "1234:5678::abcf", "1234:5678::abce", 127, TRUE },
                { "1234:5678::abcd", "1234:5678::abce", 127, FALSE },
                { "123e::ffff", "123e::0", 15, TRUE },
                { "::ffff:1.2.3.4", "1.2.3.4", 32, TRUE },
                { "::ffff:1.2.3.4", "1.2.3.3", 32, FALSE },
                { "::ffff:1.2.3.4", "::ffff:1.2.3.4", 0, FALSE }
-#endif
        };
        struct ip_addr ip, net_ip;
        unsigned int i;
@@ -52,13 +49,11 @@ static void test_net_is_in_network(void)
        net_ip.family = 0;
        test_assert(!net_is_in_network(&ip, &net_ip, 0));
        test_assert(!net_is_in_network(&net_ip, &ip, 0));
-#ifdef HAVE_IPV6
        test_assert(net_addr2ip("::1", &ip) == 0);
        net_ip = ip;
        net_ip.family = 0;
        test_assert(!net_is_in_network(&ip, &net_ip, 0));
        test_assert(!net_is_in_network(&net_ip, &ip, 0));
-#endif
        test_end();
 }
 
@@ -70,7 +65,6 @@ static void test_net_ip2addr(void)
        test_assert(net_addr2ip("127.0.0.1", &ip) == 0 &&
                    ip.family == AF_INET &&
                    ntohl(ip.u.ip4.s_addr) == (0x7f000001));
-#ifdef HAVE_IPV6
        test_assert(net_addr2ip("::5", &ip) == 0 &&
                    ip.family == AF_INET6 &&
                    ip.u.ip6.s6_addr[15] == 5);
@@ -80,7 +74,6 @@ static void test_net_ip2addr(void)
        ip.family = 123;
        test_assert(net_addr2ip("abc", &ip) < 0 &&
                    ip.family == 123);
-#endif
        test_end();
 }
 
index a7d291be36d44f48dc24653a521c67aebd08841c..dad6673c83ed3dca88ad91507c4d3a33f95b1e79 100644 (file)
@@ -364,7 +364,6 @@ uri_parse_reg_name(struct uri_parser *parser,
        return 0;
 }
 
-#ifdef HAVE_IPV6
 static int
 uri_parse_ip_literal(struct uri_parser *parser, string_t *literal,
                     struct in6_addr *ip6_r) ATTR_NULL(2,3)
@@ -415,7 +414,6 @@ uri_parse_ip_literal(struct uri_parser *parser, string_t *literal,
                *ip6_r = ip6;
        return 1;
 }
-#endif
 
 static int 
 uri_parse_host(struct uri_parser *parser,
@@ -436,7 +434,6 @@ uri_parse_host(struct uri_parser *parser,
 
        /* IP-literal / */
        if (parser->cur < parser->end && *parser->cur == '[') {
-#ifdef HAVE_IPV6
                if ((ret=uri_parse_ip_literal(parser, literal, &ip6)) <= 0)
                        return -1;
 
@@ -447,10 +444,6 @@ uri_parse_host(struct uri_parser *parser,
                        auth->have_host_ip = TRUE;
                }
                return 1;
-#else
-               parser->error = "IPv6 host address is not supported";
-               return -1;
-#endif
        }
 
        /* IPv4address /
index 1e5f1fba6d2c5057bdf6b52973a6b74c6e17f471..50307d72702701349229541c45cf8f8d61a02a55 100644 (file)
@@ -472,11 +472,9 @@ const char *client_get_session_id(struct client *client)
 
        buffer_append_c(buf, client->remote_port & 0xff);
        buffer_append_c(buf, (client->remote_port >> 8) & 0xff);
-#ifdef HAVE_IPV6
        if (IPADDR_IS_V6(&client->ip))
                buffer_append(buf, &client->ip.u.ip6, sizeof(client->ip.u.ip6));
        else
-#endif
                buffer_append(buf, &client->ip.u.ip4, sizeof(client->ip.u.ip4));
        base64_encode(buf->data, buf->used, base64_buf);
        client->session_id = p_strdup(client->pool, str_c(base64_buf));
index a98a0b4c56fb16d1c7453eaf018c529b13f3241b..591194cd72e2ab305f43b81ae6e9e9878794097a 100644 (file)
@@ -632,9 +632,6 @@ static void print_build_options(void)
 #ifdef IOLOOP_NOTIFY_KQUEUE
                " notify=kqueue"
 #endif
-#ifdef HAVE_IPV6
-               " ipv6"
-#endif
 #ifdef HAVE_GNUTLS
                " gnutls"
 #endif