Add -z "TOS" option to ping6, to test DSCP/ECN values

ping has the option to add the (deprecated) TOS byte
using the -z option. Adding the same option, with the
same (deprecated) Traffic Class Byte (nowadays actually
DSCP and ECN fields) to ping6 to validate proper QoS
processing in network switches.

Reviewed by:	tuexen
MFC after:	2 weeks
Sponsored by:	NetApp, Inc.
Differential Revision:	https://reviews.freebsd.org/D26384
This commit is contained in:
Richard Scheffenegger 2020-09-10 00:50:18 +00:00
parent e74e64a191
commit 6034024dad
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=365547
2 changed files with 22 additions and 2 deletions

View File

@ -29,7 +29,7 @@
.\" .\"
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd October 20, 2019 .Dd September 10, 2020
.Dt PING6 8 .Dt PING6 8
.Os .Os
.Sh NAME .Sh NAME
@ -87,6 +87,9 @@ packets to network hosts
.Op Fl W Ar waittime .Op Fl W Ar waittime
.Ek .Ek
.Bk -words .Bk -words
.Op Fl z Ar tclass
.Ek
.Bk -words
.Op Ar hops ... .Op Ar hops ...
.Ek .Ek
.Bk -words .Bk -words
@ -329,6 +332,8 @@ This option is present for backward compatibility.
has no effect if has no effect if
.Fl y .Fl y
is specified. is specified.
.It Fl z Ar tclass
Use the specified traffic class when sending.
.It Ar hops .It Ar hops
IPv6 addresses for intermediate nodes, IPv6 addresses for intermediate nodes,
which will be put into type 0 routing header. which will be put into type 0 routing header.

View File

@ -229,6 +229,7 @@ static char *hostname;
static int ident; /* process id to identify our packets */ static int ident; /* process id to identify our packets */
static u_int8_t nonce[8]; /* nonce field for node information */ static u_int8_t nonce[8]; /* nonce field for node information */
static int hoplimit = -1; /* hoplimit */ static int hoplimit = -1; /* hoplimit */
static int tclass = -1; /* traffic class */
static u_char *packet = NULL; static u_char *packet = NULL;
static cap_channel_t *capdns; static cap_channel_t *capdns;
@ -352,7 +353,7 @@ main(int argc, char *argv[])
#endif /*IPSEC_POLICY_IPSEC*/ #endif /*IPSEC_POLICY_IPSEC*/
#endif #endif
while ((ch = getopt(argc, argv, while ((ch = getopt(argc, argv,
"k:b:c:DdfHe:m:I:i:l:unNop:qaAS:s:OvyYW:t:" ADDOPTS)) != -1) { "k:b:c:DdfHe:m:I:i:l:unNop:qaAS:s:OvyYW:t:z:" ADDOPTS)) != -1) {
#undef ADDOPTS #undef ADDOPTS
switch (ch) { switch (ch) {
case 'k': case 'k':
@ -585,6 +586,14 @@ main(int argc, char *argv[])
err(1, "setitimer"); err(1, "setitimer");
} }
break; break;
case 'z': /* traffic class */
tclass = strtol(optarg, &e, 10);
if (*optarg == '\0' || *e != '\0')
errx(1, "illegal traffic class %s", optarg);
if (255 < tclass || tclass < -1)
errx(1,
"illegal traffic class -- %s", optarg);
break;
#ifdef IPSEC #ifdef IPSEC
#ifdef IPSEC_POLICY_IPSEC #ifdef IPSEC_POLICY_IPSEC
case 'P': case 'P':
@ -937,6 +946,12 @@ main(int argc, char *argv[])
scmsgp = CMSG_NXTHDR(&smsghdr, scmsgp); scmsgp = CMSG_NXTHDR(&smsghdr, scmsgp);
} }
if (tclass != -1) {
if (setsockopt(ssend, IPPROTO_IPV6, IPV6_TCLASS,
&tclass, sizeof(tclass)) == -1)
err(1, "setsockopt(IPV6_TCLASS)");
}
if (argc > 1) { /* some intermediate addrs are specified */ if (argc > 1) { /* some intermediate addrs are specified */
int hops; int hops;
int rthdrlen; int rthdrlen;