Commit b614ca18 authored by Tollef Fog Heen's avatar Tollef Fog Heen

Merge r3949: add new option to set the identity of a varnish instance and...

Merge r3949: add new option to set the identity of a varnish instance and allow it to be accessed using server.identity



git-svn-id: http://www.varnish-cache.org/svn/branches/2.0@3992 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 1b4314e1
......@@ -566,6 +566,16 @@ VRT_r_server_ip(struct sess *sp)
return (sp->mysockaddr);
}
const char*
VRT_r_server_identity(struct sess *sp)
{
if (heritage.identity[0] != '\0')
return heritage.identity;
else
return heritage.name;
}
const char*
VRT_r_server_hostname(struct sess *sp)
{
......
......@@ -65,6 +65,7 @@ struct heritage {
struct hash_slinger *hash;
char name[1024];
char identity[1024];
};
struct params {
......
......@@ -216,6 +216,7 @@ usage(void)
fprintf(stderr, FMT, "", " -h simple_list");
fprintf(stderr, FMT, "", " -h classic [default]");
fprintf(stderr, FMT, "", " -h classic,<buckets>");
fprintf(stderr, FMT, "-i identity", "Identity of varnish instance");
fprintf(stderr, FMT, "-l bytesize", "Size of shared memory log");
fprintf(stderr, FMT, "-n dir", "varnishd working directory");
fprintf(stderr, FMT, "-P file", "PID file");
......@@ -424,6 +425,7 @@ main(int argc, char * const *argv)
unsigned F_flag = 0;
const char *b_arg = NULL;
const char *f_arg = NULL;
const char *i_arg = NULL;
const char *l_arg = "80m";
uintmax_t l_size;
const char *q;
......@@ -471,7 +473,7 @@ main(int argc, char * const *argv)
cli_check(cli);
while ((o = getopt(argc, argv,
"a:b:Cdf:Fg:h:l:n:P:p:s:T:t:u:Vw:")) != -1)
"a:b:Cdf:Fg:h:i:l:n:P:p:s:T:t:u:Vw:")) != -1)
switch (o) {
case 'a':
MCF_ParamSet(cli, "listen_address", optarg);
......@@ -498,6 +500,9 @@ main(int argc, char * const *argv)
case 'h':
h_arg = optarg;
break;
case 'i':
i_arg = optarg;
break;
case 'l':
l_arg = optarg;
break;
......@@ -589,6 +594,17 @@ main(int argc, char * const *argv)
exit(1);
}
if (i_arg != NULL) {
size_t len;
if (snprintf(heritage.identity, sizeof heritage.identity, "%s", i_arg) > sizeof heritage.identity) {
fprintf(stderr, "Invalid identity name: %s\n",
strerror(ENAMETOOLONG));
exit(1);
}
}
if (n_arg != NULL)
openlog(n_arg, LOG_PID, LOG_LOCAL0);
else
......
......@@ -39,6 +39,9 @@ varnish v1 -vcl+backend {
set resp.proto = "HTTP/1.2";
set resp.response = "Naah, lets fail it";
set resp.status = 904;
# XXX should be moved to it's own test
set resp.http.x-served-by-hostname = server.hostname;
set resp.http.x-served-by-identity = server.identity;
set resp.http.foobar =
resp.proto
resp.status;
......
......@@ -9,6 +9,7 @@
struct sockaddr * VRT_r_client_ip(const struct sess *);
struct sockaddr * VRT_r_server_ip(struct sess *);
const char * VRT_r_server_hostname(struct sess *);
const char * VRT_r_server_identity(struct sess *);
int VRT_r_server_port(struct sess *);
const char * VRT_r_req_request(const struct sess *);
void VRT_l_req_request(const struct sess *, const char *, ...);
......
......@@ -159,8 +159,8 @@ vcl_output_lang_h(struct vsb *sb)
/* ../../include/vcl.h */
vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 3718 2009-02-10 14");
vsb_cat(sb, ":25:49Z tfheen $\n *\n * NB: This file is machine gen");
vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 3991 2009-03-23 12");
vsb_cat(sb, ":42:15Z tfheen $\n *\n * NB: This file is machine gen");
vsb_cat(sb, "erated, DO NOT EDIT!\n *\n * Edit and run vcc_gen_fixe");
vsb_cat(sb, "d_token.tcl instead\n */\n\nstruct sess;\n");
vsb_cat(sb, "struct cli;\n\ntypedef void vcl_init_f(struct cli *);\n");
......@@ -330,7 +330,8 @@ vcl_output_lang_h(struct vsb *sb)
vsb_cat(sb, " */\n\nstruct sockaddr * VRT_r_client_ip(const struct ");
vsb_cat(sb, "sess *);\nstruct sockaddr * VRT_r_server_ip(struct ses");
vsb_cat(sb, "s *);\nconst char * VRT_r_server_hostname(struct sess ");
vsb_cat(sb, "*);\nint VRT_r_server_port(struct sess *);\n");
vsb_cat(sb, "*);\nconst char * VRT_r_server_identity(struct sess *)");
vsb_cat(sb, ";\nint VRT_r_server_port(struct sess *);\n");
vsb_cat(sb, "const char * VRT_r_req_request(const struct sess *);\n");
vsb_cat(sb, "void VRT_l_req_request(const struct sess *, const char");
vsb_cat(sb, " *, ...);\nconst char * VRT_r_req_url(const struct ses");
......
......@@ -56,6 +56,11 @@ set spobj {
{recv pipe pass hash miss hit fetch deliver error }
"struct sess *"
}
{ server.identity
RO STRING
{recv pipe pass hash miss hit fetch deliver error }
"struct sess *"
}
{ server.port
RO INT
{recv pipe pass hash miss hit fetch deliver error }
......
......@@ -32,6 +32,13 @@ struct var vcc_vars[] = {
| VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER
| VCL_MET_ERROR
},
{ "server.identity", STRING, 15,
"VRT_r_server_identity(sp)", NULL,
V_RO, 0,
VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH
| VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER
| VCL_MET_ERROR
},
{ "server.port", INT, 11,
"VRT_r_server_port(sp)", NULL,
V_RO, 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