traceroute: Implement ECN bleaching detection

Explicit Congestion Notification (ECN) is a mechanism that allows
end-to-end notification of network congestion without dropping packets
by explicitly setting the ECN code point (2 bits).

Per RFC 8087, section 3.5, network devices should not be configured to
change the ECN code point in the packets that they forward, except to
set the CE (Congestion Experienced) code point ('11') to signal
incipient congestion.

The current commit adds an -E flag to traceroute that crafts a packet
with an ECT(1) code point ('01').

If the packet is received back with a zero ECN code point ('00'), it
outputs that the hop in question erases or "bleaches" the ECN code point
values.  Bleaching may occur for various reasons (including normalizing
packets to hide which equipment supports ECN).  This policy prevents the
use of ECN by applications.

If the packet is received back with an all-ones ECN code point ('11'),
it outputs that the hop in question is experiencing "congestion".

If the packet is received back with a different ECN code point ('10'),
it outputs that the hop in question changes or "mangles" the ECN code
point values.

If the packet is received with the same ECN code point that was sent
('01'), it outputs that the hop has "passed" the ECN bits appropriately.

Inspired by:	Darwin
Reviewed by:	imp, markj
MFC after:	1 month
Pull Request:	https://github.com/freebsd/freebsd-src/pull/879
This commit is contained in:
Jose Luis Duran 2023-10-28 00:28:52 +00:00 committed by Mark Johnston
parent 0c2218d1d5
commit 8aafae6639
2 changed files with 46 additions and 4 deletions

View file

@ -15,7 +15,7 @@
.\"
.\" $Id: traceroute.8,v 1.19 2000/09/21 08:44:19 leres Exp $
.\"
.Dd November 25, 2020
.Dd October 25, 2023
.Dt TRACEROUTE 8
.Os
.Sh NAME
@ -24,7 +24,7 @@
.Sh SYNOPSIS
.Nm
.Bk -words
.Op Fl adDeFISnrvx
.Op Fl adDeEFISnrvx
.Op Fl f Ar first_ttl
.Op Fl g Ar gateway
.Op Fl M Ar first_ttl
@ -66,6 +66,22 @@ default.
Firewall evasion mode.
Use fixed destination ports for UDP, UDP-Lite, TCP and SCTP probes.
The destination port does NOT increment with each packet sent.
.It Fl E
Detect ECN bleaching.
Set the
.Em IPTOS_ECN_ECT1
Explicit Congestion Notification (ECN) bits
.Pq Dv 01 ,
and report if the hop has bleached
.Pq Dv 00
or mangled
.Pq Dv 10
them, or if it is experiencing congestion
.Pq Dv 11 .
Otherwise, report that it passed the bits appropriately.
If
.Fl t
is also specified, the corresponding ECN bits will be replaced.
.It Fl f Ar first_ttl
Set the initial time-to-live used in the first outgoing probe packet.
.It Fl F

View file

@ -365,6 +365,7 @@ int doipcksum = 1; /* calculate ip checksums by default */
int optlen; /* length of ip options */
int fixedPort = 0; /* Use fixed destination port for TCP and UDP */
int printdiff = 0; /* Print the difference between sent and quoted */
int ecnflag = 0; /* ECN bleaching detection flag */
extern int optind;
extern int opterr;
@ -597,7 +598,7 @@ main(int argc, char **argv)
prog = argv[0];
opterr = 0;
while ((op = getopt(argc, argv, "aA:edDFInrSvxf:g:i:M:m:P:p:q:s:t:w:z:")) != EOF)
while ((op = getopt(argc, argv, "aA:eEdDFInrSvxf:g:i:M:m:P:p:q:s:t:w:z:")) != EOF)
switch (op) {
case 'a':
as_path = 1;
@ -620,6 +621,10 @@ main(int argc, char **argv)
fixedPort = 1;
break;
case 'E':
ecnflag = 1;
break;
case 'f':
case 'M': /* FreeBSD compat. */
first_ttl = str2val(optarg, "first ttl", 1, 255);
@ -784,6 +789,10 @@ main(int argc, char **argv)
outip->ip_v = IPVERSION;
if (settos)
outip->ip_tos = tos;
if (ecnflag) {
outip->ip_tos &= ~IPTOS_ECN_MASK;
outip->ip_tos |= IPTOS_ECN_ECT1;
}
#ifdef BYTESWAP_IP_HDR
outip->ip_len = htons(packlen);
outip->ip_off = htons(off);
@ -1122,6 +1131,23 @@ main(int argc, char **argv)
#endif
precis = 3;
Printf(" %.*f ms", precis, T);
if (ecnflag) {
u_char ecn = hip->ip_tos & IPTOS_ECN_MASK;
switch (ecn) {
case IPTOS_ECN_ECT1:
Printf(" (ecn=passed)");
break;
case IPTOS_ECN_NOTECT:
Printf(" (ecn=bleached)");
break;
case IPTOS_ECN_CE:
Printf(" (ecn=congested)");
break;
default:
Printf(" (ecn=mangled)");
break;
}
}
if (printdiff) {
Printf("\n");
Printf("%*.*s%s\n",
@ -2126,7 +2152,7 @@ usage(void)
Fprintf(stderr, "Version %s\n", version);
Fprintf(stderr,
"Usage: %s [-adDeFInrSvx] [-f first_ttl] [-g gateway] [-i iface]\n"
"Usage: %s [-adDeEFInrSvx] [-f first_ttl] [-g gateway] [-i iface]\n"
"\t[-m max_ttl] [-p port] [-P proto] [-q nqueries] [-s src_addr]\n"
"\t[-t tos] [-w waittime] [-A as_server] [-z pausemsecs] host [packetlen]\n", prog);
exit(1);