[master] dbd1cdfb2 backend.list -j now outputs IPs/port information
Nils Goroll
nils.goroll at uplex.de
Mon Sep 30 13:38:07 UTC 2024
commit dbd1cdfb25b6f80f9b4c3e014079e7fbccc006f5
Author: Guillaume Quintard <guillaume.quintard at varnish-software.com>
Date: Tue Sep 24 05:48:13 2024 -0400
backend.list -j now outputs IPs/port information
diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index fe7e4f4e1..922a4bb13 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -624,12 +624,17 @@ static void v_matchproto_(vdi_list_f)
vbe_list(VRT_CTX, const struct director *d, struct vsb *vsb, int pflag,
int jflag)
{
+ char buf[VTCP_ADDRBUFSIZE];
struct backend *bp;
+ struct vrt_endpoint *vep;
(void)ctx;
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
CAST_OBJ_NOTNULL(bp, d->priv, BACKEND_MAGIC);
+ CHECK_OBJ_NOTNULL(bp->endpoint, VRT_ENDPOINT_MAGIC);
+
+ vep = bp->endpoint;
if (bp->probe != NULL)
VBP_Status(vsb, bp, pflag, jflag);
@@ -641,6 +646,17 @@ vbe_list(VRT_CTX, const struct director *d, struct vsb *vsb, int pflag,
return;
else
VSB_cat(vsb, "0/0\thealthy");
+
+ if (jflag && pflag) {
+ if (vep->ipv4 != NULL) {
+ VTCP_name(vep->ipv4, buf, sizeof buf, NULL, 0);
+ VSB_printf(vsb, "\"ipv4\": \"%s\",\n", buf);
+ }
+ if (vep->ipv6 != NULL) {
+ VTCP_name(vep->ipv6, buf, sizeof buf, NULL, 0);
+ VSB_printf(vsb, "\"ipv6\": \"%s\",\n", buf);
+ }
+ }
}
/*--------------------------------------------------------------------
diff --git a/bin/varnishtest/tests/b00091.vtc b/bin/varnishtest/tests/b00091.vtc
new file mode 100644
index 000000000..9bc1b98ea
--- /dev/null
+++ b/bin/varnishtest/tests/b00091.vtc
@@ -0,0 +1,41 @@
+varnishtest "IPs/port in varnishadm backend.list -j"
+
+feature cmd "jq -V"
+
+server s0 {
+} -start
+
+
+varnish v1 -vcl+backend {
+ backend s1 {
+ .host = "127.0.0.1";
+ .port = "2222";
+ .probe = { .url = "/"; }
+ }
+ backend s2 {
+ .host = "::1:2:3:4";
+ .port = "3333";
+ }
+
+ sub vcl_recv {
+ set req.backend_hint = s0;
+ set req.backend_hint = s1;
+ set req.backend_hint = s2;
+ }
+} -start
+
+shell {
+ set -e
+
+varnishadm -n ${v1_name} backend.list -j
+ varnishadm -n ${v1_name} backend.list -jp > result.json
+ jq '
+ .[3]["vcl1.s0"].ipv4 == "${s0_addr}" or error("wrong s0 ipv4"),
+ .[3]["vcl1.s1"].ipv4 == "127.0.0.1" or error("wrong s2 ipv4"),
+ .[3]["vcl1.s2"].ipv4 == null or error("s3 ipv4 exists"),
+
+ .[3]["vcl1.s0"].ipv6 == null or error("s0 ipv6 exists"),
+ .[3]["vcl1.s1"].ipv6 == null or error("s2 ipv6 exists"),
+ .[3]["vcl1.s2"].ipv6 == "::1:2:3:4" or error("wrong s3 ipv6")
+ ' result.json
+}
More information about the varnish-commit
mailing list