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

Add conversion from IP to string format to allow things like:

	set bereq.http.HeyYou = client.ip " asked for  " req.url;



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@1663 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 6a9b5a22
...@@ -472,3 +472,19 @@ VRT_r_obj_lastuse(struct sess *sp) ...@@ -472,3 +472,19 @@ VRT_r_obj_lastuse(struct sess *sp)
clock_gettime(CLOCK_MONOTONIC, &now); clock_gettime(CLOCK_MONOTONIC, &now);
return (now.tv_sec - sp->obj->lru_stamp); return (now.tv_sec - sp->obj->lru_stamp);
} }
/*--------------------------------------------------------------------*/
char *
VRT_IP_string(struct sess *sp, struct sockaddr *sa)
{
char h[64], p[8], *q;
TCP_name(sa, sa->sa_len, h, sizeof h, p, sizeof p);
q = WS_Alloc(sp->http->ws, strlen(h) + strlen(p) + 2);
AN(q);
strcpy(q, h);
strcat(q, ":");
strcat(q, p);
return (q);
}
...@@ -85,6 +85,7 @@ void VRT_alloc_backends(struct VCL_conf *cp); ...@@ -85,6 +85,7 @@ void VRT_alloc_backends(struct VCL_conf *cp);
void VRT_free_backends(struct VCL_conf *cp); void VRT_free_backends(struct VCL_conf *cp);
void VRT_fini_backend(struct backend *be); void VRT_fini_backend(struct backend *be);
char *VRT_IP_string(struct sess *sp, struct sockaddr *sa);
#define VRT_done(sp, hand) \ #define VRT_done(sp, hand) \
do { \ do { \
......
...@@ -441,6 +441,7 @@ vcl_output_lang_h(struct vsb *sb) ...@@ -441,6 +441,7 @@ vcl_output_lang_h(struct vsb *sb)
vsb_cat(sb, "void VRT_free_backends(struct VCL_conf *cp);\n"); vsb_cat(sb, "void VRT_free_backends(struct VCL_conf *cp);\n");
vsb_cat(sb, "void VRT_fini_backend(struct backend *be);\n"); vsb_cat(sb, "void VRT_fini_backend(struct backend *be);\n");
vsb_cat(sb, "\n"); vsb_cat(sb, "\n");
vsb_cat(sb, "char *VRT_IP_string(struct sess *sp, struct sockaddr *sa);\n");
vsb_cat(sb, "\n"); vsb_cat(sb, "\n");
vsb_cat(sb, "#define VRT_done(sp, hand) \\\n"); vsb_cat(sb, "#define VRT_done(sp, hand) \\\n");
vsb_cat(sb, " do { \\\n"); vsb_cat(sb, " do { \\\n");
......
...@@ -66,6 +66,9 @@ vcc_StringVal(struct tokenlist *tl) ...@@ -66,6 +66,9 @@ vcc_StringVal(struct tokenlist *tl)
case STRING: case STRING:
Fb(tl, 0, "%s", vp->rname); Fb(tl, 0, "%s", vp->rname);
break; break;
case IP:
Fb(tl, 0, "VRT_IP_string(sp, %s)", vp->rname);
break;
default: default:
vsb_printf(tl->sb, vsb_printf(tl->sb,
"String representation of '%s' not implemented yet.\n", "String representation of '%s' not implemented yet.\n",
......
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