iputils/backport-ping6-Fix-support-for-DSCP.patch
2025-02-13 06:19:15 +00:00

55 lines
2.0 KiB
Diff

From 425f711a62f7d7523badd6b917f15ad58ecdb0ae Mon Sep 17 00:00:00 2001
From: Guillaume Nault <guillaume.nault@wanadoo.fr>
Date: Thu, 18 May 2023 18:12:54 +0200
Subject: [PATCH] ping6: Fix support for DSCP (Traffic Class, option -Q)
Set the IPV6_TCLASS option on probe_fd. Otherwise ip-rule is unaware
of the DSCP value at connect() time and can lookup the remote address
in the wrong routing table.
For example:
ip route add table main unreachable 2001:db8::10/124
ip route add table 100 2001:db8::10/124 dev eth0
ip -6 rule add dsfield 0x04 table 100
ping -Q 0x04 2001:db8::11
Without this patch, probe_fd fails to connect to 2001:db8::11 (No route
to host) since the route lookup is done in the main table instead of
table 100.
Note that, to work correctly, this patch also depends on a Linux kernel
bug fix (see
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e010ae08c71fda8be3d6bda256837795a0b3ea41).
That kernel patch has been backported to Linux stable trees and should
have already reached most distributions.
Reference:https://github.com/iputils/iputils/commit/425f711a62f7d7523badd6b917f15ad58ecdb0ae
Conflict:NA
Fixes: 33370345c7d8 ("Initial import of iputils")
Link: https://github.com/iputils/iputils/pull/468
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Guillaume Nault <guillaume.nault@wanadoo.fr>
---
ping/ping6_common.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/ping/ping6_common.c b/ping/ping6_common.c
index 21333aa0..e980a152 100644
--- a/ping/ping6_common.c
+++ b/ping/ping6_common.c
@@ -182,6 +182,10 @@ int ping6_run(struct ping_rts *rts, int argc, char **argv, struct addrinfo *ai,
disable_capability_raw();
}
+ if (rts->tclass &&
+ setsockopt(probe_fd, IPPROTO_IPV6, IPV6_TCLASS, &rts->tclass, sizeof (rts->tclass)) <0)
+ error(2, errno, "setsockopt(IPV6_TCLASS)");
+
if (!IN6_IS_ADDR_LINKLOCAL(&rts->firsthop.sin6_addr) &&
!IN6_IS_ADDR_MC_LINKLOCAL(&rts->firsthop.sin6_addr))
rts->firsthop.sin6_family = AF_INET6;