[master] 2e9682e std.set_ip_tos() is silently ignored if local.ip is the bogo-ip, hence if the listen address is UDS.

Geoff Simmons geoff at uplex.de
Thu Feb 22 09:23:09 UTC 2018


commit 2e9682ea2f26a292151867803e9596602e7854fa
Author: Geoff Simmons <geoff at uplex.de>
Date:   Sat Feb 17 11:10:30 2018 +0100

    std.set_ip_tos() is silently ignored if local.ip is the bogo-ip,
    hence if the listen address is UDS.
    
    Otherwise, the setsockopt() call will fail VTCP_Assert().
    
    Also, verify that std.ip() and std.port() don't work with UDS.

diff --git a/bin/varnishtest/tests/m00046.vtc b/bin/varnishtest/tests/m00046.vtc
new file mode 100644
index 0000000..fc0945b
--- /dev/null
+++ b/bin/varnishtest/tests/m00046.vtc
@@ -0,0 +1,47 @@
+varnishtest "std.ip(), .port() and .set_ip_tos() don't work for UDS addresses"
+
+varnish v1 -arg "-a ${tmpdir}/v1.sock -b '${bad_backend}'" -start
+
+varnish v2 -arg "-a ${tmpdir}/v2.sock" -vcl {
+	import std;
+	backend default { .host = "${bad_ip}"; }
+
+	sub vcl_recv {
+		return(synth(200));
+	}
+
+	sub vcl_synth {
+		set resp.http.v1_addr = std.ip("${v1_addr}", client.ip);
+	}
+} -start
+
+client c1 -connect "${tmpdir}/v2.sock" {
+	txreq
+	rxresp
+	expect resp.http.v1_addr == "0.0.0.0"
+} -run
+
+varnish v2 -errvcl {IP constant '"${v1_addr}"' could not be resolved to an IP address:} {
+	import std;
+
+	sub vcl_recv {
+		set resp.http.v1_port = std.port("${v1_addr}");
+	}
+}
+
+varnish v2 -vcl {
+	import std;
+	backend default { .host = "${bad_ip}"; }
+
+	sub vcl_recv {
+	    # Silently ignored for a UDS
+	    std.set_ip_tos(0);
+	    return(synth(200));
+	}
+}
+
+client c1 -connect "${tmpdir}/v2.sock" {
+	txreq
+	rxresp
+	expect resp.status == 200
+} -run
diff --git a/lib/libvmod_std/vmod_std.c b/lib/libvmod_std/vmod_std.c
index efd6d84..fdf1227 100644
--- a/lib/libvmod_std/vmod_std.c
+++ b/lib/libvmod_std/vmod_std.c
@@ -53,9 +53,14 @@
 VCL_VOID v_matchproto_(td_std_set_ip_tos)
 vmod_set_ip_tos(VRT_CTX, VCL_INT tos)
 {
+	struct suckaddr *sa;
 	int itos = tos;
 
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	AZ(SES_Get_local_addr(ctx->req->sp, &sa));
+	/* Silently ignore for non-IP addresses. */
+	if (VSA_Compare(sa, bogo_ip) == 0)
+		return;
 	VTCP_Assert(setsockopt(ctx->req->sp->fd,
 	    IPPROTO_IP, IP_TOS, &itos, sizeof(itos)));
 }


More information about the varnish-commit mailing list