mail-host.c revision eb209d12e3b1cfed564c35cf19fdb1bf7fcc6811
/* Copyright (c) 2010-2014 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "bsearch-insert-pos.h"
#include "md5.h"
#include "mail-host.h"
#define VHOST_MULTIPLIER 100
struct mail_vhost {
unsigned int hash;
};
struct mail_host_list {
bool hosts_unsorted;
bool consistent_hashing;
};
static int
{
}
static int
{
return -1;
return 1;
/* hash collision. not ideal, but we'll need to keep the order
consistent across directors so compare the IPs next. */
}
static int
{
return 1;
return -1;
else
return 0;
}
{
struct mail_vhost *vhost;
unsigned char md5[MD5_RESULTLEN];
const char *ip_str;
char num_str[MAX_INT_STRLEN];
unsigned int i, j;
for (i = 0; i < host->vhost_count; i++) {
}
}
{
/* rebuild vhosts */
}
{
struct mail_vhost *vhost;
unsigned int i;
/* rebuild vhosts */
for (i = 0; i < (*hostp)->vhost_count; i++) {
}
}
}
{
if (list->consistent_hashing)
else
}
struct mail_host *
{
return host;
}
{
unsigned int i, ips_count;
return -1;
}
for (i = 0; i < ips_count; i++)
return 0;
}
static int
{
i_error("IP address family mismatch: %s vs %s",
return -1;
}
i_error("IP addresses reversed: %s-%s",
return -1;
}
if (IPADDR_IS_V4(&ip1)) {
max_bits = 32;
last_bits = 8;
} else {
#ifndef HAVE_IPV6
i_error("IPv6 not supported");
return -1;
#else
max_bits = 128;
last_bits = 16;
#endif
}
/* make sure initial bits match */
i_error("IP address range too large: %s-%s",
return -1;
}
}
for (j = last_bits; j < 32; j++) {
i_error("IP address range too large: %s-%s",
return -1;
}
}
/* create hosts from the final bits */
do {
i1++;
return 0;
}
const char *hosts_string)
{
int ret = 0;
T_BEGIN {
if (p != NULL) {
/* see if this is ip1-ip2 range */
host2 = p + 1;
ip2) < 0)
ret = -1;
continue;
}
}
ret = -1;
}
} T_END;
if (ret < 0)
i_error("No valid servers specified");
else
i_error("Empty server list");
ret = -1;
}
return ret;
}
{
}
{
unsigned int i, count;
for (i = 0; i < count; i++) {
break;
}
}
}
struct mail_host *
{
if (list->hosts_unsorted)
return *hostp;
}
return NULL;
}
static struct mail_host *
{
const struct mail_vhost *vhosts;
if (count == 0)
return NULL;
idx = 0;
}
}
static struct mail_host *
{
const struct mail_vhost *vhosts;
unsigned int count;
if (count == 0)
return NULL;
}
struct mail_host *
{
if (list->hosts_unsorted)
if (list->consistent_hashing)
else
}
{
if (list->hosts_unsorted)
}
{
struct mail_host_list *list;
return list;
}
{
}
{
return dest;
}
{
struct mail_host_list *dest;
}
return dest;
}