Author: rscheff
Date: Sat Oct 24 21:01:18 2020
New Revision: 367021
URL: https://svnweb.freebsd.org/changeset/base/367021

Log:
  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

Modified:
  head/sbin/ping/ping.8
  head/sbin/ping/ping.c
  head/sbin/ping6/ping6.8
  head/sbin/ping6/ping6.c

Modified: head/sbin/ping/ping.8
==============================================================================
--- head/sbin/ping/ping.8       Sat Oct 24 20:57:13 2020        (r367020)
+++ head/sbin/ping/ping.8       Sat Oct 24 21:01:18 2020        (r367021)
@@ -28,7 +28,7 @@
 .\"     @(#)ping.8     8.2 (Berkeley) 12/11/93
 .\" $FreeBSD$
 .\"
-.Dd August 22, 2019
+.Dd October 2, 2020
 .Dt PING 8
 .Os
 .Sh NAME
@@ -39,6 +39,7 @@ packets to network hosts
 .Sh SYNOPSIS
 .Nm
 .Op Fl AaDdfHnoQqRrv
+.Op Fl C Ar pcp
 .Op Fl c Ar count
 .Op Fl G Ar sweepmaxsize
 .Op Fl g Ar sweepminsize
@@ -57,6 +58,7 @@ packets to network hosts
 .Ar host
 .Nm
 .Op Fl AaDdfHLnoQqRrv
+.Op Fl C Ar pcp
 .Op Fl c Ar count
 .Op Fl I Ar iface
 .Op Fl i Ar wait
@@ -112,6 +114,9 @@ Include a bell
 character in the output when any packet is received.
 This option is ignored
 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
 Stop after sending
 (and receiving)

Modified: head/sbin/ping/ping.c
==============================================================================
--- head/sbin/ping/ping.c       Sat Oct 24 20:57:13 2020        (r367020)
+++ head/sbin/ping/ping.c       Sat Oct 24 21:01:18 2020        (r367021)
@@ -155,6 +155,7 @@ static int options;
 #define        F_TIME          0x100000
 #define        F_SWEEP         0x200000
 #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
@@ -247,7 +248,7 @@ main(int argc, char *const *argv)
        u_long alarmtimeout;
        long ltmp;
        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 hnamebuf[MAXHOSTNAMELEN], snamebuf[MAXHOSTNAMELEN];
 #ifdef IP_OPTIONS
@@ -295,11 +296,11 @@ main(int argc, char *const *argv)
                err(EX_OSERR, "srecv socket");
        }
 
-       alarmtimeout = df = preload = tos = 0;
+       alarmtimeout = df = preload = tos = pcp = 0;
 
        outpack = outpackhdr + sizeof(struct ip);
        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_POLICY_IPSEC
                "P:"
@@ -314,6 +315,13 @@ main(int argc, char *const *argv)
                case 'a':
                        options |= F_AUDIBLE;
                        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':
                        ltmp = strtol(optarg, &ep, 0);
                        if (*ep || ep == optarg || ltmp <= 0)
@@ -665,6 +673,10 @@ main(int argc, char *const *argv)
        if (options & F_SO_DONTROUTE)
                (void)setsockopt(ssend, SOL_SOCKET, SO_DONTROUTE, (char *)&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_POLICY_IPSEC
        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",
-"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]",
 "           " SECOPT " [-p pattern] [-S src_addr] [-s packetsize] [-t 
timeout]",
 "            [-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]",
 "            [-s packetsize] [-T ttl] [-t timeout] [-W waittime]",
 "            [-z tos] mcast-group");

Modified: head/sbin/ping6/ping6.8
==============================================================================
--- head/sbin/ping6/ping6.8     Sat Oct 24 20:57:13 2020        (r367020)
+++ head/sbin/ping6/ping6.8     Sat Oct 24 21:01:18 2020        (r367021)
@@ -29,7 +29,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd September 10, 2020
+.Dd October 2, 2020
 .Dt PING6 8
 .Os
 .Sh NAME
@@ -47,6 +47,9 @@ packets to network hosts
 .Op Fl b Ar bufsiz
 .Ek
 .Bk -words
+.Op Fl C Ar pcp
+.Ek
+.Bk -words
 .Op Fl c Ar count
 .Ek
 .Bk -words
@@ -144,6 +147,9 @@ This is an experimental option.
 .El
 .It Fl b Ar bufsiz
 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
 Stop after sending
 (and receiving)

Modified: head/sbin/ping6/ping6.c
==============================================================================
--- head/sbin/ping6/ping6.c     Sat Oct 24 20:57:13 2020        (r367020)
+++ head/sbin/ping6/ping6.c     Sat Oct 24 21:01:18 2020        (r367021)
@@ -230,6 +230,7 @@ static int ident;           /* process id to identify our 
packe
 static u_int8_t nonce[8];      /* nonce field for node information */
 static int hoplimit = -1;      /* hoplimit */
 static int tclass = -1;                /* traffic class */
+static int pcp = -2;           /* vlan priority code point */
 static u_char *packet = NULL;
 static cap_channel_t *capdns;
 
@@ -353,7 +354,7 @@ main(int argc, char *argv[])
 #endif /*IPSEC_POLICY_IPSEC*/
 #endif
        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
                switch (ch) {
                case 'k':
@@ -413,6 +414,13 @@ main(int argc, char *argv[])
 "-b option ignored: SO_SNDBUF/SO_RCVBUF socket options not supported");
 #endif
                        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':
                        npackets = strtol(optarg, &e, 10);
                        if (npackets <= 0 || *optarg == '\0' || *e != '\0')
@@ -950,6 +958,12 @@ main(int argc, char *argv[])
                if (setsockopt(ssend, IPPROTO_IPV6, IPV6_TCLASS,
                    &tclass, sizeof(tclass)) == -1)
                        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 */
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to