Commit baa2311d authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Stylistic and some minor simplifications to shut up Flexelint.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@5475 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 523c98f1
......@@ -81,54 +81,48 @@ struct vdi_dns {
double ttl;
};
/* Compare an IPv4 backend to a IPv4 addr/len */
static int
vdi_dns_comp_addrinfo4(const struct backend *bp,
const struct sockaddr_in *addr,
const struct sockaddr_storage *addr,
const socklen_t len)
{
uint32_t u, p;
struct sockaddr_in *bps = (struct sockaddr_in *) bp->ipv4;
const struct sockaddr_in *bps = (const void *)bp->ipv4;
const struct sockaddr_in *bpd = (const void *)addr;
if (bp->ipv4len != len || len <= 0)
return 0;
return (0);
u = addr->sin_addr.s_addr;
u = bpd->sin_addr.s_addr;
p = bps->sin_addr.s_addr;
return u == p;
return (u == p);
}
/* Compare an IPv6 backend to a IPv6 addr/len */
static int
vdi_dns_comp_addrinfo6(const struct backend *bp,
struct sockaddr_in6 *addr,
const struct sockaddr_storage *addr,
const socklen_t len)
{
uint8_t *u, *p;
int i;
struct sockaddr_in6 *bps = (struct sockaddr_in6 *) bp->ipv6;
const uint8_t *u, *p;
const struct sockaddr_in6 *bps = (const void *)bp->ipv6;
const struct sockaddr_in6 *bpd = (const void *)addr;
if (bp->ipv6len != len || len <= 0)
return 0;
return (0);
u = addr->sin6_addr.s6_addr;
u = bpd->sin6_addr.s6_addr;
p = bps->sin6_addr.s6_addr;
for (i=0; i < 16; i++) {
if (u[i] != p[i])
return 0;
}
return 1;
return (!memcmp(u, p, 16));
}
/* Check if a backends socket is the same as addr */
static int
vdi_dns_comp_addrinfo(const struct director *dir,
struct sockaddr_storage *addr,
const struct sockaddr_storage *addr,
const socklen_t len)
{
struct backend *bp;
......@@ -136,13 +130,11 @@ vdi_dns_comp_addrinfo(const struct director *dir,
bp = vdi_get_backend_if_simple(dir);
AN(bp);
if (addr->ss_family == PF_INET && bp->ipv4) {
return (vdi_dns_comp_addrinfo4(bp, (struct sockaddr_in *)
addr, len));
return (vdi_dns_comp_addrinfo4(bp, addr, len));
} else if (addr->ss_family == PF_INET6 && bp->ipv6) {
return (vdi_dns_comp_addrinfo6(bp, (struct sockaddr_in6 *)
addr, len));
return (vdi_dns_comp_addrinfo6(bp, addr, len));
}
return 0;
return (0);
}
/* Pick a host from an existing hostgroup.
......@@ -167,11 +159,11 @@ vdi_dns_pick_host(const struct sess *sp, struct vdi_dns_hostgroup *group) {
current = i + initial;
if (VDI_Healthy_sp(sp, group->hosts[current])) {
group->next_host = current+1;
return group->hosts[current];
return (group->hosts[current]);
}
}
return NULL;
return (NULL);
}
/* Remove an item from the dns cache.
......@@ -196,7 +188,7 @@ vdi_dns_pop_cache(struct vdi_dns *vs,
static inline int
vdi_dns_groupmatch(const struct vdi_dns_hostgroup *group, const char *hostname)
{
return !strcmp(group->hostname, hostname);
return (!strcmp(group->hostname, hostname));
}
/* Search the cache for 'hostname' and put a backend-pointer as necessary,
......@@ -221,17 +213,17 @@ vdi_dns_cache_has(const struct sess *sp,
if (hostgr->ttl <= sp->t_req) {
if (rwlock)
vdi_dns_pop_cache(vs, hostgr);
return 0;
return (0);
}
if (vdi_dns_groupmatch(hostgr, hostname)) {
ret = (vdi_dns_pick_host(sp, hostgr));
*backend = ret;
if (*backend != NULL)
CHECK_OBJ_NOTNULL(*backend, DIRECTOR_MAGIC);
return 1;
return (1);
}
}
return 0;
return (0);
}
/* Add a newly cached item to the dns cache list.
......@@ -266,6 +258,7 @@ vdi_dns_cache_add(const struct sess *sp,
int error, i, host = 0;
struct addrinfo *res0, *res, hint;
struct vdi_dns_hostgroup *new;
/* Due to possible race while upgrading the lock, we have to
* recheck if the result is already looked up. The overhead for
* this is insignificant unless dns isn't cached properly (all
......@@ -273,7 +266,7 @@ vdi_dns_cache_add(const struct sess *sp,
*/
if (vdi_dns_cache_has(sp, vs, hostname, backend, 1))
return 1;
return (1);
memset(&hint, 0, sizeof hint);
hint.ai_family = PF_UNSPEC;
......@@ -281,16 +274,15 @@ vdi_dns_cache_add(const struct sess *sp,
ALLOC_OBJ(new, VDI_DNSDIR_MAGIC);
XXXAN(new);
new->hostname = calloc(sizeof(char), strlen(hostname)+1);
XXXAN(new->hostname);
strcpy(new->hostname, hostname);
REPLACE(new->hostname, hostname);
error = getaddrinfo(hostname, "80", &hint, &res0);
VSC_main->dir_dns_lookups++;
if (error) {
vdi_dns_cache_list_add(sp, vs, new);
VSC_main->dir_dns_failed++;
return 0;
return (0);
}
for (res = res0; res; res = res->ai_next) {
......@@ -314,7 +306,7 @@ vdi_dns_cache_add(const struct sess *sp,
new->nhosts = host;
vdi_dns_cache_list_add(sp, vs, new);
*backend = vdi_dns_pick_host(sp, new);
return 1;
return (1);
}
/* Walk through the cached lookups looking for the relevant host, add one
......@@ -329,10 +321,16 @@ vdi_dns_walk_cache(const struct sess *sp,
{
struct director *backend = NULL;
int ret;
AZ(pthread_rwlock_rdlock(&vs->rwlock));
ret = vdi_dns_cache_has(sp, vs, hostname, &backend, 0);
AZ(pthread_rwlock_unlock(&vs->rwlock));
if (!ret) {
/*
* XXX: Isn't there a race here where another thread
* XXX: could grab the lock and add it before we do ?
* XXX: Should 'ret' be checked for that ?
*/
AZ(pthread_rwlock_wrlock(&vs->rwlock));
ret = vdi_dns_cache_add(sp, vs, hostname, &backend);
AZ(pthread_rwlock_unlock(&vs->rwlock));
......@@ -342,7 +340,7 @@ vdi_dns_walk_cache(const struct sess *sp,
/* Bank backend == cached a failure, so to speak */
if (backend != NULL)
CHECK_OBJ_NOTNULL(backend, DIRECTOR_MAGIC);
return backend;
return (backend);
}
/* Parses the Host:-header and heads out to find a backend.
......@@ -352,9 +350,8 @@ vdi_dns_find_backend(const struct sess *sp, struct vdi_dns *vs)
{
struct director *ret;
struct http *hp;
char *p;
char *p, *q;
char hostname[NI_MAXHOST];
int i;
/* bereq is only present after recv et. al, otherwise use req (ie:
* use req for health checks in vcl_recv and such).
......@@ -369,22 +366,16 @@ vdi_dns_find_backend(const struct sess *sp, struct vdi_dns *vs)
if (http_GetHdr(hp, H_Host, &p) == 0)
return (NULL);
/* We need a working copy since it's going to be modified */
strncpy(hostname, p, sizeof(hostname));
/* remove port-portion of the Host-header, if present. */
for (i = 0; i < strlen(hostname); i++) {
if (hostname[i] == ':') {
hostname[i] = '\0';
break;
}
}
q = strchr(p, ':');
if (q == NULL)
q = strchr(p, '\0');
AN(q);
if (vs->suffix)
strncat(hostname, vs->suffix, sizeof(hostname) - strlen(hostname));
bprintf(hostname, "%.*s%s", (int)(q - p), p,
vs->suffix ? vs->suffix : "");
ret = vdi_dns_walk_cache(sp, vs, hostname);
return ret;
return (ret);
}
static struct vbc *
......@@ -412,10 +403,10 @@ vdi_dns_healthy(double now, const struct director *dir, uintptr_t target)
/* XXX: Fooling -Werror for a bit until it's actually implemented.
*/
if (now || dir || target)
return 1;
return (1);
else
return 1;
return 1;
return (1);
return (1);
/*
struct vdi_dns *vs;
struct director *dir;
......@@ -428,8 +419,8 @@ vdi_dns_healthy(double now, const struct director *dir, uintptr_t target)
dir = vdi_dns_find_backend(sp, vs);
if (dir)
return 1;
return 0;
return (1);
return (0);
*/
}
......
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