[master] 5697dd8ff Give VCL_PROBE a vcl_name member and a _tostring() function.

Poul-Henning Kamp phk at FreeBSD.org
Wed Nov 26 16:09:05 UTC 2025


commit 5697dd8ff4cd3b88758ef1d732b63f23abcd56d5
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Nov 26 16:07:52 2025 +0000

    Give VCL_PROBE a vcl_name member and a _tostring() function.
    
    Fixes: #4417

diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index 2847e8b87..fe6c8bd96 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -824,6 +824,15 @@ VRT_BACKEND_string(VCL_BACKEND d)
 	return (d->vcl_name);
 }
 
+VCL_STRING v_matchproto_()
+VRT_PROBE_string(VCL_PROBE p)
+{
+	if (p == NULL)
+		return (NULL);
+	CHECK_OBJ_NOTNULL(p, VRT_BACKEND_PROBE_MAGIC);
+	return (p->vcl_name);
+}
+
 VCL_STRING v_matchproto_()
 VRT_BOOL_string(VCL_BOOL val)
 {
diff --git a/bin/varnishtest/tests/r04417.vtc b/bin/varnishtest/tests/r04417.vtc
new file mode 100644
index 000000000..2fc299279
--- /dev/null
+++ b/bin/varnishtest/tests/r04417.vtc
@@ -0,0 +1,31 @@
+vtest "Test VCL_PROBE type handling in VCC"
+
+# To truly test this we would have to inspect the generated
+# C-source code.
+
+varnish v1 -vcl {
+	vcl 4.1;
+
+	backend be none;
+
+	probe p1 { }
+	probe p2 { }
+
+	sub vcl_recv {
+		return (synth(200));
+	}
+
+	sub vcl_synth {
+		set resp.http.self-cmp = (p1 == p1);
+		set resp.http.cmp = (p1 == p2);
+		set resp.http.name = p1 + "/" + p2;
+	}
+} -start
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.http.cmp == false
+	expect resp.http.self-cmp == true
+	expect resp.http.name == p1/p2
+} -run
diff --git a/include/vrt.h b/include/vrt.h
index c21a5232f..3d09735b3 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -57,6 +57,9 @@
  * Whenever something is deleted or changed in a way which is not
  * binary/load-time compatible, increment MAJOR version
  *
+ * 22.1 (trunk)
+ *	"vcl_name" member added to vrt_backend_probe{}
+ *	VRT_PROBE_string() added
  * 22.0 (2025-09-15)
  *	VRT_r_obj_stale_age() added
  *	VRT_r_obj_stale_can_esi() added
@@ -623,6 +626,7 @@ VCL_STRING VRT_BOOL_string(VCL_BOOL);
 VCL_STRING VRT_BLOB_string(VRT_CTX, VCL_BLOB);
 VCL_STRING VRT_INT_string(VRT_CTX, VCL_INT);
 VCL_STRING VRT_IP_string(VRT_CTX, VCL_IP);
+VCL_STRING VRT_PROBE_string(VCL_PROBE);
 VCL_STRING VRT_REAL_string(VRT_CTX, VCL_REAL);
 VCL_STRING VRT_STEVEDORE_string(VCL_STEVEDORE);
 VCL_STRING VRT_STRANDS_string(VRT_CTX, VCL_STRANDS);
@@ -720,6 +724,7 @@ struct vrt_backend_probe {
 	const char			*url;
 	const char			*request;
 	VRT_BACKEND_PROBE_FIELDS(const)
+	const char			*vcl_name;
 };
 
 /* Backend related */
diff --git a/lib/libvcc/vcc_backend.c b/lib/libvcc/vcc_backend.c
index 3d4a1779f..90d0f6bad 100644
--- a/lib/libvcc/vcc_backend.c
+++ b/lib/libvcc/vcc_backend.c
@@ -216,8 +216,14 @@ vcc_ParseProbeSpec(struct vcc *tl, const struct symbol *sym, char **namep)
 	}
 	Fh(tl, 0, "static const struct vrt_backend_probe %s[] = {{\n", name);
 	Fh(tl, 0, "\t.magic = VRT_BACKEND_PROBE_MAGIC,\n");
-	if (namep != NULL)
+	if (sym != NULL) {
+		Fh(tl, 0, "\t.vcl_name = \"%s\",\n", sym->name);
+	} else {
+		Fh(tl, 0, "\t.vcl_name = \"%s\",\n", name);
+	}
+	if (namep != NULL) {
 		*namep = TlDup(tl, name);
+	}
 
 	window = 0;
 	threshold = 0;
diff --git a/lib/libvcc/vcc_types.c b/lib/libvcc/vcc_types.c
index 3a3c1dd21..abb75a72f 100644
--- a/lib/libvcc/vcc_types.c
+++ b/lib/libvcc/vcc_types.c
@@ -174,6 +174,7 @@ const struct type PROBE[1] = {{
 	.magic =		TYPE_MAGIC,
 	.name =			"PROBE",
 	.global_pfx =		"vgc_probe",
+	.tostring =		"VRT_PROBE_string(\v1)",
 	.default_sym =		default_probe,
 }};
 



More information about the varnish-commit mailing list