[master] d0a23b2b2 std.set_ip_tos() to support IPv6
Nils Goroll
nils.goroll at uplex.de
Mon Nov 16 14:00:12 UTC 2020
commit d0a23b2b25f6717bc3260f20c99847d0a3fc465c
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Mon Nov 16 14:38:37 2020 +0100
std.set_ip_tos() to support IPv6
diff --git a/lib/libvmod_std/vmod_std.c b/lib/libvmod_std/vmod_std.c
index 948a0972b..57b12c6a6 100644
--- a/lib/libvmod_std/vmod_std.c
+++ b/lib/libvmod_std/vmod_std.c
@@ -55,15 +55,26 @@ VCL_VOID v_matchproto_(td_std_set_ip_tos)
vmod_set_ip_tos(VRT_CTX, VCL_INT tos)
{
struct suckaddr *sa;
- int itos = tos;
+ int fam, 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)));
+ fam = VSA_Get_Proto(sa);
+ switch (fam) {
+ case PF_INET:
+ VTCP_Assert(setsockopt(ctx->req->sp->fd,
+ IPPROTO_IP, IP_TOS, &itos, sizeof(itos)));
+ break;
+ case PF_INET6:
+ VTCP_Assert(setsockopt(ctx->req->sp->fd,
+ IPPROTO_IPV6, IPV6_TCLASS, &itos, sizeof(itos)));
+ break;
+ default:
+ INCOMPL();
+ }
}
static const char *
diff --git a/lib/libvmod_std/vmod_std.vcc b/lib/libvmod_std/vmod_std.vcc
index 961e90ae1..d0aea5707 100644
--- a/lib/libvmod_std/vmod_std.vcc
+++ b/lib/libvmod_std/vmod_std.vcc
@@ -538,12 +538,14 @@ Example::
$Function VOID set_ip_tos(INT tos)
-Sets the IP type-of-service (TOS) field for the current session to
-*tos*. Silently ignored if the listen address is a Unix domain socket.
-
-Please note that the TOS field is not removed by the end of the
-request so probably want to set it on every request should you utilize
-it.
+Sets the Differentiated Services Codepoint (DSCP) / IPv4 Type of
+Service (TOS) / IPv6 Traffic Class (TCLASS) byte for the current
+session to *tos*. Silently ignored if the listen address is a Unix
+domain socket.
+
+Please note that setting the traffic class affects all requests on the
+same http1.1 / http2 TCP connection and, in particular, is not removed
+at the end of the request.
Example::
More information about the varnish-commit
mailing list