Commit 98f8202e authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Some minor cleaups and additional asserts to get rid of the worst

FlexeLint spammage.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@5098 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 7ae15041
...@@ -79,14 +79,13 @@ struct vdi_dns { ...@@ -79,14 +79,13 @@ struct vdi_dns {
pthread_rwlock_t rwlock; pthread_rwlock_t rwlock;
const char *suffix; const char *suffix;
double ttl; double ttl;
const unsigned max_cache_size;
}; };
/* Compare an IPv4 backend to a IPv4 addr/len */ /* Compare an IPv4 backend to a IPv4 addr/len */
static int static int
vdi_dns_comp_addrinfo4(struct backend *bp, vdi_dns_comp_addrinfo4(const struct backend *bp,
const struct sockaddr_in *addr, const struct sockaddr_in *addr,
const socklen_t len) const socklen_t len)
{ {
...@@ -104,7 +103,7 @@ vdi_dns_comp_addrinfo4(struct backend *bp, ...@@ -104,7 +103,7 @@ vdi_dns_comp_addrinfo4(struct backend *bp,
/* Compare an IPv6 backend to a IPv6 addr/len */ /* Compare an IPv6 backend to a IPv6 addr/len */
static int static int
vdi_dns_comp_addrinfo6(struct backend *bp, vdi_dns_comp_addrinfo6(const struct backend *bp,
struct sockaddr_in6 *addr, struct sockaddr_in6 *addr,
const socklen_t len) const socklen_t len)
{ {
...@@ -128,12 +127,14 @@ vdi_dns_comp_addrinfo6(struct backend *bp, ...@@ -128,12 +127,14 @@ vdi_dns_comp_addrinfo6(struct backend *bp,
/* Check if a backends socket is the same as addr */ /* Check if a backends socket is the same as addr */
static int static int
vdi_dns_comp_addrinfo(struct director *dir, vdi_dns_comp_addrinfo(const struct director *dir,
struct sockaddr *addr, struct sockaddr *addr,
const socklen_t len) const socklen_t len)
{ {
struct backend *bp; struct backend *bp;
bp = vdi_get_backend_if_simple(dir); bp = vdi_get_backend_if_simple(dir);
AN(bp);
if (addr->sa_family == PF_INET && bp->ipv4) { if (addr->sa_family == PF_INET && bp->ipv4) {
return (vdi_dns_comp_addrinfo4(bp, (struct sockaddr_in *) return (vdi_dns_comp_addrinfo4(bp, (struct sockaddr_in *)
addr, len)); addr, len));
...@@ -279,8 +280,9 @@ vdi_dns_cache_add(const struct sess *sp, ...@@ -279,8 +280,9 @@ vdi_dns_cache_add(const struct sess *sp,
hint.ai_socktype = SOCK_STREAM; hint.ai_socktype = SOCK_STREAM;
ALLOC_OBJ(new, VDI_DNSDIR_MAGIC); ALLOC_OBJ(new, VDI_DNSDIR_MAGIC);
XXXAN(new);
new->hostname = calloc(sizeof(char), strlen(hostname)+1); new->hostname = calloc(sizeof(char), strlen(hostname)+1);
assert(new->hostname != NULL); XXXAN(new->hostname);
strcpy(new->hostname, hostname); strcpy(new->hostname, hostname);
error = getaddrinfo(hostname, "80", &hint, &res0); error = getaddrinfo(hostname, "80", &hint, &res0);
...@@ -292,15 +294,15 @@ vdi_dns_cache_add(const struct sess *sp, ...@@ -292,15 +294,15 @@ vdi_dns_cache_add(const struct sess *sp,
} }
for (res = res0; res; res = res->ai_next) { for (res = res0; res; res = res->ai_next) {
if (res->ai_family != PF_INET && if (res->ai_family != PF_INET && res->ai_family != PF_INET6)
res->ai_family != PF_INET6)
continue; continue;
for (i = 0; i < vs->nhosts; i++) { for (i = 0; i < vs->nhosts; i++) {
if (vdi_dns_comp_addrinfo(vs->hosts[i], if (vdi_dns_comp_addrinfo(vs->hosts[i],
res->ai_addr, res->ai_addrlen)) { res->ai_addr, res->ai_addrlen)) {
new->hosts[host] = vs->hosts[i]; new->hosts[host] = vs->hosts[i];
CHECK_OBJ_NOTNULL(new->hosts[host], DIRECTOR_MAGIC); CHECK_OBJ_NOTNULL(new->hosts[host],
DIRECTOR_MAGIC);
host++; host++;
} }
} }
...@@ -327,11 +329,11 @@ vdi_dns_walk_cache(const struct sess *sp, ...@@ -327,11 +329,11 @@ vdi_dns_walk_cache(const struct sess *sp,
int ret; int ret;
AZ(pthread_rwlock_rdlock(&vs->rwlock)); AZ(pthread_rwlock_rdlock(&vs->rwlock));
ret = vdi_dns_cache_has(sp, vs, hostname, &backend, 0); ret = vdi_dns_cache_has(sp, vs, hostname, &backend, 0);
pthread_rwlock_unlock(&vs->rwlock); AZ(pthread_rwlock_unlock(&vs->rwlock));
if (!ret) { if (!ret) {
AZ(pthread_rwlock_wrlock(&vs->rwlock)); AZ(pthread_rwlock_wrlock(&vs->rwlock));
ret = vdi_dns_cache_add(sp, vs, hostname, &backend); ret = vdi_dns_cache_add(sp, vs, hostname, &backend);
pthread_rwlock_unlock(&vs->rwlock); AZ(pthread_rwlock_unlock(&vs->rwlock));
} else } else
VSC_main->dir_dns_hit++; VSC_main->dir_dns_hit++;
...@@ -434,17 +436,15 @@ static void ...@@ -434,17 +436,15 @@ static void
vdi_dns_fini(struct director *d) vdi_dns_fini(struct director *d)
{ {
struct vdi_dns *vs; struct vdi_dns *vs;
struct director **vh;
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC); CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
CAST_OBJ_NOTNULL(vs, d->priv, VDI_DNS_MAGIC); CAST_OBJ_NOTNULL(vs, d->priv, VDI_DNS_MAGIC);
vh = vs->hosts;
free(vs->hosts); free(vs->hosts);
free(vs->dir.vcl_name); free(vs->dir.vcl_name);
vs->dir.magic = 0; vs->dir.magic = 0;
/* FIXME: Free the cache */ /* FIXME: Free the cache */
pthread_rwlock_destroy(&vs->rwlock); AZ(pthread_rwlock_destroy(&vs->rwlock));
FREE_OBJ(vs); FREE_OBJ(vs);
} }
...@@ -482,6 +482,6 @@ VRT_init_dir_dns(struct cli *cli, struct director **bp, int idx, ...@@ -482,6 +482,6 @@ VRT_init_dir_dns(struct cli *cli, struct director **bp, int idx,
vs->nhosts = t->nmember; vs->nhosts = t->nmember;
vs->ttl = t->ttl; vs->ttl = t->ttl;
VTAILQ_INIT(&vs->cachelist); VTAILQ_INIT(&vs->cachelist);
pthread_rwlock_init(&vs->rwlock, NULL); AZ(pthread_rwlock_init(&vs->rwlock, NULL));
bp[idx] = &vs->dir; bp[idx] = &vs->dir;
} }
...@@ -100,6 +100,8 @@ ...@@ -100,6 +100,8 @@
-sem(WS_Init, custodial(2)) -sem(WS_Init, custodial(2))
-sem(http_Setup, custodial(2)) -sem(http_Setup, custodial(2))
-sem(vdi_dns_cache_list_add, custodial(3))
-e455 // thread lock -e455 // thread lock
-e458 // unprotected read -e458 // unprotected read
-e763 // Redundant declaration for symbol '...' previously declared -e763 // Redundant declaration for symbol '...' previously declared
......
...@@ -35,7 +35,6 @@ SVNID("$Id$") ...@@ -35,7 +35,6 @@ SVNID("$Id$")
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netdb.h>
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
...@@ -51,7 +50,7 @@ SVNID("$Id$") ...@@ -51,7 +50,7 @@ SVNID("$Id$")
* Parse directors * Parse directors
*/ */
struct vcc_dir_backend_defaults { static struct vcc_dir_backend_defaults {
char *port; char *port;
char *hostheader; char *hostheader;
double connect_timeout; double connect_timeout;
...@@ -72,20 +71,21 @@ static void vcc_dir_initialize_defaults(void) ...@@ -72,20 +71,21 @@ static void vcc_dir_initialize_defaults(void)
b_defaults.saint = UINT_MAX; b_defaults.saint = UINT_MAX;
} }
static struct token *dns_first; static const struct token *dns_first;
static void static void
print_backend(struct vcc *tl, print_backend(struct vcc *tl,
int serial, int serial,
uint8_t *ip) const uint8_t *ip)
{ {
char vgcname[BUFSIZ]; char vgcname[BUFSIZ];
char strip[16]; char strip[16];
struct token tmptok; struct token tmptok;
struct vsb *vsb; struct vsb *vsb;
sprintf(strip, "%d.%d.%d.%d",ip[3],ip[2],ip[1],ip[0]);
sprintf(strip, "%u.%u.%u.%u", ip[3], ip[2], ip[1], ip[0]);
tmptok.dec = strip; tmptok.dec = strip;
sprintf(vgcname,"%.*s_%d",PF(tl->t_dir),serial); sprintf(vgcname,"%.*s_%d",PF(tl->t_dir), serial);
vsb = vsb_newauto(); vsb = vsb_newauto();
AN(vsb); AN(vsb);
tl->fb = vsb; tl->fb = vsb;
...@@ -127,6 +127,7 @@ print_backend(struct vcc *tl, ...@@ -127,6 +127,7 @@ print_backend(struct vcc *tl,
Ff(tl, 0, "\tVRT_fini_dir(cli, VGCDIR(%s));\n", vgcname); Ff(tl, 0, "\tVRT_fini_dir(cli, VGCDIR(%s));\n", vgcname);
tl->ndirector++; tl->ndirector++;
} }
/* /*
* Output backends for all IPs in the range supplied by * Output backends for all IPs in the range supplied by
* "a[0].a[1].a[2].a[3]/inmask". * "a[0].a[1].a[2].a[3]/inmask".
...@@ -138,7 +139,7 @@ print_backend(struct vcc *tl, ...@@ -138,7 +139,7 @@ print_backend(struct vcc *tl,
static void static void
vcc_dir_dns_makebackend(struct vcc *tl, vcc_dir_dns_makebackend(struct vcc *tl,
int *serial, int *serial,
unsigned char a[], const unsigned char a[],
int inmask) int inmask)
{ {
uint32_t ip4=0; uint32_t ip4=0;
...@@ -258,7 +259,8 @@ vcc_dir_dns_parse_list(struct vcc *tl, int *serial) ...@@ -258,7 +259,8 @@ vcc_dir_dns_parse_list(struct vcc *tl, int *serial)
vcc_dir_dns_parse_backend_options(tl); vcc_dir_dns_parse_backend_options(tl);
while (tl->t->tok == CSTR) { while (tl->t->tok == CSTR) {
mask = 32; mask = 32;
ret = sscanf(tl->t->dec, "%hhu.%hhu.%hhu.%hhu",&a[0],&a[1],&a[2],&a[3]); ret = sscanf(tl->t->dec, "%hhu.%hhu.%hhu.%hhu",
&a[0], &a[1], &a[2], &a[3]);
assert(ret == 4); assert(ret == 4);
vcc_NextToken(tl); vcc_NextToken(tl);
if (tl->t->tok == '/') { if (tl->t->tok == '/') {
...@@ -277,7 +279,7 @@ vcc_ParseDnsDirector(struct vcc *tl) ...@@ -277,7 +279,7 @@ vcc_ParseDnsDirector(struct vcc *tl)
{ {
struct token *t_field, *t_be, *t_suffix = NULL; struct token *t_field, *t_be, *t_suffix = NULL;
double ttl = 60.0; double ttl = 60.0;
int nbh, nelem = 0; int nelem = 0;
struct fld_spec *fs; struct fld_spec *fs;
const char *first; const char *first;
char *p; char *p;
...@@ -294,7 +296,6 @@ vcc_ParseDnsDirector(struct vcc *tl) ...@@ -294,7 +296,6 @@ vcc_ParseDnsDirector(struct vcc *tl)
first = ""; first = "";
t_be = tl->t; t_be = tl->t;
vcc_ResetFldSpec(fs); vcc_ResetFldSpec(fs);
nbh = -1;
ExpectErr(tl, '{'); ExpectErr(tl, '{');
vcc_NextToken(tl); vcc_NextToken(tl);
......
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