r5434 - in branches/2.1/varnish-cache: bin/varnishd doc/sphinx/reference include lib/libvcl
tfheen at varnish-cache.org
tfheen at varnish-cache.org
Tue Oct 19 17:01:04 CEST 2010
Author: tfheen
Date: 2010-10-19 17:01:04 +0200 (Tue, 19 Oct 2010)
New Revision: 5434
Modified:
branches/2.1/varnish-cache/bin/varnishd/Makefile.am
branches/2.1/varnish-cache/bin/varnishd/cache_backend.c
branches/2.1/varnish-cache/bin/varnishd/cache_backend.h
branches/2.1/varnish-cache/bin/varnishd/cache_backend_cfg.c
branches/2.1/varnish-cache/bin/varnishd/flint.lnt
branches/2.1/varnish-cache/doc/sphinx/reference/vcl.rst
branches/2.1/varnish-cache/include/stat_field.h
branches/2.1/varnish-cache/include/vrt.h
branches/2.1/varnish-cache/lib/libvcl/Makefile.am
branches/2.1/varnish-cache/lib/libvcl/vcc_backend.c
branches/2.1/varnish-cache/lib/libvcl/vcc_compile.h
branches/2.1/varnish-cache/lib/libvcl/vcc_fixed_token.c
Log:
Merge DNS director
The DNS director allows Varnish to pick backend based on the Host
header provided by the client, and how it resolves in DNS. A suffix
can be added to make it "internal" (see vcl(7)).
This includes commits 5062, 5063, 5064, 5099, 5172, 5173, 5174, 5175
Modified: branches/2.1/varnish-cache/bin/varnishd/Makefile.am
===================================================================
--- branches/2.1/varnish-cache/bin/varnishd/Makefile.am 2010-10-19 14:12:13 UTC (rev 5433)
+++ branches/2.1/varnish-cache/bin/varnishd/Makefile.am 2010-10-19 15:01:04 UTC (rev 5434)
@@ -21,6 +21,7 @@
cache_center.c \
cache_cli.c \
cache_dir_random.c \
+ cache_dir_dns.c \
cache_dir_round_robin.c \
cache_esi.c \
cache_expire.c \
Modified: branches/2.1/varnish-cache/bin/varnishd/cache_backend.c
===================================================================
--- branches/2.1/varnish-cache/bin/varnishd/cache_backend.c 2010-10-19 14:12:13 UTC (rev 5433)
+++ branches/2.1/varnish-cache/bin/varnishd/cache_backend.c 2010-10-19 15:01:04 UTC (rev 5434)
@@ -484,6 +484,24 @@
struct backend *backend;
};
+/* Returns the backend if and only if the this is a simple director.
+ * XXX: Needs a better name and possibly needs a better general approach.
+ * XXX: This is mainly used by the DNS director to fetch the actual backend
+ * XXX: so it can compare DNS lookups with the actual IP.
+ */
+struct backend *
+vdi_get_backend_if_simple(const struct director *d)
+{
+ CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
+ struct vdi_simple *vs, *vs2;
+
+ vs2 = d->priv;
+ if (vs2->magic != VDI_SIMPLE_MAGIC)
+ return NULL;
+ CAST_OBJ_NOTNULL(vs, d->priv, VDI_SIMPLE_MAGIC);
+ return vs->backend;
+}
+
static struct vbe_conn *
vdi_simple_getfd(const struct director *d, struct sess *sp)
{
Modified: branches/2.1/varnish-cache/bin/varnishd/cache_backend.h
===================================================================
--- branches/2.1/varnish-cache/bin/varnishd/cache_backend.h 2010-10-19 14:12:13 UTC (rev 5433)
+++ branches/2.1/varnish-cache/bin/varnishd/cache_backend.h 2010-10-19 15:01:04 UTC (rev 5434)
@@ -143,6 +143,7 @@
/* cache_backend.c */
void VBE_ReleaseConn(struct vbe_conn *vc);
+struct backend *vdi_get_backend_if_simple(const struct director *d);
/* cache_backend_cfg.c */
extern struct lock VBE_mtx;
@@ -158,6 +159,7 @@
/* Init functions for directors */
typedef void dir_init_f(struct cli *, struct director **, int , const void*);
dir_init_f VRT_init_dir_simple;
+dir_init_f VRT_init_dir_dns;
dir_init_f VRT_init_dir_hash;
dir_init_f VRT_init_dir_random;
dir_init_f VRT_init_dir_round_robin;
Modified: branches/2.1/varnish-cache/bin/varnishd/cache_backend_cfg.c
===================================================================
--- branches/2.1/varnish-cache/bin/varnishd/cache_backend_cfg.c 2010-10-19 14:12:13 UTC (rev 5433)
+++ branches/2.1/varnish-cache/bin/varnishd/cache_backend_cfg.c 2010-10-19 15:01:04 UTC (rev 5434)
@@ -273,6 +273,8 @@
VRT_init_dir_hash(cli, dir, idx, priv);
else if (!strcmp(name, "random"))
VRT_init_dir_random(cli, dir, idx, priv);
+ else if (!strcmp(name, "dns"))
+ VRT_init_dir_dns(cli, dir, idx, priv);
else if (!strcmp(name, "round-robin"))
VRT_init_dir_round_robin(cli, dir, idx, priv);
else if (!strcmp(name, "client"))
Modified: branches/2.1/varnish-cache/bin/varnishd/flint.lnt
===================================================================
--- branches/2.1/varnish-cache/bin/varnishd/flint.lnt 2010-10-19 14:12:13 UTC (rev 5433)
+++ branches/2.1/varnish-cache/bin/varnishd/flint.lnt 2010-10-19 15:01:04 UTC (rev 5434)
@@ -141,6 +141,7 @@
-sem(WS_Init, custodial(2))
-sem(http_Setup, custodial(2))
+-sem(vdi_dns_cache_list_add, custodial(3))
-ffc // No automatic custody
-e455 // thread lock
Modified: branches/2.1/varnish-cache/doc/sphinx/reference/vcl.rst
===================================================================
--- branches/2.1/varnish-cache/doc/sphinx/reference/vcl.rst 2010-10-19 14:12:13 UTC (rev 5433)
+++ branches/2.1/varnish-cache/doc/sphinx/reference/vcl.rst 2010-10-19 15:01:04 UTC (rev 5434)
@@ -175,6 +175,34 @@
of retries the director should take in order to find a healthy
backend.
+The DNS director
+~~~~~~~~~~~~~~~~
+
+The DNS director can use backends in three different ways. Either like the
+random or round-robin director or using .list::
+
+ director directorname dns {
+ .list = {
+ .host_header = "www.example.com";
+ .port = "80";
+ .connect_timeout = 0.4;
+ "192.168.15.0"/24;
+ "192.168.16.128"/25;
+ }
+ .ttl = 5m;
+ .suffix = "internal.example.net";
+ }
+
+This will specify 384 backends, all using port 80 and a connection timeout
+of 0.4s. Options must come before the list of IPs in the .list statement.
+
+The .ttl defines the cache duration of the DNS lookups.
+
+The above example will append "internal.example.net" to the incoming Host
+header supplied by the client, before looking it up. All settings are
+optional.
+
+
Backend probes
--------------
Modified: branches/2.1/varnish-cache/include/stat_field.h
===================================================================
--- branches/2.1/varnish-cache/include/stat_field.h 2010-10-19 14:12:13 UTC (rev 5433)
+++ branches/2.1/varnish-cache/include/stat_field.h 2010-10-19 15:01:04 UTC (rev 5434)
@@ -154,3 +154,8 @@
MAC_STAT(uptime, uint64_t, 0, 'a', "Client uptime")
MAC_STAT(backend_retry, uint64_t, 0, 'a', "Backend conn. retry")
+
+MAC_STAT(dir_dns_lookups, uint64_t, 0, 'a', "DNS director lookups")
+MAC_STAT(dir_dns_failed, uint64_t, 0, 'a', "DNS director failed lookups")
+MAC_STAT(dir_dns_hit, uint64_t, 0, 'a', "DNS director cached lookups hit")
+MAC_STAT(dir_dns_cache_full, uint64_t, 0, 'a', "DNS director full dnscache")
Modified: branches/2.1/varnish-cache/include/vrt.h
===================================================================
--- branches/2.1/varnish-cache/include/vrt.h 2010-10-19 14:12:13 UTC (rev 5433)
+++ branches/2.1/varnish-cache/include/vrt.h 2010-10-19 15:01:04 UTC (rev 5434)
@@ -111,7 +111,22 @@
const struct vrt_dir_round_robin_entry *members;
};
+/*
+ * A director with dns-based selection
+ */
+struct vrt_dir_dns_entry {
+ int host;
+};
+
+struct vrt_dir_dns {
+ const char *name;
+ const char *suffix;
+ const double ttl;
+ unsigned nmember;
+ const struct vrt_dir_dns_entry *members;
+};
+
/*
* other stuff.
* XXX: document when bored
Modified: branches/2.1/varnish-cache/lib/libvcl/Makefile.am
===================================================================
--- branches/2.1/varnish-cache/lib/libvcl/Makefile.am 2010-10-19 14:12:13 UTC (rev 5433)
+++ branches/2.1/varnish-cache/lib/libvcl/Makefile.am 2010-10-19 15:01:04 UTC (rev 5434)
@@ -18,6 +18,7 @@
vcc_compile.c \
vcc_dir_random.c \
vcc_dir_round_robin.c \
+ vcc_dir_dns.c \
vcc_parse.c \
vcc_fixed_token.c \
vcc_obj.c \
Modified: branches/2.1/varnish-cache/lib/libvcl/vcc_backend.c
===================================================================
--- branches/2.1/varnish-cache/lib/libvcl/vcc_backend.c 2010-10-19 14:12:13 UTC (rev 5433)
+++ branches/2.1/varnish-cache/lib/libvcl/vcc_backend.c 2010-10-19 15:01:04 UTC (rev 5434)
@@ -225,7 +225,7 @@
* in that context.
*/
-static void
+void
vcc_EmitBeIdent(const struct tokenlist *tl, struct vsb *v,
int serial, const struct token *first, const struct token *last)
{
@@ -681,6 +681,7 @@
{ "random", vcc_ParseRandomDirector },
{ "client", vcc_ParseRandomDirector },
{ "round-robin", vcc_ParseRoundRobinDirector },
+ { "dns", vcc_ParseDnsDirector },
{ NULL, NULL }
};
Modified: branches/2.1/varnish-cache/lib/libvcl/vcc_compile.h
===================================================================
--- branches/2.1/varnish-cache/lib/libvcl/vcc_compile.h 2010-10-19 14:12:13 UTC (rev 5433)
+++ branches/2.1/varnish-cache/lib/libvcl/vcc_compile.h 2010-10-19 15:01:04 UTC (rev 5434)
@@ -167,6 +167,10 @@
void vcc_IsField(struct tokenlist *tl, struct token **t, struct fld_spec *fs);
void vcc_FieldsOk(struct tokenlist *tl, const struct fld_spec *fs);
+void Emit_Sockaddr(struct tokenlist *tl, const struct token *t_host, const char *port);
+void vcc_EmitBeIdent(const struct tokenlist *tl, struct vsb *v,
+ int serial, const struct token *first, const struct token *last);
+
/* vcc_compile.c */
extern struct method method_tab[];
/*
@@ -191,6 +195,9 @@
/* vcc_dir_round_robin.c */
parsedirector_f vcc_ParseRoundRobinDirector;
+/* vcc_dir_dns.c */
+parsedirector_f vcc_ParseDnsDirector;
+
/* vcc_obj.c */
extern struct var vcc_vars[];
Modified: branches/2.1/varnish-cache/lib/libvcl/vcc_fixed_token.c
===================================================================
--- branches/2.1/varnish-cache/lib/libvcl/vcc_fixed_token.c 2010-10-19 14:12:13 UTC (rev 5433)
+++ branches/2.1/varnish-cache/lib/libvcl/vcc_fixed_token.c 2010-10-19 15:01:04 UTC (rev 5434)
@@ -268,7 +268,14 @@
vsb_cat(sb, " {\n\tconst char\t\t\t\t*name;\n");
vsb_cat(sb, "\tunsigned\t\t\t\tnmember;\n\tconst struct vrt_dir_rou");
vsb_cat(sb, "nd_robin_entry\t*members;\n};\n");
- vsb_cat(sb, "\n\n/*\n * other stuff.\n * XXX: document when bored\n");
+ vsb_cat(sb, "\n/*\n * A director with dns-based selection\n");
+ vsb_cat(sb, " */\n\nstruct vrt_dir_dns_entry {\n");
+ vsb_cat(sb, "\tint\t\t\t\t\thost;\n};\n\nstruct vrt_dir_dns {\n");
+ vsb_cat(sb, "\tconst char\t\t\t\t*name;\n\tconst char\t\t\t\t*suffi");
+ vsb_cat(sb, "x;\n\tconst double\t\t\t\tttl;\n");
+ vsb_cat(sb, "\tunsigned\t\t\t\tnmember;\n\tconst struct vrt_dir_dns");
+ vsb_cat(sb, "_entry\t\t*members;\n};\n\n/*\n");
+ vsb_cat(sb, " * other stuff.\n * XXX: document when bored\n");
vsb_cat(sb, " */\n\nstruct vrt_ref {\n\tunsigned\tsource;\n");
vsb_cat(sb, "\tunsigned\toffset;\n\tunsigned\tline;\n");
vsb_cat(sb, "\tunsigned\tpos;\n\tunsigned\tcount;\n");
More information about the varnish-commit
mailing list