Make use of IP_VLAN_PCP setsockopt in ping and ping6.

In order to validate the proper marking and use of a different
ethernet priority class, add the new session-specific PCP
feature to the ping/ping6 utilities.

Reviewed by:	mav, bcr
Sponsored by:	NetApp, Inc.
Differential Revision:	https://reviews.freebsd.org/D26627
This commit is contained in:
Richard Scheffenegger 2020-10-24 21:01:18 +00:00
parent cb8e067818
commit 81a6f4c7ae
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=367021
4 changed files with 45 additions and 8 deletions

View File

@ -28,7 +28,7 @@
.\" @(#)ping.8 8.2 (Berkeley) 12/11/93 .\" @(#)ping.8 8.2 (Berkeley) 12/11/93
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd August 22, 2019 .Dd October 2, 2020
.Dt PING 8 .Dt PING 8
.Os .Os
.Sh NAME .Sh NAME
@ -39,6 +39,7 @@ packets to network hosts
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl AaDdfHnoQqRrv .Op Fl AaDdfHnoQqRrv
.Op Fl C Ar pcp
.Op Fl c Ar count .Op Fl c Ar count
.Op Fl G Ar sweepmaxsize .Op Fl G Ar sweepmaxsize
.Op Fl g Ar sweepminsize .Op Fl g Ar sweepminsize
@ -57,6 +58,7 @@ packets to network hosts
.Ar host .Ar host
.Nm .Nm
.Op Fl AaDdfHLnoQqRrv .Op Fl AaDdfHLnoQqRrv
.Op Fl C Ar pcp
.Op Fl c Ar count .Op Fl c Ar count
.Op Fl I Ar iface .Op Fl I Ar iface
.Op Fl i Ar wait .Op Fl i Ar wait
@ -112,6 +114,9 @@ Include a bell
character in the output when any packet is received. character in the output when any packet is received.
This option is ignored This option is ignored
if other format options are present. if other format options are present.
.It Fl C Ar pcp
Add an 802.1p Ethernet Priority Code Point when sending a packet.
0..7 uses that specific PCP, -1 uses the interface default PCP (or none).
.It Fl c Ar count .It Fl c Ar count
Stop after sending Stop after sending
(and receiving) (and receiving)

View File

@ -155,6 +155,7 @@ static int options;
#define F_TIME 0x100000 #define F_TIME 0x100000
#define F_SWEEP 0x200000 #define F_SWEEP 0x200000
#define F_WAITTIME 0x400000 #define F_WAITTIME 0x400000
#define F_IP_VLAN_PCP 0x800000
/* /*
* MAX_DUP_CHK is the number of bits in received table, i.e. the maximum * MAX_DUP_CHK is the number of bits in received table, i.e. the maximum
@ -247,7 +248,7 @@ main(int argc, char *const *argv)
u_long alarmtimeout; u_long alarmtimeout;
long ltmp; long ltmp;
int almost_done, ch, df, hold, i, icmp_len, mib[4], preload; int almost_done, ch, df, hold, i, icmp_len, mib[4], preload;
int ssend_errno, srecv_errno, tos, ttl; int ssend_errno, srecv_errno, tos, ttl, pcp;
char ctrl[CMSG_SPACE(sizeof(struct timespec))]; char ctrl[CMSG_SPACE(sizeof(struct timespec))];
char hnamebuf[MAXHOSTNAMELEN], snamebuf[MAXHOSTNAMELEN]; char hnamebuf[MAXHOSTNAMELEN], snamebuf[MAXHOSTNAMELEN];
#ifdef IP_OPTIONS #ifdef IP_OPTIONS
@ -295,11 +296,11 @@ main(int argc, char *const *argv)
err(EX_OSERR, "srecv socket"); err(EX_OSERR, "srecv socket");
} }
alarmtimeout = df = preload = tos = 0; alarmtimeout = df = preload = tos = pcp = 0;
outpack = outpackhdr + sizeof(struct ip); outpack = outpackhdr + sizeof(struct ip);
while ((ch = getopt(argc, argv, while ((ch = getopt(argc, argv,
"Aac:DdfG:g:Hh:I:i:Ll:M:m:nop:QqRrS:s:T:t:vW:z:" "AaC:c:DdfG:g:Hh:I:i:Ll:M:m:nop:QqRrS:s:T:t:vW:z:"
#ifdef IPSEC #ifdef IPSEC
#ifdef IPSEC_POLICY_IPSEC #ifdef IPSEC_POLICY_IPSEC
"P:" "P:"
@ -314,6 +315,13 @@ main(int argc, char *const *argv)
case 'a': case 'a':
options |= F_AUDIBLE; options |= F_AUDIBLE;
break; break;
case 'C':
options |= F_IP_VLAN_PCP;
ltmp = strtol(optarg, &ep, 0);
if (*ep || ep == optarg || ltmp > 7 || ltmp < -1)
errx(EX_USAGE, "invalid PCP: `%s'", optarg);
pcp = ltmp;
break;
case 'c': case 'c':
ltmp = strtol(optarg, &ep, 0); ltmp = strtol(optarg, &ep, 0);
if (*ep || ep == optarg || ltmp <= 0) if (*ep || ep == optarg || ltmp <= 0)
@ -665,6 +673,10 @@ main(int argc, char *const *argv)
if (options & F_SO_DONTROUTE) if (options & F_SO_DONTROUTE)
(void)setsockopt(ssend, SOL_SOCKET, SO_DONTROUTE, (char *)&hold, (void)setsockopt(ssend, SOL_SOCKET, SO_DONTROUTE, (char *)&hold,
sizeof(hold)); sizeof(hold));
if (options & F_IP_VLAN_PCP) {
(void)setsockopt(ssend, IPPROTO_IP, IP_VLAN_PCP, (char *)&pcp,
sizeof(pcp));
}
#ifdef IPSEC #ifdef IPSEC
#ifdef IPSEC_POLICY_IPSEC #ifdef IPSEC_POLICY_IPSEC
if (options & F_POLICY) { if (options & F_POLICY) {
@ -1762,11 +1774,11 @@ usage(void)
{ {
(void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", (void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
"usage: ping [-AaDdfHnoQqRrv] [-c count] [-G sweepmaxsize] [-g sweepminsize]", "usage: ping [-AaDdfHnoQqRrv] [-C pcp] [-c count] [-G sweepmaxsize] [-g sweepminsize]",
" [-h sweepincrsize] [-i wait] [-l preload] [-M mask | time] [-m ttl]", " [-h sweepincrsize] [-i wait] [-l preload] [-M mask | time] [-m ttl]",
" " SECOPT " [-p pattern] [-S src_addr] [-s packetsize] [-t timeout]", " " SECOPT " [-p pattern] [-S src_addr] [-s packetsize] [-t timeout]",
" [-W waittime] [-z tos] host", " [-W waittime] [-z tos] host",
" ping [-AaDdfHLnoQqRrv] [-c count] [-I iface] [-i wait] [-l preload]", " ping [-AaDdfHLnoQqRrv] [-C pcp] [-c count] [-I iface] [-i wait] [-l preload]",
" [-M mask | time] [-m ttl]" SECOPT " [-p pattern] [-S src_addr]", " [-M mask | time] [-m ttl]" SECOPT " [-p pattern] [-S src_addr]",
" [-s packetsize] [-T ttl] [-t timeout] [-W waittime]", " [-s packetsize] [-T ttl] [-t timeout] [-W waittime]",
" [-z tos] mcast-group"); " [-z tos] mcast-group");

View File

@ -29,7 +29,7 @@
.\" .\"
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd September 10, 2020 .Dd October 2, 2020
.Dt PING6 8 .Dt PING6 8
.Os .Os
.Sh NAME .Sh NAME
@ -47,6 +47,9 @@ packets to network hosts
.Op Fl b Ar bufsiz .Op Fl b Ar bufsiz
.Ek .Ek
.Bk -words .Bk -words
.Op Fl C Ar pcp
.Ek
.Bk -words
.Op Fl c Ar count .Op Fl c Ar count
.Ek .Ek
.Bk -words .Bk -words
@ -144,6 +147,9 @@ This is an experimental option.
.El .El
.It Fl b Ar bufsiz .It Fl b Ar bufsiz
Set socket buffer size. Set socket buffer size.
.It Fl C Ar pcp
Add an 802.1p Ethernet Priority Code Point when sending a packet.
0..7 uses that specific PCP, -1 uses the interface default PCP (or none).
.It Fl c Ar count .It Fl c Ar count
Stop after sending Stop after sending
(and receiving) (and receiving)

View File

@ -230,6 +230,7 @@ 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 int tclass = -1; /* traffic class */
static int pcp = -2; /* vlan priority code point */
static u_char *packet = NULL; static u_char *packet = NULL;
static cap_channel_t *capdns; static cap_channel_t *capdns;
@ -353,7 +354,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:z:" ADDOPTS)) != -1) { "k:b:C: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':
@ -413,6 +414,13 @@ main(int argc, char *argv[])
"-b option ignored: SO_SNDBUF/SO_RCVBUF socket options not supported"); "-b option ignored: SO_SNDBUF/SO_RCVBUF socket options not supported");
#endif #endif
break; break;
case 'C': /* vlan priority code point */
pcp = strtol(optarg, &e, 10);
if (*optarg == '\0' || *e != '\0')
errx(1, "illegal vlan pcp %s", optarg);
if (7 < pcp || pcp < -1)
errx(1, "illegal vlan pcp -- %s", optarg);
break;
case 'c': case 'c':
npackets = strtol(optarg, &e, 10); npackets = strtol(optarg, &e, 10);
if (npackets <= 0 || *optarg == '\0' || *e != '\0') if (npackets <= 0 || *optarg == '\0' || *e != '\0')
@ -952,6 +960,12 @@ main(int argc, char *argv[])
err(1, "setsockopt(IPV6_TCLASS)"); err(1, "setsockopt(IPV6_TCLASS)");
} }
if (pcp != -2) {
if (setsockopt(ssend, IPPROTO_IPV6, IPV6_VLAN_PCP,
&pcp, sizeof(pcp)) == -1)
err(1, "setsockopt(IPV6_VLAN_PCP)");
}
if (argc > 1) { /* some intermediate addrs are specified */ if (argc > 1) { /* some intermediate addrs are specified */
int hops; int hops;
int rthdrlen; int rthdrlen;